[Python]Attack/Defence Specialist Units

Flying Pig

Utrinque Paratus
Retired Moderator
Joined
Jan 24, 2009
Messages
15,651
Location
Perfidious Albion
Is there a way (hopefully in Python) to make a unit which gets a bonus in attack or defence against any unit (short of writing out every unit name in the XML)?
 
You can give the bonuses against CombatTypes, can't you? This will at least be a much smaller list.
 
does every unit have a combattype?

What you can do is use terrain modifiers. Give a Unit +20% defense on any terrain.
 
You're doing this so you can have a unit with different attack and defense strengths, right.

Assuming anything without a combat type cannot attack or defend itself, this unit's strength won't matter--free win and cannot be attacked by units without a CT.
 
I'm liking the terrain idea at the moment.

Assuming anything without a combat type cannot attack or defend itself, this unit's strength won't matter--free win and cannot be attacked by units without a CT.

Can you explain this a bit more?
 
Workers, Settlers, and Work Boats all have NONE for their combat type. In CIV4UnitInfos.xml this looks like

Code:
<Combat>NONE</Combat>

When you attack one of these units, there is no combat; you simply kill/capture the unit. Having 200% or 5000000% strength against them won't make a difference. And they cannot attack. Period. So having 200% defense won't matter either.

However, I see that also other units that can attack and defend themselves (e.g. Lions) with NONE for combat type, so my idea won't work. You're better off going with the terrain bonus which will work for all units. It will just look weird when hovering over the unit, but the effect is what you want.
 
You could assign unitcombats to those units that have none. Perhaps a "UNITCOMBAT_NONCOMBATANT" for the workers, settlers, and workboats and a "UNITCOMBAT_ANIMAL" for the animals.

This might have some odd side effects. One side effect is that you could actually allow promotions for them - not very useful for the noncombatants, but I don't see why animals shouldn't be able to get at least Combat I.
 
Holy crap, I can just see it now . . . a Combat II, Shock Bear roaming the lands tearing up my poor exploring Warriors! :eek:
 
Is there a way (hopefully in Python) to make a unit which gets a bonus in attack or defence against any unit (short of writing out every unit name in the XML)?

<rant>
IMO, this thread is a complete farce. Why would you complain about having to do a feature in XML and then try to do the same feature in python. It's re-inventing the wheel, except that the wheel was already invented 10000 years ago and your new wheel is harder to use and less efficient. Just create the XML and be gone. Or make a new unitcombat and specify that instead. I'm sorr-ee that Firaxis didn't make a mind-helmet that allows modders to wish up new features and code it for them. Life sucks. Good things take time. Frankly, I'm happy that they were kind enough to give us a way to specify unitclass's individually. It gives modders more room to move around with. The alternative would be much worse.
</rant>

Sorry, I just hate it when people whine about XML. XML is the greatest tool modders have ever been given. Simple, elegant, understandable. What's not to love?
 
I think you're reading way too much into Flying Pig's post. I would certainly look for an easier method than listing every unit in the XML and doesn't break when a modder adds new units. Seeking better ways of doing things is a commendable action IMHO. It's the spirit behind BUG. :)
 
I think you're reading way too much into Flying Pig's post. I would certainly look for an easier method than listing every unit in the XML and doesn't break when a modder adds new units. Seeking better ways of doing things is a commendable action IMHO. It's the spirit behind BUG. :)

Probably, but I think the time he has taken to find an alternate to the XML is already far greater than the time it would have taken to hunker down and write it all out. A Better way is always great, but I don't think there is a "better" way, unless you mean creating a unitcombat. In the python, undoubtedly, he would have to use gc.getInfoTypeForString("UNIT_XYZ") over and over which, frankly, takes longer to write than one XML block. :p

I feel like I should start yelling at you lazy whippersnappers, but I'm younger than all of you. :lol:
 
I often find when interviewing candidates for software engineer roles that a leading indicator of a great engineer is a bit of laziness and a lot of willingness to do a lot of creating work up front to save repetitive work over time.

The first time I do a tedious task, I look for a better way, whether that be faster or more elegant or easier or whatever. If I don't find one, the next time I need to do that same tedious task, I make a better way. Chances are good that anything I've needed to do twice others will need to do as well.
 
Luckily, the mod I'm using only has 2 terrain types, so I gave it a 50% cut to base strength and a 100% attack bonus on both terrain types. Works great - screaming angel of death on the attack (it gets 4 moves and a free Blitz), sitting duck on the defence
 
I often find when interviewing candidates for software engineer roles that a leading indicator of a great engineer is a bit of laziness and a lot of willingness to do a lot of creating work up front to save repetitive work over time.

The first time I do a tedious task, I look for a better way, whether that be faster or more elegant or easier or whatever. If I don't find one, the next time I need to do that same tedious task, I make a better way. Chances are good that anything I've needed to do twice others will need to do as well.

A lazy programmer is the best programmer. :mischief:

I believe that's why Firaxis made UnitCLASS and UnitCOMBAT's for. If you've got too many UnitCLASS's, create a new UNITCOMBAT. I did that for missionaries. :p

And that's not what bugged me. It's that Flying Pig began his search in the exact wrong direction. I have never seen an instance where doing the same thing in python was easier or faster than in XML. (prove me wrong.) Python is very useful, but not when it comes to altering combat results. Plus, how on earth was he going to tell the AI that certain units had "invisible" advantages?
 
I didn't think it could be done neatly in XML, and such problems are normally fixed by python.

Rule of Thumb: If the AI needs to know about it, cross Python off the list. Python can't teach the AI.

Although, I'm glad you got it working ;)
 
I said a "bit" of laziness, and it's more what lies behind that laziness: wanting to avoid boring, repetitive tasks and willing to do a lot of work to do so. The key is to find someone who will spend far more energy making a better way than they would ever spend doing the task themselves in the hope that they will save themselves or other people more energy in the future.

My guess is that FP knows Python or some other programming language and is more familiar with it. When in doubt, go with what you know. My only suggestion for the future would be to start with the explanation of why Python would be a bad choice (AI) before assailing someone's character and motives. ;)
 
Top Bottom