python help needed - onCorporationSpread building spawn

Ahwaric

Shrubbery-hugger
Joined
Nov 12, 2005
Messages
1,217
Location
Kraków, Poland
I am currently working on the modmod for Fall from Heaven that adds some tactical changes and new guilds (corporations).
If you want you can check it here: Orbi
For one of the corporations I need it to spawn a building when civ spreads to a city, as I need some extra effects for it.
I tried the code below in the CvEventManager.py :

Code:
	def onCorporationSpread(self, argsList):
		'Corporation Has Spread to a City'
		iCorporation, iOwner, pSpreadCity = argsList
		player = PyPlayer(iOwner)
		iSteward = gc.getInfoTypeForString('CORPORATION_STEWARDS_OF_INEQUITY')
		pPlayer = gc.getPlayer(iOwner)

		if iCorporation == iSteward:
			city.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_STEWARDS'), 1)

		if (not self.__LOG_RELIGIONSPREAD):
			return
		CvUtil.pyPrint('%s has spread to Player %d Civilization %s city of %s'
			%(gc.getCorporationInfo(iCorporation).getDescription(), iOwner, player.getCivilizationName(), pSpreadCity.getName()))

Unfortunatelly it does not work. Any advice what I am doing wrong?
I need also to prevent the spawning in the cities that already have BUILDING_BAZAAR. How should I do that?

Anything that helps is appreciated :)
 
When you work with python, sdon't forget to turn on the debuger and the python exception. In you code you should replace city with pSpreadCity.

Tcho !

Edit :sorry misunderstood, will check how to prevent the corporation spread
 
For the corporation spreading. There is no entry in python to prevent that. How the corporation is spread to your city? . A work around would be to remove it when it is spread adding a message saying that the people refuse the corporation.

Tcho !
 
When you work with python, sdon't forget to turn on the debuger and the python exception. In you code you should replace city with pSpreadCity.

:blush:

Edit :sorry misunderstood, will check how to prevent the corporation spread

In fact you got it right, and your advice works like a charm.
I wanted two things:
1. Create building when the corporation spreads to the city
2. If there is Bazaar of Mammon already in the city, the building is not created. I still need help with this part, as I do not know how to do it.

Current code is:

Spoiler :
Code:
	def onCorporationSpread(self, argsList):
		'Corporation Has Spread to a City'
		iCorporation, iOwner, pSpreadCity = argsList
		player = PyPlayer(iOwner)
		iSteward = gc.getInfoTypeForString('CORPORATION_STEWARDS_OF_INEQUITY')
		pPlayer = gc.getPlayer(iOwner)

		if iCorporation == iSteward:
			pSpreadCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_STEWARDS'), 1)

		if (not self.__LOG_RELIGIONSPREAD):
			return
		CvUtil.pyPrint('%s has spread to Player %d Civilization %s city of %s'
			%(gc.getCorporationInfo(iCorporation).getDescription(), iOwner, player.getCivilizationName(), pSpreadCity.getName()))
 
This should work :

Code:
		iSteward = gc.getInfoTypeForString('CORPORATION_STEWARDS_OF_INEQUITY')
		iBaazar = gc.getInfoTypeForString('BUILDING_BAAZAR') #put the right type there of your building
		pPlayer = gc.getPlayer(iOwner)

		if (iCorporation == iSteward) and (pSpreadCity.getNumBuilding(iBaazar) == 0) :
			pSpreadCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_STEWARDS'), 1)

Tcho !
 
Top Bottom