Skip to content

Commit 622ae3e

Browse files
authored
Fix some bugs with maneuvers (#4483)
* split ai_control_info_check and player-not-use-ai wipes maneuvers * remove redundant flag upkeep and clarify logic
1 parent a246ef2 commit 622ae3e

File tree

4 files changed

+45
-30
lines changed

4 files changed

+45
-30
lines changed

code/ai/aicode.cpp

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14710,7 +14710,8 @@ void ai_frame(int objnum)
1471014710
}
1471114711
}
1471214712

14713-
static void ai_control_info_check(ai_info *aip, ship_info *sip, physics_info *pi)
14713+
// set and removes any maneuver flags for ai maneuver overrides
14714+
static void ai_control_info_flags_upkeep(ai_info* aip, ship_info* sip, physics_info* pi)
1471414715
{
1471514716
if (aip->ai_override_flags.none_set())
1471614717
return;
@@ -14741,6 +14742,37 @@ static void ai_control_info_check(ai_info *aip, ship_info *sip, physics_info *pi
1474114742
}
1474214743
else
1474314744
{
14745+
if (aip->ai_override_flags[AI::Maneuver_Override_Flags::Dont_bank_when_turning] || sip->flags[Ship::Info_Flags::Dont_bank_when_turning])
14746+
AI_ci.control_flags |= CIF_DONT_BANK_WHEN_TURNING;
14747+
if (aip->ai_override_flags[AI::Maneuver_Override_Flags::Dont_clamp_max_velocity] || sip->flags[Ship::Info_Flags::Dont_clamp_max_velocity])
14748+
AI_ci.control_flags |= CIF_DONT_CLAMP_MAX_VELOCITY;
14749+
if (aip->ai_override_flags[AI::Maneuver_Override_Flags::Instantaneous_acceleration] || sip->flags[Ship::Info_Flags::Instantaneous_acceleration])
14750+
AI_ci.control_flags |= CIF_INSTANTANEOUS_ACCELERATION;
14751+
}
14752+
14753+
// set physics flag according to whether we are instantaneously accelerating
14754+
if (AI_ci.control_flags & CIF_INSTANTANEOUS_ACCELERATION)
14755+
pi->flags |= PF_MANEUVER_NO_DAMP;
14756+
else
14757+
pi->flags &= ~PF_MANEUVER_NO_DAMP;
14758+
}
14759+
14760+
// applies any rotational or lateral maneuver values to the AI's CI
14761+
static void ai_control_info_apply(ai_info *aip)
14762+
{
14763+
if (aip->ai_override_flags.none_set())
14764+
return;
14765+
14766+
bool lateral_maneuver = false;
14767+
bool rotational_maneuver = false;
14768+
14769+
if (aip->ai_override_flags[AI::Maneuver_Override_Flags::Lateral_never_expire] || !timestamp_elapsed(aip->ai_override_lat_timestamp))
14770+
lateral_maneuver = true;
14771+
14772+
if (aip->ai_override_flags[AI::Maneuver_Override_Flags::Rotational_never_expire] || timestamp_elapsed(aip->ai_override_rot_timestamp))
14773+
rotational_maneuver = true;
14774+
14775+
if (lateral_maneuver || rotational_maneuver) {
1474414776
if (aip->ai_override_flags[AI::Maneuver_Override_Flags::Full_rot])
1474514777
{
1474614778
AI_ci.pitch = aip->ai_override_ci.pitch;
@@ -14750,17 +14782,11 @@ static void ai_control_info_check(ai_info *aip, ship_info *sip, physics_info *pi
1475014782
else
1475114783
{
1475214784
if (aip->ai_override_flags[AI::Maneuver_Override_Flags::Pitch])
14753-
{
1475414785
AI_ci.pitch = aip->ai_override_ci.pitch;
14755-
}
1475614786
if (aip->ai_override_flags[AI::Maneuver_Override_Flags::Heading])
14757-
{
1475814787
AI_ci.heading = aip->ai_override_ci.heading;
14759-
}
1476014788
if (aip->ai_override_flags[AI::Maneuver_Override_Flags::Roll])
14761-
{
1476214789
AI_ci.bank = aip->ai_override_ci.bank;
14763-
}
1476414790
}
1476514791

1476614792
if (aip->ai_override_flags[AI::Maneuver_Override_Flags::Full_lat])
@@ -14772,32 +14798,13 @@ static void ai_control_info_check(ai_info *aip, ship_info *sip, physics_info *pi
1477214798
else
1477314799
{
1477414800
if (aip->ai_override_flags[AI::Maneuver_Override_Flags::Up])
14775-
{
1477614801
AI_ci.vertical = aip->ai_override_ci.vertical;
14777-
}
1477814802
if (aip->ai_override_flags[AI::Maneuver_Override_Flags::Sideways])
14779-
{
1478014803
AI_ci.sideways = aip->ai_override_ci.sideways;
14781-
}
1478214804
if (aip->ai_override_flags[AI::Maneuver_Override_Flags::Forward])
14783-
{
1478414805
AI_ci.forward = aip->ai_override_ci.forward;
14785-
}
1478614806
}
14787-
14788-
if (aip->ai_override_flags[AI::Maneuver_Override_Flags::Dont_bank_when_turning] || sip->flags[Ship::Info_Flags::Dont_bank_when_turning])
14789-
AI_ci.control_flags |= CIF_DONT_BANK_WHEN_TURNING;
14790-
if (aip->ai_override_flags[AI::Maneuver_Override_Flags::Dont_clamp_max_velocity] || sip->flags[Ship::Info_Flags::Dont_clamp_max_velocity])
14791-
AI_ci.control_flags |= CIF_DONT_CLAMP_MAX_VELOCITY;
14792-
if (aip->ai_override_flags[AI::Maneuver_Override_Flags::Instantaneous_acceleration] || sip->flags[Ship::Info_Flags::Instantaneous_acceleration])
14793-
AI_ci.control_flags |= CIF_INSTANTANEOUS_ACCELERATION;
1479414807
}
14795-
14796-
// set physics flag according to whether we are instantaneously accelerating
14797-
if (AI_ci.control_flags & CIF_INSTANTANEOUS_ACCELERATION)
14798-
pi->flags |= PF_NO_DAMP;
14799-
else
14800-
pi->flags &= ~PF_NO_DAMP;
1480114808
}
1480214809

1480314810
int Last_ai_obj = -1;
@@ -14857,9 +14864,12 @@ void ai_process( object * obj, int ai_index, float frametime )
1485714864
if (shipp->flags[Ship::Ship_Flags::Dying] && sip->flags[Ship::Info_Flags::Large_ship_deathroll])
1485814865
rfc = false;
1485914866

14867+
// regardless if we're acting on them, upkeep maneuver flags
14868+
ai_control_info_flags_upkeep(aip, sip, &obj->phys_info);
14869+
1486014870
if (rfc) {
1486114871
// Wanderer - sexp based override goes here - only if rfc is valid though
14862-
ai_control_info_check(aip, sip, &obj->phys_info);
14872+
ai_control_info_apply(aip);
1486314873
physics_read_flying_controls( &obj->orient, &obj->phys_info, &AI_ci, frametime);
1486414874
}
1486514875

code/parse/sexp.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12208,6 +12208,11 @@ void multi_sexp_hud_display_gauge()
1220812208
void sexp_player_use_ai(int flag)
1220912209
{
1221012210
Player_use_ai = flag ? 1 : 0;
12211+
12212+
if (!flag) {
12213+
Player_ai->ai_override_flags.reset();
12214+
Player_obj->phys_info.flags &= ~PF_MANEUVER_NO_DAMP;
12215+
}
1221112216
}
1221212217

1221312218
// Karajorma

code/physics/physics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ void physics_sim_rot(matrix * orient, physics_info * pi, float sim_time )
168168
shock_amplitude = pi->shockwave_shake_amp * shock_fraction_time_left;
169169
}
170170
}
171-
else if (pi->flags & PF_NO_DAMP) {
171+
else if (pi->flags & PF_MANEUVER_NO_DAMP) {
172172
rotdamp = 0.0f;
173173
}
174174
else {
@@ -305,7 +305,7 @@ void physics_sim_vel(vec3d * position, physics_info * pi, float sim_time, matrix
305305
}
306306
}
307307
// no damping at all
308-
else if (pi->flags & PF_NO_DAMP) {
308+
else if (pi->flags & PF_MANEUVER_NO_DAMP) {
309309
damp = vmd_zero_vector;
310310
}
311311
// newtonian

code/physics/physics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#define PF_GLIDING (1 << 14)
3333
#define PF_FORCE_GLIDE (1 << 15)
3434
#define PF_NEWTONIAN_DAMP (1 << 16) // SUSHI: Whether or not to use newtonian dampening
35-
#define PF_NO_DAMP (1 << 17) // Goober5000 - don't damp velocity changes in physics; used for instantaneous acceleration
35+
#define PF_MANEUVER_NO_DAMP (1 << 17) // Goober5000 - don't damp velocity changes in physics; used for instantaneous acceleration
3636

3737
//information for physics sim for an object
3838
typedef struct physics_info {

0 commit comments

Comments
 (0)