Skip to content

Commit 75a7fc5

Browse files
Merge pull request #6901 from wookieejedi/debris-cleanup-2
Debris Cleanup
2 parents 6132f8b + 32183f5 commit 75a7fc5

3 files changed

Lines changed: 26 additions & 16 deletions

File tree

code/debris/debris.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include "utils/Random.h"
3838
#include "weapon/weapon.h"
3939

40-
constexpr int MIN_RADIUS_FOR_PERSISTENT_DEBRIS = 50; // ship radius at which debris from it becomes persistant
4140
constexpr int DEBRIS_SOUND_DELAY = 2000; // time to start debris sound after created
4241

4342
int Num_hull_pieces; // number of hull pieces in existence
@@ -567,22 +566,10 @@ object *debris_create_only(int parent_objnum, int parent_ship_class, int alt_typ
567566
}
568567

569568
// Create Debris piece n!
570-
if ( hull_flag ) {
571-
if (Random::next() < (Random::MAX_VALUE/6)) // Make some pieces blow up shortly after explosion.
572-
db->lifeleft = 2.0f * (frand()) + 0.5f;
573-
else {
574-
db->flags.set(Debris_Flags::DoNotExpire);
575-
db->lifeleft = -1.0f; // large hull pieces stay around forever
576-
}
577-
} else {
578-
// small non-hull pieces should stick around longer the larger they are
579-
// sqrtf should make sure its never too crazy long
580-
db->lifeleft = (frand() * 2.0f + 0.1f) * sqrtf(radius);
581-
}
582-
583-
//WMC - Oh noes, we may need to change lifeleft
584569
if(hull_flag)
585570
{
571+
// set lifeleft based on tabled entries if they are not negative
572+
// coded originally by WMC then clean-up added by wookieejedi
586573
if(sip->debris_min_lifetime >= 0.0f && sip->debris_max_lifetime >= 0.0f)
587574
{
588575
db->lifeleft = (( sip->debris_max_lifetime - sip->debris_min_lifetime ) * frand()) + sip->debris_min_lifetime;
@@ -597,6 +584,22 @@ object *debris_create_only(int parent_objnum, int parent_ship_class, int alt_typ
597584
if(db->lifeleft > sip->debris_max_lifetime)
598585
db->lifeleft = sip->debris_max_lifetime;
599586
}
587+
// By default, make some pieces blow up shortly after explosion.
588+
else if (Random::next() < (Random::MAX_VALUE / 6))
589+
{
590+
db->lifeleft = 2.0f * (frand()) + 0.5f;
591+
}
592+
else
593+
{
594+
db->flags.set(Debris_Flags::DoNotExpire);
595+
db->lifeleft = -1.0f; // large hull pieces stay around forever
596+
}
597+
}
598+
else
599+
{
600+
// small non-hull pieces should stick around longer the larger they are
601+
// sqrtf should make sure its never too crazy long
602+
db->lifeleft = (frand() * 2.0f + 0.1f) * sqrtf(radius);
600603
}
601604

602605
// increase lifetime for vaporized debris
@@ -698,7 +701,7 @@ object *debris_create_only(int parent_objnum, int parent_ship_class, int alt_typ
698701
db->arc_timeout = TIMESTAMP::immediate();
699702
}
700703

701-
if (parent_objnum >= 0 && Objects[parent_objnum].radius >= MIN_RADIUS_FOR_PERSISTENT_DEBRIS) {
704+
if (parent_objnum >= 0 && Objects[parent_objnum].radius >= Min_radius_for_persistent_debris) {
702705
db->flags.set(Debris_Flags::DoNotExpire);
703706
} else {
704707
debris_add_to_hull_list(db);

code/mod_table/mod_table.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ bool Disable_intro_movie;
173173
bool Show_locked_status_scramble_missions;
174174
bool Disable_expensive_turret_target_check;
175175
float Shield_percent_skips_damage;
176+
float Min_radius_for_persistent_debris;
176177

177178

178179
#ifdef WITH_DISCORD
@@ -1551,6 +1552,10 @@ void parse_mod_table(const char *filename)
15511552
}
15521553
}
15531554

1555+
if (optional_string("$Minimum ship radius for persistent debris:")) {
1556+
stuff_float(&Min_radius_for_persistent_debris);
1557+
}
1558+
15541559
// end of options ----------------------------------------
15551560

15561561
// if we've been through once already and are at the same place, force a move
@@ -1788,6 +1793,7 @@ void mod_table_reset()
17881793
Show_locked_status_scramble_missions = false;
17891794
Disable_expensive_turret_target_check = false;
17901795
Shield_percent_skips_damage = 0.1f;
1796+
Min_radius_for_persistent_debris = 50.0f;
17911797
}
17921798

17931799
void mod_table_set_version_flags()

code/mod_table/mod_table.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ extern bool Disable_intro_movie;
188188
extern bool Show_locked_status_scramble_missions;
189189
extern bool Disable_expensive_turret_target_check;
190190
extern float Shield_percent_skips_damage;
191+
extern float Min_radius_for_persistent_debris;
191192

192193
void mod_table_init();
193194
void mod_table_post_process();

0 commit comments

Comments
 (0)