-
Notifications
You must be signed in to change notification settings - Fork 180
Expand file tree
/
Copy pathmissionshipchoice.cpp
More file actions
3577 lines (2989 loc) · 99.8 KB
/
missionshipchoice.cpp
File metadata and controls
3577 lines (2989 loc) · 99.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) Volition, Inc. 1999. All rights reserved.
*
* All source code herein is the property of Volition, Inc. You may not sell
* or otherwise commercially exploit the source or things you created based on the
* source.
*
*/
#include "ai/aigoals.h"
#include "anim/animplay.h"
#include "anim/packunpack.h"
#include "cfile/cfile.h"
#include "freespace.h"
#include "gamehelp/contexthelp.h"
#include "gamesequence/gamesequence.h"
#include "gamesnd/gamesnd.h"
#include "globalincs/alphacolors.h"
#include "globalincs/linklist.h"
#include "hud/hudbrackets.h"
#include "hud/hudparse.h"
#include "hud/hudwingmanstatus.h"
#include "io/key.h"
#include "io/mouse.h"
#include "io/timer.h"
#include "lighting/lighting.h"
#include "localization/localize.h"
#include "menuui/snazzyui.h"
#include "mission/missionhotkey.h"
#include "mission/missionparse.h"
#include "missionui/missionbrief.h"
#include "missionui/missionscreencommon.h"
#include "missionui/missionshipchoice.h"
#include "missionui/missionweaponchoice.h"
#include "mod_table/mod_table.h"
#include "network/multi.h"
#include "network/multimsgs.h"
#include "network/multiteamselect.h"
#include "network/multiui.h"
#include "network/multiutil.h"
#include "parse/parselo.h"
#include "pilotfile/pilotfile.h"
#include "playerman/player.h"
#include "popup/popup.h"
#include "render/3d.h"
#include "ship/ship.h"
#include "sound/fsspeech.h"
#include "species_defs/species_defs.h"
#include "weapon/weapon.h"
//////////////////////////////////////////////////////
// Game-wide Globals
//////////////////////////////////////////////////////
char default_player_ship[255];
int Select_default_ship = 0;
int Ship_select_open = 0; // This game-wide global flag is set to 1 to indicate that the ship
// select screen has been opened and memory allocated. This flag
// is needed so we can know if ship_select_close() needs to called if
// restoring a game from the Options screen invoked from ship select
int Commit_pressed; // flag to indicate that the commit button was pressed
// use a flag, so the ship_create() can be done at the end of the loop
//////////////////////////////////////////////////////
// Module Globals
//////////////////////////////////////////////////////
static int Ship_anim_class = -1; // ship class that is playing as an animation
static int Ss_delta_x, Ss_delta_y; // used to offset the carried icon to make it smoothly leave static position
// UnknownPlayer //
float ShipSelectScreenShipRot = 0.0f;
int ShipSelectModelNum = -1;
int anim_timer_start = 0;
//static matrix ShipScreenOrient = IDENTITY_MATRIX;
//////////////////////////////////////////////////////
// UI Data structs
//////////////////////////////////////////////////////
typedef struct ss_icon_info
{
int icon_bmaps[NUM_ICON_FRAMES];
int current_icon_bitmap;
int model_index;
generic_anim ss_anim;
} ss_icon_info;
//ss_icon_info Ss_icons[MAX_SHIP_CLASSES]; // holds ui info on different ship icons
//ss_wing_info Ss_wings[MAX_WING_BLOCKS]; // holds ui info for wings and wing slots
ss_wing_info Ss_wings_teams[MAX_TVT_TEAMS][MAX_WING_BLOCKS];
ss_wing_info *Ss_wings = NULL;
ss_icon_info Ss_icons_teams[MAX_TVT_TEAMS][MAX_SHIP_CLASSES];
ss_icon_info *Ss_icons = NULL;
int Ss_mouse_down_on_region = -1;
int Selected_ss_class; // set to ship class of selected ship, -1 if none selected
int Hot_ss_icon; // index that icon is over in list (0..MAX_WING_SLOTS-1)
int Hot_ss_slot; // index for slot that mouse is over (0..MAX_WSS_SLOTS)
////////////////////////////////////////////////////////////
// Ship Select UI
////////////////////////////////////////////////////////////
UI_WINDOW Ship_select_ui_window;
int Ship_select_overlay_id = -1;
static int Ship_anim_coords[GR_NUM_RESOLUTIONS][2] = {
{
257, 84 // GR_640
},
{
412, 135 // GR_1024
}
};
static int Ship_info_coords[GR_NUM_RESOLUTIONS][2] = {
{
28, 78 // GR_640
},
{
45, 125 // GR_1024
}
};
// coordinate lookup indicies
#define SHIP_SELECT_X_COORD 0
#define SHIP_SELECT_Y_COORD 1
#define SHIP_SELECT_W_COORD 2
#define SHIP_SELECT_H_COORD 3
// NK: changed from 37 to 51 for new FS2 animations
#define SHIP_ANIM_LOOP_FRAME 51
#define MAX_ICONS_ON_SCREEN 4
// (x,y) pairs for ship icon and ship icon number
int Ship_list_coords[GR_NUM_RESOLUTIONS][MAX_ICONS_ON_SCREEN][4] = {
{
{23,331,4,341},
{23,361,4,371},
{23,391,4,401},
{23,421,4,431}
},
{
{29,530,10,540},
{29,578,10,588},
{29,626,10,636},
{29,674,10,684}
}
};
// Store the x locations for the icons in the wing formations
int Wing_icon_coords[GR_NUM_RESOLUTIONS][MAX_WSS_SLOTS][2] = {
{
{124,345},
{100,376},
{148,376},
{124,407},
{222,345},
{198,376},
{246,376},
{222,407},
{320,345},
{296,376},
{344,376},
{320,407}
},
{
{218,584},
{194,615},
{242,615},
{218,646},
{373,584},
{349,615},
{397,615},
{373,646},
{531,584},
{507,615},
{555,615},
{531,646}
}
};
//////////////////////////////////////////////////////
// Linked List of icons to show on ship selection list
//////////////////////////////////////////////////////
#define SS_ACTIVE_ITEM_USED (1<<0)
typedef struct ss_active_item
{
ss_active_item *prev, *next;
int ship_class;
int flags;
} ss_active_item;
static ss_active_item SS_active_head;
//static ss_active_item SS_active_items[MAX_WSS_SLOTS];//DTP commented out or else singleplayer will only have a max of MAX_WSS_SLOTS ships
static ss_active_item SS_active_items[MAX_SHIP_CLASSES];//DTP, now we have all ships in the TBL, as they can all be playerships
static int SS_active_list_start;
static int SS_active_list_size;
//////////////////////////////////////////////////////
// Background bitmaps data for ship_select
//////////////////////////////////////////////////////
static const char* Ship_select_background_fname[GR_NUM_RESOLUTIONS] = {
"ShipSelect",
"2_ShipSelect"
};
static const char* Ship_select_background_mask_fname[GR_NUM_RESOLUTIONS] = {
"ShipSelect-m",
"2_ShipSelect-m"
};
int Ship_select_background_bitmap;
//////////////////////////////////////////////////////
// Ship select specific buttons
//////////////////////////////////////////////////////
#define NUM_SS_BUTTONS 4
#define SS_BUTTON_SCROLL_UP 0
#define SS_BUTTON_SCROLL_DOWN 1
#define SS_BUTTON_RESET 2
#define SS_BUTTON_DUMMY 3 // needed to capture mouse for drag/drop icons
// convenient struct for handling all button controls
struct ss_buttons {
const char *filename;
int x, y, xt, yt;
int hotspot;
int scrollable;
UI_BUTTON button; // because we have a class inside this struct, we need the constructor below..
ss_buttons(const 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) {}
};
static ss_buttons Ship_select_buttons[GR_NUM_RESOLUTIONS][NUM_SS_BUTTONS] = {
{ // GR_640
ss_buttons("ssb_08", 5, 303, -1, -1, 8, 0), // SCROLL UP
ss_buttons("ssb_09", 5, 454, -1, -1, 9, 0), // SCROLL DOWN
ss_buttons("ssb_39", 571, 347, -1, -1, 39,0), // RESET
ss_buttons("ssb_39", 0, 0, -1, -1, 99,0) // dummy for drag n' drop
},
{ // GR_1024
ss_buttons("2_ssb_08", 8, 485, -1, -1, 8, 0), // SCROLL UP
ss_buttons("2_ssb_09", 8, 727, -1, -1, 9, 0), // SCROLL DOWN
ss_buttons("2_ssb_39", 913, 556, -1, -1, 39,0), // RESET
ss_buttons("2_ssb_39", 0, 0, -1, -1, 99,0) // dummy for drag n' drop
}
};
// ship select text
#define SHIP_SELECT_NUM_TEXT 1
UI_XSTR Ship_select_text[GR_NUM_RESOLUTIONS][SHIP_SELECT_NUM_TEXT] = {
{ // GR_640
{ "Reset", 1337, 580, 337, UI_XSTR_COLOR_GREEN, -1, &Ship_select_buttons[0][SS_BUTTON_RESET].button }
},
{ // GR_1024
{ "Reset", 1337, 938, 546, UI_XSTR_COLOR_GREEN, -1, &Ship_select_buttons[1][SS_BUTTON_RESET].button }
}
};
// Mask bitmap pointer and Mask bitmap_id
static bitmap* ShipSelectMaskPtr; // bitmap pointer to the ship select mask bitmap
static ubyte* ShipSelectMaskData; // pointer to actual bitmap data
static int Shipselect_mask_w, Shipselect_mask_h;
static int ShipSelectMaskBitmap; // bitmap id of the ship select mask bitmap
static MENU_REGION Region[NUM_SHIP_SELECT_REGIONS];
static int Num_mask_regions;
//stuff for ht&l. vars and such
extern fov_t View_zoom;
extern float Canv_h2, Canv_w2;
//////////////////////////////////////////////////////
// Drag and Drop variables
//////////////////////////////////////////////////////
typedef struct ss_carry_icon_info
{
int from_slot; // slot index (0..MAX_WSS_SLOTS-1), -1 if carried from list
int ship_class; // ship class of carried icon
int from_x, from_y;
} ss_carry_icon_info;
ss_carry_icon_info Carried_ss_icon;
////////////////////////////////////////////////////////////////////
// Internal function prototypes
////////////////////////////////////////////////////////////////////
// render functions
void draw_ship_icons();
void draw_ship_icon_with_number(int screen_offset, int ship_class);
void start_ship_animation(int ship_class, int play_sound=0);
// pick-up
int pick_from_ship_list(int screen_offset, int ship_class);
void pick_from_wing(int wb_num, int ws_num);
// ui related
void ship_select_button_do(int i);
void ship_select_common_init(bool API_Access);
void ss_reset_selected_ship();
void ss_restore_loadout();
void maybe_change_selected_wing_ship(int wb_num, int ws_num);
// init functions
void ss_init_pool(team_data *pteam);
commit_pressed_status create_wings();
// loading/unloading
void ss_unload_all_icons();
void ss_unload_all_anims();
void ss_init_units();
anim* ss_load_individual_animation(int ship_class);
// Carry icon functions
int ss_icon_being_carried();
void ss_reset_carried_icon();
void ss_set_carried_icon(int from_slot, int ship_class);
#define SHIP_DESC_X 445
#define SHIP_DESC_Y 273
const char *ss_tooltip_handler(const char *str)
{
if (Selected_ss_class < 0)
return NULL;
if (!stricmp(str, NOX("@ship_name"))) {
return Ship_info[Selected_ss_class].name;
} else if (!stricmp(str, NOX("@ship_type"))) {
return Ship_info[Selected_ss_class].type_str.get();
} else if (!stricmp(str, NOX("@ship_maneuverability"))) {
return Ship_info[Selected_ss_class].maneuverability_str.get();
} else if (!stricmp(str, NOX("@ship_armor"))) {
return Ship_info[Selected_ss_class].armor_str.get();
} else if (!stricmp(str, NOX("@ship_manufacturer"))) {
return Ship_info[Selected_ss_class].manufacturer_str.get();
} else if (!stricmp(str, NOX("@ship_desc"))) {
char *str2;
int x, y, w, h;
str2 = Ship_info[Selected_ss_class].desc.get();
if (str2 == NULL)
return NULL;
gr_get_string_size(&w, &h, str2);
x = SHIP_DESC_X - w / 2;
y = SHIP_DESC_Y - h / 2;
gr_set_color_fast(&Color_black);
gr_rect(x - 5, y - 5, w + 10, h + 10, GR_RESIZE_MENU);
gr_set_color_fast(&Color_bright_white);
gr_string(x, y, str2, GR_RESIZE_MENU);
return str2;
}
return NULL;
}
// Is an icon being carried?
int ss_icon_being_carried()
{
if ( Carried_ss_icon.ship_class >= 0 ) {
return 1;
}
return 0;
}
// Clear out carried icon info
void ss_reset_carried_icon()
{
Carried_ss_icon.from_slot = -1;
Carried_ss_icon.ship_class = -1;
}
// return !0 if carried icon has moved from where it was picked up
int ss_carried_icon_moved()
{
int mx, my;
mouse_get_pos_unscaled( &mx, &my );
if ( Carried_ss_icon.from_x != mx || Carried_ss_icon.from_y != my) {
return 1;
}
return 0;
}
// Set carried icon data
void ss_set_carried_icon(int from_slot, int ship_class)
{
Carried_ss_icon.from_slot = from_slot;
Carried_ss_icon.ship_class = ship_class;
// Set the mouse to captured
Ship_select_buttons[gr_screen.res][SS_BUTTON_DUMMY].button.capture_mouse();
}
// clear all active list items, and reset the flags inside the SS_active_items[] array
void clear_active_list()
{
int i;
for ( i = 0; i < ship_info_size(); i++ ) { //DTP singleplayer ship choice fix
//for ( i = 0; i < MAX_WSS_SLOTS; i++ ) {
SS_active_items[i].flags = 0;
SS_active_items[i].ship_class = -1;
}
list_init(&SS_active_head);
SS_active_list_start = 0;
SS_active_list_size = 0;
}
// get a free element from SS_active_items[]
ss_active_item *get_free_active_list_node()
{
int i;
for ( i = 0; i < ship_info_size(); i++ ) {
//for ( i = 0; i < MAX_WSS_SLOTS; i++ ) { //DTP, ONLY MAX_WSS_SLOTS SHIPS ???
if ( SS_active_items[i].flags == 0 ) {
SS_active_items[i].flags |= SS_ACTIVE_ITEM_USED;
return &SS_active_items[i];
}
}
return NULL;
}
// add a ship into the active list
void active_list_add(int ship_class)
{
ss_active_item *sai;
sai = get_free_active_list_node();
Assert(sai != NULL);
sai->ship_class = ship_class;
list_append(&SS_active_head, sai);
}
// remove a ship from the active list
void active_list_remove(int ship_class)
{
ss_active_item *sai, *temp;
// next store players not assigned to wings
sai = GET_FIRST(&SS_active_head);
while(sai != END_OF_LIST(&SS_active_head)){
temp = GET_NEXT(sai);
if ( sai->ship_class == ship_class ) {
list_remove(&SS_active_head, sai);
sai->flags = 0;
}
sai = temp;
}
}
// Build up the ship selection active list, which is a list of all ships that the player
// can choose from.
void init_active_list()
{
int i;
ss_active_item *sai;
Assert( Ss_pool != NULL );
clear_active_list();
// build the active list
for ( i = 0; i < ship_info_size(); i++ ) {
if ( Ss_pool[i] > 0 ) {
sai = get_free_active_list_node();
if ( sai != NULL ) {
sai->ship_class = i;
list_append(&SS_active_head, sai);
SS_active_list_size++;
}
}
}
}
void ship_select_check_buttons()
{
int i;
ss_buttons *b;
for ( i = 0; i < NUM_SS_BUTTONS; i++ ) {
b = &Ship_select_buttons[gr_screen.res][i];
if ( b->button.pressed() ) {
ship_select_button_do(b->hotspot);
}
}
}
// reset the ship selection to the mission defaults
void ss_reset_to_default()
{
if ( Game_mode & GM_MULTIPLAYER ) {
Int3();
return;
}
ss_init_pool(&Team_data[Common_team]);
ss_init_units();
init_active_list();
ss_reset_selected_ship();
ss_reset_carried_icon();
// reset weapons
wl_reset_to_defaults();
start_ship_animation(Selected_ss_class, 1);
}
// -------------------------------------------------------------------
// ship_select_redraw_pressed_buttons()
//
// Redraw any ship select buttons that are pressed down. This function is needed
// since we sometimes need to draw pressed buttons last to ensure the entire
// button gets drawn (and not overlapped by other buttons)
//
void ship_select_redraw_pressed_buttons()
{
int i;
ss_buttons *b;
common_redraw_pressed_buttons();
for ( i = 0; i < NUM_SS_BUTTONS; i++ ) {
b = &Ship_select_buttons[gr_screen.res][i];
if ( b->button.pressed() ) {
b->button.draw_forced(2);
}
}
}
void ship_select_buttons_init()
{
ss_buttons *b;
int i;
for ( i = 0; i < NUM_SS_BUTTONS; i++ ) {
b = &Ship_select_buttons[gr_screen.res][i];
b->button.create( &Ship_select_ui_window, "", b->x, b->y, 60, 30, b->scrollable);
// set up callback for when a mouse first goes over a button
b->button.set_highlight_action( common_play_highlight_sound );
b->button.set_bmaps(b->filename);
b->button.link_hotspot(b->hotspot);
}
// add all xstrs
for(i=0; i<SHIP_SELECT_NUM_TEXT; i++){
Ship_select_ui_window.add_XSTR(&Ship_select_text[gr_screen.res][i]);
}
// We don't want to have the reset button appear in multiplayer
if ( Game_mode & GM_MULTIPLAYER ) {
Ship_select_buttons[gr_screen.res][SS_BUTTON_RESET].button.disable();
Ship_select_buttons[gr_screen.res][SS_BUTTON_RESET].button.hide();
}
Ship_select_buttons[gr_screen.res][SS_BUTTON_DUMMY].button.disable();
Ship_select_buttons[gr_screen.res][SS_BUTTON_DUMMY].button.hide();
}
// -------------------------------------------------------------------------------------
// ship_select_button_do() do the button action for the specified pressed button
//
void ship_select_button_do(int i)
{
if ( Background_playing )
return;
switch ( i ) {
case SHIP_SELECT_SHIP_SCROLL_UP:
if ( Current_screen != ON_SHIP_SELECT )
break;
if ( common_scroll_down_pressed(&SS_active_list_start, SS_active_list_size, MAX_ICONS_ON_SCREEN) ) {
gamesnd_play_iface(InterfaceSounds::SCROLL);
} else {
gamesnd_play_iface(InterfaceSounds::GENERAL_FAIL);
}
break;
case SHIP_SELECT_SHIP_SCROLL_DOWN:
if ( Current_screen != ON_SHIP_SELECT )
break;
if ( common_scroll_up_pressed(&SS_active_list_start, SS_active_list_size, MAX_ICONS_ON_SCREEN) ) {
gamesnd_play_iface(InterfaceSounds::SCROLL);
} else {
gamesnd_play_iface(InterfaceSounds::GENERAL_FAIL);
}
break;
case SHIP_SELECT_RESET:
ss_reset_to_default();
break;
} // end switch
}
// ---------------------------------------------------------------------
// ship_select_init() is called once when the ship select screen begins
//
//
void ship_select_init()
{
// SS_active_items = new ss_active_item[Num_ship_classes];
common_set_interface_palette("ShipPalette");
common_flash_button_init();
// if in multiplayer -- set my state to be ship select
if ( Game_mode & GM_MULTIPLAYER ){
// also set the ship which is mine as the default
maybe_change_selected_wing_ship(Net_player->p_info.ship_index/MAX_WING_SLOTS,Net_player->p_info.ship_index%MAX_WING_SLOTS);
}
set_active_ui(&Ship_select_ui_window);
Current_screen = ON_SHIP_SELECT;
Ss_mouse_down_on_region = -1;
Ship_select_overlay_id = help_overlay_get_index(SS_OVERLAY);
help_overlay_set_state(Ship_select_overlay_id,gr_screen.res,0);
if ( Ship_select_open ) {
//reset the animation
Ship_anim_class = -1;
start_ship_animation( Selected_ss_class );
common_buttons_maybe_reload(&Ship_select_ui_window); // AL 11-21-97: this is necessary since we may returning from the hotkey
// screen, which can release common button bitmaps.
common_reset_buttons();
nprintf(("Alan","ship_select_init() returning without doing anything\n"));
return;
}
nprintf(("Alan","entering ship_select_init()\n"));
common_select_init();
ShipSelectMaskBitmap = bm_load(Ship_select_background_mask_fname[gr_screen.res]);
if (ShipSelectMaskBitmap < 0) {
if (gr_screen.res == GR_640) {
Error(LOCATION,"Could not load in 'shipselect-m'!");
} else if (gr_screen.res == GR_1024) {
Error(LOCATION,"Could not load in '2_shipselect-m'!");
}
}
Shipselect_mask_w = -1;
Shipselect_mask_h = -1;
// get a pointer to bitmap by using bm_lock()
ShipSelectMaskPtr = bm_lock(ShipSelectMaskBitmap, 8, BMP_AABITMAP | BMP_MASK_BITMAP);
ShipSelectMaskData = (ubyte*)ShipSelectMaskPtr->data;
bm_get_info(ShipSelectMaskBitmap, &Shipselect_mask_w, &Shipselect_mask_h);
// Set up the mask regions
// initialize the different regions of the menu that will react when the mouse moves over it
Num_mask_regions = 0;
snazzy_menu_add_region(&Region[Num_mask_regions++], "", COMMON_BRIEFING_REGION, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", COMMON_SS_REGION, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", COMMON_WEAPON_REGION, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", COMMON_COMMIT_REGION, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", COMMON_HELP_REGION, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", COMMON_OPTIONS_REGION, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", SHIP_SELECT_SHIP_SCROLL_UP, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", SHIP_SELECT_SHIP_SCROLL_DOWN, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", SHIP_SELECT_ICON_0, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", SHIP_SELECT_ICON_1, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", SHIP_SELECT_ICON_2, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", SHIP_SELECT_ICON_3, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_0_SHIP_0, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_0_SHIP_1, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_0_SHIP_2, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_0_SHIP_3, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_1_SHIP_0, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_1_SHIP_1, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_1_SHIP_2, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_1_SHIP_3, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_2_SHIP_0, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_2_SHIP_1, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_2_SHIP_2, 0);
snazzy_menu_add_region(&Region[Num_mask_regions++], "", WING_2_SHIP_3, 0);
Ship_select_open = 1; // This game-wide global flag is set to 1 to indicate that the ship
// select screen has been opened and memory allocated. This flag
// is needed so we can know if ship_select_close() needs to called if
// restoring a game from the Options screen invoked from ship select
// init ship selection masks and buttons
Ship_select_ui_window.create( 0, 0, gr_screen.max_w_unscaled, gr_screen.max_h_unscaled, 0 );
Ship_select_ui_window.set_mask_bmap(Ship_select_background_mask_fname[gr_screen.res]);
Ship_select_ui_window.tooltip_handler = ss_tooltip_handler;
common_buttons_init(&Ship_select_ui_window);
ship_select_buttons_init();
// init ship selection background bitmap
Ship_select_background_bitmap = mission_ui_background_load(Briefing->ship_select_background[gr_screen.res], Ship_select_background_fname[gr_screen.res]);
// init ship selection ship model rendering window
start_ship_animation( Selected_ss_class );
}
// Return the ship class for the icon specified by index. Need to iterate through the active
// list of icons to find out what ship class for this icon
//
// input: index => list index (0..3)
// exit: ship class, -1 if none
//
int ss_get_ship_class_from_list(int index)
{
ss_active_item *sai;
int list_entry, i, count;
i = 0;
count = 0;
list_entry = -1;
for ( sai = GET_FIRST(&SS_active_head); sai != END_OF_LIST(&SS_active_head); sai = GET_NEXT(sai) ) {
count++;
if ( count <= SS_active_list_start )
continue;
if ( i >= MAX_ICONS_ON_SCREEN )
break;
if ( i == index ) {
list_entry = sai->ship_class;
break;
}
i++;
}
return list_entry;
}
// ---------------------------------------------------------------------
// maybe_pick_up_list_icon()
//
void maybe_pick_up_list_icon(int offset)
{
int ship_class;
ship_class = ss_get_ship_class_from_list(offset);
if ( ship_class != -1 ) {
pick_from_ship_list(offset, ship_class);
}
}
// ---------------------------------------------------------------------
// maybe_change_selected_ship()
//
void maybe_change_selected_ship(int offset)
{
int ship_class;
ship_class = ss_get_ship_class_from_list(offset);
if ( ship_class == -1 )
return;
if ( Ss_mouse_down_on_region != (SHIP_SELECT_ICON_0+offset) ) {
return;
}
if ( Selected_ss_class == -1 ) {
Selected_ss_class = ship_class;
start_ship_animation(Selected_ss_class, 1);
}
else if ( Selected_ss_class != ship_class ) {
Selected_ss_class = ship_class;
start_ship_animation(Selected_ss_class, 1);
}
else
Assert( Selected_ss_class == ship_class );
}
void maybe_change_selected_wing_ship(int wb_num, int ws_num)
{
Assert(wb_num >= 0 && wb_num < MAX_WING_BLOCKS);
Assert(ws_num >= 0 && ws_num < MAX_WING_SLOTS);
Assert( (Ss_wings != NULL) && (Wss_slots != NULL) );
if ( Ss_wings[wb_num].wingnum < 0 ) {
return;
}
if ( Selected_ss_class != -1 && Selected_ss_class != Wss_slots[wb_num*MAX_WING_SLOTS+ws_num].ship_class ) {
Selected_ss_class = Wss_slots[wb_num*MAX_WING_SLOTS+ws_num].ship_class;
start_ship_animation(Selected_ss_class, 1);
}
}
// ---------------------------------------------------------------------
// do_mouse_over_wing_slot()
//
// returns: 0 => icon wasn't dropped onto slot
// 1 => icon was dropped onto slot
int do_mouse_over_wing_slot(int block, int slot)
{
Hot_ss_slot = block*MAX_WING_SLOTS + slot;
if ( !mouse_down(MOUSE_LEFT_BUTTON) ) {
if ( ss_icon_being_carried() ) {
if ( ss_disabled_slot(block*MAX_WING_SLOTS+slot) ) {
gamesnd_play_iface(InterfaceSounds::ICON_DROP);
return 0;
}
if ( !ss_carried_icon_moved() ) {
ss_reset_carried_icon();
return 0;
}
ss_drop(Carried_ss_icon.from_slot, Carried_ss_icon.ship_class, Hot_ss_slot, -1);
ss_reset_carried_icon();
}
}
else {
if ( Ss_mouse_down_on_region == (WING_0_SHIP_0+block*MAX_WING_SLOTS+slot) ) {
pick_from_wing(block, slot);
}
}
return 1;
}
void do_mouse_over_list_slot(int index)
{
Hot_ss_icon = index;
if ( Ss_mouse_down_on_region != (SHIP_SELECT_ICON_0+index) ){
return;
}
if ( mouse_down(MOUSE_LEFT_BUTTON) )
maybe_pick_up_list_icon(index);
}
// Icon has been dropped, but not onto a wing slot
void ss_maybe_drop_icon()
{
if ( Drop_icon_mflag ) {
if ( ss_icon_being_carried() ) {
// Add back into the ship entry list
if ( Carried_ss_icon.from_slot >= 0 ) {
// return to list
ss_drop(Carried_ss_icon.from_slot, -1, -1, Carried_ss_icon.ship_class);
} else {
if ( ss_carried_icon_moved() ) {
gamesnd_play_iface(InterfaceSounds::ICON_DROP);
}
}
ss_reset_carried_icon();
}
}
}
// maybe flash a button if player hasn't done anything for a while
void ss_maybe_flash_button()
{
if ( common_flash_bright() ) {
// weapon loadout button
if ( Common_buttons[Current_screen-1][gr_screen.res][2].button.button_hilighted() ) {
common_flash_button_init();
} else {
Common_buttons[Current_screen-1][gr_screen.res][2].button.draw_forced(1);
}
}
}
// blit any active ship information text
void ship_select_blit_ship_info()
{
int y_start, line_height;
ship_info *sip;
char str[100];
color *header_clr = &Color_white;
color *text = &Color_green;
// if we don't have a valid ship selected, do nothing
if(Selected_ss_class == -1){
return;
}
// get the ship class
sip = &Ship_info[Selected_ss_class];
// starting line
y_start = Ship_info_coords[gr_screen.res][SHIP_SELECT_Y_COORD];
line_height = gr_get_font_height() + 1;
memset(str,0,100);
// blit the ship class (name)
gr_set_color_fast(header_clr);
gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD], y_start, XSTR("Class",739), GR_RESIZE_MENU);
y_start += line_height;
if(strlen(sip->get_display_name())){
gr_set_color_fast(text);
gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD]+4, y_start, sip->get_display_name(), GR_RESIZE_MENU);
}
y_start += line_height;
// blit the ship type
gr_set_color_fast(header_clr);
gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD], y_start, XSTR("Type",740), GR_RESIZE_MENU);
y_start += line_height;
gr_set_color_fast(text);
if(sip->type_str){
gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD]+4, y_start, sip->type_str.get(), GR_RESIZE_MENU);
}
else
{
gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD]+4, y_start, ship_get_type(sip), GR_RESIZE_MENU);
}
y_start+=line_height;
// blit the ship length
gr_set_color_fast(header_clr);
gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD], y_start, XSTR("Length",741), GR_RESIZE_MENU);
y_start += line_height;
gr_set_color_fast(text);
if(sip->ship_length){
if (Lcl_gr || Lcl_pl) {
// in german and polish, drop the s from Meters and make sure M is caps
char *sp = strstr(sip->ship_length.get(), "Meters");
if (sp) {
sp[5] = ' '; // make the old s a space now
}
}
gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD]+4, y_start, sip->ship_length.get(), GR_RESIZE_MENU);
}
else if(ShipSelectModelNum >= 0)
{
polymodel *pm = model_get(ShipSelectModelNum);
sprintf( str, "%d", fl2i(pm->maxs.xyz.z - pm->mins.xyz.z) );
strcat_s(str, " M");
gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD]+4, y_start, str, GR_RESIZE_MENU);
}
else
{
gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD]+4, y_start, XSTR("Unknown", 497), GR_RESIZE_MENU);
}
y_start += line_height;
// blit the max velocity
gr_set_color_fast(header_clr);
gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD], y_start, XSTR("Max Velocity",742), GR_RESIZE_MENU);
y_start += line_height;
sprintf(str, XSTR("%d m/s",743),fl2i((float)sip->max_vel.xyz.z * Hud_speed_multiplier));
gr_set_color_fast(text);
gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD]+4, y_start,str, GR_RESIZE_MENU);
y_start += line_height;
// blit the maneuverability
gr_set_color_fast(header_clr);
gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD], y_start, XSTR("Maneuverability",744), GR_RESIZE_MENU);
y_start += line_height;
gr_set_color_fast(text);
if(sip->maneuverability_str){
gr_string(Ship_info_coords[gr_screen.res][SHIP_SELECT_X_COORD]+4, y_start, sip->maneuverability_str.get(), GR_RESIZE_MENU);
}
else if(ShipSelectModelNum >= 0)
{
int sum = fl2i(sip->rotation_time.xyz.x + sip->rotation_time.xyz.y);
if(sum <= 6)