Creates chidren from a dying weapon
| 3289 | |
| 3290 | // Creates chidren from a dying weapon |
| 3291 | void 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; |
no test coverage detected