예제 #1
0
	def getBonusSales(self, player):
		r = {}
		playerGoldTr = gc.getTeam(player.getTeam()).isGoldTrading()
		for other in TradeUtil.getBonusTradePartners(player):
			if other.isHuman():
				continue
			if not playerGoldTr and not gc.getTeam(other.getTeam()).isGoldTrading():
				continue
			if other.AI_maxGoldPerTurnTrade(player.getID()) <= 2:
				continue
			# As getBonusTrades, but switch the parameters in this call:
			will, wont = TradeUtil.getTradeableBonuses(player, other)
			r[other.getID()] = set()
			for iBonus in will.intersection(TradeUtil.getDesiredBonuses(other)):
				if player.getNumTradeableBonuses(iBonus) > 1 and player.AI_corporationBonusVal(iBonus) <= 0:
					r[other.getID()].add(iBonus)
		return r # </advc.210e>
예제 #2
0
파일: MoreCiv4lerts.py 프로젝트: AP-ML/DTM
	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):
						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)
				
				#Determine removed bonuses
				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)

			#save curr trades for next time
			self.PrevAvailBonusTrades = tradesByPlayer
		
		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)
예제 #3
0
    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):
                        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)

                #Determine removed bonuses
                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)

            #save curr trades for next time
            self.PrevAvailBonusTrades = tradesByPlayer

        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)
예제 #4
0
	def CheckForAlerts(self, iPlayer, bBeginTurn):
		CyPlayer = GC.getPlayer(iPlayer)
		CyTeam = GC.getTeam(CyPlayer.getTeam())
		iGrowthCount = 0

		bCheck1 = self.options.isShowDomPopAlert()
		bCheck2 = bBeginTurn and self.options.isShowCityPendingExpandBorderAlert()

		if bCheck1 or bCheck2:
			# Check for cultural expansion and population growth
			icon = "Art/Interface/Buttons/General/Warning_popup.dds"
			iActiveTeam = GAME.getActiveTeam()
			for iPlayerX in xrange(GC.getMAX_PC_PLAYERS()):
				CyPlayerX = GC.getPlayer(iPlayerX)
				if not CyPlayerX.isAlive() or CyPlayerX.getTeam() != iActiveTeam:
					continue
				for cityX in CyPlayerX.cities():
					if cityX.getFoodTurnsLeft() == 1 and not cityX.isFoodProduction() and not cityX.AI_isEmphasize(5):
						iGrowthCount += 1
					if bCheck2 and cityX.getCultureLevel() != GC.getNumCultureLevelInfos() - 1:
						if cityX.getCulture(iPlayerX) + cityX.getCommerceRate(CommerceTypes.COMMERCE_CULTURE) >= cityX.getCultureThreshold():
							msg = TRNSLTR.getText("TXT_KEY_MORECIV4LERTS_CITY_TO_EXPAND",(cityX.getName(),))
							CvUtil.sendMessage(msg, iPlayer, EVENT_MESSAGE_TIME_LONG, icon, -1, cityX.getX(), cityX.getY(), True, True)

		# Check Domination Limit
		if self.getCheckForDomVictory() and GAME.isVictoryValid(3):
			# Population Limit
			if bCheck1 and iGrowthCount:
				iTotalPop = GAME.getTotalPopulation()
				if iTotalPop > 10:
					iTeamPop = CyTeam.getTotalPopulation()
					fPercent = iTeamPop * 100.0 / iTotalPop
					fPercentNext = (iTeamPop + iGrowthCount) * 100.0 / iTotalPop

					if iTeamPop + iGrowthCount != self.lastPopCount:
						fVictoryPercent = GAME.getAdjustedPopulationPercent(3) * 1.0
						iLimitPop = int(iTotalPop * fVictoryPercent / 100)

						if fPercent >= fVictoryPercent:
							msg = TRNSLTR.getText("TXT_KEY_MORECIV4LERTS_POP_EXCEEDS_LIMIT", (iTeamPop, (u"%.2f%%" % fPercent), iLimitPop, (u"%.2f%%" % fVictoryPercent)))
							self._addMessageNoIcon(iPlayer, msg)

						elif fPercentNext >= fVictoryPercent:
							msg = TRNSLTR.getText("TXT_KEY_MORECIV4LERTS_POP_GROWTH_EXCEEDS_LIMIT", (iTeamPop, iGrowthCount, (u"%.2f%%" % fPercentNext), iLimitPop, (u"%.2f%%" % fVictoryPercent)))
							self._addMessageNoIcon(iPlayer, msg)

						elif fVictoryPercent - fPercentNext < self.options.getDomPopThreshold():
							msg = TRNSLTR.getText("TXT_KEY_MORECIV4LERTS_POP_GROWTH_CLOSE_TO_LIMIT", (iTeamPop, iGrowthCount, (u"%.2f%%" % fPercentNext), iLimitPop, (u"%.2f%%" % fVictoryPercent)))
							self._addMessageNoIcon(iPlayer, msg)

						elif fVictoryPercent - fPercent < self.options.getDomPopThreshold():
							msg = TRNSLTR.getText("TXT_KEY_MORECIV4LERTS_POP_CLOSE_TO_LIMIT", (iTeamPop, (u"%.2f%%" % fPercent), iLimitPop, (u"%.2f%%" % fVictoryPercent)))
							self._addMessageNoIcon(iPlayer, msg)

						self.lastPopCount = iTeamPop + iGrowthCount
			# Land Limit
			if self.options.isShowDomLandAlert():
				iTeamLand = CyTeam.getTotalLand()
				if iTeamLand > 40 and iTeamLand != self.lastLandCount:
					iTotalLand = GC.getMap().getLandPlots()
					fVictoryPercent = GAME.getAdjustedLandPercent(3) * 1.0
					iLimitLand = int(iTotalLand * fVictoryPercent / 100)
					fPercent = (iTeamLand * 100.0) / iTotalLand

					if fPercent > fVictoryPercent:
						msg = TRNSLTR.getText("TXT_KEY_MORECIV4LERTS_LAND_EXCEEDS_LIMIT", (iTeamLand, (u"%.2f%%" % fPercent), iLimitLand, (u"%.2f%%" % fVictoryPercent)))
						self._addMessageNoIcon(iPlayer, msg)

					elif fVictoryPercent - fPercent < self.options.getDomLandThreshold():
						msg = TRNSLTR.getText("TXT_KEY_MORECIV4LERTS_LAND_CLOSE_TO_LIMIT", (iTeamLand, (u"%.2f%%" % fPercent), iLimitLand, (u"%.2f%%" % fVictoryPercent)))
						self._addMessageNoIcon(iPlayer, msg)

					self.lastLandCount = iTeamLand

		if not bBeginTurn: return
		#********#
		# Trades #
		# | || | #
		tradeData = TradeData()
		# Bonus
		if self.options.isShowBonusTradeAlert():
			desiredBonuses = TradeUtil.getDesiredBonuses(CyPlayer, CyTeam)
			tradesByPlayer = {}
			for CyPlayerX in TradeUtil.getBonusTradePartners(CyPlayer):
				will, wont = TradeUtil.getTradeableBonuses(CyPlayerX, iPlayer)
				tradesByPlayer[CyPlayerX.getID()] = will

			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)
					msg = TRNSLTR.getText("TXT_KEY_MORECIV4LERTS_NEW_BONUS_AVAIL", (GC.getPlayer(iLoopPlayer).getName(), szNewTrades))
					self._addMessageNoIcon(iPlayer, msg)
				#Determine removed bonuses
				removedTrades = previousTrades.difference(currentTrades).intersection(desiredBonuses)
				if removedTrades:
					szRemovedTrades = self.buildBonusString(removedTrades)
					msg = TRNSLTR.getText("TXT_KEY_MORECIV4LERTS_BONUS_NOT_AVAIL", (GC.getPlayer(iLoopPlayer).getName(), szRemovedTrades))
					self._addMessageNoIcon(iPlayer, msg)
			#save curr trades for next time
			self.PrevAvailBonusTrades = tradesByPlayer
		# Tech
		if self.options.isShowTechTradeAlert():
			techsByPlayer = {}
			researchTechs = set()
			iTotalTechs = GC.getNumTechInfos()
			tradeData.ItemType = TradeableItems.TRADE_TECHNOLOGIES
			bCheck1 = True
			for CyPlayerX in TradeUtil.getTechTradePartners(CyPlayer):
				techsToTrade = set()
				for iTech in range(iTotalTechs):
					if bCheck1 and CyPlayer.canResearch(iTech):
						researchTechs.add(iTech)
					tradeData.iData = iTech
					if CyPlayerX.canTradeItem(iPlayer, tradeData, False):
						if CyPlayerX.getTradeDenial(iPlayer, tradeData) == DenialTypes.NO_DENIAL: # will trade
							techsToTrade.add(iTech)
				bCheck1 = False
				techsByPlayer[CyPlayerX.getID()] = techsToTrade

			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)
					msg = TRNSLTR.getText("TXT_KEY_MORECIV4LERTS_NEW_TECH_AVAIL", (GC.getPlayer(iLoopPlayer).getName(), szNewTechs))
					self._addMessageNoIcon(iPlayer, msg)
				#Determine removed techs
				removedTechs = previousTechs.difference(currentTechs).intersection(researchTechs)
				if removedTechs:
					szRemovedTechs = self.buildTechString(removedTechs)
					msg = TRNSLTR.getText("TXT_KEY_MORECIV4LERTS_TECH_NOT_AVAIL", (GC.getPlayer(iLoopPlayer).getName(), szRemovedTechs))
					self._addMessageNoIcon(iPlayer, msg)
			#save curr trades for next time
			self.PrevAvailTechTrades = techsByPlayer
		# Map
		if self.options.isShowMapTradeAlert():
			tradeData.ItemType = TradeableItems.TRADE_MAPS
			oldSet = self.PrevAvailMapTrades
			TXT_KEY = "TXT_KEY_MORECIV4LERTS_MAP"
			willTrade = self.getTrades(TradeUtil.getMapTradePartners(CyPlayer), iPlayer, tradeData, oldSet, TXT_KEY)
			if willTrade != oldSet:
				self.PrevAvailMapTrades = willTrade
		# Open Borders
		if self.options.isShowOpenBordersTradeAlert():
			tradeData.ItemType = TradeableItems.TRADE_OPEN_BORDERS
			oldSet = self.PrevAvailOpenBordersTrades
			TXT_KEY = "TXT_KEY_MORECIV4LERTS_OPEN_BORDERS"
			willTrade = self.getTrades(TradeUtil.getOpenBordersTradePartners(CyPlayer), iPlayer, tradeData, oldSet, TXT_KEY)
			if willTrade != oldSet:
				self.PrevAvailOpenBordersTrades = willTrade
		# Defensive Pact
		if self.options.isShowDefensivePactTradeAlert():
			tradeData.ItemType = TradeableItems.TRADE_DEFENSIVE_PACT
			oldSet = self.PrevAvailDefensivePactTrades
			TXT_KEY = "TXT_KEY_MORECIV4LERTS_DEFENSIVE_PACT"
			willTrade = self.getTrades(TradeUtil.getDefensivePactTradePartners(CyPlayer), iPlayer, tradeData, oldSet, TXT_KEY)
			if willTrade != oldSet:
				self.PrevAvailDefensivePactTrades = willTrade
		# Alliance
		if self.options.isShowPermanentAllianceTradeAlert():
			tradeData.ItemType = TradeableItems.TRADE_PERMANENT_ALLIANCE
			oldSet = self.PrevAvailPermanentAllianceTrades
			TXT_KEY = "TXT_KEY_MORECIV4LERTS_PERMANENT_ALLIANCE"
			willTrade = self.getTrades(TradeUtil.getPermanentAllianceTradePartners(CyPlayer), iPlayer, tradeData, oldSet, TXT_KEY)
			if willTrade != oldSet:
				self.PrevAvailPermanentAllianceTrades = willTrade
		# Vassalage
		if self.options.isShowVassalTradeAlert():
			tradeData.ItemType = TradeableItems.TRADE_VASSAL
			oldSet = self.PrevAvailVassalTrades
			TXT_KEY = "TXT_KEY_MORECIV4LERTS_VASSAL"
			willTrade = self.getTrades(TradeUtil.getVassalTradePartners(CyPlayer), iPlayer, tradeData, oldSet, TXT_KEY)
			if willTrade != oldSet:
				self.PrevAvailVassalTrades = willTrade
		# Capitulate
		if self.options.isShowSurrenderTradeAlert():
			tradeData.ItemType = TradeableItems.TRADE_SURRENDER
			oldSet = self.PrevAvailSurrenderTrades
			TXT_KEY = "TXT_KEY_MORECIV4LERTS_SURRENDER"
			willTrade = self.getTrades(TradeUtil.getCapitulationTradePartners(CyPlayer), iPlayer, tradeData, oldSet, TXT_KEY)
			if willTrade != oldSet:
				self.PrevAvailSurrenderTrades = willTrade
		# Peace Treaty
		if self.options.isShowPeaceTradeAlert():
			tradeData.ItemType = TradeableItems.TRADE_PEACE_TREATY
			tradeData.iData = GC.getDefineINT("PEACE_TREATY_LENGTH")
			oldSet = self.PrevAvailPeaceTrades
			TXT_KEY = "TXT_KEY_MORECIV4LERTS_PEACE_TREATY"
			willTrade = self.getTrades(TradeUtil.getPeaceTradePartners(CyPlayer), iPlayer, tradeData, oldSet, TXT_KEY)
			if willTrade != oldSet:
				self.PrevAvailPeaceTrades = willTrade