Replacing a unit in the field?

yepzer

Chieftain
Joined
Jan 12, 2006
Messages
32
Location
Denmark
Hi

How can I mod a new unit action that replaces one unit with another?
What python file should I start manipulating?
Any considerations regards to copying unit properties (level/experience)?

Obviously, this XML snippet would upgrade the unit. But it would also
replace the unit in the city build screen, which I don't want.
I'm looking for an action to upgrade the unit in the "field", not
replace the entire unit class.
Code:
<UnitClassUpgrades>
         <UnitClassUpgrade>
	<UnitClassUpgradeType>UNITCLASS_ARCHER</UnitClassUpgradeType>
	<bUnitClassUpgrade>1</bUnitClassUpgrade>
         </UnitClassUpgrade>
</UnitClassUpgrades>

With that I would like to mod a Conscripts mod:
Code:
Workers (and Indian Fast workers) get a special action "conscript"
which changes the worker into a combat unit (depending on technology level):
archer, musketman, infantary. New new unit gets a -10% attack penalty
(might require a "promotion").

I haven't been able to find a mod that does this kind of magic,
so any code snippets or help would be of great help.


yepzer
 
Someone should have told me to use SDK MOD Action Buttons 2.0 (Note: currently not Warlords 2.08 compliant). It provides two hooks, configurable by XML. Here's my implementation for the Conscript mod:

Code:
from CvPythonExtensions import *
gc = CyGlobalContext()
	
def doMessage(m):
	CyInterface().addMessage(CyGame().getActivePlayer(),True,10,"%s" %m,'',1,'',ColorTypes(8),-1,-1,True,True)

def canDoConscript(pUnit,replace_class,tech_req):
	if pUnit.getUnitClassType() == gc.getInfoTypeForString(replace_class):
		player = gc.getActivePlayer()
		team = gc.getTeam(player.getTeam())
		return team.isHasTech(gc.getInfoTypeForString(tech_req))
	else:
		return false
	
def doConscript(old_unit,new_unit_str,promo,price):
	player = gc.getActivePlayer()
	replace = old_unit.getName()
	old_unit.kill(true,PlayerTypes.NO_PLAYER)
	newUnit = player.initUnit(gc.getInfoTypeForString(new_unit_str), old_unit.getX(), old_unit.getY(), UnitAITypes.NO_UNITAI)
	if promo <> '':
		newUnit.setHasPromotion(gc.getInfoTypeForString(promo),true)
	newUnit.finishMoves()
	player.changeGold(-price)	
	m = "%s changed into %s"%(replace,newUnit.getName())
	doMessage(m)
 

Attachments

  • screenshot.jpg
    screenshot.jpg
    62.3 KB · Views: 130
(Never got around to uploading the "entire" MOD - See attached).
It's fairly straight forward, add the py-files, create a specific use of the AB-dll (add a promotion) etc.

yepzer
 
Cool idea!!! You need to make one to have it go backwards... Like Swords to Plowshears or something like that. Like we had that massive build during WWII and then all the men from the war came back to work. You could either turn them into Workers or have them join a city (representing the Baby Boom).
 
Top Bottom