davidlallen
Deity
I want to have a unit which looks different, when it moves in certain terrain. I have this partly working; I use another unit with its own artdef, and I hook onUnitMove to call pUnit.convert(). In the following complete standalone example, I convert Knight to its related unit Cataphract, whenever the knight moves off grass. And the Cataphract converts back to knight when it moves onto grass.
This works, as long as I move the unit only one plot. If I move the unit two plots, and the first plot causes a change, the unit forgets its mission and stops. How do I keep the mission for the unit?
In case you are curious, the actual application is in Dune Wars. When a Fremen unit moves into the desert, it automatically attracts a sandworm to ride. We have the graphics for a sandworm rider; I just need to make it appear and disappear on demand.
Code:
def Convert(self, pUnit, iNewType):
ix = pUnit.getX() ; iy = pUnit.getY()
iOwner = pUnit.getOwner()
pOwner = gc.getPlayer(iOwner)
dir = DirectionTypes(pUnit.getFacingDirection())
pNew = pOwner.initUnit(iNewType, ix, iy, \
UnitAITypes.NO_UNITAI, dir)
pNew.convert(pUnit)
pUnit.kill(true, iOwner)
def onUnitMove(self, argsList):
pPlot,pUnit,pOldPlot = argsList
iUnit = pUnit.getUnitType()
iTerr = pPlot.getTerrainType()
iUnit1 = gc.getInfoTypeForString("UNIT_BYZANTINE_CATAPHRACT")
iUnit2 = gc.getInfoTypeForString("UNIT_KNIGHT")
iTerr1 = gc.getInfoTypeForString("TERRAIN_GRASS")
if iUnit == iUnit1 and iTerr == iTerr1:
self.Convert(pUnit, iUnit2)
elif iUnit == iUnit2 and iTerr != iTerr1:
self.Convert(pUnit, iUnit1)
This works, as long as I move the unit only one plot. If I move the unit two plots, and the first plot causes a change, the unit forgets its mission and stops. How do I keep the mission for the unit?
In case you are curious, the actual application is in Dune Wars. When a Fremen unit moves into the desert, it automatically attracts a sandworm to ride. We have the graphics for a sandworm rider; I just need to make it appear and disappear on demand.