Skip to content

Configurable primary selection - #7709

Open
Kestrellius wants to merge 14 commits into
scp-fs2open:masterfrom
Kestrellius:configurable-primary-select
Open

Configurable primary selection#7709
Kestrellius wants to merge 14 commits into
scp-fs2open:masterfrom
Kestrellius:configurable-primary-select

Conversation

@Kestrellius

Copy link
Copy Markdown
Contributor

The current primary weapon selection logic for the AI is a complicated set of hardcoded rules from eighteen years ago, and does not take into account many major changes to damage calculations since then. This PR introduces a new system, gated behind an AI_profiles flag like the previous iteration, which is intended to be elegant, comprehensive, and easily configurable by the modder.

The function goes through all available primary weapons and determines their damage per hit against the current target (shields, subsystem, or hull, depending on what the ship has targeted and whether the facing shield quadrant is up or down), taking into account as much of the damage calculation logic as was feasible. The biggest shortcoming here is the weapon hit curves: those assume that we have a weapon object, which at decision time we just don't, so I wasn't able to take them into account.

Next, we calculate the DPS, taking into account rate of fire, bursts, multishot, and energy consumption. There's some additional logic to check whether the weapon will kill the target in one shot (or one burst), and, if so, to give it some extra value in accordance with an AI class parameter.

The biggest limitation at this stage is consideration of weapon accuracy. Because projectile hit chance depends on target maneuvering choices, and target maneuvering choices will often depend on player input (either because the target is the player, or because it's reacting to the player), it is strictly impossible for us to perfectly calculate hit chance. Approximation is possible, but very difficult, and in practice would require hardcoding lots of assumptions, which I dislike doing, or exposing those assumptions to the modder, which would get very messy. So, at least for the moment, accuracy is disregarded and the function assumes that every projectile fired by the weapon will connect.

These limitations can be compensated for, when necessary, using the primary selection target flags system. I'm open to alternative naming suggestions, since 'flags' are really not quite what these are. For a given weapon, the modder may specify a set of modifiers to be activated under certain conditions, and multiply the weapon's value by a specified factor. A condition may be an armor type, a ship type, a ship class, or a weapon class. For example, the modder might give a heavy cannon a multiplier of 100 when used against cruisers, to ensure this weapon will always be used against those targets when available. Conversely, a multiplier of 0 will totally forbid use of the weapon against the target. Note that the traditional ad-hoc flags that controlled use of weapons against certain targets -- like the Huge flag forbidding use of the weapon against fighters -- are totally ignored by this system, except insofar as they affect damage.

Once we have the effective DPS and we've applied all the modifiers, we just take the weapon with the highest value.

I considered adding a set of modular curves to modify the final weapon value, or possibly other parts of the calculation, over inputs like target radius, target speed, distance to target, etc. I may still do that in the future, but at the moment I'm really not sure it would add much. The flags can be very granular if you want them to be, and the kind of dynamic attribute changes that would demand curves tend to change quickly enough that weapon-swapping isn't very useful anyway.

I also introduced a couple of AI parameters to provide more control over when the AI tries to choose a new primary -- a parameter for the delay between attempts, and an option to do a special check after a configurable delay when the target or target subsystem changes, or the target's shields drop or regenerate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant