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

Function CreateImpactSpawnFromWeapon

Descent3/WeaponFire.cpp:3291–3353  ·  view source on GitHub ↗

Creates chidren from a dying weapon

Source from the content-addressed store, hash-verified

3289
3290// Creates chidren from a dying weapon
3291void CreateImpactSpawnFromWeapon(object *obj, vector *normal) {
3292 int n = obj->id;
3293 object *home_target = NULL;
3294
3295 ASSERT(Weapons[n].spawn_count > 0 && Weapons[n].spawn_handle >= 0);
3296
3297 int num = Weapons[n].spawn_count;
3298 int spawn_index = Weapons[n].spawn_handle;
3299
3300 // See if we should spawn the alternate
3301 if (Weapons[n].alternate_spawn_handle >= 0 && Weapons[n].alternate_chance > 0) {
3302 if ((ps_rand() % 100) < Weapons[n].alternate_chance)
3303 spawn_index = Weapons[n].alternate_spawn_handle;
3304 }
3305
3306 if (Game_mode & GM_MULTI)
3307 ps_srand(num);
3308
3309 if (Weapons[n].flags & WF_HOMING_SPLIT) {
3310 home_target = FindSpawnHomingTarget(obj);
3311 }
3312
3313 for (int i = 0; i < num; i++) {
3314 if (home_target != NULL) {
3315 vector subvec = home_target->pos - obj->pos;
3316 float mag = vm_GetMagnitudeFast(&subvec);
3317 subvec /= mag;
3318
3319 int objnum = CreateAndFireWeapon(&obj->pos, &subvec, obj, spawn_index);
3320
3321 // Stagger the weapons a bit
3322 if (objnum > -1) {
3323 object *created_obj = &Objects[objnum];
3324
3325 float scalar = .2 + ((float)(ps_rand() % 1000) / 1000.0);
3326
3327 created_obj->mtype.phys_info.velocity *= scalar;
3328 }
3329 } else {
3330 matrix temp_mat;
3331 matrix rot_mat;
3332 vector new_norm;
3333
3334 float norm = ((float)(ps_rand() % 1000)) / 1000.0;
3335 int x_twist = 16384 - (norm * 32768);
3336 if (x_twist < 0)
3337 x_twist = 65536 + x_twist;
3338
3339 norm = ((float)(ps_rand() % 1000)) / 1000.0;
3340 int y_twist = 16384 - (norm * 32768);
3341 if (y_twist < 0)
3342 y_twist = 65536 + y_twist;
3343
3344 vm_VectorToMatrix(&rot_mat, normal, NULL, NULL);
3345 vm_TransposeMatrix(&rot_mat);
3346 vm_AnglesToMatrix(&temp_mat, x_twist, y_twist, 0);
3347
3348 new_norm = temp_mat.fvec * rot_mat;

Callers 2

collide_weapon_and_wallFunction · 0.85

Calls 8

ps_randFunction · 0.85
ps_srandFunction · 0.85
FindSpawnHomingTargetFunction · 0.85
CreateAndFireWeaponFunction · 0.85
vm_GetMagnitudeFastFunction · 0.50
vm_VectorToMatrixFunction · 0.50
vm_TransposeMatrixFunction · 0.50
vm_AnglesToMatrixFunction · 0.50

Tested by

no test coverage detected