Code
8183/// What happens when you have enough Culture to acquire a new Plot?8184void CvCity::DoJONSCultureLevelIncrease()8185{8186 VALIDATE_OBJECT81878188 int iOverflow = GetJONSCultureStored() - GetJONSCultureThreshold();8189#if defined(MOD_UI_CITY_EXPANSION)8190 bool bIsHumanControlled = (GET_PLAYER(getOwner()).isHuman() && !IsPuppet());8191 bool bSendEvent = true;8192 if (!(MOD_UI_CITY_EXPANSION && bIsHumanControlled)) {8193 // We need to defer this for humans picking their own tiles8194#endif8195 SetJONSCultureStored(iOverflow);8196 ChangeJONSCultureLevel(1);8197#if defined(MOD_UI_CITY_EXPANSION)8198 }8199#endif82008201 CvPlot* pPlotToAcquire = GetNextBuyablePlot();82028203 // maybe the player owns ALL of the plots or there are none avaialable?8204 if(pPlotToAcquire)8205 {8206#if defined(MOD_UI_CITY_EXPANSION)8207 // For human players, let them decide which plot to acquire8208 if (MOD_UI_CITY_EXPANSION && bIsHumanControlled) {8209 // Yep CITY_PLOTS_RADIUS is a #define and not taken from the database - well done Firaxis!8210#if defined(MOD_GLOBAL_CITY_WORKING)8211 bool bCanAcquirePlot = plotDistance(getX(), getY(), pPlotToAcquire->getX(), pPlotToAcquire->getY()) <= getWorkPlotDistance();8212#else8213 bool bCanAcquirePlot = plotDistance(getX(), getY(), pPlotToAcquire->getX(), pPlotToAcquire->getY()) <= CITY_PLOTS_RADIUS);8214#endif8215 if (bCanAcquirePlot && GetBuyPlotCost(pPlotToAcquire->getX(), pPlotToAcquire->getY()) < 1) {8216 // Within working/buying distance8217 bSendEvent = false;82188219 CvNotifications* pNotifications = GET_PLAYER(getOwner()).GetNotifications();8220 if (pNotifications) {8221 Localization::String localizedText = Localization::Lookup("TXT_KEY_NOTIFICATION_CITY_CULTURE_ACQUIRED_NEW_PLOT");8222 localizedText << getNameKey();8223 Localization::String localizedSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_CITY_CULTURE_ACQUIRED_NEW_PLOT");8224 localizedSummary << getNameKey();8225 pNotifications->Add(NOTIFICATION_CITY_TILE, localizedText.toUTF8(), localizedSummary.toUTF8(), getX(), getY(), GetID());8226 }8227 } else {8228 // The cheapest plot we can have is outside our working/buying distance, so just acquire it8229 DoAcquirePlot(pPlotToAcquire->getX(), pPlotToAcquire->getY());8230 // and also the deferred stuff8231 SetJONSCultureStored(iOverflow);8232 ChangeJONSCultureLevel(1);8233 }8234 } else {8235 // AI or dis-interested human, just acquire the plot normally8236#endif8237 if(GC.getLogging() && GC.getAILogging())8238 {8239 CvPlayerAI& kOwner = GET_PLAYER(getOwner());8240 CvString playerName;8241 FILogFile* pLog;8242 CvString strBaseString;8243 CvString strOutBuf;8244 playerName = kOwner.getCivilizationShortDescription();8245 pLog = LOGFILEMGR.GetLog(kOwner.GetCitySpecializationAI()->GetLogFileName(playerName), FILogFile::kDontTimeStamp);8246 strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns());8247 strBaseString += playerName + ", ";8248 strOutBuf.Format("%s, City Culture Leveled Up. Level: %d Border Expanded, X: %d, Y: %d", getName().GetCString(), 8249 GetJONSCultureLevel(), pPlotToAcquire->getX(), pPlotToAcquire->getY());8250 strBaseString += strOutBuf;8251 pLog->Msg(strBaseString);8252 }8253 DoAcquirePlot(pPlotToAcquire->getX(), pPlotToAcquire->getY());8254#if defined(MOD_UI_CITY_EXPANSION)8255 }8256#endif82578258#if defined(MOD_UI_CITY_EXPANSION)8259 // If the human is picking their own tile, the event will be sent when the tile is "bought"8260 if (bSendEvent) {8261#endif8262#if defined(MOD_EVENTS_CITY)8263 if (MOD_EVENTS_CITY) {8264 GAMEEVENTINVOKE_HOOK(GAMEEVENT_CityBoughtPlot, getOwner(), GetID(), pPlotToAcquire->getX(), pPlotToAcquire->getY(), false, true);8265 } else {8266#endif8267 ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();8268 if (pkScriptSystem) 8269 {8270 CvLuaArgsHandle args;8271 args->Push(getOwner());8272 args->Push(GetID());8273 args->Push(pPlotToAcquire->getX());8274 args->Push(pPlotToAcquire->getY());8275 args->Push(false); // bGold8276 args->Push(true); // bFaith/bCulture82778278 bool bResult;8279 LuaSupport::CallHook(pkScriptSystem, "CityBoughtPlot", args.get(), bResult);8280 }8281#if defined(MOD_EVENTS_CITY)8282 }8283#endif8284#if defined(MOD_UI_CITY_EXPANSION)8285 }8286#endif82878288#if defined(MOD_UI_CITY_EXPANSION)8289 } else if (MOD_UI_CITY_EXPANSION && bIsHumanControlled) {8290 // Do the stuff we deferred as we though we'd do it when the human bought a tile but can't as there are no tiles to buy!8291 SetJONSCultureStored(iOverflow);8292 ChangeJONSCultureLevel(1);8293#endif8294 }8295}