[Help Needed][XML or Python ?] How to capture tanks, plane, etc ?

Fabrysse

Charming-snake learner
Joined
Sep 11, 2006
Messages
430
Location
Toulouse - France
Hi,
I'd like to add a function to the game, but I don't really know how to do that...

Here is what I want to do :
When you fight a "machine" (tank, plane, artillery, etc), and if you win (perhaps if you kill the unit), you have a percent chance to capture the unit, and then may use it as one of yours.
Imagine that you have defeated a tank, the soldiers in the tank are dead or are gone away. The tank is not every time destroyed. Perhaps, you could repar and use it ?...

How I think I'll do that ?
I thought add a python function like that :
  • when a unit is killed, if this unit has the "<FormationType>FORMATION_TYPE_MACHINE</FormationType>" (in UnitInfo.xml)
  • get a random percent chance that the combat winner capture the unit,
  • create the same unit for the winner on the plot from where the attack was launched.

Questions :
  • How can I get the unit's FormationType infos with python ?
  • Will it run if I try to create a unic unit of civ A for civ B ?
  • Can't I just use the XML tag "<Capture>UNITCLASS_MYUNIT</Capture>" (and forgot python stuff) ? And if I use that, will the unit fight before being captured ?
 
Because you do not want every unit to be capured or capture killed units, I think It would be better to include to 2 addition XML tags to UnitInfo.xml called <iCaptureBonusChance> and <iGetCapturedChance> . <iCaptureBonusChance> should modify the chance of capturing an emeny unit while <iGetCapturedChance> modifies the chance a unit becomes captured. This allows certain units to become better/worse captures while other units become become harder or easier to be captured.

Let's say an artilery piece has a iGetCapturedChance value of 50. Then a Regular infantry unit with a iCaptureBonusChance of 0% can capture the artilery unit with a chance of 50+0 = 50%. A tank on the other hand, which tend to destroy their target have a negative iCaptureBonusChance of -40 and would therefore only have a 50-40=10% chance of capturing the artilery unit.

I think I'm going to implement this in my BTS Utlimate Combat Mod
 
Because you do not want every unit to be capured or capture killed units, I think It would be better to include to 2 addition XML tags to UnitInfo.xml called <iCaptureBonusChance> and <iGetCapturedChance> . <iCaptureBonusChance> should modify the chance of capturing an emeny unit while <iGetCapturedChance> modifies the chance a unit becomes captured. This allows certain units to become better/worse captures while other units become become harder or easier to be captured.

Let's say an artilery piece has a iGetCapturedChance value of 50. Then a Regular infantry unit with a iCaptureBonusChance of 0% can capture the artilery unit with a chance of 50+0 = 50%. A tank on the other hand, which tend to destroy their target have iCaptureBonusChance of -40 and would therefore only have a 50-40=10% chance of capturing the artilery unit.

That's a very good idea !!!
The problem is that I can't do it with SDK. I suppose it's possible to put those tags in a .ini file, and make it running only with python...
Or I use other already existing tags to make that. I'll search something like that.
Thanks !

Other question :
In onUnitKilled, can I know where is located the unit who attacked ?...
 
It did exactly what you want. Now yes you could put those tags in an INI file. Sorry I can't help more, I'm just so busy. :cry:
 
It did exactly what you want. Now yes you could put those tags in an INI file. Sorry I can't help more, I'm just so busy. :cry:

Hi,
I'm not at home, so I can't test your zUnitEnslavement mod in game. I think I won't write new python code. I'll probably use your's (with credits given, of course). :goodjob:
I have few questions :
  • It doesn't seem to be BtS compatible (at least, initUnit doesn't give direction info)... Right ?
  • Will it run with air units :
    Code:
    self.addUnitClass("UNITCLASS_ANTIAIRCRAFT_ARTILLERY", "UNIT_FIGHTER", 3)
  • In unitInfos.xml, we have a <capture> tag. If I write :
    Code:
    self.addUnitClass("UNITCLASS_TANK", "UNIT_SETTLER", 30)
    will the winner get a settler (the original unit is captured) or a worker (uses the "capture" tag) ?
  • Special units... The loser, instead of tanks has panzers, but the winner has tanks. If I write :
    Code:
    self.addUnitClass("UNITCLASS_TANK", "UNIT_PANZER", 10)
    will the winner get a panzer ?
 
Yes you will have to add the direction info to the initUnit. I'm not sure if it will work with air units because I'm not sure if they actually combat each other. The capture tag works separately from this MOD COMP, so I'm not sure what you want there. That last one will give a Panzer to the winner if the winning unit is a tank (of course the 10% come in to play as well).
 
Back
Top Bottom