Skip to content

Commit

Permalink
Merge pull request #6365 from Baezon/disambiguate-shockwave-damage
Browse files Browse the repository at this point in the history
Disambiguate `ShockwaveDamage` cases
  • Loading branch information
Goober5000 authored Oct 29, 2024
2 parents 95fef2a + 649d458 commit e58f8f9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
8 changes: 4 additions & 4 deletions code/scripting/api/objs/weaponclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,11 @@ ADE_VIRTVAR(EnergyConsumed, l_Weaponclass, nullptr, nullptr, "number", "Energy C
return ade_set_args(L, "f", Weapon_info[idx].energy_consumed);
}

ADE_VIRTVAR(ShockwaveDamage, l_Weaponclass, "number", "Damage the shockwave is set to if damage is overriden", "number", "Shockwave Damage, or 0 if weapon shockwave damage is not overriden. Returns nil if handle is invalid")
ADE_VIRTVAR(ShockwaveDamage, l_Weaponclass, "number", "Damage the shockwave is set to if damage is overridden", "number", "Shockwave Damage if explicitly specified via table, or -1 if unspecified. Returns nil if handle is invalid")
{
int idx;
if(!ade_get_args(L, "o", l_Weaponclass.Get(&idx)))
return ade_set_error(L, "f", 0.0f);
return ade_set_error(L, "f", -1.0f);

if(idx < 0 || idx >= weapon_info_size())
return ADE_RETURN_NIL;
Expand All @@ -561,10 +561,10 @@ ADE_VIRTVAR(ShockwaveDamage, l_Weaponclass, "number", "Damage the shockwave is s
LuaError(L, "Setting Shockwave Damage is not supported");
}

if (Weapon_info[idx].shockwave.damage_overidden) {
if (Weapon_info[idx].shockwave.damage_overridden) {
return ade_set_args(L, "f", Weapon_info[idx].shockwave.damage);
} else {
return ade_set_args(L, "f", 0.0f);
return ade_set_args(L, "f", -1.0f);
}
}

Expand Down
2 changes: 1 addition & 1 deletion code/weapon/shockwave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ void shockwave_create_info_init(shockwave_create_info *sci)
sci->rot_angles.p = sci->rot_angles.b = sci->rot_angles.h = 0.0f;
sci->rot_defined = false;
sci->damage_type_idx = sci->damage_type_idx_sav = -1;
sci->damage_overidden = false;
sci->damage_overridden = false;

sci->blast_sound_id = GameSounds::SHOCKWAVE_IMPACT;
}
Expand Down
2 changes: 1 addition & 1 deletion code/weapon/shockwave.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ typedef struct shockwave_create_info {
int radius_curve_idx; // curve for shockwave radius over time
angles rot_angles;
bool rot_defined; // if the modder specified rot_angles
bool damage_overidden; // did this have shockwave damage specifically set or not
bool damage_overridden; // did this have shockwave damage specifically set or not

int damage_type_idx;
int damage_type_idx_sav; // stored value from table used to reset damage_type_idx
Expand Down
12 changes: 10 additions & 2 deletions code/weapon/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,9 @@ void parse_shockwave_info(shockwave_create_info *sci, const char *pre_char)
sprintf(buf, "%sShockwave damage:", pre_char);
if(optional_string(buf.c_str())) {
stuff_float(&sci->damage);
sci->damage_overidden = true;
if (sci->damage < 0.0f)
sci->damage = 0.0f;
sci->damage_overridden = true;
}

sprintf(buf, "%sShockwave damage type:", pre_char);
Expand Down Expand Up @@ -1321,9 +1323,15 @@ int parse_weapon(int subtype, bool replace, const char *filename)

if(optional_string("$Damage:")) {
stuff_float(&wip->damage);

if (wip->damage < 0.0f) {
Warning(LOCATION, "$Damage in weapon '%s' should not be negative.\nConsider the 'heals' flag instead if this is intentional. ", wip->name);
wip->damage = 0.0f;
}

//WMC - now that shockwave damage can be set for them individually,
//do this automagically
if(!wip->shockwave.damage_overidden) {
if(!wip->shockwave.damage_overridden) {
wip->shockwave.damage = wip->damage;
}
}
Expand Down

0 comments on commit e58f8f9

Please sign in to comment.