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 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)))