Skip to content

One fix and one enhancement to AI shield behavior #6737

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

Merged
merged 4 commits into from
May 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/ai/ai.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ typedef struct ai_info {
float time_enemy_near; // SUSHI: amount of time enemy continuously "near" the player
fix last_attack_time; // Missiontime of last time this ship attacked its enemy.
fix last_hit_time; // Missiontime of last time this ship was hit by anyone.
int last_hit_quadrant; // Shield section of last hit.
int danger_shield_quadrant; // Shield section AI will prefer to prioritize for recharging, it if possible.
fix last_hit_target_time; // Missiontime of last time this ship successfully hit target.
int hitter_objnum; // Object index of ship that hit this ship last time.
int hitter_signature; // Signature of hitter. Prevents stupidity if hitter gets killed.
Expand Down
2 changes: 2 additions & 0 deletions code/ai/ai_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ namespace AI {
Guards_ignore_protected_attackers,
Standard_strafe_used_more,
Unify_usage_ai_shield_manage_delay,
Fix_AI_shield_management_bug,
AI_balances_shields_when_attacked,
Disable_ai_transferring_energy,
Freespace_1_missile_behavior,
ETS_uses_power_output,
Expand Down
4 changes: 4 additions & 0 deletions code/ai/ai_profiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,10 @@ void parse_ai_profiles_tbl(const char *filename)

set_flag(profile, "$unify usage of AI Shield Manage Delay:", AI::Profile_Flags::Unify_usage_ai_shield_manage_delay);

set_flag(profile, "$fix AI shield management bug:", AI::Profile_Flags::Fix_AI_shield_management_bug);

set_flag(profile, "$AI balances shields instead of directs when attacked:", AI::Profile_Flags::AI_balances_shields_when_attacked);

set_flag(profile, "$disable AI transferring energy:", AI::Profile_Flags::Disable_ai_transferring_energy);

set_flag(profile, "$enable freespace 1 style missile behavior:", AI::Profile_Flags::Freespace_1_missile_behavior);
Expand Down
8 changes: 5 additions & 3 deletions code/ai/aicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,8 @@ void parse_ai_class()
set_aic_flag(aicp, "$use actual primary range:", AI::Profile_Flags::Use_actual_primary_range);

set_aic_flag(aicp, "$firing requires exact los:", AI::Profile_Flags::Require_exact_los);

set_aic_flag(aicp, "$AI balances shields instead of directs when attacked:", AI::Profile_Flags::AI_balances_shields_when_attacked);
}

void reset_ai_class_names()
Expand Down Expand Up @@ -13320,8 +13322,8 @@ void ai_manage_shield(object *objp, ai_info *aip)
aip->shield_manage_timestamp = timestamp((int) (delay * 1000.0f));

if (sip->is_small_ship() || (aip->ai_profile_flags[AI::Profile_Flags::All_ships_manage_shields])) {
if (Missiontime - aip->last_hit_time < F1_0*10)
ai_transfer_shield(objp, aip->last_hit_quadrant);
if ((Missiontime - aip->last_hit_time < F1_0 * 10) && !((aip->ai_profile_flags[AI::Profile_Flags::AI_balances_shields_when_attacked])))
ai_transfer_shield(objp, aip->danger_shield_quadrant);
else
ai_balance_shield(objp);
}
Expand Down Expand Up @@ -15559,7 +15561,7 @@ void init_ai_object(int objnum)
aip->time_enemy_near = 0.0f;
aip->last_attack_time = 0;
aip->last_hit_time = 0;
aip->last_hit_quadrant = 0;
aip->danger_shield_quadrant = 0;
aip->hitter_objnum = -1;
aip->hitter_signature = -1;
aip->resume_goal_time = -1;
Expand Down
6 changes: 6 additions & 0 deletions code/object/collideshipweapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,12 @@ static int ship_weapon_check_collision(object *ship_objp, object *weapon_objp, f

// make sure that the shield is active in that quadrant
if (shipp->flags[Ship::Ship_Flags::Dying] || !ship_is_shield_up(ship_objp, quadrant_num)) {
// if the shield is down in the quadrant we still want the AI to record that the shield was hit here
// so that the AI can put energy torwards repairing that shield segement (but put behind a flag)
// --wookieejedi
if (The_mission.ai_profile->flags[AI::Profile_Flags::Fix_AI_shield_management_bug] && SCP_vector_inbounds(ship_objp->shield_quadrant, quadrant_num)) {
Ai_info[Ships[ship_objp->instance].ai_index].danger_shield_quadrant = quadrant_num;
}
quadrant_num = -1;
shield_collision = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion code/object/objectshield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ float shield_apply_damage(object *objp, int quadrant_num, float damage)

if (objp->type != OBJ_SHIP && objp->type != OBJ_START)
return damage;
Ai_info[Ships[objp->instance].ai_index].last_hit_quadrant = quadrant_num;
Ai_info[Ships[objp->instance].ai_index].danger_shield_quadrant = quadrant_num;

remaining_damage = damage - objp->shield_quadrant[quadrant_num];
if (remaining_damage > 0.0f) {
Expand Down
Loading