diff --git a/code/ai/ai.h b/code/ai/ai.h index 5e43d79ccce..4e853ee6095 100644 --- a/code/ai/ai.h +++ b/code/ai/ai.h @@ -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); diff --git a/code/ai/ai_flags.h b/code/ai/ai_flags.h index 42a54b4f959..1b1d43b971c 100644 --- a/code/ai/ai_flags.h +++ b/code/ai/ai_flags.h @@ -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 }; diff --git a/code/ai/ai_profiles.cpp b/code/ai/ai_profiles.cpp index 07c5dbe0487..7e918e9c717 100644 --- a/code/ai/ai_profiles.cpp +++ b/code/ai/ai_profiles.cpp @@ -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_profiles; // local to this file static int Ai_profiles_initted = 0; @@ -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); } } @@ -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)) { @@ -144,16 +144,8 @@ 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(); } } @@ -161,7 +153,7 @@ void parse_ai_profiles_tbl(const char *filename) if (!no_create) { // base profile, so zero it out - if (profile == &Ai_profiles[0]) + if (profile == &Ai_profiles.front()) { profile->reset(); } @@ -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 @@ -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'; @@ -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; @@ -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; @@ -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; @@ -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); + } } diff --git a/code/ai/ai_profiles.h b/code/ai/ai_profiles.h index 88f66d354bd..89aba300a4d 100644 --- a/code/ai/ai_profiles.h +++ b/code/ai/ai_profiles.h @@ -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 flags; + flagset 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 @@ -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((ai_p)-Ai_profiles)) +extern SCP_vector Ai_profiles; void ai_profiles_init(); diff --git a/code/ai/aibig.cpp b/code/ai/aibig.cpp index 8b1cae84623..907d0cbe279 100644 --- a/code/ai/aibig.cpp +++ b/code/ai/aibig.cpp @@ -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 { @@ -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) @@ -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; } @@ -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; @@ -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); @@ -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); @@ -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; @@ -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)) @@ -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; @@ -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); } @@ -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 @@ -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); } diff --git a/code/ai/aicode.cpp b/code/ai/aicode.cpp index ef949fe97dd..ac0ade4dc7e 100644 --- a/code/ai/aicode.cpp +++ b/code/ai/aicode.cpp @@ -382,7 +382,7 @@ bool ai_good_time_to_rearm(object *objp) Assert(objp->type == OBJ_SHIP); team = Ships[objp->instance].team; - if (The_mission.ai_profile->flags[AI::Profile_Flags::Fix_good_rearm_time_bug]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_good_rearm_time_bug]) return Iff_info[team].ai_good_rearm_timestamp.isValid() && !timestamp_elapsed(Iff_info[team].ai_good_rearm_timestamp); else return Iff_info[team].ai_good_rearm_timestamp.isValid(); @@ -636,7 +636,7 @@ int ai_get_autoscale_index(int absolute_index) int ai_maybe_autoscale(int absolute_index) { - if (The_mission.ai_profile->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale]) return ai_get_autoscale_index(absolute_index); else return absolute_index; @@ -1381,7 +1381,7 @@ void ai_turn_towards_vector(const vec3d* dest, object* objp, const vec3d* slide_ vm_vec_zero(&vel_limit); // get the turn rate if we have Use_axial_turnrate_differences - if (objp->type == OBJ_SHIP && The_mission.ai_profile->flags[AI::Profile_Flags::Use_axial_turnrate_differences]) { + if (objp->type == OBJ_SHIP && The_mission.ai_profile()->flags[AI::Profile_Flags::Use_axial_turnrate_differences]) { vel_limit = Ship_info[Ships[objp->instance].ship_info_index].max_rotvel; } else { // else get the turn time @@ -1481,10 +1481,10 @@ void ai_turn_towards_vector(const vec3d* dest, object* objp, const vec3d* slide_ vm_vector_2_matrix_norm(&goal_orient, &desired_fvec, nullptr, rvec); vm_angular_move_matrix(&goal_orient, &curr_orient, &vel_in, delta_time, - &out_orient, &vel_out, &vel_limit, &acc_limit, The_mission.ai_profile->flags[AI::Profile_Flags::No_turning_directional_bias]); + &out_orient, &vel_out, &vel_limit, &acc_limit, The_mission.ai_profile()->flags[AI::Profile_Flags::No_turning_directional_bias]); } else { vm_angular_move_forward_vec(&desired_fvec, &curr_orient, &vel_in, delta_time, bank, - &out_orient, &vel_out, &vel_limit, &acc_limit, The_mission.ai_profile->flags[AI::Profile_Flags::No_turning_directional_bias]); + &out_orient, &vel_out, &vel_limit, &acc_limit, The_mission.ai_profile()->flags[AI::Profile_Flags::No_turning_directional_bias]); } if (Framerate_independent_turning) { @@ -1653,7 +1653,7 @@ void adjust_accel_for_docking(ai_info *aip) float ratio = objp->phys_info.mass / dock_calc_total_docked_mass(objp); // put cap on how much ship can slow down - if ( (ratio < 0.8f) && !(The_mission.ai_profile->flags[AI::Profile_Flags::No_min_dock_speed_cap]) ) { + if ( (ratio < 0.8f) && !(The_mission.ai_profile()->flags[AI::Profile_Flags::No_min_dock_speed_cap]) ) { ratio = 0.8f; } @@ -2094,7 +2094,7 @@ float get_wing_lowest_av_ab_speed(object *objp) } else { - recharge_scale = ets_power_factor(objp) * Energy_levels[shipp->engine_recharge_index] * 2.0f * The_mission.ai_profile->afterburner_recharge_scale[Game_skill_level]; + recharge_scale = ets_power_factor(objp) * Energy_levels[shipp->engine_recharge_index] * 2.0f * The_mission.ai_profile()->afterburner_recharge_scale[Game_skill_level]; recharge_scale = sip->afterburner_recover_rate * recharge_scale / (sip->afterburner_burn_rate + sip->afterburner_recover_rate * recharge_scale); lowest_max_av_ab_speed = recharge_scale * (objp->phys_info.afterburner_max_vel.xyz.z - objp->phys_info.max_vel.xyz.z) + objp->phys_info.max_vel.xyz.z; } @@ -2123,7 +2123,7 @@ float get_wing_lowest_av_ab_speed(object *objp) } else { - recharge_scale = ets_power_factor(o) * Energy_levels[oshipp->engine_recharge_index] * 2.0f * The_mission.ai_profile->afterburner_recharge_scale[Game_skill_level]; + recharge_scale = ets_power_factor(o) * Energy_levels[oshipp->engine_recharge_index] * 2.0f * The_mission.ai_profile()->afterburner_recharge_scale[Game_skill_level]; recharge_scale = osip->afterburner_recover_rate * recharge_scale / (osip->afterburner_burn_rate + osip->afterburner_recover_rate * recharge_scale); cur_max = recharge_scale * (o->phys_info.afterburner_max_vel.xyz.z - o->phys_info.max_vel.xyz.z) + o->phys_info.max_vel.xyz.z; } @@ -2282,7 +2282,7 @@ void evaluate_object_as_nearest_objnum(eval_nearest_objnum *eno) // Don't pick a target that this ship's type refuses to chase, or it will park in AIM_NONE holding a target it never attacks. // Only for unconstrained searches: an explicit chase-ship-class/type order should still produce a target even if ai_chase() doesn't chase it. - if (The_mission.ai_profile->flags[AI::Profile_Flags::Fix_ai_target_recovery] + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_ai_target_recovery] && eno->enemy_ship_info_index < 0 && eno->enemy_class_type < 0 && !ai_class_type_actively_pursues(eno->attacker_class_type, Ship_info[shipp->ship_info_index].class_type)) return; @@ -2552,7 +2552,7 @@ int find_enemy(int objnum, float range, int max_attackers, int ship_info_index, if (class_type < 0 || class_type == Ship_info[target_shipp->ship_info_index].class_type) { if (!(target_objp->flags[Object::Object_Flags::Protected])) { // same as get_nearest_objnum: only skip an unpursued target for unconstrained searches - if (!The_mission.ai_profile->flags[AI::Profile_Flags::Fix_ai_target_recovery] + if (!The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_ai_target_recovery] || ship_info_index >= 0 || class_type >= 0 || ai_class_type_actively_pursues(Ship_info[shipp->ship_info_index].class_type, Ship_info[target_shipp->ship_info_index].class_type)) { @@ -3687,7 +3687,7 @@ void ai_form_on_wing(object *objp, object *goal_objp) aip->ai_flags.set(AI::AI_Flags::Formation_object); // if this goal is going to stick around for a while, change the mode - if (The_mission.ai_profile->flags[AI::Profile_Flags::Do_not_clear_goals_when_running_form_on_wing]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Do_not_clear_goals_when_running_form_on_wing]) { aip->mode = AIM_NONE; aip->submode = -1; @@ -3858,7 +3858,7 @@ void ai_update_aim(ai_info *aip) // returns if the currently active goal trying to afterburn hard bool ai_willing_to_afterburn_hard(ai_info* aip) { return aip->active_goal == AI_ACTIVE_GOAL_DYNAMIC ? - The_mission.ai_profile->flags[AI::Profile_Flags::Dynamic_goals_afterburn_hard] : + The_mission.ai_profile()->flags[AI::Profile_Flags::Dynamic_goals_afterburn_hard] : (aip->active_goal > -1 && aip->goals[aip->active_goal].flags[AI::Goal_Flags::Afterburn_hard]); } @@ -3938,7 +3938,7 @@ void modify_model_path_points(object *objp) int count = aip->path_length - static_cast(pnp - &Path_points[aip->path_start]); int randomize_pnt = -1; - if (The_mission.ai_profile->flags[AI::Profile_Flags::Fix_model_path_refresh_randomization]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_model_path_refresh_randomization]) randomize_pnt = aip->mp_randomized_vert; copy_xlate_model_path_points(mobjp, &pm->paths[path_num], dir, count, path_num, pnp, randomize_pnt); @@ -4044,7 +4044,7 @@ void set_accel_for_docking(object *objp, ai_info *aip, float dot, float dot_to_n ai_afterburn_hard(Pl_objp, aip); } else { float max_bay_speed = sip->max_speed; - bool fix_bay_speed_ramp = The_mission.ai_profile->flags[AI::Profile_Flags::Fix_bay_speed_ramp]; + bool fix_bay_speed_ramp = The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_bay_speed_ramp]; ship_info *gsip = &Ship_info[Ships[gobjp->instance].ship_info_index]; polymodel *pm = model_get(gsip->model_num); @@ -4064,7 +4064,7 @@ void set_accel_for_docking(object *objp, ai_info *aip, float dot, float dot_to_n } if (speed_mult == FLT_MIN) { - speed_mult = The_mission.ai_profile->bay_arrive_speed_mult; + speed_mult = The_mission.ai_profile()->bay_arrive_speed_mult; } } else { // Departing if (gsip->pathMetadata.find(pathName) != gsip->pathMetadata.end()) { @@ -4072,7 +4072,7 @@ void set_accel_for_docking(object *objp, ai_info *aip, float dot, float dot_to_n } if (speed_mult == FLT_MIN) { - speed_mult = The_mission.ai_profile->bay_depart_speed_mult; + speed_mult = The_mission.ai_profile()->bay_depart_speed_mult; } } @@ -4503,7 +4503,7 @@ float ai_path_1_or_2(bool allow_path_shortcut) float ai_path() { - switch (The_mission.ai_profile->ai_path_mode) + switch (The_mission.ai_profile()->ai_path_mode) { case AI_PATH_MODE_NORMAL: return ai_path_0(); @@ -4515,7 +4515,7 @@ float ai_path() return ai_path_1_or_2(true); break; default: - Error(LOCATION, "Invalid path mode found: %d\n", The_mission.ai_profile->ai_path_mode); + Error(LOCATION, "Invalid path mode found: %d\n", The_mission.ai_profile()->ai_path_mode); return ai_path_0(); } } @@ -4612,7 +4612,7 @@ float ai_safety_goto_spot(object *objp) } else set_accel_for_target_speed(objp, sip->max_speed * dot_val * (dist/200.0f + 0.2f)); - if (The_mission.ai_profile->flags[AI::Profile_Flags::Fix_keep_safe_distance]) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_keep_safe_distance]) { // hey, let's try actually aiming toward our goal! turn_towards_point(objp, &aip->goal_point, nullptr, 0.0f); } @@ -4881,7 +4881,7 @@ void ai_fly_to_target_position(const vec3d* target_pos, bool* pl_done_p=NULL, bo max_allowed_speed = 0.9f * get_wing_lowest_max_speed(Pl_objp); max_allowed_ab_speed = 0.95f * get_wing_lowest_av_ab_speed(Pl_objp); if (ab_allowed) { - float self_ab_scale = ets_power_factor(Pl_objp) * Energy_levels[shipp->engine_recharge_index] * 2.0f * The_mission.ai_profile->afterburner_recharge_scale[Game_skill_level]; + float self_ab_scale = ets_power_factor(Pl_objp) * Energy_levels[shipp->engine_recharge_index] * 2.0f * The_mission.ai_profile()->afterburner_recharge_scale[Game_skill_level]; self_ab_scale = sip->afterburner_recover_rate * self_ab_scale / (sip->afterburner_burn_rate + sip->afterburner_recover_rate * self_ab_scale); self_ab_speed = 0.95f * (self_ab_scale * (Pl_objp->phys_info.afterburner_max_vel.xyz.z - Pl_objp->phys_info.max_vel.xyz.z) + Pl_objp->phys_info.max_vel.xyz.z); } @@ -4955,7 +4955,7 @@ void ai_fly_to_target_position(const vec3d* target_pos, bool* pl_done_p=NULL, bo // exactly the slow speeds at which a big ship could aim precisely. Together these could trap a // capital ship in an endless overshoot-turnaround-miss loop at its final waypoint. With the flag // set, big ships complete a waypoint anywhere within their own radius of it, and the check always runs. - bool fix_waypoint_completion = The_mission.ai_profile->flags[AI::Profile_Flags::Fix_big_ship_waypoint_completion]; + bool fix_waypoint_completion = The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_big_ship_waypoint_completion]; float waypoint_tolerance = MIN_DIST_TO_WAYPOINT_GOAL + ((fix_waypoint_completion && sip->is_big_or_huge()) ? Pl_objp->radius : fl_sqrt(Pl_objp->radius)); if ( fix_waypoint_completion || (dist_to_goal < MIN_DIST_TO_WAYPOINT_GOAL) || dist_to_cover_this_frame > 0.1f ) { @@ -5254,7 +5254,7 @@ int ai_maybe_fire_afterburner(object *objp, ai_info *aip) //If ai_aburn_use_factor is not specified, calculate a number based on the AI class. Otherwise, use that value. if (aip->ai_aburn_use_factor == INT_MIN) { - if (The_mission.ai_profile->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale]) { // Highest two levels always aburner away if (ai_get_autoscale_index(aip->ai_class) >= ai_get_autoscale_index(Num_ai_classes) - 2) @@ -5384,7 +5384,7 @@ void evade_weapon() int aburn_time = F1_0 / 2; // within 200m bad, within 1.5 seconds good - if (The_mission.ai_profile->flags[AI::Profile_Flags::Improved_missile_avoidance]) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Improved_missile_avoidance]) { should_afterburn = dist < weapon_objp->phys_info.speed * 1.5f; aburn_time = F1_0 + F1_0 / 2; } @@ -5400,7 +5400,7 @@ void evade_weapon() // Fancy (read: effective) dodging // Try to go perpindicular to the incoming missile, and pick the quickest direction to get there - if (The_mission.ai_profile->flags[AI::Profile_Flags::Improved_missile_avoidance]) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Improved_missile_avoidance]) { vec3d avoid_point; vm_project_point_onto_plane(&avoid_point, &vec_from_enemy, &Pl_objp->orient.vec.fvec, &vmd_zero_vector); vm_vec_normalize(&avoid_point); @@ -6102,7 +6102,7 @@ void set_primary_weapon_linkage(object *objp) } // Don't want all ships always linking weapons at start, so asynchronize. - if (!(The_mission.ai_profile->flags[AI::Profile_Flags::Allow_primary_link_at_start])) + if (!(The_mission.ai_profile()->flags[AI::Profile_Flags::Allow_primary_link_at_start])) { if (Missiontime < i2f(30)) return; @@ -6116,7 +6116,7 @@ void set_primary_weapon_linkage(object *objp) // get energy level float energy; - if (The_mission.ai_profile->flags[AI::Profile_Flags::Fix_linked_primary_bug]) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_linked_primary_bug]) { energy = shipp->weapon_energy / sip->max_weapon_reserve * 100.0f; } else { energy = shipp->weapon_energy; @@ -6367,9 +6367,9 @@ int ai_fire_primary_weapon(object *objp) //We can only check LoS if we have a target defined weapon_info* wip = &Weapon_info[swp->primary_bank_weapons[swp->current_primary_bank]]; - if (aip->target_objnum != -1 && (The_mission.ai_profile->flags[AI::Profile_Flags::Require_exact_los] || wip->wi_flags[Weapon::Info_Flags::Require_exact_los])) { + if (aip->target_objnum != -1 && (The_mission.ai_profile()->flags[AI::Profile_Flags::Require_exact_los] || wip->wi_flags[Weapon::Info_Flags::Require_exact_los])) { //Check if th AI has Line of Sight and is allowed to fire - if (!check_los(OBJ_INDEX(objp), aip->target_objnum, The_mission.ai_profile->los_min_detection_radius, swp->current_primary_bank, -1, nullptr)) { + if (!check_los(OBJ_INDEX(objp), aip->target_objnum, The_mission.ai_profile()->los_min_detection_radius, swp->current_primary_bank, -1, nullptr)) { return 0; } } @@ -6379,7 +6379,7 @@ int ai_fire_primary_weapon(object *objp) vec3d v2t; bool condition; - if (The_mission.ai_profile->flags[AI::Profile_Flags::Fix_ramming_stationary_targets_bug]) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_ramming_stationary_targets_bug]) { // fixed by Mantis 3147 - Avoid bashing orientation if trying to avoid a collision. condition = !(vm_vec_mag_quick(&G_predicted_pos) < AICODE_SMALL_MAGNITUDE) && (aip->submode != SM_AVOID); } else { @@ -6398,7 +6398,7 @@ int ai_fire_primary_weapon(object *objp) } //SUSHI: Burst-fire for ballistic primaries. - if (The_mission.ai_profile->primary_ammo_burst_mult[Game_skill_level] > 0 && //Make sure we are using burst fire + if (The_mission.ai_profile()->primary_ammo_burst_mult[Game_skill_level] > 0 && //Make sure we are using burst fire enemy_objp != NULL && enemy_sip != NULL && //We need a target, obviously (enemy_objp->phys_info.speed >= 1.0f) && //Only burst for moving ships (enemy_sip->is_small_ship() || enemy_sip->flags[Ship::Info_Flags::Transport]) && //Only burst for small ships (transports count) @@ -6750,9 +6750,9 @@ bool check_ok_to_fire(int objnum, int target_objnum, const weapon_info *wip, int } } - if (The_mission.ai_profile->flags[AI::Profile_Flags::Require_exact_los] || wip->wi_flags[Weapon::Info_Flags::Require_exact_los]) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Require_exact_los] || wip->wi_flags[Weapon::Info_Flags::Require_exact_los]) { //Check if th AI has Line of Sight and is allowed to fire - if (!check_los(objnum, target_objnum, The_mission.ai_profile->los_min_detection_radius, -1, secondary_bank, firing_pos_global)) { + if (!check_los(objnum, target_objnum, The_mission.ai_profile()->los_min_detection_radius, -1, secondary_bank, firing_pos_global)) { return false; } } @@ -6773,7 +6773,7 @@ bool check_ok_to_fire(int objnum, int target_objnum, const weapon_info *wip, int int swarmers = 0; if (wip->wi_flags[Weapon::Info_Flags::Swarm]) swarmers = 2; // Note, always want to be able to fire swarmers if no currently incident homers. - if (The_mission.ai_profile->max_allowed_player_homers[Game_skill_level] < num_homers + swarmers) { + if (The_mission.ai_profile()->max_allowed_player_homers[Game_skill_level] < num_homers + swarmers) { return false; } } else if (num_homers > 3) { @@ -7225,7 +7225,7 @@ void set_predicted_enemy_pos(vec3d *predicted_enemy_pos, object *pobjp, vec3d *e wip = ai_get_weapon(&shipp->weapons); target_moving_direction = *enemy_vel; - if (wip != NULL && The_mission.ai_profile->flags[AI::Profile_Flags::Use_additive_weapon_velocity]) + if (wip != nullptr && The_mission.ai_profile()->flags[AI::Profile_Flags::Use_additive_weapon_velocity]) vm_vec_scale_sub2(&target_moving_direction, &pobjp->phys_info.vel, wip->vel_inherit_amount); if (wip != NULL) @@ -7257,7 +7257,7 @@ void set_predicted_enemy_pos(vec3d *predicted_enemy_pos, object *pobjp, vec3d *e // Compute position of gun in absolute space and use that as fire position // ...unless we want to just use the ship center - if(pm->gun_banks != NULL && !(The_mission.ai_profile->flags[AI::Profile_Flags::Ai_aims_from_ship_center])){ + if(pm->gun_banks != nullptr && !(The_mission.ai_profile()->flags[AI::Profile_Flags::Ai_aims_from_ship_center])){ pnt = pm->gun_banks[0].pnt[0]; } else { //Use the convergence offset, if there is one @@ -8115,7 +8115,7 @@ void ai_chase_attack(ai_info *aip, ship_info *sip, vec3d *predicted_enemy_pos, f vec3d new_pos; start_bank = Ships[aip->shipnum].weapons.current_primary_bank; - if (po->n_guns && start_bank != -1 && !(The_mission.ai_profile->flags[AI::Profile_Flags::Ai_aims_from_ship_center])) { + if (po->n_guns && start_bank != -1 && !(The_mission.ai_profile()->flags[AI::Profile_Flags::Ai_aims_from_ship_center])) { rel_pos = &po->gun_banks[start_bank].pnt[0]; } else rel_pos = NULL; @@ -8395,7 +8395,7 @@ void ai_set_guard_object(object *objp, object *other_objp) // If ship to guard is in a wing, guard that whole wing, unless the appropriate flag has been set auto other_shipp = &Ships[other_objp->instance]; - if ((other_shipp->wingnum != -1) && (other_shipp->wingnum != shipp->wingnum) && !(The_mission.ai_profile->flags[AI::Profile_Flags::Ai_guards_specific_ship_in_wing])) { + if ((other_shipp->wingnum != -1) && (other_shipp->wingnum != shipp->wingnum) && !(The_mission.ai_profile()->flags[AI::Profile_Flags::Ai_guards_specific_ship_in_wing])) { ai_set_guard_wing(objp, other_shipp->wingnum); } else { @@ -8644,7 +8644,7 @@ float set_secondary_fire_delay(ai_info *aip, ship *shipp, weapon_info *swip, boo if (aip->ai_class_autoscale) { - if (The_mission.ai_profile->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale]) t += (ai_get_autoscale_index(Num_ai_classes) - ai_get_autoscale_index(aip->ai_class) + 1) * 0.5f; else t += (Num_ai_classes - aip->ai_class + 1) * 0.5f; @@ -9050,7 +9050,7 @@ void ai_chase() if (!go_after_it) { // If we picked this target ourselves -- through auto-attack, dynamic chase, or a standing chase order -- // drop it, so that the retargeting logic in ai_frame() can find something we are willing to chase. - if (The_mission.ai_profile->flags[AI::Profile_Flags::Fix_ai_target_recovery]) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_ai_target_recovery]) { if (aip->active_goal < 0 || aip->active_goal == AI_ACTIVE_GOAL_DYNAMIC || (aip->active_goal < MAX_AI_GOALS && ai_goal_is_standing_chase(aip->goals[aip->active_goal].ai_mode))) { aip->target_objnum = -1; @@ -9086,10 +9086,10 @@ void ai_chase() } if (better_collision_avoidance_triggered( - The_mission.ai_profile->flags[AI::Profile_Flags::Better_combat_collision_avoidance], - The_mission.ai_profile->better_collision_avoid_aggression_combat, + The_mission.ai_profile()->flags[AI::Profile_Flags::Better_combat_collision_avoidance], + The_mission.ai_profile()->better_collision_avoid_aggression_combat, Pl_objp, - The_mission.ai_profile->flags[AI::Profile_Flags::Better_combat_collision_avoid_includes_target] ? nullptr : En_objp)) { + The_mission.ai_profile()->flags[AI::Profile_Flags::Better_combat_collision_avoid_includes_target] ? nullptr : En_objp)) { return; } @@ -9133,8 +9133,8 @@ void ai_chase() // If just acquired target, or target is not in reasonable cone, don't refine believed enemy position. if ((real_dot_to_enemy < 0.25f) || (aip->target_time < 1.0f)) { predicted_enemy_pos = enemy_pos; - } else if (aip->ai_flags[AI::AI_Flags::Seek_lock] && !(The_mission.ai_profile->flags[AI::Profile_Flags::Ignore_aspect_when_leading]) ) { - if (The_mission.ai_profile->flags[AI::Profile_Flags::Fix_ramming_stationary_targets_bug]) { + } else if (aip->ai_flags[AI::AI_Flags::Seek_lock] && !(The_mission.ai_profile()->flags[AI::Profile_Flags::Ignore_aspect_when_leading]) ) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_ramming_stationary_targets_bug]) { // fixed by Mantis 3147 - Bash orientation if aspect seekers are equipped. set_predicted_enemy_pos(&predicted_enemy_pos, Pl_objp, &aip->last_aim_enemy_pos, &aip->last_aim_enemy_vel, aip); // Set G_fire_pos predicted_enemy_pos = enemy_pos; @@ -10406,10 +10406,10 @@ int ai_maybe_limit_attackers(int attacked_objnum) int num_attacking; num_attacking = num_ships_attacking(attacked_objnum); - if (num_attacking == The_mission.ai_profile->max_attackers[Game_skill_level]) { + if (num_attacking == The_mission.ai_profile()->max_attackers[Game_skill_level]) { remove_farthest_attacker(attacked_objnum); rval=0; - } else if (num_attacking > The_mission.ai_profile->max_attackers[Game_skill_level]) { + } else if (num_attacking > The_mission.ai_profile()->max_attackers[Game_skill_level]) { rval=1; } } @@ -10447,7 +10447,7 @@ void guard_object_was_hit(object *guard_objp, object *hitter_objp) return; // If the hitter is protected, ignore it - if (The_mission.ai_profile->flags[AI::Profile_Flags::Guards_ignore_protected_attackers] && + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Guards_ignore_protected_attackers] && hitter_objp->flags[Object::Object_Flags::Protected]) return; @@ -10809,7 +10809,7 @@ void ai_guard_find_nearby_object() } // if still not attacking anything and flag is set, engage mines near the guarding ship itself - if (aip->target_objnum == -1 && The_mission.ai_profile->flags[AI::Profile_Flags::Ships_intercept_mines]) { + if (aip->target_objnum == -1 && The_mission.ai_profile()->flags[AI::Profile_Flags::Ships_intercept_mines]) { object *mine_objp = ai_find_nearby_mine_threat(Pl_objp); if (mine_objp) guard_object_was_hit(Pl_objp, mine_objp); @@ -10992,7 +10992,7 @@ void ai_big_guard() // got the point, now let's go there ai_turn_towards_vector(&goal_pt, Pl_objp, nullptr, nullptr, 0.0f, 0); - accelerate_ship(aip, The_mission.ai_profile->guard_big_orbit_max_speed_percent); + accelerate_ship(aip, The_mission.ai_profile()->guard_big_orbit_max_speed_percent); bool free_ab_use = aip->ai_flags[AI::AI_Flags::Free_afterburner_use] || aip->ai_profile_flags[AI::Profile_Flags::Free_afterburner_use]; @@ -11078,15 +11078,15 @@ void ai_guard() } if (better_collision_avoidance_triggered( - The_mission.ai_profile->flags[AI::Profile_Flags::Better_guard_collision_avoidance], - The_mission.ai_profile->better_collision_avoid_aggression_guard, + The_mission.ai_profile()->flags[AI::Profile_Flags::Better_guard_collision_avoidance], + The_mission.ai_profile()->better_collision_avoid_aggression_guard, Pl_objp, En_objp)) { return; } // handler for guard object with BIG radius - if (guard_objp->radius > The_mission.ai_profile->guard_big_orbit_above_target_radius) { + if (guard_objp->radius > The_mission.ai_profile()->guard_big_orbit_above_target_radius) { ai_big_guard(); return; } @@ -11307,7 +11307,7 @@ void ai_do_objects_repairing_stuff( object *repaired_objp, object *repair_objp, // if this is a player ship, then subtract the repair penalty from this player's score if ( repaired_objp->flags[Object::Object_Flags::Player_ship] ) { if ( !(Game_mode & GM_MULTIPLAYER) ) { - Player->stats.m_score -= The_mission.ai_profile->repair_penalty[Game_skill_level]; // subtract the penalty + Player->stats.m_score -= The_mission.ai_profile()->repair_penalty[Game_skill_level]; // subtract the penalty } } break; @@ -12492,7 +12492,7 @@ void ai_process_subobjects(int objnum) // Goober5000 and wookieejedi - conversely, if the engines are no longer blown (e.g. after repair), resume normal chase behavior. // The rest of the AI assumes SM_ATTACK_FOREVER implies blown engines, // so don't leave the submode set after the engines recover, or the ship will never evade and will ignore being hit. - else if (The_mission.ai_profile->flags[AI::Profile_Flags::Fix_small_ai_recover_after_engines_repaired] && ((aip->mode == AIM_CHASE) && (aip->submode == SM_ATTACK_FOREVER))) { + else if (The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_small_ai_recover_after_engines_repaired] && ((aip->mode == AIM_CHASE) && (aip->submode == SM_ATTACK_FOREVER))) { aip->submode = SM_ATTACK; aip->submode_start_time = Missiontime; } @@ -12948,7 +12948,7 @@ int ai_formation() (shipp->wingnum >= 0 && Wings[shipp->wingnum].flags[Ship::Wing_Flags::Waypoints_no_formation])) return 1; - if (The_mission.ai_profile->flags[AI::Profile_Flags::Fix_ai_path_order_bug]){ + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_ai_path_order_bug]){ // skip if wing leader has no waypoint order or a different waypoint list // ...or if it's a different start index or direction if ( (laip->mode != AIM_WAYPOINTS) @@ -13346,7 +13346,7 @@ void ai_maybe_launch_cmeasure(object *objp, ai_info *aip) // If not on player's team and Skill_level + ai_class is low, never fire a countermeasure. The ship is too dumb. //SUSHI: Only bail if autoscale is on... if (iff_x_attacks_y(Player_ship->team, shipp->team) && aip->ai_class_autoscale) { - if (The_mission.ai_profile->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale]) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale]) { if (Game_skill_level + ai_get_autoscale_index(aip->ai_class) < 4) { return; } @@ -13367,7 +13367,7 @@ void ai_maybe_launch_cmeasure(object *objp, ai_info *aip) bool in_countermeasure_range = dist < weapon_objp->phys_info.speed * 2.0f; weapon_info *cmeasure = &Weapon_info[shipp->current_cmeasure]; - if (The_mission.ai_profile->flags[AI::Profile_Flags::Improved_missile_avoidance]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Improved_missile_avoidance]) in_countermeasure_range = dist < cmeasure->cm_effective_rad; if ( in_countermeasure_range ) { @@ -13383,13 +13383,13 @@ void ai_maybe_launch_cmeasure(object *objp, ai_info *aip) if ( (aip->ai_profile_flags[AI::Profile_Flags::Unify_usage_countermeasure_firechance]) || (shipp->team != Player_ship->team) ) { fire_chance = aip->ai_cmeasure_fire_chance; } else { - fire_chance = The_mission.ai_profile->cmeasure_fire_chance[NUM_SKILL_LEVELS/2]; + fire_chance = The_mission.ai_profile()->cmeasure_fire_chance[NUM_SKILL_LEVELS/2]; } // Decrease chance to fire at lower ai class (SUSHI: Only if autoscale is on) if (aip->ai_class_autoscale) { - if (The_mission.ai_profile->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale]) fire_chance *= (float)ai_get_autoscale_index(aip->ai_class) / ai_get_autoscale_index(Num_ai_classes); else fire_chance *= (float)aip->ai_class / Num_ai_classes; @@ -13470,11 +13470,11 @@ void ai_chase_circle(object *objp) if (aip->ignore_objnum == UNUSED_OBJNUM) { dist_to_goal = vm_vec_dist_quick(&aip->goal_point, &objp->pos); - if (dist_to_goal > 2 * The_mission.ai_profile->attack_any_idle_circle_distance) { + if (dist_to_goal > 2 * The_mission.ai_profile()->attack_any_idle_circle_distance) { vec3d vec_to_goal; // Too far from circle goal, create a new goal point. vm_vec_normalized_dir(&vec_to_goal, &aip->goal_point, &objp->pos); - vm_vec_scale_add(&aip->goal_point, &objp->pos, &vec_to_goal, The_mission.ai_profile->attack_any_idle_circle_distance); + vm_vec_scale_add(&aip->goal_point, &objp->pos, &vec_to_goal, The_mission.ai_profile()->attack_any_idle_circle_distance); } goal_point = aip->goal_point; @@ -13530,13 +13530,13 @@ void ai_manage_shield(object *objp, ai_info *aip) // Scale time until next manage shield based on Skill_level. // Ships on player's team are treated as if Skill_level is average. // Or use unifying behavior if specified. --wookieejedi - if (The_mission.ai_profile->flags[AI::Profile_Flags::Unify_usage_ai_shield_manage_delay] || (iff_x_attacks_y(Player_ship->team, Ships[objp->instance].team))) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Unify_usage_ai_shield_manage_delay] || (iff_x_attacks_y(Player_ship->team, Ships[objp->instance].team))) { delay = aip->ai_shield_manage_delay; } else { - delay = The_mission.ai_profile->shield_manage_delay[NUM_SKILL_LEVELS/2]; + delay = The_mission.ai_profile()->shield_manage_delay[NUM_SKILL_LEVELS/2]; } // Scale between 1x and 3x based on ai_class (SUSHI: only if autoscale is on) @@ -13545,7 +13545,7 @@ void ai_manage_shield(object *objp, ai_info *aip) int number_of_as_classes = ai_get_autoscale_index(Num_ai_classes); // Cyborg: Make sure that autoscale index is greater than one before dividing, coverity 1523548 - if (The_mission.ai_profile->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale] && number_of_as_classes > 1) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale] && number_of_as_classes > 1) delay = delay + delay * (float)(3 * (number_of_as_classes - ai_get_autoscale_index(aip->ai_class) - 1) / (number_of_as_classes - 1)); else { static bool autoscale_checked = false; @@ -13611,7 +13611,7 @@ void ai_maybe_evade_locked_missile(object *objp, ai_info *aip) vec3d v2m; float dist = vm_vec_normalized_dir(&v2m, &objp->pos, &missile_objp->pos); - if (The_mission.ai_profile->flags[AI::Profile_Flags::Improved_missile_avoidance] + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Improved_missile_avoidance] && vm_vec_dot(&v2m, &missile_objp->orient.vec.fvec) < 0.5f ) { // don't bother if the missile isn't actually coming towards us aip->nearest_locked_object = -1; @@ -13619,7 +13619,7 @@ void ai_maybe_evade_locked_missile(object *objp, ai_info *aip) } // evade missiles 4 seconds away normally, 2 seconds away with the flag (evading too early is a thing!) - float evade_dist_scalar = The_mission.ai_profile->flags[AI::Profile_Flags::Improved_missile_avoidance] ? 2.0f : 4.0f; + float evade_dist_scalar = The_mission.ai_profile()->flags[AI::Profile_Flags::Improved_missile_avoidance] ? 2.0f : 4.0f; float evade_distance = evade_dist_scalar * vm_vec_mag_quick(&missile_objp->phys_info.vel); if (dist < evade_distance) { switch (aip->mode) { @@ -13639,7 +13639,7 @@ void ai_maybe_evade_locked_missile(object *objp, ai_info *aip) if (((((Missiontime >> 18) ^ OBJ_INDEX(objp)) & 3) == 0) || (objp->phys_info.speed < 40.0f) || (frand() < 1.0f - (float) shipp->cmeasure_count/8.0f || - The_mission.ai_profile->flags[AI::Profile_Flags::Improved_missile_avoidance])) { + The_mission.ai_profile()->flags[AI::Profile_Flags::Improved_missile_avoidance])) { if (aip->submode != SM_ATTACK_FOREVER) { // SM_ATTACK_FOREVER means engines blown. aip->submode = SM_EVADE_WEAPON; aip->submode_start_time = Missiontime; @@ -14009,7 +14009,7 @@ int ai_acquire_emerge_path(object *pl_objp, int parent_objnum, int allowed_path_ vm_vec_copy_normalize(&rvec, &parent_sip->pathMetadata[pathName].arrival_rvec); vm_vec_unrotate(&rvec, &rvec, &Objects[aip->path_objnum].orient); } - else if (The_mission.ai_profile->flags[AI::Profile_Flags::Fighterbay_arrivals_use_carrier_orient]) { + else if (The_mission.ai_profile()->flags[AI::Profile_Flags::Fighterbay_arrivals_use_carrier_orient]) { // using only the flag provides a way for modders to use a quick option (though not 100% perfect) // also, it is more intuitive that the carrier's uvec is preferable to attempt to match first // this avoids unintutive scenarios like rear-facing arrivals ending up side down @@ -14397,10 +14397,10 @@ void ai_execute_behavior(ai_info *aip) if (En_objp) { Assert(En_objp->type == OBJ_SHIP); if (!(better_collision_avoidance_triggered( - The_mission.ai_profile->flags[AI::Profile_Flags::Better_combat_collision_avoidance], - The_mission.ai_profile->better_collision_avoid_aggression_combat, + The_mission.ai_profile()->flags[AI::Profile_Flags::Better_combat_collision_avoidance], + The_mission.ai_profile()->better_collision_avoid_aggression_combat, Pl_objp, - The_mission.ai_profile->flags[AI::Profile_Flags::Better_combat_collision_avoid_includes_target] ? nullptr : En_objp))) { + The_mission.ai_profile()->flags[AI::Profile_Flags::Better_combat_collision_avoid_includes_target] ? nullptr : En_objp))) { ai_big_strafe(); // strafe a big ship } } else { @@ -14584,7 +14584,7 @@ int maybe_request_support(object *objp) try_to_rearm = true; } else if (ai_bad_time_to_rearm(objp)) { try_to_rearm = false; - } else if (num_allies_rearming(objp) < The_mission.ai_profile->max_allies_rearming_threshold) { + } else if (num_allies_rearming(objp) < The_mission.ai_profile()->max_allies_rearming_threshold) { if (desire >= 8) { // guarantees disabled will cause repair request try_to_rearm = true; } else if (desire >= 3) { // >= 3 means having a single subsystem fully blown will cause repair. @@ -14865,7 +14865,7 @@ static int ai_find_shockwave_ship(object *objp) // Only look at objects in the process of dying. if (shipp->flags[Ship::Ship_Flags::Dying]) { float damage; - if (The_mission.ai_profile->flags[AI::Profile_Flags::Fix_avoid_shockwave_bugs]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_avoid_shockwave_bugs]) damage = ship_get_exp_damage(A); // A is the object that is actually exploding! else damage = ship_get_exp_damage(objp); @@ -14888,7 +14888,7 @@ static int ai_find_shockwave_ship(object *objp) int aas_1(object *objp, ai_info *aip, vec3d *safe_pos) { - bool fix_bugs = The_mission.ai_profile->flags[AI::Profile_Flags::Fix_avoid_shockwave_bugs]; + bool fix_bugs = The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_avoid_shockwave_bugs]; // MAKE SURE safe_pos DOES NOT TAKE US TOWARD THE A SHIP WE'RE ATTACKING. if (aip->ai_flags[AI::AI_Flags::Avoid_shockwave_weapon]) { @@ -15085,7 +15085,7 @@ int aas_1(object *objp, ai_info *aip, vec3d *safe_pos) int ai_avoid_shockwave(object *objp, ai_info *aip) { vec3d safe_pos; - bool fix_bugs = The_mission.ai_profile->flags[AI::Profile_Flags::Fix_avoid_shockwave_bugs]; + bool fix_bugs = The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_avoid_shockwave_bugs]; // BIG|HUGE do not respond to shockwaves // Goober5000 - let's treat shockwave response the same way whether from weapon or ship @@ -15294,8 +15294,8 @@ int maybe_big_ship_collide_recover_frame(object *objp, ai_info *aip) float dot, dist; vec3d v2g; - bool better_collision_avoid_and_fighting = (The_mission.ai_profile->flags[AI::Profile_Flags::Better_combat_collision_avoidance] && aip->mode == AIM_CHASE) - || (The_mission.ai_profile->flags[AI::Profile_Flags::Better_guard_collision_avoidance] && aip->mode == AIM_GUARD); + bool better_collision_avoid_and_fighting = (The_mission.ai_profile()->flags[AI::Profile_Flags::Better_combat_collision_avoidance] && aip->mode == AIM_CHASE) + || (The_mission.ai_profile()->flags[AI::Profile_Flags::Better_guard_collision_avoidance] && aip->mode == AIM_GUARD); // 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; @@ -15475,7 +15475,7 @@ void ai_frame(int objnum) // that is about to detonate on us (within proximity_radius * 1.5). // Skip departing ships (AIM_WARP_OUT/AIM_BAY_DEPART): ai_maybe_depart() ran just above and may // have committed this ship to leaving, so we must not divert it back to a mine here. - if (The_mission.ai_profile->flags[AI::Profile_Flags::Ships_intercept_mines] + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Ships_intercept_mines] && aip->mode != AIM_GUARD && aip->mode != AIM_EVADE_WEAPON && aip->mode != AIM_WARP_OUT && aip->mode != AIM_BAY_DEPART && Ship_info[shipp->ship_info_index].class_type > -1 @@ -15496,7 +15496,7 @@ void ai_frame(int objnum) } else if (aip->resume_goal_time == -1) { // AL 12-9-97: Don't allow cargo and navbuoys to set their aip->target_objnum if ( Ship_info[shipp->ship_info_index].class_type > -1 && (Ship_types[Ship_info[shipp->ship_info_index].class_type].flags[Ship::Type_Info_Flags::AI_auto_attacks]) ) { - target_objnum = find_enemy(objnum, MAX_ENEMY_DISTANCE, The_mission.ai_profile->max_attackers[Game_skill_level]); // Attack up to 2.5K units away. + target_objnum = find_enemy(objnum, MAX_ENEMY_DISTANCE, The_mission.ai_profile()->max_attackers[Game_skill_level]); // Attack up to 2.5K units away. if (target_objnum != -1) { if (aip->target_objnum != target_objnum) aip->aspect_locked_time = 0.0f; @@ -15506,7 +15506,7 @@ void ai_frame(int objnum) { En_objp = &Objects[target_objnum]; } - } else if (aip->mode != AIM_GUARD && The_mission.ai_profile->flags[AI::Profile_Flags::Ships_intercept_mines]) { + } else if (aip->mode != AIM_GUARD && The_mission.ai_profile()->flags[AI::Profile_Flags::Ships_intercept_mines]) { // No enemy found so check for nearby hostile mines within their targetable range object *mine_objp = ai_find_nearby_mine_threat(Pl_objp); if (mine_objp) { @@ -15557,7 +15557,7 @@ void ai_frame(int objnum) En_objp = NULL; } - if (aip->mode == AIM_CHASE || ((The_mission.ai_profile->flags[AI::Profile_Flags::Fix_ai_target_recovery]) && aip->mode == AIM_STRAFE)) { + if (aip->mode == AIM_CHASE || ((The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_ai_target_recovery]) && aip->mode == AIM_STRAFE)) { // If we're chasing or strafing against large ship but have lost our target, clear the active goal // to ensure ai_process_mission_orders() re-evaluates our orders next frame. // Without this fighter/bomber whose strafe target is destroyed drops to AIM_NONE (see ai_execute_behavior) @@ -15570,7 +15570,7 @@ void ai_frame(int objnum) // Similarly, a ship that has already dropped to AIM_NONE while holding a standing chase order can never // recover on its own: ai_execute_behavior() does nothing in AIM_NONE, and ai_process_mission_orders() // returns early while active_goal is set. Clear the active goal so the order is re-processed next frame. - else if (The_mission.ai_profile->flags[AI::Profile_Flags::Fix_ai_target_recovery] && aip->mode == AIM_NONE + else if (The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_ai_target_recovery] && aip->mode == AIM_NONE && aip->active_goal >= 0 && aip->active_goal < MAX_AI_GOALS && ai_goal_is_standing_chase(aip->goals[aip->active_goal].ai_mode)) { aip->active_goal = -1; @@ -15580,7 +15580,7 @@ void ai_frame(int objnum) if ((aip->resume_goal_time > 0) && (aip->resume_goal_time < Missiontime)) { aip->active_goal = AI_ACTIVE_GOAL_NONE; aip->resume_goal_time = -1; - target_objnum = find_enemy(objnum, 2000.0f, The_mission.ai_profile->max_attackers[Game_skill_level]); + target_objnum = find_enemy(objnum, 2000.0f, The_mission.ai_profile()->max_attackers[Game_skill_level]); if (target_objnum != -1) { if (aip->target_objnum != target_objnum) { aip->aspect_locked_time = 0.0f; @@ -15882,7 +15882,7 @@ void init_ai_object(int objnum) } //Init stuff from AI class and AI profiles - init_aip_from_class_and_profile(aip, &Ai_classes[Ship_info[ship_type].ai_class], The_mission.ai_profile); + init_aip_from_class_and_profile(aip, &Ai_classes[Ship_info[ship_type].ai_class], The_mission.ai_profile()); aip->wp_list_index = -1; aip->wp_index = INVALID_WAYPOINT_POSITION; @@ -15986,7 +15986,7 @@ void init_ai_system() //Unset per-difficulty-level values are marked with FLT_MIN or INT_MIN //Which flags are set is handled by using two flag ints: one with the flag values (TRUE/FALSE), one that //just says which flags are set. -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) { // since we use it so much in this function, sanity check the value for Game_skill_level if (Game_skill_level < 0 || Game_skill_level >= NUM_SKILL_LEVELS) { @@ -16079,7 +16079,7 @@ void ai_do_default_behavior(object *obj) // fighters automatically chase things if (!is_instructor(obj) && (sip->is_fighter_bomber())) { - int enemy_objnum = find_enemy(OBJ_INDEX(obj), 1000.0f, The_mission.ai_profile->max_attackers[Game_skill_level]); + int enemy_objnum = find_enemy(OBJ_INDEX(obj), 1000.0f, The_mission.ai_profile()->max_attackers[Game_skill_level]); set_target_objnum(aip, enemy_objnum); aip->mode = AIM_CHASE; aip->submode = SM_ATTACK; @@ -16127,7 +16127,7 @@ void process_friendly_hit_message( int message, object *objp ) if (Ships[objp->instance].flags[Ship::Ship_Flags::No_builtin_messages]) { index = -1; } - if (The_mission.ai_profile->flags[AI::Profile_Flags::Check_comms_for_non_player_ships] && hud_communications_state(&Ships[objp->instance]) <= COMM_DAMAGED) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Check_comms_for_non_player_ships] && hud_communications_state(&Ships[objp->instance]) <= COMM_DAMAGED) { index = -1; } @@ -16449,7 +16449,7 @@ void ai_ship_hit(object *objp_ship, object *hit_objp, const vec3d *hit_normal) aip = &Ai_info[shipp->ai_index]; if (objp_ship->flags[Object::Object_Flags::Player_ship]) { - if (The_mission.ai_profile->flags[AI::Profile_Flags::Reset_last_hit_target_time_for_player_hits]) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Reset_last_hit_target_time_for_player_hits]) { //SUSHI: So that hitting a player ship actually resets the last_hit_target_time counter for whoever hit the player. //This is all copypasted from code below // Added OBJ_BEAM for traitor detection - FUBAR diff --git a/code/ai/aigoals.cpp b/code/ai/aigoals.cpp index 4b8439950cc..c28cb003718 100644 --- a/code/ai/aigoals.cpp +++ b/code/ai/aigoals.cpp @@ -72,8 +72,8 @@ constexpr int MIN_GOAL_PRIORITY = 1; // ai_add_goal_sub_sexp(), the goal clearing is integrated into the logic of the relevant sexp operators [[nodiscard]] bool causes_goal_clearing(ai_goal_mode ai_mode) { - return ((ai_mode == AI_GOAL_STAY_STILL && !The_mission.ai_profile->flags[AI::Profile_Flags::Do_not_clear_goals_when_running_stay_still]) - || (ai_mode == AI_GOAL_FORM_ON_WING && !The_mission.ai_profile->flags[AI::Profile_Flags::Do_not_clear_goals_when_running_form_on_wing]) + return ((ai_mode == AI_GOAL_STAY_STILL && !The_mission.ai_profile()->flags[AI::Profile_Flags::Do_not_clear_goals_when_running_stay_still]) + || (ai_mode == AI_GOAL_FORM_ON_WING && !The_mission.ai_profile()->flags[AI::Profile_Flags::Do_not_clear_goals_when_running_form_on_wing]) || (ai_mode == AI_GOAL_PLAY_DEAD)); } @@ -213,7 +213,7 @@ void ai_maybe_add_form_goal(wing* wingp) } // we may simply not want the mission to do this - if (The_mission.ai_profile->flags[AI::Profile_Flags::Dont_form_on_wing_at_mission_start]) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Dont_form_on_wing_at_mission_start]) { return; } @@ -795,14 +795,14 @@ void ai_add_goal_sub_player(ai_goal_type type, ai_goal_mode mode, int submode, c aigp->flags.set(AI::Goal_Flags::Clear_all_goals_first); // also set up the override, since it's no longer done automatically in ai_mission_goal_achievable - if (mode == AI_GOAL_FORM_ON_WING && !The_mission.ai_profile->flags[AI::Profile_Flags::Do_not_set_override_when_assigning_form_on_wing]) + if (mode == AI_GOAL_FORM_ON_WING && !The_mission.ai_profile()->flags[AI::Profile_Flags::Do_not_set_override_when_assigning_form_on_wing]) aigp->flags.set(AI::Goal_Flags::Want_override); // generally, players want ships to form-on-wing only until they need to do something else - if (mode == AI_GOAL_FORM_ON_WING && The_mission.ai_profile->flags[AI::Profile_Flags::Purge_player_issued_form_on_wing_after_subsequent_order]) + if (mode == AI_GOAL_FORM_ON_WING && The_mission.ai_profile()->flags[AI::Profile_Flags::Purge_player_issued_form_on_wing_after_subsequent_order]) aigp->flags.set(AI::Goal_Flags::Purge_when_new_goal_added); - if (The_mission.ai_profile->flags[AI::Profile_Flags::Player_orders_afterburn_hard]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Player_orders_afterburn_hard]) aigp->flags.set(AI::Goal_Flags::Afterburn_hard); @@ -894,7 +894,7 @@ void ai_add_goal_sub_scripting(ai_goal_type type, ai_goal_mode mode, int submode aigp->flags.set(AI::Goal_Flags::Clear_all_goals_first); // also set up the override, since it's no longer done automatically in ai_mission_goal_achievable - if (mode == AI_GOAL_FORM_ON_WING && !The_mission.ai_profile->flags[AI::Profile_Flags::Do_not_set_override_when_assigning_form_on_wing]) + if (mode == AI_GOAL_FORM_ON_WING && !The_mission.ai_profile()->flags[AI::Profile_Flags::Do_not_set_override_when_assigning_form_on_wing]) aigp->flags.set(AI::Goal_Flags::Want_override); aigp->priority = priority; @@ -1135,7 +1135,7 @@ void ai_add_goal_sub_sexp( int sexp, ai_goal_type type, ai_info *aip, ai_goal *a aigp->priority = eval_num(n, priority_is_nan, priority_is_nan_forever); n = CDR(n); - bool clear_goals = !The_mission.ai_profile->flags[AI::Profile_Flags::Do_not_clear_goals_when_running_stay_still]; + bool clear_goals = !The_mission.ai_profile()->flags[AI::Profile_Flags::Do_not_clear_goals_when_running_stay_still]; if (n >= 0) { clear_goals = is_sexp_true(n); @@ -1217,9 +1217,9 @@ void ai_add_goal_sub_sexp( int sexp, ai_goal_type type, ai_info *aip, ai_goal *a n = CDR(n); } else - aigp->priority = The_mission.ai_profile->default_form_on_wing_priority; + aigp->priority = The_mission.ai_profile()->default_form_on_wing_priority; - bool clear_goals = !The_mission.ai_profile->flags[AI::Profile_Flags::Do_not_clear_goals_when_running_form_on_wing]; + bool clear_goals = !The_mission.ai_profile()->flags[AI::Profile_Flags::Do_not_clear_goals_when_running_form_on_wing]; if (n >= 0) { clear_goals = is_sexp_true(n); @@ -1228,7 +1228,7 @@ void ai_add_goal_sub_sexp( int sexp, ai_goal_type type, ai_info *aip, ai_goal *a if (clear_goals) aigp->flags.set(AI::Goal_Flags::Clear_all_goals_first); - bool set_override = !The_mission.ai_profile->flags[AI::Profile_Flags::Do_not_set_override_when_assigning_form_on_wing]; + bool set_override = !The_mission.ai_profile()->flags[AI::Profile_Flags::Do_not_set_override_when_assigning_form_on_wing]; if (n >= 0) { set_override = is_sexp_true(n); @@ -1564,7 +1564,7 @@ int ai_remove_goal_sexp_sub( int sexp, ai_goal* aigp, bool &remove_more ) goalmode = (op == OP_AI_IGNORE) ? AI_GOAL_IGNORE : AI_GOAL_IGNORE_NEW; break; case OP_AI_FORM_ON_WING: - priority = eval_priority_et_seq(CDDR(node), The_mission.ai_profile->default_form_on_wing_priority); + priority = eval_priority_et_seq(CDDR(node), The_mission.ai_profile()->default_form_on_wing_priority); goalmode = AI_GOAL_FORM_ON_WING; break; case OP_AI_FLY_TO_SHIP: diff --git a/code/ai/aiturret.cpp b/code/ai/aiturret.cpp index 8446ed952f5..6c33236b452 100644 --- a/code/ai/aiturret.cpp +++ b/code/ai/aiturret.cpp @@ -592,7 +592,7 @@ void evaluate_obj_as_target(object *objp, eval_enemy_obj_struct *eeo) // however if this is removed turrets still track targets but don't fire at them (which looks silly) if (eeo->eeo_flags & EEOF_TAGGED_ONLY) { if (!ship_is_tagged(objp) && - ( (The_mission.ai_profile->flags[AI::Profile_Flags::Strict_turret_tagged_only_targeting]) || + ( (The_mission.ai_profile()->flags[AI::Profile_Flags::Strict_turret_tagged_only_targeting]) || ( !(objp->type == OBJ_WEAPON) && !(turret_weapon_has_flags(&eeo->turret_subsys->weapons, Weapon::Info_Flags::Spawn))) )) { return; } @@ -704,9 +704,9 @@ void evaluate_obj_as_target(object *objp, eval_enemy_obj_struct *eeo) // return if we're over the cap // int max_turrets = 3 + Game_skill_level * Game_skill_level; - int max_turrets = The_mission.ai_profile->max_turret_ownage_target[Game_skill_level]; + int max_turrets = The_mission.ai_profile()->max_turret_ownage_target[Game_skill_level]; if (objp->flags[Object::Object_Flags::Player_ship]) { - max_turrets = The_mission.ai_profile->max_turret_ownage_player[Game_skill_level]; + max_turrets = The_mission.ai_profile()->max_turret_ownage_player[Game_skill_level]; } // Apply the per-turret limit for small targets, if there is one and this is a small target if (ss->turret_max_target_ownage != -1 && (Ship_info[shipp->ship_info_index].is_small_ship())) { @@ -1317,7 +1317,7 @@ void aifft_update_predicted_enemy_pos(const object *objp, const ship *shipp, shi target_vel = ss->last_aim_enemy_vel; //Try to guess where the enemy will be, and store that spot in predicted_enemy_pos - if (The_mission.ai_profile->flags[AI::Profile_Flags::Use_additive_weapon_velocity]) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Use_additive_weapon_velocity]) { vm_vec_scale_sub2(&target_vel, &objp->phys_info.vel, wip->vel_inherit_amount); } @@ -1621,7 +1621,7 @@ void turret_set_next_fire_timestamp(int weapon_num, const weapon_info *wip, ship wait *= aip->ai_ship_fire_delay_scale_friendly * 0.5f; if (aip->ai_class_autoscale) { - if (The_mission.ai_profile->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale]) wait += (ai_get_autoscale_index(Num_ai_classes) - ai_get_autoscale_index(aip->ai_class) - 1) * 40.0f; else wait += (Num_ai_classes - aip->ai_class - 1) * 40.0f; @@ -1630,7 +1630,7 @@ void turret_set_next_fire_timestamp(int weapon_num, const weapon_info *wip, ship wait *= aip->ai_ship_fire_delay_scale_friendly; if (aip->ai_class_autoscale) { - if (The_mission.ai_profile->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale]) wait += (ai_get_autoscale_index(Num_ai_classes) - ai_get_autoscale_index(aip->ai_class) - 1) * 100.0f; else wait += (Num_ai_classes - aip->ai_class - 1) * 100.0f; @@ -1646,7 +1646,7 @@ void turret_set_next_fire_timestamp(int weapon_num, const weapon_info *wip, ship } if (aip->ai_class_autoscale) { - if (The_mission.ai_profile->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale]) wait += (ai_get_autoscale_index(Num_ai_classes) - ai_get_autoscale_index(aip->ai_class) - 1) * 40.0f; else wait += (Num_ai_classes - aip->ai_class - 1) * 40.0f; @@ -1657,7 +1657,7 @@ void turret_set_next_fire_timestamp(int weapon_num, const weapon_info *wip, ship wait *= aip->ai_ship_fire_delay_scale_friendly; if (aip->ai_class_autoscale) { - if (The_mission.ai_profile->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale]) wait += (ai_get_autoscale_index(Num_ai_classes) - ai_get_autoscale_index(aip->ai_class) - 1) * 100.0f; else wait += (Num_ai_classes - aip->ai_class - 1) * 100.0f; @@ -1671,7 +1671,7 @@ void turret_set_next_fire_timestamp(int weapon_num, const weapon_info *wip, ship } if (aip->ai_class_autoscale) { - if (The_mission.ai_profile->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale]) wait += (ai_get_autoscale_index(Num_ai_classes) - ai_get_autoscale_index(aip->ai_class) - 1) * 100.0f; else wait += (Num_ai_classes - aip->ai_class - 1) * 100.0f; @@ -1923,7 +1923,7 @@ bool turret_fire_weapon(int weapon_num, if (swp->primary_bank_ammo[turret_pbank] >= points) { swp->primary_bank_ammo[turret_pbank] -= points; - } else if ((swp->primary_bank_ammo[turret_pbank] >= 0) && !(The_mission.ai_profile->flags[AI::Profile_Flags::Prevent_negative_turret_ammo])) { + } else if ((swp->primary_bank_ammo[turret_pbank] >= 0) && !(The_mission.ai_profile()->flags[AI::Profile_Flags::Prevent_negative_turret_ammo])) { // default behavior allowed ammo to be negative swp->primary_bank_ammo[turret_pbank] -= points; } else { @@ -1934,7 +1934,7 @@ bool turret_fire_weapon(int weapon_num, if (!no_ammo_needed) { if (swp->secondary_bank_ammo[turret_sbank] > 0) { swp->secondary_bank_ammo[turret_sbank]--; - } else if ((swp->secondary_bank_ammo[turret_sbank] == 0) && !(The_mission.ai_profile->flags[AI::Profile_Flags::Prevent_negative_turret_ammo])) { + } else if ((swp->secondary_bank_ammo[turret_sbank] == 0) && !(The_mission.ai_profile()->flags[AI::Profile_Flags::Prevent_negative_turret_ammo])) { // default behavior allowed ammo to be negative swp->secondary_bank_ammo[turret_sbank]--; } else { @@ -2078,7 +2078,7 @@ void turret_swarm_fire_from_turret(turret_swarm_info *tsi) // *If it's a non-homer, then use the last fire direction instead of turret orientation to fix inaccuracy // problems with non-homing swarm weapons -Et1 - if ( (Weapon_info[tsi->weapon_class].subtype == WP_LASER) || ((The_mission.ai_profile->flags[AI::Profile_Flags::Hack_improve_non_homing_swarm_turret_fire_accuracy]) + if ( (Weapon_info[tsi->weapon_class].subtype == WP_LASER) || ((The_mission.ai_profile()->flags[AI::Profile_Flags::Hack_improve_non_homing_swarm_turret_fire_accuracy]) && !(Weapon_info[tsi->weapon_class].is_homing())) ) { turret_fvec = tsi->turret->turret_last_fire_direction; @@ -2295,7 +2295,7 @@ void ai_turret_execute_behavior(const ship *shipp, ship_subsys *ss) if (lep) { base_dist_to_enemy = vm_vec_normalized_dir(&v2e, &predicted_enemy_pos, &global_gun_pos); dist_to_enemy = base_dist_to_enemy; - if (!The_mission.ai_profile->flags[AI::Profile_Flags::Turrets_ignore_target_radius]) { + if (!The_mission.ai_profile()->flags[AI::Profile_Flags::Turrets_ignore_target_radius]) { dist_to_enemy -= lep->radius; } base_dist_to_enemy = MAX(0.0f, base_dist_to_enemy); @@ -2501,7 +2501,7 @@ void ai_turret_execute_behavior(const ship *shipp, ship_subsys *ss) } else { // check tagged-only for bombs only if the flag is set; see Mantis #3114 - if (tagged_only && ((lep->type != OBJ_WEAPON) || The_mission.ai_profile->flags[AI::Profile_Flags::Strict_turret_tagged_only_targeting])) { + if (tagged_only && ((lep->type != OBJ_WEAPON) || The_mission.ai_profile()->flags[AI::Profile_Flags::Strict_turret_tagged_only_targeting])) { tentative_return = true; continue; } @@ -2566,9 +2566,9 @@ void ai_turret_execute_behavior(const ship *shipp, ship_subsys *ss) ss->targeted_subsys = aifft_find_turret_subsys(objp, ss, &global_gun_pos, lep, &dot); } // recheck in 2-3 seconds - ss->turret_next_enemy_check_stamp = timestamp((int)((MAX(dot, 0.5f) * The_mission.ai_profile->turret_target_recheck_time) + (The_mission.ai_profile->turret_target_recheck_time / 2.0f))); + ss->turret_next_enemy_check_stamp = timestamp(fl2i((MAX(dot, 0.5f) * The_mission.ai_profile()->turret_target_recheck_time) + (The_mission.ai_profile()->turret_target_recheck_time / 2.0f))); } else { - ss->turret_next_enemy_check_stamp = timestamp((int)(The_mission.ai_profile->turret_target_recheck_time * frand_range(0.9f, 1.1f))); // Check every two seconds + ss->turret_next_enemy_check_stamp = timestamp(fl2i(The_mission.ai_profile()->turret_target_recheck_time * frand_range(0.9f, 1.1f))); // Check every two seconds } } @@ -2684,7 +2684,7 @@ void ai_turret_execute_behavior(const ship *shipp, ship_subsys *ss) // aspect seeking and target is locked. bool in_sight = false; - if (The_mission.ai_profile->flags[AI::Profile_Flags::Use_only_single_fov_for_turrets]) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Use_only_single_fov_for_turrets]) { // we have already passed the FOV test of the turret so... in_sight = true; } else { diff --git a/code/asteroid/asteroid.cpp b/code/asteroid/asteroid.cpp index 9c59ee6940c..c46456044b5 100644 --- a/code/asteroid/asteroid.cpp +++ b/code/asteroid/asteroid.cpp @@ -1036,7 +1036,7 @@ static void maybe_throw_asteroid() continue; // This should've been greater equal, but alas... - if (target.incoming_asteroids > The_mission.ai_profile->max_incoming_asteroids[Game_skill_level]) + if (target.incoming_asteroids > The_mission.ai_profile()->max_incoming_asteroids[Game_skill_level]) continue; nprintf(("AI", "Incoming asteroids to %s: %i\n", Ships[target_objp->instance].ship_name, target.incoming_asteroids)); @@ -1719,7 +1719,7 @@ void asteroid_hit( object * pasteroid_obj, object * other_obj, vec3d * hitpos, f send_asteroid_hit( pasteroid_obj, other_obj, hitpos, damage, force ); } - if (hitpos && force && The_mission.ai_profile->flags[AI::Profile_Flags::Whackable_asteroids]) { + if (hitpos && force && The_mission.ai_profile()->flags[AI::Profile_Flags::Whackable_asteroids]) { vec3d rel_hit_pos = *hitpos - pasteroid_obj->pos; physics_calculate_and_apply_whack(force, &rel_hit_pos, &pasteroid_obj->phys_info, &pasteroid_obj->orient, &pasteroid_obj->phys_info.I_body_inv); pasteroid_obj->phys_info.desired_vel = pasteroid_obj->phys_info.vel; diff --git a/code/debris/debris.cpp b/code/debris/debris.cpp index 1f960f949f2..63f96024ee6 100644 --- a/code/debris/debris.cpp +++ b/code/debris/debris.cpp @@ -894,7 +894,7 @@ void debris_hit(object *debris_obj, object * /*other_obj*/, vec3d *hitpos, float damage = 0.0f; } - if (hitpos && force && The_mission.ai_profile->flags[AI::Profile_Flags::Whackable_debris]) { + if (hitpos && force && The_mission.ai_profile()->flags[AI::Profile_Flags::Whackable_debris]) { vec3d rel_hit_pos = *hitpos - debris_obj->pos; physics_calculate_and_apply_whack(force, &rel_hit_pos, &debris_obj->phys_info, &debris_obj->orient, &debris_obj->phys_info.I_body_inv); } diff --git a/code/hud/hudets.cpp b/code/hud/hudets.cpp index 99f27f91711..67d0d71ed58 100644 --- a/code/hud/hudets.cpp +++ b/code/hud/hudets.cpp @@ -79,7 +79,7 @@ float ets_power_factor(object *objp, bool include_power_output) auto shipp = &Ships[objp->instance]; int properties = ets_properties(objp); - if (The_mission.ai_profile->flags[AI::Profile_Flags::ETS_energy_same_regardless_of_system_presence] && (properties != (HAS_WEAPONS | HAS_SHIELDS | HAS_ENGINES))) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::ETS_energy_same_regardless_of_system_presence] && (properties != (HAS_WEAPONS | HAS_SHIELDS | HAS_ENGINES))) { // in retail, the effect of having a missing system (e.g. an unshielded ship) is as if all that energy were redirected to other systems, so take the inverse of that constexpr float missing_single_factor = 2.0f/3; @@ -88,14 +88,14 @@ float ets_power_factor(object *objp, bool include_power_output) // if the properties are *equal* to just one, then it's missing double; otherwise we ruled out the all-three case so it has two and it's missing single float missing_factor = (properties == HAS_WEAPONS || properties == HAS_SHIELDS || properties == HAS_ENGINES) ? missing_double_factor : missing_single_factor; - if (The_mission.ai_profile->flags[AI::Profile_Flags::ETS_uses_power_output] && include_power_output) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::ETS_uses_power_output] && include_power_output) return Ship_info[shipp->ship_info_index].power_output * missing_factor; else return missing_factor; } else { - if (The_mission.ai_profile->flags[AI::Profile_Flags::ETS_uses_power_output] && include_power_output) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::ETS_uses_power_output] && include_power_output) return Ship_info[shipp->ship_info_index].power_output; else return 1.0f; @@ -137,7 +137,7 @@ void update_ets(object* objp, float fl_frametime) // update weapon energy max_new_weapon_energy = fl_frametime * ship_p->max_weapon_regen_per_second * max_g; if ( objp->flags[Object::Object_Flags::Player_ship] ) { - ship_p->weapon_energy += ets_power_factor(objp) * Energy_levels[ship_p->weapon_recharge_index] * max_new_weapon_energy * The_mission.ai_profile->weapon_energy_scale[Game_skill_level]; + ship_p->weapon_energy += ets_power_factor(objp) * Energy_levels[ship_p->weapon_recharge_index] * max_new_weapon_energy * The_mission.ai_profile()->weapon_energy_scale[Game_skill_level]; } else { ship_p->weapon_energy += ets_power_factor(objp) * Energy_levels[ship_p->weapon_recharge_index] * max_new_weapon_energy; } @@ -149,7 +149,7 @@ void update_ets(object* objp, float fl_frametime) float shield_delta; max_new_shield_energy = fl_frametime * ship_p->max_shield_regen_per_second * shield_get_max_strength(ship_p, true); // recharge rate is unaffected by $Max Shield Recharge if ( objp->flags[Object::Object_Flags::Player_ship] ) { - shield_delta = ets_power_factor(objp) * Energy_levels[ship_p->shield_recharge_index] * max_new_shield_energy * The_mission.ai_profile->shield_energy_scale[Game_skill_level]; + shield_delta = ets_power_factor(objp) * Energy_levels[ship_p->shield_recharge_index] * max_new_shield_energy * The_mission.ai_profile()->shield_energy_scale[Game_skill_level]; } else { shield_delta = ets_power_factor(objp) * Energy_levels[ship_p->shield_recharge_index] * max_new_shield_energy; } @@ -230,7 +230,7 @@ float ets_get_max_speed(object* objp, float engine_energy) ship_info* sip = &Ship_info[shipp->ship_info_index]; float initial_engine_recharge_energy_level; - if (The_mission.ai_profile->flags[AI::Profile_Flags::ETS_energy_same_regardless_of_system_presence]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::ETS_energy_same_regardless_of_system_presence]) { int properties = ets_properties(objp); if (properties == (HAS_WEAPONS | HAS_SHIELDS | HAS_ENGINES)) @@ -357,7 +357,7 @@ void ai_manage_ets(object* obj) // emergency check for ships with shields if (!(obj->flags[Object::Object_Flags::No_shields])) { float shield_left_percent = get_shield_pct(obj); - if (!(The_mission.ai_profile->flags[AI::Profile_Flags::Disable_ai_transferring_energy])) { + if (!(The_mission.ai_profile()->flags[AI::Profile_Flags::Disable_ai_transferring_energy])) { if ( shield_left_percent < SHIELDS_EMERG_LEVEL_PERCENT ) { if (ship_p->target_shields_delta == 0.0f) transfer_energy_to_shields(obj); diff --git a/code/hud/hudsquadmsg.cpp b/code/hud/hudsquadmsg.cpp index 137313d22e3..564de107356 100644 --- a/code/hud/hudsquadmsg.cpp +++ b/code/hud/hudsquadmsg.cpp @@ -342,7 +342,7 @@ bool hud_squadmsg_ship_valid(ship *shipp, object *objp) } // maybe check comm system - if (The_mission.ai_profile->flags[AI::Profile_Flags::Check_comms_for_non_player_ships] && hud_communications_state(shipp) != COMM_OK) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Check_comms_for_non_player_ships] && hud_communications_state(shipp) != COMM_OK) return false; // If we got to this point, the ship must be valid. @@ -1253,7 +1253,7 @@ int hud_squadmsg_send_ship_command( int shipnum, int command, int send_message, Objects[ainfo->target_objnum].flags.remove(Object::Object_Flags::Protected); } - ai_mode = (The_mission.ai_profile->flags[AI::Profile_Flags::Hudsquadmsg_tactical_disarm_disable]) ? AI_GOAL_DISABLE_SHIP_TACTICAL : AI_GOAL_DISABLE_SHIP; + ai_mode = (The_mission.ai_profile()->flags[AI::Profile_Flags::Hudsquadmsg_tactical_disarm_disable]) ? AI_GOAL_DISABLE_SHIP_TACTICAL : AI_GOAL_DISABLE_SHIP; ai_submode = -SUBSYSTEM_ENGINE; message = MESSAGE_DISABLE_TARGET; break; @@ -1267,7 +1267,7 @@ int hud_squadmsg_send_ship_command( int shipnum, int command, int send_message, Objects[ainfo->target_objnum].flags.remove(Object::Object_Flags::Protected); } - ai_mode = (The_mission.ai_profile->flags[AI::Profile_Flags::Hudsquadmsg_tactical_disarm_disable]) ? AI_GOAL_DISARM_SHIP_TACTICAL : AI_GOAL_DISARM_SHIP; + ai_mode = (The_mission.ai_profile()->flags[AI::Profile_Flags::Hudsquadmsg_tactical_disarm_disable]) ? AI_GOAL_DISARM_SHIP_TACTICAL : AI_GOAL_DISARM_SHIP; ai_submode = -SUBSYSTEM_TURRET; message = MESSAGE_DISARM_TARGET; break; @@ -1542,7 +1542,7 @@ int hud_squadmsg_send_wing_command( int wingnum, int command, int send_message, Assert(target_shipname); Assert(wing_team != target_team); - ai_mode = (The_mission.ai_profile->flags[AI::Profile_Flags::Hudsquadmsg_tactical_disarm_disable]) ? AI_GOAL_DISABLE_SHIP_TACTICAL : AI_GOAL_DISABLE_SHIP; + ai_mode = (The_mission.ai_profile()->flags[AI::Profile_Flags::Hudsquadmsg_tactical_disarm_disable]) ? AI_GOAL_DISABLE_SHIP_TACTICAL : AI_GOAL_DISABLE_SHIP; ai_submode = -SUBSYSTEM_ENGINE; message = MESSAGE_DISABLE_TARGET; break; @@ -1551,7 +1551,7 @@ int hud_squadmsg_send_wing_command( int wingnum, int command, int send_message, Assert(target_shipname); Assert(wing_team != target_team); - ai_mode = (The_mission.ai_profile->flags[AI::Profile_Flags::Hudsquadmsg_tactical_disarm_disable]) ? AI_GOAL_DISARM_SHIP_TACTICAL : AI_GOAL_DISARM_SHIP; + ai_mode = (The_mission.ai_profile()->flags[AI::Profile_Flags::Hudsquadmsg_tactical_disarm_disable]) ? AI_GOAL_DISARM_SHIP_TACTICAL : AI_GOAL_DISARM_SHIP; ai_submode = -SUBSYSTEM_TURRET; message = MESSAGE_DISARM_TARGET; break; diff --git a/code/hud/hudtarget.cpp b/code/hud/hudtarget.cpp index 2caba8d4069..e23c1da3e5d 100644 --- a/code/hud/hudtarget.cpp +++ b/code/hud/hudtarget.cpp @@ -3873,7 +3873,7 @@ bool hud_calculate_lead_pos(vec3d* shooter_pos, vec3d *lead_target_pos, vec3d *t } } - if(The_mission.ai_profile->flags[AI::Profile_Flags::Use_additive_weapon_velocity]) + if(The_mission.ai_profile()->flags[AI::Profile_Flags::Use_additive_weapon_velocity]) vm_vec_scale_sub2(&target_speed, &Player_obj->phys_info.vel, wip->vel_inherit_amount); // test if the target is moving at all @@ -3970,14 +3970,14 @@ void polish_predicted_target_pos(weapon_info *wip, object *targetp, vec3d *enemy vec3d enemy_vel = targetp->phys_info.vel; vec3d enemy_acc; - if (The_mission.ai_profile->second_order_lead_predict_factor > 0) { + if (The_mission.ai_profile()->second_order_lead_predict_factor > 0) { vec3d world_rotvel; vm_vec_unrotate(&world_rotvel, &targetp->phys_info.rotvel, &targetp->orient); vm_vec_cross(&enemy_acc, &world_rotvel, &enemy_vel); } // additive velocity stuff // not just the player's main target - if (The_mission.ai_profile->flags[AI::Profile_Flags::Use_additive_weapon_velocity]) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Use_additive_weapon_velocity]) { vm_vec_scale_sub2( &enemy_vel, &reference_object->phys_info.vel, wip->vel_inherit_amount); } @@ -3985,8 +3985,8 @@ void polish_predicted_target_pos(weapon_info *wip, object *targetp, vec3d *enemy dist_to_enemy = vm_vec_dist_quick(predicted_enemy_pos, &reference_pos); time_to_enemy = dist_to_enemy/weapon_speed; vm_vec_scale_add(predicted_enemy_pos, enemy_pos, &enemy_vel, time_to_enemy); - if (The_mission.ai_profile->second_order_lead_predict_factor > 0) { - vm_vec_scale_add(predicted_enemy_pos, predicted_enemy_pos, &enemy_acc, (time_to_enemy * time_to_enemy / 2) * The_mission.ai_profile->second_order_lead_predict_factor); + if (The_mission.ai_profile()->second_order_lead_predict_factor > 0) { + vm_vec_scale_add(predicted_enemy_pos, predicted_enemy_pos, &enemy_acc, (time_to_enemy * time_to_enemy / 2) * The_mission.ai_profile()->second_order_lead_predict_factor); } vm_vec_sub(last_delta_vec, predicted_enemy_pos, &last_predicted_enemy_pos); last_predicted_enemy_pos= *predicted_enemy_pos; diff --git a/code/lab/manager/lab_manager.cpp b/code/lab/manager/lab_manager.cpp index 038785750b0..e60cab2e599 100644 --- a/code/lab/manager/lab_manager.cpp +++ b/code/lab/manager/lab_manager.cpp @@ -36,9 +36,6 @@ namespace ltp = lighting_profiles; LabManager::LabManager() { The_mission.Reset(); - if (The_mission.ai_profile == nullptr) - The_mission.ai_profile = &Ai_profiles[Default_ai_profile]; - Renderer.reset(new LabRenderer()); labUi = LabUi(); diff --git a/code/mission/mission_flags.h b/code/mission/mission_flags.h index 134d9398554..2f14938141a 100644 --- a/code/mission/mission_flags.h +++ b/code/mission/mission_flags.h @@ -38,7 +38,8 @@ namespace Mission { Preload_subspace, // Preload the subspace tunnel for both the sexp and specs checkbox (for scripts) - MjnMixael Large_ships_no_collide_by_default, // Automatically puts all large ships in a shared collision group Limited_support_rearm_pool, // Support ships can only rearm weapons while mission-level pool is available - MjnMixael - + Has_transient_ai_profile, // Runtime only: ai_profile_index refers to a per-mission copy that is removed on reset - Goober5000 + NUM_VALUES }; diff --git a/code/mission/missiongoals.cpp b/code/mission/missiongoals.cpp index 4d06525de1c..ca09d274d77 100644 --- a/code/mission/missiongoals.cpp +++ b/code/mission/missiongoals.cpp @@ -700,7 +700,7 @@ void multi_player_maybe_add_score (int score, int team) return; } - if (!(The_mission.ai_profile->flags[AI::Profile_Flags::Allow_multi_event_scoring])) { + if (!(The_mission.ai_profile()->flags[AI::Profile_Flags::Allow_multi_event_scoring])) { return; } diff --git a/code/mission/missionmessage.cpp b/code/mission/missionmessage.cpp index 5bd686668ab..90adc269719 100644 --- a/code/mission/missionmessage.cpp +++ b/code/mission/missionmessage.cpp @@ -1793,7 +1793,7 @@ void message_queue_process() goto all_done; } // G5K 4-26-20: Can't send messages if comm is destroyed - if ( The_mission.ai_profile->flags[AI::Profile_Flags::Check_comms_for_non_player_ships] && (provisional_message_shipnum >= 0) && hud_communications_state(&Ships[provisional_message_shipnum], (q->builtin_type == MESSAGE_WINGMAN_SCREAM)) == COMM_DESTROYED ) { + if ( The_mission.ai_profile()->flags[AI::Profile_Flags::Check_comms_for_non_player_ships] && (provisional_message_shipnum >= 0) && hud_communications_state(&Ships[provisional_message_shipnum], (q->builtin_type == MESSAGE_WINGMAN_SCREAM)) == COMM_DESTROYED ) { goto all_done; } @@ -2750,7 +2750,7 @@ int comm_between_player_and_ship(int other_shipnum, bool for_death_scream) int other_comm_state = hud_communications_state(&Ships[other_shipnum], for_death_scream); - if (The_mission.ai_profile->flags[AI::Profile_Flags::Check_comms_for_non_player_ships]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Check_comms_for_non_player_ships]) { return MIN(player_comm_state, other_comm_state); } diff --git a/code/mission/missionparse.cpp b/code/mission/missionparse.cpp index cccd93941ea..3371dc541db 100644 --- a/code/mission/missionparse.cpp +++ b/code/mission/missionparse.cpp @@ -427,7 +427,8 @@ flag_def_list_new Parse_mission_flags[] = { {"Full Nebula Background Bitmaps", Mission::Mission_Flags::Fullneb_background_bitmaps, true, true}, {"Preload Subspace Tunnel", Mission::Mission_Flags::Preload_subspace, true, false}, {"Large Ships Do Not Collide By Default", Mission::Mission_Flags::Large_ships_no_collide_by_default, true, false}, - {"Limit Support Rearm to Mission Pool", Mission::Mission_Flags::Limited_support_rearm_pool, true, true} + {"Limit Support Rearm to Mission Pool", Mission::Mission_Flags::Limited_support_rearm_pool, true, true}, + {"Has Transient AI Profile", Mission::Mission_Flags::Has_transient_ai_profile, false, false} }; parse_object_flag_description Parse_mission_flag_descriptions[] = { @@ -463,6 +464,7 @@ parse_object_flag_description Parse_mission_flag_descrip {Mission::Mission_Flags::Preload_subspace, "Preload the subspace tunnel for both the sexp and specs checkbox"}, {Mission::Mission_Flags::Large_ships_no_collide_by_default, "Automatically places all large ships in the configured collision group, preventing large ships from colliding with each other"}, {Mission::Mission_Flags::Limited_support_rearm_pool, "Support ships can only rearm from the mission weapon pool"}, + {Mission::Mission_Flags::Has_transient_ai_profile, "The mission is using a temporary copy of its AI profile"}, }; const size_t Num_parse_mission_flags = sizeof(Parse_mission_flags) / sizeof(flag_def_list_new); @@ -852,6 +854,7 @@ void parse_mission_info(mission *pm, bool basic = false) if (optional_string("+Flags:")){ stuff_flagset(&pm->flags); + mission_clear_inactive_flags(pm->flags); } // nebula mission stuff @@ -1107,7 +1110,7 @@ void parse_mission_info(mission *pm, bool basic = false) index = ai_profile_lookup(temp); if (index >= 0) - The_mission.ai_profile = &Ai_profiles[index]; + pm->ai_profile_index = index; else WarningEx(LOCATION, "Mission: %s\nUnknown AI profile %s!", pm->name.c_str(), temp ); } @@ -2442,7 +2445,7 @@ int parse_create_object_sub(p_object *p_objp, bool standalone_ship) aip->ai_class = p_objp->ai_class; shipp->weapons.ai_class = p_objp->ai_class; // Fred uses this instead of above. //Fixes a bug where the AI class attributes were not copied if the AI class was set in the mission. - if (The_mission.ai_profile->flags[AI::Profile_Flags::Fix_ai_class_bug]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_ai_class_bug]) ship_set_new_ai_class(shipp, p_objp->ai_class); aip->mode = AIM_NONE; @@ -6847,6 +6850,51 @@ void apply_default_custom_data(mission* pm) } } +// dates (YYYYMMDD) of the commits that changed how shot-down weapons explode, and of the commit that restored +// the retail rules behind the "consistent dinky shockwaves" flag +constexpr int ERA_DINKY_AREA_EFFECTS_START = 20051108; // area-effect weapons without a shockwave were reduced too +constexpr int ERA_BEAM_KILLS_START = 20161128; // weapons destroyed by beams began using the dinky shockwave +constexpr int ERA_MULTIPLIER_START = 20191217; // PR 2201 changed the default dinky multiplier to 1.0 +constexpr int ERA_DINKY_END = 20270201; // TODO: set to the merge date of the fix + +// missions balanced under earlier rules get a per-mission copy of their AI profile adjusted to match +static void mission_apply_era_adjustments() +{ + // a profile that mentions the flag knows the current rules + if (The_mission.ai_profile()->explicit_flags[AI::Profile_Flags::Consistent_dinky_shockwaves]) + return; + + int modified = mission_parse_date(The_mission.modified); + if (modified < 0) + { + mprintf(("Unable to parse modification date '%s'; no era adjustments will be applied\n", The_mission.modified)); + return; + } + + if (modified >= ERA_DINKY_END) + return; + + bool reduce_area_effects = (modified >= ERA_DINKY_AREA_EFFECTS_START); + bool beam_kills_shot_down = (modified >= ERA_BEAM_KILLS_START); + bool buggy_multiplier = (modified >= ERA_MULTIPLIER_START) && !Dinky_shockwave_default_multiplier_specified; + + if (!reduce_area_effects && !beam_kills_shot_down && !buggy_multiplier) + return; + + auto profile = mission_get_transient_ai_profile(); + if (reduce_area_effects) + profile->flags.set(AI::Profile_Flags::Era_reduce_shot_down_area_effects); + if (beam_kills_shot_down) + profile->flags.set(AI::Profile_Flags::Era_beam_kills_count_as_shot_down); + if (buggy_multiplier) + profile->dinky_shockwave_multiplier = 1.0f; + + mprintf(("Mission modified %s; applying era adjustments:%s%s%s\n", The_mission.modified, + reduce_area_effects ? " reduce-area-effects" : "", + beam_kills_shot_down ? " beam-kills-count-as-shot-down" : "", + buggy_multiplier ? " multiplier-1.0" : "")); +} + bool parse_mission(mission *pm, int flags) { int saved_warning_count = Global_warning_count; @@ -6873,6 +6921,10 @@ bool parse_mission(mission *pm, int flags) if (flags & MPF_ONLY_MISSION_INFO) return true; + // must happen before anything copies values from the AI profile + if (!Fred_running) + mission_apply_era_adjustments(); + parse_plot_info(pm); parse_variables(); parse_sexp_containers(); @@ -7320,6 +7372,13 @@ int get_mission_info(const char *filename, mission *mission_p, bool basic, bool void mission::Reset() { + // must happen before flags are cleared + if (flags[Mission::Mission_Flags::Has_transient_ai_profile]) + { + Assertion(ai_profile_index == sz2i(Ai_profiles.size()) - 1, "The transient AI profile must be the last profile in the list!"); + Ai_profiles.pop_back(); + } + name.clear(); author.clear(); required_fso_version = LEGACY_MISSION_VERSION; @@ -7362,7 +7421,7 @@ void mission::Reset() substitute_event_music_name[ 0 ] = '\0'; substitute_briefing_music_name[ 0 ] = '\0'; - ai_profile = &Ai_profiles[Default_ai_profile]; + ai_profile_index = Default_ai_profile; lighting_profile_name = lighting_profiles::default_name(); cutscenes.clear( ); @@ -7377,6 +7436,50 @@ void mission::Reset() fred_layers.emplace_back("Default"); } +ai_profile_t *mission_get_transient_ai_profile() +{ + Assertion(!Fred_running, "Transient AI profiles should only be created in-game!"); + + if (!The_mission.flags[Mission::Mission_Flags::Has_transient_ai_profile]) + { + Ai_profiles.emplace_back(); + Ai_profiles.back() = Ai_profiles[The_mission.ai_profile_index]; + + The_mission.ai_profile_index = sz2i(Ai_profiles.size()) - 1; + The_mission.flags.set(Mission::Mission_Flags::Has_transient_ai_profile); + } + + return &Ai_profiles[The_mission.ai_profile_index]; +} + +int mission_parse_date(const char *date) +{ + int month, day, year; + + // FRED writes dates with strftime's %x, which in the C locale is MM/DD/YY + if (sscanf(date, "%d/%d/%d", &month, &day, &year) != 3) + return -1; + + if (month < 1 || month > 12 || day < 1 || day > 31 || year < 0) + return -1; + + if (year < 70) + year += 2000; + else if (year < 100) + year += 1900; + + return year * 10000 + month * 100 + day; +} + +void mission_clear_inactive_flags(flagset &flags) +{ + for (const auto &parse_mission_flag : Parse_mission_flags) + { + if (!parse_mission_flag.in_use) + flags.remove(parse_mission_flag.def); + } +} + void support_ship_info::reset() { arrival_location = ArrivalLocation::AT_LOCATION; diff --git a/code/mission/missionparse.h b/code/mission/missionparse.h index bc6765b6b4f..0a5ae4ec9e6 100644 --- a/code/mission/missionparse.h +++ b/code/mission/missionparse.h @@ -240,7 +240,8 @@ typedef struct mission { char substitute_briefing_music_name[NAME_LENGTH]; // Goober5000 - ai_profile_t *ai_profile; + int ai_profile_index; + const ai_profile_t *ai_profile() const { return &Ai_profiles[ai_profile_index]; } SCP_string lighting_profile_name; @@ -615,6 +616,16 @@ extern char Neb2_texture_name[MAX_FILENAME_LEN]; void mission_init(mission *pm, bool quick_init = false); + +// returns a copy of the mission's AI profile that can be modified for the rest of the mission +ai_profile_t *mission_get_transient_ai_profile(); + +// returns a mission's $Created: or $Modified: date as YYYYMMDD, or -1 if it can't be parsed +int mission_parse_date(const char *date); + +// removes flags that are inactive or meaningful only at runtime +void mission_clear_inactive_flags(flagset &flags); + bool parse_main(const char *mission_name, int flags = 0); p_object *mission_parse_get_arrival_ship(ushort net_signature); p_object *mission_parse_get_arrival_ship(const char *name); diff --git a/code/missioneditor/missionsave.cpp b/code/missioneditor/missionsave.cpp index 6f57eba347f..44b2c01d2fe 100644 --- a/code/missioneditor/missionsave.cpp +++ b/code/missioneditor/missionsave.cpp @@ -2566,7 +2566,9 @@ int Fred_mission_save::save_mission_info() fout("\n+Flags:"); } - fout(" " UINT64_T_ARG, The_mission.flags.to_u64()); + auto mission_flags = The_mission.flags; + mission_clear_inactive_flags(mission_flags); + fout(" " UINT64_T_ARG, mission_flags.to_u64()); // maybe write out Nebula values if (The_mission.flags[Mission::Mission_Flags::Fullneb]) { @@ -3102,15 +3104,14 @@ int Fred_mission_save::save_mission_info() } // Goober5000's AI profile stuff - int profile_index = AI_PROFILES_INDEX(The_mission.ai_profile); - Assert(profile_index >= 0 && profile_index < MAX_AI_PROFILES); + Assertion(Ai_profiles.in_bounds(The_mission.ai_profile_index), "Mission AI profile index %d is out of range!", The_mission.ai_profile_index); fso_comment_push(";;FSO 3.6.9;;"); if (optional_string_fred("$AI Profile:")) { parse_comments(2); - fout(" %s", The_mission.ai_profile->profile_name); + fout(" %s", The_mission.ai_profile()->profile_name); } else { - fout_version("\n\n$AI Profile: %s", The_mission.ai_profile->profile_name); + fout_version("\n\n$AI Profile: %s", The_mission.ai_profile()->profile_name); } fso_comment_pop(); diff --git a/code/mod_table/mod_table.cpp b/code/mod_table/mod_table.cpp index 2ca750af08c..cf472c9d2c7 100644 --- a/code/mod_table/mod_table.cpp +++ b/code/mod_table/mod_table.cpp @@ -94,6 +94,7 @@ bool Disable_built_in_translations; bool Weapon_shockwaves_respect_huge; bool Using_in_game_options; float Dinky_shockwave_default_multiplier; +bool Dinky_shockwave_default_multiplier_specified; bool Shockwaves_always_damage_bombs; bool Shockwaves_damage_all_obj_types_once; bool Shockwaves_inherit_parent_damage_type; @@ -1320,6 +1321,7 @@ void parse_mod_table(const char *filename) if (optional_string("$Dinky Shockwave Default Multiplier:")) { stuff_float(&Dinky_shockwave_default_multiplier); + Dinky_shockwave_default_multiplier_specified = true; } if (optional_string("$Shockwaves Always Damage Bombs:")) { @@ -1724,7 +1726,7 @@ static void mod_table_log_settings() else mprintf(("Game Settings Table: Not using in-game options system.\n")); - mprintf(("Game Settings Table: Default dinky shockwave multiplier is %.2f\n", Dinky_shockwave_default_multiplier)); + mprintf(("Game Settings Table: Default dinky shockwave multiplier is %.2f (%s)\n", Dinky_shockwave_default_multiplier, Dinky_shockwave_default_multiplier_specified ? "from table" : "engine default")); if (Shockwaves_always_damage_bombs) mprintf(("Game Settings Table: Shockwaves always damage bombs\n")); @@ -1922,7 +1924,8 @@ void mod_table_reset() Disable_built_in_translations = false; Weapon_shockwaves_respect_huge = false; Using_in_game_options = true; - Dinky_shockwave_default_multiplier = 1.0f; + Dinky_shockwave_default_multiplier = 0.25f; + Dinky_shockwave_default_multiplier_specified = false; Shockwaves_always_damage_bombs = false; Shockwaves_damage_all_obj_types_once = false; Shockwaves_inherit_parent_damage_type = false; diff --git a/code/mod_table/mod_table.h b/code/mod_table/mod_table.h index d502f96098b..9f4ba52315d 100644 --- a/code/mod_table/mod_table.h +++ b/code/mod_table/mod_table.h @@ -113,6 +113,7 @@ extern bool Disable_built_in_translations; extern bool Weapon_shockwaves_respect_huge; extern bool Using_in_game_options; extern float Dinky_shockwave_default_multiplier; +extern bool Dinky_shockwave_default_multiplier_specified; extern bool Shockwaves_always_damage_bombs; extern bool Shockwaves_damage_all_obj_types_once; extern bool Shockwaves_inherit_parent_damage_type; diff --git a/code/model/modelrender.cpp b/code/model/modelrender.cpp index a9a772cf652..ae76fc78d74 100644 --- a/code/model/modelrender.cpp +++ b/code/model/modelrender.cpp @@ -911,19 +911,19 @@ float model_render_determine_depth(int obj_num, int model_num, const matrix* ori if ( detail_level_locked < 0 ) { switch (Detail.detail_distance) { case 0: // lowest - depth /= The_mission.ai_profile->detail_distance_mult[0]; + depth /= The_mission.ai_profile()->detail_distance_mult[0]; break; case 1: // lower than normal - depth /= The_mission.ai_profile->detail_distance_mult[1]; + depth /= The_mission.ai_profile()->detail_distance_mult[1]; break; case 2: // default - depth /= The_mission.ai_profile->detail_distance_mult[2]; + depth /= The_mission.ai_profile()->detail_distance_mult[2]; break; case 3: // above normal - depth /= The_mission.ai_profile->detail_distance_mult[3]; + depth /= The_mission.ai_profile()->detail_distance_mult[3]; break; case 4: // even more normal - depth /= The_mission.ai_profile->detail_distance_mult[4]; + depth /= The_mission.ai_profile()->detail_distance_mult[4]; break; } diff --git a/code/network/multiteamselect.cpp b/code/network/multiteamselect.cpp index e1a3f87b627..66b5577b7ca 100644 --- a/code/network/multiteamselect.cpp +++ b/code/network/multiteamselect.cpp @@ -2731,12 +2731,12 @@ int multi_ts_ok_to_commit() } // if the ship doesn't have primary weapons - if (!primary_ok && !(The_mission.ai_profile->flags[AI::Profile_Flags::Multi_allow_empty_secondaries])) { + if (!primary_ok && !(The_mission.ai_profile()->flags[AI::Profile_Flags::Multi_allow_empty_secondaries])) { return 2; } // if the ship doesn't have secondary weapons - if (!secondary_ok && !(The_mission.ai_profile->flags[AI::Profile_Flags::Multi_allow_empty_secondaries])) { + if (!secondary_ok && !(The_mission.ai_profile()->flags[AI::Profile_Flags::Multi_allow_empty_secondaries])) { return 3; } } diff --git a/code/object/collidedebrisship.cpp b/code/object/collidedebrisship.cpp index fa7c340410a..db725aee4cc 100644 --- a/code/object/collidedebrisship.cpp +++ b/code/object/collidedebrisship.cpp @@ -132,7 +132,7 @@ int collide_debris_ship( obj_pair * pair ) } if (Ship_info[shipp->ship_info_index].flags[Ship::Info_Flags::Big_damage] && - The_mission.ai_profile->flags[AI::Profile_Flags::Debris_respects_big_damage]) { + The_mission.ai_profile()->flags[AI::Profile_Flags::Debris_respects_big_damage]) { // scale based on hull float hull_pct = ship_objp->hull_strength / shipp->ship_max_hull_strength; @@ -153,7 +153,7 @@ int collide_debris_ship( obj_pair * pair ) if ( debris_hit_info.heavy == ship_objp) { int quadrant_num = get_ship_quadrant_from_global(&hitpos, ship_objp); - if (The_mission.ai_profile->flags[AI::Profile_Flags::No_shield_damage_from_ship_collisions] || + if (The_mission.ai_profile()->flags[AI::Profile_Flags::No_shield_damage_from_ship_collisions] || (ship_objp->flags[Object::Object_Flags::No_shields]) || !ship_is_shield_up(ship_objp, quadrant_num) ) { quadrant_num = -1; } @@ -344,7 +344,7 @@ int collide_asteroid_ship( obj_pair * pair ) if ( asteroid_hit_info.heavy == ship_objp) { int quadrant_num = get_ship_quadrant_from_global(&hitpos, ship_objp); - if (The_mission.ai_profile->flags[AI::Profile_Flags::No_shield_damage_from_ship_collisions] || + if (The_mission.ai_profile()->flags[AI::Profile_Flags::No_shield_damage_from_ship_collisions] || (ship_objp->flags[Object::Object_Flags::No_shields]) || !ship_is_shield_up(ship_objp, quadrant_num) ) { quadrant_num = -1; } diff --git a/code/object/collideshipship.cpp b/code/object/collideshipship.cpp index 4ad05b0eb0b..9ccaf2c7827 100644 --- a/code/object/collideshipship.cpp +++ b/code/object/collideshipship.cpp @@ -705,7 +705,7 @@ void calculate_ship_ship_collision_physics(collision_info_struct *ship_ship_hit_ vm_vec_rotate(&delta_rotvel_heavy, &rotational_impulse_heavy, &heavy_I_inv); float rotation_factor_heavy = (heavy->type == OBJ_SHIP) ? heavy_sip->collision_physics.rotation_factor : COLLISION_ROTATION_FACTOR; if (heavy == Player_obj) { - rotation_factor_heavy *= The_mission.ai_profile->rot_fac_multiplier_ply_collisions; + rotation_factor_heavy *= The_mission.ai_profile()->rot_fac_multiplier_ply_collisions; } vm_vec_scale(&delta_rotvel_heavy, rotation_factor_heavy); // hack decrease rotation (delta_rotvel) vm_vec_cross(&delta_vel_from_delta_rotvel_heavy, &delta_rotvel_heavy , &ship_ship_hit_info->r_heavy); @@ -731,7 +731,7 @@ void calculate_ship_ship_collision_physics(collision_info_struct *ship_ship_hit_ // when trying to do AI landings for certain ships rotation_factor_light *= 0.0f; } else if (lighter == Player_obj) { - rotation_factor_light *= The_mission.ai_profile->rot_fac_multiplier_ply_collisions; + rotation_factor_light *= The_mission.ai_profile()->rot_fac_multiplier_ply_collisions; } vm_vec_scale(&delta_rotvel_light, rotation_factor_light); // hack decrease rotation (delta_rotvel) vm_vec_cross(&delta_vel_from_delta_rotvel_light, &delta_rotvel_light, &ship_ship_hit_info->r_light); @@ -1384,7 +1384,7 @@ void collide_ship_ship_process(obj_pair * pair, const std::any& collision_data) } int quadrant_num = -1; - if (!The_mission.ai_profile->flags[AI::Profile_Flags::No_shield_damage_from_ship_collisions] && !(ship_ship_hit_info.heavy->flags[Object::Object_Flags::No_shields])) { + if (!The_mission.ai_profile()->flags[AI::Profile_Flags::No_shield_damage_from_ship_collisions] && !(ship_ship_hit_info.heavy->flags[Object::Object_Flags::No_shields])) { quadrant_num = get_ship_quadrant_from_global(&world_hit_pos, ship_ship_hit_info.heavy); if (!ship_is_shield_up(ship_ship_hit_info.heavy, quadrant_num)) quadrant_num = -1; diff --git a/code/object/collideshipweapon.cpp b/code/object/collideshipweapon.cpp index c06d08dc192..4efd7839cc9 100644 --- a/code/object/collideshipweapon.cpp +++ b/code/object/collideshipweapon.cpp @@ -123,12 +123,12 @@ static void ship_weapon_do_hit_stuff(object *pship_obj, object *weapon_obj, cons // if this is friendly fire, we check for the friendly fire cap values if (wp->team == shipp->team) { - if (&Objects[weapon_obj->parent] == pship_obj && The_mission.ai_profile->weapon_self_damage_cap[Game_skill_level] >= 0.f) { + if (&Objects[weapon_obj->parent] == pship_obj && The_mission.ai_profile()->weapon_self_damage_cap[Game_skill_level] >= 0.f) { // if this is a ship shooting itself, we use the self damage cap - damage = MIN(damage, The_mission.ai_profile->weapon_self_damage_cap[Game_skill_level]); - } else if (The_mission.ai_profile->weapon_friendly_damage_cap[Game_skill_level] >= 0.f) { + damage = MIN(damage, The_mission.ai_profile()->weapon_self_damage_cap[Game_skill_level]); + } else if (The_mission.ai_profile()->weapon_friendly_damage_cap[Game_skill_level] >= 0.f) { // otherwise we use the friendly damage cap - damage = MIN(damage, The_mission.ai_profile->weapon_friendly_damage_cap[Game_skill_level]); + damage = MIN(damage, The_mission.ai_profile()->weapon_friendly_damage_cap[Game_skill_level]); } } @@ -235,7 +235,7 @@ static std::tuple ship_weapon_check_coll vec3d weapon_start_pos = weapon_objp->last_pos; // Maybe take into account the ship's velocity, so it won't later overstep the weapon's // current position (what will be its last_pos next frame) - if (The_mission.ai_profile->flags[AI::Profile_Flags::Fixed_ship_weapon_collision]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Fixed_ship_weapon_collision]) weapon_start_pos += ship_objp->phys_info.vel * flFrametime; if (!IS_VEC_NULL(&The_mission.gravity) && wip->gravity_const != 0.0f) { @@ -466,7 +466,7 @@ static std::tuple ship_weapon_check_coll // 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)) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_AI_shield_management_bug] && SCP_vector_inbounds(ship_objp->shield_quadrant, quadrant_num)) { notify_ai_shield_down = quadrant_num; } quadrant_num = -1; diff --git a/code/object/collideweaponweapon.cpp b/code/object/collideweaponweapon.cpp index 04e49bec114..dac03e3cf40 100644 --- a/code/object/collideweaponweapon.cpp +++ b/code/object/collideweaponweapon.cpp @@ -69,14 +69,14 @@ int collide_weapon_weapon( obj_pair * pair ) // the erroneous extra time a bomb stays invulnerable without the fix float extra_buggy_time = 0.0f; - if (!(The_mission.ai_profile->flags[AI::Profile_Flags::Aspect_invulnerability_fix]) && wipA->is_locked_homing()) + if (!(The_mission.ai_profile()->flags[AI::Profile_Flags::Aspect_invulnerability_fix]) && wipA->is_locked_homing()) extra_buggy_time = (wipA->lifetime * LOCKED_HOMING_EXTENDED_LIFE_FACTOR) - wipA->lifetime; - if ((The_mission.ai_profile->flags[AI::Profile_Flags::Aspect_invulnerability_fix]) && (wipA->is_locked_homing()) && (wpA->homing_object != &obj_used_list)) { - if (A_time_alive < The_mission.ai_profile->delay_bomb_arm_timer[Game_skill_level] ) + if ((The_mission.ai_profile()->flags[AI::Profile_Flags::Aspect_invulnerability_fix]) && (wipA->is_locked_homing()) && (wpA->homing_object != &obj_used_list)) { + if (A_time_alive < The_mission.ai_profile()->delay_bomb_arm_timer[Game_skill_level] ) return 0; } - else if (A_time_alive - extra_buggy_time < The_mission.ai_profile->delay_bomb_arm_timer[Game_skill_level] ) + else if (A_time_alive - extra_buggy_time < The_mission.ai_profile()->delay_bomb_arm_timer[Game_skill_level] ) return 0; } @@ -87,14 +87,14 @@ int collide_weapon_weapon( obj_pair * pair ) // the erroneous extra time a bomb stays invulnerable without the fix float extra_buggy_time = 0.0f; - if (!(The_mission.ai_profile->flags[AI::Profile_Flags::Aspect_invulnerability_fix]) && wipB->is_locked_homing()) + if (!(The_mission.ai_profile()->flags[AI::Profile_Flags::Aspect_invulnerability_fix]) && wipB->is_locked_homing()) extra_buggy_time = (wipB->lifetime * LOCKED_HOMING_EXTENDED_LIFE_FACTOR) - wipB->lifetime; - if ((The_mission.ai_profile->flags[AI::Profile_Flags::Aspect_invulnerability_fix]) && (wipB->is_locked_homing()) && (wpB->homing_object != &obj_used_list)) { - if (B_time_alive < The_mission.ai_profile->delay_bomb_arm_timer[Game_skill_level] ) + if ((The_mission.ai_profile()->flags[AI::Profile_Flags::Aspect_invulnerability_fix]) && (wipB->is_locked_homing()) && (wpB->homing_object != &obj_used_list)) { + if (B_time_alive < The_mission.ai_profile()->delay_bomb_arm_timer[Game_skill_level] ) return 0; } - else if (B_time_alive - extra_buggy_time < The_mission.ai_profile->delay_bomb_arm_timer[Game_skill_level] ) + else if (B_time_alive - extra_buggy_time < The_mission.ai_profile()->delay_bomb_arm_timer[Game_skill_level] ) return 0; } diff --git a/code/parse/sexp.cpp b/code/parse/sexp.cpp index 2ac42ba0db2..c41a74b911d 100644 --- a/code/parse/sexp.cpp +++ b/code/parse/sexp.cpp @@ -4232,7 +4232,7 @@ int check_sexp_potential_issues(int node, int *bad_node, SCP_string &issue_msg) case OP_IS_DESTROYED: case OP_TIME_WING_DESTROYED: { - if (!The_mission.ai_profile->flags[AI::Profile_Flags::Cancel_future_waves_of_any_wing_launched_from_an_exited_ship]) + if (!The_mission.ai_profile()->flags[AI::Profile_Flags::Cancel_future_waves_of_any_wing_launched_from_an_exited_ship]) { for (int n = first_arg_node; n >= 0; n = CDR(n)) { @@ -13938,7 +13938,7 @@ void sexp_player_use_ai(bool use_ai) void sexp_set_friendly_damage_caps(int n) { bool is_nan; bool is_nan_forever; - ai_profile_t& aip = *The_mission.ai_profile; + ai_profile_t& aip = *mission_get_transient_ai_profile(); float beam_friendly_cap = i2fl(eval_num(n, is_nan, is_nan_forever)); if (!is_nan && !is_nan_forever) { diff --git a/code/physics/physics.cpp b/code/physics/physics.cpp index 639313f7ea1..da2a128c397 100644 --- a/code/physics/physics.cpp +++ b/code/physics/physics.cpp @@ -755,7 +755,7 @@ void physics_read_flying_controls( matrix * orient, physics_info * pi, control_i // Only do the glide cap if we have one and are actively thrusting in some direction. // Unless AIPF2_GLIDE_DECAY_REQUIRES_THRUST isn't set. -MageKing17 - if ( curGlideCap >= 0.0f && (!(The_mission.ai_profile->flags[AI::Profile_Flags::Glide_decay_requires_thrust]) || ci->forward != 0.0f || ci->sideways != 0.0f || ci->vertical != 0.0f) ) { + if ( curGlideCap >= 0.0f && (!(The_mission.ai_profile()->flags[AI::Profile_Flags::Glide_decay_requires_thrust]) || ci->forward != 0.0f || ci->sideways != 0.0f || ci->vertical != 0.0f) ) { float currentmag = vm_vec_mag(&pi->desired_vel); if ( currentmag > curGlideCap ) { vm_vec_scale( &pi->desired_vel, curGlideCap / currentmag ); @@ -783,7 +783,7 @@ void physics_maybe_reset_speed_after_whack(physics_info *pi, const vec3d *previo // for release builds SCP_UNUSED(source); - if (pi->flags & PF_USE_VEL || The_mission.ai_profile->flags[AI::Profile_Flags::Dont_limit_change_in_speed_due_to_physics_whack]) + if (pi->flags & PF_USE_VEL || The_mission.ai_profile()->flags[AI::Profile_Flags::Dont_limit_change_in_speed_due_to_physics_whack]) return; vec3d delta_vel = pi->vel - *previous_vel; diff --git a/code/scripting/api/objs/ship.cpp b/code/scripting/api/objs/ship.cpp index 755baf86358..3a612f77094 100644 --- a/code/scripting/api/objs/ship.cpp +++ b/code/scripting/api/objs/ship.cpp @@ -1891,7 +1891,7 @@ ADE_FUNC(giveOrder, l_Ship, "enumeration Order /* ORDER_* */, [object Target=nil ai_submode = 0; if (omitted_priority) - priority = The_mission.ai_profile->default_form_on_wing_priority / 100.0f; + priority = The_mission.ai_profile()->default_form_on_wing_priority / 100.0f; } break; } diff --git a/code/ship/afterburner.cpp b/code/ship/afterburner.cpp index 2860e61769f..4a99bd5fdd9 100644 --- a/code/ship/afterburner.cpp +++ b/code/ship/afterburner.cpp @@ -235,7 +235,7 @@ void afterburners_update(object *objp, float fl_frametime) if ( shipp->afterburner_fuel < sip->afterburner_fuel_capacity ) { float recharge_scale; - recharge_scale = ets_power_factor(objp) * Energy_levels[shipp->engine_recharge_index] * 2.0f * The_mission.ai_profile->afterburner_recharge_scale[Game_skill_level]; + recharge_scale = ets_power_factor(objp) * Energy_levels[shipp->engine_recharge_index] * 2.0f * The_mission.ai_profile()->afterburner_recharge_scale[Game_skill_level]; shipp->afterburner_fuel += (sip->afterburner_recover_rate * fl_frametime * recharge_scale); if ( shipp->afterburner_fuel > sip->afterburner_fuel_capacity){ diff --git a/code/ship/ship.cpp b/code/ship/ship.cpp index 123ba8783b4..d1a773fae64 100644 --- a/code/ship/ship.cpp +++ b/code/ship/ship.cpp @@ -6775,7 +6775,7 @@ void physics_ship_init(object *objp) pi->glide_accel_mult = sinfo->glide_accel_mult; //SUSHI: This defaults to the AI_Profile value, and is only optionally overridden - if (The_mission.ai_profile->flags[AI::Profile_Flags::Use_newtonian_dampening]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Use_newtonian_dampening]) pi->flags |= PF_NEWTONIAN_DAMP; if (sinfo->newtonian_damp_override) { @@ -7882,9 +7882,9 @@ static int subsys_set(int objnum, int ignore_subsys_info) // Wanderer if (model_system->flags[Model::Subsystem_Flags::No_ss_targeting]) ship_system->flags.set(Ship::Subsystem_Flags::No_SS_targeting); - if ((The_mission.ai_profile->flags[AI::Profile_Flags::Advanced_turret_fov_edge_checks]) || (model_system->flags[Model::Subsystem_Flags::Fov_edge_check])) + if ((The_mission.ai_profile()->flags[AI::Profile_Flags::Advanced_turret_fov_edge_checks]) || (model_system->flags[Model::Subsystem_Flags::Fov_edge_check])) ship_system->flags.set(Ship::Subsystem_Flags::FOV_edge_check); - if ((The_mission.ai_profile->flags[AI::Profile_Flags::Require_turret_to_have_target_in_fov]) || (model_system->flags[Model::Subsystem_Flags::Fov_required])) + if ((The_mission.ai_profile()->flags[AI::Profile_Flags::Require_turret_to_have_target_in_fov]) || (model_system->flags[Model::Subsystem_Flags::Fov_required])) ship_system->flags.set(Ship::Subsystem_Flags::FOV_Required); if (model_system->flags[Model::Subsystem_Flags::No_replace]) @@ -9169,7 +9169,7 @@ void ship_cleanup(int shipnum, int cleanup_mode) } // maybe clean up any wings that arrived from this ship - if (The_mission.ai_profile->flags[AI::Profile_Flags::Cancel_future_waves_of_any_wing_launched_from_an_exited_ship]) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Cancel_future_waves_of_any_wing_launched_from_an_exited_ship]) { for (int child_wingnum = 0; child_wingnum < Num_wings; ++child_wingnum) { auto child_wingp = &Wings[child_wingnum]; if (child_wingp->arrival_location == ArrivalLocation::FROM_DOCK_BAY && child_wingp->arrival_anchor.value() == entry_index) { @@ -12878,14 +12878,14 @@ bool in_autoaim_fov(ship *shipp, int bank_to_fire, object *obj) const bool autoaim_convergence_flagged = ((sip->aiming_flags[Object::Aiming_Flags::Autoaim_convergence]) || (winfo_p->aiming_flags[Object::Aiming_Flags::Autoaim_convergence])); // Now check that we have a target and an FOV value - has_converging_autoaim = ((autoaim_convergence_flagged || (The_mission.ai_profile->player_autoaim_fov[Game_skill_level] > 0.0f && !( Game_mode & GM_MULTIPLAYER ))) && aip->target_objnum != -1); + has_converging_autoaim = ((autoaim_convergence_flagged || (The_mission.ai_profile()->player_autoaim_fov[Game_skill_level] > 0.0f && !( Game_mode & GM_MULTIPLAYER ))) && aip->target_objnum != -1); has_autoaim = ((autoaim_flagged || has_converging_autoaim || (sip->bank_autoaim_fov[bank_to_fire] > 0.0f)) && aip->target_objnum != -1); if (!has_autoaim) { return false; } - autoaim_fov = std::max({shipp->autoaim_fov, The_mission.ai_profile->player_autoaim_fov[Game_skill_level], winfo_p->autoaim_fov, sip->bank_autoaim_fov[bank_to_fire]}); + autoaim_fov = std::max({shipp->autoaim_fov, The_mission.ai_profile()->player_autoaim_fov[Game_skill_level], winfo_p->autoaim_fov, sip->bank_autoaim_fov[bank_to_fire]}); if (aip->targeted_subsys != nullptr) { get_subsystem_world_pos(&Objects[aip->target_objnum], aip->targeted_subsys, &target_position); @@ -13087,14 +13087,14 @@ int ship_fire_primary(object * obj, int force, bool rollback_shot) const bool auto_convergence_flagged = ((sip->aiming_flags[Object::Aiming_Flags::Auto_convergence]) || (winfo_p->aiming_flags[Object::Aiming_Flags::Auto_convergence])); // Now add in other checks like difficulty and game mode as appropriate. Also make sure we have a target and an FOV if necessary. - has_converging_autoaim = ((autoaim_convergence_flagged || (The_mission.ai_profile->player_autoaim_fov[Game_skill_level] > 0.0f && !( Game_mode & GM_MULTIPLAYER ))) && aip->target_objnum != -1); + has_converging_autoaim = ((autoaim_convergence_flagged || (The_mission.ai_profile()->player_autoaim_fov[Game_skill_level] > 0.0f && !( Game_mode & GM_MULTIPLAYER ))) && aip->target_objnum != -1); has_autoaim = ((autoaim_flagged || has_converging_autoaim || (sip->bank_autoaim_fov[bank_to_fire] > 0.0f)) && aip->target_objnum != -1); needs_target_pos = ((auto_convergence_flagged || has_autoaim) && aip->target_objnum != -1); // TODO: check if weapon has launch curves that might need distance to enemy if (needs_target_pos) { if (has_autoaim) { - autoaim_fov = std::max({shipp->autoaim_fov, The_mission.ai_profile->player_autoaim_fov[Game_skill_level], winfo_p->autoaim_fov, sip->bank_autoaim_fov[bank_to_fire]}); + autoaim_fov = std::max({shipp->autoaim_fov, The_mission.ai_profile()->player_autoaim_fov[Game_skill_level], winfo_p->autoaim_fov, sip->bank_autoaim_fov[bank_to_fire]}); } // If a subsystem is targeted, fire in that direction instead @@ -13110,7 +13110,7 @@ int ship_fire_primary(object * obj, int force, bool rollback_shot) dist_to_target = vm_vec_dist_quick(&target_position, &obj->pos); target_velocity_vec = Objects[aip->target_objnum].phys_info.vel; - if (The_mission.ai_profile->flags[AI::Profile_Flags::Use_additive_weapon_velocity]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Use_additive_weapon_velocity]) vm_vec_scale_sub2(&target_velocity_vec, &obj->phys_info.vel, winfo_p->vel_inherit_amount); } @@ -13213,7 +13213,7 @@ int ship_fire_primary(object * obj, int force, bool rollback_shot) } // Goober5000 (thanks to _argv[-1] for the original idea) - if ( (num_primary_banks > 1) && !(winfo_p->wi_flags[Weapon::Info_Flags::No_linked_penalty]) && !(The_mission.ai_profile->flags[AI::Profile_Flags::Disable_linked_fire_penalty]) ) + if ( (num_primary_banks > 1) && !(winfo_p->wi_flags[Weapon::Info_Flags::No_linked_penalty]) && !(The_mission.ai_profile()->flags[AI::Profile_Flags::Disable_linked_fire_penalty]) ) { int effective_primary_banks = 0; for (int it = 0; it < num_primary_banks; it++) @@ -14104,12 +14104,12 @@ bool ship_secondary_bank_can_dual_fire(const ship *shipp, int bank) // use the flag, not Player_obj, for multiplayer correctness if (shipp->objnum >= 0 && Objects[shipp->objnum].flags[Object::Object_Flags::Player_ship]) { - if (The_mission.ai_profile->flags[AI::Profile_Flags::Disable_player_secondary_doublefire]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Disable_player_secondary_doublefire]) return false; } else { - if (The_mission.ai_profile->flags[AI::Profile_Flags::Disable_ai_secondary_doublefire]) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Disable_ai_secondary_doublefire]) return false; } @@ -15080,7 +15080,7 @@ int get_available_secondary_weapons(object *objp, int *outlist, int *outbanklist float target_range, weapon_range_max, weapon_range_min; target_range = 0.0f; - if (The_mission.ai_profile->ai_range_aware_secondary_select_mode!= AI_RANGE_AWARE_SEC_SEL_MODE_RETAIL) { + if (The_mission.ai_profile()->ai_range_aware_secondary_select_mode!= AI_RANGE_AWARE_SEC_SEL_MODE_RETAIL) { vec3d our_position = objp->pos; vec3d target_position; object *target = &Objects[Ai_info[shipp->ai_index].target_objnum]; @@ -15102,7 +15102,7 @@ int get_available_secondary_weapons(object *objp, int *outlist, int *outbanklist } for (i=0; iweapons.num_secondary_banks; i++) if (ship_secondary_has_ammo(&shipp->weapons, i)) { - if (The_mission.ai_profile->ai_range_aware_secondary_select_mode != AI_RANGE_AWARE_SEC_SEL_MODE_RETAIL) { + if (The_mission.ai_profile()->ai_range_aware_secondary_select_mode != AI_RANGE_AWARE_SEC_SEL_MODE_RETAIL) { wepp = &Weapon_info[shipp->weapons.secondary_bank_weapons[i]]; weapon_range_min = wepp->weapon_min_range; weapon_range_max = wepp->weapon_range; @@ -17264,7 +17264,7 @@ int ship_get_random_player_wing_ship( int flags, float max_dist, int persona_ind if (flags == SHIP_GET_UNSILENCED) { if (Ships[ship_index].flags[Ship_Flags::No_builtin_messages]) continue; - if (The_mission.ai_profile->flags[AI::Profile_Flags::Check_comms_for_non_player_ships] && hud_communications_state(&Ships[ship_index]) <= COMM_DAMAGED) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Check_comms_for_non_player_ships] && hud_communications_state(&Ships[ship_index]) <= COMM_DAMAGED) continue; } @@ -17500,7 +17500,7 @@ int ship_engine_ok_to_warp(ship *sp) int ship_navigation_ok_to_warp(ship *sp) { // if not using the special flag, warp is always allowed - if (!(The_mission.ai_profile->flags[AI::Profile_Flags::Navigation_subsys_governs_warp])) + if (!(The_mission.ai_profile()->flags[AI::Profile_Flags::Navigation_subsys_governs_warp])) return 1; float navigation_strength = ship_get_subsystem_strength(sp, SUBSYSTEM_NAVIGATION); @@ -18468,7 +18468,7 @@ void ship_maybe_praise_self(ship *deader_sp, ship *killer_sp) if ( killer_sp->flags[Ship_Flags::No_builtin_messages] ) { return; } - if (The_mission.ai_profile->flags[AI::Profile_Flags::Check_comms_for_non_player_ships] && hud_communications_state(killer_sp) != COMM_OK) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Check_comms_for_non_player_ships] && hud_communications_state(killer_sp) != COMM_OK) { return; } @@ -18576,7 +18576,7 @@ void ship_maybe_ask_for_help(ship* sp, ship* attacker) return; } - if (The_mission.ai_profile->flags[AI::Profile_Flags::Check_comms_for_non_player_ships] && hud_communications_state(&Ships[objp->instance]) <= COMM_DAMAGED) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Check_comms_for_non_player_ships] && hud_communications_state(&Ships[objp->instance]) <= COMM_DAMAGED) { return; } @@ -18629,7 +18629,7 @@ void ship_scream(ship *sp) // Bail if the ship is silenced if (sp->flags[Ship_Flags::No_builtin_messages]) return; - if (The_mission.ai_profile->flags[AI::Profile_Flags::Check_comms_for_non_player_ships] && hud_communications_state(sp, true) <= COMM_DAMAGED) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Check_comms_for_non_player_ships] && hud_communications_state(sp, true) <= COMM_DAMAGED) return; if (message_send_builtin(MESSAGE_WINGMAN_SCREAM, sp, nullptr, -1, multi_team_filter)) { @@ -18661,7 +18661,7 @@ void ship_maybe_scream(ship *sp) return; // for WCSaga, only do a subset of the checks - if (!(The_mission.ai_profile->flags[AI::Profile_Flags::Perform_fewer_scream_checks])) + if (!(The_mission.ai_profile()->flags[AI::Profile_Flags::Perform_fewer_scream_checks])) { // bail if this ship isn't from the player wing if (!(sp->flags[Ship_Flags::From_player_wing])) @@ -18711,7 +18711,7 @@ void ship_maybe_tell_about_low_ammo(ship *sp) if (sp->flags[Ship_Flags::No_builtin_messages]) { return; } - if (The_mission.ai_profile->flags[AI::Profile_Flags::Check_comms_for_non_player_ships] && hud_communications_state(sp) <= COMM_DAMAGED) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Check_comms_for_non_player_ships] && hud_communications_state(sp) <= COMM_DAMAGED) return; // don't mention low ammo if we're docked, for the same reason as in maybe_request_support @@ -18775,7 +18775,7 @@ void ship_maybe_tell_about_rearm(ship *sp) // Silent ships should remain just that if (sp->flags[Ship_Flags::No_builtin_messages]) return; - if (The_mission.ai_profile->flags[AI::Profile_Flags::Check_comms_for_non_player_ships] && hud_communications_state(sp) <= COMM_DAMAGED) + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Check_comms_for_non_player_ships] && hud_communications_state(sp) <= COMM_DAMAGED) return; // AL 1-4-98: If ship integrity is low, tell player you want to get repaired. Otherwise, tell @@ -20295,7 +20295,7 @@ void ship_set_new_ai_class(ship *shipp, int new_ai_class) // we hafta change a bunch of stuff here... aip->ai_class = new_ai_class; - init_aip_from_class_and_profile(aip, &Ai_classes[new_ai_class], The_mission.ai_profile); + init_aip_from_class_and_profile(aip, &Ai_classes[new_ai_class], The_mission.ai_profile()); shipp->weapons.ai_class = new_ai_class; diff --git a/code/ship/shiphit.cpp b/code/ship/shiphit.cpp index 7052850417e..852992d610f 100755 --- a/code/ship/shiphit.cpp +++ b/code/ship/shiphit.cpp @@ -799,7 +799,7 @@ std::pair, float> do_subobj_hit_stuff(object *ship_ { // MK, 9/2/99. Shockwaves do zero subsystem damage on small ships. // Goober5000 - added back in via flag - if ((Ship_info[ship_p->ship_info_index].is_small_ship()) && !(The_mission.ai_profile->flags[AI::Profile_Flags::Shockwaves_damage_small_ship_subsystems])) + if ((Ship_info[ship_p->ship_info_index].is_small_ship()) && !(The_mission.ai_profile()->flags[AI::Profile_Flags::Shockwaves_damage_small_ship_subsystems])) return std::make_pair(subsys_impact, damage); else { damage_left = shockwave_get_damage(other_obj->instance) / 4.0f; @@ -1040,13 +1040,13 @@ std::pair, float> do_subobj_hit_stuff(object *ship_ { // Decrease damage to subsystems to player ships. if (ship_objp->flags[Object::Object_Flags::Player_ship]){ - ss_dif_scale = The_mission.ai_profile->subsys_damage_scale[Game_skill_level]; + ss_dif_scale = The_mission.ai_profile()->subsys_damage_scale[Game_skill_level]; } // maybe modify damage FROM player ships if (other_obj && other_obj->parent >= 0 && Objects[other_obj->parent].signature == other_obj->parent_sig) { if (Objects[other_obj->parent].flags[Object::Object_Flags::Player_ship]) - ss_dif_scale *= The_mission.ai_profile->player_damage_inflicted_scale[Game_skill_level]; + ss_dif_scale *= The_mission.ai_profile()->player_damage_inflicted_scale[Game_skill_level]; } // Goober5000 - subsys guardian @@ -2335,15 +2335,19 @@ static int maybe_shockwave_damage_adjust(const object *ship_objp, const object * } // get max damage and adjust if needed to account for shockwave created from destroyed weapon + int wp_index = shockwave_get_weapon_index(other_obj->instance); max_damage = shockwave_get_damage(other_obj->instance); if (shockwave_get_flags(other_obj->instance) & SW_WEAPON_KILL) { - max_damage *= 4.0f; + if ((wp_index >= 0) && The_mission.ai_profile()->flags[AI::Profile_Flags::Consistent_dinky_shockwaves]) { + max_damage = Weapon_info[wp_index].shockwave.damage; + } else { + max_damage *= 4.0f; + } } // If the shockwave was caused by a weapon, then check if the weapon can deal lethal damage to the ship. // If it cannot, then neither should the shockwave caused by the weapon be able to do the same. // The code for this is copied from part of weapon_get_damage_scale. - int wp_index = shockwave_get_weapon_index(other_obj->instance); if ((wp_index >= 0) && Weapon_shockwaves_respect_huge) { wip = &Weapon_info[wp_index]; @@ -2462,7 +2466,7 @@ static void ship_do_damage(object *ship_objp, object *other_obj, const vec3d *hi if (other_obj && other_obj->parent >= 0 && Objects[other_obj->parent].signature == other_obj->parent_sig) { if(Objects[other_obj->parent].flags[Object::Object_Flags::Player_ship]) - difficulty_scale_factor *= The_mission.ai_profile->player_damage_inflicted_scale[Game_skill_level]; + difficulty_scale_factor *= The_mission.ai_profile()->player_damage_inflicted_scale[Game_skill_level]; } MONITOR_INC( ShipHits, 1 ); @@ -2487,7 +2491,7 @@ static void ship_do_damage(object *ship_objp, object *other_obj, const vec3d *hi // Do a little "skill" balancing for the player in single player and coop multiplayer if (ship_objp->flags[Object::Object_Flags::Player_ship]) { // Nuke - store it in a couple factor and we will apply it where needed - difficulty_scale_factor *= The_mission.ai_profile->player_damage_scale[Game_skill_level]; + difficulty_scale_factor *= The_mission.ai_profile()->player_damage_scale[Game_skill_level]; } } } @@ -2602,8 +2606,8 @@ static void ship_do_damage(object *ship_objp, object *other_obj, const vec3d *hi // Unless the backwards compatible flag is on, remove difficulty scaling as well // The hull/subsystem code below will re-add it where necessary - if (!The_mission.ai_profile->flags[AI::Profile_Flags::Carry_shield_difficulty_scaling_bug]) - remaining_damage /= difficulty_scale_factor; + if (!The_mission.ai_profile()->flags[AI::Profile_Flags::Carry_shield_difficulty_scaling_bug]) + remaining_damage /= difficulty_scale_factor; // the rest of the damage is what overflowed from the shield damage and pierced damage = remaining_damage + (damage * piercing_pct); @@ -2738,7 +2742,7 @@ static void ship_do_damage(object *ship_objp, object *other_obj, const vec3d *hi // Goober5000 - only count beams fired by fighters or bombers unless the ai profile says different if (bobjn >= 0) { - if ( !(The_mission.ai_profile->flags[AI::Profile_Flags::Include_beams_in_stat_calcs]) && + if ( !(The_mission.ai_profile()->flags[AI::Profile_Flags::Include_beams_in_stat_calcs]) && !(Ship_info[Ships[Objects[bobjn].instance].ship_info_index].is_fighter_bomber()) && !(Objects[bobjn].flags[Object::Object_Flags::Player_ship]) ) { bobjn = -1; diff --git a/code/stats/scoring.cpp b/code/stats/scoring.cpp index 2b023d31b9a..fc07b4830df 100644 --- a/code/stats/scoring.cpp +++ b/code/stats/scoring.cpp @@ -574,9 +574,9 @@ void scoring_level_init( scoring_struct *scp ) memset(scp->m_dogfight_kills, 0, MAX_PLAYERS * sizeof(int)); - if (The_mission.ai_profile != NULL) { - Kill_percentage = The_mission.ai_profile->kill_percentage_scale[Game_skill_level]; - Assist_percentage = The_mission.ai_profile->assist_percentage_scale[Game_skill_level]; + if (Ai_profiles.in_bounds(The_mission.ai_profile_index)) { + Kill_percentage = The_mission.ai_profile()->kill_percentage_scale[Game_skill_level]; + Assist_percentage = The_mission.ai_profile()->assist_percentage_scale[Game_skill_level]; } else { Kill_percentage = 0.30f; Assist_percentage = 0.15f; @@ -1004,7 +1004,7 @@ int scoring_eval_kill(const object *ship_objp) killer_sig = dead_ship->damage_ship_id[max_damage_index]; // set the scale value if we only award 100% score for 100% damage - if (The_mission.ai_profile->flags[AI::Profile_Flags::Kill_scoring_scales_with_damage]) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Kill_scoring_scales_with_damage]) { scoring_scale_by_damage = max_damage_pct; } @@ -1102,7 +1102,7 @@ int scoring_eval_kill(const object *ship_objp) if (!(Netgame.type_flags & NG_TYPE_DOGFIGHT) && (Ship_info[dead_ship->ship_info_index].is_big_or_huge())) { for (idx=0; idxp_info.team) && (&Net_players[idx] != net_plr)) { - assist_score = (int)(dead_ship->score * The_mission.ai_profile->assist_award_percentage_scale[Game_skill_level]); + assist_score = fl2i(dead_ship->score * The_mission.ai_profile()->assist_award_percentage_scale[Game_skill_level]); Net_players[idx].m_player->stats.m_score += assist_score; #ifdef SCORING_DEBUG @@ -1329,7 +1329,7 @@ void scoring_eval_assists(ship *sp,int killer_sig, bool is_enemy_player) // evaluate each damage slot to see if it did enough to give the assis for(idx=0;idxdamage_ship[idx]/sp->total_damage_received) >= Assist_percentage) || (The_mission.ai_profile->flags[AI::Profile_Flags::Assist_scoring_scales_with_damage])){ + if(((sp->damage_ship[idx]/sp->total_damage_received) >= Assist_percentage) || (The_mission.ai_profile()->flags[AI::Profile_Flags::Assist_scoring_scales_with_damage])){ // get the player which did this damage (if any) plr = NULL; @@ -1367,7 +1367,7 @@ void scoring_eval_assists(ship *sp,int killer_sig, bool is_enemy_player) // maybe award assist points based on damage - if (The_mission.ai_profile->flags[AI::Profile_Flags::Assist_scoring_scales_with_damage]) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Assist_scoring_scales_with_damage]) { scoring_scale_by_damage = (sp->damage_ship[idx]/sp->total_damage_received); assist_score = (int)(sp->score * scoring_scale_factor * scoring_scale_by_damage); plr->stats.m_score += assist_score; diff --git a/code/weapon/beam.cpp b/code/weapon/beam.cpp index 352dfd32894..0119b08c995 100644 --- a/code/weapon/beam.cpp +++ b/code/weapon/beam.cpp @@ -3899,7 +3899,7 @@ int beam_collide_early_out(object *a, object *b) /* if(bwi->b_info.beam_type == BEAM_TYPE_C){ return 1; }*/ - if(The_mission.ai_profile->flags[AI::Profile_Flags::Beams_damage_weapons]) { + if(The_mission.ai_profile()->flags[AI::Profile_Flags::Beams_damage_weapons]) { if((Weapon_info[Weapons[b->instance].weapon_info_index].weapon_hitpoints <= 0) && (Weapon_info[Weapons[b->instance].weapon_info_index].subtype == WP_LASER)) { return 1; } @@ -4215,7 +4215,7 @@ void beam_handle_collisions(beam *b) } case OBJ_WEAPON: - if (The_mission.ai_profile->flags[AI::Profile_Flags::Beams_damage_weapons]) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Beams_damage_weapons]) { if (!(Game_mode & GM_MULTIPLAYER) || MULTIPLAYER_MASTER) { object *trgt = &Objects[target]; @@ -4242,12 +4242,14 @@ void beam_handle_collisions(beam *b) if (trgt->hull_strength < 0) { Weapons[trgt->instance].weapon_flags.set(Weapon::Weapon_Flags::Destroyed_by_weapon); + Weapons[trgt->instance].weapon_flags.set(Weapon::Weapon_Flags::Destroyed_by_beam); bool armed = weapon_hit(trgt, nullptr, &trgt->pos); maybe_play_conditional_impacts({}, trgt, nullptr, armed, -1, &trgt->pos); } } else { if (!(Game_mode & GM_MULTIPLAYER) || MULTIPLAYER_MASTER) { Weapons[trgt->instance].weapon_flags.set(Weapon::Weapon_Flags::Destroyed_by_weapon); + Weapons[trgt->instance].weapon_flags.set(Weapon::Weapon_Flags::Destroyed_by_beam); bool armed = weapon_hit(trgt, nullptr, &trgt->pos); maybe_play_conditional_impacts({}, trgt, nullptr, armed, -1, &trgt->pos); } @@ -4261,6 +4263,7 @@ void beam_handle_collisions(beam *b) if (!(Game_mode & GM_MULTIPLAYER) || MULTIPLAYER_MASTER) { Weapons[Objects[target].instance].weapon_flags.set(Weapon::Weapon_Flags::Destroyed_by_weapon); + Weapons[Objects[target].instance].weapon_flags.set(Weapon::Weapon_Flags::Destroyed_by_beam); bool armed = weapon_hit(&Objects[target], nullptr, &Objects[target].pos); maybe_play_conditional_impacts({}, &Objects[target], nullptr, armed, -1, &Objects[target].pos); } @@ -4374,7 +4377,7 @@ int beam_ok_to_fire(beam *b) vm_vec_normalize(&aim_dir); if (!(b->flags & BF_IS_FIGHTER_BEAM)) { - if (The_mission.ai_profile->flags[AI::Profile_Flags::Force_beam_turret_fov]) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Force_beam_turret_fov]) { vec3d turret_normal; model_instance_local_to_global_dir(&turret_normal, &b->subsys->system_info->turret_norm, Ships[b->objp->instance].model_instance_num, b->subsys->system_info->subobj_num, &b->objp->orient, true); @@ -4503,9 +4506,9 @@ float beam_get_ship_damage(beam *b, object *objp, vec3d* hitpos) // same team. yikes if ( (b->team == Ships[objp->instance].team) - && (The_mission.ai_profile->beam_friendly_damage_cap[Game_skill_level] >= 0.f) - && (damage > The_mission.ai_profile->beam_friendly_damage_cap[Game_skill_level]) ) { - damage = The_mission.ai_profile->beam_friendly_damage_cap[Game_skill_level] * attenuation; + && (The_mission.ai_profile()->beam_friendly_damage_cap[Game_skill_level] >= 0.f) + && (damage > The_mission.ai_profile()->beam_friendly_damage_cap[Game_skill_level]) ) { + damage = The_mission.ai_profile()->beam_friendly_damage_cap[Game_skill_level] * attenuation; } else { // normal damage damage *= attenuation; diff --git a/code/weapon/shockwave.cpp b/code/weapon/shockwave.cpp index ec75394bfcd..48db67b1c2e 100644 --- a/code/weapon/shockwave.cpp +++ b/code/weapon/shockwave.cpp @@ -143,6 +143,7 @@ int shockwave_create(int parent_objnum, const vec3d* pos, const shockwave_create sw->inner_radius = sci->inner_rad; sw->outer_radius = sci->outer_rad; sw->damage = sci->damage; + sw->radius_curve_idx = sci->radius_curve_idx; sw->blast = sci->blast; sw->radius = 1.0f; sw->pos = *pos; @@ -299,8 +300,8 @@ void shockwave_move(object *shockwave_objp, float frametime) if (sw->weapon_info_index >= 0) wip = &Weapon_info[sw->weapon_info_index]; - if (wip && wip->shockwave.radius_curve_idx >= 0) { - float val = Curves[wip->shockwave.radius_curve_idx].GetValue(sw->time_elapsed / sw->total_time); + if (sw->radius_curve_idx >= 0) { + float val = Curves[sw->radius_curve_idx].GetValue(sw->time_elapsed / sw->total_time); sw->radius = val * sw->outer_radius; if (sw->radius < 0.0f) sw->radius = 0.0f; @@ -313,7 +314,7 @@ void shockwave_move(object *shockwave_objp, float frametime) // which by default results in shockwave applying no damage. // Provide optional fix to ensure shockwave is not killed until after this frame's damage pass has run. bool sw_expired = sw->time_elapsed > sw->total_time; - bool sw_expire_fix = The_mission.ai_profile->flags[AI::Profile_Flags::Fix_shockwave_expire_before_do_damage]; + bool sw_expire_fix = The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_shockwave_expire_before_do_damage]; if ( sw_expired && !sw_expire_fix ) { shockwave_objp->flags.set(Object::Object_Flags::Should_be_dead); @@ -386,12 +387,12 @@ void shockwave_move(object *shockwave_objp, float frametime) && Objects[shockwave_objp->parent].type == OBJ_SHIP && Ships[Objects[shockwave_objp->parent].instance].team == shipp->team) { if (&Objects[shockwave_objp->parent] == objp - && The_mission.ai_profile->weapon_self_damage_cap[Game_skill_level] >= 0.f) { + && The_mission.ai_profile()->weapon_self_damage_cap[Game_skill_level] >= 0.f) { // if this is a ship shooting itself, we use the self damage cap - damage = MIN(damage, The_mission.ai_profile->weapon_self_damage_cap[Game_skill_level]); - } else if (The_mission.ai_profile->weapon_friendly_damage_cap[Game_skill_level] >= 0.f) { + damage = MIN(damage, The_mission.ai_profile()->weapon_self_damage_cap[Game_skill_level]); + } else if (The_mission.ai_profile()->weapon_friendly_damage_cap[Game_skill_level] >= 0.f) { // otherwise we use the friendly damage cap - damage = MIN(damage, The_mission.ai_profile->weapon_friendly_damage_cap[Game_skill_level]); + damage = MIN(damage, The_mission.ai_profile()->weapon_friendly_damage_cap[Game_skill_level]); } } @@ -415,8 +416,8 @@ void shockwave_move(object *shockwave_objp, float frametime) if (shockwave_objp->parent >= 0 && sw->weapon_info_index >= 0 && Objects[shockwave_objp->parent].type == OBJ_SHIP && Ships[Objects[shockwave_objp->parent].instance].team == Weapons[objp->instance].team && - The_mission.ai_profile->weapon_friendly_damage_cap[Game_skill_level] >= 0.f) { - damage = MIN(damage, The_mission.ai_profile->weapon_friendly_damage_cap[Game_skill_level]); + The_mission.ai_profile()->weapon_friendly_damage_cap[Game_skill_level] >= 0.f) { + damage = MIN(damage, The_mission.ai_profile()->weapon_friendly_damage_cap[Game_skill_level]); } objp->hull_strength -= damage; @@ -832,6 +833,56 @@ void shockwave_create_info_init(shockwave_create_info *sci) sci->blast_sound_id = GameSounds::SHOCKWAVE_IMPACT; } +/** + * Copies every field that isn't in specified_fields (SCI_* bits) from the parent + */ +void shockwave_create_info_inherit(shockwave_create_info *sci, const shockwave_create_info *parent, int specified_fields) +{ + if (!(specified_fields & SCI_DAMAGE)) + sci->damage = parent->damage; + sci->damage_overridden = (specified_fields & SCI_DAMAGE) != 0; + + if (!(specified_fields & SCI_DAMAGE_TYPE)) { + sci->damage_type_idx = parent->damage_type_idx; + sci->damage_type_idx_sav = parent->damage_type_idx_sav; + } + + if (!(specified_fields & SCI_BLAST)) + sci->blast = parent->blast; + + if (!(specified_fields & SCI_INNER_RAD)) + sci->inner_rad = parent->inner_rad; + + if (!(specified_fields & SCI_OUTER_RAD)) + sci->outer_rad = parent->outer_rad; + + if (sci->outer_rad < sci->inner_rad) + sci->outer_rad = sci->inner_rad; + + if (!(specified_fields & SCI_RADIUS_CURVE)) + sci->radius_curve_idx = parent->radius_curve_idx; + + if (!(specified_fields & SCI_SPEED)) + sci->speed = parent->speed; + + if (!(specified_fields & SCI_ROTATION)) { + sci->rot_angles = parent->rot_angles; + sci->rot_defined = parent->rot_defined; + } + + if (!(specified_fields & SCI_ROT_RELATIVE)) + sci->rot_parent_relative = parent->rot_parent_relative; + + if (!(specified_fields & SCI_MODEL)) + strcpy_s(sci->pof_name, parent->pof_name); + + if (!(specified_fields & SCI_NAME)) + strcpy_s(sci->name, parent->name); + + if (!(specified_fields & SCI_SOUND)) + sci->blast_sound_id = parent->blast_sound_id; +} + /** * Loads a shockwave in preparation for a mission */ diff --git a/code/weapon/shockwave.h b/code/weapon/shockwave.h index 194c492b551..6abcbd67148 100644 --- a/code/weapon/shockwave.h +++ b/code/weapon/shockwave.h @@ -25,6 +25,20 @@ class model_draw_list; #define SW_SHIP_DEATH (1<<2) #define SW_WEAPON_KILL (1<<3) // Shockwave created when weapon destroyed by another +// fields of shockwave_create_info, for tracking which ones a table entry specified +#define SCI_DAMAGE (1<<0) +#define SCI_DAMAGE_TYPE (1<<1) +#define SCI_BLAST (1<<2) +#define SCI_INNER_RAD (1<<3) +#define SCI_OUTER_RAD (1<<4) +#define SCI_RADIUS_CURVE (1<<5) +#define SCI_SPEED (1<<6) +#define SCI_ROTATION (1<<7) +#define SCI_ROT_RELATIVE (1<<8) +#define SCI_MODEL (1<<9) +#define SCI_NAME (1<<10) +#define SCI_SOUND (1<<11) + #define MAX_SHOCKWAVES 16 // ----------------------------------------------------------- @@ -55,6 +69,7 @@ typedef struct shockwave { SCP_vector> obj_sig_hitlist; float speed, radius; float inner_radius, outer_radius, damage; + int radius_curve_idx; // curve for radius over time, or -1 to expand at a constant speed int weapon_info_index; // -1 if shockwave not caused by weapon int damage_type_idx; //What type of damage this shockwave does to armor vec3d pos; @@ -96,6 +111,7 @@ typedef struct shockwave_create_info { extern bool Use_3D_shockwaves; extern void shockwave_create_info_init(shockwave_create_info *sci); +extern void shockwave_create_info_inherit(shockwave_create_info *sci, const shockwave_create_info *parent, int specified_fields); extern void shockwave_create_info_load(const shockwave_create_info *sci); void shockwave_level_init(); diff --git a/code/weapon/weapon.h b/code/weapon/weapon.h index ecb122486fd..e47dcc54137 100644 --- a/code/weapon/weapon.h +++ b/code/weapon/weapon.h @@ -455,6 +455,7 @@ struct weapon_info shockwave_create_info shockwave; shockwave_create_info dinky_shockwave; + int dinky_shockwave_specified_fields; // SCI_* bits; everything else is inherited from the regular shockwave fix arm_time; float arm_dist; @@ -551,6 +552,7 @@ struct weapon_info gamesnd_id cockpit_launch_snd; gamesnd_id impact_snd; gamesnd_id disarmed_impact_snd; + bool disarmed_impact_snd_specified; // if not, the regular impact sound is used gamesnd_id shield_impact_snd; gamesnd_id flyby_snd; // whizz-by sound, transmitted through weapon's portable atmosphere. gamesnd_id ambient_snd; diff --git a/code/weapon/weapon_flags.h b/code/weapon/weapon_flags.h index e86eccb0654..668b8955c4d 100644 --- a/code/weapon/weapon_flags.h +++ b/code/weapon/weapon_flags.h @@ -110,6 +110,7 @@ namespace Weapon { Dead_in_water, // a missiles engines have died Locked_when_fired, // fired with a lock Destroyed_by_weapon, // destroyed by damage from other weapon + Destroyed_by_beam, // set along with Destroyed_by_weapon if that weapon was a beam Spawned, //Spawned from a spawning type weapon No_homing, // this weapon should ignore any homing behavior it'd usually have Overridden_homing, // Homing is overridden by an external source (probably scripting) diff --git a/code/weapon/weapons.cpp b/code/weapon/weapons.cpp index f147f081c8a..12a256cafc9 100644 --- a/code/weapon/weapons.cpp +++ b/code/weapon/weapons.cpp @@ -526,9 +526,10 @@ void parse_wi_flags(weapon_info *weaponp) } } -void parse_shockwave_info(shockwave_create_info *sci, const char *pre_char) +void parse_shockwave_info(shockwave_create_info *sci, const char *pre_char, int *specified_fields = nullptr) { SCP_string buf; + int fields = 0; sprintf(buf, "%sShockwave damage:", pre_char); if(optional_string(buf.c_str())) { @@ -536,6 +537,7 @@ void parse_shockwave_info(shockwave_create_info *sci, const char *pre_char) if (sci->damage < 0.0f) sci->damage = 0.0f; sci->damage_overridden = true; + fields |= SCI_DAMAGE; } sprintf(buf, "%sShockwave damage type:", pre_char); @@ -543,21 +545,25 @@ void parse_shockwave_info(shockwave_create_info *sci, const char *pre_char) stuff_string(buf, F_NAME); sci->damage_type_idx_sav = damage_type_add(buf.c_str()); sci->damage_type_idx = sci->damage_type_idx_sav; + fields |= SCI_DAMAGE_TYPE; } sprintf(buf, "%sBlast Force:", pre_char); if(optional_string(buf.c_str())) { stuff_float(&sci->blast); + fields |= SCI_BLAST; } sprintf(buf, "%sInner Radius:", pre_char); if(optional_string(buf.c_str())) { stuff_float(&sci->inner_rad); + fields |= SCI_INNER_RAD; } sprintf(buf, "%sOuter Radius:", pre_char); if(optional_string(buf.c_str())) { stuff_float(&sci->outer_rad); + fields |= SCI_OUTER_RAD; } if (sci->outer_rad < sci->inner_rad) { @@ -568,11 +574,13 @@ void parse_shockwave_info(shockwave_create_info *sci, const char *pre_char) sprintf(buf, "%sShockwave Radius Multiplier over Lifetime Curve:", pre_char); if (optional_string(buf.c_str())) { sci->radius_curve_idx = curve_parse(" Shockwave will not use a curve."); + fields |= SCI_RADIUS_CURVE; } sprintf(buf, "%sShockwave Speed:", pre_char); if(optional_string(buf.c_str())) { stuff_float(&sci->speed); + fields |= SCI_SPEED; } sprintf(buf, "%sShockwave Rotation:", pre_char); @@ -596,25 +604,33 @@ void parse_shockwave_info(shockwave_create_info *sci, const char *pre_char) sci->rot_angles.h = angs[2]; sci->rot_defined = true; + fields |= SCI_ROTATION; } sprintf(buf, "%sShockwave Rotation Is Relative To Parent:", pre_char); if(optional_string(buf.c_str())) { stuff_boolean(&sci->rot_parent_relative); + fields |= SCI_ROT_RELATIVE; } sprintf(buf, "%sShockwave Model:", pre_char); if(optional_string(buf.c_str())) { stuff_string(sci->pof_name, F_NAME, MAX_FILENAME_LEN); + fields |= SCI_MODEL; } sprintf(buf, "%sShockwave Name:", pre_char); if(optional_string(buf.c_str())) { stuff_string(sci->name, F_NAME, MAX_FILENAME_LEN); + fields |= SCI_NAME; } sprintf(buf, "%sShockwave Sound:", pre_char); - parse_game_sound(buf.c_str(), &sci->blast_sound_id); + if (parse_game_sound(buf.c_str(), &sci->blast_sound_id)) + fields |= SCI_SOUND; + + if (specified_fields != nullptr) + *specified_fields |= fields; } static SCP_vector Removed_weapons; @@ -1494,16 +1510,16 @@ int parse_weapon(int subtype, bool replace, const char *filename) parse_shockwave_info(&wip->shockwave, "$"); - //Retain compatibility + // unspecified dinky fields are inherited again after all tables are parsed, but copy now so that + // the fields below are checked against something sensible if(first_time) { wip->dinky_shockwave = wip->shockwave; - wip->dinky_shockwave.damage *= Dinky_shockwave_default_multiplier; } if(optional_string("$Dinky shockwave:")) { - parse_shockwave_info(&wip->dinky_shockwave, "+"); + parse_shockwave_info(&wip->dinky_shockwave, "+", &wip->dinky_shockwave_specified_fields); } if(optional_string("$Armor Factor:")) { @@ -2000,7 +2016,8 @@ int parse_weapon(int subtype, bool replace, const char *filename) parse_game_sound("$ImpactSnd:", &wip->impact_snd); //Disarmed impact sound - parse_game_sound("$Disarmed ImpactSnd:", &wip->disarmed_impact_snd); + if (parse_game_sound("$Disarmed ImpactSnd:", &wip->disarmed_impact_snd)) + wip->disarmed_impact_snd_specified = true; //Shield Impact sound --wookieejedi parse_game_sound("$Shield ImpactSnd:", &wip->shield_impact_snd); @@ -5060,6 +5077,11 @@ void weapon_do_post_parse() weapon_post_process_entries(); weapon_generate_indexes_for_substitution(); weapon_generate_indexes_for_precedence(); + + // this must happen before the damage types are finalized + for (auto &wi : Weapon_info) + shockwave_create_info_inherit(&wi.dinky_shockwave, &wi.shockwave, wi.dinky_shockwave_specified_fields); + weapon_finalize_shockwave_damage_types(); Default_cmeasure_index = -1; @@ -5078,6 +5100,9 @@ void weapon_do_post_parse() // catch a fall back cmeasure index, just in case if ( (first_cmeasure_index < 0) && (wip->wi_flags[Weapon::Info_Flags::Cmeasure]) ) first_cmeasure_index = i; + + if (!wip->disarmed_impact_snd_specified) + wip->disarmed_impact_snd = wip->impact_snd; } // catch cmeasure fallback @@ -5456,7 +5481,7 @@ void find_homing_object(object *weapon_objp, int num) // Goober5000: if missiles can't home on sensor-ghosted ships, // they definitely shouldn't home on stealth ships - if ( sp->flags[Ship::Ship_Flags::Stealth] && (The_mission.ai_profile->flags[AI::Profile_Flags::Fix_heat_seeker_stealth_bug]) ) { + if ( sp->flags[Ship::Ship_Flags::Stealth] && (The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_heat_seeker_stealth_bug]) ) { continue; } @@ -5474,7 +5499,7 @@ void find_homing_object(object *weapon_objp, int num) // For co-op, it's probably also OK. if (!( Game_mode & GM_MULTIPLAYER ) && objp == Player_obj) { int num_homers = compute_num_homing_objects(objp); - if (The_mission.ai_profile->max_allowed_player_homers[Game_skill_level] < num_homers) + if (The_mission.ai_profile()->max_allowed_player_homers[Game_skill_level] < num_homers) continue; } } @@ -5671,7 +5696,7 @@ bool aspect_should_lose_target(weapon* wp) if (target_info->wi_flags[Weapon::Info_Flags::Cmeasure]) { // Check if we can home on this countermeasure - bool home_on_cmeasure = The_mission.ai_profile->flags[AI::Profile_Flags::Aspect_lock_countermeasure] + bool home_on_cmeasure = The_mission.ai_profile()->flags[AI::Profile_Flags::Aspect_lock_countermeasure] || target_info->wi_flags[Weapon::Info_Flags::Cmeasure_aspect_home_on]; if (!home_on_cmeasure) @@ -5715,7 +5740,7 @@ void weapon_home(object *obj, int num, float frame_time) else max_speed=wip->max_speed; - bool fs1_behavior = The_mission.ai_profile->flags[AI::Profile_Flags::Freespace_1_missile_behavior] || wip->wi_flags[Weapon::Info_Flags::Freespace_1_missile_behavior]; + bool fs1_behavior = The_mission.ai_profile()->flags[AI::Profile_Flags::Freespace_1_missile_behavior] || wip->wi_flags[Weapon::Info_Flags::Freespace_1_missile_behavior]; float free_flight_time = wip->free_flight_time / 2.0f; if (fs1_behavior) { @@ -5804,7 +5829,7 @@ void weapon_home(object *obj, int num, float frame_time) if (wp->homing_subsys != NULL) { if (wp->homing_subsys->flags[Ship::Subsystem_Flags::Missiles_ignore_if_dead]) { if ((wp->homing_subsys->max_hits > 0) && (wp->homing_subsys->current_hits <= 0)) { - if (The_mission.ai_profile->flags[AI::Profile_Flags::Fix_ignore_if_dead_flag]) { + if (The_mission.ai_profile()->flags[AI::Profile_Flags::Fix_ignore_if_dead_flag]) { // fixed way: clear dead subsys so the missile picks a hull attack point // or, for Javelins, re-acquire another engine wp->homing_subsys = nullptr; @@ -5874,7 +5899,7 @@ void weapon_home(object *obj, int num, float frame_time) { weapon_info* hobj_infop = &Weapon_info[Weapons[hobjp->instance].weapon_info_index]; - bool home_on_cmeasure = The_mission.ai_profile->flags[AI::Profile_Flags::Aspect_lock_countermeasure] + bool home_on_cmeasure = The_mission.ai_profile()->flags[AI::Profile_Flags::Aspect_lock_countermeasure] || hobj_infop->wi_flags[Weapon::Info_Flags::Cmeasure_aspect_home_on]; // don't home on countermeasures or non-bombs, that's handled elsewhere @@ -5914,7 +5939,7 @@ void weapon_home(object *obj, int num, float frame_time) // add this missile to nearest_locked_object if its the closest // with the flag, only do it if its also mostly pointed at its target if (((aip->nearest_locked_object == -1) || (dist < aip->nearest_locked_distance)) && - (!(The_mission.ai_profile->flags[AI::Profile_Flags::Improved_missile_avoidance]) || vm_vec_dot(&target_vector, &obj->orient.vec.fvec) > 0.5f)) { + (!(The_mission.ai_profile()->flags[AI::Profile_Flags::Improved_missile_avoidance]) || vm_vec_dot(&target_vector, &obj->orient.vec.fvec) > 0.5f)) { aip->nearest_locked_object = OBJ_INDEX(obj); aip->nearest_locked_distance = dist; } @@ -7349,7 +7374,7 @@ int weapon_create( const vec3d *pos, const matrix *porient, int weapon_type, int } else { wp->lifeleft = (((rand_val) * (wip->life_max - wip->life_min)) + wip->life_min) * life_mult; if((wip->wi_flags[Weapon::Info_Flags::Cmeasure]) && (parent_objp != NULL) && (parent_objp->flags[Object::Object_Flags::Player_ship])) { - wp->lifeleft *= The_mission.ai_profile->cmeasure_life_scale[Game_skill_level]; + wp->lifeleft *= The_mission.ai_profile()->cmeasure_life_scale[Game_skill_level]; } } @@ -7443,7 +7468,7 @@ int weapon_create( const vec3d *pos, const matrix *porient, int weapon_type, int // Turey - maybe make the initial speed of the weapon take into account the velocity of the parent. // Improves aiming during gliding. - if ((parent_objp != nullptr) && (The_mission.ai_profile->flags[AI::Profile_Flags::Use_additive_weapon_velocity]) && !(already_inherited_parent_speed)) { + if ((parent_objp != nullptr) && (The_mission.ai_profile()->flags[AI::Profile_Flags::Use_additive_weapon_velocity]) && !(already_inherited_parent_speed)) { float pspeed = vm_vec_mag( &parent_objp->phys_info.vel ); vm_vec_scale_add2( &objp->phys_info.vel, &parent_objp->phys_info.vel, wip->vel_inherit_amount ); wp->weapon_max_vel += pspeed * wip->vel_inherit_amount; @@ -8140,8 +8165,9 @@ void weapon_area_apply_blast(const vec3d * /*force_apply_pos*/, object *objp, co * @param sci Shockwave info * @param pos World pos of explosion center * @param impacted_obj Object pointer to ship that weapon impacted on (can be NULL) + * @param regular_damage_to_huge Whether huge ships take the regular shockwave's damage rather than sci's */ -void weapon_do_area_effect(object *wobjp, const shockwave_create_info *sci, const vec3d *pos, const object *impacted_obj) +void weapon_do_area_effect(object *wobjp, const shockwave_create_info *sci, const vec3d *pos, const object *impacted_obj, bool regular_damage_to_huge) { weapon_info *wip; object *objp; @@ -8149,6 +8175,8 @@ void weapon_do_area_effect(object *wobjp, const shockwave_create_info *sci, cons wip = &Weapon_info[Weapons[wobjp->instance].weapon_info_index]; + int damage_type_idx = The_mission.ai_profile()->flags[AI::Profile_Flags::Consistent_dinky_shockwaves] ? sci->damage_type_idx : wip->shockwave.damage_type_idx; + // only blast ships and asteroids // And (some) weapons for ( objp = GET_FIRST(&obj_used_list); objp !=END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) { @@ -8172,7 +8200,11 @@ void weapon_do_area_effect(object *wobjp, const shockwave_create_info *sci, cons continue; } - if ( weapon_area_calc_damage(objp, pos, sci->inner_rad, sci->outer_rad, sci->blast, sci->damage, &blast, &damage, sci->outer_rad) == -1 ){ + float max_damage = sci->damage; + if (regular_damage_to_huge && objp->type == OBJ_SHIP && Ship_info[Ships[objp->instance].ship_info_index].is_huge_ship()) + max_damage = wip->shockwave.damage; + + if ( weapon_area_calc_damage(objp, pos, sci->inner_rad, sci->outer_rad, sci->blast, max_damage, &blast, &damage, sci->outer_rad) == -1 ){ continue; } @@ -8194,16 +8226,16 @@ void weapon_do_area_effect(object *wobjp, const shockwave_create_info *sci, cons // if this is friendly fire, we check for the friendly fire cap values if (wp->team == shipp->team) { - if (wobjp->parent > -1 && &Objects[wobjp->parent] == objp && The_mission.ai_profile->weapon_self_damage_cap[Game_skill_level] >= 0.f) { + if (wobjp->parent > -1 && &Objects[wobjp->parent] == objp && The_mission.ai_profile()->weapon_self_damage_cap[Game_skill_level] >= 0.f) { // if this is a ship damaging itself, we use the self damage cap - damage = MIN(damage, The_mission.ai_profile->weapon_self_damage_cap[Game_skill_level]); - } else if (The_mission.ai_profile->weapon_friendly_damage_cap[Game_skill_level] >= 0.f) { + damage = MIN(damage, The_mission.ai_profile()->weapon_self_damage_cap[Game_skill_level]); + } else if (The_mission.ai_profile()->weapon_friendly_damage_cap[Game_skill_level] >= 0.f) { // otherwise we use the friendly damage cap - damage = MIN(damage, The_mission.ai_profile->weapon_friendly_damage_cap[Game_skill_level]); + damage = MIN(damage, The_mission.ai_profile()->weapon_friendly_damage_cap[Game_skill_level]); } } - ship_apply_global_damage(objp, wobjp, pos, damage, wip->shockwave.damage_type_idx); + ship_apply_global_damage(objp, wobjp, pos, damage, damage_type_idx); weapon_area_apply_blast(nullptr, objp, pos, blast, false); break; } @@ -8215,14 +8247,14 @@ void weapon_do_area_effect(object *wobjp, const shockwave_create_info *sci, cons target_wip = &Weapon_info[Weapons[objp->instance].weapon_info_index]; if (target_wip->armor_type_idx >= 0) - damage = Armor_types[target_wip->armor_type_idx].GetDamage(damage, wip->shockwave.damage_type_idx, 1.0f, false); + damage = Armor_types[target_wip->armor_type_idx].GetDamage(damage, damage_type_idx, 1.0f, false); weapon* wp = &Weapons[wobjp->instance]; weapon* target_wp = &Weapons[objp->instance]; // if this is friendly fire, we check for the friendly fire cap value - if (wp->team == target_wp->team && The_mission.ai_profile->weapon_friendly_damage_cap[Game_skill_level] >= 0.f) { - damage = MIN(damage, The_mission.ai_profile->weapon_friendly_damage_cap[Game_skill_level]); + if (wp->team == target_wp->team && The_mission.ai_profile()->weapon_friendly_damage_cap[Game_skill_level] >= 0.f) { + damage = MIN(damage, The_mission.ai_profile()->weapon_friendly_damage_cap[Game_skill_level]); } objp->hull_strength -= damage; @@ -8252,44 +8284,60 @@ void weapon_do_area_effect(object *wobjp, const shockwave_create_info *sci, cons //1: weapon is destroyed before arm time //2: weapon is destroyed before arm distance from ship //3: weapon is outside arm radius from target ship -bool weapon_armed(weapon *wp, bool hit_target) + +// retail beams detonated a bomb at full strength, so a beam kill only counts with one of the flags +static bool weapon_shot_down(const weapon *wp) { - Assert(wp != NULL); + if (!wp->weapon_flags[Weapon::Weapon_Flags::Destroyed_by_weapon]) + return false; + return The_mission.ai_profile()->flags[AI::Profile_Flags::Consistent_dinky_shockwaves] + || The_mission.ai_profile()->flags[AI::Profile_Flags::Era_beam_kills_count_as_shot_down] + || !wp->weapon_flags[Weapon::Weapon_Flags::Destroyed_by_beam]; +} + +static bool weapon_failed_to_arm(weapon *wp, bool hit_target) +{ weapon_info *wip = &Weapon_info[wp->weapon_info_index]; + object *wobj = &Objects[wp->objnum]; + object *pobj; - if((wp->weapon_flags[Weapon::Weapon_Flags::Destroyed_by_weapon]) - && !wip->arm_time - && wip->arm_dist == 0.0f - && wip->arm_radius == 0.0f) - { - return false; + if(wobj->parent > -1) { + pobj = &Objects[wobj->parent]; + } else { + pobj = nullptr; } - else + + if( ((wip->arm_time) && ((Missiontime - wp->creation_time) < wip->arm_time)) + || ((wip->arm_dist) && (pobj != nullptr && pobj->type != OBJ_NONE && (vm_vec_dist(&wobj->pos, &pobj->pos) < wip->arm_dist)))) { - object *wobj = &Objects[wp->objnum]; - object *pobj; + return true; + } + if(wip->arm_radius && (!hit_target)) { + if(!weapon_has_homing_object(wp)) + return true; + if(IS_VEC_NULL(&wp->homing_pos) || vm_vec_dist(&wobj->pos, &wp->homing_pos) > wip->arm_radius) + return true; + } - if(wobj->parent > -1) { - pobj = &Objects[wobj->parent]; - } else { - pobj = NULL; - } + return false; +} - if( ((wip->arm_time) && ((Missiontime - wp->creation_time) < wip->arm_time)) - || ((wip->arm_dist) && (pobj != NULL && pobj->type != OBJ_NONE && (vm_vec_dist(&wobj->pos, &pobj->pos) < wip->arm_dist)))) - { - return false; - } - if(wip->arm_radius && (!hit_target)) { - if(!weapon_has_homing_object(wp)) - return false; - if(IS_VEC_NULL(&wp->homing_pos) || vm_vec_dist(&wobj->pos, &wp->homing_pos) > wip->arm_radius) - return false; - } +bool weapon_armed(weapon *wp, bool hit_target) +{ + Assert(wp != nullptr); + + weapon_info *wip = &Weapon_info[wp->weapon_info_index]; + + // without the flag, a shot-down weapon that has any arm parameter is only checked against those + if (weapon_shot_down(wp) + && (The_mission.ai_profile()->flags[AI::Profile_Flags::Consistent_dinky_shockwaves] + || (!wip->arm_time && wip->arm_dist == 0.0f && wip->arm_radius == 0.0f))) + { + return false; } - return true; + return !weapon_failed_to_arm(wp, hit_target); } static std::unique_ptr weapon_hit_make_effect_host(const object* weapon_obj, const object* impacted_obj, int impacted_submodel, const vec3d* hitpos, const vec3d* local_hitpos) { @@ -8608,19 +8656,43 @@ bool weapon_hit( object* weapon_obj, object* impacted_obj, const vec3d* hitpos, weapon_hit_do_sound(impacted_obj, wip, hitpos, armed_weapon, quadrant); } + bool consistent_dinky = The_mission.ai_profile()->flags[AI::Profile_Flags::Consistent_dinky_shockwaves]; + bool shot_down = weapon_shot_down(wp); + + //Which shockwave? + const shockwave_create_info *sci = &wip->shockwave; + shockwave_create_info dinky_sci; + bool regular_damage_to_huge = false; + if(!armed_weapon) { + dinky_sci = wip->dinky_shockwave; + sci = &dinky_sci; + + if (!dinky_sci.damage_overridden) { + bool only_shot_down = shot_down && !weapon_failed_to_arm(wp, hit_target); + + // retail did not reduce the damage of a shot-down weapon that has no shockwave + if (consistent_dinky || !only_shot_down || dinky_sci.speed > 0.0f + || The_mission.ai_profile()->flags[AI::Profile_Flags::Era_reduce_shot_down_area_effects]) + dinky_sci.damage = wip->shockwave.damage * The_mission.ai_profile()->dinky_shockwave_multiplier; + else + dinky_sci.damage = wip->shockwave.damage; + + regular_damage_to_huge = consistent_dinky && only_shot_down; + } + } + //Set shockwaves flag int sw_flag = SW_WEAPON; - if ( ((impacted_obj) && (impacted_obj->type == OBJ_WEAPON)) || (Weapons[num].weapon_flags[Weapon::Weapon_Flags::Destroyed_by_weapon])) { + // with the flag, SW_WEAPON_KILL means huge ships take the regular shockwave's damage; + // without it, they take four times this shockwave's damage + if (consistent_dinky) { + if (regular_damage_to_huge) + sw_flag |= SW_WEAPON_KILL; + } else if ( ((impacted_obj) && (impacted_obj->type == OBJ_WEAPON)) || shot_down) { sw_flag |= SW_WEAPON_KILL; } - //Which shockwave? - shockwave_create_info *sci = &wip->shockwave; - if(!armed_weapon) { - sci = &wip->dinky_shockwave; - } - // check if this is an area effect weapon (i.e. has a blast radius) if (sci->inner_rad != 0.0f || sci->outer_rad != 0.0f) { @@ -8628,7 +8700,7 @@ bool weapon_hit( object* weapon_obj, object* impacted_obj, const vec3d* hitpos, shockwave_create(OBJ_INDEX(weapon_obj), hitpos, sci, sw_flag, -1); } else { - weapon_do_area_effect(weapon_obj, sci, hitpos, impacted_obj); + weapon_do_area_effect(weapon_obj, sci, hitpos, impacted_obj, regular_damage_to_huge); } } @@ -9096,7 +9168,7 @@ float weapon_get_damage_scale(const weapon_info *wip, const object *wep, const o // if the hit object was a ship and we're doing damage scaling if ( (target->type == OBJ_SHIP) && - !(The_mission.ai_profile->flags[AI::Profile_Flags::Disable_weapon_damage_scaling]) && + !(The_mission.ai_profile()->flags[AI::Profile_Flags::Disable_weapon_damage_scaling]) && !(Ship_info[Ships[target->instance].ship_info_index].flags[Ship::Info_Flags::Disable_weapon_damage_scaling]) ) { ship_info *sip; @@ -9133,7 +9205,7 @@ float weapon_get_damage_scale(const weapon_info *wip, const object *wep, const o if( is_big_damage_ship && !(wip->hurts_big_ships()) ){ // if the player is firing it - if ( from_player && !(The_mission.ai_profile->flags[AI::Profile_Flags::Player_weapon_scale_fix])) { + if ( from_player && !(The_mission.ai_profile()->flags[AI::Profile_Flags::Player_weapon_scale_fix])) { // if it's a laser weapon if(wip->subtype == WP_LASER){ total_scale *= 0.01f; @@ -9831,6 +9903,7 @@ void weapon_info::reset() shockwave_create_info_init(&this->shockwave); shockwave_create_info_init(&this->dinky_shockwave); + this->dinky_shockwave_specified_fields = 0; this->arm_time = 0; this->arm_dist = 0.0f; @@ -9936,6 +10009,7 @@ void weapon_info::reset() this->cockpit_launch_snd = gamesnd_id(); this->impact_snd = gamesnd_id(); this->disarmed_impact_snd = gamesnd_id(); + this->disarmed_impact_snd_specified = false; this->shield_impact_snd = gamesnd_id(); this->flyby_snd = gamesnd_id(); diff --git a/fred2/missionnotesdlg.cpp b/fred2/missionnotesdlg.cpp index 3a73f896b05..b2d1b72370b 100644 --- a/fred2/missionnotesdlg.cpp +++ b/fred2/missionnotesdlg.cpp @@ -322,7 +322,7 @@ void CMissionNotesDlg::OnOK() string_copy(The_mission.squad_filename, m_squad_filename, MAX_FILENAME_LEN - 1); } - The_mission.ai_profile = &Ai_profiles[m_ai_profile]; + The_mission.ai_profile_index = m_ai_profile; MODIFY(Current_soundtrack_num, m_event_music - 1); strcpy_s(The_mission.substitute_event_music_name, m_substitute_event_music); @@ -409,8 +409,8 @@ BOOL CMissionNotesDlg::OnInitDialog() CDialog::OnInitDialog(); box = (CComboBox *) GetDlgItem(IDC_AI_PROFILE); - for (i=0; iAddString(Ai_profiles[i].profile_name); + for (const auto &profile : Ai_profiles){ + box->AddString(profile.profile_name); } box = (CComboBox *) GetDlgItem(IDC_EVENT_MUSIC); @@ -454,7 +454,7 @@ BOOL CMissionNotesDlg::OnInitDialog() } m_type = The_mission.game_type; - m_ai_profile = AI_PROFILES_INDEX(The_mission.ai_profile); + m_ai_profile = The_mission.ai_profile_index; m_event_music = Current_soundtrack_num + 1; m_substitute_event_music = The_mission.substitute_event_music_name; diff --git a/freespace2/freespace.cpp b/freespace2/freespace.cpp index 98a2ada5c36..b600d1eeb7e 100644 --- a/freespace2/freespace.cpp +++ b/freespace2/freespace.cpp @@ -5223,7 +5223,7 @@ void game_process_event( int current_state, int event ) shipfx_warpout_start( Player_obj ); Player->control_mode = PCM_WARPOUT_STAGE2; - if (!(The_mission.ai_profile->flags[AI::Profile_Flags::No_warp_camera])) { + if (!(The_mission.ai_profile()->flags[AI::Profile_Flags::No_warp_camera])) { Player->saved_viewer_mode = Viewer_mode; Viewer_mode |= VM_WARP_CHASE; Warp_camera = warp_camera(Player_obj); diff --git a/qtfred/src/mission/dialogs/MissionSpecDialogModel.cpp b/qtfred/src/mission/dialogs/MissionSpecDialogModel.cpp index 132eac7c28a..a7fef6e8872 100644 --- a/qtfred/src/mission/dialogs/MissionSpecDialogModel.cpp +++ b/qtfred/src/mission/dialogs/MissionSpecDialogModel.cpp @@ -55,7 +55,7 @@ void MissionSpecDialogModel::initializeData() { } _m_type = The_mission.game_type; - _m_ai_profile = AI_PROFILES_INDEX(The_mission.ai_profile); + _m_ai_profile = The_mission.ai_profile_index; _m_event_music = Current_soundtrack_num + 1; _m_substitute_event_music = The_mission.substitute_event_music_name; @@ -181,7 +181,7 @@ bool MissionSpecDialogModel::apply() { strncpy(The_mission.squad_filename, _m_squad_filename.c_str(), MAX_FILENAME_LEN); } - The_mission.ai_profile = &Ai_profiles[_m_ai_profile]; + The_mission.ai_profile_index = _m_ai_profile; Current_soundtrack_num = _m_event_music - 1; strcpy_s(The_mission.substitute_event_music_name, _m_substitute_event_music.c_str()); diff --git a/qtfred/src/ui/dialogs/MissionSpecDialog.cpp b/qtfred/src/ui/dialogs/MissionSpecDialog.cpp index ff2e9b0a0a0..76e145f0e52 100644 --- a/qtfred/src/ui/dialogs/MissionSpecDialog.cpp +++ b/qtfred/src/ui/dialogs/MissionSpecDialog.cpp @@ -241,8 +241,8 @@ void MissionSpecDialog::updateMusic() { void MissionSpecDialog::updateAIProfiles() { int idx = _model->getAIProfileIndex(); ui->aiProfileCombo->clear(); - for (int i = 0; i < Num_ai_profiles; i++) { - ui->aiProfileCombo->addItem(Ai_profiles[i].profile_name, QVariant(AI_PROFILES_INDEX(&Ai_profiles[i]))); + for (int i = 0; i < sz2i(Ai_profiles.size()); i++) { + ui->aiProfileCombo->addItem(Ai_profiles[i].profile_name, QVariant(i)); } ui->aiProfileCombo->setCurrentIndex(ui->aiProfileCombo->findData(idx)); } diff --git a/test/src/mission/test_missionparse.cpp b/test/src/mission/test_missionparse.cpp new file mode 100644 index 00000000000..be1d0047a57 --- /dev/null +++ b/test/src/mission/test_missionparse.cpp @@ -0,0 +1,14 @@ +#include + +#include "mission/missionparse.h" + +TEST(MissionParseTest, parse_date) { + ASSERT_EQ(mission_parse_date("12/17/19 at 14:00:00"), 20191217); + ASSERT_EQ(mission_parse_date("06/02/99 at 13:21:55"), 19990602); + ASSERT_EQ(mission_parse_date("01/31/27 at 23:59:59"), 20270131); + ASSERT_EQ(mission_parse_date("02/01/27 at 00:00:00"), 20270201); + + ASSERT_EQ(mission_parse_date(""), -1); + ASSERT_EQ(mission_parse_date("garbage"), -1); + ASSERT_EQ(mission_parse_date("13/01/20 at 00:00:00"), -1); +} diff --git a/test/src/source_groups.cmake b/test/src/source_groups.cmake index 1c268dda86e..8dc580959a2 100644 --- a/test/src/source_groups.cmake +++ b/test/src/source_groups.cmake @@ -41,6 +41,10 @@ add_file_folder("menuui" menuui/test_intel_parse.cpp ) +add_file_folder("Mission" + mission/test_missionparse.cpp +) + add_file_folder("mod" mod/test_mod_table.cpp ) diff --git a/test/src/weapon/weapons.cpp b/test/src/weapon/weapons.cpp index f0722c1a973..98b2a265411 100644 --- a/test/src/weapon/weapons.cpp +++ b/test/src/weapon/weapons.cpp @@ -34,3 +34,18 @@ TEST_F(WeaponsParseTest, description_too_many_lines) { ASSERT_THROW(weapon_init(), os::dialogs::WarningException); } + +TEST_F(WeaponsParseTest, dinky_inheritance) { + weapon_init(); + + int idx = weapon_info_lookup("Test weapon"); + ASSERT_GE(idx, 0); + + const auto &wi = Weapon_info[idx]; + ASSERT_EQ(wi.dinky_shockwave_specified_fields, SCI_INNER_RAD); + ASSERT_FLOAT_EQ(wi.dinky_shockwave.inner_rad, 5.0f); + ASSERT_FLOAT_EQ(wi.dinky_shockwave.outer_rad, 40.0f); + ASSERT_FLOAT_EQ(wi.dinky_shockwave.speed, 80.0f); + ASSERT_FLOAT_EQ(wi.dinky_shockwave.damage, 200.0f); + ASSERT_FALSE(wi.dinky_shockwave.damage_overridden); +} diff --git a/test/test_data/weapon/dinky_inheritance/data/tables/test-wep.tbm b/test/test_data/weapon/dinky_inheritance/data/tables/test-wep.tbm new file mode 100644 index 00000000000..da46f7db049 --- /dev/null +++ b/test/test_data/weapon/dinky_inheritance/data/tables/test-wep.tbm @@ -0,0 +1,51 @@ + +#Primary Weapons + +#End + +#Secondary Weapons + +$Name: Test weapon ++Title: XSTR("A test!", -1) ++Description: XSTR("A test weapon", -1) +$end_multi_text +$Model File: +$Mass: 0.1 +$Velocity: 5000.0 +$Fire Wait: 6.0 +$Damage: 100.0 +$Blast Force: 1.0 +$Inner Radius: 10.0 +$Outer Radius: 20.0 +$Shockwave Speed: 50.0 +$Dinky shockwave: + +Inner Radius: 5.0 +$Armor Factor: 0.0 +$Shield Factor: 0.0 +$Subsystem Factor: 0.0 +$Lifetime: 0.5 +$Energy Consumed: 0.0 +$Cargo Size: 1.0 +$Homing: YES + +Type: ASPECT + +Turn Time: 0.1 + +View Cone: 360.0 + +Min Lock Time: 2.0 + +Lock Pixels/Sec: 110 + +Catch-up Pixels/Sec: 100 + +Catch-up Penalty: 30 + +Seeker Strength: 999 +$LaunchSnd: -1 +$ImpactSnd: -1 +$FlyBySnd: -1 +$Rearm Rate: 1.0 +$Flags: ( "player allowed" "no homing speed ramp" "no dumbfire") + +;; a later change to the regular shockwave must carry through to the dinky fields that weren't specified +$Name: Test weapon ++nocreate +$Damage: 200.0 +$Outer Radius: 40.0 +$Shockwave Speed: 80.0 + +#End