Outitch
Chieftain
"Great General Spare Troops" V1.0 python mod for BTS by Outitch
Hello everybody, this is my very first attempt to mod CIV .
This simple python modcomp consist in the following code, which should be inserted inside the function onUnitKilled() from the file CvEventManager.py in your mod folder.
What the mod does:
Let me know if there is any bug.
And last, a link to download the modcomp: http://forums.civfanatics.com/downloads.php?do=file&id=18333
Hello everybody, this is my very first attempt to mod CIV .
This simple python modcomp consist in the following code, which should be inserted inside the function onUnitKilled() from the file CvEventManager.py in your mod folder.
Code:
def onUnitKilled(self, argsList):
'Unit Killed'
unit, iAttacker = argsList
player = PyPlayer(unit.getOwner())
attacker = PyPlayer(iAttacker)
# Great general spare troops
if unit.isHasPromotion(gc.getInfoTypeForString("PROMOTION_LEADER")):
name = unit.getNameNoDesc()
combat = unit.getUnitCombatType()
pPlot = unit.plot()
bGGalone = True
bSameCombat = False
for iUnit in range(pPlot.getNumUnits()):
pUnit = pPlot.getUnit(iUnit)
if pUnit.isPromotionValid(gc.getInfoTypeForString("PROMOTION_LEADER")) and pUnit.getOwner() == unit.getOwner() and pUnit.getDomainType() == unit.getDomainType() and (not pUnit.isHasPromotion(gc.getInfoTypeForString("PROMOTION_LEADER"))):
if bGGalone:
pNewGGunit = pUnit # We have found a new unit for our GG
bGGalone = False # GG is no longer alone
if pUnit.getUnitCombatType() == combat:
bSameCombat = True # GG has found a new unit of same combat class
elif pUnit.getUnitCombatType() == combat:
if bSameCombat == False:
pNewGGunit = pUnit # We have found a new unit of same combat class for our GG
bSameCombat = True # GG has found a new unit of same combat class
elif pUnit.baseCombatStr() > pNewGGunit.baseCombatStr():
pNewGGunit = pUnit # We have found a stronger new unit of same combat class for our GG
elif pUnit.baseCombatStr() == pNewGGunit.baseCombatStr() and pUnit.getExperience() > pNewGGunit.getExperience():
pNewGGunit = pUnit # We have found a more experienced new unit of same combat class and same strength for our GG
elif not bSameCombat: # If we have not yet found a new unit of the same combat class
if pUnit.baseCombatStr() > pNewGGunit.baseCombatStr():
pNewGGunit = pUnit # We have found a stronger new unit for our GG
elif pUnit.baseCombatStr() == pNewGGunit.baseCombatStr() and pUnit.getExperience() > pNewGGunit.getExperience():
pNewGGunit = pUnit # We have found a more experienced new unit of same strength for our GG
if not bGGalone: # Put the GG to pNewGGunit
unit.setLeaderUnitType(gc.getInfoTypeForString("NO_UNIT")) # Remove, for the game, the leader. Will avoid ingame message "GG died in combat"
pNewGGunit.setHasPromotion(gc.getInfoTypeForString("PROMOTION_LEADER"),True) # Asign GG to its new unit, only add leader promotion
pNewGGunit.setLeaderUnitType(gc.getInfoTypeForString("UNIT_GREAT_GENERAL")) # Asign GG to its new unit, set for the game the unit with a leader, if not ingame message "GG died in combat" will never trigger next time our GG dies for real
pNewGGunit.setName(name) # Name the unit with the GG's name
pNewGGunit.setExperience(pNewGGunit.getExperience() + gc.getUnitInfo(gc.getInfoTypeForString("UNIT_GREAT_GENERAL")).getLeaderExperience() ,-1) # Gives GG xp again to the new unit, may be considered unfair and can be removed or not (to the appreciation of the user)
# End of great general spare troops
if (not self.__LOG_UNITKILLED):
return
CvUtil.pyPrint('Player %d Civilization %s Unit %s was killed by Player %d'
%(player.getID(), player.getCivilizationName(), PyInfo.UnitInfo(unit.getUnitType()).getDescription(), attacker.getID()))
What the mod does:
- If a unit possessing the leader promotion (i.e. having a great general attached to) dies from combat, the great general will try to attach to a new unit if there is any remaining unit from the stack which was containing the former (defeated) leader unit.
- The leader will try to attach to a unit of the same combat class, or the stronger unit remaining if there is no unit of the same combat class.
- The last line of python code make the leader give once again 20 xp to his new unit, but fell free to comment this line if you don't want that the leader gives xp again each times he is attached to a new unit.
- I always favored great generals as city specialist (who will grant free xp without taking risk) rather than warlords attached to units (who will either be lost after a few fights or, in my opinion, be useless since the odds are already high without warlord). With the ability for a warlord to survive as long as the stack is not empty, the choice between a warlord or a city specialist seems, in my opinion, more balanced.
- AI, which seems to think its battles in terms of stack victory/defeat, has a tendency to waste its warlords quickly (I often saw AI warlords attached to a siege unit commiting suicide against my walls). So this modcomp should also benefit to AI.
Let me know if there is any bug.
And last, a link to download the modcomp: http://forums.civfanatics.com/downloads.php?do=file&id=18333