diff --git a/WpCommon/inc/StartupHelpers.h b/WpCommon/inc/StartupHelpers.h index f2f3e12..83e7840 100644 --- a/WpCommon/inc/StartupHelpers.h +++ b/WpCommon/inc/StartupHelpers.h @@ -78,7 +78,7 @@ inline void createBiotopAndScenarioFromIniFile(const string& fileIni, CBiotop** CScenarioPlayer* pScenarioPlayer{ nullptr }; char resuBuffer[512]; - int resu = getStringSectionFromFile("CYBIOSPHERE", "Biotop", "", resuBuffer, 512, fileIni); + getStringSectionFromFile("CYBIOSPHERE", "Biotop", "", resuBuffer, 512, fileIni); string biotopName = resuBuffer; clearWindowsEolIfNeeded(biotopName); @@ -86,7 +86,7 @@ inline void createBiotopAndScenarioFromIniFile(const string& fileIni, CBiotop** { string resuDataPath; pBiotop = new CBiotop(0, 0, 0); - bool resu = getStringSectionFromFile("CYBIOSPHERE", "DataPath", "", resuBuffer, 512, fileIni); + getStringSectionFromFile("CYBIOSPHERE", "DataPath", "", resuBuffer, 512, fileIni); resuDataPath = resuBuffer; clearWindowsEolIfNeeded(resuDataPath); if (resuDataPath != "") @@ -104,14 +104,14 @@ inline void createBiotopAndScenarioFromIniFile(const string& fileIni, CBiotop** } pScenarioPlayer = new CScenarioPlayer(pBiotop); - resu = getStringSectionFromFile("CYBIOSPHERE", "Scenario", "", resuBuffer, 512, fileIni); + getStringSectionFromFile("CYBIOSPHERE", "Scenario", "", resuBuffer, 512, fileIni); string scenarioName = resuBuffer; clearWindowsEolIfNeeded(scenarioName); if (scenarioName != "") { string resuDataPath; - bool resu = getStringSectionFromFile("CYBIOSPHERE", "DataPath", "", resuBuffer, 512, fileIni); + getStringSectionFromFile("CYBIOSPHERE", "DataPath", "", resuBuffer, 512, fileIni); resuDataPath = resuBuffer; clearWindowsEolIfNeeded(resuDataPath); if (resuDataPath != "") @@ -124,6 +124,12 @@ inline void createBiotopAndScenarioFromIniFile(const string& fileIni, CBiotop** pScenarioPlayer->NextCmdNextSecond(); } + string resuSpecieName; + getStringSectionFromFile("CYBIOSPHERE", "AutoSaveSpecie", "", resuBuffer, 512, fileIni); + resuSpecieName = resuBuffer; + if (resuSpecieName != "") + pBiotop->setAutoSaveSpecieName(resuSpecieName); + *pNewBiotop = pBiotop; *pNewScenarioPlayer = pScenarioPlayer; } diff --git a/WpEnvironment/inc/CBiotop.h b/WpEnvironment/inc/CBiotop.h index 9959657..9a30aeb 100644 --- a/WpEnvironment/inc/CBiotop.h +++ b/WpEnvironment/inc/CBiotop.h @@ -270,6 +270,7 @@ class DLL_CYBIOCORE_API CBiotop bool m_bColorizeSearch; CGene m_GeneToMark{}; bool m_bMarkDominantAlleleOnly{ false }; + string m_AutoSaveSpecieName{ "" }; //--------------------------------------------------------------------------- // associations @@ -434,6 +435,7 @@ class DLL_CYBIOCORE_API CBiotop CGeoMapPopulation* getGeoMapSpecieByIndex(size_t index); void saveAllGeoMapsInFile(string fileNameWithPath); void saveAllRecordsInFiles(); + void saveAllEntitiesOfSpecie(string specieName); private: timeCountType getNextSmallestTimeCountInAllMeasures(timeCountType previousSmallestTimeCount); @@ -521,6 +523,7 @@ class DLL_CYBIOCORE_API CBiotop bool getMarkDominantAlleleOnly(); void setGlobalGridDimension(size_t dimX, size_t dimY); void setGlobalGridCoordOffset(Point_t startingCoord); + void setAutoSaveSpecieName(string specieName); }; // end CBiotop diff --git a/WpEnvironment/src/CBiotop.cpp b/WpEnvironment/src/CBiotop.cpp index 54866d5..0672c57 100644 --- a/WpEnvironment/src/CBiotop.cpp +++ b/WpEnvironment/src/CBiotop.cpp @@ -131,7 +131,7 @@ CBiotop* CBiotop::extractNewBiotopFromArea(Point_t startCoord, size_t dimX, size || ((startCoord.x + dimX) > m_Dimension.x) || ((startCoord.y + dimY) > m_Dimension.y)) { CYBIOCORE_LOG_TIME(m_BioTime); - CYBIOCORE_LOG("ERROR - Try to exctract Arean with invalid coord\n"); + CYBIOCORE_LOG("ERROR - Try to exctract Arean with invalid coord startX=%u sizeX=%u\n", startCoord.x, dimX); return NULL; } @@ -752,12 +752,12 @@ size_t CBiotop::getNbOfMinerals() return (tempCount); } -size_t CBiotop::getNbOfSpecieEntities(string& SpecieName) +size_t CBiotop::getNbOfSpecieEntities(string& specieName) { size_t tempCount = 0; for (CBasicEntity* pEntity : m_tEntity) { - if ((pEntity->getSpecieName() == SpecieName) && (pEntity->isAlive() || (pEntity->getStatus() == STATUS_STATIC))) + if ((pEntity->getSpecieName() == specieName) && (pEntity->isAlive() || (pEntity->getStatus() == STATUS_STATIC))) tempCount++; } return (tempCount); @@ -1706,11 +1706,15 @@ void CBiotop::nextDay(void) m_BioTime.years++; } - // Automatic metric record in files every 2 days + // Automatic metric records if ((m_BioTime.days % 2) == 1) { saveAllRecordsInFiles(); } + if ((m_AutoSaveSpecieName != "") && ((m_BioTime.days % 100) == 0)) + { + saveAllEntitiesOfSpecie(m_AutoSaveSpecieName); + } } void CBiotop::nextHourForAllEntities(void) @@ -2349,6 +2353,22 @@ void CBiotop::saveAllRecordsInFiles() saveAllGeoMapsInFile(geomapFileName); } +void CBiotop::saveAllEntitiesOfSpecie(string specieName) +{ + string path = m_DefaultFilePath + "/AutoSave/"; + CYBIOCORE_LOG_TIME(m_BioTime); + CYBIOCORE_LOG("BIOTOP - Save all entities of specie name %s path %s\n", specieName.c_str(), path.c_str()); + + for (CBasicEntity* pCurEntity : m_tEntity) + { + if (pCurEntity->getSpecieName() == specieName) + { + string entityFileName{ path + pCurEntity->getLabel() + ".xml"}; + pCurEntity->saveInXmlFile(entityFileName); + } + } +} + //=========================================================================== // Event management //=========================================================================== @@ -3213,3 +3233,9 @@ void CBiotop::setGlobalGridCoordOffset(Point_t startingCoord) m_GlobalStepCoordOffset.x = startingCoord.x * NB_STEPS_PER_GRID_SQUARE; m_GlobalStepCoordOffset.y = startingCoord.y * NB_STEPS_PER_GRID_SQUARE; } + +void CBiotop::setAutoSaveSpecieName(string specieName) +{ + m_AutoSaveSpecieName = specieName; +} +