Ok, here's version 2. I didn't edit the OP, so we could have them both around for comparison.
Code:
/** The missions available to ships. The notion of "weakest" is
intentionally left fuzzy. The weakest target is one that is likely to
die quickly, and also one that is unlikely to kill the ship. Some
relative of scaling these two factors should be employed to come up with
a single weakness value. */
enum MissionType {
/** No mission set. This mission is treated as
ATTACK_SHIPS_NEAREST_FIRST. */
NONE,
/** Keep current position -- do not move for any reason. */
HOLD_POSITION,
/** Move to a speficic location. Enemy presence will be ignored. */
MOVE_TO,
/** Attack a specific fighter group or vessel. */
ATTACK_THIS,
/** Defend a specific fighter group or vessel, by attacking its
attackers in order from weakest to strongest. Defenders with
sufficient PD will place themselves between the defendee and known
hostile LR sources. */
DEFEND_THIS,
/** Moves to a specific location. Movement will be interrupted to
engage non-fighter targets as soon as they are found. */
PATROL_TO,
/** Attack ships without further direction, in order of weakest to
strongest. */
ATTACK_SHIPS_WEAKEST_FIRST,
/** Attack ships without further direction, in order of nearest to
farthest. */
ATTACK_SHIPS_NEAREST_FIRST,
/** Enter starlane. The ship is immobilized for a few combat turns
until the ship can enter the starlane. The ship can still attack
and be attacked. This mission is only valid when the ship is inside
a starlane entry point -- if it isn't, the mission is cancelled. */
ENTER_STARLANE
};
/** The attack postures available to ships. Each posture indicates a
desired range at which to engage enemies for which the ship has been
given an ATTACK* mission. */
enum AttackPosture {
/** Do not fire at targets. This effectively puts the ship at
STANDOFF's range, but does not fire any weapons. */
HOLD_FIRE,
/** Only fire non-ammo-consuming weapons at targets. This effectively
puts the ship at ASSAULT's range, but does not fire any LR
weapons, or SR/PD weapons that consume ammo. */
SAVE_AMMO,
/** Close to within 95% of its shortest-ranged LR weapon's maximum
range. If the ship has no LR weapons, this posture acts as
ASSAULT. */
STANDOFF,
/** Close to within 95% of its shortest-ranged, non-PD weapon's
range. */
ASSAULT,
/** Close to within 95% of its shortest-ranged weapon's range. The
ship will use its PD weapons on the target, instead of using them
on enemy LR and Fighters. */
BRAWL
};
The missions are back to something a lot more like the fighter missions, except for HOLD_POSITION.
The attack postures are designed to control how the ship should move with respect to range, and how it should fire. This could perhaps more cleanly be defined in terms of a range-setting and a weapons-use setting, but I'm thinking ahead a bit here -- it is going to be a massively simpler interface to select 2 settings than to select 3.
STANDOFF allows a ship to stay at extreme range when using LR weapons. If it doesn't have any, it will stay as far away as it can while still using its SR weapons. ASSAULT puts a ship within SR range. BRAWL is all-out attack. It puts the ship at point-blank range, and even directs the PD weapons to attack the target, regardless of the presence of LR and Fighters. Note that the "95%" is a placeholder -- it may have to be closer than that to keep the weapons in range of moving targets. Testing will define the real number used.
HOLD_FIRE indicates that the ship should move to STANDOFF-range, but should not fire yet. SAVE_AMMO indicates that the ship should move to ASSAULT range, but not fire ammo-consuming weapons. It is assumed that all LR weapons will consume ammo, which explains the use of ASSAULT-range for SAVE_AMMO.
I should also note some assumptions made in this missions thread, and the one for Fighters.
1) Firing and movement are separate. For instance, Fighters will shoot at their primary target when in range, but will take pot shots at targets of opportunity when their primary target is in range. So, even when under an ATTACK_THIS mission, if a Fighter cannot hit its attack-target, it will fire on the nearest thing it can hit, with bombers preferring to hit ships and interceptors preferring to hit other Fighters. This firing policy applies to ships as well (though they will always pick near ships first, then near Fighters, regardless of type).
2) All weapons fire in all directions. Only range is considered when selecting targets/firing opportunities.
3) Fighters and ships will try to get out of the range of enemies firing at them, within limits of accomplishing their missions. So a ship with the STANDOFF mission that starts taking fire from the left, will move to the right in a big circle around its target, moving away from its attacker. The HOLD_POSITION mission is obviously an exception.
4) Ships' PD weapons are reserved for shooting down LR and Fighters. If there are no LR or Fighters around and there are ship targets in range of its PD, the ship will use its PD on ships, even though it may not be too effective. When a ship is given an ATTACK_THIS mission on a Fighter or Fighters, it will also use its ship weapons in addition to its PD to try to shoot down the fighters.
5) Weapons do the same damage at all ranges. Getting closer doesn't score more damage, and there is no minimum range.