Hooks
static bool BeforeCvGame_LogGameState(CvGame* self, bool bLogHeaders);static void AfterCvGame_LogGameState(CvGame* self, bool bLogHeaders);static void ReplaceCvGame_LogGameState(void (*original)(CvGame*, bool), CvGame* self, bool bLogHeaders);CivRegisterBefore<CivHooks::CvGame_LogGameState>(host, &BeforeCvGame_LogGameState);CivRegisterAfter<CivHooks::CvGame_LogGameState>(host, &AfterCvGame_LogGameState);CivRegisterReplace<CivHooks::CvGame_LogGameState>(host, &ReplaceCvGame_LogGameState);
Code
11028void CvGame::LogGameState(bool bLogHeaders)11029{11030 if(GC.getLogging() && GC.getAILogging())11031 {11032 CvString strOutput;1103311034 CvString playerName;11035 CvString otherPlayerName;11036 CvString strMinorString;11037 CvString strDesc;11038 CvString strLogName;11039 CvString strTemp;1104011041 strLogName = "WorldState_Log.csv";1104211043 FILogFile* pLog;11044 pLog = LOGFILEMGR.GetLog(strLogName, FILogFile::kDontTimeStamp);1104511046 // Get the leading info for this line11047 strOutput.Format("%03d", GC.getGame().getElapsedGameTurns());1104811049 AIGrandStrategyTypes eGrandStrategy;11050 int iGSConquest = 0;11051 int iGSSpaceship = 0;11052 int iGSUN = 0;11053 int iGSCulture = 0;1105411055 int iAlly = 0;11056 int iFriend = 0;11057 int iFavorable = 0;11058 int iNeutral = 0;11059 int iCompetitor = 0;11060 int iEnemy = 0;11061 int iUnforgivable = 0;1106211063 int iMajorWar = 0;11064 int iMajorHostile = 0;11065 int iMajorDeceptive = 0;11066 int iMajorGuarded = 0;11067 int iMajorAfraid = 0;11068 int iMajorFriendly = 0;11069 int iMajorNeutral = 0;1107011071 int iMinorIgnore = 0;11072 int iMinorFriendly = 0;11073 int iMinorProtective = 0;11074 int iMinorConquest = 0;11075 int iMinorBully = 0;1107611077 int iPlayerLoop2;11078 PlayerTypes eLoopPlayer2;1107911080 // Loop through all Players11081 PlayerTypes eLoopPlayer;11082 CvPlayer* pPlayer;11083 for(int iPlayerLoop = 0; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++)11084 {11085 eLoopPlayer = (PlayerTypes) iPlayerLoop;11086 pPlayer = &GET_PLAYER(eLoopPlayer);1108711088 if(pPlayer->isAlive())11089 {11090 eGrandStrategy = pPlayer->GetGrandStrategyAI()->GetActiveGrandStrategy();1109111092 if(eGrandStrategy == GC.getInfoTypeForString("AIGRANDSTRATEGY_CONQUEST"))11093 {11094 iGSConquest++;11095 }11096 else if(eGrandStrategy == GC.getInfoTypeForString("AIGRANDSTRATEGY_SPACESHIP"))11097 {11098 iGSSpaceship++;11099 }11100 else if(eGrandStrategy == GC.getInfoTypeForString("AIGRANDSTRATEGY_UNITED_NATIONS"))11101 {11102 iGSUN++;11103 }11104 else if(eGrandStrategy == GC.getInfoTypeForString("AIGRANDSTRATEGY_CULTURE"))11105 {11106 iGSCulture++;11107 }1110811109 // Loop through all players11110 for(iPlayerLoop2 = 0; iPlayerLoop2 < MAX_CIV_PLAYERS; iPlayerLoop2++)11111 {11112 eLoopPlayer2 = (PlayerTypes) iPlayerLoop2;1111311114 if(GET_PLAYER(eLoopPlayer2).isAlive())11115 {11116 // Major11117 if(eLoopPlayer2 < MAX_MAJOR_CIVS)11118 {11119 switch(pPlayer->GetDiplomacyAI()->GetMajorCivOpinion(eLoopPlayer2))11120 {11121 case MAJOR_CIV_OPINION_ALLY:11122 iAlly++;11123 break;11124 case MAJOR_CIV_OPINION_FRIEND:11125 iFriend++;11126 break;11127 case MAJOR_CIV_OPINION_FAVORABLE:11128 iFavorable++;11129 break;11130 case MAJOR_CIV_OPINION_NEUTRAL:11131 iNeutral++;11132 break;11133 case MAJOR_CIV_OPINION_COMPETITOR:11134 iCompetitor++;11135 break;11136 case MAJOR_CIV_OPINION_ENEMY:11137 iEnemy++;11138 break;11139 case MAJOR_CIV_OPINION_UNFORGIVABLE:11140 iUnforgivable++;11141 break;11142 }1114311144 switch(pPlayer->GetDiplomacyAI()->GetMajorCivApproach(eLoopPlayer2, false))11145 {11146 case MAJOR_CIV_APPROACH_WAR:11147 iMajorWar++;11148 break;11149 case MAJOR_CIV_APPROACH_HOSTILE:11150 iMajorHostile++;11151 break;11152 case MAJOR_CIV_APPROACH_DECEPTIVE:11153 iMajorDeceptive++;11154 break;11155 case MAJOR_CIV_APPROACH_GUARDED:11156 iMajorGuarded++;11157 break;11158 case MAJOR_CIV_APPROACH_AFRAID:11159 iMajorAfraid++;11160 break;11161 case MAJOR_CIV_APPROACH_FRIENDLY:11162 iMajorFriendly++;11163 break;11164 case MAJOR_CIV_APPROACH_NEUTRAL:11165 iMajorNeutral++;11166 break;11167 }11168 }11169 // Minor11170 else11171 {11172 switch(pPlayer->GetDiplomacyAI()->GetMinorCivApproach(eLoopPlayer2))11173 {11174 case MINOR_CIV_APPROACH_IGNORE:11175 iMinorIgnore++;11176 break;11177 case MINOR_CIV_APPROACH_FRIENDLY:11178 iMinorFriendly++;11179 break;11180 case MINOR_CIV_APPROACH_PROTECTIVE:11181 iMinorProtective++;11182 break;11183 case MINOR_CIV_APPROACH_CONQUEST:11184 iMinorConquest++;11185 break;11186 case MINOR_CIV_APPROACH_BULLY:11187 iMinorBully++;11188 break;11189 }11190 }11191 }11192 }11193 }11194 }1119511196 bool bFirstTurn = bLogHeaders || getElapsedGameTurns() == 0;1119711198 // Grand Strategies11199 if(bFirstTurn)11200 {11201 strOutput += ", Conquest";11202 strOutput += ", Spaceship";11203 strOutput += ", United Nations";11204 strOutput += ", Culture";11205 }11206 else11207 {11208 strTemp.Format("%d", iGSConquest);11209 strOutput += ", " + strTemp;11210 strTemp.Format("%d", iGSSpaceship);11211 strOutput += ", " + strTemp;11212 strTemp.Format("%d", iGSUN);11213 strOutput += ", " + strTemp;11214 strTemp.Format("%d", iGSCulture);11215 strOutput += ", " + strTemp;11216 }1121711218 strOutput += ", ";1121911220 // Major Approaches11221 if(bFirstTurn)11222 {11223 strOutput += ", Ally";11224 strOutput += ", Friend";11225 strOutput += ", Favorable";11226 strOutput += ", Neutral";11227 strOutput += ", Competitor";11228 strOutput += ", Enemy";11229 strOutput += ", Unforgivable";11230 }11231 else11232 {11233 strTemp.Format("%d", iAlly);11234 strOutput += ", " + strTemp;11235 strTemp.Format("%d", iFriend);11236 strOutput += ", " + strTemp;11237 strTemp.Format("%d", iFavorable);11238 strOutput += ", " + strTemp;11239 strTemp.Format("%d", iNeutral);11240 strOutput += ", " + strTemp;11241 strTemp.Format("%d", iCompetitor);11242 strOutput += ", " + strTemp;11243 strTemp.Format("%d", iEnemy);11244 strOutput += ", " + strTemp;11245 strTemp.Format("%d", iUnforgivable);11246 strOutput += ", " + strTemp;11247 }1124811249 strOutput += ", ";1125011251 // Major Approaches11252 if(bFirstTurn)11253 {11254 strOutput += ", War";11255 strOutput += ", Hostile";11256 strOutput += ", Deceptive";11257 strOutput += ", Guarded";11258 strOutput += ", Afraid";11259 strOutput += ", Friendly";11260 strOutput += ", Neutral";11261 }11262 else11263 {11264 strTemp.Format("%d", iMajorWar);11265 strOutput += ", " + strTemp;11266 strTemp.Format("%d", iMajorHostile);11267 strOutput += ", " + strTemp;11268 strTemp.Format("%d", iMajorDeceptive);11269 strOutput += ", " + strTemp;11270 strTemp.Format("%d", iMajorGuarded);11271 strOutput += ", " + strTemp;11272 strTemp.Format("%d", iMajorAfraid);11273 strOutput += ", " + strTemp;11274 strTemp.Format("%d", iMajorFriendly);11275 strOutput += ", " + strTemp;11276 strTemp.Format("%d", iMajorNeutral);11277 strOutput += ", " + strTemp;11278 }1127911280 strOutput += ", ";1128111282 // Minor Approaches11283 if(bFirstTurn)11284 {11285 strOutput += ", Ignore";11286 strOutput += ", Friendly";11287 strOutput += ", Protective";11288 strOutput += ", Conquest";11289 strOutput += ", Bully";11290 }11291 else11292 {11293 strTemp.Format("%d", iMinorIgnore);11294 strOutput += ", " + strTemp;11295 strTemp.Format("%d", iMinorFriendly);11296 strOutput += ", " + strTemp;11297 strTemp.Format("%d", iMinorProtective);11298 strOutput += ", " + strTemp;11299 strTemp.Format("%d", iMinorConquest);11300 strOutput += ", " + strTemp;11301 strTemp.Format("%d", iMinorBully);11302 strOutput += ", " + strTemp;11303 }1130411305 pLog->Msg(strOutput);11306 }11307}