Hooks
static bool BeforeCvPlayer_GatherPerTurnReplayStats(CvPlayer* self, int iGameTurn);static void AfterCvPlayer_GatherPerTurnReplayStats(CvPlayer* self, int iGameTurn);static void ReplaceCvPlayer_GatherPerTurnReplayStats(void (*original)(CvPlayer*, int), CvPlayer* self, int iGameTurn);CivRegisterBefore<CivHooks::CvPlayer_GatherPerTurnReplayStats>(host, &BeforeCvPlayer_GatherPerTurnReplayStats);CivRegisterAfter<CivHooks::CvPlayer_GatherPerTurnReplayStats>(host, &AfterCvPlayer_GatherPerTurnReplayStats);CivRegisterReplace<CivHooks::CvPlayer_GatherPerTurnReplayStats>(host, &ReplaceCvPlayer_GatherPerTurnReplayStats);
Code
27962void CvPlayer::GatherPerTurnReplayStats(int iGameTurn)27963{27964 AI_PERF_FORMAT("AI-perf.csv", ("CvPlayer::GatherPerTurnReplayStats, Turn %03d, %s", GC.getGame().getElapsedGameTurns(), getCivilizationShortDescription()) );27965#if !defined(FINAL_RELEASE)27966 cvStopWatch watch("Replay Stat Recording");27967#endif27968 ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();27969 if(pkScriptSystem)27970 {27971 CvLuaArgsHandle args;27972 args->Push(GetID());2797327974 bool bResult;27975 LuaSupport::CallHook(pkScriptSystem, "GatherPerTurnReplayStats", args.get(), bResult);27976 }2797727978 //Only record the following statistics if the player is alive.27979 if(isAlive())27980 {27981 // Production Per Turn27982 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_PRODUCTIONPERTURN"), iGameTurn, calculateTotalYield(YIELD_PRODUCTION));27983 // Gold27984 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_TOTALGOLD"), iGameTurn, GetTreasury()->GetGold());27985 // Gold per Turn27986 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_GOLDPERTURN"), iGameTurn, calculateTotalYield(YIELD_GOLD));27987 // Num Cities27988 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_CITYCOUNT"), iGameTurn, getNumCities());2798927990 // Number of Techs known27991 CvTeam& team = GET_TEAM(getTeam());27992 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_TECHSKNOWN"), iGameTurn, team.GetTeamTechs()->GetNumTechsKnown());2799327994 // Science per Turn27995 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_SCIENCEPERTURN"), iGameTurn, calculateTotalYield(YIELD_SCIENCE));27996 // antonjs: This data is also used to calculate Great Scientist and Research Agreement beaker bonuses. If replay data changes27997 // or is disabled, CvPlayer::GetScienceYieldFromPreviousTurns must also change.2799827999 // Total Culture28000 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_TOTALCULTURE"), iGameTurn, getJONSCulture());2800128002 // Culture per turn28003 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_CULTUREPERTURN"), iGameTurn, GetTotalJONSCulturePerTurn());2800428005 // Happiness28006 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_EXCESSHAPINESS"), iGameTurn, GetExcessHappiness());28007 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_HAPPINESS"), iGameTurn, GetHappiness());28008 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_UNHAPPINESS"), iGameTurn, GetUnhappiness());2800928010 // Golden Age turns28011 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_GOLDENAGETURNS"), iGameTurn, getGoldenAgeTurns());2801228013 // Population28014 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_POPULATION"), iGameTurn, getTotalPopulation());2801528016 // Food Per Turn28017 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_FOODPERTURN"), iGameTurn, calculateTotalYield(YIELD_FOOD));2801828019 // Total Land28020 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_TOTALLAND"), iGameTurn, getTotalLand());2802128022 CvTreasury* pkTreasury = GetTreasury();28023 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_GPTCITYCONNECTIONS"), iGameTurn, pkTreasury->GetCityConnectionGold());28024 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_GPTINTERNATIONALTRADE"), iGameTurn, pkTreasury->GetGoldPerTurnFromTradeRoutes());28025 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_GPTDEALS"), iGameTurn, pkTreasury->GetGoldPerTurnFromDiplomacy());28026 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_UNITMAINTENANCE"), iGameTurn, pkTreasury->GetExpensePerTurnUnitMaintenance());28027 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_BUILDINGMAINTENANCE"), iGameTurn, pkTreasury->GetBuildingGoldMaintenance());28028 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_IMPROVEMENTMAINTENANCE"), iGameTurn, pkTreasury->GetImprovementGoldMaintenance());28029#if defined(MOD_BUGFIX_DUMMY_POLICIES)28030 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_NUMBEROFPOLICIES"), iGameTurn, GetPlayerPolicies()->GetNumPoliciesOwned(MOD_BUGFIX_DUMMY_POLICIES));28031#else28032 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_NUMBEROFPOLICIES"), iGameTurn, GetPlayerPolicies()->GetNumPoliciesOwned());28033#endif2803428035 // workers28036 int iWorkerCount = 0;28037 CvUnit* pLoopUnit;28038 int iLoopUnit;28039 for(pLoopUnit = firstUnit(&iLoopUnit); pLoopUnit != NULL; pLoopUnit = nextUnit(&iLoopUnit))28040 {28041 if(pLoopUnit->AI_getUnitAIType() == UNITAI_WORKER)28042 {28043 iWorkerCount++;28044 }28045 }28046 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_NUMBEROFWORKERS"), iGameTurn, iWorkerCount);280472804828049 // go through all the plots the player has under their control28050 CvPlotsVector& aiPlots = GetPlots();2805128052 // worked tiles28053 int iWorkedTiles = 0;28054 int iImprovedTiles = 0;28055 for(uint uiPlotIndex = 0; uiPlotIndex < aiPlots.size(); uiPlotIndex++)28056 {28057 // when we encounter the first plot that is invalid, the rest of the list will be invalid28058 if(aiPlots[uiPlotIndex] == -1)28059 {28060 break;28061 }2806228063 CvPlot* pPlot = GC.getMap().plotByIndex(aiPlots[uiPlotIndex]);28064 if(!pPlot)28065 {28066 continue;28067 }2806828069 // plot has city in it, don't count28070 if(pPlot->getPlotCity())28071 {28072 continue;28073 }2807428075 if(pPlot->isBeingWorked())28076 {28077 iWorkedTiles++;28078 }2807928080 if(pPlot->getImprovementType() != NO_IMPROVEMENT)28081 {28082 iImprovedTiles++;28083 }28084 }2808528086 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_IMPROVEDTILES"), iGameTurn, iImprovedTiles);28087 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_WORKEDTILES"), iGameTurn, iWorkedTiles);28088 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_NUMBEROFWORKERS"), iGameTurn, iWorkerCount);280892809028091 setReplayDataValue(getReplayDataSetIndex("REPLAYDATASET_MILITARYMIGHT"), iGameTurn, GetMilitaryMight());28092 }28093}