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.
16 static char rcsid[] = "$Id: weapon.c,v 1.1.1.1 2001-01-19 03:29:59 bradleyb Exp $";
46 int POrderList (int num);
47 int SOrderList (int num);
48 // Note, only Vulcan cannon requires ammo.
49 // NOTE: Now Vulcan and Gauss require ammo. -5/3/95 Yuan
50 //ubyte Default_primary_ammo_level[MAX_PRIMARY_WEAPONS] = {255, 0, 255, 255, 255};
51 //ubyte Default_secondary_ammo_level[MAX_SECONDARY_WEAPONS] = {3, 0, 0, 0, 0};
53 // Convert primary weapons to indices in Weapon_info array.
54 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};
55 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};
57 //for each Secondary weapon, which gun it fires out of
58 ubyte Secondary_weapon_to_gun_num[MAX_SECONDARY_WEAPONS] = {4,4,7,7,7,4,4,7,4,7};
60 int Primary_ammo_max[MAX_PRIMARY_WEAPONS] = {0, VULCAN_AMMO_MAX, 0, 0, 0, 0, VULCAN_AMMO_MAX, 0, 0, 0};
61 ubyte Secondary_ammo_max[MAX_SECONDARY_WEAPONS] = {20, 10, 10, 5, 5, 20, 20, 15, 10, 10};
63 //for each primary weapon, what kind of powerup gives weapon
64 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};
66 //for each Secondary weapon, what kind of powerup gives weapon
67 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};
69 weapon_info Weapon_info[MAX_WEAPON_TYPES];
71 byte Primary_weapon, Secondary_weapon;
73 // autoselect ordering
75 ubyte PrimaryOrder[]={9,8,7,6,5,4,3,2,1,0,255};
76 ubyte SecondaryOrder[]={9,8,4,3,1,5,0,255,7,6,2};
78 ubyte DefaultPrimaryOrder[]={9,8,7,6,5,4,3,2,1,0,255};
79 ubyte DefaultSecondaryOrder[]={9,8,4,3,1,5,0,255,7,6,2};
81 // Cycling weapon key pressed?
85 //allow player to reorder menus?
86 extern ubyte MenuReordering;
88 //char *Primary_weapon_names[MAX_PRIMARY_WEAPONS] = {
91 // "Spreadfire Cannon",
96 //char *Secondary_weapon_names[MAX_SECONDARY_WEAPONS] = {
97 // "Concussion Missile",
104 //char *Primary_weapon_names_short[MAX_PRIMARY_WEAPONS] = {
112 //char *Secondary_weapon_names_short[MAX_SECONDARY_WEAPONS] = {
113 // "Concsn\nMissile",
114 // "Homing\nMissile",
120 byte Weapon_is_energy[MAX_WEAPON_TYPES] = {
131 // ; (0) Laser Level 1
132 // ; (1) Laser Level 2
133 // ; (2) Laser Level 3
134 // ; (3) Laser Level 4
139 // ; (8) ---------- Concussion Missile ----------
140 // ; (9) ---------- Flare ----------
141 // ; (10) ---------- Blue laser that blue guy shoots -----------
142 // ; (11) ---------- Vulcan Cannon ----------
143 // ; (12) ---------- Spreadfire Cannon ----------
144 // ; (13) ---------- Plasma Cannon ----------
145 // ; (14) ---------- Fusion Cannon ----------
146 // ; (15) ---------- Homing Missile ----------
147 // ; (16) ---------- Proximity Bomb ----------
148 // ; (17) ---------- Smart Missile ----------
149 // ; (18) ---------- Mega Missile ----------
150 // ; (19) ---------- Children of the PLAYER'S Smart Missile ----------
151 // ; (20) ---------- Bad Guy Spreadfire Laser ----------
152 // ; (21) ---------- SuperMech Homing Missile ----------
153 // ; (22) ---------- Regular Mech's missile -----------
154 // ; (23) ---------- Silent Spreadfire Laser ----------
155 // ; (24) ---------- Red laser that baby spiders shoot -----------
156 // ; (25) ---------- Green laser that rifleman shoots -----------
157 // ; (26) ---------- Plasma gun that 'plasguy' fires ------------
158 // ; (27) ---------- Blobs fired by Red Spiders -----------
159 // ; (28) ---------- Final Boss's Mega Missile ----------
160 // ; (29) ---------- Children of the ROBOT'S Smart Missile ----------
161 // ; (30) Laser Level 5
162 // ; (31) Laser Level 6
163 // ; (32) ---------- Super Vulcan Cannon ----------
164 // ; (33) ---------- Super Spreadfire Cannon ----------
165 // ; (34) ---------- Super Plasma Cannon ----------
166 // ; (35) ---------- Super Fusion Cannon ----------
168 // ------------------------------------------------------------------------------------
174 // See weapon.h for bit values
175 int player_has_weapon(int weapon_num, int secondary_flag)
177 int return_value = 0;
180 // Hack! If energy goes negative, you can't fire a weapon that doesn't require energy.
181 // But energy should not go negative (but it does), so find out why it does!
182 if (Players[Player_num].energy < 0)
183 Players[Player_num].energy = 0;
185 if (!secondary_flag) {
186 weapon_index = Primary_weapon_to_weapon_info[weapon_num];
188 if (Players[Player_num].primary_weapon_flags & (1 << weapon_num))
189 return_value |= HAS_WEAPON_FLAG;
191 // Special case: Gauss cannon uses vulcan ammo.
192 if (weapon_num == GAUSS_INDEX) {
193 if (Weapon_info[weapon_index].ammo_usage <= Players[Player_num].primary_ammo[VULCAN_INDEX])
194 return_value |= HAS_AMMO_FLAG;
196 if (Weapon_info[weapon_index].ammo_usage <= Players[Player_num].primary_ammo[weapon_num])
197 return_value |= HAS_AMMO_FLAG;
199 if (weapon_num == OMEGA_INDEX) { // Hack: Make sure player has energy to omega
200 if (Players[Player_num].energy || Omega_charge)
201 return_value |= HAS_ENERGY_FLAG;
203 if (Weapon_info[weapon_index].energy_usage <= Players[Player_num].energy)
204 return_value |= HAS_ENERGY_FLAG;
207 weapon_index = Secondary_weapon_to_weapon_info[weapon_num];
209 if (Players[Player_num].secondary_weapon_flags & (1 << weapon_num))
210 return_value |= HAS_WEAPON_FLAG;
212 if (Weapon_info[weapon_index].ammo_usage <= Players[Player_num].secondary_ammo[weapon_num])
213 return_value |= HAS_AMMO_FLAG;
215 if (Weapon_info[weapon_index].energy_usage <= Players[Player_num].energy)
216 return_value |= HAS_ENERGY_FLAG;
222 void InitWeaponOrdering ()
224 // short routine to setup default weapon priorities for new pilots
228 for (i=0;i<MAX_PRIMARY_WEAPONS+1;i++)
229 PrimaryOrder[i]=DefaultPrimaryOrder[i];
230 for (i=0;i<MAX_SECONDARY_WEAPONS+1;i++)
231 SecondaryOrder[i]=DefaultSecondaryOrder[i];
236 mprintf ((0,"Cycling primary!\n"));
238 auto_select_weapon (0);
242 void CycleSecondary ()
244 mprintf ((0,"Cycling secondary!\n"));
246 auto_select_weapon (1);
251 // ------------------------------------------------------------------------------------
252 //if message flag set, print message saying selected
253 void select_weapon(int weapon_num, int secondary_flag, int print_message, int wait_for_rearm)
257 if (Newdemo_state==ND_STATE_RECORDING )
258 newdemo_record_player_weapon(secondary_flag, weapon_num);
260 if (!secondary_flag) {
261 if (Primary_weapon != weapon_num) {
262 if (wait_for_rearm) digi_play_sample_once( SOUND_GOOD_SELECTION_PRIMARY, F1_0 );
264 if (Game_mode & GM_MULTI) {
265 if (wait_for_rearm) multi_send_play_sound(SOUND_GOOD_SELECTION_PRIMARY, F1_0);
269 Next_laser_fire_time = GameTime + REARM_TIME;
271 Next_laser_fire_time = 0;
272 Global_laser_firing_count = 0;
274 // Select super version if available.
278 ; // -- MK, only plays when can't fire weapon anyway, fixes bug -- digi_play_sample_once( SOUND_ALREADY_SELECTED, F1_0 );
280 digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
283 Primary_weapon = weapon_num;
284 weapon_name = PRIMARY_WEAPON_NAMES(weapon_num);
285 #if defined (TACTILE)
286 tactile_set_button_jolt();
290 //save flag for whether was super version
291 Primary_last_was_super[weapon_num % SUPER_WEAPON] = (weapon_num >= SUPER_WEAPON);
295 if (Secondary_weapon != weapon_num) {
296 if (wait_for_rearm) digi_play_sample_once( SOUND_GOOD_SELECTION_SECONDARY, F1_0 );
298 if (Game_mode & GM_MULTI) {
299 if (wait_for_rearm) multi_send_play_sound(SOUND_GOOD_SELECTION_PRIMARY, F1_0);
303 Next_missile_fire_time = GameTime + REARM_TIME;
305 Next_missile_fire_time = 0;
306 Global_missile_firing_count = 0;
311 digi_play_sample_once( SOUND_ALREADY_SELECTED, F1_0 );
313 digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
317 Secondary_weapon = weapon_num;
318 weapon_name = SECONDARY_WEAPON_NAMES(weapon_num);
320 //save flag for whether was super version
321 Secondary_last_was_super[weapon_num % SUPER_WEAPON] = (weapon_num >= SUPER_WEAPON);
326 if (weapon_num == LASER_INDEX && !secondary_flag)
327 HUD_init_message("%s Level %d %s", weapon_name, Players[Player_num].laser_level+1, TXT_SELECTED);
329 HUD_init_message("%s %s", weapon_name, TXT_SELECTED);
334 //flags whether the last time we use this weapon, it was the 'super' version
335 ubyte Primary_last_was_super[MAX_PRIMARY_WEAPONS];
336 ubyte Secondary_last_was_super[MAX_SECONDARY_WEAPONS];
338 // ------------------------------------------------------------------------------------
339 // Select a weapon, primary or secondary.
340 void do_weapon_select(int weapon_num, int secondary_flag)
342 int weapon_num_save=weapon_num;
343 int weapon_status,current,has_flag;
344 ubyte last_was_super;
346 if (!secondary_flag) {
347 current = Primary_weapon;
348 last_was_super = Primary_last_was_super[weapon_num];
349 has_flag = HAS_WEAPON_FLAG;
352 current = Secondary_weapon;
353 last_was_super = Secondary_last_was_super[weapon_num];
354 has_flag = HAS_WEAPON_FLAG+HAS_AMMO_FLAG;
357 if (current == weapon_num || current == weapon_num+SUPER_WEAPON) {
359 //already have this selected, so toggle to other of normal/super version
361 weapon_num += weapon_num+SUPER_WEAPON - current;
362 weapon_status = player_has_weapon(weapon_num, secondary_flag);
366 //go to last-select version of requested missile
369 weapon_num += SUPER_WEAPON;
371 weapon_status = player_has_weapon(weapon_num, secondary_flag);
373 //if don't have last-selected, try other version
375 if ((weapon_status & has_flag) != has_flag) {
376 weapon_num = 2*weapon_num_save+SUPER_WEAPON - weapon_num;
377 weapon_status = player_has_weapon(weapon_num, secondary_flag);
378 if ((weapon_status & has_flag) != has_flag)
379 weapon_num = 2*weapon_num_save+SUPER_WEAPON - weapon_num;
383 //if we don't have the weapon we're switching to, give error & bail
384 if ((weapon_status & has_flag) != has_flag) {
385 if (!secondary_flag) {
386 if (weapon_num==SUPER_LASER_INDEX)
387 return; //no such thing as super laser, so no error
388 HUD_init_message("%s %s!", TXT_DONT_HAVE, PRIMARY_WEAPON_NAMES(weapon_num));
391 HUD_init_message("%s %s%s",TXT_HAVE_NO, SECONDARY_WEAPON_NAMES(weapon_num), TXT_SX);
392 digi_play_sample( SOUND_BAD_SELECTION, F1_0 );
396 //now actually select the weapon
397 select_weapon(weapon_num, secondary_flag, 1, 1);
400 // ----------------------------------------------------------------------------------------
401 // Automatically select next best weapon if unable to fire current weapon.
402 // Weapon type: 0==primary, 1==secondary
403 void auto_select_weapon(int weapon_type)
409 if (weapon_type==0) {
410 r = player_has_weapon(Primary_weapon, 0);
411 if (r != HAS_ALL || Cycling) {
415 cur_weapon = POrderList(Primary_weapon);
416 cutpoint = POrderList (255);
421 if (cur_weapon>=cutpoint)
427 HUD_init_message(TXT_NO_PRIMARY);
430 ButtonReflexClear(0);
432 select_weapon(0, 0, 0, 1);
435 select_weapon (Primary_weapon,0,0,1);
445 if (cur_weapon==MAX_PRIMARY_WEAPONS)
448 // Hack alert! Because the fusion uses 0 energy at the end (it's got the weird chargeup)
449 // it looks like it takes 0 to fire, but it doesn't, so never auto-select.
450 // if (PrimaryOrder[cur_weapon] == FUSION_INDEX)
453 if (PrimaryOrder[cur_weapon] == Primary_weapon) {
456 HUD_init_message(TXT_NO_PRIMARY);
459 ButtonReflexClear(0);
462 // if (POrderList(0)<POrderList(255))
463 select_weapon(0, 0, 0, 1);
466 select_weapon (Primary_weapon,0,0,1);
468 try_again = 0; // Tried all weapons!
470 } else if (PrimaryOrder[cur_weapon]!=255 && player_has_weapon(PrimaryOrder[cur_weapon], 0) == HAS_ALL) {
471 select_weapon(PrimaryOrder[cur_weapon], 0, 1, 1 );
479 Assert(weapon_type==1);
480 r = player_has_weapon(Secondary_weapon, 1);
481 if (r != HAS_ALL || Cycling) {
485 cur_weapon = SOrderList(Secondary_weapon);
486 cutpoint = SOrderList (255);
492 if (cur_weapon>=cutpoint)
497 HUD_init_message("No secondary weapons selected!");
499 select_weapon (Secondary_weapon,1,0,1);
507 if (cur_weapon==MAX_SECONDARY_WEAPONS)
510 if (SecondaryOrder[cur_weapon] == Secondary_weapon) {
512 HUD_init_message("No secondary weapons available!");
514 select_weapon (Secondary_weapon,1,0,1);
516 try_again = 0; // Tried all weapons!
517 } else if (player_has_weapon(SecondaryOrder[cur_weapon], 1) == HAS_ALL) {
518 select_weapon(SecondaryOrder[cur_weapon], 1, 1, 1 );
531 // ----------------------------------------------------------------------------------------
532 // Show player which weapons he has, how much ammo...
533 // Looks like a debug screen now because it writes to mono screen, but that will change...
534 void show_weapon_status(void)
538 for (i=0; i<MAX_PRIMARY_WEAPONS; i++) {
539 if (Players[Player_num].primary_weapon_flags & (1 << i))
540 mprintf((0, "HAVE"));
544 mprintf((0, " Weapon: %20s, charges: %4i\n", PRIMARY_WEAPON_NAMES(i), Players[Player_num].primary_ammo[i]));
548 for (i=0; i<MAX_SECONDARY_WEAPONS; i++) {
549 if (Players[Player_num].secondary_weapon_flags & (1 << i))
550 mprintf((0, "HAVE"));
554 mprintf((0, " Weapon: %20s, charges: %4i\n", SECONDARY_WEAPON_NAMES(i), Players[Player_num].secondary_ammo[i]));
564 // ---------------------------------------------------------------------
565 //called when one of these weapons is picked up
566 //when you pick up a secondary, you always get the weapon & ammo for it
567 // Returns true if powerup picked up, else returns false.
568 int pick_up_secondary(int weapon_index,int count)
574 max = Secondary_ammo_max[weapon_index];
576 if (Players[Player_num].flags & PLAYER_FLAGS_AMMO_RACK)
579 if (Players[Player_num].secondary_ammo[weapon_index] >= max) {
580 HUD_init_message("%s %i %ss!", TXT_ALREADY_HAVE, Players[Player_num].secondary_ammo[weapon_index],SECONDARY_WEAPON_NAMES(weapon_index));
584 Players[Player_num].secondary_weapon_flags |= (1<<weapon_index);
585 Players[Player_num].secondary_ammo[weapon_index] += count;
587 num_picked_up = count;
588 if (Players[Player_num].secondary_ammo[weapon_index] > max) {
589 num_picked_up = count - (Players[Player_num].secondary_ammo[weapon_index] - max);
590 Players[Player_num].secondary_ammo[weapon_index] = max;
593 cutpoint=SOrderList (255);
594 if (SOrderList (weapon_index)<cutpoint && ((SOrderList (weapon_index) < SOrderList(Secondary_weapon)) || (Players[Player_num].secondary_ammo[Secondary_weapon] == 0)) )
595 select_weapon(weapon_index,1, 0, 1);
597 //if we don't auto-select this weapon, but it's a proxbomb or smart mine,
598 //we want to do a mini-auto-selection that applies to the drop bomb key
600 if ((weapon_index == PROXIMITY_INDEX || weapon_index == SMART_MINE_INDEX) &&
601 !(Secondary_weapon == PROXIMITY_INDEX || Secondary_weapon == SMART_MINE_INDEX)) {
604 cur = Secondary_last_was_super[PROXIMITY_INDEX]?SMART_MINE_INDEX:PROXIMITY_INDEX;
606 if (SOrderList (weapon_index) < SOrderList(cur))
607 Secondary_last_was_super[PROXIMITY_INDEX] = (weapon_index == SMART_MINE_INDEX);
611 //note: flash for all but concussion was 7,14,21
613 PALETTE_FLASH_ADD(15,15,15);
614 HUD_init_message("%d %s%s",num_picked_up,SECONDARY_WEAPON_NAMES(weapon_index), TXT_SX);
617 PALETTE_FLASH_ADD(10,10,10);
618 HUD_init_message("%s!",SECONDARY_WEAPON_NAMES(weapon_index));
624 void ReorderPrimary ()
626 newmenu_item m[MAX_PRIMARY_WEAPONS+1];
629 for (i=0;i<MAX_PRIMARY_WEAPONS+1;i++)
631 m[i].type=NM_TYPE_MENU;
632 if (PrimaryOrder[i]==255)
633 m[i].text="
\88\88\88\88\88\88\88 Never autoselect
\88\88\88\88\88\88\88";
635 m[i].text=(char *)PRIMARY_WEAPON_NAMES(PrimaryOrder[i]);
636 m[i].value=PrimaryOrder[i];
639 i = newmenu_do("Reorder Primary","Shift+Up/Down arrow to move item", i, m, NULL);
642 for (i=0;i<MAX_PRIMARY_WEAPONS+1;i++)
643 PrimaryOrder[i]=m[i].value;
646 void ReorderSecondary ()
648 newmenu_item m[MAX_SECONDARY_WEAPONS+1];
651 for (i=0;i<MAX_SECONDARY_WEAPONS+1;i++)
653 m[i].type=NM_TYPE_MENU;
654 if (SecondaryOrder[i]==255)
655 m[i].text="
\88\88\88\88\88\88\88 Never autoselect
\88\88\88\88\88\88\88";
657 m[i].text=(char *)SECONDARY_WEAPON_NAMES(SecondaryOrder[i]);
658 m[i].value=SecondaryOrder[i];
661 i = newmenu_do("Reorder Secondary","Shift+Up/Down arrow to move item", i, m, NULL);
663 for (i=0;i<MAX_SECONDARY_WEAPONS+1;i++)
664 SecondaryOrder[i]=m[i].value;
667 int POrderList (int num)
671 for (i=0;i<MAX_PRIMARY_WEAPONS+1;i++)
672 if (PrimaryOrder[i]==num)
674 mprintf ((0,"Primary %d has priority of %d!\n",num,i));
677 Error ("Primary Weapon is not in order list!!!");
680 int SOrderList (int num)
684 for (i=0;i<MAX_SECONDARY_WEAPONS+1;i++)
685 if (SecondaryOrder[i]==num)
687 mprintf ((0,"Secondary %d has priority of %d!\n",num,i));
690 mprintf ((0,"Error! Secondary Num=%d\n",num));
691 Error ("Secondary Weapon is not in order list!!!");
695 //called when a primary weapon is picked up
696 //returns true if actually picked up
697 int pick_up_primary(int weapon_index)
699 //ushort old_flags = Players[Player_num].primary_weapon_flags;
700 ushort flag = 1<<weapon_index;
702 int supposed_weapon=Primary_weapon;
704 if (weapon_index!=LASER_INDEX && Players[Player_num].primary_weapon_flags & flag) { //already have
705 HUD_init_message("%s %s!", TXT_ALREADY_HAVE_THE, PRIMARY_WEAPON_NAMES(weapon_index));
709 Players[Player_num].primary_weapon_flags |= flag;
711 cutpoint=POrderList (255);
713 if (Primary_weapon==LASER_INDEX && Players[Player_num].laser_level>=4)
714 supposed_weapon=SUPER_LASER_INDEX; // allotment for stupid way of doing super laser
717 if (POrderList(weapon_index)<cutpoint && POrderList(weapon_index)<POrderList(supposed_weapon))
718 select_weapon(weapon_index,0,0,1);
720 PALETTE_FLASH_ADD(7,14,21);
721 mprintf ((0,"Weapon index: %d\n",weapon_index));
723 if (weapon_index!=LASER_INDEX)
724 HUD_init_message("%s!",PRIMARY_WEAPON_NAMES(weapon_index));
728 int check_to_use_primary(int weapon_index)
730 ushort old_flags = Players[Player_num].primary_weapon_flags;
731 ushort flag = 1<<weapon_index;
734 cutpoint=POrderList (255);
736 if (!(old_flags & flag) && POrderList(weapon_index)<cutpoint && POrderList(weapon_index)<POrderList(Primary_weapon))
738 if (weapon_index==SUPER_LASER_INDEX)
739 select_weapon(LASER_INDEX,0,0,1);
741 select_weapon(weapon_index,0,0,1);
744 PALETTE_FLASH_ADD(7,14,21);
751 //called when ammo (for the vulcan cannon) is picked up
752 // Returns the amount picked up
753 int pick_up_ammo(int class_flag,int weapon_index,int ammo_count)
755 int max,cutpoint,supposed_weapon=Primary_weapon;
756 int old_ammo=class_flag; //kill warning
758 Assert(class_flag==CLASS_PRIMARY && weapon_index==VULCAN_INDEX);
760 max = Primary_ammo_max[weapon_index];
761 if (Players[Player_num].flags & PLAYER_FLAGS_AMMO_RACK)
764 if (Players[Player_num].primary_ammo[weapon_index] == max)
767 old_ammo = Players[Player_num].primary_ammo[weapon_index];
769 Players[Player_num].primary_ammo[weapon_index] += ammo_count;
771 if (Players[Player_num].primary_ammo[weapon_index] > max) {
772 ammo_count += (max - Players[Player_num].primary_ammo[weapon_index]);
773 Players[Player_num].primary_ammo[weapon_index] = max;
775 cutpoint=POrderList (255);
777 if (Primary_weapon==LASER_INDEX && Players[Player_num].laser_level>=4)
778 supposed_weapon=SUPER_LASER_INDEX; // allotment for stupid way of doing super laser
781 if (Players[Player_num].primary_weapon_flags&(1<<weapon_index) && weapon_index>Primary_weapon && old_ammo==0 &&
782 POrderList(weapon_index)<cutpoint && POrderList(weapon_index)<POrderList(supposed_weapon))
783 select_weapon(weapon_index,0,0,1);
785 return ammo_count; //return amount used
788 #define SMEGA_SHAKE_TIME (F1_0*2)
789 #define MAX_SMEGA_DETONATES 4
790 fix Smega_detonate_times[MAX_SMEGA_DETONATES];
792 // Call this to initialize for a new level.
793 // Sets all super mega missile detonation times to 0 which means there aren't any.
794 void init_smega_detonates(void)
798 for (i=0; i<MAX_SMEGA_DETONATES; i++)
799 Smega_detonate_times[i] = 0;
802 fix Seismic_tremor_magnitude;
803 fix Next_seismic_sound_time;
804 int Seismic_sound_playing = 0;
805 int Seismic_tremor_volume;
807 int Seismic_sound = SOUND_SEISMIC_DISTURBANCE_START;
809 // If a smega missile been detonated, rock the mine!
810 // This should be called every frame.
811 // Maybe this should affect all robots, being called when they get their physics done.
812 void rock_the_mine_frame(void)
816 for (i=0; i<MAX_SMEGA_DETONATES; i++) {
818 if (Smega_detonate_times[i] != 0) {
820 delta_time = GameTime - Smega_detonate_times[i];
822 if (!Seismic_sound_playing) {
823 digi_play_sample_looping(Seismic_sound, F1_0, -1, -1);
824 Seismic_sound_playing = 1;
825 Next_seismic_sound_time = GameTime + d_rand()/2;
828 if (delta_time < SMEGA_SHAKE_TIME) {
830 // Control center destroyed, rock the player's ship.
832 // -- fc = abs(delta_time - SMEGA_SHAKE_TIME/2);
833 // Changed 10/23/95 to make decreasing for super mega missile.
834 fc = (SMEGA_SHAKE_TIME - delta_time)/2;
835 fc /= SMEGA_SHAKE_TIME/32;
842 Seismic_tremor_volume += fc;
844 rx = fixmul(d_rand() - 16384, 3*F1_0/16 + (F1_0*(16-fc))/32);
845 rz = fixmul(d_rand() - 16384, 3*F1_0/16 + (F1_0*(16-fc))/32);
847 ConsoleObject->mtype.phys_info.rotvel.x += rx;
848 ConsoleObject->mtype.phys_info.rotvel.z += rz;
851 if (Buddy_objnum != -1) {
852 Objects[Buddy_objnum].mtype.phys_info.rotvel.x += rx*4;
853 Objects[Buddy_objnum].mtype.phys_info.rotvel.z += rz*4;
856 // Shake a guided missile!
857 Seismic_tremor_magnitude += rx;
860 Smega_detonate_times[i] = 0;
865 // Hook in the rumble sound effect here.
868 extern int Level_shake_frequency, Level_shake_duration;
870 extern void multi_send_seismic (fix,fix);
873 #define SEISMIC_DISTURBANCE_DURATION (F1_0*5)
874 fix Seismic_disturbance_start_time = 0, Seismic_disturbance_end_time;
878 int on_seismic_level(void)
880 return Seismic_level;
883 void init_seismic_disturbances(void)
885 Seismic_disturbance_start_time = 0;
886 Seismic_disturbance_end_time = 0;
889 // Return true if time to start a seismic disturbance.
890 int start_seismic_disturbance(void)
894 if (Level_shake_duration < 1)
897 rval = (2 * fixmul(d_rand(), Level_shake_frequency)) < FrameTime;
900 Seismic_disturbance_start_time = GameTime;
901 Seismic_disturbance_end_time = GameTime + Level_shake_duration;
902 if (!Seismic_sound_playing) {
903 digi_play_sample_looping(Seismic_sound, F1_0, -1, -1);
904 Seismic_sound_playing = 1;
905 Next_seismic_sound_time = GameTime + d_rand()/2;
909 if (Game_mode & GM_MULTI)
910 multi_send_seismic (Seismic_disturbance_start_time,Seismic_disturbance_end_time);
917 void seismic_disturbance_frame(void)
919 if (Level_shake_frequency) {
920 if (((Seismic_disturbance_start_time < GameTime) && (Seismic_disturbance_end_time > GameTime)) || start_seismic_disturbance()) {
924 delta_time = GameTime - Seismic_disturbance_start_time;
926 fc = abs(delta_time - (Seismic_disturbance_end_time - Seismic_disturbance_start_time)/2);
934 Seismic_tremor_volume += fc;
936 rx = fixmul(d_rand() - 16384, 3*F1_0/16 + (F1_0*(16-fc))/32);
937 rz = fixmul(d_rand() - 16384, 3*F1_0/16 + (F1_0*(16-fc))/32);
939 ConsoleObject->mtype.phys_info.rotvel.x += rx;
940 ConsoleObject->mtype.phys_info.rotvel.z += rz;
943 if (Buddy_objnum != -1) {
944 Objects[Buddy_objnum].mtype.phys_info.rotvel.x += rx*4;
945 Objects[Buddy_objnum].mtype.phys_info.rotvel.z += rz*4;
948 // Shake a guided missile!
949 Seismic_tremor_magnitude += rx;
955 // Call this when a smega detonates to start the process of rocking the mine.
956 void smega_rock_stuff(void)
960 for (i=0; i<MAX_SMEGA_DETONATES; i++) {
961 if (Smega_detonate_times[i] + SMEGA_SHAKE_TIME < GameTime)
962 Smega_detonate_times[i] = 0;
965 for (i=0; i<MAX_SMEGA_DETONATES; i++) {
966 if (Smega_detonate_times[i] == 0) {
967 Smega_detonate_times[i] = GameTime;
973 int Super_mines_yes = 1;
975 // Call this once/frame to process all super mines in the level.
976 void process_super_mines_frame(void)
981 // If we don't know of there being any super mines in the level, just
982 // check every 8th object each frame.
983 if (Super_mines_yes == 0) {
984 start = FrameCount & 7;
993 for (i=start; i<=Highest_object_index; i+=add) {
994 if ((Objects[i].type == OBJ_WEAPON) && (Objects[i].id == SUPERPROX_ID)) {
997 parent_num = Objects[i].ctype.laser_info.parent_num;
1000 if (Objects[i].lifeleft + F1_0*2 < Weapon_info[SUPERPROX_ID].lifetime) {
1001 vms_vector *bombpos;
1003 bombpos = &Objects[i].pos;
1005 for (j=0; j<=Highest_object_index; j++) {
1006 if ((Objects[j].type == OBJ_PLAYER) || (Objects[j].type == OBJ_ROBOT)) {
1009 dist = vm_vec_dist_quick(bombpos, &Objects[j].pos);
1011 if (j != parent_num)
1012 if (dist - Objects[j].size < F1_0*20)
1014 if (Objects[i].segnum == Objects[j].segnum)
1015 Objects[i].lifeleft = 1;
1017 // Object which is close enough to detonate smart mine is not in same segment as smart mine.
1018 // Need to do a more expensive check to make sure there isn't an obstruction.
1019 if (((FrameCount ^ (i+j)) % 4) == 0) {
1024 mprintf((0, "Expensive proxmine collision check. Frame %i\n", FrameCount));
1026 fq.startseg = Objects[i].segnum;
1027 fq.p0 = &Objects[i].pos;
1028 fq.p1 = &Objects[j].pos;
1031 fq.ignore_obj_list = NULL;
1034 fate = find_vector_intersection(&fq, &hit_data);
1035 if (fate != HIT_WALL)
1036 Objects[i].lifeleft = 1;
1048 #define SPIT_SPEED 20
1050 //this function is for when the player intentionally drops a powerup
1051 //this function is based on drop_powerup()
1052 int spit_powerup(object *spitter, int id,int seed)
1056 vms_vector new_velocity, new_pos;
1060 vm_vec_scale_add(&new_velocity,&spitter->mtype.phys_info.velocity,&spitter->orient.fvec,i2f(SPIT_SPEED));
1062 new_velocity.x += (d_rand() - 16384) * SPIT_SPEED * 2;
1063 new_velocity.y += (d_rand() - 16384) * SPIT_SPEED * 2;
1064 new_velocity.z += (d_rand() - 16384) * SPIT_SPEED * 2;
1066 // Give keys zero velocity so they can be tracked better in multi
1068 if ((Game_mode & GM_MULTI) && (id >= POW_KEY_BLUE) && (id <= POW_KEY_GOLD))
1069 vm_vec_zero(&new_velocity);
1071 //there's a piece of code which lets the player pick up a powerup if
1072 //the distance between him and the powerup is less than 2 time their
1073 //combined radii. So we need to create powerups pretty far out from
1076 vm_vec_scale_add(&new_pos,&spitter->pos,&spitter->orient.fvec,spitter->size);
1079 if (Game_mode & GM_MULTI)
1081 if (Net_create_loc >= MAX_NET_CREATE_OBJECTS)
1083 mprintf( (0, "WEAPON:Not enough slots to drop all powerups!\n" ));
1089 objnum = obj_create( OBJ_POWERUP, id, spitter->segnum, &new_pos, &vmd_identity_matrix, Powerup_info[id].size, CT_POWERUP, MT_PHYSICS, RT_POWERUP);
1092 mprintf((1, "Can't create object in object_create_egg. Aborting.\n"));
1097 obj = &Objects[objnum];
1099 obj->mtype.phys_info.velocity = new_velocity;
1100 obj->mtype.phys_info.drag = 512; //1024;
1101 obj->mtype.phys_info.mass = F1_0;
1103 obj->mtype.phys_info.flags = PF_BOUNCE;
1105 obj->rtype.vclip_info.vclip_num = Powerup_info[obj->id].vclip_num;
1106 obj->rtype.vclip_info.frametime = Vclip[obj->rtype.vclip_info.vclip_num].frame_time;
1107 obj->rtype.vclip_info.framenum = 0;
1109 if (spitter == ConsoleObject)
1110 obj->ctype.powerup_info.flags |= PF_SPAT_BY_PLAYER;
1115 case POW_SHIELD_BOOST:
1117 obj->lifeleft = (d_rand() + F1_0*3) * 64; // Lives for 3 to 3.5 binary minutes (a binary minute is 64 seconds)
1118 if (Game_mode & GM_MULTI)
1122 //if (Game_mode & GM_MULTI)
1123 // obj->lifeleft = (d_rand() + F1_0*3) * 64; // Lives for 5 to 5.5 binary minutes (a binary minute is 64 seconds)
1130 void DropCurrentWeapon ()
1132 int objnum,ammo=0,seed;
1134 if (Primary_weapon==0)
1136 HUD_init_message("You cannot drop your base weapon!");
1140 HUD_init_message("%s dropped!",PRIMARY_WEAPON_NAMES(Primary_weapon));
1141 digi_play_sample (SOUND_DROP_WEAPON,F1_0);
1145 objnum = spit_powerup(ConsoleObject,Primary_weapon_to_powerup[Primary_weapon],seed);
1150 if (Primary_weapon == VULCAN_INDEX || Primary_weapon == GAUSS_INDEX) {
1152 //if it's one of these, drop some ammo with the weapon
1154 ammo = Players[Player_num].primary_ammo[VULCAN_INDEX];
1156 if ((Players[Player_num].primary_weapon_flags & HAS_FLAG(VULCAN_INDEX)) && (Players[Player_num].primary_weapon_flags & HAS_FLAG(GAUSS_INDEX)))
1157 ammo /= 2; //if both vulcan & gauss, drop half
1159 Players[Player_num].primary_ammo[VULCAN_INDEX] -= ammo;
1162 Objects[objnum].ctype.powerup_info.count = ammo;
1165 if (Primary_weapon == OMEGA_INDEX) {
1167 //dropped weapon has current energy
1170 Objects[objnum].ctype.powerup_info.count = Omega_charge;
1174 if ((Game_mode & GM_MULTI) && objnum>-1)
1175 multi_send_drop_weapon(objnum,seed);
1178 Players[Player_num].primary_weapon_flags &= (~(1<<Primary_weapon));
1179 auto_select_weapon (0);
1183 void DropSecondaryWeapon ()
1187 if (Players[Player_num].secondary_ammo[Secondary_weapon] ==0)
1189 HUD_init_message("No secondary weapon to drop!");
1193 if ((Secondary_weapon_to_powerup[Secondary_weapon]==POW_PROXIMITY_WEAPON ||
1194 Secondary_weapon_to_powerup[Secondary_weapon]==POW_SMART_MINE) &&
1195 Players[Player_num].secondary_ammo[Secondary_weapon]<4)
1197 HUD_init_message("You need at least 4 to drop!");
1201 HUD_init_message("%s dropped!",SECONDARY_WEAPON_NAMES(Secondary_weapon));
1202 digi_play_sample (SOUND_DROP_WEAPON,F1_0);
1206 objnum = spit_powerup(ConsoleObject,Secondary_weapon_to_powerup[Secondary_weapon],seed);
1213 if ((Game_mode & GM_MULTI) && objnum>-1)
1214 multi_send_drop_weapon(objnum,seed);
1217 if (Secondary_weapon_to_powerup[Secondary_weapon]==POW_PROXIMITY_WEAPON ||
1218 Secondary_weapon_to_powerup[Secondary_weapon]==POW_SMART_MINE)
1219 Players[Player_num].secondary_ammo[Secondary_weapon]-=4;
1221 Players[Player_num].secondary_ammo[Secondary_weapon]--;
1223 if (Players[Player_num].secondary_ammo[Secondary_weapon]==0)
1225 Players[Player_num].secondary_weapon_flags &= (~(1<<Secondary_weapon));
1226 auto_select_weapon (1);
1230 // ---------------------------------------------------------------------------------------
1231 // Do seismic disturbance stuff including the looping sounds with changing volume.
1232 void do_seismic_stuff(void)
1236 stv_save = Seismic_tremor_volume;
1237 Seismic_tremor_magnitude = 0;
1238 Seismic_tremor_volume = 0;
1240 rock_the_mine_frame();
1241 seismic_disturbance_frame();
1243 if (stv_save != 0) {
1244 if (Seismic_tremor_volume == 0) {
1245 digi_stop_looping_sound();
1246 Seismic_sound_playing = 0;
1249 if ((GameTime > Next_seismic_sound_time) && Seismic_tremor_volume) {
1252 volume = Seismic_tremor_volume * 2048;
1255 digi_change_looping_volume(volume);
1256 Next_seismic_sound_time = GameTime + d_rand()/4 + 8192;
1262 int tactile_fire_duration[]={120,80,150,250,150,200,100,180,280,100};
1263 int tactile_fire_repeat[]={260,90,160,160,160,210,110,191,291,111};
1265 void tactile_set_button_jolt ()
1271 static int stickmag=-1;
1274 dur=tactile_fire_duration[Primary_weapon];
1275 rep=tactile_fire_repeat[Primary_weapon];
1281 if (t=FindArg("-stickmag"))
1282 stickmag=atoi (Args[t+1]);
1286 infile=(FILE *)fopen ("stick.val","rt");
1291 fscanf (infile,"%d %d\n",&tactile_fire_duration[i],&tactile_fire_repeat[i]);
1292 mprintf ((0,"scan value[%d]=%d\n",i,tactile_fire_duration[i]));
1297 ButtonReflexJolt (0,stickmag,0,dur,rep);