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
4140constexpr int DEBRIS_SOUND_DELAY = 2000 ; // time to start debris sound after created
4241
4342int 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);
0 commit comments