[SDK Request] Units dependant on units

Vehem

Modmod Monkey
Joined
Nov 22, 2005
Messages
3,219
In order to allow for a more complex "army structure", I'd like to have certain units require a number of other units to be present before they can be trained. This would be useful to restrict the creation of Elite-type units to only a certain percentage of the overall force.

Example:

Elite Unit: Praetorian Guard
Requires: 4 Legionaires

In this case, you would be allowed only 1 Praetorian for every 4 Legionaires you currently control (the number you currently control being as they are listed in the [Enhanced?] Military Advisor - Empirewide, not just local).

Ideally the requirement could be for an arbitrary number of different unit types.

Example:

Elite Unit: Grand Knight of the Empire
Requires: 4 Footmen
Requires: 8 Squires
Requires: 16 Peasants

In the above example, the "Grand Knight" would act as a "power-piece" in the game, whilst the other units play a lesser role, doing the day-to-day defending and policing of the empire. One strategy may be to attack an opponent's "peasant-force" in order to prevent him replacing the grand-knight once he is finally toppled. Likewise, a counter strategy may involve having far more support troops than a neccessary to raise a new Knight, to ensure that when he is lost, he can quickly be replaced.

Mechanics-wise

Axeman requires 2 Warriors
If Axeman is killed, but warriors are alive, axeman can be rebuilt using the original warriors as the required units.
If Warriors are killed, the axeman remains in-play, but cannot be replaces until the warriors are also replaced.
If you have 4 warriors, you may have 2 axemen in play at a time.



--

Of course - the above is nothing trivial to code, but I'm hoping one of the codesmiths finds it interesting enough to throw a few lines of C++ at it.

--
Vehem
 
Yeah, you probably want to intercept the python CannotTrain function in CvGameInterface.py.

Something like the following:

Code:
def cannotTrain(argsList):
	pCity = argsList[0]
	eUnit = argsList[1]
	bContinue = argsList[2]
	bTestVisible = argsList[3]
	ePlayer = pCity.getOwner()
	pPlayer = gc.getPlayer(ePlayer)

	if eUnit == gc.getInfoTypeForString('UNIT_AXEMAN'):
		iWarriorCount = pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_WARRIOR'))
		iAxemanCount = pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_AXEMAN'))
		if (iAxemanCount + 1) * 2 < iWarriorCount:
			return True

	return False
 
Kael said:
Yeah, you probably want to intercept the python CannotTrain function in CvGameInterface.py.

Something like the following:

Code:
def cannotTrain(argsList):
	pCity = argsList[0]
	eUnit = argsList[1]
	bContinue = argsList[2]
	bTestVisible = argsList[3]
	ePlayer = pCity.getOwner()
	pPlayer = gc.getPlayer(ePlayer)

	if eUnit == gc.getInfoTypeForString('UNIT_AXEMAN'):
		iWarriorCount = pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_WARRIOR'))
		iAxemanCount = pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_AXEMAN'))
		if (iAxemanCount + 1) * 2 < iWarriorCount:
			return True

	return False

Aye - the python route would work well for specific instances, but I was considering a more generic implementation that would allow for the requirements to simply be added to XML as needed.

If you were to build a large system of interdependencies (spanning the length of the game), you'd end up with a lot of python checks against the InfoTypeForString which would quickly get very hard to manage and not be as accessible to other people who may wish to use it as the XML/SDK solution could be.

That being said - the code Kael supplied is a lot more complete than the Python I toyed with earlier, so I may have a play with that and see if it lends itself to larger scale use - thanks Kael.

--
Vehem
 
Didn't somebody do this already??? I could've sworn there was already a mod/modcomp out there that allowed only a certain number of units based on total army size...
 
Vehem said:
Aye - the python route would work well for specific instances, but I was considering a more generic implementation that would allow for the requirements to simply be added to XML as needed.

If you were to build a large system of interdependencies (spanning the length of the game), you'd end up with a lot of python checks against the InfoTypeForString which would quickly get very hard to manage and not be as accessible to other people who may wish to use it as the XML/SDK solution could be.

That being said - the code Kael supplied is a lot more complete than the Python I toyed with earlier, so I may have a play with that and see if it lends itself to larger scale use - thanks Kael.

--
Vehem

Np, I agree with you that an XML/SDK solution would be more managable if you intended to do lots of work with it.

BTW, you may want to consider the impact of gifting units. Something to keep the player from building the uber unit, gifting it to his ally, building another uber unit (since after gifting the player has essentially lost the unit), etc.
 
Kael said:
BTW, you may want to consider the impact of gifting units. Something to keep the player from building the uber unit, gifting it to his ally, building another uber unit (since after gifting the player has essentially lost the unit), etc.

Very good point - and one I hadn't considered. I guess the most straightforward fix would be to intercept the "gifting" and check that the receiving player could support the new unit (has the unit-requirements). "Your ally cannot support this unit" or similar...

--
Vehem
 
Back
Top Bottom