Add feature to customize how CMs are launched (#7224)

This commit is contained in:
Mike Nelson authored and GitHub committed 2026-03-05 15:15:56 -05:00
1 parent f6588f802e
commit 8e23ce837f
3 files changed
+52 -12

No files matched your search

+26 -12
View File
@@ -25,18 +25,33 @@ const float CMEASURE_DETONATE_DISTANCE = 40.0f;
//Used to set a countermeasure velocity after being launched from a ship as a countermeasure
//ie not as a primary or secondary.
void cmeasure_set_ship_launch_vel(object *objp, object *parent_objp, int arand)
void cmeasure_set_ship_launch_vel(object* objp, object* parent_objp, int arand)
{
vec3d vel, rand_vec;
vec3d vel;
vec3d rand_vec;
vec3d world_dir;
//Get cmeasure rear velocity in world
vm_vec_scale_add(&vel, &parent_objp->phys_info.vel, &parent_objp->orient.vec.fvec, -25.0f);
weapon* wp = &Weapons[objp->instance];
auto* wip = &Weapon_info[wp->weapon_info_index];
//Get random velocity vector
static_randvec(arand+1, &rand_vec);
// Start with parent velocity
vel = parent_objp->phys_info.vel;
//Add it to the rear velocity
vm_vec_scale_add2(&vel, &rand_vec, 2.0f);
// Normalize direction
vec3d local_dir = wip->cm_launch_vec;
if (vm_vec_mag_squared(&local_dir) > 0.0f) {
vm_vec_normalize(&local_dir);
}
// Convert from ship to world space
vm_vec_unrotate(&world_dir, &local_dir, &parent_objp->orient);
// Apply launch impulse
vm_vec_scale_add2(&vel, &world_dir, wip->cm_launch_speed);
// Add random variance
static_randvec(arand + 1, &rand_vec);
vm_vec_scale_add2(&vel, &rand_vec, wip->cm_launch_variance);
objp->phys_info.vel = vel;
@@ -44,17 +59,16 @@ void cmeasure_set_ship_launch_vel(object *objp, object *parent_objp, int arand)
vm_vec_zero(&objp->phys_info.rotvel);
vm_vec_zero(&objp->phys_info.max_vel);
vm_vec_zero(&objp->phys_info.max_rotvel);
// blow out his reverse thrusters. Or drag, same thing.
objp->phys_info.rotdamp = 10000.0f;
objp->phys_info.side_slip_time_const = 10000.0f;
objp->phys_info.max_vel.xyz.z = -25.0f;
vm_vec_copy_scale(&objp->phys_info.desired_vel, &objp->orient.vec.fvec, objp->phys_info.max_vel.xyz.z );
// Desired velocity should align with launch direction, not hardcoded backward
vm_vec_copy_scale(&objp->phys_info.desired_vel, &world_dir, wip->cm_launch_speed);
// if this cmeasure has a single segment trail, let the trail know since we just changed the velocity
// yeah this is hacky but that's what this function gets for CHANGING the velocity on objects with a ""CONSTANT VELOCITY""
weapon* wp = &Weapons[objp->instance];
if (wp->trail_ptr && wp->trail_ptr->single_segment) {
wp->trail_ptr->vel[0] = objp->phys_info.vel;
wp->trail_ptr->vel[1] = objp->phys_info.vel;
+3
View File
@@ -627,6 +627,9 @@ struct weapon_info
float cm_heat_effectiveness;
float cm_effective_rad;
float cm_detonation_rad;
vec3d cm_launch_vec;
float cm_launch_speed;
float cm_launch_variance;
bool cm_kill_single; // should the countermeasure kill just the single decoyed missile within CMEASURE_DETONATE_DISTANCE?
int cmeasure_timer_interval; // how many milliseconds between pulses
int cmeasure_firewait; // delay in milliseconds between countermeasure firing --wookieejedi
+23
View File
@@ -2842,6 +2842,26 @@ int parse_weapon(int subtype, bool replace, const char *filename)
if (optional_string("+Missile Detonation Radius:"))
stuff_float(&wip->cm_detonation_rad);
if (optional_string("+Launch Vector:")) {
stuff_vec3d(&wip->cm_launch_vec);
}
if (optional_string("+Launch Speed:")) {
stuff_float(&wip->cm_launch_speed);
if (wip->cm_launch_speed < 0) {
Warning(LOCATION, "Countermeasure launch speed for weapon \'%s\' should be non-negative. Value will not be used.", wip->name);
wip->cm_launch_speed = 25.0f;
}
}
if (optional_string("+Launch Variance:")) {
stuff_float(&wip->cm_launch_variance);
if (wip->cm_launch_variance < 0) {
Warning(LOCATION, "Countermeasure launch variance for weapon \'%s\' should be non-negative. Value will not be used.", wip->name);
wip->cm_launch_variance = 2.0f;
}
}
if (optional_string("+Single Missile Kill:"))
stuff_boolean(&wip->cm_kill_single);
@@ -9684,6 +9704,9 @@ void weapon_info::reset()
this->cm_heat_effectiveness = 1.0f;
this->cm_effective_rad = MAX_CMEASURE_TRACK_DIST;
this->cm_detonation_rad = CMEASURE_DETONATE_DISTANCE;
this->cm_launch_vec = {{{0.0f, 0.0f, -1.0f}}};
this->cm_launch_speed = 25.0f;
this->cm_launch_variance = 2.0f;
this->cm_kill_single = false;
this->cmeasure_timer_interval = 0;
this->cmeasure_firewait = CMEASURE_WAIT;