Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions code/cmeasure/cmeasure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

int Cmeasures_homing_check = 0;
int Countermeasures_enabled = 1; // Debug, set to 0 means no one can fire countermeasures.
const int 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.
Expand Down
1 change: 1 addition & 0 deletions code/cmeasure/cmeasure.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class object;
// Maximum distance at which a countermeasure can be tracked
// If this value is too large, missiles will always be tracking countermeasures.
#define MAX_CMEASURE_TRACK_DIST 300.0f
extern const int CMEASURE_DETONATE_DISTANCE;

extern int Cmeasures_homing_check;
extern int Countermeasures_enabled;
Expand Down
2 changes: 2 additions & 0 deletions code/weapon/weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ typedef struct weapon_info {
float cm_aspect_effectiveness;
float cm_heat_effectiveness;
float cm_effective_rad;
float cm_detonation_rad;
bool cm_kill_single; // should the countermeasure kill just the single decoyed missile within CMEASURE_DETONATE_DISTANCE?

// *

Expand Down
56 changes: 39 additions & 17 deletions code/weapon/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,8 @@ void init_weapon_entry(int weap_info_index)
wip->cm_aspect_effectiveness = 1.0f;
wip->cm_heat_effectiveness = 1.0f;
wip->cm_effective_rad = MAX_CMEASURE_TRACK_DIST;
wip->cm_detonation_rad = CMEASURE_DETONATE_DISTANCE;
wip->cm_kill_single = false;

wip->b_info.beam_type = -1;
wip->b_info.beam_life = -1.0f;
Expand Down Expand Up @@ -2191,6 +2193,12 @@ int parse_weapon(int subtype, bool replace, const char *filename)

if (optional_string("+Effective Radius:"))
stuff_float(&wip->cm_effective_rad);

if (optional_string("+Missile Detonation Radius:"))
stuff_float(&wip->cm_detonation_rad);

if (optional_string("+Single Missile Kill:"))
stuff_boolean(&wip->cm_kill_single);
}

// beam weapon optional stuff
Expand Down Expand Up @@ -3885,32 +3893,43 @@ void weapon_maybe_play_warning(weapon *wp)
}
}

#define CMEASURE_DETONATE_DISTANCE 40.0f

/**
* Detonate all missiles near this countermeasure.
*/
void detonate_nearby_missiles(object *killer_objp)
void detonate_nearby_missiles(object* killer_objp, object* missile_objp)
{
if(killer_objp->type != OBJ_WEAPON) {
if(killer_objp->type != OBJ_WEAPON || missile_objp->type != OBJ_WEAPON) {
Int3();
return;
}

missile_obj *mop;
weapon_info* killer_infop = &Weapon_info[Weapons[killer_objp->instance].weapon_info_index];

mop = GET_FIRST(&Missile_obj_list);
while(mop != END_OF_LIST(&Missile_obj_list)) {
object *objp;
weapon *wp;
if (killer_infop->cm_kill_single) {
weapon* wp = &Weapons[missile_objp->instance];
if (wp->lifeleft > 0.2f) {
nprintf(("Countermeasures", "Countermeasure (%s-%i) detonated missile (%s-%i) Frame: %i\n",
killer_infop->name, killer_objp->signature,
Weapon_info[Weapons[missile_objp->instance].weapon_info_index].name, missile_objp->signature, Framecount));
wp->lifeleft = 0.2f;
}
return;
}

objp = &Objects[mop->objnum];
wp = &Weapons[objp->instance];
missile_obj* mop = GET_FIRST(&Missile_obj_list);

while(mop != END_OF_LIST(&Missile_obj_list)) {
object* objp = &Objects[mop->objnum];
weapon* wp = &Weapons[objp->instance];

if (iff_x_attacks_y(Weapons[killer_objp->instance].team, wp->team)) {
if ( Missiontime - wp->creation_time > F1_0/2) {
if (vm_vec_dist_quick(&killer_objp->pos, &objp->pos) < CMEASURE_DETONATE_DISTANCE) {
if (vm_vec_dist_quick(&killer_objp->pos, &objp->pos) < killer_infop->cm_detonation_rad) {
if (wp->lifeleft > 0.2f) {
nprintf(("Countermeasures", "Countermeasure (%s-%i) detonated missile (%s-%i) Frame: %i\n",
killer_infop->name, killer_objp->signature,
Weapon_info[Weapons[objp->instance].weapon_info_index].name, objp->signature, Framecount));
wp->lifeleft = 0.2f;
}
}
Expand Down Expand Up @@ -4280,6 +4299,9 @@ void weapon_home(object *obj, int num, float frame_time)
return;
}

// if we've got this far, this should be valid
weapon_info* hobj_infop = &Weapon_info[Weapons[hobjp->instance].weapon_info_index];

if (wip->acceleration_time > 0.0f) {
if (Missiontime - wp->creation_time < fl2f(wip->acceleration_time)) {
float t;
Expand Down Expand Up @@ -4369,14 +4391,14 @@ void weapon_home(object *obj, int num, float frame_time)
case OBJ_WEAPON:
{
bool home_on_cmeasure = The_mission.ai_profile->flags2 & AIPF2_ASPECT_LOCK_COUNTERMEASURE
|| Weapon_info[Weapons[hobjp->instance].weapon_info_index].wi_flags3 & WIF3_CMEASURE_ASPECT_HOME_ON;
|| hobj_infop->wi_flags3 & WIF3_CMEASURE_ASPECT_HOME_ON;

// don't home on countermeasures or non-bombs, that's handled elsewhere
if (((Weapon_info[Weapons[hobjp->instance].weapon_info_index].wi_flags & WIF_CMEASURE) && !home_on_cmeasure))
if (((hobj_infop->wi_flags & WIF_CMEASURE) && !home_on_cmeasure))
{
break;
}
else if (!(Weapon_info[Weapons[hobjp->instance].weapon_info_index].wi_flags & WIF_BOMB))
else if (!(hobj_infop->wi_flags & WIF_BOMB))
{
break;
}
Expand Down Expand Up @@ -4433,13 +4455,13 @@ void weapon_home(object *obj, int num, float frame_time)
float dist;

dist = vm_vec_dist_quick(&obj->pos, &hobjp->pos);
if (hobjp->type == OBJ_WEAPON && (Weapon_info[Weapons[hobjp->instance].weapon_info_index].wi_flags & WIF_CMEASURE))
if (hobjp->type == OBJ_WEAPON && (hobj_infop->wi_flags & WIF_CMEASURE))
{
if (dist < CMEASURE_DETONATE_DISTANCE)
if (dist < hobj_infop->cm_detonation_rad)
{
// Make this missile detonate soon. Not right away, not sure why. Seems better.
if (iff_x_attacks_y(Weapons[hobjp->instance].team, wp->team)) {
detonate_nearby_missiles(hobjp);
detonate_nearby_missiles(hobjp, obj);
return;
}
}
Expand Down