Exemple #1
0
def getCurrentValuesByTeam():
    valuesByTeam = {}
    for team in PlayerUtil.teams(True, None, False):
        valuesByTeam[team.getID()] = values = []
        for targetTeam in PlayerUtil.teams():
            values.append(team.getEspionagePointsAgainstTeam(targetTeam.getID()))
    return valuesByTeam
Exemple #2
0
def onEmbargoRejected(argsList):
	#BugUtil.debug("DiplomacyUtil::onEmbargoRejected %s" %(str(argsList)))
	eTargetPlayer, eDemandPlayer, eVictim = argsList
	BugUtil.debug("DiplomacyUtil - %s rejects demand from %s to stop trading with %s",
			PlayerUtil.getPlayer(eTargetPlayer).getName(), 
			PlayerUtil.getPlayer(eDemandPlayer).getName(), 
			PlayerUtil.getPlayer(eVictim).getName())
Exemple #3
0
def isWillingToTalk(playerOrID, toPlayerOrID):
	"""
	Returns True if <player> is willing to talk to <toPlayer>.
	
	- Every player is willing to talk to themselves
	- All human players are willing to talk
	- Uses BUG DLL if present, otherwise scans attitude hover text
	  for "Refuses to Talk!!!" in the current language
	
	Note: This function does not check if the two players can make contact.
	"""
	playerID, player = PlayerUtil.getPlayerAndID(playerOrID)
	toPlayerID = PlayerUtil.getPlayerID(toPlayerOrID)
	# if playerID == toPlayerID or player.isHuman():
		# # all players talk to themselves, and all humans talk
		# return True
	# if BugDll.isPresent():
		# return player.AI_isWillingToTalk(toPlayerID)
	# else:
		# hover = AttitudeUtil.getAttitudeString(playerID, toPlayerID)
		# if hover:
			# return (hover.find(BugUtil.getPlainText("TXT_KEY_MISC_REFUSES_TO_TALK")) == -1)
		# else:
			# # haven't met yet
			# return False
	# K-Mod
	return playerID == toPlayerID or player.AI_isWillingToTalk(toPlayerID)
Exemple #4
0
def onWarDemanded(argsList):
	#BugUtil.debug("DiplomacyUtil::onWarDemanded %s" %(str(argsList)))
	eDemandPlayer, eTargetPlayer, eVictim = argsList
	BugUtil.debug("DiplomacyUtil - %s asks %s to declare war on %s",
			PlayerUtil.getPlayer(eDemandPlayer).getName(), 
			PlayerUtil.getPlayer(eTargetPlayer).getName(), 
			PlayerUtil.getPlayer(eVictim).getName())
Exemple #5
0
def onWarRejected(argsList):
	#BugUtil.debug("DiplomacyUtil::onWarRejected %s" %(str(argsList)))
	eTargetPlayer, eDemandPlayer, eVictim = argsList
	BugUtil.debug("DiplomacyUtil - %s rejects demand from %s to declare war on %s",
			PlayerUtil.getPlayer(eTargetPlayer).getName(), 
			PlayerUtil.getPlayer(eDemandPlayer).getName(), 
			PlayerUtil.getPlayer(eVictim).getName())
Exemple #6
0
def onReligionRejected(argsList):
	#BugUtil.debug("DiplomacyUtil::onReligionRejected %s" %(str(argsList)))
	eTargetPlayer, eDemandPlayer, eReligion = argsList
	BugUtil.debug("DiplomacyUtil - %s rejects demand from %s to convert to %s",
			PlayerUtil.getPlayer(eTargetPlayer).getName(), 
			PlayerUtil.getPlayer(eDemandPlayer).getName(), 
			gc.getReligionInfo(eReligion).getDescription())
Exemple #7
0
def onDealRejected(argsList):
	#BugUtil.debug("DiplomacyUtil::onDealRejected %s" %(str(argsList)))
	eTargetPlayer, eOfferPlayer, pTrade = argsList
	BugUtil.debug("DiplomacyUtil - %s accepts trade offered by %s: %r",
			PlayerUtil.getPlayer(eTargetPlayer).getName(),
			PlayerUtil.getPlayer(eOfferPlayer).getName(), 
			pTrade)
def isWorstEnemy(playerOrID, enemyOrID):
	"""
	Returns True if <enemy> is one of the worst enemies of <player>'s team.
	"""
	player, team = PlayerUtil.getPlayerAndTeam(playerOrID)
	enemy, enemyTeam = PlayerUtil.getPlayerAndTeam(enemyOrID)
	return not team.isHuman() and team.getID() != enemyTeam.getID() and getWorstEnemyTeam(player) == enemyTeam.getID()
Exemple #9
0
def onCivicRejected(argsList):
	#BugUtil.debug("DiplomacyUtil::onCivicRejected %s" %(str(argsList)))
	eTargetPlayer, eDemandPlayer, eCivic = argsList
	BugUtil.debug("DiplomacyUtil - %s rejects demand from %s to switch to %s",
			PlayerUtil.getPlayer(eTargetPlayer).getName(), 
			PlayerUtil.getPlayer(eDemandPlayer).getName(), 
			gc.getCivicInfo(eCivic).getDescription())
	def fillStratAdvGrid(self):
		self.iconGrid.clearData()
		self.iHumanKnowableUnits = UnitUtil.getKnowableUnits(self.iActivePlayer)
		self.iHumanUnits = UnitUtil.getTrainableUnits(self.iActivePlayer, self.iHumanKnowableUnits, True, True)
		#self.iHumanYesUnits, self.iHumanNoUnits = UnitUtil.getTrainableAndUntrainableUnits(self.iActivePlayer, self.iHumanKnowableUnits, True)
		BugUtil.debug("----------------------- fillStratAdvGrid start")
		self.iHumanObsoleteUnits = UnitUtil.findObsoleteUnits(self.iHumanUnits)
		for eUnit in self.iHumanObsoleteUnits:
			BugUtil.debug("  obs %s", gc.getUnitInfo(eUnit).getDescription())
		
		activePlayer, activeTeam = PlayerUtil.getPlayerAndTeam(self.iActivePlayer)
		iRow = 0
		for player in PlayerUtil.players(alive=True, barbarian=False, minor=False):
			ePlayer = player.getID()
			if (ePlayer != self.iActivePlayer
					and (activeTeam.isHasMet(player.getTeam()) or gc.getGame().isDebugMode())):
				self.iconGrid.appendRow(player.getCivilizationShortDescription(0), "", 3)
				
				# add leaderhead icon
				self.iconGrid.addIcon(iRow, self.SA_Col_Leader,
						gc.getLeaderHeadInfo(player.getLeaderType()).getButton(), 64, 
						WidgetTypes.WIDGET_LEADERHEAD, player.getID(), self.iActivePlayer)
				
				# add bonus and unit icons
				self.addStratAdvBonuses(activePlayer, player, iRow)
				self.addStratAdvUnits(activePlayer, player, iRow)
				
				iRow += 1
		
		BugUtil.debug("----------------------- fillStratAdvGrid end")
		self.iconGrid.refresh()
def getWorstEnemyTeams():
	"""
	Returns a dictionary of the team IDs that are each team's worst enemy.
	
	The key is team ID; the value is the worst enemy team ID.
	If a team has no worst enemy, -1 is stored as its value.
	Ignores dead, human, barbarian, and minor teams.
	
	Loops over players because CyTeam does not have getWorstEnemyName().
	"""
	namesToID = {}
	for team in PlayerUtil.teams(alive=True, barbarian=False, minor=False):
		namesToID[team.getName()] = team.getID()
	enemies = {}
	for team in PlayerUtil.teams(alive=True, human=False, barbarian=False, minor=False):
		eTeam = team.getID()
		eLeader = team.getLeaderID()
		if eLeader != -1:
			player = PlayerUtil.getPlayer(eLeader)
			worstEnemyName = player.getWorstEnemyName()
			if worstEnemyName:
				try:
					enemies[eTeam] = namesToID[worstEnemyName]
				except KeyError:
					BugUtil.debug("Cannot find team \"%s\"", worstEnemyName)
					enemies[eTeam] = -1
			else:
				enemies[eTeam] = -1
	return enemies
def printStatus(ePlayer, eAskingPlayer=None):
	player = PlayerUtil.getPlayer(ePlayer)
	if eAskingPlayer is None:
		eAskingPlayer = PlayerUtil.getActivePlayerID()
	print "Trade Status -- %s" % player.getCivilizationShortDescription(0)
	for eItem, name in STATUS_TRADE_ITEMS:
		tradeData = TradeData()
		tradeData.ItemType = eItem
		can = player.canTradeItem(eAskingPlayer, tradeData, False)
		denial = player.getTradeDenial(eAskingPlayer, tradeData)
		will = denial == DenialTypes.NO_DENIAL
		if denial in DENIALS:
			denial = DENIALS[denial]
		else:
			denial = str(denial)
		if not can:
			if will:
				print "%s: can't but will" % (name)
			else:
				print "%s: can't and won't because %s" % (name, denial)
		else:
			if will:
				print "%s: will" % (name)
			else:
				print "%s: won't because %s" % (name, denial)
Exemple #13
0
def onHelpOffered(argsList):
	#BugUtil.debug("DiplomacyUtil::onHelpOffered %s" %(str(argsList)))
	eOfferPlayer, eTargetPlayer, pTrade = argsList
	BugUtil.debug("DiplomacyUtil - %s offers help to %s: %r",
			PlayerUtil.getPlayer(eOfferPlayer).getName(), 
			PlayerUtil.getPlayer(eTargetPlayer).getName(),
			pTrade)
def onVassalOffered(argsList):
    # BugUtil.debug("DiplomacyUtil::onVassalOffered %s" %(str(argsList)))
    eOfferPlayer, eTargetPlayer = argsList
    BugUtil.debug(
        "DiplomacyUtil - %s offers vassalage to %s",
        PlayerUtil.getPlayer(eOfferPlayer).getCivilizationShortDescription(0),
        PlayerUtil.getPlayer(eTargetPlayer).getCivilizationShortDescription(0),
    )
def tradeParters(playerOrID):
	"""
	Iterates over all of <player>'s possible trade partners, yielding each CyPlayer in turn.
	"""
	player = PlayerUtil.getPlayer(playerOrID)
	for partner in PlayerUtil.players(alive=True, barbarian=False, minor=False):
		if canTrade(player, partner):
			yield partner
Exemple #16
0
def onDealCanceled(argsList):
	#BugUtil.debug("DiplomacyUtil::onDealCanceled %s" %(str(argsList)))
	eOfferPlayer, eTargetPlayer, pTrade = argsList
	if eOfferPlayer != -1 and eTargetPlayer != -1 and pTrade is not None:
		BugUtil.debug("DiplomacyUtil - %s cancels deal with %s: %r",
				PlayerUtil.getPlayer(eOfferPlayer).getName(), 
				PlayerUtil.getPlayer(eTargetPlayer).getName(),
				pTrade)
def onEmbargoAccepted(argsList):
    # BugUtil.debug("DiplomacyUtil::onEmbargoAccepted %s" %(str(argsList)))
    eTargetPlayer, eDemandPlayer, eVictim = argsList
    BugUtil.debug(
        "DiplomacyUtil - %s agrees to demand from %s to stop trading with %s",
        PlayerUtil.getPlayer(eTargetPlayer).getCivilizationShortDescription(0),
        PlayerUtil.getPlayer(eDemandPlayer).getCivilizationShortDescription(0),
        PlayerUtil.getPlayer(eVictim).getCivilizationShortDescription(0),
    )
def onHelpOffered(argsList):
    # BugUtil.debug("DiplomacyUtil::onHelpOffered %s" %(str(argsList)))
    eOfferPlayer, eTargetPlayer, pTrade = argsList
    BugUtil.debug(
        "DiplomacyUtil - %s offers help to %s: %r",
        PlayerUtil.getPlayer(eOfferPlayer).getCivilizationShortDescription(0),
        PlayerUtil.getPlayer(eTargetPlayer).getCivilizationShortDescription(0),
        pTrade,
    )
def onDealRejected(argsList):
    # BugUtil.debug("DiplomacyUtil::onDealRejected %s" %(str(argsList)))
    eTargetPlayer, eOfferPlayer, pTrade = argsList
    BugUtil.debug(
        "DiplomacyUtil - %s accepts trade offered by %s: %r",
        PlayerUtil.getPlayer(eTargetPlayer).getCivilizationShortDescription(0),
        PlayerUtil.getPlayer(eOfferPlayer).getCivilizationShortDescription(0),
        pTrade,
    )
def onReligionAccepted(argsList):
    # BugUtil.debug("DiplomacyUtil::onReligionAccepted %s" %(str(argsList)))
    eTargetPlayer, eDemandPlayer, eReligion = argsList
    BugUtil.debug(
        "DiplomacyUtil - %s accepts demand from %s to convert to %s",
        PlayerUtil.getPlayer(eTargetPlayer).getCivilizationShortDescription(0),
        PlayerUtil.getPlayer(eDemandPlayer).getCivilizationShortDescription(0),
        gc.getReligionInfo(eReligion).getDescription(),
    )
def onCivicAccepted(argsList):
    # BugUtil.debug("DiplomacyUtil::onCivicAccepted %s" %(str(argsList)))
    eTargetPlayer, eDemandPlayer, eCivic = argsList
    BugUtil.debug(
        "DiplomacyUtil - %s accepts demand from %s to switch to %s",
        PlayerUtil.getPlayer(eTargetPlayer).getCivilizationShortDescription(0),
        PlayerUtil.getPlayer(eDemandPlayer).getCivilizationShortDescription(0),
        gc.getCivicInfo(eCivic).getDescription(),
    )
Exemple #22
0
def getSpending(playerOrID, ActiveplayerOrID=None):
    if ActiveplayerOrID != None:
        pActiveTeam = PlayerUtil.getPlayerTeam(ActiveplayerOrID)

    iTotal = 0
    for targetTeam in PlayerUtil.teams(True, None, False):
        if ActiveplayerOrID == None or pActiveTeam.isHasMet(targetTeam.getID()):
            iTotal += getDifferenceByTeam(PlayerUtil.getPlayerTeam(playerOrID), targetTeam.getID())
    return iTotal
	def reset(self):
		"Clears state kept for each city."
		#DLP
		if CyGame().isPitbossHost():
			return
		self._beforeReset()
		player = PlayerUtil.getActivePlayer()
		for city in PlayerUtil.playerCities(player):
			self.resetCity(city)
	def checkAllActivePlayerCities(self):
		"Loops over active player's cities, telling each alert to perform its check."
		#DLP
		if CyGame().isPitbossHost():
			return
		ePlayer, player = PlayerUtil.getActivePlayerAndID()
		for city in PlayerUtil.playerCities(player):
			for alert in self.alerts:
				alert.checkCity(getCityId(city), city, ePlayer, player)
def onWarRejected(argsList):
    # BugUtil.debug("DiplomacyUtil::onWarRejected %s" %(str(argsList)))
    eTargetPlayer, eDemandPlayer, eVictim = argsList
    BugUtil.debug(
        "DiplomacyUtil - %s rejects demand from %s to declare war on %s",
        PlayerUtil.getPlayer(eTargetPlayer).getCivilizationShortDescription(0),
        PlayerUtil.getPlayer(eDemandPlayer).getCivilizationShortDescription(0),
        PlayerUtil.getPlayer(eVictim).getCivilizationShortDescription(0),
    )
Exemple #26
0
def onTributeDemanded(argsList):
	#BugUtil.debug("DiplomacyUtil::onTributeDemanded %s" %(str(argsList)))
	eDemandPlayer, eTargetPlayer, pTrade = argsList
	szItems = ""
	for i in range(pTrade.getCount()):
		szItems = szItems + TradeUtil.format(eTargetPlayer, pTrade.getTrade(i))
	BugUtil.debug("DiplomacyUtil - %s demands a tribute (%s) from %s",
			PlayerUtil.getPlayer(eDemandPlayer).getName(), 
			szItems,
			PlayerUtil.getPlayer(eTargetPlayer).getName())
Exemple #27
0
def onTributeRejected(argsList):
	#BugUtil.debug("DiplomacyUtil::onTributeRejected %s" %(str(argsList)))
	eTargetPlayer, eDemandPlayer, pTrade = argsList
	szItems = ""
	for i in range(pTrade.getCount()):
		szItems = szItems + TradeUtil.format(eTargetPlayer, pTrade.getTrade(i))
	BugUtil.debug("DiplomacyUtil - %s refuses to give tribute (%s) to %s",
			PlayerUtil.getPlayer(eTargetPlayer).getName(), 
			szItems,
			PlayerUtil.getPlayer(eDemandPlayer).getName())
Exemple #28
0
def onHelpAccepted(argsList):
	#BugUtil.debug("DiplomacyUtil::onHelpAccepted %s" %(str(argsList)))
	eTargetPlayer, eDemandPlayer, pTrade = argsList
	szItems = ""
	for i in range(pTrade.getCount()):
		szItems = szItems + TradeUtil.format(eTargetPlayer, pTrade.getTrade(i))
	BugUtil.debug("DiplomacyUtil - %s agrees to give help (%s) to %s",
			PlayerUtil.getPlayer(eTargetPlayer).getName(), 
			szItems,
			PlayerUtil.getPlayer(eDemandPlayer).getName())
Exemple #29
0
def getDifferenceByTeam(teamOrID, targetTeamOrID=None):
    eTeam, team = PlayerUtil.getTeamAndID(teamOrID)
    if targetTeamOrID is None:
        eTargetTeam = PlayerUtil.getActiveTeamID()
    else:
        eTargetTeam = PlayerUtil.getTeamID(targetTeamOrID)
    iPrevious = getPreviousValueByTeam(eTeam, eTargetTeam)
    if iPrevious is not None:
        return team.getEspionagePointsAgainstTeam(eTargetTeam) - iPrevious
    else:
        return 0
Exemple #30
0
	def check(self):
		if (not Civ4lertsOpt.isShowRefusesToTalkAlert()):
			return
		eActivePlayer, activePlayer = PlayerUtil.getActivePlayerAndID()
		refusals = self.refusals[eActivePlayer]
		newRefusals = set()
		for player in PlayerUtil.players(True, False, False, False):
			if DiplomacyUtil.canContact(activePlayer, player) and not DiplomacyUtil.isWillingToTalk(player, eActivePlayer):
				newRefusals.add(player.getID())
		self.display(eActivePlayer, "TXT_KEY_CIV4LERTS_ON_WILLING_TO_TALK", refusals.difference(newRefusals))
		self.display(eActivePlayer, "TXT_KEY_CIV4LERTS_ON_REFUSES_TO_TALK", newRefusals.difference(refusals))
		self.refusals[eActivePlayer] = newRefusals
Exemple #31
0
 def onPlayerChangeStateReligion(self, argsList):
     if isSilent(): return  # advc.127
     ePlayer, eNewReligion, eOldReligion = argsList
     self.checkIfIsAnyOrHasMetAllTeams(PlayerUtil.getPlayerTeamID(ePlayer))
Exemple #32
0
 def onCityRazed(self, argsList):
     if isSilent(): return  # advc.127
     city, ePlayer = argsList
     self.checkIfIsAnyOrHasMetAllTeams(
         PlayerUtil.getPlayerTeamID(city.getOwner()),
         PlayerUtil.getPlayerTeamID(ePlayer))
Exemple #33
0
 def check(self, silent=False):
     if self.isEnabled():
         gc.getPlayer(PlayerUtil.getActivePlayerID()).checkAlert(
             self.getID(), silent)
    def drawFinance(self):
        screen = self.getScreen()
        # Header...
        screen.setLabel(
            self.WIDGET_HEADER, "Background", u"<font=4b>" +
            localText.getText("TXT_KEY_ECONOMICS_ADVISOR_FINANCE_TAB",
                              ()).upper() + u"</font>",
            CvUtil.FONT_CENTER_JUSTIFY, self.X_SCREEN, self.Y_TITLE,
            self.Z_CONTROLS, FontTypes.TITLE_FONT, WidgetTypes.WIDGET_GENERAL,
            -1, -1)

        player = gc.getPlayer(self.iActiveLeader)

        # numCities = player.getNumCities()

        # K-Mod - I've changed these costs to include inflation.
        inflationFactor = 100 + player.getInflationRate()
        totalUnitCost = (player.calculateUnitCost() * inflationFactor +
                         50) / 100
        totalUnitSupply = (player.calculateUnitSupply() * inflationFactor +
                           50) / 100
        totalMaintenance = (player.getTotalMaintenance() * inflationFactor +
                            50) / 100
        totalCivicUpkeep = (
            player.getCivicUpkeep([], False) * inflationFactor + 50) / 100

        # totalPreInflatedCosts = player.calculatePreInflatedCosts()
        totalInflatedCosts = player.calculateInflatedCosts()
        goldCommerce = player.getCommerceRate(CommerceTypes.COMMERCE_GOLD)
        # if (not player.isCommerceFlexible(CommerceTypes.COMMERCE_RESEARCH)):
        # goldCommerce += player.calculateBaseNetResearch()
        gold = player.getGold()
        goldFromCivs = player.getGoldPerTurn()
        goldPerTurn = player.calculateGoldRate()

        szTreasuryPanel = self.getNextWidgetName()
        screen.addPanel(
            szTreasuryPanel, u"", "", True, True, self.X_LEFT_PANEL,
            self.Y_TOP_PANEL,
            self.X_RIGHT_PANEL + self.PANE_WIDTH - self.X_LEFT_PANEL,
            self.H_TOP_PANEL, PanelStyles.PANEL_STYLE_MAIN)
        szText = localText.getText("TXT_KEY_FINANCIAL_ADVISOR_TREASURY",
                                   (gold, )).upper()
        if gold < 0:
            if goldPerTurn != 0:
                if gold + goldPerTurn >= 0:
                    szText += BugUtil.getText("TXT_KEY_MISC_POS_GOLD_PER_TURN",
                                              goldPerTurn)
                elif goldPerTurn >= 0:
                    szText += BugUtil.getText(
                        "TXT_KEY_MISC_POS_WARNING_GOLD_PER_TURN", goldPerTurn)
                else:
                    szText += BugUtil.getText("TXT_KEY_MISC_NEG_GOLD_PER_TURN",
                                              goldPerTurn)
        else:
            if goldPerTurn != 0:
                if goldPerTurn >= 0:
                    szText += BugUtil.getText("TXT_KEY_MISC_POS_GOLD_PER_TURN",
                                              goldPerTurn)
                elif gold + goldPerTurn >= 0:
                    szText += BugUtil.getText(
                        "TXT_KEY_MISC_NEG_WARNING_GOLD_PER_TURN", goldPerTurn)
                else:
                    szText += BugUtil.getText("TXT_KEY_MISC_NEG_GOLD_PER_TURN",
                                              goldPerTurn)
        screen.setLabel(
            self.getNextWidgetName(), szTreasuryPanel,
            u"<font=4>" + szText + u"</font>", CvUtil.FONT_CENTER_JUSTIFY,
            (self.X_LEFT_PANEL + self.PANE_WIDTH + self.X_RIGHT_PANEL) / 2,
            self.Y_TOP_PANEL + self.H_TOP_PANEL / 2 - self.Y_SPACING / 2,
            self.Z_CONTROLS, FontTypes.TITLE_FONT,
            WidgetTypes.WIDGET_HELP_FINANCE_GOLD_RESERVE, -1, -1)

        szCommercePanel = self.getNextWidgetName()
        screen.addPanel(szCommercePanel, u"", "", True, True,
                        self.X_LEFT_PANEL, self.Y_LOCATION, self.PANE_WIDTH,
                        self.PANE_HEIGHT, PanelStyles.PANEL_STYLE_MAIN)
        screen.setLabel(
            self.getNextWidgetName(), "Background",
            u"<font=3>" + localText.getText("TXT_KEY_CONCEPT_COMMERCE",
                                            ()).upper() + u"</font>",
            CvUtil.FONT_CENTER_JUSTIFY,
            self.X_LEFT_PANEL + self.PANE_WIDTH / 2,
            self.Y_LOCATION + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
            FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

        szIncomePanel = self.getNextWidgetName()
        screen.addPanel(szIncomePanel, u"", "", True, True,
                        self.X_MIDDLE_PANEL, self.Y_LOCATION, self.PANE_WIDTH,
                        self.PANE_HEIGHT, PanelStyles.PANEL_STYLE_MAIN)
        screen.setLabel(
            self.getNextWidgetName(), "Background", u"<font=3>" +
            localText.getText("TXT_KEY_FINANCIAL_ADVISOR_INCOME_HEADER",
                              ()).upper() + u"</font>",
            CvUtil.FONT_CENTER_JUSTIFY,
            self.X_MIDDLE_PANEL + self.PANE_WIDTH / 2,
            self.Y_LOCATION + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
            FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

        szExpensePanel = self.getNextWidgetName()
        screen.addPanel(szExpensePanel, u"", "", True, True,
                        self.X_RIGHT_PANEL, self.Y_LOCATION, self.PANE_WIDTH,
                        self.PANE_HEIGHT, PanelStyles.PANEL_STYLE_MAIN)
        screen.setLabel(
            self.getNextWidgetName(), "Background", u"<font=3>" +
            localText.getText("TXT_KEY_FINANCIAL_ADVISOR_EXPENSES_HEADER",
                              ()).upper() + u"</font>",
            CvUtil.FONT_CENTER_JUSTIFY,
            self.X_RIGHT_PANEL + self.PANE_WIDTH / 2,
            self.Y_LOCATION + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
            FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

        # Commerce
        yLocation = self.Y_LOCATION
        iCommerce = 0

        # sum all worked tiles' commerce yields for player
        # move to MapUtil?
        iWorkedTileCount = 0
        iWorkedTiles = 0
        for city in PlayerUtil.playerCities(player):
            if not city.isDisorder():
                for i in xrange(gc.getNUM_CITY_PLOTS()):
                    plot = city.getCityIndexPlot(i)
                    if plot and not plot.isNone() and plot.hasYield():
                        if city.isWorkingPlot(plot):
                            iWorkedTileCount += 1
                            iWorkedTiles += plot.getYield(
                                YieldTypes.YIELD_COMMERCE)

        yLocation += 1.5 * self.Y_SPACING
        screen.setLabel(
            self.getNextWidgetName(), "Background",
            u"<font=3>" + localText.getText("TXT_KEY_CONCEPT_WORKED_TILES",
                                            (iWorkedTileCount, )) + "</font>",
            CvUtil.FONT_LEFT_JUSTIFY, self.X_LEFT_PANEL + self.TEXT_MARGIN,
            yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
            FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
        screen.setLabel(self.getNextWidgetName(), "Background",
                        u"<font=3>" + unicode(iWorkedTiles) + "</font>",
                        CvUtil.FONT_RIGHT_JUSTIFY,
                        self.X_LEFT_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
                        yLocation + self.TEXT_MARGIN,
                        self.Z_CONTROLS + self.DZ, FontTypes.GAME_FONT,
                        WidgetTypes.WIDGET_GENERAL, -1, -1)
        iCommerce += iWorkedTiles

        # trade
        iDomesticTrade, _, iForeignTrade, _ = TradeUtil.calculateTradeRoutes(
            player)

        if iDomesticTrade > 0:
            if TradeUtil.isFractionalTrade():
                iDomesticTrade //= 100
            yLocation += self.Y_SPACING
            screen.setLabel(
                self.getNextWidgetName(), "Background", u"<font=3>" +
                localText.getText("TXT_KEY_CONCEPT_DOMESTIC_TRADE",
                                  ()) + "</font>", CvUtil.FONT_LEFT_JUSTIFY,
                self.X_LEFT_PANEL + self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT,
                *BugDll.widget("WIDGET_HELP_FINANCE_DOMESTIC_TRADE",
                               self.iActiveLeader, 1))
            screen.setLabel(
                self.getNextWidgetName(), "Background",
                u"<font=3>" + unicode(iDomesticTrade) + "</font>",
                CvUtil.FONT_RIGHT_JUSTIFY,
                self.X_LEFT_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT,
                *BugDll.widget("WIDGET_HELP_FINANCE_DOMESTIC_TRADE",
                               self.iActiveLeader, 1))
            iCommerce += iDomesticTrade

        if iForeignTrade > 0:
            if TradeUtil.isFractionalTrade():
                iForeignTrade //= 100
            yLocation += self.Y_SPACING
            screen.setLabel(
                self.getNextWidgetName(), "Background", u"<font=3>" +
                localText.getText("TXT_KEY_CONCEPT_FOREIGN_TRADE",
                                  ()) + "</font>", CvUtil.FONT_LEFT_JUSTIFY,
                self.X_LEFT_PANEL + self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT,
                *BugDll.widget("WIDGET_HELP_FINANCE_FOREIGN_TRADE",
                               self.iActiveLeader, 1))
            screen.setLabel(
                self.getNextWidgetName(), "Background",
                u"<font=3>" + unicode(iForeignTrade) + "</font>",
                CvUtil.FONT_RIGHT_JUSTIFY,
                self.X_LEFT_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT,
                *BugDll.widget("WIDGET_HELP_FINANCE_FOREIGN_TRADE",
                               self.iActiveLeader, 1))
            iCommerce += iForeignTrade

        # corporations
        iCorporations = 0
        for city in PlayerUtil.playerCities(player):
            if not city.isDisorder():
                iCorporations += city.getCorporationYield(
                    YieldTypes.YIELD_COMMERCE)

        if iCorporations > 0:
            yLocation += self.Y_SPACING
            screen.setLabel(
                self.getNextWidgetName(), "Background",
                u"<font=3>" + localText.getText("TXT_KEY_CONCEPT_CORPORATIONS",
                                                ()) + "</font>",
                CvUtil.FONT_LEFT_JUSTIFY, self.X_LEFT_PANEL + self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
            screen.setLabel(
                self.getNextWidgetName(), "Background",
                u"<font=3>" + unicode(iCorporations) + "</font>",
                CvUtil.FONT_RIGHT_JUSTIFY,
                self.X_LEFT_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
            iCommerce += iCorporations

        # specialists
        iSpecialists = 0
        for city in PlayerUtil.playerCities(player):
            if not city.isDisorder():
                for eSpec in xrange(gc.getNumSpecialistInfos()):
                    iSpecialists += player.specialistYield(
                        eSpec, YieldTypes.YIELD_COMMERCE) * (
                            city.getSpecialistCount(eSpec) +
                            city.getFreeSpecialistCount(eSpec))

        if iSpecialists > 0:
            yLocation += self.Y_SPACING
            screen.setLabel(
                self.getNextWidgetName(), "Background",
                u"<font=3>" + localText.getText("TXT_KEY_CONCEPT_SPECIALISTS",
                                                ()) + "</font>",
                CvUtil.FONT_LEFT_JUSTIFY, self.X_LEFT_PANEL + self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
            screen.setLabel(
                self.getNextWidgetName(), "Background",
                u"<font=3>" + unicode(iSpecialists) + "</font>",
                CvUtil.FONT_RIGHT_JUSTIFY,
                self.X_LEFT_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
            iCommerce += iSpecialists

        # buildings
        iTotalCommerce = player.calculateTotalYield(YieldTypes.YIELD_COMMERCE)
        # buildings includes 50% capital bonus for Bureaucracy civic
        iBuildings = iTotalCommerce - iCommerce
        if iBuildings > 0:
            yLocation += self.Y_SPACING
            screen.setLabel(
                self.getNextWidgetName(), "Background",
                u"<font=3>" + localText.getText("TXT_KEY_CONCEPT_BUILDINGS",
                                                ()) + "</font>",
                CvUtil.FONT_LEFT_JUSTIFY, self.X_LEFT_PANEL + self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
            screen.setLabel(
                self.getNextWidgetName(), "Background",
                u"<font=3>" + unicode(iBuildings) + "</font>",
                CvUtil.FONT_RIGHT_JUSTIFY,
                self.X_LEFT_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
            iCommerce += iBuildings

        yLocation += 1.5 * self.Y_SPACING
        screen.setLabel(
            self.getNextWidgetName(), "Background", u"<font=3>" +
            localText.getText("TXT_KEY_BUG_FINANCIAL_ADVISOR_COMMERCE",
                              ()) + "</font>", CvUtil.FONT_LEFT_JUSTIFY,
            self.X_LEFT_PANEL + self.TEXT_MARGIN, yLocation + self.TEXT_MARGIN,
            self.Z_CONTROLS + self.DZ, FontTypes.GAME_FONT,
            WidgetTypes.WIDGET_GENERAL, -1, -1)
        screen.setLabel(self.getNextWidgetName(), "Background",
                        u"<font=3>" + unicode(iCommerce) + "</font>",
                        CvUtil.FONT_RIGHT_JUSTIFY,
                        self.X_LEFT_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
                        yLocation + self.TEXT_MARGIN,
                        self.Z_CONTROLS + self.DZ, FontTypes.GAME_FONT,
                        WidgetTypes.WIDGET_GENERAL, -1, -1)

        # Slider percentages

        yLocation += 0.5 * self.Y_SPACING
        for iI in xrange(CommerceTypes.NUM_COMMERCE_TYPES):
            eCommerce = (iI + 1) % CommerceTypes.NUM_COMMERCE_TYPES

            if (player.isCommerceFlexible(eCommerce)):
                yLocation += self.Y_SPACING
                screen.setButtonGFC(
                    self.getNextWidgetName(), u"", "",
                    self.X_LEFT_PANEL + self.TEXT_MARGIN,
                    int(yLocation) + self.TEXT_MARGIN, 20, 20,
                    WidgetTypes.WIDGET_CHANGE_PERCENT, eCommerce,
                    gc.getDefineINT("COMMERCE_PERCENT_CHANGE_INCREMENTS"),
                    ButtonStyles.BUTTON_STYLE_CITY_PLUS)
                screen.setButtonGFC(
                    self.getNextWidgetName(), u"", "",
                    self.X_LEFT_PANEL + self.TEXT_MARGIN + 24,
                    int(yLocation) + self.TEXT_MARGIN, 20, 20,
                    WidgetTypes.WIDGET_CHANGE_PERCENT, eCommerce,
                    -gc.getDefineINT("COMMERCE_PERCENT_CHANGE_INCREMENTS"),
                    ButtonStyles.BUTTON_STYLE_CITY_MINUS)

                szText = u"<font=3>" + gc.getCommerceInfo(
                    eCommerce).getDescription() + u" (" + unicode(
                        player.getCommercePercent(eCommerce)) + u"%)</font>"
                screen.setLabel(self.getNextWidgetName(), "Background", szText,
                                CvUtil.FONT_LEFT_JUSTIFY,
                                self.X_LEFT_PANEL + self.TEXT_MARGIN + 50,
                                yLocation + self.TEXT_MARGIN,
                                self.Z_CONTROLS + self.DZ, FontTypes.GAME_FONT,
                                WidgetTypes.WIDGET_GENERAL, -1, -1)
                szRate = u"<font=3>" + unicode(
                    player.getCommerceRate(
                        CommerceTypes(eCommerce))) + u"</font>"
                screen.setLabel(
                    self.getNextWidgetName(), "Background", szRate,
                    CvUtil.FONT_RIGHT_JUSTIFY,
                    self.X_LEFT_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
                    yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                    FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

        # K-Mod. Show gold rate if it hasn't been shown already
        if (not player.isCommerceFlexible(CommerceTypes.COMMERCE_GOLD)):
            yLocation += self.Y_SPACING
            szText = u"<font=3>" + gc.getCommerceInfo(
                CommerceTypes.COMMERCE_GOLD).getDescription(
                ) + u" (" + unicode(
                    player.getCommercePercent(
                        CommerceTypes.COMMERCE_GOLD)) + u"%)</font>"
            screen.setLabel(self.getNextWidgetName(), "Background", szText,
                            CvUtil.FONT_LEFT_JUSTIFY,
                            self.X_LEFT_PANEL + self.TEXT_MARGIN + 50,
                            yLocation + self.TEXT_MARGIN,
                            self.Z_CONTROLS + self.DZ, FontTypes.GAME_FONT,
                            WidgetTypes.WIDGET_GENERAL, -1, -1)
            szCommerce = u"<font=3>" + unicode(goldCommerce) + u"</font>"
            screen.setLabel(
                self.getNextWidgetName(), "Background", szCommerce,
                CvUtil.FONT_RIGHT_JUSTIFY,
                self.X_LEFT_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

        # Income
        yLocation = self.Y_LOCATION
        iTaxRate = player.getCommercePercent(CommerceTypes.COMMERCE_GOLD)

        multipliers = []
        for eBldg in xrange(gc.getNumBuildingInfos()):
            info = gc.getBuildingInfo(eBldg)
            iMultiplier = info.getCommerceModifier(CommerceTypes.COMMERCE_GOLD)
            if iMultiplier > 0:
                multipliers.append([eBldg, iMultiplier, 0, 0.0])

        iBuildingCount = 0
        iHeadquartersCount = 0
        iShrinesCount = 0
        fTaxes = 0.0
        fBuildings = 0.0
        fHeadquarters = 0.0
        fShrines = 0.0
        fCorporations = 0.0
        fSpecialists = 0.0
        iWealthCount = 0
        fWealth = 0.0
        eWealth = gc.getInfoTypeForString("PROCESS_WEALTH")
        # ignores
        #   CyCity.getReligionCommerce() -- excludes shrines
        #   CyPlayer.getFreeCityCommerce()
        #   CyPlayer.getSpecialistExtraCommerce() * (CyCity.getSpecialistPopulation() + CyCity.getNumGreatPeople())
        for city in PlayerUtil.playerCities(player):
            if not city.isDisorder():
                fCityTaxes = city.getYieldRate(
                    YieldTypes.YIELD_COMMERCE) * iTaxRate / 100.0
                fTaxes += fCityTaxes

                fCityBuildings = 0.0
                fCityHeadquarters = 0.0
                fCityShrines = 0.0
                for eBldg in xrange(gc.getNumBuildingInfos()):
                    iCount = city.getNumRealBuilding(eBldg)
                    if iCount > 0:
                        iBuildingGold = city.getBuildingCommerceByBuilding(
                            CommerceTypes.COMMERCE_GOLD, eBldg)
                        if iBuildingGold > 0:
                            info = gc.getBuildingInfo(eBldg)
                            if info.getFoundsCorporation() != -1:
                                fCityHeadquarters += iBuildingGold
                                iHeadquartersCount += 1
                            elif info.getGlobalReligionCommerce() != -1:
                                fCityShrines += iBuildingGold
                                iShrinesCount += 1
                            else:
                                fCityBuildings += iBuildingGold
                                iBuildingCount += iCount
                fBuildings += fCityBuildings
                fHeadquarters += fCityHeadquarters
                fShrines += fCityShrines

                fCityCorporations = city.getCorporationCommerce(
                    CommerceTypes.COMMERCE_GOLD)
                fCorporations += fCityCorporations

                fCitySpecialists = city.getSpecialistCommerce(
                    CommerceTypes.COMMERCE_GOLD)
                fSpecialists += fCitySpecialists

                fCityWealth = 0.0
                if city.isProductionProcess() and city.getProductionProcess(
                ) == eWealth:
                    fCityWealth = city.getProductionToCommerceModifier(
                        CommerceTypes.COMMERCE_GOLD) * city.getYieldRate(
                            YieldTypes.YIELD_PRODUCTION) / 100.0
                    fWealth += fCityWealth
                    iWealthCount += 1

                # buildings don't multiply wealth
                fCityTotel = fCityTaxes + fCityBuildings + fCityHeadquarters + fCityCorporations + fCitySpecialists
                for entry in multipliers:
                    eBldg, iMultiplier, _, _ = entry
                    iCount = city.getNumRealBuilding(eBldg)
                    if iCount > 0:
                        entry[2] += iCount
                        entry[3] += iCount * fCityTotel * iMultiplier / 100.0

        # K-Mod, karadoc
        # The 'total minus taxes' was wrong. We don't need to use that anyway
        # I've changed the 'taxes' output to use fTaxes instead of goldcommerce - totalminustaxes
        ##
        #iTotalMinusTaxes = int(fBuildings) + int(fCorporations) + int(fSpecialists) + int(fWealth)
        #for _, _, _, fGold in multipliers:
        #    iTotalMinusTaxes += int(fGold)

        yLocation += 1.5 * self.Y_SPACING
        screen.setLabel(
            self.getNextWidgetName(), "Background",
            u"<font=3>" + localText.getText("TXT_KEY_FINANCIAL_ADVISOR_TAXES",
                                            ()) + "</font>",
            CvUtil.FONT_LEFT_JUSTIFY, self.X_MIDDLE_PANEL + self.TEXT_MARGIN,
            yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
            FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
        screen.setLabel(
            self.getNextWidgetName(), "Background",
            u"<font=3>" + unicode(int(fTaxes)) + "</font>",
            CvUtil.FONT_RIGHT_JUSTIFY,
            self.X_MIDDLE_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
            yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
            FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

        if fBuildings > 0.0:
            yLocation += self.Y_SPACING
            screen.setLabel(
                self.getNextWidgetName(), "Background", u"<font=3>" +
                localText.getText("TXT_KEY_CONCEPT_BUILDINGS",
                                  ()) + " (%d)</font>" % iBuildingCount,
                CvUtil.FONT_LEFT_JUSTIFY,
                self.X_MIDDLE_PANEL + self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
            screen.setLabel(
                self.getNextWidgetName(), "Background",
                u"<font=3>" + unicode(int(fBuildings)) + "</font>",
                CvUtil.FONT_RIGHT_JUSTIFY,
                self.X_MIDDLE_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

        if fHeadquarters > 0.0:
            yLocation += self.Y_SPACING
            screen.setLabel(
                self.getNextWidgetName(), "Background", u"<font=3>" +
                localText.getText("TXT_KEY_CORPORATION_HEADQUARTERS",
                                  ()) + " (%d)</font>" % iHeadquartersCount,
                CvUtil.FONT_LEFT_JUSTIFY,
                self.X_MIDDLE_PANEL + self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
            screen.setLabel(
                self.getNextWidgetName(), "Background",
                u"<font=3>" + unicode(int(fHeadquarters)) + "</font>",
                CvUtil.FONT_RIGHT_JUSTIFY,
                self.X_MIDDLE_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

        if fCorporations > 0.0:
            yLocation += self.Y_SPACING
            screen.setLabel(
                self.getNextWidgetName(), "Background",
                u"<font=3>" + localText.getText("TXT_KEY_CONCEPT_CORPORATIONS",
                                                ()) + "</font>",
                CvUtil.FONT_LEFT_JUSTIFY,
                self.X_MIDDLE_PANEL + self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
            screen.setLabel(
                self.getNextWidgetName(), "Background",
                u"<font=3>" + unicode(int(fCorporations)) + "</font>",
                CvUtil.FONT_RIGHT_JUSTIFY,
                self.X_MIDDLE_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

        if fShrines > 0.0:
            yLocation += self.Y_SPACING
            screen.setLabel(
                self.getNextWidgetName(), "Background", u"<font=3>" +
                localText.getText("TXT_KEY_CONCEPT_RELIGIOUS_SHRINES",
                                  ()) + " (%d)</font>" % iShrinesCount,
                CvUtil.FONT_LEFT_JUSTIFY,
                self.X_MIDDLE_PANEL + self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
            screen.setLabel(
                self.getNextWidgetName(), "Background",
                u"<font=3>" + unicode(int(fShrines)) + "</font>",
                CvUtil.FONT_RIGHT_JUSTIFY,
                self.X_MIDDLE_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

        if fSpecialists > 0.0:
            yLocation += self.Y_SPACING
            screen.setLabel(
                self.getNextWidgetName(), "Background",
                u"<font=3>" + localText.getText("TXT_KEY_CONCEPT_SPECIALISTS",
                                                ()) + "</font>",
                CvUtil.FONT_LEFT_JUSTIFY,
                self.X_MIDDLE_PANEL + self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT,
                *BugDll.widget("WIDGET_HELP_FINANCE_SPECIALISTS",
                               self.iActiveLeader, 1))
            screen.setLabel(
                self.getNextWidgetName(), "Background",
                u"<font=3>" + unicode(int(fSpecialists)) + "</font>",
                CvUtil.FONT_RIGHT_JUSTIFY,
                self.X_MIDDLE_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT,
                *BugDll.widget("WIDGET_HELP_FINANCE_SPECIALISTS",
                               self.iActiveLeader, 1))

        for eBldg, iMultiplier, iCount, fGold in multipliers:
            if iCount > 0 and fGold > 0.0:
                fAverage = fGold / iCount
                szDescription = gc.getBuildingInfo(
                    eBldg).getDescription() + u" " + localText.getText(
                        "TXT_KEY_BUG_FINANCIAL_ADVISOR_BUILDING_COUNT_AVERAGE",
                        (iCount, BugUtil.formatFloat(fAverage, 2)))
                yLocation += self.Y_SPACING
                screen.setLabel(self.getNextWidgetName(), "Background",
                                u"<font=3>" + szDescription + "</font>",
                                CvUtil.FONT_LEFT_JUSTIFY,
                                self.X_MIDDLE_PANEL + self.TEXT_MARGIN,
                                yLocation + self.TEXT_MARGIN,
                                self.Z_CONTROLS + self.DZ, FontTypes.GAME_FONT,
                                WidgetTypes.WIDGET_GENERAL, -1, -1)
                screen.setLabel(
                    self.getNextWidgetName(), "Background",
                    u"<font=3>" + unicode(int(fGold)) + "</font>",
                    CvUtil.FONT_RIGHT_JUSTIFY,
                    self.X_MIDDLE_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
                    yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                    FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

        if fWealth > 0.0 and iWealthCount > 0:
            yLocation += self.Y_SPACING
            screen.setLabel(
                self.getNextWidgetName(), "Background",
                u"<font=3>" + localText.getText("TXT_KEY_PROCESS_WEALTH", ()) +
                " (%d)</font>" % iWealthCount, CvUtil.FONT_LEFT_JUSTIFY,
                self.X_MIDDLE_PANEL + self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
            screen.setLabel(
                self.getNextWidgetName(), "Background",
                u"<font=3>" + unicode(int(fWealth)) + "</font>",
                CvUtil.FONT_RIGHT_JUSTIFY,
                self.X_MIDDLE_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

        iIncome = goldCommerce
        if (goldFromCivs > 0):
            yLocation += self.Y_SPACING
            szText = unicode(goldFromCivs) + " : " + localText.getText(
                "TXT_KEY_FINANCIAL_ADVISOR_PER_TURN", ())
            screen.setLabel(
                self.getNextWidgetName(), "Background", u"<font=3>" +
                localText.getText("TXT_KEY_FINANCIAL_ADVISOR_PER_TURN",
                                  ()) + "</font>", CvUtil.FONT_LEFT_JUSTIFY,
                self.X_MIDDLE_PANEL + self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT,
                WidgetTypes.WIDGET_HELP_FINANCE_FOREIGN_INCOME,
                self.iActiveLeader, 1)
            screen.setLabel(
                self.getNextWidgetName(), "Background",
                u"<font=3>" + unicode(goldFromCivs) + "</font>",
                CvUtil.FONT_RIGHT_JUSTIFY,
                self.X_MIDDLE_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT,
                WidgetTypes.WIDGET_HELP_FINANCE_FOREIGN_INCOME,
                self.iActiveLeader, 1)
            iIncome += goldFromCivs

        yLocation += 1.5 * self.Y_SPACING
        screen.setLabel(
            self.getNextWidgetName(), "Background",
            u"<font=3>" + localText.getText("TXT_KEY_FINANCIAL_ADVISOR_INCOME",
                                            ()) + "</font>",
            CvUtil.FONT_LEFT_JUSTIFY, self.X_MIDDLE_PANEL + self.TEXT_MARGIN,
            yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
            FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
        screen.setLabel(
            self.getNextWidgetName(), "Background",
            u"<font=3>" + unicode(iIncome) + "</font>",
            CvUtil.FONT_RIGHT_JUSTIFY,
            self.X_MIDDLE_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
            yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
            FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

        # Expenses
        yLocation = self.Y_LOCATION
        iExpenses = 0

        yLocation += 1.5 * self.Y_SPACING
        screen.setLabel(
            self.getNextWidgetName(), "Background", u"<font=3>" +
            localText.getText("TXT_KEY_FINANCIAL_ADVISOR_UNITCOST",
                              ()) + u"</font>", CvUtil.FONT_LEFT_JUSTIFY,
            self.X_RIGHT_PANEL + self.TEXT_MARGIN,
            yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
            FontTypes.GAME_FONT, WidgetTypes.WIDGET_HELP_FINANCE_UNIT_COST,
            self.iActiveLeader, 1)
        screen.setLabel(
            self.getNextWidgetName(), "Background",
            u"<font=3>" + unicode(totalUnitCost) + u"</font>",
            CvUtil.FONT_RIGHT_JUSTIFY,
            self.X_RIGHT_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
            yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
            FontTypes.GAME_FONT, WidgetTypes.WIDGET_HELP_FINANCE_UNIT_COST,
            self.iActiveLeader, 1)
        iExpenses += totalUnitCost

        yLocation += self.Y_SPACING
        screen.setLabel(
            self.getNextWidgetName(), "Background", u"<font=3>" +
            localText.getText("TXT_KEY_FINANCIAL_ADVISOR_UNITSUPPLY",
                              ()) + "</font>", CvUtil.FONT_LEFT_JUSTIFY,
            self.X_RIGHT_PANEL + self.TEXT_MARGIN,
            yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
            FontTypes.GAME_FONT, WidgetTypes.WIDGET_HELP_FINANCE_AWAY_SUPPLY,
            self.iActiveLeader, 1)
        screen.setLabel(
            self.getNextWidgetName(), "Background",
            u"<font=3>" + unicode(totalUnitSupply) + "</font>",
            CvUtil.FONT_RIGHT_JUSTIFY,
            self.X_RIGHT_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
            yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
            FontTypes.GAME_FONT, WidgetTypes.WIDGET_HELP_FINANCE_AWAY_SUPPLY,
            self.iActiveLeader, 1)
        iExpenses += totalUnitSupply

        yLocation += self.Y_SPACING
        screen.setLabel(
            self.getNextWidgetName(), "Background", u"<font=3>" +
            localText.getText("TXT_KEY_FINANCIAL_ADVISOR_MAINTENANCE",
                              ()) + "</font>", CvUtil.FONT_LEFT_JUSTIFY,
            self.X_RIGHT_PANEL + self.TEXT_MARGIN,
            yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
            FontTypes.GAME_FONT, WidgetTypes.WIDGET_HELP_FINANCE_CITY_MAINT,
            self.iActiveLeader, 1)
        screen.setLabel(
            self.getNextWidgetName(), "Background",
            u"<font=3>" + unicode(totalMaintenance) + "</font>",
            CvUtil.FONT_RIGHT_JUSTIFY,
            self.X_RIGHT_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
            yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
            FontTypes.GAME_FONT, WidgetTypes.WIDGET_HELP_FINANCE_CITY_MAINT,
            self.iActiveLeader, 1)
        iExpenses += totalMaintenance

        yLocation += self.Y_SPACING
        screen.setLabel(
            self.getNextWidgetName(), "Background",
            u"<font=3>" + localText.getText("TXT_KEY_FINANCIAL_ADVISOR_CIVICS",
                                            ()) + "</font>",
            CvUtil.FONT_LEFT_JUSTIFY, self.X_RIGHT_PANEL + self.TEXT_MARGIN,
            yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
            FontTypes.GAME_FONT, WidgetTypes.WIDGET_HELP_FINANCE_CIVIC_UPKEEP,
            self.iActiveLeader, 1)
        screen.setLabel(
            self.getNextWidgetName(), "Background",
            u"<font=3>" + unicode(totalCivicUpkeep) + "</font>",
            CvUtil.FONT_RIGHT_JUSTIFY,
            self.X_RIGHT_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
            yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
            FontTypes.GAME_FONT, WidgetTypes.WIDGET_HELP_FINANCE_CIVIC_UPKEEP,
            self.iActiveLeader, 1)
        iExpenses += totalCivicUpkeep

        if (goldFromCivs < 0):
            yLocation += self.Y_SPACING
            screen.setLabel(
                self.getNextWidgetName(), "Background", u"<font=3>" +
                localText.getText("TXT_KEY_FINANCIAL_ADVISOR_COST_PER_TURN",
                                  ()) + "</font>", CvUtil.FONT_LEFT_JUSTIFY,
                self.X_RIGHT_PANEL + self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT,
                WidgetTypes.WIDGET_HELP_FINANCE_FOREIGN_INCOME,
                self.iActiveLeader, 1)
            screen.setLabel(
                self.getNextWidgetName(), "Background",
                u"<font=3>" + unicode(-goldFromCivs) + "</font>",
                CvUtil.FONT_RIGHT_JUSTIFY,
                self.X_RIGHT_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
                yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
                FontTypes.GAME_FONT,
                WidgetTypes.WIDGET_HELP_FINANCE_FOREIGN_INCOME,
                self.iActiveLeader, 1)
            iExpenses -= goldFromCivs

        # yLocation += self.Y_SPACING
        # iInflation = totalInflatedCosts - totalPreInflatedCosts
        # screen.setLabel(self.getNextWidgetName(), "Background", u"<font=3>(" + localText.getText("TXT_KEY_FINANCIAL_ADVISOR_INFLATION", ()) + "</font>", CvUtil.FONT_LEFT_JUSTIFY, self.X_RIGHT_PANEL + self.TEXT_MARGIN, yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ, FontTypes.GAME_FONT, WidgetTypes.WIDGET_HELP_FINANCE_INFLATED_COSTS, self.iActiveLeader, 1)
        # screen.setLabel(self.getNextWidgetName(), "Background", u"<font=3>" + unicode(iInflation) + ")</font>", CvUtil.FONT_RIGHT_JUSTIFY, self.X_RIGHT_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN, yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ, FontTypes.GAME_FONT, WidgetTypes.WIDGET_HELP_FINANCE_INFLATED_COSTS, self.iActiveLeader, 1)
        # iExpenses += iInflation

        yLocation += 1.5 * self.Y_SPACING
        screen.setLabel(
            self.getNextWidgetName(), "Background", u"<font=3>" +
            localText.getText("TXT_KEY_FINANCIAL_ADVISOR_EXPENSES",
                              ()) + "</font>", CvUtil.FONT_LEFT_JUSTIFY,
            self.X_RIGHT_PANEL + self.TEXT_MARGIN,
            yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
            FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
        #screen.setLabel(self.getNextWidgetName(), "Background", u"<font=3>" + unicode(iExpenses) + "</font>", CvUtil.FONT_RIGHT_JUSTIFY, self.X_RIGHT_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN, yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ, FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )
        screen.setLabel(
            self.getNextWidgetName(), "Background",
            u"<font=3>" + unicode(totalInflatedCosts) + "</font>",
            CvUtil.FONT_RIGHT_JUSTIFY,
            self.X_RIGHT_PANEL + self.PANE_WIDTH - self.TEXT_MARGIN,
            yLocation + self.TEXT_MARGIN, self.Z_CONTROLS + self.DZ,
            FontTypes.GAME_FONT,
            WidgetTypes.WIDGET_HELP_FINANCE_INFLATED_COSTS, self.iActiveLeader,
            1)

        return 0
Exemple #35
0
 def onEmbargoAccepted(self, argsList):
     if isSilent(): return  # advc.127
     eOfferPlayer, eTargetPlayer, pTrade = argsList
     self.checkIfIsAnyOrHasMetAllTeams(
         PlayerUtil.getPlayerTeamID(eOfferPlayer),
         PlayerUtil.getPlayerTeamID(eTargetPlayer))
Exemple #36
0
 def onCityRazed(self, argsList):
     city, ePlayer = argsList
     self.checkIfIsAnyOrHasMetAllTeams(
         PlayerUtil.getPlayerTeamID(city.getOwner()),
         PlayerUtil.getPlayerTeamID(ePlayer))
Exemple #37
0
def getTradeUnits(player, trade):
	return PlayerUtil.getPlayer(player).getUnit(trade.iData).getName()
Exemple #38
0
def getTradePlayer(player, trade):
    return PlayerUtil.getPlayer(trade.iData).getName()
Exemple #39
0
 def onPlayerChangeStateReligion(self, argsList):
     ePlayer, eNewReligion, eOldReligion = argsList
     self.checkIfIsAnyOrHasMetAllTeams(PlayerUtil.getPlayerTeamID(ePlayer))
Exemple #40
0
 def reset(self):
     "Clears state kept for each city."
     self._beforeReset()
     player = PlayerUtil.getActivePlayer()
     for city in PlayerUtil.playerCities(player):
         self.resetCity(city)
Exemple #41
0
 def checkAllActivePlayerCities(self):
     "Loops over active player's cities, telling each alert to perform its check."
     ePlayer, player = PlayerUtil.getActivePlayerAndID()
     for city in PlayerUtil.playerCities(player):
         for alert in self.alerts:
             alert.checkCity(getCityId(city), city, ePlayer, player)
Exemple #42
0
 def onDealCanceled(self, argsList):
     eOfferPlayer, eTargetPlayer, pTrade = argsList
     self.checkIfIsAnyOrHasMetAllTeams(
         PlayerUtil.getPlayerTeamID(eOfferPlayer),
         PlayerUtil.getPlayerTeamID(eTargetPlayer))
Exemple #43
0
 def onEmbargoAccepted(self, argsList):
     eOfferPlayer, eTargetPlayer, pTrade = argsList
     self.checkIfIsAnyOrHasMetAllTeams(
         PlayerUtil.getPlayerTeamID(eOfferPlayer),
         PlayerUtil.getPlayerTeamID(eTargetPlayer))
Exemple #44
0
 def _reset(self):
     self.refusals = {}
     for player in PlayerUtil.players():
         self.refusals[player.getID()] = set()
def addEvents(eventManager):
    """Adds the diplomacy events to BugEventManager."""
    global g_eventManager
    g_eventManager = eventManager

    # Trade
    DiploEvent("AI_DIPLOCOMMENT_OFFER_DEAL",
               "DealOffered",
               onDealOffered,
               sendTrade=True)
    DiploEvent("AI_DIPLOCOMMENT_CANCEL_DEAL",
               "DealCanceled",
               onDealCanceled,
               sendTrade=True)
    DiploEvent("USER_DIPLOCOMMENT_ACCEPT_OFFER",
               "DealAccepted",
               onDealAccepted,
               sendTrade=True)
    DiploEvent("USER_DIPLOCOMMENT_REJECT_OFFER",
               "DealRejected",
               onDealRejected,
               sendTrade=True)

    # Free Stuff
    DiploEvent("AI_DIPLOCOMMENT_OFFER_CITY",
               "CityOffered",
               onCityOffered,
               tradeType=TradeableItems.TRADE_CITIES)
    DiploEvent("AI_DIPLOCOMMENT_GIVE_HELP",
               "HelpOffered",
               onHelpOffered,
               sendTrade=True)
    DiploEvent("AI_DIPLOCOMMENT_OFFER_PEACE", "PeaceOffered", onPeaceOffered)
    DiploEvent("AI_DIPLOCOMMENT_OFFER_VASSAL", "VassalOffered",
               onVassalOffered)

    # Ask for Help
    DiploEvent("AI_DIPLOCOMMENT_ASK_FOR_HELP",
               "HelpDemanded",
               onHelpDemanded,
               sendTrade=True)
    DiploEvent("USER_DIPLOCOMMENT_GIVE_HELP",
               "HelpAccepted",
               onHelpAccepted,
               sendTrade=True)
    DiploEvent("USER_DIPLOCOMMENT_REFUSE_HELP",
               "HelpRejected",
               onHelpRejected,
               sendTrade=True)

    # Demand Tribute
    DiploEvent("AI_DIPLOCOMMENT_DEMAND_TRIBUTE",
               "TributeDemanded",
               onTributeDemanded,
               sendTrade=True)
    DiploEvent("USER_DIPLOCOMMENT_ACCEPT_DEMAND",
               "TributeAccepted",
               onTributeAccepted,
               sendTrade=True)
    DiploEvent("USER_DIPLOCOMMENT_REJECT_DEMAND",
               "TributeRejected",
               onTributeRejected,
               sendTrade=True)

    # Religion
    DiploEvent("AI_DIPLOCOMMENT_RELIGION_PRESSURE",
               "ReligionDemanded",
               onReligionDemanded,
               argFunc=lambda eFromPlayer, eToPlayer, args, data:
               (PlayerUtil.getStateReligion(eFromPlayer), ))
    DiploEvent("USER_DIPLOCOMMENT_CONVERT",
               "ReligionAccepted",
               onReligionAccepted,
               argFunc=lambda eFromPlayer, eToPlayer, args, data:
               (PlayerUtil.getStateReligion(eToPlayer), ))
    DiploEvent("USER_DIPLOCOMMENT_NO_CONVERT",
               "ReligionRejected",
               onReligionRejected,
               argFunc=lambda eFromPlayer, eToPlayer, args, data:
               (PlayerUtil.getStateReligion(eToPlayer), ))

    # Civic
    DiploEvent("AI_DIPLOCOMMENT_CIVIC_PRESSURE",
               "CivicDemanded",
               onCivicDemanded,
               argFunc=lambda eFromPlayer, eToPlayer, args, data:
               (PlayerUtil.getFavoriteCivic(eFromPlayer), ))
    DiploEvent("USER_DIPLOCOMMENT_REVOLUTION",
               "CivicAccepted",
               onCivicAccepted,
               argFunc=lambda eFromPlayer, eToPlayer, args, data:
               (PlayerUtil.getFavoriteCivic(eToPlayer), ))
    DiploEvent("USER_DIPLOCOMMENT_NO_REVOLUTION",
               "CivicRejected",
               onCivicRejected,
               argFunc=lambda eFromPlayer, eToPlayer, args, data:
               (PlayerUtil.getFavoriteCivic(eToPlayer), ))

    # Join War
    DiploEvent("AI_DIPLOCOMMENT_JOIN_WAR",
               "WarDemanded",
               onWarDemanded,
               sendData=True)
    DiploEvent("USER_DIPLOCOMMENT_JOIN_WAR",
               "WarAccepted",
               onWarAccepted,
               sendData=True)
    DiploEvent("USER_DIPLOCOMMENT_NO_JOIN_WAR",
               "WarRejected",
               onWarRejected,
               sendData=True)

    # Trade Embargo
    DiploEvent("AI_DIPLOCOMMENT_STOP_TRADING",
               "EmbargoDemanded",
               onEmbargoDemanded,
               sendData=True)
    DiploEvent("USER_DIPLOCOMMENT_STOP_TRADING",
               "EmbargoAccepted",
               onEmbargoAccepted,
               sendData=True)
    DiploEvent("USER_DIPLOCOMMENT_NO_STOP_TRADING",
               "EmbargoRejected",
               onEmbargoRejected,
               sendData=True)
def doUpdate():
    """ Goes through the current diplomacy situation to determine potential favorite civics for each civ. """
    if gDetectionNecessary:
        BugUtil.debug("FavoriteCivicDetector.doUpdate() START")
        pActivePlayer = gc.getActivePlayer()
        pActiveTeam = gc.getTeam(pActivePlayer.getTeam())
        for iPlayer in range(gc.getMAX_PLAYERS()):
            pPlayer = gc.getPlayer(iPlayer)
            # Player we are updating must be a valid, living, non-human, full-fledged civ.
            if (pPlayer and (not pPlayer.isNone()) and pPlayer.isAlive()
                    and (not pPlayer.isHuman()) and (not pPlayer.isBarbarian())
                    and (not pPlayer.isMinorCiv())):
                BugUtil.debug("Updating Info for Player %d (%s)" %
                              (iPlayer, pPlayer.getName()))
                iTeam = pPlayer.getTeam()
                pTeam = gc.getTeam(iTeam)
                # Team assumed valid, living, etc. since the player was.
                if (not pActiveTeam.isHasMet(iTeam)):
                    BugUtil.debug(
                        " -- Skipping; active team has not met team we are updating"
                    )
                    continue
                favorite = gFavoriteByPlayer[iPlayer]
                # Check Diplomacy first (if necessary)
                if not favorite.isKnown():
                    if PlayerUtil.isGivingFavoriteCivicDenial(
                            pPlayer, pActivePlayer):
                        BugUtil.debug(
                            " -- Player showing FAVORITE_CIVIC trade denial; must be running his/her favorite."
                        )
                        for eCategory in range(gc.getNumCivicOptionInfos()):
                            eCivic = pPlayer.getCivics(eCategory)
                            for eOtherCivic in gCivicsByCategory[eCategory]:
                                if (eOtherCivic != eCivic):
                                    favorite.removePossible(eOtherCivic)
                # Now take Attitude survey (if necessary)
                if not favorite.isKnown():
                    for iOtherPlayer in range(gc.getMAX_PLAYERS()):
                        pOtherPlayer = gc.getPlayer(iOtherPlayer)
                        # Test attitude against other valid, living, full-fledged civs; these can be human
                        if (pOtherPlayer and (iOtherPlayer != iPlayer)
                                and (not pOtherPlayer.isNone())
                                and pOtherPlayer.isAlive()
                                and (not pOtherPlayer.isBarbarian())
                                and (not pOtherPlayer.isMinorCiv())):
                            BugUtil.debug(
                                " -- Testing against Player %d (%s)" %
                                (iOtherPlayer, pOtherPlayer.getName()))
                            iOtherTeam = pOtherPlayer.getTeam()
                            if ((not pActiveTeam.isHasMet(iOtherTeam))
                                    or (not pTeam.isHasMet(iOtherTeam))):
                                BugUtil.debug(
                                    "     -- Skipping; either active team or updating team has not met test team"
                                )
                                continue
                            pAttitude = AttitudeUtil.Attitude(
                                iPlayer, iOtherPlayer)
                            bFoundPossibleFavorite = pAttitude.hasModifier(
                                "TXT_KEY_MISC_ATTITUDE_FAVORITE_CIVIC")
                            for eCategory in range(
                                    gc.getNumCivicOptionInfos()):
                                eCivic = pPlayer.getCivics(eCategory)
                                if (eCivic == pOtherPlayer.getCivics(eCategory)
                                    ):
                                    if bFoundPossibleFavorite:
                                        BugUtil.debug(
                                            "     -- Players share civic %d (%s) and %s is giving the diplo modifier."
                                            %
                                            (eCivic,
                                             gc.getCivicInfo(eCivic).getText(),
                                             pPlayer.getName()))
                                        BugUtil.debug(
                                            "         -- This is the only possible favorite in category %d (%s)."
                                            % (eCategory,
                                               gc.getCivicOptionInfo(
                                                   eCategory).getText()))
                                        for eOtherCivic in gCivicsByCategory[
                                                eCategory]:
                                            if (eOtherCivic != eCivic):
                                                favorite.removePossible(
                                                    eOtherCivic)
                                    else:
                                        BugUtil.debug(
                                            "     -- Players share civic %d (%s) but %s is NOT giving the diplo modifier."
                                            %
                                            (eCivic,
                                             gc.getCivicInfo(eCivic).getText(),
                                             pPlayer.getName()))
                                        BugUtil.debug(
                                            "         -- This one must be ruled out as a possible favorite."
                                        )
                                        favorite.removePossible(eCivic)
                                else:
                                    if bFoundPossibleFavorite:
                                        BugUtil.debug(
                                            "     -- Players do NOT share civic %d (%s) but %s is giving the diplo modifier."
                                            %
                                            (eCivic,
                                             gc.getCivicInfo(eCivic).getText(),
                                             pPlayer.getName()))
                                        BugUtil.debug(
                                            "         -- All civics in category %d (%s) must be ruled out."
                                            % (eCategory,
                                               gc.getCivicOptionInfo(
                                                   eCategory).getText()))
                                        for eOtherCivic in gCivicsByCategory[
                                                eCategory]:
                                            favorite.removePossible(
                                                eOtherCivic)
                                    else:
                                        BugUtil.debug(
                                            "     -- Players do NOT share civic %d (%s) and %s is NOT giving the diplo modifier."
                                            %
                                            (eCivic,
                                             gc.getCivicInfo(eCivic).getText(),
                                             pPlayer.getName()))
                                        BugUtil.debug(
                                            "         -- This doesn't tell us anything new."
                                        )
                BugUtil.debug(" -- Finished update for %s: %s" %
                              (pPlayer.getName(), str(favorite)))
Exemple #47
0
 def check(self):
     if (not Civ4lertsOpt.isShowWorstEnemyAlert()):
         return
     eActivePlayer = PlayerUtil.getActivePlayerID()
     eActiveTeam, activeTeam = PlayerUtil.getActiveTeamAndID()
     enemies = self.enemies[eActivePlayer]
     newEnemies = AttitudeUtil.getWorstEnemyTeams()
     delayedMessages = {}
     for eTeam, eNewEnemy in newEnemies.iteritems():
         if activeTeam.isHasMet(eTeam):
             eOldEnemy = enemies[eTeam]
             if eOldEnemy != -1 and not gc.getTeam(eOldEnemy).isAlive():
                 eOldEnemy = -1
                 enemies[eTeam] = -1
             #if eActiveTeam != eNewEnemy and not activeTeam.isHasMet(eNewEnemy):
             if eNewEnemy != -1 and not activeTeam.isHasMet(
                     eNewEnemy
             ):  # K-Mod. (isHasMet(-1) could cause a seg-fault.)
                 eNewEnemy = -1
             if eOldEnemy != eNewEnemy:
                 enemies[eTeam] = eNewEnemy
                 if eNewEnemy == -1:
                     if eOldEnemy == eActiveTeam:
                         message = BugUtil.getText(
                             "TXT_KEY_CIV4LERTS_ON_YOU_NO_WORST_ENEMY",
                             gc.getTeam(eTeam).getName())
                     else:
                         message = BugUtil.getText(
                             "TXT_KEY_CIV4LERTS_ON_NO_WORST_ENEMY",
                             (gc.getTeam(eTeam).getName(),
                              gc.getTeam(eOldEnemy).getName()))
                 elif eOldEnemy == -1:
                     message = None  # handled below
                     if eNewEnemy not in delayedMessages:
                         delayedMessages[eNewEnemy] = gc.getTeam(
                             eTeam).getName()
                     else:
                         delayedMessages[eNewEnemy] += u", " + gc.getTeam(
                             eTeam).getName()
                 else:
                     if eOldEnemy == eActiveTeam:
                         message = BugUtil.getText(
                             "TXT_KEY_CIV4LERTS_ON_SWITCH_WORST_ENEMY_FROM_YOU",
                             (gc.getTeam(eTeam).getName(),
                              gc.getTeam(eNewEnemy).getName()))
                     elif eNewEnemy == eActiveTeam:
                         message = BugUtil.getText(
                             "TXT_KEY_CIV4LERTS_ON_SWITCH_WORST_ENEMY_TO_YOU",
                             (gc.getTeam(eTeam).getName(),
                              gc.getTeam(eOldEnemy).getName()))
                     else:
                         message = BugUtil.getText(
                             "TXT_KEY_CIV4LERTS_ON_SWITCH_WORST_ENEMY",
                             (gc.getTeam(eTeam).getName(),
                              gc.getTeam(eNewEnemy).getName(),
                              gc.getTeam(eOldEnemy).getName()))
                 if message:
                     addMessageNoIcon(eActivePlayer, message)
     for eEnemy, haters in delayedMessages.iteritems():
         if eActiveTeam == eEnemy:
             message = BugUtil.getText(
                 "TXT_KEY_CIV4LERTS_ON_YOU_WORST_ENEMY", haters)
         else:
             message = BugUtil.getText(
                 "TXT_KEY_CIV4LERTS_ON_WORST_ENEMY",
                 (haters, gc.getTeam(eEnemy).getName()))
         addMessageNoIcon(eActivePlayer, message)
def settingsOK():
    """
	Returns True if BUFFY is active and all game/map settings and CRCs are acceptable, 
	on Mac, or it's an XOTM game.
	"""
    game = gc.getGame()
    map = gc.getMap()

    # xOTM games are always okay
    # EF: Mac only?
    if isXOTMScenario():
        return True

    if not Buffy.isActive():
        return False

    if not Buffy.isDllInCorrectPath():
        return False

    if game.getWarningStatus() == 1:
        return False

    # Check that the map script used is a valid one
    if not isMapScriptOK():
        return False

    # Don't allow the balanced option
    if getBalanced():
        return False

    # Check that the world wrap setting is OK
    if not getWorldWrapSettingOK():
        return False

    # Check that all victory conditions are enabled
    for iVCLoop in range(gc.getNumVictoryInfos()):
        if not game.isVictoryValid(iVCLoop):
            return False

    # Ensure the game is single player
    if game.isGameMultiPlayer():
        return False

    # Check the options
    if len(getInvalidGameOptions()) > 0:
        return False

    opponentCount = -1
    seenLeaders = set()
    for player in PlayerUtil.players(barbarian=False, minor=False):
        opponentCount += 1
        iLeader = player.getLeaderType()
        if iLeader >= 0:
            if iLeader in seenLeaders:
                return False
            seenLeaders.add(iLeader)

    if not isOpponentCountOK(opponentCount):
        return False

    if game.isTeamGame():
        return False

    if crcResult != 0:
        return False

    return True
def onVassalOffered(argsList):
	#BugUtil.debug("DiplomacyUtil::onVassalOffered %s" %(str(argsList)))
	eOfferPlayer, eTargetPlayer = argsList
	BugUtil.debug("DiplomacyUtil - %s offers vassalage to %s",
			PlayerUtil.getPlayer(eOfferPlayer).getName(), 
			PlayerUtil.getPlayer(eTargetPlayer).getName())
Exemple #50
0
	def drawHelpInfo(self):
		
		screen = self.getScreen()
		szArea = "ReligionList"
		
		## johny smith
		## This attaches the text to the panel
		## This is for every line of font
		# Founded...
		screen.setLabelAt("", szArea, localText.getText("TXT_KEY_RELIGION_SCREEN_DATE_FOUNDED", ()), CvUtil.FONT_LEFT_JUSTIFY, self.LEFT_EDGE_TEXT, self.Y_FOUNDED, self.DZ, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

		# Date Founded:
		xLoop = self.X_RELIGION_START
		for iRel in self.RELIGIONS:
			if (gc.getGame().getReligionGameTurnFounded(iRel) >= 0):
				szFounded = CyGameTextMgr().getTimeStr(gc.getGame().getReligionGameTurnFounded(iRel), false)
				screen.setLabelAt("", szArea, szFounded, CvUtil.FONT_CENTER_JUSTIFY, xLoop, self.Y_FOUNDED, self.DZ, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
			xLoop += self.DX_RELIGION

#		screen.setLabelAt("", szArea, "", CvUtil.FONT_CENTER_JUSTIFY, xLoop, self.Y_FOUNDED, self.DZ, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

		# Holy City...
		screen.setLabelAt("", szArea, localText.getText("TXT_KEY_RELIGION_SCREEN_HOLY_CITY", ()), CvUtil.FONT_LEFT_JUSTIFY, self.LEFT_EDGE_TEXT, self.Y_HOLY_CITY, self.DZ, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

		xLoop = self.X_RELIGION_START
		for iRel in self.RELIGIONS:
			if (gc.getGame().getReligionGameTurnFounded(iRel) >= 0):
				pHolyCity = gc.getGame().getHolyCity(iRel)
				if pHolyCity.isNone():
					szFounded = localText.getText("TXT_KEY_NONE", ())
					screen.setLabelAt("", szArea, szFounded, CvUtil.FONT_CENTER_JUSTIFY, xLoop, self.Y_HOLY_CITY, self.DZ, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
				elif not pHolyCity.isRevealed(gc.getPlayer(self.iActivePlayer).getTeam(), False):
					szFounded = localText.getText("TXT_KEY_UNKNOWN", ())
					screen.setLabelAt("", szArea, szFounded, CvUtil.FONT_CENTER_JUSTIFY, xLoop, self.Y_HOLY_CITY, self.DZ, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
				else:
					szFounded = pHolyCity.getName()
					screen.setLabelAt("", szArea, u"(%s)" % gc.getPlayer(pHolyCity.getOwner()).getCivilizationAdjective(0), CvUtil.FONT_CENTER_JUSTIFY, xLoop, self.Y_HOLY_CITY+8, self.DZ, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
					screen.setLabelAt("", szArea, szFounded, CvUtil.FONT_CENTER_JUSTIFY, xLoop, self.Y_HOLY_CITY-8, self.DZ, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
#			else:
#				szFounded = "-"
#				screen.setLabelAt("", szArea, szFounded, CvUtil.FONT_CENTER_JUSTIFY, xLoop, self.Y_HOLY_CITY, self.DZ, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
			xLoop += self.DX_RELIGION

		# Influence...
		screen.setLabelAt("", szArea, localText.getText("TXT_KEY_RELIGION_SCREEN_INFLUENCE", ()), CvUtil.FONT_LEFT_JUSTIFY, self.LEFT_EDGE_TEXT, self.Y_INFLUENCE, self.DZ, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

		xLoop = self.X_RELIGION_START
		for iRel in self.RELIGIONS:
			if (gc.getGame().getReligionGameTurnFounded(iRel) >= 0):
				szFounded = str(gc.getGame().calculateReligionPercent(iRel)) + "%"
				screen.setLabelAt("", szArea, szFounded, CvUtil.FONT_CENTER_JUSTIFY, xLoop, self.Y_INFLUENCE, self.DZ, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
#			else:
#				szFounded = "-"
#				screen.setLabelAt("", szArea, szFounded, CvUtil.FONT_CENTER_JUSTIFY, xLoop, self.Y_INFLUENCE, self.DZ, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
			xLoop += self.DX_RELIGION

		if AdvisorOpt.isReligious():
			# Count the number of temples and monastery
			self.BUGConstants()
			iPlayer = PyPlayer(self.iActivePlayer)
			cityList = iPlayer.getCityList()
# BUG - start
			iCities = [0] * self.NUM_RELIGIONS
			iTemple = [0] * self.NUM_RELIGIONS
			iMonastery = [0] * self.NUM_RELIGIONS
			iMissionaries_Active = [0] * self.NUM_RELIGIONS
			iMissionaries_Construct = [0] * self.NUM_RELIGIONS
			
			for pLoopCity in cityList:
				lHolyCity = pLoopCity.getHolyCity()
				lReligions = pLoopCity.getReligions()

				for iRel in self.RELIGIONS:
					# count the number of cities
					if iRel in lReligions:
						iCities[iRel] += 1

					# count the number of temples
					iBldg = ReligionUtil.getBuilding(iRel, ReligionUtil.BUILDING_TEMPLE)
					if self.calculateBuilding(pLoopCity, iBldg) == self.objectHave:
						iTemple[iRel] += 1

					# count the number of monasteries
					iBldg = ReligionUtil.getBuilding(iRel, ReligionUtil.BUILDING_MONASTERY)
					if self.calculateBuilding(pLoopCity, iBldg) == self.objectHave:
						iMonastery[iRel] += 1

					# count the number of missionaries under construction
					iUnit = ReligionUtil.getUnit(iRel, ReligionUtil.UNIT_MISSIONARY)
					if pLoopCity.GetCy().getFirstUnitOrder(iUnit) != -1:
						iMissionaries_Construct[iRel] += 1

			# count the number of active missionaries
			for iUnit in PlayerUtil.playerUnits(self.iActivePlayer):  
				for iRel in self.RELIGIONS:
					if iUnit.getUnitType() == ReligionUtil.getUnit(iRel, ReligionUtil.UNIT_MISSIONARY):
						iMissionaries_Active[iRel] += 1

			# number of cities...
			iY = self.Y_INFLUENCE + 20
			sCities = "%s [%i]:" % (self.szCities, len(cityList))
			screen.setLabelAt("", szArea, sCities, CvUtil.FONT_LEFT_JUSTIFY, self.LEFT_EDGE_TEXT, iY, self.DZ, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

			xLoop = self.X_RELIGION_START
			for iRel in self.RELIGIONS:
				if (gc.getGame().getReligionGameTurnFounded(iRel) >= 0):
					szFounded = "%i" % (iCities[iRel])
					screen.setLabelAt("", szArea, szFounded, CvUtil.FONT_CENTER_JUSTIFY, xLoop, iY, self.DZ, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
				xLoop += self.DX_RELIGION

			# number of temples...
			iY = self.Y_INFLUENCE + 40
			screen.setLabelAt("", szArea, self.szTemples, CvUtil.FONT_LEFT_JUSTIFY, self.LEFT_EDGE_TEXT, iY, self.DZ, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

			xLoop = self.X_RELIGION_START
			for iRel in self.RELIGIONS:
				if (gc.getGame().getReligionGameTurnFounded(iRel) >= 0):
					szFounded = "%i" % (iTemple[iRel])
					screen.setLabelAt("", szArea, szFounded, CvUtil.FONT_CENTER_JUSTIFY, xLoop, iY, self.DZ, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
				xLoop += self.DX_RELIGION

			# number of monasteries...
			iY = self.Y_INFLUENCE + 60
			screen.setLabelAt("", szArea, self.szMonastaries, CvUtil.FONT_LEFT_JUSTIFY, self.LEFT_EDGE_TEXT, iY, self.DZ, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

			xLoop = self.X_RELIGION_START
			for iRel in self.RELIGIONS:
				if (gc.getGame().getReligionGameTurnFounded(iRel) >= 0):
					szFounded = "%i" % (iMonastery[iRel])
					screen.setLabelAt("", szArea, szFounded, CvUtil.FONT_CENTER_JUSTIFY, xLoop, iY, self.DZ, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
				xLoop += self.DX_RELIGION

			# number of missionaries...
			iY = self.Y_INFLUENCE + 80
			screen.setLabelAt("", szArea, self.szMissionaries, CvUtil.FONT_LEFT_JUSTIFY, self.LEFT_EDGE_TEXT, iY, self.DZ, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

			xLoop = self.X_RELIGION_START
			for iRel in self.RELIGIONS:
				if (gc.getGame().getReligionGameTurnFounded(iRel) >= 0):
					szFounded = "%i [%i]" % (iMissionaries_Active[iRel], iMissionaries_Construct[iRel])
					screen.setLabelAt("", szArea, szFounded, CvUtil.FONT_CENTER_JUSTIFY, xLoop, iY, self.DZ, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
				xLoop += self.DX_RELIGION

		self.iReligionSelected = gc.getPlayer(self.iActivePlayer).getStateReligion()
		if (self.iReligionSelected == -1):
			self.iReligionSelected = gc.getNumReligionInfos()
		self.iReligionExamined = self.iReligionSelected
		self.iReligionOriginal = self.iReligionSelected
Exemple #51
0
	def showSituationReport(self):

		self.timer.start()
		self.deleteAllWidgets()
		screen = self.getScreen()
		
		# get Player arrays
		pVassals = [[]] * gc.getMAX_PLAYERS()
		pDefPacts = [[]] * gc.getMAX_PLAYERS()
		bVassals = False
		bDefPacts = False
		for iLoopPlayer in range(gc.getMAX_PLAYERS()):
			pPlayer = gc.getPlayer(iLoopPlayer)

			if (pPlayer.isAlive()
			and (gc.getTeam(pPlayer.getTeam()).isHasMet(gc.getPlayer(self.iActivePlayer).getTeam())
			or gc.getGame().isDebugMode())
			and iLoopPlayer != self.iActivePlayer
			and not pPlayer.isBarbarian()
			and not pPlayer.isMinorCiv()):
				pVassals[iLoopPlayer] = PlayerUtil.getVassals(iLoopPlayer, self.iActivePlayer)
				pDefPacts[iLoopPlayer] = PlayerUtil.getDefensivePacts(iLoopPlayer, self.iActivePlayer)

				if len(pVassals[iLoopPlayer]) > 0:
					bVassals = True

				if len(pDefPacts[iLoopPlayer]) > 0:
					bDefPacts = True

		bVassals = True
		bDefPacts = True
		self.initIconGrid(screen, bVassals, bDefPacts)
		self.initPower()
		
		activePlayer = gc.getPlayer(self.iActivePlayer)		
		
		# Assemble the panel
		iPANEL_X = 5
		iPANEL_Y = 60
		iPANEL_WIDTH = self.W_SCREEN - 20
		iPANEL_HEIGHT = self.H_SCREEN - 120

		self.tradePanel = self.getNextWidgetName()
		screen.addPanel(self.tradePanel, "", "", True, True, iPANEL_X, iPANEL_Y, iPANEL_WIDTH, iPANEL_HEIGHT, PanelStyles.PANEL_STYLE_MAIN )
		
		self.iconGrid.createGrid()
		self.iconGrid.clearData()

		iRow = 0
		for iLoopPlayer in range(gc.getMAX_PLAYERS()):
			pPlayer = gc.getPlayer(iLoopPlayer)

			if (pPlayer.isAlive()
			and (gc.getTeam(pPlayer.getTeam()).isHasMet(gc.getPlayer(self.iActivePlayer).getTeam())
			or gc.getGame().isDebugMode())
			and iLoopPlayer != self.iActivePlayer
			and not pPlayer.isBarbarian()
			and not pPlayer.isMinorCiv()):


#				szPlayerName = pPlayer.getName() + "/" + pPlayer.getCivilizationShortDescription(0)
#				BugUtil.debug("Grid_ThreatIndex - Start %i %s" % (iLoopPlayer, szPlayerName))
#				BugUtil.debug("Grid_ThreatIndex - Start %i" % (iLoopPlayer))

				self.iconGrid.appendRow(pPlayer.getName(), "", 3)

				# add leaderhead icon
				self.iconGrid.addIcon(iRow, self.Col_Leader,
										gc.getLeaderHeadInfo(pPlayer.getLeaderType()).getButton(), 64, 
										WidgetTypes.WIDGET_LEADERHEAD, iLoopPlayer, self.iActivePlayer)

				# add worst enemy
				self.Grid_WorstEnemy(iRow, iLoopPlayer)

				# add current war opponents
				pActiveWars = PlayerUtil.getActiveWars(iLoopPlayer, self.iActivePlayer)
				bCurrentWar = len(pActiveWars) > 0
				for pLoopPlayer in pActiveWars:
					self.iconGrid.addIcon(iRow, self.Col_Curr_Wars, 
											gc.getLeaderHeadInfo (pLoopPlayer.getLeaderType()).getButton(), 32, 
											*BugDll.widgetVersion(2, "WIDGET_LEADERHEAD_RELATIONS", iLoopPlayer, pLoopPlayer.getID(),
																WidgetTypes.WIDGET_LEADERHEAD, iLoopPlayer, pLoopPlayer.getID()))

				# show vassals
				if bVassals:
					for pLoopPlayer in pVassals[iLoopPlayer]:
						self.iconGrid.addIcon(iRow, self.Col_Vassals, 
												gc.getLeaderHeadInfo (pLoopPlayer.getLeaderType()).getButton(), 32, 
												*BugDll.widgetVersion(2, "WIDGET_LEADERHEAD_RELATIONS", iLoopPlayer, pLoopPlayer.getID(),
																	WidgetTypes.WIDGET_LEADERHEAD, iLoopPlayer, pLoopPlayer.getID()))

				# show defensive pacts
				if bDefPacts:
					for pLoopPlayer in pDefPacts[iLoopPlayer]:
						self.iconGrid.addIcon(iRow, self.Col_DefPacts, 
												gc.getLeaderHeadInfo (pLoopPlayer.getLeaderType()).getButton(), 32, 
												*BugDll.widgetVersion(2, "WIDGET_LEADERHEAD_RELATIONS", iLoopPlayer, pLoopPlayer.getID(),
																	WidgetTypes.WIDGET_LEADERHEAD, iLoopPlayer, pLoopPlayer.getID()))

				# show players that the current player will declare on
				bWHEOOH, pPossibleWars = PlayerUtil.getPossibleWars(iLoopPlayer, self.iActivePlayer)
				for pLoopPlayer in pPossibleWars:
					self.iconGrid.addIcon(iRow, self.Col_WillDeclareOn, 
											gc.getLeaderHeadInfo (pLoopPlayer.getLeaderType()).getButton(), 32, 
											*BugDll.widgetVersion(2, "WIDGET_LEADERHEAD_RELATIONS", iLoopPlayer, pLoopPlayer.getID(),
																WidgetTypes.WIDGET_LEADERHEAD, iLoopPlayer, pLoopPlayer.getID()))
				# show WHEOOH
				if bWHEOOH:
					sWHEOOH = u" %c" % CyGame().getSymbolID(FontSymbols.OCCUPATION_CHAR)
				else:
					sWHEOOH = ""
				
				# show possible trade embargos
				pPossibleEmbargos = PlayerUtil.getPossibleEmbargos(iLoopPlayer, self.iActivePlayer)
				for pLoopPlayer in pPossibleEmbargos:
					self.iconGrid.addIcon(iRow, self.Col_WillEmbargo, 
											gc.getLeaderHeadInfo (pLoopPlayer.getLeaderType()).getButton(), 32, 
											*BugDll.widgetVersion(2, "WIDGET_LEADERHEAD_RELATIONS", iLoopPlayer, pLoopPlayer.getID(),
																WidgetTypes.WIDGET_LEADERHEAD, iLoopPlayer, pLoopPlayer.getID()))

				self.iconGrid.setText(iRow, self.Col_WHEOOH, sWHEOOH, 3)

				# add the threat index
				self.Grid_ThreatIndex(iRow, iLoopPlayer, bCurrentWar, bWHEOOH)

				iRow += 1

		self.iconGrid.refresh()
		self.drawTabs()
		self.timer.log("SitRep")
Exemple #52
0
	def UL_refreshUnitSelection(self, bReload, bRedraw):
		screen = self.getScreen()
		screen.minimapClearAllFlashingTiles()
		
		if (bRedraw):
			iBtn_X = self.X_TEXT + self.MAP_MARGIN
			iBtn_Y = self.Y_TEXT + self.MAP_MARGIN / 2
			iTxt_X = iBtn_X + 22
			iTxt_Y = iBtn_Y + 2
			if (self.bUnitDetails):
				szText = localText.getText("TXT_KEY_MILITARY_ADVISOR_UNIT_TOGGLE_OFF", ())
				screen.setButtonGFC(self.UNIT_BUTTON_ID, u"", "", iBtn_X, iBtn_Y, 20, 20, WidgetTypes.WIDGET_GENERAL, -1, -1, ButtonStyles.BUTTON_STYLE_CITY_MINUS )
				screen.setLabel(self.UNIT_BUTTON_LABEL_ID, "", szText, CvUtil.FONT_LEFT_JUSTIFY, iTxt_X, iTxt_Y, 0, FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
			else:
				szText = localText.getText("TXT_KEY_MILITARY_ADVISOR_UNIT_TOGGLE_ON", ())
				screen.setButtonGFC(self.UNIT_BUTTON_ID, u"", "", iBtn_X, iBtn_Y, 20, 20, WidgetTypes.WIDGET_GENERAL, -1, -1, ButtonStyles.BUTTON_STYLE_CITY_PLUS )
				screen.setLabel(self.UNIT_BUTTON_LABEL_ID, "", szText, CvUtil.FONT_LEFT_JUSTIFY, iTxt_X, iTxt_Y, 0, FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

		if bReload:
			self.timer.start()
			_, activePlayer, iActiveTeam, activeTeam = PlayerUtil.getActivePlayerAndTeamAndIDs()
			self.stats = UnitGrouper.GrouperStats(self.grouper)
			for player in PlayerUtil.players(alive=True):
				for unit in PlayerUtil.playerUnits(player):
					plot = unit.plot()
					if plot.isNone():
						continue
					bVisible = plot.isVisible(iActiveTeam, False) and not unit.isInvisible(iActiveTeam, False)
					if not bVisible:
						continue
					if unit.getVisualOwner() in self.selectedLeaders:
						self.stats.processUnit(activePlayer, activeTeam, unit)
			self.timer.log("process units")
		
		iGroupID = 1
		szText = localText.getText("TXT_KEY_PEDIA_ALL_UNITS", ()).upper()
		bAllSelected = iGroupID in self.selectedGroups
		if (bAllSelected):
			szText = localText.changeTextColor(u"<u>" + szText + u"</u>", gc.getInfoTypeForString("COLOR_YELLOW"))
		if (bRedraw):
			screen.addListBoxGFC(self.UNIT_LIST_ID, "", self.X_TEXT + self.MAP_MARGIN, self.Y_TEXT + self.MAP_MARGIN + 15, self.W_TEXT - 2 * self.MAP_MARGIN, self.H_TEXT - 2 * self.MAP_MARGIN - 15, TableStyles.TABLE_STYLE_STANDARD)
			screen.enableSelect(self.UNIT_LIST_ID, False)
			screen.setStyle(self.UNIT_LIST_ID, "Table_StandardCiv_Style")
			screen.appendListBoxString(self.UNIT_LIST_ID, szText, WidgetTypes.WIDGET_MINIMAP_HIGHLIGHT, 1, iGroupID, CvUtil.FONT_LEFT_JUSTIFY)
		else:
			screen.setListBoxStringGFC(self.UNIT_LIST_ID, 0, szText, WidgetTypes.WIDGET_MINIMAP_HIGHLIGHT, 1, iGroupID, CvUtil.FONT_LEFT_JUSTIFY)
		
#		for grouping in self.stats.itergroupings():
#			for group in grouping.itergroups():
#				BugUtil.debug("%s / %s : %d (%d)" % (grouping.grouping.title, group.group.title, group.size(), group.isEmpty()))
		
		eYellow = gc.getInfoTypeForString("COLOR_YELLOW")
		eRed = gc.getInfoTypeForString("COLOR_RED")
		eWhite = gc.getInfoTypeForString("COLOR_WHITE")
		grouping1 = self.stats.getGrouping(self.groupingKeys[0])
		grouping2 = self.stats.getGrouping(self.groupingKeys[1])
		BugUtil.debug("Grouping 1 is %s" % grouping1.grouping.title)
		BugUtil.debug("Grouping 2 is %s" % grouping2.grouping.title)
		self.timer.start()
		iItem = 1
		for group1 in grouping1.itergroups():
			if (group1.isEmpty()):
				continue
			units1 = group1.units
			iGroupID += 1
			bGroup1Selected = iGroupID in self.selectedGroups
			szDescription = group1.group.title.upper() + u" (%d)" % len(units1)
			if (bGroup1Selected):
				szDescription = u"   <u>" + szDescription + u"</u>"
			else:
				szDescription = u"   " + szDescription
			if (bGroup1Selected or bAllSelected):
				szDescription = localText.changeTextColor(szDescription, eYellow)
			if (bRedraw):
				screen.appendListBoxString(self.UNIT_LIST_ID, szDescription, WidgetTypes.WIDGET_MINIMAP_HIGHLIGHT, 1, iGroupID, CvUtil.FONT_LEFT_JUSTIFY)
			else:
				screen.setListBoxStringGFC(self.UNIT_LIST_ID, iItem, szDescription, WidgetTypes.WIDGET_MINIMAP_HIGHLIGHT, 1, iGroupID, CvUtil.FONT_LEFT_JUSTIFY)
			iItem += 1
			bGroup1Selected = bGroup1Selected or bAllSelected
			for group2 in grouping2.itergroups():
				units2 = group2.units & units1
				if (not units2):
					continue
				iGroupID += 1
				bGroup2Selected = iGroupID in self.selectedGroups
				szDescription = group2.group.title + u" (%d)" % len(units2)
				if (bGroup2Selected):
					szDescription = u"      <u>" + szDescription + u"</u>"
				else:
					szDescription = u"      " + szDescription
				if (bGroup2Selected or bGroup1Selected):
					szDescription = localText.changeTextColor(szDescription, eYellow)
				if (bRedraw):
					screen.appendListBoxString(self.UNIT_LIST_ID, szDescription, WidgetTypes.WIDGET_MINIMAP_HIGHLIGHT, 1, iGroupID, CvUtil.FONT_LEFT_JUSTIFY)
				else:
					screen.setListBoxStringGFC(self.UNIT_LIST_ID, iItem, szDescription, WidgetTypes.WIDGET_MINIMAP_HIGHLIGHT, 1, iGroupID, CvUtil.FONT_LEFT_JUSTIFY)
				iItem += 1
				
				bGroup2Selected = bGroup2Selected or bGroup1Selected
				for unit in units2:
					loopUnit = unit.unit
					bUnitSelected = self.isSelectedUnit(loopUnit.getOwner(), loopUnit.getID())
					if (self.bUnitDetails):
						szDescription = CyGameTextMgr().getSpecificUnitHelp(loopUnit, true, false)

						listMatches = re.findall("<.*?color.*?>", szDescription)	
						for szMatch in listMatches:
							szDescription = szDescription.replace(szMatch, u"")
						
						if (loopUnit.isWaiting()):
							szDescription = '*' + szDescription
						
						if (bUnitSelected):
							szDescription = u"         <u>" + szDescription + u"</u>"
						else:
							szDescription = u"         " + szDescription

						if (bUnitSelected or bGroup2Selected):
							szDescription = localText.changeTextColor(szDescription, eYellow)

						if (bRedraw):
							screen.appendListBoxString(self.UNIT_LIST_ID, szDescription, WidgetTypes.WIDGET_MINIMAP_HIGHLIGHT, -loopUnit.getOwner(), loopUnit.getID(), CvUtil.FONT_LEFT_JUSTIFY)
						else:
							screen.setListBoxStringGFC(self.UNIT_LIST_ID, iItem, szDescription, WidgetTypes.WIDGET_MINIMAP_HIGHLIGHT, -loopUnit.getOwner(), loopUnit.getID(), CvUtil.FONT_LEFT_JUSTIFY)
						iItem += 1

					iPlayer = loopUnit.getVisualOwner()
					player = PyPlayer(iPlayer)
					iColor = gc.getPlayerColorInfo(gc.getPlayer(iPlayer).getPlayerColor()).getColorTypePrimary()
					screen.setMinimapColor(MinimapModeTypes.MINIMAPMODE_MILITARY, loopUnit.getX(), loopUnit.getY(), iColor, 0.6)
					if (bUnitSelected or bGroup2Selected) and iPlayer in self.selectedLeaders:
						
						if (player.getTeam().isAtWar(gc.getPlayer(self.iActivePlayer).getTeam())):
							iColor = eRed
						elif (gc.getPlayer(iPlayer).getTeam() != gc.getPlayer(self.iActivePlayer).getTeam()):
							iColor = eYellow
						else:
							iColor = eWhite
						screen.minimapFlashPlot(loopUnit.getX(), loopUnit.getY(), iColor, -1)
		self.timer.log("draw unit list")
Exemple #53
0
def getCanTrainUnits(playerOrID, askingPlayerOrID=None, military=None):
    """
    Returns the set of all units the player can train.

    Searches all of the player's cities to find which units can be trained.

    If askingPlayerOrID is given, only cities they have seen are checked, and
    only units whose prerequisite techs they know or can research are returned.
    Also, if the two players' trade networks are not connected, units that
    require resources to train are returned in a second set.

    If military is provided, only military or civilian units are checked
    depending on its value, True or False, respectively.

    *** OBSOLETE ***

    """
    player, team = PlayerUtil.getPlayerAndTeam(playerOrID)
    askingPlayer = PlayerUtil.getPlayer(askingPlayerOrID)
    if askingPlayer:
        eAskingTeam, askingTeam = PlayerUtil.getPlayerTeamAndID(askingPlayer)
        trade = player.canTradeNetworkWith(askingPlayer.getID())
    civInfo = gc.getCivilizationInfo(player.getCivilizationType())
    units = set()
    maybeUnits = set()
    for eClass in xrange(NUM_CLASSES):
        eUnit = civInfo.getCivilizationUnits(eClass)
        if eUnit == -1:
            classInfo = gc.getUnitClassInfo(eClass)
            BugUtil.debug("%s doesn't have %s", civInfo.getDescription(),
                          classInfo.getDescription())
            eUnit = classInfo.getDefaultUnitIndex()
        unitInfo = gc.getUnitInfo(eUnit)
        if unitInfo:
            if ((military == True and unitInfo.getUnitCombatType() <= 0) or
                (military == False and unitInfo.getUnitCombatType() > 0)):
                BugUtil.debug("skipping (non-)military %s",
                              unitInfo.getDescription())
                continue
            if askingPlayer:
                for eTech in unitTechs[eUnit]:
                    if not (askingTeam.isHasTech(eTech)
                            or askingPlayer.canResearch(eTech, False)):
                        BugUtil.debug("%s doesn't comprehend %s",
                                      askingPlayer.getName(),
                                      gc.getTechInfo(eTech).getDescription())
                        skip = True
                        break
                else:
                    skip = False
                if skip:
                    BugUtil.debug("skipping unknowable %s",
                                  unitInfo.getDescription())
                    continue
            for city in PlayerUtil.playerCities(player):
                if askingPlayer:
                    if not city.isRevealed(eAskingTeam, False):
                        continue
                    if city.canTrain(eUnit, False, not trade):
                        if eUnit in unitsWithBonuses:
                            maybeUnits.add(eUnit)
                        else:
                            units.add(eUnit)
                        break
                else:
                    if city.canTrain(eUnit, False, False):
                        units.add(eUnit)
                        break
    BugUtil.debug("%s can train:", player.getName())
    for eUnit in units:
        unitInfo = gc.getUnitInfo(eUnit)
        BugUtil.debug("  %s", unitInfo.getDescription())
    if askingPlayer:
        BugUtil.debug("%s can maybe train:", player.getName())
        for eUnit in maybeUnits:
            unitInfo = gc.getUnitInfo(eUnit)
            BugUtil.debug("  %s", unitInfo.getDescription())
        return units, maybeUnits
    else:
        return units
Exemple #54
0
def getTradePlayer(player, trade):
    return PlayerUtil.getPlayer(trade.iData).getCivilizationShortDescription(0)
def getTrainableUnits(playerOrID,
                      knowableUnits,
                      checkCities=True,
                      military=None):
    """
	Returns the set of all units the player can train, including obsolete ones.
	"""
    game = CyGame()
    player, team = PlayerUtil.getPlayerAndTeam(playerOrID)
    civInfo = gc.getCivilizationInfo(player.getCivilizationType())
    if checkCities:
        cities = PlayerUtil.getPlayerCities(player)
    else:
        cities = None
    units = set()
    BugUtil.debug("%s =========", player.getCivilizationShortDescription(0))
    for eClass in range(NUM_CLASSES):
        eUnit = civInfo.getCivilizationUnits(eClass)
        if eUnit == -1 or eUnit not in knowableUnits:
            #BugUtil.debug("  %s -> unknowable", gc.getUnitClassInfo(eClass).getDescription())
            continue
        unitInfo = gc.getUnitInfo(eUnit)
        # military
        if military is not None:
            combat = (unitInfo.getUnitCombatType() > 0
                      or unitInfo.getNukeRange() != -1
                      or unitInfo.getAirCombat() > 0)
            if military != combat:
                #BugUtil.debug("  %s -> combat is %s", unitInfo.getDescription(), combat)
                continue
        # OCC and Settlers
        if game.isOption(GameOptionTypes.GAMEOPTION_ONE_CITY_CHALLENGE
                         ) and unitInfo.isFound():
            BugUtil.debug("  %s -> no founding units in OCC",
                          unitInfo.getDescription())
            continue
        # techs
        for eTech in unitTechs[eUnit]:
            if not team.isHasTech(eTech):
                BugUtil.debug("  %s -> doesn't know %s",
                              unitInfo.getDescription(),
                              gc.getTechInfo(eTech).getDescription())
                missing = True
                break
        else:
            missing = False
        if missing:
            continue
        # state religion
        eReligion = unitInfo.getStateReligion()
        if eReligion != -1 and player.getStateReligion() != eReligion:
            BugUtil.debug("  %s -> wrong state religion",
                          unitInfo.getDescription())
            continue
        # nukes
        if (game.isNoNukes()
                or not game.isNukesValid()) and unitInfo.getNukeRange() != -1:
            BugUtil.debug("  %s -> no nukes", unitInfo.getDescription())
            continue
        # getSpecialUnitType, game.isSpecialUnitValid
        eSpecialType = unitInfo.getSpecialUnitType()
        if eSpecialType != -1 and not game.isSpecialUnitValid(eSpecialType):
            BugUtil.debug("  %s -> special unit type %s invalid",
                          unitInfo.getDescription(),
                          gc.getSpecialUnitInfo(eSpecialType).getDescription())
            continue
        # cities
        if cities and not canAnyCityBuildUnit(eUnit, cities, -1, True):
            BugUtil.debug("  %s -> no city can train unit",
                          unitInfo.getDescription())
            continue
        BugUtil.debug("  %s", unitInfo.getDescription())
        units.add(eUnit)
    return units
Exemple #56
0
 def __init__(self, queue=None):
     self.clear()
     if queue:
         self.queues[PlayerUtil.getActivePlayerID()] = queue