I NEED HELP with Revolutions Mod CyGame ChangePlayer function

GUSTAVUS II

Chieftain
Joined
Oct 12, 2007
Messages
44
Location
Malmo,Minnesota
Hello, I have a error that occurs while using my own custom event python
with a revolutions mod combined with bugmod.

cyGame changePlayer is a Revolutions Special Function that is triggering
missing cyGame info instead of switching my civ with another civ like it should.

Code:
AttributeError: 'CyGame' object has no attribute changePlayer

ChangePlayer works well in other mods. I think I am just leaving something out.


The rest of my code is functioning properly, I believe I must not be importing
something correctly or I am missing a class. The info I have questions about
I will show in bold below.

Code:
[INDENT]
[B]from CvPythonExtensions import *
import CvEventManager
import CvUtil
import PyHelpers	
import Popup as PyPopup
import pickle		
import random
import CvTranslator
import sys
import CvAlertManager
import RevDefs
import RevUtils
import RevInstances
import RevolutionInit
import SdToolKitCustom as SDTK
import RevData
import ChangePlayer[/B]



[B]# globals
gc = CyGlobalContext()
g = CyGame()
alert = CvAlertManager.CvAlertManager()
PyPlayer = PyHelpers.PyPlayer
PyInfo = PyHelpers.PyInfo		
localText = CyTranslator()
game = CyGame()

#the main class

class CvGustavusEventManager:
	def __init__(self, eventManager):
		# initialize base class
		eventManager.addEventHandler("BeginGameTurn", self.onBeginGameTurn)


		
		
	# When a turn begins :
	def onBeginGameTurn(self, argsList):
		iGameTurn, = argsList[/B]
		
		#BE CAREFULL : 
		#The Map I used to test the Mod is not so big :
		# X : from 0 to 103
		#Y : from 0 to 63
		#
		# I tested with create Germany at turn 1 and France + Spain at turn 4 => IT WORKS!
		
		###############################################################
		#
		#   ENTER YOUR INFOS HERE
		#
		###############################################################
		
		#TURN 1 : Germany
		if(iGameTurn == 1):
			#Germany have to start
			iNewPlayer = 7    # Player ID (= player's position in list) in your Map
			self.CreateNewCivGermany(iNewPlayer, 87, 40)    # 87 (X) and 40 (Y) are coordonates of the plot where the unit will be created
                
		#TURN 4 : France
		elif(iGameTurn == 4):
			#France have to start
			iNewPlayer = 8    # Player ID (= player's position in list) in your Map
			self.CreateNewCivFrance(iNewPlayer, 90, 17)    # 90 (X) and 17 (Y) are coordonates of the plot where the unit will be created
			
                #TURN 5 : Spain
		elif(iGameTurn == 5):
			#Spain have to start too
			iNewPlayer = 9    # Player ID (= player's position in list) in your Map
			self.CreateNewCivSpain(iNewPlayer, 86, 19)
                 
                #TURN 6 : Birth of Christ
		elif(iGameTurn == 6):
			#Tech Christianity to be Granted
			iNewPlayer = 1    
			self.CreateNewFaith(iNewPlayer, 80, 45)
                        iTechHappy28 = CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),'TECH_THEOLOGY')

                        pPlayer = gc.getPlayer(1)
                        pTeam = gc.getTeam(pPlayer.getTeam())
                        pTeam.setHasTech(iTechHappy28, true, 19, false, false)

                #TURN 7 : Vikings turn into Rome
		elif(iGameTurn == 7):
			#Switching Civs With Same WBS Slot
			playerIdx = 1    
			newCivType = 40
                        newLeaderType = 3
                        self.changeCiv(playerIdx,newCivType,newLeaderType)

                #TURN 8 : MAKING A CIV RISE WHEN ANOTHER HAS FALLEN
		elif(iGameTurn == 8):
			#INFO
			iNewPlayer = 12
                        iPlayer = 3
                        iPlayer2 = 4
                        iPlayer3 = 5
                        iPlayer4 = 6
                        self.CreateNewCivWhenAnotherisGoneMulti(iNewPlayer,iPlayer,iPlayer2,iPlayer3,iPlayer4, 86, 40)

                #TURN 20 : MAKING A CIV RISE WHEN ANOTHER HAS FALLEN
		elif(iGameTurn == 20):
			#INFO
			iNewPlayer = 11
                        iPlayer = 2
                        self.CreateNewCivWhenAnotherisGone(iNewPlayer,iPlayer, 49, 45)
                 
                #TURN 25 : in reverse
		elif(iGameTurn == 25):
			#INFO
			iNewPlayer = 2
                        iPlayer = 11
                        self.CreateNewCivWhenAnotherisGone(iNewPlayer,iPlayer, 49, 45)

                #INSERT THE OTHER TURNS/CIVS HERE...
		#elif(iGameTurn == ??):
			#Germany have to start
			#iNewPlayer = ??
			#self.CreateNewCiv(iNewPlayer, ??, ??)
		
		###############################################################
		#
		#   END YOUR INFOS HERE
		#
		###############################################################
				
				
	# My function that creates the new unit :
	def CreateNewCivGermany(self, iNewPlayer, iX, iY):
                pCity = CyMap().plot(87,40).getPlotCity()
		pNewPlayer = gc.getPlayer(iNewPlayer)
		if(not pNewPlayer.isAlive()):
			#Create new Player
			pNewPlayer.setPlayable(True)
			g.addPlayer(iNewPlayer,pNewPlayer.getPersonalityType(), pNewPlayer.getCivilizationType(),True)
			#Create a settler
			pCity=pNewPlayer.initCity( iX, iY)
                        pCity.setName("Berlin", False)
                        pCity.setPopulation(4)
                        pCity.setFood(533)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_SWORDSMAN"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
			#Add a message on screen
			CyInterface().addMessage(g.getActivePlayer(),true,15,"Year %s: A new Civilization (%s) has been created !" %(g.getGameTurnYear(), pNewPlayer.getCivilizationDescription(pNewPlayer.getCivilizationType())),'',0,'',ColorTypes(11), 1, 1, True,True)
			
		return

        def CreateNewCivFrance(self, iNewPlayer, iX, iY):
                pCity = CyMap().plot(90,17).getPlotCity()
		pNewPlayer = gc.getPlayer(iNewPlayer)
		if(not pNewPlayer.isAlive()):
			#Create new Player
			pNewPlayer.setPlayable(True)
			g.addPlayer(iNewPlayer,pNewPlayer.getPersonalityType(), pNewPlayer.getCivilizationType(),True)
			#Create a settler
                        pCity=pNewPlayer.initCity( iX, iY)
                        pCity.setName("Paris", False)
                        pCity.setPopulation(4)
                        pCity.setFood(533)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_SWORDSMAN"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_SWORDSMAN"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
			#Add a message on screen
			CyInterface().addMessage(g.getActivePlayer(),true,15,"Year %s: A new Civilization (%s) has been created !" %(g.getGameTurnYear(), pNewPlayer.getCivilizationDescription(pNewPlayer.getCivilizationType())),'',0,'',ColorTypes(11), 1, 1, True,True)
			
		return
        
        def CreateNewCivSpain(self, iNewPlayer, iX, iY):
                pCity = CyMap().plot(86,19).getPlotCity()
		pNewPlayer = gc.getPlayer(iNewPlayer)
		if(not pNewPlayer.isAlive()):
			#Create new Player
			pNewPlayer.setPlayable(True)
			g.addPlayer(iNewPlayer,pNewPlayer.getPersonalityType(), pNewPlayer.getCivilizationType(),True)
			#Create a settler
			pCity=pNewPlayer.initCity( iX, iY)
                        pCity.setName("Madrid", False)
                        pCity.setPopulation(4)
                        pCity.setFood(533)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_INFANTRY"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_INFANTRY"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_INFANTRY"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
			#Add a message on screen
			CyInterface().addMessage(g.getActivePlayer(),true,15,"Year %s: A new Civilization (%s) has been created !" %(g.getGameTurnYear(), pNewPlayer.getCivilizationDescription(pNewPlayer.getCivilizationType())),'',0,'',ColorTypes(11), 1, 1, True,True)
			
		return

	def CreateNewCivWhenAnotherisGone(self, iNewPlayer,iPlayer, iX, iY):
		pNewPlayer = gc.getPlayer(iNewPlayer)
                ploopPlayer = gc.getPlayer(iPlayer)
                if not ploopPlayer.isHuman() and not pNewPlayer.isAlive():
			#Create new Player
			pNewPlayer.setPlayable(True)
			g.addPlayer(iNewPlayer,pNewPlayer.getPersonalityType(), pNewPlayer.getCivilizationType(),True)
			#Create a settler
			pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_INFANTRY"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_RAIDERTANK"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_RAIDERTANK"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_RAIDERTANK"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_RAIDERTANK"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_RAIDERTANK"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_RAIDERTANK"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_RAIDERTANK"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        #Add a message on screen
			CyInterface().addMessage(g.getActivePlayer(),true,15,"Year %s: A new Civilization (%s) has been created !" %(g.getGameTurnYear(), pNewPlayer.getCivilizationDescription(pNewPlayer.getCivilizationType())),'',0,'',ColorTypes(11), 1, 1, True,True)
			
		return

        def changeCiv(self,playerIdx,newCivType,newLeaderType):
                newPlayer = gc.getPlayer(playerIdx)
                newCivType = gc.getPlayer(newCivType)
                teamIdx = gc.getPlayer(playerIdx).getTeam()
                [B]success = game.changePlayer(playerIdx,newCivType,newLeaderType,teamIdx,0,True )[/B]
                CyAudioGame().Play2DSound("AS2D_FANFARE2")
                CyInterface().addMessage(g.getActivePlayer(),true,15,"Year 400 BC: Rome has been liberated !",'',0,'',ColorTypes(11), 1, 1, True,True)
                game.convertUnits( playerIdx )
                return success

        def CreateNewCivWhenAnotherisGoneMulti(self, iNewPlayer,iPlayer,iPlayer2,iPlayer3,iPlayer4, iX, iY):
                pCity = CyMap().plot(87,40).getPlotCity()
                pCity2 = CyMap().plot(85,35).getPlotCity()
		pNewPlayer = gc.getPlayer(iNewPlayer)
                ploopPlayer = gc.getPlayer(iPlayer)
                ploopPlayer2 = gc.getPlayer(iPlayer2)
                ploopPlayer3 = gc.getPlayer(iPlayer3)
                ploopPlayer4 = gc.getPlayer(iPlayer4)
                if not ploopPlayer.isHuman() and not ploopPlayer2.isHuman() and not ploopPlayer3.isHuman() and not ploopPlayer4.isHuman() and not pNewPlayer.isAlive():
			#Create new Player
			pNewPlayer.setPlayable(True)
			g.addPlayer(iNewPlayer,pNewPlayer.getPersonalityType(), pNewPlayer.getCivilizationType(),True)
			#Create a settler
			pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_INFANTRY"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_INFANTRY"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_INFANTRY"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_INFANTRY"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.acquireCity(pCity,true,false)
                        pCity.setName("New Berlin", False)
                        pCity.setPopulation(10)
                        pCity.setFood(533)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_INFANTRY"), 85, 35, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_INFANTRY"), 85, 35, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pCity2=pNewPlayer.initCity( 85, 35)
                        pCity2.setName("Koln", False)
                        pCity2.setPopulation(6)
                        pCity2.setFood(133)
                        #Add a message on screen
			CyInterface().addMessage(g.getActivePlayer(),true,15,"Year %s: A new Civilization (%s) has been created !" %(g.getGameTurnYear(), pNewPlayer.getCivilizationDescription(pNewPlayer.getCivilizationType())),'',0,'',ColorTypes(11), 1, 1, True,True)
			
		return

        def CreateNewFaith(self, iNewPlayer, iX, iY):					
		pNewPlayer = gc.getPlayer(iNewPlayer)
		if(pNewPlayer.isAlive()):
			#Rome is Alive
                        #Create a unit
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_WORKER"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
			#Add a message on screen
			CyInterface().addMessage(g.getActivePlayer(),true,15,"Year %s: The Catholic Church (%s) has been born !" %(g.getGameTurnYear(), pNewPlayer.getCivilizationDescription(pNewPlayer.getCivilizationType())),'',0,'',ColorTypes(11), 1, 1, True,True)
			
		return				

[/INDENT]
 
If you refer to the CivIV Python API the is no CyGame.changePlayer() method. Perhaps the method is part of the ChangePlayer module instead of CvPythonExtensions?
Code:
                import ChangePlayer
My best guess is you have to go:
Code:
                success = ChangePlayer.changePlayer(playerIdx,newCivType,newLeaderType,teamIdx,0,True )
But if there is a ChangePlayer class in the ChangePlayer module you might have to change the import line to:
Code:
                from ChangePlayer import *
I'd urge you to study Python some more at any rate. These issues would be self-explanatory once you know the bare basics.
 
Looking at RevDCM's DLL code showed that CyGame indeed doesn't have a 'changePlayer' , and I assume that if Revolutions had it, so would RevDCM...
 
Rev does it via various Python event handlers and such that ultimately call a new function on the CvGame object called changeHumanPlayer.

It's all normally controlled via the BUG configuration, like in the Revolution.xml config file there is a section that looks like this:
Code:
		<section id="ChangePlayer">
			<option id="ChangePlayerEnable" key="Enable" type="boolean" default="True"/>
			<option id="ChangePlayerDebugMode" key="DebugMode" type="boolean" default="False"/>
		</section>

If the first of those two settings sets Enable to True, which is the default setting in the above stuff, then the RevolutionInit.py file initializes a ChangePlayer object which registers its event handlers (it registers one for the keyboard events to look for specific key combinations). The default settings for this are evidently that Cntrl-Shift-P lets you change your civilization's civilization type and leader and Cntrl-Shift-L lets you change which of the civs in the game you control (and Cntrl-Shift-U forces a graphics update, apparently used to force unit flags to the new correct flag, for the player by switching them to another civ and back).

So you don't normally call any of that stuff manually. You initialize a ChangePlayer object, saving the instance in some global variable so it can be found again later, and everything else is then more or less automatic. It registers its keyboard event handler and looks for the key's it does stuff for and if it spots one it does its thing.

The code is already used in RevolutionInit.py, RevDefs.py, RevUtils,py, and RevEvents.py (and maybe some more) as they are provided. Running pure unmodified RevDCM should have this working properly if it is enabled.

Well, that is assuming you are actually using the RevDCM mod as your base, or some other mod that does. If not then your are probably not using a DLL that has the necessary new feature(s) for this stuff built into it.
 
It looks like my "Revolution.ini" file is not my problem, as the changeplayer is enabled
here.
Code:
[INDENT]
; -----------------------------------------------------
; -----------------------------------------------------
[ChangePlayer]
Enable = True

; Turn on Debug output
DebugMode = False
[/INDENT]

I am currently using RevDCM version 2.5.


changePlayer is used in my other .py files in my mod such as
RevolutionInit.py, RevDefs.py, RevUtils.py, and RevEvents.py

Why does it read changePlayer as CyGame in my other .py
files but not in my own eventmanager?

I have tried different instances like "ChangePlayer.changeplayer",
"RevolutionInit.changePlayer" and "RevDCM.changeplayer" with
no class of "changePlayer" found within these files.

RevUtils.ChangeCiv worked as far as changing my leader, but with that
function I could not seem to be able to change my Civ, or even the leader's
name.

Here is the current code I am working with:
Code:
[INDENT]
from CvPythonExtensions import *
from ChangePlayer import *
from RevUtils import *
from RevCivicsUtils import *
from RevDCM import *
import CvEventManager
import CvUtil
import PyHelpers	
import Popup as PyPopup
import pickle		
import random
import CvTranslator
import sys
import CvAlertManager
import RevDefs 
import RevInstances
import RevolutionInit
import SdToolKitCustom as SDTK
import RevData




# globals
gc = CyGlobalContext()
g = CyGame()
alert = CvAlertManager.CvAlertManager()
PyPlayer = PyHelpers.PyPlayer
PyInfo = PyHelpers.PyInfo		
localText = CyTranslator()
game = CyGame()

#the main class

class CvGustavusEventManager:
	def __init__(self, eventManager):
		# initialize base class
		eventManager.addEventHandler("BeginGameTurn", self.onBeginGameTurn)


		
		
	# When a turn begins :
	def onBeginGameTurn(self, argsList):
		iGameTurn, = argsList
		
		#BE CAREFULL : 
		#The Map I used to test the Mod is not so big :
		# X : from 0 to 103
		#Y : from 0 to 63
		#
		# I tested with create Germany at turn 1 and France + Spain at turn 4 => IT WORKS!
		
		###############################################################
		#
		#   ENTER YOUR INFOS HERE
		#
		###############################################################
		
		#TURN 1 : Germany
		if(iGameTurn == 1):
			#Germany have to start
			iNewPlayer = 7    # Player ID (= player's position in list) in your Map
			self.CreateNewCivGermany(iNewPlayer, 87, 40)    # 87 (X) and 40 (Y) are coordonates of the plot where the unit will be created
                
		#TURN 4 : France
		elif(iGameTurn == 4):
			#France have to start
			iNewPlayer = 8    # Player ID (= player's position in list) in your Map
			self.CreateNewCivFrance(iNewPlayer, 90, 17)    # 90 (X) and 17 (Y) are coordonates of the plot where the unit will be created
			
                #TURN 5 : Spain
		elif(iGameTurn == 5):
			#Spain have to start too
			iNewPlayer = 9    # Player ID (= player's position in list) in your Map
			self.CreateNewCivSpain(iNewPlayer, 86, 19)
                 
                #TURN 6 : Birth of Christ
		elif(iGameTurn == 6):
			#Tech Christianity to be Granted
			iNewPlayer = 1    
			self.CreateNewFaith(iNewPlayer, 80, 45)
                        iTechHappy28 = CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),'TECH_THEOLOGY')

                        pPlayer = gc.getPlayer(1)
                        pTeam = gc.getTeam(pPlayer.getTeam())
                        pTeam.setHasTech(iTechHappy28, true, 19, false, false)

                #TURN 7 : Vikings turn into Rome
		elif(iGameTurn == 7):
			#Switching Civs With Same WBS Slot
			playerIdx = 1    
			newCivType = 40
                        newLeaderType = 4
                        self.changeCiv(playerIdx,newCivType,newLeaderType)

                #TURN 8 : MAKING A CIV RISE WHEN ANOTHER HAS FALLEN
		elif(iGameTurn == 8):
			#INFO
			iNewPlayer = 12
                        iPlayer = 3
                        iPlayer2 = 4
                        iPlayer3 = 5
                        iPlayer4 = 6
                        self.CreateNewCivWhenAnotherisGoneMulti(iNewPlayer,iPlayer,iPlayer2,iPlayer3,iPlayer4, 86, 40)

                #TURN 20 : MAKING A CIV RISE WHEN ANOTHER HAS FALLEN
		elif(iGameTurn == 20):
			#INFO
			iNewPlayer = 11
                        iPlayer = 2
                        self.CreateNewCivWhenAnotherisGone(iNewPlayer,iPlayer, 49, 45)
                 
                #TURN 25 : in reverse
		elif(iGameTurn == 25):
			#INFO
			iNewPlayer = 2
                        iPlayer = 11
                        self.CreateNewCivWhenAnotherisGone(iNewPlayer,iPlayer, 49, 45)

                #INSERT THE OTHER TURNS/CIVS HERE...
		#elif(iGameTurn == ??):
			#Germany have to start
			#iNewPlayer = ??
			#self.CreateNewCiv(iNewPlayer, ??, ??)
		
		###############################################################
		#
		#   END YOUR INFOS HERE
		#
		###############################################################
				
				
	# My function that creates the new unit :
	def CreateNewCivGermany(self, iNewPlayer, iX, iY):
                pCity = CyMap().plot(87,40).getPlotCity()
		pNewPlayer = gc.getPlayer(iNewPlayer)
		if(not pNewPlayer.isAlive()):
			#Create new Player
			pNewPlayer.setPlayable(True)
			g.addPlayer(iNewPlayer,pNewPlayer.getPersonalityType(), pNewPlayer.getCivilizationType(),True)
			#Create a settler
			pCity=pNewPlayer.initCity( iX, iY)
                        pCity.setName("Berlin", False)
                        pCity.setPopulation(4)
                        pCity.setFood(533)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_SWORDSMAN"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
			#Add a message on screen
			CyInterface().addMessage(g.getActivePlayer(),true,15,"Year %s: A new Civilization (%s) has been created !" %(g.getGameTurnYear(), pNewPlayer.getCivilizationDescription(pNewPlayer.getCivilizationType())),'',0,'',ColorTypes(11), 1, 1, True,True)
			
		return

        def CreateNewCivFrance(self, iNewPlayer, iX, iY):
                pCity = CyMap().plot(90,17).getPlotCity()
		pNewPlayer = gc.getPlayer(iNewPlayer)
		if(not pNewPlayer.isAlive()):
			#Create new Player
			pNewPlayer.setPlayable(True)
			g.addPlayer(iNewPlayer,pNewPlayer.getPersonalityType(), pNewPlayer.getCivilizationType(),True)
			#Create a settler
                        pCity=pNewPlayer.initCity( iX, iY)
                        pCity.setName("Paris", False)
                        pCity.setPopulation(4)
                        pCity.setFood(533)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_SWORDSMAN"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_SWORDSMAN"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
			#Add a message on screen
			CyInterface().addMessage(g.getActivePlayer(),true,15,"Year %s: A new Civilization (%s) has been created !" %(g.getGameTurnYear(), pNewPlayer.getCivilizationDescription(pNewPlayer.getCivilizationType())),'',0,'',ColorTypes(11), 1, 1, True,True)
			
		return
        
        def CreateNewCivSpain(self, iNewPlayer, iX, iY):
                pCity = CyMap().plot(86,19).getPlotCity()
		pNewPlayer = gc.getPlayer(iNewPlayer)
		if(not pNewPlayer.isAlive()):
			#Create new Player
			pNewPlayer.setPlayable(True)
			g.addPlayer(iNewPlayer,pNewPlayer.getPersonalityType(), pNewPlayer.getCivilizationType(),True)
			#Create a settler
			pCity=pNewPlayer.initCity( iX, iY)
                        pCity.setName("Madrid", False)
                        pCity.setPopulation(4)
                        pCity.setFood(533)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_INFANTRY"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_INFANTRY"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_INFANTRY"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
			#Add a message on screen
			CyInterface().addMessage(g.getActivePlayer(),true,15,"Year %s: A new Civilization (%s) has been created !" %(g.getGameTurnYear(), pNewPlayer.getCivilizationDescription(pNewPlayer.getCivilizationType())),'',0,'',ColorTypes(11), 1, 1, True,True)
			
		return

	def CreateNewCivWhenAnotherisGone(self, iNewPlayer,iPlayer, iX, iY):
		pNewPlayer = gc.getPlayer(iNewPlayer)
                ploopPlayer = gc.getPlayer(iPlayer)
                if not ploopPlayer.isHuman() and not pNewPlayer.isAlive():
			#Create new Player
			pNewPlayer.setPlayable(True)
			g.addPlayer(iNewPlayer,pNewPlayer.getPersonalityType(), pNewPlayer.getCivilizationType(),True)
			#Create a settler
			pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_INFANTRY"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_RAIDERTANK"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_RAIDERTANK"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_RAIDERTANK"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_RAIDERTANK"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_RAIDERTANK"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_RAIDERTANK"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_RAIDERTANK"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        #Add a message on screen
			CyInterface().addMessage(g.getActivePlayer(),true,15,"Year %s: A new Civilization (%s) has been created !" %(g.getGameTurnYear(), pNewPlayer.getCivilizationDescription(pNewPlayer.getCivilizationType())),'',0,'',ColorTypes(11), 1, 1, True,True)
			
		return

        def changeCiv(self,playerIdx,newCivType,newLeaderType):
                newPlayer = gc.getPlayer(playerIdx)
                newCivType = gc.getPlayer(newCivType)
                teamIdx = gc.getPlayer(playerIdx).getTeam()
                success = game.changePlayer(playerIdx,newCivType,newLeaderType,teamIdx,0,True )
                CyAudioGame().Play2DSound("AS2D_FANFARE2")
                CyInterface().addMessage(g.getActivePlayer(),true,15,"Year 400 BC: Rome has been liberated !",'',0,'',ColorTypes(11), 1, 1, True,True)
                return success

        def CreateNewCivWhenAnotherisGoneMulti(self, iNewPlayer,iPlayer,iPlayer2,iPlayer3,iPlayer4, iX, iY):
                pCity = CyMap().plot(87,40).getPlotCity()
                pCity2 = CyMap().plot(85,35).getPlotCity()
		pNewPlayer = gc.getPlayer(iNewPlayer)
                ploopPlayer = gc.getPlayer(iPlayer)
                ploopPlayer2 = gc.getPlayer(iPlayer2)
                ploopPlayer3 = gc.getPlayer(iPlayer3)
                ploopPlayer4 = gc.getPlayer(iPlayer4)
                if not ploopPlayer.isHuman() and not ploopPlayer2.isHuman() and not ploopPlayer3.isHuman() and not ploopPlayer4.isHuman() and not pNewPlayer.isAlive():
			#Create new Player
			pNewPlayer.setPlayable(True)
			g.addPlayer(iNewPlayer,pNewPlayer.getPersonalityType(), pNewPlayer.getCivilizationType(),True)
			#Create a settler
			pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_INFANTRY"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_INFANTRY"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_INFANTRY"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_INFANTRY"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.acquireCity(pCity,true,false)
                        pCity.setName("New Berlin", False)
                        pCity.setPopulation(10)
                        pCity.setFood(533)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_INFANTRY"), 85, 35, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_INFANTRY"), 85, 35, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pCity2=pNewPlayer.initCity( 85, 35)
                        pCity2.setName("Koln", False)
                        pCity2.setPopulation(6)
                        pCity2.setFood(133)
                        #Add a message on screen
			CyInterface().addMessage(g.getActivePlayer(),true,15,"Year %s: A new Civilization (%s) has been created !" %(g.getGameTurnYear(), pNewPlayer.getCivilizationDescription(pNewPlayer.getCivilizationType())),'',0,'',ColorTypes(11), 1, 1, True,True)
			
		return

        def CreateNewFaith(self, iNewPlayer, iX, iY):					
		pNewPlayer = gc.getPlayer(iNewPlayer)
		if(pNewPlayer.isAlive()):
			#Rome is Alive
                        #Create a unit
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_WORKER"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
			#Add a message on screen
			CyInterface().addMessage(g.getActivePlayer(),true,15,"Year %s: The Catholic Church (%s) has been born !" %(g.getGameTurnYear(), pNewPlayer.getCivilizationDescription(pNewPlayer.getCivilizationType())),'',0,'',ColorTypes(11), 1, 1, True,True)
			
		return				

[/INDENT]

Is there any thing I am missing? I have seen this code work in
other mods using Revolutions such as "CivIV Rise and Fall of the Roman Empire"
here is a link to a post that shows you what I mean by this:
http://forums.civfanatics.com/showthread.php?t=334458
(The very bottom post on this thread shows an example of changePlayer working correctly.)
 
So if other mods use this then the question is, how do they do it? Then do it that way...

Or you could try these things:

For changing which existing civilization the player controls it looks like a call to RevUtils.changeHuman( newHumanIdx, oldHumanIdx ) is probably the thing to try. THis ends up calling game.changeHumanPlayer( oldHumanIdx, newHumanIdx ).

For changing the civilization type and leader type of a civilization it looks like RevUtils.changeCiv( playerIdx, newCivType, newLeaderType, teamIdx) is the way to go. ThIs ends up calling player.changeCiv( newCivType ) and player.changeLeader( newLeaderType ) and also some stuff related to dynamic civ names.

These are the functions that end up being called when it is set up to do these things via keyboard shortcuts.
 
Thank you God-Emperor! After checking out samples on nullege.com
of RevUtils.changeCiv, I understood what method to use!

Code:
[INDENT]
success = RevUtils.changeCiv( playerIdx,newCivType,newLeaderType, teamIdx )
[/INDENT]

This line is Exactly what I needed! Thank You!:goodjob:

Code:
[INDENT]
def changeCivtoRome(self,playerIdx,newCivType,newLeaderType):
              newPlayer = gc.getPlayer(playerIdx)
              teamIdx = gc.getPlayer(playerIdx).getTeam()
              success = RevUtils.changeCiv( playerIdx,newCivType,newLeaderType, teamIdx )
              [B]newDesc  = "Roman Empire"
              newShort = "Rome"
              newAdj   = "Roman"
              newPlayer.setCivName( newDesc, newShort, newAdj )[/B]
              CyAudioGame().Play2DSound("AS2D_FANFARE2")
              CyInterface().addMessage(g.getActivePlayer(),true,15,"Year 400 BC: Rome has been liberated !",'',0,'',ColorTypes(11), 1, 1, True,True)

              return success 
[/INDENT]

I have also discovered the right function from DynamicCivNames
to change the Civ Names! Thank You! This is exactly what I was looking for!
 
Back
Top Bottom