2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
19 char laser_rcsid[] = "$Id: laser.c,v 1.3 2001-01-31 15:17:54 bradleyb Exp $";
61 int Laser_rapid_fire = 0;
64 object *Guided_missile[MAX_PLAYERS]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
65 int Guided_missile_sig[MAX_PLAYERS]={-1,-1,-1,-1,-1,-1,-1,-1};
67 int find_homing_object_complete(vms_vector *curpos, object *tracker, int track_obj_type1, int track_obj_type2);
69 extern char Multi_is_guided;
70 extern char BounceCheat;
72 extern void newdemo_record_guided_end();
73 extern void newdemo_record_guided_start();
75 int find_homing_object(vms_vector *curpos, object *tracker);
77 //---------------------------------------------------------------------------------
78 // Called by render code.... determines if the laser is from a robot or the
79 // player and calls the appropriate routine.
81 void Laser_render(object *obj)
84 // Commented out by John (sort of, typed by Mike) on 6/8/94
87 case WEAPON_TYPE_WEAK_LASER:
88 case WEAPON_TYPE_STRONG_LASER:
89 case WEAPON_TYPE_CANNON_BALL:
90 case WEAPON_TYPE_MISSILE:
93 Error( "Invalid weapon type in Laser_render\n" );
97 switch( Weapon_info[obj->id].render_type ) {
98 case WEAPON_RENDER_LASER:
99 Int3(); // Not supported anymore!
100 //Laser_draw_one(obj-Objects, Weapon_info[obj->id].bitmap );
102 case WEAPON_RENDER_BLOB:
103 draw_object_blob(obj, Weapon_info[obj->id].bitmap );
105 case WEAPON_RENDER_POLYMODEL:
107 case WEAPON_RENDER_VCLIP:
108 Int3(); // Oops, not supported, type added by mk on 09/09/94, but not for lasers...
110 Error( "Invalid weapon render type in Laser_render\n" );
115 //---------------------------------------------------------------------------------
116 // Draws a texture-mapped laser bolt
118 //void Laser_draw_one( int objnum, grs_bitmap * bmp )
123 // vms_vector start_pos,end_pos;
125 // obj = &Objects[objnum];
127 // start_pos = obj->pos;
128 // vm_vec_scale_add(&end_pos,&start_pos,&obj->orient.fvec,-Laser_length);
130 // g3_rotate_point(&p1,&start_pos);
131 // g3_rotate_point(&p2,&end_pos);
134 // t2 = Interpolation_method;
135 // t3 = Transparency_on;
138 // //Interpolation_method = 3; // Full perspective
139 // Interpolation_method = 1; // Linear
140 // Transparency_on = 1;
142 // //gr_setcolor( gr_getcolor(31,15,0));
143 // //g3_draw_line_ptrs(p1,p2);
144 // //g3_draw_rod(p1,0x2000,p2,0x2000);
145 // //g3_draw_rod(p1,Laser_width,p2,Laser_width);
146 // g3_draw_rod_tmap(bmp,&p2,Laser_width,&p1,Laser_width,0);
148 // Interpolation_method = t2;
149 // Transparency_on = t3;
153 // Changed by MK on 09/07/94
154 // I want you to be able to blow up your own bombs.
155 // AND...Your proximity bombs can blow you up if they're 2.0 seconds or more old.
156 // Changed by MK on 06/06/95: Now must be 4.0 seconds old. Much valid Net-complaining.
157 int laser_are_related( int o1, int o2 )
159 if ( (o1<0) || (o2<0) )
162 // See if o2 is the parent of o1
163 if ( Objects[o1].type == OBJ_WEAPON )
164 if ( (Objects[o1].ctype.laser_info.parent_num==o2) && (Objects[o1].ctype.laser_info.parent_signature==Objects[o2].signature) )
166 // o1 is a weapon, o2 is the parent of 1, so if o1 is PROXIMITY_BOMB and o2 is player, they are related only if o1 < 2.0 seconds old
167 if ((Objects[o1].id == PHOENIX_ID && (GameTime > Objects[o1].ctype.laser_info.creation_time + F1_0/4)) ||
168 (Objects[o1].id == GUIDEDMISS_ID && (GameTime > Objects[o1].ctype.laser_info.creation_time + F1_0*2)) ||
169 (((Objects[o1].id == PROXIMITY_ID) || (Objects[o1].id == SUPERPROX_ID)) && (GameTime > Objects[o1].ctype.laser_info.creation_time + F1_0*4))) {
175 // See if o1 is the parent of o2
176 if ( Objects[o2].type == OBJ_WEAPON )
178 if ( (Objects[o2].ctype.laser_info.parent_num==o1) && (Objects[o2].ctype.laser_info.parent_signature==Objects[o1].signature) )
180 // o2 is a weapon, o1 is the parent of 2, so if o2 is PROXIMITY_BOMB and o1 is player, they are related only if o1 < 2.0 seconds old
181 if ((Objects[o2].id == PHOENIX_ID && (GameTime > Objects[o2].ctype.laser_info.creation_time + F1_0/4)) ||
182 (Objects[o2].id == GUIDEDMISS_ID && (GameTime > Objects[o2].ctype.laser_info.creation_time + F1_0*2)) ||
183 (((Objects[o2].id == PROXIMITY_ID) || (Objects[o2].id == SUPERPROX_ID)) && (GameTime > Objects[o2].ctype.laser_info.creation_time + F1_0*4))) {
190 // They must both be weapons
191 if ( Objects[o1].type != OBJ_WEAPON || Objects[o2].type != OBJ_WEAPON )
194 // Here is the 09/07/94 change -- Siblings must be identical, others can hurt each other
195 // See if they're siblings...
196 // MK: 06/08/95, Don't allow prox bombs to detonate for 3/4 second. Else too likely to get toasted by your own bomb if hit by opponent.
197 if ( Objects[o1].ctype.laser_info.parent_signature==Objects[o2].ctype.laser_info.parent_signature )
199 if (Objects[o1].id == PROXIMITY_ID || Objects[o2].id == PROXIMITY_ID || Objects[o1].id == SUPERPROX_ID || Objects[o2].id == SUPERPROX_ID) {
200 // If neither is older than 1/2 second, then can't blow up!
201 if ((GameTime > (Objects[o1].ctype.laser_info.creation_time + F1_0/2)) || (GameTime > (Objects[o2].ctype.laser_info.creation_time + F1_0/2)))
209 // Anything can cause a collision with a robot super prox mine.
210 if (Objects[o1].id == ROBOT_SUPERPROX_ID || Objects[o2].id == ROBOT_SUPERPROX_ID ||
211 Objects[o1].id == PROXIMITY_ID || Objects[o2].id == PROXIMITY_ID ||
212 Objects[o1].id == SUPERPROX_ID || Objects[o2].id == SUPERPROX_ID ||
213 Objects[o1].id == PMINE_ID || Objects[o2].id == PMINE_ID)
219 //--unused-- int Muzzle_scale=2;
222 void do_muzzle_stuff(int segnum, vms_vector *pos)
224 Muzzle_data[Muzzle_queue_index].create_time = timer_get_fixed_seconds();
225 Muzzle_data[Muzzle_queue_index].segnum = segnum;
226 Muzzle_data[Muzzle_queue_index].pos = *pos;
227 Muzzle_queue_index++;
228 if (Muzzle_queue_index >= MUZZLE_QUEUE_MAX)
229 Muzzle_queue_index = 0;
232 //creates a weapon object
233 int create_weapon_object(int weapon_type,int segnum,vms_vector *position)
236 fix laser_radius = -1;
240 switch( Weapon_info[weapon_type].render_type ) {
242 case WEAPON_RENDER_BLOB:
243 rtype = RT_LASER; // Render as a laser even if blob (see render code above for explanation)
244 laser_radius = Weapon_info[weapon_type].blob_size;
246 case WEAPON_RENDER_POLYMODEL:
247 laser_radius = 0; // Filled in below.
250 case WEAPON_RENDER_LASER:
251 Int3(); // Not supported anymore
253 case WEAPON_RENDER_NONE:
257 case WEAPON_RENDER_VCLIP:
258 rtype = RT_WEAPON_VCLIP;
259 laser_radius = Weapon_info[weapon_type].blob_size;
262 Error( "Invalid weapon render type in Laser_create_new\n" );
265 Assert(laser_radius != -1);
268 objnum = obj_create( OBJ_WEAPON, weapon_type, segnum, position, NULL, laser_radius, CT_WEAPON, MT_PHYSICS, rtype );
270 obj = &Objects[objnum];
272 if (Weapon_info[weapon_type].render_type == WEAPON_RENDER_POLYMODEL) {
273 obj->rtype.pobj_info.model_num = Weapon_info[obj->id].model_num;
274 obj->size = fixdiv(Polygon_models[obj->rtype.pobj_info.model_num].rad,Weapon_info[obj->id].po_len_to_width_ratio);
277 obj->mtype.phys_info.mass = Weapon_info[weapon_type].mass;
278 obj->mtype.phys_info.drag = Weapon_info[weapon_type].drag;
279 vm_vec_zero(&obj->mtype.phys_info.thrust);
281 if (Weapon_info[weapon_type].bounce==1)
282 obj->mtype.phys_info.flags |= PF_BOUNCE;
284 if (Weapon_info[weapon_type].bounce==2 || BounceCheat)
285 obj->mtype.phys_info.flags |= PF_BOUNCE+PF_BOUNCES_TWICE;
291 extern int Doing_lighting_hack_flag;
293 // -------------------------------------------------------------------------------------------------------------------------------
294 // ***** HEY ARTISTS!! *****
295 // Here are the constants you're looking for! --MK
297 // Change the following constants to affect the look of the omega cannon.
298 // Changing these constants will not affect the damage done.
299 // WARNING: If you change DESIRED_OMEGA_DIST and MAX_OMEGA_BLOBS, you don't merely change the look of the cannon,
300 // you change its range. If you decrease DESIRED_OMEGA_DIST, you decrease how far the gun can fire.
301 #define MIN_OMEGA_BLOBS 3 // No matter how close the obstruction, at this many blobs created.
302 #define MIN_OMEGA_DIST (F1_0*3) // At least this distance between blobs, unless doing so would violate MIN_OMEGA_BLOBS
303 #define DESIRED_OMEGA_DIST (F1_0*5) // This is the desired distance between blobs. For distances > MIN_OMEGA_BLOBS*DESIRED_OMEGA_DIST, but not very large, this will apply.
304 #define MAX_OMEGA_BLOBS 16 // No matter how far away the obstruction, this is the maximum number of blobs.
305 #define MAX_OMEGA_DIST (MAX_OMEGA_BLOBS * DESIRED_OMEGA_DIST) // Maximum extent of lightning blobs.
307 // Additionally, several constants which apply to homing objects in general control the behavior of the Omega Cannon.
308 // They are defined in laser.h. They are copied here for reference. These values are valid on 1/10/96:
309 // If you want the Omega Cannon view cone to be different than the Homing Missile viewcone, contact MK to make the change.
310 // (Unless you are a programmer, in which case, do it yourself!)
311 #define OMEGA_MIN_TRACKABLE_DOT (15*F1_0/16) // Larger values mean narrower cone. F1_0 means damn near impossible. 0 means 180 degree field of view.
312 #define OMEGA_MAX_TRACKABLE_DIST MAX_OMEGA_DIST // An object must be at least this close to be tracked.
314 // Note, you don't need to change these constants. You can control damage and energy consumption by changing the
315 // usual bitmaps.tbl parameters.
316 #define OMEGA_DAMAGE_SCALE 32 // Controls how much damage is done. This gets multiplied by FrameTime and then again by the damage specified in bitmaps.tbl in the $WEAPON line.
317 #define OMEGA_ENERGY_CONSUMPTION 16 // Controls how much energy is consumed. This gets multiplied by FrameTime and then again by the energy parameter from bitmaps.tbl.
318 // -------------------------------------------------------------------------------------------------------------------------------
320 void delete_old_omega_blobs(object *parent_objp)
326 parent_num = parent_objp->ctype.laser_info.parent_num;
328 for (i=0; i<=Highest_object_index; i++)
329 if (Objects[i].type == OBJ_WEAPON)
330 if (Objects[i].id == OMEGA_ID)
331 if (Objects[i].ctype.laser_info.parent_num == parent_num) {
336 mprintf((0, "%i Omega blobs deleted in frame %i\n", count, FrameCount));
339 // ---------------------------------------------------------------------------------
340 void create_omega_blobs(int firing_segnum, vms_vector *firing_pos, vms_vector *goal_pos, object *parent_objp)
342 int i, last_segnum, last_created_objnum = -1;
343 vms_vector vec_to_goal;
347 vms_vector omega_delta_vector;
348 vms_vector blob_pos, perturb_vec;
349 fix perturb_array[MAX_OMEGA_BLOBS];
351 if (Game_mode & GM_MULTI)
352 delete_old_omega_blobs(parent_objp);
354 vm_vec_sub(&vec_to_goal, goal_pos, firing_pos);
356 dist_to_goal = vm_vec_normalize_quick(&vec_to_goal);
358 if (dist_to_goal < MIN_OMEGA_BLOBS * MIN_OMEGA_DIST) {
359 omega_blob_dist = MIN_OMEGA_DIST;
360 num_omega_blobs = dist_to_goal/omega_blob_dist;
361 if (num_omega_blobs == 0)
364 omega_blob_dist = DESIRED_OMEGA_DIST;
365 num_omega_blobs = dist_to_goal / omega_blob_dist;
366 if (num_omega_blobs > MAX_OMEGA_BLOBS) {
367 num_omega_blobs = MAX_OMEGA_BLOBS;
368 omega_blob_dist = dist_to_goal / num_omega_blobs;
369 } else if (num_omega_blobs < MIN_OMEGA_BLOBS) {
370 num_omega_blobs = MIN_OMEGA_BLOBS;
371 omega_blob_dist = dist_to_goal / num_omega_blobs;
375 omega_delta_vector = vec_to_goal;
376 vm_vec_scale(&omega_delta_vector, omega_blob_dist);
378 // Now, create all the blobs
379 blob_pos = *firing_pos;
380 last_segnum = firing_segnum;
382 // If nearby, don't perturb vector. If not nearby, start halfway out.
383 if (dist_to_goal < MIN_OMEGA_DIST*4) {
384 for (i=0; i<num_omega_blobs; i++)
385 perturb_array[i] = 0;
387 vm_vec_scale_add2(&blob_pos, &omega_delta_vector, F1_0/2); // Put first blob half way out.
388 for (i=0; i<num_omega_blobs/2; i++) {
389 perturb_array[i] = F1_0*i + F1_0/4;
390 perturb_array[num_omega_blobs-1-i] = F1_0*i;
394 // Create random perturbation vector, but favor _not_ going up in player's reference.
395 make_random_vector(&perturb_vec);
396 vm_vec_scale_add2(&perturb_vec, &parent_objp->orient.uvec, -F1_0/2);
398 Doing_lighting_hack_flag = 1; // Ugly, but prevents blobs which are probably outside the mine from killing framerate.
400 for (i=0; i<num_omega_blobs; i++) {
402 int blob_objnum, segnum;
404 // This will put the last blob right at the destination object, causing damage.
405 if (i == num_omega_blobs-1)
406 vm_vec_scale_add2(&blob_pos, &omega_delta_vector, 15*F1_0/32); // Move last blob another (almost) half section
408 // Every so often, re-perturb blobs
412 make_random_vector(&temp_vec);
413 vm_vec_scale_add2(&perturb_vec, &temp_vec, F1_0/4);
416 vm_vec_scale_add(&temp_pos, &blob_pos, &perturb_vec, perturb_array[i]);
418 segnum = find_point_seg(&temp_pos, last_segnum);
422 last_segnum = segnum;
423 blob_objnum = obj_create(OBJ_WEAPON, OMEGA_ID, segnum, &temp_pos, NULL, 0, CT_WEAPON, MT_PHYSICS, RT_WEAPON_VCLIP );
424 if (blob_objnum == -1)
427 last_created_objnum = blob_objnum;
429 objp = &Objects[blob_objnum];
431 objp->lifeleft = ONE_FRAME_TIME;
432 objp->mtype.phys_info.velocity = vec_to_goal;
434 // Only make the last one move fast, else multiple blobs might collide with target.
435 vm_vec_scale(&objp->mtype.phys_info.velocity, F1_0*4);
437 objp->size = Weapon_info[objp->id].blob_size;
439 objp->shields = fixmul(OMEGA_DAMAGE_SCALE*FrameTime, Weapon_info[objp->id].strength[Difficulty_level]);
441 objp->ctype.laser_info.parent_type = parent_objp->type;
442 objp->ctype.laser_info.parent_signature = parent_objp->signature;
443 objp->ctype.laser_info.parent_num = parent_objp-Objects;
444 objp->movement_type = MT_NONE; // Only last one moves, that will get bashed below.
448 vm_vec_add2(&blob_pos, &omega_delta_vector);
452 // Make last one move faster, but it's already moving at speed = F1_0*4.
453 if (last_created_objnum != -1) {
454 vm_vec_scale(&Objects[last_created_objnum].mtype.phys_info.velocity, Weapon_info[OMEGA_ID].speed[Difficulty_level]/4);
455 Objects[last_created_objnum].movement_type = MT_PHYSICS;
458 Doing_lighting_hack_flag = 0;
461 #define MIN_OMEGA_CHARGE (MAX_OMEGA_CHARGE/8)
462 #define OMEGA_CHARGE_SCALE 4 // FrameTime / OMEGA_CHARGE_SCALE added to Omega_charge every frame.
463 fix Omega_charge = MAX_OMEGA_CHARGE;
465 #define OMEGA_CHARGE_SCALE 4
467 int Last_omega_fire_frame=0;
469 // ---------------------------------------------------------------------------------
470 // Call this every frame to recharge the Omega Cannon.
471 void omega_charge_frame(void)
473 fix delta_charge, old_omega_charge;
475 if (Omega_charge == MAX_OMEGA_CHARGE)
478 if (!(player_has_weapon(OMEGA_INDEX, 0) & HAS_WEAPON_FLAG))
484 if ((Primary_weapon == OMEGA_INDEX) && (Omega_charge == 0) && (Players[Player_num].energy == 0)) {
486 auto_select_weapon(0);
489 // Don't charge while firing.
490 if ((Last_omega_fire_frame == FrameCount) || (Last_omega_fire_frame == FrameCount-1))
493 if (Players[Player_num].energy) {
496 old_omega_charge = Omega_charge;
497 Omega_charge += FrameTime/OMEGA_CHARGE_SCALE;
498 if (Omega_charge > MAX_OMEGA_CHARGE)
499 Omega_charge = MAX_OMEGA_CHARGE;
501 delta_charge = Omega_charge - old_omega_charge;
503 energy_used = fixmul(F1_0*190/17, delta_charge);
504 if (Difficulty_level < 2)
505 energy_used = fixmul(energy_used, i2f(Difficulty_level+2)/4);
507 Players[Player_num].energy -= energy_used;
508 if (Players[Player_num].energy < 0)
509 Players[Player_num].energy = 0;
515 // -- fix Last_omega_muzzle_flash_time;
517 // ---------------------------------------------------------------------------------
518 // *objp is the object firing the omega cannon
519 // *pos is the location from which the omega bolt starts
520 void do_omega_stuff(object *parent_objp, vms_vector *firing_pos, object *weapon_objp)
522 int lock_objnum, firing_segnum;
524 int pnum = parent_objp->id;
526 if (pnum == Player_num) {
527 // If charge >= min, or (some charge and zero energy), allow to fire.
528 if (!((Omega_charge >= MIN_OMEGA_CHARGE) || (Omega_charge && !Players[pnum].energy))) {
529 obj_delete(weapon_objp-Objects);
533 Omega_charge -= FrameTime;
534 if (Omega_charge < 0)
537 // Ensure that the lightning cannon can be fired next frame.
538 Next_laser_fire_time = GameTime+1;
540 Last_omega_fire_frame = FrameCount;
543 weapon_objp->ctype.laser_info.parent_type = OBJ_PLAYER;
544 weapon_objp->ctype.laser_info.parent_num = Players[pnum].objnum;
545 weapon_objp->ctype.laser_info.parent_signature = Objects[Players[pnum].objnum].signature;
547 lock_objnum = find_homing_object(firing_pos, weapon_objp);
549 firing_segnum = find_point_seg(firing_pos, parent_objp->segnum);
552 if ( parent_objp == Viewer )
553 digi_play_sample( Weapon_info[weapon_objp->id].flash_sound, F1_0 );
555 digi_link_sound_to_pos( Weapon_info[weapon_objp->id].flash_sound, weapon_objp->segnum, 0, &weapon_objp->pos, 0, F1_0 );
557 // -- if ((Last_omega_muzzle_flash_time + F1_0/4 < GameTime) || (Last_omega_muzzle_flash_time > GameTime)) {
558 // -- do_muzzle_stuff(firing_segnum, firing_pos);
559 // -- Last_omega_muzzle_flash_time = GameTime;
562 // Delete the original object. Its only purpose in life was to determine which object to home in on.
563 obj_delete(weapon_objp-Objects);
565 // If couldn't lock on anything, fire straight ahead.
566 if (lock_objnum == -1) {
570 vms_vector perturb_vec, perturbed_fvec;
572 make_random_vector(&perturb_vec);
573 vm_vec_scale_add(&perturbed_fvec, &parent_objp->orient.fvec, &perturb_vec, F1_0/16);
575 vm_vec_scale_add(&goal_pos, firing_pos, &perturbed_fvec, MAX_OMEGA_DIST);
576 fq.startseg = firing_segnum;
577 if (fq.startseg == -1) {
578 mprintf((1, "Trying to fire Omega Cannon, but gun is outside mine. Aborting!\n"));
584 fq.thisobjnum = parent_objp-Objects;
585 fq.ignore_obj_list = NULL;
586 fq.flags = FQ_IGNORE_POWERUPS | FQ_TRANSPOINT | FQ_CHECK_OBJS; //what about trans walls???
588 fate = find_vector_intersection(&fq, &hit_data);
589 if (fate != HIT_NONE) {
590 Assert(hit_data.hit_seg != -1); // How can this be? We went from inside the mine to outside without hitting anything?
591 goal_pos = hit_data.hit_pnt;
594 goal_pos = Objects[lock_objnum].pos;
596 // This is where we create a pile of omega blobs!
597 create_omega_blobs(firing_segnum, firing_pos, &goal_pos, parent_objp);
601 // ---------------------------------------------------------------------------------
602 // Initializes a laser after Fire is pressed
603 // Returns object number.
604 int Laser_create_new( vms_vector * direction, vms_vector * position, int segnum, int parent, int weapon_type, int make_sound )
608 fix parent_speed, weapon_speed;
612 Assert( weapon_type < N_weapon_types );
614 if ( (weapon_type<0) || (weapon_type>=N_weapon_types) )
617 // Don't let homing blobs make muzzle flash.
618 if (Objects[parent].type == OBJ_ROBOT)
619 do_muzzle_stuff(segnum, position);
621 objnum = create_weapon_object(weapon_type,segnum,position);
624 mprintf((1, "Can't create laser - Out of objects!\n" ));
628 obj = &Objects[objnum];
630 // Do the special Omega Cannon stuff. Then return on account of everything that follows does
631 // not apply to the Omega Cannon.
632 if (weapon_type == OMEGA_ID) {
633 // Create orientation matrix for tracking purposes.
634 vm_vector_2_matrix( &obj->orient, direction, &Objects[parent].orient.uvec ,NULL);
636 if (( &Objects[parent] != Viewer ) && (Objects[parent].type != OBJ_WEAPON)) {
638 if (Weapon_info[obj->id].flash_vclip > -1 )
639 object_create_muzzle_flash( obj->segnum, &obj->pos, Weapon_info[obj->id].flash_size, Weapon_info[obj->id].flash_vclip );
642 do_omega_stuff(&Objects[parent], position, obj);
647 if (Objects[parent].type == OBJ_PLAYER) {
648 if (weapon_type == FUSION_ID) {
650 if (Fusion_charge <= 0)
651 obj->ctype.laser_info.multiplier = F1_0;
652 else if (Fusion_charge <= 4*F1_0)
653 obj->ctype.laser_info.multiplier = F1_0 + Fusion_charge/2;
655 obj->ctype.laser_info.multiplier = 4*F1_0;
657 } else if ((weapon_type >= LASER_ID && weapon_type <= MAX_SUPER_LASER_LEVEL) && (Players[Objects[parent].id].flags & PLAYER_FLAGS_QUAD_LASERS))
658 obj->ctype.laser_info.multiplier = F1_0*3/4;
659 else if (weapon_type == GUIDEDMISS_ID) {
660 if (parent==Players[Player_num].objnum) {
661 Guided_missile[Player_num]= obj;
662 Guided_missile_sig[Player_num] = obj->signature;
663 if (Newdemo_state==ND_STATE_RECORDING)
664 newdemo_record_guided_start();
669 // Make children of smart bomb bounce so if they hit a wall right away, they
670 // won't detonate. The frame interval code will clear this bit after 1/2 second.
671 if ((weapon_type == PLAYER_SMART_HOMING_ID) || (weapon_type == SMART_MINE_HOMING_ID) || (weapon_type == ROBOT_SMART_HOMING_ID) || (weapon_type == ROBOT_SMART_MINE_HOMING_ID) || (weapon_type == EARTHSHAKER_MEGA_ID))
672 obj->mtype.phys_info.flags |= PF_BOUNCE;
674 if (Weapon_info[weapon_type].render_type == WEAPON_RENDER_POLYMODEL)
675 laser_length = Polygon_models[obj->rtype.pobj_info.model_num].rad * 2;
677 if (weapon_type == FLARE_ID)
678 obj->mtype.phys_info.flags |= PF_STICK; //this obj sticks to walls
680 obj->shields = Weapon_info[obj->id].strength[Difficulty_level];
682 // Fill in laser-specific data
684 obj->lifeleft = Weapon_info[obj->id].lifetime;
685 obj->ctype.laser_info.parent_type = Objects[parent].type;
686 obj->ctype.laser_info.parent_signature = Objects[parent].signature;
687 obj->ctype.laser_info.parent_num = parent;
689 // Assign parent type to highest level creator. This propagates parent type down from
690 // the original creator through weapons which create children of their own (ie, smart missile)
691 if (Objects[parent].type == OBJ_WEAPON) {
692 int highest_parent = parent;
696 while ((count++ < 10) && (Objects[highest_parent].type == OBJ_WEAPON)) {
699 next_parent = Objects[highest_parent].ctype.laser_info.parent_num;
700 if (Objects[next_parent].signature != Objects[highest_parent].ctype.laser_info.parent_signature)
701 break; // Probably means parent was killed. Just continue.
703 if (next_parent == highest_parent) {
704 Int3(); // Hmm, object is parent of itself. This would seem to be bad, no?
708 highest_parent = next_parent;
710 obj->ctype.laser_info.parent_num = highest_parent;
711 obj->ctype.laser_info.parent_type = Objects[highest_parent].type;
712 obj->ctype.laser_info.parent_signature = Objects[highest_parent].signature;
716 // Create orientation matrix so we can look from this pov
717 // Homing missiles also need an orientation matrix so they know if they can make a turn.
718 if ((obj->render_type == RT_POLYOBJ) || (Weapon_info[obj->id].homing_flag))
719 vm_vector_2_matrix( &obj->orient,direction, &Objects[parent].orient.uvec ,NULL);
721 if (( &Objects[parent] != Viewer ) && (Objects[parent].type != OBJ_WEAPON)) {
723 if (Weapon_info[obj->id].flash_vclip > -1 )
724 object_create_muzzle_flash( obj->segnum, &obj->pos, Weapon_info[obj->id].flash_size, Weapon_info[obj->id].flash_vclip );
728 if (Weapon_info[obj->id].flash_sound > -1 ) {
730 if ( parent == (Viewer-Objects) ) {
731 if (weapon_type == VULCAN_ID) // Make your own vulcan gun 1/2 as loud.
733 digi_play_sample( Weapon_info[obj->id].flash_sound, volume );
735 digi_link_sound_to_pos( Weapon_info[obj->id].flash_sound, obj->segnum, 0, &obj->pos, 0, volume );
740 // Fire the laser from the gun tip so that the back end of the laser bolt is at the gun tip.
741 // Move 1 frame, so that the end-tip of the laser is touching the gun barrel.
742 // This also jitters the laser a bit so that it doesn't alias.
743 // Don't do for weapons created by weapons.
744 if ((Objects[parent].type == OBJ_PLAYER) && (Weapon_info[weapon_type].render_type != WEAPON_RENDER_NONE) && (weapon_type != FLARE_ID)) {
748 vm_vec_scale_add( &end_pos, &obj->pos, direction, Laser_offset+(laser_length/2) );
749 end_segnum = find_point_seg(&end_pos, obj->segnum);
750 if (end_segnum != obj->segnum) {
751 // mprintf(0, "Warning: Laser tip not in same segment as player.\n");
752 if (end_segnum != -1) {
754 obj_relink(obj-Objects, end_segnum);
756 mprintf((0, "Warning: Laser tip outside mine. Laser not being moved to end of gun.\n"));
761 // Here's where to fix the problem with objects which are moving backwards imparting higher velocity to their weaponfire.
762 // Find out if moving backwards.
763 if ((weapon_type == PROXIMITY_ID) || (weapon_type == SUPERPROX_ID)) {
764 parent_speed = vm_vec_mag_quick(&Objects[parent].mtype.phys_info.velocity);
765 if (vm_vec_dot(&Objects[parent].mtype.phys_info.velocity, &Objects[parent].orient.fvec) < 0)
766 parent_speed = -parent_speed;
770 weapon_speed = Weapon_info[obj->id].speed[Difficulty_level];
771 if (Weapon_info[obj->id].speedvar != 128) {
774 // Get a scale factor between speedvar% and 1.0.
775 randval = F1_0 - ((d_rand() * Weapon_info[obj->id].speedvar) >> 6);
776 weapon_speed = fixmul(weapon_speed, randval);
779 // Ugly hack (too bad we're on a deadline), for homing missiles dropped by smart bomb, start them out slower.
780 if ((obj->id == PLAYER_SMART_HOMING_ID) || (obj->id == SMART_MINE_HOMING_ID) || (obj->id == ROBOT_SMART_HOMING_ID) || (obj->id == ROBOT_SMART_MINE_HOMING_ID) || (obj->id == EARTHSHAKER_MEGA_ID))
783 if (Weapon_info[obj->id].thrust != 0)
786 vm_vec_copy_scale( &obj->mtype.phys_info.velocity, direction, weapon_speed + parent_speed );
789 if (Weapon_info[weapon_type].thrust != 0) {
790 obj->mtype.phys_info.thrust = obj->mtype.phys_info.velocity;
791 vm_vec_scale(&obj->mtype.phys_info.thrust, fixdiv(Weapon_info[obj->id].thrust, weapon_speed+parent_speed));
794 if ((obj->type == OBJ_WEAPON) && (obj->id == FLARE_ID))
795 obj->lifeleft += (d_rand()-16384) << 2; // add in -2..2 seconds
797 // mprintf( 0, "Weapon speed = %.1f (%.1f)\n", f2fl(Weapon_info[obj->id].speed[Difficulty_level] + parent_speed), f2fl(parent_speed) );
802 // -----------------------------------------------------------------------------------------------------------
803 // Calls Laser_create_new, but takes care of the segment and point computation for you.
804 int Laser_create_new_easy( vms_vector * direction, vms_vector * position, int parent, int weapon_type, int make_sound )
808 object *pobjp = &Objects[parent];
811 // Find segment containing laser fire position. If the robot is straddling a segment, the position from
812 // which it fires may be in a different segment, which is bad news for find_vector_intersection. So, cast
813 // a ray from the object center (whose segment we know) to the laser position. Then, in the call to Laser_create_new
814 // use the data returned from this call to find_vector_intersection.
815 // Note that while find_vector_intersection is pretty slow, it is not terribly slow if the destination point is
816 // in the same segment as the source point.
819 fq.startseg = pobjp->segnum;
822 fq.thisobjnum = pobjp-Objects;
823 fq.ignore_obj_list = NULL;
824 fq.flags = FQ_TRANSWALL | FQ_CHECK_OBJS; //what about trans walls???
826 fate = find_vector_intersection(&fq, &hit_data);
827 if (fate != HIT_NONE || hit_data.hit_seg==-1) {
828 mprintf((1, "Warning: Laser from parent=%i stuck in wall or object, didn't fire!\n", parent));
832 return Laser_create_new( direction, &hit_data.hit_pnt, hit_data.hit_seg, parent, weapon_type, make_sound );
836 int Muzzle_queue_index = 0;
838 muzzle_info Muzzle_data[MUZZLE_QUEUE_MAX];
840 // -----------------------------------------------------------------------------------------------------------
841 // Determine if two objects are on a line of sight. If so, return true, else return false.
843 int object_to_object_visibility(object *obj1, object *obj2, int trans_type)
850 fq.startseg = obj1->segnum;
853 fq.thisobjnum = obj1-Objects;
854 fq.ignore_obj_list = NULL;
855 fq.flags = trans_type;
857 fate = find_vector_intersection(&fq, &hit_data);
859 if (fate == HIT_WALL)
861 else if (fate == HIT_NONE)
864 Int3(); // Contact Mike: Oops, what happened? What is fate?
865 // 2 = hit object (impossible), 3 = bad starting point (bad)
870 fix Min_trackable_dot = MIN_TRACKABLE_DOT;
872 // -----------------------------------------------------------------------------------------------------------
873 // Return true if weapon *tracker is able to track object Objects[track_goal], else return false.
874 // In order for the object to be trackable, it must be within a reasonable turning radius for the missile
875 // and it must not be obstructed by a wall.
876 int object_is_trackable(int track_goal, object *tracker, fix *dot)
878 vms_vector vector_to_goal;
881 if (track_goal == -1)
884 if (Game_mode & GM_MULTI_COOP)
887 objp = &Objects[track_goal];
889 // Don't track player if he's cloaked.
890 if ((track_goal == Players[Player_num].objnum) && (Players[Player_num].flags & PLAYER_FLAGS_CLOAKED))
893 // Can't track AI object if he's cloaked.
894 if (objp->type == OBJ_ROBOT) {
895 if (objp->ctype.ai_info.CLOAKED)
897 // Your missiles don't track your escort.
898 if (Robot_info[objp->id].companion)
899 if (tracker->ctype.laser_info.parent_type == OBJ_PLAYER)
902 vm_vec_sub(&vector_to_goal, &objp->pos, &tracker->pos);
903 vm_vec_normalize_quick(&vector_to_goal);
904 *dot = vm_vec_dot(&vector_to_goal, &tracker->orient.fvec);
906 if ((*dot < Min_trackable_dot) && (*dot > F1_0*9/10)) {
907 // -- mprintf((0, "."));
908 vm_vec_normalize(&vector_to_goal);
909 *dot = vm_vec_dot(&vector_to_goal, &tracker->orient.fvec);
912 //mprintf((0, " OIT: dot=%5.2f ", f2fl(dot)));
914 // mprintf((0, "object_is_trackable: [%3i] %7.3f, min = %7.3f\n", track_goal, f2fl(dot), f2fl(Min_trackable_dot)));
916 if (*dot >= Min_trackable_dot) {
918 // dot is in legal range, now see if object is visible
919 rval = object_to_object_visibility(tracker, objp, FQ_TRANSWALL);
920 //mprintf((0, " TRACK "));
923 //mprintf((0, " LOST! "));
929 extern int Robots_kill_robots_cheat;
931 // --------------------------------------------------------------------------------------------
932 int call_find_homing_object_complete(object *tracker, vms_vector *curpos)
934 if (Game_mode & GM_MULTI) {
935 if (tracker->ctype.laser_info.parent_type == OBJ_PLAYER) {
936 // It's fired by a player, so if robots present, track robot, else track player.
937 if (Game_mode & GM_MULTI_COOP)
938 return find_homing_object_complete( curpos, tracker, OBJ_ROBOT, -1);
940 return find_homing_object_complete( curpos, tracker, OBJ_PLAYER, OBJ_ROBOT);
944 if (Robots_kill_robots_cheat)
945 goal2_type = OBJ_ROBOT;
946 Assert(tracker->ctype.laser_info.parent_type == OBJ_ROBOT);
947 return find_homing_object_complete(curpos, tracker, OBJ_PLAYER, goal2_type);
950 return find_homing_object_complete( curpos, tracker, OBJ_ROBOT, -1);
953 // --------------------------------------------------------------------------------------------
954 // Find object to home in on.
955 // Scan list of objects rendered last frame, find one that satisfies function of nearness to center and distance.
956 int find_homing_object(vms_vector *curpos, object *tracker)
959 fix max_dot = -F1_0*2;
960 int best_objnum = -1;
962 // Contact Mike: This is a bad and stupid thing. Who called this routine with an illegal laser type??
963 Assert((Weapon_info[tracker->id].homing_flag) || (tracker->id == OMEGA_ID));
965 // Find an object to track based on game mode (eg, whether in network play) and who fired it.
967 if (Game_mode & GM_MULTI)
968 return call_find_homing_object_complete(tracker, curpos);
970 int cur_min_trackable_dot;
972 cur_min_trackable_dot = MIN_TRACKABLE_DOT;
973 if ((tracker->type == OBJ_WEAPON) && (tracker->id == OMEGA_ID))
974 cur_min_trackable_dot = OMEGA_MIN_TRACKABLE_DOT;
976 // Not in network mode. If not fired by player, then track player.
977 if (tracker->ctype.laser_info.parent_num != Players[Player_num].objnum) {
978 if (!(Players[Player_num].flags & PLAYER_FLAGS_CLOAKED))
979 best_objnum = ConsoleObject - Objects;
982 fix dist, max_trackable_dist;
984 // Find the window which has the forward view.
985 for (i=0; i<MAX_RENDERED_WINDOWS; i++)
986 if (Window_rendered_data[i].frame >= FrameCount-1)
987 if (Window_rendered_data[i].viewer == ConsoleObject)
988 if (!Window_rendered_data[i].rear_view) {
993 // Couldn't find suitable view from this frame, so do complete search.
994 if (window_num == -1) {
995 mprintf((0, "Note: Calling find_homing_object_complete because no suitable rendered window.\n"));
996 return call_find_homing_object_complete(tracker, curpos);
999 max_trackable_dist = MAX_TRACKABLE_DIST;
1000 if (tracker->id == OMEGA_ID)
1001 max_trackable_dist = OMEGA_MAX_TRACKABLE_DIST;
1003 // Not in network mode and fired by player.
1004 for (i=Window_rendered_data[window_num].num_objects-1; i>=0; i--) {
1006 vms_vector vec_to_curobj;
1007 int objnum = Window_rendered_data[window_num].rendered_objects[i];
1008 object *curobjp = &Objects[objnum];
1010 if (objnum == Players[Player_num].objnum)
1013 // Can't track AI object if he's cloaked.
1014 if (curobjp->type == OBJ_ROBOT) {
1015 if (curobjp->ctype.ai_info.CLOAKED)
1018 // Your missiles don't track your escort.
1019 if (Robot_info[curobjp->id].companion)
1020 if (tracker->ctype.laser_info.parent_type == OBJ_PLAYER)
1024 vm_vec_sub(&vec_to_curobj, &curobjp->pos, curpos);
1025 dist = vm_vec_normalize_quick(&vec_to_curobj);
1026 if (dist < max_trackable_dist) {
1027 dot = vm_vec_dot(&vec_to_curobj, &tracker->orient.fvec);
1029 // mprintf(0, "Object %i: dist = %7.3f, dot = %7.3f\n", objnum, f2fl(dist), f2fl(dot));
1031 // Note: This uses the constant, not-scaled-by-frametime value, because it is only used
1032 // to determine if an object is initially trackable. find_homing_object is called on subsequent
1033 // frames to determine if the object remains trackable.
1034 // mprintf((0, "find_homing_object: [%3i] %7.3f, min = %7.3f\n", curobjp-Objects, f2fl(dot), f2fl(MIN_TRACKABLE_DOT)));
1035 if (dot > cur_min_trackable_dot) {
1036 if (dot > max_dot) {
1037 if (object_to_object_visibility(tracker, &Objects[objnum], FQ_TRANSWALL)) {
1039 best_objnum = objnum;
1042 } else if (dot > F1_0 - (F1_0 - cur_min_trackable_dot)*2) {
1043 vm_vec_normalize(&vec_to_curobj);
1044 dot = vm_vec_dot(&vec_to_curobj, &tracker->orient.fvec);
1045 if (dot > cur_min_trackable_dot) {
1046 if (dot > max_dot) {
1047 if (object_to_object_visibility(tracker, &Objects[objnum], FQ_TRANSWALL)) {
1049 best_objnum = objnum;
1059 // mprintf(0, "Selecting object #%i\n=n", best_objnum);
1064 // --------------------------------------------------------------------------------------------
1065 // Find object to home in on.
1066 // Scan list of objects rendered last frame, find one that satisfies function of nearness to center and distance.
1067 // Can track two kinds of objects. If you are only interested in one type, set track_obj_type2 to NULL
1068 // Always track proximity bombs. --MK, 06/14/95
1069 // Make homing objects not track parent's prox bombs.
1070 int find_homing_object_complete(vms_vector *curpos, object *tracker, int track_obj_type1, int track_obj_type2)
1073 fix max_dot = -F1_0*2;
1074 int best_objnum = -1;
1075 fix max_trackable_dist;
1076 fix min_trackable_dot;
1078 // Contact Mike: This is a bad and stupid thing. Who called this routine with an illegal laser type??
1079 Assert((Weapon_info[tracker->id].homing_flag) || (tracker->id == OMEGA_ID));
1081 max_trackable_dist = MAX_TRACKABLE_DIST;
1082 min_trackable_dot = MIN_TRACKABLE_DOT;
1084 if (tracker->id == OMEGA_ID) {
1085 max_trackable_dist = OMEGA_MAX_TRACKABLE_DIST;
1086 min_trackable_dot = OMEGA_MIN_TRACKABLE_DOT;
1089 for (objnum=0; objnum<=Highest_object_index; objnum++) {
1090 int is_proximity = 0;
1092 vms_vector vec_to_curobj;
1093 object *curobjp = &Objects[objnum];
1095 if ((curobjp->type != track_obj_type1) && (curobjp->type != track_obj_type2))
1097 if ((curobjp->type == OBJ_WEAPON) && ((curobjp->id == PROXIMITY_ID) || (curobjp->id == SUPERPROX_ID))) {
1098 if (curobjp->ctype.laser_info.parent_signature != tracker->ctype.laser_info.parent_signature)
1106 if (objnum == tracker->ctype.laser_info.parent_num) // Don't track shooter
1109 // Don't track cloaked players.
1110 if (curobjp->type == OBJ_PLAYER)
1112 if (Players[curobjp->id].flags & PLAYER_FLAGS_CLOAKED)
1114 // Don't track teammates in team games
1116 if ((Game_mode & GM_TEAM) && (Objects[tracker->ctype.laser_info.parent_num].type == OBJ_PLAYER) && (get_team(curobjp->id) == get_team(Objects[tracker->ctype.laser_info.parent_num].id)))
1121 // Can't track AI object if he's cloaked.
1122 if (curobjp->type == OBJ_ROBOT) {
1123 if (curobjp->ctype.ai_info.CLOAKED)
1126 // Your missiles don't track your escort.
1127 if (Robot_info[curobjp->id].companion)
1128 if (tracker->ctype.laser_info.parent_type == OBJ_PLAYER)
1132 vm_vec_sub(&vec_to_curobj, &curobjp->pos, curpos);
1133 dist = vm_vec_mag_quick(&vec_to_curobj);
1135 if (dist < max_trackable_dist) {
1136 vm_vec_normalize_quick(&vec_to_curobj);
1137 dot = vm_vec_dot(&vec_to_curobj, &tracker->orient.fvec);
1139 dot = ((dot << 3) + dot) >> 3; // I suspect Watcom would be too stupid to figure out the obvious...
1141 // Note: This uses the constant, not-scaled-by-frametime value, because it is only used
1142 // to determine if an object is initially trackable. find_homing_object is called on subsequent
1143 // frames to determine if the object remains trackable.
1144 // mprintf((0, "fho_complete: [%3i] %7.3f, min = %7.3f\n", curobjp-Objects, f2fl(dot), f2fl(MIN_TRACKABLE_DOT)));
1145 if (dot > min_trackable_dot) {
1146 // mprintf(0, "Object %i: dist = %7.3f, dot = %7.3f\n", objnum, f2fl(dist), f2fl(dot));
1147 if (dot > max_dot) {
1148 if (object_to_object_visibility(tracker, &Objects[objnum], FQ_TRANSWALL)) {
1150 best_objnum = objnum;
1158 // -- mprintf((0, "Selecting object #%i in find_homing_object_complete\n\n", best_objnum));
1163 // ------------------------------------------------------------------------------------------------------------
1164 // See if legal to keep tracking currently tracked object. If not, see if another object is trackable. If not, return -1,
1165 // else return object number of tracking object.
1166 // Computes and returns a fairly precise dot product.
1167 int track_track_goal(int track_goal, object *tracker, fix *dot)
1169 // Every 8 frames for each object, scan all objects.
1170 if (object_is_trackable(track_goal, tracker, dot) && ((((tracker-Objects) ^ FrameCount) % 8) != 0)) {
1171 //mprintf((0, "ttg: QO"));
1173 } else if ((((tracker-Objects) ^ FrameCount) % 4) == 0) {
1176 // If player fired missile, then search for an object, if not, then give up.
1177 if (Objects[tracker->ctype.laser_info.parent_num].type == OBJ_PLAYER) {
1180 if (track_goal == -1)
1182 if (Game_mode & GM_MULTI)
1184 if (Game_mode & GM_MULTI_COOP)
1185 rval = find_homing_object_complete( &tracker->pos, tracker, OBJ_ROBOT, -1);
1186 else if (Game_mode & GM_MULTI_ROBOTS) // Not cooperative, if robots, track either robot or player
1187 rval = find_homing_object_complete( &tracker->pos, tracker, OBJ_PLAYER, OBJ_ROBOT);
1188 else // Not cooperative and no robots, track only a player
1189 rval = find_homing_object_complete( &tracker->pos, tracker, OBJ_PLAYER, -1);
1192 rval = find_homing_object_complete(&tracker->pos, tracker, OBJ_PLAYER, OBJ_ROBOT);
1196 goal_type = Objects[tracker->ctype.laser_info.track_goal].type;
1197 if ((goal_type == OBJ_PLAYER) || (goal_type == OBJ_ROBOT))
1198 rval = find_homing_object_complete(&tracker->pos, tracker, goal_type, -1);
1204 int goal_type, goal2_type = -1;
1206 if (Robots_kill_robots_cheat)
1207 goal2_type = OBJ_ROBOT;
1209 if (track_goal == -1)
1210 rval = find_homing_object_complete(&tracker->pos, tracker, OBJ_PLAYER, goal2_type);
1212 goal_type = Objects[tracker->ctype.laser_info.track_goal].type;
1213 rval = find_homing_object_complete(&tracker->pos, tracker, goal_type, goal2_type);
1217 Assert(rval != -2); // This means it never got set which is bad! Contact Mike.
1221 //if (track_goal != -1)
1222 // mprintf((0, "Object %i not tracking anything.\n", tracker-Objects));
1227 //-------------- Initializes a laser after Fire is pressed -----------------
1229 void Laser_player_fire_spread_delay(object *obj, int laser_type, int gun_num, fix spreadr, fix spreadu, fix delay_time, int make_sound, int harmless)
1232 vms_vector LaserPos, LaserDir;
1235 vms_vector gun_point, *pnt;
1239 create_awareness_event(obj, PA_WEAPON_WALL_COLLISION);
1241 // Find the initial position of the laser
1242 pnt = &Player_ship->gun_points[gun_num];
1244 vm_copy_transpose_matrix(&m,&obj->orient);
1245 vm_vec_rotate(&gun_point,pnt,&m);
1247 vm_vec_add(&LaserPos,&obj->pos,&gun_point);
1249 // If supposed to fire at a delayed time (delay_time), then move this point backwards.
1251 vm_vec_scale_add2(&LaserPos, &obj->orient.fvec, -fixmul(delay_time, Weapon_info[laser_type].speed[Difficulty_level]));
1253 // do_muzzle_stuff(obj, &Pos);
1255 //--------------- Find LaserPos and LaserSeg ------------------
1257 fq.startseg = obj->segnum;
1260 fq.thisobjnum = obj-Objects;
1261 fq.ignore_obj_list = NULL;
1262 fq.flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS;
1264 Fate = find_vector_intersection(&fq, &hit_data);
1266 LaserSeg = hit_data.hit_seg;
1268 if (LaserSeg == -1) //some sort of annoying error
1271 //SORT OF HACK... IF ABOVE WAS CORRECT THIS WOULDNT BE NECESSARY.
1272 if ( vm_vec_dist_quick(&LaserPos, &obj->pos) > 0x50000 )
1275 if (Fate==HIT_WALL) {
1277 mprintf((0, "Your DELAYED laser is stuck thru a wall!\n" ));
1279 mprintf((0, "Your laser is stuck thru a wall!\n" ));
1283 if (Fate==HIT_OBJECT) {
1284 // if ( Objects[hit_data.hit_object].type == OBJ_ROBOT )
1285 // Objects[hit_data.hit_object].flags |= OF_SHOULD_BE_DEAD;
1286 mprintf((0, "Your laser is stuck in an object!\n" ));
1287 // if ( Objects[hit_data.hit_object].type != OBJ_POWERUP )
1289 //as of 12/6/94, we don't care if the laser is stuck in an object. We
1290 //just fire away normally
1293 // Now, make laser spread out.
1294 LaserDir = obj->orient.fvec;
1295 if ((spreadr != 0) || (spreadu != 0)) {
1296 vm_vec_scale_add2(&LaserDir, &obj->orient.rvec, spreadr);
1297 vm_vec_scale_add2(&LaserDir, &obj->orient.uvec, spreadu);
1300 objnum = Laser_create_new( &LaserDir, &LaserPos, LaserSeg, obj-Objects, laser_type, make_sound );
1302 // Omega cannon is a hack, not surprisingly. Don't want to do the rest of this stuff.
1303 if (laser_type == OMEGA_ID)
1310 if (laser_type==GUIDEDMISS_ID && Multi_is_guided) {
1311 mprintf ((0,"Guided missile %s activated!\n",Players[obj->id].callsign));
1312 Guided_missile[obj->id]=&Objects[objnum];
1318 if (laser_type == CONCUSSION_ID ||
1319 laser_type == HOMING_ID ||
1320 laser_type == SMART_ID ||
1321 laser_type == MEGA_ID ||
1322 laser_type == FLASH_ID ||
1323 //laser_type == GUIDEDMISS_ID ||
1324 //laser_type == SUPERPROX_ID ||
1325 laser_type == MERCURY_ID ||
1326 laser_type == EARTHSHAKER_ID)
1327 if (Missile_viewer == NULL && obj->id==Player_num)
1328 Missile_viewer = &Objects[objnum];
1330 // If this weapon is supposed to be silent, set that bit!
1332 Objects[objnum].flags |= OF_SILENT;
1334 // If this weapon is supposed to be silent, set that bit!
1336 Objects[objnum].flags |= OF_HARMLESS;
1338 // If the object firing the laser is the player, then indicate the laser object so robots can dodge.
1339 // New by MK on 6/8/95, don't let robots evade proximity bombs, thereby decreasing uselessness of bombs.
1340 if ((obj == ConsoleObject) && ((Objects[objnum].id != PROXIMITY_ID) && (Objects[objnum].id != SUPERPROX_ID)))
1341 Player_fired_laser_this_frame = objnum;
1343 if (Weapon_info[laser_type].homing_flag) {
1344 if (obj == ConsoleObject)
1346 Objects[objnum].ctype.laser_info.track_goal = find_homing_object(&LaserPos, &Objects[objnum]);
1348 Network_laser_track = Objects[objnum].ctype.laser_info.track_goal;
1352 else // Some other player shot the homing thing
1354 Assert(Game_mode & GM_MULTI);
1355 Objects[objnum].ctype.laser_info.track_goal = Network_laser_track;
1358 // mprintf((0, "Selecting object #%i in find_homing_object_complete\n", Network_laser_track));
1362 // -----------------------------------------------------------------------------------------------------------
1363 void Laser_player_fire_spread(object *obj, int laser_type, int gun_num, fix spreadr, fix spreadu, int make_sound, int harmless)
1365 Laser_player_fire_spread_delay(obj, laser_type, gun_num, spreadr, spreadu, 0, make_sound, harmless);
1369 // -----------------------------------------------------------------------------------------------------------
1370 void Laser_player_fire(object *obj, int laser_type, int gun_num, int make_sound, int harmless)
1372 Laser_player_fire_spread(obj, laser_type, gun_num, 0, 0, make_sound, harmless);
1375 // -----------------------------------------------------------------------------------------------------------
1376 void Flare_create(object *obj)
1380 energy_usage = Weapon_info[FLARE_ID].energy_usage;
1382 if (Difficulty_level < 2)
1383 energy_usage = fixmul(energy_usage, i2f(Difficulty_level+2)/4);
1385 // MK, 11/04/95: Allowed to fire flare even if no energy.
1386 // -- if (Players[Player_num].energy >= energy_usage) {
1387 Players[Player_num].energy -= energy_usage;
1389 if (Players[Player_num].energy <= 0) {
1390 Players[Player_num].energy = 0;
1391 // -- auto_select_weapon(0);
1394 Laser_player_fire( obj, FLARE_ID, 6, 1, 0);
1397 if (Game_mode & GM_MULTI) {
1398 Network_laser_fired = 1;
1399 Network_laser_gun = FLARE_ADJUST;
1400 Network_laser_flags = 0;
1401 Network_laser_level = 0;
1408 #define HOMING_MISSILE_SCALE 16
1410 //-------------------------------------------------------------------------------------------
1411 // Set object *objp's orientation to (or towards if I'm ambitious) its velocity.
1412 void homing_missile_turn_towards_velocity(object *objp, vms_vector *norm_vel)
1414 vms_vector new_fvec;
1416 new_fvec = *norm_vel;
1418 vm_vec_scale(&new_fvec, FrameTime*HOMING_MISSILE_SCALE);
1419 vm_vec_add2(&new_fvec, &objp->orient.fvec);
1420 vm_vec_normalize_quick(&new_fvec);
1422 // if ((norm_vel->x == 0) && (norm_vel->y == 0) && (norm_vel->z == 0))
1425 vm_vector_2_matrix(&objp->orient, &new_fvec, NULL, NULL);
1428 //-------------------------------------------------------------------------------------------
1429 //sequence this laser object for this _frame_ (underscores added here to aid MK in his searching!)
1430 void Laser_do_weapon_sequence(object *obj)
1432 Assert(obj->control_type == CT_WEAPON);
1434 // Ok, this is a big hack by MK.
1435 // If you want an object to last for exactly one frame, then give it a lifeleft of ONE_FRAME_TIME
1436 if (obj->lifeleft == ONE_FRAME_TIME) {
1437 if (Game_mode & GM_MULTI)
1438 obj->lifeleft = OMEGA_MULTI_LIFELEFT;
1441 obj->render_type = RT_NONE;
1444 if (obj->lifeleft < 0 ) { // We died of old age
1445 obj->flags |= OF_SHOULD_BE_DEAD;
1446 if ( Weapon_info[obj->id].damage_radius )
1447 explode_badass_weapon(obj,&obj->pos);
1451 //delete weapons that are not moving
1452 if ( !((FrameCount ^ obj->signature) & 3) &&
1453 (obj->id != FLARE_ID) &&
1454 (Weapon_info[obj->id].speed[Difficulty_level] > 0) &&
1455 (vm_vec_mag_quick(&obj->mtype.phys_info.velocity) < F2_0)) {
1456 obj_delete(obj-Objects);
1460 if ( obj->id == FUSION_ID ) { //always set fusion weapon to max vel
1462 vm_vec_normalize_quick(&obj->mtype.phys_info.velocity);
1464 vm_vec_scale(&obj->mtype.phys_info.velocity, Weapon_info[obj->id].speed[Difficulty_level]);
1467 // -- // The Super Spreadfire (Helix) blobs travel in a sinusoidal path. That is accomplished
1468 // -- // by modifying velocity (direction) in the frame interval.
1469 // -- if (obj->id == SSPREADFIRE_ID) {
1470 // -- fix age, sinval, cosval;
1471 // -- vms_vector p, newp;
1474 // -- speed = vm_vec_mag_quick(&obj->phys_info.velocity);
1476 // -- age = Weapon_info[obj->id].lifetime - obj->lifeleft;
1478 // -- fix_fast_sincos(age, &sinval, &cosval);
1480 // -- // Note: Below code assumes x=1, y=0. Need to scale this for values around a circle for 5 helix positions.
1481 // -- p.x = cosval << 3;
1482 // -- p.y = sinval << 3;
1485 // -- vm_vec_rotate(&newp, &p, &obj->orient);
1487 // -- vm_vec_add(&goal_point, &obj->pos, &newp);
1489 // -- vm_vec_sub(&vec_to_goal, &goal_point, obj
1493 // For homing missiles, turn towards target. (unless it's the guided missile)
1494 if (Weapon_info[obj->id].homing_flag && !(obj->id==GUIDEDMISS_ID && obj==Guided_missile[Objects[obj->ctype.laser_info.parent_num].id] && obj->signature==Guided_missile[Objects[obj->ctype.laser_info.parent_num].id]->signature)) {
1495 vms_vector vector_to_object, temp_vec;
1497 fix speed, max_speed;
1499 // For first 1/2 second of life, missile flies straight.
1500 if (obj->ctype.laser_info.creation_time + HOMING_MISSILE_STRAIGHT_TIME < GameTime) {
1502 int track_goal = obj->ctype.laser_info.track_goal;
1504 //mprintf((0, "%5i: mtd=%5.2f", FrameCount, f2fl(Min_trackable_dot)));
1506 // If it's time to do tracking, then it's time to grow up, stop bouncing and start exploding!.
1507 if ((obj->id == ROBOT_SMART_MINE_HOMING_ID) || (obj->id == ROBOT_SMART_HOMING_ID) || (obj->id == SMART_MINE_HOMING_ID) || (obj->id == PLAYER_SMART_HOMING_ID) || (obj->id == EARTHSHAKER_MEGA_ID)) {
1508 // if (obj->mtype.phys_info.flags & PF_BOUNCE) mprintf(0, "Debouncing smart child %i\n", obj-Objects);
1509 obj->mtype.phys_info.flags &= ~PF_BOUNCE;
1512 // Make sure the object we are tracking is still trackable.
1513 track_goal = track_track_goal(track_goal, obj, &dot);
1515 //mprintf((0, " after ttg=%3i ", track_goal));
1517 if (track_goal == Players[Player_num].objnum) {
1520 dist_to_player = vm_vec_dist_quick(&obj->pos, &Objects[track_goal].pos);
1521 if ((dist_to_player < Players[Player_num].homing_object_dist) || (Players[Player_num].homing_object_dist < 0))
1522 Players[Player_num].homing_object_dist = dist_to_player;
1526 if (track_goal != -1) {
1527 vm_vec_sub(&vector_to_object, &Objects[track_goal].pos, &obj->pos);
1529 vm_vec_normalize_quick(&vector_to_object);
1530 temp_vec = obj->mtype.phys_info.velocity;
1531 speed = vm_vec_normalize_quick(&temp_vec);
1532 max_speed = Weapon_info[obj->id].speed[Difficulty_level];
1533 if (speed+F1_0 < max_speed) {
1534 speed += fixmul(max_speed, FrameTime/2);
1535 if (speed > max_speed)
1539 // -- dot = vm_vec_dot(&temp_vec, &vector_to_object);
1540 //mprintf((0, " dot=%5.2f ", f2fl(dot)));
1541 vm_vec_add2(&temp_vec, &vector_to_object);
1542 // The boss' smart children track better...
1543 if (Weapon_info[obj->id].render_type != WEAPON_RENDER_POLYMODEL)
1544 vm_vec_add2(&temp_vec, &vector_to_object);
1545 vm_vec_normalize_quick(&temp_vec);
1546 obj->mtype.phys_info.velocity = temp_vec;
1547 vm_vec_scale(&obj->mtype.phys_info.velocity, speed);
1549 // Subtract off life proportional to amount turned.
1550 // For hardest turn, it will lose 2 seconds per second.
1552 fix lifelost, absdot;
1554 absdot = abs(F1_0 - dot);
1556 lifelost = fixmul(absdot*32, FrameTime);
1557 obj->lifeleft -= lifelost;
1558 // -- mprintf((0, "Missile %3i, dot = %7.3f life lost = %7.3f, life left = %7.3f\n", obj-Objects, f2fl(dot), f2fl(lifelost), f2fl(obj->lifeleft)));
1561 // Only polygon objects have visible orientation, so only they should turn.
1562 if (Weapon_info[obj->id].render_type == WEAPON_RENDER_POLYMODEL)
1563 homing_missile_turn_towards_velocity(obj, &temp_vec); // temp_vec is normalized velocity.
1567 //mprintf((0, "\n"));
1570 // Make sure weapon is not moving faster than allowed speed.
1574 weapon_speed = vm_vec_mag_quick(&obj->mtype.phys_info.velocity);
1575 if (weapon_speed > Weapon_info[obj->id].speed[Difficulty_level]) {
1576 // Only slow down if not allowed to move. Makes sense, huh? Allows proxbombs to get moved by physics force. --MK, 2/13/96
1577 if (Weapon_info[obj->id].speed[Difficulty_level]) {
1580 scale_factor = fixdiv(Weapon_info[obj->id].speed[Difficulty_level], weapon_speed);
1581 vm_vec_scale(&obj->mtype.phys_info.velocity, scale_factor);
1587 fix Last_laser_fired_time = 0;
1589 extern int Player_fired_laser_this_frame;
1593 // --------------------------------------------------------------------------------------------------
1594 // Assumption: This is only called by the actual console player, not for network players
1596 int do_laser_firing_player(void)
1598 player *plp = &Players[Player_num];
1600 int ammo_used,primary_ammo;
1605 static int Spreadfire_toggle=0;
1606 static int Helix_orientation = 0;
1611 weapon_index = Primary_weapon_to_weapon_info[Primary_weapon];
1612 energy_used = Weapon_info[weapon_index].energy_usage;
1613 if (Primary_weapon == OMEGA_INDEX)
1614 energy_used = 0; // Omega consumes energy when recharging, not when firing.
1616 if (Difficulty_level < 2)
1617 energy_used = fixmul(energy_used, i2f(Difficulty_level+2)/4);
1619 // MK, 01/26/96, Helix use 2x energy in multiplayer. bitmaps.tbl parm should have been reduced for single player.
1620 if (weapon_index == HELIX_INDEX)
1621 if (Game_mode & GM_MULTI)
1624 ammo_used = Weapon_info[weapon_index].ammo_usage;
1626 addval = 2*FrameTime;
1630 if ((Last_laser_fired_time + 2*FrameTime < GameTime) || (GameTime < Last_laser_fired_time))
1631 Next_laser_fire_time = GameTime;
1633 Last_laser_fired_time = GameTime;
1635 primary_ammo = (Primary_weapon == GAUSS_INDEX)?(plp->primary_ammo[VULCAN_INDEX]):(plp->primary_ammo[Primary_weapon]);
1637 if (!((plp->energy >= energy_used) && (primary_ammo >= ammo_used)))
1638 auto_select_weapon(0); // Make sure the player can fire from this weapon.
1645 while (Next_laser_fire_time <= GameTime) {
1646 if ((plp->energy >= energy_used) && (primary_ammo >= ammo_used)) {
1647 int laser_level, flags;
1650 if (Laser_rapid_fire!=0xBADA55)
1651 Next_laser_fire_time += Weapon_info[weapon_index].fire_wait;
1653 Next_laser_fire_time += F1_0/25;
1655 laser_level = Players[Player_num].laser_level;
1659 if (Primary_weapon == SPREADFIRE_INDEX) {
1660 if (Spreadfire_toggle)
1661 flags |= LASER_SPREADFIRE_TOGGLED;
1662 Spreadfire_toggle = !Spreadfire_toggle;
1665 if (Primary_weapon == HELIX_INDEX) {
1666 Helix_orientation++;
1667 flags |= ((Helix_orientation & LASER_HELIX_MASK) << LASER_HELIX_SHIFT);
1670 if (Players[Player_num].flags & PLAYER_FLAGS_QUAD_LASERS)
1671 flags |= LASER_QUAD;
1673 rval += do_laser_firing(Players[Player_num].objnum, Primary_weapon, laser_level, flags, nfires);
1675 plp->energy -= (energy_used * rval) / Weapon_info[weapon_index].fire_count;
1676 if (plp->energy < 0)
1679 if ((Primary_weapon == VULCAN_INDEX) || (Primary_weapon == GAUSS_INDEX)) {
1680 if (ammo_used > plp->primary_ammo[VULCAN_INDEX])
1681 plp->primary_ammo[VULCAN_INDEX] = 0;
1683 plp->primary_ammo[VULCAN_INDEX] -= ammo_used;
1686 auto_select_weapon(0); // Make sure the player can fire from this weapon.
1689 auto_select_weapon(0); // Make sure the player can fire from this weapon.
1690 Next_laser_fire_time = GameTime; // Prevents shots-to-fire from building up.
1691 break; // Couldn't fire weapon, so abort.
1694 //mprintf(0, " fires = %i\n", rval);
1696 Global_laser_firing_count = 0;
1701 // -- #define MAX_LIGHTNING_DISTANCE (F1_0*300)
1702 // -- #define MAX_LIGHTNING_BLOBS 16
1703 // -- #define LIGHTNING_BLOB_DISTANCE (MAX_LIGHTNING_DISTANCE/MAX_LIGHTNING_BLOBS)
1705 // -- #define LIGHTNING_BLOB_ID 13
1707 // -- #define LIGHTNING_TIME (F1_0/4)
1708 // -- #define LIGHTNING_DELAY (F1_0/8)
1710 // -- int Lightning_gun_num = 1;
1712 // -- fix Lightning_start_time = -F1_0*10, Lightning_last_time;
1714 // -- // --------------------------------------------------------------------------------------------------
1715 // -- // Return -1 if failed to create at least one blob. Else return index of last blob created.
1716 // -- int create_lightning_blobs(vms_vector *direction, vms_vector *start_pos, int start_segnum, int parent)
1720 // -- fvi_info hit_data;
1721 // -- vms_vector end_pos;
1722 // -- vms_vector norm_dir;
1724 // -- int num_blobs;
1725 // -- vms_vector tvec;
1726 // -- fix dist_to_hit_point;
1727 // -- vms_vector point_pos, delta_pos;
1729 // -- vms_vector *gun_pos;
1731 // -- vms_vector gun_pos2;
1733 // -- if (Players[Player_num].energy > F1_0)
1734 // -- Players[Player_num].energy -= F1_0;
1736 // -- if (Players[Player_num].energy <= F1_0) {
1737 // -- Players[Player_num].energy = 0;
1738 // -- auto_select_weapon(0);
1742 // -- norm_dir = *direction;
1744 // -- vm_vec_normalize_quick(&norm_dir);
1745 // -- vm_vec_scale_add(&end_pos, start_pos, &norm_dir, MAX_LIGHTNING_DISTANCE);
1747 // -- fq.p0 = start_pos;
1748 // -- fq.startseg = start_segnum;
1749 // -- fq.p1 = &end_pos;
1751 // -- fq.thisobjnum = parent;
1752 // -- fq.ignore_obj_list = NULL;
1753 // -- fq.flags = FQ_TRANSWALL | FQ_CHECK_OBJS;
1755 // -- fate = find_vector_intersection(&fq, &hit_data);
1756 // -- if (hit_data.hit_seg == -1) {
1757 // -- mprintf((1, "Warning: Lightning bolt has hit seg of -1.\n"));
1761 // -- dist_to_hit_point = vm_vec_mag(vm_vec_sub(&tvec, &hit_data.hit_pnt, start_pos));
1762 // -- num_blobs = dist_to_hit_point/LIGHTNING_BLOB_DISTANCE;
1764 // -- if (num_blobs > MAX_LIGHTNING_BLOBS)
1765 // -- num_blobs = MAX_LIGHTNING_BLOBS;
1767 // -- if (num_blobs < MAX_LIGHTNING_BLOBS/4)
1768 // -- num_blobs = MAX_LIGHTNING_BLOBS/4;
1770 // -- // Find the initial position of the laser
1771 // -- gun_pos = &Player_ship->gun_points[Lightning_gun_num];
1772 // -- vm_copy_transpose_matrix(&m,&Objects[parent].orient);
1773 // -- vm_vec_rotate(&gun_pos2, gun_pos, &m);
1774 // -- vm_vec_add(&point_pos, &Objects[parent].pos, &gun_pos2);
1776 // -- delta_pos = norm_dir;
1777 // -- vm_vec_scale(&delta_pos, dist_to_hit_point/num_blobs);
1779 // -- for (i=0; i<num_blobs; i++) {
1780 // -- int point_seg;
1783 // -- vm_vec_add2(&point_pos, &delta_pos);
1784 // -- point_seg = find_point_seg(&point_pos, start_segnum);
1785 // -- if (point_seg == -1) // Hey, we thought we were creating points on a line, but we left the mine!
1788 // -- objnum = Laser_create_new( direction, &point_pos, point_seg, parent, LIGHTNING_BLOB_ID, 0 );
1790 // -- if ( objnum < 0 ) {
1791 // -- mprintf((1, "Can't create lightning blob - Out of objects!\n" ));
1796 // -- obj = &Objects[objnum];
1798 // -- digi_play_sample( Weapon_info[obj->id].flash_sound, F1_0 );
1800 // -- // -- vm_vec_scale( &obj->mtype.phys_info.velocity, F1_0/2);
1802 // -- obj->lifeleft = (LIGHTNING_TIME + LIGHTNING_DELAY)/2;
1806 // -- return objnum;
1810 // -- // --------------------------------------------------------------------------------------------------
1811 // -- // Lightning Cannon.
1812 // -- // While being fired, creates path of blobs forward from player until it hits something.
1813 // -- // Up to MAX_LIGHTNING_BLOBS blobs, spaced LIGHTNING_BLOB_DISTANCE units apart.
1814 // -- // When the player releases the firing key, the blobs move forward.
1815 // -- void lightning_frame(void)
1817 // -- if ((GameTime - Lightning_start_time < LIGHTNING_TIME) && (GameTime - Lightning_start_time > 0)) {
1818 // -- if (GameTime - Lightning_last_time > LIGHTNING_DELAY) {
1819 // -- create_lightning_blobs(&ConsoleObject->orient.fvec, &ConsoleObject->pos, ConsoleObject->segnum, ConsoleObject-Objects);
1820 // -- Lightning_last_time = GameTime;
1825 // --------------------------------------------------------------------------------------------------
1826 // Object "objnum" fires weapon "weapon_num" of level "level". (Right now (9/24/94) level is used only for type 0 laser.
1827 // Flags are the player flags. For network mode, set to 0.
1828 // It is assumed that this is a player object (as in multiplayer), and therefore the gun positions are known.
1829 // Returns number of times a weapon was fired. This is typically 1, but might be more for low frame rates.
1830 // More than one shot is fired with a pseudo-delay so that players on show machines can fire (for themselves
1831 // or other players) often enough for things like the vulcan cannon.
1832 int do_laser_firing(int objnum, int weapon_num, int level, int flags, int nfires)
1834 object *objp = &Objects[objnum];
1836 switch (weapon_num) {
1840 Laser_offset = ((F1_0*2)*(d_rand()%8))/8;
1842 if (level <= MAX_LASER_LEVEL)
1843 weapon_num = LASER_ID + level;
1845 weapon_num = SUPER_LASER_ID + (level-MAX_LASER_LEVEL-1);
1847 Laser_player_fire( objp, weapon_num, 0, 1, 0);
1848 Laser_player_fire( objp, weapon_num, 1, 0, 0);
1850 if (flags & LASER_QUAD) {
1851 // hideous system to make quad laser 1.5x powerful as normal laser, make every other quad laser bolt harmless
1852 Laser_player_fire( objp, weapon_num, 2, 0, 0);
1853 Laser_player_fire( objp, weapon_num, 3, 0, 0);
1857 case VULCAN_INDEX: {
1858 // Only make sound for 1/4 of vulcan bullets.
1860 //if (d_rand() > 24576)
1862 Laser_player_fire_spread( objp, VULCAN_ID, 6, d_rand()/8 - 32767/16, d_rand()/8 - 32767/16, make_sound, 0);
1864 Laser_player_fire_spread( objp, VULCAN_ID, 6, d_rand()/8 - 32767/16, d_rand()/8 - 32767/16, 0, 0);
1866 Laser_player_fire_spread( objp, VULCAN_ID, 6, d_rand()/8 - 32767/16, d_rand()/8 - 32767/16, 0, 0);
1871 case SPREADFIRE_INDEX:
1872 if (flags & LASER_SPREADFIRE_TOGGLED) {
1873 Laser_player_fire_spread( objp, SPREADFIRE_ID, 6, F1_0/16, 0, 0, 0);
1874 Laser_player_fire_spread( objp, SPREADFIRE_ID, 6, -F1_0/16, 0, 0, 0);
1875 Laser_player_fire_spread( objp, SPREADFIRE_ID, 6, 0, 0, 1, 0);
1877 Laser_player_fire_spread( objp, SPREADFIRE_ID, 6, 0, F1_0/16, 0, 0);
1878 Laser_player_fire_spread( objp, SPREADFIRE_ID, 6, 0, -F1_0/16, 0, 0);
1879 Laser_player_fire_spread( objp, SPREADFIRE_ID, 6, 0, 0, 1, 0);
1884 Laser_player_fire( objp, PLASMA_ID, 0, 1, 0);
1885 Laser_player_fire( objp, PLASMA_ID, 1, 0, 0);
1887 Laser_player_fire_spread_delay( objp, PLASMA_ID, 0, 0, 0, FrameTime/2, 1, 0);
1888 Laser_player_fire_spread_delay( objp, PLASMA_ID, 1, 0, 0, FrameTime/2, 0, 0);
1892 case FUSION_INDEX: {
1893 vms_vector force_vec;
1895 // mprintf((0, "Fusion multiplier %f.\n", f2fl(Fusion_charge)));
1897 Laser_player_fire( objp, FUSION_ID, 0, 1, 0);
1898 Laser_player_fire( objp, FUSION_ID, 1, 1, 0);
1900 flags = (byte)(Fusion_charge >> 12);
1904 force_vec.x = -(objp->orient.fvec.x << 7);
1905 force_vec.y = -(objp->orient.fvec.y << 7);
1906 force_vec.z = -(objp->orient.fvec.z << 7);
1907 phys_apply_force(objp, &force_vec);
1909 force_vec.x = (force_vec.x >> 4) + d_rand() - 16384;
1910 force_vec.y = (force_vec.y >> 4) + d_rand() - 16384;
1911 force_vec.z = (force_vec.z >> 4) + d_rand() - 16384;
1912 phys_apply_rot(objp, &force_vec);
1916 case SUPER_LASER_INDEX: {
1917 int super_level = 3; //make some new kind of laser eventually
1918 Laser_player_fire( objp, super_level, 0, 1, 0);
1919 Laser_player_fire( objp, super_level, 1, 0, 0);
1921 if (flags & LASER_QUAD) {
1922 // hideous system to make quad laser 1.5x powerful as normal laser, make every other quad laser bolt harmless
1923 Laser_player_fire( objp, super_level, 2, 0, 0);
1924 Laser_player_fire( objp, super_level, 3, 0, 0);
1929 // Only make sound for 1/4 of vulcan bullets.
1931 //if (d_rand() > 24576)
1934 Laser_player_fire_spread( objp, GAUSS_ID, 6, (d_rand()/8 - 32767/16)/5, (d_rand()/8 - 32767/16)/5, make_sound, 0);
1936 Laser_player_fire_spread( objp, GAUSS_ID, 6, (d_rand()/8 - 32767/16)/5, (d_rand()/8 - 32767/16)/5, 0, 0);
1938 Laser_player_fire_spread( objp, GAUSS_ID, 6, (d_rand()/8 - 32767/16)/5, (d_rand()/8 - 32767/16)/5, 0, 0);
1945 fix spreadr,spreadu;
1946 helix_orient = (flags >> LASER_HELIX_SHIFT) & LASER_HELIX_MASK;
1947 switch(helix_orient) {
1949 case 0: spreadr = F1_0/16; spreadu = 0; break; // Vertical
1950 case 1: spreadr = F1_0/17; spreadu = F1_0/42; break; // 22.5 degrees
1951 case 2: spreadr = F1_0/22; spreadu = F1_0/22; break; // 45 degrees
1952 case 3: spreadr = F1_0/42; spreadu = F1_0/17; break; // 67.5 degrees
1953 case 4: spreadr = 0; spreadu = F1_0/16; break; // 90 degrees
1954 case 5: spreadr = -F1_0/42; spreadu = F1_0/17; break; // 112.5 degrees
1955 case 6: spreadr = -F1_0/22; spreadu = F1_0/22; break; // 135 degrees
1956 case 7: spreadr = -F1_0/17; spreadu = F1_0/42; break; // 157.5 degrees
1958 Error("Invalid helix_orientation value %x\n",helix_orient);
1961 Laser_player_fire_spread( objp, HELIX_ID, 6, 0, 0, 1, 0);
1962 Laser_player_fire_spread( objp, HELIX_ID, 6, spreadr, spreadu, 0, 0);
1963 Laser_player_fire_spread( objp, HELIX_ID, 6, -spreadr, -spreadu, 0, 0);
1964 Laser_player_fire_spread( objp, HELIX_ID, 6, spreadr*2, spreadu*2, 0, 0);
1965 Laser_player_fire_spread( objp, HELIX_ID, 6, -spreadr*2, -spreadu*2, 0, 0);
1970 Laser_player_fire( objp, PHOENIX_ID, 0, 1, 0);
1971 Laser_player_fire( objp, PHOENIX_ID, 1, 0, 0);
1973 Laser_player_fire_spread_delay( objp, PHOENIX_ID, 0, 0, 0, FrameTime/2, 1, 0);
1974 Laser_player_fire_spread_delay( objp, PHOENIX_ID, 1, 0, 0, FrameTime/2, 0, 0);
1979 Laser_player_fire( objp, OMEGA_ID, 1, 1, 0);
1983 Int3(); // Contact Yuan: Unknown Primary weapon type, setting to 0.
1987 // Set values to be recognized during comunication phase, if we are the
1990 if ((Game_mode & GM_MULTI) && (objnum == Players[Player_num].objnum))
1992 // mprintf((0, "Flags on fire: %d.\n", flags));
1993 Network_laser_fired = nfires;
1994 Network_laser_gun = weapon_num;
1995 Network_laser_flags = flags;
1996 Network_laser_level = level;
2003 #define MAX_SMART_DISTANCE (F1_0*150)
2004 #define MAX_OBJDISTS 30
2006 // -------------------------------------------------------------------------------------------
2007 // if goal_obj == -1, then create random vector
2008 int create_homing_missile(object *objp, int goal_obj, int objtype, int make_sound)
2011 vms_vector vector_to_goal;
2012 vms_vector random_vector;
2013 //vms_vector goal_pos;
2015 if (goal_obj == -1) {
2016 make_random_vector(&vector_to_goal);
2018 vm_vec_normalized_dir_quick(&vector_to_goal, &Objects[goal_obj].pos, &objp->pos);
2019 make_random_vector(&random_vector);
2020 vm_vec_scale_add2(&vector_to_goal, &random_vector, F1_0/4);
2021 vm_vec_normalize_quick(&vector_to_goal);
2024 // Create a vector towards the goal, then add some noise to it.
2025 objnum = Laser_create_new(&vector_to_goal, &objp->pos, objp->segnum, objp-Objects, objtype, make_sound);
2029 // Fixed to make sure the right person gets credit for the kill
2031 // Objects[objnum].ctype.laser_info.parent_num = objp->ctype.laser_info.parent_num;
2032 // Objects[objnum].ctype.laser_info.parent_type = objp->ctype.laser_info.parent_type;
2033 // Objects[objnum].ctype.laser_info.parent_signature = objp->ctype.laser_info.parent_signature;
2035 Objects[objnum].ctype.laser_info.track_goal = goal_obj;
2040 extern void blast_nearby_glass(object *objp, fix damage);
2042 // -------------------------------------------------------------------------------------------
2043 // Create the children of a smart bomb, which is a bunch of homing missiles.
2044 void create_smart_children(object *objp, int num_smart_children)
2048 int parent_type, parent_num;
2049 int objlist[MAX_OBJDISTS];
2052 if (objp->type == OBJ_WEAPON) {
2053 parent_type = objp->ctype.laser_info.parent_type;
2054 parent_num = objp->ctype.laser_info.parent_num;
2055 } else if (objp->type == OBJ_ROBOT) {
2056 parent_type = OBJ_ROBOT;
2057 parent_num = objp-Objects;
2059 Int3(); // Hey, what kind of object is this!?
2064 if (objp->id == EARTHSHAKER_ID)
2065 blast_nearby_glass(objp, Weapon_info[EARTHSHAKER_ID].strength[Difficulty_level]);
2068 if ((objp->type == OBJ_WEAPON) && ((objp->id == SMART_ID) || (objp->id == SUPERPROX_ID) || (objp->id == ROBOT_SUPERPROX_ID) || (objp->id == EARTHSHAKER_ID)))
2069 Assert(Weapon_info[objp->id].children != -1);
2072 if (((objp->type == OBJ_WEAPON) && (Weapon_info[objp->id].children != -1)) || (objp->type == OBJ_ROBOT)) {
2075 if (Game_mode & GM_MULTI)
2078 for (objnum=0; objnum<=Highest_object_index; objnum++) {
2079 object *curobjp = &Objects[objnum];
2081 if ((((curobjp->type == OBJ_ROBOT) && (!curobjp->ctype.ai_info.CLOAKED)) || (curobjp->type == OBJ_PLAYER)) && (objnum != parent_num)) {
2084 if (curobjp->type == OBJ_PLAYER)
2086 if ((parent_type == OBJ_PLAYER) && (Game_mode & GM_MULTI_COOP))
2089 if ((Game_mode & GM_TEAM) && (get_team(curobjp->id) == get_team(Objects[parent_num].id)))
2093 if (Players[curobjp->id].flags & PLAYER_FLAGS_CLOAKED)
2097 // Robot blobs can't track robots.
2098 if (curobjp->type == OBJ_ROBOT) {
2099 if (parent_type == OBJ_ROBOT)
2102 // Your shots won't track the buddy.
2103 if (parent_type == OBJ_PLAYER)
2104 if (Robot_info[curobjp->id].companion)
2108 dist = vm_vec_dist_quick(&objp->pos, &curobjp->pos);
2109 if (dist < MAX_SMART_DISTANCE) {
2112 oovis = object_to_object_visibility(objp, curobjp, FQ_TRANSWALL);
2114 if (oovis) { //object_to_object_visibility(objp, curobjp, FQ_TRANSWALL)) {
2115 objlist[numobjs] = objnum;
2117 if (numobjs >= MAX_OBJDISTS) {
2118 mprintf((0, "Warning -- too many objects near smart bomb explosion. See laser.c.\n"));
2119 numobjs = MAX_OBJDISTS;
2127 // Get type of weapon for child from parent.
2128 if (objp->type == OBJ_WEAPON) {
2129 blob_id = Weapon_info[objp->id].children;
2130 Assert(blob_id != -1); // Hmm, missing data in bitmaps.tbl. Need "children=NN" parameter.
2132 Assert(objp->type == OBJ_ROBOT);
2133 blob_id = ROBOT_SMART_HOMING_ID;
2136 // -- //determine what kind of blob to drop
2137 // -- // Note: parent_type is not the type of the weapon's parent. It is actually the type of the weapon's
2138 // -- // earliest ancestor. This deals with the issue of weapons spewing weapons which spew weapons.
2139 // -- switch (parent_type) {
2140 // -- case OBJ_WEAPON:
2141 // -- Int3(); // Should this ever happen?
2142 // -- switch (objp->id) {
2143 // -- case SUPERPROX_ID: blob_id = SMART_MINE_HOMING_ID; break;
2144 // -- case ROBOT_SUPERPROX_ID: blob_id = ROBOT_SMART_MINE_HOMING_ID; break;
2145 // -- case EARTHSHAKER_ID: blob_id = EARTHSHAKER_MEGA_ID; break;
2146 // -- default: Int3(); //bogus id for weapon
2149 // -- case OBJ_PLAYER:
2150 // -- switch (objp->id) {
2151 // -- case SUPERPROX_ID: blob_id = SMART_MINE_HOMING_ID; break;
2152 // -- case ROBOT_SUPERPROX_ID: Int3(); break;
2153 // -- case EARTHSHAKER_ID: blob_id = EARTHSHAKER_MEGA_ID; break;
2154 // -- case SMART_ID: blob_id = PLAYER_SMART_HOMING_ID; break;
2155 // -- default: Int3(); //bogus id for weapon
2158 // -- case OBJ_ROBOT:
2159 // -- switch (objp->id) {
2160 // -- case ROBOT_SUPERPROX_ID: blob_id = ROBOT_SMART_MINE_HOMING_ID; break;
2161 // -- // -- case EARTHSHAKER_ID: blob_id = EARTHSHAKER_MEGA_ID; break;
2162 // -- case SMART_ID: blob_id = ROBOT_SMART_HOMING_ID; break;
2163 // -- default: blob_id = ROBOT_SMART_HOMING_ID; break;
2166 // -- default: Int3(); //bogus type for parent object
2170 for (i=0; i<num_smart_children; i++) {
2172 objnum = (numobjs==0)?-1:objlist[(d_rand() * numobjs) >> 15];
2173 create_homing_missile(objp, objnum, blob_id, make_sound);
2179 int Missile_gun = 0;
2181 //give up control of the guided missile
2182 void release_guided_missile(int player_num)
2184 if (player_num == Player_num)
2186 if (Guided_missile[player_num]==NULL)
2189 Missile_viewer = Guided_missile[player_num];
2191 if (Game_mode & GM_MULTI)
2192 multi_send_guided_info (Guided_missile[Player_num],1);
2194 if (Newdemo_state==ND_STATE_RECORDING)
2195 newdemo_record_guided_end();
2198 Guided_missile[player_num] = NULL;
2201 int Proximity_dropped=0,Smartmines_dropped=0;
2203 // -------------------------------------------------------------------------------------------
2204 //parameter determines whether or not to do autoselect if have run out of ammo
2205 //this is needed because if you drop a bomb with the B key, you don't want
2206 //want to autoselect if the bomb isn't actually selected.
2207 void do_missile_firing(int do_autoselect)
2211 Assert(Secondary_weapon < MAX_SECONDARY_WEAPONS);
2213 if (Guided_missile[Player_num] && Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num]) {
2214 release_guided_missile(Player_num);
2215 Next_missile_fire_time = GameTime + Weapon_info[Secondary_weapon_to_weapon_info[Secondary_weapon]].fire_wait;
2219 if (!Player_is_dead && (Players[Player_num].secondary_ammo[Secondary_weapon] > 0)) {
2221 int weapon_id,weapon_gun;
2223 Players[Player_num].secondary_ammo[Secondary_weapon]--;
2225 weapon_id = Secondary_weapon_to_weapon_info[Secondary_weapon];
2227 if (Laser_rapid_fire!=0xBADA55)
2228 Next_missile_fire_time = GameTime + Weapon_info[weapon_id].fire_wait;
2230 Next_missile_fire_time = GameTime + F1_0/25;
2232 weapon_gun = Secondary_weapon_to_gun_num[Secondary_weapon];
2234 if (weapon_gun==4) { //alternate left/right
2235 weapon_gun += (gun_flag = (Missile_gun & 1));
2239 Laser_player_fire( ConsoleObject, weapon_id, weapon_gun, 1, 0);
2241 if (Secondary_weapon == PROXIMITY_INDEX) {
2242 if (++Proximity_dropped == 4) {
2243 Proximity_dropped = 0;
2245 maybe_drop_net_powerup(POW_PROXIMITY_WEAPON);
2249 else if (Secondary_weapon == SMART_MINE_INDEX) {
2250 if (++Smartmines_dropped == 4) {
2251 Smartmines_dropped = 0;
2253 maybe_drop_net_powerup(POW_SMART_MINE);
2258 else if (Secondary_weapon != CONCUSSION_INDEX)
2259 maybe_drop_net_powerup(Secondary_weapon_to_powerup[Secondary_weapon]);
2262 if (Secondary_weapon == MEGA_INDEX || Secondary_weapon == SMISSILE5_INDEX) {
2263 vms_vector force_vec;
2265 force_vec.x = -(ConsoleObject->orient.fvec.x << 7);
2266 force_vec.y = -(ConsoleObject->orient.fvec.y << 7);
2267 force_vec.z = -(ConsoleObject->orient.fvec.z << 7);
2268 phys_apply_force(ConsoleObject, &force_vec);
2270 force_vec.x = (force_vec.x >> 4) + d_rand() - 16384;
2271 force_vec.y = (force_vec.y >> 4) + d_rand() - 16384;
2272 force_vec.z = (force_vec.z >> 4) + d_rand() - 16384;
2273 phys_apply_rot(ConsoleObject, &force_vec);
2277 if (Game_mode & GM_MULTI)
2279 Network_laser_fired = 1; //how many
2280 Network_laser_gun = Secondary_weapon + MISSILE_ADJUST;
2281 Network_laser_flags = gun_flag;
2282 Network_laser_level = 0;
2287 auto_select_weapon(1); //select next missile, if this one out of ammo