Skip to content
Draft
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 @@ -627,7 +627,7 @@ void ai_announce_ship_dying(object *dying_objp);
void ai_process_subobjects(int objnum);

//SUSHI: Setting ai_info stuff from both ai class and ai profile
void init_aip_from_class_and_profile(ai_info *aip, ai_class *aicp, ai_profile_t *profile);
void init_aip_from_class_and_profile(ai_info *aip, ai_class *aicp, const ai_profile_t *profile);

void ai_update_aim(ai_info *aip);

Expand Down
5 changes: 5 additions & 0 deletions code/ai/ai_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ namespace AI {
Fix_small_ai_recover_after_engines_repaired, // ensure small ship AI can switch back to useful AI modes if engines get repaired
Fix_model_path_refresh_randomization, // a subsystem path keeps its randomized point when the path is refreshed because the target moved
Fix_bay_speed_ramp, // the fighterbay speed ramp covers only the bay path itself, not points that route a departing ship around the carrier, and never exceeds max speed
Consistent_dinky_shockwaves, // any shot-down weapon (including area-effect weapons and beam kills) uses its dinky shockwave; huge ships take full damage only if the dinky damage is defaulted

// internal flags set by mission_apply_era_adjustments(); not parsed from tables, and only consulted when Consistent_dinky_shockwaves is off
Era_reduce_shot_down_area_effects, // a shot-down weapon without a shockwave has its area damage multiplied like a shockwave would be
Era_beam_kills_count_as_shot_down, // a weapon destroyed by a beam uses its dinky shockwave

NUM_VALUES
};
Expand Down
32 changes: 16 additions & 16 deletions code/ai/ai_profiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@


// global stuff
int Num_ai_profiles;
int Default_ai_profile;
ai_profile_t Ai_profiles[MAX_AI_PROFILES];
SCP_vector<ai_profile_t> Ai_profiles;

// local to this file
static int Ai_profiles_initted = 0;
Expand All @@ -36,6 +35,7 @@ void set_flag(ai_profile_t *profile, const char *name, AI::Profile_Flags flag)
bool val;
stuff_boolean(&val);
profile->flags.set(flag, val);
profile->explicit_flags.set(flag);
}
}

Expand Down Expand Up @@ -116,7 +116,7 @@ void parse_ai_profiles_tbl(const char *filename)
stuff_string(profile_name, F_NAME, NAME_LENGTH);

// see if it exists
for (i = 0; i < Num_ai_profiles; i++)
for (i = 0; i < sz2i(Ai_profiles.size()); i++)
{
if (!stricmp(Ai_profiles[i].profile_name, profile_name))
{
Expand Down Expand Up @@ -144,24 +144,16 @@ void parse_ai_profiles_tbl(const char *filename)
}
else
{
// make sure we're under the limit
if (Num_ai_profiles >= MAX_AI_PROFILES)
{
Warning(LOCATION, "Too many profiles in ai_profiles.tbl! Max is %d.\n", MAX_AI_PROFILES - 1); // -1 because one is built-in
skip_to_string("#End", NULL);
break;
}

profile = &Ai_profiles[Num_ai_profiles];
Num_ai_profiles++;
Ai_profiles.emplace_back();
profile = &Ai_profiles.back();
}
}

// initialize profile if we're not building from a previously parsed one
if (!no_create)
{
// base profile, so zero it out
if (profile == &Ai_profiles[0])
if (profile == &Ai_profiles.front())
{
profile->reset();
}
Expand Down Expand Up @@ -771,6 +763,8 @@ void parse_ai_profiles_tbl(const char *filename)

set_flag(profile, "$fix fighterbay speed ramp:", AI::Profile_Flags::Fix_bay_speed_ramp);

set_flag(profile, "$consistent dinky shockwaves:", AI::Profile_Flags::Consistent_dinky_shockwaves);

// end of options ----------------------------------------

// if we've been through once already and are at the same place, force a move
Expand Down Expand Up @@ -807,7 +801,7 @@ void ai_profiles_init()
if (Ai_profiles_initted)
return;

Num_ai_profiles = 0;
Ai_profiles.clear();
Default_ai_profile = 0;
Default_profile_name[0] = '\0';

Expand Down Expand Up @@ -840,7 +834,7 @@ void ai_profiles_init()

int ai_profile_lookup(const char *name)
{
for (int i = 0; i < Num_ai_profiles; i++)
for (int i = 0; i < sz2i(Ai_profiles.size()); i++)
if (!stricmp(name, Ai_profiles[i].profile_name))
return i;

Expand All @@ -852,6 +846,7 @@ void ai_profile_t::reset()
memset(profile_name, 0, sizeof(profile_name));

flags.reset();
explicit_flags.reset();

los_min_detection_radius = 10.0f;
ai_path_mode = AI_PATH_MODE_NORMAL;
Expand Down Expand Up @@ -879,6 +874,8 @@ void ai_profile_t::reset()

default_form_on_wing_priority = 99; // as originally assigned in ai_add_goal_sub_sexp()

dinky_shockwave_multiplier = Dinky_shockwave_default_multiplier;

for (int i = 0; i < NUM_SKILL_LEVELS; ++i) {
max_incoming_asteroids[i] = 0;
max_allowed_player_homers[i] = 0;
Expand Down Expand Up @@ -1008,4 +1005,7 @@ void ai_profile_t::reset()
flags.set(AI::Profile_Flags::Fix_model_path_refresh_randomization);
flags.set(AI::Profile_Flags::Fix_bay_speed_ramp);
}
if (mod_supports_version(27, 0, 0)) {
flags.set(AI::Profile_Flags::Consistent_dinky_shockwaves);
}
}
10 changes: 4 additions & 6 deletions code/ai/ai_profiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@

#define AI_RANGE_AWARE_SEC_SEL_MODE_RETAIL 0
#define AI_RANGE_AWARE_SEC_SEL_MODE_AWARE 1

#define MAX_AI_PROFILES 8

class ai_profile_t {
public:
char profile_name[NAME_LENGTH];

flagset<AI::Profile_Flags> flags;
flagset<AI::Profile_Flags> explicit_flags; // flags that a table specified, whether true or false

// difficulty-related values
int max_incoming_asteroids[NUM_SKILL_LEVELS]; // max number of asteroids thrown at friendlies
Expand Down Expand Up @@ -155,15 +154,14 @@ class ai_profile_t {

int default_form_on_wing_priority; // the priority used if not specified in the sexp

float dinky_shockwave_multiplier; // damage multiplier for a dinky shockwave that doesn't specify its own damage

void reset();
};


extern int Num_ai_profiles;
extern int Default_ai_profile;
extern ai_profile_t Ai_profiles[MAX_AI_PROFILES];

#define AI_PROFILES_INDEX(ai_p) (static_cast<int>((ai_p)-Ai_profiles))
extern SCP_vector<ai_profile_t> Ai_profiles;

void ai_profiles_init();

Expand Down
32 changes: 16 additions & 16 deletions code/ai/aibig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ bool ai_big_maybe_follow_subsys_path(bool do_dot_check)
}
}
// 2. use radii value in ai_profiles table if specified and no valid point found
if (!found_point && The_mission.ai_profile->subsystem_path_radii) {
aip->path_goal_dist = The_mission.ai_profile->subsystem_path_radii;
if (!found_point && The_mission.ai_profile()->subsystem_path_radii) {
aip->path_goal_dist = The_mission.ai_profile()->subsystem_path_radii;
}
// 3. use default radii value if no valid point or specified radii
else {
Expand Down Expand Up @@ -725,8 +725,8 @@ void ai_big_chase_attack(ai_info *aip, ship_info *sip, vec3d *enemy_pos, float d
// if moving slowly and attacking a large ship,
// check if need to enter standard strafe mode
// including ai_profile flag and if enemy fighters are near
if (Pl_objp->phys_info.speed < The_mission.ai_profile->standard_strafe_when_below_speed &&
(The_mission.ai_profile->flags[AI::Profile_Flags::Standard_strafe_used_more] || ai_big_maybe_start_strafe(aip, sip))) {
if (Pl_objp->phys_info.speed < The_mission.ai_profile()->standard_strafe_when_below_speed &&
(The_mission.ai_profile()->flags[AI::Profile_Flags::Standard_strafe_used_more] || ai_big_maybe_start_strafe(aip, sip))) {
aip->previous_mode = aip->mode;
aip->mode = AIM_STRAFE;
aip->submode_parm0 = Missiontime; // use parm0 as time strafe mode entered (i.e. MODE start time)
Expand Down Expand Up @@ -1108,7 +1108,7 @@ void ai_big_chase()
} else if (En_objp->flags[Object::Object_Flags::Protected]) { // If protected and we're not attacking a subsystem, stop attacking!
update_aspect_lock_information(aip, &vec_to_enemy, dist_to_enemy - En_objp->radius, En_objp->radius);
aip->target_objnum = -1;
if (find_enemy(OBJ_INDEX(Pl_objp), MAX_ENEMY_DISTANCE, The_mission.ai_profile->max_attackers[Game_skill_level]) == -1) {
if (find_enemy(OBJ_INDEX(Pl_objp), MAX_ENEMY_DISTANCE, The_mission.ai_profile()->max_attackers[Game_skill_level]) == -1) {
ai_do_default_behavior(Pl_objp);
return;
}
Expand Down Expand Up @@ -1195,7 +1195,7 @@ void ai_big_chase()
}

// If a collision is expected, pull out!
if (!(The_mission.ai_profile->flags[AI::Profile_Flags::Kamikaze_no_collision_avoidance] && aip->ai_flags[AI::AI_Flags::Kamikaze])) {
if (!(The_mission.ai_profile()->flags[AI::Profile_Flags::Kamikaze_no_collision_avoidance] && aip->ai_flags[AI::AI_Flags::Kamikaze])) {

float dist_normal_to_enemy;

Expand Down Expand Up @@ -1403,7 +1403,7 @@ void ai_big_attack_get_data(vec3d *enemy_pos, float *dist_to_enemy, float *dot_t
float weapon_speed;

// Compute position of gun in absolute space and use that as fire position.
if (po->n_guns > 0 && !(The_mission.ai_profile->flags[AI::Profile_Flags::Ai_aims_from_ship_center])) {
if (po->n_guns > 0 && !(The_mission.ai_profile()->flags[AI::Profile_Flags::Ai_aims_from_ship_center])) {
pnt = po->gun_banks[0].pnt[0];
vm_vec_unrotate(&gun_pos, &pnt, &Pl_objp->orient);
vm_vec_add2(&gun_pos, &Pl_objp->pos);
Expand Down Expand Up @@ -1440,7 +1440,7 @@ static bool ai_big_strafe_maybe_retreat(const vec3d *target_pos)

bool collide_time;
bool collide_distance;
if (The_mission.ai_profile->flags[AI::Profile_Flags::Fix_standard_strafe]) {
if (The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_standard_strafe]) {
// check if ship facing target, as likely will only collide if facing
vec3d vec_to_tpos;
vm_vec_normalized_dir(&vec_to_tpos, target_pos, &Pl_objp->pos);
Expand All @@ -1449,8 +1449,8 @@ static bool ai_big_strafe_maybe_retreat(const vec3d *target_pos)
collide_time = false;
collide_distance = false;
} else {
collide_time = (Pl_objp->phys_info.speed > 0.0f) && (dist_to_target / Pl_objp->phys_info.speed) < (The_mission.ai_profile->strafe_retreat_collide_time);
collide_distance = dist_to_target < ((The_mission.ai_profile->strafe_retreat_collide_distance) + speed_to_dist_penalty);
collide_time = (Pl_objp->phys_info.speed > 0.0f) && (dist_to_target / Pl_objp->phys_info.speed) < (The_mission.ai_profile()->strafe_retreat_collide_time);
collide_distance = dist_to_target < ((The_mission.ai_profile()->strafe_retreat_collide_distance) + speed_to_dist_penalty);
}
} else {
float dist_normal_to_target;
Expand All @@ -1460,8 +1460,8 @@ static bool ai_big_strafe_maybe_retreat(const vec3d *target_pos)
} else {
dist_normal_to_target = 0.2f * dist_to_target;
}
collide_time = (Pl_objp->phys_info.speed > 0.0f) && (dist_normal_to_target / Pl_objp->phys_info.speed) < (The_mission.ai_profile->strafe_retreat_collide_time);
collide_distance = dist_normal_to_target < ((The_mission.ai_profile->strafe_retreat_collide_distance) + speed_to_dist_penalty);
collide_time = (Pl_objp->phys_info.speed > 0.0f) && (dist_normal_to_target / Pl_objp->phys_info.speed) < (The_mission.ai_profile()->strafe_retreat_collide_time);
collide_distance = dist_normal_to_target < ((The_mission.ai_profile()->strafe_retreat_collide_distance) + speed_to_dist_penalty);
}

//if ((dot_to_enemy > 1.0f - 0.1f * En_objp->radius/(dist_to_enemy + 1.0f)) && (Pl_objp->phys_info.speed > dist_to_enemy/5.0f))
Expand All @@ -1480,7 +1480,7 @@ static bool ai_big_strafe_maybe_retreat(const vec3d *target_pos)

int is_inside;
vec3d goal_point;
get_world_closest_box_point_with_delta(&goal_point, En_objp, &Pl_objp->pos, &is_inside, The_mission.ai_profile->strafe_retreat_box_dist);
get_world_closest_box_point_with_delta(&goal_point, En_objp, &Pl_objp->pos, &is_inside, The_mission.ai_profile()->strafe_retreat_box_dist);

// set goal point
aip->goal_point = goal_point;
Expand Down Expand Up @@ -1595,7 +1595,7 @@ void ai_big_strafe_attack()
accelerate_ship(aip, accel);

// if haven't been hit in quite a while, leave strafe mode
fix long_enough = fl2f(The_mission.ai_profile->strafe_max_unhit_time);
fix long_enough = fl2f(The_mission.ai_profile()->strafe_max_unhit_time);
if ( (last_hit > long_enough) && ( (Missiontime - aip->submode_parm0) > long_enough) ) {
ai_big_switch_to_chase_mode(aip);
}
Expand Down Expand Up @@ -1667,7 +1667,7 @@ void ai_big_strafe_glide_attack()
//Keep going until we are too far away.
//If we are still on approach but too far away, this will still trigger. This will allow us to reposition the target
//point and allow for a "jinking" effect.
if (target_ship_dist > (The_mission.ai_profile->strafe_retreat_box_dist + target_objp->radius) &&
if (target_ship_dist > (The_mission.ai_profile()->strafe_retreat_box_dist + target_objp->radius) &&
Missiontime - aip->submode_start_time > i2f(GLIDE_STRAFE_MIN_TIME)) {
//This checks whether we are moving toward the target or away from it. If moving towards, we reset the stage so that we
//pick a new attack vector (jinking). If moving away, we're at the end of a run so do a full reset (possibly allowing a
Expand Down Expand Up @@ -1717,7 +1717,7 @@ void ai_big_strafe_glide_attack()

// if haven't been hit in quite a while, leave strafe mode
// (same as ai_big_strafe_attack)
fix long_enough = fl2f(The_mission.ai_profile->strafe_max_unhit_time);
fix long_enough = fl2f(The_mission.ai_profile()->strafe_max_unhit_time);
if ( (Missiontime - aip->last_hit_time > long_enough) && ( (Missiontime - aip->submode_parm0) > long_enough) ) {
ai_big_switch_to_chase_mode(aip);
}
Expand Down
Loading
Loading