Code
1090// FUNCTION: reset()1091// Initializes data members that are serialized.1092void CvGame::reset(HandicapTypes eHandicap, bool bConstructorCall)1093{1094 int iI;10951096 //--------------------------------1097 // Uninit class1098 uninit();10991100 m_fCurrentTurnTimerPauseDelta = 0.f;11011102 CvString strUTF8DatabasePath = gDLL->GetCacheFolderPath();1103 strUTF8DatabasePath += "Civ5SavedGameDatabase.db";11041105 std::wstring wstrDatabasePath = CvStringUtils::FromUTF8ToUTF16(strUTF8DatabasePath);11061107 if(DeleteFileW(wstrDatabasePath.c_str()) == FALSE)1108 {1109 if(GetLastError() != ERROR_FILE_NOT_FOUND)1110 {1111 CvAssertMsg(false, "Warning! Cannot delete existing Civ5SavedGameDatabase! Does something have it opened?");1112 }1113 }11141115 Database::Connection db;1116 if(db.Open(strUTF8DatabasePath.c_str(), Database::OPEN_CREATE | Database::OPEN_READWRITE | Database::OPEN_FULLMUTEX))1117 {1118 db.Execute("CREATE TABLE SimpleValues(Name TEXT Primary Key, Value VARIANT)");1119 }1120 else1121 {1122 CvAssertMsg(false, "Warning! Cannot create new Civ5SavedGameDatabase.");1123 }112411251126 m_eHandicap = eHandicap;11271128 if(!bConstructorCall)1129 {1130 CvAssertMsg(m_paiUnitCreatedCount==NULL, "about to leak memory, CvGame::m_paiUnitCreatedCount");1131 m_paiUnitCreatedCount = FNEW(int[GC.getNumUnitInfos()], c_eCiv5GameplayDLL, 0);1132 for(iI = 0; iI < GC.getNumUnitInfos(); iI++)1133 {1134 CvUnitEntry* pkUnitInfo = GC.getUnitInfo((UnitTypes)iI);1135 if(!pkUnitInfo)1136 {1137 continue;1138 }1139 m_paiUnitCreatedCount[iI] = 0;1140 }11411142 CvAssertMsg(m_paiUnitClassCreatedCount==NULL, "about to leak memory, CvGame::m_paiUnitClassCreatedCount");1143 m_paiUnitClassCreatedCount = FNEW(int[GC.getNumUnitClassInfos()], c_eCiv5GameplayDLL, 0);1144 for(iI = 0; iI < GC.getNumUnitClassInfos(); iI++)1145 {1146 CvUnitClassInfo* pkUnitClassInfo = GC.getUnitClassInfo((UnitClassTypes)iI);1147 if(!pkUnitClassInfo)1148 {1149 continue;1150 }1151 m_paiUnitClassCreatedCount[iI] = 0;1152 }11531154 CvAssertMsg(m_paiBuildingClassCreatedCount==NULL, "about to leak memory, CvGame::m_paiBuildingClassCreatedCount");1155 m_paiBuildingClassCreatedCount = FNEW(int[GC.getNumBuildingClassInfos()], c_eCiv5GameplayDLL, 0);1156 for(iI = 0; iI < GC.getNumBuildingClassInfos(); iI++)1157 {1158 CvBuildingClassInfo* pkBuildingClassInfo = GC.getBuildingClassInfo((BuildingClassTypes)iI);1159 if(!pkBuildingClassInfo)1160 {1161 continue;1162 }11631164 m_paiBuildingClassCreatedCount[iI] = 0;1165 }11661167 CvAssertMsg(m_paiProjectCreatedCount==NULL, "about to leak memory, CvGame::m_paiProjectCreatedCount");1168 m_paiProjectCreatedCount = FNEW(int[GC.getNumProjectInfos()], c_eCiv5GameplayDLL, 0);1169 for(iI = 0; iI < GC.getNumProjectInfos(); iI++)1170 {1171 m_paiProjectCreatedCount[iI] = 0;1172 }11731174 //antonjs: todo: remove unused UN and voting variables and allocations1175 CvAssertMsg(0 < GC.getNumVoteInfos(), "GC.getNumVoteInfos() is not greater than zero in CvGame::reset");1176 CvAssertMsg(m_paiVoteOutcome==NULL, "about to leak memory, CvGame::m_paiVoteOutcome");1177 m_paiVoteOutcome = FNEW(PlayerVoteTypes[GC.getNumVoteInfos()], c_eCiv5GameplayDLL, 0);1178 for(iI = 0; iI < GC.getNumVoteInfos(); iI++)1179 {1180 m_paiVoteOutcome[iI] = NO_PLAYER_VOTE;1181 }11821183 CvAssertMsg(0 < GC.getNumVoteSourceInfos(), "GC.getNumVoteSourceInfos() is not greater than zero in CvGame::reset");1184 CvAssertMsg(m_aiDiploVote==NULL, "about to leak memory, CvGame::m_aiDiploVote");1185 m_aiDiploVote = FNEW(int[GC.getNumVoteSourceInfos()], c_eCiv5GameplayDLL, 0);1186 for(iI = 0; iI < GC.getNumVoteSourceInfos(); iI++)1187 {1188 m_aiDiploVote[iI] = 0;1189 }11901191 CvAssertMsg(0 < MAX_CIV_TEAMS, "MAX_CIV_TEAMS is not greater than zero in CvGame::reset");1192 CvAssertMsg(m_aiVotesCast==NULL, "about to leak memory, CvGame::m_aiVotesCast");1193 m_aiVotesCast = FNEW(int[MAX_CIV_TEAMS], c_eCiv5GameplayDLL, 0);1194 for(iI = 0; iI < MAX_CIV_TEAMS; iI++)1195 {1196 m_aiVotesCast[iI] = NO_TEAM;1197 }11981199 CvAssertMsg(0 < MAX_CIV_TEAMS, "MAX_CIV_TEAMS is not greater than zero in CvGame::reset");1200 CvAssertMsg(m_aiPreviousVotesCast == NULL, "About to leak memory, CvGame::m_aiPreviousVotesCast. Please send Anton your save file and version.");1201 m_aiPreviousVotesCast = FNEW(int[MAX_CIV_TEAMS], c_eCiv5GameplayDLL, 0);1202 for (iI = 0; iI < MAX_CIV_TEAMS; iI++)1203 {1204 m_aiPreviousVotesCast[iI] = NO_TEAM;1205 }12061207 CvAssertMsg(0 < MAX_CIV_TEAMS, "MAX_CIV_TEAMS is not greater than zero in CvGame::reset");1208 CvAssertMsg(m_aiNumVotesForTeam==NULL, "about to leak memory, CvGame::m_aiNumVotesForTeam");1209 m_aiNumVotesForTeam = FNEW(int[MAX_CIV_TEAMS], c_eCiv5GameplayDLL, 0);1210 for(iI = 0; iI < MAX_CIV_TEAMS; iI++)1211 {1212 m_aiNumVotesForTeam[iI] = 0;1213 }12141215 CvAssertMsg(0 < MAX_CIV_TEAMS, "MAX_CIV_TEAMS is not greater than zero in CvGame::reset");1216 CvAssertMsg(m_aiTeamCompetitionWinnersScratchPad==NULL, "about to leak memory, CvGame::m_aiTeamCompetitionWinnersScratchPad");1217 m_aiTeamCompetitionWinnersScratchPad = FNEW(int[MAX_CIV_TEAMS], c_eCiv5GameplayDLL, 0);1218 for(iI = 0; iI < MAX_CIV_TEAMS; iI++)1219 {1220 m_aiTeamCompetitionWinnersScratchPad[iI] = 0;1221 }12221223 CvAssertMsg(m_pabSpecialUnitValid==NULL, "about to leak memory, CvGame::m_pabSpecialUnitValid");1224 m_pabSpecialUnitValid = FNEW(bool[GC.getNumSpecialUnitInfos()], c_eCiv5GameplayDLL, 0);1225 for(iI = 0; iI < GC.getNumSpecialUnitInfos(); iI++)1226 {1227 m_pabSpecialUnitValid[iI] = false;1228 }12291230 CvAssertMsg(m_aiSecretaryGeneralTimer==NULL, "about to leak memory, CvGame::m_aiSecretaryGeneralTimer");1231 CvAssertMsg(m_aiVoteTimer==NULL, "about to leak memory, CvGame::m_aiVoteTimer");1232 m_aiSecretaryGeneralTimer = FNEW(int[GC.getNumVoteSourceInfos()], c_eCiv5GameplayDLL, 0);1233 m_aiVoteTimer = FNEW(int[GC.getNumVoteSourceInfos()], c_eCiv5GameplayDLL, 0);1234 for(iI = 0; iI < GC.getNumVoteSourceInfos(); iI++)1235 {1236 m_aiSecretaryGeneralTimer[iI] = 0;1237 m_aiVoteTimer[iI] = 0;1238 }12391240 CvAssertMsg(m_ppaaiTeamVictoryRank==NULL, "about to leak memory, CvGame::m_ppaaiTeamVictoryRank");1241 m_ppaaiTeamVictoryRank = FNEW(int*[GC.getNumVictoryInfos()], c_eCiv5GameplayDLL, 0);1242 for(iI = 0; iI < GC.getNumVictoryInfos(); iI++)1243 {1244 m_ppaaiTeamVictoryRank[iI] = FNEW(int[GC.getNUM_VICTORY_POINT_AWARDS()], c_eCiv5GameplayDLL, 0);1245 for(int iJ = 0; iJ < GC.getNUM_VICTORY_POINT_AWARDS(); iJ++)1246 {1247 m_ppaaiTeamVictoryRank[iI][iJ] = NO_TEAM;1248 }1249 }12501251 CvAssertMsg(m_pSettlerSiteEvaluator==NULL, "about to leak memory, CvGame::m_pSettlerSiteEvaluator");1252 m_pSettlerSiteEvaluator = FNEW(CvSiteEvaluatorForSettler, c_eCiv5GameplayDLL, 0);1253 m_pSettlerSiteEvaluator->Init();12541255 CvAssertMsg(m_pStartSiteEvaluator==NULL, "about to leak memory, CvGame::m_pStartSiteEvaluator");1256 m_pStartSiteEvaluator = FNEW(CvSiteEvaluatorForStart, c_eCiv5GameplayDLL, 0);1257 m_pStartSiteEvaluator->Init();12581259 CvAssertMsg(m_pStartPositioner==NULL, "about to leak memory, CvGame::m_pStartPositioner");1260 m_pStartPositioner = FNEW(CvStartPositioner, c_eCiv5GameplayDLL, 0);1261 m_pStartPositioner->Init(m_pStartSiteEvaluator);12621263 m_kGameDeals.Init();12641265 CvAssertMsg(m_pGameReligions==NULL, "about to leak memory, CvGame::m_pGameReligions");1266 m_pGameReligions = FNEW(CvGameReligions, c_eCiv5GameplayDLL, 0);1267 m_pGameReligions->Init();12681269 CvAssertMsg(m_pGameCulture==NULL, "about to leak memory, CvGame::m_pGameCulture");1270 m_pGameCulture = FNEW(CvGameCulture, c_eCiv5GameplayDLL, 0);12711272 CvAssertMsg(m_pGameLeagues==NULL, "about to leak memory, CvGame::m_pGameLeagues");1273 m_pGameLeagues = FNEW(CvGameLeagues, c_eCiv5GameplayDLL, 0);1274 m_pGameLeagues->Init();12751276 CvAssertMsg(m_pGameTrade==NULL, "about to leak memory, CvGame::m_pGameTrade");1277 m_pGameTrade = FNEW(CvGameTrade, c_eCiv5GameplayDLL, 0);1278 m_pGameTrade->Init();12791280 CvAssertMsg(m_pTacticalMap==NULL, "about to leak memory, CvGame::m_pTacticalMap");1281 m_pTacticalMap = FNEW(CvTacticalAnalysisMap, c_eCiv5GameplayDLL, 0);12821283 CvAssertMsg(m_pAdvisorCounsel==NULL, "about to leak memory, CvGame::m_pAdvisorCounsel");1284 m_pAdvisorCounsel = FNEW(CvAdvisorCounsel, c_eCiv5GameplayDLL, 0);12851286 CvAssertMsg(m_pAdvisorRecommender==NULL, "about to leak memory, CvGame::m_pAdvisorRecommender");1287 m_pAdvisorRecommender = FNEW(CvAdvisorRecommender, c_eCiv5GameplayDLL, 0);1288 }12891290 m_voteSelections.RemoveAll();1291 m_votesTriggered.RemoveAll();12921293 m_mapRand.reset();1294 m_jonRand.reset();12951296 m_iNumSessions = 1;12971298 m_AdvisorMessagesViewed.clear();12991300 CvCityManager::Reset();1301}