WEAPON.C 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. /*
  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-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  12. */
  13. /*
  14. * $Source: f:/miner/source/main/rcs/weapon.c $
  15. * $Revision: 2.1 $
  16. * $Author: john $
  17. * $Date: 1995/03/21 14:38:43 $
  18. *
  19. * Functions for weapons...
  20. *
  21. * $Log: weapon.c $
  22. * Revision 2.1 1995/03/21 14:38:43 john
  23. * Ifdef'd out the NETWORK code.
  24. *
  25. * Revision 2.0 1995/02/27 11:27:25 john
  26. * New version 2.0, which has no anonymous unions, builds with
  27. * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  28. *
  29. * Revision 1.54 1995/02/15 15:21:48 mike
  30. * make smart missile select if mega missiles used up.
  31. *
  32. *
  33. * Revision 1.53 1995/02/12 02:12:30 john
  34. * Fixed bug with state restore making weapon beeps.
  35. *
  36. * Revision 1.52 1995/02/09 20:42:15 mike
  37. * change weapon autoselect, always autoselect smart, mega.
  38. *
  39. * Revision 1.51 1995/02/07 20:44:26 mike
  40. * autoselect mega, smart when you pick them up.
  41. *
  42. * Revision 1.50 1995/02/07 13:32:25 rob
  43. * Added include of multi.h
  44. *
  45. * Revision 1.49 1995/02/07 13:21:33 yuan
  46. * Fixed 2nd typo
  47. *
  48. * Revision 1.48 1995/02/07 13:16:39 yuan
  49. * Fixed typo.
  50. *
  51. * Revision 1.47 1995/02/07 12:53:12 rob
  52. * Added network sound prop. to weapon switch.
  53. *
  54. * Revision 1.46 1995/02/06 15:53:17 mike
  55. * don't autoselect smart or mega missile when you pick it up.
  56. *
  57. * Revision 1.45 1995/02/02 21:43:34 mike
  58. * make autoselection better.
  59. *
  60. * Revision 1.44 1995/02/02 16:27:21 mike
  61. * make concussion missiles trade up.
  62. *
  63. * Revision 1.43 1995/02/01 23:34:57 adam
  64. * messed with weapon change sounds
  65. *
  66. * Revision 1.42 1995/02/01 17:12:47 mike
  67. * Make smart missile, mega missile not auto-select.
  68. *
  69. * Revision 1.41 1995/02/01 15:50:54 mike
  70. * fix bogus weapon selection sound code.
  71. *
  72. * Revision 1.40 1995/01/31 16:16:31 mike
  73. * Separate smart blobs for robot and player.
  74. *
  75. * Revision 1.39 1995/01/30 21:12:11 mike
  76. * Use new weapon selection sounds, different for primary and secondary.
  77. *
  78. * Revision 1.38 1995/01/29 13:46:52 mike
  79. * Don't auto-select fusion cannon when you run out of energy.
  80. *
  81. * Revision 1.37 1995/01/20 11:11:13 allender
  82. * record weapon changes again. (John somehow lost my 1.35 changes).
  83. *
  84. * Revision 1.36 1995/01/19 17:00:46 john
  85. * Made save game work between levels.
  86. *
  87. * Revision 1.34 1995/01/09 17:03:48 mike
  88. * fix autoselection of weapons.
  89. *
  90. * Revision 1.33 1995/01/05 15:46:31 john
  91. * Made weapons not rearm when starting a saved game.
  92. *
  93. * Revision 1.32 1995/01/03 12:34:23 mike
  94. * autoselect next lower weapon if run out of smart or mega missile.
  95. *
  96. * Revision 1.31 1994/12/12 21:39:37 matt
  97. * Changed vulcan ammo: 10K max, 5K w/weapon, 1250 per powerup
  98. *
  99. * Revision 1.30 1994/12/09 19:55:04 matt
  100. * Added weapon name in "not available in shareware" message
  101. *
  102. * Revision 1.29 1994/12/06 13:50:24 adam
  103. * added shareware msg. when choosing 4 top weapons
  104. *
  105. * Revision 1.28 1994/12/02 22:07:13 mike
  106. * if you gots 19 concussion missiles and you runs over 4, say you picks up 1, not 4, we do the math, see?
  107. *
  108. * Revision 1.27 1994/12/02 20:06:24 matt
  109. * Made vulcan ammo print at approx 25 times actual
  110. *
  111. * Revision 1.26 1994/12/02 15:05:03 matt
  112. * Fixed bogus weapon constants and arrays
  113. *
  114. * Revision 1.25 1994/12/02 10:50:34 yuan
  115. * Localization
  116. *
  117. * Revision 1.24 1994/11/29 15:48:28 matt
  118. * selecting weapon now makes sound
  119. *
  120. * Revision 1.23 1994/11/28 11:26:58 matt
  121. * Cleaned up hud message printing for picking up weapons
  122. *
  123. * Revision 1.22 1994/11/27 23:13:39 matt
  124. * Made changes for new mprintf calling convention
  125. *
  126. * Revision 1.21 1994/11/12 16:38:34 mike
  127. * clean up default ammo stuff.
  128. *
  129. * Revision 1.20 1994/11/07 17:41:18 mike
  130. * messages for when you try to fire a weapon you don't have or don't have ammo for.
  131. *
  132. * Revision 1.19 1994/10/21 20:40:05 mike
  133. * fix double vulcan ammo.
  134. *
  135. * Revision 1.18 1994/10/20 09:49:05 mike
  136. * kill messages no one liked...*sniff* *sniff*
  137. *
  138. * Revision 1.17 1994/10/19 11:17:07 mike
  139. * Limit amount of player ammo.
  140. *
  141. * Revision 1.16 1994/10/12 08:04:18 mike
  142. * Fix proximity/homing confusion.
  143. *
  144. * Revision 1.15 1994/10/11 18:27:58 matt
  145. * Changed auto selection of secondary weapons
  146. *
  147. * Revision 1.14 1994/10/08 23:37:54 matt
  148. * Don't pick up weapons you already have; also fixed auto_select bug
  149. * for seconary weapons
  150. *
  151. * Revision 1.13 1994/10/08 14:55:47 matt
  152. * Fixed bug that selected vulcan cannon when picked up ammo, even though
  153. * you didn't have the weapon.
  154. *
  155. * Revision 1.12 1994/10/08 12:50:32 matt
  156. * Fixed bug that let you select weapons you don't have
  157. *
  158. * Revision 1.11 1994/10/07 23:37:56 matt
  159. * Made weapons select when pick up better one
  160. *
  161. * Revision 1.10 1994/10/07 16:02:08 matt
  162. * Fixed problem with weapon auto-select
  163. *
  164. * Revision 1.9 1994/10/05 17:00:20 matt
  165. * Made player_has_weapon() public and moved constants to header file
  166. *
  167. * Revision 1.8 1994/09/26 11:27:13 mike
  168. * Fix auto selection of weapon when you run out of ammo.
  169. *
  170. * Revision 1.7 1994/09/13 16:40:45 mike
  171. * Add rearm delay and missile firing delay.
  172. *
  173. * Revision 1.6 1994/09/13 14:43:12 matt
  174. * Added cockpit weapon displays
  175. *
  176. * Revision 1.5 1994/09/03 15:23:06 mike
  177. * Auto select next weaker weapon when one runs out, clean up code.
  178. *
  179. * Revision 1.4 1994/09/02 16:38:19 mike
  180. * Eliminate a pile of arrays, associate weapon data with Weapon_info.
  181. *
  182. * Revision 1.3 1994/09/02 11:57:10 mike
  183. * Add a bunch of stuff, I forget what.
  184. *
  185. * Revision 1.2 1994/06/03 16:26:32 john
  186. * Initial version.
  187. *
  188. * Revision 1.1 1994/06/03 14:40:43 john
  189. * Initial revision
  190. *
  191. *
  192. */
  193. #pragma off (unreferenced)
  194. static char rcsid[] = "$Id: weapon.c 2.1 1995/03/21 14:38:43 john Exp $";
  195. #pragma on (unreferenced)
  196. #include "game.h"
  197. #include "weapon.h"
  198. #include "mono.h"
  199. #include "player.h"
  200. #include "gauges.h"
  201. #include "error.h"
  202. #include "sounds.h"
  203. #include "text.h"
  204. #include "powerup.h"
  205. #include "newdemo.h"
  206. #include "multi.h"
  207. // Note, only Vulcan cannon requires ammo.
  208. //ubyte Default_primary_ammo_level[MAX_PRIMARY_WEAPONS] = {255, 0, 255, 255, 255};
  209. //ubyte Default_secondary_ammo_level[MAX_SECONDARY_WEAPONS] = {3, 0, 0, 0, 0};
  210. // Convert primary weapons to indices in Weapon_info array.
  211. ubyte Primary_weapon_to_weapon_info[MAX_PRIMARY_WEAPONS] = {0, 11, 12, 13, 14};
  212. ubyte Secondary_weapon_to_weapon_info[MAX_SECONDARY_WEAPONS] = {8, 15, 16, 17, 18};
  213. int Primary_ammo_max[MAX_PRIMARY_WEAPONS] = {0, VULCAN_AMMO_MAX, 0, 0, 0};
  214. ubyte Secondary_ammo_max[MAX_SECONDARY_WEAPONS] = {20, 10, 10, 5, 5};
  215. weapon_info Weapon_info[MAX_WEAPON_TYPES];
  216. int N_weapon_types=0;
  217. byte Primary_weapon, Secondary_weapon;
  218. //char *Primary_weapon_names[MAX_PRIMARY_WEAPONS] = {
  219. // "Laser Cannon",
  220. // "Vulcan Cannon",
  221. // "Spreadfire Cannon",
  222. // "Plasma Cannon",
  223. // "Fusion Cannon"
  224. //};
  225. //char *Secondary_weapon_names[MAX_SECONDARY_WEAPONS] = {
  226. // "Concussion Missile",
  227. // "Homing Missile",
  228. // "Proximity Bomb",
  229. // "Smart Missile",
  230. // "Mega Missile"
  231. //};
  232. //char *Primary_weapon_names_short[MAX_PRIMARY_WEAPONS] = {
  233. // "Laser",
  234. // "Vulcan",
  235. // "Spread",
  236. // "Plasma",
  237. // "Fusion"
  238. //};
  239. //char *Secondary_weapon_names_short[MAX_SECONDARY_WEAPONS] = {
  240. // "Concsn\nMissile",
  241. // "Homing\nMissile",
  242. // "Proxim.\nBomb",
  243. // "Smart\nMissile",
  244. // "Mega\nMissile"
  245. //};
  246. // ------------------------------------------------------------------------------------
  247. // Return:
  248. // Bits set:
  249. // HAS_WEAPON_FLAG
  250. // HAS_ENERGY_FLAG
  251. // HAS_AMMO_FLAG
  252. // See weapon.h for bit values
  253. int player_has_weapon(int weapon_num, int secondary_flag)
  254. {
  255. int return_value = 0;
  256. int weapon_index;
  257. // Hack! If energy goes negative, you can't fire a weapon that doesn't require energy.
  258. // But energy should not go negative (but it does), so find out why it does!
  259. if (Players[Player_num].energy < 0)
  260. Players[Player_num].energy = 0;
  261. if (!secondary_flag) {
  262. weapon_index = Primary_weapon_to_weapon_info[weapon_num];
  263. if (Players[Player_num].primary_weapon_flags & (1 << weapon_num))
  264. return_value |= HAS_WEAPON_FLAG;
  265. if (Weapon_info[weapon_index].ammo_usage <= Players[Player_num].primary_ammo[weapon_num])
  266. return_value |= HAS_AMMO_FLAG;
  267. if (Weapon_info[weapon_index].energy_usage <= Players[Player_num].energy)
  268. return_value |= HAS_ENERGY_FLAG;
  269. } else {
  270. weapon_index = Secondary_weapon_to_weapon_info[weapon_num];
  271. if (Players[Player_num].secondary_weapon_flags & (1 << weapon_num))
  272. return_value |= HAS_WEAPON_FLAG;
  273. if (Weapon_info[weapon_index].ammo_usage <= Players[Player_num].secondary_ammo[weapon_num])
  274. return_value |= HAS_AMMO_FLAG;
  275. if (Weapon_info[weapon_index].energy_usage <= Players[Player_num].energy)
  276. return_value |= HAS_ENERGY_FLAG;
  277. }
  278. return return_value;
  279. }
  280. // ------------------------------------------------------------------------------------
  281. //if message flag set, print message saying selected
  282. select_weapon(int weapon_num, int secondary_flag, int print_message, int wait_for_rearm)
  283. {
  284. char *weapon_name;
  285. #ifndef SHAREWARE
  286. if (Newdemo_state==ND_STATE_RECORDING )
  287. newdemo_record_player_weapon(secondary_flag, weapon_num);
  288. #endif
  289. if (!secondary_flag) {
  290. if (Primary_weapon != weapon_num) {
  291. if (wait_for_rearm) digi_play_sample_once( SOUND_GOOD_SELECTION_PRIMARY, F1_0 );
  292. #ifdef NETWORK
  293. if (Game_mode & GM_MULTI) {
  294. if (wait_for_rearm) multi_send_play_sound(SOUND_GOOD_SELECTION_PRIMARY, F1_0);
  295. }
  296. #endif
  297. if (wait_for_rearm)
  298. Next_laser_fire_time = GameTime + REARM_TIME;
  299. else
  300. Next_laser_fire_time = 0;
  301. Global_laser_firing_count = 0;
  302. } else {
  303. if (wait_for_rearm) digi_play_sample( SOUND_ALREADY_SELECTED, F1_0 );
  304. }
  305. Primary_weapon = weapon_num;
  306. weapon_name = PRIMARY_WEAPON_NAMES(weapon_num);
  307. } else {
  308. if (Secondary_weapon != weapon_num) {
  309. if (wait_for_rearm) digi_play_sample_once( SOUND_GOOD_SELECTION_SECONDARY, F1_0 );
  310. #ifdef NETWORK
  311. if (Game_mode & GM_MULTI) {
  312. if (wait_for_rearm) multi_send_play_sound(SOUND_GOOD_SELECTION_PRIMARY, F1_0);
  313. }
  314. #endif
  315. if (wait_for_rearm)
  316. Next_missile_fire_time = GameTime + REARM_TIME;
  317. else
  318. Next_missile_fire_time = 0;
  319. Global_missile_firing_count = 0;
  320. } else {
  321. if (wait_for_rearm) digi_play_sample_once( SOUND_ALREADY_SELECTED, F1_0 );
  322. }
  323. Secondary_weapon = weapon_num;
  324. weapon_name = SECONDARY_WEAPON_NAMES(weapon_num);
  325. }
  326. if (print_message)
  327. HUD_init_message("%s %s", weapon_name, TXT_SELECTED);
  328. }
  329. // ------------------------------------------------------------------------------------
  330. // Select a weapon, primary or secondary.
  331. void do_weapon_select(int weapon_num, int secondary_flag)
  332. {
  333. int weapon_status = player_has_weapon(weapon_num, secondary_flag);
  334. char *weapon_name;
  335. #ifdef SHAREWARE // do special hud msg. for picking registered weapon in shareware version.
  336. if (weapon_num >= NUM_SHAREWARE_WEAPONS) {
  337. weapon_name = secondary_flag?SECONDARY_WEAPON_NAMES(weapon_num):PRIMARY_WEAPON_NAMES(weapon_num);
  338. HUD_init_message("%s %s!", weapon_name,TXT_NOT_IN_SHAREWARE);
  339. digi_play_sample( SOUND_BAD_SELECTION, F1_0 );
  340. return;
  341. }
  342. #endif
  343. if (!secondary_flag) {
  344. weapon_name = PRIMARY_WEAPON_NAMES(weapon_num);
  345. if ((weapon_status & HAS_WEAPON_FLAG) == 0) {
  346. HUD_init_message("%s %s!", TXT_DONT_HAVE, weapon_name);
  347. digi_play_sample( SOUND_BAD_SELECTION, F1_0 );
  348. return;
  349. }
  350. else if ((weapon_status & HAS_AMMO_FLAG) == 0) {
  351. HUD_init_message("%s %s!", TXT_DONT_HAVE_AMMO, weapon_name);
  352. digi_play_sample( SOUND_BAD_SELECTION, F1_0 );
  353. return;
  354. }
  355. }
  356. else {
  357. weapon_name = SECONDARY_WEAPON_NAMES(weapon_num);
  358. if (weapon_status != HAS_ALL) {
  359. HUD_init_message("%s %s%s",TXT_HAVE_NO, weapon_name, TXT_SX);
  360. digi_play_sample( SOUND_BAD_SELECTION, F1_0 );
  361. return;
  362. }
  363. }
  364. select_weapon(weapon_num, secondary_flag, 1, 1);
  365. }
  366. // ----------------------------------------------------------------------------------------
  367. // Automatically select next best weapon if unable to fire current weapon.
  368. // Weapon type: 0==primary, 1==secondary
  369. void auto_select_weapon(int weapon_type)
  370. {
  371. int r;
  372. if (weapon_type==0) {
  373. r = player_has_weapon(Primary_weapon, 0);
  374. if (r != HAS_ALL) {
  375. int cur_weapon;
  376. int try_again = 1;
  377. cur_weapon = Primary_weapon;
  378. while (try_again) {
  379. cur_weapon--;
  380. if (cur_weapon < 0)
  381. cur_weapon = MAX_PRIMARY_WEAPONS-1;
  382. // Hack alert! Because the fusion uses 0 energy at the end (it's got the weird chargeup)
  383. // it looks like it takes 0 to fire, but it doesn't, so never auto-select.
  384. if (cur_weapon == FUSION_INDEX)
  385. continue;
  386. if (cur_weapon == Primary_weapon) {
  387. HUD_init_message(TXT_NO_PRIMARY);
  388. try_again = 0; // Tried all weapons!
  389. select_weapon(0, 0, 0, 1);
  390. } else if (player_has_weapon(cur_weapon, 0) == HAS_ALL) {
  391. select_weapon(cur_weapon, 0, 1, 1 );
  392. try_again = 0;
  393. }
  394. }
  395. }
  396. } else {
  397. Assert(weapon_type==1);
  398. if (Secondary_weapon != PROXIMITY_INDEX) {
  399. if (!(player_has_weapon(Secondary_weapon, 1) == HAS_ALL)) {
  400. if (Secondary_weapon > SMART_INDEX)
  401. if (player_has_weapon(SMART_INDEX, 1) == HAS_ALL) {
  402. select_weapon(SMART_INDEX, 1, 1, 1);
  403. goto weapon_selected;
  404. }
  405. if (player_has_weapon(HOMING_INDEX, 1) == HAS_ALL)
  406. select_weapon(HOMING_INDEX, 1, 1, 1);
  407. else if (player_has_weapon(CONCUSSION_INDEX, 1) == HAS_ALL)
  408. select_weapon(CONCUSSION_INDEX, 1, 1, 1);
  409. weapon_selected: ;
  410. }
  411. }
  412. }
  413. }
  414. #ifndef RELEASE
  415. // ----------------------------------------------------------------------------------------
  416. // Show player which weapons he has, how much ammo...
  417. // Looks like a debug screen now because it writes to mono screen, but that will change...
  418. void show_weapon_status(void)
  419. {
  420. int i;
  421. for (i=0; i<MAX_PRIMARY_WEAPONS; i++) {
  422. if (Players[Player_num].primary_weapon_flags & (1 << i))
  423. mprintf((0, "HAVE"));
  424. else
  425. mprintf((0, " "));
  426. mprintf((0, " Weapon: %20s, charges: %4i\n", PRIMARY_WEAPON_NAMES(i), Players[Player_num].primary_ammo[i]));
  427. }
  428. mprintf((0, "\n"));
  429. for (i=0; i<MAX_SECONDARY_WEAPONS; i++) {
  430. if (Players[Player_num].secondary_weapon_flags & (1 << i))
  431. mprintf((0, "HAVE"));
  432. else
  433. mprintf((0, " "));
  434. mprintf((0, " Weapon: %20s, charges: %4i\n", SECONDARY_WEAPON_NAMES(i), Players[Player_num].secondary_ammo[i]));
  435. }
  436. mprintf((0, "\n"));
  437. mprintf((0, "\n"));
  438. }
  439. #endif
  440. // ---------------------------------------------------------------------
  441. //called when one of these weapons is picked up
  442. //when you pick up a secondary, you always get the weapon & ammo for it
  443. // Returns true if powerup picked up, else returns false.
  444. int pick_up_secondary(int weapon_index,int count)
  445. {
  446. int num_picked_up;
  447. if (Players[Player_num].secondary_ammo[weapon_index] >= Secondary_ammo_max[weapon_index]) {
  448. HUD_init_message("%s %i %ss!", TXT_ALREADY_HAVE, Players[Player_num].secondary_ammo[weapon_index],SECONDARY_WEAPON_NAMES(weapon_index));
  449. return 0;
  450. }
  451. Players[Player_num].secondary_weapon_flags |= (1<<weapon_index);
  452. Players[Player_num].secondary_ammo[weapon_index] += count;
  453. num_picked_up = count;
  454. if (Players[Player_num].secondary_ammo[weapon_index] > Secondary_ammo_max[weapon_index]) {
  455. num_picked_up = count - (Players[Player_num].secondary_ammo[weapon_index] - Secondary_ammo_max[weapon_index]);
  456. Players[Player_num].secondary_ammo[weapon_index] = Secondary_ammo_max[weapon_index];
  457. }
  458. //if you pick up a homing, and you're currently using concussion,
  459. //and you had no homings before, then upgrade
  460. if ((Secondary_weapon<weapon_index) && (weapon_index != PROXIMITY_INDEX)) // && (Players[Player_num].secondary_ammo[weapon_index] == count))
  461. select_weapon(weapon_index,1, 0, 1);
  462. //if you pick up a concussion, and you've got homing (or smart or mega) selected but are out,
  463. //then select concussion
  464. if ((weapon_index != PROXIMITY_INDEX) && (Players[Player_num].secondary_ammo[Secondary_weapon] == 0))
  465. select_weapon(weapon_index,1, 0, 1);
  466. //note: flash for all but concussion was 7,14,21
  467. if (count>1) {
  468. PALETTE_FLASH_ADD(15,15,15);
  469. HUD_init_message("%d %s%s",num_picked_up,SECONDARY_WEAPON_NAMES(weapon_index), TXT_SX);
  470. }
  471. else {
  472. PALETTE_FLASH_ADD(10,10,10);
  473. HUD_init_message("%s!",SECONDARY_WEAPON_NAMES(weapon_index));
  474. }
  475. return 1;
  476. }
  477. //called when a primary weapon is picked up
  478. //returns true if actually picked up
  479. int pick_up_primary(int weapon_index)
  480. {
  481. ubyte old_flags = Players[Player_num].primary_weapon_flags;
  482. ubyte flag = 1<<weapon_index;
  483. if (Players[Player_num].primary_weapon_flags & flag) { //already have
  484. HUD_init_message("%s %s!", TXT_ALREADY_HAVE_THE, PRIMARY_WEAPON_NAMES(weapon_index));
  485. return 0;
  486. }
  487. Players[Player_num].primary_weapon_flags |= flag;
  488. if (!(old_flags & flag) && weapon_index>Primary_weapon)
  489. select_weapon(weapon_index,0,0,1);
  490. PALETTE_FLASH_ADD(7,14,21);
  491. HUD_init_message("%s!",PRIMARY_WEAPON_NAMES(weapon_index));
  492. return 1;
  493. }
  494. //called when ammo (for the vulcan cannon) is picked up
  495. // Return true if ammo picked up, else return false.
  496. int pick_up_ammo(int class_flag,int weapon_index,int ammo_count)
  497. {
  498. int old_ammo=class_flag; //kill warning
  499. Assert(class_flag==CLASS_PRIMARY && weapon_index==VULCAN_INDEX);
  500. if (Players[Player_num].primary_ammo[weapon_index] == Primary_ammo_max[weapon_index])
  501. return 0;
  502. old_ammo = Players[Player_num].primary_ammo[weapon_index];
  503. Players[Player_num].primary_ammo[weapon_index] += ammo_count;
  504. if (Players[Player_num].primary_ammo[weapon_index] > Primary_ammo_max[weapon_index])
  505. Players[Player_num].primary_ammo[weapon_index] = Primary_ammo_max[weapon_index];
  506. if (Players[Player_num].primary_weapon_flags&(1<<weapon_index) && weapon_index>Primary_weapon && old_ammo==0)
  507. select_weapon(weapon_index,0,0,1);
  508. return 1;
  509. }
  510.