MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / PlayerShipBreakup

Function PlayerShipBreakup

Descent3/Player.cpp:3149–3188  ·  view source on GitHub ↗

breaks off a random piece.

Source from the content-addressed store, hash-verified

3147
3148// breaks off a random piece.
3149void PlayerShipBreakup(object *obj, float magnitude) {
3150 int subobjnum, i, j, idx;
3151 unsigned test_flag;
3152 int n_models = Death[obj->id].dying_model ? Death[obj->id].dying_model->n_models : 0;
3153 int n_remaining_models;
3154
3155 // don't break off object 0.
3156 if (n_models == 1)
3157 return;
3158
3159 // count number of valid subobjects skip 1st subobject
3160 n_remaining_models = 0;
3161 test_flag = obj->rtype.pobj_info.subobj_flags;
3162 for (i = 1; i < n_models; i++) {
3163 if (test_flag & (1 << i))
3164 n_remaining_models++;
3165 }
3166
3167 // this is an INDEX into the VALID subobjects in the polymodel. (skip 1st subobj)
3168 idx = (ps_rand() * n_remaining_models / D3_RAND_MAX) + 1;
3169
3170 subobjnum = -1;
3171 for (i = 1, j = 1; i < n_models; i++) {
3172 if (test_flag & (1 << i)) { // valid subobject?
3173 if (idx == j) { // correct subobject index?
3174 test_flag &= ~(1 << i);
3175 subobjnum = i;
3176 break;
3177 }
3178 j++;
3179 }
3180 }
3181
3182 // okay, if no suboject found, blowup.
3183 if (subobjnum == -1) {
3184 StartPlayerExplosion(obj->id);
3185 } else {
3186 PlayerShipSpewPart(obj, subobjnum, magnitude);
3187 }
3188}
3189
3190// spews a part of the player ship and all its child subobjects
3191void PlayerShipSpewPartSub(object *obj, bsp_info *submodel, float magnitude);

Callers 1

DoNewPlayerDeathFrameFunction · 0.85

Calls 3

ps_randFunction · 0.85
StartPlayerExplosionFunction · 0.85
PlayerShipSpewPartFunction · 0.85

Tested by

no test coverage detected