Free Units with Tech Question...

Wolfshanze

CFC Historian
Joined
Nov 12, 2001
Messages
5,689
Location
Florida
I know it's in there, and I know how to set it up... getting a free unit when you're the first to discover a tech (like getting a free Great General if you're the first to reach Fascism)...

But I was wondering if there was a way to give EVERYONE a free unit whenever they discovered a tech (as an example... could it be possible to give EVERY civ a free general whenever each civ discovered the Fascism tech?!?!?).

Is that possible in the XML? To give a free unit to each civ that discovers a given tech... not just the first to reach that tech?

I have an idea (and no it's not Fascism giving Generals, that was only an example), but I don't know if this is possible or not.
 
You can always handle it in Python with the onTechAcquired event handler.
Really?

Can you explain this a bit more?
 
From CvEventManager.py
Code:
	def onTechAcquired(self, argsList):
		'Tech Acquired'
		iTechType, iTeam, iPlayer, bAnnounce = argsList
		# Note that iPlayer may be NULL (-1) and not a refer to a player object

You just need to add some code to check if iTechType is the desired tech. If it is, pick a city belonging to iPlayer and spawn the unit(s) there.

Note that all the existing code does is show you what was researched and nothing else.

Compared to to SDK alterations it has one advantage, and some disadvantages.
Pro:
-Doesn't require recompiling the SDK


Con:
-Not particularly extensible. You have to replicate the code to add a unit for each tech you want to have that ability.
-Runs slower
 
This should do exactly what you ask for. Fast and simple really.

Code:
	def onTechAcquired(self, argsList):
		iTechType, iTeam, iPlayer, bAnnounce = argsList

		# Give each civ a free Great General upon discovering Fascism
		if (iTechType == gc.getInfoTypeForString('TECH_FASCISM')):
			pPlayer = gc.getPlayer(iPlayer)
			pCity = pPlayer.getCapitalCity()
			iUnit = gc.getInfoTypeForString("UNIT_GREAT_GENERAL")
			pUnit = pPlayer.initUnit(iUnit, pCity.getX(), pCity.getY(), UnitAITypes.NO_UNITAI)

You should probably remove the free Great General from the tech XML - unless you want first to acquire Fascism to get 2 free Great Generals.

This can easily be copy/pasted and adapted for other tech/unit combos - and with a few extra lines of codes added it could even take UUs into account, add experience to the unit, choose a more appropriate city for the unit to start in (ie. a coastal city for naval units) and/or even grant multiple units.


Btw then while Python does run slower than SDK then it really is a non-issue when used for something like this, since the check is only called once a civ acquires a new tech.
 
Oops, small error in the code above.

For the purpose of this method then
Code:
			pPlayer = gc.getPlayer(iPlayer)

should be
Code:
			pPlayer = PyPlayer(iPlayer)

to be able to use .getCapitalCity().
 
Back
Top Bottom