1 /* $Id: weapon.c,v 1.10 2004-08-28 23:17:45 schaffner Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Functions for weapons...
26 static char rcsid[] = "$Id: weapon.c,v 1.10 2004-08-28 23:17:45 schaffner Exp $";
54 int POrderList (int num);
55 int SOrderList (int num);
56 // Note, only Vulcan cannon requires ammo.
57 // NOTE: Now Vulcan and Gauss require ammo. -5/3/95 Yuan
58 //ubyte Default_primary_ammo_level[MAX_PRIMARY_WEAPONS] = {255, 0, 255, 255, 255};
59 //ubyte Default_secondary_ammo_level[MAX_SECONDARY_WEAPONS] = {3, 0, 0, 0, 0};
61 // Convert primary weapons to indices in Weapon_info array.
62 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};
63 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};
65 //for each Secondary weapon, which gun it fires out of
66 ubyte Secondary_weapon_to_gun_num[MAX_SECONDARY_WEAPONS] = {4,4,7,7,7,4,4,7,4,7};
68 int Primary_ammo_max[MAX_PRIMARY_WEAPONS] = {0, VULCAN_AMMO_MAX, 0, 0, 0, 0, VULCAN_AMMO_MAX, 0, 0, 0};
69 ubyte Secondary_ammo_max[MAX_SECONDARY_WEAPONS] = {20, 10, 10, 5, 5, 20, 20, 15, 10, 10};
71 //for each primary weapon, what kind of powerup gives weapon
72 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};
74 //for each Secondary weapon, what kind of powerup gives weapon
75 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};
77 weapon_info Weapon_info[MAX_WEAPON_TYPES];
79 sbyte Primary_weapon, Secondary_weapon;
81 // autoselect ordering
83 ubyte PrimaryOrder[]={9,8,7,6,5,4,3,2,1,0,255};
84 ubyte SecondaryOrder[]={9,8,4,3,1,5,0,255,7,6,2};
86 ubyte DefaultPrimaryOrder[]={9,8,7,6,5,4,3,2,1,0,255};
87 ubyte DefaultSecondaryOrder[]={9,8,4,3,1,5,0,255,7,6,2};
89 // Cycling weapon key pressed?
93 //allow player to reorder menus?
94 extern ubyte MenuReordering;
96 //char *Primary_weapon_names[MAX_PRIMARY_WEAPONS] = {
99 // "Spreadfire Cannon",
104 //char *Secondary_weapon_names[MAX_SECONDARY_WEAPONS] = {
105 // "Concussion Missile",
112 //char *Primary_weapon_names_short[MAX_PRIMARY_WEAPONS] = {
120 //char *Secondary_weapon_names_short[MAX_SECONDARY_WEAPONS] = {
121 // "Concsn\nMissile",
122 // "Homing\nMissile",
128 sbyte Weapon_is_energy[MAX_WEAPON_TYPES] = {
139 // ; (0) Laser Level 1
140 // ; (1) Laser Level 2
141 // ; (2) Laser Level 3
142 // ; (3) Laser Level 4
147 // ; (8) ---------- Concussion Missile ----------
148 // ; (9) ---------- Flare ----------
149 // ; (10) ---------- Blue laser that blue guy shoots -----------
150 // ; (11) ---------- Vulcan Cannon ----------
151 // ; (12) ---------- Spreadfire Cannon ----------
152 // ; (13) ---------- Plasma Cannon ----------
153 // ; (14) ---------- Fusion Cannon ----------
154 // ; (15) ---------- Homing Missile ----------
155 // ; (16) ---------- Proximity Bomb ----------
156 // ; (17) ---------- Smart Missile ----------
157 // ; (18) ---------- Mega Missile ----------
158 // ; (19) ---------- Children of the PLAYER'S Smart Missile ----------
159 // ; (20) ---------- Bad Guy Spreadfire Laser ----------
160 // ; (21) ---------- SuperMech Homing Missile ----------
161 // ; (22) ---------- Regular Mech's missile -----------
162 // ; (23) ---------- Silent Spreadfire Laser ----------
163 // ; (24) ---------- Red laser that baby spiders shoot -----------
164 // ; (25) ---------- Green laser that rifleman shoots -----------
165 // ; (26) ---------- Plasma gun that 'plasguy' fires ------------
166 // ; (27) ---------- Blobs fired by Red Spiders -----------
167 // ; (28) ---------- Final Boss's Mega Missile ----------
168 // ; (29) ---------- Children of the ROBOT'S Smart Missile ----------
169 // ; (30) Laser Level 5
170 // ; (31) Laser Level 6
171 // ; (32) ---------- Super Vulcan Cannon ----------
172 // ; (33) ---------- Super Spreadfire Cannon ----------
173 // ; (34) ---------- Super Plasma Cannon ----------
174 // ; (35) ---------- Super Fusion Cannon ----------
176 // ------------------------------------------------------------------------------------
182 // See weapon.h for bit values
183 int player_has_weapon(int weapon_num, int secondary_flag)
185 int return_value = 0;
188 // Hack! If energy goes negative, you can't fire a weapon that doesn't require energy.
189 // But energy should not go negative (but it does), so find out why it does!
190 if (Players[Player_num].energy < 0)
191 Players[Player_num].energy = 0;
193 if (!secondary_flag) {
194 weapon_index = Primary_weapon_to_weapon_info[weapon_num];
196 if (Players[Player_num].primary_weapon_flags & (1 << weapon_num))
197 return_value |= HAS_WEAPON_FLAG;
199 // Special case: Gauss cannon uses vulcan ammo.
200 if (weapon_num == GAUSS_INDEX) {
201 if (Weapon_info[weapon_index].ammo_usage <= Players[Player_num].primary_ammo[VULCAN_INDEX])
202 return_value |= HAS_AMMO_FLAG;
204 if (Weapon_info[weapon_index].ammo_usage <= Players[Player_num].primary_ammo[weapon_num])
205 return_value |= HAS_AMMO_FLAG;
207 if (weapon_num == OMEGA_INDEX) { // Hack: Make sure player has energy to omega
208 if (Players[Player_num].energy || Omega_charge)
209 return_value |= HAS_ENERGY_FLAG;
211 if (Weapon_info[weapon_index].energy_usage <= Players[Player_num].energy)
212 return_value |= HAS_ENERGY_FLAG;
215 weapon_index = Secondary_weapon_to_weapon_info[weapon_num];
217 if (Players[Player_num].secondary_weapon_flags & (1 << weapon_num))
218 return_value |= HAS_WEAPON_FLAG;
220 if (Weapon_info[weapon_index].ammo_usage <= Players[Player_num].secondary_ammo[weapon_num])
221 return_value |= HAS_AMMO_FLAG;
223 if (Weapon_info[weapon_index].energy_usage <= Players[Player_num].energy)
224 return_value |= HAS_ENERGY_FLAG;
230 void InitWeaponOrdering ()
232 // short routine to setup default weapon priorities for new pilots
236 for (i=0;i<MAX_PRIMARY_WEAPONS+1;i++)
237 PrimaryOrder[i]=DefaultPrimaryOrder[i];
238 for (i=0;i<MAX_SECONDARY_WEAPONS+1;i++)
239 SecondaryOrder[i]=DefaultSecondaryOrder[i];
244 mprintf ((0,"Cycling primary!\n"));
246 auto_select_weapon (0);
250 void CycleSecondary ()
252 mprintf ((0,"Cycling secondary!\n"));
254 auto_select_weapon (1);
259 // ------------------------------------------------------------------------------------
260 //if message flag set, print message saying selected
261 void select_weapon(int weapon_num, int secondary_flag, int print_message, int wait_for_rearm)
265 if (Newdemo_state==ND_STATE_RECORDING )
266 newdemo_record_player_weapon(secondary_flag, weapon_num);
268 if (!secondary_flag) {
269 if (Primary_weapon != weapon_num) {
270 if (wait_for_rearm) digi_play_sample_once( SOUND_GOOD_SELECTION_PRIMARY, F1_0 );
272 if (Game_mode & GM_MULTI) {
273 if (wait_for_rearm) multi_send_play_sound(SOUND_GOOD_SELECTION_PRIMARY, F1_0);
277 Next_laser_fire_time = GameTime + REARM_TIME;
279 Next_laser_fire_time = 0;
280 Global_laser_firing_count = 0;
282 // Select super version if available.
286 ; // -- MK, only plays when can't fire weapon anyway, fixes bug -- digi_play_sample_once( SOUND_ALREADY_SELECTED, F1_0 );
288 digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
291 Primary_weapon = weapon_num;
292 weapon_name = PRIMARY_WEAPON_NAMES(weapon_num);
293 #if defined (TACTILE)
294 tactile_set_button_jolt();
298 //save flag for whether was super version
299 Primary_last_was_super[weapon_num % SUPER_WEAPON] = (weapon_num >= SUPER_WEAPON);
303 if (Secondary_weapon != weapon_num) {
304 if (wait_for_rearm) digi_play_sample_once( SOUND_GOOD_SELECTION_SECONDARY, F1_0 );
306 if (Game_mode & GM_MULTI) {
307 if (wait_for_rearm) multi_send_play_sound(SOUND_GOOD_SELECTION_PRIMARY, F1_0);
311 Next_missile_fire_time = GameTime + REARM_TIME;
313 Next_missile_fire_time = 0;
314 Global_missile_firing_count = 0;
319 digi_play_sample_once( SOUND_ALREADY_SELECTED, F1_0 );
321 digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
325 Secondary_weapon = weapon_num;
326 weapon_name = SECONDARY_WEAPON_NAMES(weapon_num);
328 //save flag for whether was super version
329 Secondary_last_was_super[weapon_num % SUPER_WEAPON] = (weapon_num >= SUPER_WEAPON);
334 if (weapon_num == LASER_INDEX && !secondary_flag)
335 HUD_init_message("%s Level %d %s", weapon_name, Players[Player_num].laser_level+1, TXT_SELECTED);
337 HUD_init_message("%s %s", weapon_name, TXT_SELECTED);
342 //flags whether the last time we use this weapon, it was the 'super' version
343 ubyte Primary_last_was_super[MAX_PRIMARY_WEAPONS];
344 ubyte Secondary_last_was_super[MAX_SECONDARY_WEAPONS];
346 // ------------------------------------------------------------------------------------
347 // Select a weapon, primary or secondary.
348 void do_weapon_select(int weapon_num, int secondary_flag)
350 int weapon_num_save=weapon_num;
351 int weapon_status,current,has_flag;
352 ubyte last_was_super;
354 if (!secondary_flag) {
355 current = Primary_weapon;
356 last_was_super = Primary_last_was_super[weapon_num];
357 has_flag = HAS_WEAPON_FLAG;
360 current = Secondary_weapon;
361 last_was_super = Secondary_last_was_super[weapon_num];
362 has_flag = HAS_WEAPON_FLAG+HAS_AMMO_FLAG;
365 if (current == weapon_num || current == weapon_num+SUPER_WEAPON) {
367 //already have this selected, so toggle to other of normal/super version
369 weapon_num += weapon_num+SUPER_WEAPON - current;
370 weapon_status = player_has_weapon(weapon_num, secondary_flag);
374 //go to last-select version of requested missile
377 weapon_num += SUPER_WEAPON;
379 weapon_status = player_has_weapon(weapon_num, secondary_flag);
381 //if don't have last-selected, try other version
383 if ((weapon_status & has_flag) != has_flag) {
384 weapon_num = 2*weapon_num_save+SUPER_WEAPON - weapon_num;
385 weapon_status = player_has_weapon(weapon_num, secondary_flag);
386 if ((weapon_status & has_flag) != has_flag)
387 weapon_num = 2*weapon_num_save+SUPER_WEAPON - weapon_num;
391 //if we don't have the weapon we're switching to, give error & bail
392 if ((weapon_status & has_flag) != has_flag) {
393 if (!secondary_flag) {
394 if (weapon_num==SUPER_LASER_INDEX)
395 return; //no such thing as super laser, so no error
396 HUD_init_message("%s %s!", TXT_DONT_HAVE, PRIMARY_WEAPON_NAMES(weapon_num));
399 HUD_init_message("%s %s%s",TXT_HAVE_NO, SECONDARY_WEAPON_NAMES(weapon_num), TXT_SX);
400 digi_play_sample( SOUND_BAD_SELECTION, F1_0 );
404 //now actually select the weapon
405 select_weapon(weapon_num, secondary_flag, 1, 1);
408 // ----------------------------------------------------------------------------------------
409 // Automatically select next best weapon if unable to fire current weapon.
410 // Weapon type: 0==primary, 1==secondary
411 void auto_select_weapon(int weapon_type)
417 if (weapon_type==0) {
418 r = player_has_weapon(Primary_weapon, 0);
419 if (r != HAS_ALL || Cycling) {
423 cur_weapon = POrderList(Primary_weapon);
424 cutpoint = POrderList (255);
429 if (cur_weapon>=cutpoint)
435 HUD_init_message(TXT_NO_PRIMARY);
438 ButtonReflexClear(0);
440 select_weapon(0, 0, 0, 1);
443 select_weapon (Primary_weapon,0,0,1);
453 if (cur_weapon==MAX_PRIMARY_WEAPONS)
456 // Hack alert! Because the fusion uses 0 energy at the end (it's got the weird chargeup)
457 // it looks like it takes 0 to fire, but it doesn't, so never auto-select.
458 // if (PrimaryOrder[cur_weapon] == FUSION_INDEX)
461 if (PrimaryOrder[cur_weapon] == Primary_weapon) {
464 HUD_init_message(TXT_NO_PRIMARY);
467 ButtonReflexClear(0);
470 // if (POrderList(0)<POrderList(255))
471 select_weapon(0, 0, 0, 1);
474 select_weapon (Primary_weapon,0,0,1);
476 try_again = 0; // Tried all weapons!
478 } else if (PrimaryOrder[cur_weapon]!=255 && player_has_weapon(PrimaryOrder[cur_weapon], 0) == HAS_ALL) {
479 select_weapon(PrimaryOrder[cur_weapon], 0, 1, 1 );
487 Assert(weapon_type==1);
488 r = player_has_weapon(Secondary_weapon, 1);
489 if (r != HAS_ALL || Cycling) {
493 cur_weapon = SOrderList(Secondary_weapon);
494 cutpoint = SOrderList (255);
500 if (cur_weapon>=cutpoint)
505 HUD_init_message("No secondary weapons selected!");
507 select_weapon (Secondary_weapon,1,0,1);
515 if (cur_weapon==MAX_SECONDARY_WEAPONS)
518 if (SecondaryOrder[cur_weapon] == Secondary_weapon) {
520 HUD_init_message("No secondary weapons available!");
522 select_weapon (Secondary_weapon,1,0,1);
524 try_again = 0; // Tried all weapons!
525 } else if (player_has_weapon(SecondaryOrder[cur_weapon], 1) == HAS_ALL) {
526 select_weapon(SecondaryOrder[cur_weapon], 1, 1, 1 );
539 // ----------------------------------------------------------------------------------------
540 // Show player which weapons he has, how much ammo...
541 // Looks like a debug screen now because it writes to mono screen, but that will change...
542 void show_weapon_status(void)
546 for (i=0; i<MAX_PRIMARY_WEAPONS; i++) {
547 if (Players[Player_num].primary_weapon_flags & (1 << i))
548 mprintf((0, "HAVE"));
552 mprintf((0, " Weapon: %20s, charges: %4i\n", PRIMARY_WEAPON_NAMES(i), Players[Player_num].primary_ammo[i]));
556 for (i=0; i<MAX_SECONDARY_WEAPONS; i++) {
557 if (Players[Player_num].secondary_weapon_flags & (1 << i))
558 mprintf((0, "HAVE"));
562 mprintf((0, " Weapon: %20s, charges: %4i\n", SECONDARY_WEAPON_NAMES(i), Players[Player_num].secondary_ammo[i]));
572 // ---------------------------------------------------------------------
573 //called when one of these weapons is picked up
574 //when you pick up a secondary, you always get the weapon & ammo for it
575 // Returns true if powerup picked up, else returns false.
576 int pick_up_secondary(int weapon_index,int count)
582 max = Secondary_ammo_max[weapon_index];
584 if (Players[Player_num].flags & PLAYER_FLAGS_AMMO_RACK)
587 if (Players[Player_num].secondary_ammo[weapon_index] >= max) {
588 HUD_init_message("%s %i %ss!", TXT_ALREADY_HAVE, Players[Player_num].secondary_ammo[weapon_index],SECONDARY_WEAPON_NAMES(weapon_index));
592 Players[Player_num].secondary_weapon_flags |= (1<<weapon_index);
593 Players[Player_num].secondary_ammo[weapon_index] += count;
595 num_picked_up = count;
596 if (Players[Player_num].secondary_ammo[weapon_index] > max) {
597 num_picked_up = count - (Players[Player_num].secondary_ammo[weapon_index] - max);
598 Players[Player_num].secondary_ammo[weapon_index] = max;
601 cutpoint=SOrderList (255);
602 if (SOrderList (weapon_index)<cutpoint && ((SOrderList (weapon_index) < SOrderList(Secondary_weapon)) || (Players[Player_num].secondary_ammo[Secondary_weapon] == 0)) )
603 select_weapon(weapon_index,1, 0, 1);
605 //if we don't auto-select this weapon, but it's a proxbomb or smart mine,
606 //we want to do a mini-auto-selection that applies to the drop bomb key
608 if ((weapon_index == PROXIMITY_INDEX || weapon_index == SMART_MINE_INDEX) &&
609 !(Secondary_weapon == PROXIMITY_INDEX || Secondary_weapon == SMART_MINE_INDEX)) {
612 cur = Secondary_last_was_super[PROXIMITY_INDEX]?SMART_MINE_INDEX:PROXIMITY_INDEX;
614 if (SOrderList (weapon_index) < SOrderList(cur))
615 Secondary_last_was_super[PROXIMITY_INDEX] = (weapon_index == SMART_MINE_INDEX);
619 //note: flash for all but concussion was 7,14,21
621 PALETTE_FLASH_ADD(15,15,15);
622 HUD_init_message("%d %s%s",num_picked_up,SECONDARY_WEAPON_NAMES(weapon_index), TXT_SX);
625 PALETTE_FLASH_ADD(10,10,10);
626 HUD_init_message("%s!",SECONDARY_WEAPON_NAMES(weapon_index));
632 void ReorderPrimary ()
634 newmenu_item m[MAX_PRIMARY_WEAPONS+1];
637 for (i=0;i<MAX_PRIMARY_WEAPONS+1;i++)
639 m[i].type=NM_TYPE_MENU;
640 if (PrimaryOrder[i]==255)
641 m[i].text="
\88\88\88\88\88\88\88 Never autoselect
\88\88\88\88\88\88\88";
643 m[i].text=(char *)PRIMARY_WEAPON_NAMES(PrimaryOrder[i]);
644 m[i].value=PrimaryOrder[i];
647 i = newmenu_do("Reorder Primary","Shift+Up/Down arrow to move item", i, m, NULL);
650 for (i=0;i<MAX_PRIMARY_WEAPONS+1;i++)
651 PrimaryOrder[i]=m[i].value;
654 void ReorderSecondary ()
656 newmenu_item m[MAX_SECONDARY_WEAPONS+1];
659 for (i=0;i<MAX_SECONDARY_WEAPONS+1;i++)
661 m[i].type=NM_TYPE_MENU;
662 if (SecondaryOrder[i]==255)
663 m[i].text="
\88\88\88\88\88\88\88 Never autoselect
\88\88\88\88\88\88\88";
665 m[i].text=(char *)SECONDARY_WEAPON_NAMES(SecondaryOrder[i]);
666 m[i].value=SecondaryOrder[i];
669 i = newmenu_do("Reorder Secondary","Shift+Up/Down arrow to move item", i, m, NULL);
671 for (i=0;i<MAX_SECONDARY_WEAPONS+1;i++)
672 SecondaryOrder[i]=m[i].value;
675 int POrderList (int num)
679 for (i=0;i<MAX_PRIMARY_WEAPONS+1;i++)
680 if (PrimaryOrder[i]==num)
682 mprintf ((0,"Primary %d has priority of %d!\n",num,i));
685 Error ("Primary Weapon is not in order list!!!");
688 int SOrderList (int num)
692 for (i=0;i<MAX_SECONDARY_WEAPONS+1;i++)
693 if (SecondaryOrder[i]==num)
695 mprintf ((0,"Secondary %d has priority of %d!\n",num,i));
698 mprintf ((0,"Error! Secondary Num=%d\n",num));
699 Error ("Secondary Weapon is not in order list!!!");
703 //called when a primary weapon is picked up
704 //returns true if actually picked up
705 int pick_up_primary(int weapon_index)
707 //ushort old_flags = Players[Player_num].primary_weapon_flags;
708 ushort flag = 1<<weapon_index;
710 int supposed_weapon=Primary_weapon;
712 if (weapon_index!=LASER_INDEX && Players[Player_num].primary_weapon_flags & flag) { //already have
713 HUD_init_message("%s %s!", TXT_ALREADY_HAVE_THE, PRIMARY_WEAPON_NAMES(weapon_index));
717 Players[Player_num].primary_weapon_flags |= flag;
719 cutpoint=POrderList (255);
721 if (Primary_weapon==LASER_INDEX && Players[Player_num].laser_level>=4)
722 supposed_weapon=SUPER_LASER_INDEX; // allotment for stupid way of doing super laser
725 if (POrderList(weapon_index)<cutpoint && POrderList(weapon_index)<POrderList(supposed_weapon))
726 select_weapon(weapon_index,0,0,1);
728 PALETTE_FLASH_ADD(7,14,21);
729 mprintf ((0,"Weapon index: %d\n",weapon_index));
731 if (weapon_index!=LASER_INDEX)
732 HUD_init_message("%s!",PRIMARY_WEAPON_NAMES(weapon_index));
736 int check_to_use_primary(int weapon_index)
738 ushort old_flags = Players[Player_num].primary_weapon_flags;
739 ushort flag = 1<<weapon_index;
742 cutpoint=POrderList (255);
744 if (!(old_flags & flag) && POrderList(weapon_index)<cutpoint && POrderList(weapon_index)<POrderList(Primary_weapon))
746 if (weapon_index==SUPER_LASER_INDEX)
747 select_weapon(LASER_INDEX,0,0,1);
749 select_weapon(weapon_index,0,0,1);
752 PALETTE_FLASH_ADD(7,14,21);
759 //called when ammo (for the vulcan cannon) is picked up
760 // Returns the amount picked up
761 int pick_up_ammo(int class_flag,int weapon_index,int ammo_count)
763 int max,cutpoint,supposed_weapon=Primary_weapon;
764 int old_ammo=class_flag; //kill warning
766 Assert(class_flag==CLASS_PRIMARY && weapon_index==VULCAN_INDEX);
768 max = Primary_ammo_max[weapon_index];
769 if (Players[Player_num].flags & PLAYER_FLAGS_AMMO_RACK)
772 if (Players[Player_num].primary_ammo[weapon_index] == max)
775 old_ammo = Players[Player_num].primary_ammo[weapon_index];
777 Players[Player_num].primary_ammo[weapon_index] += ammo_count;
779 if (Players[Player_num].primary_ammo[weapon_index] > max) {
780 ammo_count += (max - Players[Player_num].primary_ammo[weapon_index]);
781 Players[Player_num].primary_ammo[weapon_index] = max;
783 cutpoint=POrderList (255);
785 if (Primary_weapon==LASER_INDEX && Players[Player_num].laser_level>=4)
786 supposed_weapon=SUPER_LASER_INDEX; // allotment for stupid way of doing super laser
789 if (Players[Player_num].primary_weapon_flags&(1<<weapon_index) && weapon_index>Primary_weapon && old_ammo==0 &&
790 POrderList(weapon_index)<cutpoint && POrderList(weapon_index)<POrderList(supposed_weapon))
791 select_weapon(weapon_index,0,0,1);
793 return ammo_count; //return amount used
796 #define SMEGA_SHAKE_TIME (F1_0*2)
797 #define MAX_SMEGA_DETONATES 4
798 fix Smega_detonate_times[MAX_SMEGA_DETONATES];
800 // Call this to initialize for a new level.
801 // Sets all super mega missile detonation times to 0 which means there aren't any.
802 void init_smega_detonates(void)
806 for (i=0; i<MAX_SMEGA_DETONATES; i++)
807 Smega_detonate_times[i] = 0;
810 fix Seismic_tremor_magnitude;
811 fix Next_seismic_sound_time;
812 int Seismic_sound_playing = 0;
813 int Seismic_tremor_volume;
815 int Seismic_sound = SOUND_SEISMIC_DISTURBANCE_START;
817 // If a smega missile been detonated, rock the mine!
818 // This should be called every frame.
819 // Maybe this should affect all robots, being called when they get their physics done.
820 void rock_the_mine_frame(void)
824 for (i=0; i<MAX_SMEGA_DETONATES; i++) {
826 if (Smega_detonate_times[i] != 0) {
828 delta_time = GameTime - Smega_detonate_times[i];
830 if (!Seismic_sound_playing) {
831 digi_play_sample_looping(Seismic_sound, F1_0, -1, -1);
832 Seismic_sound_playing = 1;
833 Next_seismic_sound_time = GameTime + d_rand()/2;
836 if (delta_time < SMEGA_SHAKE_TIME) {
838 // Control center destroyed, rock the player's ship.
840 // -- fc = abs(delta_time - SMEGA_SHAKE_TIME/2);
841 // Changed 10/23/95 to make decreasing for super mega missile.
842 fc = (SMEGA_SHAKE_TIME - delta_time)/2;
843 fc /= SMEGA_SHAKE_TIME/32;
850 Seismic_tremor_volume += fc;
852 rx = fixmul(d_rand() - 16384, 3*F1_0/16 + (F1_0*(16-fc))/32);
853 rz = fixmul(d_rand() - 16384, 3*F1_0/16 + (F1_0*(16-fc))/32);
855 ConsoleObject->mtype.phys_info.rotvel.x += rx;
856 ConsoleObject->mtype.phys_info.rotvel.z += rz;
859 if (Buddy_objnum != -1) {
860 Objects[Buddy_objnum].mtype.phys_info.rotvel.x += rx*4;
861 Objects[Buddy_objnum].mtype.phys_info.rotvel.z += rz*4;
864 // Shake a guided missile!
865 Seismic_tremor_magnitude += rx;
868 Smega_detonate_times[i] = 0;
873 // Hook in the rumble sound effect here.
876 extern int Level_shake_frequency, Level_shake_duration;
878 extern void multi_send_seismic (fix,fix);
881 #define SEISMIC_DISTURBANCE_DURATION (F1_0*5)
882 fix Seismic_disturbance_start_time = 0, Seismic_disturbance_end_time;
886 int on_seismic_level(void)
888 return Seismic_level;
891 void init_seismic_disturbances(void)
893 Seismic_disturbance_start_time = 0;
894 Seismic_disturbance_end_time = 0;
897 // Return true if time to start a seismic disturbance.
898 int start_seismic_disturbance(void)
902 if (Level_shake_duration < 1)
905 rval = (2 * fixmul(d_rand(), Level_shake_frequency)) < FrameTime;
908 Seismic_disturbance_start_time = GameTime;
909 Seismic_disturbance_end_time = GameTime + Level_shake_duration;
910 if (!Seismic_sound_playing) {
911 digi_play_sample_looping(Seismic_sound, F1_0, -1, -1);
912 Seismic_sound_playing = 1;
913 Next_seismic_sound_time = GameTime + d_rand()/2;
917 if (Game_mode & GM_MULTI)
918 multi_send_seismic (Seismic_disturbance_start_time,Seismic_disturbance_end_time);
925 void seismic_disturbance_frame(void)
927 if (Level_shake_frequency) {
928 if (((Seismic_disturbance_start_time < GameTime) && (Seismic_disturbance_end_time > GameTime)) || start_seismic_disturbance()) {
932 delta_time = GameTime - Seismic_disturbance_start_time;
934 fc = abs(delta_time - (Seismic_disturbance_end_time - Seismic_disturbance_start_time)/2);
942 Seismic_tremor_volume += fc;
944 rx = fixmul(d_rand() - 16384, 3*F1_0/16 + (F1_0*(16-fc))/32);
945 rz = fixmul(d_rand() - 16384, 3*F1_0/16 + (F1_0*(16-fc))/32);
947 ConsoleObject->mtype.phys_info.rotvel.x += rx;
948 ConsoleObject->mtype.phys_info.rotvel.z += rz;
951 if (Buddy_objnum != -1) {
952 Objects[Buddy_objnum].mtype.phys_info.rotvel.x += rx*4;
953 Objects[Buddy_objnum].mtype.phys_info.rotvel.z += rz*4;
956 // Shake a guided missile!
957 Seismic_tremor_magnitude += rx;
963 // Call this when a smega detonates to start the process of rocking the mine.
964 void smega_rock_stuff(void)
968 for (i=0; i<MAX_SMEGA_DETONATES; i++) {
969 if (Smega_detonate_times[i] + SMEGA_SHAKE_TIME < GameTime)
970 Smega_detonate_times[i] = 0;
973 for (i=0; i<MAX_SMEGA_DETONATES; i++) {
974 if (Smega_detonate_times[i] == 0) {
975 Smega_detonate_times[i] = GameTime;
981 int Super_mines_yes = 1;
983 // Call this once/frame to process all super mines in the level.
984 void process_super_mines_frame(void)
989 // If we don't know of there being any super mines in the level, just
990 // check every 8th object each frame.
991 if (Super_mines_yes == 0) {
992 start = FrameCount & 7;
1001 for (i=start; i<=Highest_object_index; i+=add) {
1002 if ((Objects[i].type == OBJ_WEAPON) && (Objects[i].id == SUPERPROX_ID)) {
1005 parent_num = Objects[i].ctype.laser_info.parent_num;
1007 Super_mines_yes = 1;
1008 if (Objects[i].lifeleft + F1_0*2 < Weapon_info[SUPERPROX_ID].lifetime) {
1009 vms_vector *bombpos;
1011 bombpos = &Objects[i].pos;
1013 for (j=0; j<=Highest_object_index; j++) {
1014 if ((Objects[j].type == OBJ_PLAYER) || (Objects[j].type == OBJ_ROBOT)) {
1017 dist = vm_vec_dist_quick(bombpos, &Objects[j].pos);
1019 if (j != parent_num)
1020 if (dist - Objects[j].size < F1_0*20)
1022 if (Objects[i].segnum == Objects[j].segnum)
1023 Objects[i].lifeleft = 1;
1025 // Object which is close enough to detonate smart mine is not in same segment as smart mine.
1026 // Need to do a more expensive check to make sure there isn't an obstruction.
1027 if (((FrameCount ^ (i+j)) % 4) == 0) {
1032 mprintf((0, "Expensive proxmine collision check. Frame %i\n", FrameCount));
1034 fq.startseg = Objects[i].segnum;
1035 fq.p0 = &Objects[i].pos;
1036 fq.p1 = &Objects[j].pos;
1039 fq.ignore_obj_list = NULL;
1042 fate = find_vector_intersection(&fq, &hit_data);
1043 if (fate != HIT_WALL)
1044 Objects[i].lifeleft = 1;
1056 #define SPIT_SPEED 20
1058 //this function is for when the player intentionally drops a powerup
1059 //this function is based on drop_powerup()
1060 int spit_powerup(object *spitter, int id,int seed)
1064 vms_vector new_velocity, new_pos;
1068 vm_vec_scale_add(&new_velocity,&spitter->mtype.phys_info.velocity,&spitter->orient.fvec,i2f(SPIT_SPEED));
1070 new_velocity.x += (d_rand() - 16384) * SPIT_SPEED * 2;
1071 new_velocity.y += (d_rand() - 16384) * SPIT_SPEED * 2;
1072 new_velocity.z += (d_rand() - 16384) * SPIT_SPEED * 2;
1074 // Give keys zero velocity so they can be tracked better in multi
1076 if ((Game_mode & GM_MULTI) && (id >= POW_KEY_BLUE) && (id <= POW_KEY_GOLD))
1077 vm_vec_zero(&new_velocity);
1079 //there's a piece of code which lets the player pick up a powerup if
1080 //the distance between him and the powerup is less than 2 time their
1081 //combined radii. So we need to create powerups pretty far out from
1084 vm_vec_scale_add(&new_pos,&spitter->pos,&spitter->orient.fvec,spitter->size);
1087 if (Game_mode & GM_MULTI)
1089 if (Net_create_loc >= MAX_NET_CREATE_OBJECTS)
1091 mprintf( (0, "WEAPON:Not enough slots to drop all powerups!\n" ));
1097 objnum = obj_create( OBJ_POWERUP, id, spitter->segnum, &new_pos, &vmd_identity_matrix, Powerup_info[id].size, CT_POWERUP, MT_PHYSICS, RT_POWERUP);
1100 mprintf((1, "Can't create object in object_create_egg. Aborting.\n"));
1105 obj = &Objects[objnum];
1107 obj->mtype.phys_info.velocity = new_velocity;
1108 obj->mtype.phys_info.drag = 512; //1024;
1109 obj->mtype.phys_info.mass = F1_0;
1111 obj->mtype.phys_info.flags = PF_BOUNCE;
1113 obj->rtype.vclip_info.vclip_num = Powerup_info[obj->id].vclip_num;
1114 obj->rtype.vclip_info.frametime = Vclip[obj->rtype.vclip_info.vclip_num].frame_time;
1115 obj->rtype.vclip_info.framenum = 0;
1117 if (spitter == ConsoleObject)
1118 obj->ctype.powerup_info.flags |= PF_SPAT_BY_PLAYER;
1123 case POW_SHIELD_BOOST:
1125 obj->lifeleft = (d_rand() + F1_0*3) * 64; // Lives for 3 to 3.5 binary minutes (a binary minute is 64 seconds)
1126 if (Game_mode & GM_MULTI)
1130 //if (Game_mode & GM_MULTI)
1131 // obj->lifeleft = (d_rand() + F1_0*3) * 64; // Lives for 5 to 5.5 binary minutes (a binary minute is 64 seconds)
1138 void DropCurrentWeapon ()
1140 int objnum,ammo=0,seed;
1142 if (Primary_weapon==0)
1144 HUD_init_message("You cannot drop your base weapon!");
1148 HUD_init_message("%s dropped!",PRIMARY_WEAPON_NAMES(Primary_weapon));
1149 digi_play_sample (SOUND_DROP_WEAPON,F1_0);
1153 objnum = spit_powerup(ConsoleObject,Primary_weapon_to_powerup[Primary_weapon],seed);
1158 if (Primary_weapon == VULCAN_INDEX || Primary_weapon == GAUSS_INDEX) {
1160 //if it's one of these, drop some ammo with the weapon
1162 ammo = Players[Player_num].primary_ammo[VULCAN_INDEX];
1164 if ((Players[Player_num].primary_weapon_flags & HAS_FLAG(VULCAN_INDEX)) && (Players[Player_num].primary_weapon_flags & HAS_FLAG(GAUSS_INDEX)))
1165 ammo /= 2; //if both vulcan & gauss, drop half
1167 Players[Player_num].primary_ammo[VULCAN_INDEX] -= ammo;
1170 Objects[objnum].ctype.powerup_info.count = ammo;
1173 if (Primary_weapon == OMEGA_INDEX) {
1175 //dropped weapon has current energy
1178 Objects[objnum].ctype.powerup_info.count = Omega_charge;
1182 if ((Game_mode & GM_MULTI) && objnum>-1)
1183 multi_send_drop_weapon(objnum,seed);
1186 Players[Player_num].primary_weapon_flags &= (~(1<<Primary_weapon));
1187 auto_select_weapon (0);
1191 void DropSecondaryWeapon ()
1195 if (Players[Player_num].secondary_ammo[Secondary_weapon] ==0)
1197 HUD_init_message("No secondary weapon to drop!");
1201 if ((Secondary_weapon_to_powerup[Secondary_weapon]==POW_PROXIMITY_WEAPON ||
1202 Secondary_weapon_to_powerup[Secondary_weapon]==POW_SMART_MINE) &&
1203 Players[Player_num].secondary_ammo[Secondary_weapon]<4)
1205 HUD_init_message("You need at least 4 to drop!");
1209 HUD_init_message("%s dropped!",SECONDARY_WEAPON_NAMES(Secondary_weapon));
1210 digi_play_sample (SOUND_DROP_WEAPON,F1_0);
1214 objnum = spit_powerup(ConsoleObject,Secondary_weapon_to_powerup[Secondary_weapon],seed);
1221 if ((Game_mode & GM_MULTI) && objnum>-1)
1222 multi_send_drop_weapon(objnum,seed);
1225 if (Secondary_weapon_to_powerup[Secondary_weapon]==POW_PROXIMITY_WEAPON ||
1226 Secondary_weapon_to_powerup[Secondary_weapon]==POW_SMART_MINE)
1227 Players[Player_num].secondary_ammo[Secondary_weapon]-=4;
1229 Players[Player_num].secondary_ammo[Secondary_weapon]--;
1231 if (Players[Player_num].secondary_ammo[Secondary_weapon]==0)
1233 Players[Player_num].secondary_weapon_flags &= (~(1<<Secondary_weapon));
1234 auto_select_weapon (1);
1238 // ---------------------------------------------------------------------------------------
1239 // Do seismic disturbance stuff including the looping sounds with changing volume.
1240 void do_seismic_stuff(void)
1244 stv_save = Seismic_tremor_volume;
1245 Seismic_tremor_magnitude = 0;
1246 Seismic_tremor_volume = 0;
1248 rock_the_mine_frame();
1249 seismic_disturbance_frame();
1251 if (stv_save != 0) {
1252 if (Seismic_tremor_volume == 0) {
1253 digi_stop_looping_sound();
1254 Seismic_sound_playing = 0;
1257 if ((GameTime > Next_seismic_sound_time) && Seismic_tremor_volume) {
1260 volume = Seismic_tremor_volume * 2048;
1263 digi_change_looping_volume(volume);
1264 Next_seismic_sound_time = GameTime + d_rand()/4 + 8192;
1270 int tactile_fire_duration[]={120,80,150,250,150,200,100,180,280,100};
1271 int tactile_fire_repeat[]={260,90,160,160,160,210,110,191,291,111};
1273 void tactile_set_button_jolt ()
1279 static int stickmag=-1;
1282 dur=tactile_fire_duration[Primary_weapon];
1283 rep=tactile_fire_repeat[Primary_weapon];
1289 if (t=FindArg("-stickmag"))
1290 stickmag=atoi (Args[t+1]);
1294 infile=(FILE *)fopen ("stick.val","rt");
1299 fscanf (infile,"%d %d\n",&tactile_fire_duration[i],&tactile_fire_repeat[i]);
1300 mprintf ((0,"scan value[%d]=%d\n",i,tactile_fire_duration[i]));
1305 ButtonReflexJolt (0,stickmag,0,dur,rep);
1311 * reads n weapon_info structs from a CFILE
1313 extern int weapon_info_read_n(weapon_info *wi, int n, CFILE *fp, int file_version)
1317 for (i = 0; i < n; i++) {
1318 wi[i].render_type = cfile_read_byte(fp);
1319 wi[i].persistent = cfile_read_byte(fp);
1320 wi[i].model_num = cfile_read_short(fp);
1321 wi[i].model_num_inner = cfile_read_short(fp);
1323 wi[i].flash_vclip = cfile_read_byte(fp);
1324 wi[i].robot_hit_vclip = cfile_read_byte(fp);
1325 wi[i].flash_sound = cfile_read_short(fp);
1327 wi[i].wall_hit_vclip = cfile_read_byte(fp);
1328 wi[i].fire_count = cfile_read_byte(fp);
1329 wi[i].robot_hit_sound = cfile_read_short(fp);
1331 wi[i].ammo_usage = cfile_read_byte(fp);
1332 wi[i].weapon_vclip = cfile_read_byte(fp);
1333 wi[i].wall_hit_sound = cfile_read_short(fp);
1335 wi[i].destroyable = cfile_read_byte(fp);
1336 wi[i].matter = cfile_read_byte(fp);
1337 wi[i].bounce = cfile_read_byte(fp);
1338 wi[i].homing_flag = cfile_read_byte(fp);
1340 wi[i].speedvar = cfile_read_byte(fp);
1341 wi[i].flags = cfile_read_byte(fp);
1342 wi[i].flash = cfile_read_byte(fp);
1343 wi[i].afterburner_size = cfile_read_byte(fp);
1345 if (file_version >= 3)
1346 wi[i].children = cfile_read_byte(fp);
1348 /* Set the type of children correctly when using old
1349 * datafiles. In earlier descent versions this was simply
1350 * hard-coded in create_smart_children().
1355 wi[i].children = PLAYER_SMART_HOMING_ID;
1358 wi[i].children = SMART_MINE_HOMING_ID;
1360 #if 0 /* not present in shareware */
1361 case ROBOT_SUPERPROX_ID:
1362 wi[i].children = ROBOT_SMART_MINE_HOMING_ID;
1364 case EARTHSHAKER_ID:
1365 wi[i].children = EARTHSHAKER_MEGA_ID;
1369 wi[i].children = -1;
1373 wi[i].energy_usage = cfile_read_fix(fp);
1374 wi[i].fire_wait = cfile_read_fix(fp);
1376 if (file_version >= 3)
1377 wi[i].multi_damage_scale = cfile_read_fix(fp);
1378 else /* FIXME: hack this to set the real values */
1379 wi[i].multi_damage_scale = F1_0;
1381 bitmap_index_read(&wi[i].bitmap, fp);
1383 wi[i].blob_size = cfile_read_fix(fp);
1384 wi[i].flash_size = cfile_read_fix(fp);
1385 wi[i].impact_size = cfile_read_fix(fp);
1386 for (j = 0; j < NDL; j++)
1387 wi[i].strength[j] = cfile_read_fix(fp);
1388 for (j = 0; j < NDL; j++)
1389 wi[i].speed[j] = cfile_read_fix(fp);
1390 wi[i].mass = cfile_read_fix(fp);
1391 wi[i].drag = cfile_read_fix(fp);
1392 wi[i].thrust = cfile_read_fix(fp);
1393 wi[i].po_len_to_width_ratio = cfile_read_fix(fp);
1394 wi[i].light = cfile_read_fix(fp);
1395 wi[i].lifetime = cfile_read_fix(fp);
1396 wi[i].damage_radius = cfile_read_fix(fp);
1397 bitmap_index_read(&wi[i].picture, fp);
1398 if (file_version >= 3)
1399 bitmap_index_read(&wi[i].hires_picture, fp);
1401 wi[i].hires_picture.index = wi[i].picture.index;