Example #1
0
    def doNewHuman(self, iNewPlayerID, iOldPlayerID):
        # This still not working properly. Boo.... Close though.
        CyInterface().addImmediateMessage("doNewHuman", "")
        self.bLaunchedChangeHumanPopup = False
        gc.getPlayer(iOldPlayerID).setNewPlayerAlive(True)
        iSettler = CvUtil.findInfoTypeNum(gc.getUnitInfo, gc.getNumUnitInfos(),
                                          'UNIT_SETTLER')
        gc.getPlayer(iOldPlayerID).initUnit(iSettler, 0, 0,
                                            UnitAITypes.NO_UNITAI,
                                            DirectionTypes.DIRECTION_SOUTH)
        gc.getPlayer(iOldPlayerID).setFoundedFirstCity(False)
        gc.getPlayer(iOldPlayerID).setIsHuman(True)

        toKillPlayer = gc.getPlayer(iOldPlayerID)
        CyInterface().addImmediateMessage("calling changeHuman", "")
        RevUtils.changeHuman(iNewPlayerID, iOldPlayerID)

        if (toKillPlayer.getNumCities() == 0):
            # Kills off the lion in the ice field
            CvUtil.pyPrint("Killing off player %d" % (toKillPlayer.getID()))
            toKillPlayer.killUnits()
            toKillPlayer.setIsHuman(False)
            #success = game.changePlayer( toKillPlayer.getID(), toKillPlayer.getCivilizationType(), toKillPlayer.getLeaderType(), -1, False, False )
            toKillPlayer.setNewPlayerAlive(False)
            toKillPlayer.setFoundedFirstCity(True)
Example #2
0
    def pickHumanHandler(self, iPlayerID, netUserData, popupReturn):

        CvUtil.pyPrint('Handling pick human popup')

        if (popupReturn.getButtonClicked() == 0):  # if you pressed cancel
            CyInterface().addImmediateMessage(
                "Kill your remaining units if you'd like to see end game screens",
                "")
            return

        toKillPlayer = gc.getActivePlayer()

        newHumanIdx = popupReturn.getSelectedPullDownValue(1)
        newPlayer = gc.getPlayer(newHumanIdx)

        # game.setActivePlayer( newHumanIdx, False )
        # newPlayer.setIsHuman(True)

        # CvUtil.pyPrint("You now control the %s"%(newPlayer.getCivilizationDescription(0)))
        # CyInterface().addImmediateMessage("You now control the %s"%(newPlayer.getCivilizationDescription(0)),"")

        RevUtils.changeHuman(newHumanIdx, toKillPlayer.getID())

        if (toKillPlayer.getNumCities() == 0):
            # Kills off the lion in the ice field
            CvUtil.pyPrint("Killing off player %d" % (toKillPlayer.getID()))
            toKillPlayer.killUnits()
            toKillPlayer.setIsHuman(False)
            #success = game.changePlayer( toKillPlayer.getID(), toKillPlayer.getCivilizationType(), toKillPlayer.getLeaderType(), -1, False, False )
            toKillPlayer.setNewPlayerAlive(False)
            toKillPlayer.setFoundedFirstCity(True)
Example #3
0
	def waitingForHandler( self, iPlayerID, netUserData, popupReturn ) :

		if( popupReturn.getButtonClicked() == 0 ):

			pPlayer = gc.getActivePlayer()
			RevUtils.changeHuman( pPlayer.getID(), -1 )
			self.waitingFor()
		
		elif( popupReturn.getButtonClicked() == 1 ):
			game.setForcedAIAutoPlay(gc.getActivePlayer(), 1, true)
Example #4
0
    def checkPlayer(self):
        iPlayer = GAME.getActivePlayer()
        CyPlayer = GC.getActivePlayer()

        if CyPlayer and not CyPlayer.isAlive():
            if GAME.getAIAutoPlay(iPlayer) > 0:
                try:
                    bCanCancelAuto = SdToolKit.sdObjectGetVal(
                        "AIAutoPlay", GAME, "bCanCancelAuto")
                    if bCanCancelAuto is None:
                        bCanCancelAuto = True
                        SdToolKit.sdObjectSetVal("AIAutoPlay", GAME,
                                                 "bCanCancelAuto", True)
                except:
                    print "Error! AIAutoPlay: Can't find bCanCancelAuto, assuming it would be True"
                    bCanCancelAuto = True

                if bCanCancelAuto:
                    if self.refortify:
                        RevUtils.doRefortify(iPlayer)
                        self.disableMultiCheck(iPlayer)
                    self.checkPlayer()
            popup = PyPopup.PyPopup(
                RevDefs.pickHumanPopup,
                contextType=EventContextTypes.EVENTCONTEXT_ALL,
                bDynamic=False)
            popup.setHeaderString(
                TRNSLTR.getText("TXT_KEY_AIAUTOPLAY_PICK_CIV", ()))
            popup.setBodyString(
                TRNSLTR.getText("TXT_KEY_AIAUTOPLAY_CIV_DIED", ()))
            popup.addSeparator()
            popup.createPythonPullDown(
                TRNSLTR.getText("TXT_KEY_AIAUTOPLAY_TAKE_CONTROL_CIV", ()), 1)

            for iPlayerX in range(GC.getMAX_PC_PLAYERS()):
                if iPlayerX == iPlayer: continue
                CyPlayerX = GC.getPlayer(iPlayerX)
                if CyPlayerX.isAlive():
                    popup.addPullDownString(
                        TRNSLTR.getText("TXT_KEY_AIAUTOPLAY_OF_THE", ()) %
                        (CyPlayerX.getName(),
                         CyPlayerX.getCivilizationDescription(0)), iPlayerX, 1)

            popup.popup.setSelectedPulldownID(iPlayer, 1)

            popup.addSeparator()
            popup.addButton(TRNSLTR.getText("TXT_KEY_AIAUTOPLAY_NONE", ()))
            print 'Launching pick human popup'
            popup.launch()

        for i in range(GC.getMAX_PC_TEAMS()):
            CyPlayer.setEspionageSpendingWeightAgainstTeam(
                i,
                CyPlayer.getEspionageSpendingWeightAgainstTeam(i) / 10)
Example #5
0
    def onEndPlayerTurn(self, argsList):
        iGameTurn, iPlayer = argsList

        # Can't use isHuman as isHuman has been deactivated by automation
        if (self.refortify and iPlayer == game.getActivePlayer()
                and game.getAIAutoPlay() == 1):
            RevUtils.doRefortify(game.getActivePlayer())

        if (iPlayer == gc.getBARBARIAN_PLAYER() and game.getAIAutoPlay() == 1):
            # About to turn off automation
            #SdToolKitAdvanced.sdObjectSetVal( "AIAutoPlay", game, "bCanCancelAuto", False )
            #self.checkPlayer()
            pass
Example #6
0
    def onKbdEvent(self, argsList):
        'keypress handler'
        eventType, key, mx, my, px, py = argsList

        if (eventType == RevDefs.EventKeyDown):
            theKey = int(key)

            if (theKey == int(InputTypes.KB_X) and self.customEM.bShift
                    and self.customEM.bCtrl):
                # Get it?  Shift ... control ... to the AI
                #-------------------------------------------------------------------------------------------------
                # Lemmy101 RevolutionMP edit
                #-------------------------------------------------------------------------------------------------
                if (game.getAIAutoPlay(game.getActivePlayer()) > 0):
                    try:
                        bCanCancelAuto = SdToolKitCustom.sdObjectGetVal(
                            "AIAutoPlay", game, "bCanCancelAuto")
                        if (bCanCancelAuto is None):
                            bCanCancelAuto = True
                            SdToolKitCustom.sdObjectSetVal(
                                "AIAutoPlay", game, "bCanCancelAuto", True)
                    except:
                        print "Error!  AIAutoPlay: Can't find bCanCancelAuto, assuming it would be True"
                        bCanCancelAuto = True

                    if (bCanCancelAuto):
                        if (self.refortify):
                            RevUtils.doRefortify(game.getActivePlayer())
                            self.disableMultiCheck(game.getActivePlayer())
#-------------------------------------------------------------------------------------------------
# END Lemmy101 RevolutionMP edit
#-------------------------------------------------------------------------------------------------

                        self.checkPlayer()
                else:
                    self.toAIChooser()

            if (theKey == int(InputTypes.KB_M) and self.customEM.bShift
                    and self.customEM.bCtrl):
                # Toggle auto moves
                if (self.LOG_DEBUG):
                    CyInterface().addImmediateMessage("Moving your units...",
                                                      "")
                #self.playerID = gc.getActivePlayer().getID()
                game.setAIAutoPlay(game.getActivePlayer(), 1)

            if (theKey == int(InputTypes.KB_O) and self.customEM.bShift
                    and self.customEM.bCtrl):
                RevUtils.doRefortify(game.getActivePlayer())
Example #7
0
	def onEndPlayerTurn( self, argsList ) :
		iGameTurn, iPlayer = argsList

		# Can't use isHuman as isHuman has been deactivated by automation
#-------------------------------------------------------------------------------------------------
# Lemmy101 RevolutionMP edit
#-------------------------------------------------------------------------------------------------
		if( self.refortify and iPlayer == game.getActivePlayer() and game.getAIAutoPlay(iPlayer) == 1 ) :
			RevUtils.doRefortify( iPlayer )
		
		if( iPlayer == gc.getBARBARIAN_PLAYER() and game.getAIAutoPlay(iPlayer) == 1 ) :
			# About to turn off automation
			#SdToolKitCustom.sdObjectSetVal( "AIAutoPlay", game, "bCanCancelAuto", False )
			#self.checkPlayer()
			pass
Example #8
0
def assimilateHandler(iPlayerID, netUserData, popupReturn):

	global noAssimilateList

	if popupReturn.getButtonClicked() == 0:
		if LOG_DEBUG:
			print "[REV] Assimilation accepted!"
		if netUserData[2]:
			pMotherland = GC.getPlayer(RevData.revObjectGetVal(GC.getPlayer(netUserData[0]), 'MotherlandID' ))
			pMotherland.AI_changeAttitudeExtra( etUserData[1], pMotherland.AI_getAttitudeExtra(netUserData[0]))
			if LOG_DEBUG:
				print "[REV] Rebel motherland %s extra attidude to %s now %d"%(pMotherland.getCivilizationDescription(0), GC.getPlayer(netUserData[1]).getCivilizationDescription(0), pMotherland.AI_getAttitudeExtra(netUserData[0]))

			[iOdds, attackerTeam, victimTeam] = RevUtils.computeWarOdds(pMotherland, GC.getPlayer(netUserData[1]), GC.getPlayer(netUserData[0]).getCapitalCity().area(), False, True, True)

			if attackerTeam.canDeclareWar(victimTeam.getID()) and iOdds > GAME.getSorenRandNum(100, 'Revolution: War'):
				if LOG_DEBUG:
					print "[REV] Rebel motherland takes exception, team %d declare war on team %d"%(attackerTeam.getID(), victimTeam.getID())
				attackerTeam.declareWar( victimTeam.getID(), True, WarPlanTypes.NO_WARPLAN )

		GC.getPlayer(netUserData[1]).assimilatePlayer(netUserData[0])
	elif popupReturn.getButtonClicked() == 1:
		if LOG_DEBUG:
			print "[REV] Assimilation postponed"
	else:
		if LOG_DEBUG:
			print "[REV] Assimilation rejected!"
		noAssimilateList.append(netUserData[0])
Example #9
0
def changeHumanHandler( playerID, netUserData, popupReturn ) :
	'Handles changeHuman popup'

	if( popupReturn.getButtonClicked() == 0 ):  # if you pressed cancel
		return

	newHumanIdx = popupReturn.getSelectedPullDownValue( 1 )
	newPlayer = gc.getPlayer(newHumanIdx)
	oldHumanIdx = playerID
	oldPlayer = gc.getPlayer(oldHumanIdx)

	if( newHumanIdx == oldHumanIdx ) :
		if( LOG_DEBUG ) : CvUtil.pyPrint( "   CP : You have selected the same civ, no change")
		CyInterface().addImmediateMessage("You retain control of the %s"%(oldPlayer.getCivilizationDescription(0)),"")
		return


	if( LOG_DEBUG ) : CvUtil.pyPrint( "   CP : You have selected player %d, the %s"%(newHumanIdx, newPlayer.getCivilizationDescription(0)) )

	success = RevUtils.changeHuman( newHumanIdx, oldHumanIdx )

	if( success ) :
		if( LOG_DEBUG ) : CvUtil.pyPrint( "   CP : Number of human players is now %d"%(game.getNumHumanPlayers()) )
		if( LOG_DEBUG ) : CvUtil.pyPrint( "   CP : Active player is now %d"%(game.getActivePlayer()) )
##			for i in range(0,gc.getMAX_CIV_PLAYERS()) :
##				if( LOG_DEBUG ) : CvUtil.pyPrint( "   CP : Player %d is human %d"%(i,gc.getPlayer(i).isHuman()))
		CyInterface().addImmediateMessage("You now control the %s"%(newPlayer.getCivilizationDescription(0)),"")
	else :
		if( LOG_DEBUG ) : CvUtil.pyPrint( "   CP : Error occured, number of human players is now %d"%(game.getNumHumanPlayers()) )
		CyInterface().addImmediateMessage("An error occured in changeHuman ...","")
Example #10
0
def onEndGameTurn(argsList) :

	## Fix to stop modulo by zero DH 5th July 2012 ##
	if GAME.getGameTurn()%int(max(1,RevUtils.getGameSpeedMod())*10) == 0:
		updateAttitudeExtras()

	removeFloatingRebellions()

	if allowAssimilation:
		checkForAssimilation()

	for i in xrange(MAX_PC_PLAYERS) :
		playerI = GC.getPlayer(i)
		if( playerI.isRebel() ) :
			if( GC.getTeam(playerI.getTeam()).getAtWarCount(True) == 0 ) :
				playerI.setIsRebel( False )
				if( LOG_DEBUG ) : CvUtil.pyPrint("Rev - %s (Player %d) is no longer a rebel due to no wars"%(playerI.getCivilizationDescription(0),i))
			elif( GC.getTeam(playerI.getTeam()).countRebelAgainst() == 0 ) :
				playerI.setIsRebel( False )
				if( LOG_DEBUG ) : CvUtil.pyPrint("Rev - %s (Player %d) is no longer a rebel due to no rebel against"%(playerI.getCivilizationDescription(0),i))
			elif( playerI.getNumCities() > 3 and (GAME.getGameTurn() - playerI.getCapitalCity().getGameTurnAcquired() > 15) ) :
				playerI.setIsRebel( False )
				if( LOG_DEBUG ) : CvUtil.pyPrint("Rev - %s (Player %d) is no longer a rebel by cities and capital ownership turns"%(playerI.getCivilizationDescription(0),i))
			elif( playerI.getNumCities() > 0 and (GAME.getGameTurn() - playerI.getCapitalCity().getGameTurnAcquired() > 30) ) :
				playerI.setIsRebel( False )
				if( LOG_DEBUG ) : CvUtil.pyPrint("Rev - %s (Player %d) is no longer a rebel by capital ownership turns"%(playerI.getCivilizationDescription(0),i))
			elif( LOG_DEBUG ) :
				teamString = ""
				for j in xrange(MAX_PC_TEAMS):
					if( GC.getTeam(playerI.getTeam()).isRebelAgainst(j) ) :
						teamString += "%d, "%(j)
				CvUtil.pyPrint("Rev - %s (%d) is a rebel against teams %s"%(playerI.getCivilizationDescription(0),i,teamString))
Example #11
0
def changeCivHandler( playerID, netUserData, popupReturn ) :
	'Handles changeCiv popup'

	if( popupReturn.getButtonClicked() == 0 ):  # if you pressed cancel
		return

	playerIdx = popupReturn.getSelectedPullDownValue( 1 )
	newCivType = popupReturn.getSelectedPullDownValue( 2 )
	newLeaderType = popupReturn.getSelectedPullDownValue( 3 )
	teamIdx = popupReturn.getSelectedPullDownValue( 4 )

	if( LOG_DEBUG ) : CvUtil.pyPrint( "   CP : You have selected player %d, the %s, on team %d"%(playerIdx, gc.getPlayer(playerIdx).getCivilizationDescription(0), gc.getPlayer(playerIdx).getTeam()) )
	if( LOG_DEBUG ) : CvUtil.pyPrint( "   CP : New team idx is %d"%(teamIdx) )

	#player = gc.getPlayer(playerIdx)
	#game.changePlayer( playerIdx, newCivType, newLeaderType, teamIdx, player.isHuman(), True )
	success = RevUtils.changeCiv( playerIdx, newCivType, newLeaderType, teamIdx )

	if( success ) :
		CyInterface().addImmediateMessage("Player %d has been changed"%(playerIdx),"")
		if( LOG_DEBUG ) : CvUtil.pyPrint( "   CP : Player change completed" )
	else :
		CyInterface().addImmediateMessage("An error occured in changeCiv.","")
		if( LOG_DEBUG ) : CvUtil.pyPrint( "   CP : Error on changeCiv" )
		return


	popup = PyPopup.PyPopup(RevDefs.updateGraphicsPopup,contextType = EventContextTypes.EVENTCONTEXT_ALL)
	popup.setBodyString("If you see any unit flags or other graphics which have not updated to the new civ type, press Ctrl+Shift+U to update them.  Note that this will end you turn and (in rare circumstances) flash other parts of the game map on the screen.\n\nYou can also do this now by clicking the top button below now.")
	popup.addButton( "Update now" )
Example #12
0
def changeHumanHandler(playerID, netUserData, popupReturn):

    if not popupReturn.getButtonClicked():  # if you pressed cancel
        return

    newHumanIdx = popupReturn.getSelectedPullDownValue(1)
    newPlayer = GC.getPlayer(newHumanIdx)
    oldHumanIdx = playerID
    oldPlayer = GC.getPlayer(oldHumanIdx)

    if newHumanIdx == oldHumanIdx:
        print "	CP: You have selected the same civ, no change"
        CyInterface().addImmediateMessage(
            "You retain control of the %s" %
            (oldPlayer.getCivilizationDescription(0)), "")
        return

    print "	CP: You have selected player %d, the %s" % (
        newHumanIdx, newPlayer.getCivilizationDescription(0))

    success = RevUtils.changeHuman(newHumanIdx, oldHumanIdx)

    if success:
        print "	CP: Active player is now %d" % GAME.getActivePlayer()
        CyInterface().addImmediateMessage(
            "You now control the %s" %
            (newPlayer.getCivilizationDescription(0)), "")
    else:
        print "	CP: Error occured, number of human players is now %d" % GAME.getNumHumanPlayers(
        )
        CyInterface().addImmediateMessage(
            "An error occured in changeHuman ...", "")


##def changeCiv( playerIdx, newCivType, newLeaderType, teamIdx = -1 ):
##	# Changes specified players civ, leader and/or team
##	# Does not change isHuman setting
##
##	player = GC.getPlayer(playerIdx)
##	success = GAME.changePlayer( playerIdx, newCivType, newLeaderType, teamIdx, player.isHuman(), True )
##
##	#GAME.convertUnits( playerIdx )
##
##	return success
##
##def changeHuman( newHumanIdx, oldHumanIdx ):
##
##	newPlayer = GC.getPlayer(newHumanIdx)
##	oldPlayer = GC.getPlayer(oldHumanIdx)
##
##	GAME.setActivePlayer( newHumanIdx, False )
##	success = GAME.changePlayer( newHumanIdx, newPlayer.getCivilizationType(), newPlayer.getLeaderType(), -1, True, False )
##	if( success ):
##		success = GAME.changePlayer( oldHumanIdx, oldPlayer.getCivilizationType(), oldPlayer.getLeaderType(), -1, False, False )
##
##	return success
Example #13
0
def init(newCustomEM, RevOptHandle):

	global revCultureModifier, cityLostModifier, cityAcquiredModifier, acquiredTurns, LOG_DEBUG, centerPopups, RevOpt, customEM
	global endWarsOnDeath, allowAssimilation, bSmallRevolts, MAX_PC_PLAYERS, MAX_PC_TEAMS

	MAX_PC_PLAYERS = GC.getMAX_PC_PLAYERS()
	MAX_PC_TEAMS = GC.getMAX_PC_TEAMS()
	RevOpt = RevOptHandle
	customEM = newCustomEM

	print "Initializing RevEvents"

	LOG_DEBUG = RevOpt.isRevDebugMode()

	# Config settings
	revCultureModifier = RevOpt.getRevCultureModifier()
	cityLostModifier = RevOpt.getCityLostModifier()
	cityAcquiredModifier = RevOpt.getCityAcquiredModifier()
	acquiredTurns = RevOpt.getAcquiredTurns()

	# Controls for event handling
	endWarsOnDeath = RevOpt.isEndWarsOnDeath()
	allowAssimilation = RevOpt.isAllowAssimilation()
	bSmallRevolts = RevOpt.isAllowSmallBarbRevs()

	centerPopups = RevOpt.isCenterPopups()

	# Register events
	customEM.addEventHandler( 'EndGameTurn', onEndGameTurn )
	customEM.addEventHandler( 'BeginPlayerTurn', onBeginPlayerTurn )
	customEM.addEventHandler( 'EndPlayerTurn', onEndPlayerTurn )
	customEM.addEventHandler( "setPlayerAlive", onSetPlayerAlive )
	customEM.addEventHandler( "changeWar", onChangeWar )
	customEM.addEventHandler( "religionFounded", onReligionFounded )

	customEM.addEventHandler( 'cityBuilt', onCityBuilt )
	customEM.addEventHandler( 'cityAcquired', onCityAcquired )
	customEM.addEventHandler( "cityLost", onCityLost )
	customEM.addEventHandler( "buildingBuilt", onBuildingBuilt )

	customEM.setPopupHandler( RevDefs.assimilationPopup, ["assimilationPopup", assimilateHandler, blankHandler] )

	RevUtils.initCivicsList()
Example #14
0
	def onKbdEvent( self, argsList ) :
		'keypress handler'
		eventType,key,mx,my,px,py = argsList

		if ( eventType == RevDefs.EventKeyDown ):
			theKey=int(key)

			if( theKey == int(InputTypes.KB_X) and self.customEM.bShift and self.customEM.bCtrl ) :
				# Get it?  Shift ... control ... to the AI
#-------------------------------------------------------------------------------------------------
# Lemmy101 RevolutionMP edit
#-------------------------------------------------------------------------------------------------
				if( game.getAIAutoPlay(game.getActivePlayer()) > 0 ) :
					try :
						bCanCancelAuto = SdToolKitCustom.sdObjectGetVal( "AIAutoPlay", game, "bCanCancelAuto" )
						if( bCanCancelAuto is None ) :
							bCanCancelAuto = True
							SdToolKitCustom.sdObjectSetVal( "AIAutoPlay", game, "bCanCancelAuto", True )
					except :
						print "Error!  AIAutoPlay: Can't find bCanCancelAuto, assuming it would be True"
						bCanCancelAuto = True

					if( bCanCancelAuto ) :
						if( self.refortify ) :
							RevUtils.doRefortify( game.getActivePlayer() )
							self.disableMultiCheck(game.getActivePlayer())
#-------------------------------------------------------------------------------------------------
# END Lemmy101 RevolutionMP edit
#-------------------------------------------------------------------------------------------------   
					  
						self.checkPlayer()
				else :
					self.toAIChooser()

			if( theKey == int(InputTypes.KB_M) and self.customEM.bShift and self.customEM.bCtrl ) :
				# Toggle auto moves
				if( self.LOG_DEBUG ) : CyInterface().addImmediateMessage("Moving your units...","")
				#self.playerID = gc.getActivePlayer().getID()
				game.setAIAutoPlay( game.getActivePlayer(), 1 )

			if( theKey == int(InputTypes.KB_O) and self.customEM.bShift and self.customEM.bCtrl ) :
				RevUtils.doRefortify( game.getActivePlayer() )
Example #15
0
def updateGraphics():
    # Switch human player around to force a redraw of unit flags
    iHuman = GAME.getActivePlayer()

    iSwitchTo = -1
    for iPlayerX in xrange(GC.getMAX_PC_PLAYERS()):
        CyPlayer = GC.getPlayer(iPlayerX)
        if not CyPlayer.isAlive():
            iSwitchTo = iPlayerX
            break

    if iSwitchTo < 0:
        iSwitchTo = 1 + GAME.getSorenRandNum(GC.getMAX_PC_PLAYERS() - 1,
                                             'ChangePlayer')

    GAME.setForcedAIAutoPlay(iHuman, 3, True)

    RevUtils.changeHuman(iSwitchTo, iHuman)

    RevUtils.changeHuman(iHuman, iSwitchTo)
Example #16
0
def updateGraphics( ) :
	# Switch human player around to force a redraw of unit flags
	iHuman = game.getActivePlayer()

	iSwitchTo = -1
	for i in range(0,gc.getMAX_CIV_PLAYERS()) :
		player = PyPlayer(i)
		if( not player.isNone() ) :
			if( not player.isAlive() ) :
				iSwitchTo = i
				break

	if( iSwitchTo < 0 ) :
		iSwitchTo = 1 + game.getSorenRandNum( gc.getMAX_CIV_PLAYERS() - 1, 'ChangePlayer')

	game.setForcedAIAutoPlay(iHuman, 3, true )

	RevUtils.changeHuman( iSwitchTo, iHuman )

	RevUtils.changeHuman( iHuman, iSwitchTo )
Example #17
0
def updateGraphics():
    # Switch human player around to force a redraw of unit flags
    iHuman = game.getActivePlayer()

    iSwitchTo = -1
    for i in range(0, gc.getMAX_CIV_PLAYERS()):
        player = PyPlayer(i)
        if (not player.isNone()):
            if (not player.isAlive()):
                iSwitchTo = i
                break

    if (iSwitchTo < 0):
        iSwitchTo = 1 + game.getSorenRandNum(gc.getMAX_CIV_PLAYERS() - 1,
                                             'ChangePlayer')

    game.setForcedAIAutoPlay(iHuman, 3, true)

    RevUtils.changeHuman(iSwitchTo, iHuman)

    RevUtils.changeHuman(iHuman, iSwitchTo)
Example #18
0
	def doNewHuman( self, iNewPlayerID, iOldPlayerID ):
	# This still not working properly. Boo.... Close though.
		CyInterface().addImmediateMessage("doNewHuman","")
		self.bLaunchedChangeHumanPopup = False
		gc.getPlayer(iOldPlayerID).setNewPlayerAlive( True )
		iSettler = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_SETTLER')
		gc.getPlayer(iOldPlayerID).initUnit( iSettler, 0, 0, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH )
		gc.getPlayer(iOldPlayerID).setFoundedFirstCity( False )
		gc.getPlayer(iOldPlayerID).setIsHuman( True )
	
		toKillPlayer = gc.getPlayer(iOldPlayerID)
		CyInterface().addImmediateMessage("calling changeHuman","")
		RevUtils.changeHuman( iNewPlayerID, iOldPlayerID )
	
		if( toKillPlayer.getNumCities() == 0 ) :
			# Kills off the lion in the ice field
			CvUtil.pyPrint("Killing off player %d"%(toKillPlayer.getID()))
			toKillPlayer.killUnits()
			toKillPlayer.setIsHuman(False)
			#success = game.changePlayer( toKillPlayer.getID(), toKillPlayer.getCivilizationType(), toKillPlayer.getLeaderType(), -1, False, False )
			toKillPlayer.setNewPlayerAlive(False)
			toKillPlayer.setFoundedFirstCity(True)
Example #19
0
    def doNewHuman(self, iPlayerNew, iPlayerOld):

        CyInterface().addImmediateMessage("doNewHuman", "")

        CyPlayer = GC.getPlayer(iPlayerOld)
        CyPlayer.setNewPlayerAlive(True)

        iSettler = GC.getInfoTypeForString("UNIT_SETTLER")
        CyPlayer.initUnit(iSettler, 0, 0, UnitAITypes.NO_UNITAI,
                          DirectionTypes.DIRECTION_SOUTH)
        CyPlayer.setFoundedFirstCity(False)
        CyPlayer.setIsHuman(True)

        CyInterface().addImmediateMessage("calling changeHuman", "")
        RevUtils.changeHuman(iPlayerNew, iPlayerOld)

        if not CyPlayer.getNumCities():
            print "Killing off player %d" % iPlayerOld
            CyPlayer.killUnits()
            CyPlayer.setIsHuman(False)
            CyPlayer.setNewPlayerAlive(False)
            CyPlayer.setFoundedFirstCity(True)
Example #20
0
    def onKbdEvent(self, argsList):
        eventType, key, mx, my, px, py = argsList

        if eventType == 6 and self.customEM.bShift and self.customEM.bCtrl:

            if key == InputTypes.KB_X:

                iPlayer = GAME.getActivePlayer()

                if GAME.getAIAutoPlay(iPlayer) > 0:
                    try:
                        bCanCancelAuto = SdToolKit.sdObjectGetVal(
                            "AIAutoPlay", GAME, "bCanCancelAuto")
                        if bCanCancelAuto is None:
                            bCanCancelAuto = True
                            SdToolKit.sdObjectSetVal("AIAutoPlay", GAME,
                                                     "bCanCancelAuto", True)
                    except:
                        print "Error! AIAutoPlay: Can't find bCanCancelAuto, assuming it would be True"
                        bCanCancelAuto = True

                    if bCanCancelAuto:
                        if self.refortify:
                            RevUtils.doRefortify(iPlayer)
                            self.disableMultiCheck(iPlayer)
                        self.checkPlayer()
                else:
                    self.toAIChooser()

            elif key == InputTypes.KB_M:
                # Toggle auto moves
                if self.LOG_DEBUG:
                    CyInterface().addImmediateMessage(
                        TRNSLTR.getText("TXT_KEY_AIAUTOPLAY_MOVING", ()), "")
                GAME.setAIAutoPlay(GAME.getActivePlayer(), 1)

            elif key == InputTypes.KB_O:
                RevUtils.doRefortify(GAME.getActivePlayer())
Example #21
0
def changeHumanHandler(playerID, netUserData, popupReturn):
    'Handles changeHuman popup'

    if (popupReturn.getButtonClicked() == 0):  # if you pressed cancel
        return

    newHumanIdx = popupReturn.getSelectedPullDownValue(1)
    newPlayer = gc.getPlayer(newHumanIdx)
    oldHumanIdx = playerID
    oldPlayer = gc.getPlayer(oldHumanIdx)

    if (newHumanIdx == oldHumanIdx):
        if (LOG_DEBUG):
            CvUtil.pyPrint("   CP : You have selected the same civ, no change")
        CyInterface().addImmediateMessage(
            "You retain control of the %s" %
            (oldPlayer.getCivilizationDescription(0)), "")
        return

    if (LOG_DEBUG):
        CvUtil.pyPrint("   CP : You have selected player %d, the %s" %
                       (newHumanIdx, newPlayer.getCivilizationDescription(0)))

    success = RevUtils.changeHuman(newHumanIdx, oldHumanIdx)

    if (success):
        if (LOG_DEBUG):
            CvUtil.pyPrint("   CP : Number of human players is now %d" %
                           (game.getNumHumanPlayers()))
        if (LOG_DEBUG):
            CvUtil.pyPrint("   CP : Active player is now %d" %
                           (game.getActivePlayer()))
        ##			for i in range(0,gc.getMAX_CIV_PLAYERS()) :
        ##				if( LOG_DEBUG ) : CvUtil.pyPrint( "   CP : Player %d is human %d"%(i,gc.getPlayer(i).isHuman()))
        CyInterface().addImmediateMessage(
            "You now control the %s" %
            (newPlayer.getCivilizationDescription(0)), "")
    else:
        if (LOG_DEBUG):
            CvUtil.pyPrint(
                "   CP : Error occured, number of human players is now %d" %
                (game.getNumHumanPlayers()))
        CyInterface().addImmediateMessage(
            "An error occured in changeHuman ...", "")
Example #22
0
def changeCivHandler(playerID, netUserData, popupReturn):
    'Handles changeCiv popup'

    if (popupReturn.getButtonClicked() == 0):  # if you pressed cancel
        return

    playerIdx = popupReturn.getSelectedPullDownValue(1)
    newCivType = popupReturn.getSelectedPullDownValue(2)
    newLeaderType = popupReturn.getSelectedPullDownValue(3)
    teamIdx = popupReturn.getSelectedPullDownValue(4)

    if ((iTeam >= 0) and (iTeam <= gc.getMAX_CIV_TEAMS())):
        playerI = gc.getPlayer(playerIdx)
        if (playerI.isAlive):
            if (LOG_DEBUG):
                CvUtil.pyPrint(
                    "   CP : You have selected player %d, the %s, on team %d" %
                    (playerIdx, playerI.getCivilizationDescription(0),
                     playerI.getTeam()))
    if ((iTeam >= 0) and (iTeam <= gc.getMAX_CIV_TEAMS())):
        teamI = gc.getTeam(teamIdx)
        if (LOG_DEBUG):
            CvUtil.pyPrint("   CP : New team idx is %d" % (teamIdx))

    #player = gc.getPlayer(playerIdx)
    #game.changePlayer( playerIdx, newCivType, newLeaderType, teamIdx, player.isHuman(), True )
    success = RevUtils.changeCiv(playerIdx, newCivType, newLeaderType, teamIdx)

    if (success):
        CyInterface().addImmediateMessage(
            "Player %d has been changed" % (playerIdx), "")
        if (LOG_DEBUG): CvUtil.pyPrint("   CP : Player change completed")
    else:
        CyInterface().addImmediateMessage("An error occured in changeCiv.", "")
        if (LOG_DEBUG): CvUtil.pyPrint("   CP : Error on changeCiv")
        return

    popup = PyPopup.PyPopup(RevDefs.updateGraphicsPopup,
                            contextType=EventContextTypes.EVENTCONTEXT_ALL)
    popup.setBodyString(
        "If you see any unit flags or other graphics which have not updated to the new civ type, press Ctrl+Shift+U to update them.  Note that this will end you turn and (in rare circumstances) flash other parts of the game map on the screen.\n\nYou can also do this now by clicking the top button below now."
    )
    popup.addButton("Update now")
Example #23
0
def changeCivHandler(playerID, netUserData, popupReturn):

    if not popupReturn.getButtonClicked():  # if you pressed cancel
        return

    iPlayer = popupReturn.getSelectedPullDownValue(1)
    newCivType = popupReturn.getSelectedPullDownValue(2)
    newLeaderType = popupReturn.getSelectedPullDownValue(3)
    iTeam = popupReturn.getSelectedPullDownValue(4)

    if iTeam > -1 and iTeam <= GC.getMAX_PC_TEAMS():
        playerI = GC.getPlayer(iPlayer)
        if playerI.isAlive:
            print "	CP: You have selected player %d, the %s, on team %d" % (
                iPlayer, playerI.getCivilizationDescription(0),
                playerI.getTeam())

            teamI = GC.getTeam(iTeam)
            print "	CP: New team idx is %d" % iTeam

    #player = GC.getPlayer(iPlayer)
    #GAME.changePlayer(iPlayer, newCivType, newLeaderType, iTeam, player.isHuman(), True)
    success = RevUtils.changeCiv(iPlayer, newCivType, newLeaderType, iTeam)

    if success:
        CyInterface().addImmediateMessage(
            "Player %d has been changed" % (iPlayer), "")
        print "	CP: Player change completed"
    else:
        CyInterface().addImmediateMessage("An error occured in changeCiv.", "")
        print "	CP: Error on changeCiv"
        return

    popup = PyPopup.PyPopup(RevDefs.updateGraphicsPopup,
                            contextType=EventContextTypes.EVENTCONTEXT_ALL)
    popup.setBodyString(
        "If you see any unit flags or other graphics which have not updated to the new civ type, press Ctrl+Shift+U to update them.  Note that this will end you turn and (in rare circumstances) flash other parts of the game map on the screen.\n\nYou can also do this now by clicking the top button below now."
    )
    popup.addButton("Update now")
Example #24
0
def checkRebelBonuses(argsList):
	# Give bonuses to a rebel player who successfully captures one of their rebellious cities
	owner, playerType, pCity, bConquest, bTrade = argsList

	newOwnerID = pCity.getOwner()
	newOwner = GC.getPlayer(newOwnerID)
	newOwnerCiv = newOwner.getCivilizationType()
	oldOwnerID = pCity.getPreviousOwner()
	orgOwnerID = pCity.getOriginalOwner()

	# TODO: Handle case where city is acquired by disorganized rebels
	if newOwnerID == GC.getBARBARIAN_PLAYER() and pCity.getRevolutionCounter() > 0:
		print "[REV] City %s captured by barb rebels!" % pCity.getName()
		oldOwner = GC.getPlayer(oldOwnerID)

		if not oldOwnerID == orgOwnerID:
			orgOwner = GC.getPlayer(orgOwnerID)

		if pCity.countTotalCultureTimes100() > 100*100:
			if not oldOwnerID == pCity.findHighestCulture():
				cultOwner = GC.getPlayer(pCity.findHighestCulture())

	elif newOwnerCiv == RevData.getCityVal(pCity, 'RevolutionCiv'):

		# TODO: Check whether revolt is active in RevoltData
		if pCity.getReinforcementCounter() > 0 or (pCity.unhappyLevel(0) - pCity.happyLevel()) > 0:
			print "[REV] Rebellious pCity %s is captured by rebel identity %s (%d)!!!" %(pCity.getName(), newOwner.getCivilizationDescription(0), newOwnerCiv)

			newOwnerTeam = GC.getTeam(newOwner.getTeam())
			oldOwner = GC.getPlayer(oldOwnerID)
			oldOwnerTeam = GC.getTeam(oldOwner.getTeam())
			if oldOwnerTeam.isAVassal():
				for teamID in xrange(MAX_PC_TEAMS):
					if oldOwnerTeam.isVassal(teamID):
						oldOwnerTeam = GC.getTeam(teamID)

			ix = pCity.getX()
			iy = pCity.getY()

			[iWorker, iBestDefender, iCounter, iAttack] = RevUtils.getHandoverUnitTypes(pCity)

			newUnitList = []

			# Couple units regardless of rebel status
			newUnitList.append(newOwner.initUnit(iBestDefender, ix, iy, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH))
			if pCity.getPopulation() > 4:
				newUnitList.append(newOwner.initUnit(iCounter, ix, iy, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH))

			if newOwner.isRebel():
				# Extra benefits if still considered a rebel
				szTxt = TRNSLTR.getText("TXT_KEY_REV_MESS_YOUR_CAPTURE",())%(pCity.getName())
				icon = CyArtFileMgr().getInterfaceArtInfo("INTERFACE_RESISTANCE").getPath()
				sound = "AS2D_CITY_REVOLT"
				eMsgType = InterfaceMessageTypes.MESSAGE_TYPE_MINOR_EVENT
				iMsgTime = GC.getEVENT_MESSAGE_TIME()
				CvUtil.sendMessage(szTxt, newOwnerID, iMsgTime, icon, ColorTypes(8), ix, iy, True, True, eMsgType, sound, False)

				szTxt = TRNSLTR.getText("TXT_KEY_REV_MESS_REBEL_CONTROL",())%(newOwner.getCivilizationDescription(0),pCity.getName())
				CvUtil.sendMessage(szTxt, oldOwnerID, iMsgTime, None, ColorTypes(7), eMsgType=eMsgType, bForce=False)

				# Gold
				iGold = GAME.getSorenRandNum(min([80,8*pCity.getPopulation()]), 'Rev') + 8
				szTxt = TRNSLTR.getText("TXT_KEY_REV_MESS_YOUR_CAPTURE_GOLD",()) %(pCity.getName(),iGold)
				CvUtil.sendMessage(szTxt, newOwnerID, iMsgTime, icon, ColorTypes(8), ix, iy, False, False, eMsgType, sound, False)
				newOwner.changeGold(iGold)

				# Culture
				newCulVal = int( revCultureModifier*max([pCity.getCulture(oldOwnerID),pCity.countTotalCultureTimes100()/200]) )
				newPlotVal = int( revCultureModifier*max([pCity.plot().getCulture(oldOwnerID),pCity.plot().countTotalCulture()/2]) )
				RevUtils.giveCityCulture( pCity, newOwnerID, newCulVal, newPlotVal)

				# Extra units
				if iWorker != -1:
					newUnitList.append(newOwner.initUnit(iWorker, ix, iy, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH))
				if pCity.getPopulation() > 7:
					newUnitList.append(newOwner.initUnit(iBestDefender, ix, iy, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH))
				if pCity.getPopulation() > 4 and newOwnerTeam.getPower(True) < oldOwnerTeam.getPower(True)/4:
					newUnitList.append(newOwner.initUnit(iAttack, ix, iy, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH))

				if newOwner.getNumCities() <= 1:
					# Extra units for first city captured
					newUnitList.append(newOwner.initUnit(iCounter, ix, iy, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH))
					if newOwnerTeam.getPower(True) < oldOwnerTeam.getPower(True)/2:
						newUnitList.append(newOwner.initUnit(iBestDefender, ix, iy, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH))
						newUnitList.append(newOwner.initUnit(iAttack, ix, iy, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH))
					elif newOwnerTeam.getPower(True) < oldOwnerTeam.getPower(True):
						newUnitList.append(newOwner.initUnit(iAttack, ix, iy, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH))

				# Give a boat to island rebels
				if pCity.isCoastal(10) and pCity.area().getNumCities() < 3 and pCity.area().getNumTiles() < 25:
					iBestCombat = -1
					for iUnitX in xrange(GC.getNumUnitInfos()):
						info = GC.getUnitInfo(iUnitX)
						if (info.getDomainType() == DomainTypes.DOMAIN_SEA
						and info.getUnitAIType(UnitAITypes.UNITAI_ASSAULT_SEA)
						and newOwner.canTrain(iUnitX,False,False)
						):
							iCombat = info.getCombat()
							if iBestCombat < iCombat:
								bestUnit = info
								iBestUnit = iUnitX
								iBestCombat = iCombat

					if iBestCombat > -1:
						newOwner.initUnit(iBestUnit, ix, iy, UnitAITypes.UNITAI_ASSAULT_SEA, DirectionTypes.DIRECTION_SOUTH)
						print "Rev - Rebels get a %s to raid motherland" % bestUnit.getDescription()

				# Change city disorder timer to favor new player
				iTurns = pCity.getOccupationTimer()
				iTurns = iTurns/4 + 1
				pCity.setOccupationTimer(iTurns)

				# Temporary happiness boost
				pCity.changeRevSuccessTimer( int(iTurns + RevUtils.getGameSpeedMod()*15) )

				# Trigger golden age for rebel civ under certain circumstances
				revTurn = RevData.revObjectGetVal(newOwner, 'RevolutionTurn')
				if not revTurn == None and GAME.getGameTurn() - revTurn < 4*GAME.goldenAgeLength():
					if newOwner.getNumCities() == 3:
						if not newOwner.getCitiesLost():
							# By verifying they've never lost a city, gaurantee it doesn't happen multiple times
							szTxt = TRNSLTR.getText("TXT_KEY_REV_MESS_GOLDEN_AGE",())
							CvUtil.sendMessage(szTxt, newOwnerID, iMsgTime, icon, ColorTypes(8), ix, iy, False, False, eMsgType, sound, False)
							newOwner.changeGoldenAgeTurns( int(1.5*GAME.goldenAgeLength()) )

			else: # Conqueror not considered a rebel, fewer benefits
				# Culture
				newCulVal = int(revCultureModifier*max([pCity.getCulture(oldOwnerID)/2,pCity.countTotalCultureTimes100()/400]))
				newPlotVal = int(revCultureModifier*max([pCity.plot().getCulture(oldOwnerID)/2,pCity.plot().countTotalCulture()/4]))
				RevUtils.giveCityCulture(pCity, newOwnerID, newCulVal, newPlotVal)

				# Change city disorder timer to favor new player
				iTurns = pCity.getOccupationTimer()
				iTurns = min([iTurns, iTurns/3 + 1])
				pCity.setOccupationTimer(iTurns)

				# Temporary happiness boost
				pCity.changeRevSuccessTimer(int(iTurns + RevUtils.getGameSpeedMod()*6))

			# Injure free units
			for unit in newUnitList:
				if unit.canFight():
					iDamage = 20 + GAME.getSorenRandNum(20,'Rev - Injure unit')
					unit.setDamage(iDamage, oldOwnerID)

		else: # City once rebelled as this civ type, but not currently rebellious
			if LOG_DEBUG:
				print "[REV] %s, captured by former rebel identity: %s (%d)!"%(pCity.getName(),newOwner.getCivilizationDescription(0),newOwnerCiv)
			newCulVal = int( revCultureModifier*max([pCity.getCulture(oldOwnerID)/2,pCity.countTotalCultureTimes100()/400]) )
			newPlotVal = int( revCultureModifier*max([pCity.plot().getCulture(oldOwnerID)/2,pCity.plot().countTotalCulture()/4]) )
			RevUtils.giveCityCulture( pCity, newOwnerID, newCulVal, newPlotVal)

			iTurns = pCity.getOccupationTimer()
			iTurns = iTurns/2 + 1
			pCity.setOccupationTimer(iTurns)
Example #25
0
def checkForAssimilation():

	iNumPlayers = 0
	iMaxEra = 0
	players = []
	for iPlayerX in xrange(MAX_PC_PLAYERS):
		CyPlayerX = GC.getPlayer(iPlayerX)
		if CyPlayerX.isAlive() and not CyPlayerX.isMinorCiv():
			iNumPlayers += 1
			if not CyPlayerX.isHuman():
				players.append((iPlayerX, CyPlayerX))
			iEra = CyPlayerX.getCurrentEra()
			if iEra > iMaxEra:
				iMaxEra = iEra

	if iNumPlayers == 0: return

	MAP = GC.getMap()

	minNumPlots = int((MAP.getLandPlots()/(1.0*iNumPlayers) + .5)/3.0) + 1
	if minNumPlots > 21: minNumPlots = 21
	elif minNumPlots < 9: minNumPlots = 9

	iTurn = GAME.getGameTurn()
	for iPlayerX, CyPlayerX in players:

		CyTeamX = GC.getTeam(CyPlayerX.getTeam())
		CyCity0 = CyPlayerX.getCapitalCity()
		if CyCity0 is None: continue
		iTurnAcquiredCity0 = CyCity0.getGameTurnAcquired()
		CyPlot0 = None
		szCiv = CyPlayerX.getCivilizationDescription(0)

		iMinCities = GC.getWorldInfo(MAP.getWorldSize()).getTargetNumCities()
		iNumCities = CyPlayerX.getNumCities() # We know this is greater than 0 as a capital city has been confirmed.

		bRiskWar = False
		iPlayerML = RevData.revObjectGetVal(CyPlayerX, 'MotherlandID')

		if iPlayerML != None:
			CyPlayerML = GC.getPlayer(iPlayerML)
			bWarSeparatist = CyTeamX.isAtWar(CyPlayerML.getTeam())
			if bWarSeparatist:
				revTurn = RevData.revObjectGetVal(CyPlayerX, 'RevolutionTurn')
				if revTurn != None and iTurn - revTurn < 40:
					bRiskWar = True

		CyPlayerDominant = None
		joinPlayerID = RevData.revObjectGetVal(CyPlayerX, 'JoinPlayerID')

		if not joinPlayerID == None and iTurn - iTurnAcquiredCity0 < 30 and not CyTeamX.isAVassal():
			if iNumCities < iMinCities:
				iOdds = 12 + iNumCities * 2

				if iPlayerML != None and bWarSeparatist:
					iCivType = CyPlayerX.getCivilizationType()
					for CyCityML in CyPlayerML.cities():
						if RevData.getCityVal(CyCityML, 'RevolutionCiv') == iCivType:
							revTurn = RevData.getCityVal(pCity, 'RevolutionTurn')
							if revTurn != None and iTurn - revTurn < 25:
								iOdds -= 2

				if iOdds > 10 + GAME.getSorenRandNum(100, 'Revolution: Assimilate'):
					CyPlayerDominant = GC.getPlayer(joinPlayerID)
					print "	Revolt - Assimilation! The rebel %s are requesting again to join the %s now that they've captured %d cities"%(szCiv, CyPlayerDominant.getCivilizationDescription(0), iNumCities)


		else:
			if iTurn - iTurnAcquiredCity0 > 15 and iNumCities < iMinCities:
				iTotalLand = CyPlayerX.getTotalLand()
				if iTotalLand < minNumPlots:

					if CyCity0.area().getNumCities() < iNumCities + 2:
						continue # Isolated

					if CyTeamX.getNumMembers() > 1:
						continue # In alliance

					iOdds = 2*(minNumPlots - iTotalLand) + (4 + 4*iMaxEra)/CyCity0.getPopulation()

					if CyCity0.getOccupationTimer() > 0:
						iOdds *= 3

					iOdds += CyCity0.getRevolutionIndex()/100

					CyPlot0 = CyCity0.plot()
					### Special cases
					if CyTeamX.isAVassal():

						if iOdds > 10 + GAME.getSorenRandNum(100, 'Revolution: Assimilate'):

							# If player is a Vassal, should only be allowed to assimilate with master
							CyPlayerMaster = None
							for iTeamY in xrange(MAX_PC_TEAMS):
								if not CyTeamX.isVassal(iTeamY): continue

								iPlayerMaster = GC.getTeam(iTeamY).getLeaderID()
								CyPlayerMaster = GC.getPlayer(iPlayerMaster)

								print "	Revolt - Assimilation!  Vassal %s considering assimilation to master %s" %(szCiv, CyPlayerMaster.getCivilizationDescription(0))

								relations = CyPlayerX.AI_getAttitude(iPlayerMaster)

								if CyPlot0.getCulture(iPlayerMaster)/(1.0*CyPlot0.countTotalCulture()) > .25:
									# Assimilate with master with large culture in city
									if not relations == AttitudeTypes.ATTITUDE_FURIOUS:

										if not CyPlayerMaster.isHuman():
											CyPlayerDominant = CyPlayerMaster

										elif not iPlayerX in noAssimilateList:
											CyPlayerDominant = CyPlayerMaster
										if CyPlayerDominant:
											print "	Revolt - Assimilation to master based on culture"

								elif relations in (AttitudeTypes.ATTITUDE_PLEASED, AttitudeTypes.ATTITUDE_FRIENDLY):
									# Assimilate with friendly, powerful master
									masterPower = CyPlayerMaster.getPower()
									vassalPower = CyPlayerX.getPower()

									if masterPower > 3*vassalPower:
										if not CyPlayerMaster.isHuman():
											CyPlayerDominant = CyPlayerMaster
										elif not iPlayerX in noAssimilateList:
											CyPlayerDominant = CyPlayerMaster
										if CyPlayerDominant:
											print "	Revolt - Assimilation to friendly and powerful master"
								break

					elif CyPlot0.calculateCulturePercent(iPlayerX) < 60:
						### Capital has foreign influence
						iPlayerCult = CyPlot0.calculateCulturalOwner() # iPlayerCult guaranteed to be alive
						if iPlayerCult != iPlayerX:
							iOdds += 15

						if iOdds > 10 + GAME.getSorenRandNum(100, 'Revolution: Assimilate'):
							print "	Revolt - Assimilation!  %s considering assimilation by culture" % szCiv

							if iPlayerCult > -1 and iPlayerCult != iPlayerX and not CyPlayerX.AI_getAttitude(iPlayerCult) == AttitudeTypes.ATTITUDE_FURIOUS:
								## Assimilate with cultural owner
								CyPlayerY = GC.getPlayer(iPlayerCult)
								if CyPlayerY.isAlive():
									if not CyPlayerY.isHuman():
										CyPlayerDominant = CyPlayerY
									elif not iPlayerX in noAssimilateList:
										CyPlayerDominant = CyPlayerY
									if CyPlayerDominant:
										print "	Revolt - Assimilation culture owner: " + CyPlayerDominant.getCivilizationDescription(0)

							if not CyPlayerDominant:
								## Check for good relations with second place culture
								iMaxCult2 = 0
								for iPlayerY in xrange(MAX_PC_PLAYERS):
									if iPlayerY in (iPlayerX, iPlayerCult): continue
									CyPlayerY = GC.getPlayer(iPlayerY)
									if not CyPlayerY.isAlive(): continue
									iCulture = CyPlot0.getCulture(iPlayerY)
									if iCulture > iMaxCult2:
										iPlayerCult2 = iPlayerY
										CyPlayerCult2 = CyPlayerY
										iMaxCult2 = iCulture

								iTotalCulture = CyPlot0.countTotalCulture()
								if iMaxCult2/(1.0*iTotalCulture) > .2:
									relations = CyPlayerX.AI_getAttitude(iPlayerCult2)
									if relations in (AttitudeTypes.ATTITUDE_PLEASED, AttitudeTypes.ATTITUDE_FRIENDLY) \
									or relations == AttitudeTypes.ATTITUDE_CAUTIOUS and iMaxCult2/(1.0*iTotalCulture) > .4:
										if not CyPlayerCult2.isHuman():
											CyPlayerDominant = CyPlayerCult2
										elif not iPlayerX in noAssimilateList:
											CyPlayerDominant = CyPlayerCult2
										if CyPlayerDominant:
											print "	Revolt - Assimilation to friendly, 2nd culture player"

		if CyPlayerDominant:
			# Assimilate!
			if CyPlayerDominant.isHuman():
				# Zoom to city
				if CyPlot0 is None: CyPlot0 = CyCity0.plot()
				CyCamera().JustLookAt(CyPlot0.getPoint())
				# Additions by Caesium et al
				caesiumtR = CyUserProfile().getResolutionString(CyUserProfile().getResolution())
				caesiumtextResolution = caesiumtR.split('x')
				caesiumpasx = int(caesiumtextResolution[0])/10
				caesiumpasy = int(caesiumtextResolution[1])/10
				popup = PyPopup.PyPopup(RevDefs.assimilationPopup, contextType = EventContextTypes.EVENTCONTEXT_ALL, bDynamic = False)
				if centerPopups: popup.setPosition(3*caesiumpasx,3*caesiumpasy)
				# Additions by Caesium et al
				bodStr = TRNSLTR.getText("TXT_KEY_REV_ASSIM_POPUP", ()) %(szCiv, szCiv)
				if bRiskWar:
					bodStr += '\n\n' + TRNSLTR.getText("TXT_KEY_REV_ASSIM_POPUP_REBEL", ())%(CyPlayerML.getCivilizationDescription(0))
				popup.setBodyString(bodStr)
				popup.addSeparator()
				popup.addButton(TRNSLTR.getText("TXT_KEY_REV_BUTTON_ACCEPT",()))
				popup.addButton(TRNSLTR.getText("TXT_KEY_REV_BUTTON_MAYBE_LATER",()))
				popup.addButton(TRNSLTR.getText("TXT_KEY_REV_BUTTON_NEVER",()))
				popup.setUserData((iPlayerX, CyPlayerDominant.getID(), bRiskWar))
				popup.launch(bCreateOkButton = False)
			else:
				if bRiskWar:
					# Assimilating a rebel involves potential war declaration, attitude issues
					CyPlayerML.AI_changeAttitudeExtra(CyPlayerDominant.getID(), CyPlayerML.AI_getAttitudeExtra(iPlayerX))
					print "	Revolt - The %s (motherland of the rebel %s) is considering attacking the %s over the assimilation"%(CyPlayerML.getCivilizationDescription(0),szCiv,CyPlayerDominant.getCivilizationDescription(0))
					[iOdds,attackerTeam,victimTeam] = RevUtils.computeWarOdds(CyPlayerML, CyPlayerDominant, CyCity0.area(), False, True, True )
					if attackerTeam.canDeclareWar(victimTeam.getID()) and iOdds > GAME.getSorenRandNum(100, 'Revolution: War'):
						print "  Revolt - Rebel motherland takes exception to assimilation, team %d declare war on team %d"%(attackerTeam.getID(), victimTeam.getID())
						attackerTeam.declareWar( victimTeam.getID(), True, WarPlanTypes.NO_WARPLAN )

				CyPlayerDominant.assimilatePlayer(iPlayerX)
Example #26
0
	def newNameByCivics( self, iPlayer, bVerbose = True, bForceUpdate = False ) :
		# Assigns a new name to a player based on their civics choices

		pPlayer = gc.getPlayer(iPlayer)
		capital = pPlayer.getCapitalCity()
		playerEra = pPlayer.getCurrentEra()
		pTeam = gc.getTeam(pPlayer.getTeam())
		
		cityString = None
		if( not capital == None and not capital.isNone() ) :
			try :
				# Silly game to force ascii encoding now
				cityString =  pPlayer.getCivilizationDescription(0)
				cityString += "&" + CvUtil.convertToStr(capital.getName())
				cityString =  cityString.split('&',1)[-1]
			except :
				pass

		curDesc  = pPlayer.getCivilizationDescription(0)
		curShort = pPlayer.getCivilizationShortDescription(0)
		curAdj   = pPlayer.getCivilizationAdjective(0)

		civInfo = gc.getCivilizationInfo(pPlayer.getCivilizationType())
		origDesc  = civInfo.getDescription()
		
		eGovCivic = pPlayer.getCivics(gc.getInfoTypeForString("CIVICOPTION_GOVERNMENT"))
		bNoRealElections = (gc.getInfoTypeForString("CIVIC_HEREDITARY_RULE") == eGovCivic or gc.getInfoTypeForString("CIVIC_HEREDITARY_RULE") == eGovCivic or gc.getInfoTypeForString("CIVIC_DESPOTISM") == eGovCivic or gc.getInfoTypeForString("CIVIC_FASCIST") == eGovCivic)
		
		if( not game.isOption(GameOptionTypes.GAMEOPTION_LEAD_ANY_CIV) ) :
			if( pPlayer.getLeaderType() in LeaderCivNames.LeaderCivNames.keys() ) :
				[curDesc,curShort,curAdj] = LeaderCivNames.LeaderCivNames[pPlayer.getLeaderType()]

		newName = curDesc
		if( SDTK.sdObjectExists( "Revolution", pPlayer ) ) :
			revTurn = SDTK.sdObjectGetVal( "Revolution", pPlayer, 'RevolutionTurn' )
		else :
			revTurn = None

		if( SDTK.sdObjectExists( "BarbarianCiv", pPlayer ) ) :
			barbTurn = SDTK.sdObjectGetVal( "BarbarianCiv", pPlayer, 'SpawnTurn' )
		else :
			barbTurn = None

		if( not pPlayer.isAlive() ) :
			if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is not alive")
			newName = localText.getText("TXT_KEY_MOD_DCN_REFUGEES", ())%(curAdj)
			return [newName, curShort, curAdj]
		
		if( pPlayer.isRebel() ) :
			# Maintain name of rebels from Revolution Mod
			if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is rebel, keeping current name")
			if( bForceUpdate ) :
				return self.nameForNewPlayer(iPlayer)
			else :
				return [curDesc, curShort, curAdj]
		elif( pPlayer.isMinorCiv() and not barbTurn == None ) :
			# Maintain minor civ name
			if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is Minor Barb Civ, keeping current name")
			if( bForceUpdate ) :
				return self.nameForNewPlayer(iPlayer)
			else :
				return [curDesc, curShort, curAdj]
		elif( not barbTurn == None and game.getGameTurn() - barbTurn < 20 and pPlayer.getNumCities() < 4 ) :
			# Maintain name of BarbarianCiv created player
			if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is BarbCiv, keeping current name")
			if( bForceUpdate ) :
				return self.nameForNewPlayer(iPlayer)
			else :
				return [curDesc, curShort, curAdj]

		
		# Special options for teams and permanent alliances
		if( self.bTeamNaming and pTeam.getNumMembers() > 1 ) : # and pTeam.getPermanentAllianceTradingCount() > 0 ) :
			if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - Multiple players on team")
			if( self.LOG_DEBUG and bVerbose and pTeam.getPermanentAllianceTradingCount() > 0 ) : CvUtil.pyPrint("Names - Player in Permanent Alliance")
			if( pTeam.getNumMembers() == 2 ) :
				iLeader = pTeam.getLeaderID()
				newName = gc.getPlayer(iLeader).getCivilizationAdjective(0) + "-"
				for idx in range(0,gc.getMAX_CIV_PLAYERS()):
					if( not idx == iLeader and gc.getPlayer(idx).getTeam() == pTeam.getID() ) :
						newName += gc.getPlayer(idx).getCivilizationAdjective(0)
						break
				newName += u" " + localText.getText("TXT_KEY_MOD_DCN_ALLIANCE", ())
				return [newName,curShort,curAdj]
			else :
				iLeader = pTeam.getLeaderID()
				newName = gc.getPlayer(iLeader).getCivilizationAdjective(0)[0:4]
				for idx in range(0,gc.getMAX_CIV_PLAYERS()):
					if( not idx == iLeader and gc.getPlayer(idx).getTeam() == pTeam.getID() ) :
						newName += gc.getPlayer(idx).getCivilizationAdjective(0)[0:3]
				newName += u" " + localText.getText("TXT_KEY_MOD_DCN_ALLIANCE", ())
				return [newName,curShort,curAdj]
		
		sSocRep = localText.getText("TXT_KEY_MOD_DCN_SOC_REP", ()).replace('%s','').strip()
		sPeoplesRep = localText.getText("TXT_KEY_MOD_DCN_PEOPLES_REP", ()).replace('%s','').strip()
		
		# Main naming conditions
		if( RevUtils.isCommunism(iPlayer) ) :
			if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is communist")
			if( RevUtils.isCanDoElections(iPlayer) and not bNoRealElections) :
				if( not bForceUpdate and (sSocRep in curDesc or sPeoplesRep in curDesc) ) :
					if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - keeping prior name")
					newName = curDesc
				elif( 50 > game.getSorenRandNum(100,'Rev: Naming') ) :
					newName = localText.getText("TXT_KEY_MOD_DCN_SOC_REP", ())%(curShort)
				else :
					newName = localText.getText("TXT_KEY_MOD_DCN_PEOPLES_REP", ())%(curShort)
			elif( RevUtils.getDemocracyLevel(iPlayer)[0] == -8 ) :
				if( localText.getText("TXT_KEY_MOD_DCN_RUSSIAN_MATCH", ()) in curAdj ) :
					curAdj = localText.getText("TXT_KEY_MOD_DCN_SOVIET", ())
				newName = localText.getText("TXT_KEY_MOD_DCN_UNION", ())%(curAdj)
			else :
				newName = localText.getText("TXT_KEY_MOD_DCN_PEOPLES_REP", ())%(curShort)
		elif( RevUtils.isCanDoElections(iPlayer) and not bNoRealElections) :
			if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player can do elections")
			sRepOf = localText.getText("TXT_KEY_MOD_DCN_REPUBLIC_OF", ()).replace('%s','').strip()
			sRepublic = localText.getText("TXT_KEY_MOD_DCN_REPUBLIC", ())
			
			if( pPlayer.getNumCities() == 1 ) :
				if( not bForceUpdate and (curDesc.startswith(localText.getText("TXT_KEY_MOD_DCN_FREE", ())) or ((sRepOf in curDesc or sRepublic in curDesc) and cityString in curDesc)) ) :
					if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - keeping prior name")
					newName = curDesc
				elif( 40 > game.getSorenRandNum(100,'Rev: Naming') ) :
					newName = localText.getText("TXT_KEY_MOD_DCN_FREE_STATE", ())%(curAdj)
				else :
					if( not cityString == None and len(cityString) < 10 and len(cityString) > 0) :
						if( cityString in curAdj or cityString in curShort ) :
							newName = localText.getText("TXT_KEY_MOD_DCN_THE_REPUBLIC_OF_CITY", ())%(cityString)
						else :
							newName = localText.getText("TXT_KEY_MOD_DCN_REPUBLIC_OF_CITY", ())%(curAdj,cityString)
					else :
						newName = localText.getText("TXT_KEY_MOD_DCN_FREE_REPUBLIC", ())%(curAdj)
			else :
				if( not bForceUpdate and (sRepublic in curDesc and not sPeoplesRep in curDesc and not sSocRep in curDesc and curDesc.startswith(localText.getText("TXT_KEY_MOD_DCN_FREE", ()))) ) :
					if( len(curDesc) < 17 and 20 > game.getSorenRandNum(100,'Rev: Naming') and not localText.getText("TXT_KEY_MOD_DCN_NEW", ()) in curDesc ) :
						newName = localText.getText("TXT_KEY_MOD_DCN_NEW", ()) + curDesc
					else :
						if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - keeping prior name")
						newName = curDesc
				elif( 50 > game.getSorenRandNum(100,'Rev: Naming') ) :
					newName = localText.getText("TXT_KEY_MOD_DCN_REPUBLIC", ())%(curAdj)
				else :
					newName = localText.getText("TXT_KEY_MOD_DCN_THE_REPUBLIC_OF", ())%(curShort)

			if( RevUtils.isFreeSpeech(iPlayer) and RevUtils.getLaborFreedom(iPlayer)[0] > 9 ) :
				if( len(newName) < 16 and not localText.getText("TXT_KEY_MOD_DCN_FREE", ()) in newName and not localText.getText("TXT_KEY_MOD_DCN_NEW", ()) in newName ) :
					newName = localText.getText("TXT_KEY_MOD_DCN_FREE", ()) + ' ' + newName
		elif( RevUtils.getDemocracyLevel(iPlayer)[0] == -8 ) :
			if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is police state")
			empString = localText.getText("TXT_KEY_MOD_DCN_PLAIN_EMPIRE", ())
			if( localText.getText("TXT_KEY_MOD_DCN_GERMAN_MATCH", ()) in curAdj ) :
				empString = localText.getText("TXT_KEY_MOD_DCN_REICH", ())
			
			if( not bForceUpdate and empString in curDesc ) :
				if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - keeping prior name")
				newName = curDesc
			elif( 70 > game.getSorenRandNum(100,'Rev: Naming') and not localText.getText("TXT_KEY_MOD_DCN_REICH", ()) in empString ) :
				newName = localText.getText("TXT_KEY_MOD_DCN_THE_BLANK_OF", ())%(empString,curShort)
			else :
				newName = curAdj + ' ' + empString
		else :
			sGreat = localText.getText("TXT_KEY_MOD_DCN_GREAT_KINGDOM", ()).replace('%s','').strip()
			sKingdom = localText.getText("TXT_KEY_MOD_DCN_KINGDOM", ())
			if( RevUtils.getDemocracyLevel(iPlayer)[0] == -6 ) :

				if( pTeam.isAVassal() ) :
					if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is a vassal")
					sKingdom = localText.getText("TXT_KEY_MOD_DCN_DUCHY", ())
				else :
					if( localText.getText("TXT_KEY_MOD_DCN_PERSIAN_MATCH", ()) in curAdj or localText.getText("TXT_KEY_MOD_DCN_OTTOMAN_MATCH", ()) in curAdj or localText.getText("TXT_KEY_MOD_DCN_SUMERIAN_MATCH", ()) in curAdj ) :
						sKingdom = localText.getText("TXT_KEY_MOD_DCN_SULTANATE", ())
					elif( localText.getText("TXT_KEY_MOD_DCN_ARABIAN_MATCH", ()) in curAdj ) :
						sKingdom = localText.getText("TXT_KEY_MOD_DCN_CALIPHATE", ())
				
				if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is in monarchy")
				if( pPlayer.getNumCities() < 4 ) :
					if( not cityString == None and len(cityString) < 10 and len(cityString) > 0 ) :
						if( cityString in curAdj or cityString in curShort ) :
							newName = localText.getText("TXT_KEY_MOD_DCN_THE_BLANK_OF_CITY", ())%(sKingdom,cityString)
						else :
							newName = localText.getText("TXT_KEY_MOD_DCN_BLANK_OF_CITY", ())%(sKingdom,curAdj,cityString)
					else :
						newName = curAdj + ' ' + sKingdom
				elif( game.getPlayerRank(iPlayer) < game.countCivPlayersAlive()/7 and not pTeam.isAVassal() and (sGreat in curDesc or 40 > game.getSorenRandNum(100,'Rev: Naming')) ) :
					newName = localText.getText("TXT_KEY_MOD_DCN_GREAT_KINGDOM", ())%(curAdj,sKingdom)
				else :
					sOf = localText.getText("TXT_KEY_MOD_DCN_THE_BLANK_OF", ()).replace('%s','')
					if( not bForceUpdate and sKingdom in curDesc and (not sOf in curDesc or pPlayer.getNumCities < 6) and (not sGreat in curDesc) ) :
						if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - keeping prior name")
						newName = curDesc
					elif( 50 > game.getSorenRandNum(100,'Rev: Naming') ) :
						newName = curAdj + ' ' + sKingdom
					else :
						newName = localText.getText("TXT_KEY_MOD_DCN_THE_BLANK_OF", ())%(sKingdom,curShort)
			
			elif( RevUtils.getDemocracyLevel(iPlayer)[0] == -10 or playerEra == 0 ) :
				
				empString = localText.getText("TXT_KEY_MOD_DCN_PLAIN_EMPIRE", ())
				if( playerEra < 2 and pPlayer.getNumCities() < 3 ) :
					if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player has one city in early era")
					empString = localText.getText("TXT_KEY_MOD_DCN_PLAIN_CITY_STATE", ())
				if( pTeam.isAVassal() ) :
					if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is a vassal")
					empString = localText.getText("TXT_KEY_MOD_DCN_FIEFDOM", ())
				
				if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is in despotism")
				if( not bForceUpdate and empString in curDesc and not game.getGameTurn() == 0 ) :
					if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - keeping prior name")
					newName = curDesc
				elif( 50 > game.getSorenRandNum(100,'Rev: Naming') ) :
					newName = curAdj + ' ' + empString
				else :
					newName = localText.getText("TXT_KEY_MOD_DCN_THE_BLANK_OF", ())%(empString,curShort)
			
			else :
				if( self.LOG_DEBUG and bVerbose ) : 
					CvUtil.pyPrint("Names - Error: player fits no government category ... ")
					return [curDesc,curShort,curAdj]
					
			sHoly = localText.getText("TXT_KEY_MOD_DCN_HOLY", ()) + ' '
			if( RevUtils.getReligiousFreedom(iPlayer)[0] < -9 ) :
				if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is theocracy")
				if( len(newName) < 16 and not sHoly in newName and not sGreat in newName and not newName.startswith(localText.getText("TXT_KEY_MOD_DCN_HOLY_HRE_MATCH", ())) ) :
					newName = sHoly + newName
			elif( newName.startswith(sHoly) and not origDesc.startswith(sHoly) ) :
				# Cut off any inappropriately saved 'Holy ' prefix
				newName = newName[len(sHoly):]

		return [newName, curShort, curAdj]
Example #27
0
    def newNameByCivics(self, iPlayer, bVerbose=True, bForceUpdate=False):
        # Assigns a new name to a player based on their civics choices

        pPlayer = gc.getPlayer(iPlayer)
        capital = pPlayer.getCapitalCity()
        playerEra = pPlayer.getCurrentEra()
        pTeam = gc.getTeam(pPlayer.getTeam())

        cityString = None
        if capital:
            try:
                # Silly game to force ascii encoding now
                cityString = pPlayer.getCivilizationDescription(0)
                cityString += "&" + CvUtil.convertToStr(capital.getName())
                cityString = cityString.split('&', 1)[-1]
            except:
                pass

        curDesc = pPlayer.getCivilizationDescription(0)
        curShort = pPlayer.getCivilizationShortDescription(0)
        curAdj = pPlayer.getCivilizationAdjective(0)

        origDesc = ""
        if (pPlayer.getCivilizationType() >= 0):
            civInfo = gc.getCivilizationInfo(pPlayer.getCivilizationType())
            origDesc = civInfo.getDescription()

        eLeader = pPlayer.getLeaderType()

        bFemaleLeader = self.isFemaleLeader(eLeader)

        iLanguage = gc.getGame().getCurrentLanguage()
        bFrench = iLanguage == 1  #0 - English, 1 - French, 2 - German, 3 - Italian, 4 - Spanish

        eGovCivic = pPlayer.getCivics(
            gc.getInfoTypeForString("CIVICOPTION_GOVERNMENT"))
        ePowerCivic = pPlayer.getCivics(
            gc.getInfoTypeForString("CIVICOPTION_POWER"))
        bNoRealElections = (
            gc.getInfoTypeForString("CIVIC_MONARCHY") == eGovCivic
            or gc.getInfoTypeForString("CIVIC_MONARCHY") == eGovCivic
            or gc.getInfoTypeForString("CIVIC_DESPOTISM") == eGovCivic
            or gc.getInfoTypeForString("CIVIC_TOTALITARIANISM") == eGovCivic)

        bFederal = (gc.getInfoTypeForString("CIVIC_FEDERALISM") == eGovCivic
                    and (ePowerCivic
                         == gc.getInfoTypeForString("CIVIC_LEGISLATURE")))
        bConfederation = (not bFederal
                          and (gc.getInfoTypeForString("CIVIC_FEDERALISM")
                               == eGovCivic))

        bPacifist = (pPlayer.getCivics(
            gc.getInfoTypeForString("CIVICOPTION_MILITARY")) ==
                     gc.getInfoTypeForString("CIVIC_PACIFISM"))

        if (not game.isOption(GameOptionTypes.GAMEOPTION_LEAD_ANY_CIV)):
            if (pPlayer.getLeaderType()
                    in LeaderCivNames.LeaderCivNames.keys()):
                [curDesc, curShort, curAdj
                 ] = LeaderCivNames.LeaderCivNames[pPlayer.getLeaderType()]

        newName = curDesc
        if (SDTK.sdObjectExists("Revolution", pPlayer)):
            revTurn = SDTK.sdObjectGetVal("Revolution", pPlayer,
                                          'RevolutionTurn')
        else:
            revTurn = None

        if (SDTK.sdObjectExists("BarbarianCiv", pPlayer)):
            barbTurn = SDTK.sdObjectGetVal("BarbarianCiv", pPlayer,
                                           'SpawnTurn')
        else:
            barbTurn = None

        if (not pPlayer.isAlive()):
            newName = localText.getText("TXT_KEY_MOD_DCN_REFUGEES",
                                        ()) % (curAdj)
            return [newName, curShort, curAdj]

        if pPlayer.isRebel():
            # Maintain name of rebels from Revolution Mod
            if bForceUpdate:
                return self.nameForNewPlayer(iPlayer)
            else:
                return [curDesc, curShort, curAdj]
        elif (pPlayer.isMinorCiv() and not barbTurn == None):
            # Maintain minor civ name
            if bForceUpdate:
                return self.nameForNewPlayer(iPlayer)
            else:
                return [curDesc, curShort, curAdj]
        elif (not barbTurn == None and game.getGameTurn() - barbTurn < 20
              and pPlayer.getNumCities() < 4):
            # Maintain name of BarbarianCiv created player
            if bForceUpdate:
                return self.nameForNewPlayer(iPlayer)
            else:
                return [curDesc, curShort, curAdj]

        # Special options for teams and permanent alliances
        if (self.bTeamNaming and pTeam.getNumMembers() >
                1):  # and pTeam.getPermanentAllianceTradingCount() > 0 ) :
            if (pTeam.getNumMembers() == 2):
                iLeader = pTeam.getLeaderID()
                newName = gc.getPlayer(iLeader).getCivilizationAdjective(
                    0) + "-"
                for idx in range(0, gc.getMAX_PC_PLAYERS()):
                    if (not idx == iLeader
                            and gc.getPlayer(idx).getTeam() == pTeam.getID()):
                        newName += gc.getPlayer(idx).getCivilizationAdjective(
                            0)
                        break
                newName += u" " + localText.getText("TXT_KEY_MOD_DCN_ALLIANCE",
                                                    ())
                return [newName, curShort, curAdj]
            else:
                iLeader = pTeam.getLeaderID()
                newName = gc.getPlayer(iLeader).getCivilizationAdjective(
                    0)[0:4]
                for idx in range(0, gc.getMAX_PC_PLAYERS()):
                    if not idx == iLeader and gc.getPlayer(
                            idx).getTeam() == pTeam.getID():
                        newName += gc.getPlayer(idx).getCivilizationAdjective(
                            0)[0:3]
                newName += u" " + localText.getText("TXT_KEY_MOD_DCN_ALLIANCE",
                                                    ())
                return [newName, curShort, curAdj]

        sSocRep = localText.getText("TXT_KEY_MOD_DCN_SOC_REP",
                                    ()).replace('%s', '').strip()
        sPeoplesRep = localText.getText("TXT_KEY_MOD_DCN_PEOPLES_REP",
                                        ()).replace('%s', '').strip()

        # Anarchy Naming
        if pPlayer.isAnarchy and pPlayer.getAnarchyTurns() > 1:
            if 75 > game.getSorenRandNum(100, 'Rev: Naming'):
                newName = localText.getText("TXT_KEY_MOD_DCN_PROVISIONAL_GOV",
                                            ()) % (curAdj)
            else:
                newName = localText.getText("TXT_KEY_MOD_DCN_PROVISIONAL_AUTH",
                                            ()) % (curAdj)
            return [newName, curShort, curAdj]

        if (not pPlayer.isAnarchy
                or pPlayer.getAnarchyTurns() < 2) and "Provisional" in curDesc:
            if gc.getInfoTypeForString("CIVIC_MONARCHY") == eGovCivic:
                newName = curAdj + ' ' + localText.getText(
                    "TXT_KEY_MOD_DCN_KINGDOM", ())
            elif (gc.getInfoTypeForString("CIVIC_REPUBLIC") == eGovCivic):
                newName = localText.getText("TXT_KEY_MOD_DCN_REPUBLIC",
                                            ()) % (curAdj)
            else:
                newName = curAdj + ' Nation'
            return [newName, curShort, curAdj]

        # Main naming conditions
        if RevUtils.isCommunism(iPlayer):
            if RevUtils.isCanDoElections(iPlayer) and not bNoRealElections:
                if not bForceUpdate and (sSocRep in curDesc
                                         or sPeoplesRep in curDesc):
                    newName = curDesc
                elif 50 > game.getSorenRandNum(100, 'Rev: Naming'):
                    newName = localText.getText("TXT_KEY_MOD_DCN_SOC_REP",
                                                ()) % (curShort)
                else:
                    newName = localText.getText("TXT_KEY_MOD_DCN_PEOPLES_REP",
                                                ()) % (curShort)
            elif (RevUtils.getDemocracyLevel(iPlayer)[0] == -8):
                if (localText.getText("TXT_KEY_MOD_DCN_RUSSIAN_MATCH", ())
                        in curAdj):
                    curAdj = localText.getText("TXT_KEY_MOD_DCN_SOVIET", ())
                newName = localText.getText("TXT_KEY_MOD_DCN_UNION",
                                            ()) % (curAdj)
            else:
                newName = localText.getText("TXT_KEY_MOD_DCN_PEOPLES_REP",
                                            ()) % (curShort)
        elif (RevUtils.isCanDoElections(iPlayer) and not bNoRealElections):
            sRepOf = localText.getText("TXT_KEY_MOD_DCN_REPUBLIC_OF",
                                       ()).replace('%s', '').strip()
            sRepublic = localText.getText("TXT_KEY_MOD_DCN_REPUBLIC", ())

            if pPlayer.getNumCities() == 1:
                if (not bForceUpdate
                        and (curDesc.startswith(
                            localText.getText("TXT_KEY_MOD_DCN_FREE", ())) or
                             ((sRepOf in curDesc or sRepublic in curDesc)
                              and cityString in curDesc))):
                    newName = curDesc
                elif 40 > game.getSorenRandNum(100, 'Rev: Naming'):
                    newName = localText.getText("TXT_KEY_MOD_DCN_FREE_STATE",
                                                ()) % (curAdj)
                else:
                    if (not cityString == None and len(cityString) < 10
                            and len(cityString) > 0):
                        if (cityString in curAdj or cityString in curShort):
                            newName = localText.getText(
                                "TXT_KEY_MOD_DCN_THE_REPUBLIC_OF_CITY",
                                ()) % (cityString)
                        else:
                            newName = localText.getText(
                                "TXT_KEY_MOD_DCN_REPUBLIC_OF_CITY",
                                ()) % (curAdj, cityString)
                    else:
                        newName = localText.getText(
                            "TXT_KEY_MOD_DCN_FREE_REPUBLIC", ()) % (curAdj)
            else:
                if (not bFederal and not bConfederation and not bForceUpdate
                        and
                    (sRepublic in curDesc and not sPeoplesRep in curDesc
                     and not sSocRep in curDesc and curDesc.startswith(
                         localText.getText("TXT_KEY_MOD_DCN_FREE", ())))):
                    if (len(curDesc) < 17
                            and 20 > game.getSorenRandNum(100, 'Rev: Naming')
                            and not localText.getText("TXT_KEY_MOD_DCN_NEW",
                                                      ()) in curDesc):
                        newName = localText.getText("TXT_KEY_MOD_DCN_NEW",
                                                    ()) + curDesc
                    else:
                        newName = curDesc
                elif bFederal:
                    if (pPlayer.getCivilizationType() ==
                            gc.getInfoTypeForString(
                                "CIVILIZATION_UNITED_STATES")):
                        newName = localText.getText(
                            "TXT_KEY_MOD_DCN_UNITED_STATES", ()) % (curShort)
                    elif 50 > game.getSorenRandNum(100, 'Rev: Naming'):
                        newName = localText.getText(
                            "TXT_KEY_MOD_DCN_FEDERATED_STATES",
                            ()) % (curShort)
                    else:
                        newName = localText.getText(
                            "TXT_KEY_MOD_DCN_FEDERATION", ()) % (curAdj)
                elif (bConfederation):
                    if (50 > game.getSorenRandNum(100, 'Rev: Naming')):
                        newName = localText.getText(
                            "TXT_KEY_MOD_DCN_CONFEDERATION", ()) % (curAdj)
                    else:
                        newName = localText.getText(
                            "TXT_KEY_MOD_DCN_CONFEDERATION_STATES",
                            ()) % (curShort)
                elif (50 > game.getSorenRandNum(100, 'Rev: Naming')):
                    newName = localText.getText("TXT_KEY_MOD_DCN_REPUBLIC",
                                                ()) % (curAdj)
                elif (33 > game.getSorenRandNum(100, 'Rev: Naming')):
                    newName = localText.getText(
                        "TXT_KEY_MOD_DCN_THE_COMMONWEALTH_OF", ()) % (curShort)
                else:
                    newName = localText.getText(
                        "TXT_KEY_MOD_DCN_THE_REPUBLIC_OF", ()) % (curShort)

            if (RevUtils.isFreeSpeech(iPlayer)
                    and RevUtils.getLaborFreedom(iPlayer)[0] > 9):
                if (len(newName) < 16
                        and not localText.getText("TXT_KEY_MOD_DCN_FREE",
                                                  ()) in newName
                        and not localText.getText("TXT_KEY_MOD_DCN_NEW",
                                                  ()) in newName):
                    newName = localText.getText("TXT_KEY_MOD_DCN_FREE",
                                                ()) + ' ' + newName
        elif (RevUtils.getDemocracyLevel(iPlayer)[0] == -8):
            empString = localText.getText("TXT_KEY_MOD_DCN_PLAIN_EMPIRE", ())
            if (localText.getText("TXT_KEY_MOD_DCN_GERMAN_MATCH", ())
                    in curAdj):
                empString = localText.getText("TXT_KEY_MOD_DCN_REICH", ())

            if (not bForceUpdate and empString in curDesc):
                newName = curDesc
            elif (70 > game.getSorenRandNum(100, 'Rev: Naming')
                  and not localText.getText("TXT_KEY_MOD_DCN_REICH",
                                            ()) in empString):
                newName = localText.getText("TXT_KEY_MOD_DCN_THE_BLANK_OF",
                                            ()) % (empString, curShort)
            else:
                if (bFrench):
                    newName = empString + ' ' + curAdj
                else:
                    newName = curAdj + ' ' + empString
        else:
            sGreat = localText.getText("TXT_KEY_MOD_DCN_GREAT_KINGDOM",
                                       ()).replace('%s', '').strip()

            iMinCitiesKingdom = 3
            if (pPlayer.getNumCities() >= iMinCitiesKingdom):
                if (bFemaleLeader):
                    sKingdom = localText.getText("TXT_KEY_MOD_DCN_QUEENDOM",
                                                 ())
                else:
                    sKingdom = localText.getText("TXT_KEY_MOD_DCN_KINGDOM", ())
            else:
                sKingdom = localText.getText("TXT_KEY_MOD_DCN_PRINCIPALITY",
                                             ())

            if RevUtils.getDemocracyLevel(iPlayer)[0] == -6:

                if pTeam.isAVassal():
                    sKingdom = localText.getText("TXT_KEY_MOD_DCN_DUCHY", ())
                else:
                    if (localText.getText("TXT_KEY_MOD_DCN_PERSIAN_MATCH",
                                          ()) in curAdj or localText.getText(
                                              "TXT_KEY_MOD_DCN_OTTOMAN_MATCH",
                                              ()) in curAdj
                            or localText.getText(
                                "TXT_KEY_MOD_DCN_SUMERIAN_MATCH",
                                ()) in curAdj):
                        sKingdom = localText.getText(
                            "TXT_KEY_MOD_DCN_SULTANATE", ())
                    elif (localText.getText("TXT_KEY_MOD_DCN_ARABIAN_MATCH",
                                            ()) in curAdj):
                        sKingdom = localText.getText(
                            "TXT_KEY_MOD_DCN_CALIPHATE", ())

                if pPlayer.getNumCities() < 4:
                    if not cityString == None and len(cityString) < 10 and len(
                            cityString) > 0:
                        if (cityString in curAdj or cityString in curShort):
                            newName = localText.getText(
                                "TXT_KEY_MOD_DCN_THE_BLANK_OF_CITY",
                                ()) % (sKingdom, cityString)
                        else:
                            if bFrench:
                                newName = localText.getText(
                                    "TXT_KEY_MOD_DCN_BLANK_OF_CITY",
                                    ()) % (sKingdom, curAdj, cityString)
                            else:
                                newName = localText.getText(
                                    "TXT_KEY_MOD_DCN_BLANK_OF_CITY",
                                    ()) % (curAdj, sKingdom, cityString)
                    else:
                        if bFrench:
                            newName = sKingdom + ' ' + curAdj
                        else:
                            newName = curAdj + ' ' + sKingdom
                elif (game.getPlayerRank(iPlayer) <
                      game.countCivPlayersAlive() / 7
                      and not pTeam.isAVassal()
                      and (sGreat in curDesc
                           or 40 > game.getSorenRandNum(100, 'Rev: Naming'))):
                    if bFrench:
                        newName = localText.getText(
                            "TXT_KEY_MOD_DCN_GREAT_KINGDOM",
                            ()) % (sKingdom, curAdj)
                    else:
                        newName = localText.getText(
                            "TXT_KEY_MOD_DCN_GREAT_KINGDOM",
                            ()) % (curAdj, sKingdom)
                else:
                    sOf = localText.getText("TXT_KEY_MOD_DCN_THE_BLANK_OF",
                                            ()).replace('%s', '')
                    if (not bForceUpdate and sKingdom in curDesc and
                        (not sOf in curDesc or pPlayer.getNumCities < 6)
                            and (not sGreat in curDesc)):
                        newName = curDesc
                    elif 50 > game.getSorenRandNum(100, 'Rev: Naming'):
                        if bFrench:
                            newName = sKingdom + ' ' + curAdj
                        else:
                            newName = curAdj + ' ' + sKingdom
                    else:
                        newName = localText.getText(
                            "TXT_KEY_MOD_DCN_THE_BLANK_OF",
                            ()) % (sKingdom, curShort)

            elif RevUtils.getDemocracyLevel(
                    iPlayer)[0] == -10 or playerEra == 0:

                empString = localText.getText("TXT_KEY_MOD_DCN_PLAIN_EMPIRE",
                                              ())
                if playerEra < 2 and pPlayer.getNumCities() < 3:
                    empString = localText.getText(
                        "TXT_KEY_MOD_DCN_PLAIN_CITY_STATE", ())
                if pTeam.isAVassal():
                    if 50 > game.getSorenRandNum(100, 'Rev: Naming'):
                        empString = localText.getText(
                            "TXT_KEY_MOD_DCN_FIEFDOM", ())
                    elif 50 > game.getSorenRandNum(100, 'Rev: Naming'):
                        empString = localText.getText(
                            "TXT_KEY_MOD_DCN_PROTECTORATE", ())
                    else:
                        empString = localText.getText(
                            "TXT_KEY_MOD_DCN_TERRITORY", ())

                if not bForceUpdate and empString in curDesc and not game.getGameTurn(
                ) == 0:
                    newName = curDesc
                elif (50 > game.getSorenRandNum(100, 'Rev: Naming')):
                    if (bFrench):
                        newName = empString + ' ' + curAdj
                    else:
                        newName = curAdj + ' ' + empString
                else:
                    newName = localText.getText("TXT_KEY_MOD_DCN_THE_BLANK_OF",
                                                ()) % (empString, curShort)

            sHoly = localText.getText("TXT_KEY_MOD_DCN_HOLY", ()) + ' '
            if (RevUtils.getReligiousFreedom(iPlayer)[0] < -9):
                if (len(newName) < 16 and not sHoly in newName
                        and not sGreat in newName and not newName.startswith(
                            localText.getText("TXT_KEY_MOD_DCN_HOLY_HRE_MATCH",
                                              ()))):
                    newName = sHoly + newName
            elif newName.startswith(sHoly) and not origDesc.startswith(sHoly):
                # Cut off any inappropriately saved 'Holy ' prefix
                newName = newName[len(sHoly):]

        if bPacifist:
            szPacifist = localText.getText("TXT_KEY_MOD_DCN_PACIFIST", ())
            if not szPacifist in newName and 50 > game.getSorenRandNum(
                    100, 'Rev: Naming'):
                szPacifist = localText.getText("TXT_KEY_MOD_DCN_PEACEFUL", ())

            if not szPacifist in newName:
                if bFrench:
                    newName = newName + ' ' + szPacifist
                else:
                    newName = szPacifist + ' ' + newName

        return [newName, curShort, curAdj]
Example #28
0
 def onEndPlayerTurn(self, argsList):
     iGameTurn, iPlayer = argsList
     # Can't use isHuman as isHuman has been deactivated by automation
     if self.refortify and iPlayer == GAME.getActivePlayer(
     ) and GAME.getAIAutoPlay(iPlayer) == 1:
         RevUtils.doRefortify(iPlayer)