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/MissionShipChoice.cpp $
15 * C module to allow player ship selection for the mission
18 * Revision 1.4 2003/05/25 02:30:43 taylor
21 * Revision 1.3 2002/06/17 06:33:09 relnev
22 * ryan's struct patch for gcc 2.95
24 * Revision 1.2 2002/06/09 04:41:23 relnev
25 * added copyright header
27 * Revision 1.1.1.1 2002/05/03 03:28:10 root
31 * 26 11/02/99 3:23p Jefff
32 * "x Meters" to "x Meter" in German
34 * 25 8/05/99 3:40p Jefff
35 * hi-res text adjustments
37 * 24 8/04/99 11:56a Jefff
38 * fixed gamma wing hi-res coordinate error. fixed
39 * ss_load_individual_animation to load anis from a packfile.
41 * 23 7/30/99 4:22p Andsager
42 * restored ship and weapon anim sounds for demo. Added sound for
43 * changing ship in weapon loadout screen.
45 * 22 7/28/99 12:23p Jefff
46 * updated hi-res wing icon coords
48 * 21 7/21/99 3:24p Andsager
49 * Modify demo to use 2 frame ship and weapon select anis and cut sounds
52 * 20 7/16/99 2:23p Anoop
55 * 19 7/16/99 1:49p Dave
56 * 8 bit aabitmaps. yay.
58 * 18 7/15/99 6:36p Jamesa
59 * Moved default ship name into the ships.tbl
61 * 17 7/15/99 9:20a Andsager
62 * FS2_DEMO initial checkin
64 * 16 6/29/99 7:39p Dave
65 * Lots of small bug fixes.
67 * 15 6/04/99 11:32a Dave
68 * Added reset text to ship select screen. Fixed minor xstr bug in ui
71 * 14 3/23/99 9:26p Neilk
72 * fixed various multiplayer lock button problems
74 * 13 3/23/99 11:55a Neilk
75 * new support for ship anis
77 * 14 3/15/99 6:27p Neilk
78 * Added hires support for the ship animations
80 * 13 3/15/99 11:18a Neilk
81 * Modified animation code so ship animations loop back to frame 51
83 * 12 3/12/99 12:02p Davidg
84 * Modified coordinates for low res ship animations for new artwork
86 * 11 3/10/99 6:21p Neilk
87 * Added new artwork for hires
89 * 10 2/21/99 6:01p Dave
90 * Fixed standalone WSS packets.
92 * 9 2/18/99 11:46a Neilk
93 * hires interface coord support
95 * 8 2/11/99 3:08p Dave
96 * PXO refresh button. Very preliminary squad war support.
98 * 7 2/01/99 5:55p Dave
99 * Removed the idea of explicit bitmaps for buttons. Fixed text
100 * highlighting for disabled gadgets.
102 * 6 1/29/99 4:17p Dave
103 * New interface screens.
105 * 5 12/18/98 1:13a Dave
106 * Rough 1024x768 support for Direct3D. Proper detection and usage through
109 * 4 11/30/98 1:07p Dave
110 * 16 bit conversion, first run.
112 * 3 10/13/98 9:28a Dave
113 * Started neatening up freespace.h. Many variables renamed and
114 * reorganized. Added AlphaColors.[h,cpp]
116 * 2 10/07/98 10:53a Dave
119 * 1 10/07/98 10:50a Dave
121 * 102 9/11/98 4:14p Dave
122 * Fixed file checksumming of < file_size. Put in more verbose kicking and
123 * PXO stats store reporting.
125 * 101 6/09/98 10:31a Hoffoss
126 * Created index numbers for all xstr() references. Any new xstr() stuff
127 * added from here on out should be added to the end if the list. The
128 * current list count can be found in FreeSpace.cpp (search for
131 * 100 6/01/98 11:43a John
132 * JAS & MK: Classified all strings for localization.
134 * 99 5/23/98 5:50p Lawrance
135 * Don't reset scroll offset when rebuilding the list
137 * 98 5/06/98 11:50p Lawrance
138 * Clean up help overlay code for loadout screens
140 * 97 4/30/98 6:03p Lawrance
141 * Make drag and drop work better.
143 * 96 4/29/98 3:31p Lawrance
144 * draw disabled frames for icons when appropriate
146 * 95 4/28/98 9:35a Dave
147 * Remove bogus assert in create_wings() for ships which arrive late and
148 * haven't been created yet.
150 * 94 4/27/98 6:02p Dave
151 * Modify how missile scoring works. Fixed a team select ui bug. Speed up
152 * multi_lag system. Put in new main hall.
154 * 93 4/14/98 12:57a Dave
155 * Made weapon select screen show netplayer names above ships. Fixed pilot
156 * info popup to show the status of pilot images more correctly.
158 * 92 4/13/98 3:27p Lawrance
159 * fix coords for ship selection pool numbers
161 * 91 4/13/98 3:11p Andsager
162 * Fixed bug when there is no description for a ship.
164 * 90 4/10/98 4:51p Hoffoss
165 * Made several changes related to tooltips.
167 * 89 4/05/98 7:43p Lawrance
168 * fix up saving/restoring of link status and auto-target/match-speed.
170 * 88 4/03/98 4:16p Adam
171 * changed coord's and skip frame for new SS animations
173 * 87 4/02/98 11:40a Lawrance
174 * check for #ifdef DEMO instead of #ifdef DEMO_RELEASE
176 * 86 4/01/98 11:19p Dave
177 * Put in auto-loading of xferred pilot pic files. Grey out background
178 * behind pinfo popup. Put a chatbox message in when players are kicked.
179 * Moved mission title down in briefing. Other ui fixes.
181 * 85 4/01/98 9:21p John
182 * Made NDEBUG, optimized build with no warnings or errors.
184 * 84 3/31/98 11:47p Lawrance
185 * Fix some bugs related to wingmen selection when doing a quick mission
188 * 83 3/31/98 1:50p Duncan
189 * ALAN: fix bugs with selecting alternate weapons
191 * 82 3/30/98 12:18a Lawrance
192 * change some DEMO_RELEASE code to not compile code rather than return
195 * 81 3/29/98 12:55a Lawrance
196 * Get demo build working with limited set of data.
198 * 80 3/26/98 6:01p Dave
199 * Put in file checksumming routine in cfile. Made pilot pic xferring more
200 * robust. Cut header size of voice data packets in half. Put in
201 * restricted game host query system.
203 * 79 3/25/98 8:43p Hoffoss
204 * Changed anim_play() to not be so damn complex when you try and call it.
206 * 78 3/12/98 4:03p Lawrance
207 * don't press buttons when icon dropped on them
209 * 77 3/09/98 11:13a Lawrance
210 * Fix up drop sound effects used in loadout screens.
212 * 76 3/06/98 5:36p Dave
213 * Finished up first rev of team vs team. Probably needs to be debugged
216 * 75 3/05/98 6:48p Lawrance
217 * reposition commit_pressed() to ensure popup gets called after clear but
220 * 74 3/05/98 5:03p Dave
221 * More work on team vs. team support for multiplayer. Need to fix bugs in
224 * 73 3/05/98 12:38a Lawrance
225 * Fix bug with flashing buttons showing over help overlay
227 * 72 3/02/98 5:42p John
228 * Removed WinAVI stuff from Freespace. Made all HUD gauges wriggle from
229 * afterburner. Made gr_set_clip work good with negative x &y. Made
230 * model_caching be on by default. Made each cached model have it's own
231 * bitmap id. Made asteroids not rotate when model_caching is on.
233 * 71 3/01/98 3:26p Dave
234 * Fixed a few team select bugs. Put in multiplayer intertface sounds.
235 * Corrected how ships are disabled/enabled in team select/weapon select
238 * 70 2/28/98 7:04p Lawrance
239 * Don't show reset button in multiplayer
241 * 69 2/26/98 8:21p Allender
242 * fix compiler warning
244 * 68 2/26/98 4:59p Allender
245 * groundwork for team vs team briefings. Moved weaponry pool into the
246 * Team_data structure. Added team field into the p_info structure.
247 * Allow for mutliple structures in the briefing code.
249 * 67 2/24/98 6:21p Lawrance
250 * Integrate new reset button into loadout screens
252 * 66 2/22/98 4:30p John
253 * More string externalization classification
255 * 65 2/22/98 4:17p John
256 * More string externalization classification... 190 left to go!
258 * 64 2/22/98 12:19p John
259 * Externalized some strings
261 * 63 2/19/98 6:26p Dave
262 * Fixed a few file xfer bugs. Tweaked mp team select screen. Put in
263 * initial support for player data uploading.
265 * 62 2/18/98 3:56p Dave
266 * Several bugs fixed for mp team select screen. Put in standalone packet
267 * routing for team select.
269 * 61 2/17/98 6:07p Dave
270 * Tore out old multiplayer team select screen, installed new one.
272 * 60 2/13/98 3:46p Dave
273 * Put in dynamic chatbox sizing. Made multiplayer file lookups use cfile
276 * 59 2/12/98 2:38p Allender
277 * fix multiplayer primary/secondary weapon problems when ships are
278 * outfitted with less than max number
280 * 58 2/07/98 5:47p Lawrance
281 * reset flashing if a button gets highlighted
283 * 57 2/05/98 11:21p Lawrance
284 * When flashing buttons, use highlight frame
286 * 56 1/30/98 10:00a Allender
287 * made large ships able to attack other ships. Made goal code recognize
288 * when ships removed from wings during ship select
290 * 55 1/22/98 5:26p Dave
291 * Modified some pregame sequencing packets. Starting to repair broken
294 * 54 1/17/98 2:46a Dave
295 * Reworked multiplayer join/accept process. Ingame join still needs to be
298 * 53 1/15/98 4:11p Lawrance
299 * Add call to check if slot is player occupied.
301 * 52 1/13/98 4:47p Allender
302 * change default terran ship to reflect new ship class name
304 * 51 1/12/98 5:17p Dave
305 * Put in a bunch of multiplayer sequencing code. Made weapon/ship select
306 * work through the standalone.
308 * 50 1/10/98 12:46a Lawrance
309 * Store last_modified time for mission into player loadout struct.
311 * 49 1/09/98 6:06p Dave
312 * Put in network sound support for multiplayer ship/weapon select
313 * screens. Made clients exit game correctly through warp effect. Fixed
314 * main hall menu help overlay bug.
316 * 48 1/08/98 11:38a Lawrance
319 * 47 1/08/98 11:36a Lawrance
320 * Get ship select and weapons loadout icon dropping sound effects working
321 * for single and multiplayer
323 * 46 1/02/98 9:10p Lawrance
324 * Big changes to how colors get set on the HUD.
326 * 45 12/29/97 4:21p Lawrance
327 * Flash buttons on briefing/ship select/weapons loadout when enough time
328 * has elapsed without activity.
330 * 44 12/29/97 9:42a Lawrance
331 * Ensure that WING_SLOT_IS_PLAYER gets set correctly in multiplayer.
333 * 43 12/24/97 8:54p Lawrance
334 * Integrating new popup code
336 * 42 12/24/97 1:19p Lawrance
337 * fix some bugs with the multiplayer ship/weapons loadout
339 * 41 12/23/97 5:25p Allender
340 * more fixes to multiplayer ship selection. Fixed strange reentrant
341 * problem with cf_callback when loading freespace data
343 * 40 12/23/97 11:59a Allender
344 * changes to ship/wespon selection for multplayer. added sounds to some
345 * interface screens. Update and modiied end-of-briefing packets -- yet
348 * 39 12/23/97 11:04a Lawrance
349 * fix bug in ss_swap_slot_slot()
351 * 38 12/23/97 10:57a Lawrance
352 * move player_set_weapon_prefs() to when commit is pressed in briefing
353 * (from entering gameplay)
355 * 37 12/23/97 10:54a Lawrance
356 * fix some bugs in multiplayer ship selection
358 * 36 12/22/97 6:18p Lawrance
359 * Get save/restore of player loadout working with new code
361 * 35 12/22/97 1:40a Lawrance
362 * Re-write ship select/weapons loadout to be multiplayer friendly
364 * 34 12/19/97 1:23p Dave
365 * Put in multiplayer groundwork for new weapon/ship select screens.
371 #include "missionscreencommon.h"
372 #include "missionshipchoice.h"
373 #include "missionparse.h"
374 #include "missionbrief.h"
375 #include "freespace.h"
376 #include "gamesequence.h"
385 #include "linklist.h"
391 #include "audiostr.h"
394 #include "snazzyui.h"
395 #include "animplay.h"
396 #include "packunpack.h"
397 #include "missionweaponchoice.h"
398 #include "contexthelp.h"
401 #include "missionhotkey.h"
403 #include "multimsgs.h"
404 #include "missionload.h"
405 #include "eventmusic.h"
409 #include "multiteamselect.h"
410 #include "multiutil.h"
411 #include "hudwingmanstatus.h"
412 #include "alphacolors.h"
413 #include "localize.h"
415 //////////////////////////////////////////////////////
417 //////////////////////////////////////////////////////
418 char default_player_ship[255] = NOX("GTF Ulysses");
419 int Select_default_ship = 0;
420 int Ship_select_open = 0; // This game-wide global flag is set to 1 to indicate that the ship
421 // select screen has been opened and memory allocated. This flag
422 // is needed so we can know if ship_select_close() needs to called if
423 // restoring a game from the Options screen invoked from ship select
425 int Commit_pressed; // flag to indicate that the commit button was pressed
426 // use a flag, so the ship_create() can be done at the end of the loop
428 //////////////////////////////////////////////////////
430 //////////////////////////////////////////////////////
431 static int Ship_anim_class = -1; // ship class that is playing as an animation
432 static int Ss_delta_x, Ss_delta_y; // used to offset the carried icon to make it smoothly leave static position
434 //////////////////////////////////////////////////////
436 //////////////////////////////////////////////////////
437 typedef struct ss_icon_info
439 int icon_bmaps[NUM_ICON_FRAMES];
440 int current_icon_bitmap;
442 anim_instance_t *anim_instance;
445 typedef struct ss_slot_info
447 int status; // slot status (WING_SLOT_DISABLED, etc)
448 int sa_index; // index into ship arrival list, -1 if ship is created
449 int original_ship_class;
452 typedef struct ss_wing_info
457 ss_slot_info ss_slots[MAX_WING_SLOTS];
460 //ss_icon_info Ss_icons[MAX_SHIP_TYPES]; // holds ui info on different ship icons
461 //ss_wing_info Ss_wings[MAX_WING_BLOCKS]; // holds ui info for wings and wing slots
463 ss_wing_info Ss_wings_teams[MAX_TEAMS][MAX_WING_BLOCKS];
464 ss_wing_info *Ss_wings;
466 ss_icon_info Ss_icons_teams[MAX_TEAMS][MAX_SHIP_TYPES];
467 ss_icon_info *Ss_icons;
469 int Ss_mouse_down_on_region = -1;
471 int Selected_ss_class; // set to ship class of selected ship, -1 if none selected
472 int Hot_ss_icon; // index that icon is over in list (0..4)
473 int Hot_ss_slot; // index for slot that mouse is over (0..11)
475 ////////////////////////////////////////////////////////////
477 ////////////////////////////////////////////////////////////
478 UI_WINDOW Ship_select_ui_window;
480 static int Ship_anim_coords[GR_NUM_RESOLUTIONS][2] = {
494 static int Ship_info_coords[GR_NUM_RESOLUTIONS][2] = {
504 // coordinate lookup indicies
505 #define SHIP_SELECT_X_COORD 0
506 #define SHIP_SELECT_Y_COORD 1
507 #define SHIP_SELECT_W_COORD 2
508 #define SHIP_SELECT_H_COORD 3
511 // NK: changed from 37 to 51 for new FS2 animations
512 #if defined(FS2_DEMO) || defined(FS1_DEMO)
513 #define SHIP_ANIM_LOOP_FRAME 0
515 #define SHIP_ANIM_LOOP_FRAME 36
517 #define SHIP_ANIM_LOOP_FRAME 51
520 #define MAX_ICONS_ON_SCREEN 4
522 // (x,y) pairs for ship icon and ship icon number
523 int Ship_list_coords[GR_NUM_RESOLUTIONS][MAX_ICONS_ON_SCREEN][4] = {
538 // Store the x locations for the icons in the wing formations
539 int Wing_icon_coords[GR_NUM_RESOLUTIONS][MAX_WSS_SLOTS][2] = {
574 //////////////////////////////////////////////////////
575 // Linked List of icons to show on ship selection list
576 //////////////////////////////////////////////////////
577 #define SS_ACTIVE_ITEM_USED (1<<0)
578 typedef struct ss_active_item
580 ss_active_item *prev, *next;
585 static ss_active_item SS_active_head;
586 static ss_active_item SS_active_items[MAX_WSS_SLOTS];
588 static int SS_active_list_start;
589 static int SS_active_list_size;
591 //////////////////////////////////////////////////////
592 // Background bitmaps data for ship_select
593 //////////////////////////////////////////////////////
594 static char* Ship_select_background_fname[GR_NUM_RESOLUTIONS] = {
604 static char* Ship_select_background_mask_fname[GR_NUM_RESOLUTIONS] = {
609 int Ship_select_background_bitmap;
611 //////////////////////////////////////////////////////
612 // Ship select specific buttons
613 //////////////////////////////////////////////////////
614 #define NUM_SS_BUTTONS 4
615 #define SS_BUTTON_SCROLL_UP 0
616 #define SS_BUTTON_SCROLL_DOWN 1
617 #define SS_BUTTON_RESET 2
618 #define SS_BUTTON_DUMMY 3 // needed to capture mouse for drag/drop icons
620 // convenient struct for handling all button controls
626 UI_BUTTON button; // because we have a class inside this struct, we need the constructor below..
628 ss_buttons(char *name, int x1, int y1, int xt1, int yt1, int h, int s) : filename(name), x(x1), y(y1), xt(xt1), yt(yt1), hotspot(h), scrollable(s) {}
631 static ss_buttons Ship_select_buttons[GR_NUM_RESOLUTIONS][NUM_SS_BUTTONS] = {
634 ss_buttons("ssb_08", 0, 301, -1, -1, 8, 0), // SCROLL UP
635 ss_buttons("ssb_09", 0, 453, -1, -1, 9, 0), // SCROLL DOWN
636 ss_buttons("ssb_39", 566, 317, -1, -1, 39, 0), // RESET
637 ss_buttons("ssb_39", 0, 0, -1, -1, 99, 0) // dummy for drag n' drop
639 ss_buttons("ssb_08", 5, 303, -1, -1, 8, 0), // SCROLL UP
640 ss_buttons("ssb_09", 5, 454, -1, -1, 9, 0), // SCROLL DOWN
641 ss_buttons("ssb_39", 571, 347, -1, -1, 39,0), // RESET
642 ss_buttons("ssb_39", 0, 0, -1, -1, 99,0) // dummy for drag n' drop
646 ss_buttons("2_ssb_08", 8, 485, -1, -1, 8, 0), // SCROLL UP
647 ss_buttons("2_ssb_09", 8, 727, -1, -1, 9, 0), // SCROLL DOWN
648 ss_buttons("2_ssb_39", 913, 556, -1, -1, 39,0), // RESET
649 ss_buttons("2_ssb_39", 0, 0, -1, -1, 99,0) // dummy for drag n' drop
655 #define SHIP_SELECT_NUM_TEXT 0
657 #define SHIP_SELECT_NUM_TEXT 1
659 UI_XSTR Ship_select_text[GR_NUM_RESOLUTIONS][SHIP_SELECT_NUM_TEXT] = {
661 // not needed for FS1
663 { "Reset", 1337, 580, 337, UI_XSTR_COLOR_GREEN, -1, &Ship_select_buttons[0][SS_BUTTON_RESET].button }
667 // not needed for FS1
669 { "Reset", 1337, 938, 546, UI_XSTR_COLOR_GREEN, -1, &Ship_select_buttons[1][SS_BUTTON_RESET].button }
674 // Mask bitmap pointer and Mask bitmap_id
675 static bitmap* ShipSelectMaskPtr; // bitmap pointer to the ship select mask bitmap
676 static ubyte* ShipSelectMaskData; // pointer to actual bitmap data
677 static int Shipselect_mask_w, Shipselect_mask_h;
678 static int ShipSelectMaskBitmap; // bitmap id of the ship select mask bitmap
680 static MENU_REGION Region[NUM_SHIP_SELECT_REGIONS];
681 static int Num_mask_regions;
683 //////////////////////////////////////////////////////
684 // Drag and Drop variables
685 //////////////////////////////////////////////////////
686 typedef struct ss_carry_icon_info
688 int from_slot; // slot index (0..11), -1 if carried from list
689 int ship_class; // ship class of carried icon
691 } ss_carry_icon_info;
693 ss_carry_icon_info Carried_ss_icon;
695 ////////////////////////////////////////////////////////////////////
696 // Internal function prototypes
697 ////////////////////////////////////////////////////////////////////
700 void draw_ship_icons();
701 void draw_ship_icon_with_number(int screen_offset, int ship_class);
702 void stop_ship_animation();
703 void start_ship_animation(int ship_class, int play_sound=0);
706 int pick_from_ship_list(int screen_offset, int ship_class);
707 void pick_from_wing(int wb_num, int ws_num);
710 void ship_select_button_do(int i);
711 void ship_select_common_init();
712 void ss_reset_selected_ship();
713 void ss_restore_loadout();
714 void maybe_change_selected_wing_ship(int wb_num, int ws_num);
717 void ss_init_pool(team_data *pteam);
721 void ss_unload_icons();
722 void ss_init_units();
723 void unload_ship_anim_instances();
724 void unload_ship_anims();
725 anim* ss_load_individual_animation(int ship_class);
727 // Carry icon functions
728 int ss_icon_being_carried();
729 void ss_reset_carried_icon();
730 void ss_set_carried_icon(int from_slot, int ship_class);
732 #define SHIP_DESC_X 445
733 #define SHIP_DESC_Y 273
735 char *ss_tooltip_handler(char *str)
737 if (Selected_ss_class < 0)
740 if (!stricmp(str, NOX("@ship_name"))) {
741 return Ship_info[Selected_ss_class].name;
743 } else if (!stricmp(str, NOX("@ship_type"))) {
744 return Ship_info[Selected_ss_class].type_str;
746 } else if (!stricmp(str, NOX("@ship_maneuverability"))) {
747 return Ship_info[Selected_ss_class].maneuverability_str;
749 } else if (!stricmp(str, NOX("@ship_armor"))) {
750 return Ship_info[Selected_ss_class].armor_str;
752 } else if (!stricmp(str, NOX("@ship_manufacturer"))) {
753 return Ship_info[Selected_ss_class].manufacturer_str;
755 } else if (!stricmp(str, NOX("@ship_desc"))) {
759 str = Ship_info[Selected_ss_class].desc;
763 gr_get_string_size(&w, &h, str);
764 x = SHIP_DESC_X - w / 2;
765 y = SHIP_DESC_Y - h / 2;
767 gr_set_color_fast(&Color_black);
768 gr_rect(x - 5, y - 5, w + 10, h + 10);
770 gr_set_color_fast(&Color_bright_white);
771 gr_string(x, y, str);
778 // Is an icon being carried?
779 int ss_icon_being_carried()
781 if ( Carried_ss_icon.ship_class >= 0 ) {
788 // Clear out carried icon info
789 void ss_reset_carried_icon()
791 Carried_ss_icon.from_slot = -1;
792 Carried_ss_icon.ship_class = -1;
795 // return !0 if carried icon has moved from where it was picked up
796 int ss_carried_icon_moved()
800 mouse_get_pos( &mx, &my );
801 if ( Carried_ss_icon.from_x != mx || Carried_ss_icon.from_y != my) {
808 // Set carried icon data
809 void ss_set_carried_icon(int from_slot, int ship_class)
811 Carried_ss_icon.from_slot = from_slot;
812 Carried_ss_icon.ship_class = ship_class;
814 // Set the mouse to captured
815 Ship_select_buttons[gr_screen.res][SS_BUTTON_DUMMY].button.capture_mouse();
818 // clear all active list items, and reset the flags inside the SS_active_items[] array
819 void clear_active_list()
822 for ( i = 0; i < MAX_WSS_SLOTS; i++ ) {
823 SS_active_items[i].flags = 0;
824 SS_active_items[i].ship_class = -1;
826 list_init(&SS_active_head);
828 SS_active_list_start = 0;
829 SS_active_list_size = 0;
832 // get a free element from SS_active_items[]
833 ss_active_item *get_free_active_list_node()
836 for ( i = 0; i < MAX_WSS_SLOTS; i++ ) {
837 if ( SS_active_items[i].flags == 0 ) {
838 SS_active_items[i].flags |= SS_ACTIVE_ITEM_USED;
839 return &SS_active_items[i];
845 // add a ship into the active list
846 void active_list_add(int ship_class)
850 sai = get_free_active_list_node();
852 sai->ship_class = ship_class;
853 list_append(&SS_active_head, sai);
856 // remove a ship from the active list
857 void active_list_remove(int ship_class)
859 ss_active_item *sai, *temp;
861 // next store players not assigned to wings
862 sai = GET_FIRST(&SS_active_head);
864 while(sai != END_OF_LIST(&SS_active_head)){
865 temp = GET_NEXT(sai);
866 if ( sai->ship_class == ship_class ) {
867 list_remove(&SS_active_head, sai);
874 // Build up the ship selection active list, which is a list of all ships that the player
876 void init_active_list()
883 // build the active list
884 for ( i = 0; i < MAX_SHIP_TYPES; i++ ) {
885 if ( Ss_pool[i] > 0 ) {
886 sai = get_free_active_list_node();
889 list_append(&SS_active_head, sai);
890 SS_active_list_size++;
896 void ship_select_check_buttons()
901 for ( i = 0; i < NUM_SS_BUTTONS; i++ ) {
902 b = &Ship_select_buttons[gr_screen.res][i];
903 if ( b->button.pressed() ) {
904 ship_select_button_do(b->hotspot);
909 // reset the ship selection to the mission defaults
910 void ss_reset_to_default()
912 if ( Game_mode & GM_MULTIPLAYER ) {
917 stop_ship_animation();
919 ss_init_pool(&Team_data[Common_team]);
922 ss_reset_selected_ship();
923 ss_reset_carried_icon();
926 wl_reset_to_defaults();
928 start_ship_animation(Selected_ss_class, 1);
931 // -------------------------------------------------------------------
932 // ship_select_redraw_pressed_buttons()
934 // Redraw any ship select buttons that are pressed down. This function is needed
935 // since we sometimes need to draw pressed buttons last to ensure the entire
936 // button gets drawn (and not overlapped by other buttons)
938 void ship_select_redraw_pressed_buttons()
943 common_redraw_pressed_buttons();
945 for ( i = 0; i < NUM_SS_BUTTONS; i++ ) {
946 b = &Ship_select_buttons[gr_screen.res][i];
947 if ( b->button.pressed() ) {
948 b->button.draw_forced(2);
953 void ship_select_buttons_init()
958 for ( i = 0; i < NUM_SS_BUTTONS; i++ ) {
959 b = &Ship_select_buttons[gr_screen.res][i];
960 b->button.create( &Ship_select_ui_window, "", b->x, b->y, 60, 30, b->scrollable);
961 // set up callback for when a mouse first goes over a button
962 b->button.set_highlight_action( common_play_highlight_sound );
963 b->button.set_bmaps(b->filename);
964 b->button.link_hotspot(b->hotspot);
968 for(i=0; i<SHIP_SELECT_NUM_TEXT; i++){
969 Ship_select_ui_window.add_XSTR(&Ship_select_text[gr_screen.res][i]);
972 // We don't want to have the reset button appear in multiplayer
973 if ( Game_mode & GM_MULTIPLAYER ) {
974 Ship_select_buttons[gr_screen.res][SS_BUTTON_RESET].button.disable();
975 Ship_select_buttons[gr_screen.res][SS_BUTTON_RESET].button.hide();
978 Ship_select_buttons[gr_screen.res][SS_BUTTON_DUMMY].button.disable();
979 Ship_select_buttons[gr_screen.res][SS_BUTTON_DUMMY].button.hide();
982 // -------------------------------------------------------------------------------------
983 // ship_select_button_do() do the button action for the specified pressed button
985 void ship_select_button_do(int i)
987 if ( Background_playing )
991 case SHIP_SELECT_SHIP_SCROLL_UP:
992 if ( Current_screen != ON_SHIP_SELECT )
995 if ( common_scroll_down_pressed(&SS_active_list_start, SS_active_list_size, MAX_ICONS_ON_SCREEN) ) {
996 gamesnd_play_iface(SND_SCROLL);
998 gamesnd_play_iface(SND_GENERAL_FAIL);
1002 case SHIP_SELECT_SHIP_SCROLL_DOWN:
1003 if ( Current_screen != ON_SHIP_SELECT )
1006 if ( common_scroll_up_pressed(&SS_active_list_start, SS_active_list_size, MAX_ICONS_ON_SCREEN) ) {
1007 gamesnd_play_iface(SND_SCROLL);
1009 gamesnd_play_iface(SND_GENERAL_FAIL);
1014 case SHIP_SELECT_RESET:
1015 ss_reset_to_default();
1020 // ---------------------------------------------------------------------
1021 // ship_select_init() is called once when the ship select screen begins
1024 void ship_select_init()
1026 common_set_interface_palette("ShipPalette");
1027 common_flash_button_init();
1029 // if in multiplayer -- set my state to be ship select
1030 if ( Game_mode & GM_MULTIPLAYER ){
1031 // also set the ship which is mine as the default
1032 maybe_change_selected_wing_ship(Net_player->p_info.ship_index/4,Net_player->p_info.ship_index % 4);
1035 set_active_ui(&Ship_select_ui_window);
1036 Current_screen = ON_SHIP_SELECT;
1038 Ss_mouse_down_on_region = -1;
1040 help_overlay_set_state(SS_OVERLAY,0);
1042 if ( Ship_select_open ) {
1043 start_ship_animation( Selected_ss_class );
1044 common_buttons_maybe_reload(&Ship_select_ui_window); // AL 11-21-97: this is necessary since we may returning from the hotkey
1045 // screen, which can release common button bitmaps.
1046 common_reset_buttons();
1047 nprintf(("Alan","ship_select_init() returning without doing anything\n"));
1051 nprintf(("Alan","entering ship_select_init()\n"));
1052 common_select_init();
1054 ShipSelectMaskBitmap = bm_load(Ship_select_background_mask_fname[gr_screen.res]);
1055 if (ShipSelectMaskBitmap < 0) {
1056 if (gr_screen.res == GR_640) {
1057 Error(LOCATION,"Could not load in 'shipselect-m'!");
1058 } else if (gr_screen.res == GR_1024) {
1059 Error(LOCATION,"Could not load in '2_shipselect-m'!");
1063 Shipselect_mask_w = -1;
1064 Shipselect_mask_h = -1;
1066 // get a pointer to bitmap by using bm_lock()
1067 ShipSelectMaskPtr = bm_lock(ShipSelectMaskBitmap, 8, BMP_AABITMAP);
1068 ShipSelectMaskData = (ubyte*)ShipSelectMaskPtr->data;
1069 bm_get_info(ShipSelectMaskBitmap, &Shipselect_mask_w, &Shipselect_mask_h);
1071 help_overlay_load(SS_OVERLAY);
1073 // Set up the mask regions
1074 // initialize the different regions of the menu that will react when the mouse moves over it
1075 Num_mask_regions = 0;
1077 snazzy_menu_add_region(&Region[Num_mask_regions++], "", COMMON_BRIEFING_REGION, 0);
1078 snazzy_menu_add_region(&Region[Num_mask_regions++], "", COMMON_SS_REGION, 0);
1079 snazzy_menu_add_region(&Region[Num_mask_regions++], "", COMMON_WEAPON_REGION, 0);
1080 snazzy_menu_add_region(&Region[Num_mask_regions++], "", COMMON_COMMIT_REGION, 0);
1081 snazzy_menu_add_region(&Region[Num_mask_regions++], "", COMMON_HELP_REGION, 0);
1082 snazzy_menu_add_region(&Region[Num_mask_regions++], "", COMMON_OPTIONS_REGION, 0);
1084 snazzy_menu_add_region(&Region[Num_mask_regions++], "", SHIP_SELECT_SHIP_SCROLL_UP, 0);
1085 snazzy_menu_add_region(&Region[Num_mask_regions++], "", SHIP_SELECT_SHIP_SCROLL_DOWN, 0);
1087 snazzy_menu_add_region(&Region[Num_mask_regions++], "", SHIP_SELECT_ICON_0, 0);
1088 snazzy_menu_add_region(&Region[Num_mask_regions++], "", SHIP_SELECT_ICON_1, 0);
1089 snazzy_menu_add_region(&Region[Num_mask_regions++], "", SHIP_SELECT_ICON_2, 0);
1090 snazzy_menu_add_region(&Region[Num_mask_regions++], "", SHIP_SELECT_ICON_3, 0);
1092 snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_0_SHIP_0, 0);
1093 snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_0_SHIP_1, 0);
1094 snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_0_SHIP_2, 0);
1095 snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_0_SHIP_3, 0);
1096 snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_1_SHIP_0, 0);
1097 snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_1_SHIP_1, 0);
1098 snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_1_SHIP_2, 0);
1099 snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_1_SHIP_3, 0);
1100 snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_2_SHIP_0, 0);
1101 snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_2_SHIP_1, 0);
1102 snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_2_SHIP_2, 0);
1103 snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_2_SHIP_3, 0);
1105 Ship_select_open = 1; // This game-wide global flag is set to 1 to indicate that the ship
1106 // select screen has been opened and memory allocated. This flag
1107 // is needed so we can know if ship_select_close() needs to called if
1108 // restoring a game from the Options screen invoked from ship select
1110 // init ship selection masks and buttons
1111 Ship_select_ui_window.create( 0, 0, gr_screen.max_w, gr_screen.max_h, 0 );
1112 Ship_select_ui_window.set_mask_bmap(Ship_select_background_mask_fname[gr_screen.res]);
1113 Ship_select_ui_window.tooltip_handler = ss_tooltip_handler;
1114 common_buttons_init(&Ship_select_ui_window);
1115 ship_select_buttons_init();
1116 start_ship_animation( Selected_ss_class );
1118 // init ship selection background bitmpa
1119 Ship_select_background_bitmap = bm_load(Ship_select_background_fname[gr_screen.res]);
1123 // Return the ship class for the icon specified by index. Need to iterate through the active
1124 // list of icons to find out what ship class for this icon
1126 // input: index => list index (0..3)
1127 // exit: ship class, -1 if none
1129 int ss_get_ship_class_from_list(int index)
1131 ss_active_item *sai;
1132 int list_entry, i, count;
1137 for ( sai = GET_FIRST(&SS_active_head); sai != END_OF_LIST(&SS_active_head); sai = GET_NEXT(sai) ) {
1139 if ( count <= SS_active_list_start )
1142 if ( i >= MAX_ICONS_ON_SCREEN )
1146 list_entry = sai->ship_class;
1156 // ---------------------------------------------------------------------
1157 // maybe_pick_up_list_icon()
1159 void maybe_pick_up_list_icon(int offset)
1163 ship_class = ss_get_ship_class_from_list(offset);
1164 if ( ship_class != -1 ) {
1165 pick_from_ship_list(offset, ship_class);
1169 // ---------------------------------------------------------------------
1170 // maybe_change_selected_ship()
1172 void maybe_change_selected_ship(int offset)
1176 ship_class = ss_get_ship_class_from_list(offset);
1177 if ( ship_class == -1 )
1180 if ( Ss_mouse_down_on_region != (SHIP_SELECT_ICON_0+offset) ) {
1184 if ( Selected_ss_class == -1 ) {
1185 Selected_ss_class = ship_class;
1186 start_ship_animation(Selected_ss_class, 1);
1188 else if ( Selected_ss_class != ship_class ) {
1189 Selected_ss_class = ship_class;
1190 start_ship_animation(Selected_ss_class, 1);
1193 Assert( Selected_ss_class == ship_class );
1196 void maybe_change_selected_wing_ship(int wb_num, int ws_num)
1198 ss_slot_info *ss_slot;
1200 Assert(wb_num >= 0 && wb_num < MAX_WING_BLOCKS);
1201 Assert(ws_num >= 0 && ws_num < MAX_WING_SLOTS);
1203 if ( Ss_wings[wb_num].wingnum < 0 ) {
1207 ss_slot = &Ss_wings[wb_num].ss_slots[ws_num];
1208 switch ( ss_slot->status & ~WING_SLOT_LOCKED ) {
1210 case WING_SLOT_FILLED:
1211 case WING_SLOT_FILLED|WING_SLOT_IS_PLAYER:
1212 if ( Selected_ss_class != -1 && Selected_ss_class != Wss_slots[wb_num*4+ws_num].ship_class ) {
1213 Selected_ss_class = Wss_slots[wb_num*4+ws_num].ship_class;
1214 start_ship_animation(Selected_ss_class, 1);
1224 // ---------------------------------------------------------------------
1225 // do_mouse_over_wing_slot()
1227 // returns: 0 => icon wasn't dropped onto slot
1228 // 1 => icon was dropped onto slot
1229 int do_mouse_over_wing_slot(int block, int slot)
1231 Hot_ss_slot = block*4 + slot;
1233 if ( !mouse_down(MOUSE_LEFT_BUTTON) ) {
1234 if ( ss_icon_being_carried() ) {
1236 if ( ss_disabled_slot(block*4+slot) ) {
1237 gamesnd_play_iface(SND_ICON_DROP);
1241 if ( !ss_carried_icon_moved() ) {
1242 ss_reset_carried_icon();
1246 ss_drop(Carried_ss_icon.from_slot, Carried_ss_icon.ship_class, Hot_ss_slot, -1);
1247 ss_reset_carried_icon();
1251 if ( Ss_mouse_down_on_region == (WING_0_SHIP_0+block*4+slot) ) {
1252 pick_from_wing(block, slot);
1259 void do_mouse_over_list_slot(int index)
1261 Hot_ss_icon = index;
1263 if ( Ss_mouse_down_on_region != (SHIP_SELECT_ICON_0+index) ){
1267 if ( mouse_down(MOUSE_LEFT_BUTTON) )
1268 maybe_pick_up_list_icon(index);
1271 // Icon has been dropped, but not onto a wing slot
1272 void ss_maybe_drop_icon()
1274 if ( Drop_icon_mflag ) {
1275 if ( ss_icon_being_carried() ) {
1276 // Add back into the ship entry list
1277 if ( Carried_ss_icon.from_slot >= 0 ) {
1279 ss_drop(Carried_ss_icon.from_slot, -1, -1, Carried_ss_icon.ship_class);
1281 if ( ss_carried_icon_moved() ) {
1282 gamesnd_play_iface(SND_ICON_DROP);
1285 ss_reset_carried_icon();
1290 void ss_anim_pause()
1292 if ( Selected_ss_class >= 0 && Ss_icons[Selected_ss_class].anim_instance ) {
1293 anim_pause(Ss_icons[Selected_ss_class].anim_instance);
1297 void ss_anim_unpause()
1299 if ( Selected_ss_class >= 0 && Ss_icons[Selected_ss_class].anim_instance ) {
1300 anim_unpause(Ss_icons[Selected_ss_class].anim_instance);
1304 // maybe flash a button if player hasn't done anything for a while
1305 void ss_maybe_flash_button()
1307 if ( common_flash_bright() ) {
1308 // weapon loadout button
1309 if ( Common_buttons[Current_screen-1][gr_screen.res][2].button.button_hilighted() ) {
1310 common_flash_button_init();
1312 Common_buttons[Current_screen-1][gr_screen.res][2].button.draw_forced(1);
1318 // -------------------------------------------------------------------------------------
1319 // ship_select_render(float frametime)
1321 void ship_select_render(float frametime)
1323 if ( !Background_playing ) {
1324 gr_set_bitmap(Ship_select_background_bitmap);
1328 anim_render_all(0, frametime);
1329 anim_render_all(ON_SHIP_SELECT, frametime);
1333 // blit any active ship information text
1334 void ship_select_blit_ship_info()
1340 color *header = &Color_white;
1341 color *text = &Color_green;
1344 // if we don't have a valid ship selected, do nothing
1345 if(Selected_ss_class == -1){
1349 // get the ship class
1350 sip = &Ship_info[Selected_ss_class];
1353 y_start = Ship_info_coords[gr_screen.res][SHIP_SELECT_Y_COORD];
1357 // blit the ship class (name)
1358 gr_set_color_fast(header);
1359 gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD], y_start,XSTR("Class",739));
1361 if(strlen(sip->name)){
1362 gr_set_color_fast(text);
1363 gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD]+4, y_start,sip->name);
1367 // blit the ship type
1368 gr_set_color_fast(header);
1369 gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD], y_start,XSTR("Type",740));
1371 if((sip->type_str != NULL) && strlen(sip->type_str)){
1372 gr_set_color_fast(text);
1373 gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD]+4, y_start,sip->type_str);
1377 // blit the ship length
1378 gr_set_color_fast(header);
1379 gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD], y_start,XSTR("Length",741));
1381 if((sip->ship_length != NULL) && strlen(sip->ship_length)){
1383 // in german, drop the s from Meters and make sure M is caps
1384 char *sp = strstr(sip->ship_length, "Meters");
1386 sp[5] = ' '; // make the old s a space now
1389 gr_set_color_fast(text);
1390 gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD]+4, y_start, sip->ship_length);
1394 // blit the max velocity
1395 gr_set_color_fast(header);
1396 gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD], y_start,XSTR("Max Velocity",742));
1398 sprintf(str,XSTR("%d m/s",743),(int)sip->max_vel.xyz.z);
1399 gr_set_color_fast(text);
1400 gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD]+4, y_start,str);
1403 // blit the maneuverability
1404 gr_set_color_fast(header);
1405 gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD], y_start,XSTR("Maneuverability",744));
1407 if((sip->maneuverability_str != NULL) && strlen(sip->maneuverability_str)){
1408 gr_set_color_fast(text);
1409 gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD]+4, y_start,sip->maneuverability_str);
1414 gr_set_color_fast(header);
1415 gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD], y_start,XSTR("Armor",745));
1417 if((sip->armor_str != NULL) && strlen(sip->armor_str)){
1418 gr_set_color_fast(text);
1419 gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD]+4, y_start,sip->armor_str);
1423 // blit the gun mounts
1424 gr_set_color_fast(header);
1425 gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD], y_start,XSTR("Gun Mounts",746));
1427 if((sip->gun_mounts != NULL) && strlen(sip->gun_mounts)){
1428 gr_set_color_fast(text);
1429 gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD]+4, y_start,sip->gun_mounts);
1433 // blit the missile banke
1434 gr_set_color_fast(header);
1435 gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD], y_start,XSTR("Missile Banks",747));
1437 if((sip->missile_banks != NULL) && strlen(sip->missile_banks)){
1438 gr_set_color_fast(text);
1439 gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD]+4, y_start,sip->missile_banks);
1443 // blit the manufacturer
1444 gr_set_color_fast(header);
1445 gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD], y_start,XSTR("Manufacturer",748));
1447 if((sip->manufacturer_str != NULL) && strlen(sip->manufacturer_str)){
1448 gr_set_color_fast(text);
1449 gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD]+4, y_start,sip->manufacturer_str);
1453 // blit the _short_ text description
1455 Assert(Multi_ts_ship_info_line_count < 3);
1456 gr_set_color_fast(&Color_normal);
1457 for(idx=0;idx<SHIP_SELECT_ship_info_line_count;idx++){
1458 gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD], y_start, SHIP_SELECT_ship_info_lines[idx]);
1466 // ---------------------------------------------------------------------
1467 // ship_select_do() is called once per game frame, and is responsible for
1468 // updating the ship select screen
1470 // frametime is in seconds
1471 void ship_select_do(float frametime)
1473 int k, ship_select_choice, snazzy_action;
1475 ship_select_choice = snazzy_menu_do(ShipSelectMaskData, Shipselect_mask_w, Shipselect_mask_h, Num_mask_regions, Region, &snazzy_action, 0);
1480 k = common_select_do(frametime);
1482 if ( help_overlay_active(SS_OVERLAY) ) {
1489 // Check common keypresses
1490 common_check_keys(k);
1492 if ( Mouse_down_last_frame ) {
1493 Ss_mouse_down_on_region = ship_select_choice;
1496 // Check for the mouse over a region (not clicked, just over)
1497 if ( ship_select_choice > -1 ) {
1499 switch(ship_select_choice) {
1500 case SHIP_SELECT_ICON_0:
1501 do_mouse_over_list_slot(0);
1503 case SHIP_SELECT_ICON_1:
1504 do_mouse_over_list_slot(1);
1506 case SHIP_SELECT_ICON_2:
1507 do_mouse_over_list_slot(2);
1509 case SHIP_SELECT_ICON_3:
1510 do_mouse_over_list_slot(3);
1513 if ( do_mouse_over_wing_slot(0,0) )
1514 ship_select_choice = -1;
1517 if ( do_mouse_over_wing_slot(0,1) )
1518 ship_select_choice = -1;
1521 if ( do_mouse_over_wing_slot(0,2) )
1522 ship_select_choice = -1;
1525 if ( do_mouse_over_wing_slot(0,3) )
1526 ship_select_choice = -1;
1529 if ( do_mouse_over_wing_slot(1,0) )
1530 ship_select_choice = -1;
1533 if ( do_mouse_over_wing_slot(1,1) )
1534 ship_select_choice = -1;
1537 if ( do_mouse_over_wing_slot(1,2) )
1538 ship_select_choice = -1;
1541 if ( do_mouse_over_wing_slot(1,3) )
1542 ship_select_choice = -1;
1545 if ( do_mouse_over_wing_slot(2,0) )
1546 ship_select_choice = -1;
1549 if ( do_mouse_over_wing_slot(2,1) )
1550 ship_select_choice = -1;
1553 if ( do_mouse_over_wing_slot(2,2) )
1554 ship_select_choice = -1;
1557 if ( do_mouse_over_wing_slot(2,3) )
1558 ship_select_choice = -1;
1567 common_check_buttons();
1568 ship_select_check_buttons();
1570 // Check for the mouse clicks over a region
1571 if ( ship_select_choice > -1 && snazzy_action == SNAZZY_CLICKED ) {
1572 switch (ship_select_choice) {
1574 case SHIP_SELECT_ICON_0:
1575 maybe_change_selected_ship(0);
1578 case SHIP_SELECT_ICON_1:
1579 maybe_change_selected_ship(1);
1582 case SHIP_SELECT_ICON_2:
1583 maybe_change_selected_ship(2);
1586 case SHIP_SELECT_ICON_3:
1587 maybe_change_selected_ship(3);
1591 maybe_change_selected_wing_ship(0,0);
1595 maybe_change_selected_wing_ship(0,1);
1599 maybe_change_selected_wing_ship(0,2);
1603 maybe_change_selected_wing_ship(0,3);
1607 maybe_change_selected_wing_ship(1,0);
1611 maybe_change_selected_wing_ship(1,1);
1615 maybe_change_selected_wing_ship(1,2);
1619 maybe_change_selected_wing_ship(1,3);
1623 maybe_change_selected_wing_ship(2,0);
1627 maybe_change_selected_wing_ship(2,1);
1631 maybe_change_selected_wing_ship(2,2);
1635 maybe_change_selected_wing_ship(2,3);
1644 ss_maybe_drop_icon();
1646 if ( Ship_anim_class >= 0) {
1647 Assert(Selected_ss_class >= 0);
1648 if ( Ss_icons[Selected_ss_class].anim_instance->frame_num == Ss_icons[Selected_ss_class].anim_instance->stop_at ) {
1649 nprintf(("anim", "Frame number = %d, Stop at %d\n", Ss_icons[Selected_ss_class].anim_instance->frame_num, Ss_icons[Selected_ss_class].anim_instance->stop_at));
1650 anim_play_struct aps;
1651 anim_release_render_instance(Ss_icons[Selected_ss_class].anim_instance);
1652 anim_play_init(&aps, Ss_icons[Selected_ss_class].anim, Ship_anim_coords[gr_screen.res][0], Ship_anim_coords[gr_screen.res][1]);
1653 aps.start_at = SHIP_ANIM_LOOP_FRAME;
1654 // aps.start_at = 0;
1655 aps.screen_id = ON_SHIP_SELECT;
1656 aps.framerate_independent = 1;
1657 aps.skip_frames = 0;
1658 Ss_icons[Selected_ss_class].anim_instance = anim_play(&aps);
1664 ship_select_render(frametime);
1665 if ( !Background_playing ) {
1666 Ship_select_ui_window.draw();
1667 ship_select_redraw_pressed_buttons();
1668 common_render_selected_screen_button();
1671 // The background transition plays once. Display ship icons after Background done playing
1672 if ( !Background_playing ) {
1674 for ( int i = 0; i < MAX_WING_BLOCKS; i++ ) {
1675 draw_wing_block(i, Hot_ss_slot, -1, Selected_ss_class);
1679 if ( ss_icon_being_carried() ) {
1680 int mouse_x, mouse_y;
1681 mouse_get_pos( &mouse_x, &mouse_y );
1682 gr_set_bitmap(Ss_icons[Carried_ss_icon.ship_class].icon_bmaps[ICON_FRAME_SELECTED]);
1683 gr_bitmap(mouse_x + Ss_delta_x , mouse_y + Ss_delta_y);
1686 // draw out ship information
1687 ship_select_blit_ship_info();
1690 ss_maybe_flash_button();
1692 // blit help overlay if active
1693 help_overlay_maybe_blit(SS_OVERLAY);
1695 // If the commit button was pressed, do the commit button actions. Done at the end of the
1696 // loop so there isn't a skip in the animation (since ship_create() can take a long time if
1697 // the ship model is not in memory
1698 if ( Commit_pressed ) {
1705 if ( Game_mode & GM_MULTIPLAYER ) {
1706 if ( Selected_ss_class >= 0 )
1707 Net_player->p_info.ship_class = Selected_ss_class;
1710 if(!Background_playing){
1711 // should render this as close to last as possible so it overlaps all controls
1712 // chatbox_render();
1715 // If the commit button was pressed, do the commit button actions. Done at the end of the
1716 // loop so there isn't a skip in the animation (since ship_create() can take a long time if
1717 // the ship model is not in memory
1718 if ( Commit_pressed ) {
1725 // ------------------------------------------------------------------------
1726 // ship_select_close() is called once when the ship select screen is exited
1729 void ship_select_close()
1733 if ( !Ship_select_open ) {
1734 nprintf(("Alan","ship_select_close() returning without doing anything\n"));
1738 nprintf(("Alan", "Entering ship_select_close()\n"));
1740 // done with the bitmaps, so unlock it
1741 bm_unlock(ShipSelectMaskBitmap);
1743 // unload the bitmaps
1744 bm_unload(ShipSelectMaskBitmap);
1745 help_overlay_unload(SS_OVERLAY);
1747 // release the bitmpas that were previously extracted from anim files
1750 // Release any active ship anim instances
1751 unload_ship_anim_instances();
1753 // unload ship animations if they were loaded
1754 unload_ship_anims();
1756 Ship_select_ui_window.destroy();
1759 common_free_interface_palette();
1762 Ship_anim_class = -1;
1763 Ship_select_open = 0; // This game-wide global flag is set to 0 to indicate that the ship
1764 // select screen has been closed and memory freed. This flag
1765 // is needed so we can know if ship_select_close() needs to called if
1766 // restoring a game from the Options screen invoked from ship select
1769 // ss_unload_icons() frees the bitmaps used for ship icons
1770 void ss_unload_icons()
1775 for ( i = 0; i < MAX_SHIP_TYPES; i++ ) {
1776 icon = &Ss_icons[i];
1778 for ( j = 0; j < NUM_ICON_FRAMES; j++ ) {
1779 if ( icon->icon_bmaps[j] >= 0 ) {
1780 bm_release(icon->icon_bmaps[j]);
1781 icon->icon_bmaps[j] = -1;
1787 // ------------------------------------------------------------------------
1788 // draw_ship_icons() will request which icons to draw on screen.
1789 void draw_ship_icons()
1794 ss_active_item *sai;
1796 for ( sai = GET_FIRST(&SS_active_head); sai != END_OF_LIST(&SS_active_head); sai = GET_NEXT(sai) ) {
1798 if ( count <= SS_active_list_start )
1801 if ( i >= MAX_ICONS_ON_SCREEN )
1804 draw_ship_icon_with_number(i, sai->ship_class);
1809 // ------------------------------------------------------------------------
1810 // draw_ship_icon_with_number() will draw a ship icon on screen with the
1811 // number of available ships to the left.
1814 void draw_ship_icon_with_number(int screen_offset, int ship_class)
1818 ss_icon_info *ss_icon;
1821 Assert( screen_offset >= 0 && screen_offset <= 3 );
1822 Assert( ship_class >= 0 );
1823 ss_icon = &Ss_icons[ship_class];
1825 num_x = Ship_list_coords[gr_screen.res][screen_offset][2];
1826 num_y = Ship_list_coords[gr_screen.res][screen_offset][3];
1828 // assume default bitmap is to be used
1829 ss_icon->current_icon_bitmap = ss_icon->icon_bmaps[ICON_FRAME_NORMAL];
1831 // next check if ship has mouse over it
1832 if ( Hot_ss_icon > -1 ) {
1833 Assert(Hot_ss_icon <= 3);
1834 if ( Hot_ss_icon == screen_offset )
1835 ss_icon->current_icon_bitmap = ss_icon->icon_bmaps[ICON_FRAME_HOT];
1838 // highest precedence is if the ship is selected
1839 if ( Selected_ss_class > -1 ) {
1840 if ( Selected_ss_class == ship_class )
1841 ss_icon->current_icon_bitmap = ss_icon->icon_bmaps[ICON_FRAME_SELECTED];
1844 if ( Ss_pool[ship_class] <= 0 ) {
1849 gr_set_bitmap(ss_icon->current_icon_bitmap);
1850 gr_bitmap(Ship_list_coords[gr_screen.res][screen_offset][0], Ship_list_coords[gr_screen.res][screen_offset][1]);
1853 sprintf(buf, "%d", Ss_pool[ship_class] );
1854 gr_set_color_fast(&Color_white);
1855 gr_string(num_x, num_y, buf);
1858 // ------------------------------------------------------------------------
1859 // stop_ship_animation() will halt the currently playing ship animation. The
1860 // instance will be freed, (but the compressed data is not freed). The animation
1861 // will not display after this function is called (even on this frame), since
1862 // the instance is removed from the anim_render_list.
1863 void stop_ship_animation()
1865 ss_icon_info *ss_icon;
1867 if ( Ship_anim_class == -1 )
1870 ss_icon = &Ss_icons[Ship_anim_class];
1872 anim_release_render_instance(ss_icon->anim_instance);
1873 ss_icon->anim_instance = NULL;
1875 Ship_anim_class = -1;
1879 // ------------------------------------------------------------------------
1880 // this loads an individual animation file
1881 // it attempts to load a hires version (ie, it attaches a "2_" in front of the
1882 // filename. if no hires version is available, it defaults to the lowres
1884 anim* ss_load_individual_animation(int ship_class)
1887 char animation_filename[CF_MAX_FILENAME_LENGTH+4];
1890 // If we are in 1024x768, we first want to append "2_" in front of the filename
1891 if (gr_screen.res == GR_1024) {
1892 Assert(strlen(Ship_info[ship_class].anim_filename) <= 30);
1893 strcpy(animation_filename, "2_");
1894 strcat(animation_filename, Ship_info[ship_class].anim_filename);
1895 // now check if file exists
1896 // GRR must add a .ANI at the end for detection
1897 strcat(animation_filename, ".ani");
1899 p_anim = anim_load(animation_filename, 1);
1900 if (p_anim == NULL) {
1901 // failed loading hi-res, revert to low res
1902 strcpy(animation_filename, Ship_info[ship_class].anim_filename);
1903 p_anim = anim_load(animation_filename, 1);
1904 mprintf(("Ship ANI: Can not find %s, using lowres version instead.\n", animation_filename));
1906 mprintf(("SHIP ANI: Found hires version of %s\n",animation_filename));
1909 // this is lame and doesnt work cuz cf_exist() doesnt search the packfiles
1910 if (!cf_exist(animation_filename, CF_TYPE_INTERFACE)) {
1911 // file does not exist, use original low res version
1912 strcpy(animation_filename, Ship_info[ship_class].anim_filename);
1913 mprintf(("Ship ANI: Can not find %s, using lowres version instead.\n", animation_filename));
1915 animation_filename[strlen(animation_filename) - 4] = '\0';
1916 mprintf(("SHIP ANI: Found hires version of %s\n",animation_filename));
1920 strcpy(animation_filename, Ship_info[ship_class].anim_filename);
1921 p_anim = anim_load(animation_filename, 1);
1927 // ------------------------------------------------------------------------
1928 // start_ship_animation() will start a ship animation playing, and will
1929 // load the compressed anim from disk if required.
1930 void start_ship_animation(int ship_class, int play_sound)
1932 ss_icon_info *ss_icon;
1933 Assert( ship_class >= 0 );
1935 if ( Ship_anim_class == ship_class )
1938 if ( Ship_anim_class >= 0 ) {
1939 stop_ship_animation();
1942 ss_icon = &Ss_icons[ship_class];
1944 // see if we need to load in the animation from disk
1945 if ( ss_icon->anim == NULL ) {
1946 ss_icon->anim = ss_load_individual_animation(ship_class);
1949 // see if we need to get an instance
1950 if ( ss_icon->anim_instance == NULL ) {
1951 anim_play_struct aps;
1953 anim_play_init(&aps, ss_icon->anim, Ship_anim_coords[gr_screen.res][0], Ship_anim_coords[gr_screen.res][1]);
1954 aps.screen_id = ON_SHIP_SELECT;
1955 aps.framerate_independent = 1;
1956 aps.skip_frames = 0;
1957 ss_icon->anim_instance = anim_play(&aps);
1960 Ship_anim_class = ship_class;
1962 // if ( play_sound ) {
1963 gamesnd_play_iface(SND_SHIP_ICON_CHANGE);
1967 // ------------------------------------------------------------------------
1968 // unload_ship_anims() will free all compressed anims from memory that were
1969 // loaded for the ship animations.
1972 void unload_ship_anims()
1974 for ( int i = 0; i < MAX_SHIP_TYPES; i++ ) {
1975 if ( Ss_icons[i].anim ) {
1976 anim_free(Ss_icons[i].anim);
1977 Ss_icons[i].anim = NULL;
1982 // ------------------------------------------------------------------------
1983 // unload_ship_anim_instances() will free any active ship animation instances.
1986 void unload_ship_anim_instances()
1988 for ( int i = 0; i < MAX_SHIP_TYPES; i++ ) {
1989 if ( Ss_icons[i].anim_instance ) {
1990 anim_release_render_instance(Ss_icons[i].anim_instance);
1991 Ss_icons[i].anim_instance = NULL;
1996 // ------------------------------------------------------------------------
1997 // commit_pressed() is called when the commit button from any of the briefing/ship select/ weapon
1998 // select screens is pressed. The ship selected is created, and the interface music is stopped.
1999 void commit_pressed()
2001 int player_ship_info_index;
2003 if ( Wss_num_wings > 0 ) {
2004 if(!(Game_mode & GM_MULTIPLAYER)){
2006 rc = create_wings();
2008 gamesnd_play_iface(SND_GENERAL_FAIL);
2015 if ( Selected_ss_class == -1 ) {
2016 player_ship_info_index = Team_data[Common_team].default_ship;
2019 Assert(Selected_ss_class >= 0 );
2020 player_ship_info_index = Selected_ss_class;
2023 update_player_ship( player_ship_info_index );
2024 if ( wl_update_ship_weapons(Ships[Player_obj->instance].objnum, &Wss_slots[0]) == -1 ) {
2025 popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR( "Player ship has no weapons", 461));
2030 // Check to ensure that the hotkeys are still pointing to valid objects. It is possible
2031 // for the player to assign a ship to a hotkey, then go and delete that ship in the
2032 // ship selection, and then try to start the mission. This function will detect those objects,
2033 // and remove them from the hotkey linked lists.
2034 mission_hotkey_validate();
2036 gamesnd_play_iface(SND_COMMIT_PRESSED);
2038 // save the player loadout
2039 if ( !(Game_mode & GM_MULTIPLAYER) ) {
2040 strcpy(Player_loadout.filename, Game_current_mission_filename);
2041 strcpy(Player_loadout.last_modified, The_mission.modified);
2045 // move to the next stage
2046 // in multiplayer this is the final mission sync
2047 if(Game_mode & GM_MULTIPLAYER){
2048 Multi_sync_mode = MULTI_SYNC_POST_BRIEFING;
2049 gameseq_post_event(GS_EVENT_MULTI_MISSION_SYNC);
2051 // otherwise tell the standalone to move everyone into this state and continue
2052 if((Net_player->flags & NETINFO_FLAG_GAME_HOST) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER)){
2053 send_mission_sync_packet(MULTI_SYNC_POST_BRIEFING);
2056 // in single player we jump directly into the mission
2058 gameseq_post_event(GS_EVENT_ENTER_GAME);
2062 // ------------------------------------------------------------------------
2063 // pick_from_ship_list() will determine if an icon from the ship selection
2064 // list can be picked up (for drag and drop). It calculates the difference
2065 // in x & y between the icon and the mouse, so we can move the icon with the
2066 // mouse in a realistic way
2067 int pick_from_ship_list(int screen_offset, int ship_class)
2070 Assert(ship_class >= 0);
2072 if ( Wss_num_wings == 0 )
2075 // If carrying an icon, then do nothing
2076 if ( ss_icon_being_carried() )
2079 if ( Ss_pool[ship_class] > 0 ) {
2080 int mouse_x, mouse_y;
2082 ss_set_carried_icon(-1, ship_class);
2083 mouse_get_pos( &mouse_x, &mouse_y );
2084 Ss_delta_x = Ship_list_coords[gr_screen.res][screen_offset][0] - mouse_x;
2085 Ss_delta_y = Ship_list_coords[gr_screen.res][screen_offset][1] - mouse_y;
2086 Assert( Ss_pool[ship_class] >= 0 );
2090 common_flash_button_init();
2094 // ------------------------------------------------------------------------
2095 // pick_from_wing() will determine if an icon from the wing formation (wb_num)
2096 // and slot number (ws_num) can be picked up (for drag and drop). It calculates
2097 // the difference in x & y between the icon and the mouse, so we can move the icon with the
2098 // mouse in a realistic way
2099 void pick_from_wing(int wb_num, int ws_num)
2102 Assert(wb_num >= 0 && wb_num < MAX_WING_BLOCKS);
2103 Assert(ws_num >= 0 && ws_num < MAX_WING_SLOTS);
2107 wb = &Ss_wings[wb_num];
2108 ws = &wb->ss_slots[ws_num];
2109 slot_index = wb_num*4+ws_num;
2111 if ( wb->wingnum < 0 )
2114 // Take care of case where the mouse button goes from up to down in one frame while
2116 if ( Drop_on_wing_mflag && ss_icon_being_carried() ) {
2117 if ( !ss_disabled_slot(slot_index) ) {
2118 ss_drop(Carried_ss_icon.from_slot, Carried_ss_icon.ship_class, slot_index, -1);
2119 ss_reset_carried_icon();
2120 gamesnd_play_iface(SND_ICON_DROP_ON_WING);
2124 if ( ss_icon_being_carried() )
2127 if ( ss_disabled_slot(slot_index) ) {
2131 switch ( ws->status ) {
2132 case WING_SLOT_DISABLED:
2133 case WING_SLOT_IGNORE:
2137 case WING_SLOT_EMPTY:
2138 case WING_SLOT_EMPTY|WING_SLOT_IS_PLAYER:
2139 // TODO: add fail sound
2143 case WING_SLOT_FILLED|WING_SLOT_IS_PLAYER:
2144 case WING_SLOT_FILLED:
2146 int mouse_x, mouse_y;
2147 Assert(Wss_slots[slot_index].ship_class >= 0);
2148 ss_set_carried_icon(slot_index, Wss_slots[slot_index].ship_class);
2150 mouse_get_pos( &mouse_x, &mouse_y );
2151 Ss_delta_x = Wing_icon_coords[gr_screen.res][slot_index][0] - mouse_x;
2152 Ss_delta_y = Wing_icon_coords[gr_screen.res][slot_index][1] - mouse_y;
2153 Carried_ss_icon.from_x = mouse_x;
2154 Carried_ss_icon.from_y = mouse_y;
2164 common_flash_button_init();
2167 // ------------------------------------------------------------------------
2168 // draw_wing_block() will draw the wing icons for the wing formation number
2169 // passed in as a parameter.
2171 // input: wb_num => wing block number (numbering starts at 0)
2172 // hot_slot => index of slot that mouse is over
2173 // selected_slot => index of slot that is selected
2174 // class_select => all ships of this class are drawn selected (send -1 to not use)
2175 void draw_wing_block(int wb_num, int hot_slot, int selected_slot, int class_select)
2181 int i, bitmap_to_draw, w, h, sx, sy, slot_index;
2183 Assert(wb_num >= 0 && wb_num < MAX_WING_BLOCKS);
2184 wb = &Ss_wings[wb_num];
2186 if ( wb->wingnum == -1 )
2189 // print the wing name under the wing
2190 wp = &Wings[wb->wingnum];
2191 gr_get_string_size(&w, &h, wp->name);
2192 sx = Wing_icon_coords[gr_screen.res][wb_num*4][0] + 16 - w/2;
2193 sy = Wing_icon_coords[gr_screen.res][wb_num*4 + 3][1] + 32 + h;
2194 gr_set_color_fast(&Color_normal);
2195 gr_string(sx, sy, wp->name);
2197 for ( i = 0; i < MAX_WING_SLOTS; i++ ) {
2198 bitmap_to_draw = -1;
2199 ws = &wb->ss_slots[i];
2200 slot_index = wb_num*4 + i;
2202 if ( Wss_slots[slot_index].ship_class >= 0 ) {
2203 icon = &Ss_icons[Wss_slots[slot_index].ship_class];
2208 switch(ws->status & ~WING_SLOT_LOCKED ) {
2209 case WING_SLOT_FILLED:
2210 case WING_SLOT_FILLED|WING_SLOT_IS_PLAYER:
2214 if ( class_select >= 0 ) { // only ship select
2215 if ( Carried_ss_icon.from_slot == slot_index ) {
2216 if ( ss_carried_icon_moved() ) {
2217 bitmap_to_draw = Wing_slot_empty_bitmap;
2219 bitmap_to_draw = -1;
2225 if ( ws->status & WING_SLOT_LOCKED ) {
2226 bitmap_to_draw = icon->icon_bmaps[ICON_FRAME_DISABLED];
2228 // in multiplayer, determine if this it the special case where the slot is disabled, and
2229 // it is also _my_ slot (ie, team capatains/host have not locked players yet)
2230 if((Game_mode & GM_MULTIPLAYER) && multi_ts_disabled_high_slot(slot_index)){
2231 bitmap_to_draw = icon->icon_bmaps[ICON_FRAME_DISABLED_HIGH];
2237 bitmap_to_draw = icon->icon_bmaps[ICON_FRAME_NORMAL];
2238 if ( selected_slot == slot_index || class_select == Wss_slots[slot_index].ship_class) {
2239 bitmap_to_draw = icon->icon_bmaps[ICON_FRAME_SELECTED];
2240 } else if ( hot_slot == slot_index ) {
2241 if ( mouse_down(MOUSE_LEFT_BUTTON) ){
2242 bitmap_to_draw = icon->icon_bmaps[ICON_FRAME_SELECTED];
2244 bitmap_to_draw = icon->icon_bmaps[ICON_FRAME_HOT];
2248 if ( ws->status & WING_SLOT_IS_PLAYER && (selected_slot != slot_index) ) {
2249 bitmap_to_draw = icon->icon_bmaps[ICON_FRAME_PLAYER];
2253 case WING_SLOT_EMPTY:
2254 case WING_SLOT_EMPTY|WING_SLOT_IS_PLAYER:
2255 bitmap_to_draw = Wing_slot_empty_bitmap;
2258 case WING_SLOT_DISABLED:
2259 case WING_SLOT_IGNORE:
2261 bitmap_to_draw = icon->icon_bmaps[ICON_FRAME_DISABLED];
2263 bitmap_to_draw = Wing_slot_disabled_bitmap;
2274 if ( bitmap_to_draw != -1 ) {
2275 gr_set_bitmap(bitmap_to_draw);
2276 gr_bitmap(Wing_icon_coords[gr_screen.res][slot_index][0], Wing_icon_coords[gr_screen.res][slot_index][1]);
2281 // called by multiplayer team select to set the slot based flags
2282 void ss_make_slot_empty(int slot_index)
2284 int wing_num,slot_num;
2288 // calculate the wing #
2289 wing_num = slot_index / 4;
2290 slot_num = slot_index % 4;
2292 // get the wing and slot entries
2293 wb = &Ss_wings[wing_num];
2294 ws = &wb->ss_slots[slot_num];
2297 ws->status &= ~(WING_SLOT_FILLED | WING_SLOT_DISABLED);
2298 ws->status |= WING_SLOT_EMPTY;
2301 // called by multiplayer team select to set the slot based flags
2302 void ss_make_slot_full(int slot_index)
2304 int wing_num,slot_num;
2308 // calculate the wing #
2309 wing_num = slot_index / 4;
2310 slot_num = slot_index % 4;
2312 // get the wing and slot entries
2313 wb = &Ss_wings[wing_num];
2314 ws = &wb->ss_slots[slot_num];
2317 ws->status &= ~(WING_SLOT_EMPTY | WING_SLOT_DISABLED);
2318 ws->status |= WING_SLOT_FILLED;
2321 void ss_blit_ship_icon(int x,int y,int ship_class,int bmap_num)
2323 // blit the bitmap in the correct location
2324 if(ship_class == -1){
2325 gr_set_bitmap(Wing_slot_empty_bitmap);
2327 ss_icon_info *icon = &Ss_icons[ship_class];
2328 Assert(icon->icon_bmaps[bmap_num] != -1);
2329 gr_set_bitmap(icon->icon_bmaps[bmap_num]);
2334 // ------------------------------------------------------------------------
2335 // unload_ship_icons() frees the memory that was used to hold the bitmaps
2338 void unload_wing_icons()
2340 if ( Wing_slot_empty_bitmap != -1 ) {
2341 bm_release(Wing_slot_empty_bitmap);
2342 Wing_slot_empty_bitmap = -1;
2345 if ( Wing_slot_disabled_bitmap != -1 ) {
2346 bm_release(Wing_slot_disabled_bitmap);
2347 Wing_slot_disabled_bitmap = -1;
2351 // ------------------------------------------------------------------------
2352 // create_wings() will ensure the correct ships are in the player wings
2353 // for the game. It works by calling change_ship_type() on the wing ships
2354 // so they match what the player selected. ship_create() is called for the
2355 // player ship (and current_count, ship_index[] is updated), since it is not yet
2356 // part of the wing structure.
2358 // returns: 0 ==> success
2367 int shipnum, objnum, slot_index;
2368 int cleanup_ship_index[MAX_WING_SLOTS];
2372 for ( i = 0; i < MAX_WING_BLOCKS; i++ ) {
2376 if ( wb->wingnum == -1 )
2379 wp = &Wings[wb->wingnum];
2381 for ( j = 0; j < MAX_WING_SLOTS; j++ ) {
2383 ws = &wb->ss_slots[j];
2384 switch ( ws->status ) {
2386 case WING_SLOT_FILLED:
2387 case WING_SLOT_FILLED|WING_SLOT_IS_PLAYER:
2388 case WING_SLOT_FILLED|WING_SLOT_LOCKED:
2389 case WING_SLOT_FILLED|WING_SLOT_IS_PLAYER|WING_SLOT_LOCKED:
2390 if ( wp->ship_index[j] >= 0 ) {
2391 Assert(Ships[wp->ship_index[j]].objnum >= 0);
2394 if ( ws->status & WING_SLOT_IS_PLAYER ) {
2395 update_player_ship(Wss_slots[slot_index].ship_class);
2397 if ( wl_update_ship_weapons(Ships[Player_obj->instance].objnum, &Wss_slots[i*4+j]) == -1 ) {
2398 popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR( "Player ship has no weapons", 461));
2402 objnum = OBJ_INDEX(Player_obj);
2403 shipnum = Objects[objnum].instance;
2407 for ( p_objp = GET_FIRST(&ship_arrival_list); p_objp != END_OF_LIST(&ship_arrival_list); p_objp = GET_NEXT(p_objp) ) {
2408 if ( p_objp->wingnum == WING_INDEX(wp) ) {
2409 if ( ws->sa_index == (p_objp-ship_arrivals) ) {
2410 p_objp->ship_class = Wss_slots[slot_index].ship_class;
2411 wl_update_parse_object_weapons(p_objp, &Wss_slots[i*4+j]);
2421 // Change the ship type of the ship if different than current.
2422 // NOTE: This will reset the weapons for this ship. I think this is
2423 // the right thing to do, since the ships may have different numbers
2424 // of weapons and may not have the same allowed weapon types
2425 if ( Ships[wp->ship_index[j]].ship_info_index != Wss_slots[slot_index].ship_class )
2426 change_ship_type(wp->ship_index[j], Wss_slots[slot_index].ship_class);
2427 wl_update_ship_weapons(Ships[wp->ship_index[j]].objnum, &Wss_slots[i*4+j]);
2433 case WING_SLOT_EMPTY:
2434 case WING_SLOT_EMPTY|WING_SLOT_IS_PLAYER:
2435 if ( ws->status & WING_SLOT_IS_PLAYER ) {
2436 popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR( "Player %s must select a place in player wing", 462), Player->callsign);
2444 } // end for (wing slot)
2445 } // end for (wing block)
2447 for ( i = 0; i < MAX_WING_BLOCKS; i++ ) {
2449 wp = &Wings[wb->wingnum];
2451 if ( wb->wingnum == -1 )
2454 for ( k = 0; k < MAX_WING_SLOTS; k++ ) {
2455 cleanup_ship_index[k] = -1;
2458 for ( j = 0; j < MAX_WING_SLOTS; j++ ) {
2459 ws = &wb->ss_slots[j];
2460 switch( ws->status ) {
2461 case WING_SLOT_EMPTY:
2462 // delete ship that is not going to be used by the wing
2463 if ( wb->is_late ) {
2464 list_remove( &ship_arrival_list, &ship_arrivals[ws->sa_index]);
2466 Assert(wp->wave_count >= 0);
2469 shipnum = wp->ship_index[j];
2470 Assert( shipnum >= 0 && shipnum < MAX_SHIPS );
2471 cleanup_ship_index[j] = shipnum;
2472 ship_add_exited_ship( &Ships[shipnum], SEF_PLAYER_DELETED );
2473 obj_delete(Ships[shipnum].objnum);
2474 hud_set_wingman_status_none( Ships[shipnum].wing_status_wing_index, Ships[shipnum].wing_status_wing_pos);
2483 } // end for (wing slot)
2485 for ( k = 0; k < MAX_WING_SLOTS; k++ ) {
2486 if ( cleanup_ship_index[k] != -1 ) {
2487 ship_wing_cleanup( cleanup_ship_index[k], wp );
2491 } // end for (wing block)
2496 void ship_stop_animation()
2498 if ( Ship_anim_class >= 0 )
2499 stop_ship_animation();
2502 // ----------------------------------------------------------------------------
2503 // update_player_ship()
2505 // Updates the ship class of the player ship
2507 // parameters: si_index => ship info index of ship class to change to
2510 void update_player_ship(int si_index)
2512 Assert( si_index >= 0 );
2513 Assert( Player_obj != NULL);
2516 // Change the ship type of the player ship if different than current.
2517 // NOTE: This will reset the weapons for this ship. I think this is
2518 // the right thing to do, since the ships may have different numbers
2519 // of weapons and may not have the same allowed weapon types
2520 if ( Player_ship->ship_info_index != si_index )
2521 change_ship_type(Player_obj->instance, si_index);
2523 Player->last_ship_flown_si_index = si_index;
2526 // ----------------------------------------------------------------------------
2527 // create a default player ship
2529 // parameters: use_last_flown => select ship that was last flown on a mission
2530 // (this is a default parameter which is set to 1)
2532 // returns: 0 => success
2535 int create_default_player_ship(int use_last_flown)
2537 int player_ship_class=-1, i;
2539 // find the ship that matches the string stored in default_player_ship
2541 if ( use_last_flown ) {
2542 player_ship_class = Players[Player_num].last_ship_flown_si_index;
2545 for (i = 0; i < Num_ship_types; i++) {
2546 if ( !stricmp(Ship_info[i].name, default_player_ship) ) {
2547 player_ship_class = i;
2548 Players[Player_num].last_ship_flown_si_index = player_ship_class;
2553 if (i == Num_ship_types)
2557 update_player_ship(player_ship_class);
2559 // debug code to keep using descent style physics if the player starts a new game
2561 if ( use_descent ) {
2563 toggle_player_object();
2570 // return the original ship class for the specified slot
2571 int ss_return_original_ship_class(int slot_num)
2578 return Ss_wings[wnum].ss_slots[snum].original_ship_class;
2581 // return the ship arrival index for the slot (-1 means no ship arrival index)
2582 int ss_return_saindex(int slot_num)
2589 return Ss_wings[wnum].ss_slots[snum].sa_index;
2592 // ----------------------------------------------------------------------------
2595 // For a given wing slot, return the ship index if the ship has been created.
2596 // Otherwise, find the index into ship_arrivals[] for the ship
2598 // input: wing_block => wing block of ship to find
2599 // wing_slot => wing slot of ship to find
2600 // ship_index => OUTPUT parameter: the Ships[] index of the ship in the wing slot
2601 // This value will be -1 if there is no ship created yet
2602 // ppobjp => OUTPUT parameter: returns a pointer to a parse object for
2603 // the ship that hasn't been created yet. Set to NULL if the
2604 // ship has already been created
2606 // returns: the original ship class of the ship, or -1 if the ship doesn't exist
2608 // NOTE: For the player wing, the player is not yet in the wp->ship_index[].. so
2609 // that is why there is an offset of 1 when getting ship indicies from the player
2610 // wing. The player is special cased by looking at the status of the wing slot
2612 int ss_return_ship(int wing_block, int wing_slot, int *ship_index, p_object **ppobjp)
2619 if (!Wss_num_wings) {
2621 *ship_index = Player_obj->instance;
2622 return Player_ship->ship_info_index;
2625 if ( Ss_wings[wing_block].wingnum < 0 ) {
2629 ws = &Ss_wings[wing_block].ss_slots[wing_slot];
2631 // Check to see if ship is on the ship_arrivals[] list
2632 if ( ws->sa_index != -1 ) {
2634 *ppobjp = &ship_arrivals[ws->sa_index];
2636 *ship_index = Wings[Ss_wings[wing_block].wingnum].ship_index[wing_slot];
2637 Assert(*ship_index != -1);
2640 return ws->original_ship_class;
2643 // return the name of the ship in the specified wing position... if the ship is the
2644 // player ship, return the player callsign
2646 // input: ensure at least NAME_LENGTH bytes allocated for name buffer
2647 void ss_return_name(int wing_block, int wing_slot, char *name)
2652 ws = &Ss_wings[wing_block].ss_slots[wing_slot];
2653 wp = &Wings[Ss_wings[wing_block].wingnum];
2655 if (!Wss_num_wings) {
2656 strcpy(name, Player->callsign);
2660 // Check to see if ship is on the ship_arrivals[] list
2661 if ( ws->sa_index != -1 ) {
2662 strcpy(name, ship_arrivals[ws->sa_index].name);
2665 sp = &Ships[wp->ship_index[wing_slot]];
2667 // in multiplayer, return the callsigns of the players who are in the ships
2668 if(Game_mode & GM_MULTIPLAYER){
2669 int player_index = multi_find_player_by_object(&Objects[sp->objnum]);
2670 if(player_index != -1){
2671 strcpy(name,Net_players[player_index].player->callsign);
2673 strcpy(name,sp->ship_name);
2676 strcpy(name, sp->ship_name);
2681 int ss_get_selected_ship()
2683 return Selected_ss_class;
2686 // Set selected ship to the first occupied wing slot, or first ship in pool if no slots are occupied
2687 void ss_reset_selected_ship()
2691 Selected_ss_class = -1;
2693 if ( Wss_num_wings <= 0 ) {
2694 Selected_ss_class = Team_data[Common_team].default_ship;
2698 // get first ship class found on slots
2699 for ( i = 0; i < MAX_WSS_SLOTS; i++ ) {
2700 if ( Wss_slots[i].ship_class >= 0 ) {
2701 Selected_ss_class = Wss_slots[i].ship_class;
2706 if ( Selected_ss_class == -1 ) {
2708 for ( i = 0; i < MAX_SHIP_TYPES; i++ ) {
2709 if ( Ss_pool[i] > 0 ) {
2710 Selected_ss_class = i;
2715 if ( Selected_ss_class == -1 ) {
2721 // There may be ships that are in wings but not in Team_data[0]. Since we still want to show those
2722 // icons in the ship selection list, the code below checks for these cases. If a ship is found in
2723 // a wing, and is not in Team_data[0], it is appended to the end of the ship_count[] and ship_list[] arrays
2724 // that are in Team_data[0]
2726 // exit: number of distinct ship classes available to choose from
2727 int ss_fixup_team_data(team_data *tdata)
2729 int i, j, k, ship_in_parse_player, list_size;
2731 team_data *p_team_data;
2733 p_team_data = tdata;
2734 ship_in_parse_player = 0;
2735 list_size = p_team_data->number_choices;
2737 for ( i = 0; i < MAX_PLAYER_WINGS; i++ ) {
2739 if ( Starting_wings[i] == -1 )
2741 wp = &Wings[Starting_wings[i]];
2742 for ( j = 0; j < wp->current_count; j++ ) {
2743 ship_in_parse_player = 0;
2745 for ( k = 0; k < p_team_data->number_choices; k++ ) {
2746 Assert( p_team_data->ship_count[k] >= 0 );
2747 if ( p_team_data->ship_list[k] == Ships[wp->ship_index[j]].ship_info_index ) {
2748 ship_in_parse_player = 1;
2751 } // end for, go to next item in parse player
2753 if ( !ship_in_parse_player ) {
2754 p_team_data->ship_count[list_size] = 0;
2755 p_team_data->ship_list[list_size] = Ships[wp->ship_index[j]].ship_info_index;
2756 p_team_data->number_choices++;
2759 } // end for, go get next ship in wing
2761 if ( wp->current_count == 0 ) {
2763 for ( p_objp = GET_FIRST(&ship_arrival_list); p_objp != END_OF_LIST(&ship_arrival_list); p_objp = GET_NEXT(p_objp) ) {
2764 if ( p_objp->wingnum == WING_INDEX(wp) ) {
2765 ship_in_parse_player = 0;
2767 for ( k = 0; k < p_team_data->number_choices; k++ ) {
2768 Assert( p_team_data->ship_count[k] >= 0 );
2769 if ( p_team_data->ship_list[k] == p_objp->ship_class ) {
2770 ship_in_parse_player = 1;
2773 } // end for, go to next item in parse player
2775 if ( !ship_in_parse_player ) {
2776 p_team_data->ship_count[list_size] = 0;
2777 p_team_data->ship_list[list_size] = p_objp->ship_class;
2778 p_team_data->number_choices++;
2784 } // end for, go to next wing
2786 if ( list_size == 0 ) {
2787 // ensure that the default player ship is in the ship_list too
2788 ship_in_parse_player = 0;
2789 for ( k = 0; k < p_team_data->number_choices; k++ ) {
2790 Assert( p_team_data->ship_count[k] >= 0 );
2791 if ( p_team_data->ship_list[k] == p_team_data->default_ship ) {
2792 ship_in_parse_player = 1;
2796 if ( !ship_in_parse_player ) {
2797 p_team_data->ship_count[list_size] = 0;
2798 p_team_data->ship_list[list_size] = p_team_data->default_ship;
2799 p_team_data->number_choices++;
2807 // set numbers of ships in pool to default values
2808 void ss_init_pool(team_data *pteam)
2812 for ( i = 0; i < MAX_SHIP_TYPES; i++ ) {
2816 // set number of available ships based on counts in team_data
2817 for ( i = 0; i < pteam->number_choices; i++ ) {
2818 Ss_pool[pteam->ship_list[i]] = pteam->ship_count[i];
2822 // load the icons for a specific ship class
2823 void ss_load_icons(int ship_class)
2826 int first_frame, num_frames, i;
2828 icon = &Ss_icons[ship_class];
2830 first_frame = bm_load_animation(Ship_info[ship_class].icon_filename, &num_frames);
2831 if ( first_frame == -1 ) {
2832 Int3(); // Could not load in icon frames.. get Alan
2836 for ( i = 0; i < num_frames; i++ ) {
2837 icon->icon_bmaps[i] = first_frame+i;
2840 // set the current bitmap for the ship icon
2841 icon->current_icon_bitmap = icon->icon_bmaps[ICON_FRAME_NORMAL];
2844 // load all the icons for ships in the pool
2845 void ss_load_all_icons()
2847 #ifndef DEMO // not for FS2_DEMO
2851 for ( i = 0; i < MAX_SHIP_TYPES; i++ ) {
2853 Ss_icons[i].current_icon_bitmap = -1;
2854 Ss_icons[i].anim = NULL;
2855 Ss_icons[i].anim_instance = NULL;
2856 for ( j = 0; j < NUM_ICON_FRAMES; j++ ) {
2857 Ss_icons[i].icon_bmaps[j] = -1;
2860 if ( Ss_pool[i] >= 0 ) {
2868 // Load in a specific ship animation. The data is loaded as a memory-mapped file since these animations
2870 void ss_load_anim(int ship_class)
2874 icon = &Ss_icons[ship_class];
2876 // load the compressed ship animation into memory
2877 // NOTE: if last parm of load_anim is 1, the anim file is mapped to memory
2878 Assert( icon->anim == NULL );
2879 icon->anim = ss_load_individual_animation(ship_class);
2880 if ( icon->anim == NULL ) {
2881 Int3(); // couldn't load anim filename.. get Alan
2885 // Load in any ship animations. This function assumes that Ss_pool has been inited.
2886 void ss_load_all_anims()
2888 #ifndef DEMO // not for FS2_DEMO
2892 for ( i = 0; i < MAX_SHIP_TYPES; i++ ) {
2893 if ( Ss_pool[i] > 0 ) {
2901 // determine if the slot is disabled
2902 int ss_disabled_slot(int slot_num)
2904 if ( Wss_num_wings <= 0 ){
2908 // HACK HACK HACK - call the team select function in multiplayer
2909 if(Game_mode & GM_MULTIPLAYER) {
2910 return multi_ts_disabled_slot(slot_num);
2912 return ( Ss_wings[slot_num/4].ss_slots[slot_num%4].status & WING_SLOT_IGNORE );
2915 // reset the slot data
2916 void ss_clear_slots()
2921 for ( i = 0; i < MAX_WSS_SLOTS; i++ ) {
2922 Wss_slots[i].ship_class = -1;
2925 for ( i = 0; i < 3; i++ ) {
2926 for ( j = 0; j < 4; j++ ) {
2927 slot = &Ss_wings[i].ss_slots[j];
2928 slot->status = WING_SLOT_DISABLED;
2929 slot->sa_index = -1;
2930 slot->original_ship_class = -1;
2935 // initialize all wing struct stuff
2936 void ss_clear_wings()
2940 for(idx=0;idx<MAX_PLAYER_WINGS;idx++){
2941 Ss_wings[idx].wingnum = -1;
2942 Ss_wings[idx].num_slots = 0;
2943 Ss_wings[idx].is_late = 0;
2947 // set up Wss_num_wings and Wss_wings[] based on Starting_wings[] info
2948 void ss_init_wing_info(int wing_num,int starting_wing_num)
2951 ss_wing_info *ss_wing;
2954 ss_wing = &Ss_wings[wing_num];
2956 if ( Starting_wings[starting_wing_num] < 0 ) {
2960 ss_wing->wingnum = Starting_wings[starting_wing_num];
2963 wp = &Wings[Ss_wings[wing_num].wingnum];
2964 ss_wing->num_slots = wp->current_count;
2966 if ( wp->current_count == 0 || wp->ship_index[0] == -1 ) {
2968 // Temporarily fill in the current count and initialize the ship list in the wing
2969 // This gets cleaned up before the mission is started
2970 for ( p_objp = GET_FIRST(&ship_arrival_list); p_objp != END_OF_LIST(&ship_arrival_list); p_objp = GET_NEXT(p_objp) ) {
2971 if ( p_objp->wingnum == WING_INDEX(wp) ) {
2972 slot = &ss_wing->ss_slots[ss_wing->num_slots++];
2973 slot->sa_index = p_objp-ship_arrivals;
2974 slot->original_ship_class = p_objp->ship_class;
2976 ss_wing->is_late = 1;
2981 // Determine if a ship is actually a console player ship
2982 int ss_wing_slot_is_console_player(int index)
2984 int wingnum, slotnum;
2989 if ( wingnum >= Wss_num_wings ) {
2993 if ( Ss_wings[wingnum].ss_slots[slotnum].status & WING_SLOT_IS_PLAYER ) {
3000 // init the ship selection portion of the units, and set up the ui data
3001 void ss_init_units()
3005 ss_slot_info *ss_slot;
3006 ss_wing_info *ss_wing;
3008 for ( i = 0; i < Wss_num_wings; i++ ) {
3010 ss_wing = &Ss_wings[i];
3012 if ( ss_wing->wingnum < 0 ) {
3017 wp = &Wings[ss_wing->wingnum];
3019 for ( j = 0; j < ss_wing->num_slots; j++ ) {
3021 ss_slot = &ss_wing->ss_slots[j];
3023 if ( ss_slot->sa_index == -1 ) {
3024 ss_slot->original_ship_class = Ships[wp->ship_index[j]].ship_info_index;
3027 // Set the type of slot. Check if the slot is marked as locked, if so then the player is not
3028 // going to be able to modify that ship.
3029 if ( ss_slot->sa_index == -1 ) {
3031 if ( Ships[wp->ship_index[j]].flags & SF_LOCKED ) {
3032 ss_slot->status = WING_SLOT_DISABLED;
3033 ss_slot->status |= WING_SLOT_LOCKED;
3035 ss_slot->status = WING_SLOT_FILLED;
3038 objnum = Ships[wp->ship_index[j]].objnum;
3039 if ( Objects[objnum].flags & OF_PLAYER_SHIP ) {
3040 if ( ss_slot->status & WING_SLOT_LOCKED ) {
3041 // Int3(); // Get Alan
3044 ss_slot->status &= ~(WING_SLOT_LOCKED);
3046 ss_slot->status = WING_SLOT_FILLED;
3047 if ( objnum == OBJ_INDEX(Player_obj) ) {
3048 ss_slot->status |= WING_SLOT_IS_PLAYER;
3052 if ( ship_arrivals[ss_slot->sa_index].flags & P_SF_LOCKED ) {
3053 ss_slot->status = WING_SLOT_DISABLED;
3054 ss_slot->status |= WING_SLOT_LOCKED;
3056 ss_slot->status = WING_SLOT_FILLED;
3058 if ( ship_arrivals[ss_slot->sa_index].flags & P_OF_PLAYER_START ) {
3059 if ( ss_slot->status & WING_SLOT_LOCKED ) {
3060 // Int3(); // Get Alan
3063 ss_slot->status &= ~(WING_SLOT_LOCKED);
3065 ss_slot->status = WING_SLOT_FILLED;
3066 ss_slot->status |= WING_SLOT_IS_PLAYER;
3070 // Assign the ship class to the unit
3071 Wss_slots[i*4+j].ship_class = ss_slot->original_ship_class;
3076 // lock/unlock any necessary slots for multiplayer
3077 if(Game_mode & GM_MULTIPLAYER){
3078 ss_recalc_multiplayer_slots();
3082 // set the necessary pointers
3083 void ss_set_team_pointers(int team)
3085 Ss_wings = Ss_wings_teams[team];
3086 Ss_icons = Ss_icons_teams[team];
3087 Ss_pool = Ss_pool_teams[team];
3088 Wl_pool = Wl_pool_teams[team];
3089 Wss_slots = Wss_slots_teams[team];
3092 // initialize team specific stuff
3093 void ship_select_init_team_data(int team_num)
3097 // set up the pointers to initialize the data structures.
3098 Ss_wings = Ss_wings_teams[team_num];
3099 Ss_icons = Ss_icons_teams[team_num];
3100 Ss_pool = Ss_pool_teams[team_num];
3101 Wl_pool = Wl_pool_teams[team_num];
3102 Wss_slots = Wss_slots_teams[team_num];
3104 ss_fixup_team_data(&Team_data[team_num]);
3105 ss_init_pool(&Team_data[team_num]);
3107 ss_clear_slots(); // reset data for slots
3110 // determine how many wings we should be checking for
3112 if((Game_mode & GM_MULTIPLAYER) && (Netgame.type_flags & NG_TYPE_TEAM)){
3113 // now setup wings for easy reference
3114 ss_init_wing_info(0,team_num);
3116 // now setup wings for easy reference
3117 for(idx=0;idx<MAX_PLAYER_WINGS;idx++){
3118 ss_init_wing_info(idx,idx);
3123 // if there are no wings, don't call the init_units() function
3124 if ( Wss_num_wings <= 0 ) {
3125 Wss_slots[0].ship_class = Team_data[team_num].default_ship;
3132 // called when the briefing is entered
3133 void ship_select_common_init()
3137 // initialize team critical data for all teams
3138 if((Game_mode & GM_MULTIPLAYER) && (Netgame.type_flags & NG_TYPE_TEAM)){
3139 // initialize for all teams in the game
3140 for(idx=0;idx<MULTI_TS_MAX_TEAMS;idx++){
3141 ship_select_init_team_data(idx);
3144 // finally, intialize team data for myself
3145 ship_select_init_team_data(Common_team);
3147 ship_select_init_team_data(Common_team);
3152 // load the necessary icons/animations
3153 ss_load_all_icons();
3154 ss_load_all_anims();
3156 ss_reset_selected_ship();
3157 ss_reset_carried_icon();
3160 // change any interface data based on updated Wss_slots[] and Ss_pool[]
3161 void ss_synch_interface()
3166 int old_list_start = SS_active_list_start;
3168 init_active_list(); // build the list of pool ships
3170 if ( old_list_start < SS_active_list_size ) {
3171 SS_active_list_start = old_list_start;
3174 for ( i = 0; i < MAX_WSS_SLOTS; i++ ) {
3175 slot = &Ss_wings[i/4].ss_slots[i%4];
3177 if ( Wss_slots[i].ship_class == -1 ) {
3178 if ( slot->status & WING_SLOT_FILLED ) {
3179 slot->status &= ~WING_SLOT_FILLED;
3180 slot->status |= WING_SLOT_EMPTY;
3183 if ( slot->status & WING_SLOT_EMPTY ) {
3184 slot->status &= ~WING_SLOT_EMPTY;
3185 slot->status |= WING_SLOT_FILLED;
3191 // exit: data changed flag
3192 int ss_swap_slot_slot(int from_slot, int to_slot, int *sound)
3194 int i, tmp, fwnum, fsnum, twnum, tsnum;
3196 if ( from_slot == to_slot ) {
3197 *sound=SND_ICON_DROP_ON_WING;
3201 // ensure from_slot has a ship to pick up
3202 if ( Wss_slots[from_slot].ship_class < 0 ) {
3203 *sound=SND_ICON_DROP;
3207 fwnum = from_slot/4;
3208 fsnum = from_slot%4;
3214 tmp = Wss_slots[from_slot].ship_class;
3215 Wss_slots[from_slot].ship_class = Wss_slots[to_slot].ship_class;
3216 Wss_slots[to_slot].ship_class = tmp;
3219 for ( i = 0; i < MAX_WL_WEAPONS; i++ ) {
3220 tmp = Wss_slots[from_slot].wep[i];
3221 Wss_slots[from_slot].wep[i] = Wss_slots[to_slot].wep[i];
3222 Wss_slots[to_slot].wep[i] = tmp;
3224 tmp = Wss_slots[from_slot].wep_count[i];
3225 Wss_slots[from_slot].wep_count[i] = Wss_slots[to_slot].wep_count[i];
3226 Wss_slots[to_slot].wep_count[i] = tmp;
3229 *sound=SND_ICON_DROP_ON_WING;
3233 // exit: data changed flag
3234 int ss_dump_to_list(int from_slot, int to_list, int *sound)
3236 int i, fwnum, fsnum;
3239 slot = &Wss_slots[from_slot];
3241 // ensure from_slot has a ship to pick up
3242 if ( slot->ship_class < 0 ) {
3243 *sound=SND_ICON_DROP;
3247 fwnum = from_slot/4;
3248 fsnum = from_slot%4;
3250 // put ship back in list
3251 Ss_pool[to_list]++; // return to list
3252 slot->ship_class = -1; // remove from slot
3254 // put weapons back in list
3255 for ( i = 0; i < MAX_WL_WEAPONS; i++ ) {
3256 if ( (slot->wep[i] >= 0) && (slot->wep_count[i] > 0) ) {
3257 Wl_pool[slot->wep[i]] += slot->wep_count[i];
3259 slot->wep_count[i] = 0;
3263 *sound=SND_ICON_DROP;
3267 // exit: data changed flag
3268 int ss_grab_from_list(int from_list, int to_slot, int *sound)
3271 int i, wep[MAX_WL_WEAPONS], wep_count[MAX_WL_WEAPONS];
3273 slot = &Wss_slots[to_slot];
3275 // ensure that pool has ship
3276 if ( Ss_pool[from_list] <= 0 ) {
3277 *sound=SND_ICON_DROP;
3281 Assert(slot->ship_class < 0 ); // slot should be empty
3283 // take ship from list->slot
3284 Ss_pool[from_list]--;
3285 slot->ship_class = from_list;
3287 // take weapons from list->slot
3288 wl_get_default_weapons(from_list, to_slot, wep, wep_count);
3289 wl_remove_weps_from_pool(wep, wep_count, slot->ship_class);
3290 for ( i = 0; i < MAX_WL_WEAPONS; i++ ) {
3291 slot->wep[i] = wep[i];
3292 slot->wep_count[i] = wep_count[i];
3295 *sound=SND_ICON_DROP_ON_WING;
3299 // exit: data changed flag
3300 int ss_swap_list_slot(int from_list, int to_slot, int *sound)
3302 int i, wep[MAX_WL_WEAPONS], wep_count[MAX_WL_WEAPONS];
3305 // ensure that pool has ship
3306 if ( Ss_pool[from_list] <= 0 ) {
3307 *sound=SND_ICON_DROP;
3311 slot = &Wss_slots[to_slot];
3312 Assert(slot->ship_class >= 0 ); // slot should be filled
3314 // put ship from slot->list
3315 Ss_pool[Wss_slots[to_slot].ship_class]++;
3317 // put weapons from slot->list
3318 for ( i = 0; i < MAX_WL_WEAPONS; i++ ) {
3319 if ( (slot->wep[i] >= 0) && (slot->wep_count[i] > 0) ) {
3320 Wl_pool[slot->wep[i]] += slot->wep_count[i];
3322 slot->wep_count[i] = 0;
3326 // take ship from list->slot
3327 Ss_pool[from_list]--;
3328 slot->ship_class = from_list;
3330 // take weapons from list->slot
3331 wl_get_default_weapons(from_list, to_slot, wep, wep_count);
3332 wl_remove_weps_from_pool(wep, wep_count, slot->ship_class);
3333 for ( i = 0; i < MAX_WL_WEAPONS; i++ ) {
3334 slot->wep[i] = wep[i];
3335 slot->wep_count[i] = wep_count[i];
3338 *sound=SND_ICON_DROP_ON_WING;
3342 void ss_apply(int mode, int from_slot, int from_list, int to_slot, int to_list,int player_index)
3348 case WSS_SWAP_SLOT_SLOT:
3349 update = ss_swap_slot_slot(from_slot, to_slot, &sound);
3351 case WSS_DUMP_TO_LIST:
3352 update = ss_dump_to_list(from_slot, to_list, &sound);
3354 case WSS_GRAB_FROM_LIST:
3355 update = ss_grab_from_list(from_list, to_slot, &sound);
3357 case WSS_SWAP_LIST_SLOT:
3358 update = ss_swap_list_slot(from_list, to_slot, &sound);
3362 // only play this sound if the move was done locally (by the host in other words)
3363 if ( (sound >= 0) && (player_index == -1) ) {
3364 gamesnd_play_iface(sound);
3368 // NO LONGER USED - THERE IS A MULTIPLAYER VERSION OF THIS SCREEN NOW
3370 if ( MULTIPLAYER_HOST ) {
3372 ubyte wss_data[MAX_PACKET_SIZE-20];
3373 size = store_wss_data(wss_data, MAX_PACKET_SIZE-20, sound);
3374 send_wss_update_packet(wss_data, size, player_index);
3378 ss_synch_interface();
3382 void ss_drop(int from_slot,int from_list,int to_slot,int to_list,int player_index)
3385 common_flash_button_init();
3387 mode = wss_get_mode(from_slot, from_list, to_slot, to_list, -1);
3389 ss_apply(mode, from_slot, from_list, to_slot, to_list,player_index);
3393 // lock/unlock any necessary slots for multiplayer
3394 void ss_recalc_multiplayer_slots()
3398 ss_slot_info *ss_slot;
3399 ss_wing_info *ss_wing;
3402 if ( Wss_num_wings <= 0 ) {
3403 Wss_slots[0].ship_class = Team_data[Common_team].default_ship;;
3407 for ( i = 0; i < Wss_num_wings; i++ ) {
3408 ss_wing = &Ss_wings[i];
3409 if ( ss_wing->wingnum < 0 ) {
3414 // NOTE : the method below will eventually have to change to account for all possible netgame options
3416 // get the wing pointer
3417 wp = &Wings[ss_wing->wingnum];
3418 for ( j = 0; j < ss_wing->num_slots; j++ ) {
3419 // get the objnum of the ship in this slot
3420 objnum = Ships[wp->ship_index[j]].objnum;
3422 // get the slot pointer
3423 ss_slot = &ss_wing->ss_slots[j];
3425 if (ss_slot->sa_index == -1) {
3426 // lock all slots by default
3427 ss_slot->status |= WING_SLOT_LOCKED;
3429 // if this is my slot, then unlock it
3430 if(!multi_ts_disabled_slot((i*4)+j)){
3431 ss_slot->status &= ~WING_SLOT_LOCKED;