Improved collision avoidance for fighters#2810
Conversation
|
I’ll also note that I’ve been testing the branch for the past two days and turning on the updated collision even makes for immersion improved since the AI is behaving a lot more competently. |
wookieejedi
left a comment
There was a problem hiding this comment.
Definitely want to give some other folks time to look at it, but through code evaluation and personal testing everything worked well.
| bool better_collision_avoid_and_fighting = The_mission.ai_profile->flags[AI::Profile_Flags::Better_collision_avoidance] && aip->mode == AIM_CHASE; | ||
|
|
||
| // if this guy's in battle he doesn't have the time to spend up to 35 seconds recovering! | ||
| int phase1_time = better_collision_avoid_and_fighting ? 2 : 5; |
There was a problem hiding this comment.
Might be good to expose this value at some point and make it settable via the ai table. Maybe within the scope of this PR? BTW, I looked through everything, too. Looks good.
There was a problem hiding this comment.
I'm generally averse to adding profile options if the code can handle it properly in general for all cases (obviously exempting the very flag I'm adding), which is the intention of the values chosen here as well as with collision_avoidance_aggression. The only use case I can think of for exposing it would be to choose unusual values to fit unusual ships, which this should be able to handle, even as is. I am more than willing to re-examine this code to improve and generalize it further later, but once things go into the tables they rarely come out.
The `$better combat collision avoidance for fightercraft:` flag is incredibly useful in preventing AI from hitting large ships while attacking, and the ability to tune the collision avoidance aggression factor further helps mods tune behavior based on their ship speeds (tuning that value is via `+combat collision avoidance aggression for fightercraft:` ). Nevertheless, the improve collision avoidance still is not performed for that actual fightercraft's actual target, so there can be situations where a fast fighter attacks a large ship with high speed, and then when that fighter break off from the attack they turn directly into the large ship's hull. Allowing the target to be incorporated into the `better_collision_avoidance_triggered` check prevents this from happening. To allow the target to be a part of the checks we just simply need to not pass an 'ignor_ship` argument to `maybe_avoid_big_ship`. This PR adds that ability via flag. This new flag is tested and works as expected. For example, without the flag a squadron of TIEs in FotG would literally ram themselves to death attacking some of our larger capital ships because they would break off attack too late, but with this flag they no longer accidentally collide at all. In discussion with Asteroth it was decided to make this enhanced behavior behind a flag, too. This PR also fixes a small oversight from the original scp-fs2open#2810 where `next_check_time` was never actually used within the `else` block of `maybe_avoid_big_ship`.
The `$better combat collision avoidance for fightercraft:` flag is incredibly useful in preventing AI from hitting large ships while attacking, and the ability to tune the collision avoidance aggression factor further helps mods tune behavior based on their ship speeds (tuning that value is via `+combat collision avoidance aggression for fightercraft:` ). Nevertheless, the improve collision avoidance still is not performed for that actual fightercraft's actual target, so there can be situations where a fast fighter attacks a large ship with high speed, and then when that fighter break off from the attack they turn directly into the large ship's hull. Allowing the target to be incorporated into the `better_collision_avoidance_triggered` check prevents this from happening. To allow the target to be a part of the checks we just simply need to not pass an 'ignor_ship` argument to `maybe_avoid_big_ship`. This PR adds that ability via flag. This new flag is tested and works as expected. For example, without the flag a squadron of TIEs in FotG would literally ram themselves to death attacking some of our larger capital ships because they would break off attack too late, but with this flag they no longer accidentally collide at all. In discussion with Asteroth it was decided to make this enhanced behavior behind a flag, too. This PR also fixes a small oversight from the original #2810 where `next_check_time` was never actually used within the `else` block of `maybe_avoid_big_ship`.
Tired of enemies afterburning directly into the broad side of an Orion? Not anymore!
Adds the "$better combat collision avoidance for fightercraft:" flag. While fighting, and only while fighting, (that is,
AIM_CHASE) small ships will project their velocity outward to predict collisions and avoid colliding with big or huge ships that it finds, before executing any of its submodes. This is sort of collision detection is usually only done while in an attack submode, and only along the me-to-my-target vector, making it only useful to circumvent intervening obstacles. For this reason (and probably also for now irrelevant performance reasons), the timings used by the function are relatively long, so atime_scaleparameter was added so it could be used much more frequently by the general combat collision avoidance. 1.5 seconds, the default time to recheck if no collision was found, is more than enough time to go from 'a comfortable distance from the destroyer' to a collision, so the time scale has been set for it to check ten times more frequently.Additionally, since this system is not perfect and collisions will still occasionally occur, ships in combat will now spend far less time recovering from it. Rather than up to 45 seconds (!!!) and usually making them utterly useless and a sitting duck, these ships will only spend two seconds recovering, instead of leisurely waltzing to the ship's bounding box.
One small change that is not covered by the flag, and will affect retail is that the recovery system was slightly altered. Normally after a collision the ship will project a vector 100m away from the collision to go to for phase 1, and then the closest bbox point for phase 2 (spending at most 15 and 30 seconds on each phase). I've modified it slightly so that phase 1 generates a relative direction to travel in, rather than a global position, and since it can't actually reach this point now the time was reduced to 5 seconds (an average case for phase 1). For high velocity collisions its entirely possible the ship can end up several hundred meters from its original position by the time it regains control, so it may end up spending phase 1 uselessly traveling basically back to the original collision point rather than actually moving away from the collision.
This was done because it works very well in tandem with the other changes, but is hard to reconcile with the retail handling while also being very minor and unlikely to break anything.