CvMap::Validate()
- Defined in
- CvMap.cpp, line 2184
- Class
- CvMap
- Hook name
CivHooks::CvMap_Validate
Hooks
static bool BeforeCvMap_Validate(CvMap* self, int& result);static void AfterCvMap_Validate(CvMap* self, int& result);static int ReplaceCvMap_Validate(int (*original)(CvMap*), CvMap* self);CivRegisterBefore<CivHooks::CvMap_Validate>(host, &BeforeCvMap_Validate);CivRegisterAfter<CivHooks::CvMap_Validate>(host, &AfterCvMap_Validate);CivRegisterReplace<CivHooks::CvMap_Validate>(host, &ReplaceCvMap_Validate);
Code
2184int CvMap::Validate()2185{2186 //SS: Patch Trade Connections.2187 //Just after the BNW Launch trade connection data could be corrupted due to razing cities.2188 //This function is used because it's called immediately after serialization.2189 //Iterate through all trade connections.2190 //Clear the connection if the source or dest city does not exist.2191 CvGameTrade* pGameTrade = GC.getGame().GetGameTrade();2192 if(pGameTrade)2193 {2194 for (uint ui = 0; ui < pGameTrade->m_aTradeConnections.size(); ui++)2195 {2196 TradeConnection& connection = pGameTrade->m_aTradeConnections[ui];2197 if(connection.m_iID > -1)2198 {2199 CvPlot* pOriginPlot = plot(connection.m_iOriginX, connection.m_iOriginY);2200 if(pOriginPlot)2201 {2202 if(pOriginPlot->getPlotCity() == NULL)2203 {2204#if defined(MOD_BUGFIX_MINOR)2205 pGameTrade->ClearAllCityTradeRoutes(pOriginPlot, true);2206#else2207 pGameTrade->ClearAllCityTradeRoutes(pOriginPlot);2208#endif2209 continue;2210 }2211 }22122213 CvPlot* pDestPlot = plot(connection.m_iDestX, connection.m_iDestY);2214 if(pDestPlot)2215 {2216 if(pDestPlot->getPlotCity() == NULL)2217 {2218#if defined(MOD_BUGFIX_MINOR)2219 pGameTrade->ClearAllCityTradeRoutes(pDestPlot, true);2220#else2221 pGameTrade->ClearAllCityTradeRoutes(pDestPlot);2222#endif2223 continue;2224 }2225 }2226 }2227 }2228 }2229223022312232 int iErrors = 0;2233 for(int iI = 0; iI < numPlots(); iI++)2234 {2235 CvPlot* pLoopPlot = plotByIndexUnchecked(iI);2236 iErrors |= pLoopPlot->Validate(*this);2237 }22382239 return iErrors;2240}