Skip to content

Commit

Permalink
Cleanup variable name in weapon_do_area_effect function (scp-fs2ope…
Browse files Browse the repository at this point in the history
…n#6303)

* Cleanup variable name in `weapon_do_area_effect` function

Per discussion in scp-fs2open#6302, this PR renames `other_obj` to `impacted_obj` to minimize confusion

* update other functions with impacted_obj naming

* nullptr

* appease clang's strange rules

* fighting clang continues

* use !empty check instead of > 0

* remove un-needed no lint comment
  • Loading branch information
wookieejedi authored Aug 18, 2024
1 parent cc5bb30 commit db13168
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion code/weapon/weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ size_t* get_pointer_to_weapon_fire_pattern_index(int weapon_type, int ship_idx,
void weapon_maybe_spew_particle(object *obj);

bool weapon_armed(weapon *wp, bool hit_target);
void weapon_hit( object * weapon_obj, object * other_obj, vec3d * hitpos, int quadrant = -1, vec3d* hitnormal = NULL );
void weapon_hit( object * weapon_obj, object * impacted_obj, vec3d * hitpos, int quadrant = -1, vec3d* hitnormal = nullptr );
void spawn_child_weapons( object *objp, int spawn_index_override = -1);

// call to detonate a weapon. essentially calls weapon_hit() with other_obj as NULL, and sends a packet in multiplayer
Expand Down
60 changes: 30 additions & 30 deletions code/weapon/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7401,9 +7401,9 @@ void weapon_area_apply_blast(vec3d * /*force_apply_pos*/, object *objp, vec3d *b
* @param wobjp Object pointer to weapon causing explosion
* @param sci Shockwave info
* @param pos World pos of explosion center
* @param other_obj Object pointer to ship that weapon impacted on (can be NULL)
* @param impacted_obj Object pointer to ship that weapon impacted on (can be NULL)
*/
void weapon_do_area_effect(object *wobjp, shockwave_create_info *sci, vec3d *pos, object *other_obj)
void weapon_do_area_effect(object *wobjp, shockwave_create_info *sci, vec3d *pos, object *impacted_obj)
{
weapon_info *wip;
object *objp;
Expand Down Expand Up @@ -7439,15 +7439,15 @@ void weapon_do_area_effect(object *wobjp, shockwave_create_info *sci, vec3d *pos
}

// scale damage
damage *= weapon_get_damage_scale(wip, wobjp, other_obj);
damage *= weapon_get_damage_scale(wip, wobjp, impacted_obj);

weapon_info* target_wip;

switch ( objp->type ) {
case OBJ_SHIP: {
// If we're doing an AoE Electronics blast, do the electronics stuff (unless it also has the regular "electronics"
// flag and this is the ship the missile directly impacted; then leave it for the regular code below) -MageKing17
if ( (wip->wi_flags[Weapon::Info_Flags::Aoe_Electronics]) && !((objp->flags[Object::Object_Flags::Invulnerable]) || ((objp == other_obj) && (wip->wi_flags[Weapon::Info_Flags::Electronics]))) ) {
if ( (wip->wi_flags[Weapon::Info_Flags::Aoe_Electronics]) && !((objp->flags[Object::Object_Flags::Invulnerable]) || ((objp == impacted_obj) && (wip->wi_flags[Weapon::Info_Flags::Electronics]))) ) { // NOLINT(readability-simplify-boolean-expr)
weapon_do_electronics_effect(objp, pos, Weapons[wobjp->instance].weapon_info_index);
}

Expand Down Expand Up @@ -7559,7 +7559,7 @@ bool weapon_armed(weapon *wp, bool hit_target)
* Called when a weapon hits something (or, in the case of
* missiles explodes for any particular reason)
*/
void weapon_hit( object * weapon_obj, object * other_obj, vec3d * hitpos, int quadrant, vec3d* hitnormal )
void weapon_hit( object * weapon_obj, object * impacted_obj, vec3d * hitpos, int quadrant, vec3d* hitnormal )
{
Assert(weapon_obj != NULL);
if(weapon_obj == NULL){
Expand Down Expand Up @@ -7594,20 +7594,20 @@ void weapon_hit( object * weapon_obj, object * other_obj, vec3d * hitpos, int qu
scripting::hooks::OnMissileDeathStarted->run(scripting::hooks::WeaponDeathConditions{ wp },
scripting::hook_param_list(
scripting::hook_param("Weapon", 'o', weapon_obj),
scripting::hook_param("Object", 'o', other_obj)));
scripting::hook_param("Object", 'o', impacted_obj)));
}

// check if the weapon actually hit the intended target
if (weapon_has_homing_object(wp))
if (wp->homing_object == other_obj)
if (wp->homing_object == impacted_obj)
hit_target = true;

//This is an expensive check
bool armed_weapon = weapon_armed(&Weapons[num], hit_target);

// if this is the player ship, and is a laser hit, skip it. wait for player "pain" to take care of it
if ((other_obj != Player_obj) || (wip->subtype != WP_LASER) || !MULTIPLAYER_CLIENT) {
weapon_hit_do_sound(other_obj, wip, hitpos, armed_weapon, quadrant);
if ((impacted_obj != Player_obj) || (wip->subtype != WP_LASER) || !MULTIPLAYER_CLIENT) { // NOLINT(readability-simplify-boolean-expr)
weapon_hit_do_sound(impacted_obj, wip, hitpos, armed_weapon, quadrant);
}


Expand All @@ -7622,21 +7622,21 @@ void weapon_hit( object * weapon_obj, object * other_obj, vec3d * hitpos, int qu
hit_angle = vm_vec_delta_ang(hitnormal, &reverse_incoming, nullptr);
}

if (wip->conditional_impacts.size() > 0 && other_obj != nullptr && (other_obj->type == OBJ_SHIP || other_obj->type == OBJ_WEAPON)) {
if (other_obj->type == OBJ_SHIP) {
shipp = &Ships[other_obj->instance];
if (!wip->conditional_impacts.empty() && impacted_obj != nullptr && (impacted_obj->type == OBJ_SHIP || impacted_obj->type == OBJ_WEAPON)) {
if (impacted_obj->type == OBJ_SHIP) {
shipp = &Ships[impacted_obj->instance];
if (quadrant == -1) {
relevant_armor_idx = shipp->armor_type_idx;
relevant_fraction = other_obj->hull_strength / i2fl(shipp->ship_max_hull_strength);
relevant_fraction = impacted_obj->hull_strength / i2fl(shipp->ship_max_hull_strength);
} else {
relevant_armor_idx = shipp->shield_armor_type_idx;
relevant_fraction = ship_quadrant_shield_strength(other_obj, quadrant);
relevant_fraction = ship_quadrant_shield_strength(impacted_obj, quadrant);
}
} else {
target_wp = &Weapons[other_obj->instance];
target_wp = &Weapons[impacted_obj->instance];
target_wip = &Weapon_info[target_wp->weapon_info_index];
relevant_armor_idx = target_wip->armor_type_idx;
relevant_fraction = other_obj->hull_strength / i2fl(target_wip->weapon_hitpoints);
relevant_fraction = impacted_obj->hull_strength / i2fl(target_wip->weapon_hitpoints);
}

if (wip->conditional_impacts.count(relevant_armor_idx) == 1) {
Expand Down Expand Up @@ -7689,18 +7689,18 @@ void weapon_hit( object * weapon_obj, object * other_obj, vec3d * hitpos, int qu
particleSource.finish();
}

if ((other_obj != nullptr) && (quadrant == -1) && (!valid_conditional_impact && wip->piercing_impact_effect.isValid() && armed_weapon)) {
if ((other_obj->type == OBJ_SHIP) || (other_obj->type == OBJ_DEBRIS)) {
if ((impacted_obj != nullptr) && (quadrant == -1) && (!valid_conditional_impact && wip->piercing_impact_effect.isValid() && armed_weapon)) {
if ((impacted_obj->type == OBJ_SHIP) || (impacted_obj->type == OBJ_DEBRIS)) {

int ok_to_draw = 1;

if (other_obj->type == OBJ_SHIP) {
if (impacted_obj->type == OBJ_SHIP) {
float draw_limit, hull_pct;
int dmg_type_idx, piercing_type;

shipp = &Ships[other_obj->instance];
shipp = &Ships[impacted_obj->instance];

hull_pct = other_obj->hull_strength / shipp->ship_max_hull_strength;
hull_pct = impacted_obj->hull_strength / shipp->ship_max_hull_strength;
dmg_type_idx = wip->damage_type_idx;
draw_limit = Ship_info[shipp->ship_info_index].piercing_damage_draw_limit;

Expand Down Expand Up @@ -7750,7 +7750,7 @@ void weapon_hit( object * weapon_obj, object * other_obj, vec3d * hitpos, int qu
//Set shockwaves flag
int sw_flag = SW_WEAPON;

if ( ((other_obj) && (other_obj->type == OBJ_WEAPON)) || (Weapons[num].weapon_flags[Weapon::Weapon_Flags::Destroyed_by_weapon])) {
if ( ((impacted_obj) && (impacted_obj->type == OBJ_WEAPON)) || (Weapons[num].weapon_flags[Weapon::Weapon_Flags::Destroyed_by_weapon])) {
sw_flag |= SW_WEAPON_KILL;
}

Expand All @@ -7767,7 +7767,7 @@ void weapon_hit( object * weapon_obj, object * other_obj, vec3d * hitpos, int qu
shockwave_create(OBJ_INDEX(weapon_obj), hitpos, sci, sw_flag, -1);
}
else {
weapon_do_area_effect(weapon_obj, sci, hitpos, other_obj);
weapon_do_area_effect(weapon_obj, sci, hitpos, impacted_obj);
}
}

Expand All @@ -7777,13 +7777,13 @@ void weapon_hit( object * weapon_obj, object * other_obj, vec3d * hitpos, int qu
}

// if this weapon has the "Electronics" flag set, then disrupt subsystems in sphere
if ((other_obj != NULL) && (wip->wi_flags[Weapon::Info_Flags::Electronics])) {
if (other_obj->type == OBJ_SHIP) {
weapon_do_electronics_effect(other_obj, &weapon_obj->pos, Weapons[weapon_obj->instance].weapon_info_index);
if ((impacted_obj != nullptr) && (wip->wi_flags[Weapon::Info_Flags::Electronics])) {
if (impacted_obj->type == OBJ_SHIP) {
weapon_do_electronics_effect(impacted_obj, &weapon_obj->pos, Weapons[weapon_obj->instance].weapon_info_index);
}
}

if (!wip->pierce_objects || wip->spawn_children_on_pierce || !other_obj) {
if (!wip->pierce_objects || wip->spawn_children_on_pierce || !impacted_obj) {
// spawn weapons - note the change from FS 1 multiplayer.
if (wip->wi_flags[Weapon::Info_Flags::Spawn]) {
if (!((wip->wi_flags[Weapon::Info_Flags::Dont_spawn_if_shot]) && (Weapons[num].weapon_flags[Weapon::Weapon_Flags::Destroyed_by_weapon]))) { // prevent spawning of children if shot down and the dont spawn if shot flag is set (DahBlount)
Expand All @@ -7792,8 +7792,8 @@ void weapon_hit( object * weapon_obj, object * other_obj, vec3d * hitpos, int qu
}
}

//No other_obj means this weapon detonates
if (wip->pierce_objects && other_obj && other_obj->type != OBJ_WEAPON)
//No impacted_obj means this weapon detonates
if (wip->pierce_objects && impacted_obj && impacted_obj->type != OBJ_WEAPON)
return;

// For all objects that had this weapon as a target, wipe it out, forcing find of a new enemy
Expand Down Expand Up @@ -7834,7 +7834,7 @@ void weapon_hit( object * weapon_obj, object * other_obj, vec3d * hitpos, int qu
scripting::hooks::OnMissileDeath->run(scripting::hooks::WeaponDeathConditions{ wp },
scripting::hook_param_list(
scripting::hook_param("Weapon", 'o', weapon_obj),
scripting::hook_param("Object", 'o', other_obj)));
scripting::hook_param("Object", 'o', impacted_obj)));
}

weapon_obj->flags.set(Object::Object_Flags::Should_be_dead);
Expand Down

0 comments on commit db13168

Please sign in to comment.