Skip to content

Commit c307ef7

Browse files
authored
Allow ship debris pieces hitpoints depend on radius (#6771)
* Allow ship debris pieces hitpoints depend on radius Currently, ship debris pieces have their hitpoints set via a Max and Min range. This constricts modders by needing all debris pieces to have somewhat the same size, otherwise the uniform random hitpoints assignment will could make small pieces much stronger than big pieces. This PR adds a new field `+Hitpoints Radius Multiplier:` which is just a value that multiplies the debris radius, this value, and the debris hitpoints to calculate a final hitpoints value for the spawned debris piece. This multiplier thus allows modders to have debris pieces that are very large have much strong hitpoints then debris pieces that are very small. * incorporate feedback fix * match other logical checks
1 parent 2701544 commit c307ef7

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

code/debris/debris.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -650,19 +650,25 @@ object *debris_create_only(int parent_objnum, int parent_ship_class, int alt_typ
650650
obj->hull_strength = hull_strength;
651651

652652
if (hull_flag) {
653-
if(sip->debris_min_hitpoints >= 0.0f && sip->debris_max_hitpoints >= 0.0f)
653+
float min_hp = sip->debris_min_hitpoints;
654+
float max_hp = sip->debris_max_hitpoints;
655+
if (sip->debris_hitpoints_radius_multi >= 0.0f) {
656+
min_hp *= sip->debris_hitpoints_radius_multi * radius;
657+
max_hp *= sip->debris_hitpoints_radius_multi * radius;
658+
}
659+
if (min_hp >= 0.0f && max_hp >= 0.0f)
654660
{
655-
obj->hull_strength = (( sip->debris_max_hitpoints - sip->debris_min_hitpoints ) * frand()) + sip->debris_min_hitpoints;
661+
obj->hull_strength = ((max_hp - min_hp) * frand()) + min_hp;
656662
}
657-
else if(sip->debris_min_hitpoints >= 0.0f)
663+
else if(min_hp >= 0.0f)
658664
{
659-
if(obj->hull_strength < sip->debris_min_hitpoints)
660-
obj->hull_strength = sip->debris_min_hitpoints;
665+
if (obj->hull_strength < min_hp)
666+
obj->hull_strength = min_hp;
661667
}
662-
else if(sip->debris_max_hitpoints >= 0.0f)
668+
else if(max_hp >= 0.0f)
663669
{
664-
if(obj->hull_strength > sip->debris_max_hitpoints)
665-
obj->hull_strength = sip->debris_max_hitpoints;
670+
if (obj->hull_strength > max_hp)
671+
obj->hull_strength = max_hp;
666672
}
667673
db->damage_mult = sip->debris_damage_mult;
668674

code/ship/ship.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,7 @@ void ship_info::clone(const ship_info& other)
10851085
debris_damage_type_idx = other.debris_damage_type_idx;
10861086
debris_min_hitpoints = other.debris_min_hitpoints;
10871087
debris_max_hitpoints = other.debris_max_hitpoints;
1088+
debris_hitpoints_radius_multi = other.debris_hitpoints_radius_multi;
10881089
debris_damage_mult = other.debris_damage_mult;
10891090
debris_arc_percent = other.debris_arc_percent;
10901091
debris_gravity_const = other.debris_gravity_const;
@@ -1440,6 +1441,7 @@ void ship_info::move(ship_info&& other)
14401441
debris_damage_type_idx = other.debris_damage_type_idx;
14411442
debris_min_hitpoints = other.debris_min_hitpoints;
14421443
debris_max_hitpoints = other.debris_max_hitpoints;
1444+
debris_hitpoints_radius_multi = other.debris_hitpoints_radius_multi;
14431445
debris_damage_mult = other.debris_damage_mult;
14441446
debris_arc_percent = other.debris_arc_percent;
14451447
debris_gravity_const = other.debris_gravity_const;
@@ -1799,6 +1801,7 @@ ship_info::ship_info()
17991801
debris_max_speed = -1.0f;
18001802
debris_min_rotspeed = -1.0f;
18011803
debris_max_rotspeed = -1.0f;
1804+
debris_hitpoints_radius_multi = -1.0f;
18021805
debris_damage_type_idx = -1;
18031806
debris_min_hitpoints = -1.0f;
18041807
debris_max_hitpoints = -1.0f;
@@ -3442,6 +3445,11 @@ static void parse_ship_values(ship_info* sip, const bool is_template, const bool
34423445
if(sip->debris_max_hitpoints < 0.0f)
34433446
Warning(LOCATION, "Debris max hitpoints on %s '%s' is below 0 and will be ignored", info_type_name, sip->name);
34443447
}
3448+
if(optional_string("+Hitpoints Radius Multiplier:")) {
3449+
stuff_float(&sip->debris_hitpoints_radius_multi);
3450+
if (sip->debris_hitpoints_radius_multi < 0.0f)
3451+
Warning(LOCATION, "Hitpoints Radius Multiplier on %s '%s' is below 0 and will be ignored", info_type_name, sip->name);
3452+
}
34453453
if(optional_string("+Damage Multiplier:")) {
34463454
stuff_float(&sip->debris_damage_mult);
34473455
if(sip->debris_damage_mult < 0.0f)

code/ship/ship.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,7 @@ class ship_info
12361236
int debris_damage_type_idx;
12371237
float debris_min_hitpoints;
12381238
float debris_max_hitpoints;
1239+
float debris_hitpoints_radius_multi;
12391240
float debris_damage_mult;
12401241
float debris_arc_percent;
12411242
float debris_gravity_const; // see gravity_const above

0 commit comments

Comments
 (0)