def _willPassTest(self, city): if (CityUtil.willGrowThisTurn(city)): iExtra = 1 elif (CityUtil.willShrinkThisTurn(city)): iExtra = -1 else: iExtra = 0 iHappy = city.happyLevel() iUnhappy = city.unhappyLevel(iExtra) if (iUnhappy > 0 and city.getHurryAngerTimer() > 0 and city.getHurryAngerTimer() % city.flatHurryAngerLength() == 0): iUnhappy -= 1 if (iUnhappy > 0 and city.getConscriptAngerTimer() and city.getConscriptAngerTimer() % city.flatConscriptAngerLength() == 0): iUnhappy -= 1 if (iUnhappy > 0 and city.getDefyResolutionAngerTimer() > 0 and city.getDefyResolutionAngerTimer() % city.flatDefyResolutionAngerLength() == 0): iUnhappy -= 1 if (iUnhappy > 0 and city.getEspionageHappinessCounter() > 0): iUnhappy -= 1 if (iHappy > 0 and city.getHappinessTimer() == 1): iHappy -= self.kiTempHappy if (iHappy < 0): iHappy = 0 if (iUnhappy < 0): iUnhappy = 0 return iHappy < iUnhappy
def checkCity(self, cityId, city, iPlayer, player): if Civ4lertsOpt.isShowCityPendingGrowthAlert(): if CityUtil.willGrowThisTurn(city): message = TRNSLTR.getText("TXT_KEY_CIV4LERTS_ON_CITY_PENDING_GROWTH", (city.getName(), city.getPopulation() + 1)) addMessageAtPlot(iPlayer, message, "Art/Interface/Symbols/Food/food05.dds", city.getX(), city.getY()) elif CityUtil.willShrinkThisTurn(city): message = TRNSLTR.getText("TXT_KEY_CIV4LERTS_ON_CITY_PENDING_SHRINKAGE", (city.getName(), city.getPopulation() - 1)) addMessageAtPlot(iPlayer, message, "Art/Interface/Symbols/Food/food05.dds", city.getX(), city.getY())
def _willPassTest(self, city): if (CityUtil.willGrowThisTurn(city)): iExtra = 1 elif (CityUtil.willShrinkThisTurn(city)): iExtra = -1 else: iExtra = 0 # badHealth() doesn't take iExtra! iHealthRate = city.healthRate(False, iExtra) if (city.getEspionageHealthCounter() > 0): iHealthRate += 1 return iHealthRate < 0
def checkCity(self, cityId, city, iPlayer, player): if (Civ4lertsOpt.isShowCityPendingGrowthAlert()): if (CityUtil.willGrowThisTurn(city)): message = localText.getText( "TXT_KEY_CIV4LERTS_ON_CITY_PENDING_GROWTH", (city.getName(), city.getPopulation() + 1)) icon = "Art/Interface/Symbols/Food/food05.dds" addMessageAtCity(iPlayer, message, icon, city) elif (CityUtil.willShrinkThisTurn(city)): message = localText.getText( "TXT_KEY_CIV4LERTS_ON_CITY_PENDING_SHRINKAGE", (city.getName(), city.getPopulation() - 1)) icon = "Art/Interface/Symbols/Food/food05.dds" addMessageAtCity(iPlayer, message, icon, city)
def checkCity(self, cityId, city, iPlayer, player): if (Civ4lertsOpt.isShowCityPendingGrowthAlert()): if (CityUtil.willGrowThisTurn(city)): if Civ4lertsOpt.isShowPendingPositive(): # advc.106d message = localText.getText( "TXT_KEY_CIV4LERTS_ON_CITY_PENDING_GROWTH", (city.getName(), city.getPopulation() + 1)) icon = "Art/Interface/Symbols/Food/food05.dds" addMessageAtCity(iPlayer, message, icon, city) elif (CityUtil.willShrinkThisTurn(city)): message = localText.getText( "TXT_KEY_CIV4LERTS_ON_CITY_PENDING_SHRINKAGE", (city.getName(), city.getPopulation() - 1)) icon = "Art/Interface/Symbols/Food/food05.dds" addMessageAtCity(iPlayer, message, icon, city)
def CheckForAlerts(self, iActivePlayer, activeTeam, BeginTurn): ##Added "else: pass" code to diagnose strange results - might be related to indent issues ourPop = 0 ourLand = 0 totalPop = 0 totalLand = 0 LimitPop = 0 LimitLand = 0 DomVictory = 3 popGrowthCount = 0 currentTurn = gc.getGame().getGameTurn() activePlayer = gc.getPlayer(iActivePlayer) if (self.getCheckForDomPopVictory() or (BeginTurn and self.getCheckForCityBorderExpansion())): # Check for cultural expansion and population growth teamPlayerList = [] teamPlayerList = PyGame.getCivTeamList(PyGame.getActiveTeam()) teamPlayerList.append(PyPlayer(iActivePlayer)) for loopPlayer in range(len(teamPlayerList)): lCity = [] # EF: This looks very wrong. Above the list of players will not be 0, 1, ... # but here it uses loopPlayer which is 0, 1, ... lCity = PyPlayer(loopPlayer).getCityList() for loopCity in range(len(lCity)): city = gc.getPlayer(loopPlayer).getCity(loopCity) #if (city.getFoodTurnsLeft() == 1 and not city.isFoodProduction()) and not city.AI_isEmphasize(5): if CityUtil.willGrowThisTurn(city): # advc popGrowthCount = popGrowthCount + 1 if (BeginTurn and self.getCheckForCityBorderExpansion()): if (city.getCultureLevel() != gc.getNumCultureLevelInfos() - 1): if ((city.getCulture(loopPlayer) + city.getCommerceRate( CommerceTypes.COMMERCE_CULTURE)) >= city.getCultureThreshold()): message = localText.getText( "TXT_KEY_MORECIV4LERTS_CITY_TO_EXPAND", (city.getName(), )) icon = "Art/Interface/Buttons/General/Warning_popup.dds" self._addMessageAtCity(loopPlayer, message, icon, city) else: pass else: pass #expand check else: pass #message check else: pass #end city loop else: pass #end activePlayer loop else: pass # end expansion check / pop count # Check Domination Limit if (self.getCheckForDomVictory() and gc.getGame().isVictoryValid(DomVictory)): # Population Limit if (self.getCheckForDomPopVictory()): VictoryPopPercent = 0.0 VictoryPopPercent = gc.getGame().getAdjustedPopulationPercent( DomVictory) * 1.0 totalPop = gc.getGame().getTotalPopulation() LimitPop = int((totalPop * VictoryPopPercent) / 100.0) ourPop = activeTeam.getTotalPopulation() if (totalPop > 0): popPercent = (ourPop * 100.0) / totalPop NextpopPercent = ( (ourPop + popGrowthCount) * 100.0) / totalPop else: popPercent = 0.0 NextpopPercent = 0.0 if (totalPop > 1 and (currentTurn <> self.lastDomLimitMsgTurn or (ourPop + popGrowthCount) <> self.lastPopCount)): self.lastPopCount = ourPop + popGrowthCount if (popPercent >= VictoryPopPercent): message = localText.getText( "TXT_KEY_MORECIV4LERTS_POP_EXCEEDS_LIMIT", (ourPop, (u"%.2f%%" % popPercent), LimitPop, (u"%.2f%%" % VictoryPopPercent))) self._addMessageNoIcon(iActivePlayer, message) elif (popGrowthCount > 0 and NextpopPercent >= VictoryPopPercent): message = localText.getText( "TXT_KEY_MORECIV4LERTS_POP_GROWTH_EXCEEDS_LIMIT", (ourPop, popGrowthCount, (u"%.2f%%" % NextpopPercent), LimitPop, (u"%.2f%%" % VictoryPopPercent))) self._addMessageNoIcon(iActivePlayer, message) elif (popGrowthCount > 0 and (VictoryPopPercent - NextpopPercent < self.getPopThreshold())): message = localText.getText( "TXT_KEY_MORECIV4LERTS_POP_GROWTH_CLOSE_TO_LIMIT", (ourPop, popGrowthCount, (u"%.2f%%" % NextpopPercent), LimitPop, (u"%.2f%%" % VictoryPopPercent))) self._addMessageNoIcon(iActivePlayer, message) ## .005 elif (VictoryPopPercent - popPercent < self.getPopThreshold()): elif (popGrowthCount > 0 and (VictoryPopPercent - popPercent < self.getPopThreshold())): message = localText.getText( "TXT_KEY_MORECIV4LERTS_POP_CLOSE_TO_LIMIT", (ourPop, (u"%.2f%%" % popPercent), LimitPop, (u"%.2f%%" % VictoryPopPercent))) self._addMessageNoIcon(iActivePlayer, message) else: pass #end elif else: pass #end totalPop if else: pass #end pop limit if # Land Limit if (self.getCheckForDomLandVictory()): VictoryLandPercent = 0.0 VictoryLandPercent = gc.getGame().getAdjustedLandPercent( DomVictory) * 1.0 totalLand = gc.getMap().getLandPlots() LimitLand = int((totalLand * VictoryLandPercent) / 100.0) ourLand = activeTeam.getTotalLand() if (totalLand > 0): landPercent = (ourLand * 100.0) / totalLand else: landPercent = 0.0 if (currentTurn <> self.lastDomLimitMsgTurn or ourLand <> self.lastLandCount): self.lastLandCount = ourLand if (landPercent > VictoryLandPercent): message = localText.getText( "TXT_KEY_MORECIV4LERTS_LAND_EXCEEDS_LIMIT", (ourLand, (u"%.2f%%" % landPercent), LimitLand, (u"%.2f%%" % VictoryLandPercent))) self._addMessageNoIcon(iActivePlayer, message) elif (VictoryLandPercent - landPercent < self.getLandThreshold()): message = localText.getText( "TXT_KEY_MORECIV4LERTS_LAND_CLOSE_TO_LIMIT", (ourLand, (u"%.2f%%" % landPercent), LimitLand, (u"%.2f%%" % VictoryLandPercent))) self._addMessageNoIcon(iActivePlayer, message) else: pass #end elif else: pass #end currentTurn if else: pass #end land limit if else: pass #end dom limt if #save turn num if (self.getCheckForDomVictory()): self.lastDomLimitMsgTurn = currentTurn # tech trades if (BeginTurn and self.getCheckForTechs()): researchTechs = set() for iTech in range(gc.getNumTechInfos()): if (activePlayer.canResearch(iTech, True)): researchTechs.add(iTech) techsByPlayer = self.getTechTrades(activePlayer, activeTeam) for iLoopPlayer, currentTechs in techsByPlayer.iteritems(): #Did he have trades avail last turn if (self.PrevAvailTechTrades.has_key(iLoopPlayer)): previousTechs = self.PrevAvailTechTrades[iLoopPlayer] else: previousTechs = set() #Determine new techs newTechs = currentTechs.difference(previousTechs).intersection( researchTechs) if (newTechs): szNewTechs = self.buildTechString(newTechs) message = localText.getText( "TXT_KEY_MORECIV4LERTS_NEW_TECH_AVAIL", (gc.getPlayer(iLoopPlayer).getName(), szNewTechs)) self._addMessageNoIcon(iActivePlayer, message) #Determine removed techs removedTechs = previousTechs.difference( currentTechs).intersection(researchTechs) if (removedTechs): szRemovedTechs = self.buildTechString(removedTechs) message = localText.getText( "TXT_KEY_MORECIV4LERTS_TECH_NOT_AVAIL", (gc.getPlayer(iLoopPlayer).getName(), szRemovedTechs)) self._addMessageNoIcon(iActivePlayer, message) else: pass #end activePlayer loop #save curr trades for next time self.PrevAvailTechTrades = techsByPlayer else: pass #end new trades if # bonus trades if (BeginTurn and self.getCheckForBonuses()): desiredBonuses = TradeUtil.getDesiredBonuses(activePlayer) tradesByPlayer = self.getBonusTrades(activePlayer, activeTeam) for iLoopPlayer, currentTrades in tradesByPlayer.iteritems(): #Did he have trades avail last turn if (self.PrevAvailBonusTrades.has_key(iLoopPlayer)): previousTrades = self.PrevAvailBonusTrades[iLoopPlayer] else: previousTrades = set() #Determine new bonuses newTrades = currentTrades.difference( previousTrades).intersection(desiredBonuses) if (newTrades): szNewTrades = self.buildBonusString(newTrades) message = localText.getText( "TXT_KEY_MORECIV4LERTS_NEW_BONUS_AVAIL", (gc.getPlayer(iLoopPlayer).getName(), szNewTrades)) self._addMessageNoIcon(iActivePlayer, message) # advc.106: Moved here to avoid messages about "flickering" offers self.PrevAvailBonusTrades = tradesByPlayer #Determine removed bonuses # <advc.106> This is rarely relevant (resources being no # longer available). #removedTrades = previousTrades.difference(currentTrades).intersection(desiredBonuses) #if (removedTrades): # szRemovedTrades = self.buildBonusString(removedTrades) # message = #localText.getText("TXT_KEY_MORECIV4LERTS_BONUS_NOT_AVAIL", # (gc.getPlayer(iLoopPlayer).getName(), szRemovedTrades)) # self._addMessageNoIcon(iActivePlayer, message) # </advc.106> #save curr trades for next time # self.PrevAvailBonusTrades = tradesByPlayer # advc.106: moved up self.checkForExports(activePlayer) # advc.210e if (BeginTurn and self.getCheckForMap()): currentTrades = self.getMapTrades(activePlayer, activeTeam) newTrades = currentTrades.difference(self.PrevAvailMapTrades) self.PrevAvailMapTrades = currentTrades if (newTrades): players = self.buildPlayerString(newTrades) message = localText.getText("TXT_KEY_MORECIV4LERTS_MAP", (players, )) self._addMessageNoIcon(iActivePlayer, message) if (BeginTurn and self.getCheckForOpenBorders()): currentTrades = self.getOpenBordersTrades(activePlayer, activeTeam) newTrades = currentTrades.difference( self.PrevAvailOpenBordersTrades) self.PrevAvailOpenBordersTrades = currentTrades if (newTrades): players = self.buildPlayerString(newTrades) message = localText.getText( "TXT_KEY_MORECIV4LERTS_OPEN_BORDERS", (players, )) self._addMessageNoIcon(iActivePlayer, message) if (BeginTurn and self.getCheckForDefensivePact()): currentTrades = self.getDefensivePactTrades( activePlayer, activeTeam) newTrades = currentTrades.difference( self.PrevAvailDefensivePactTrades) self.PrevAvailDefensivePactTrades = currentTrades if (newTrades): players = self.buildPlayerString(newTrades) message = localText.getText( "TXT_KEY_MORECIV4LERTS_DEFENSIVE_PACT", (players, )) self._addMessageNoIcon(iActivePlayer, message) if (BeginTurn and self.getCheckForPermanentAlliance()): currentTrades = self.getPermanentAllianceTrades( activePlayer, activeTeam) newTrades = currentTrades.difference( self.PrevAvailPermanentAllianceTrades) self.PrevAvailPermanentAllianceTrades = currentTrades if (newTrades): players = self.buildPlayerString(newTrades) message = localText.getText( "TXT_KEY_MORECIV4LERTS_PERMANENT_ALLIANCE", (players, )) self._addMessageNoIcon(iActivePlayer, message) if (BeginTurn and self.getCheckForVassal()): currentTrades = self.getVassalTrades(activePlayer, activeTeam) newTrades = currentTrades.difference(self.PrevAvailVassalTrades) self.PrevAvailVassalTrades = currentTrades if (newTrades): players = self.buildPlayerString(newTrades) message = localText.getText("TXT_KEY_MORECIV4LERTS_VASSAL", (players, )) self._addMessageNoIcon(iActivePlayer, message) if (BeginTurn and self.getCheckForSurrender()): currentTrades = self.getSurrenderTrades(activePlayer, activeTeam) newTrades = currentTrades.difference(self.PrevAvailSurrenderTrades) self.PrevAvailSurrenderTrades = currentTrades if (newTrades): players = self.buildPlayerString(newTrades) message = localText.getText("TXT_KEY_MORECIV4LERTS_SURRENDER", (players, )) self._addMessageNoIcon(iActivePlayer, message) if (BeginTurn and self.getCheckForPeace()): currentTrades = self.getPeaceTrades(activePlayer, activeTeam) newTrades = currentTrades.difference(self.PrevAvailPeaceTrades) self.PrevAvailPeaceTrades = currentTrades if (newTrades): players = self.buildPlayerString(newTrades) message = localText.getText( "TXT_KEY_MORECIV4LERTS_PEACE_TREATY", (players, )) self._addMessageNoIcon(iActivePlayer, message)