-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix ai behavior when avoiding ship and weapon shockwaves #6378
base: master
Are you sure you want to change the base?
fix ai behavior when avoiding ship and weapon shockwaves #6378
Conversation
b9beefe
to
4e0419d
Compare
4e0419d
to
73cff97
Compare
mc.p1 = &expected_pos; // Point 2 of ray to check | ||
mc.flags = MC_CHECK_MODEL; | ||
|
||
model_collide(&mc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm loathe to add more collision checks unless absolutely necessary, especially since this appears to be called every frame for a thing which is in the average case unlikely to move much (and also this case doesn't need tons of accuracy, some approximation/lag should be fine), so at the very least the result should probably be cached.
Alternatively, have you considered just using the weapon's homing_pos
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a fair point, and I had the same reluctance, but I ended up adding it after seeing how many collision checks were used elsewhere in the code, and due to the difficulty of solving this problem without a collision check. I'm certainly open to suggestions though. And I could cache the result, at the cost of adding some additional fields to ai_info
.
The weapon's homing_pos
will work if the missile is homing on a subsystem, but will not work if the weapon is homing on the actual ship, since the position will be at the center of the ship.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a large ship, the homing_pos
shouldn't be the center of the ship, see the usage of ai_big_pick_attack_point
in weapon_home
. They tend to spread themselves over the hull surface on the side facing the missile.
@@ -14682,12 +14705,13 @@ int aas_1(object *objp, ai_info *aip, vec3d *safe_pos) | |||
Assert(aip->shockwave_object > -1); | |||
object *ship_objp = &Objects[aip->shockwave_object]; | |||
if (ship_objp == objp) { | |||
aip->shockwave_object = -1; | |||
aip->shockwave_object = -1; // this one was already present in retail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some additional weapon cases above which also return 0, but don't seem to reset shockwave_object
, should those be updated as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shockwave_object
field should be reset when, and only when, an Avoid_shockwave_
flag is removed, not necessarily when the function returns 0.
There is of course the interesting // See if too far away to care about shockwave.
case which returns 0 but does not remove the flag, as the flag is commented out -- even though the equivalent distance case for ship shockwaves removes the flag. The fact that the line is commented out makes me think Volition had a good reason for not clearing the flag. I'll give that another test. There's always the possibility of another separate AI profiles flag for that specific line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I'm fine with whatever you go with, I figured I'd bring it up.
73cff97
to
869596d
Compare
7eac144
to
3b79162
Compare
The FreeSpace AI includes behavior to run away from shockwaves to try to avoid explosion damage. This is implemented for both ships and missiles, although the missile implementation has been buggy ever since retail. There are several issues: 1. The AI attempts to evade a weapon immediately upon launch. Many missiles have a period of free flight before they start homing on their target. During the free flight period, the homing position is not set. Consequently, the AI will not know the position to avoid and will make assumptions. 2. The AI assumes the shockwave-producing weapon will detonate at the center of the ship it is targeting, although missiles detonate on the surface. A capital ship is likely to be significantly larger than the weapon's blast radius, leading the AI to believe the detonation will be much farther away than it actually is. 3. When avoiding ship shockwaves, the `shockwave_object` field is not cleared when avoiding is complete. This can result in stale references (though not crashes, due to object type checks), causing AI to not avoid future explosions in certain cases. 4. When avoiding ship shockwaves, the code does not check the correct ship for the amount of damage caused by the shockwave. All of these issues are now fixed. Since this is a change in AI behavior, these fixes are tied to a new AI profiles flag.
3b79162
to
7f788a9
Compare
The FreeSpace AI includes behavior to run away from shockwaves to try to avoid explosion damage. This is implemented for both ships and missiles, although the missile implementation has been buggy ever since retail. There are several issues:
shockwave_object
field is not cleared when avoiding is complete. This can result in stale references (though not crashes, due to object type checks), causing AI to not avoid future explosions in certain cases.All of these issues are now fixed. Since this is a change in AI behavior, these fixes are tied to a new AI profiles flag.
Already tested, but in draft pending additional tests.Tested with both ship and weapon shockwaves.