/// Log chosen policy void CvPolicyAI::LogBranchChoice(PolicyBranchTypes eBranch) { if(GC.getLogging() && GC.getAILogging()) { CvString strOutBuf; CvString strBaseString; CvString strTemp; CvString playerName; CvString strDesc; // Find the name of this civ and city playerName = m_pCurrentPolicies->GetPlayer()->getCivilizationShortDescription(); FILogFile* pLog; pLog = LOGFILEMGR.GetLog(GetLogFileName(playerName), FILogFile::kDontTimeStamp); // Get the leading info for this line strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns()); strBaseString += playerName + ", "; strTemp.Format("CHOSEN, Branch %d", eBranch); strOutBuf = strBaseString + strTemp; pLog->Msg(strOutBuf); } }
bool CvSakke::DecodePublicParams( const String& aPublicParams, OUT octet& aPx, OUT octet& aPy ) { CvString publicParams = aPublicParams; vector<CvString> tokens; publicParams.Tokenize( "#", tokens ); if ( tokens.size() != 2 ) return false; tokens[0].TrimLeft("["); tokens[0].TrimRight("]"); vector<CvString> tokensP; tokens[0].Tokenize( ",", tokensP ); if ( tokensP.size() != 2 ) return false; String decoded; CvBase64::Decode( tokensP[0], decoded ); OCTET_JOIN_BYTES( decoded.data(), (int)decoded.size(), &aPx ); decoded.clear(); CvBase64::Decode( tokensP[1], decoded ); OCTET_JOIN_BYTES( decoded.data(), (int)decoded.size(), &aPy ); return true; }
/// Log all possible tech choices void CvTechAI::LogPossibleResearch() { if(GC.getLogging() && GC.getAILogging()) { CvString strOutBuf; CvString strBaseString; CvString strTemp; CvString playerName; CvString strDesc; // Find the name of this civ playerName = m_pCurrentTechs->GetPlayer()->getCivilizationShortDescription(); FILogFile* pLog = LOGFILEMGR.GetLog(GetLogFileName(playerName), FILogFile::kDontTimeStamp); // Get the leading info for this line strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns()); strBaseString += playerName + ", "; // Dump out the weight of each Researchable Tech for(int iI = 0; iI < m_ResearchableTechs.size(); iI++) { TechTypes eTech = (TechTypes) m_ResearchableTechs.GetElement(iI); int iWeight = m_ResearchableTechs.GetWeight(iI); CvTechEntry* pTechEntry = GC.getTechInfo(eTech); const char* szTechType = (pTechEntry != NULL)? pTechEntry->GetType() : "Unknown Tech"; strTemp.Format("%s, %d", szTechType, iWeight); strOutBuf = strBaseString + strTemp; pLog->Msg(strOutBuf); } } }
/* CDpkgConfig* CvSakke::GetSakkeParams() //temporary { return CDpkgConfig::Instance(); } */ bool CvSakke::DecodePublicKey( const String& aPublicKey, OUT octet& aZ_S ) { OCTET_CLEAR(&aZ_S); if ( aPublicKey[0] != '[' || aPublicKey[aPublicKey.length()-1] != ']' ) return false; CvString publicKey = aPublicKey; publicKey.TrimLeft( "[" ); publicKey.TrimRight( "]" ); vector<CvString> tokens; publicKey.Tokenize( ",", tokens ); if ( tokens.size() != 2 ) return false; OCTET_JOIN_BYTE( 4, 1, &aZ_S ); for ( vector<CvString>::const_iterator itr = tokens.begin(); itr != tokens.end(); ++itr ) { String decoded; CvBase64::Decode( *itr, decoded ); if ( decoded.size() != FS ) return false; OCTET_JOIN_BYTES( decoded.data(), FS, &aZ_S ); } return true; }
bool CvSakke::DecodeEncapsulatedData( const String& aEncapsulatedData, OUT octet& aRbS, OUT octet& aH ) { OCTET_CLEAR(&aRbS); OCTET_CLEAR(&aH); CvString encapsulatedData = aEncapsulatedData; vector<CvString> tokens; encapsulatedData.Tokenize( ",", tokens ); if ( tokens.size() != 2 ) return false; String decoded; CvBase64::Decode( tokens[0], decoded ); if ( decoded.size() != aH.max ) return false; OCTET_JOIN_BYTES( decoded.data(), aH.max, &aH ); decoded.clear(); CvBase64::Decode( tokens[1], decoded ); if ( decoded.size() != aRbS.max ) return false; OCTET_JOIN_BYTES( decoded.data(), aRbS.max, &aRbS ); return true; }
//------------------------------------------------------------------------------------------------------ // // FUNCTION: LoadCivXml(FXml* pFXml, TCHAR* szFilename) // // PURPOSE : Gets the full pathname for the xml file from the FileManager . // If it is succesful we return true // from the function and a valid FXml pointer to the pFXml parameter. // //------------------------------------------------------------------------------------------------------ bool CvXMLLoadUtility::LoadCivXml(FXml* pFXml, const TCHAR* szFilename) { char szLog[256]; sprintf(szLog, "LoadCivXml (%s)", szFilename); PROFILE(szLog); OutputDebugString(szLog); OutputDebugString("\n"); CvString szPath = szFilename; CvString fsFilename = szFilename; if (!gDLL->fileManagerEnabled()) { szPath = "Assets//" + szPath; } logMsg("Loading XML file %s\n", szPath.c_str()); if (!gDLL->getXMLIFace()->LoadXml(pFXml, szPath)) { logMsg("Load XML file %s FAILED\n", szPath.c_str()); return false; } logMsg("Load XML file %s SUCCEEDED\n", szPath.c_str()); GC.setCurrentXMLFile(szFilename); return true; // success }
//------------------------------------------------------------------------------------------------------ bool CvTerrainPlaneInfo::read(CvXMLLoadUtility* pXML) { CvString szTextVal; if (!CvInfoBase::read(pXML)) return false; pXML->GetChildXmlValByName( &m_bVisible, "bVisible"); pXML->GetChildXmlValByName( &m_bGroundPlane, "bGroundPlane"); pXML->GetChildXmlValByName( &m_fMaterialAlpha, "MaterialAlpha"); pXML->GetChildXmlValByName( &m_fCloseAlpha, "CloseAlpha"); pXML->GetChildXmlValByName( szTextVal, "TextureFile"); setBaseTexture(szTextVal); pXML->GetChildXmlValByName( &m_BaseTextureScaleU, "TextureScalingU"); pXML->GetChildXmlValByName( &m_BaseTextureScaleV, "TextureScalingV"); pXML->GetChildXmlValByName( &m_fURate, "URate"); pXML->GetChildXmlValByName( &m_fVRate, "VRate"); pXML->GetChildXmlValByName( &m_fZHeight, "ZHeight"); pXML->GetChildXmlValByName( szTextVal, "FogType"); if(szTextVal.CompareNoCase("FOG_TYPE_NONE") == 0) m_eFogType = FOG_TYPE_NONE; else if(szTextVal.CompareNoCase("FOG_TYPE_PARALLEL") == 0) m_eFogType = FOG_TYPE_PARALLEL; else if(szTextVal.CompareNoCase("FOG_TYPE_PROJECTED") == 0) m_eFogType = FOG_TYPE_PROJECTED; else { FAssertMsg(false, "[Jason] Unknown fog type."); m_eFogType = FOG_TYPE_NONE; } return true; }
/// Logging function to write out info on Ideology choices void CvPolicyAI::LogIdeologyChoice(CvString &decisionState, int iWeightFreedom, int iWeightAutocracy, int iWeightOrder) { if(GC.getLogging() && GC.getAILogging()) { CvString strOutBuf; CvString strBaseString; CvString strTemp; CvString playerName; // Find the name of this civ playerName = m_pCurrentPolicies->GetPlayer()->getCivilizationShortDescription(); FILogFile* pLog; pLog = LOGFILEMGR.GetLog(GetLogFileName(playerName), FILogFile::kDontTimeStamp); // Get the leading info for this line strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns()); strBaseString += playerName + ", "; strTemp.Format("%s, Freedom: %d, Order: %d, Autocracy: %d", decisionState.c_str(), iWeightFreedom, iWeightOrder, iWeightAutocracy); strOutBuf = strBaseString + strTemp; pLog->Msg(strOutBuf); } }
CvPlot* CvArmyAI::DetectNearbyEnemy(PlayerTypes eEnemy, bool bNaval) { UnitHandle pUnit = GetFirstUnit(); while(pUnit) { for(int iDirectionLoop = 0; iDirectionLoop < NUM_DIRECTION_TYPES; ++iDirectionLoop) { CvPlot* pAdjacentPlot = plotDirection(pUnit->getX(), pUnit->getY(), ((DirectionTypes)iDirectionLoop)); if(pAdjacentPlot != NULL && pAdjacentPlot->isWater()==bNaval && pAdjacentPlot->getOwner() == eEnemy) { UnitHandle pOtherUnit = pAdjacentPlot->getBestDefender(eEnemy); if(pOtherUnit) { if(GC.getLogging() && GC.getAILogging()) { CvString strMsg; strMsg.Format("Ran into enemy unit during attack (x=%d y=%d). Need to declare war to continue!", pAdjacentPlot->getX(), pAdjacentPlot->getY()); GET_PLAYER(m_eOwner).getAIOperation(m_iOperationID)->LogOperationSpecialMessage(strMsg); } return pAdjacentPlot; } } } pUnit = GetNextUnit(); } return NULL; }
/// Helper function to read a single type (as a string) and find its ID in a database table. /// Assumes the type is in the table's field "Type" int ReadDBLookup(FDataStream& kStream, const char* szTable, bool* bValid /*= NULL*/) { FStringFixedBuffer(sTemp, 256); kStream >> sTemp; if (bValid) *bValid = true; if(sTemp.GetLength() > 0 && sTemp != "NO_TYPE") { Database::Connection* pDB = GC.GetGameDatabase(); if(pDB) { Database::Results kResults; CvString szCommand; szCommand.Format("SELECT ID from %s where Type = ? LIMIT 1", szTable); if(pDB->Execute(kResults, szCommand.c_str())) { kResults.Bind(1, sTemp.c_str()); if(kResults.Step()) { return kResults.GetInt(0); } else if (bValid) *bValid = false; } } else if (bValid) *bValid = false; } return -1; }
/// Log chosen policy void CvPolicyAI::LogPolicyChoice(PolicyTypes ePolicy) { if(GC.getLogging() && GC.getAILogging()) { CvString strOutBuf; CvString strBaseString; CvString strTemp; CvString playerName; CvString strDesc; // Find the name of this civ and city playerName = m_pCurrentPolicies->GetPlayer()->getCivilizationShortDescription(); FILogFile* pLog; pLog = LOGFILEMGR.GetLog(GetLogFileName(playerName), FILogFile::kDontTimeStamp); // Get the leading info for this line strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns()); strBaseString += playerName + ", "; CvPolicyEntry* pPolicyEntry = GC.getPolicyInfo(ePolicy); const char* szPolicyType = (pPolicyEntry != NULL)? pPolicyEntry->GetType() : "Unknown"; strTemp.Format("CHOSEN, %s", szPolicyType); strOutBuf = strBaseString + strTemp; pLog->Msg(strOutBuf); } }
void TreasuryHelpers::AppendToLog(CvString& strHeader, CvString& strLog, CvString strHeaderValue, float fValue) { strHeader += strHeaderValue; strHeader += ","; CvString str; str.Format("%.2f,", fValue); strLog += str; }
void TreasuryHelpers::AppendToLog(CvString& strHeader, CvString& strLog, CvString strHeaderValue, int iValue) { strHeader += strHeaderValue; strHeader += ","; CvString str; str.Format("%d,", iValue); strLog += str; }
/// Serialization read void CvUnitProductionAI::Read(FDataStream& kStream) { // Version number to maintain backwards compatibility uint uiVersion; kStream >> uiVersion; int iWeight; // Reset vector m_UnitAIWeights.clear(); // Loop through reading each one and adding it to our vector if(m_pUnits) { #ifdef AUI_WARNING_FIXES for (uint i = 0; i < m_pUnits->GetNumUnits(); i++) #else for(int i = 0; i < m_pUnits->GetNumUnits(); i++) #endif { m_UnitAIWeights.push_back(i, 0); } #ifdef AUI_WARNING_FIXES uint iNumEntries; int iType; kStream >> iNumEntries; for (uint iI = 0; iI < iNumEntries; iI++) #else int iNumEntries; int iType; kStream >> iNumEntries; for(int iI = 0; iI < iNumEntries; iI++) #endif { bool bValid = true; iType = CvInfosSerializationHelper::ReadHashed(kStream, &bValid); if(iType != -1 || !bValid) { kStream >> iWeight; if(iType != -1) { m_UnitAIWeights.IncreaseWeight(iType, iWeight); } else { CvString szError; szError.Format("LOAD ERROR: Unit Type not found"); GC.LogMessage(szError.GetCString()); CvAssertMsg(false, szError); } } } }
/// Log dominance zone data void CvTacticalAnalysisMap::LogZones() { if(GC.getLogging() && GC.getAILogging()) { CvString szLogMsg; CvTacticalDominanceZone* pZone; for(unsigned int iI = 0; iI < m_DominanceZones.size(); iI++) { pZone = &m_DominanceZones[iI]; szLogMsg.Format("Zone ID: %d, Area ID: %d, Value: %d, FRIENDLY Str: %d (%d), Ranged: %d (%d), ENEMY Str: %d (%d), Ranged: %d (%d), Closest Enemy: %d", pZone->GetDominanceZoneID(), pZone->GetAreaID(), pZone->GetDominanceZoneValue(), pZone->GetFriendlyStrength(), pZone->GetFriendlyUnitCount(), pZone->GetFriendlyRangedStrength(), pZone->GetFriendlyRangedUnitCount(), pZone->GetEnemyStrength(), pZone->GetEnemyUnitCount(), pZone->GetEnemyRangedStrength(), pZone->GetEnemyRangedUnitCount(), pZone->GetRangeClosestEnemyUnit()); if(pZone->GetDominanceFlag() == TACTICAL_DOMINANCE_FRIENDLY) { szLogMsg += ", Friendly"; } else if(pZone->GetDominanceFlag() == TACTICAL_DOMINANCE_ENEMY) { szLogMsg += ", Enemy"; } else if(pZone->GetDominanceFlag() == TACTICAL_DOMINANCE_EVEN) { szLogMsg += ", Even"; } else if(pZone->GetDominanceFlag() == TACTICAL_DOMINANCE_NO_UNITS_VISIBLE) { szLogMsg += ", No Units Visible"; } if(pZone->IsWater()) { szLogMsg += ", Water"; } else { szLogMsg += ", Land"; } if(pZone->GetTerritoryType() == TACTICAL_TERRITORY_TEMP_ZONE) { szLogMsg += ", Temporary Zone"; } else if(pZone->GetClosestCity()) { szLogMsg += ", " + pZone->GetClosestCity()->getName(); if (m_pPlayer->GetTacticalAI()->IsTemporaryZoneCity(pZone->GetClosestCity())) { szLogMsg += " (Temp)"; } } m_pPlayer->GetTacticalAI()->LogTacticalMessage(szLogMsg, true /*bSkipLogDominanceZone*/); } } }
//------------------------------------------------------------------------------ //string GetGreatPersonRateModifierDetails(UnitClassTypes eGreatPersonClass); int CvLuaLeague::lGetGreatPersonRateModifierDetails(lua_State* L) { CvLeague* pLeague = GetInstance(L); const UnitClassTypes eGreatPersonClass = (UnitClassTypes) lua_tointeger(L, 2); CvString sValue = pLeague->GetGreatPersonRateModifierDetails(eGreatPersonClass); lua_pushstring(L, sValue.c_str()); return 1; }
//------------------------------------------------------------------------------ //string GetLeagueSplashNextEraDetails(LeagueSpecialSessionTypes eGoverningSpecialSession, bool bJustFounded); int CvLuaLeague::lGetLeagueSplashNextEraDetails(lua_State* L) { CvLeague* pLeague = GetInstance(L); const LeagueSpecialSessionTypes eGoverningSpecialSession = (LeagueSpecialSessionTypes) lua_tointeger(L, 2); const bool bJustFounded = lua_toboolean(L, 3); CvString sValue = pLeague->GetLeagueSplashNextEraDetails(eGoverningSpecialSession, bJustFounded); lua_pushstring(L, sValue.c_str()); return 1; }
//------------------------------------------------------------------------------ //string GetProjectDetails(LeagueProjectTypes eProject, PlayerTypes eObserver); int CvLuaLeague::lGetProjectDetails(lua_State* L) { CvLeague* pLeague = GetInstance(L); const LeagueProjectTypes eProject = (LeagueProjectTypes) lua_tointeger(L, 2); const PlayerTypes eObserver = (PlayerTypes) luaL_optint(L, 3, NO_PLAYER); CvString sValue = pLeague->GetProjectDetails(eProject, eObserver); lua_pushstring(L, sValue.c_str()); return 1; }
//------------------------------------------------------------------------------ //string GetMemberDetails(PlayerTypes eMember, PlayerTypes eObserver); int CvLuaLeague::lGetMemberDetails(lua_State* L) { CvLeague* pLeague = GetInstance(L); const PlayerTypes eMember = (PlayerTypes) lua_tointeger(L, 2); const PlayerTypes eObserver = (PlayerTypes) lua_tointeger(L, 3); CvString sValue = pLeague->GetMemberDetails(eMember, eObserver); lua_pushstring(L, sValue.c_str()); return 1; }
/// Log GrandStrategy state: what are the Priorities and who is Active? void CvGrandStrategyAI::LogGrandStrategies(const FStaticVector< int, 5, true, c_eCiv5GameplayDLL >& vModifiedGrandStrategyPriorities) { if(GC.getLogging() && GC.getAILogging()) { CvString strOutBuf; CvString strBaseString; CvString strTemp; CvString playerName; CvString strDesc; CvString strLogName; // Find the name of this civ and city playerName = GetPlayer()->getCivilizationShortDescription(); // Open the log file if(GC.getPlayerAndCityAILogSplit()) { strLogName = "GrandStrategyAI_Log_" + playerName + ".csv"; } else { strLogName = "GrandStrategyAI_Log.csv"; } FILogFile* pLog; pLog = LOGFILEMGR.GetLog(strLogName, FILogFile::kDontTimeStamp); AIGrandStrategyTypes eGrandStrategy; // Loop through Grand Strategies for(int iGrandStrategyLoop = 0; iGrandStrategyLoop < GC.getNumAIGrandStrategyInfos(); iGrandStrategyLoop++) { // Get the leading info for this line strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns()); strBaseString += playerName + ", "; eGrandStrategy = (AIGrandStrategyTypes) iGrandStrategyLoop; // GrandStrategy Info CvAIGrandStrategyXMLEntry* pEntry = GC.getAIGrandStrategyInfo(eGrandStrategy); const char* szAIGrandStrategyType = (pEntry != NULL)? pEntry->GetType() : "Unknown Type"; if(GetActiveGrandStrategy() == eGrandStrategy) { strTemp.Format("*** %s, %d, %d", szAIGrandStrategyType, GetGrandStrategyPriority(eGrandStrategy), vModifiedGrandStrategyPriorities[eGrandStrategy]); } else { strTemp.Format("%s, %d, %d", szAIGrandStrategyType, GetGrandStrategyPriority(eGrandStrategy), vModifiedGrandStrategyPriorities[eGrandStrategy]); } strOutBuf = strBaseString + strTemp; pLog->Msg(strOutBuf); } } }
//------------------------------------------------------------------------------ //string GetResolutionDetails(ResolutionTypes eResolution, PlayerTypes eObserver, int iResolutionID, int iProposerChoice); int CvLuaLeague::lGetResolutionDetails(lua_State* L) { CvLeague* pLeague = GetInstance(L); const ResolutionTypes eResolution = (ResolutionTypes) lua_tointeger(L, 2); const PlayerTypes eObserver = (PlayerTypes) lua_tointeger(L, 3); const int iResolutionID = lua_tointeger(L, 4); const int iProposerChoice = lua_tointeger(L, 5); CvString sValue = pLeague->GetResolutionDetails(eResolution, eObserver, iResolutionID, iProposerChoice); lua_pushstring(L, sValue.c_str()); return 1; }
//------------------------------------------------------------------------------ //string GetResolutionName(ResolutionTypes eResolution, int iResolutionID, int iProposerChoice, bool bIncludePrefix); int CvLuaLeague::lGetResolutionName(lua_State* L) { CvLeague* pLeague = GetInstance(L); const ResolutionTypes eResolution = (ResolutionTypes) lua_tointeger(L, 2); const int iResolutionID = lua_tointeger(L, 3); const int iProposerChoice = lua_tointeger(L, 4); const bool bIncludePrefix = lua_toboolean(L, 5); CvString sValue = pLeague->GetResolutionName(eResolution, iResolutionID, iProposerChoice, bIncludePrefix); lua_pushstring(L, sValue.c_str()); return 1; }
void CvFlavorManager::LogFlavors(FlavorTypes eFlavor) { CvString strOutBuf; CvString strBaseString; CvString strTemp; CvString playerName; CvString strDesc; CvString strLogName; if(GC.getLogging() && GC.getAILogging()) { // Find the name of this civ playerName = m_pPlayer->getCivilizationShortDescription(); // Open the log file if(GC.getPlayerAndCityAILogSplit()) { strLogName = "FlavorAILog_" + playerName + ".csv"; } else { strLogName = "FlavorAILog.csv"; } FILogFile* pLog; pLog = LOGFILEMGR.GetLog(strLogName, FILogFile::kDontTimeStamp); // Get the leading info for this line strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns()); strBaseString += playerName + ", "; // Dump out the setting for each flavor if(eFlavor == NO_FLAVOR) { for(int iI = 0; iI < GC.getNumFlavorTypes(); iI++) { // Only dump if non-zero // if (m_piLatestFlavorValues[iI] > 0) { strTemp.Format("Flavor, %s, %d", GC.getFlavorTypes((FlavorTypes)iI).GetCString(), GetIndividualFlavor((FlavorTypes) iI)); strOutBuf = strBaseString + strTemp; pLog->Msg(strOutBuf); } } } else { strTemp.Format("Flavor, %s, %d", GC.getFlavorTypes(eFlavor).GetCString(), GetIndividualFlavor(eFlavor)); strOutBuf = strBaseString + strTemp; pLog->Msg(strOutBuf); } } }
/// Serialization read void CvUnitProductionAI::Read(FDataStream& kStream) { // Version number to maintain backwards compatibility uint uiVersion; kStream >> uiVersion; // modVersion - v1, Snarko // We are using our own value here to keep backwards compatibility. // While we could use the Firaxis value that would cause issues when they update it, so we use our own for maximum backward compatibility. // Old firaxis patch and old mod version? No problem! Except if you weren't using our mod before... uint modVersion; kStream >> modVersion; // END modVersion int iWeight; // Reset vector m_UnitAIWeights.clear(); // Loop through reading each one and adding it to our vector if(m_pUnits) { for(int i = 0; i < m_pUnits->GetNumUnits(); i++) { m_UnitAIWeights.push_back(i, 0); } int iNumEntries; int iType; kStream >> iNumEntries; for(int iI = 0; iI < iNumEntries; iI++) { bool bValid = true; iType = CvInfosSerializationHelper::ReadHashed(kStream, &bValid); if(iType != -1 || !bValid) { kStream >> iWeight; if(iType != -1) { m_UnitAIWeights.IncreaseWeight(iType, iWeight); } else { CvString szError; szError.Format("LOAD ERROR: Unit Type not found"); GC.LogMessage(szError.GetCString()); CvAssertMsg(false, szError); } } } }
/* Check if corrent admin password is given and set player password to new value. * I do not test specical chars in passwords. Simply omit them... * */ int CyGame::setCivPassword(int ePlayer, const char *szNewPw, const char *szAdminPw) { //convert adminpassword to CvString CvString adminPW; adminPW.Convert ( GC.getInitCore().getAdminPassword() ); if( strcmp( adminPW.GetCString(), szAdminPw ) == 0 ){ CvWString newCivPW( szNewPw ); GC.getInitCore().setCivPassword((PlayerTypes)ePlayer, newCivPW ); }else{ return -1; } return 0; }
/// Serialization read void CvUnitProductionAI::Read(FDataStream& kStream) { // Version number to maintain backwards compatibility uint uiVersion; kStream >> uiVersion; int iWeight; // Reset vector m_UnitAIWeights.clear(); // Loop through reading each one and adding it to our vector if(m_pUnits) { if(uiVersion >= 2) { for(int i = 0; i < m_pUnits->GetNumUnits(); i++) { m_UnitAIWeights.push_back(i, 0); } int iNumEntries; FStringFixedBuffer(sTemp, 64); int iType; kStream >> iNumEntries; for(int iI = 0; iI < iNumEntries; iI++) { kStream >> sTemp; if(sTemp != "NO_UNIT") { iType = GC.getInfoTypeForString(sTemp); kStream >> iWeight; if(iType != -1) { m_UnitAIWeights.IncreaseWeight(iType, iWeight); } else { CvString szError; szError.Format("LOAD ERROR: Unit Type not found: %s", sTemp); GC.LogMessage(szError.GetCString()); CvAssertMsg(false, szError); } } } } else { for(int i = 0; i < 90 /* Units in gold master */; i++)
//------------------------------------------------------------------------------ bool CvDllGameContext::GetDefineSTRING(char* szBuffer, size_t lenBuffer, const char* szName, bool bReportErrors) { if(szBuffer != NULL && lenBuffer > 0) { CvString strDefine = GC.getDefineSTRING(szName, bReportErrors); if(strDefine.size() < lenBuffer) { strncpy_s(szBuffer, lenBuffer, strDefine.c_str(), strDefine.size()); return true; } } return false; }
CvString CvXMLLoadUtilityModTools::deleteFileName(const char* szDirName, const char szLocateChar) { CvString szDirNameStrip = szDirName; string::size_type pos = szDirNameStrip.find_last_of(szLocateChar); if(pos != string::npos) { szDirNameStrip.erase(pos + 1); } else { FAssertMsg(false, "Couldn't find the directory slash") } return szDirNameStrip; }
void CvArmyAI::RemoveStuckUnits() { CvAIOperation* pOperation = GET_PLAYER(GetOwner()).getAIOperation(GetOperationID()); for(unsigned int iI = 0; iI < m_FormationEntries.size(); iI++) { if(m_FormationEntries[iI].GetUnitID() > ARMYSLOT_NO_UNIT && m_FormationEntries[iI].GetTurnAtCheckpoint()==ARMYSLOT_UNKNOWN_TURN_AT_CHECKPOINT) { CvString strMsg; strMsg.Format("Removing unit %d from army %d because no path to checkpoint",m_FormationEntries[iI].GetUnitID(),GetID()); pOperation->LogOperationSpecialMessage(strMsg); RemoveUnit(m_FormationEntries[iI].GetUnitID()); } } }
/// Serialization read void CvBuildingProductionAI::Read(FDataStream& kStream) { // Version number to maintain backwards compatibility uint uiVersion; kStream >> uiVersion; MOD_SERIALIZE_INIT_READ(kStream); // Reset vector m_BuildingAIWeights.clear(); // Loop through reading each one and adding it to our vector if(m_pCityBuildings) { for(int i = 0; i < m_pCityBuildings->GetPossibleBuildings()->GetNumBuildings(); i++) { m_BuildingAIWeights.push_back(i, 0); } int iNumEntries; FStringFixedBuffer(sTemp, 64); int iType; kStream >> iNumEntries; for(int iI = 0; iI < iNumEntries; iI++) { bool bValid = true; iType = CvInfosSerializationHelper::ReadHashed(kStream, &bValid); if(iType != -1 || !bValid) { int iWeight; kStream >> iWeight; if(iType != -1) { m_BuildingAIWeights.IncreaseWeight(iType, iWeight); } else { CvString szError; szError.Format("LOAD ERROR: Building Type not found"); GC.LogMessage(szError.GetCString()); CvAssertMsg(false, szError); } } } }