mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-12-04 09:14:47 +00:00
Changed: Minor changes
This commit is contained in:
parent
17429dd145
commit
e8cf46226a
3 changed files with 197 additions and 193 deletions
|
@ -90,14 +90,14 @@ static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::str
|
||||||
*/
|
*/
|
||||||
static bool CheckIfNeedRebuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::string &fileNameWithExtension, bool mustDivideBy2);
|
static bool CheckIfNeedRebuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::string &fileNameWithExtension, bool mustDivideBy2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// replace slashes by the matching os value in a file name
|
/// replace slashes by the matching os value in a file name
|
||||||
static std::string replaceSlashes(const std::string &src)
|
static std::string replaceSlashes(const std::string &src)
|
||||||
{
|
{
|
||||||
std::string result = src;
|
std::string result = src;
|
||||||
for(uint k = 0; k < result.size(); ++k)
|
for(uint k = 0; k < result.size(); ++k)
|
||||||
#ifdef NL_OS_WINDOWS
|
#ifdef NL_OS_WINDOWS
|
||||||
if (result[k] == '/') result[k] = '\\';
|
if (result[k] == '/') result[k] = '\\';
|
||||||
#else
|
#else
|
||||||
if (result[k] == '\\') result[k] = '/';
|
if (result[k] == '\\') result[k] = '/';
|
||||||
|
@ -109,7 +109,7 @@ static std::string replaceSlashes(const std::string &src)
|
||||||
|
|
||||||
///=====================================================
|
///=====================================================
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
// Filter addSearchPath
|
// Filter addSearchPath
|
||||||
NLMISC::createDebug();
|
NLMISC::createDebug();
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
CInfoMaskGeneration infoMaskGen(_Path_Input_TexBases,
|
CInfoMaskGeneration infoMaskGen(_Path_Input_TexBases,
|
||||||
_Path_Input_Masks,
|
_Path_Input_Masks,
|
||||||
_Path_Output_MaksOptimized,
|
_Path_Output_MasksOptimized,
|
||||||
_Path_Output_Gtm,
|
_Path_Output_Gtm,
|
||||||
argv[3],
|
argv[3],
|
||||||
1);
|
1);
|
||||||
|
@ -232,7 +232,7 @@ int main(int argc, char* argv[])
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
CBuildInfo bi;
|
CBuildInfo bi;
|
||||||
|
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
// reads infos from the config files //
|
// reads infos from the config files //
|
||||||
|
@ -259,7 +259,7 @@ int main(int argc, char* argv[])
|
||||||
catch (const NLMISC::EUnknownVar &)
|
catch (const NLMISC::EUnknownVar &)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// input
|
/// input
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -310,7 +310,7 @@ int main(int argc, char* argv[])
|
||||||
/// default ascii character for unused masks
|
/// default ascii character for unused masks
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bi.DefaultSeparator = cf.getVar ("default_separator").asString();
|
bi.DefaultSeparator = cf.getVar ("default_separator").asString();
|
||||||
}
|
}
|
||||||
catch (const NLMISC::EUnknownVar &)
|
catch (const NLMISC::EUnknownVar &)
|
||||||
{
|
{
|
||||||
|
@ -319,7 +319,7 @@ int main(int argc, char* argv[])
|
||||||
/// extension for bitmaps
|
/// extension for bitmaps
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NLMISC::CConfigFile::CVar &bitmap_extensions = cf.getVar ("bitmap_extensions");
|
NLMISC::CConfigFile::CVar &bitmap_extensions = cf.getVar ("bitmap_extensions");
|
||||||
for (uint k = 0; k < (uint) bitmap_extensions.size(); ++k)
|
for (uint k = 0; k < (uint) bitmap_extensions.size(); ++k)
|
||||||
{
|
{
|
||||||
std::string ext = "." + bitmap_extensions.asString(k);
|
std::string ext = "." + bitmap_extensions.asString(k);
|
||||||
|
@ -327,8 +327,8 @@ int main(int argc, char* argv[])
|
||||||
if (std::find(bi.BitmapExtensions.begin(), bi.BitmapExtensions.end(), ext) == bi.BitmapExtensions.end())
|
if (std::find(bi.BitmapExtensions.begin(), bi.BitmapExtensions.end(), ext) == bi.BitmapExtensions.end())
|
||||||
{
|
{
|
||||||
bi.BitmapExtensions.push_back(ext);
|
bi.BitmapExtensions.push_back(ext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const NLMISC::EUnknownVar &)
|
catch (const NLMISC::EUnknownVar &)
|
||||||
{
|
{
|
||||||
|
@ -338,7 +338,7 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bi.LowDefShift = cf.getVar ("low_def_shift").asInt();
|
bi.LowDefShift = cf.getVar ("low_def_shift").asInt();
|
||||||
}
|
}
|
||||||
catch (const NLMISC::EUnknownVar &)
|
catch (const NLMISC::EUnknownVar &)
|
||||||
{
|
{
|
||||||
|
@ -377,7 +377,7 @@ int main(int argc, char* argv[])
|
||||||
static void validateCgiInfo()
|
static void validateCgiInfo()
|
||||||
{
|
{
|
||||||
NLMISC::CIFile f;
|
NLMISC::CIFile f;
|
||||||
|
|
||||||
|
|
||||||
vector<StrInfoTexColor> temp;
|
vector<StrInfoTexColor> temp;
|
||||||
uint version;
|
uint version;
|
||||||
|
@ -409,15 +409,15 @@ static void validateGtmInfo()
|
||||||
///======================================================
|
///======================================================
|
||||||
static void BuildMasksFromConfigFile(NLMISC::CConfigFile &cf,
|
static void BuildMasksFromConfigFile(NLMISC::CConfigFile &cf,
|
||||||
TColorMaskVect &colorMasks)
|
TColorMaskVect &colorMasks)
|
||||||
|
|
||||||
{
|
{
|
||||||
/// get a list of the alpha mask extensions
|
/// get a list of the alpha mask extensions
|
||||||
NLMISC::CConfigFile::CVar &mask_extensions = cf.getVar ("mask_extensions");
|
NLMISC::CConfigFile::CVar &mask_extensions = cf.getVar ("mask_extensions");
|
||||||
colorMasks.resize(mask_extensions.size());
|
colorMasks.resize(mask_extensions.size());
|
||||||
|
|
||||||
/// For each kind of mask, build a list of the color modifiers
|
/// For each kind of mask, build a list of the color modifiers
|
||||||
for (uint k = 0; k < (uint) mask_extensions.size(); ++k)
|
for (uint k = 0; k < (uint) mask_extensions.size(); ++k)
|
||||||
{
|
{
|
||||||
colorMasks[k].MaskExt = mask_extensions.asString(k);
|
colorMasks[k].MaskExt = mask_extensions.asString(k);
|
||||||
NLMISC::CConfigFile::CVar &luminosities = cf.getVar (colorMasks[k].MaskExt + "_luminosities");
|
NLMISC::CConfigFile::CVar &luminosities = cf.getVar (colorMasks[k].MaskExt + "_luminosities");
|
||||||
NLMISC::CConfigFile::CVar &contrasts = cf.getVar (colorMasks[k].MaskExt + "_constrasts");
|
NLMISC::CConfigFile::CVar &contrasts = cf.getVar (colorMasks[k].MaskExt + "_constrasts");
|
||||||
|
@ -427,7 +427,7 @@ static void BuildMasksFromConfigFile(NLMISC::CConfigFile &cf,
|
||||||
NLMISC::CConfigFile::CVar &colorIDs = cf.getVar (colorMasks[k].MaskExt + "_color_id");
|
NLMISC::CConfigFile::CVar &colorIDs = cf.getVar (colorMasks[k].MaskExt + "_color_id");
|
||||||
|
|
||||||
if (luminosities.size() != contrasts.size()
|
if (luminosities.size() != contrasts.size()
|
||||||
|| luminosities.size() != hues.size()
|
|| luminosities.size() != hues.size()
|
||||||
|| luminosities.size() != lightness.size()
|
|| luminosities.size() != lightness.size()
|
||||||
|| luminosities.size() != saturation.size()
|
|| luminosities.size() != saturation.size()
|
||||||
|| luminosities.size() != colorIDs.size()
|
|| luminosities.size() != colorIDs.size()
|
||||||
|
@ -473,16 +473,16 @@ static void BuildColoredVersions(const CBuildInfo &bi)
|
||||||
{
|
{
|
||||||
for (uint l = 0; l < bi.BitmapExtensions.size(); ++l)
|
for (uint l = 0; l < bi.BitmapExtensions.size(); ++l)
|
||||||
{
|
{
|
||||||
std::string fileExt = "." + NLMISC::strupr(NLMISC::CFile::getExtension(files[k]));
|
std::string fileExt = "." + NLMISC::strupr(NLMISC::CFile::getExtension(files[k]));
|
||||||
if (fileExt == bi.BitmapExtensions[l])
|
if (fileExt == bi.BitmapExtensions[l])
|
||||||
{
|
{
|
||||||
//nlwarning("Processing : %s ", files[k].c_str());
|
//nlwarning("Processing : %s ", files[k].c_str());
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (CheckIfNeedRebuildColoredVersionForOneBitmap(bi, NLMISC::CFile::getFilename(files[k]),
|
if (CheckIfNeedRebuildColoredVersionForOneBitmap(bi, NLMISC::CFile::getFilename(files[k]),
|
||||||
sizeVersion==1) )
|
sizeVersion==1) )
|
||||||
{
|
{
|
||||||
BuildColoredVersionForOneBitmap(bi,
|
BuildColoredVersionForOneBitmap(bi,
|
||||||
NLMISC::CFile::getFilename(files[k]),
|
NLMISC::CFile::getFilename(files[k]),
|
||||||
sizeVersion==1);
|
sizeVersion==1);
|
||||||
}
|
}
|
||||||
|
@ -493,7 +493,7 @@ static void BuildColoredVersions(const CBuildInfo &bi)
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
nlwarning("Processing of %s failed : %s \n", files[k].c_str(), e.what());
|
nlwarning("Processing of %s failed : %s \n", files[k].c_str(), e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -502,7 +502,7 @@ static void BuildColoredVersions(const CBuildInfo &bi)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// used to loop throiugh the process, avoiding unused masks
|
/// used to loop throiugh the process, avoiding unused masks
|
||||||
struct CLoopInfo
|
struct CLoopInfo
|
||||||
{
|
{
|
||||||
NLMISC::CBitmap Mask;
|
NLMISC::CBitmap Mask;
|
||||||
|
@ -512,11 +512,11 @@ struct CLoopInfo
|
||||||
|
|
||||||
|
|
||||||
///======================================================
|
///======================================================
|
||||||
static bool CheckIfNeedRebuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::string &fileNameWithExtension,
|
static bool CheckIfNeedRebuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::string &fileNameWithExtension,
|
||||||
bool mustDivideBy2)
|
bool mustDivideBy2)
|
||||||
{
|
{
|
||||||
if (bi.CachePath.empty()) return true;
|
if (bi.CachePath.empty()) return true;
|
||||||
uint32 srcDate = (uint32) NLMISC::CFile::getFileModificationDate(replaceSlashes(bi.InputPath + fileNameWithExtension));
|
uint32 srcDate = (uint32) NLMISC::CFile::getFileModificationDate(replaceSlashes(bi.InputPath + fileNameWithExtension));
|
||||||
static std::vector<CLoopInfo> masks;
|
static std::vector<CLoopInfo> masks;
|
||||||
/// check the needed masks
|
/// check the needed masks
|
||||||
masks.clear();
|
masks.clear();
|
||||||
|
@ -530,16 +530,16 @@ static bool CheckIfNeedRebuildColoredVersionForOneBitmap(const CBuildInfo &bi, c
|
||||||
std::string maskFileName = NLMISC::CPath::lookup(maskName,
|
std::string maskFileName = NLMISC::CPath::lookup(maskName,
|
||||||
false, false);
|
false, false);
|
||||||
if (!maskFileName.empty()) // found the mask ?
|
if (!maskFileName.empty()) // found the mask ?
|
||||||
{
|
{
|
||||||
CLoopInfo li;
|
CLoopInfo li;
|
||||||
li.Counter = 0;
|
li.Counter = 0;
|
||||||
li.MaskID = k;
|
li.MaskID = k;
|
||||||
|
|
||||||
if (NLMISC::CFile::fileExists(maskFileName))
|
if (NLMISC::CFile::fileExists(maskFileName))
|
||||||
{
|
{
|
||||||
srcDate = std::max(srcDate, (uint32) NLMISC::CFile::getFileModificationDate(replaceSlashes(maskFileName)));
|
srcDate = std::max(srcDate, (uint32) NLMISC::CFile::getFileModificationDate(replaceSlashes(maskFileName)));
|
||||||
masks.push_back(li);
|
masks.push_back(li);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -550,7 +550,7 @@ static bool CheckIfNeedRebuildColoredVersionForOneBitmap(const CBuildInfo &bi, c
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Must now if was moved beetween normal dir and d4/ dir.
|
// Must now if was moved beetween normal dir and d4/ dir.
|
||||||
CHLSBankTextureInfo hlsInfo;
|
CHLSBankTextureInfo hlsInfo;
|
||||||
// read .hlsInfo cache
|
// read .hlsInfo cache
|
||||||
CIFile f;
|
CIFile f;
|
||||||
|
@ -573,24 +573,24 @@ static bool CheckIfNeedRebuildColoredVersionForOneBitmap(const CBuildInfo &bi, c
|
||||||
|
|
||||||
/// check is each generated texture has the same date or is more recent
|
/// check is each generated texture has the same date or is more recent
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
uint l;
|
uint l;
|
||||||
std::string outputFileName = fileName;
|
std::string outputFileName = fileName;
|
||||||
|
|
||||||
/// build current tex name
|
/// build current tex name
|
||||||
for (l = 0; l < masks.size(); ++l)
|
for (l = 0; l < masks.size(); ++l)
|
||||||
{
|
{
|
||||||
uint maskID = masks[l].MaskID;
|
uint maskID = masks[l].MaskID;
|
||||||
uint colorID = masks[l].Counter;
|
uint colorID = masks[l].Counter;
|
||||||
/// complete the file name
|
/// complete the file name
|
||||||
outputFileName += bi.DefaultSeparator + bi.ColorMasks[maskID].CMs[colorID].ColID;
|
outputFileName += bi.DefaultSeparator + bi.ColorMasks[maskID].CMs[colorID].ColID;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compare date
|
// compare date
|
||||||
std::string searchName = replaceSlashes(bi.CachePath + outputFileName + bi.OutputFormat);
|
std::string searchName = replaceSlashes(bi.CachePath + outputFileName + bi.OutputFormat);
|
||||||
if ((uint32) NLMISC::CFile::getFileModificationDate(searchName) < srcDate)
|
if ((uint32) NLMISC::CFile::getFileModificationDate(searchName) < srcDate)
|
||||||
{
|
{
|
||||||
return true; // not found or more old => need rebuild
|
return true; // not found or more old => need rebuild
|
||||||
}
|
}
|
||||||
|
|
||||||
// get version that is in the cache
|
// get version that is in the cache
|
||||||
|
@ -599,7 +599,7 @@ static bool CheckIfNeedRebuildColoredVersionForOneBitmap(const CBuildInfo &bi, c
|
||||||
{
|
{
|
||||||
nlwarning(("Couldn't move " + searchName + " to " + cacheDest).c_str());
|
nlwarning(("Couldn't move " + searchName + " to " + cacheDest).c_str());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// increment counters
|
/// increment counters
|
||||||
for (l = 0; l < (uint) masks.size(); ++l)
|
for (l = 0; l < (uint) masks.size(); ++l)
|
||||||
|
@ -624,9 +624,9 @@ static bool CheckIfNeedRebuildColoredVersionForOneBitmap(const CBuildInfo &bi, c
|
||||||
|
|
||||||
|
|
||||||
///======================================================
|
///======================================================
|
||||||
static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::string &fileNameWithExtension,
|
static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::string &fileNameWithExtension,
|
||||||
bool mustDivideBy2)
|
bool mustDivideBy2)
|
||||||
{
|
{
|
||||||
uint32 depth;
|
uint32 depth;
|
||||||
NLMISC::CBitmap srcBitmap;
|
NLMISC::CBitmap srcBitmap;
|
||||||
NLMISC::CBitmap resultBitmap;
|
NLMISC::CBitmap resultBitmap;
|
||||||
|
@ -651,6 +651,7 @@ static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::str
|
||||||
{
|
{
|
||||||
throw NLMISC::Exception(std::string("Failed to load bitmap ") + actualInputPath + fileNameWithExtension);
|
throw NLMISC::Exception(std::string("Failed to load bitmap ") + actualInputPath + fileNameWithExtension);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (srcBitmap.PixelFormat != NLMISC::CBitmap::RGBA)
|
if (srcBitmap.PixelFormat != NLMISC::CBitmap::RGBA)
|
||||||
{
|
{
|
||||||
srcBitmap.convertToType(NLMISC::CBitmap::RGBA);
|
srcBitmap.convertToType(NLMISC::CBitmap::RGBA);
|
||||||
|
@ -660,7 +661,7 @@ static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::str
|
||||||
{
|
{
|
||||||
nlwarning("Unable to open %s. Processing next", (actualInputPath + fileNameWithExtension).c_str());
|
nlwarning("Unable to open %s. Processing next", (actualInputPath + fileNameWithExtension).c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const NLMISC::Exception &)
|
catch (const NLMISC::Exception &)
|
||||||
{
|
{
|
||||||
|
@ -668,7 +669,7 @@ static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::str
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// **** Build and prepare build of the .hlsinfo to write.
|
/// **** Build and prepare build of the .hlsinfo to write.
|
||||||
CHLSBankTextureInfo hlsInfo;
|
CHLSBankTextureInfo hlsInfo;
|
||||||
CBitmap hlsInfoSrcBitmap;
|
CBitmap hlsInfoSrcBitmap;
|
||||||
|
@ -703,7 +704,7 @@ static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::str
|
||||||
std::string maskFileName = NLMISC::CPath::lookup(maskName,
|
std::string maskFileName = NLMISC::CPath::lookup(maskName,
|
||||||
false, false);
|
false, false);
|
||||||
if (!maskFileName.empty()) // found the mask ?
|
if (!maskFileName.empty()) // found the mask ?
|
||||||
{
|
{
|
||||||
CLoopInfo li;
|
CLoopInfo li;
|
||||||
li.Counter = 0;
|
li.Counter = 0;
|
||||||
li.MaskID = k;
|
li.MaskID = k;
|
||||||
|
@ -735,6 +736,7 @@ static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::str
|
||||||
{
|
{
|
||||||
throw NLMISC::Exception("Bitmap and mask do not have the same size");
|
throw NLMISC::Exception("Bitmap and mask do not have the same size");
|
||||||
}
|
}
|
||||||
|
|
||||||
masks.push_back(li);
|
masks.push_back(li);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -762,14 +764,14 @@ static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// **** generate each texture
|
// **** generate each texture
|
||||||
// NB : if there are no masks the texture just will be copied
|
// NB : if there are no masks the texture just will be copied
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
resultBitmap = srcBitmap;
|
resultBitmap = srcBitmap;
|
||||||
uint l;
|
uint l;
|
||||||
std::string outputFileName = fileName;
|
std::string outputFileName = fileName;
|
||||||
|
|
||||||
// Add an instance entry to the hlsInfo
|
// Add an instance entry to the hlsInfo
|
||||||
uint instId= (uint)hlsInfo.Instances.size();
|
uint instId= (uint)hlsInfo.Instances.size();
|
||||||
hlsInfo.Instances.resize(instId+1);
|
hlsInfo.Instances.resize(instId+1);
|
||||||
|
@ -797,9 +799,9 @@ static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::str
|
||||||
/// complete the file name
|
/// complete the file name
|
||||||
outputFileName += bi.DefaultSeparator + bi.ColorMasks[maskID].CMs[colorID].ColID;
|
outputFileName += bi.DefaultSeparator + bi.ColorMasks[maskID].CMs[colorID].ColID;
|
||||||
}
|
}
|
||||||
|
|
||||||
// save good hlsInfo instance name
|
// save good hlsInfo instance name
|
||||||
hlsTextInstance.Name= outputFileName + bi.OutputFormat;
|
hlsTextInstance.Name = outputFileName + bi.OutputFormat;
|
||||||
|
|
||||||
nlwarning("Writing %s", outputFileName.c_str());
|
nlwarning("Writing %s", outputFileName.c_str());
|
||||||
/// Save the result. We let propagate exceptions (if there's no more space disk it useless to continue...)
|
/// Save the result. We let propagate exceptions (if there's no more space disk it useless to continue...)
|
||||||
|
@ -832,9 +834,9 @@ static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::str
|
||||||
nlwarning(("Couldn't write " + bi.OutputPath + outputFileName + bi.OutputFormat + " : " + e.what()).c_str());
|
nlwarning(("Couldn't write " + bi.OutputPath + outputFileName + bi.OutputFormat + " : " + e.what()).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// increment counters
|
|
||||||
|
/// increment counters
|
||||||
for (l = 0; l < (uint) masks.size(); ++l)
|
for (l = 0; l < (uint) masks.size(); ++l)
|
||||||
{
|
{
|
||||||
++ (masks[l].Counter);
|
++ (masks[l].Counter);
|
||||||
|
|
|
@ -45,7 +45,7 @@ static char const* stateName(CSpawnGroupFauna::TState s)
|
||||||
|
|
||||||
// helper : get a fauna xyr zone from a base zone or a zone reference
|
// helper : get a fauna xyr zone from a base zone or a zone reference
|
||||||
static inline const CFaunaGenericPlace *getFaunaGenericPlace(const CAIPlace *place)
|
static inline const CFaunaGenericPlace *getFaunaGenericPlace(const CAIPlace *place)
|
||||||
{
|
{
|
||||||
const CFaunaGenericPlace *faunaPlace = dynamic_cast<const CFaunaGenericPlace *>(place);
|
const CFaunaGenericPlace *faunaPlace = dynamic_cast<const CFaunaGenericPlace *>(place);
|
||||||
nlassert(faunaPlace);
|
nlassert(faunaPlace);
|
||||||
return faunaPlace;
|
return faunaPlace;
|
||||||
|
@ -75,11 +75,11 @@ CSpawnGroupFauna::CSpawnGroupFauna(CPersistent<CSpawnGroup>& owner, RYAI_MAP_CRU
|
||||||
{
|
{
|
||||||
// variables for CAIMgrFauna's update prioritisation system
|
// variables for CAIMgrFauna's update prioritisation system
|
||||||
_UpdatePriority = 0; // 0..15 - priority class (distance based - 0 is highest priority)
|
_UpdatePriority = 0; // 0..15 - priority class (distance based - 0 is highest priority)
|
||||||
|
|
||||||
_Leader = (CBotFauna*)NULL;
|
_Leader = (CBotFauna*)NULL;
|
||||||
|
|
||||||
_Timer.set(0);
|
_Timer.set(0);
|
||||||
|
|
||||||
// pick a spawn place
|
// pick a spawn place
|
||||||
sint spawnPlace = getPersistent().getNextPlace(NULL, CAIPlaceXYRFauna::FLAG_SPAWN);
|
sint spawnPlace = getPersistent().getNextPlace(NULL, CAIPlaceXYRFauna::FLAG_SPAWN);
|
||||||
if (spawnPlace == CGrpFauna::INVALID_PLACE)
|
if (spawnPlace == CGrpFauna::INVALID_PLACE)
|
||||||
|
@ -88,40 +88,40 @@ CSpawnGroupFauna::CSpawnGroupFauna(CPersistent<CSpawnGroup>& owner, RYAI_MAP_CRU
|
||||||
// seek place with the smallest index
|
// seek place with the smallest index
|
||||||
sint minIndex = INT_MAX;
|
sint minIndex = INT_MAX;
|
||||||
for (uint k = 0; k < getPersistent().places().size(); ++k)
|
for (uint k = 0; k < getPersistent().places().size(); ++k)
|
||||||
{
|
{
|
||||||
const CFaunaGenericPlace *place = getFaunaGenericPlace(getPersistent().places()[k]);
|
const CFaunaGenericPlace *place = getFaunaGenericPlace(getPersistent().places()[k]);
|
||||||
minIndex = std::min((sint) place->getIndex(), minIndex);
|
minIndex = std::min((sint) place->getIndex(), minIndex);
|
||||||
}
|
}
|
||||||
for (uint k = 0; k < getPersistent().places().size(); ++k)
|
for (uint k = 0; k < getPersistent().places().size(); ++k)
|
||||||
{
|
{
|
||||||
const CFaunaGenericPlace *place = getFaunaGenericPlace(getPersistent().places()[k]);
|
const CFaunaGenericPlace *place = getFaunaGenericPlace(getPersistent().places()[k]);
|
||||||
if ((sint) place->getIndex() == minIndex)
|
if ((sint) place->getIndex() == minIndex)
|
||||||
{
|
{
|
||||||
candidates.push_back(k);
|
candidates.push_back(k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
spawnPlace = (sint) candidates[rand() % candidates.size()];
|
spawnPlace = (sint) candidates[rand() % candidates.size()];
|
||||||
//nlwarning("No spawn place found for group %s, using place with smallest index", getPersistent().getName().c_str());
|
//nlwarning("No spawn place found for group %s, using place with smallest index", getPersistent().getName().c_str());
|
||||||
}
|
}
|
||||||
setPlace(spawnPlace);
|
setPlace(spawnPlace);
|
||||||
_CenterPos = _TargetPlace->midPos();
|
_CenterPos = _TargetPlace->midPos();
|
||||||
|
|
||||||
// make sure memory's been allocated for the bots
|
// make sure memory's been allocated for the bots
|
||||||
if (bots().size()==0)
|
if (bots().size()==0)
|
||||||
getPersistent().allocateBots();
|
getPersistent().allocateBots();
|
||||||
|
|
||||||
if (bots().size()!=0)
|
if (bots().size()!=0)
|
||||||
{
|
{
|
||||||
uint32 const spawnTimer = getPersistent().timer(CGrpFauna::SPAWN_TIME);
|
uint32 const spawnTimer = getPersistent().timer(CGrpFauna::SPAWN_TIME);
|
||||||
_Timer.set(spawnTimer);
|
_Timer.set(spawnTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup the update priority system variables
|
// setup the update priority system variables
|
||||||
_LastUpdate = CTimeInterface::gameCycle();
|
_LastUpdate = CTimeInterface::gameCycle();
|
||||||
_DeltaTime = 1;
|
_DeltaTime = 1;
|
||||||
|
|
||||||
_CurrentCycle = 0;
|
_CurrentCycle = 0;
|
||||||
|
|
||||||
setMustDespawnBots(false);
|
setMustDespawnBots(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,14 +138,14 @@ void CSpawnGroupFauna::despawnGrp() // critical code (despawn 'this' object).
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSpawnGroupFauna::recalcUpdatePriorityDeltaAndGroupPos()
|
void CSpawnGroupFauna::recalcUpdatePriorityDeltaAndGroupPos()
|
||||||
{
|
{
|
||||||
// recalculate the priority delta score for the group based on players in vision
|
// recalculate the priority delta score for the group based on players in vision
|
||||||
bool speedUpdate = false;
|
bool speedUpdate = false;
|
||||||
|
|
||||||
sint32 grpPosx = 0;
|
sint32 grpPosx = 0;
|
||||||
sint32 grpPosy = 0;
|
sint32 grpPosy = 0;
|
||||||
sint32 nbBots = 0;
|
sint32 nbBots = 0;
|
||||||
|
|
||||||
FOREACH(it, CCont<CBot>, bots())
|
FOREACH(it, CCont<CBot>, bots())
|
||||||
{
|
{
|
||||||
CBotFauna *bot=NLMISC::safe_cast<CBotFauna*>(*it);
|
CBotFauna *bot=NLMISC::safe_cast<CBotFauna*>(*it);
|
||||||
|
@ -159,39 +159,39 @@ void CSpawnGroupFauna::recalcUpdatePriorityDeltaAndGroupPos()
|
||||||
grpPosy+=(sint32)(pos.y().asInt()*(1.0/1000.0));
|
grpPosy+=(sint32)(pos.y().asInt()*(1.0/1000.0));
|
||||||
nbBots++;
|
nbBots++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (botFauna->havePlayersAround())
|
if (botFauna->havePlayersAround())
|
||||||
{
|
{
|
||||||
speedUpdate=true;
|
speedUpdate=true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nbBots>0)
|
if (nbBots>0)
|
||||||
{
|
{
|
||||||
_CenterPos = CAIVector(grpPosx/nbBots,grpPosy/nbBots);
|
_CenterPos = CAIVector(grpPosx/nbBots,grpPosy/nbBots);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (speedUpdate)
|
if (speedUpdate)
|
||||||
_UpdatePriority = 1;
|
_UpdatePriority = 1;
|
||||||
else
|
else
|
||||||
_UpdatePriority = 31;
|
_UpdatePriority = 31;
|
||||||
|
|
||||||
// if players are approaching then crop our move time
|
// if players are approaching then crop our move time
|
||||||
uint32 curTime = CTimeInterface::gameCycle ();
|
uint32 curTime = CTimeInterface::gameCycle ();
|
||||||
if (((sint32)(curTime-_LastUpdate))>(_UpdatePriority+1))
|
if (((sint32)(curTime-_LastUpdate))>(_UpdatePriority+1))
|
||||||
_LastUpdate = curTime-(_UpdatePriority+1);
|
_LastUpdate = curTime-(_UpdatePriority+1);
|
||||||
|
|
||||||
_DeltaTime = curTime-_LastUpdate;
|
_DeltaTime = curTime-_LastUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
CBotFauna* CSpawnGroupFauna::findLeader()
|
CBotFauna* CSpawnGroupFauna::findLeader()
|
||||||
{
|
{
|
||||||
CBotFauna* possibleLeader = NULL;
|
CBotFauna* possibleLeader = NULL;
|
||||||
|
|
||||||
CCont<CBot >::iterator it = bots().begin();
|
CCont<CBot >::iterator it = bots().begin();
|
||||||
CCont<CBot >::iterator itEnd = bots().end();
|
CCont<CBot >::iterator itEnd = bots().end();
|
||||||
while (it!=itEnd)
|
while (it!=itEnd)
|
||||||
|
@ -214,21 +214,21 @@ CBotFauna* CSpawnGroupFauna::findLeader()
|
||||||
void CSpawnGroupFauna::update()
|
void CSpawnGroupFauna::update()
|
||||||
{
|
{
|
||||||
H_AUTO(GrpFaunaUpdate);
|
H_AUTO(GrpFaunaUpdate);
|
||||||
|
|
||||||
++AISStat::GrpTotalUpdCtr;
|
++AISStat::GrpTotalUpdCtr;
|
||||||
++AISStat::GrpFaunaUpdCtr;
|
++AISStat::GrpFaunaUpdCtr;
|
||||||
|
|
||||||
getPersistent().updateStateInstance();
|
getPersistent().updateStateInstance();
|
||||||
|
|
||||||
if (_CurrentCycle==std::numeric_limits<uint32>::max())
|
if (_CurrentCycle==std::numeric_limits<uint32>::max())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Respawn
|
// Respawn
|
||||||
// breakable
|
// breakable
|
||||||
{
|
{
|
||||||
H_AUTO(GrpFaunaUpdateDealWithDead);
|
H_AUTO(GrpFaunaUpdateDealWithDead);
|
||||||
checkDespawn ();
|
checkDespawn ();
|
||||||
|
|
||||||
if (nbBotToRespawn()>0)
|
if (nbBotToRespawn()>0)
|
||||||
{
|
{
|
||||||
if (nbSpawnedBot()>0) // (getPersistent().bots().size()/2))
|
if (nbSpawnedBot()>0) // (getPersistent().bots().size()/2))
|
||||||
|
@ -246,23 +246,23 @@ void CSpawnGroupFauna::update()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// recalculate our priority rating in function of distance from player
|
// recalculate our priority rating in function of distance from player
|
||||||
// if players are approaching then crop our move time
|
// if players are approaching then crop our move time
|
||||||
recalcUpdatePriorityDeltaAndGroupPos();
|
recalcUpdatePriorityDeltaAndGroupPos();
|
||||||
|
|
||||||
// identify the leader, call type-dependent update and calculate group position and radius
|
// identify the leader, call type-dependent update and calculate group position and radius
|
||||||
{
|
{
|
||||||
H_AUTO(GrpFaunaUpdateByType);
|
H_AUTO(GrpFaunaUpdateByType);
|
||||||
|
|
||||||
H_TIME(GrpFaunaUpdateFindLeader, _Leader = findLeader(););
|
H_TIME(GrpFaunaUpdateFindLeader, _Leader = findLeader(););
|
||||||
// locate the first live bot and treat them as the group leader
|
// locate the first live bot and treat them as the group leader
|
||||||
|
|
||||||
// update the state variable (think about changing state)
|
// update the state variable (think about changing state)
|
||||||
H_TIME(GrpFaunaUpdateCheckTimer, checkTimers(););
|
H_TIME(GrpFaunaUpdateCheckTimer, checkTimers(););
|
||||||
|
|
||||||
H_TIME(GrpFaunaUpdateGeneralUpdate, generalUpdate(););
|
H_TIME(GrpFaunaUpdateGeneralUpdate, generalUpdate(););
|
||||||
|
|
||||||
// re-find leader as it could have been despawn ..
|
// re-find leader as it could have been despawn ..
|
||||||
_Leader = findLeader();
|
_Leader = findLeader();
|
||||||
}
|
}
|
||||||
|
@ -273,10 +273,10 @@ void CSpawnGroupFauna::update()
|
||||||
void CSpawnGroupFauna::generalUpdate(TState state)
|
void CSpawnGroupFauna::generalUpdate(TState state)
|
||||||
{
|
{
|
||||||
H_TIME(GrpFaunaReorganize, reorganize(bots().begin(), bots().end()););
|
H_TIME(GrpFaunaReorganize, reorganize(bots().begin(), bots().end()););
|
||||||
|
|
||||||
{
|
{
|
||||||
H_AUTO(GrpFaunaUpdDespawnTest);
|
H_AUTO(GrpFaunaUpdDespawnTest);
|
||||||
|
|
||||||
if ( !mustDespawnBots()
|
if ( !mustDespawnBots()
|
||||||
&& getUpdatePriority ()>(2<<3)
|
&& getUpdatePriority ()>(2<<3)
|
||||||
&& !getPersistent().timeAllowSpawn() ) // 40*3 -> more than 120 meters far from players
|
&& !getPersistent().timeAllowSpawn() ) // 40*3 -> more than 120 meters far from players
|
||||||
|
@ -284,10 +284,10 @@ void CSpawnGroupFauna::generalUpdate(TState state)
|
||||||
setMustDespawnBots (true);
|
setMustDespawnBots (true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state==StateUndefined)
|
if (state==StateUndefined)
|
||||||
state=CGrpFauna::cycles[_CurrentCycle]._Activity;
|
state=CGrpFauna::cycles[_CurrentCycle]._Activity;
|
||||||
|
|
||||||
// call a type-dependent update
|
// call a type-dependent update
|
||||||
switch (getPersistent().getType())
|
switch (getPersistent().getType())
|
||||||
{
|
{
|
||||||
|
@ -306,7 +306,7 @@ void CSpawnGroupFauna::generalUpdate(TState state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FaunaTypePlant:
|
case FaunaTypePlant:
|
||||||
{
|
{
|
||||||
H_AUTO(GrpFaunaUpdPlant);
|
H_AUTO(GrpFaunaUpdPlant);
|
||||||
|
@ -322,7 +322,7 @@ void CSpawnGroupFauna::generalUpdate(TState state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: nlwarning("CSpawnGroupFauna::update() FAILED because group type not valid: %d",getPersistent().getType());
|
default: nlwarning("CSpawnGroupFauna::update() FAILED because group type not valid: %d",getPersistent().getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -351,7 +351,7 @@ void CSpawnGroupFauna::updateSpawning()
|
||||||
|
|
||||||
for (i=0;i<curPop.size();++i)
|
for (i=0;i<curPop.size();++i)
|
||||||
targetCount+=curPop[i].getBotCount(getPersistent().getCountMultiplierFlag());
|
targetCount+=curPop[i].getBotCount(getPersistent().getCountMultiplierFlag());
|
||||||
|
|
||||||
// if no more bots to spawn then change state...
|
// if no more bots to spawn then change state...
|
||||||
if (bots()[targetCount-1]->isSpawned())
|
if (bots()[targetCount-1]->isSpawned())
|
||||||
{
|
{
|
||||||
|
@ -378,8 +378,8 @@ void CSpawnGroupFauna::updateSpawning()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// by definition there must be a bot type
|
// by definition there must be a bot type
|
||||||
nlassert(i<curPop.size());
|
nlassert(i<curPop.size());
|
||||||
|
|
||||||
|
@ -409,7 +409,7 @@ void CSpawnGroupFauna::incCurrentCycle()
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSpawnGroupFauna::setCurrentCycle(uint32 cycle)
|
void CSpawnGroupFauna::setCurrentCycle(uint32 cycle)
|
||||||
{
|
{
|
||||||
if (getPersistent().places().isEmpty())
|
if (getPersistent().places().isEmpty())
|
||||||
{
|
{
|
||||||
nlwarning("No places in fauna group %s", getPersistent().getName().c_str());
|
nlwarning("No places in fauna group %s", getPersistent().getName().c_str());
|
||||||
|
@ -426,11 +426,11 @@ void CSpawnGroupFauna::setCurrentCycle(uint32 cycle)
|
||||||
// First we search a neighbour place that has wanted activity
|
// First we search a neighbour place that has wanted activity
|
||||||
// otherwise we change activity to the one we found
|
// otherwise we change activity to the one we found
|
||||||
switch(CGrpFauna::cycles[cycle]._Place)
|
switch(CGrpFauna::cycles[cycle]._Place)
|
||||||
{
|
{
|
||||||
case CGrpFauna::EAT_PLACE:
|
case CGrpFauna::EAT_PLACE:
|
||||||
nextPlace = getPersistent().getNextPlace(targetPlacePtr, CAIPlaceXYRFauna::FLAG_EAT);
|
nextPlace = getPersistent().getNextPlace(targetPlacePtr, CAIPlaceXYRFauna::FLAG_EAT);
|
||||||
if (nextPlace == CGrpFauna::INVALID_PLACE)
|
if (nextPlace == CGrpFauna::INVALID_PLACE)
|
||||||
{
|
{
|
||||||
nextPlace = getPersistent().getNextPlace(targetPlacePtr, CAIPlaceXYRFauna::FLAG_REST);
|
nextPlace = getPersistent().getNextPlace(targetPlacePtr, CAIPlaceXYRFauna::FLAG_REST);
|
||||||
if (nextPlace != CGrpFauna::INVALID_PLACE)
|
if (nextPlace != CGrpFauna::INVALID_PLACE)
|
||||||
{
|
{
|
||||||
|
@ -446,10 +446,10 @@ void CSpawnGroupFauna::setCurrentCycle(uint32 cycle)
|
||||||
cycle = CGrpFauna::REST_PLACE; // force to rest
|
cycle = CGrpFauna::REST_PLACE; // force to rest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CGrpFauna::REST_PLACE:
|
case CGrpFauna::REST_PLACE:
|
||||||
nextPlace = getPersistent().getNextPlace(targetPlacePtr, CAIPlaceXYRFauna::FLAG_REST);
|
nextPlace = getPersistent().getNextPlace(targetPlacePtr, CAIPlaceXYRFauna::FLAG_REST);
|
||||||
if (nextPlace == CGrpFauna::INVALID_PLACE)
|
if (nextPlace == CGrpFauna::INVALID_PLACE)
|
||||||
{
|
{
|
||||||
nextPlace = getPersistent().getNextPlace(targetPlacePtr, CAIPlaceXYRFauna::FLAG_EAT);
|
nextPlace = getPersistent().getNextPlace(targetPlacePtr, CAIPlaceXYRFauna::FLAG_EAT);
|
||||||
|
@ -467,9 +467,9 @@ void CSpawnGroupFauna::setCurrentCycle(uint32 cycle)
|
||||||
cycle = CGrpFauna::EAT_PLACE; // force to rest
|
cycle = CGrpFauna::EAT_PLACE; // force to rest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_CurrentCycle = cycle;
|
_CurrentCycle = cycle;
|
||||||
setPlace(nextPlace);
|
setPlace(nextPlace);
|
||||||
|
|
||||||
|
@ -501,25 +501,25 @@ void CSpawnGroupFauna::checkTimers()
|
||||||
{
|
{
|
||||||
if (CGrpFauna::cycles[_CurrentCycle]._Activity==StateSpawning)
|
if (CGrpFauna::cycles[_CurrentCycle]._Activity==StateSpawning)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!_ArrivedInZone) // if we are changing the current activity zone.
|
if (!_ArrivedInZone) // if we are changing the current activity zone.
|
||||||
{
|
{
|
||||||
if ( !_Leader.isNULL()
|
if ( !_Leader.isNULL()
|
||||||
&& _Leader->isSpawned())
|
&& _Leader->isSpawned())
|
||||||
{
|
{
|
||||||
const CAIPos leaderPos(_Leader->getSpawn()->pos());
|
const CAIPos leaderPos(_Leader->getSpawn()->pos());
|
||||||
const CAIPos midPos=_TargetPlace->midPos(); // better is very possible.
|
const CAIPos midPos=_TargetPlace->midPos(); // better is very possible.
|
||||||
|
|
||||||
if (leaderPos.distTo(midPos)<_TargetPlace->getRadius()) // si leader dans la zone.
|
if (leaderPos.distTo(midPos)<_TargetPlace->getRadius()) // si leader dans la zone.
|
||||||
{
|
{
|
||||||
_ArrivedInZone=true; // we desactivate the boolean.
|
_ArrivedInZone=true; // we desactivate the boolean.
|
||||||
const CFaunaGenericPlace *faunaPlace = getFaunaGenericPlace(targetPlace());
|
const CFaunaGenericPlace *faunaPlace = getFaunaGenericPlace(targetPlace());
|
||||||
NLMISC::CRandom rnd;
|
NLMISC::CRandom rnd;
|
||||||
uint32 stayTime = faunaPlace->getMinStayTime() + (sint32) (rnd.frand() * ((sint32) faunaPlace->getMaxStayTime() - (sint32) faunaPlace->getMinStayTime()));
|
uint32 stayTime = faunaPlace->getMinStayTime() + (sint32) (rnd.frand() * ((sint32) faunaPlace->getMaxStayTime() - (sint32) faunaPlace->getMinStayTime()));
|
||||||
_Timer.set(stayTime);
|
_Timer.set(stayTime);
|
||||||
/*
|
/*
|
||||||
nlwarning("Group %s : Setting stay time to %d in place %s with index %d",
|
nlwarning("Group %s : Setting stay time to %d in place %s with index %d",
|
||||||
getPersistent().getName().c_str(),
|
getPersistent().getName().c_str(),
|
||||||
(int) stayTime,
|
(int) stayTime,
|
||||||
faunaPlace->getName().c_str(),
|
faunaPlace->getName().c_str(),
|
||||||
(int) faunaPlace->getIndex());
|
(int) faunaPlace->getIndex());
|
||||||
|
@ -528,7 +528,7 @@ void CSpawnGroupFauna::checkTimers()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -553,17 +553,17 @@ void CSpawnGroupFauna::despawnBots(bool immediately)
|
||||||
}
|
}
|
||||||
|
|
||||||
CAIPos const& CSpawnGroupFauna::magnetPos() const
|
CAIPos const& CSpawnGroupFauna::magnetPos() const
|
||||||
{
|
{
|
||||||
return targetPlace()->midPos();
|
return targetPlace()->midPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
float CSpawnGroupFauna::magnetRadiusNear() const
|
float CSpawnGroupFauna::magnetRadiusNear() const
|
||||||
{
|
{
|
||||||
return targetPlace()->getRadius()*(7.0f/8.0f);
|
return targetPlace()->getRadius()*(7.0f/8.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float CSpawnGroupFauna::magnetRadiusFar() const
|
float CSpawnGroupFauna::magnetRadiusFar() const
|
||||||
{
|
{
|
||||||
return targetPlace()->getRadius()*(9.0f/8.0f);
|
return targetPlace()->getRadius()*(9.0f/8.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -603,19 +603,19 @@ CGrpFauna::CGrpFauna(CMgrFauna* mgr, CAIAliasDescriptionNode* aliasTree, RYAI_MA
|
||||||
, CDynGrpBase()
|
, CDynGrpBase()
|
||||||
, CPersistentStateInstance(*mgr->getStateMachine())
|
, CPersistentStateInstance(*mgr->getStateMachine())
|
||||||
{
|
{
|
||||||
|
|
||||||
// state
|
// state
|
||||||
|
|
||||||
_CurPopulation = std::numeric_limits<uint32>::max();
|
_CurPopulation = std::numeric_limits<uint32>::max();
|
||||||
|
|
||||||
_CurrentCycle = std::numeric_limits<sint32>::max();
|
_CurrentCycle = std::numeric_limits<sint32>::max();
|
||||||
|
|
||||||
// default values.
|
// default values.
|
||||||
setTimer(EAT_TIME, refTimer(EAT_TIME));
|
setTimer(EAT_TIME, refTimer(EAT_TIME));
|
||||||
setTimer(REST_TIME, refTimer(REST_TIME));
|
setTimer(REST_TIME, refTimer(REST_TIME));
|
||||||
setTimer(SPAWN_TIME, refTimer(SPAWN_TIME));
|
setTimer(SPAWN_TIME, refTimer(SPAWN_TIME));
|
||||||
setTimer(CORPSE_TIME, refTimer(CORPSE_TIME));
|
setTimer(CORPSE_TIME, refTimer(CORPSE_TIME));
|
||||||
setTimer(RESPAWN_TIME, refTimer(RESPAWN_TIME));
|
setTimer(RESPAWN_TIME, refTimer(RESPAWN_TIME));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGrpFauna::stateChange(CAIState const* oldState, CAIState const* newState)
|
void CGrpFauna::stateChange(CAIState const* oldState, CAIState const* newState)
|
||||||
|
@ -630,8 +630,8 @@ std::string CGrpFauna::getOneLineInfoString() const
|
||||||
std::vector<std::string> CGrpFauna::getMultiLineInfoString() const
|
std::vector<std::string> CGrpFauna::getMultiLineInfoString() const
|
||||||
{
|
{
|
||||||
std::vector<std::string> container;
|
std::vector<std::string> container;
|
||||||
|
|
||||||
|
|
||||||
pushTitle(container, "CGrpFauna");
|
pushTitle(container, "CGrpFauna");
|
||||||
pushEntry(container, "id=" + CGroup::getIndexString());
|
pushEntry(container, "id=" + CGroup::getIndexString());
|
||||||
container.back() += " alias=" + getAliasString();
|
container.back() += " alias=" + getAliasString();
|
||||||
|
@ -642,7 +642,7 @@ std::vector<std::string> CGrpFauna::getMultiLineInfoString() const
|
||||||
CPopulation const* pop = *it;
|
CPopulation const* pop = *it;
|
||||||
uint32 index = pop->getChildIndex();
|
uint32 index = pop->getChildIndex();
|
||||||
pushEntry(container, "- population["+toString(index)+"]: "+((_CurPopulation==index)? "* ACTIVE *": ""));
|
pushEntry(container, "- population["+toString(index)+"]: "+((_CurPopulation==index)? "* ACTIVE *": ""));
|
||||||
|
|
||||||
for (uint j=0; j<pop->size(); ++j)
|
for (uint j=0; j<pop->size(); ++j)
|
||||||
{
|
{
|
||||||
CPopulationRecord& popRecord = (*pop)[j];
|
CPopulationRecord& popRecord = (*pop)[j];
|
||||||
|
@ -661,8 +661,8 @@ std::vector<std::string> CGrpFauna::getMultiLineInfoString() const
|
||||||
container.push_back(" " + *itString);
|
container.push_back(" " + *itString);
|
||||||
}
|
}
|
||||||
pushFooter(container);
|
pushFooter(container);
|
||||||
|
|
||||||
|
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -684,26 +684,26 @@ CAliasTreeOwner* CGrpFauna::createChild(IAliasCont* cont, CAIAliasDescriptionNod
|
||||||
{
|
{
|
||||||
if (!cont)
|
if (!cont)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
CAliasTreeOwner* child = NULL;
|
CAliasTreeOwner* child = NULL;
|
||||||
|
|
||||||
switch (aliasTree->getType())
|
switch (aliasTree->getType())
|
||||||
{
|
{
|
||||||
// create the child and adds it to the corresponding position.
|
// create the child and adds it to the corresponding position.
|
||||||
case AITypePlaceFauna:
|
case AITypePlaceFauna:
|
||||||
child = new CAIPlaceXYRFauna(this, aliasTree);
|
child = new CAIPlaceXYRFauna(this, aliasTree);
|
||||||
break;
|
break;
|
||||||
case AITypePlace:
|
case AITypePlace:
|
||||||
{
|
{
|
||||||
std::string const& name = aliasTree->getName();
|
std::string const& name = aliasTree->getName();
|
||||||
CAIPlaceXYRFauna *faunaPlace = new CAIPlaceXYRFauna(this, aliasTree);
|
CAIPlaceXYRFauna *faunaPlace = new CAIPlaceXYRFauna(this, aliasTree);
|
||||||
child = faunaPlace;
|
child = faunaPlace;
|
||||||
uint placeIndex = faunaPlace->setupFromOldName(name);
|
uint placeIndex = faunaPlace->setupFromOldName(name);
|
||||||
nlassert(placeIndex!=std::numeric_limits<uint>::max());
|
nlassert(placeIndex!=std::numeric_limits<uint>::max());
|
||||||
|
|
||||||
if (placeIndex!=std::numeric_limits<uint>::max())
|
if (placeIndex!=std::numeric_limits<uint>::max())
|
||||||
cont->addAliasChild(child, placeIndex);
|
cont->addAliasChild(child, placeIndex);
|
||||||
|
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -711,7 +711,7 @@ CAliasTreeOwner* CGrpFauna::createChild(IAliasCont* cont, CAIAliasDescriptionNod
|
||||||
child = new CPopulation(this, aliasTree);
|
child = new CPopulation(this, aliasTree);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (child)
|
if (child)
|
||||||
cont->addAliasChild(child);
|
cont->addAliasChild(child);
|
||||||
return child;
|
return child;
|
||||||
|
@ -726,13 +726,13 @@ void CGrpFauna::displayPlaces(CStringWriter& stringWriter) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CGrpFauna::~CGrpFauna()
|
CGrpFauna::~CGrpFauna()
|
||||||
{
|
{
|
||||||
if (isSpawned()) // to avoid bad CDbgPtr link interpretation
|
if (isSpawned()) // to avoid bad CDbgPtr link interpretation
|
||||||
{
|
{
|
||||||
despawnGrp();
|
despawnGrp();
|
||||||
}
|
}
|
||||||
|
|
||||||
// unlink all child persistent state instance
|
// unlink all child persistent state instance
|
||||||
while (!_PSIChilds.empty())
|
while (!_PSIChilds.empty())
|
||||||
{
|
{
|
||||||
|
@ -750,12 +750,12 @@ void CGrpFauna::setEvent(uint eventId)
|
||||||
void CGrpFauna::serviceEvent (const CServiceEvent &info)
|
void CGrpFauna::serviceEvent (const CServiceEvent &info)
|
||||||
{
|
{
|
||||||
CGroup::serviceEvent(info);
|
CGroup::serviceEvent(info);
|
||||||
|
|
||||||
if ((info.getServiceName() == "EGS") && (info.getEventType() == CServiceEvent::SERVICE_UP))
|
if ((info.getServiceName() == "EGS") && (info.getEventType() == CServiceEvent::SERVICE_UP))
|
||||||
{
|
{
|
||||||
processStateEvent(getEventContainer().EventEGSUp);
|
processStateEvent(getEventContainer().EventEGSUp);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NLMISC::CSmartPtr<CSpawnGroup> CGrpFauna::createSpawnGroup()
|
NLMISC::CSmartPtr<CSpawnGroup> CGrpFauna::createSpawnGroup()
|
||||||
|
@ -767,7 +767,7 @@ bool CGrpFauna::spawn()
|
||||||
{
|
{
|
||||||
if (!getSpawnCounter().remainToMax())
|
if (!getSpawnCounter().remainToMax())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
setStartState(getStartState()); // stateInstance.
|
setStartState(getStartState()); // stateInstance.
|
||||||
return spawnPop(std::numeric_limits<uint>::max());
|
return spawnPop(std::numeric_limits<uint>::max());
|
||||||
}
|
}
|
||||||
|
@ -778,7 +778,7 @@ bool CGrpFauna::timeAllowSpawn(uint32 popVersion) const
|
||||||
{
|
{
|
||||||
popVersion = _CurPopulation;
|
popVersion = _CurPopulation;
|
||||||
}
|
}
|
||||||
|
|
||||||
CPopulation* popPtr = _Populations[popVersion];
|
CPopulation* popPtr = _Populations[popVersion];
|
||||||
#ifdef NL_DEBUG
|
#ifdef NL_DEBUG
|
||||||
nlassert(popPtr);
|
nlassert(popPtr);
|
||||||
|
@ -788,7 +788,7 @@ bool CGrpFauna::timeAllowSpawn(uint32 popVersion) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
TSpawnType st = popPtr->getSpawnType();
|
TSpawnType st = popPtr->getSpawnType();
|
||||||
|
|
||||||
bool const& isDay = CTimeInterface::isDay();
|
bool const& isDay = CTimeInterface::isDay();
|
||||||
|
|
||||||
return (st==SpawnTypeAlways) || (isDay&&st==SpawnTypeDay) || (!isDay&&st==SpawnTypeNight);
|
return (st==SpawnTypeAlways) || (isDay&&st==SpawnTypeDay) || (!isDay&&st==SpawnTypeNight);
|
||||||
|
@ -806,7 +806,7 @@ bool CGrpFauna::spawnPop(uint popVersion)
|
||||||
|| !places()[EAT_PLACE]->worldValidPos().isValid()
|
|| !places()[EAT_PLACE]->worldValidPos().isValid()
|
||||||
|| !places()[REST_PLACE]->worldValidPos().isValid()) // coz time is not initialized yet ..
|
|| !places()[REST_PLACE]->worldValidPos().isValid()) // coz time is not initialized yet ..
|
||||||
return false;*/
|
return false;*/
|
||||||
|
|
||||||
// check compatibility.
|
// check compatibility.
|
||||||
/*
|
/*
|
||||||
{
|
{
|
||||||
|
@ -829,7 +829,7 @@ bool CGrpFauna::spawnPop(uint popVersion)
|
||||||
checkArcs(*_Places[k]);
|
checkArcs(*_Places[k]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// check flags ..
|
// check flags ..
|
||||||
for (uint32 i=0;i<places().size();i++)
|
for (uint32 i=0;i<places().size();i++)
|
||||||
{
|
{
|
||||||
|
@ -839,7 +839,7 @@ bool CGrpFauna::spawnPop(uint popVersion)
|
||||||
if ((flags&getAStarFlag())!=0)
|
if ((flags&getAStarFlag())!=0)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the validity of the input parameter
|
// check the validity of the input parameter
|
||||||
if (popVersion!=std::numeric_limits<uint>::max() && popVersion>=_Populations.size())
|
if (popVersion!=std::numeric_limits<uint>::max() && popVersion>=_Populations.size())
|
||||||
{
|
{
|
||||||
|
@ -853,17 +853,19 @@ bool CGrpFauna::spawnPop(uint popVersion)
|
||||||
if (_CurrentCycle!=~0)
|
if (_CurrentCycle!=~0)
|
||||||
{
|
{
|
||||||
Cycle const& cycle = _Cycles[_CurrentCycle];
|
Cycle const& cycle = _Cycles[_CurrentCycle];
|
||||||
|
|
||||||
// this to avoid bug dues to bad data initialization.
|
// this to avoid bug dues to bad data initialization.
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
++_CurrentCycleIndex;
|
++_CurrentCycleIndex;
|
||||||
} while ( _CurrentCycleIndex<(sint32)cycle._PopList.size()
|
}
|
||||||
|
while ( _CurrentCycleIndex<(sint32)cycle._PopList.size()
|
||||||
&& !_Populations[cycle._PopList[_CurrentCycleIndex]]);
|
&& !_Populations[cycle._PopList[_CurrentCycleIndex]]);
|
||||||
|
|
||||||
if (_CurrentCycleIndex<(sint32)cycle._PopList.size())
|
if (_CurrentCycleIndex<(sint32)cycle._PopList.size())
|
||||||
{
|
{
|
||||||
popVersion=cycle._PopList[_CurrentCycleIndex];
|
popVersion=cycle._PopList[_CurrentCycleIndex];
|
||||||
|
|
||||||
if (!timeAllowSpawn(popVersion))
|
if (!timeAllowSpawn(popVersion))
|
||||||
{
|
{
|
||||||
popVersion=~0;
|
popVersion=~0;
|
||||||
|
@ -875,12 +877,12 @@ bool CGrpFauna::spawnPop(uint popVersion)
|
||||||
_CurrentCycle = ~0;
|
_CurrentCycle = ~0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the population version has not been specified then select one at weighted random with day/night difference.
|
// if the population version has not been specified then select one at weighted random with day/night difference.
|
||||||
if (popVersion==~0)
|
if (popVersion==~0)
|
||||||
{
|
{
|
||||||
uint32 totalWeight = 0;
|
uint32 totalWeight = 0;
|
||||||
|
|
||||||
// we can precalculate this, but it won't appears so much to be called.
|
// we can precalculate this, but it won't appears so much to be called.
|
||||||
FOREACH(it, CCont<CPopulation>, _Populations)
|
FOREACH(it, CCont<CPopulation>, _Populations)
|
||||||
{
|
{
|
||||||
|
@ -889,10 +891,10 @@ bool CGrpFauna::spawnPop(uint popVersion)
|
||||||
continue;
|
continue;
|
||||||
totalWeight += pop.getWeight();
|
totalWeight += pop.getWeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (totalWeight==0)
|
if (totalWeight==0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
{
|
{
|
||||||
sint32 rnd = CAIS::rand32(totalWeight);
|
sint32 rnd = CAIS::rand32(totalWeight);
|
||||||
FOREACH(it, CCont<CPopulation>, _Populations)
|
FOREACH(it, CCont<CPopulation>, _Populations)
|
||||||
|
@ -900,50 +902,50 @@ bool CGrpFauna::spawnPop(uint popVersion)
|
||||||
CPopulation const& pop = *(*it);
|
CPopulation const& pop = *(*it);
|
||||||
if (!timeAllowSpawn(pop.getChildIndex()))
|
if (!timeAllowSpawn(pop.getChildIndex()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
rnd -= pop.getWeight();
|
rnd -= pop.getWeight();
|
||||||
if (rnd>0) // we found the population to spawn. :)
|
if (rnd>0) // we found the population to spawn. :)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
popVersion=pop.getChildIndex();
|
popVersion=pop.getChildIndex();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !FINAL_VERSION
|
#if !FINAL_VERSION
|
||||||
nlassert(popVersion!=~0);
|
nlassert(popVersion!=~0);
|
||||||
#endif
|
#endif
|
||||||
if (popVersion==~0)
|
if (popVersion==~0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// find if we are starting a new cycle ..
|
// find if we are starting a new cycle ..
|
||||||
for (uint32 i=0;i<_Cycles.size();i++)
|
for (uint32 i=0;i<_Cycles.size();i++)
|
||||||
{
|
{
|
||||||
nlassert(_Cycles[i]._PopList.size()>0);
|
nlassert(_Cycles[i]._PopList.size()>0);
|
||||||
if (_Cycles[i]._PopList[0]!=popVersion)
|
if (_Cycles[i]._PopList[0]!=popVersion)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
_CurrentCycle = i;
|
_CurrentCycle = i;
|
||||||
_CurrentCycleIndex = 0;
|
_CurrentCycleIndex = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (popVersion >= _Populations.size())
|
if (popVersion >= _Populations.size())
|
||||||
{
|
{
|
||||||
nlwarning("Problem with pop size for group id %s, NAME = %s", this->CGroup::getFullName().c_str(), getName().c_str() );
|
nlwarning("Problem with pop size for group id %s, NAME = %s", this->CGroup::getFullName().c_str(), getName().c_str() );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup the pointer to the current population
|
// setup the pointer to the current population
|
||||||
_CurPopulation = popVersion;
|
_CurPopulation = popVersion;
|
||||||
|
|
||||||
// check that we have a defined spawn location
|
// check that we have a defined spawn location
|
||||||
if (!_Places[SPAWN_PLACE])
|
if (!_Places[SPAWN_PLACE])
|
||||||
{
|
{
|
||||||
nlwarning("CGrpFauna::spawn(idx) FAILED for group %s because _spawnPlace==NULL",this->CGroup::getFullName().c_str());
|
nlwarning("CGrpFauna::spawn(idx) FAILED for group %s because _spawnPlace==NULL",this->CGroup::getFullName().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the group is already spawned despawn it
|
// if the group is already spawned despawn it
|
||||||
if (isSpawned())
|
if (isSpawned())
|
||||||
{
|
{
|
||||||
|
@ -953,9 +955,9 @@ bool CGrpFauna::spawnPop(uint popVersion)
|
||||||
nlassert(_CurPopulation!=~0);
|
nlassert(_CurPopulation!=~0);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// Init the group type.
|
// Init the group type.
|
||||||
setType ((*_Populations[_CurPopulation])[0].getCreatureSheet()->FaunaType()); // gets the first population record of the population to spawn.
|
setType ((*_Populations[_CurPopulation])[0].getCreatureSheet()->FaunaType()); // gets the first population record of the population to spawn.
|
||||||
|
|
||||||
{
|
{
|
||||||
uint32 botCount=0;
|
uint32 botCount=0;
|
||||||
uint32 i;
|
uint32 i;
|
||||||
|
@ -966,7 +968,7 @@ bool CGrpFauna::spawnPop(uint popVersion)
|
||||||
if ( curPop[i].getBotCount(getCountMultiplierFlag()) == 0
|
if ( curPop[i].getBotCount(getCountMultiplierFlag()) == 0
|
||||||
|| curPop[i].getCreatureSheet()->FaunaType() == getType())
|
|| curPop[i].getCreatureSheet()->FaunaType() == getType())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (getGroupDesc()) // Dyn system.
|
if (getGroupDesc()) // Dyn system.
|
||||||
{
|
{
|
||||||
nlwarning("****** WARNING: Different Fauna Type in Template Group %s", getGroupDesc()->getFullName().c_str());
|
nlwarning("****** WARNING: Different Fauna Type in Template Group %s", getGroupDesc()->getFullName().c_str());
|
||||||
|
@ -977,11 +979,11 @@ bool CGrpFauna::spawnPop(uint popVersion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bots().setChildSize(botCount); // set the good size for bots vector.
|
bots().setChildSize(botCount); // set the good size for bots vector.
|
||||||
|
|
||||||
for (i=0;i<botCount;i++)
|
for (i=0;i<botCount;i++)
|
||||||
_Bots.addChild(new CBotFauna(getType(), this), i);
|
_Bots.addChild(new CBotFauna(getType(), this), i);
|
||||||
}
|
}
|
||||||
|
|
||||||
return CGroup::spawn();
|
return CGroup::spawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1000,10 +1002,10 @@ void CGrpFauna::setCyles(std::string const& cycles)
|
||||||
while (strIndex<cycles.size())
|
while (strIndex<cycles.size())
|
||||||
{
|
{
|
||||||
char carac = cycles[++strIndex];
|
char carac = cycles[++strIndex];
|
||||||
|
|
||||||
if (carac>='A' && carac<='Z')
|
if (carac>='A' && carac<='Z')
|
||||||
carac += 'a'-'A';
|
carac += 'a'-'A';
|
||||||
|
|
||||||
if (carac>='a' && carac<='z')
|
if (carac>='a' && carac<='z')
|
||||||
{
|
{
|
||||||
if (curCycle==~0)
|
if (curCycle==~0)
|
||||||
|
@ -1021,17 +1023,17 @@ void CGrpFauna::setCyles(std::string const& cycles)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGrpFauna::setPopulation(CPopulation* pop)
|
void CGrpFauna::setPopulation(CPopulation* pop)
|
||||||
{
|
{
|
||||||
CPopulation* sameAliasPop = NULL;
|
CPopulation* sameAliasPop = NULL;
|
||||||
uint32 index = ~0;
|
uint32 index = ~0;
|
||||||
|
|
||||||
if (pop)
|
if (pop)
|
||||||
sameAliasPop = _Populations.getChildByAlias(pop->getAlias());
|
sameAliasPop = _Populations.getChildByAlias(pop->getAlias());
|
||||||
|
|
||||||
if (pop && pop->size()==0) // no population record :(
|
if (pop && pop->size()==0) // no population record :(
|
||||||
pop=NULL;
|
pop=NULL;
|
||||||
|
|
||||||
if (sameAliasPop) // Alias already present ?
|
if (sameAliasPop) // Alias already present ?
|
||||||
{
|
{
|
||||||
index = sameAliasPop->getChildIndex();
|
index = sameAliasPop->getChildIndex();
|
||||||
|
@ -1041,7 +1043,7 @@ void CGrpFauna::setPopulation(CPopulation* pop)
|
||||||
{
|
{
|
||||||
_Populations.addChild(pop); // else simply add it to the populations container
|
_Populations.addChild(pop); // else simply add it to the populations container
|
||||||
}
|
}
|
||||||
|
|
||||||
// if it was the current population, respawn it. (to check with designers?)
|
// if it was the current population, respawn it. (to check with designers?)
|
||||||
if (index==_CurPopulation)
|
if (index==_CurPopulation)
|
||||||
{
|
{
|
||||||
|
@ -1057,24 +1059,24 @@ void CGrpFauna::setPopulation(CPopulation* pop)
|
||||||
void CGrpFauna::allocateBots()
|
void CGrpFauna::allocateBots()
|
||||||
{
|
{
|
||||||
uint maxPopulation = 0;
|
uint maxPopulation = 0;
|
||||||
|
|
||||||
// work out how much space we need
|
// work out how much space we need
|
||||||
CCont<CPopulation>::iterator it = populations().begin();
|
CCont<CPopulation>::iterator it = populations().begin();
|
||||||
CCont<CPopulation>::iterator itEnd = populations().end();
|
CCont<CPopulation>::iterator itEnd = populations().end();
|
||||||
|
|
||||||
while (it!=itEnd)
|
while (it!=itEnd)
|
||||||
{
|
{
|
||||||
CPopulation* pop = *(it);
|
CPopulation* pop = *(it);
|
||||||
uint count=0;
|
uint count=0;
|
||||||
|
|
||||||
for (sint j=(sint)pop->size()-1;j>=0;j--)
|
for (sint j=(sint)pop->size()-1;j>=0;j--)
|
||||||
count+=(*pop)[j].getBotCount(getCountMultiplierFlag());
|
count+=(*pop)[j].getBotCount(getCountMultiplierFlag());
|
||||||
|
|
||||||
if (count>maxPopulation)
|
if (count>maxPopulation)
|
||||||
maxPopulation=count;
|
maxPopulation=count;
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
_Bots.setChildSize(maxPopulation);
|
_Bots.setChildSize(maxPopulation);
|
||||||
for (uint32 i=0;i<maxPopulation;i++)
|
for (uint32 i=0;i<maxPopulation;i++)
|
||||||
_Bots.addChild(new CBotFauna(getType(),this),i);
|
_Bots.addChild(new CBotFauna(getType(),this),i);
|
||||||
|
@ -1085,13 +1087,13 @@ void CGrpFauna::setType(TFaunaType type)
|
||||||
{
|
{
|
||||||
faction().removeProperties();
|
faction().removeProperties();
|
||||||
if (type==AITYPES::FaunaTypePredator)
|
if (type==AITYPES::FaunaTypePredator)
|
||||||
faction().addProperty(AITYPES::CPropertyId("Predator"));
|
faction().addProperty(AITYPES::CPropertyId("Predator"));
|
||||||
_Type = type;
|
_Type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
CMgrFauna& CGrpFauna::mgr() const
|
CMgrFauna& CGrpFauna::mgr() const
|
||||||
{
|
{
|
||||||
return *static_cast<CMgrFauna*>(getOwner());
|
return *static_cast<CMgrFauna*>(getOwner());
|
||||||
}
|
}
|
||||||
|
|
||||||
CAIS::CCounter& CGrpFauna::getSpawnCounter()
|
CAIS::CCounter& CGrpFauna::getSpawnCounter()
|
||||||
|
@ -1134,13 +1136,13 @@ sint CGrpFauna::getNextPlace(const CFaunaGenericPlace *startPlace, CAIPlaceXYRFa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sint minIndex = INT_MAX;
|
sint minIndex = INT_MAX;
|
||||||
sint firstIndex = INT_MAX;
|
sint firstIndex = INT_MAX;
|
||||||
if (startPlace->getReachNext())
|
if (startPlace->getReachNext())
|
||||||
{
|
{
|
||||||
for (uint k = 0; k < _Places.size(); ++k)
|
for (uint k = 0; k < _Places.size(); ++k)
|
||||||
{
|
{
|
||||||
const CFaunaGenericPlace *place = getFaunaGenericPlace(_Places[k]);
|
const CFaunaGenericPlace *place = getFaunaGenericPlace(_Places[k]);
|
||||||
firstIndex = std::min(firstIndex, (sint) place->getIndex());
|
firstIndex = std::min(firstIndex, (sint) place->getIndex());
|
||||||
if (place->getIndex() < minIndex && place->getIndex() > startPlace->getIndex())
|
if (place->getIndex() < minIndex && place->getIndex() > startPlace->getIndex())
|
||||||
|
@ -1165,9 +1167,9 @@ sint CGrpFauna::getNextPlace(const CFaunaGenericPlace *startPlace, CAIPlaceXYRFa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// includes all places reachable from the arcs list
|
// includes all places reachable from the arcs list
|
||||||
for (uint k = 0; k < _Places.size(); ++k)
|
for (uint k = 0; k < _Places.size(); ++k)
|
||||||
{
|
{
|
||||||
const CFaunaGenericPlace *place = getFaunaGenericPlace(_Places[k]);
|
const CFaunaGenericPlace *place = getFaunaGenericPlace(_Places[k]);
|
||||||
if (place != startPlace && place->getFlag(wantedFlag))
|
if (place != startPlace && place->getFlag(wantedFlag))
|
||||||
{
|
{
|
||||||
|
@ -1192,7 +1194,7 @@ sint CGrpFauna::getNextPlace(const CFaunaGenericPlace *startPlace, CAIPlaceXYRFa
|
||||||
if (!activeCandidates.empty())
|
if (!activeCandidates.empty())
|
||||||
{
|
{
|
||||||
return (sint) activeCandidates[rand() % activeCandidates.size()];
|
return (sint) activeCandidates[rand() % activeCandidates.size()];
|
||||||
}
|
}
|
||||||
// if current place is valid then don't move
|
// if current place is valid then don't move
|
||||||
if (startPlace && startPlace->getActive()) return CAIPlaceXYRFauna::INVALID_PLACE;
|
if (startPlace && startPlace->getActive()) return CAIPlaceXYRFauna::INVALID_PLACE;
|
||||||
// otherwise select a place in unactive places
|
// otherwise select a place in unactive places
|
||||||
|
@ -1210,7 +1212,7 @@ bool CGrpFauna::checkArcs(const CAIPlace &startPlace) const
|
||||||
if (startPlaceGeneric->getReachNext())
|
if (startPlaceGeneric->getReachNext())
|
||||||
{
|
{
|
||||||
for (uint k = 0; k < _Places.size(); ++k)
|
for (uint k = 0; k < _Places.size(); ++k)
|
||||||
{
|
{
|
||||||
const CFaunaGenericPlace *place = getFaunaGenericPlace(_Places[k]);
|
const CFaunaGenericPlace *place = getFaunaGenericPlace(_Places[k]);
|
||||||
firstIndex = std::min(firstIndex, (sint) place->getIndex());
|
firstIndex = std::min(firstIndex, (sint) place->getIndex());
|
||||||
if (place->getIndex() < minIndex && place->getIndex() > startPlaceGeneric->getIndex())
|
if (place->getIndex() < minIndex && place->getIndex() > startPlaceGeneric->getIndex())
|
||||||
|
@ -1226,22 +1228,22 @@ bool CGrpFauna::checkArcs(const CAIPlace &startPlace) const
|
||||||
{
|
{
|
||||||
RYAI_MAP_CRUNCH::CCompatibleResult res;
|
RYAI_MAP_CRUNCH::CCompatibleResult res;
|
||||||
areCompatiblesWithoutStartRestriction(startPlace.worldValidPos(), _Places[k]->worldValidPos(), getAStarFlag(), res);
|
areCompatiblesWithoutStartRestriction(startPlace.worldValidPos(), _Places[k]->worldValidPos(), getAStarFlag(), res);
|
||||||
if (!res.isValid()) return false;
|
if (!res.isValid()) return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// includes all places reachable from the arcs list
|
// includes all places reachable from the arcs list
|
||||||
for (uint k = 0; k < _Places.size(); ++k)
|
for (uint k = 0; k < _Places.size(); ++k)
|
||||||
{
|
{
|
||||||
const CFaunaGenericPlace *place = getFaunaGenericPlace(_Places[k]);
|
const CFaunaGenericPlace *place = getFaunaGenericPlace(_Places[k]);
|
||||||
if (place != startPlaceGeneric)
|
if (place != startPlaceGeneric)
|
||||||
{
|
{
|
||||||
if (std::find(startPlaceGeneric->getArcs().begin(), startPlaceGeneric->getArcs().end(), place->getIndex()) != startPlaceGeneric->getArcs().end())
|
if (std::find(startPlaceGeneric->getArcs().begin(), startPlaceGeneric->getArcs().end(), place->getIndex()) != startPlaceGeneric->getArcs().end())
|
||||||
{
|
{
|
||||||
// this place is in current arc list
|
// this place is in current arc list
|
||||||
RYAI_MAP_CRUNCH::CCompatibleResult res;
|
RYAI_MAP_CRUNCH::CCompatibleResult res;
|
||||||
areCompatiblesWithoutStartRestriction(startPlace.worldValidPos(), _Places[k]->worldValidPos(), getAStarFlag(), res);
|
areCompatiblesWithoutStartRestriction(startPlace.worldValidPos(), _Places[k]->worldValidPos(), getAStarFlag(), res);
|
||||||
if (!res.isValid()) return false;
|
if (!res.isValid()) return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1249,7 +1251,7 @@ bool CGrpFauna::checkArcs(const CAIPlace &startPlace) const
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSpawnGroupFauna::setPlace(int placeIndex)
|
void CSpawnGroupFauna::setPlace(int placeIndex)
|
||||||
{
|
{
|
||||||
const CFaunaGenericPlace *place = getFaunaGenericPlace(getPersistent().places()[placeIndex]);
|
const CFaunaGenericPlace *place = getFaunaGenericPlace(getPersistent().places()[placeIndex]);
|
||||||
//nlwarning("Going to place %s with index %d", getPersistent().places()[placeIndex]->getName().c_str(), place->getIndex());
|
//nlwarning("Going to place %s with index %d", getPersistent().places()[placeIndex]->getName().c_str(), place->getIndex());
|
||||||
|
|
||||||
|
@ -1257,7 +1259,7 @@ void CSpawnGroupFauna::setPlace(int placeIndex)
|
||||||
{
|
{
|
||||||
nlwarning("Bad place index for fauna group %s", getPersistent().getName().c_str());
|
nlwarning("Bad place index for fauna group %s", getPersistent().getName().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// const CFaunaGenericPlace *faunaPlace = getFaunaGenericPlace(getPersistent().places()[placeIndex]);
|
// const CFaunaGenericPlace *faunaPlace = getFaunaGenericPlace(getPersistent().places()[placeIndex]);
|
||||||
// nlwarning("Group %s : Chosing place %s (%d) with graph index %d", getPersistent().getName().c_str(), faunaPlace->getName().c_str(), placeIndex, (int) faunaPlace->getIndex());
|
// nlwarning("Group %s : Chosing place %s (%d) with graph index %d", getPersistent().getName().c_str(), faunaPlace->getName().c_str(), placeIndex, (int) faunaPlace->getIndex());
|
||||||
|
|
||||||
|
|
|
@ -896,7 +896,7 @@ void cbEventNpcGroupScript( NLNET::CMessage& msgin, const std::string &serviceNa
|
||||||
msgin.serial(messageVersion);
|
msgin.serial(messageVersion);
|
||||||
nlassert(messageVersion==1);
|
nlassert(messageVersion==1);
|
||||||
msgin.serial(nbString);
|
msgin.serial(nbString);
|
||||||
|
|
||||||
string eid;
|
string eid;
|
||||||
string firstCommand;
|
string firstCommand;
|
||||||
msgin.serial(eid); // Player or boteid
|
msgin.serial(eid); // Player or boteid
|
||||||
|
|
Loading…
Reference in a new issue