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 static char rcsid[] = "$Id: weapon.c,v 1.3 2002-07-26 09:22:05 btb Exp $";
47 int POrderList (int num);
48 int SOrderList (int num);
49 // Note, only Vulcan cannon requires ammo.
50 // NOTE: Now Vulcan and Gauss require ammo. -5/3/95 Yuan
51 //ubyte Default_primary_ammo_level[MAX_PRIMARY_WEAPONS] = {255, 0, 255, 255, 255};
52 //ubyte Default_secondary_ammo_level[MAX_SECONDARY_WEAPONS] = {3, 0, 0, 0, 0};
54 // Convert primary weapons to indices in Weapon_info array.
55 ubyte Primary_weapon_to_weapon_info[MAX_PRIMARY_WEAPONS] = {LASER_ID, VULCAN_ID, SPREADFIRE_ID, PLASMA_ID, FUSION_ID, SUPER_LASER_ID, GAUSS_ID, HELIX_ID, PHOENIX_ID, OMEGA_ID};
56 ubyte Secondary_weapon_to_weapon_info[MAX_SECONDARY_WEAPONS] = {CONCUSSION_ID, HOMING_ID, PROXIMITY_ID, SMART_ID, MEGA_ID, FLASH_ID, GUIDEDMISS_ID, SUPERPROX_ID, MERCURY_ID, EARTHSHAKER_ID};
58 //for each Secondary weapon, which gun it fires out of
59 ubyte Secondary_weapon_to_gun_num[MAX_SECONDARY_WEAPONS] = {4,4,7,7,7,4,4,7,4,7};
61 int Primary_ammo_max[MAX_PRIMARY_WEAPONS] = {0, VULCAN_AMMO_MAX, 0, 0, 0, 0, VULCAN_AMMO_MAX, 0, 0, 0};
62 ubyte Secondary_ammo_max[MAX_SECONDARY_WEAPONS] = {20, 10, 10, 5, 5, 20, 20, 15, 10, 10};
64 //for each primary weapon, what kind of powerup gives weapon
65 ubyte Primary_weapon_to_powerup[MAX_PRIMARY_WEAPONS] = {POW_LASER,POW_VULCAN_WEAPON,POW_SPREADFIRE_WEAPON,POW_PLASMA_WEAPON,POW_FUSION_WEAPON,POW_LASER,POW_GAUSS_WEAPON,POW_HELIX_WEAPON,POW_PHOENIX_WEAPON,POW_OMEGA_WEAPON};
67 //for each Secondary weapon, what kind of powerup gives weapon
68 ubyte Secondary_weapon_to_powerup[MAX_SECONDARY_WEAPONS] = {POW_MISSILE_1,POW_HOMING_AMMO_1,POW_PROXIMITY_WEAPON,POW_SMARTBOMB_WEAPON,POW_MEGA_WEAPON,POW_SMISSILE1_1,POW_GUIDED_MISSILE_1,POW_SMART_MINE,POW_MERCURY_MISSILE_1,POW_EARTHSHAKER_MISSILE};
70 weapon_info Weapon_info[MAX_WEAPON_TYPES];
72 byte Primary_weapon, Secondary_weapon;
74 // autoselect ordering
76 ubyte PrimaryOrder[]={9,8,7,6,5,4,3,2,1,0,255};
77 ubyte SecondaryOrder[]={9,8,4,3,1,5,0,255,7,6,2};
79 ubyte DefaultPrimaryOrder[]={9,8,7,6,5,4,3,2,1,0,255};
80 ubyte DefaultSecondaryOrder[]={9,8,4,3,1,5,0,255,7,6,2};
82 // Cycling weapon key pressed?
86 //allow player to reorder menus?
87 extern ubyte MenuReordering;
89 //char *Primary_weapon_names[MAX_PRIMARY_WEAPONS] = {
92 // "Spreadfire Cannon",
97 //char *Secondary_weapon_names[MAX_SECONDARY_WEAPONS] = {
98 // "Concussion Missile",
105 //char *Primary_weapon_names_short[MAX_PRIMARY_WEAPONS] = {
113 //char *Secondary_weapon_names_short[MAX_SECONDARY_WEAPONS] = {
114 // "Concsn\nMissile",
115 // "Homing\nMissile",
121 byte Weapon_is_energy[MAX_WEAPON_TYPES] = {
132 // ; (0) Laser Level 1
133 // ; (1) Laser Level 2
134 // ; (2) Laser Level 3
135 // ; (3) Laser Level 4
140 // ; (8) ---------- Concussion Missile ----------
141 // ; (9) ---------- Flare ----------
142 // ; (10) ---------- Blue laser that blue guy shoots -----------
143 // ; (11) ---------- Vulcan Cannon ----------
144 // ; (12) ---------- Spreadfire Cannon ----------
145 // ; (13) ---------- Plasma Cannon ----------
146 // ; (14) ---------- Fusion Cannon ----------
147 // ; (15) ---------- Homing Missile ----------
148 // ; (16) ---------- Proximity Bomb ----------
149 // ; (17) ---------- Smart Missile ----------
150 // ; (18) ---------- Mega Missile ----------
151 // ; (19) ---------- Children of the PLAYER'S Smart Missile ----------
152 // ; (20) ---------- Bad Guy Spreadfire Laser ----------
153 // ; (21) ---------- SuperMech Homing Missile ----------
154 // ; (22) ---------- Regular Mech's missile -----------
155 // ; (23) ---------- Silent Spreadfire Laser ----------
156 // ; (24) ---------- Red laser that baby spiders shoot -----------
157 // ; (25) ---------- Green laser that rifleman shoots -----------
158 // ; (26) ---------- Plasma gun that 'plasguy' fires ------------
159 // ; (27) ---------- Blobs fired by Red Spiders -----------
160 // ; (28) ---------- Final Boss's Mega Missile ----------
161 // ; (29) ---------- Children of the ROBOT'S Smart Missile ----------
162 // ; (30) Laser Level 5
163 // ; (31) Laser Level 6
164 // ; (32) ---------- Super Vulcan Cannon ----------
165 // ; (33) ---------- Super Spreadfire Cannon ----------
166 // ; (34) ---------- Super Plasma Cannon ----------
167 // ; (35) ---------- Super Fusion Cannon ----------
169 // ------------------------------------------------------------------------------------
175 // See weapon.h for bit values
176 int player_has_weapon(int weapon_num, int secondary_flag)
178 int return_value = 0;
181 // Hack! If energy goes negative, you can't fire a weapon that doesn't require energy.
182 // But energy should not go negative (but it does), so find out why it does!
183 if (Players[Player_num].energy < 0)
184 Players[Player_num].energy = 0;
186 if (!secondary_flag) {
187 weapon_index = Primary_weapon_to_weapon_info[weapon_num];
189 if (Players[Player_num].primary_weapon_flags & (1 << weapon_num))
190 return_value |= HAS_WEAPON_FLAG;
192 // Special case: Gauss cannon uses vulcan ammo.
193 if (weapon_num == GAUSS_INDEX) {
194 if (Weapon_info[weapon_index].ammo_usage <= Players[Player_num].primary_ammo[VULCAN_INDEX])
195 return_value |= HAS_AMMO_FLAG;
197 if (Weapon_info[weapon_index].ammo_usage <= Players[Player_num].primary_ammo[weapon_num])
198 return_value |= HAS_AMMO_FLAG;
200 if (weapon_num == OMEGA_INDEX) { // Hack: Make sure player has energy to omega
201 if (Players[Player_num].energy || Omega_charge)
202 return_value |= HAS_ENERGY_FLAG;
204 if (Weapon_info[weapon_index].energy_usage <= Players[Player_num].energy)
205 return_value |= HAS_ENERGY_FLAG;
208 weapon_index = Secondary_weapon_to_weapon_info[weapon_num];
210 if (Players[Player_num].secondary_weapon_flags & (1 << weapon_num))
211 return_value |= HAS_WEAPON_FLAG;
213 if (Weapon_info[weapon_index].ammo_usage <= Players[Player_num].secondary_ammo[weapon_num])
214 return_value |= HAS_AMMO_FLAG;
216 if (Weapon_info[weapon_index].energy_usage <= Players[Player_num].energy)
217 return_value |= HAS_ENERGY_FLAG;
223 void InitWeaponOrdering ()
225 // short routine to setup default weapon priorities for new pilots
229 for (i=0;i<MAX_PRIMARY_WEAPONS+1;i++)
230 PrimaryOrder[i]=DefaultPrimaryOrder[i];
231 for (i=0;i<MAX_SECONDARY_WEAPONS+1;i++)
232 SecondaryOrder[i]=DefaultSecondaryOrder[i];
237 mprintf ((0,"Cycling primary!\n"));
239 auto_select_weapon (0);
243 void CycleSecondary ()
245 mprintf ((0,"Cycling secondary!\n"));
247 auto_select_weapon (1);
252 // ------------------------------------------------------------------------------------
253 //if message flag set, print message saying selected
254 void select_weapon(int weapon_num, int secondary_flag, int print_message, int wait_for_rearm)
258 if (Newdemo_state==ND_STATE_RECORDING )
259 newdemo_record_player_weapon(secondary_flag, weapon_num);
261 if (!secondary_flag) {
262 if (Primary_weapon != weapon_num) {
263 if (wait_for_rearm) digi_play_sample_once( SOUND_GOOD_SELECTION_PRIMARY, F1_0 );
265 if (Game_mode & GM_MULTI) {
266 if (wait_for_rearm) multi_send_play_sound(SOUND_GOOD_SELECTION_PRIMARY, F1_0);
270 Next_laser_fire_time = GameTime + REARM_TIME;
272 Next_laser_fire_time = 0;
273 Global_laser_firing_count = 0;
275 // Select super version if available.
279 ; // -- MK, only plays when can't fire weapon anyway, fixes bug -- digi_play_sample_once( SOUND_ALREADY_SELECTED, F1_0 );
281 digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
284 Primary_weapon = weapon_num;
285 weapon_name = PRIMARY_WEAPON_NAMES(weapon_num);
286 #if defined (TACTILE)
287 tactile_set_button_jolt();
291 //save flag for whether was super version
292 Primary_last_was_super[weapon_num % SUPER_WEAPON] = (weapon_num >= SUPER_WEAPON);
296 if (Secondary_weapon != weapon_num) {
297 if (wait_for_rearm) digi_play_sample_once( SOUND_GOOD_SELECTION_SECONDARY, F1_0 );
299 if (Game_mode & GM_MULTI) {
300 if (wait_for_rearm) multi_send_play_sound(SOUND_GOOD_SELECTION_PRIMARY, F1_0);
304 Next_missile_fire_time = GameTime + REARM_TIME;
306 Next_missile_fire_time = 0;
307 Global_missile_firing_count = 0;
312 digi_play_sample_once( SOUND_ALREADY_SELECTED, F1_0 );
314 digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
318 Secondary_weapon = weapon_num;
319 weapon_name = SECONDARY_WEAPON_NAMES(weapon_num);
321 //save flag for whether was super version
322 Secondary_last_was_super[weapon_num % SUPER_WEAPON] = (weapon_num >= SUPER_WEAPON);
327 if (weapon_num == LASER_INDEX && !secondary_flag)
328 HUD_init_message("%s Level %d %s", weapon_name, Players[Player_num].laser_level+1, TXT_SELECTED);
330 HUD_init_message("%s %s", weapon_name, TXT_SELECTED);
335 //flags whether the last time we use this weapon, it was the 'super' version
336 ubyte Primary_last_was_super[MAX_PRIMARY_WEAPONS];
337 ubyte Secondary_last_was_super[MAX_SECONDARY_WEAPONS];
339 // ------------------------------------------------------------------------------------
340 // Select a weapon, primary or secondary.
341 void do_weapon_select(int weapon_num, int secondary_flag)
343 int weapon_num_save=weapon_num;
344 int weapon_status,current,has_flag;
345 ubyte last_was_super;
347 if (!secondary_flag) {
348 current = Primary_weapon;
349 last_was_super = Primary_last_was_super[weapon_num];
350 has_flag = HAS_WEAPON_FLAG;
353 current = Secondary_weapon;
354 last_was_super = Secondary_last_was_super[weapon_num];
355 has_flag = HAS_WEAPON_FLAG+HAS_AMMO_FLAG;
358 if (current == weapon_num || current == weapon_num+SUPER_WEAPON) {
360 //already have this selected, so toggle to other of normal/super version
362 weapon_num += weapon_num+SUPER_WEAPON - current;
363 weapon_status = player_has_weapon(weapon_num, secondary_flag);
367 //go to last-select version of requested missile
370 weapon_num += SUPER_WEAPON;
372 weapon_status = player_has_weapon(weapon_num, secondary_flag);
374 //if don't have last-selected, try other version
376 if ((weapon_status & has_flag) != has_flag) {
377 weapon_num = 2*weapon_num_save+SUPER_WEAPON - weapon_num;
378 weapon_status = player_has_weapon(weapon_num, secondary_flag);
379 if ((weapon_status & has_flag) != has_flag)
380 weapon_num = 2*weapon_num_save+SUPER_WEAPON - weapon_num;
384 //if we don't have the weapon we're switching to, give error & bail
385 if ((weapon_status & has_flag) != has_flag) {
386 if (!secondary_flag) {
387 if (weapon_num==SUPER_LASER_INDEX)
388 return; //no such thing as super laser, so no error
389 HUD_init_message("%s %s!", TXT_DONT_HAVE, PRIMARY_WEAPON_NAMES(weapon_num));
392 HUD_init_message("%s %s%s",TXT_HAVE_NO, SECONDARY_WEAPON_NAMES(weapon_num), TXT_SX);
393 digi_play_sample( SOUND_BAD_SELECTION, F1_0 );
397 //now actually select the weapon
398 select_weapon(weapon_num, secondary_flag, 1, 1);
401 // ----------------------------------------------------------------------------------------
402 // Automatically select next best weapon if unable to fire current weapon.
403 // Weapon type: 0==primary, 1==secondary
404 void auto_select_weapon(int weapon_type)
410 if (weapon_type==0) {
411 r = player_has_weapon(Primary_weapon, 0);
412 if (r != HAS_ALL || Cycling) {
416 cur_weapon = POrderList(Primary_weapon);
417 cutpoint = POrderList (255);
422 if (cur_weapon>=cutpoint)
428 HUD_init_message(TXT_NO_PRIMARY);
431 ButtonReflexClear(0);
433 select_weapon(0, 0, 0, 1);
436 select_weapon (Primary_weapon,0,0,1);
446 if (cur_weapon==MAX_PRIMARY_WEAPONS)
449 // Hack alert! Because the fusion uses 0 energy at the end (it's got the weird chargeup)
450 // it looks like it takes 0 to fire, but it doesn't, so never auto-select.
451 // if (PrimaryOrder[cur_weapon] == FUSION_INDEX)
454 if (PrimaryOrder[cur_weapon] == Primary_weapon) {
457 HUD_init_message(TXT_NO_PRIMARY);
460 ButtonReflexClear(0);
463 // if (POrderList(0)<POrderList(255))
464 select_weapon(0, 0, 0, 1);
467 select_weapon (Primary_weapon,0,0,1);
469 try_again = 0; // Tried all weapons!
471 } else if (PrimaryOrder[cur_weapon]!=255 && player_has_weapon(PrimaryOrder[cur_weapon], 0) == HAS_ALL) {
472 select_weapon(PrimaryOrder[cur_weapon], 0, 1, 1 );
480 Assert(weapon_type==1);
481 r = player_has_weapon(Secondary_weapon, 1);
482 if (r != HAS_ALL || Cycling) {
486 cur_weapon = SOrderList(Secondary_weapon);
487 cutpoint = SOrderList (255);
493 if (cur_weapon>=cutpoint)
498 HUD_init_message("No secondary weapons selected!");
500 select_weapon (Secondary_weapon,1,0,1);
508 if (cur_weapon==MAX_SECONDARY_WEAPONS)
511 if (SecondaryOrder[cur_weapon] == Secondary_weapon) {
513 HUD_init_message("No secondary weapons available!");
515 select_weapon (Secondary_weapon,1,0,1);
517 try_again = 0; // Tried all weapons!
518 } else if (player_has_weapon(SecondaryOrder[cur_weapon], 1) == HAS_ALL) {
519 select_weapon(SecondaryOrder[cur_weapon], 1, 1, 1 );
532 // ----------------------------------------------------------------------------------------
533 // Show player which weapons he has, how much ammo...
534 // Looks like a debug screen now because it writes to mono screen, but that will change...
535 void show_weapon_status(void)
539 for (i=0; i<MAX_PRIMARY_WEAPONS; i++) {
540 if (Players[Player_num].primary_weapon_flags & (1 << i))
541 mprintf((0, "HAVE"));
545 mprintf((0, " Weapon: %20s, charges: %4i\n", PRIMARY_WEAPON_NAMES(i), Players[Player_num].primary_ammo[i]));
549 for (i=0; i<MAX_SECONDARY_WEAPONS; i++) {
550 if (Players[Player_num].secondary_weapon_flags & (1 << i))
551 mprintf((0, "HAVE"));
555 mprintf((0, " Weapon: %20s, charges: %4i\n", SECONDARY_WEAPON_NAMES(i), Players[Player_num].secondary_ammo[i]));
565 // ---------------------------------------------------------------------
566 //called when one of these weapons is picked up
567 //when you pick up a secondary, you always get the weapon & ammo for it
568 // Returns true if powerup picked up, else returns false.
569 int pick_up_secondary(int weapon_index,int count)
575 max = Secondary_ammo_max[weapon_index];
577 if (Players[Player_num].flags & PLAYER_FLAGS_AMMO_RACK)
580 if (Players[Player_num].secondary_ammo[weapon_index] >= max) {
581 HUD_init_message("%s %i %ss!", TXT_ALREADY_HAVE, Players[Player_num].secondary_ammo[weapon_index],SECONDARY_WEAPON_NAMES(weapon_index));
585 Players[Player_num].secondary_weapon_flags |= (1<<weapon_index);
586 Players[Player_num].secondary_ammo[weapon_index] += count;
588 num_picked_up = count;
589 if (Players[Player_num].secondary_ammo[weapon_index] > max) {
590 num_picked_up = count - (Players[Player_num].secondary_ammo[weapon_index] - max);
591 Players[Player_num].secondary_ammo[weapon_index] = max;
594 cutpoint=SOrderList (255);
595 if (SOrderList (weapon_index)<cutpoint && ((SOrderList (weapon_index) < SOrderList(Secondary_weapon)) || (Players[Player_num].secondary_ammo[Secondary_weapon] == 0)) )
596 select_weapon(weapon_index,1, 0, 1);
598 //if we don't auto-select this weapon, but it's a proxbomb or smart mine,
599 //we want to do a mini-auto-selection that applies to the drop bomb key
601 if ((weapon_index == PROXIMITY_INDEX || weapon_index == SMART_MINE_INDEX) &&
602 !(Secondary_weapon == PROXIMITY_INDEX || Secondary_weapon == SMART_MINE_INDEX)) {
605 cur = Secondary_last_was_super[PROXIMITY_INDEX]?SMART_MINE_INDEX:PROXIMITY_INDEX;
607 if (SOrderList (weapon_index) < SOrderList(cur))
608 Secondary_last_was_super[PROXIMITY_INDEX] = (weapon_index == SMART_MINE_INDEX);
612 //note: flash for all but concussion was 7,14,21
614 PALETTE_FLASH_ADD(15,15,15);
615 HUD_init_message("%d %s%s",num_picked_up,SECONDARY_WEAPON_NAMES(weapon_index), TXT_SX);
618 PALETTE_FLASH_ADD(10,10,10);
619 HUD_init_message("%s!",SECONDARY_WEAPON_NAMES(weapon_index));
625 void ReorderPrimary ()
627 newmenu_item m[MAX_PRIMARY_WEAPONS+1];
630 for (i=0;i<MAX_PRIMARY_WEAPONS+1;i++)
632 m[i].type=NM_TYPE_MENU;
633 if (PrimaryOrder[i]==255)
634 m[i].text="
\88\88\88\88\88\88\88 Never autoselect
\88\88\88\88\88\88\88";
636 m[i].text=(char *)PRIMARY_WEAPON_NAMES(PrimaryOrder[i]);
637 m[i].value=PrimaryOrder[i];
640 i = newmenu_do("Reorder Primary","Shift+Up/Down arrow to move item", i, m, NULL);
643 for (i=0;i<MAX_PRIMARY_WEAPONS+1;i++)
644 PrimaryOrder[i]=m[i].value;
647 void ReorderSecondary ()
649 newmenu_item m[MAX_SECONDARY_WEAPONS+1];
652 for (i=0;i<MAX_SECONDARY_WEAPONS+1;i++)
654 m[i].type=NM_TYPE_MENU;
655 if (SecondaryOrder[i]==255)
656 m[i].text="
\88\88\88\88\88\88\88 Never autoselect
\88\88\88\88\88\88\88";
658 m[i].text=(char *)SECONDARY_WEAPON_NAMES(SecondaryOrder[i]);
659 m[i].value=SecondaryOrder[i];
662 i = newmenu_do("Reorder Secondary","Shift+Up/Down arrow to move item", i, m, NULL);
664 for (i=0;i<MAX_SECONDARY_WEAPONS+1;i++)
665 SecondaryOrder[i]=m[i].value;
668 int POrderList (int num)
672 for (i=0;i<MAX_PRIMARY_WEAPONS+1;i++)
673 if (PrimaryOrder[i]==num)
675 mprintf ((0,"Primary %d has priority of %d!\n",num,i));
678 Error ("Primary Weapon is not in order list!!!");
681 int SOrderList (int num)
685 for (i=0;i<MAX_SECONDARY_WEAPONS+1;i++)
686 if (SecondaryOrder[i]==num)
688 mprintf ((0,"Secondary %d has priority of %d!\n",num,i));
691 mprintf ((0,"Error! Secondary Num=%d\n",num));
692 Error ("Secondary Weapon is not in order list!!!");
696 //called when a primary weapon is picked up
697 //returns true if actually picked up
698 int pick_up_primary(int weapon_index)
700 //ushort old_flags = Players[Player_num].primary_weapon_flags;
701 ushort flag = 1<<weapon_index;
703 int supposed_weapon=Primary_weapon;
705 if (weapon_index!=LASER_INDEX && Players[Player_num].primary_weapon_flags & flag) { //already have
706 HUD_init_message("%s %s!", TXT_ALREADY_HAVE_THE, PRIMARY_WEAPON_NAMES(weapon_index));
710 Players[Player_num].primary_weapon_flags |= flag;
712 cutpoint=POrderList (255);
714 if (Primary_weapon==LASER_INDEX && Players[Player_num].laser_level>=4)
715 supposed_weapon=SUPER_LASER_INDEX; // allotment for stupid way of doing super laser
718 if (POrderList(weapon_index)<cutpoint && POrderList(weapon_index)<POrderList(supposed_weapon))
719 select_weapon(weapon_index,0,0,1);
721 PALETTE_FLASH_ADD(7,14,21);
722 mprintf ((0,"Weapon index: %d\n",weapon_index));
724 if (weapon_index!=LASER_INDEX)
725 HUD_init_message("%s!",PRIMARY_WEAPON_NAMES(weapon_index));
729 int check_to_use_primary(int weapon_index)
731 ushort old_flags = Players[Player_num].primary_weapon_flags;
732 ushort flag = 1<<weapon_index;
735 cutpoint=POrderList (255);
737 if (!(old_flags & flag) && POrderList(weapon_index)<cutpoint && POrderList(weapon_index)<POrderList(Primary_weapon))
739 if (weapon_index==SUPER_LASER_INDEX)
740 select_weapon(LASER_INDEX,0,0,1);
742 select_weapon(weapon_index,0,0,1);
745 PALETTE_FLASH_ADD(7,14,21);
752 //called when ammo (for the vulcan cannon) is picked up
753 // Returns the amount picked up
754 int pick_up_ammo(int class_flag,int weapon_index,int ammo_count)
756 int max,cutpoint,supposed_weapon=Primary_weapon;
757 int old_ammo=class_flag; //kill warning
759 Assert(class_flag==CLASS_PRIMARY && weapon_index==VULCAN_INDEX);
761 max = Primary_ammo_max[weapon_index];
762 if (Players[Player_num].flags & PLAYER_FLAGS_AMMO_RACK)
765 if (Players[Player_num].primary_ammo[weapon_index] == max)
768 old_ammo = Players[Player_num].primary_ammo[weapon_index];
770 Players[Player_num].primary_ammo[weapon_index] += ammo_count;
772 if (Players[Player_num].primary_ammo[weapon_index] > max) {
773 ammo_count += (max - Players[Player_num].primary_ammo[weapon_index]);
774 Players[Player_num].primary_ammo[weapon_index] = max;
776 cutpoint=POrderList (255);
778 if (Primary_weapon==LASER_INDEX && Players[Player_num].laser_level>=4)
779 supposed_weapon=SUPER_LASER_INDEX; // allotment for stupid way of doing super laser
782 if (Players[Player_num].primary_weapon_flags&(1<<weapon_index) && weapon_index>Primary_weapon && old_ammo==0 &&
783 POrderList(weapon_index)<cutpoint && POrderList(weapon_index)<POrderList(supposed_weapon))
784 select_weapon(weapon_index,0,0,1);
786 return ammo_count; //return amount used
789 #define SMEGA_SHAKE_TIME (F1_0*2)
790 #define MAX_SMEGA_DETONATES 4
791 fix Smega_detonate_times[MAX_SMEGA_DETONATES];
793 // Call this to initialize for a new level.
794 // Sets all super mega missile detonation times to 0 which means there aren't any.
795 void init_smega_detonates(void)
799 for (i=0; i<MAX_SMEGA_DETONATES; i++)
800 Smega_detonate_times[i] = 0;
803 fix Seismic_tremor_magnitude;
804 fix Next_seismic_sound_time;
805 int Seismic_sound_playing = 0;
806 int Seismic_tremor_volume;
808 int Seismic_sound = SOUND_SEISMIC_DISTURBANCE_START;
810 // If a smega missile been detonated, rock the mine!
811 // This should be called every frame.
812 // Maybe this should affect all robots, being called when they get their physics done.
813 void rock_the_mine_frame(void)
817 for (i=0; i<MAX_SMEGA_DETONATES; i++) {
819 if (Smega_detonate_times[i] != 0) {
821 delta_time = GameTime - Smega_detonate_times[i];
823 if (!Seismic_sound_playing) {
824 digi_play_sample_looping(Seismic_sound, F1_0, -1, -1);
825 Seismic_sound_playing = 1;
826 Next_seismic_sound_time = GameTime + d_rand()/2;
829 if (delta_time < SMEGA_SHAKE_TIME) {
831 // Control center destroyed, rock the player's ship.
833 // -- fc = abs(delta_time - SMEGA_SHAKE_TIME/2);
834 // Changed 10/23/95 to make decreasing for super mega missile.
835 fc = (SMEGA_SHAKE_TIME - delta_time)/2;
836 fc /= SMEGA_SHAKE_TIME/32;
843 Seismic_tremor_volume += fc;
845 rx = fixmul(d_rand() - 16384, 3*F1_0/16 + (F1_0*(16-fc))/32);
846 rz = fixmul(d_rand() - 16384, 3*F1_0/16 + (F1_0*(16-fc))/32);
848 ConsoleObject->mtype.phys_info.rotvel.x += rx;
849 ConsoleObject->mtype.phys_info.rotvel.z += rz;
852 if (Buddy_objnum != -1) {
853 Objects[Buddy_objnum].mtype.phys_info.rotvel.x += rx*4;
854 Objects[Buddy_objnum].mtype.phys_info.rotvel.z += rz*4;
857 // Shake a guided missile!
858 Seismic_tremor_magnitude += rx;
861 Smega_detonate_times[i] = 0;
866 // Hook in the rumble sound effect here.
869 extern int Level_shake_frequency, Level_shake_duration;
871 extern void multi_send_seismic (fix,fix);
874 #define SEISMIC_DISTURBANCE_DURATION (F1_0*5)
875 fix Seismic_disturbance_start_time = 0, Seismic_disturbance_end_time;
879 int on_seismic_level(void)
881 return Seismic_level;
884 void init_seismic_disturbances(void)
886 Seismic_disturbance_start_time = 0;
887 Seismic_disturbance_end_time = 0;
890 // Return true if time to start a seismic disturbance.
891 int start_seismic_disturbance(void)
895 if (Level_shake_duration < 1)
898 rval = (2 * fixmul(d_rand(), Level_shake_frequency)) < FrameTime;
901 Seismic_disturbance_start_time = GameTime;
902 Seismic_disturbance_end_time = GameTime + Level_shake_duration;
903 if (!Seismic_sound_playing) {
904 digi_play_sample_looping(Seismic_sound, F1_0, -1, -1);
905 Seismic_sound_playing = 1;
906 Next_seismic_sound_time = GameTime + d_rand()/2;
910 if (Game_mode & GM_MULTI)
911 multi_send_seismic (Seismic_disturbance_start_time,Seismic_disturbance_end_time);
918 void seismic_disturbance_frame(void)
920 if (Level_shake_frequency) {
921 if (((Seismic_disturbance_start_time < GameTime) && (Seismic_disturbance_end_time > GameTime)) || start_seismic_disturbance()) {
925 delta_time = GameTime - Seismic_disturbance_start_time;
927 fc = abs(delta_time - (Seismic_disturbance_end_time - Seismic_disturbance_start_time)/2);
935 Seismic_tremor_volume += fc;
937 rx = fixmul(d_rand() - 16384, 3*F1_0/16 + (F1_0*(16-fc))/32);
938 rz = fixmul(d_rand() - 16384, 3*F1_0/16 + (F1_0*(16-fc))/32);
940 ConsoleObject->mtype.phys_info.rotvel.x += rx;
941 ConsoleObject->mtype.phys_info.rotvel.z += rz;
944 if (Buddy_objnum != -1) {
945 Objects[Buddy_objnum].mtype.phys_info.rotvel.x += rx*4;
946 Objects[Buddy_objnum].mtype.phys_info.rotvel.z += rz*4;
949 // Shake a guided missile!
950 Seismic_tremor_magnitude += rx;
956 // Call this when a smega detonates to start the process of rocking the mine.
957 void smega_rock_stuff(void)
961 for (i=0; i<MAX_SMEGA_DETONATES; i++) {
962 if (Smega_detonate_times[i] + SMEGA_SHAKE_TIME < GameTime)
963 Smega_detonate_times[i] = 0;
966 for (i=0; i<MAX_SMEGA_DETONATES; i++) {
967 if (Smega_detonate_times[i] == 0) {
968 Smega_detonate_times[i] = GameTime;
974 int Super_mines_yes = 1;
976 // Call this once/frame to process all super mines in the level.
977 void process_super_mines_frame(void)
982 // If we don't know of there being any super mines in the level, just
983 // check every 8th object each frame.
984 if (Super_mines_yes == 0) {
985 start = FrameCount & 7;
994 for (i=start; i<=Highest_object_index; i+=add) {
995 if ((Objects[i].type == OBJ_WEAPON) && (Objects[i].id == SUPERPROX_ID)) {
998 parent_num = Objects[i].ctype.laser_info.parent_num;
1000 Super_mines_yes = 1;
1001 if (Objects[i].lifeleft + F1_0*2 < Weapon_info[SUPERPROX_ID].lifetime) {
1002 vms_vector *bombpos;
1004 bombpos = &Objects[i].pos;
1006 for (j=0; j<=Highest_object_index; j++) {
1007 if ((Objects[j].type == OBJ_PLAYER) || (Objects[j].type == OBJ_ROBOT)) {
1010 dist = vm_vec_dist_quick(bombpos, &Objects[j].pos);
1012 if (j != parent_num)
1013 if (dist - Objects[j].size < F1_0*20)
1015 if (Objects[i].segnum == Objects[j].segnum)
1016 Objects[i].lifeleft = 1;
1018 // Object which is close enough to detonate smart mine is not in same segment as smart mine.
1019 // Need to do a more expensive check to make sure there isn't an obstruction.
1020 if (((FrameCount ^ (i+j)) % 4) == 0) {
1025 mprintf((0, "Expensive proxmine collision check. Frame %i\n", FrameCount));
1027 fq.startseg = Objects[i].segnum;
1028 fq.p0 = &Objects[i].pos;
1029 fq.p1 = &Objects[j].pos;
1032 fq.ignore_obj_list = NULL;
1035 fate = find_vector_intersection(&fq, &hit_data);
1036 if (fate != HIT_WALL)
1037 Objects[i].lifeleft = 1;
1049 #define SPIT_SPEED 20
1051 //this function is for when the player intentionally drops a powerup
1052 //this function is based on drop_powerup()
1053 int spit_powerup(object *spitter, int id,int seed)
1057 vms_vector new_velocity, new_pos;
1061 vm_vec_scale_add(&new_velocity,&spitter->mtype.phys_info.velocity,&spitter->orient.fvec,i2f(SPIT_SPEED));
1063 new_velocity.x += (d_rand() - 16384) * SPIT_SPEED * 2;
1064 new_velocity.y += (d_rand() - 16384) * SPIT_SPEED * 2;
1065 new_velocity.z += (d_rand() - 16384) * SPIT_SPEED * 2;
1067 // Give keys zero velocity so they can be tracked better in multi
1069 if ((Game_mode & GM_MULTI) && (id >= POW_KEY_BLUE) && (id <= POW_KEY_GOLD))
1070 vm_vec_zero(&new_velocity);
1072 //there's a piece of code which lets the player pick up a powerup if
1073 //the distance between him and the powerup is less than 2 time their
1074 //combined radii. So we need to create powerups pretty far out from
1077 vm_vec_scale_add(&new_pos,&spitter->pos,&spitter->orient.fvec,spitter->size);
1080 if (Game_mode & GM_MULTI)
1082 if (Net_create_loc >= MAX_NET_CREATE_OBJECTS)
1084 mprintf( (0, "WEAPON:Not enough slots to drop all powerups!\n" ));
1090 objnum = obj_create( OBJ_POWERUP, id, spitter->segnum, &new_pos, &vmd_identity_matrix, Powerup_info[id].size, CT_POWERUP, MT_PHYSICS, RT_POWERUP);
1093 mprintf((1, "Can't create object in object_create_egg. Aborting.\n"));
1098 obj = &Objects[objnum];
1100 obj->mtype.phys_info.velocity = new_velocity;
1101 obj->mtype.phys_info.drag = 512; //1024;
1102 obj->mtype.phys_info.mass = F1_0;
1104 obj->mtype.phys_info.flags = PF_BOUNCE;
1106 obj->rtype.vclip_info.vclip_num = Powerup_info[obj->id].vclip_num;
1107 obj->rtype.vclip_info.frametime = Vclip[obj->rtype.vclip_info.vclip_num].frame_time;
1108 obj->rtype.vclip_info.framenum = 0;
1110 if (spitter == ConsoleObject)
1111 obj->ctype.powerup_info.flags |= PF_SPAT_BY_PLAYER;
1116 case POW_SHIELD_BOOST:
1118 obj->lifeleft = (d_rand() + F1_0*3) * 64; // Lives for 3 to 3.5 binary minutes (a binary minute is 64 seconds)
1119 if (Game_mode & GM_MULTI)
1123 //if (Game_mode & GM_MULTI)
1124 // obj->lifeleft = (d_rand() + F1_0*3) * 64; // Lives for 5 to 5.5 binary minutes (a binary minute is 64 seconds)
1131 void DropCurrentWeapon ()
1133 int objnum,ammo=0,seed;
1135 if (Primary_weapon==0)
1137 HUD_init_message("You cannot drop your base weapon!");
1141 HUD_init_message("%s dropped!",PRIMARY_WEAPON_NAMES(Primary_weapon));
1142 digi_play_sample (SOUND_DROP_WEAPON,F1_0);
1146 objnum = spit_powerup(ConsoleObject,Primary_weapon_to_powerup[Primary_weapon],seed);
1151 if (Primary_weapon == VULCAN_INDEX || Primary_weapon == GAUSS_INDEX) {
1153 //if it's one of these, drop some ammo with the weapon
1155 ammo = Players[Player_num].primary_ammo[VULCAN_INDEX];
1157 if ((Players[Player_num].primary_weapon_flags & HAS_FLAG(VULCAN_INDEX)) && (Players[Player_num].primary_weapon_flags & HAS_FLAG(GAUSS_INDEX)))
1158 ammo /= 2; //if both vulcan & gauss, drop half
1160 Players[Player_num].primary_ammo[VULCAN_INDEX] -= ammo;
1163 Objects[objnum].ctype.powerup_info.count = ammo;
1166 if (Primary_weapon == OMEGA_INDEX) {
1168 //dropped weapon has current energy
1171 Objects[objnum].ctype.powerup_info.count = Omega_charge;
1175 if ((Game_mode & GM_MULTI) && objnum>-1)
1176 multi_send_drop_weapon(objnum,seed);
1179 Players[Player_num].primary_weapon_flags &= (~(1<<Primary_weapon));
1180 auto_select_weapon (0);
1184 void DropSecondaryWeapon ()
1188 if (Players[Player_num].secondary_ammo[Secondary_weapon] ==0)
1190 HUD_init_message("No secondary weapon to drop!");
1194 if ((Secondary_weapon_to_powerup[Secondary_weapon]==POW_PROXIMITY_WEAPON ||
1195 Secondary_weapon_to_powerup[Secondary_weapon]==POW_SMART_MINE) &&
1196 Players[Player_num].secondary_ammo[Secondary_weapon]<4)
1198 HUD_init_message("You need at least 4 to drop!");
1202 HUD_init_message("%s dropped!",SECONDARY_WEAPON_NAMES(Secondary_weapon));
1203 digi_play_sample (SOUND_DROP_WEAPON,F1_0);
1207 objnum = spit_powerup(ConsoleObject,Secondary_weapon_to_powerup[Secondary_weapon],seed);
1214 if ((Game_mode & GM_MULTI) && objnum>-1)
1215 multi_send_drop_weapon(objnum,seed);
1218 if (Secondary_weapon_to_powerup[Secondary_weapon]==POW_PROXIMITY_WEAPON ||
1219 Secondary_weapon_to_powerup[Secondary_weapon]==POW_SMART_MINE)
1220 Players[Player_num].secondary_ammo[Secondary_weapon]-=4;
1222 Players[Player_num].secondary_ammo[Secondary_weapon]--;
1224 if (Players[Player_num].secondary_ammo[Secondary_weapon]==0)
1226 Players[Player_num].secondary_weapon_flags &= (~(1<<Secondary_weapon));
1227 auto_select_weapon (1);
1231 // ---------------------------------------------------------------------------------------
1232 // Do seismic disturbance stuff including the looping sounds with changing volume.
1233 void do_seismic_stuff(void)
1237 stv_save = Seismic_tremor_volume;
1238 Seismic_tremor_magnitude = 0;
1239 Seismic_tremor_volume = 0;
1241 rock_the_mine_frame();
1242 seismic_disturbance_frame();
1244 if (stv_save != 0) {
1245 if (Seismic_tremor_volume == 0) {
1246 digi_stop_looping_sound();
1247 Seismic_sound_playing = 0;
1250 if ((GameTime > Next_seismic_sound_time) && Seismic_tremor_volume) {
1253 volume = Seismic_tremor_volume * 2048;
1256 digi_change_looping_volume(volume);
1257 Next_seismic_sound_time = GameTime + d_rand()/4 + 8192;
1263 int tactile_fire_duration[]={120,80,150,250,150,200,100,180,280,100};
1264 int tactile_fire_repeat[]={260,90,160,160,160,210,110,191,291,111};
1266 void tactile_set_button_jolt ()
1272 static int stickmag=-1;
1275 dur=tactile_fire_duration[Primary_weapon];
1276 rep=tactile_fire_repeat[Primary_weapon];
1282 if (t=FindArg("-stickmag"))
1283 stickmag=atoi (Args[t+1]);
1287 infile=(FILE *)fopen ("stick.val","rt");
1292 fscanf (infile,"%d %d\n",&tactile_fire_duration[i],&tactile_fire_repeat[i]);
1293 mprintf ((0,"scan value[%d]=%d\n",i,tactile_fire_duration[i]));
1298 ButtonReflexJolt (0,stickmag,0,dur,rep);
1304 * reads a weapon_info structure from a CFILE
1306 extern void weapon_info_read(weapon_info *wi, CFILE *fp)
1310 wi->render_type = cfile_read_byte(fp);
1311 wi->persistent = cfile_read_byte(fp);
1312 wi->model_num = cfile_read_short(fp);
1313 wi->model_num_inner = cfile_read_short(fp);
1315 wi->flash_vclip = cfile_read_byte(fp);
1316 wi->robot_hit_vclip = cfile_read_byte(fp);
1317 wi->flash_sound = cfile_read_short(fp);
1319 wi->wall_hit_vclip = cfile_read_byte(fp);
1320 wi->fire_count = cfile_read_byte(fp);
1321 wi->robot_hit_sound = cfile_read_short(fp);
1323 wi->ammo_usage = cfile_read_byte(fp);
1324 wi->weapon_vclip = cfile_read_byte(fp);
1325 wi->wall_hit_sound = cfile_read_short(fp);
1327 wi->destroyable = cfile_read_byte(fp);
1328 wi->matter = cfile_read_byte(fp);
1329 wi->bounce = cfile_read_byte(fp);
1330 wi->homing_flag = cfile_read_byte(fp);
1332 wi->speedvar = cfile_read_byte(fp);
1333 wi->flags = cfile_read_byte(fp);
1334 wi->flash = cfile_read_byte(fp);
1335 wi->afterburner_size = cfile_read_byte(fp);
1337 wi->children = cfile_read_byte(fp);
1339 wi->energy_usage = cfile_read_fix(fp);
1340 wi->fire_wait = cfile_read_fix(fp);
1342 wi->multi_damage_scale = cfile_read_fix(fp);
1344 wi->bitmap.index = cfile_read_short(fp); // bitmap_index = short
1346 wi->blob_size = cfile_read_fix(fp);
1347 wi->flash_size = cfile_read_fix(fp);
1348 wi->impact_size = cfile_read_fix(fp);
1349 for (i = 0; i < NDL; i++)
1350 wi->strength[i] = cfile_read_fix(fp);
1351 for (i = 0; i < NDL; i++)
1352 wi->speed[i] = cfile_read_fix(fp);
1353 wi->mass = cfile_read_fix(fp);
1354 wi->drag = cfile_read_fix(fp);
1355 wi->thrust = cfile_read_fix(fp);
1356 wi->po_len_to_width_ratio = cfile_read_fix(fp);
1357 wi->light = cfile_read_fix(fp);
1358 wi->lifetime = cfile_read_fix(fp);
1359 wi->damage_radius = cfile_read_fix(fp);
1360 wi->picture.index = cfile_read_short(fp); // bitmap_index is a short
1361 wi->hires_picture.index = cfile_read_short(fp); // bitmap_index is a short