1 /* $Id: weapon.c,v 1.6 2002-08-06 05:21:33 btb 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.
20 static char rcsid[] = "$Id: weapon.c,v 1.6 2002-08-06 05:21:33 btb Exp $";
48 int POrderList (int num);
49 int SOrderList (int num);
50 // Note, only Vulcan cannon requires ammo.
51 // NOTE: Now Vulcan and Gauss require ammo. -5/3/95 Yuan
52 //ubyte Default_primary_ammo_level[MAX_PRIMARY_WEAPONS] = {255, 0, 255, 255, 255};
53 //ubyte Default_secondary_ammo_level[MAX_SECONDARY_WEAPONS] = {3, 0, 0, 0, 0};
55 // Convert primary weapons to indices in Weapon_info array.
56 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};
57 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};
59 //for each Secondary weapon, which gun it fires out of
60 ubyte Secondary_weapon_to_gun_num[MAX_SECONDARY_WEAPONS] = {4,4,7,7,7,4,4,7,4,7};
62 int Primary_ammo_max[MAX_PRIMARY_WEAPONS] = {0, VULCAN_AMMO_MAX, 0, 0, 0, 0, VULCAN_AMMO_MAX, 0, 0, 0};
63 ubyte Secondary_ammo_max[MAX_SECONDARY_WEAPONS] = {20, 10, 10, 5, 5, 20, 20, 15, 10, 10};
65 //for each primary weapon, what kind of powerup gives weapon
66 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};
68 //for each Secondary weapon, what kind of powerup gives weapon
69 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};
71 weapon_info Weapon_info[MAX_WEAPON_TYPES];
73 byte Primary_weapon, Secondary_weapon;
75 // autoselect ordering
77 ubyte PrimaryOrder[]={9,8,7,6,5,4,3,2,1,0,255};
78 ubyte SecondaryOrder[]={9,8,4,3,1,5,0,255,7,6,2};
80 ubyte DefaultPrimaryOrder[]={9,8,7,6,5,4,3,2,1,0,255};
81 ubyte DefaultSecondaryOrder[]={9,8,4,3,1,5,0,255,7,6,2};
83 // Cycling weapon key pressed?
87 //allow player to reorder menus?
88 extern ubyte MenuReordering;
90 //char *Primary_weapon_names[MAX_PRIMARY_WEAPONS] = {
93 // "Spreadfire Cannon",
98 //char *Secondary_weapon_names[MAX_SECONDARY_WEAPONS] = {
99 // "Concussion Missile",
106 //char *Primary_weapon_names_short[MAX_PRIMARY_WEAPONS] = {
114 //char *Secondary_weapon_names_short[MAX_SECONDARY_WEAPONS] = {
115 // "Concsn\nMissile",
116 // "Homing\nMissile",
122 byte Weapon_is_energy[MAX_WEAPON_TYPES] = {
133 // ; (0) Laser Level 1
134 // ; (1) Laser Level 2
135 // ; (2) Laser Level 3
136 // ; (3) Laser Level 4
141 // ; (8) ---------- Concussion Missile ----------
142 // ; (9) ---------- Flare ----------
143 // ; (10) ---------- Blue laser that blue guy shoots -----------
144 // ; (11) ---------- Vulcan Cannon ----------
145 // ; (12) ---------- Spreadfire Cannon ----------
146 // ; (13) ---------- Plasma Cannon ----------
147 // ; (14) ---------- Fusion Cannon ----------
148 // ; (15) ---------- Homing Missile ----------
149 // ; (16) ---------- Proximity Bomb ----------
150 // ; (17) ---------- Smart Missile ----------
151 // ; (18) ---------- Mega Missile ----------
152 // ; (19) ---------- Children of the PLAYER'S Smart Missile ----------
153 // ; (20) ---------- Bad Guy Spreadfire Laser ----------
154 // ; (21) ---------- SuperMech Homing Missile ----------
155 // ; (22) ---------- Regular Mech's missile -----------
156 // ; (23) ---------- Silent Spreadfire Laser ----------
157 // ; (24) ---------- Red laser that baby spiders shoot -----------
158 // ; (25) ---------- Green laser that rifleman shoots -----------
159 // ; (26) ---------- Plasma gun that 'plasguy' fires ------------
160 // ; (27) ---------- Blobs fired by Red Spiders -----------
161 // ; (28) ---------- Final Boss's Mega Missile ----------
162 // ; (29) ---------- Children of the ROBOT'S Smart Missile ----------
163 // ; (30) Laser Level 5
164 // ; (31) Laser Level 6
165 // ; (32) ---------- Super Vulcan Cannon ----------
166 // ; (33) ---------- Super Spreadfire Cannon ----------
167 // ; (34) ---------- Super Plasma Cannon ----------
168 // ; (35) ---------- Super Fusion Cannon ----------
170 // ------------------------------------------------------------------------------------
176 // See weapon.h for bit values
177 int player_has_weapon(int weapon_num, int secondary_flag)
179 int return_value = 0;
182 // Hack! If energy goes negative, you can't fire a weapon that doesn't require energy.
183 // But energy should not go negative (but it does), so find out why it does!
184 if (Players[Player_num].energy < 0)
185 Players[Player_num].energy = 0;
187 if (!secondary_flag) {
188 weapon_index = Primary_weapon_to_weapon_info[weapon_num];
190 if (Players[Player_num].primary_weapon_flags & (1 << weapon_num))
191 return_value |= HAS_WEAPON_FLAG;
193 // Special case: Gauss cannon uses vulcan ammo.
194 if (weapon_num == GAUSS_INDEX) {
195 if (Weapon_info[weapon_index].ammo_usage <= Players[Player_num].primary_ammo[VULCAN_INDEX])
196 return_value |= HAS_AMMO_FLAG;
198 if (Weapon_info[weapon_index].ammo_usage <= Players[Player_num].primary_ammo[weapon_num])
199 return_value |= HAS_AMMO_FLAG;
201 if (weapon_num == OMEGA_INDEX) { // Hack: Make sure player has energy to omega
202 if (Players[Player_num].energy || Omega_charge)
203 return_value |= HAS_ENERGY_FLAG;
205 if (Weapon_info[weapon_index].energy_usage <= Players[Player_num].energy)
206 return_value |= HAS_ENERGY_FLAG;
209 weapon_index = Secondary_weapon_to_weapon_info[weapon_num];
211 if (Players[Player_num].secondary_weapon_flags & (1 << weapon_num))
212 return_value |= HAS_WEAPON_FLAG;
214 if (Weapon_info[weapon_index].ammo_usage <= Players[Player_num].secondary_ammo[weapon_num])
215 return_value |= HAS_AMMO_FLAG;
217 if (Weapon_info[weapon_index].energy_usage <= Players[Player_num].energy)
218 return_value |= HAS_ENERGY_FLAG;
224 void InitWeaponOrdering ()
226 // short routine to setup default weapon priorities for new pilots
230 for (i=0;i<MAX_PRIMARY_WEAPONS+1;i++)
231 PrimaryOrder[i]=DefaultPrimaryOrder[i];
232 for (i=0;i<MAX_SECONDARY_WEAPONS+1;i++)
233 SecondaryOrder[i]=DefaultSecondaryOrder[i];
238 mprintf ((0,"Cycling primary!\n"));
240 auto_select_weapon (0);
244 void CycleSecondary ()
246 mprintf ((0,"Cycling secondary!\n"));
248 auto_select_weapon (1);
253 // ------------------------------------------------------------------------------------
254 //if message flag set, print message saying selected
255 void select_weapon(int weapon_num, int secondary_flag, int print_message, int wait_for_rearm)
259 if (Newdemo_state==ND_STATE_RECORDING )
260 newdemo_record_player_weapon(secondary_flag, weapon_num);
262 if (!secondary_flag) {
263 if (Primary_weapon != weapon_num) {
264 if (wait_for_rearm) digi_play_sample_once( SOUND_GOOD_SELECTION_PRIMARY, F1_0 );
266 if (Game_mode & GM_MULTI) {
267 if (wait_for_rearm) multi_send_play_sound(SOUND_GOOD_SELECTION_PRIMARY, F1_0);
271 Next_laser_fire_time = GameTime + REARM_TIME;
273 Next_laser_fire_time = 0;
274 Global_laser_firing_count = 0;
276 // Select super version if available.
280 ; // -- MK, only plays when can't fire weapon anyway, fixes bug -- digi_play_sample_once( SOUND_ALREADY_SELECTED, F1_0 );
282 digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
285 Primary_weapon = weapon_num;
286 weapon_name = PRIMARY_WEAPON_NAMES(weapon_num);
287 #if defined (TACTILE)
288 tactile_set_button_jolt();
292 //save flag for whether was super version
293 Primary_last_was_super[weapon_num % SUPER_WEAPON] = (weapon_num >= SUPER_WEAPON);
297 if (Secondary_weapon != weapon_num) {
298 if (wait_for_rearm) digi_play_sample_once( SOUND_GOOD_SELECTION_SECONDARY, F1_0 );
300 if (Game_mode & GM_MULTI) {
301 if (wait_for_rearm) multi_send_play_sound(SOUND_GOOD_SELECTION_PRIMARY, F1_0);
305 Next_missile_fire_time = GameTime + REARM_TIME;
307 Next_missile_fire_time = 0;
308 Global_missile_firing_count = 0;
313 digi_play_sample_once( SOUND_ALREADY_SELECTED, F1_0 );
315 digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
319 Secondary_weapon = weapon_num;
320 weapon_name = SECONDARY_WEAPON_NAMES(weapon_num);
322 //save flag for whether was super version
323 Secondary_last_was_super[weapon_num % SUPER_WEAPON] = (weapon_num >= SUPER_WEAPON);
328 if (weapon_num == LASER_INDEX && !secondary_flag)
329 HUD_init_message("%s Level %d %s", weapon_name, Players[Player_num].laser_level+1, TXT_SELECTED);
331 HUD_init_message("%s %s", weapon_name, TXT_SELECTED);
336 //flags whether the last time we use this weapon, it was the 'super' version
337 ubyte Primary_last_was_super[MAX_PRIMARY_WEAPONS];
338 ubyte Secondary_last_was_super[MAX_SECONDARY_WEAPONS];
340 // ------------------------------------------------------------------------------------
341 // Select a weapon, primary or secondary.
342 void do_weapon_select(int weapon_num, int secondary_flag)
344 int weapon_num_save=weapon_num;
345 int weapon_status,current,has_flag;
346 ubyte last_was_super;
348 if (!secondary_flag) {
349 current = Primary_weapon;
350 last_was_super = Primary_last_was_super[weapon_num];
351 has_flag = HAS_WEAPON_FLAG;
354 current = Secondary_weapon;
355 last_was_super = Secondary_last_was_super[weapon_num];
356 has_flag = HAS_WEAPON_FLAG+HAS_AMMO_FLAG;
359 if (current == weapon_num || current == weapon_num+SUPER_WEAPON) {
361 //already have this selected, so toggle to other of normal/super version
363 weapon_num += weapon_num+SUPER_WEAPON - current;
364 weapon_status = player_has_weapon(weapon_num, secondary_flag);
368 //go to last-select version of requested missile
371 weapon_num += SUPER_WEAPON;
373 weapon_status = player_has_weapon(weapon_num, secondary_flag);
375 //if don't have last-selected, try other version
377 if ((weapon_status & has_flag) != has_flag) {
378 weapon_num = 2*weapon_num_save+SUPER_WEAPON - weapon_num;
379 weapon_status = player_has_weapon(weapon_num, secondary_flag);
380 if ((weapon_status & has_flag) != has_flag)
381 weapon_num = 2*weapon_num_save+SUPER_WEAPON - weapon_num;
385 //if we don't have the weapon we're switching to, give error & bail
386 if ((weapon_status & has_flag) != has_flag) {
387 if (!secondary_flag) {
388 if (weapon_num==SUPER_LASER_INDEX)
389 return; //no such thing as super laser, so no error
390 HUD_init_message("%s %s!", TXT_DONT_HAVE, PRIMARY_WEAPON_NAMES(weapon_num));
393 HUD_init_message("%s %s%s",TXT_HAVE_NO, SECONDARY_WEAPON_NAMES(weapon_num), TXT_SX);
394 digi_play_sample( SOUND_BAD_SELECTION, F1_0 );
398 //now actually select the weapon
399 select_weapon(weapon_num, secondary_flag, 1, 1);
402 // ----------------------------------------------------------------------------------------
403 // Automatically select next best weapon if unable to fire current weapon.
404 // Weapon type: 0==primary, 1==secondary
405 void auto_select_weapon(int weapon_type)
411 if (weapon_type==0) {
412 r = player_has_weapon(Primary_weapon, 0);
413 if (r != HAS_ALL || Cycling) {
417 cur_weapon = POrderList(Primary_weapon);
418 cutpoint = POrderList (255);
423 if (cur_weapon>=cutpoint)
429 HUD_init_message(TXT_NO_PRIMARY);
432 ButtonReflexClear(0);
434 select_weapon(0, 0, 0, 1);
437 select_weapon (Primary_weapon,0,0,1);
447 if (cur_weapon==MAX_PRIMARY_WEAPONS)
450 // Hack alert! Because the fusion uses 0 energy at the end (it's got the weird chargeup)
451 // it looks like it takes 0 to fire, but it doesn't, so never auto-select.
452 // if (PrimaryOrder[cur_weapon] == FUSION_INDEX)
455 if (PrimaryOrder[cur_weapon] == Primary_weapon) {
458 HUD_init_message(TXT_NO_PRIMARY);
461 ButtonReflexClear(0);
464 // if (POrderList(0)<POrderList(255))
465 select_weapon(0, 0, 0, 1);
468 select_weapon (Primary_weapon,0,0,1);
470 try_again = 0; // Tried all weapons!
472 } else if (PrimaryOrder[cur_weapon]!=255 && player_has_weapon(PrimaryOrder[cur_weapon], 0) == HAS_ALL) {
473 select_weapon(PrimaryOrder[cur_weapon], 0, 1, 1 );
481 Assert(weapon_type==1);
482 r = player_has_weapon(Secondary_weapon, 1);
483 if (r != HAS_ALL || Cycling) {
487 cur_weapon = SOrderList(Secondary_weapon);
488 cutpoint = SOrderList (255);
494 if (cur_weapon>=cutpoint)
499 HUD_init_message("No secondary weapons selected!");
501 select_weapon (Secondary_weapon,1,0,1);
509 if (cur_weapon==MAX_SECONDARY_WEAPONS)
512 if (SecondaryOrder[cur_weapon] == Secondary_weapon) {
514 HUD_init_message("No secondary weapons available!");
516 select_weapon (Secondary_weapon,1,0,1);
518 try_again = 0; // Tried all weapons!
519 } else if (player_has_weapon(SecondaryOrder[cur_weapon], 1) == HAS_ALL) {
520 select_weapon(SecondaryOrder[cur_weapon], 1, 1, 1 );
533 // ----------------------------------------------------------------------------------------
534 // Show player which weapons he has, how much ammo...
535 // Looks like a debug screen now because it writes to mono screen, but that will change...
536 void show_weapon_status(void)
540 for (i=0; i<MAX_PRIMARY_WEAPONS; i++) {
541 if (Players[Player_num].primary_weapon_flags & (1 << i))
542 mprintf((0, "HAVE"));
546 mprintf((0, " Weapon: %20s, charges: %4i\n", PRIMARY_WEAPON_NAMES(i), Players[Player_num].primary_ammo[i]));
550 for (i=0; i<MAX_SECONDARY_WEAPONS; i++) {
551 if (Players[Player_num].secondary_weapon_flags & (1 << i))
552 mprintf((0, "HAVE"));
556 mprintf((0, " Weapon: %20s, charges: %4i\n", SECONDARY_WEAPON_NAMES(i), Players[Player_num].secondary_ammo[i]));
566 // ---------------------------------------------------------------------
567 //called when one of these weapons is picked up
568 //when you pick up a secondary, you always get the weapon & ammo for it
569 // Returns true if powerup picked up, else returns false.
570 int pick_up_secondary(int weapon_index,int count)
576 max = Secondary_ammo_max[weapon_index];
578 if (Players[Player_num].flags & PLAYER_FLAGS_AMMO_RACK)
581 if (Players[Player_num].secondary_ammo[weapon_index] >= max) {
582 HUD_init_message("%s %i %ss!", TXT_ALREADY_HAVE, Players[Player_num].secondary_ammo[weapon_index],SECONDARY_WEAPON_NAMES(weapon_index));
586 Players[Player_num].secondary_weapon_flags |= (1<<weapon_index);
587 Players[Player_num].secondary_ammo[weapon_index] += count;
589 num_picked_up = count;
590 if (Players[Player_num].secondary_ammo[weapon_index] > max) {
591 num_picked_up = count - (Players[Player_num].secondary_ammo[weapon_index] - max);
592 Players[Player_num].secondary_ammo[weapon_index] = max;
595 cutpoint=SOrderList (255);
596 if (SOrderList (weapon_index)<cutpoint && ((SOrderList (weapon_index) < SOrderList(Secondary_weapon)) || (Players[Player_num].secondary_ammo[Secondary_weapon] == 0)) )
597 select_weapon(weapon_index,1, 0, 1);
599 //if we don't auto-select this weapon, but it's a proxbomb or smart mine,
600 //we want to do a mini-auto-selection that applies to the drop bomb key
602 if ((weapon_index == PROXIMITY_INDEX || weapon_index == SMART_MINE_INDEX) &&
603 !(Secondary_weapon == PROXIMITY_INDEX || Secondary_weapon == SMART_MINE_INDEX)) {
606 cur = Secondary_last_was_super[PROXIMITY_INDEX]?SMART_MINE_INDEX:PROXIMITY_INDEX;
608 if (SOrderList (weapon_index) < SOrderList(cur))
609 Secondary_last_was_super[PROXIMITY_INDEX] = (weapon_index == SMART_MINE_INDEX);
613 //note: flash for all but concussion was 7,14,21
615 PALETTE_FLASH_ADD(15,15,15);
616 HUD_init_message("%d %s%s",num_picked_up,SECONDARY_WEAPON_NAMES(weapon_index), TXT_SX);
619 PALETTE_FLASH_ADD(10,10,10);
620 HUD_init_message("%s!",SECONDARY_WEAPON_NAMES(weapon_index));
626 void ReorderPrimary ()
628 newmenu_item m[MAX_PRIMARY_WEAPONS+1];
631 for (i=0;i<MAX_PRIMARY_WEAPONS+1;i++)
633 m[i].type=NM_TYPE_MENU;
634 if (PrimaryOrder[i]==255)
635 m[i].text="
\88\88\88\88\88\88\88 Never autoselect
\88\88\88\88\88\88\88";
637 m[i].text=(char *)PRIMARY_WEAPON_NAMES(PrimaryOrder[i]);
638 m[i].value=PrimaryOrder[i];
641 i = newmenu_do("Reorder Primary","Shift+Up/Down arrow to move item", i, m, NULL);
644 for (i=0;i<MAX_PRIMARY_WEAPONS+1;i++)
645 PrimaryOrder[i]=m[i].value;
648 void ReorderSecondary ()
650 newmenu_item m[MAX_SECONDARY_WEAPONS+1];
653 for (i=0;i<MAX_SECONDARY_WEAPONS+1;i++)
655 m[i].type=NM_TYPE_MENU;
656 if (SecondaryOrder[i]==255)
657 m[i].text="
\88\88\88\88\88\88\88 Never autoselect
\88\88\88\88\88\88\88";
659 m[i].text=(char *)SECONDARY_WEAPON_NAMES(SecondaryOrder[i]);
660 m[i].value=SecondaryOrder[i];
663 i = newmenu_do("Reorder Secondary","Shift+Up/Down arrow to move item", i, m, NULL);
665 for (i=0;i<MAX_SECONDARY_WEAPONS+1;i++)
666 SecondaryOrder[i]=m[i].value;
669 int POrderList (int num)
673 for (i=0;i<MAX_PRIMARY_WEAPONS+1;i++)
674 if (PrimaryOrder[i]==num)
676 mprintf ((0,"Primary %d has priority of %d!\n",num,i));
679 Error ("Primary Weapon is not in order list!!!");
682 int SOrderList (int num)
686 for (i=0;i<MAX_SECONDARY_WEAPONS+1;i++)
687 if (SecondaryOrder[i]==num)
689 mprintf ((0,"Secondary %d has priority of %d!\n",num,i));
692 mprintf ((0,"Error! Secondary Num=%d\n",num));
693 Error ("Secondary Weapon is not in order list!!!");
697 //called when a primary weapon is picked up
698 //returns true if actually picked up
699 int pick_up_primary(int weapon_index)
701 //ushort old_flags = Players[Player_num].primary_weapon_flags;
702 ushort flag = 1<<weapon_index;
704 int supposed_weapon=Primary_weapon;
706 if (weapon_index!=LASER_INDEX && Players[Player_num].primary_weapon_flags & flag) { //already have
707 HUD_init_message("%s %s!", TXT_ALREADY_HAVE_THE, PRIMARY_WEAPON_NAMES(weapon_index));
711 Players[Player_num].primary_weapon_flags |= flag;
713 cutpoint=POrderList (255);
715 if (Primary_weapon==LASER_INDEX && Players[Player_num].laser_level>=4)
716 supposed_weapon=SUPER_LASER_INDEX; // allotment for stupid way of doing super laser
719 if (POrderList(weapon_index)<cutpoint && POrderList(weapon_index)<POrderList(supposed_weapon))
720 select_weapon(weapon_index,0,0,1);
722 PALETTE_FLASH_ADD(7,14,21);
723 mprintf ((0,"Weapon index: %d\n",weapon_index));
725 if (weapon_index!=LASER_INDEX)
726 HUD_init_message("%s!",PRIMARY_WEAPON_NAMES(weapon_index));
730 int check_to_use_primary(int weapon_index)
732 ushort old_flags = Players[Player_num].primary_weapon_flags;
733 ushort flag = 1<<weapon_index;
736 cutpoint=POrderList (255);
738 if (!(old_flags & flag) && POrderList(weapon_index)<cutpoint && POrderList(weapon_index)<POrderList(Primary_weapon))
740 if (weapon_index==SUPER_LASER_INDEX)
741 select_weapon(LASER_INDEX,0,0,1);
743 select_weapon(weapon_index,0,0,1);
746 PALETTE_FLASH_ADD(7,14,21);
753 //called when ammo (for the vulcan cannon) is picked up
754 // Returns the amount picked up
755 int pick_up_ammo(int class_flag,int weapon_index,int ammo_count)
757 int max,cutpoint,supposed_weapon=Primary_weapon;
758 int old_ammo=class_flag; //kill warning
760 Assert(class_flag==CLASS_PRIMARY && weapon_index==VULCAN_INDEX);
762 max = Primary_ammo_max[weapon_index];
763 if (Players[Player_num].flags & PLAYER_FLAGS_AMMO_RACK)
766 if (Players[Player_num].primary_ammo[weapon_index] == max)
769 old_ammo = Players[Player_num].primary_ammo[weapon_index];
771 Players[Player_num].primary_ammo[weapon_index] += ammo_count;
773 if (Players[Player_num].primary_ammo[weapon_index] > max) {
774 ammo_count += (max - Players[Player_num].primary_ammo[weapon_index]);
775 Players[Player_num].primary_ammo[weapon_index] = max;
777 cutpoint=POrderList (255);
779 if (Primary_weapon==LASER_INDEX && Players[Player_num].laser_level>=4)
780 supposed_weapon=SUPER_LASER_INDEX; // allotment for stupid way of doing super laser
783 if (Players[Player_num].primary_weapon_flags&(1<<weapon_index) && weapon_index>Primary_weapon && old_ammo==0 &&
784 POrderList(weapon_index)<cutpoint && POrderList(weapon_index)<POrderList(supposed_weapon))
785 select_weapon(weapon_index,0,0,1);
787 return ammo_count; //return amount used
790 #define SMEGA_SHAKE_TIME (F1_0*2)
791 #define MAX_SMEGA_DETONATES 4
792 fix Smega_detonate_times[MAX_SMEGA_DETONATES];
794 // Call this to initialize for a new level.
795 // Sets all super mega missile detonation times to 0 which means there aren't any.
796 void init_smega_detonates(void)
800 for (i=0; i<MAX_SMEGA_DETONATES; i++)
801 Smega_detonate_times[i] = 0;
804 fix Seismic_tremor_magnitude;
805 fix Next_seismic_sound_time;
806 int Seismic_sound_playing = 0;
807 int Seismic_tremor_volume;
809 int Seismic_sound = SOUND_SEISMIC_DISTURBANCE_START;
811 // If a smega missile been detonated, rock the mine!
812 // This should be called every frame.
813 // Maybe this should affect all robots, being called when they get their physics done.
814 void rock_the_mine_frame(void)
818 for (i=0; i<MAX_SMEGA_DETONATES; i++) {
820 if (Smega_detonate_times[i] != 0) {
822 delta_time = GameTime - Smega_detonate_times[i];
824 if (!Seismic_sound_playing) {
825 digi_play_sample_looping(Seismic_sound, F1_0, -1, -1);
826 Seismic_sound_playing = 1;
827 Next_seismic_sound_time = GameTime + d_rand()/2;
830 if (delta_time < SMEGA_SHAKE_TIME) {
832 // Control center destroyed, rock the player's ship.
834 // -- fc = abs(delta_time - SMEGA_SHAKE_TIME/2);
835 // Changed 10/23/95 to make decreasing for super mega missile.
836 fc = (SMEGA_SHAKE_TIME - delta_time)/2;
837 fc /= SMEGA_SHAKE_TIME/32;
844 Seismic_tremor_volume += fc;
846 rx = fixmul(d_rand() - 16384, 3*F1_0/16 + (F1_0*(16-fc))/32);
847 rz = fixmul(d_rand() - 16384, 3*F1_0/16 + (F1_0*(16-fc))/32);
849 ConsoleObject->mtype.phys_info.rotvel.x += rx;
850 ConsoleObject->mtype.phys_info.rotvel.z += rz;
853 if (Buddy_objnum != -1) {
854 Objects[Buddy_objnum].mtype.phys_info.rotvel.x += rx*4;
855 Objects[Buddy_objnum].mtype.phys_info.rotvel.z += rz*4;
858 // Shake a guided missile!
859 Seismic_tremor_magnitude += rx;
862 Smega_detonate_times[i] = 0;
867 // Hook in the rumble sound effect here.
870 extern int Level_shake_frequency, Level_shake_duration;
872 extern void multi_send_seismic (fix,fix);
875 #define SEISMIC_DISTURBANCE_DURATION (F1_0*5)
876 fix Seismic_disturbance_start_time = 0, Seismic_disturbance_end_time;
880 int on_seismic_level(void)
882 return Seismic_level;
885 void init_seismic_disturbances(void)
887 Seismic_disturbance_start_time = 0;
888 Seismic_disturbance_end_time = 0;
891 // Return true if time to start a seismic disturbance.
892 int start_seismic_disturbance(void)
896 if (Level_shake_duration < 1)
899 rval = (2 * fixmul(d_rand(), Level_shake_frequency)) < FrameTime;
902 Seismic_disturbance_start_time = GameTime;
903 Seismic_disturbance_end_time = GameTime + Level_shake_duration;
904 if (!Seismic_sound_playing) {
905 digi_play_sample_looping(Seismic_sound, F1_0, -1, -1);
906 Seismic_sound_playing = 1;
907 Next_seismic_sound_time = GameTime + d_rand()/2;
911 if (Game_mode & GM_MULTI)
912 multi_send_seismic (Seismic_disturbance_start_time,Seismic_disturbance_end_time);
919 void seismic_disturbance_frame(void)
921 if (Level_shake_frequency) {
922 if (((Seismic_disturbance_start_time < GameTime) && (Seismic_disturbance_end_time > GameTime)) || start_seismic_disturbance()) {
926 delta_time = GameTime - Seismic_disturbance_start_time;
928 fc = abs(delta_time - (Seismic_disturbance_end_time - Seismic_disturbance_start_time)/2);
936 Seismic_tremor_volume += fc;
938 rx = fixmul(d_rand() - 16384, 3*F1_0/16 + (F1_0*(16-fc))/32);
939 rz = fixmul(d_rand() - 16384, 3*F1_0/16 + (F1_0*(16-fc))/32);
941 ConsoleObject->mtype.phys_info.rotvel.x += rx;
942 ConsoleObject->mtype.phys_info.rotvel.z += rz;
945 if (Buddy_objnum != -1) {
946 Objects[Buddy_objnum].mtype.phys_info.rotvel.x += rx*4;
947 Objects[Buddy_objnum].mtype.phys_info.rotvel.z += rz*4;
950 // Shake a guided missile!
951 Seismic_tremor_magnitude += rx;
957 // Call this when a smega detonates to start the process of rocking the mine.
958 void smega_rock_stuff(void)
962 for (i=0; i<MAX_SMEGA_DETONATES; i++) {
963 if (Smega_detonate_times[i] + SMEGA_SHAKE_TIME < GameTime)
964 Smega_detonate_times[i] = 0;
967 for (i=0; i<MAX_SMEGA_DETONATES; i++) {
968 if (Smega_detonate_times[i] == 0) {
969 Smega_detonate_times[i] = GameTime;
975 int Super_mines_yes = 1;
977 // Call this once/frame to process all super mines in the level.
978 void process_super_mines_frame(void)
983 // If we don't know of there being any super mines in the level, just
984 // check every 8th object each frame.
985 if (Super_mines_yes == 0) {
986 start = FrameCount & 7;
995 for (i=start; i<=Highest_object_index; i+=add) {
996 if ((Objects[i].type == OBJ_WEAPON) && (Objects[i].id == SUPERPROX_ID)) {
999 parent_num = Objects[i].ctype.laser_info.parent_num;
1001 Super_mines_yes = 1;
1002 if (Objects[i].lifeleft + F1_0*2 < Weapon_info[SUPERPROX_ID].lifetime) {
1003 vms_vector *bombpos;
1005 bombpos = &Objects[i].pos;
1007 for (j=0; j<=Highest_object_index; j++) {
1008 if ((Objects[j].type == OBJ_PLAYER) || (Objects[j].type == OBJ_ROBOT)) {
1011 dist = vm_vec_dist_quick(bombpos, &Objects[j].pos);
1013 if (j != parent_num)
1014 if (dist - Objects[j].size < F1_0*20)
1016 if (Objects[i].segnum == Objects[j].segnum)
1017 Objects[i].lifeleft = 1;
1019 // Object which is close enough to detonate smart mine is not in same segment as smart mine.
1020 // Need to do a more expensive check to make sure there isn't an obstruction.
1021 if (((FrameCount ^ (i+j)) % 4) == 0) {
1026 mprintf((0, "Expensive proxmine collision check. Frame %i\n", FrameCount));
1028 fq.startseg = Objects[i].segnum;
1029 fq.p0 = &Objects[i].pos;
1030 fq.p1 = &Objects[j].pos;
1033 fq.ignore_obj_list = NULL;
1036 fate = find_vector_intersection(&fq, &hit_data);
1037 if (fate != HIT_WALL)
1038 Objects[i].lifeleft = 1;
1050 #define SPIT_SPEED 20
1052 //this function is for when the player intentionally drops a powerup
1053 //this function is based on drop_powerup()
1054 int spit_powerup(object *spitter, int id,int seed)
1058 vms_vector new_velocity, new_pos;
1062 vm_vec_scale_add(&new_velocity,&spitter->mtype.phys_info.velocity,&spitter->orient.fvec,i2f(SPIT_SPEED));
1064 new_velocity.x += (d_rand() - 16384) * SPIT_SPEED * 2;
1065 new_velocity.y += (d_rand() - 16384) * SPIT_SPEED * 2;
1066 new_velocity.z += (d_rand() - 16384) * SPIT_SPEED * 2;
1068 // Give keys zero velocity so they can be tracked better in multi
1070 if ((Game_mode & GM_MULTI) && (id >= POW_KEY_BLUE) && (id <= POW_KEY_GOLD))
1071 vm_vec_zero(&new_velocity);
1073 //there's a piece of code which lets the player pick up a powerup if
1074 //the distance between him and the powerup is less than 2 time their
1075 //combined radii. So we need to create powerups pretty far out from
1078 vm_vec_scale_add(&new_pos,&spitter->pos,&spitter->orient.fvec,spitter->size);
1081 if (Game_mode & GM_MULTI)
1083 if (Net_create_loc >= MAX_NET_CREATE_OBJECTS)
1085 mprintf( (0, "WEAPON:Not enough slots to drop all powerups!\n" ));
1091 objnum = obj_create( OBJ_POWERUP, id, spitter->segnum, &new_pos, &vmd_identity_matrix, Powerup_info[id].size, CT_POWERUP, MT_PHYSICS, RT_POWERUP);
1094 mprintf((1, "Can't create object in object_create_egg. Aborting.\n"));
1099 obj = &Objects[objnum];
1101 obj->mtype.phys_info.velocity = new_velocity;
1102 obj->mtype.phys_info.drag = 512; //1024;
1103 obj->mtype.phys_info.mass = F1_0;
1105 obj->mtype.phys_info.flags = PF_BOUNCE;
1107 obj->rtype.vclip_info.vclip_num = Powerup_info[obj->id].vclip_num;
1108 obj->rtype.vclip_info.frametime = Vclip[obj->rtype.vclip_info.vclip_num].frame_time;
1109 obj->rtype.vclip_info.framenum = 0;
1111 if (spitter == ConsoleObject)
1112 obj->ctype.powerup_info.flags |= PF_SPAT_BY_PLAYER;
1117 case POW_SHIELD_BOOST:
1119 obj->lifeleft = (d_rand() + F1_0*3) * 64; // Lives for 3 to 3.5 binary minutes (a binary minute is 64 seconds)
1120 if (Game_mode & GM_MULTI)
1124 //if (Game_mode & GM_MULTI)
1125 // obj->lifeleft = (d_rand() + F1_0*3) * 64; // Lives for 5 to 5.5 binary minutes (a binary minute is 64 seconds)
1132 void DropCurrentWeapon ()
1134 int objnum,ammo=0,seed;
1136 if (Primary_weapon==0)
1138 HUD_init_message("You cannot drop your base weapon!");
1142 HUD_init_message("%s dropped!",PRIMARY_WEAPON_NAMES(Primary_weapon));
1143 digi_play_sample (SOUND_DROP_WEAPON,F1_0);
1147 objnum = spit_powerup(ConsoleObject,Primary_weapon_to_powerup[Primary_weapon],seed);
1152 if (Primary_weapon == VULCAN_INDEX || Primary_weapon == GAUSS_INDEX) {
1154 //if it's one of these, drop some ammo with the weapon
1156 ammo = Players[Player_num].primary_ammo[VULCAN_INDEX];
1158 if ((Players[Player_num].primary_weapon_flags & HAS_FLAG(VULCAN_INDEX)) && (Players[Player_num].primary_weapon_flags & HAS_FLAG(GAUSS_INDEX)))
1159 ammo /= 2; //if both vulcan & gauss, drop half
1161 Players[Player_num].primary_ammo[VULCAN_INDEX] -= ammo;
1164 Objects[objnum].ctype.powerup_info.count = ammo;
1167 if (Primary_weapon == OMEGA_INDEX) {
1169 //dropped weapon has current energy
1172 Objects[objnum].ctype.powerup_info.count = Omega_charge;
1176 if ((Game_mode & GM_MULTI) && objnum>-1)
1177 multi_send_drop_weapon(objnum,seed);
1180 Players[Player_num].primary_weapon_flags &= (~(1<<Primary_weapon));
1181 auto_select_weapon (0);
1185 void DropSecondaryWeapon ()
1189 if (Players[Player_num].secondary_ammo[Secondary_weapon] ==0)
1191 HUD_init_message("No secondary weapon to drop!");
1195 if ((Secondary_weapon_to_powerup[Secondary_weapon]==POW_PROXIMITY_WEAPON ||
1196 Secondary_weapon_to_powerup[Secondary_weapon]==POW_SMART_MINE) &&
1197 Players[Player_num].secondary_ammo[Secondary_weapon]<4)
1199 HUD_init_message("You need at least 4 to drop!");
1203 HUD_init_message("%s dropped!",SECONDARY_WEAPON_NAMES(Secondary_weapon));
1204 digi_play_sample (SOUND_DROP_WEAPON,F1_0);
1208 objnum = spit_powerup(ConsoleObject,Secondary_weapon_to_powerup[Secondary_weapon],seed);
1215 if ((Game_mode & GM_MULTI) && objnum>-1)
1216 multi_send_drop_weapon(objnum,seed);
1219 if (Secondary_weapon_to_powerup[Secondary_weapon]==POW_PROXIMITY_WEAPON ||
1220 Secondary_weapon_to_powerup[Secondary_weapon]==POW_SMART_MINE)
1221 Players[Player_num].secondary_ammo[Secondary_weapon]-=4;
1223 Players[Player_num].secondary_ammo[Secondary_weapon]--;
1225 if (Players[Player_num].secondary_ammo[Secondary_weapon]==0)
1227 Players[Player_num].secondary_weapon_flags &= (~(1<<Secondary_weapon));
1228 auto_select_weapon (1);
1232 // ---------------------------------------------------------------------------------------
1233 // Do seismic disturbance stuff including the looping sounds with changing volume.
1234 void do_seismic_stuff(void)
1238 stv_save = Seismic_tremor_volume;
1239 Seismic_tremor_magnitude = 0;
1240 Seismic_tremor_volume = 0;
1242 rock_the_mine_frame();
1243 seismic_disturbance_frame();
1245 if (stv_save != 0) {
1246 if (Seismic_tremor_volume == 0) {
1247 digi_stop_looping_sound();
1248 Seismic_sound_playing = 0;
1251 if ((GameTime > Next_seismic_sound_time) && Seismic_tremor_volume) {
1254 volume = Seismic_tremor_volume * 2048;
1257 digi_change_looping_volume(volume);
1258 Next_seismic_sound_time = GameTime + d_rand()/4 + 8192;
1264 int tactile_fire_duration[]={120,80,150,250,150,200,100,180,280,100};
1265 int tactile_fire_repeat[]={260,90,160,160,160,210,110,191,291,111};
1267 void tactile_set_button_jolt ()
1273 static int stickmag=-1;
1276 dur=tactile_fire_duration[Primary_weapon];
1277 rep=tactile_fire_repeat[Primary_weapon];
1283 if (t=FindArg("-stickmag"))
1284 stickmag=atoi (Args[t+1]);
1288 infile=(FILE *)fopen ("stick.val","rt");
1293 fscanf (infile,"%d %d\n",&tactile_fire_duration[i],&tactile_fire_repeat[i]);
1294 mprintf ((0,"scan value[%d]=%d\n",i,tactile_fire_duration[i]));
1299 ButtonReflexJolt (0,stickmag,0,dur,rep);
1305 * reads n weapon_info structs from a CFILE
1307 extern int weapon_info_read_n(weapon_info *wi, int n, CFILE *fp, int file_version)
1311 for (i = 0; i < n; i++) {
1312 wi[i].render_type = cfile_read_byte(fp);
1313 wi[i].persistent = cfile_read_byte(fp);
1314 wi[i].model_num = cfile_read_short(fp);
1315 wi[i].model_num_inner = cfile_read_short(fp);
1317 wi[i].flash_vclip = cfile_read_byte(fp);
1318 wi[i].robot_hit_vclip = cfile_read_byte(fp);
1319 wi[i].flash_sound = cfile_read_short(fp);
1321 wi[i].wall_hit_vclip = cfile_read_byte(fp);
1322 wi[i].fire_count = cfile_read_byte(fp);
1323 wi[i].robot_hit_sound = cfile_read_short(fp);
1325 wi[i].ammo_usage = cfile_read_byte(fp);
1326 wi[i].weapon_vclip = cfile_read_byte(fp);
1327 wi[i].wall_hit_sound = cfile_read_short(fp);
1329 wi[i].destroyable = cfile_read_byte(fp);
1330 wi[i].matter = cfile_read_byte(fp);
1331 wi[i].bounce = cfile_read_byte(fp);
1332 wi[i].homing_flag = cfile_read_byte(fp);
1334 wi[i].speedvar = cfile_read_byte(fp);
1335 wi[i].flags = cfile_read_byte(fp);
1336 wi[i].flash = cfile_read_byte(fp);
1337 wi[i].afterburner_size = cfile_read_byte(fp);
1339 if (file_version >= 3)
1340 wi[i].children = cfile_read_byte(fp);
1342 wi[i].children = -1;
1344 wi[i].energy_usage = cfile_read_fix(fp);
1345 wi[i].fire_wait = cfile_read_fix(fp);
1347 if (file_version >= 3)
1348 wi[i].multi_damage_scale = cfile_read_fix(fp);
1350 wi[i].multi_damage_scale = F1_0;
1352 bitmap_index_read(&wi[i].bitmap, fp);
1354 wi[i].blob_size = cfile_read_fix(fp);
1355 wi[i].flash_size = cfile_read_fix(fp);
1356 wi[i].impact_size = cfile_read_fix(fp);
1357 for (j = 0; j < NDL; j++)
1358 wi[i].strength[j] = cfile_read_fix(fp);
1359 for (j = 0; j < NDL; j++)
1360 wi[i].speed[j] = cfile_read_fix(fp);
1361 wi[i].mass = cfile_read_fix(fp);
1362 wi[i].drag = cfile_read_fix(fp);
1363 wi[i].thrust = cfile_read_fix(fp);
1364 wi[i].po_len_to_width_ratio = cfile_read_fix(fp);
1365 wi[i].light = cfile_read_fix(fp);
1366 wi[i].lifetime = cfile_read_fix(fp);
1367 wi[i].damage_radius = cfile_read_fix(fp);
1368 bitmap_index_read(&wi[i].picture, fp);
1369 if (file_version >= 3)
1370 bitmap_index_read(&wi[i].hires_picture, fp);
1372 wi[i].hires_picture.index = wi[i].picture.index;