Configurable primary selection - #7709
Open
Kestrellius wants to merge 14 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Hugeflag 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.