1 /* $Id: laser.c,v 1.12 2004-08-28 23:17:45 schaffner Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * This will contain the laser code
26 char laser_rcsid[] = "$Id: laser.c,v 1.12 2004-08-28 23:17:45 schaffner Exp $";
73 int Laser_rapid_fire = 0;
76 object *Guided_missile[MAX_PLAYERS]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
77 int Guided_missile_sig[MAX_PLAYERS]={-1,-1,-1,-1,-1,-1,-1,-1};
79 int find_homing_object_complete(vms_vector *curpos, object *tracker, int track_obj_type1, int track_obj_type2);
81 extern char Multi_is_guided;
82 extern char BounceCheat;
84 extern void newdemo_record_guided_end();
85 extern void newdemo_record_guided_start();
87 int find_homing_object(vms_vector *curpos, object *tracker);
89 //---------------------------------------------------------------------------------
90 // Called by render code.... determines if the laser is from a robot or the
91 // player and calls the appropriate routine.
93 void Laser_render(object *obj)
96 // Commented out by John (sort of, typed by Mike) on 6/8/94
99 case WEAPON_TYPE_WEAK_LASER:
100 case WEAPON_TYPE_STRONG_LASER:
101 case WEAPON_TYPE_CANNON_BALL:
102 case WEAPON_TYPE_MISSILE:
105 Error( "Invalid weapon type in Laser_render\n" );
109 switch( Weapon_info[obj->id].render_type ) {
110 case WEAPON_RENDER_LASER:
111 Int3(); // Not supported anymore!
112 //Laser_draw_one(obj-Objects, Weapon_info[obj->id].bitmap );
114 case WEAPON_RENDER_BLOB:
115 draw_object_blob(obj, Weapon_info[obj->id].bitmap );
117 case WEAPON_RENDER_POLYMODEL:
119 case WEAPON_RENDER_VCLIP:
120 Int3(); // Oops, not supported, type added by mk on 09/09/94, but not for lasers...
122 Error( "Invalid weapon render type in Laser_render\n" );
127 //---------------------------------------------------------------------------------
128 // Draws a texture-mapped laser bolt
130 //void Laser_draw_one( int objnum, grs_bitmap * bmp )
135 // vms_vector start_pos,end_pos;
137 // obj = &Objects[objnum];
139 // start_pos = obj->pos;
140 // vm_vec_scale_add(&end_pos,&start_pos,&obj->orient.fvec,-Laser_length);
142 // g3_rotate_point(&p1,&start_pos);
143 // g3_rotate_point(&p2,&end_pos);
146 // t2 = Interpolation_method;
147 // t3 = Transparency_on;
150 // //Interpolation_method = 3; // Full perspective
151 // Interpolation_method = 1; // Linear
152 // Transparency_on = 1;
154 // //gr_setcolor( gr_getcolor(31,15,0));
155 // //g3_draw_line_ptrs(p1,p2);
156 // //g3_draw_rod(p1,0x2000,p2,0x2000);
157 // //g3_draw_rod(p1,Laser_width,p2,Laser_width);
158 // g3_draw_rod_tmap(bmp,&p2,Laser_width,&p1,Laser_width,0);
160 // Interpolation_method = t2;
161 // Transparency_on = t3;
165 // Changed by MK on 09/07/94
166 // I want you to be able to blow up your own bombs.
167 // AND...Your proximity bombs can blow you up if they're 2.0 seconds or more old.
168 // Changed by MK on 06/06/95: Now must be 4.0 seconds old. Much valid Net-complaining.
169 int laser_are_related( int o1, int o2 )
171 if ( (o1<0) || (o2<0) )
174 // See if o2 is the parent of o1
175 if ( Objects[o1].type == OBJ_WEAPON )
176 if ( (Objects[o1].ctype.laser_info.parent_num==o2) && (Objects[o1].ctype.laser_info.parent_signature==Objects[o2].signature) )
178 // 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
179 if ((Objects[o1].id == PHOENIX_ID && (GameTime > Objects[o1].ctype.laser_info.creation_time + F1_0/4)) ||
180 (Objects[o1].id == GUIDEDMISS_ID && (GameTime > Objects[o1].ctype.laser_info.creation_time + F1_0*2)) ||
181 (((Objects[o1].id == PROXIMITY_ID) || (Objects[o1].id == SUPERPROX_ID)) && (GameTime > Objects[o1].ctype.laser_info.creation_time + F1_0*4))) {
187 // See if o1 is the parent of o2
188 if ( Objects[o2].type == OBJ_WEAPON )
190 if ( (Objects[o2].ctype.laser_info.parent_num==o1) && (Objects[o2].ctype.laser_info.parent_signature==Objects[o1].signature) )
192 // 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
193 if ((Objects[o2].id == PHOENIX_ID && (GameTime > Objects[o2].ctype.laser_info.creation_time + F1_0/4)) ||
194 (Objects[o2].id == GUIDEDMISS_ID && (GameTime > Objects[o2].ctype.laser_info.creation_time + F1_0*2)) ||
195 (((Objects[o2].id == PROXIMITY_ID) || (Objects[o2].id == SUPERPROX_ID)) && (GameTime > Objects[o2].ctype.laser_info.creation_time + F1_0*4))) {
202 // They must both be weapons
203 if ( Objects[o1].type != OBJ_WEAPON || Objects[o2].type != OBJ_WEAPON )
206 // Here is the 09/07/94 change -- Siblings must be identical, others can hurt each other
207 // See if they're siblings...
208 // 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.
209 if ( Objects[o1].ctype.laser_info.parent_signature==Objects[o2].ctype.laser_info.parent_signature )
211 if (Objects[o1].id == PROXIMITY_ID || Objects[o2].id == PROXIMITY_ID || Objects[o1].id == SUPERPROX_ID || Objects[o2].id == SUPERPROX_ID) {
212 // If neither is older than 1/2 second, then can't blow up!
213 if ((GameTime > (Objects[o1].ctype.laser_info.creation_time + F1_0/2)) || (GameTime > (Objects[o2].ctype.laser_info.creation_time + F1_0/2)))
221 // Anything can cause a collision with a robot super prox mine.
222 if (Objects[o1].id == ROBOT_SUPERPROX_ID || Objects[o2].id == ROBOT_SUPERPROX_ID ||
223 Objects[o1].id == PROXIMITY_ID || Objects[o2].id == PROXIMITY_ID ||
224 Objects[o1].id == SUPERPROX_ID || Objects[o2].id == SUPERPROX_ID ||
225 Objects[o1].id == PMINE_ID || Objects[o2].id == PMINE_ID)
231 //--unused-- int Muzzle_scale=2;
234 void do_muzzle_stuff(int segnum, vms_vector *pos)
236 Muzzle_data[Muzzle_queue_index].create_time = timer_get_fixed_seconds();
237 Muzzle_data[Muzzle_queue_index].segnum = segnum;
238 Muzzle_data[Muzzle_queue_index].pos = *pos;
239 Muzzle_queue_index++;
240 if (Muzzle_queue_index >= MUZZLE_QUEUE_MAX)
241 Muzzle_queue_index = 0;
244 //creates a weapon object
245 int create_weapon_object(int weapon_type,int segnum,vms_vector *position)
248 fix laser_radius = -1;
252 switch( Weapon_info[weapon_type].render_type ) {
254 case WEAPON_RENDER_BLOB:
255 rtype = RT_LASER; // Render as a laser even if blob (see render code above for explanation)
256 laser_radius = Weapon_info[weapon_type].blob_size;
258 case WEAPON_RENDER_POLYMODEL:
259 laser_radius = 0; // Filled in below.
262 case WEAPON_RENDER_LASER:
263 Int3(); // Not supported anymore
265 case WEAPON_RENDER_NONE:
269 case WEAPON_RENDER_VCLIP:
270 rtype = RT_WEAPON_VCLIP;
271 laser_radius = Weapon_info[weapon_type].blob_size;
274 Error( "Invalid weapon render type in Laser_create_new\n" );
277 Assert(laser_radius != -1);
280 objnum = obj_create( OBJ_WEAPON, weapon_type, segnum, position, NULL, laser_radius, CT_WEAPON, MT_PHYSICS, rtype );
282 obj = &Objects[objnum];
284 if (Weapon_info[weapon_type].render_type == WEAPON_RENDER_POLYMODEL) {
285 obj->rtype.pobj_info.model_num = Weapon_info[obj->id].model_num;
286 obj->size = fixdiv(Polygon_models[obj->rtype.pobj_info.model_num].rad,Weapon_info[obj->id].po_len_to_width_ratio);
289 obj->mtype.phys_info.mass = Weapon_info[weapon_type].mass;
290 obj->mtype.phys_info.drag = Weapon_info[weapon_type].drag;
291 vm_vec_zero(&obj->mtype.phys_info.thrust);
293 if (Weapon_info[weapon_type].bounce==1)
294 obj->mtype.phys_info.flags |= PF_BOUNCE;
296 if (Weapon_info[weapon_type].bounce==2 || BounceCheat)
297 obj->mtype.phys_info.flags |= PF_BOUNCE+PF_BOUNCES_TWICE;
303 extern int Doing_lighting_hack_flag;
305 // -------------------------------------------------------------------------------------------------------------------------------
306 // ***** HEY ARTISTS!! *****
307 // Here are the constants you're looking for! --MK
309 // Change the following constants to affect the look of the omega cannon.
310 // Changing these constants will not affect the damage done.
311 // WARNING: If you change DESIRED_OMEGA_DIST and MAX_OMEGA_BLOBS, you don't merely change the look of the cannon,
312 // you change its range. If you decrease DESIRED_OMEGA_DIST, you decrease how far the gun can fire.
313 #define MIN_OMEGA_BLOBS 3 // No matter how close the obstruction, at this many blobs created.
314 #define MIN_OMEGA_DIST (F1_0*3) // At least this distance between blobs, unless doing so would violate MIN_OMEGA_BLOBS
315 #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.
316 #define MAX_OMEGA_BLOBS 16 // No matter how far away the obstruction, this is the maximum number of blobs.
317 #define MAX_OMEGA_DIST (MAX_OMEGA_BLOBS * DESIRED_OMEGA_DIST) // Maximum extent of lightning blobs.
319 // Additionally, several constants which apply to homing objects in general control the behavior of the Omega Cannon.
320 // They are defined in laser.h. They are copied here for reference. These values are valid on 1/10/96:
321 // If you want the Omega Cannon view cone to be different than the Homing Missile viewcone, contact MK to make the change.
322 // (Unless you are a programmer, in which case, do it yourself!)
323 #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.
324 #define OMEGA_MAX_TRACKABLE_DIST MAX_OMEGA_DIST // An object must be at least this close to be tracked.
326 // Note, you don't need to change these constants. You can control damage and energy consumption by changing the
327 // usual bitmaps.tbl parameters.
328 #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.
329 #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.
330 // -------------------------------------------------------------------------------------------------------------------------------
332 void delete_old_omega_blobs(object *parent_objp)
338 parent_num = parent_objp->ctype.laser_info.parent_num;
340 for (i=0; i<=Highest_object_index; i++)
341 if (Objects[i].type == OBJ_WEAPON)
342 if (Objects[i].id == OMEGA_ID)
343 if (Objects[i].ctype.laser_info.parent_num == parent_num) {
348 mprintf((0, "%i Omega blobs deleted in frame %i\n", count, FrameCount));
351 // ---------------------------------------------------------------------------------
352 void create_omega_blobs(int firing_segnum, vms_vector *firing_pos, vms_vector *goal_pos, object *parent_objp)
354 int i, last_segnum, last_created_objnum = -1;
355 vms_vector vec_to_goal;
359 vms_vector omega_delta_vector;
360 vms_vector blob_pos, perturb_vec;
361 fix perturb_array[MAX_OMEGA_BLOBS];
363 if (Game_mode & GM_MULTI)
364 delete_old_omega_blobs(parent_objp);
366 vm_vec_sub(&vec_to_goal, goal_pos, firing_pos);
368 dist_to_goal = vm_vec_normalize_quick(&vec_to_goal);
370 if (dist_to_goal < MIN_OMEGA_BLOBS * MIN_OMEGA_DIST) {
371 omega_blob_dist = MIN_OMEGA_DIST;
372 num_omega_blobs = dist_to_goal/omega_blob_dist;
373 if (num_omega_blobs == 0)
376 omega_blob_dist = DESIRED_OMEGA_DIST;
377 num_omega_blobs = dist_to_goal / omega_blob_dist;
378 if (num_omega_blobs > MAX_OMEGA_BLOBS) {
379 num_omega_blobs = MAX_OMEGA_BLOBS;
380 omega_blob_dist = dist_to_goal / num_omega_blobs;
381 } else if (num_omega_blobs < MIN_OMEGA_BLOBS) {
382 num_omega_blobs = MIN_OMEGA_BLOBS;
383 omega_blob_dist = dist_to_goal / num_omega_blobs;
387 omega_delta_vector = vec_to_goal;
388 vm_vec_scale(&omega_delta_vector, omega_blob_dist);
390 // Now, create all the blobs
391 blob_pos = *firing_pos;
392 last_segnum = firing_segnum;
394 // If nearby, don't perturb vector. If not nearby, start halfway out.
395 if (dist_to_goal < MIN_OMEGA_DIST*4) {
396 for (i=0; i<num_omega_blobs; i++)
397 perturb_array[i] = 0;
399 vm_vec_scale_add2(&blob_pos, &omega_delta_vector, F1_0/2); // Put first blob half way out.
400 for (i=0; i<num_omega_blobs/2; i++) {
401 perturb_array[i] = F1_0*i + F1_0/4;
402 perturb_array[num_omega_blobs-1-i] = F1_0*i;
406 // Create random perturbation vector, but favor _not_ going up in player's reference.
407 make_random_vector(&perturb_vec);
408 vm_vec_scale_add2(&perturb_vec, &parent_objp->orient.uvec, -F1_0/2);
410 Doing_lighting_hack_flag = 1; // Ugly, but prevents blobs which are probably outside the mine from killing framerate.
412 for (i=0; i<num_omega_blobs; i++) {
414 int blob_objnum, segnum;
416 // This will put the last blob right at the destination object, causing damage.
417 if (i == num_omega_blobs-1)
418 vm_vec_scale_add2(&blob_pos, &omega_delta_vector, 15*F1_0/32); // Move last blob another (almost) half section
420 // Every so often, re-perturb blobs
424 make_random_vector(&temp_vec);
425 vm_vec_scale_add2(&perturb_vec, &temp_vec, F1_0/4);
428 vm_vec_scale_add(&temp_pos, &blob_pos, &perturb_vec, perturb_array[i]);
430 segnum = find_point_seg(&temp_pos, last_segnum);
434 last_segnum = segnum;
435 blob_objnum = obj_create(OBJ_WEAPON, OMEGA_ID, segnum, &temp_pos, NULL, 0, CT_WEAPON, MT_PHYSICS, RT_WEAPON_VCLIP );
436 if (blob_objnum == -1)
439 last_created_objnum = blob_objnum;
441 objp = &Objects[blob_objnum];
443 objp->lifeleft = ONE_FRAME_TIME;
444 objp->mtype.phys_info.velocity = vec_to_goal;
446 // Only make the last one move fast, else multiple blobs might collide with target.
447 vm_vec_scale(&objp->mtype.phys_info.velocity, F1_0*4);
449 objp->size = Weapon_info[objp->id].blob_size;
451 objp->shields = fixmul(OMEGA_DAMAGE_SCALE*FrameTime, Weapon_info[objp->id].strength[Difficulty_level]);
453 objp->ctype.laser_info.parent_type = parent_objp->type;
454 objp->ctype.laser_info.parent_signature = parent_objp->signature;
455 objp->ctype.laser_info.parent_num = parent_objp-Objects;
456 objp->movement_type = MT_NONE; // Only last one moves, that will get bashed below.
460 vm_vec_add2(&blob_pos, &omega_delta_vector);
464 // Make last one move faster, but it's already moving at speed = F1_0*4.
465 if (last_created_objnum != -1) {
466 vm_vec_scale(&Objects[last_created_objnum].mtype.phys_info.velocity, Weapon_info[OMEGA_ID].speed[Difficulty_level]/4);
467 Objects[last_created_objnum].movement_type = MT_PHYSICS;
470 Doing_lighting_hack_flag = 0;
473 #define MIN_OMEGA_CHARGE (MAX_OMEGA_CHARGE/8)
474 #define OMEGA_CHARGE_SCALE 4 // FrameTime / OMEGA_CHARGE_SCALE added to Omega_charge every frame.
475 fix Omega_charge = MAX_OMEGA_CHARGE;
477 #define OMEGA_CHARGE_SCALE 4
479 int Last_omega_fire_frame=0;
481 // ---------------------------------------------------------------------------------
482 // Call this every frame to recharge the Omega Cannon.
483 void omega_charge_frame(void)
485 fix delta_charge, old_omega_charge;
487 if (Omega_charge == MAX_OMEGA_CHARGE)
490 if (!(player_has_weapon(OMEGA_INDEX, 0) & HAS_WEAPON_FLAG))
496 if ((Primary_weapon == OMEGA_INDEX) && (Omega_charge == 0) && (Players[Player_num].energy == 0)) {
498 auto_select_weapon(0);
501 // Don't charge while firing.
502 if ((Last_omega_fire_frame == FrameCount) || (Last_omega_fire_frame == FrameCount-1))
505 if (Players[Player_num].energy) {
508 old_omega_charge = Omega_charge;
509 Omega_charge += FrameTime/OMEGA_CHARGE_SCALE;
510 if (Omega_charge > MAX_OMEGA_CHARGE)
511 Omega_charge = MAX_OMEGA_CHARGE;
513 delta_charge = Omega_charge - old_omega_charge;
515 energy_used = fixmul(F1_0*190/17, delta_charge);
516 if (Difficulty_level < 2)
517 energy_used = fixmul(energy_used, i2f(Difficulty_level+2)/4);
519 Players[Player_num].energy -= energy_used;
520 if (Players[Player_num].energy < 0)
521 Players[Player_num].energy = 0;
527 // -- fix Last_omega_muzzle_flash_time;
529 // ---------------------------------------------------------------------------------
530 // *objp is the object firing the omega cannon
531 // *pos is the location from which the omega bolt starts
532 void do_omega_stuff(object *parent_objp, vms_vector *firing_pos, object *weapon_objp)
534 int lock_objnum, firing_segnum;
536 int pnum = parent_objp->id;
538 if (pnum == Player_num) {
539 // If charge >= min, or (some charge and zero energy), allow to fire.
540 if (!((Omega_charge >= MIN_OMEGA_CHARGE) || (Omega_charge && !Players[pnum].energy))) {
541 obj_delete(weapon_objp-Objects);
545 Omega_charge -= FrameTime;
546 if (Omega_charge < 0)
549 // Ensure that the lightning cannon can be fired next frame.
550 Next_laser_fire_time = GameTime+1;
552 Last_omega_fire_frame = FrameCount;
555 weapon_objp->ctype.laser_info.parent_type = OBJ_PLAYER;
556 weapon_objp->ctype.laser_info.parent_num = Players[pnum].objnum;
557 weapon_objp->ctype.laser_info.parent_signature = Objects[Players[pnum].objnum].signature;
559 lock_objnum = find_homing_object(firing_pos, weapon_objp);
561 firing_segnum = find_point_seg(firing_pos, parent_objp->segnum);
564 if ( parent_objp == Viewer )
565 digi_play_sample( Weapon_info[weapon_objp->id].flash_sound, F1_0 );
567 digi_link_sound_to_pos( Weapon_info[weapon_objp->id].flash_sound, weapon_objp->segnum, 0, &weapon_objp->pos, 0, F1_0 );
569 // -- if ((Last_omega_muzzle_flash_time + F1_0/4 < GameTime) || (Last_omega_muzzle_flash_time > GameTime)) {
570 // -- do_muzzle_stuff(firing_segnum, firing_pos);
571 // -- Last_omega_muzzle_flash_time = GameTime;
574 // Delete the original object. Its only purpose in life was to determine which object to home in on.
575 obj_delete(weapon_objp-Objects);
577 // If couldn't lock on anything, fire straight ahead.
578 if (lock_objnum == -1) {
582 vms_vector perturb_vec, perturbed_fvec;
584 make_random_vector(&perturb_vec);
585 vm_vec_scale_add(&perturbed_fvec, &parent_objp->orient.fvec, &perturb_vec, F1_0/16);
587 vm_vec_scale_add(&goal_pos, firing_pos, &perturbed_fvec, MAX_OMEGA_DIST);
588 fq.startseg = firing_segnum;
589 if (fq.startseg == -1) {
590 mprintf((1, "Trying to fire Omega Cannon, but gun is outside mine. Aborting!\n"));
596 fq.thisobjnum = parent_objp-Objects;
597 fq.ignore_obj_list = NULL;
598 fq.flags = FQ_IGNORE_POWERUPS | FQ_TRANSPOINT | FQ_CHECK_OBJS; //what about trans walls???
600 fate = find_vector_intersection(&fq, &hit_data);
601 if (fate != HIT_NONE) {
602 Assert(hit_data.hit_seg != -1); // How can this be? We went from inside the mine to outside without hitting anything?
603 goal_pos = hit_data.hit_pnt;
606 goal_pos = Objects[lock_objnum].pos;
608 // This is where we create a pile of omega blobs!
609 create_omega_blobs(firing_segnum, firing_pos, &goal_pos, parent_objp);
613 // ---------------------------------------------------------------------------------
614 // Initializes a laser after Fire is pressed
615 // Returns object number.
616 int Laser_create_new( vms_vector * direction, vms_vector * position, int segnum, int parent, int weapon_type, int make_sound )
620 fix parent_speed, weapon_speed;
624 Assert( weapon_type < N_weapon_types );
626 if ( (weapon_type<0) || (weapon_type>=N_weapon_types) )
629 // Don't let homing blobs make muzzle flash.
630 if (Objects[parent].type == OBJ_ROBOT)
631 do_muzzle_stuff(segnum, position);
633 objnum = create_weapon_object(weapon_type,segnum,position);
636 mprintf((1, "Can't create laser - Out of objects!\n" ));
640 obj = &Objects[objnum];
642 // Do the special Omega Cannon stuff. Then return on account of everything that follows does
643 // not apply to the Omega Cannon.
644 if (weapon_type == OMEGA_ID) {
645 // Create orientation matrix for tracking purposes.
646 vm_vector_2_matrix( &obj->orient, direction, &Objects[parent].orient.uvec ,NULL);
648 if (( &Objects[parent] != Viewer ) && (Objects[parent].type != OBJ_WEAPON)) {
650 if (Weapon_info[obj->id].flash_vclip > -1 )
651 object_create_muzzle_flash( obj->segnum, &obj->pos, Weapon_info[obj->id].flash_size, Weapon_info[obj->id].flash_vclip );
654 do_omega_stuff(&Objects[parent], position, obj);
659 if (Objects[parent].type == OBJ_PLAYER) {
660 if (weapon_type == FUSION_ID) {
662 if (Fusion_charge <= 0)
663 obj->ctype.laser_info.multiplier = F1_0;
664 else if (Fusion_charge <= 4*F1_0)
665 obj->ctype.laser_info.multiplier = F1_0 + Fusion_charge/2;
667 obj->ctype.laser_info.multiplier = 4*F1_0;
669 } else if ((weapon_type >= LASER_ID && weapon_type <= MAX_SUPER_LASER_LEVEL) && (Players[Objects[parent].id].flags & PLAYER_FLAGS_QUAD_LASERS))
670 obj->ctype.laser_info.multiplier = F1_0*3/4;
671 else if (weapon_type == GUIDEDMISS_ID) {
672 if (parent==Players[Player_num].objnum) {
673 Guided_missile[Player_num]= obj;
674 Guided_missile_sig[Player_num] = obj->signature;
675 if (Newdemo_state==ND_STATE_RECORDING)
676 newdemo_record_guided_start();
681 // Make children of smart bomb bounce so if they hit a wall right away, they
682 // won't detonate. The frame interval code will clear this bit after 1/2 second.
683 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))
684 obj->mtype.phys_info.flags |= PF_BOUNCE;
686 if (Weapon_info[weapon_type].render_type == WEAPON_RENDER_POLYMODEL)
687 laser_length = Polygon_models[obj->rtype.pobj_info.model_num].rad * 2;
689 if (weapon_type == FLARE_ID)
690 obj->mtype.phys_info.flags |= PF_STICK; //this obj sticks to walls
692 obj->shields = Weapon_info[obj->id].strength[Difficulty_level];
694 // Fill in laser-specific data
696 obj->lifeleft = Weapon_info[obj->id].lifetime;
697 obj->ctype.laser_info.parent_type = Objects[parent].type;
698 obj->ctype.laser_info.parent_signature = Objects[parent].signature;
699 obj->ctype.laser_info.parent_num = parent;
701 // Assign parent type to highest level creator. This propagates parent type down from
702 // the original creator through weapons which create children of their own (ie, smart missile)
703 if (Objects[parent].type == OBJ_WEAPON) {
704 int highest_parent = parent;
708 while ((count++ < 10) && (Objects[highest_parent].type == OBJ_WEAPON)) {
711 next_parent = Objects[highest_parent].ctype.laser_info.parent_num;
712 if (Objects[next_parent].signature != Objects[highest_parent].ctype.laser_info.parent_signature)
713 break; // Probably means parent was killed. Just continue.
715 if (next_parent == highest_parent) {
716 Int3(); // Hmm, object is parent of itself. This would seem to be bad, no?
720 highest_parent = next_parent;
722 obj->ctype.laser_info.parent_num = highest_parent;
723 obj->ctype.laser_info.parent_type = Objects[highest_parent].type;
724 obj->ctype.laser_info.parent_signature = Objects[highest_parent].signature;
728 // Create orientation matrix so we can look from this pov
729 // Homing missiles also need an orientation matrix so they know if they can make a turn.
730 if ((obj->render_type == RT_POLYOBJ) || (Weapon_info[obj->id].homing_flag))
731 vm_vector_2_matrix( &obj->orient,direction, &Objects[parent].orient.uvec ,NULL);
733 if (( &Objects[parent] != Viewer ) && (Objects[parent].type != OBJ_WEAPON)) {
735 if (Weapon_info[obj->id].flash_vclip > -1 )
736 object_create_muzzle_flash( obj->segnum, &obj->pos, Weapon_info[obj->id].flash_size, Weapon_info[obj->id].flash_vclip );
740 if (Weapon_info[obj->id].flash_sound > -1 ) {
742 if ( parent == (Viewer-Objects) ) {
743 if (weapon_type == VULCAN_ID) // Make your own vulcan gun 1/2 as loud.
745 digi_play_sample( Weapon_info[obj->id].flash_sound, volume );
747 digi_link_sound_to_pos( Weapon_info[obj->id].flash_sound, obj->segnum, 0, &obj->pos, 0, volume );
752 // Fire the laser from the gun tip so that the back end of the laser bolt is at the gun tip.
753 // Move 1 frame, so that the end-tip of the laser is touching the gun barrel.
754 // This also jitters the laser a bit so that it doesn't alias.
755 // Don't do for weapons created by weapons.
756 if ((Objects[parent].type == OBJ_PLAYER) && (Weapon_info[weapon_type].render_type != WEAPON_RENDER_NONE) && (weapon_type != FLARE_ID)) {
760 vm_vec_scale_add( &end_pos, &obj->pos, direction, Laser_offset+(laser_length/2) );
761 end_segnum = find_point_seg(&end_pos, obj->segnum);
762 if (end_segnum != obj->segnum) {
763 // mprintf(0, "Warning: Laser tip not in same segment as player.\n");
764 if (end_segnum != -1) {
766 obj_relink(obj-Objects, end_segnum);
768 mprintf((0, "Warning: Laser tip outside mine. Laser not being moved to end of gun.\n"));
773 // Here's where to fix the problem with objects which are moving backwards imparting higher velocity to their weaponfire.
774 // Find out if moving backwards.
775 if ((weapon_type == PROXIMITY_ID) || (weapon_type == SUPERPROX_ID)) {
776 parent_speed = vm_vec_mag_quick(&Objects[parent].mtype.phys_info.velocity);
777 if (vm_vec_dot(&Objects[parent].mtype.phys_info.velocity, &Objects[parent].orient.fvec) < 0)
778 parent_speed = -parent_speed;
782 weapon_speed = Weapon_info[obj->id].speed[Difficulty_level];
783 if (Weapon_info[obj->id].speedvar != 128) {
786 // Get a scale factor between speedvar% and 1.0.
787 randval = F1_0 - ((d_rand() * Weapon_info[obj->id].speedvar) >> 6);
788 weapon_speed = fixmul(weapon_speed, randval);
791 // Ugly hack (too bad we're on a deadline), for homing missiles dropped by smart bomb, start them out slower.
792 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))
795 if (Weapon_info[obj->id].thrust != 0)
798 vm_vec_copy_scale( &obj->mtype.phys_info.velocity, direction, weapon_speed + parent_speed );
801 if (Weapon_info[weapon_type].thrust != 0) {
802 obj->mtype.phys_info.thrust = obj->mtype.phys_info.velocity;
803 vm_vec_scale(&obj->mtype.phys_info.thrust, fixdiv(Weapon_info[obj->id].thrust, weapon_speed+parent_speed));
806 if ((obj->type == OBJ_WEAPON) && (obj->id == FLARE_ID))
807 obj->lifeleft += (d_rand()-16384) << 2; // add in -2..2 seconds
809 // mprintf( 0, "Weapon speed = %.1f (%.1f)\n", f2fl(Weapon_info[obj->id].speed[Difficulty_level] + parent_speed), f2fl(parent_speed) );
814 // -----------------------------------------------------------------------------------------------------------
815 // Calls Laser_create_new, but takes care of the segment and point computation for you.
816 int Laser_create_new_easy( vms_vector * direction, vms_vector * position, int parent, int weapon_type, int make_sound )
820 object *pobjp = &Objects[parent];
823 // Find segment containing laser fire position. If the robot is straddling a segment, the position from
824 // which it fires may be in a different segment, which is bad news for find_vector_intersection. So, cast
825 // a ray from the object center (whose segment we know) to the laser position. Then, in the call to Laser_create_new
826 // use the data returned from this call to find_vector_intersection.
827 // Note that while find_vector_intersection is pretty slow, it is not terribly slow if the destination point is
828 // in the same segment as the source point.
831 fq.startseg = pobjp->segnum;
834 fq.thisobjnum = pobjp-Objects;
835 fq.ignore_obj_list = NULL;
836 fq.flags = FQ_TRANSWALL | FQ_CHECK_OBJS; //what about trans walls???
838 fate = find_vector_intersection(&fq, &hit_data);
839 if (fate != HIT_NONE || hit_data.hit_seg==-1) {
840 mprintf((1, "Warning: Laser from parent=%i stuck in wall or object, didn't fire!\n", parent));
844 return Laser_create_new( direction, &hit_data.hit_pnt, hit_data.hit_seg, parent, weapon_type, make_sound );
848 int Muzzle_queue_index = 0;
850 muzzle_info Muzzle_data[MUZZLE_QUEUE_MAX];
852 // -----------------------------------------------------------------------------------------------------------
853 // Determine if two objects are on a line of sight. If so, return true, else return false.
855 int object_to_object_visibility(object *obj1, object *obj2, int trans_type)
862 fq.startseg = obj1->segnum;
865 fq.thisobjnum = obj1-Objects;
866 fq.ignore_obj_list = NULL;
867 fq.flags = trans_type;
869 fate = find_vector_intersection(&fq, &hit_data);
871 if (fate == HIT_WALL)
873 else if (fate == HIT_NONE)
876 Int3(); // Contact Mike: Oops, what happened? What is fate?
877 // 2 = hit object (impossible), 3 = bad starting point (bad)
882 fix Min_trackable_dot = MIN_TRACKABLE_DOT;
884 // -----------------------------------------------------------------------------------------------------------
885 // Return true if weapon *tracker is able to track object Objects[track_goal], else return false.
886 // In order for the object to be trackable, it must be within a reasonable turning radius for the missile
887 // and it must not be obstructed by a wall.
888 int object_is_trackable(int track_goal, object *tracker, fix *dot)
890 vms_vector vector_to_goal;
893 if (track_goal == -1)
896 if (Game_mode & GM_MULTI_COOP)
899 objp = &Objects[track_goal];
901 // Don't track player if he's cloaked.
902 if ((track_goal == Players[Player_num].objnum) && (Players[Player_num].flags & PLAYER_FLAGS_CLOAKED))
905 // Can't track AI object if he's cloaked.
906 if (objp->type == OBJ_ROBOT) {
907 if (objp->ctype.ai_info.CLOAKED)
909 // Your missiles don't track your escort.
910 if (Robot_info[objp->id].companion)
911 if (tracker->ctype.laser_info.parent_type == OBJ_PLAYER)
914 vm_vec_sub(&vector_to_goal, &objp->pos, &tracker->pos);
915 vm_vec_normalize_quick(&vector_to_goal);
916 *dot = vm_vec_dot(&vector_to_goal, &tracker->orient.fvec);
918 if ((*dot < Min_trackable_dot) && (*dot > F1_0*9/10)) {
919 // -- mprintf((0, "."));
920 vm_vec_normalize(&vector_to_goal);
921 *dot = vm_vec_dot(&vector_to_goal, &tracker->orient.fvec);
924 //mprintf((0, " OIT: dot=%5.2f ", f2fl(dot)));
926 // mprintf((0, "object_is_trackable: [%3i] %7.3f, min = %7.3f\n", track_goal, f2fl(dot), f2fl(Min_trackable_dot)));
928 if (*dot >= Min_trackable_dot) {
930 // dot is in legal range, now see if object is visible
931 rval = object_to_object_visibility(tracker, objp, FQ_TRANSWALL);
932 //mprintf((0, " TRACK "));
935 //mprintf((0, " LOST! "));
941 extern int Robots_kill_robots_cheat;
943 // --------------------------------------------------------------------------------------------
944 int call_find_homing_object_complete(object *tracker, vms_vector *curpos)
946 if (Game_mode & GM_MULTI) {
947 if (tracker->ctype.laser_info.parent_type == OBJ_PLAYER) {
948 // It's fired by a player, so if robots present, track robot, else track player.
949 if (Game_mode & GM_MULTI_COOP)
950 return find_homing_object_complete( curpos, tracker, OBJ_ROBOT, -1);
952 return find_homing_object_complete( curpos, tracker, OBJ_PLAYER, OBJ_ROBOT);
956 if (Robots_kill_robots_cheat)
957 goal2_type = OBJ_ROBOT;
958 Assert(tracker->ctype.laser_info.parent_type == OBJ_ROBOT);
959 return find_homing_object_complete(curpos, tracker, OBJ_PLAYER, goal2_type);
962 return find_homing_object_complete( curpos, tracker, OBJ_ROBOT, -1);
965 // --------------------------------------------------------------------------------------------
966 // Find object to home in on.
967 // Scan list of objects rendered last frame, find one that satisfies function of nearness to center and distance.
968 int find_homing_object(vms_vector *curpos, object *tracker)
971 fix max_dot = -F1_0*2;
972 int best_objnum = -1;
974 // Contact Mike: This is a bad and stupid thing. Who called this routine with an illegal laser type??
975 Assert((Weapon_info[tracker->id].homing_flag) || (tracker->id == OMEGA_ID));
977 // Find an object to track based on game mode (eg, whether in network play) and who fired it.
979 if (Game_mode & GM_MULTI)
980 return call_find_homing_object_complete(tracker, curpos);
982 int cur_min_trackable_dot;
984 cur_min_trackable_dot = MIN_TRACKABLE_DOT;
985 if ((tracker->type == OBJ_WEAPON) && (tracker->id == OMEGA_ID))
986 cur_min_trackable_dot = OMEGA_MIN_TRACKABLE_DOT;
988 // Not in network mode. If not fired by player, then track player.
989 if (tracker->ctype.laser_info.parent_num != Players[Player_num].objnum) {
990 if (!(Players[Player_num].flags & PLAYER_FLAGS_CLOAKED))
991 best_objnum = ConsoleObject - Objects;
994 fix dist, max_trackable_dist;
996 // Find the window which has the forward view.
997 for (i=0; i<MAX_RENDERED_WINDOWS; i++)
998 if (Window_rendered_data[i].frame >= FrameCount-1)
999 if (Window_rendered_data[i].viewer == ConsoleObject)
1000 if (!Window_rendered_data[i].rear_view) {
1005 // Couldn't find suitable view from this frame, so do complete search.
1006 if (window_num == -1) {
1007 mprintf((0, "Note: Calling find_homing_object_complete because no suitable rendered window.\n"));
1008 return call_find_homing_object_complete(tracker, curpos);
1011 max_trackable_dist = MAX_TRACKABLE_DIST;
1012 if (tracker->id == OMEGA_ID)
1013 max_trackable_dist = OMEGA_MAX_TRACKABLE_DIST;
1015 // Not in network mode and fired by player.
1016 for (i=Window_rendered_data[window_num].num_objects-1; i>=0; i--) {
1018 vms_vector vec_to_curobj;
1019 int objnum = Window_rendered_data[window_num].rendered_objects[i];
1020 object *curobjp = &Objects[objnum];
1022 if (objnum == Players[Player_num].objnum)
1025 // Can't track AI object if he's cloaked.
1026 if (curobjp->type == OBJ_ROBOT) {
1027 if (curobjp->ctype.ai_info.CLOAKED)
1030 // Your missiles don't track your escort.
1031 if (Robot_info[curobjp->id].companion)
1032 if (tracker->ctype.laser_info.parent_type == OBJ_PLAYER)
1036 vm_vec_sub(&vec_to_curobj, &curobjp->pos, curpos);
1037 dist = vm_vec_normalize_quick(&vec_to_curobj);
1038 if (dist < max_trackable_dist) {
1039 dot = vm_vec_dot(&vec_to_curobj, &tracker->orient.fvec);
1041 // mprintf(0, "Object %i: dist = %7.3f, dot = %7.3f\n", objnum, f2fl(dist), f2fl(dot));
1043 // Note: This uses the constant, not-scaled-by-frametime value, because it is only used
1044 // to determine if an object is initially trackable. find_homing_object is called on subsequent
1045 // frames to determine if the object remains trackable.
1046 // mprintf((0, "find_homing_object: [%3i] %7.3f, min = %7.3f\n", curobjp-Objects, f2fl(dot), f2fl(MIN_TRACKABLE_DOT)));
1047 if (dot > cur_min_trackable_dot) {
1048 if (dot > max_dot) {
1049 if (object_to_object_visibility(tracker, &Objects[objnum], FQ_TRANSWALL)) {
1051 best_objnum = objnum;
1054 } else if (dot > F1_0 - (F1_0 - cur_min_trackable_dot)*2) {
1055 vm_vec_normalize(&vec_to_curobj);
1056 dot = vm_vec_dot(&vec_to_curobj, &tracker->orient.fvec);
1057 if (dot > cur_min_trackable_dot) {
1058 if (dot > max_dot) {
1059 if (object_to_object_visibility(tracker, &Objects[objnum], FQ_TRANSWALL)) {
1061 best_objnum = objnum;
1071 // mprintf(0, "Selecting object #%i\n=n", best_objnum);
1076 // --------------------------------------------------------------------------------------------
1077 // Find object to home in on.
1078 // Scan list of objects rendered last frame, find one that satisfies function of nearness to center and distance.
1079 // Can track two kinds of objects. If you are only interested in one type, set track_obj_type2 to NULL
1080 // Always track proximity bombs. --MK, 06/14/95
1081 // Make homing objects not track parent's prox bombs.
1082 int find_homing_object_complete(vms_vector *curpos, object *tracker, int track_obj_type1, int track_obj_type2)
1085 fix max_dot = -F1_0*2;
1086 int best_objnum = -1;
1087 fix max_trackable_dist;
1088 fix min_trackable_dot;
1090 // Contact Mike: This is a bad and stupid thing. Who called this routine with an illegal laser type??
1091 Assert((Weapon_info[tracker->id].homing_flag) || (tracker->id == OMEGA_ID));
1093 max_trackable_dist = MAX_TRACKABLE_DIST;
1094 min_trackable_dot = MIN_TRACKABLE_DOT;
1096 if (tracker->id == OMEGA_ID) {
1097 max_trackable_dist = OMEGA_MAX_TRACKABLE_DIST;
1098 min_trackable_dot = OMEGA_MIN_TRACKABLE_DOT;
1101 for (objnum=0; objnum<=Highest_object_index; objnum++) {
1102 int is_proximity = 0;
1104 vms_vector vec_to_curobj;
1105 object *curobjp = &Objects[objnum];
1107 if ((curobjp->type != track_obj_type1) && (curobjp->type != track_obj_type2))
1109 if ((curobjp->type == OBJ_WEAPON) && ((curobjp->id == PROXIMITY_ID) || (curobjp->id == SUPERPROX_ID))) {
1110 if (curobjp->ctype.laser_info.parent_signature != tracker->ctype.laser_info.parent_signature)
1118 if (objnum == tracker->ctype.laser_info.parent_num) // Don't track shooter
1121 // Don't track cloaked players.
1122 if (curobjp->type == OBJ_PLAYER)
1124 if (Players[curobjp->id].flags & PLAYER_FLAGS_CLOAKED)
1126 // Don't track teammates in team games
1128 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)))
1133 // Can't track AI object if he's cloaked.
1134 if (curobjp->type == OBJ_ROBOT) {
1135 if (curobjp->ctype.ai_info.CLOAKED)
1138 // Your missiles don't track your escort.
1139 if (Robot_info[curobjp->id].companion)
1140 if (tracker->ctype.laser_info.parent_type == OBJ_PLAYER)
1144 vm_vec_sub(&vec_to_curobj, &curobjp->pos, curpos);
1145 dist = vm_vec_mag_quick(&vec_to_curobj);
1147 if (dist < max_trackable_dist) {
1148 vm_vec_normalize_quick(&vec_to_curobj);
1149 dot = vm_vec_dot(&vec_to_curobj, &tracker->orient.fvec);
1151 dot = ((dot << 3) + dot) >> 3; // I suspect Watcom would be too stupid to figure out the obvious...
1153 // Note: This uses the constant, not-scaled-by-frametime value, because it is only used
1154 // to determine if an object is initially trackable. find_homing_object is called on subsequent
1155 // frames to determine if the object remains trackable.
1156 // mprintf((0, "fho_complete: [%3i] %7.3f, min = %7.3f\n", curobjp-Objects, f2fl(dot), f2fl(MIN_TRACKABLE_DOT)));
1157 if (dot > min_trackable_dot) {
1158 // mprintf(0, "Object %i: dist = %7.3f, dot = %7.3f\n", objnum, f2fl(dist), f2fl(dot));
1159 if (dot > max_dot) {
1160 if (object_to_object_visibility(tracker, &Objects[objnum], FQ_TRANSWALL)) {
1162 best_objnum = objnum;
1170 // -- mprintf((0, "Selecting object #%i in find_homing_object_complete\n\n", best_objnum));
1175 // ------------------------------------------------------------------------------------------------------------
1176 // See if legal to keep tracking currently tracked object. If not, see if another object is trackable. If not, return -1,
1177 // else return object number of tracking object.
1178 // Computes and returns a fairly precise dot product.
1179 int track_track_goal(int track_goal, object *tracker, fix *dot)
1181 // Every 8 frames for each object, scan all objects.
1182 if (object_is_trackable(track_goal, tracker, dot) && ((((tracker-Objects) ^ FrameCount) % 8) != 0)) {
1183 //mprintf((0, "ttg: QO"));
1185 } else if ((((tracker-Objects) ^ FrameCount) % 4) == 0) {
1188 // If player fired missile, then search for an object, if not, then give up.
1189 if (Objects[tracker->ctype.laser_info.parent_num].type == OBJ_PLAYER) {
1192 if (track_goal == -1)
1194 if (Game_mode & GM_MULTI)
1196 if (Game_mode & GM_MULTI_COOP)
1197 rval = find_homing_object_complete( &tracker->pos, tracker, OBJ_ROBOT, -1);
1198 else if (Game_mode & GM_MULTI_ROBOTS) // Not cooperative, if robots, track either robot or player
1199 rval = find_homing_object_complete( &tracker->pos, tracker, OBJ_PLAYER, OBJ_ROBOT);
1200 else // Not cooperative and no robots, track only a player
1201 rval = find_homing_object_complete( &tracker->pos, tracker, OBJ_PLAYER, -1);
1204 rval = find_homing_object_complete(&tracker->pos, tracker, OBJ_PLAYER, OBJ_ROBOT);
1208 goal_type = Objects[tracker->ctype.laser_info.track_goal].type;
1209 if ((goal_type == OBJ_PLAYER) || (goal_type == OBJ_ROBOT))
1210 rval = find_homing_object_complete(&tracker->pos, tracker, goal_type, -1);
1216 int goal_type, goal2_type = -1;
1218 if (Robots_kill_robots_cheat)
1219 goal2_type = OBJ_ROBOT;
1221 if (track_goal == -1)
1222 rval = find_homing_object_complete(&tracker->pos, tracker, OBJ_PLAYER, goal2_type);
1224 goal_type = Objects[tracker->ctype.laser_info.track_goal].type;
1225 rval = find_homing_object_complete(&tracker->pos, tracker, goal_type, goal2_type);
1229 Assert(rval != -2); // This means it never got set which is bad! Contact Mike.
1233 //if (track_goal != -1)
1234 // mprintf((0, "Object %i not tracking anything.\n", tracker-Objects));
1239 //-------------- Initializes a laser after Fire is pressed -----------------
1241 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)
1244 vms_vector LaserPos, LaserDir;
1247 vms_vector gun_point, *pnt;
1251 create_awareness_event(obj, PA_WEAPON_WALL_COLLISION);
1253 // Find the initial position of the laser
1254 pnt = &Player_ship->gun_points[gun_num];
1256 vm_copy_transpose_matrix(&m,&obj->orient);
1257 vm_vec_rotate(&gun_point,pnt,&m);
1259 vm_vec_add(&LaserPos,&obj->pos,&gun_point);
1261 // If supposed to fire at a delayed time (delay_time), then move this point backwards.
1263 vm_vec_scale_add2(&LaserPos, &obj->orient.fvec, -fixmul(delay_time, Weapon_info[laser_type].speed[Difficulty_level]));
1265 // do_muzzle_stuff(obj, &Pos);
1267 //--------------- Find LaserPos and LaserSeg ------------------
1269 fq.startseg = obj->segnum;
1272 fq.thisobjnum = obj-Objects;
1273 fq.ignore_obj_list = NULL;
1274 fq.flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS;
1276 Fate = find_vector_intersection(&fq, &hit_data);
1278 LaserSeg = hit_data.hit_seg;
1280 if (LaserSeg == -1) //some sort of annoying error
1283 //SORT OF HACK... IF ABOVE WAS CORRECT THIS WOULDNT BE NECESSARY.
1284 if ( vm_vec_dist_quick(&LaserPos, &obj->pos) > 0x50000 )
1287 if (Fate==HIT_WALL) {
1289 mprintf((0, "Your DELAYED laser is stuck thru a wall!\n" ));
1291 mprintf((0, "Your laser is stuck thru a wall!\n" ));
1295 if (Fate==HIT_OBJECT) {
1296 // if ( Objects[hit_data.hit_object].type == OBJ_ROBOT )
1297 // Objects[hit_data.hit_object].flags |= OF_SHOULD_BE_DEAD;
1298 mprintf((0, "Your laser is stuck in an object!\n" ));
1299 // if ( Objects[hit_data.hit_object].type != OBJ_POWERUP )
1301 //as of 12/6/94, we don't care if the laser is stuck in an object. We
1302 //just fire away normally
1305 // Now, make laser spread out.
1306 LaserDir = obj->orient.fvec;
1307 if ((spreadr != 0) || (spreadu != 0)) {
1308 vm_vec_scale_add2(&LaserDir, &obj->orient.rvec, spreadr);
1309 vm_vec_scale_add2(&LaserDir, &obj->orient.uvec, spreadu);
1312 objnum = Laser_create_new( &LaserDir, &LaserPos, LaserSeg, obj-Objects, laser_type, make_sound );
1314 // Omega cannon is a hack, not surprisingly. Don't want to do the rest of this stuff.
1315 if (laser_type == OMEGA_ID)
1322 if (laser_type==GUIDEDMISS_ID && Multi_is_guided) {
1323 mprintf ((0,"Guided missile %s activated!\n",Players[obj->id].callsign));
1324 Guided_missile[obj->id]=&Objects[objnum];
1330 if (laser_type == CONCUSSION_ID ||
1331 laser_type == HOMING_ID ||
1332 laser_type == SMART_ID ||
1333 laser_type == MEGA_ID ||
1334 laser_type == FLASH_ID ||
1335 //laser_type == GUIDEDMISS_ID ||
1336 //laser_type == SUPERPROX_ID ||
1337 laser_type == MERCURY_ID ||
1338 laser_type == EARTHSHAKER_ID)
1339 if (Missile_viewer == NULL && obj->id==Player_num)
1340 Missile_viewer = &Objects[objnum];
1342 // If this weapon is supposed to be silent, set that bit!
1344 Objects[objnum].flags |= OF_SILENT;
1346 // If this weapon is supposed to be silent, set that bit!
1348 Objects[objnum].flags |= OF_HARMLESS;
1350 // If the object firing the laser is the player, then indicate the laser object so robots can dodge.
1351 // New by MK on 6/8/95, don't let robots evade proximity bombs, thereby decreasing uselessness of bombs.
1352 if ((obj == ConsoleObject) && ((Objects[objnum].id != PROXIMITY_ID) && (Objects[objnum].id != SUPERPROX_ID)))
1353 Player_fired_laser_this_frame = objnum;
1355 if (Weapon_info[laser_type].homing_flag) {
1356 if (obj == ConsoleObject)
1358 Objects[objnum].ctype.laser_info.track_goal = find_homing_object(&LaserPos, &Objects[objnum]);
1360 Network_laser_track = Objects[objnum].ctype.laser_info.track_goal;
1364 else // Some other player shot the homing thing
1366 Assert(Game_mode & GM_MULTI);
1367 Objects[objnum].ctype.laser_info.track_goal = Network_laser_track;
1370 // mprintf((0, "Selecting object #%i in find_homing_object_complete\n", Network_laser_track));
1374 // -----------------------------------------------------------------------------------------------------------
1375 void Laser_player_fire_spread(object *obj, int laser_type, int gun_num, fix spreadr, fix spreadu, int make_sound, int harmless)
1377 Laser_player_fire_spread_delay(obj, laser_type, gun_num, spreadr, spreadu, 0, make_sound, harmless);
1381 // -----------------------------------------------------------------------------------------------------------
1382 void Laser_player_fire(object *obj, int laser_type, int gun_num, int make_sound, int harmless)
1384 Laser_player_fire_spread(obj, laser_type, gun_num, 0, 0, make_sound, harmless);
1387 // -----------------------------------------------------------------------------------------------------------
1388 void Flare_create(object *obj)
1392 energy_usage = Weapon_info[FLARE_ID].energy_usage;
1394 if (Difficulty_level < 2)
1395 energy_usage = fixmul(energy_usage, i2f(Difficulty_level+2)/4);
1397 // MK, 11/04/95: Allowed to fire flare even if no energy.
1398 // -- if (Players[Player_num].energy >= energy_usage) {
1399 Players[Player_num].energy -= energy_usage;
1401 if (Players[Player_num].energy <= 0) {
1402 Players[Player_num].energy = 0;
1403 // -- auto_select_weapon(0);
1406 Laser_player_fire( obj, FLARE_ID, 6, 1, 0);
1409 if (Game_mode & GM_MULTI) {
1410 Network_laser_fired = 1;
1411 Network_laser_gun = FLARE_ADJUST;
1412 Network_laser_flags = 0;
1413 Network_laser_level = 0;
1420 #define HOMING_MISSILE_SCALE 16
1422 #define LIMIT_HOMERS 1
1423 #define HOMER_MAX_FPS 30
1424 #define HOMER_MIN_DELAY (1000 / HOMER_MAX_FPS)
1426 //--------------------------------------------------------------------
1427 // Set object *objp's orientation to (or towards if I'm ambitious) its velocity.
1428 void homing_missile_turn_towards_velocity(object *objp, vms_vector *norm_vel)
1430 vms_vector new_fvec;
1433 static time_t last_time = -1;
1434 static int nFrames = 1;
1435 time_t this_time, delta_time;
1438 if (last_time == -1) {
1439 last_time = clock ();
1440 frame_time = FrameTime;
1443 this_time = clock ();
1444 delta_time = this_time - last_time;
1445 if (delta_time < HOMER_MIN_DELAY) {
1448 fps = (1000 + delta_time / 2) / delta_time;
1449 frame_time = fps ? (f1_0 + fps / 2) / fps : f1_0;
1450 // frame_time /= nFrames;
1452 last_time = this_time;
1456 fix frame_time = FrameTime;
1459 new_fvec = *norm_vel;
1461 vm_vec_scale(&new_fvec, frame_time * HOMING_MISSILE_SCALE);
1462 vm_vec_add2(&new_fvec, &objp->orient.fvec);
1463 vm_vec_normalize_quick(&new_fvec);
1465 // if ((norm_vel->x == 0) && (norm_vel->y == 0) && (norm_vel->z == 0))
1468 vm_vector_2_matrix(&objp->orient, &new_fvec, NULL, NULL);
1471 //-------------------------------------------------------------------------------------------
1472 //sequence this laser object for this _frame_ (underscores added here to aid MK in his searching!)
1473 void Laser_do_weapon_sequence(object *obj)
1475 Assert(obj->control_type == CT_WEAPON);
1477 // Ok, this is a big hack by MK.
1478 // If you want an object to last for exactly one frame, then give it a lifeleft of ONE_FRAME_TIME
1479 if (obj->lifeleft == ONE_FRAME_TIME) {
1480 if (Game_mode & GM_MULTI)
1481 obj->lifeleft = OMEGA_MULTI_LIFELEFT;
1484 obj->render_type = RT_NONE;
1487 if (obj->lifeleft < 0 ) { // We died of old age
1488 obj->flags |= OF_SHOULD_BE_DEAD;
1489 if ( Weapon_info[obj->id].damage_radius )
1490 explode_badass_weapon(obj,&obj->pos);
1494 //delete weapons that are not moving
1495 if ( !((FrameCount ^ obj->signature) & 3) &&
1496 (obj->id != FLARE_ID) &&
1497 (Weapon_info[obj->id].speed[Difficulty_level] > 0) &&
1498 (vm_vec_mag_quick(&obj->mtype.phys_info.velocity) < F2_0)) {
1499 obj_delete(obj-Objects);
1503 if ( obj->id == FUSION_ID ) { //always set fusion weapon to max vel
1505 vm_vec_normalize_quick(&obj->mtype.phys_info.velocity);
1507 vm_vec_scale(&obj->mtype.phys_info.velocity, Weapon_info[obj->id].speed[Difficulty_level]);
1510 // -- // The Super Spreadfire (Helix) blobs travel in a sinusoidal path. That is accomplished
1511 // -- // by modifying velocity (direction) in the frame interval.
1512 // -- if (obj->id == SSPREADFIRE_ID) {
1513 // -- fix age, sinval, cosval;
1514 // -- vms_vector p, newp;
1517 // -- speed = vm_vec_mag_quick(&obj->phys_info.velocity);
1519 // -- age = Weapon_info[obj->id].lifetime - obj->lifeleft;
1521 // -- fix_fast_sincos(age, &sinval, &cosval);
1523 // -- // Note: Below code assumes x=1, y=0. Need to scale this for values around a circle for 5 helix positions.
1524 // -- p.x = cosval << 3;
1525 // -- p.y = sinval << 3;
1528 // -- vm_vec_rotate(&newp, &p, &obj->orient);
1530 // -- vm_vec_add(&goal_point, &obj->pos, &newp);
1532 // -- vm_vec_sub(&vec_to_goal, &goal_point, obj
1536 // For homing missiles, turn towards target. (unless it's the guided missile)
1537 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)) {
1538 vms_vector vector_to_object, temp_vec;
1540 fix speed, max_speed;
1542 // For first 1/2 second of life, missile flies straight.
1543 if (obj->ctype.laser_info.creation_time + HOMING_MISSILE_STRAIGHT_TIME < GameTime) {
1545 int track_goal = obj->ctype.laser_info.track_goal;
1547 //mprintf((0, "%5i: mtd=%5.2f", FrameCount, f2fl(Min_trackable_dot)));
1549 // If it's time to do tracking, then it's time to grow up, stop bouncing and start exploding!.
1550 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)) {
1551 // if (obj->mtype.phys_info.flags & PF_BOUNCE) mprintf(0, "Debouncing smart child %i\n", obj-Objects);
1552 obj->mtype.phys_info.flags &= ~PF_BOUNCE;
1555 // Make sure the object we are tracking is still trackable.
1556 track_goal = track_track_goal(track_goal, obj, &dot);
1558 //mprintf((0, " after ttg=%3i ", track_goal));
1560 if (track_goal == Players[Player_num].objnum) {
1563 dist_to_player = vm_vec_dist_quick(&obj->pos, &Objects[track_goal].pos);
1564 if ((dist_to_player < Players[Player_num].homing_object_dist) || (Players[Player_num].homing_object_dist < 0))
1565 Players[Player_num].homing_object_dist = dist_to_player;
1569 if (track_goal != -1) {
1570 vm_vec_sub(&vector_to_object, &Objects[track_goal].pos, &obj->pos);
1572 vm_vec_normalize_quick(&vector_to_object);
1573 temp_vec = obj->mtype.phys_info.velocity;
1574 speed = vm_vec_normalize_quick(&temp_vec);
1575 max_speed = Weapon_info[obj->id].speed[Difficulty_level];
1576 if (speed+F1_0 < max_speed) {
1577 speed += fixmul(max_speed, FrameTime/2);
1578 if (speed > max_speed)
1582 // -- dot = vm_vec_dot(&temp_vec, &vector_to_object);
1583 //mprintf((0, " dot=%5.2f ", f2fl(dot)));
1584 vm_vec_add2(&temp_vec, &vector_to_object);
1585 // The boss' smart children track better...
1586 if (Weapon_info[obj->id].render_type != WEAPON_RENDER_POLYMODEL)
1587 vm_vec_add2(&temp_vec, &vector_to_object);
1588 vm_vec_normalize_quick(&temp_vec);
1589 obj->mtype.phys_info.velocity = temp_vec;
1590 vm_vec_scale(&obj->mtype.phys_info.velocity, speed);
1592 // Subtract off life proportional to amount turned.
1593 // For hardest turn, it will lose 2 seconds per second.
1595 fix lifelost, absdot;
1597 absdot = abs(F1_0 - dot);
1599 lifelost = fixmul(absdot*32, FrameTime);
1600 obj->lifeleft -= lifelost;
1601 // -- 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)));
1604 // Only polygon objects have visible orientation, so only they should turn.
1605 if (Weapon_info[obj->id].render_type == WEAPON_RENDER_POLYMODEL)
1606 homing_missile_turn_towards_velocity(obj, &temp_vec); // temp_vec is normalized velocity.
1610 //mprintf((0, "\n"));
1613 // Make sure weapon is not moving faster than allowed speed.
1617 weapon_speed = vm_vec_mag_quick(&obj->mtype.phys_info.velocity);
1618 if (weapon_speed > Weapon_info[obj->id].speed[Difficulty_level]) {
1619 // Only slow down if not allowed to move. Makes sense, huh? Allows proxbombs to get moved by physics force. --MK, 2/13/96
1620 if (Weapon_info[obj->id].speed[Difficulty_level]) {
1623 scale_factor = fixdiv(Weapon_info[obj->id].speed[Difficulty_level], weapon_speed);
1624 vm_vec_scale(&obj->mtype.phys_info.velocity, scale_factor);
1630 fix Last_laser_fired_time = 0;
1632 extern int Player_fired_laser_this_frame;
1636 // --------------------------------------------------------------------------------------------------
1637 // Assumption: This is only called by the actual console player, not for network players
1639 int do_laser_firing_player(void)
1641 player *plp = &Players[Player_num];
1643 int ammo_used,primary_ammo;
1648 static int Spreadfire_toggle=0;
1649 static int Helix_orientation = 0;
1654 weapon_index = Primary_weapon_to_weapon_info[Primary_weapon];
1655 energy_used = Weapon_info[weapon_index].energy_usage;
1656 if (Primary_weapon == OMEGA_INDEX)
1657 energy_used = 0; // Omega consumes energy when recharging, not when firing.
1659 if (Difficulty_level < 2)
1660 energy_used = fixmul(energy_used, i2f(Difficulty_level+2)/4);
1662 // MK, 01/26/96, Helix use 2x energy in multiplayer. bitmaps.tbl parm should have been reduced for single player.
1663 if (weapon_index == HELIX_INDEX)
1664 if (Game_mode & GM_MULTI)
1667 ammo_used = Weapon_info[weapon_index].ammo_usage;
1669 addval = 2*FrameTime;
1673 if ((Last_laser_fired_time + 2*FrameTime < GameTime) || (GameTime < Last_laser_fired_time))
1674 Next_laser_fire_time = GameTime;
1676 Last_laser_fired_time = GameTime;
1678 primary_ammo = (Primary_weapon == GAUSS_INDEX)?(plp->primary_ammo[VULCAN_INDEX]):(plp->primary_ammo[Primary_weapon]);
1680 if (!((plp->energy >= energy_used) && (primary_ammo >= ammo_used)))
1681 auto_select_weapon(0); // Make sure the player can fire from this weapon.
1688 while (Next_laser_fire_time <= GameTime) {
1689 if ((plp->energy >= energy_used) && (primary_ammo >= ammo_used)) {
1690 int laser_level, flags;
1693 if (Laser_rapid_fire!=0xBADA55)
1694 Next_laser_fire_time += Weapon_info[weapon_index].fire_wait;
1696 Next_laser_fire_time += F1_0/25;
1698 laser_level = Players[Player_num].laser_level;
1702 if (Primary_weapon == SPREADFIRE_INDEX) {
1703 if (Spreadfire_toggle)
1704 flags |= LASER_SPREADFIRE_TOGGLED;
1705 Spreadfire_toggle = !Spreadfire_toggle;
1708 if (Primary_weapon == HELIX_INDEX) {
1709 Helix_orientation++;
1710 flags |= ((Helix_orientation & LASER_HELIX_MASK) << LASER_HELIX_SHIFT);
1713 if (Players[Player_num].flags & PLAYER_FLAGS_QUAD_LASERS)
1714 flags |= LASER_QUAD;
1716 rval += do_laser_firing(Players[Player_num].objnum, Primary_weapon, laser_level, flags, nfires);
1718 plp->energy -= (energy_used * rval) / Weapon_info[weapon_index].fire_count;
1719 if (plp->energy < 0)
1722 if ((Primary_weapon == VULCAN_INDEX) || (Primary_weapon == GAUSS_INDEX)) {
1723 if (ammo_used > plp->primary_ammo[VULCAN_INDEX])
1724 plp->primary_ammo[VULCAN_INDEX] = 0;
1726 plp->primary_ammo[VULCAN_INDEX] -= ammo_used;
1729 auto_select_weapon(0); // Make sure the player can fire from this weapon.
1732 auto_select_weapon(0); // Make sure the player can fire from this weapon.
1733 Next_laser_fire_time = GameTime; // Prevents shots-to-fire from building up.
1734 break; // Couldn't fire weapon, so abort.
1737 //mprintf(0, " fires = %i\n", rval);
1739 Global_laser_firing_count = 0;
1744 // -- #define MAX_LIGHTNING_DISTANCE (F1_0*300)
1745 // -- #define MAX_LIGHTNING_BLOBS 16
1746 // -- #define LIGHTNING_BLOB_DISTANCE (MAX_LIGHTNING_DISTANCE/MAX_LIGHTNING_BLOBS)
1748 // -- #define LIGHTNING_BLOB_ID 13
1750 // -- #define LIGHTNING_TIME (F1_0/4)
1751 // -- #define LIGHTNING_DELAY (F1_0/8)
1753 // -- int Lightning_gun_num = 1;
1755 // -- fix Lightning_start_time = -F1_0*10, Lightning_last_time;
1757 // -- // --------------------------------------------------------------------------------------------------
1758 // -- // Return -1 if failed to create at least one blob. Else return index of last blob created.
1759 // -- int create_lightning_blobs(vms_vector *direction, vms_vector *start_pos, int start_segnum, int parent)
1763 // -- fvi_info hit_data;
1764 // -- vms_vector end_pos;
1765 // -- vms_vector norm_dir;
1767 // -- int num_blobs;
1768 // -- vms_vector tvec;
1769 // -- fix dist_to_hit_point;
1770 // -- vms_vector point_pos, delta_pos;
1772 // -- vms_vector *gun_pos;
1774 // -- vms_vector gun_pos2;
1776 // -- if (Players[Player_num].energy > F1_0)
1777 // -- Players[Player_num].energy -= F1_0;
1779 // -- if (Players[Player_num].energy <= F1_0) {
1780 // -- Players[Player_num].energy = 0;
1781 // -- auto_select_weapon(0);
1785 // -- norm_dir = *direction;
1787 // -- vm_vec_normalize_quick(&norm_dir);
1788 // -- vm_vec_scale_add(&end_pos, start_pos, &norm_dir, MAX_LIGHTNING_DISTANCE);
1790 // -- fq.p0 = start_pos;
1791 // -- fq.startseg = start_segnum;
1792 // -- fq.p1 = &end_pos;
1794 // -- fq.thisobjnum = parent;
1795 // -- fq.ignore_obj_list = NULL;
1796 // -- fq.flags = FQ_TRANSWALL | FQ_CHECK_OBJS;
1798 // -- fate = find_vector_intersection(&fq, &hit_data);
1799 // -- if (hit_data.hit_seg == -1) {
1800 // -- mprintf((1, "Warning: Lightning bolt has hit seg of -1.\n"));
1804 // -- dist_to_hit_point = vm_vec_mag(vm_vec_sub(&tvec, &hit_data.hit_pnt, start_pos));
1805 // -- num_blobs = dist_to_hit_point/LIGHTNING_BLOB_DISTANCE;
1807 // -- if (num_blobs > MAX_LIGHTNING_BLOBS)
1808 // -- num_blobs = MAX_LIGHTNING_BLOBS;
1810 // -- if (num_blobs < MAX_LIGHTNING_BLOBS/4)
1811 // -- num_blobs = MAX_LIGHTNING_BLOBS/4;
1813 // -- // Find the initial position of the laser
1814 // -- gun_pos = &Player_ship->gun_points[Lightning_gun_num];
1815 // -- vm_copy_transpose_matrix(&m,&Objects[parent].orient);
1816 // -- vm_vec_rotate(&gun_pos2, gun_pos, &m);
1817 // -- vm_vec_add(&point_pos, &Objects[parent].pos, &gun_pos2);
1819 // -- delta_pos = norm_dir;
1820 // -- vm_vec_scale(&delta_pos, dist_to_hit_point/num_blobs);
1822 // -- for (i=0; i<num_blobs; i++) {
1823 // -- int point_seg;
1826 // -- vm_vec_add2(&point_pos, &delta_pos);
1827 // -- point_seg = find_point_seg(&point_pos, start_segnum);
1828 // -- if (point_seg == -1) // Hey, we thought we were creating points on a line, but we left the mine!
1831 // -- objnum = Laser_create_new( direction, &point_pos, point_seg, parent, LIGHTNING_BLOB_ID, 0 );
1833 // -- if ( objnum < 0 ) {
1834 // -- mprintf((1, "Can't create lightning blob - Out of objects!\n" ));
1839 // -- obj = &Objects[objnum];
1841 // -- digi_play_sample( Weapon_info[obj->id].flash_sound, F1_0 );
1843 // -- // -- vm_vec_scale( &obj->mtype.phys_info.velocity, F1_0/2);
1845 // -- obj->lifeleft = (LIGHTNING_TIME + LIGHTNING_DELAY)/2;
1849 // -- return objnum;
1853 // -- // --------------------------------------------------------------------------------------------------
1854 // -- // Lightning Cannon.
1855 // -- // While being fired, creates path of blobs forward from player until it hits something.
1856 // -- // Up to MAX_LIGHTNING_BLOBS blobs, spaced LIGHTNING_BLOB_DISTANCE units apart.
1857 // -- // When the player releases the firing key, the blobs move forward.
1858 // -- void lightning_frame(void)
1860 // -- if ((GameTime - Lightning_start_time < LIGHTNING_TIME) && (GameTime - Lightning_start_time > 0)) {
1861 // -- if (GameTime - Lightning_last_time > LIGHTNING_DELAY) {
1862 // -- create_lightning_blobs(&ConsoleObject->orient.fvec, &ConsoleObject->pos, ConsoleObject->segnum, ConsoleObject-Objects);
1863 // -- Lightning_last_time = GameTime;
1868 // --------------------------------------------------------------------------------------------------
1869 // Object "objnum" fires weapon "weapon_num" of level "level". (Right now (9/24/94) level is used only for type 0 laser.
1870 // Flags are the player flags. For network mode, set to 0.
1871 // It is assumed that this is a player object (as in multiplayer), and therefore the gun positions are known.
1872 // Returns number of times a weapon was fired. This is typically 1, but might be more for low frame rates.
1873 // More than one shot is fired with a pseudo-delay so that players on show machines can fire (for themselves
1874 // or other players) often enough for things like the vulcan cannon.
1875 int do_laser_firing(int objnum, int weapon_num, int level, int flags, int nfires)
1877 object *objp = &Objects[objnum];
1879 switch (weapon_num) {
1883 Laser_offset = ((F1_0*2)*(d_rand()%8))/8;
1885 if (level <= MAX_LASER_LEVEL)
1886 weapon_num = LASER_ID + level;
1888 weapon_num = SUPER_LASER_ID + (level-MAX_LASER_LEVEL-1);
1890 Laser_player_fire( objp, weapon_num, 0, 1, 0);
1891 Laser_player_fire( objp, weapon_num, 1, 0, 0);
1893 if (flags & LASER_QUAD) {
1894 // hideous system to make quad laser 1.5x powerful as normal laser, make every other quad laser bolt harmless
1895 Laser_player_fire( objp, weapon_num, 2, 0, 0);
1896 Laser_player_fire( objp, weapon_num, 3, 0, 0);
1900 case VULCAN_INDEX: {
1901 // Only make sound for 1/4 of vulcan bullets.
1903 //if (d_rand() > 24576)
1905 Laser_player_fire_spread( objp, VULCAN_ID, 6, d_rand()/8 - 32767/16, d_rand()/8 - 32767/16, make_sound, 0);
1907 Laser_player_fire_spread( objp, VULCAN_ID, 6, d_rand()/8 - 32767/16, d_rand()/8 - 32767/16, 0, 0);
1909 Laser_player_fire_spread( objp, VULCAN_ID, 6, d_rand()/8 - 32767/16, d_rand()/8 - 32767/16, 0, 0);
1914 case SPREADFIRE_INDEX:
1915 if (flags & LASER_SPREADFIRE_TOGGLED) {
1916 Laser_player_fire_spread( objp, SPREADFIRE_ID, 6, F1_0/16, 0, 0, 0);
1917 Laser_player_fire_spread( objp, SPREADFIRE_ID, 6, -F1_0/16, 0, 0, 0);
1918 Laser_player_fire_spread( objp, SPREADFIRE_ID, 6, 0, 0, 1, 0);
1920 Laser_player_fire_spread( objp, SPREADFIRE_ID, 6, 0, F1_0/16, 0, 0);
1921 Laser_player_fire_spread( objp, SPREADFIRE_ID, 6, 0, -F1_0/16, 0, 0);
1922 Laser_player_fire_spread( objp, SPREADFIRE_ID, 6, 0, 0, 1, 0);
1927 Laser_player_fire( objp, PLASMA_ID, 0, 1, 0);
1928 Laser_player_fire( objp, PLASMA_ID, 1, 0, 0);
1930 Laser_player_fire_spread_delay( objp, PLASMA_ID, 0, 0, 0, FrameTime/2, 1, 0);
1931 Laser_player_fire_spread_delay( objp, PLASMA_ID, 1, 0, 0, FrameTime/2, 0, 0);
1935 case FUSION_INDEX: {
1936 vms_vector force_vec;
1938 // mprintf((0, "Fusion multiplier %f.\n", f2fl(Fusion_charge)));
1940 Laser_player_fire( objp, FUSION_ID, 0, 1, 0);
1941 Laser_player_fire( objp, FUSION_ID, 1, 1, 0);
1943 flags = (sbyte)(Fusion_charge >> 12);
1947 force_vec.x = -(objp->orient.fvec.x << 7);
1948 force_vec.y = -(objp->orient.fvec.y << 7);
1949 force_vec.z = -(objp->orient.fvec.z << 7);
1950 phys_apply_force(objp, &force_vec);
1952 force_vec.x = (force_vec.x >> 4) + d_rand() - 16384;
1953 force_vec.y = (force_vec.y >> 4) + d_rand() - 16384;
1954 force_vec.z = (force_vec.z >> 4) + d_rand() - 16384;
1955 phys_apply_rot(objp, &force_vec);
1959 case SUPER_LASER_INDEX: {
1960 int super_level = 3; //make some new kind of laser eventually
1961 Laser_player_fire( objp, super_level, 0, 1, 0);
1962 Laser_player_fire( objp, super_level, 1, 0, 0);
1964 if (flags & LASER_QUAD) {
1965 // hideous system to make quad laser 1.5x powerful as normal laser, make every other quad laser bolt harmless
1966 Laser_player_fire( objp, super_level, 2, 0, 0);
1967 Laser_player_fire( objp, super_level, 3, 0, 0);
1972 // Only make sound for 1/4 of vulcan bullets.
1974 //if (d_rand() > 24576)
1977 Laser_player_fire_spread( objp, GAUSS_ID, 6, (d_rand()/8 - 32767/16)/5, (d_rand()/8 - 32767/16)/5, make_sound, 0);
1979 Laser_player_fire_spread( objp, GAUSS_ID, 6, (d_rand()/8 - 32767/16)/5, (d_rand()/8 - 32767/16)/5, 0, 0);
1981 Laser_player_fire_spread( objp, GAUSS_ID, 6, (d_rand()/8 - 32767/16)/5, (d_rand()/8 - 32767/16)/5, 0, 0);
1988 fix spreadr,spreadu;
1989 helix_orient = (flags >> LASER_HELIX_SHIFT) & LASER_HELIX_MASK;
1990 switch(helix_orient) {
1992 case 0: spreadr = F1_0/16; spreadu = 0; break; // Vertical
1993 case 1: spreadr = F1_0/17; spreadu = F1_0/42; break; // 22.5 degrees
1994 case 2: spreadr = F1_0/22; spreadu = F1_0/22; break; // 45 degrees
1995 case 3: spreadr = F1_0/42; spreadu = F1_0/17; break; // 67.5 degrees
1996 case 4: spreadr = 0; spreadu = F1_0/16; break; // 90 degrees
1997 case 5: spreadr = -F1_0/42; spreadu = F1_0/17; break; // 112.5 degrees
1998 case 6: spreadr = -F1_0/22; spreadu = F1_0/22; break; // 135 degrees
1999 case 7: spreadr = -F1_0/17; spreadu = F1_0/42; break; // 157.5 degrees
2001 Error("Invalid helix_orientation value %x\n",helix_orient);
2004 Laser_player_fire_spread( objp, HELIX_ID, 6, 0, 0, 1, 0);
2005 Laser_player_fire_spread( objp, HELIX_ID, 6, spreadr, spreadu, 0, 0);
2006 Laser_player_fire_spread( objp, HELIX_ID, 6, -spreadr, -spreadu, 0, 0);
2007 Laser_player_fire_spread( objp, HELIX_ID, 6, spreadr*2, spreadu*2, 0, 0);
2008 Laser_player_fire_spread( objp, HELIX_ID, 6, -spreadr*2, -spreadu*2, 0, 0);
2013 Laser_player_fire( objp, PHOENIX_ID, 0, 1, 0);
2014 Laser_player_fire( objp, PHOENIX_ID, 1, 0, 0);
2016 Laser_player_fire_spread_delay( objp, PHOENIX_ID, 0, 0, 0, FrameTime/2, 1, 0);
2017 Laser_player_fire_spread_delay( objp, PHOENIX_ID, 1, 0, 0, FrameTime/2, 0, 0);
2022 Laser_player_fire( objp, OMEGA_ID, 1, 1, 0);
2026 Int3(); // Contact Yuan: Unknown Primary weapon type, setting to 0.
2030 // Set values to be recognized during comunication phase, if we are the
2033 if ((Game_mode & GM_MULTI) && (objnum == Players[Player_num].objnum))
2035 // mprintf((0, "Flags on fire: %d.\n", flags));
2036 Network_laser_fired = nfires;
2037 Network_laser_gun = weapon_num;
2038 Network_laser_flags = flags;
2039 Network_laser_level = level;
2046 #define MAX_SMART_DISTANCE (F1_0*150)
2047 #define MAX_OBJDISTS 30
2049 // -------------------------------------------------------------------------------------------
2050 // if goal_obj == -1, then create random vector
2051 int create_homing_missile(object *objp, int goal_obj, int objtype, int make_sound)
2054 vms_vector vector_to_goal;
2055 vms_vector random_vector;
2056 //vms_vector goal_pos;
2058 if (goal_obj == -1) {
2059 make_random_vector(&vector_to_goal);
2061 vm_vec_normalized_dir_quick(&vector_to_goal, &Objects[goal_obj].pos, &objp->pos);
2062 make_random_vector(&random_vector);
2063 vm_vec_scale_add2(&vector_to_goal, &random_vector, F1_0/4);
2064 vm_vec_normalize_quick(&vector_to_goal);
2067 // Create a vector towards the goal, then add some noise to it.
2068 objnum = Laser_create_new(&vector_to_goal, &objp->pos, objp->segnum, objp-Objects, objtype, make_sound);
2072 // Fixed to make sure the right person gets credit for the kill
2074 // Objects[objnum].ctype.laser_info.parent_num = objp->ctype.laser_info.parent_num;
2075 // Objects[objnum].ctype.laser_info.parent_type = objp->ctype.laser_info.parent_type;
2076 // Objects[objnum].ctype.laser_info.parent_signature = objp->ctype.laser_info.parent_signature;
2078 Objects[objnum].ctype.laser_info.track_goal = goal_obj;
2083 extern void blast_nearby_glass(object *objp, fix damage);
2085 //-----------------------------------------------------------------------------
2086 // Create the children of a smart bomb, which is a bunch of homing missiles.
2087 void create_smart_children(object *objp, int num_smart_children)
2089 int parent_type, parent_num;
2092 int objlist[MAX_OBJDISTS];
2095 if (objp->type == OBJ_WEAPON) {
2096 parent_type = objp->ctype.laser_info.parent_type;
2097 parent_num = objp->ctype.laser_info.parent_num;
2098 } else if (objp->type == OBJ_ROBOT) {
2099 parent_type = OBJ_ROBOT;
2100 parent_num = objp-Objects;
2102 Int3(); // Hey, what kind of object is this!?
2107 if (objp->id == EARTHSHAKER_ID)
2108 blast_nearby_glass(objp, Weapon_info[EARTHSHAKER_ID].strength[Difficulty_level]);
2111 if ((objp->type == OBJ_WEAPON) && ((objp->id == SMART_ID) || (objp->id == SUPERPROX_ID) || (objp->id == ROBOT_SUPERPROX_ID) || (objp->id == EARTHSHAKER_ID)))
2112 Assert(Weapon_info[objp->id].children != -1);
2115 if (((objp->type == OBJ_WEAPON) && (Weapon_info[objp->id].children != -1)) || (objp->type == OBJ_ROBOT)) {
2118 if (Game_mode & GM_MULTI)
2121 for (objnum=0; objnum<=Highest_object_index; objnum++) {
2122 object *curobjp = &Objects[objnum];
2124 if ((((curobjp->type == OBJ_ROBOT) && (!curobjp->ctype.ai_info.CLOAKED)) || (curobjp->type == OBJ_PLAYER)) && (objnum != parent_num)) {
2127 if (curobjp->type == OBJ_PLAYER)
2129 if ((parent_type == OBJ_PLAYER) && (Game_mode & GM_MULTI_COOP))
2132 if ((Game_mode & GM_TEAM) && (get_team(curobjp->id) == get_team(Objects[parent_num].id)))
2136 if (Players[curobjp->id].flags & PLAYER_FLAGS_CLOAKED)
2140 // Robot blobs can't track robots.
2141 if (curobjp->type == OBJ_ROBOT) {
2142 if (parent_type == OBJ_ROBOT)
2145 // Your shots won't track the buddy.
2146 if (parent_type == OBJ_PLAYER)
2147 if (Robot_info[curobjp->id].companion)
2151 dist = vm_vec_dist_quick(&objp->pos, &curobjp->pos);
2152 if (dist < MAX_SMART_DISTANCE) {
2155 oovis = object_to_object_visibility(objp, curobjp, FQ_TRANSWALL);
2157 if (oovis) { //object_to_object_visibility(objp, curobjp, FQ_TRANSWALL)) {
2158 objlist[numobjs] = objnum;
2160 if (numobjs >= MAX_OBJDISTS) {
2161 mprintf((0, "Warning -- too many objects near smart bomb explosion. See laser.c.\n"));
2162 numobjs = MAX_OBJDISTS;
2170 // Get type of weapon for child from parent.
2171 if (objp->type == OBJ_WEAPON) {
2172 blob_id = Weapon_info[objp->id].children;
2173 Assert(blob_id != -1); // Hmm, missing data in bitmaps.tbl. Need "children=NN" parameter.
2175 Assert(objp->type == OBJ_ROBOT);
2176 blob_id = ROBOT_SMART_HOMING_ID;
2179 // -- //determine what kind of blob to drop
2180 // -- // Note: parent_type is not the type of the weapon's parent. It is actually the type of the weapon's
2181 // -- // earliest ancestor. This deals with the issue of weapons spewing weapons which spew weapons.
2182 // -- switch (parent_type) {
2183 // -- case OBJ_WEAPON:
2184 // -- Int3(); // Should this ever happen?
2185 // -- switch (objp->id) {
2186 // -- case SUPERPROX_ID: blob_id = SMART_MINE_HOMING_ID; break;
2187 // -- case ROBOT_SUPERPROX_ID: blob_id = ROBOT_SMART_MINE_HOMING_ID; break;
2188 // -- case EARTHSHAKER_ID: blob_id = EARTHSHAKER_MEGA_ID; break;
2189 // -- default: Int3(); //bogus id for weapon
2192 // -- case OBJ_PLAYER:
2193 // -- switch (objp->id) {
2194 // -- case SUPERPROX_ID: blob_id = SMART_MINE_HOMING_ID; break;
2195 // -- case ROBOT_SUPERPROX_ID: Int3(); break;
2196 // -- case EARTHSHAKER_ID: blob_id = EARTHSHAKER_MEGA_ID; break;
2197 // -- case SMART_ID: blob_id = PLAYER_SMART_HOMING_ID; break;
2198 // -- default: Int3(); //bogus id for weapon
2201 // -- case OBJ_ROBOT:
2202 // -- switch (objp->id) {
2203 // -- case ROBOT_SUPERPROX_ID: blob_id = ROBOT_SMART_MINE_HOMING_ID; break;
2204 // -- // -- case EARTHSHAKER_ID: blob_id = EARTHSHAKER_MEGA_ID; break;
2205 // -- case SMART_ID: blob_id = ROBOT_SMART_HOMING_ID; break;
2206 // -- default: blob_id = ROBOT_SMART_HOMING_ID; break;
2209 // -- default: Int3(); //bogus type for parent object
2213 for (i=0; i<num_smart_children; i++) {
2215 objnum = (numobjs==0)?-1:objlist[(d_rand() * numobjs) >> 15];
2216 create_homing_missile(objp, objnum, blob_id, make_sound);
2222 int Missile_gun = 0;
2224 //give up control of the guided missile
2225 void release_guided_missile(int player_num)
2227 if (player_num == Player_num)
2229 if (Guided_missile[player_num]==NULL)
2232 Missile_viewer = Guided_missile[player_num];
2234 if (Game_mode & GM_MULTI)
2235 multi_send_guided_info (Guided_missile[Player_num],1);
2237 if (Newdemo_state==ND_STATE_RECORDING)
2238 newdemo_record_guided_end();
2241 Guided_missile[player_num] = NULL;
2244 int Proximity_dropped=0,Smartmines_dropped=0;
2246 // -------------------------------------------------------------------------------------------
2247 //parameter determines whether or not to do autoselect if have run out of ammo
2248 //this is needed because if you drop a bomb with the B key, you don't want
2249 //want to autoselect if the bomb isn't actually selected.
2250 void do_missile_firing(int do_autoselect)
2254 Assert(Secondary_weapon < MAX_SECONDARY_WEAPONS);
2256 if (Guided_missile[Player_num] && Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num]) {
2257 release_guided_missile(Player_num);
2258 Next_missile_fire_time = GameTime + Weapon_info[Secondary_weapon_to_weapon_info[Secondary_weapon]].fire_wait;
2262 if (!Player_is_dead && (Players[Player_num].secondary_ammo[Secondary_weapon] > 0)) {
2264 int weapon_id,weapon_gun;
2266 Players[Player_num].secondary_ammo[Secondary_weapon]--;
2268 weapon_id = Secondary_weapon_to_weapon_info[Secondary_weapon];
2270 if (Laser_rapid_fire!=0xBADA55)
2271 Next_missile_fire_time = GameTime + Weapon_info[weapon_id].fire_wait;
2273 Next_missile_fire_time = GameTime + F1_0/25;
2275 weapon_gun = Secondary_weapon_to_gun_num[Secondary_weapon];
2277 if (weapon_gun==4) { //alternate left/right
2278 weapon_gun += (gun_flag = (Missile_gun & 1));
2282 Laser_player_fire( ConsoleObject, weapon_id, weapon_gun, 1, 0);
2284 if (Secondary_weapon == PROXIMITY_INDEX) {
2285 if (++Proximity_dropped == 4) {
2286 Proximity_dropped = 0;
2288 maybe_drop_net_powerup(POW_PROXIMITY_WEAPON);
2292 else if (Secondary_weapon == SMART_MINE_INDEX) {
2293 if (++Smartmines_dropped == 4) {
2294 Smartmines_dropped = 0;
2296 maybe_drop_net_powerup(POW_SMART_MINE);
2301 else if (Secondary_weapon != CONCUSSION_INDEX)
2302 maybe_drop_net_powerup(Secondary_weapon_to_powerup[Secondary_weapon]);
2305 if (Secondary_weapon == MEGA_INDEX || Secondary_weapon == SMISSILE5_INDEX) {
2306 vms_vector force_vec;
2308 force_vec.x = -(ConsoleObject->orient.fvec.x << 7);
2309 force_vec.y = -(ConsoleObject->orient.fvec.y << 7);
2310 force_vec.z = -(ConsoleObject->orient.fvec.z << 7);
2311 phys_apply_force(ConsoleObject, &force_vec);
2313 force_vec.x = (force_vec.x >> 4) + d_rand() - 16384;
2314 force_vec.y = (force_vec.y >> 4) + d_rand() - 16384;
2315 force_vec.z = (force_vec.z >> 4) + d_rand() - 16384;
2316 phys_apply_rot(ConsoleObject, &force_vec);
2320 if (Game_mode & GM_MULTI)
2322 Network_laser_fired = 1; //how many
2323 Network_laser_gun = Secondary_weapon + MISSILE_ADJUST;
2324 Network_laser_flags = gun_flag;
2325 Network_laser_level = 0;
2330 auto_select_weapon(1); //select next missile, if this one out of ammo