Пример #1
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
Пример #2
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
Пример #3
0
	def check(self, silent=False):
		if (not Civ4lertsOpt.isShowWorstEnemyAlert()):
			return
		eActivePlayer = PlayerUtil.getActivePlayerID()
		eActiveTeam, activeTeam = PlayerUtil.getActiveTeamAndID()
		try: # advc.009b
			enemies = self.enemies[eActivePlayer]
		# <advc.009b>
		except AttributeError:
			return # </advc.009b>
		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 and not silent: # advc.106c
						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()))
			if not silent: # advc.106c
				addMessageNoIcon(eActivePlayer, message)
Пример #4
0
	def check(self):
		#DLP
		if CyGame().isPitbossHost():
			return
		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):
					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)
Пример #5
0
	def check(self):
		if (not Civ4lertsOpt.isShowWorstEnemyAlert()):
			return
		eActivePlayer = GAME.getActivePlayer()
		iActiveTeam = GC.getGame().getActiveTeam()
		activeTeam = GC.getTeam(iActiveTeam)
		enemies = self.enemies[eActivePlayer]
		newEnemies = AttitudeUtil.getWorstEnemyTeams()
		delayedMessages = {}
		for eTeam, eNewEnemy in newEnemies.iteritems():
			#RevolutionDCM fix
			if eTeam != -1 and activeTeam.isHasMet(eTeam):
				eOldEnemy = enemies[eTeam]
				if eOldEnemy != -1 and not GC.getTeam(eOldEnemy).isAlive():
					eOldEnemy = -1
					enemies[eTeam] = -1
				#RevolutionDCM fix
				if eNewEnemy != -1 and iActiveTeam != eNewEnemy and not activeTeam.isHasMet(eNewEnemy):
					eNewEnemy = -1
				if eOldEnemy != eNewEnemy:
					enemies[eTeam] = eNewEnemy
					if eNewEnemy == -1:
						if eOldEnemy == iActiveTeam:
							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 == iActiveTeam:
							message = BugUtil.getText("TXT_KEY_CIV4LERTS_ON_SWITCH_WORST_ENEMY_FROM_YOU", 
									(GC.getTeam(eTeam).getName(), GC.getTeam(eNewEnemy).getName()))
						elif eNewEnemy == iActiveTeam:
							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:
						addMessage(eActivePlayer, message)
		for eEnemy, haters in delayedMessages.iteritems():
			if iActiveTeam == 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()))
			addMessage(eActivePlayer, message)
Пример #6
0
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)))
	def Grid_ThreatIndex(self, iRow, iPlayer, bCurrentWar, bWHEOOH):

		pPlayer = gc.getPlayer(iPlayer)

#		BugUtil.debug("Grid_ThreatIndex - Start")

		if gc.getTeam(pPlayer.getTeam()).isAVassal():
			self.iconGrid.addStackedBar(iRow, self.Col_Threat, -1, "", localText.getText("TXT_KEY_MILITARY_SITREP_VASSAL", ()), 3)
#			BugUtil.debug("Grid_ThreatIndex - is vassal")
			return

		# initialize threat index
		iThreat = 0

		# add attitude threat value
		iRel = AttitudeUtil.getAttitudeCount(iPlayer, self.iActivePlayer)
		fRel_Threat = float(38) * float(15 - iRel) / float(30)
		if fRel_Threat < 0:
			fRel_Threat = 0.0
		elif fRel_Threat > 38:
			fRel_Threat = 38.0

#		BugUtil.debug("Grid_ThreatIndex - relationships")

		# calculate the power threat value
		fPwr_Threat = 0
		iPower = pPlayer.getPower()
		if (iPower > 0): # avoid divide by zero
			fPowerRatio = float(self.iPlayerPower) / float(iPower)
			fPwr_Threat = float(38) * float(1.5 - fPowerRatio)
			if fPwr_Threat < 0:
				fPwr_Threat = 0.0
			elif fPwr_Threat > 38:
				fPwr_Threat = 38.0

		# set power threat to 75% of max if active player cannot see the demographics
		bCannotSeeDemographics = False
		if not gc.getActivePlayer().canDoEspionageMission(self.iDemographicsMission, iPlayer, None, -1):
			bCannotSeeDemographics = True
			fPwr_Threat = 38.0 * 0.75
#			self.iconGrid.addStackedBar(iRow, self.Col_Threat, -1, "", "n/a", 3)
#			BugUtil.debug("Grid_ThreatIndex - not enough spy points")
#			return

#		BugUtil.debug("Grid_ThreatIndex - power")

		# total threat, pre WHEOOH adjustment
		fThreat = fRel_Threat + fPwr_Threat

		# WHEOOH adjustment
		if bWHEOOH and not bCurrentWar:
			fThreat = fThreat * 1.3

		# reduce the threat if the current player is in a defensive pact with the active player
		if gc.getTeam(pPlayer.getTeam()).isDefensivePact(gc.getPlayer(self.iActivePlayer).getTeam()):
			fThreat = fThreat * 0.2

		BugUtil.debug("Grid_ThreatIndex - threat adjustments - threat index %i" % int(fThreat))

		if fThreat < 15:
			sColour = "COLOR_PLAYER_GREEN"
			sThreat = localText.getText("TXT_KEY_MILITARY_THREAT_INDEX_LOW", ())
		elif  fThreat < 35:
			sColour = "COLOR_PLAYER_BLUE"
			sThreat = localText.getText("TXT_KEY_MILITARY_THREAT_INDEX_GUARDED", ())
		elif  fThreat < 55:
			sColour = "COLOR_PLAYER_YELLOW"
			sThreat = localText.getText("TXT_KEY_MILITARY_THREAT_INDEX_ELEVATED", ())
		elif  fThreat < 75:
			sColour = "COLOR_PLAYER_ORANGE"
			sThreat = localText.getText("TXT_KEY_MILITARY_THREAT_INDEX_HIGH", ())
		else:
			sColour = "COLOR_PLAYER_RED"
			sThreat = localText.getText("TXT_KEY_MILITARY_THREAT_INDEX_SEVERE", ())

		if bCannotSeeDemographics:
			sThreat += " (est)"

		self.iconGrid.addStackedBar(iRow, self.Col_Threat, fThreat, sColour, sThreat, 3)
#		BugUtil.debug("Grid_ThreatIndex - bar placed")
		return
Пример #8
0
	def Grid_ThreatIndex(self, iRow, iPlayer, bCurrentWar, bWHEOOH):

		pPlayer = gc.getPlayer(iPlayer)

#		BugUtil.debug("Grid_ThreatIndex - Start")

		if gc.getTeam(pPlayer.getTeam()).isAVassal():
			self.iconGrid.addStackedBar(iRow, self.Col_Threat, -1, "", localText.getText("TXT_KEY_MILITARY_SITREP_VASSAL", ()), 3)
#			BugUtil.debug("Grid_ThreatIndex - is vassal")
			return

		# initialize threat index
		iThreat = 0

		# add attitude threat value
		iRel = AttitudeUtil.getAttitudeCount(iPlayer, self.iActivePlayer)
		fRel_Threat = float(38) * float(15 - iRel) / float(30)
		if fRel_Threat < 0:
			fRel_Threat = 0.0
		elif fRel_Threat > 38:
			fRel_Threat = 38.0

#		BugUtil.debug("Grid_ThreatIndex - relationships")

		# calculate the power threat value
		fPwr_Threat = 0
		iPower = pPlayer.getPower()
		if (iPower > 0): # avoid divide by zero
			fPowerRatio = float(self.iPlayerPower) / float(iPower)
			fPwr_Threat = float(38) * float(1.5 - fPowerRatio)
			if fPwr_Threat < 0:
				fPwr_Threat = 0.0
			elif fPwr_Threat > 38:
				fPwr_Threat = 38.0

		# set power threat to 75% of max if active player cannot see the demographics
		bCannotSeeDemographics = False
		if not gc.getActivePlayer().canDoEspionageMission(self.iDemographicsMission, iPlayer, None, -1):
			bCannotSeeDemographics = True
			fPwr_Threat = 38.0 * 0.75
#			self.iconGrid.addStackedBar(iRow, self.Col_Threat, -1, "", "n/a", 3)
#			BugUtil.debug("Grid_ThreatIndex - not enough spy points")
#			return

#		BugUtil.debug("Grid_ThreatIndex - power")

		# total threat, pre WHEOOH adjustment
		fThreat = fRel_Threat + fPwr_Threat

		# WHEOOH adjustment
		if bWHEOOH and not bCurrentWar:
			fThreat = fThreat * 1.3

		# reduce the threat if the current player is in a defensive pact with the active player
		if gc.getTeam(pPlayer.getTeam()).isDefensivePact(gc.getPlayer(self.iActivePlayer).getTeam()):
			fThreat = fThreat * 0.2

		BugUtil.debug("Grid_ThreatIndex - threat adjustments - threat index %i" % int(fThreat))

		if fThreat < 15:
			sColour = "COLOR_PLAYER_GREEN"
			sThreat = localText.getText("TXT_KEY_MILITARY_THREAT_INDEX_LOW", ())
		elif  fThreat < 35:
			sColour = "COLOR_PLAYER_BLUE"
			sThreat = localText.getText("TXT_KEY_MILITARY_THREAT_INDEX_GUARDED", ())
		elif  fThreat < 55:
			sColour = "COLOR_PLAYER_YELLOW"
			sThreat = localText.getText("TXT_KEY_MILITARY_THREAT_INDEX_ELEVATED", ())
		elif  fThreat < 75:
			sColour = "COLOR_PLAYER_ORANGE"
			sThreat = localText.getText("TXT_KEY_MILITARY_THREAT_INDEX_HIGH", ())
		else:
			sColour = "COLOR_PLAYER_RED"
			sThreat = localText.getText("TXT_KEY_MILITARY_THREAT_INDEX_SEVERE", ())

		if bCannotSeeDemographics:
			sThreat += " (est)"

		self.iconGrid.addStackedBar(iRow, self.Col_Threat, fThreat, sColour, sThreat, 3)
#		BugUtil.debug("Grid_ThreatIndex - bar placed")
		return