davidlallen
Deity
I have a working "limited fuel" mod and gunships. When the gunship runs out of fuel, I want the unit art to be different, the rotor should be still and the shadow should show it on the ground. Refar has contributed the "grounded gunship" art.
Is there a good way to change the art (only) of a unit in python?
The only way I could think of is to create a copy of the unit, GROUNDED_GUNSHIP. When the unit runs out of fuel, create a new unit, copy its damage, experience, and promotions, and delete the old unit. Same thing in reverse when it gets refueled.
This is working, sort of, but there is one inefficiency and one problem. So I am hoping somebody can suggest a different approach.
The inefficiency: I need to copy the promotions, and there is no way to iterate like CyUnit.getNumPromotions, CyUnit.getPromotion(i). I don't want to have to loop *all* promotions with "if unit1.isHasPromotion(promo): unit2.setHasPromotion(promo,true)". So I have manually built a list in python of all the promotions the gunship could have, and I loop through that instead. It is still inefficient. Is there any way to loop the promotions that a unit has?
The problem: I am missing something about experience. There is a call getExperience, fine. But, the prototype for setExperience is (int experience, int max_experience). Huh? How do I know what the max experience is? There is no getMaxExperience or anything similar. I am calling with -1 since I don't know what else to pass. But, the new unit has an incorrect "next level" threshold.
Suppose the original unit has 3 XP, so its next level is 4. The XP shows up in the display as "(3/4)" and it is not eligible for any new promotion. I copy the unit as I have described. The new copy shows up with XP "(3/2)" and it is now eligible for promotion! Of course it has the one promotion already since I copied it. It seems that copying the unit gives it a free promotion eligibility.
I don't know if it will help any, but here is the related python function.
Is there a good way to change the art (only) of a unit in python?
The only way I could think of is to create a copy of the unit, GROUNDED_GUNSHIP. When the unit runs out of fuel, create a new unit, copy its damage, experience, and promotions, and delete the old unit. Same thing in reverse when it gets refueled.
This is working, sort of, but there is one inefficiency and one problem. So I am hoping somebody can suggest a different approach.
The inefficiency: I need to copy the promotions, and there is no way to iterate like CyUnit.getNumPromotions, CyUnit.getPromotion(i). I don't want to have to loop *all* promotions with "if unit1.isHasPromotion(promo): unit2.setHasPromotion(promo,true)". So I have manually built a list in python of all the promotions the gunship could have, and I loop through that instead. It is still inefficient. Is there any way to loop the promotions that a unit has?
The problem: I am missing something about experience. There is a call getExperience, fine. But, the prototype for setExperience is (int experience, int max_experience). Huh? How do I know what the max experience is? There is no getMaxExperience or anything similar. I am calling with -1 since I don't know what else to pass. But, the new unit has an incorrect "next level" threshold.
Suppose the original unit has 3 XP, so its next level is 4. The XP shows up in the display as "(3/4)" and it is not eligible for any new promotion. I copy the unit as I have described. The new copy shows up with XP "(3/2)" and it is now eligible for promotion! Of course it has the one promotion already since I copied it. It seems that copying the unit gives it a free promotion eligibility.
I don't know if it will help any, but here is the related python function.
Code:
def changeGunship(self, pOld, hasGas):
iOwner = pOld.getOwner()
pOwner = self.gc.getPlayer(iOwner)
if hasGas: iType = self.gc.getInfoTypeForString("UNIT_GUNSHIP")
else: iType = self.gc.getInfoTypeForString("UNIT_GUNSHIP_GROUND")
pNew = pOwner.initUnit(iType, pOld.getX(), pOld.getY(),
UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_EAST)
pNew.setDamage(pOld.getDamage(), iOwner)
pNew.setExperience(pOld.getExperience(), -1)
pNew.setScriptData(pOld.getScriptData())
# No efficient way to loop promotions I have?
for iPromo in self.gunPromos:
if pOld.isHasPromotion(iPromo): pNew.setHasPromotion(iPromo, true)
pOld.kill(false, iOwner)