[PYTHON Help needed] Dynamically add a player in game

Fabrysse

Charming-snake learner
Joined
Sep 11, 2006
Messages
430
Location
Toulouse - France
First : I don't know SDK at all. So I have to use only python.

What do I want to do ?
At turn 'N', I want the civ with ID '0' to split in 2 civs.

What is already done ?
in XML files I have defined a civ (with leader, and all needed elements) that is not playable and not included on the map.

How did I try to do that ?
Code:
#I create a new player (calling it with id 2, I suppose It'll point the third civ in the xml file...) :
NewPlayerIdx = 2
newPlayer = gc.getPlayer(NewPlayerIdx)
#The player who will loose cities
py = PyPlayer(0)
#I make a test on 1 city in list of player '0' :
apCityList = py.getCityList()
	for pCity in apCityList:
		#Try it for 'Burgos'
		if (pCity.getName() == 'Burgos'):
			#Give this city to newPlayer
			[COLOR="Red"]newPlayer.acquireCity( pCity.GetCy(), False, False )[/COLOR]
#Set this new player
newPlayer.setAlive( True )

The result is :
  • I have an error in logs, on the red line
  • Burgos is destroyed
  • The list of civs (bottom right of main screen) desappears
  • when I click the "next turn" button, I have nothing (not really a crash, but nothing can be done)

Why doesn't it run ?
Is it because I don't have defined a Leader for the new civ ? There is only one available for this civ... If that is the problem : how will I do that ?
Is it something else ?
Is it possible to do that like that ?

Should I use this other way (with hide dead civs) :
  • On map : create 1 settler for the new civ
  • atBeginGame : destroy this settler (should kill the civ)
  • at turn 'N' : use the function 'reviveActivePlayer()'

Could you help me please ?...
 
Lord Olleus said:
Check out the rebbellion component of this mod. It does something very similar to what you want in the SDK. It should be relatively straight forward to expose it to python.

Thanks. This mod is, with Omens, the model I use to create my events.
It runs, now.
 
Other python problems... :crazyeye:

  • Is there a way to force civs to sign a permanent alliance ?
  • How could I set that a team knows all map (with cities) ? Exactly : I dynamically create a new civ at turn 'N', and I want it to acquire the same map than an other civ that knows all map... I have this new civ in the map file with no alive unit in game. When I set in map file reveal map for this team, it is automatically set to "0" by the game (because the player is dead, I suppose... Is there a way to put back this value to "1" when the new civ appears really in game ?
  • I use the function Player.convert(0) to give the religion "0" to a player. There is no error in log, but that doesn't do anything. Somebody knows why ?
  • Specific sounds for units : Let's imagine that you have for exemple some UNO units in the game. You play Spain. Your units speak in spanish : no problem. But you'd like the Unit UNO to speak english, french or german... How would you do ?
 
I use the function Player.convert(0) to give the religion "0" to a player. There is no error in log, but that doesn't do anything. Somebody knows why ?

Solution :
In my specific case, it could be a problem with anarchy... At the same turn, I create a new civ that acquire some cities, and I want to convert. I think the new civ is in anarchy, so no possibility to convert.
I test tonight and give the result tomorrow...
 
Please do keep posting! I too need to create civs on the fly, or get a 40 civ DLL :/

Code:
	def armenia2christianity(self):
		playerIdx = 1
		pPlayer = gc.getPlayer(playerIdx)
		# iChristianity = gc.getInfoTypeForString('RELIGION_CHRISTIANITY')
		iChristianity = gc.getInfoTypeForString('RELIGION_JUDAISM')
		iRomanism = gc.getInfoTypeForString('RELIGION_BAAL_WORSHIP')
		CvUtil.pyPrint('historical_event: Armenia converts to Christianity on turn: %s' %(self.iGameTurn) )

		for i in range(pPlayer.getNumCities()):
			pCityLoop = pPlayer.getCity(i)
			cityName = pCityLoop.getName()
			# religion integer, true = present, true = announce, true = ? 
			pCityLoop.setHasReligion(iRomanism, False, False, True)
			pCityLoop.setHasReligion(iChristianity, True, False, False)

	         pPlayer.convert(iChristianity)

This does work for me. Civ #1 is Carthage, and has BAAL_WORSHIP as the state religion. After this runs, all of Carthage's cities have Judaism, and that is their state religion. Really all this is necessary is for 1 city to have a religion before it can be converted to.
 
Back
Top Bottom