Units built on national wonder completion

Jarlaxe Baenre

Emperor
Joined
Feb 17, 2010
Messages
1,959
Location
Calgary, Alberta, Canada
How would you, for example, get all cities within (59, 48) and (66, 54) to receive 3 units (Musketman, Rifleman, Infantry, Marine, whichever is the most modern the civ can build) upon completion of a specific building? (Let's say "BUILDING_WALKÜRE" or whatever it would be called in python)
If I can't remove the German UP, I'll improve it
 
First of all, you launch your code with the onBuildingBuilt callup in CvEventManager. The second argsList value is the building type, so the conditional statement would read:
Code:
if argsList[1] == buildingTypes.BUILDING_WALKÜRE:
You loop the coordinates with:
Code:
for iX in range(59, 66+1):
    for iY in range(48, 54+1):
You check every tile for a city with:
Code:
pPlot = gc.getMap().plot(iX, iY)
if pPlot.isCity():
Then you get the current unit type for each city with:
Code:
pCity = pPlot.getPlotCity()
eUnitType = pCity.getConscriptionUnit()
And finally you spawn the unit with:
Code:
[COLOR="Red"]player = PyHelpers.PyPlayer(ePlayer)[/COLOR]
player.initUnit(eUnitType, iX, iY, 3)
The marked line requires two things: Firstly you need to know which player ID gets the spawned units, and secondly you need to import the PyHelpers module - if it isn't imported already in the module your working with.

To get the player ID you can use the line:
Code:
ePlayer = argsList[0].getOwner()
Some practical help with this can be found in my Python tutorial.
 
In Assets\Python\CvEventManager.py, one example:
PHP:
	def onBuildingBuilt(self, argsList):
                print 'onBuildingBuilt'
		'Building Completed'
		pCity, iBuildingType = argsList
		game = gc.getGame()
	###new code
		if iBuildingType == gc.getInfoTypeForString( 'BUILDING_MT_RUSHMORE' ):
                        iX = ppCity.getX()
                        iY = ppCity.getY()
                        pPlayer = gc.getPlayer(pCity.getOwner())
                        iUnit = gc.getInfoTypeForString( 'UNIT_MACEMAN' )
                        pNewUnit = pPlayer.initUnit( iUnit, iX, iY, UnitAITypes.UNITAI_CITY_DEFENSE, DirectionTypes.NO_DIRECTION )
 
Where would I type all that? Can it just be anywhere? (But in order, of course)
Note that you also have to consider things like indentation. I you're gonna start programming, you really should learn some of the basics first. Just a suggestion.

So I intentionally didn't do your mod for you, as then you wouldn't have to learn anything. Just tell me if you're not interested and I can do the whole thing to your specifications. Then you wouldn't have to bother with it.

And most of these things are explained in the tutorial. :)
 
Also, I now realize you're mod-modding RFC, right?

Then you would add the code in the UniquePowers module with its own function definition:
Code:
        def germanUP(self, argsList):
Note that the indentation for all code must match. RFC modules mostly use 8 blank spaces for each indentation level. And the indentation levels goes up whenever the previous line ends with a colon, like the definition line above.

This function (really a method of the UniquePowers class, don't ask) would then be called from the onBuildingBuilt callup in CvRFCEventHandler module, like:
Code:
                self.up.germanUP(argsList)
This is basically it, but there are a good number of places you could mess this one up. :D
 
Top Bottom