Yea, the only problem is that effects aren't set up to be able to "apply an effect to self when skill is executed", otherwise, it would be the perfect answer. And I also agree that there's no new skill type that should be needed. However, here are some things to consider:
- Should the unit be able to instantly enter this state or should it take them time to "dig in"?
- If it takes them time, then perhaps a morph skill is more appropriate, especially if it costs them some type of resources, or modifies their commands (i.e., can no longer move). Remember that you can always have another morph skill to go back to a "not-dug-in" unit that executes nearly instantly.
- If you are going to change your "stance", you should probably implement some other penalty, i.e., aggressive stance would +damage but -armor/resistance/chance-to-be-hit (the last two which aren't yet implemented).
- Still, the idea of units having a "state" (or "stance") has merit and is probably worth consideration. Each stance could be defined in the same terms as an effect and a skill could be implemented to transition from one stance to another as a limited psudo-morphing ability, without defining another unit.
As far as targeting goes (i.e., attacking buildings first, etc.) that's a bit more complicated, and probably deserves consideration as well. I'm working on code to cause units to prefer to attack enemy units which aren't flagged as "walls" so that barrier units are treated correctly (will still have to teach the AI how to properly build them though). I'm also planning AI features which will cause the AI to attack specific unit classes and attempt to ignore others, unless blocked (specifically, harassment AI which targets harvesters & builders and other "soft targets"), so the functionality will be needed for this anyway.
This is unrelated, but may be of interest. There is code in place (although undocumented) to give an attack command more than one attack skill and a set of rules to use to choose the appropriate attack skill based upon the situation. You can use this specify a different attack skill when attacking buildings, but there is nothing to tell it to prefer to *target* buildings. Just for the record, you specify multiple attack skills in an attack command with more than one attack skill by specifying <attack-skills> instead of <attack-skill> in the <command type="attack"> tag. Each attack skill can have preferences associated with them so that the appropriate attack skill is selected based upon the situation. Look at the FPM's Lich and Battle Mech "auto_attack" commands for examples. To see more precisely how it behaves, you'll have to look at the source code for now (source/glest_game/types/command_type.cpp line 80), but this is a summary of the flags:
- whenever-possible (prefer to use this skill over all others, when possible)
- at-max-range (Haven't tested it yet and probably incomplete. I think this one was supposed to make the unit flee from their target if they got closer than the max range, so the attacking unit stayed as far away as possible)
- on-large-units (prefer to use this skill when attacking units that are larger than size 1)
- on-buildings (prefer to use this skill when attacking buildings)
- when-damaged (prefer to use this skill when attacking when at less than 100% health)
XML snippet from FPM Lich:
<command>
<type value="attack"/>
<name value="auto_attack"/>
<image path="../../../../placeholders/icon.bmp"/>
<unit-requirements/>
<upgrade-requirements>
<upgrade name="energy_extraction"/>
</upgrade-requirements>
<move-skill value="move_skill"/>
<attack-skills>
<attack-skill value="withering_dispair"/>
<attack-skill value="soul_steal">
<flags><when-damaged/></flags>
</attack-skill>
</attack-skills>
</command>
The Lich's auto-attack skill is what causes it to automatically choose the soul steal attack (the one that restores its HP using the HP of its enemies) only when the Lich is below 100% health.
XML snippet from FPM Battle Machine
<command>
<type value="attack"/>
<name value="auto_attack"/>
<image path="../../../../placeholders/icon.bmp"/>
<unit-requirements/>
<upgrade-requirements/>
<move-skill value="charge_skill"/>
<attack-skills>
<attack-skill value="melee_attack">
<flags><whenever-possible/></flags>
</attack-skill>
<attack-skill value="arrow_attack"/>
</attack-skills>
</command>
The Battle Machine's auto-attack skill allows it to use arrows to attack flying targets, but prefer to use it's melee attack whenever possible since it does a lot more damage.
So perhaps a <targeting-preferences> similar to the above can be added at some point? I would normally consider it extraneous except that my future AI will need it anyway. So those preferences could be something like:
- nearest (the current behavior)
- buildings
- non-buildings
- military
- harvester
- builder
- healer
- producer
- weakest
Most of this is for AI stuff, but if you really wanted to stick it on a command that you let human players use, you could. And one last note, there also will be a <move-skills> tag (to encapsulate <move-skill> tags) coming up to support stuff like walking when paroling, but running to attack when an enemy unit is sighted.