Do the spray effect
| 2277 | |
| 2278 | // Do the spray effect |
| 2279 | void DoSprayEffect(object *obj, otype_wb_info *static_wb, uint8_t wb_index) { |
| 2280 | vector laser_pos, laser_dir; |
| 2281 | int cur_m_bit; |
| 2282 | |
| 2283 | ASSERT(!(obj->flags & OF_DYING)); |
| 2284 | |
| 2285 | poly_model *pm = &Poly_models[obj->rtype.pobj_info.model_num]; |
| 2286 | |
| 2287 | // Go through each gun point |
| 2288 | for (cur_m_bit = 0; cur_m_bit < pm->poly_wb[0].num_gps; cur_m_bit++) { |
| 2289 | // Figure out out if this weapon fires from this gunpoint |
| 2290 | if (static_wb->gp_fire_masks[obj->dynamic_wb[wb_index].cur_firing_mask] & (0x01 << cur_m_bit)) { |
| 2291 | int weapon_num = static_wb->gp_weapon_index[cur_m_bit]; |
| 2292 | |
| 2293 | WeaponCalcGun(&laser_pos, &laser_dir, obj, pm->poly_wb[0].gp_index[cur_m_bit]); |
| 2294 | int visnum = VisEffectCreate(VIS_FIREBALL, SPRAY_INDEX, obj->roomnum, &laser_pos); |
| 2295 | |
| 2296 | if (visnum < 0) |
| 2297 | return; |
| 2298 | |
| 2299 | vis_effect *vis = &VisEffects[visnum]; |
| 2300 | |
| 2301 | // Set the initial velocity |
| 2302 | vm_ScaleVector(&vis->velocity, &laser_dir, Weapons[weapon_num].phys_info.velocity.z); |
| 2303 | |
| 2304 | // Set initial velocity to that of the firing object |
| 2305 | if (Weapons[weapon_num].phys_info.flags & PF_USES_PARENT_VELOCITY) { |
| 2306 | float fdot = (obj->mtype.phys_info.velocity * obj->orient.fvec); |
| 2307 | vector fvel; |
| 2308 | |
| 2309 | if (fdot > 0.0) |
| 2310 | fvel = obj->orient.fvec * fdot; |
| 2311 | else |
| 2312 | fvel = Zero_vector; |
| 2313 | |
| 2314 | vector rvel = 0.1f * obj->orient.rvec * (obj->mtype.phys_info.velocity * obj->orient.rvec); |
| 2315 | vector uvel = 0.1f * obj->orient.uvec * (obj->mtype.phys_info.velocity * obj->orient.uvec); |
| 2316 | |
| 2317 | vis->velocity += fvel + rvel + uvel; |
| 2318 | } |
| 2319 | |
| 2320 | vis->movement_type = MT_PHYSICS; |
| 2321 | vis->custom_handle = Weapons[weapon_num].fire_image_handle; |
| 2322 | vis->drag = Weapons[weapon_num].phys_info.drag; |
| 2323 | vis->phys_flags = Weapons[weapon_num].phys_info.flags; |
| 2324 | vis->mass = Weapons[weapon_num].phys_info.mass; |
| 2325 | vis->size = Weapons[weapon_num].size; |
| 2326 | vis->lifetime = Weapons[weapon_num].life_time; |
| 2327 | vis->lifeleft = vis->lifetime; |
| 2328 | |
| 2329 | // Now create extras so that there are no gaps |
| 2330 | |
| 2331 | if (obj != Viewer_object) { |
| 2332 | // Find hit point so we know when to stop |
| 2333 | float life_scalar = 1.0; |
| 2334 | fvi_query fq; |
| 2335 | fvi_info hit_data; |
| 2336 | int fate; |
no test coverage detected