2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/MissionUI/MissionWeaponChoice.cpp $
15 * C module for the weapon loadout screen
18 * Revision 1.3 2002/06/09 04:41:23 relnev
19 * added copyright header
21 * Revision 1.2 2002/05/07 03:16:46 theoddone33
22 * The Great Newline Fix
24 * Revision 1.1.1.1 2002/05/03 03:28:10 root
28 * 40 11/01/99 11:22a Jefff
29 * some weapon name translations
31 * 39 9/10/99 10:26a Jefff
32 * default weapon anim selection fix
34 * 38 9/06/99 3:30p Mikek
35 * Added system for restricting weapon choices based on ship class for
38 * 37 8/27/99 11:59a Jefff
39 * fixed unnecessary sound playing
41 * 36 8/05/99 3:40p Jefff
42 * hi-res text adjustments
44 * 35 8/05/99 11:32a Jefff
45 * fixed hi-res weapon anims not loading from packfile
47 * 34 7/30/99 4:35p Andsager
48 * Clean up change ship sound
50 * 33 7/30/99 4:22p Andsager
51 * restored ship and weapon anim sounds for demo. Added sound for
52 * changing ship in weapon loadout screen.
54 * 32 7/27/99 7:34p Jefff
55 * Lotsa clean up, moving stuff around, generally making the whole damn
58 * 31 7/27/99 3:01p Jefff
59 * crippled wl_start_slot_animation to prevent loading of overhead ship
60 * .anis. also began modifications for multiplayer interface.
62 * 30 7/25/99 5:49p Jefff
63 * initial weapon ani is now one of the ship's weapons. this will fall
64 * back to the original search if the ship should be weaponless.
66 * 29 7/24/99 6:03p Jefff
67 * Added "lock" text to multiplayer lock button
69 * 28 7/21/99 6:02p Jefff
70 * fixed weapon counts running into weapon icons
72 * 27 7/21/99 3:24p Andsager
73 * Modify demo to use 2 frame ship and weapon select anis and cut sounds
76 * 26 7/20/99 7:07p Jefff
77 * added "reset" text above reset button
79 * 25 7/20/99 1:48p Jefff
80 * Long weapon titles now wrap to next line
82 * 24 7/20/99 10:44a Jefff
83 * increased WEAPON_DESC_MAX_LINES to 6
85 * 23 7/20/99 12:26a Jefff
88 * 22 7/19/99 5:08p Jefff
89 * Added text descriptions for selected weapons, complete with wipe
92 * 21 7/16/99 1:50p Dave
93 * 8 bit aabitmaps. yay.
95 * 20 7/15/99 9:20a Andsager
96 * FS2_DEMO initial checkin
98 * 19 7/11/99 3:20p Kellys
99 * Make sure we load high-res weapon rotations in 1024
101 * 18 7/09/99 5:54p Dave
102 * Seperated cruiser types into individual types. Added tons of new
103 * briefing icons. Campaign screen.
105 * 17 7/09/99 12:21a Dave
106 * Change weapon loop anim frame.
108 * 16 3/25/99 2:45p Neilk
111 * 15 3/23/99 9:23p Neilk
112 * fixed various multiplayer lock button problems
114 * 14 3/10/99 6:21p Neilk
115 * Added new artwork for hires
117 * 13 2/21/99 6:01p Dave
118 * Fixed standalone WSS packets.
120 * 12 2/18/99 11:46a Neilk
121 * hires interface coord support
123 * 11 2/11/99 3:08p Dave
124 * PXO refresh button. Very preliminary squad war support.
126 * 10 2/01/99 5:55p Dave
127 * Removed the idea of explicit bitmaps for buttons. Fixed text
128 * highlighting for disabled gadgets.
130 * 9 1/30/99 1:29a Dave
131 * Fixed nebula thumbnail problem. Full support for 1024x768 choose pilot
132 * screen. Fixed beam weapon death messages.
134 * 8 1/29/99 4:17p Dave
135 * New interface screens.
137 * 7 1/27/99 9:56a Dave
138 * Temporary checkin of beam weapons for Dan to make cool sounds.
140 * 6 12/18/98 1:13a Dave
141 * Rough 1024x768 support for Direct3D. Proper detection and usage through
144 * 5 11/30/98 1:07p Dave
145 * 16 bit conversion, first run.
147 * 4 11/17/98 11:12a Dave
148 * Removed player identification by address. Now assign explicit id #'s.
150 * 3 10/13/98 9:29a Dave
151 * Started neatening up freespace.h. Many variables renamed and
152 * reorganized. Added AlphaColors.[h,cpp]
154 * 2 10/07/98 10:53a Dave
157 * 1 10/07/98 10:50a Dave
159 * 119 6/17/98 11:06a Lawrance
160 * put in weapon description tooltip
162 * 118 6/13/98 6:01p Hoffoss
163 * Externalized all new (or forgot to be added) strings to all the code.
165 * 117 6/01/98 11:43a John
166 * JAS & MK: Classified all strings for localization.
168 * 116 5/19/98 8:35p Dave
169 * Revamp PXO channel listing system. Send campaign goals/events to
170 * clients for evaluation. Made lock button pressable on all screens.
172 * 115 5/18/98 2:49p Lawrance
173 * Put in weapon animation sound hook
175 * 114 5/08/98 7:52p Lawrance
176 * Add code to loop new weapon animations
178 * 113 5/06/98 11:50p Lawrance
179 * Clean up help overlay code for loadout screens
181 * 112 5/04/98 5:27p Johnson
182 * Fixed a team vs. team weapons loadout bug.
184 * 111 5/03/98 1:55a Lawrance
185 * Fix some sound problems with loadout screens
187 * 110 4/30/98 6:03p Lawrance
188 * Make drag and drop work better.
190 * 109 4/27/98 6:02p Dave
191 * Modify how missile scoring works. Fixed a team select ui bug. Speed up
192 * multi_lag system. Put in new main hall.
194 * 108 4/24/98 2:17a Lawrance
195 * repositioin ship name in weapons loadout
197 * 107 4/22/98 7:24p Dave
198 * Made sure the "player/ships" locked button for multiplayer appears on
199 * all briefing screens.
201 * 106 4/21/98 6:45p Dave
202 * AL: Fix bug with replacement weapons on ships
204 * 105 4/17/98 5:27p Dave
205 * More work on the multi options screen. Fixed many minor ui todo bugs.
207 * 104 4/16/98 8:05p Lawrance
208 * fix some bugs with numbers over-writing weapon icons
210 * 103 4/10/98 4:51p Hoffoss
211 * Made several changes related to tooltips.
213 * 102 4/08/98 1:18a Lawrance
214 * Fix bug that could occur when picking alternate weapons (ie count could
215 * have been wrong due to missile size)
217 * 101 4/07/98 5:42p Dave
218 * Put in support for ui display of voice system status (recording,
219 * playing back, etc). Make sure main hall music is stopped before
220 * entering a multiplayer game via ingame join.
222 * 100 4/02/98 11:40a Lawrance
223 * check for #ifdef DEMO instead of #ifdef DEMO_RELEASE
225 * 99 3/31/98 1:50p Duncan
226 * ALAN: fix bugs with selecting alternate weapons
228 * 98 3/30/98 12:18a Lawrance
229 * change some DEMO_RELEASE code to not compile code rather than return
232 * 97 3/29/98 1:24p Dave
233 * Make chatbox not clear between multiplayer screens. Select player ship
234 * as default in mp team select and weapons select screens. Made create
235 * game mission list use 2 fixed size columns.
237 * 96 3/29/98 12:55a Lawrance
238 * Get demo build working with limited set of data.
240 * 95 3/26/98 5:47p Lawrance
241 * Implement default weapon picking if default weapons not available in
244 * 94 3/25/98 8:43p Hoffoss
245 * Changed anim_play() to not be so damn complex when you try and call it.
247 * 93 3/25/98 11:23a Mike
248 * Fix stack overwrite due to async between MAX_SECONDARY_WEAPONS and
251 * 92 3/21/98 2:47p Dave
252 * Fixed chat packet routing problem on standalone. Fixed wss_request
253 * packet routing on standalone.
255 * 91 3/19/98 5:34p Lawrance
256 * Tweak drag/drop behavior in weapons loadout
258 * 90 3/14/98 2:48p Dave
259 * Cleaned up observer joining code. Put in support for file xfers to
260 * ingame joiners (observers or not). Revamped and reinstalled pseudo
263 * 89 3/12/98 4:03p Lawrance
264 * don't press buttons when icon dropped on them
266 * 88 3/10/98 1:35p Lawrance
267 * Fix default selected weapon bug
269 * 87 3/09/98 9:55p Lawrance
270 * Move secondary icons to the right to avoid overlap with numbers
272 * 86 3/09/98 11:13a Lawrance
273 * Fix up drop sound effects used in loadout screens.
275 * 85 3/06/98 5:36p Dave
276 * Finished up first rev of team vs team. Probably needs to be debugged
279 * 84 3/05/98 5:03p Dave
280 * More work on team vs. team support for multiplayer. Need to fix bugs in
283 * 83 3/01/98 3:26p Dave
284 * Fixed a few team select bugs. Put in multiplayer intertface sounds.
285 * Corrected how ships are disabled/enabled in team select/weapon select
288 * 82 2/28/98 7:04p Lawrance
289 * Don't show reset button in multiplayer
291 * 81 2/27/98 11:32a Andsager
292 * AL: Fix bug with showing valid weapon slots for ships that arrive late.
294 * 80 2/26/98 4:59p Allender
295 * groundwork for team vs team briefings. Moved weaponry pool into the
296 * Team_data structure. Added team field into the p_info structure.
297 * Allow for mutliple structures in the briefing code.
299 * 79 2/24/98 6:21p Lawrance
300 * Integrate new reset button into loadout screens
302 * 78 2/22/98 4:17p John
303 * More string externalization classification... 190 left to go!
305 * 77 2/22/98 12:19p John
306 * Externalized some strings
308 * 76 2/19/98 6:26p Dave
309 * Fixed a few file xfer bugs. Tweaked mp team select screen. Put in
310 * initial support for player data uploading.
312 * 75 2/18/98 10:37p Dave
313 * Fixed a mp team select bug which allowed players to commit at
314 * inappropriate times.
316 * 74 2/18/98 3:56p Dave
317 * Several bugs fixed for mp team select screen. Put in standalone packet
318 * routing for team select.
320 * 73 2/16/98 10:27a Lawrance
321 * Fix bug in wl_cull_illegal_weapons()
323 * 72 2/15/98 11:28p Allender
324 * allow increase in MAX_WEAPON_TYPES by chaning all bitfield references
326 * 71 2/13/98 5:15p Lawrance
327 * Fix help overlay bug in weapons loadout.
329 * 70 2/13/98 3:46p Dave
330 * Put in dynamic chatbox sizing. Made multiplayer file lookups use cfile
333 * 69 2/09/98 11:24p Lawrance
334 * Allow player to click on disallowed weapons, but don't let them drag
335 * them away from the list.
337 * 68 2/07/98 5:47p Lawrance
338 * reset flashing if a button gets highlighted
340 * 67 2/06/98 5:15p Jasen
341 * AL: Allow up to 10000 of any given missile in the pool
343 * 66 2/05/98 11:21p Lawrance
344 * When flashing buttons, use highlight frame
346 * 65 2/02/98 3:36p Jasen
347 * AL: remove weapon debug name, and allow for 2 frame weapon anis
349 * 64 2/02/98 3:21p Jasen
350 * Updated coords for weapon anim location.
352 * 63 1/20/98 5:52p Lawrance
353 * account for no player ship when moving to weapons loadout
355 * 62 1/20/98 2:23p Dave
356 * Removed optimized build warnings. 99% done with ingame join fixes.
358 * 61 1/20/98 11:08a Lawrance
359 * Fix sound error when clicking on a weapon.
361 * 60 1/19/98 2:17p Lawrance
362 * Fix bug that was not recognizing non-default weapons on late-arriving
365 * 59 1/15/98 4:09p Lawrance
366 * fix weapon scrolling bug
368 * 58 1/14/98 6:44p Lawrance
369 * Take out unnecessary instance checking when freeing anims.
371 * 57 1/12/98 5:17p Dave
372 * Put in a bunch of multiplayer sequencing code. Made weapon/ship select
373 * work through the standalone.
375 * 56 1/10/98 12:47a Lawrance
376 * update some comments
378 * 55 1/09/98 6:06p Dave
379 * Put in network sound support for multiplayer ship/weapon select
380 * screens. Made clients exit game correctly through warp effect. Fixed
381 * main hall menu help overlay bug.
383 * 54 1/09/98 4:08p John
384 * Fixed a bug loading too many icon frames
386 * 53 1/08/98 10:55p Lawrance
387 * Fix bug where forbidden weapons were not updated when a ship was
388 * changed before weapons loadout is entered.
390 * 52 1/08/98 5:19p Sandeep
391 * Alan made a change which fixed missions with more than 4 types of
394 * 51 1/08/98 11:38a Lawrance
397 * 50 1/08/98 11:36a Lawrance
398 * Get ship select and weapons loadout icon dropping sound effects working
399 * for single and multiplayer
401 * 49 1/02/98 9:10p Lawrance
402 * Big changes to how colors get set on the HUD.
404 * 48 12/30/97 6:08p Lawrance
405 * Fix bug where player discarded ship before entering weapon select
407 * 47 12/29/97 4:21p Lawrance
408 * Flash buttons on briefing/ship select/weapons loadout when enough time
409 * has elapsed without activity.
411 * 46 12/29/97 10:11a Lawrance
412 * Don't play drop sound when a weapon is clicked on in a slot.
414 * 45 12/24/97 8:54p Lawrance
415 * Integrating new popup code
417 * 44 12/24/97 1:19p Lawrance
418 * fix some bugs with the multiplayer ship/weapons loadout
420 * 43 12/23/97 5:25p Allender
421 * more fixes to multiplayer ship selection. Fixed strange reentrant
422 * problem with cf_callback when loading freespace data
424 * 42 12/23/97 11:59a Allender
425 * changes to ship/wespon selection for multplayer. added sounds to some
426 * interface screens. Update and modiied end-of-briefing packets -- yet
429 * 41 12/23/97 11:48a Lawrance
430 * fix bug that could cause assert when swapping secondary weapons
432 * 40 12/22/97 6:18p Lawrance
433 * Get save/restore of player loadout working with new code
435 * 39 12/22/97 1:40a Lawrance
436 * Re-write ship select/weapons loadout to be multiplayer friendly
438 * 38 12/19/97 1:23p Dave
439 * Put in multiplayer groundwork for new weapon/ship select screens.
441 * 37 12/19/97 12:44p Dave
442 * Put in final touches on ship/weapon select. However, this is all going
448 #include "missionscreencommon.h"
449 #include "missionweaponchoice.h"
450 #include "missionshipchoice.h"
456 #include "snazzyui.h"
457 #include "animplay.h"
458 #include "freespace.h"
459 #include "gamesequence.h"
461 #include "missionbrief.h"
464 #include "animplay.h"
465 #include "contexthelp.h"
467 #include "linklist.h"
468 #include "multimsgs.h"
470 #include "multiteamselect.h"
472 #include "alphacolors.h"
473 #include "localize.h"
475 //#define MAX_PRIMARY_BANKS 3
476 //#define MAX_SECONDARY_BANKS 3 // Lowered from 5 to 3 by MK on 3/25/98. This needs to be <= MAX_WL_SECONDARY or you'll get stack overwrites.
478 #define IS_BANK_PRIMARY(x) (x<3?1:0)
479 #define IS_BANK_SECONDARY(x) (x>2?1:0)
481 #define IS_LIST_PRIMARY(x) (Weapon_info[x].subtype==WP_MISSILE?0:1)
482 #define IS_LIST_SECONDARY(x) (Weapon_info[x].subtype==WP_MISSILE?1:0)
485 #if (MAX_PRIMARY_BANKS > MAX_WL_PRIMARY)
486 #error "Illegal: MAX_PRIMARY_BANKS greater than MAX_WL_PRIMARY"
489 #if (MAX_SECONDARY_BANKS > MAX_WL_SECONDARY)
490 #error "Illegal: MAX_SECONDARY_BANKS greater than MAX_WL_SECONDARY"
494 //////////////////////////////////////////////////////////////////
496 //////////////////////////////////////////////////////////////////
498 // This game-wide global flag is set to 1 to indicate that the weapon
499 // select screen has been opened and memory allocated. This flag
500 // is needed so we can know if weapon_select_close() needs to called if
501 // restoring a game from the Options screen invoked from weapon select
502 int Weapon_select_open = 0;
504 //////////////////////////////////////////////////////////////////
506 //////////////////////////////////////////////////////////////////
508 typedef struct wl_bitmap_group
515 #define WEAPON_ANIM_LOOP_FRAME 1
517 #define WEAPON_ANIM_LOOP_FRAME 52 // frame (from 0) to loop weapon anim
520 #define WEAPON_ICON_FRAME_NORMAL 0
521 #define WEAPON_ICON_FRAME_HOT 1
522 #define WEAPON_ICON_FRAME_SELECTED 2
523 #define WEAPON_ICON_FRAME_DISABLED 3
525 // Weapn loadout specific buttons
526 #define NUM_WEAPON_BUTTONS 7
527 #define WL_BUTTON_SCROLL_PRIMARY_UP 0
528 #define WL_BUTTON_SCROLL_PRIMARY_DOWN 1
529 #define WL_BUTTON_SCROLL_SECONDARY_UP 2
530 #define WL_BUTTON_SCROLL_SECONDARY_DOWN 3
531 #define WL_BUTTON_RESET 4
532 #define WL_BUTTON_DUMMY 5
533 #define WL_BUTTON_MULTI_LOCK 6
534 UI_WINDOW Weapon_ui_window;
535 //UI_BUTTON Weapon_buttons[NUM_WEAPON_BUTTONS];
537 static char *Wl_mask_single[GR_NUM_RESOLUTIONS] = {
542 static char *Wl_mask_multi[GR_NUM_RESOLUTIONS] = {
543 "weaponloadoutmulti-m",
544 "2_weaponloadoutmulti-m"
547 static char *Wl_loadout_select_mask[GR_NUM_RESOLUTIONS] = {
553 static char *Weapon_select_background_fname[GR_NUM_RESOLUTIONS] = {
558 static char *Weapon_select_multi_background_fname[GR_NUM_RESOLUTIONS] = {
559 "WeaponLoadoutMulti",
560 "2_WeaponLoadoutMulti"
563 int Weapon_select_background_bitmap; // bitmap for weapon select brackground
565 static MENU_REGION Weapon_select_region[NUM_WEAPON_REGIONS];
566 static int Num_weapon_select_regions;
568 // Mask bitmap pointer and Mask bitmap_id
569 static bitmap* WeaponSelectMaskPtr; // bitmap pointer to the weapon select mask bitmap
570 static ubyte* WeaponSelectMaskData; // pointer to actual bitmap data
571 static int Weaponselect_mask_w, Weaponselect_mask_h;
572 static int WeaponSelectMaskBitmap; // bitmap id of the weapon select mask bitmap
575 // convenient struct for handling all button controls
580 UI_BUTTON button; // because we have a class inside this struct, we need the constructor below..
582 wl_buttons(char *name, int x1, int y1, int xt1, int yt1, int h) : filename(name), x(x1), y(y1), xt(xt1), yt(yt1), hotspot(h) {}
585 static wl_buttons Buttons[GR_NUM_RESOLUTIONS][NUM_WEAPON_BUTTONS] = {
587 wl_buttons("WLB_26", 24, 125, -1, -1, 26),
588 wl_buttons("WLB_27", 24, 276, -1, -1, 27),
589 wl_buttons("WLB_08", 24, 303, -1, -1, 8),
590 wl_buttons("WLB_09", 24, 454, -1, -1, 9),
591 wl_buttons("ssb_39", 571, 347, -1, -1, 39),
592 wl_buttons("ssb_39", 0, 0, -1, -1, 99),
593 wl_buttons("TSB_34", 603, 374, -1, -1, 34)
596 wl_buttons("2_WLB_26", 39, 200, -1, -1, 26),
597 wl_buttons("2_WLB_27", 39, 442, -1, -1, 27),
598 wl_buttons("2_WLB_08", 39, 485, -1, -1, 8),
599 wl_buttons("2_WLB_09", 39, 727, -1, -1, 9),
600 wl_buttons("2_ssb_39", 913, 556, -1, -1, 39),
601 wl_buttons("2_ssb_39", 0, 0, -1, -1, 99),
602 wl_buttons("2_TSB_34", 966, 599, -1, -1, 34)
606 //static wl_bitmap_group wl_button_bitmaps[NUM_WEAPON_BUTTONS];
608 static int Weapon_button_scrollable[NUM_WEAPON_BUTTONS] = {0, 0, 0, 0, 0, 0, 0};
610 #define MAX_WEAPON_ICONS_ON_SCREEN 8
612 // X and Y locations of the weapon icons in the scrollable lists
613 //int Weapon_icon_x[MAX_WEAPON_ICONS_ON_SCREEN] = {27, 27, 27, 27, 36, 36, 36, 36};
614 //int Weapon_icon_y[MAX_WEAPON_ICONS_ON_SCREEN] = {152, 182, 212, 242, 331, 361, 391, 421};
615 static int Wl_weapon_icon_coords[GR_NUM_RESOLUTIONS][MAX_WEAPON_ICONS_ON_SCREEN][2] = {
639 static int Wl_bank_coords[GR_NUM_RESOLUTIONS][MAX_WL_WEAPONS][2] = {
660 static int Wl_bank_count_draw_flags[MAX_WL_WEAPONS] = {
661 0, 0, 0, // primaries -- dont draw counts
662 1, 1, 1, 1 // secondaries -- do draw counts
666 static int Weapon_anim_class = -1;
667 static int Last_wl_ship_class;
669 static int Wl_overhead_coords[GR_NUM_RESOLUTIONS][2] = {
680 static int Wl_weapon_ani_coords[GR_NUM_RESOLUTIONS][2] = {
689 static int Wl_weapon_ani_coords_multi[GR_NUM_RESOLUTIONS][2] = {
699 static int Wl_weapon_desc_coords[GR_NUM_RESOLUTIONS][2] = {
708 static int Wl_delta_x, Wl_delta_y;
710 static int Wl_ship_name_coords[GR_NUM_RESOLUTIONS][2] = {
720 ///////////////////////////////////////////////////////////////////////
722 ///////////////////////////////////////////////////////////////////////
723 typedef struct wl_ship_class_info
727 anim_instance_t *anim_instance;
728 } wl_ship_class_info;
730 wl_ship_class_info Wl_ships[MAX_SHIP_TYPES];
732 typedef struct wl_icon_info
734 int icon_bmaps[NUM_ICON_FRAMES];
735 int current_icon_bmap;
738 anim_instance_t *anim_instance;
741 wl_icon_info Wl_icons_teams[MAX_TEAMS][MAX_WEAPON_TYPES];
742 wl_icon_info *Wl_icons;
744 int Plist[MAX_WEAPON_TYPES]; // used to track scrolling of primary icon list
745 int Plist_start, Plist_size;
747 int Slist[MAX_WEAPON_TYPES]; // used to track scrolling of primary icon list
748 int Slist_start, Slist_size;
750 static int Selected_wl_slot = -1; // Currently selected ship slot
751 static int Selected_wl_class = -1; // Class of weapon that is selected
752 static int Hot_wl_slot = -1; // Ship slot that mouse is over (0..11)
753 static int Hot_weapon_icon = -1; // Icon number (0-7) which has mouse over it
754 static int Hot_weapon_bank = -1; // index (0-7) for weapon slot on ship that has a droppable icon over it
755 static int Hot_weapon_bank_icon = -1;
757 static int Wl_mouse_down_on_region = -1;
761 #define WEAPON_DESC_WIPE_TIME 1.5f // time in seconds for wipe to occur (over WEAPON_DESC_MAX_LENGTH number of chars)
762 #define WEAPON_DESC_MAX_LINES 7 // max lines in the description incl. title
763 #define WEAPON_DESC_MAX_LENGTH 50 // max chars per line of description text
764 static int Weapon_desc_wipe_done = 0;
765 static float Weapon_desc_wipe_time_elapsed = 0.0f;
766 static char Weapon_desc_lines[WEAPON_DESC_MAX_LINES][WEAPON_DESC_MAX_LENGTH]; // 1st 2 lines are title, rest are desc
768 // maximum width the weapon title can be -- used in the line breaking
769 int Weapon_title_max_width[GR_NUM_RESOLUTIONS] = { 200, 320 };
771 static int Wl_new_weapon_title_coords[GR_NUM_RESOLUTIONS][2] = {
780 static int Wl_new_weapon_title_coords_multi[GR_NUM_RESOLUTIONS][2] = {
789 static int Wl_new_weapon_desc_coords[GR_NUM_RESOLUTIONS][2] = {
798 static int Wl_new_weapon_desc_coords_multi[GR_NUM_RESOLUTIONS][2] = {
808 #define WEAPON_SELECT_NUM_TEXT 2
809 UI_XSTR Weapon_select_text[GR_NUM_RESOLUTIONS][WEAPON_SELECT_NUM_TEXT] = {
811 { "Reset", 1337, 580, 337, UI_XSTR_COLOR_GREEN, -1, &Buttons[0][WL_BUTTON_RESET].button },
812 { "Lock", 1270, 602, 364, UI_XSTR_COLOR_GREEN, -1, &Buttons[0][WL_BUTTON_MULTI_LOCK].button }
815 { "Reset", 1337, 938, 546, UI_XSTR_COLOR_GREEN, -1, &Buttons[1][WL_BUTTON_RESET].button },
816 { "Lock", 1270, 964, 584, UI_XSTR_COLOR_GREEN, -1, &Buttons[1][WL_BUTTON_MULTI_LOCK].button }
821 ///////////////////////////////////////////////////////////////////////
823 ///////////////////////////////////////////////////////////////////////
824 typedef struct carried_icon
826 int weapon_class; // index Wl_icons[] for carried icon (-1 if carried from bank)
827 int num; // number of units of weapon
828 int from_bank; // bank index that icon came from (0..2 primary, 3..6 secondary). -1 if from list
829 int from_slot; // ship slot that weapon is part of
833 static carried_icon Carried_wl_icon;
835 // forward declarations
836 void draw_wl_icons();
837 void wl_draw_ship_weapons(int index);
838 void wl_pick_icon_from_list(int index);
839 void pick_from_ship_slot(int num);
840 void start_weapon_animation(int weapon_class);
841 void stop_weapon_animation();
842 void wl_start_slot_animation(int n);
843 int wl_get_pilot_subsys_index(p_object *pobjp);
845 void wl_reset_to_defaults();
847 void wl_set_selected_slot(int slot_num);
848 void wl_maybe_reset_selected_slot();
849 void wl_maybe_reset_selected_weapon_class();
851 void wl_render_icon_count(int num, int x, int y);
852 void wl_render_weapon_desc();
856 // carry icon functions
857 void wl_reset_carried_icon();
858 int wl_icon_being_carried();
859 void wl_set_carried_icon(int from_bank, int from_slot, int weapon_class);
862 // Determine hack offset for how to draw fury missile icon.
863 int wl_fury_missile_offset_hack(int weapon_class, int num_missiles)
865 if ( weapon_class < 0 ) {
869 if ( num_missiles < 100 ) {
873 if ( !strnicmp(Weapon_info[weapon_class].name, NOX("fury"), 4) ) {
880 char *wl_tooltip_handler(char *str)
882 if (Selected_wl_class < 0)
885 if (!stricmp(str, "@weapon_desc")) {
889 str = Weapon_info[Selected_wl_class].desc;
890 gr_get_string_size(&w, &h, str);
891 x = Wl_weapon_desc_coords[gr_screen.res][0] - w / 2;
892 y = Wl_weapon_desc_coords[gr_screen.res][1] - h / 2;
894 gr_set_color_fast(&Color_black);
895 gr_rect(x - 5, y - 5, w + 10, h + 10);
897 gr_set_color_fast(&Color_bright_white);
898 gr_string(x, y, str);
905 // reset the data inside the Carried_wl_icon
906 void wl_reset_carried_icon()
908 Carried_wl_icon.weapon_class = -1;
909 Carried_wl_icon.num = 0;
910 Carried_wl_icon.from_bank = -1;
911 Carried_wl_icon.from_slot = -1;
914 // Is an icon being carried?
915 int wl_icon_being_carried()
917 if ( Carried_wl_icon.weapon_class >= 0 ) {
924 // Set carried icon data
925 void wl_set_carried_icon(int from_bank, int from_slot, int weapon_class)
929 Carried_wl_icon.from_bank = from_bank;
930 Carried_wl_icon.from_slot = from_slot;
931 Carried_wl_icon.weapon_class = weapon_class;
933 mouse_get_pos( &mx, &my );
934 Carried_wl_icon.from_x=mx;
935 Carried_wl_icon.from_y=my;
937 Buttons[gr_screen.res][WL_BUTTON_DUMMY].button.capture_mouse();
940 // determine if the carried icon has moved
941 int wl_carried_icon_moved()
944 mouse_get_pos( &mx, &my );
945 if ( Carried_wl_icon.from_x != mx || Carried_wl_icon.from_y != my) {
952 // return the index for the pilot subsystem in the parse object
953 int wl_get_pilot_subsys_index(p_object *pobjp)
955 int pilot_index, start_index, end_index, i;
957 // see if there is a PILOT subystem
958 start_index = pobjp->subsys_index;
959 end_index = start_index + pobjp->subsys_count;
961 for ( i = start_index; i < end_index; i++ ) {
962 if ( !stricmp(Subsys_status[i].name, NOX("pilot") ) ) {
968 if ( pilot_index == -1 ) {
969 Error(LOCATION,"Parse object doesn't have a pilot subsystem\n");
976 // Pause the current weapon animation
979 if ( Weapon_anim_class >= 0 && Wl_icons[Weapon_anim_class].anim_instance ) {
980 anim_pause(Wl_icons[Weapon_anim_class].anim_instance);
984 // Unpause the current weapon animation
985 void wl_unpause_anim()
987 if ( Weapon_anim_class >= 0 && Wl_icons[Weapon_anim_class].anim_instance ) {
988 anim_unpause(Wl_icons[Weapon_anim_class].anim_instance);
992 // ---------------------------------------------------------------------------------
993 // weapon_button_do()
995 void weapon_button_do(int i)
998 case PRIMARY_SCROLL_UP:
999 if ( common_scroll_up_pressed(&Plist_start, Plist_size, 4) ) {
1000 gamesnd_play_iface(SND_SCROLL);
1002 gamesnd_play_iface(SND_GENERAL_FAIL);
1006 case PRIMARY_SCROLL_DOWN:
1007 if ( common_scroll_down_pressed(&Plist_start, Plist_size, 4) ) {
1008 gamesnd_play_iface(SND_SCROLL);
1010 gamesnd_play_iface(SND_GENERAL_FAIL);
1014 case SECONDARY_SCROLL_UP:
1015 if ( common_scroll_up_pressed(&Slist_start, Slist_size, 4) ) {
1016 gamesnd_play_iface(SND_SCROLL);
1018 gamesnd_play_iface(SND_GENERAL_FAIL);
1022 case SECONDARY_SCROLL_DOWN:
1023 if ( common_scroll_down_pressed(&Slist_start, Slist_size, 4) ) {
1024 gamesnd_play_iface(SND_SCROLL);
1026 gamesnd_play_iface(SND_GENERAL_FAIL);
1030 case WL_RESET_BUTTON_MASK:
1031 wl_reset_to_defaults();
1034 case WL_BUTTON_MULTI_LOCK:
1035 Assert(Game_mode & GM_MULTIPLAYER);
1036 // the "lock" button has been pressed
1037 multi_ts_lock_pressed();
1039 // disable the button if it is now locked
1040 if(multi_ts_is_locked()){
1041 Buttons[gr_screen.res][WL_BUTTON_MULTI_LOCK].button.disable();
1050 // -------------------------------------------------------------------
1051 // weapon_check_buttons()
1053 // Check if any weapons loadout screen buttons have been pressed, and
1054 // call weapon_button_do() if they have.
1056 void weapon_check_buttons()
1061 for ( i = 0; i < NUM_WEAPON_BUTTONS; i++ ) {
1062 b = &Buttons[gr_screen.res][i];
1064 if ( b->button.pressed() ) {
1065 if(i == WL_BUTTON_MULTI_LOCK){
1066 weapon_button_do(i);
1068 weapon_button_do(b->hotspot);
1074 // -------------------------------------------------------------------
1075 // wl_redraw_pressed_buttons()
1077 // Redraw any weapon loadout buttons that are pressed down. This function is needed
1078 // since we sometimes need to draw pressed buttons last to ensure the entire
1079 // button gets drawn (and not overlapped by other buttons)
1081 void wl_redraw_pressed_buttons()
1086 common_redraw_pressed_buttons();
1088 for ( i = 0; i < NUM_WEAPON_BUTTONS; i++ ) {
1089 b = &Buttons[gr_screen.res][i];
1090 if ( b->button.button_down() ) {
1091 b->button.draw_forced(2);
1096 // ---------------------------------------------------------------------------------
1097 // weapon_buttons_init()
1099 void weapon_buttons_init()
1104 for ( i = 0; i < NUM_WEAPON_BUTTONS; i++ ) {
1105 b = &Buttons[gr_screen.res][i];
1106 b->button.create( &Weapon_ui_window, "", Buttons[gr_screen.res][i].x, Buttons[gr_screen.res][i].y, 60, 30, Weapon_button_scrollable[i]);
1107 // set up callback for when a mouse first goes over a button
1108 b->button.set_highlight_action( common_play_highlight_sound );
1109 b->button.set_bmaps(Buttons[gr_screen.res][i].filename);
1110 b->button.link_hotspot(Buttons[gr_screen.res][i].hotspot);
1113 if ( Game_mode & GM_MULTIPLAYER ) {
1114 Buttons[gr_screen.res][WL_BUTTON_RESET].button.hide();
1115 Buttons[gr_screen.res][WL_BUTTON_RESET].button.disable();
1117 // if we're not the host of the game (or a team captain in team vs. team mode), disable the lock button
1118 if(Netgame.type_flags & NG_TYPE_TEAM){
1119 if(!(Net_player->flags & NETINFO_FLAG_TEAM_CAPTAIN)){
1120 Buttons[gr_screen.res][WL_BUTTON_MULTI_LOCK].button.disable();
1123 if(!(Net_player->flags & NETINFO_FLAG_GAME_HOST)){
1124 Buttons[gr_screen.res][WL_BUTTON_MULTI_LOCK].button.disable();
1128 Buttons[gr_screen.res][WL_BUTTON_MULTI_LOCK].button.hide();
1129 Buttons[gr_screen.res][WL_BUTTON_MULTI_LOCK].button.disable();
1133 for(i=0; i<WEAPON_SELECT_NUM_TEXT; i++) {
1134 Weapon_ui_window.add_XSTR(&Weapon_select_text[gr_screen.res][i]);
1137 Buttons[gr_screen.res][WL_BUTTON_DUMMY].button.hide();
1138 Buttons[gr_screen.res][WL_BUTTON_DUMMY].button.disable();
1141 // ---------------------------------------------------------------------------------
1142 // wl_render_overhead_view()
1144 void wl_render_overhead_view(float frametime)
1146 char name[NAME_LENGTH + CALLSIGN_LEN];
1147 wl_ship_class_info *wl_ship;
1150 if ( Selected_wl_slot == -1 ) {
1154 ship_class = Wss_slots[Selected_wl_slot].ship_class;
1156 // check if ship class has changed and maybe play sound
1157 if (Last_wl_ship_class != ship_class) {
1158 if (Last_wl_ship_class != -1) {
1159 gamesnd_play_iface(SND_ICON_DROP);
1161 Last_wl_ship_class = ship_class;
1164 wl_ship = &Wl_ships[ship_class];
1166 if ( wl_ship->anim_instance == NULL ) {
1167 if ( wl_ship->overhead_bitmap < 0 ) {
1169 if (gr_screen.res == GR_640)
1172 wl_ship->overhead_bitmap = bm_load(Ship_info[ship_class].overhead_filename);
1175 char filename[NAME_LENGTH+2] = "2_";
1176 strcat(filename, Ship_info[ship_class].overhead_filename);
1177 wl_ship->overhead_bitmap = bm_load(filename);
1179 if ( wl_ship->overhead_bitmap < 0 ) {
1180 Int3(); // bad things happened
1184 gr_set_bitmap(wl_ship->overhead_bitmap);
1185 gr_bitmap(Wl_overhead_coords[gr_screen.res][0], Wl_overhead_coords[gr_screen.res][1]);
1188 ss_return_name(Selected_wl_slot/4, Selected_wl_slot%4, name);
1189 gr_set_color_fast(&Color_normal);
1190 gr_string(Wl_ship_name_coords[gr_screen.res][0], Wl_ship_name_coords[gr_screen.res][1], name);
1193 // ---------------------------------------------------------------------------------
1194 // wl_get_ship_class()
1197 int wl_get_ship_class(int wl_slot)
1199 return Wss_slots[wl_slot].ship_class;
1202 // Return true if weapon_flags indicates a weapon that is legal for use in current game type.
1203 // Function added by MK on 9/6/99 to support separate legal loadouts for dogfight missions.
1204 int weapon_allowed_for_game_type(int weapon_flags)
1208 if ((Game_mode & GM_MULTIPLAYER) && (Netgame.type_flags & NG_TYPE_DOGFIGHT)) {
1209 if (weapon_flags & (1 << 1))
1211 } else if (weapon_flags & (1 << 0))
1217 // go through the possible weapons to choose from, and flag some as disabled since
1218 // that ship class cannot use that kind of weapon. The weapon filter is specified
1219 // in ships.tbl, where each ship has a list of all the possible weapons it can use.
1220 void wl_set_disabled_weapons(int ship_class)
1225 if ( ship_class == - 1 )
1228 Assert(ship_class >= 0 && ship_class < MAX_SHIP_TYPES);
1230 sip = &Ship_info[ship_class];
1232 for ( i = 0; i < MAX_WEAPON_TYPES; i++ ) {
1233 // Determine whether weapon #i is allowed on this ship class in the current type of mission.
1234 // As of 9/6/99, the only difference is dogfight missions have a different list of legal weapons.
1235 Wl_icons[i].can_use = weapon_allowed_for_game_type(sip->allowed_weapons[i]);
1239 // ---------------------------------------------------------------------------------
1240 // maybe_select_wl_slot()
1242 // A slot index was clicked on, mabye change Selected_wl_slot
1243 void maybe_select_wl_slot(int block, int slot)
1247 if ( Wss_num_wings <= 0 )
1250 sidx = block*4 + slot;
1251 if ( Wss_slots[sidx].ship_class < 0 ) {
1255 wl_set_selected_slot(sidx);
1258 // ---------------------------------------------------------------------------------
1259 // maybe_select_new_weapon()
1261 // Change to the weapon that corresponds to index in the weapon list
1263 // input: index => weapon icon index (0-7)
1265 void maybe_select_new_weapon(int index)
1269 // if a weapon is being carried, do nothing
1270 if ( wl_icon_being_carried() ) {
1274 int region_index = ICON_PRIMARY_0+index;
1276 region_index = ICON_SECONDARY_0 + (index - 4);
1279 if ( Wl_mouse_down_on_region != region_index ) {
1284 weapon_class = Plist[Plist_start+index];
1286 weapon_class = Slist[Slist_start+index-4];
1289 if ( weapon_class >= 0 ) {
1290 Selected_wl_class = weapon_class;
1291 wl_pick_icon_from_list(index);
1295 // ---------------------------------------------------------------------------------
1296 // maybe_select_new_ship_weapon()
1298 // Change to the weapon that corresponds to the ship weapon slot
1300 // input: index -> index of bank (0..2 primary, 0..6 secondary)
1301 void maybe_select_new_ship_weapon(int index)
1303 int *wep, *wep_count;
1305 if ( Selected_wl_slot == -1 )
1308 if ( wl_icon_being_carried() ) {
1312 wep = Wss_slots[Selected_wl_slot].wep;
1313 wep_count = Wss_slots[Selected_wl_slot].wep_count;
1315 if ( wep[index] < 0 || wep_count[index] <= 0 ) {
1319 if ( Wl_mouse_down_on_region != (ICON_SHIP_PRIMARY_0+index) ) {
1324 Selected_wl_class = wep[index];
1327 // Initialize Wl_pool[] to mission deafult
1328 void wl_init_pool(team_data *td)
1332 for ( i = 0; i < MAX_WEAPON_TYPES; i++ ) {
1336 for ( i = 0; i < MAX_WEAPON_TYPES; i++ ) {
1337 Wl_pool[i] = td->weaponry_pool[i]; // read from mission
1341 // load the icons for a specific ship class
1342 void wl_load_icons(int weapon_class)
1345 int first_frame, num_frames, i;
1347 icon = &Wl_icons[weapon_class];
1349 first_frame = bm_load_animation(Weapon_info[weapon_class].icon_filename, &num_frames);
1350 if ( first_frame == -1 ) {
1351 Int3(); // Could not load in icon frames.. get Alan
1355 for ( i = 0; i < num_frames ; i++ ) {
1356 icon->icon_bmaps[i] = first_frame+i;
1360 // Load in a specific weapon animation. The data is loaded as a memory-mapped file since these animations
1362 void wl_load_anim(int weapon_class)
1364 char animation_filename[CF_MAX_FILENAME_LENGTH+4];
1367 icon = &Wl_icons[weapon_class];
1368 Assert( icon->anim == NULL );
1371 // If we are in 1024x768, we first want to append "2_" in front of the filename
1372 if (gr_screen.res == GR_1024) {
1373 Assert(strlen(Weapon_info[weapon_class].anim_filename) <= 30);
1374 strcpy(animation_filename, "2_");
1375 strcat(animation_filename, Weapon_info[weapon_class].anim_filename);
1377 // now check if file exists
1378 // GRR must add a .ANI at the end for detection
1379 strcat(animation_filename,".ani");
1380 icon->anim = anim_load(animation_filename, 1);
1382 if (icon->anim == NULL) {
1383 mprintf(("Weapon ANI: Can not find %s, using lowres version instead.\n",animation_filename));
1384 strcpy(animation_filename, Weapon_info[weapon_class].anim_filename);
1385 icon->anim = anim_load(animation_filename, 1);
1389 if (!cf_exist(animation_filename, CF_TYPE_INTERFACE)) {
1390 // file does not exist, use original low res version
1391 mprintf(("Weapon ANI: Can not find %s, using lowres version instead.\n",animation_filename));
1392 strcpy(animation_filename, Weapon_info[weapon_class].anim_filename);
1394 animation_filename[strlen(animation_filename) - 4] = '\0';
1395 mprintf(("Weapon ANI: Found hires version of %s\n",animation_filename));
1399 strcpy(animation_filename, Weapon_info[weapon_class].anim_filename);
1400 // load the compressed ship animation into memory
1401 // NOTE: if last parm of load_anim is 1, the anim file is mapped to memory
1402 icon->anim = anim_load(animation_filename, 1);
1405 if ( icon->anim == NULL ) {
1406 Int3(); // couldn't load anim filename.. get Alan
1410 // Load in any weapon animations. This function assumes that Wl_pool has been inited.
1411 void wl_load_all_anims()
1413 #ifndef DEMO // not for FS2_DEMO
1417 // init anim members for weapon animations
1418 for ( i = 0; i < MAX_WEAPON_TYPES; i++ ) {
1419 Wl_icons[i].anim = NULL;
1420 Wl_icons[i].anim_instance = NULL;
1423 // init anim member for overhead ship animations
1424 for ( i = 0; i < MAX_SHIP_TYPES; i++ ) {
1425 Wl_ships[i].anim = NULL;
1426 Wl_ships[i].anim_instance = NULL;
1429 // load up the animations used for weapons (they are memory-mapped)
1430 for ( i = 0; i < MAX_WEAPON_TYPES; i++ ) {
1431 if ( Wl_pool[i] > 0 ) {
1439 // release any anim instances
1440 void wl_unload_all_anim_instances()
1442 // stop any weapon anim instances
1443 for ( int i = 0; i < MAX_WEAPON_TYPES; i++ ) {
1444 if ( Wl_icons[i].anim_instance ) {
1445 anim_release_render_instance(Wl_icons[i].anim_instance);
1446 Wl_icons[i].anim_instance = NULL;
1450 // stop any overhead anim instances
1451 for (int i = 0; i < MAX_SHIP_TYPES; i++ ) {
1452 if ( Wl_ships[i].anim_instance ) {
1453 anim_release_render_instance(Wl_ships[i].anim_instance);
1454 Wl_ships[i].anim_instance = NULL;
1459 // free source anim data if allocated
1460 void wl_unload_all_anims()
1464 // unload overhead anim instances
1465 for ( i = 0; i < MAX_SHIP_TYPES; i++ ) {
1466 if ( Wl_ships[i].anim ) {
1467 anim_free(Wl_ships[i].anim);
1468 Wl_ships[i].anim = NULL;
1472 // unload weapon anim instances
1473 for ( i = 0; i < MAX_WEAPON_TYPES; i++ ) {
1474 if ( Wl_icons[i].anim ) {
1475 anim_free(Wl_icons[i].anim);
1476 Wl_icons[i].anim = NULL;
1481 // load all the icons for weapons in the pool
1482 void wl_load_all_icons()
1484 #ifndef DEMO // not for FS2_DEMO
1488 for ( i = 0; i < MAX_WEAPON_TYPES; i++ ) {
1490 Wl_icons[i].anim = NULL;
1491 Wl_icons[i].anim_instance = NULL;
1492 for ( j = 0; j < NUM_ICON_FRAMES; j++ ) {
1493 Wl_icons[i].icon_bmaps[j] = -1;
1496 if ( Wl_pool[i] > 0 ) {
1504 // wl_unload_icons() frees the bitmaps used for weapon icons
1505 void wl_unload_icons()
1510 for ( i = 0; i < MAX_WEAPON_TYPES; i++ ) {
1511 icon = &Wl_icons[i];
1513 for ( j = 0; j < NUM_ICON_FRAMES; j++ ) {
1514 if ( icon->icon_bmaps[j] >= 0 ) {
1515 bm_release(icon->icon_bmaps[j]);
1516 icon->icon_bmaps[j] = -1;
1522 // init ship-class specific data
1523 void wl_init_ship_class_data()
1526 wl_ship_class_info *wl_ship;
1528 for ( i=0; i<MAX_SHIP_TYPES; i++ ) {
1529 wl_ship = &Wl_ships[i];
1530 wl_ship->overhead_bitmap = -1;
1531 wl_ship->anim = NULL;
1532 wl_ship->anim_instance = NULL;
1536 // free any allocated ship-class specific data
1537 void wl_free_ship_class_data()
1540 wl_ship_class_info *wl_ship;
1542 for ( i=0; i<MAX_SHIP_TYPES; i++ ) {
1543 wl_ship = &Wl_ships[i];
1545 if ( wl_ship->overhead_bitmap != -1 ) {
1546 bm_release(wl_ship->overhead_bitmap);
1547 wl_ship->overhead_bitmap = -1;
1550 if ( wl_ship->anim != NULL ) {
1551 wl_ship->anim = NULL;
1554 if ( wl_ship->anim_instance != NULL ) {
1555 wl_ship->anim_instance = NULL;
1560 // Set selected slot to first placed ship
1561 void wl_reset_selected_slot()
1564 Selected_wl_slot = -1;
1566 // in multiplayer, select the slot of the player's ship by default
1567 if((Game_mode & GM_MULTIPLAYER) && !MULTI_PERM_OBSERVER(Net_players[MY_NET_PLAYER_NUM]) && (Wss_slots[Net_player->p_info.ship_index].ship_class >= 0)){
1568 wl_set_selected_slot(Net_player->p_info.ship_index);
1572 for ( i=0; i<MAX_WSS_SLOTS; i++ ) {
1573 if ( !ss_disabled_slot(i) ) {
1574 if ( ss_wing_slot_is_console_player(i) && (Wss_slots[i].ship_class >= 0) ) {
1575 wl_set_selected_slot(i);
1581 // Didn't locate player ship, so just select the first ship we find
1582 for ( i=0; i<MAX_WSS_SLOTS; i++ ) {
1583 if ( Wss_slots[i].ship_class >= 0 ) {
1584 wl_set_selected_slot(i);
1590 // called whenever it is possible that the current selected slot has had it's ship disappear
1591 void wl_maybe_reset_selected_slot()
1595 if ( Selected_wl_slot == -1 ) {
1599 if ( Wss_slots[Selected_wl_slot].ship_class < 0 ) {
1604 wl_reset_selected_slot();
1608 // If Selected_wl_class is -1, choose the first weapon available from the pool for an animation
1609 // - on second thought, choose the first weapon that is oin the ship, then go to the pools
1610 void wl_maybe_reset_selected_weapon_class()
1614 if ( Selected_wl_class >= 0 )
1617 // try to locate a weapon class to show animation for
1618 // first check for a weapon on the ship
1619 for (i=0; i<MAX_WL_WEAPONS; i++) {
1620 // if alpha 1 has a weapon in bank i, set it as the selected type
1621 if (Wss_slots[0].wep_count[i] >= 0) {
1622 Selected_wl_class = Wss_slots[0].wep[i];
1627 // then check for a primary weapon in the pool
1628 for ( i = 0; i < Plist_size; i++ ) {
1629 if ( Plist[i] >= 0 ) {
1630 Selected_wl_class = Plist[i];
1635 // finally, if no others found yet, check for a secondary weapon in the pool
1636 for ( i = 0; i < Slist_size; i++ ) {
1637 if ( Slist[i] >= 0 ) {
1638 Selected_wl_class = Slist[i];
1644 // start an overhead animation, since selected slot has changed
1645 void wl_start_slot_animation(int n)
1647 #ifndef DEMO // not for FS2_DEMO
1650 // fallback code in wl_render_overhead_view() will
1651 // use the .pcx files
1652 // should prolly scrub out the 1e06 lines of dead code this leaves
1658 wl_ship_class_info *wl_ship;
1659 anim_play_struct aps;
1665 ship_class = Wss_slots[n].ship_class;
1667 if ( ship_class < 0 ) {
1672 wl_ship = &Wl_ships[ship_class];
1674 // maybe this animation is already playing?
1675 if ( wl_ship->anim_instance ) {
1676 anim_stop_playing(wl_ship->anim_instance);
1677 wl_ship->anim_instance = NULL;
1680 // maybe we have to load this animation
1681 if ( wl_ship->anim == NULL ) {
1682 wl_ship->anim = anim_load(Ship_info[ship_class].overhead_filename, 1);
1683 if ( wl_ship->anim == NULL ) {
1684 Int3(); // couldn't load anim filename.. get Alan
1689 anim_play_init(&aps, wl_ship->anim, Wl_overhead_coords[gr_screen.res][0], Wl_overhead_coords[gr_screen.res][1]);
1690 aps.screen_id = ON_WEAPON_SELECT;
1691 aps.framerate_independent = 1;
1692 aps.skip_frames = 0;
1693 wl_ship->anim_instance = anim_play(&aps);
1698 // Call when Selected_wl_slot needs to be changed
1699 void wl_set_selected_slot(int slot_num)
1701 if ( (slot_num >= 0) && (slot_num != Selected_wl_slot) ) {
1702 // slot has changed.... start an animation
1703 wl_start_slot_animation(slot_num);
1705 if ( Current_screen == ON_WEAPON_SELECT ) {
1706 gamesnd_play_iface(SND_OVERHEAD_SHIP_ANIM);
1711 Selected_wl_slot = slot_num;
1712 if ( Selected_wl_slot >= 0 ) {
1713 wl_set_disabled_weapons(Wss_slots[slot_num].ship_class);
1717 // determine how many missiles of type 'wi_index' will fit into capacity
1718 int wl_calc_missile_fit(int wi_index, int capacity)
1720 if ( wi_index < 0 ) {
1724 Assert(Weapon_info[wi_index].subtype == WP_MISSILE);
1725 return fl2i( capacity / Weapon_info[wi_index].cargo_size + 0.5f );
1728 // fill out the weapons for this ship_class
1729 void wl_get_ship_class_weapons(int ship_class, int *wep, int *wep_count)
1734 Assert(ship_class >= 0 && ship_class < MAX_SHIP_TYPES);
1735 sip = &Ship_info[ship_class];
1737 // reset weapons arrays
1738 for ( i=0; i < MAX_WL_WEAPONS; i++ ) {
1740 wep_count[i] = -1; // -1 means weapon bank doesn't exist.. 0 just means it is empty
1743 for ( i = 0; i < sip->num_primary_banks; i++ ) {
1744 wep[i] = sip->primary_bank_weapons[i];
1748 for ( i = 0; i < sip->num_secondary_banks; i++ ) {
1749 wep[i+MAX_WL_PRIMARY] = sip->secondary_bank_weapons[i];
1750 wep_count[i+MAX_WL_PRIMARY] = wl_calc_missile_fit(sip->secondary_bank_weapons[i], sip->secondary_bank_ammo_capacity[i]);
1754 // fill out the wep[] and wep_count[] arrays for a ship
1755 void wl_get_ship_weapons(int ship_index, int *wep, int *wep_count)
1761 Assert(ship_index >= 0);
1763 Assert(Ships[ship_index].wingnum >= 0);
1764 wp = &Wings[Ships[ship_index].wingnum];
1765 swp = &Ships[ship_index].weapons;
1767 for ( i = 0; i < swp->num_primary_banks; i++ ) {
1768 wep[i] = swp->primary_bank_weapons[i];
1770 if ( wep[i] == -1 ) {
1775 for ( i = 0; i < swp->num_secondary_banks; i++ ) {
1776 wep[i+MAX_WL_PRIMARY] = swp->secondary_bank_weapons[i];
1777 wep_count[i+MAX_WL_PRIMARY] = swp->secondary_bank_ammo[i];
1778 if ( wep[i+MAX_WL_PRIMARY] == -1 ) {
1779 wep_count[i+MAX_WL_PRIMARY] = 0;
1784 // set wep and wep_count from a ship which sits in the ship_arrivals[] list at index sa_index
1785 void wl_get_parseobj_weapons(int sa_index, int ship_class, int *wep, int *wep_count)
1792 pobjp = &ship_arrivals[sa_index];
1793 sip = &Ship_info[ship_class];
1795 pilot_index = wl_get_pilot_subsys_index(pobjp);
1797 if ( pilot_index == -1 )
1800 ss = &Subsys_status[pilot_index];
1802 if ( ss->primary_banks[0] != SUBSYS_STATUS_NO_CHANGE ) {
1803 for ( i=0; i < MAX_PRIMARY_BANKS; i++ ) {
1804 wep[i] = ss->primary_banks[i];
1808 if ( ss->secondary_banks[0] != SUBSYS_STATUS_NO_CHANGE ) {
1809 for ( i=0; i < MAX_SECONDARY_BANKS; i++ ) {
1810 wep[i+MAX_WL_PRIMARY] = ss->secondary_banks[i];
1814 // ammo counts could still be modified
1815 for ( i=0; i < MAX_SECONDARY_BANKS; i++ ) {
1816 if ( wep[i+MAX_WL_PRIMARY] >= 0 ) {
1817 wep_count[i+MAX_WL_PRIMARY] = wl_calc_missile_fit(wep[i+MAX_WL_PRIMARY], fl2i(ss->secondary_ammo[i]/100.0f * sip->secondary_bank_ammo_capacity[i] + 0.5f));
1822 // ensure that there aren't any bogus weapons assigned by default
1823 void wl_cull_illegal_weapons(int ship_class, int *wep, int *wep_count)
1826 for ( i=0; i < MAX_WL_WEAPONS; i++ ) {
1831 if ( !weapon_allowed_for_game_type(Ship_info[ship_class].allowed_weapons[wep[i]]) ) {
1838 // get the weapons info that should be on ship by default
1839 void wl_get_default_weapons(int ship_class, int slot_num, int *wep, int *wep_count)
1841 int original_ship_class, i;
1843 Assert(slot_num >= 0 && slot_num < MAX_WSS_SLOTS);
1845 // clear out wep and wep_count
1846 for ( i = 0; i < MAX_WL_WEAPONS; i++ ) {
1851 if ( ship_class < 0 )
1854 original_ship_class = ss_return_original_ship_class(slot_num);
1856 if ( original_ship_class != ship_class ) {
1857 wl_get_ship_class_weapons(ship_class, wep, wep_count);
1859 int sa_index; // ship arrival index
1860 sa_index = ss_return_saindex(slot_num);
1862 if ( sa_index >= 0 ) {
1863 // still a parse object
1864 wl_get_ship_class_weapons(ship_class, wep, wep_count);
1865 wl_get_parseobj_weapons(sa_index, ship_class, wep, wep_count);
1867 // ship has been created
1868 // wl_get_ship_weapons(slot_num/4, slot_num%4, wep, wep_count);
1869 int ship_index = -1;
1871 ss_return_ship(slot_num/4, slot_num%4, &ship_index, &pobjp);
1872 Assert(ship_index != -1);
1873 wl_get_ship_weapons(ship_index, wep, wep_count);
1877 // ensure that there aren't any bogus weapons assigned by default
1878 wl_cull_illegal_weapons(ship_class, wep, wep_count);
1881 // function to add a weapon_class to ui lists
1882 void wl_add_index_to_list(int wi_index)
1885 if ( Weapon_info[wi_index].subtype == WP_MISSILE ) {
1887 for ( i=0; i<Slist_size; i++ ) {
1888 if ( Slist[i] == wi_index )
1892 if ( i == Slist_size )
1893 Slist[Slist_size++] = wi_index;
1896 for ( i=0; i<Plist_size; i++ ) {
1897 if ( Plist[i] == wi_index )
1901 if ( i == Plist_size )
1902 Plist[Plist_size++] = wi_index;
1906 // remove the weapons specificed by wep[] and wep_count[] from Wl_pool[].
1907 void wl_remove_weps_from_pool(int *wep, int *wep_count, int ship_class)
1911 for ( i = 0; i < MAX_WL_WEAPONS; i++ ) {
1913 if ( wi_index >= 0 ) {
1914 if ( (wep_count[i] > 0) && ((Wl_pool[wi_index] - wep_count[i]) >= 0) ) {
1915 Wl_pool[wi_index] -= wep_count[i];
1917 // not enough weapons in pool
1918 // TEMP HACK: FRED doesn't fill in a weapons pool if there are no starting wings... so
1919 // add to the pool. This should be fixed.
1920 if ( Wss_num_wings <= 0 ) {
1921 wl_add_index_to_list(wi_index);
1924 if ( (Wl_pool[wi_index] <= 0) || (wep_count[i] == 0) ) {
1925 // fresh out of this weapon, pick an alternate pool weapon if we can
1926 int wep_pool_index, wep_precedence_index, new_wi_index = -1;
1927 for ( wep_pool_index = 0; wep_pool_index < MAX_WEAPON_TYPES; wep_pool_index++ ) {
1929 if ( Wl_pool[wep_pool_index] <= 0 ) {
1933 // AL 3-31-98: Only pick another primary if primary, etc
1934 if ( Weapon_info[wi_index].subtype != Weapon_info[wep_pool_index].subtype ) {
1938 if ( !weapon_allowed_for_game_type(Ship_info[ship_class].allowed_weapons[wep_pool_index]) ) {
1943 for ( wep_precedence_index = 0; wep_precedence_index < Num_player_weapon_precedence; wep_precedence_index++ ) {
1944 if ( wep_pool_index == Player_weapon_precedence[wep_precedence_index] ) {
1945 new_wi_index = wep_pool_index;
1950 if ( new_wi_index >= 0 ) {
1955 if ( new_wi_index >= 0 ) {
1956 wep[i] = new_wi_index;
1957 wi_index = new_wi_index;
1961 int new_wep_count = wep_count[i];
1962 if ( Weapon_info[wi_index].subtype == WP_MISSILE ) {
1963 int secondary_bank_index;
1964 secondary_bank_index = i-3;
1965 if ( secondary_bank_index < 0 ) {
1967 secondary_bank_index = 0;
1969 new_wep_count = wl_calc_missile_fit(wi_index, Ship_info[ship_class].secondary_bank_ammo_capacity[secondary_bank_index]);
1972 wep_count[i] = min(new_wep_count, Wl_pool[wi_index]);
1973 Assert(wep_count[i] >= 0);
1974 Wl_pool[wi_index] -= wep_count[i];
1975 if ( wep_count[i] <= 0 ) {
1984 // Init the weapons portion of Wss_slots[] and the ui data in Wl_slots[]
1985 // NOTE: it is assumed that Wl_pool[] has been initialized, and Wss_slots[].ship_class is correctly set
1986 void wl_fill_slots()
1989 int wep[MAX_WL_WEAPONS];
1990 int wep_count[MAX_WL_WEAPONS];
1992 for ( i = 0; i < MAX_WSS_SLOTS; i++ ) {
1993 if ( Wss_slots[i].ship_class < 0 ){
1997 // get the weapons info that should be on ship by default
1998 wl_get_default_weapons(Wss_slots[i].ship_class, i, wep, wep_count);
1999 wl_remove_weps_from_pool(wep, wep_count, Wss_slots[i].ship_class);
2001 // copy to Wss_slots[]
2002 for ( j = 0; j < MAX_WL_WEAPONS; j++ ) {
2003 Wss_slots[i].wep[j] = wep[j];
2004 Wss_slots[i].wep_count[j] = wep_count[j];
2009 // set up the primary and secondary icons lists that hold the weapons the player can choose from
2010 void wl_init_icon_lists()
2014 Plist_start = 0; // offset into Plist[]
2017 Plist_size = 0; // number of active elements in Plist[]
2020 for ( i = 0; i < MAX_WEAPON_TYPES; i++ ) {
2025 for ( i = 0; i < MAX_WEAPON_TYPES; i++ ) {
2026 if ( Wl_pool[i] > 0 ) {
2027 if ( Weapon_info[i].subtype == WP_MISSILE ) {
2028 Slist[Slist_size++] = i;
2030 Plist[Plist_size++] = i;
2036 // initialize team specific weapon select data structures
2037 void weapon_select_init_team(int team_num)
2039 Wl_icons = Wl_icons_teams[team_num];
2040 ss_set_team_pointers(team_num);
2042 wl_init_pool(&Team_data[team_num]);
2043 wl_init_icon_lists();
2044 wl_init_ship_class_data();
2046 wl_load_all_icons();
2047 wl_load_all_anims();
2052 // This init is called even before the weapons loadout screen is entered. It is called when the
2053 // briefing state is entered.
2054 void weapon_select_common_init()
2058 if((Game_mode & GM_MULTIPLAYER) && (Netgame.type_flags & NG_TYPE_TEAM)){
2059 // initialize for all teams
2060 for(idx=0;idx<MULTI_TS_MAX_TEAMS;idx++){
2061 weapon_select_init_team(idx);
2064 // re-initialize for me specifically
2065 weapon_select_init_team(Common_team);
2067 // initialize for my own team
2068 weapon_select_init_team(Common_team);
2071 wl_reset_selected_slot();
2072 wl_reset_carried_icon();
2073 wl_maybe_reset_selected_weapon_class();
2076 // ---------------------------------------------------------------------------------
2077 // weapon_select_init() is called to load the bitmaps and set up the mask regions for
2078 // the weapon loadout screen. common_select_init() is called to load the animations
2079 // and bitmaps which are in common with the ship select and briefing screens.
2081 // The Weapon_select_open flag is set to 1 when weapon_select_init() completes successfully
2083 void weapon_select_init()
2085 common_set_interface_palette("WeaponPalette");
2086 common_flash_button_init();
2088 // for multiplayer, change the state in my netplayer structure
2089 if ( Game_mode & GM_MULTIPLAYER )
2090 Net_player->state = NETPLAYER_STATE_WEAPON_SELECT;
2092 ship_stop_animation();
2093 stop_weapon_animation();
2094 Weapon_anim_class = -1;
2096 set_active_ui(&Weapon_ui_window);
2097 Current_screen = ON_WEAPON_SELECT;
2098 Last_wl_ship_class = -1;
2100 wl_maybe_reset_selected_slot();
2101 wl_set_disabled_weapons(Wss_slots[Selected_wl_slot].ship_class);
2103 help_overlay_set_state(WL_OVERLAY,0);
2105 if ( Weapon_select_open ) {
2106 wl_maybe_reset_selected_weapon_class();
2107 wl_start_slot_animation(Selected_wl_slot);
2108 common_buttons_maybe_reload(&Weapon_ui_window); // AL 11-21-97: this is necessary since we may returning from the hotkey
2109 // screen, which can release common button bitmaps.
2110 common_reset_buttons();
2111 nprintf(("Alan","weapon_select_init() returning without doing anything\n"));
2113 // if we're in multiplayer always select the player's ship
2114 wl_reset_selected_slot();
2119 nprintf(("Alan","entering weapon_select_init()\n"));
2120 common_select_init();
2122 WeaponSelectMaskBitmap = bm_load(Wl_loadout_select_mask[gr_screen.res]);
2123 if (WeaponSelectMaskBitmap < 0) {
2124 if (gr_screen.res == GR_640) {
2125 Error(LOCATION,"Could not load in 'weaponloadout-m'!");
2126 } else if (gr_screen.res == GR_1024) {
2127 Error(LOCATION,"Could not load in '2_weaponloadout-m'!");
2129 Error(LOCATION,"Could not load in 'weaponloadout-m'!");
2133 Weaponselect_mask_w = -1;
2134 Weaponselect_mask_h = -1;
2136 // get a pointer to bitmap by using bm_lock()
2137 WeaponSelectMaskPtr = bm_lock(WeaponSelectMaskBitmap, 8, BMP_AABITMAP);
2138 WeaponSelectMaskData = (ubyte*)WeaponSelectMaskPtr->data;
2139 Assert(WeaponSelectMaskData != NULL);
2140 bm_get_info(WeaponSelectMaskBitmap, &Weaponselect_mask_w, &Weaponselect_mask_h);
2143 // Set up the mask regions
2144 // initialize the different regions of the menu that will react when the mouse moves over it
2145 Num_weapon_select_regions = 0;
2147 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", COMMON_BRIEFING_REGION, 0);
2148 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", COMMON_SS_REGION, 0);
2149 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", COMMON_WEAPON_REGION, 0);
2150 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", COMMON_COMMIT_REGION, 0);
2151 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", COMMON_HELP_REGION, 0);
2152 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", COMMON_OPTIONS_REGION, 0);
2154 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", WING_0_SHIP_0, 0);
2155 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", WING_0_SHIP_1, 0);
2156 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", WING_0_SHIP_2, 0);
2157 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", WING_0_SHIP_3, 0);
2158 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", WING_1_SHIP_0, 0);
2159 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", WING_1_SHIP_1, 0);
2160 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", WING_1_SHIP_2, 0);
2161 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", WING_1_SHIP_3, 0);
2162 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", WING_2_SHIP_0, 0);
2163 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", WING_2_SHIP_1, 0);
2164 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", WING_2_SHIP_2, 0);
2165 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", WING_2_SHIP_3, 0);
2167 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", ICON_PRIMARY_0, 0);
2168 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", ICON_PRIMARY_1, 0);
2169 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", ICON_PRIMARY_2, 0);
2170 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", ICON_PRIMARY_3, 0);
2171 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", ICON_SECONDARY_0, 0);
2172 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", ICON_SECONDARY_1, 0);
2173 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", ICON_SECONDARY_2, 0);
2174 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", ICON_SECONDARY_3, 0);
2176 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", ICON_SHIP_PRIMARY_0, 0);
2177 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", ICON_SHIP_PRIMARY_1, 0);
2178 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", ICON_SHIP_PRIMARY_2, 0);
2179 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", ICON_SHIP_SECONDARY_0, 0);
2180 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", ICON_SHIP_SECONDARY_1, 0);
2181 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", ICON_SHIP_SECONDARY_2, 0);
2182 snazzy_menu_add_region(&Weapon_select_region[Num_weapon_select_regions++], "", ICON_SHIP_SECONDARY_3, 0);
2185 Weapon_ui_window.create( 0, 0, gr_screen.max_w, gr_screen.max_h, 0 );
2187 if(Game_mode & GM_MULTIPLAYER){
2188 Weapon_ui_window.set_mask_bmap(Wl_mask_multi[gr_screen.res]);
2190 Weapon_ui_window.set_mask_bmap(Wl_mask_single[gr_screen.res]);
2193 // initialize background bitmap
2194 if(Game_mode & GM_MULTIPLAYER) {
2195 Weapon_select_background_bitmap = bm_load(Weapon_select_multi_background_fname[gr_screen.res]);
2197 Weapon_select_background_bitmap = bm_load(Weapon_select_background_fname[gr_screen.res]);
2200 Weapon_ui_window.tooltip_handler = wl_tooltip_handler;
2201 common_buttons_init(&Weapon_ui_window);
2202 weapon_buttons_init();
2203 Weapon_select_open = 1;
2205 // if we're in multiplayer always select the player's ship
2206 wl_reset_selected_slot();
2209 // ----------------------------------------------------------------
2210 // wl_dump_carried_icon()
2211 void wl_dump_carried_icon()
2213 if ( wl_icon_being_carried() ) {
2214 // Add back into the weapon pool
2215 if ( Carried_wl_icon.from_bank >= 0 ) {
2217 wl_drop(Carried_wl_icon.from_bank, -1, -1, Carried_wl_icon.weapon_class, Carried_wl_icon.from_slot);
2219 if ( wl_carried_icon_moved() ) {
2220 gamesnd_play_iface(SND_ICON_DROP);
2224 wl_reset_carried_icon();
2228 // ----------------------------------------------------------------
2229 // drop_icon_on_slot()
2231 // Drop the Carried_wl_icon onto the specified slot. The slot numbering is:
2233 // 0->2: primary weapons
2234 // 3-6: secondary weapons
2236 // These are the slots that exist beside the overhead view of the ship.
2237 // on the weapons loadout screen.
2239 int drop_icon_on_slot(int bank_num)
2241 if ( Selected_wl_slot == -1 ) {
2245 if(Game_mode & GM_MULTIPLAYER){
2246 if(multi_ts_disabled_slot(Selected_wl_slot)){
2250 if ( ss_disabled_slot( Selected_wl_slot ) ){
2255 // check if slot exists
2256 if ( Wss_slots[Selected_wl_slot].wep_count[bank_num] < 0 ) {
2260 if ( !wl_carried_icon_moved() ) {
2261 wl_reset_carried_icon();
2265 wl_drop(Carried_wl_icon.from_bank, Carried_wl_icon.weapon_class, bank_num, -1, Selected_wl_slot);
2269 // ----------------------------------------------------------------
2270 // maybe_drop_icon_on_slot()
2272 void maybe_drop_icon_on_slot(int bank_num)
2275 if ( !mouse_down(MOUSE_LEFT_BUTTON) ) {
2276 if ( wl_icon_being_carried() )
2277 dropped = drop_icon_on_slot(bank_num);
2280 wl_reset_carried_icon();
2285 // ----------------------------------------------------------------
2286 // wl_check_for_stopped_ship_anims()
2288 void wl_check_for_stopped_ship_anims()
2292 for ( i = 0; i < MAX_SHIP_TYPES; i++ ) {
2293 ai = Wl_ships[i].anim_instance;
2295 if ( !anim_playing(ai) ) {
2296 Wl_ships[i].anim_instance = NULL;
2302 // ---------------------------------------------------------------------------------
2303 // do_mouse_over_list_weapon()
2305 void do_mouse_over_list_weapon(int index)
2307 Hot_weapon_icon = index;
2309 int region_index = ICON_PRIMARY_0+index;
2311 region_index = ICON_SECONDARY_0 + (index - 4);
2314 if ( Wl_mouse_down_on_region != region_index ){
2318 if ( mouse_down(MOUSE_LEFT_BUTTON) )
2319 wl_pick_icon_from_list(index);
2322 // ---------------------------------------------------------------------------------
2323 // do_mouse_over_ship_weapon()
2326 // input: index -> bank index on ship (0..6)
2329 // 0 -> icon was not dropped on a slot
2330 // 1 -> icon was dropped on a slot
2331 int do_mouse_over_ship_weapon(int index)
2333 int dropped_on_slot, is_moved, mx, my;
2335 dropped_on_slot = 0;
2336 Assert(Selected_wl_slot >= 0);
2338 if ( ss_disabled_slot( Selected_wl_slot ) )
2341 Hot_weapon_bank_icon = index; // bank icon will be drawn highlighted
2343 if ( mouse_down(MOUSE_LEFT_BUTTON) ) {
2344 if ( Wl_mouse_down_on_region == (ICON_SHIP_PRIMARY_0+index) ){
2345 pick_from_ship_slot(index);
2348 int was_carried = wl_icon_being_carried();
2349 maybe_drop_icon_on_slot(index);
2350 if ( was_carried && !wl_icon_being_carried() ) {
2351 mouse_get_pos( &mx, &my );
2352 if ( Carried_wl_icon.from_x != mx || Carried_wl_icon.from_y != my) {
2353 dropped_on_slot = 1;
2358 // set Hot_weapon_bank if a droppable icon is being held over a slot that
2359 // can accept that icon
2361 mouse_get_pos( &mx, &my );
2362 if ( Carried_wl_icon.from_x != mx || Carried_wl_icon.from_y != my) {
2366 if ( wl_icon_being_carried() && is_moved ) {
2367 if ( Weapon_info[Carried_wl_icon.weapon_class].subtype != WP_MISSILE ) {
2368 if ( (index < 3) && (Wss_slots[Selected_wl_slot].wep_count[index] >= 0) )
2369 Hot_weapon_bank = index;
2371 if ( index >= 3 && ( Wss_slots[Selected_wl_slot].wep_count[index] >= 0) )
2372 Hot_weapon_bank = index;
2376 return dropped_on_slot;
2380 // maybe flash a button if player hasn't done anything for a while
2381 void wl_maybe_flash_button()
2383 if ( common_flash_bright() ) {
2385 if ( Common_buttons[Current_screen-1][gr_screen.res][3].button.button_hilighted() ) {
2386 common_flash_button_init();
2388 Common_buttons[Current_screen-1][gr_screen.res][3].button.draw_forced(1);
2394 void weapon_select_render(float frametime)
2396 if ( !Background_playing ) {
2397 gr_set_bitmap(Weapon_select_background_bitmap);
2401 anim_render_all(0, frametime);
2402 anim_render_all(ON_SHIP_SELECT, frametime);
2405 // draw the weapon description text
2407 void wl_render_weapon_desc(float frametime)
2409 int *weapon_desc_coords;
2410 int *weapon_title_coords;
2412 // retrieve the correct set of text coordinates
2413 if (Game_mode & GM_MULTIPLAYER) {
2414 weapon_desc_coords = Wl_new_weapon_desc_coords_multi[gr_screen.res];
2415 weapon_title_coords = Wl_new_weapon_title_coords_multi[gr_screen.res];
2417 weapon_desc_coords = Wl_new_weapon_desc_coords[gr_screen.res];
2418 weapon_title_coords = Wl_new_weapon_title_coords[gr_screen.res];
2421 // render the normal version of the weapom desc
2422 char bright_char[WEAPON_DESC_MAX_LINES]; // one bright char per line
2423 if (!Weapon_desc_wipe_done) {
2424 // draw mid-wipe version
2425 // decide which char is last (and bright)
2426 int bright_char_index = (int)(Weapon_desc_wipe_time_elapsed * WEAPON_DESC_MAX_LENGTH / WEAPON_DESC_WIPE_TIME);
2427 int i, w, h, curr_len;
2429 // draw weapon title (above weapon anim)
2430 for (i=0; i<2; i++) {
2431 curr_len = strlen(Weapon_desc_lines[i]);
2433 if (bright_char_index < curr_len) {
2434 // save bright char and plunk in some nulls to shorten string
2435 bright_char[i] = Weapon_desc_lines[i][bright_char_index];
2436 Weapon_desc_lines[i][bright_char_index] = '\0';
2439 gr_set_color_fast(&Color_white);
2440 gr_string(weapon_title_coords[0], weapon_title_coords[1]+(10*i), Weapon_desc_lines[i]);
2442 // draw the bright letters
2443 gr_set_color_fast(&Color_bright_white);
2444 gr_get_string_size(&w, &h, Weapon_desc_lines[i], curr_len);
2445 gr_printf(weapon_title_coords[0]+w, weapon_title_coords[1]+(10*i), "%c", bright_char[i]);
2447 // restore the bright char to the string
2448 Weapon_desc_lines[i][bright_char_index] = bright_char[i];
2452 gr_set_color_fast(&Color_white);
2453 gr_string(weapon_title_coords[0], weapon_title_coords[1]+(10*i), Weapon_desc_lines[i]);
2457 // draw weapon desc (below weapon anim)
2458 for (i=2; i<WEAPON_DESC_MAX_LINES; i++) {
2459 curr_len = strlen(Weapon_desc_lines[i]);
2461 if (bright_char_index < curr_len) {
2462 // save bright char and plunk in some nulls to shorten string
2463 bright_char[i] = Weapon_desc_lines[i][bright_char_index];
2464 Weapon_desc_lines[i][bright_char_index] = '\0';
2467 gr_set_color_fast(&Color_white);
2468 gr_string(weapon_desc_coords[0], weapon_desc_coords[1]+(10*(i-2)), Weapon_desc_lines[i]);
2470 // draw the bright letters
2471 gr_set_color_fast(&Color_bright_white);
2472 gr_get_string_size(&w, &h, Weapon_desc_lines[i], curr_len);
2473 gr_printf(weapon_desc_coords[0]+w, weapon_desc_coords[1]+(10*(i-2)), "%c", bright_char[i]);
2475 // restore the bright char to the string
2476 Weapon_desc_lines[i][bright_char_index] = bright_char[i];
2480 gr_set_color_fast(&Color_white);
2481 gr_string(weapon_desc_coords[0], weapon_desc_coords[1]+(10*(i-2)), Weapon_desc_lines[i]);
2486 Weapon_desc_wipe_time_elapsed += frametime;
2487 if (Weapon_desc_wipe_time_elapsed >= WEAPON_DESC_WIPE_TIME) {
2488 // wipe is done,set flag and stop sound
2489 Weapon_desc_wipe_done = 1;
2494 // draw full version
2495 // FIXME - change to use a for loop
2496 gr_set_color_fast(&Color_white);
2497 gr_string(weapon_title_coords[0], weapon_title_coords[1], Weapon_desc_lines[0]);
2498 gr_string(weapon_title_coords[0], weapon_title_coords[1] + 10, Weapon_desc_lines[1]);
2499 gr_string(weapon_desc_coords[0], weapon_desc_coords[1], Weapon_desc_lines[2]);
2500 gr_string(weapon_desc_coords[0], weapon_desc_coords[1] + 10, Weapon_desc_lines[3]);
2501 gr_string(weapon_desc_coords[0], weapon_desc_coords[1] + 20, Weapon_desc_lines[4]);
2502 gr_string(weapon_desc_coords[0], weapon_desc_coords[1] + 30, Weapon_desc_lines[5]);
2508 // re-inits wiping vars and causes the current text to wipe in again
2509 void wl_weapon_desc_start_wipe()
2511 int currchar_src = 0, currline_dest = 2, currchar_dest = 0, i;
2513 int title_len = strlen(Weapon_info[Selected_wl_class].title);
2516 Weapon_desc_wipe_time_elapsed = 0.0f;
2517 Weapon_desc_wipe_done = 0;
2519 // break title into two lines if too long
2520 strcpy(Weapon_desc_lines[0], Weapon_info[Selected_wl_class].title);
2521 gr_get_string_size(&w, &h, Weapon_info[Selected_wl_class].title, title_len);
2522 if (w > Weapon_title_max_width[gr_screen.res]) {
2524 currchar_src = (int)(((float)title_len / (float)w) * Weapon_title_max_width[gr_screen.res]); // char to start space search at
2525 while (Weapon_desc_lines[0][currchar_src] != ' ') {
2527 if (currchar_src <= 0) {
2528 currchar_src = title_len;
2533 Weapon_desc_lines[0][currchar_src] = '\0'; // shorten line 0
2534 strcpy(Weapon_desc_lines[1], &(Weapon_desc_lines[0][currchar_src+1])); // copy remainder into line 1
2536 // entire title in line 0, thus line 1 is empty
2537 Weapon_desc_lines[1][0] = '\0';
2540 // break current description into lines (break at the /n's)
2542 while (Weapon_info[Selected_wl_class].desc[currchar_src] != '\0') {
2543 if (Weapon_info[Selected_wl_class].desc[currchar_src] == '\n') {
2545 if (currchar_src != 0) { // protect against leading /n's
2546 Weapon_desc_lines[currline_dest][currchar_dest] = '\0';
2552 Weapon_desc_lines[currline_dest][currchar_dest] = Weapon_info[Selected_wl_class].desc[currchar_src];
2558 Assert(currline_dest < WEAPON_DESC_MAX_LINES);
2559 Assert(currchar_dest < WEAPON_DESC_MAX_LENGTH);
2562 // wrap up the line processing
2563 Weapon_desc_lines[currline_dest][currchar_dest] = '\0';
2564 for (i=currline_dest+1; i<WEAPON_DESC_MAX_LINES; i++) {
2565 Weapon_desc_lines[i][0] = '\0';
2571 // ---------------------------------------------------------------------------------
2572 // weapon_select_do() is called once per frame while in the weapon loadout screen.
2574 // Calls to common_ functions are made for those functions which are common to the
2575 // ship select and briefing screens.
2577 void weapon_select_do(float frametime)
2579 int k, wl_choice, snazzy_action;
2582 if ( !Weapon_select_open )
2583 weapon_select_init();
2585 wl_choice = snazzy_menu_do(WeaponSelectMaskData, Weaponselect_mask_w, Weaponselect_mask_h, Num_weapon_select_regions, Weapon_select_region, &snazzy_action, 0);
2587 if ( wl_choice >= 0 ) {
2588 if ( snazzy_action == SNAZZY_CLICKED ) {
2589 nprintf(("Alan","got one\n"));
2594 Hot_weapon_icon = -1;
2595 Hot_weapon_bank = -1;
2596 Hot_weapon_bank_icon = -1;
2598 k = common_select_do(frametime);
2600 if ( help_overlay_active(WL_OVERLAY) ) {
2601 if ( Weapon_anim_class >= 0 && Wl_icons[Weapon_anim_class].anim_instance ) {
2602 anim_pause(Wl_icons[Weapon_anim_class].anim_instance);
2606 if ( Weapon_anim_class >= 0 && Wl_icons[Weapon_anim_class].anim_instance ) {
2607 anim_unpause(Wl_icons[Weapon_anim_class].anim_instance);
2611 // Check common keypresses
2612 common_check_keys(k);
2614 if ( Mouse_down_last_frame ) {
2615 Wl_mouse_down_on_region = wl_choice;
2618 if ( wl_choice > -1 ) {
2620 case ICON_PRIMARY_0:
2621 do_mouse_over_list_weapon(0);
2623 case ICON_PRIMARY_1:
2624 do_mouse_over_list_weapon(1);
2626 case ICON_PRIMARY_2:
2627 do_mouse_over_list_weapon(2);
2629 case ICON_PRIMARY_3:
2630 do_mouse_over_list_weapon(3);
2632 case ICON_SECONDARY_0:
2633 do_mouse_over_list_weapon(4);
2635 case ICON_SECONDARY_1:
2636 do_mouse_over_list_weapon(5);
2638 case ICON_SECONDARY_2:
2639 do_mouse_over_list_weapon(6);
2641 case ICON_SECONDARY_3:
2642 do_mouse_over_list_weapon(7);
2644 case ICON_SHIP_PRIMARY_0:
2645 if ( do_mouse_over_ship_weapon(0) )
2648 case ICON_SHIP_PRIMARY_1:
2649 if ( do_mouse_over_ship_weapon(1) )
2652 case ICON_SHIP_PRIMARY_2:
2653 if ( do_mouse_over_ship_weapon(2) )
2656 case ICON_SHIP_SECONDARY_0:
2657 if ( do_mouse_over_ship_weapon(3) )
2660 case ICON_SHIP_SECONDARY_1:
2661 if ( do_mouse_over_ship_weapon(4) )
2664 case ICON_SHIP_SECONDARY_2:
2665 if ( do_mouse_over_ship_weapon(5) )
2668 case ICON_SHIP_SECONDARY_3:
2669 if ( do_mouse_over_ship_weapon(6) )
2714 if ( !mouse_down(MOUSE_LEFT_BUTTON) ) {
2715 wl_dump_carried_icon();
2718 // Check for a mouse click on buttons
2719 common_check_buttons();
2720 weapon_check_buttons();
2722 // Check for the mouse clicks over a region
2723 if ( wl_choice > -1 && snazzy_action == SNAZZY_CLICKED ) {
2724 switch (wl_choice) {
2725 case ICON_PRIMARY_0:
2726 maybe_select_new_weapon(0);
2728 case ICON_PRIMARY_1:
2729 maybe_select_new_weapon(1);
2731 case ICON_PRIMARY_2:
2732 maybe_select_new_weapon(2);
2734 case ICON_PRIMARY_3:
2735 maybe_select_new_weapon(3);
2737 case ICON_SECONDARY_0:
2738 maybe_select_new_weapon(4);
2740 case ICON_SECONDARY_1:
2741 maybe_select_new_weapon(5);
2743 case ICON_SECONDARY_2:
2744 maybe_select_new_weapon(6);
2746 case ICON_SECONDARY_3:
2747 maybe_select_new_weapon(7);
2749 case ICON_SHIP_PRIMARY_0:
2750 maybe_select_new_ship_weapon(0);
2752 case ICON_SHIP_PRIMARY_1:
2753 maybe_select_new_ship_weapon(1);
2755 case ICON_SHIP_PRIMARY_2:
2756 maybe_select_new_ship_weapon(2);
2758 case ICON_SHIP_SECONDARY_0:
2759 maybe_select_new_ship_weapon(3);
2761 case ICON_SHIP_SECONDARY_1:
2762 maybe_select_new_ship_weapon(4);
2764 case ICON_SHIP_SECONDARY_2:
2765 maybe_select_new_ship_weapon(5);
2767 case ICON_SHIP_SECONDARY_3:
2768 maybe_select_new_ship_weapon(6);
2771 maybe_select_wl_slot(0,0);
2774 maybe_select_wl_slot(0,1);
2777 maybe_select_wl_slot(0,2);
2780 maybe_select_wl_slot(0,3);
2783 maybe_select_wl_slot(1,0);
2786 maybe_select_wl_slot(1,1);
2789 maybe_select_wl_slot(1,2);
2792 maybe_select_wl_slot(1,3);
2795 maybe_select_wl_slot(2,0);
2798 maybe_select_wl_slot(2,1);
2801 maybe_select_wl_slot(2,2);
2804 maybe_select_wl_slot(2,3);
2815 if ( Weapon_anim_class != -1 && ( Selected_wl_class == Weapon_anim_class ) ) {
2817 Assert(Selected_wl_class >= 0 && Selected_wl_class < MAX_WEAPON_TYPES );
2818 if ( Weapon_anim_class != Selected_wl_class )
2819 start_weapon_animation(Selected_wl_class);
2821 Assert(Weapon_anim_class == Selected_wl_class);
2822 icon = &Wl_icons[Selected_wl_class];
2823 if ( icon->anim_instance ) {
2824 if ( icon->anim_instance->frame_num == icon->anim_instance->stop_at ) {
2825 anim_play_struct aps;
2826 int *weapon_ani_coords;
2828 // get the correct weapon animations coords
2829 if (Game_mode & GM_MULTIPLAYER) {
2830 weapon_ani_coords = Wl_weapon_ani_coords_multi[gr_screen.res];
2832 weapon_ani_coords = Wl_weapon_ani_coords[gr_screen.res];
2835 anim_release_render_instance(icon->anim_instance);
2836 anim_play_init(&aps, icon->anim, weapon_ani_coords[0], weapon_ani_coords[1]);
2837 aps.start_at = WEAPON_ANIM_LOOP_FRAME-1;
2838 aps.screen_id = ON_WEAPON_SELECT;
2839 aps.framerate_independent = 1;
2840 aps.skip_frames = 0;
2841 icon->anim_instance = anim_play(&aps);
2846 weapon_select_render(frametime);
2847 if ( !Background_playing ) {
2848 Weapon_ui_window.draw();
2849 wl_redraw_pressed_buttons();
2851 anim_render_all(ON_WEAPON_SELECT, frametime);
2852 wl_check_for_stopped_ship_anims();
2853 wl_render_overhead_view(frametime);
2854 wl_draw_ship_weapons(Selected_wl_slot);
2855 for ( int i = 0; i < MAX_WING_BLOCKS; i++ ) {
2856 draw_wing_block(i, Hot_wl_slot, Selected_wl_slot, -1);
2858 common_render_selected_screen_button();
2861 // maybe blit the multiplayer "locked" button
2862 if((Game_mode & GM_MULTIPLAYER) && multi_ts_is_locked()){
2863 Buttons[gr_screen.res][WL_BUTTON_MULTI_LOCK].button.draw_forced(2);
2867 if ( wl_icon_being_carried() ) {
2869 Assert(Carried_wl_icon.weapon_class < MAX_WEAPON_TYPES);
2870 mouse_get_pos( &mx, &my );
2871 sx = mx + Wl_delta_x;
2872 sy = my + Wl_delta_y;
2875 if ( Wl_icons[Carried_wl_icon.weapon_class].can_use > 0) {
2876 gr_set_color_fast(&Color_blue);
2877 gr_set_bitmap(Wl_icons[Carried_wl_icon.weapon_class].icon_bmaps[WEAPON_ICON_FRAME_SELECTED]);
2881 // draw number to prevent it from disappearing on clicks
2882 if ( Carried_wl_icon.from_bank >= MAX_WL_PRIMARY ) {
2883 if ( mx == Carried_wl_icon.from_x && my == Carried_wl_icon.from_y ) {
2884 int num_missiles = Wss_slots[Carried_wl_icon.from_slot].wep_count[Carried_wl_icon.from_bank];
2885 //sprintf(buf, "%d", num_missiles);
2886 //gr_set_color_fast(&Color_white);
2888 //int x_offset = wl_fury_missile_offset_hack(Carried_wl_icon.weapon_class, num_missiles);
2889 //gr_string(sx-19-x_offset, sy+8, buf);
2892 wl_render_icon_count(num_missiles, Wl_bank_coords[gr_screen.res][Carried_wl_icon.from_bank][0], Wl_bank_coords[gr_screen.res][Carried_wl_icon.from_bank][1]);
2896 // check so see if this is really a legal weapon to carry away
2897 if ( !Wl_icons[Carried_wl_icon.weapon_class].can_use ) {
2899 diffx = abs(Carried_wl_icon.from_x-mx);
2900 diffy = abs(Carried_wl_icon.from_y-my);
2901 if ( (diffx > 2) || (diffy > 2) ) {
2902 int ship_class = Wss_slots[Selected_wl_slot].ship_class;
2905 // might have to get weapon name translation
2906 char display_name[128];
2907 strncpy(display_name, Weapon_info[Carried_wl_icon.weapon_class].name, 128);
2908 lcl_translate_wep_name(display_name);
2909 popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR( "A %s is unable to carry %s weaponry", 633), Ship_info[ship_class].name, display_name);
2911 popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR( "A %s is unable to carry %s weaponry", 633), Ship_info[ship_class].name, Weapon_info[Carried_wl_icon.weapon_class].name);
2914 wl_dump_carried_icon();
2919 if ( Weapon_anim_class != Selected_wl_class ) {
2920 start_weapon_animation(Selected_wl_class);
2923 // render weapon description text
2924 wl_render_weapon_desc(frametime);
2926 wl_maybe_flash_button();
2928 // should render the chatbox as close to the end as possible so it overlaps all controls
2929 if(!Background_playing){
2931 // render some extra stuff in multiplayer
2932 if(Game_mode & GM_MULTIPLAYER){
2933 // render the chatbox
2937 Weapon_ui_window.draw_tooltip();
2939 // render the status indicator for the voice system
2940 multi_common_voice_display_status();
2942 // blit the "ships/players" locked button
2943 // multi_ts_blit_locked_button();
2947 // blit help overlay if active
2948 help_overlay_maybe_blit(WL_OVERLAY);
2951 // If the commit button was pressed, do the commit button actions. Done at the end of the
2952 // loop so there isn't a skip in the animation (since ship_create() can take a long time if
2953 // the ship model is not in memory
2954 if ( Commit_pressed ) {
2955 if(Game_mode & GM_MULTIPLAYER){
2956 multi_ts_commit_pressed();
2964 // -------------------------------------------------------------------------------
2965 // weapon_select_close() will free the bitmap slot and memory that was allocated
2966 // to store the mask bitmap.
2968 // Weapon_select_open is cleared when this function completes.
2970 void weapon_select_close()
2972 if ( !Weapon_select_open ) {
2973 nprintf(("Alan","weapon_select_close() returning without doing anything\n"));
2977 nprintf(("Alan", "Entering weapon_select_close()\n"));
2979 stop_weapon_animation();
2981 // done with the bitmaps, so unlock it
2982 bm_unlock(WeaponSelectMaskBitmap);
2984 Weapon_ui_window.destroy();
2987 help_overlay_unload(WL_OVERLAY);
2989 bm_unload(WeaponSelectMaskBitmap);
2992 wl_unload_all_anim_instances();
2993 wl_unload_all_anims();
2995 Selected_wl_class = -1;
2996 Weapon_select_open = 0;
3000 // ------------------------------------------------------------------------
3001 // wl_render_icon_count()
3002 // renders the number next to the weapon icon
3004 // input: x,y => x,y screen position OF THE ICON (NOT where u want the text,
3005 // this is calculated to prevent overlapping)
3006 // num => the actual count to be printed
3008 void wl_render_icon_count(int num, int x, int y)
3012 int number_to_draw = (num > 1000) ? 999 : num; // cap count @ 999
3013 Assert(number_to_draw >= 0);
3015 sprintf(buf, "%d", number_to_draw);
3016 gr_get_string_size(&num_w, &num_h, buf, strlen(buf));
3019 gr_set_color_fast(&Color_white);
3020 gr_string(x-num_w-4, y+8, buf);
3024 // ------------------------------------------------------------------------
3027 // input: index => index into Wl_icons[], identifying which weapon to draw
3028 // x,y => x,y screen position to draw icon at
3029 // num => count for weapon
3030 // draw_num_flag => 0 if not to draw count for weapon, nonzero otherwise
3031 // hot_mask => value that should match Hot_weapon_icon to show mouse is over
3032 // hot_bank_mask => value that should match Hot_weapon_bank_icon to show mouse is over
3033 // select_mask => value that should match Selected_wl_class to show icon is selected
3035 void wl_render_icon(int index, int x, int y, int num, int draw_num_flag, int hot_mask, int hot_bank_mask, int select_mask)
3040 if ( Selected_wl_slot == -1 )
3043 icon = &Wl_icons[index];
3045 if ( icon->icon_bmaps[0] == -1 ) {
3046 wl_load_icons(index);
3049 // assume default bitmap is to be used
3050 bitmap_id = icon->icon_bmaps[WEAPON_ICON_FRAME_NORMAL]; // normal frame
3052 if ( bitmap_id < 0 ) {
3057 // next check if ship has mouse over it
3058 if ( !wl_icon_being_carried() ) {
3059 if ( Hot_weapon_icon > -1 && Hot_weapon_icon == hot_mask )
3060 bitmap_id = icon->icon_bmaps[WEAPON_ICON_FRAME_HOT];
3062 if ( Hot_weapon_bank_icon > -1 && Hot_weapon_bank_icon == hot_bank_mask )
3063 bitmap_id = icon->icon_bmaps[WEAPON_ICON_FRAME_HOT];
3066 // if icon is selected
3067 if ( Selected_wl_class > -1 ) {
3068 if ( Selected_wl_class == select_mask)
3069 bitmap_id = icon->icon_bmaps[WEAPON_ICON_FRAME_SELECTED]; // selected icon
3072 // if icon is disabled
3073 if ( !icon->can_use ) {
3074 bitmap_id = icon->icon_bmaps[WEAPON_ICON_FRAME_DISABLED]; // disabled icon
3077 gr_set_color_fast(&Color_blue);
3078 gr_set_bitmap(bitmap_id);
3081 // draw the number of the item
3082 // now, right justified
3083 if ( draw_num_flag != 0 ) {
3084 wl_render_icon_count(num, x, y);
3088 // ------------------------------------------------------------------------
3089 // wl_draw_ship_weapons()
3091 // Draw the icons for the weapons that are currently on the selected ship
3093 // input: slot_num => Slot to draw weapons for
3095 void wl_draw_ship_weapons(int index)
3098 int *wep, *wep_count;
3103 Assert(index >= 0 && index < MAX_WSS_SLOTS);
3104 wep = Wss_slots[index].wep;
3105 wep_count = Wss_slots[index].wep_count;
3107 for ( i = 0; i < MAX_WL_WEAPONS; i++ ) {
3109 if ( Carried_wl_icon.from_bank == i && Carried_wl_icon.from_slot == index ) {
3113 if ( (wep[i] != -1) && (wep_count[i] > 0) ) {
3114 int x_offset = wl_fury_missile_offset_hack(wep[i], wep_count[i]);
3116 wl_render_icon( wep[i], Wl_bank_coords[gr_screen.res][i][0]+x_offset, Wl_bank_coords[gr_screen.res][i][1], wep_count[i], Wl_bank_count_draw_flags[i], -1, i, wep[i]);
3121 // ------------------------------------------------------------------------
3122 // draw_wl_icon_with_number()
3124 // input: list_count => list position on screen (0-7)
3125 // weapon_class => class of weapon
3127 void draw_wl_icon_with_number(int list_count, int weapon_class)
3129 Assert( list_count >= 0 && list_count < 8 );
3131 wl_render_icon(weapon_class, Wl_weapon_icon_coords[gr_screen.res][list_count][0], Wl_weapon_icon_coords[gr_screen.res][list_count][1],
3132 Wl_pool[weapon_class], 1, list_count, -1, weapon_class);
3135 // ------------------------------------------------------------------------
3138 // Draw the weapon icons that are available
3139 void draw_wl_icons()
3144 for ( i = Plist_start; i < Plist_size; i++ ) {
3145 draw_wl_icon_with_number(count, Plist[i]);
3151 for ( i = Slist_start; i < Slist_size; i++ ) {
3152 draw_wl_icon_with_number(count+4, Slist[i]);
3158 // ------------------------------------------------------------------------
3159 // wl_pick_icon_from_list()
3161 // determine if an icon from the scrollable weapon list can be picked up
3162 // (for drag and drop). It calculates the difference in x & y between the icon
3163 // and the mouse, so we can move the icon with the mouse in a realistic way
3164 // input: index (0..7)
3165 void wl_pick_icon_from_list(int index)
3167 int weapon_class, mx, my;
3169 // if this is a multiplayer game and the player is an observer, he can never pick any weapons up
3170 if((Game_mode & GM_MULTIPLAYER) && (Net_player->flags & NETINFO_FLAG_OBSERVER)){
3174 // if a weapon is being carried, do nothing
3175 if ( wl_icon_being_carried() ) {
3180 weapon_class = Plist[Plist_start+index];
3182 weapon_class = Slist[Slist_start+index-4];
3185 // there isn't a weapon there at all!
3186 if ( weapon_class < 0 )
3189 // no weapons left of that class
3190 if ( Wl_pool[weapon_class] <= 0 ) {
3195 // some are available, but weapon cannot be used on current ship class
3196 if ( !Wl_icons[weapon_class].can_use ) {
3199 int ship_class = Wss_slots[Selected_wl_slot].ship_class;
3200 popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, "A %s is unable to carry %s weaponry", Ship_info[ship_class].name, Weapon_info[weapon_class].name);
3207 wl_set_carried_icon(-1, -1, weapon_class);
3208 common_flash_button_init();
3210 mouse_get_pos( &mx, &my );
3211 Wl_delta_x = Wl_weapon_icon_coords[gr_screen.res][index][0] - mx;
3212 Wl_delta_y = Wl_weapon_icon_coords[gr_screen.res][index][1] - my;
3215 // ------------------------------------------------------------------------
3216 // pick_from_ship_slot()
3218 // input: num -> index into shipb banks (0..2 primary, 3..6 secondary)
3219 void pick_from_ship_slot(int num)
3221 int mx, my, *wep, *wep_count;
3225 if ( Selected_wl_slot == -1 )
3228 if ( wl_icon_being_carried() )
3231 if ( ss_disabled_slot( Selected_wl_slot ) )
3234 wep = Wss_slots[Selected_wl_slot].wep;
3235 wep_count = Wss_slots[Selected_wl_slot].wep_count;
3237 // check if a weapon even exists in that slot
3238 if ( (wep[num] < 0) || (wep_count[num] <= 0) ) {
3242 Assert(Wl_icons[wep[num]].can_use);
3244 wl_set_carried_icon(num, Selected_wl_slot, wep[num]);
3245 common_flash_button_init();
3247 mouse_get_pos( &mx, &my );
3249 int x_offset = wl_fury_missile_offset_hack(wep[num], wep_count[num]);
3250 Wl_delta_x = Wl_bank_coords[gr_screen.res][num][0] - mx + x_offset;
3251 Wl_delta_y = Wl_bank_coords[gr_screen.res][num][1] - my;
3253 Carried_wl_icon.from_x = mx;
3254 Carried_wl_icon.from_y = my;
3257 // determine if this slot has no weapons
3258 int wl_slots_all_empty(wss_unit *slot)
3262 for ( i = 0; i < MAX_WL_WEAPONS; i++ ) {
3263 if ( (slot->wep_count[i] > 0) && (slot->wep[i] >= 0) )
3270 // ------------------------------------------------------------------------
3271 // wl_update_ship_weapons()
3273 // Change a ship's weapons based on the information contained in the
3274 // Weapon_data[] structure that is filled in during weapon loadout
3276 // returns: -1 => if the playre ship has no weapons
3277 // 0 => function finished without errors
3278 int wl_update_ship_weapons(int objnum, wss_unit *slot )
3280 // AL 11-15-97: Ensure that the player ship hasn't removed all
3281 // weapons from their ship. This will cause a warning to appear.
3282 if ( objnum == OBJ_INDEX(Player_obj) && Weapon_select_open ) {
3283 if ( wl_slots_all_empty(slot) ) {
3288 wl_bash_ship_weapons(&Ships[Objects[objnum].instance].weapons, slot);
3293 // ------------------------------------------------------------------------
3294 // wl_update_parse_object_weapons()
3296 // Set the Pilot subsystem of a parse_object to the weapons that are setup
3297 // for the wing_block,wing_slot ship
3299 // input: pobjp => pointer to parse object that references Pilot subsystem
3301 void wl_update_parse_object_weapons(p_object *pobjp, wss_unit *slot)
3303 int i, j, sidx, pilot_index, max_count;
3307 Assert(slot->ship_class >= 0);
3308 sip = &Ship_info[slot->ship_class];
3310 pilot_index = wl_get_pilot_subsys_index(pobjp);
3312 if ( pilot_index == -1 )
3315 ss = &Subsys_status[pilot_index];
3317 for ( i = 0; i < MAX_PRIMARY_BANKS; i++ ) {
3318 ss->primary_banks[i] = -1;
3321 for ( i = 0; i < MAX_SECONDARY_BANKS; i++ ) {
3322 ss->secondary_banks[i] = -1;
3326 for ( i = 0; i < MAX_WL_PRIMARY; i++ ) {
3327 if ( (slot->wep_count[i] > 0) && (slot->wep[i] >= 0) ) {
3328 ss->primary_banks[j] = slot->wep[i];
3334 for ( i = 0; i < MAX_WL_SECONDARY; i++ ) {
3335 sidx = i+MAX_WL_PRIMARY;
3336 if ( (slot->wep_count[sidx] > 0) && (slot->wep[sidx] >= 0) ) {
3337 ss->secondary_banks[j] = slot->wep[sidx];
3338 // Important: the secondary_ammo[] value is a percentage of max capacity!
3339 max_count = wl_calc_missile_fit(slot->wep[sidx], Ship_info[slot->ship_class].secondary_bank_ammo_capacity[j]);
3340 ss->secondary_ammo[j] = fl2i( i2fl(slot->wep_count[sidx]) / max_count * 100.0f + 0.5f);
3346 // ------------------------------------------------------------------------
3347 // stop_weapon_animation()
3349 // Stop the current weapon animation from playing.
3351 void stop_weapon_animation()
3353 if ( Weapon_anim_class < 0 )
3356 if ( anim_playing(Wl_icons[Weapon_anim_class].anim_instance) )
3357 anim_release_render_instance(Wl_icons[Weapon_anim_class].anim_instance);
3359 Wl_icons[Weapon_anim_class].anim_instance = NULL;
3360 Weapon_anim_class = -1;
3363 // ------------------------------------------------------------------------
3364 // start_weapon_animation()
3366 // Start the current weapon animation from playing.
3368 void start_weapon_animation(int weapon_class)
3371 int *weapon_ani_coords;
3373 if ( weapon_class < 0 )
3376 if ( weapon_class == Weapon_anim_class )
3379 // get the correct weapon animations coords
3380 if (Game_mode & GM_MULTIPLAYER) {
3381 weapon_ani_coords = Wl_weapon_ani_coords_multi[gr_screen.res];
3383 weapon_ani_coords = Wl_weapon_ani_coords[gr_screen.res];
3386 icon = &Wl_icons[weapon_class];
3388 // stop current animation playing
3389 stop_weapon_animation();
3391 // see if we need to load in the animation from disk
3392 if ( icon->anim == NULL ) {
3393 wl_load_anim(weapon_class);
3395 icon->anim = anim_load(Weapon_info[weapon_class].anim_filename, 1);
3396 if ( icon->anim == NULL ) {
3397 Int3(); // could not open the weapon animation
3403 // see if we need to get an instance
3404 if ( icon->anim_instance == NULL ) {
3405 anim_play_struct aps;
3407 anim_play_init(&aps, icon->anim, weapon_ani_coords[0], weapon_ani_coords[1]);
3408 aps.screen_id = ON_WEAPON_SELECT;
3409 aps.framerate_independent = 1;
3410 aps.skip_frames = 0;
3411 icon->anim_instance = anim_play(&aps);
3412 gamesnd_play_iface(SND_WEAPON_ANIM_START);
3415 Weapon_anim_class = weapon_class;
3417 // start the text wipe
3418 wl_weapon_desc_start_wipe();
3421 // reset the weapons loadout to the defaults in the mission
3422 void wl_reset_to_defaults()
3424 // don't reset of weapons pool in multiplayer
3425 if(Game_mode & GM_MULTIPLAYER){
3429 wl_init_pool(&Team_data[Common_team]);
3430 wl_init_icon_lists();
3432 wl_reset_selected_slot();
3433 wl_reset_carried_icon();
3434 wl_maybe_reset_selected_weapon_class();
3437 // Bash ship weapons, based on what is stored in the stored weapons loadout
3438 // NOTE: Wss_slots[] is assumed to be correctly set
3439 void wl_bash_ship_weapons(ship_weapon *swp, wss_unit *slot)
3443 for ( i = 0; i < MAX_PRIMARY_BANKS; i++ ) {
3444 swp->primary_bank_weapons[i] = -1;
3447 for ( i = 0; i < MAX_SECONDARY_BANKS; i++ ) {
3448 swp->secondary_bank_weapons[i] = -1;
3452 for ( i = 0; i < MAX_WL_PRIMARY; i++ ) {
3453 if ( (slot->wep_count[i] > 0) && (slot->wep[i] >= 0) ) {
3454 swp->primary_bank_weapons[j] = slot->wep[i];
3458 swp->num_primary_banks = j;
3461 for ( i = 0; i < MAX_WL_SECONDARY; i++ ) {
3462 sidx = i+MAX_WL_PRIMARY;
3463 if ( (slot->wep_count[sidx] > 0) && (slot->wep[sidx] >= 0) ) {
3464 swp->secondary_bank_weapons[j] = slot->wep[sidx];
3465 swp->secondary_bank_ammo[j] = slot->wep_count[sidx];
3469 swp->num_secondary_banks = j;
3472 // utility function for swapping two banks
3473 void wl_swap_weapons(int ship_slot, int from_bank, int to_bank)
3477 slot = &Wss_slots[ship_slot];
3479 if ( from_bank == to_bank ) {
3484 tmp = slot->wep[from_bank];
3485 slot->wep[from_bank] = slot->wep[to_bank];
3486 slot->wep[to_bank] = tmp;
3488 // swap weapon count
3489 tmp = slot->wep_count[from_bank];
3490 slot->wep_count[from_bank] = slot->wep_count[to_bank];
3491 slot->wep_count[to_bank] = tmp;
3494 // utility function used to put back overflow into the weapons pool
3495 void wl_saturate_bank(int ship_slot, int bank)
3498 int max_count, overflow;
3500 slot = &Wss_slots[ship_slot];
3502 if ( (slot->wep[bank] < 0) || (slot->wep_count <= 0) ) {
3506 max_count = wl_calc_missile_fit(slot->wep[bank], Ship_info[slot->ship_class].secondary_bank_ammo_capacity[bank-3]);
3507 overflow = slot->wep_count[bank] - max_count;
3508 if ( overflow > 0 ) {
3509 slot->wep_count[bank] -= overflow;
3510 // add overflow back to pool
3511 Wl_pool[slot->wep[bank]] += overflow;
3515 // exit: 0 -> no data changed
3516 // 1 -> data changed
3517 // sound => gets filled with sound id to play
3518 int wl_swap_slot_slot(int from_bank, int to_bank, int ship_slot, int *sound)
3521 slot = &Wss_slots[ship_slot];
3523 if ( slot->ship_class == -1 ) {
3524 Int3(); // should not be possible
3528 // do nothing if swapping with self
3529 if ( from_bank == to_bank ) {
3530 *sound=SND_ICON_DROP_ON_WING;
3531 return 0; // no update
3534 // ensure that source bank exists and has something to pick from
3535 if ( slot->wep[from_bank] == -1 || slot->wep_count[from_bank] <= 0 ) {
3539 // ensure that the dest bank exists
3540 if ( slot->wep_count[to_bank] < 0 ) {
3544 // ensure that the banks are both of the same class
3545 if ( (IS_BANK_PRIMARY(from_bank) && IS_BANK_SECONDARY(to_bank)) || (IS_BANK_SECONDARY(from_bank) && IS_BANK_PRIMARY(to_bank)) ) {
3546 // put from_bank back into list
3547 Wl_pool[slot->wep[from_bank]] += slot->wep_count[from_bank];; // return to list
3548 slot->wep[from_bank] = -1; // remove from slot
3549 slot->wep_count[from_bank] = 0;
3550 *sound=SND_ICON_DROP;
3554 // case 1: primaries (easy)
3555 if ( IS_BANK_PRIMARY(from_bank) && IS_BANK_PRIMARY(to_bank) ) {
3556 wl_swap_weapons(ship_slot, from_bank, to_bank);
3557 *sound=SND_ICON_DROP_ON_WING;
3561 // case 2: secondaries (harder)
3562 if ( IS_BANK_SECONDARY(from_bank) && IS_BANK_SECONDARY(to_bank) ) {
3564 // case 2a: secondaries are the same type
3565 if ( slot->wep[from_bank] == slot->wep[to_bank] ) {
3566 int dest_max, dest_can_fit, source_can_give;
3567 dest_max = wl_calc_missile_fit(slot->wep[to_bank], Ship_info[slot->ship_class].secondary_bank_ammo_capacity[to_bank-3]);
3569 dest_can_fit = dest_max - slot->wep_count[to_bank];
3571 if ( dest_can_fit <= 0 ) {
3572 // dest bank is already full.. nothing to do here
3576 // see how much source can give
3577 source_can_give = min(dest_can_fit, slot->wep_count[from_bank]);
3579 if ( source_can_give > 0 ) {
3580 slot->wep_count[to_bank] += source_can_give; // add to dest
3581 slot->wep_count[from_bank] -= source_can_give; // take from source
3582 *sound=SND_ICON_DROP_ON_WING;
3589 // case 2b: secondaries are different types
3590 if ( slot->wep[from_bank] != slot->wep[to_bank] ) {
3593 wl_swap_weapons(ship_slot, from_bank, to_bank);
3595 // put back some on list if required
3596 wl_saturate_bank(ship_slot, from_bank);
3597 wl_saturate_bank(ship_slot, to_bank);
3598 *sound=SND_ICON_DROP_ON_WING;
3603 Int3(); // should never get here
3607 // exit: 0 -> no data changed
3608 // 1 -> data changed
3609 // sound => gets filled with sound id to play
3610 int wl_dump_to_list(int from_bank, int to_list, int ship_slot, int *sound)
3613 slot = &Wss_slots[ship_slot];
3615 // ensure that source bank exists and has something to pick from
3616 if ( slot->wep[from_bank] == -1 || slot->wep_count[from_bank] <= 0 ) {
3620 // put weapon bank to the list
3621 Wl_pool[to_list] += slot->wep_count[from_bank]; // return to list
3622 slot->wep[from_bank] = -1; // remove from slot
3623 slot->wep_count[from_bank] = 0;
3624 *sound=SND_ICON_DROP;
3629 // exit: 0 -> no data changed
3630 // 1 -> data changed
3631 // sound => gets filled with sound id to play
3632 int wl_grab_from_list(int from_list, int to_bank, int ship_slot, int *sound)
3635 slot = &Wss_slots[ship_slot];
3638 // ensure that the banks are both of the same class
3639 if ( (IS_LIST_PRIMARY(from_list) && IS_BANK_SECONDARY(to_bank)) || (IS_LIST_SECONDARY(from_list) && IS_BANK_PRIMARY(to_bank)) ) {
3641 *sound=SND_ICON_DROP;
3645 // ensure that dest bank exists
3646 if ( slot->wep_count[to_bank] < 0 ) {
3647 *sound=SND_ICON_DROP;
3651 // bank should be empty:
3652 Assert(slot->wep_count[to_bank] == 0);
3653 Assert(slot->wep[to_bank] < 0);
3655 // ensure that pool has weapon
3656 if ( Wl_pool[from_list] <= 0 ) {
3660 // find how much dest bank can fit
3661 if ( to_bank < MAX_WL_PRIMARY ) {
3664 max_fit = wl_calc_missile_fit(from_list, Ship_info[slot->ship_class].secondary_bank_ammo_capacity[to_bank-MAX_WL_PRIMARY]);
3667 // take weapon from list
3668 if ( Wl_pool[from_list] < max_fit ) {
3669 max_fit = Wl_pool[from_list];
3671 Wl_pool[from_list] -= max_fit;
3674 slot->wep[to_bank] = from_list;
3675 slot->wep_count[to_bank] = max_fit;
3677 *sound=SND_ICON_DROP_ON_WING;
3681 // exit: 0 -> no data changed
3682 // 1 -> data changed
3683 // sound => gets filled with sound id to play
3684 int wl_swap_list_slot(int from_list, int to_bank, int ship_slot, int *sound)
3687 slot = &Wss_slots[ship_slot];
3690 // ensure that the banks are both of the same class
3691 if ( (IS_LIST_PRIMARY(from_list) && IS_BANK_SECONDARY(to_bank)) || (IS_LIST_SECONDARY(from_list) && IS_BANK_PRIMARY(to_bank)) ) {
3693 *sound=SND_ICON_DROP;
3697 // ensure that dest bank exists
3698 if ( slot->wep_count[to_bank] < 0 ) {
3702 // bank should have something in it
3703 Assert(slot->wep_count[to_bank] > 0);
3704 Assert(slot->wep[to_bank] >= 0);
3706 // ensure that pool has weapon
3707 if ( Wl_pool[from_list] <= 0 ) {
3711 // dump slot weapon back into list
3712 Wl_pool[slot->wep[to_bank]] += slot->wep_count[to_bank];
3713 slot->wep_count[to_bank] = 0;
3714 slot->wep[to_bank] = -1;
3716 // put weapon on ship from list
3718 // find how much dest bank can fit
3719 if ( to_bank < MAX_WL_PRIMARY ) {
3722 max_fit = wl_calc_missile_fit(from_list, Ship_info[slot->ship_class].secondary_bank_ammo_capacity[to_bank-MAX_WL_PRIMARY]);
3725 // take weapon from list
3726 if ( Wl_pool[from_list] < max_fit ) {
3727 max_fit = Wl_pool[from_list];
3729 Wl_pool[from_list] -= max_fit;
3732 slot->wep[to_bank] = from_list;
3733 slot->wep_count[to_bank] = max_fit;
3735 *sound=SND_ICON_DROP_ON_WING;
3739 // update any interface data that may be dependent on Wss_slots[]
3740 void wl_synch_interface()
3744 void wl_apply(int mode,int from_bank,int from_list,int to_bank,int to_list,int ship_slot,int player_index)
3750 // get the appropriate net player
3751 if(Game_mode & GM_MULTIPLAYER){
3752 if(player_index == -1){
3755 pl = &Net_players[player_index];
3762 case WSS_SWAP_SLOT_SLOT:
3763 update = wl_swap_slot_slot(from_bank, to_bank, ship_slot, &sound);
3765 case WSS_DUMP_TO_LIST:
3766 update = wl_dump_to_list(from_bank, to_list, ship_slot, &sound);
3768 case WSS_GRAB_FROM_LIST:
3769 update = wl_grab_from_list(from_list, to_bank, ship_slot, &sound);
3771 case WSS_SWAP_LIST_SLOT:
3772 update = wl_swap_list_slot(from_list, to_bank, ship_slot, &sound);
3776 // only play this sound if the move was done locally (by the host in other words)
3777 if ( (sound >= 0) && (player_index == -1) ) {
3778 gamesnd_play_iface(sound);
3782 if ( MULTIPLAYER_HOST ) {
3784 ubyte wss_data[MAX_PACKET_SIZE-20];
3786 size = store_wss_data(wss_data, MAX_PACKET_SIZE-20,sound,player_index);
3788 send_wss_update_packet(pl->p_info.team,wss_data, size);
3791 if(Game_mode & GM_MULTIPLAYER){
3794 // if the pool we're using has changed, synch stuff up
3795 if(pl->p_info.team == Net_player->p_info.team){
3796 wl_synch_interface();
3799 wl_synch_interface();
3804 void wl_drop(int from_bank,int from_list,int to_bank,int to_list, int ship_slot, int player_index)
3809 // get the appropriate net player
3810 if(Game_mode & GM_MULTIPLAYER){
3811 if(player_index == -1){
3814 pl = &Net_players[player_index];
3820 common_flash_button_init();
3821 if ( !(Game_mode & GM_MULTIPLAYER) || MULTIPLAYER_HOST ) {
3822 if((Game_mode & GM_MULTIPLAYER) && (Netgame.type_flags & NG_TYPE_TEAM)){
3823 // set the global pointers to the right pools
3824 ss_set_team_pointers(pl->p_info.team);
3828 mode = wss_get_mode(from_bank, from_list, to_bank, to_list, ship_slot);
3830 wl_apply(mode, from_bank, from_list, to_bank, to_list, ship_slot, player_index);
3833 if((Game_mode & GM_MULTIPLAYER) && (Netgame.type_flags & NG_TYPE_TEAM)){
3834 // set the global pointers to the right pools
3835 ss_set_team_pointers(Net_player->p_info.team);
3838 send_wss_request_packet(Net_player->player_id, from_bank, from_list, to_bank, to_list, ship_slot, -1, WSS_WEAPON_SELECT);