-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathmissionscreencommon.cpp
More file actions
1983 lines (1620 loc) · 57.8 KB
/
Copy pathmissionscreencommon.cpp
File metadata and controls
1983 lines (1620 loc) · 57.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 <climits> // this is need even when not building debug!!
#include <type_traits>
#include "anim/animplay.h"
#include "cutscene/cutscenes.h"
#include "cutscene/movie.h"
#include "gamehelp/contexthelp.h"
#include "gamesequence/gamesequence.h"
#include "gamesnd/eventmusic.h"
#include "gamesnd/gamesnd.h"
#include "globalincs/linklist.h"
#include "globalincs/vmallocator.h"
#include "graphics/2d.h"
#include "graphics/color.h"
#include "graphics/light.h"
#include "graphics/matrix.h"
#include "graphics/shadows.h"
#include "hud/hudwingmanstatus.h"
#include "io/key.h"
#include "io/mouse.h"
#include "io/timer.h"
#include "lighting/lighting.h"
#include "lighting/lighting_profiles.h"
#include "missionui/chatbox.h"
#include "missionui/missionbrief.h"
#include "missionui/missionscreencommon.h"
#include "missionui/missionshipchoice.h"
#include "missionui/missionweaponchoice.h"
#include "mod_table/mod_table.h"
#include "model/modelrender.h"
#include "network/multi.h"
#include "network/multi_endgame.h"
#include "network/multimsgs.h"
#include "network/multiteamselect.h"
#include "network/multiutil.h"
#include "parse/sexp.h"
#include "popup/popup.h"
#include "render/3d.h"
#include "render/batching.h"
#include "scripting/global_hooks.h"
#include "scripting/scripting.h"
#include "ship/ship.h"
#include "ui/uidefs.h"
#include "weapon/weapon.h"
//////////////////////////////////////////////////////////////////
// Game Globals
//////////////////////////////////////////////////////////////////
int Common_select_inited = 0;
// Dependent on when mouse button goes up
int Drop_icon_mflag, Drop_on_wing_mflag, Brief_mouse_up_flag;
int Mouse_down_last_frame = 0;
// Timers used to flash buttons after timeouts
#define MSC_FLASH_AFTER_TIME 60000 // time before flashing a button
#define MSC_FLASH_INTERVAL 200 // time between flashes
UI_TIMESTAMP Flash_timer; // timestamp used to start flashing
UI_TIMESTAMP Flash_toggle; // timestamp used to toggle flashing
int Flash_bright; // state of button to flash
//////////////////////////////////////////////////////////////////
// Global to modulde
//////////////////////////////////////////////////////////////////
int Current_screen;
int Next_screen;
static int InterfacePaletteBitmap = -1; // PCX file that holds the interface palette
color Icon_colors[NUM_ICON_FRAMES];
shader Icon_shaders[NUM_ICON_FRAMES];
loadout_data Player_loadout; // what the ship and weapon loadout is... used since we want to use the
// same loadout if the mission is played again
//wss_unit Wss_slots[MAX_WSS_SLOTS]; // slot data struct
//int Wl_pool[MAX_WEAPON_TYPES]; // weapon pool
//int Ss_pool[MAX_SHIP_CLASSES]; // ship pool
//int Wss_num_wings; // number of player wings
wss_unit Wss_slots_teams[MAX_TVT_TEAMS][MAX_WSS_SLOTS];
int Wl_pool_teams[MAX_TVT_TEAMS][MAX_WEAPON_TYPES];
int Ss_pool_teams[MAX_TVT_TEAMS][MAX_SHIP_CLASSES];
int Wss_num_wings_teams[MAX_TVT_TEAMS];
wss_unit *Wss_slots = NULL;
int *Wl_pool = NULL;
int *Ss_pool = NULL;
int Wss_num_wings;
//////////////////////////////////////////////////////////////////
// Externs
//////////////////////////////////////////////////////////////////
extern void ss_set_team_pointers(int team);
extern void ss_reset_team_pointers();
extern void wl_set_team_pointers(int team);
extern void wl_reset_team_pointers();
extern void ss_reset_selected_ship();
//////////////////////////////////////////////////////////////////
// UI
//////////////////////////////////////////////////////////////////
UI_WINDOW *Active_ui_window;
brief_common_buttons Common_buttons[3][GR_NUM_RESOLUTIONS][NUM_COMMON_BUTTONS] = {
{ // UGH
{ // GR_640
brief_common_buttons("CB_00", 7, 3, 37, 7, 0),
brief_common_buttons("CB_01", 7, 19, 37, 23, 1),
brief_common_buttons("CB_02", 7, 35, 37, 39, 2),
brief_common_buttons("CB_05", 571, 425, 572, 413, 5),
brief_common_buttons("CB_06", 533, 425, 500, 440, 6),
brief_common_buttons("CB_07", 533, 455, 479, 464, 7),
},
{ // GR_1024
brief_common_buttons("2_CB_00", 12, 5, 59, 12, 0),
brief_common_buttons("2_CB_01", 12, 31, 59, 37, 1),
brief_common_buttons("2_CB_02", 12, 56, 59, 62, 2),
brief_common_buttons("2_CB_05", 914, 681, 937, 671, 5),
brief_common_buttons("2_CB_06", 854, 681, 822, 704, 6),
brief_common_buttons("2_CB_07", 854, 724, 800, 743, 7),
}
},
{ // UGH
{ // GR_640
brief_common_buttons("CB_00", 7, 3, 37, 7, 0),
brief_common_buttons("CB_01", 7, 19, 37, 23, 1),
brief_common_buttons("CB_02", 7, 35, 37, 39, 2),
brief_common_buttons("CB_05", 571, 425, 572, 413, 5),
brief_common_buttons("CB_06", 533, 425, 500, 440, 6),
brief_common_buttons("CB_07", 533, 455, 479, 464, 7),
},
{ // GR_1024
brief_common_buttons("2_CB_00", 12, 5, 59, 12, 0),
brief_common_buttons("2_CB_01", 12, 31, 59, 37, 1),
brief_common_buttons("2_CB_02", 12, 56, 59, 62, 2),
brief_common_buttons("2_CB_05", 914, 681, 937, 671, 5),
brief_common_buttons("2_CB_06", 854, 681, 822, 704, 6),
brief_common_buttons("2_CB_07", 854, 724, 800, 743, 7),
}
},
{ // UGH
{ // GR_640
brief_common_buttons("CB_00", 7, 3, 37, 7, 0),
brief_common_buttons("CB_01", 7, 19, 37, 23, 1),
brief_common_buttons("CB_02", 7, 35, 37, 39, 2),
brief_common_buttons("CB_05", 571, 425, 572, 413, 5),
brief_common_buttons("CB_06", 533, 425, 500, 440, 6),
brief_common_buttons("CB_07", 533, 455, 479, 464, 7),
},
{ // GR_1024
brief_common_buttons("2_CB_00", 12, 5, 59, 12, 0),
brief_common_buttons("2_CB_01", 12, 31, 59, 37, 1),
brief_common_buttons("2_CB_02", 12, 56, 59, 62, 2),
brief_common_buttons("2_CB_05", 914, 681, 937, 671, 5),
brief_common_buttons("2_CB_06", 854, 681, 822, 704, 6),
brief_common_buttons("2_CB_07", 854, 724, 800, 743, 7),
}
}
};
#define COMMON_BRIEFING_BUTTON 0
#define COMMON_SS_BUTTON 1
#define COMMON_WEAPON_BUTTON 2
#define COMMON_COMMIT_BUTTON 3
#define COMMON_HELP_BUTTON 4
#define COMMON_OPTIONS_BUTTON 5
int Background_playing; // Flag to indicate background animation is playing
static anim *Background_anim; // Ids for the anim data that is loaded
// value for which Team_data entry to use
int Common_team;
// Ids for the instance of the anim that is playing
//static anim_instance *Background_anim_instance;
int Wing_slot_empty_bitmap;
int Wing_slot_disabled_bitmap;
// prototypes
int wss_slots_all_empty();
// Display the no ships selected error
void common_show_no_ship_error()
{
popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR( "At least one ship must be selected before proceeding to weapons loadout", 460));
}
// Check the status of the buttons common to the loadout screens
void common_check_buttons()
{
int i;
UI_BUTTON *b;
for ( i = 0; i < NUM_COMMON_BUTTONS; i++ ) {
b = &Common_buttons[Current_screen-1][gr_screen.res][i].button;
if ( b->pressed() ) {
common_button_do(i);
}
}
/*
// AL 11-23-97: let a joystick button press commit
if ( joy_down_count(0) || joy_down_count(1) ) {
Commit_pressed = 1;
}
*/
}
// -------------------------------------------------------------------
// common_redraw_pressed_buttons()
//
// Redraw any common 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 common_redraw_pressed_buttons()
{
int i;
UI_BUTTON *b;
for ( i = 0; i < NUM_COMMON_BUTTONS; i++ ) {
b = &Common_buttons[Current_screen-1][gr_screen.res][i].button;
if ( b->button_down() ) {
b->draw_forced(2);
}
}
}
void common_buttons_maybe_reload(UI_WINDOW * /*ui_window*/)
{
UI_BUTTON *b;
int i;
for ( i = 0; i < NUM_COMMON_BUTTONS; i++ ) {
b = &Common_buttons[Current_screen-1][gr_screen.res][i].button;
b->set_bmaps(Common_buttons[Current_screen-1][gr_screen.res][i].filename);
}
}
void common_buttons_init(UI_WINDOW *ui_window)
{
UI_BUTTON *b;
int i;
for ( i = 0; i < NUM_COMMON_BUTTONS; i++ ) {
b = &Common_buttons[Current_screen-1][gr_screen.res][i].button;
b->create( ui_window, "", Common_buttons[Current_screen-1][gr_screen.res][i].x, Common_buttons[Current_screen-1][gr_screen.res][i].y, 60, 30, 0, 1);
// set up callback for when a mouse first goes over a button
b->set_highlight_action( common_play_highlight_sound );
b->set_bmaps(Common_buttons[Current_screen-1][gr_screen.res][i].filename);
b->link_hotspot(Common_buttons[Current_screen-1][gr_screen.res][i].hotspot);
}
// add some text
ui_window->add_XSTR("Briefing", 1504, Common_buttons[Current_screen-1][gr_screen.res][COMMON_BRIEFING_BUTTON].xt, Common_buttons[Current_screen-1][gr_screen.res][COMMON_BRIEFING_BUTTON].yt, &Common_buttons[Current_screen-1][gr_screen.res][COMMON_BRIEFING_BUTTON].button, UI_XSTR_COLOR_GREEN);
ui_window->add_XSTR("Ship Selection", 1067, Common_buttons[Current_screen-1][gr_screen.res][COMMON_SS_BUTTON].xt, Common_buttons[Current_screen-1][gr_screen.res][COMMON_SS_BUTTON].yt, &Common_buttons[Current_screen-1][gr_screen.res][COMMON_SS_BUTTON].button, UI_XSTR_COLOR_GREEN);
ui_window->add_XSTR("Weapon Loadout", 1068, Common_buttons[Current_screen-1][gr_screen.res][COMMON_WEAPON_BUTTON].xt, Common_buttons[Current_screen-1][gr_screen.res][COMMON_WEAPON_BUTTON].yt, &Common_buttons[Current_screen-1][gr_screen.res][COMMON_WEAPON_BUTTON].button, UI_XSTR_COLOR_GREEN);
ui_window->add_XSTR("Commit", 1062, Common_buttons[Current_screen-1][gr_screen.res][COMMON_COMMIT_BUTTON].xt, Common_buttons[Current_screen-1][gr_screen.res][COMMON_COMMIT_BUTTON].yt, &Common_buttons[Current_screen-1][gr_screen.res][COMMON_COMMIT_BUTTON].button, UI_XSTR_COLOR_PINK);
ui_window->add_XSTR("Help", 928, Common_buttons[Current_screen-1][gr_screen.res][COMMON_HELP_BUTTON].xt, Common_buttons[Current_screen-1][gr_screen.res][COMMON_HELP_BUTTON].yt, &Common_buttons[Current_screen-1][gr_screen.res][COMMON_HELP_BUTTON].button, UI_XSTR_COLOR_GREEN);
ui_window->add_XSTR("Options", 1036, Common_buttons[Current_screen-1][gr_screen.res][COMMON_OPTIONS_BUTTON].xt, Common_buttons[Current_screen-1][gr_screen.res][COMMON_OPTIONS_BUTTON].yt, &Common_buttons[Current_screen-1][gr_screen.res][COMMON_OPTIONS_BUTTON].button, UI_XSTR_COLOR_GREEN);
common_reset_buttons();
Common_buttons[Current_screen-1][gr_screen.res][COMMON_COMMIT_BUTTON].button.set_hotkey(KEY_CTRLED+KEY_ENTER);
Common_buttons[Current_screen-1][gr_screen.res][COMMON_HELP_BUTTON].button.set_hotkey(KEY_F1);
Common_buttons[Current_screen-1][gr_screen.res][COMMON_OPTIONS_BUTTON].button.set_hotkey(KEY_F2);
// for scramble or training missions, disable the ship/weapon selection regions
if ( brief_only_allow_briefing() ) {
Common_buttons[Current_screen-1][gr_screen.res][COMMON_SS_REGION].button.disable();
Common_buttons[Current_screen-1][gr_screen.res][COMMON_WEAPON_REGION].button.disable();
if (Show_locked_status_scramble_missions) {
ui_window->add_XSTR("Ships/Weapons Are Locked For This Mission", 1882, Common_buttons[Current_screen-1][gr_screen.res][COMMON_WEAPON_BUTTON].xt, Common_buttons[Current_screen-1][gr_screen.res][COMMON_WEAPON_BUTTON].yt + 30, &Common_buttons[Current_screen-1][gr_screen.res][COMMON_WEAPON_BUTTON].button, UI_XSTR_COLOR_GREEN);
}
}
}
// Try to load background bitmaps as appropriate
int mission_ui_background_load(const char *custom_background, const char *single_background, const char *multi_background)
{
int background_bitmap = -1;
if (custom_background && (*custom_background != '\0'))
{
background_bitmap = bm_load(custom_background);
if (background_bitmap < 0)
mprintf(("Failed to load custom background bitmap %s!\n", custom_background));
}
// if special background failed to load, or if no special background was supplied, load the standard bitmap
if (background_bitmap < 0)
{
if (multi_background && (Game_mode & GM_MULTIPLAYER))
background_bitmap = bm_load(multi_background);
else
background_bitmap = bm_load(single_background);
}
// return what we've got
return background_bitmap;
}
void set_active_ui(UI_WINDOW *ui_window)
{
Active_ui_window = ui_window;
}
const char *common_music_get_filename(int score_index)
{
if (Cmdline_freespace_no_music) {
return "";
}
Assertion(score_index >= 0 && score_index < NUM_SCORES, "Invalid score index %d.", score_index);
if (Mission_music[score_index] < 0) {
if (!Spooled_music.empty()) {
Mission_music[score_index] = 0;
nprintf(("Sound",
"No briefing music is selected, so play first briefing track: %s\n",
Spooled_music[Mission_music[score_index]].name));
} else {
return "";
}
}
return Spooled_music[Mission_music[score_index]].filename;
}
void common_music_init(int score_index)
{
const auto file_name = common_music_get_filename(score_index);
if (file_name[0] == '\0') {
return;
}
briefing_load_music(file_name);
// Use this id to trigger the start of music playing on the briefing screen
Briefing_music_begin_timestamp = ui_timestamp(BRIEFING_MUSIC_DELAY);
}
void common_music_do()
{
if ( Cmdline_freespace_no_music ) {
return;
}
// Use this id to trigger the start of music playing on the briefing screen
if ( ui_timestamp_elapsed(Briefing_music_begin_timestamp) ) {
Briefing_music_begin_timestamp = UI_TIMESTAMP::invalid();
briefing_start_music();
}
}
void common_music_close()
{
if ( Cmdline_freespace_no_music ) {
return;
}
if ( Spooled_music.empty() )
return;
briefing_stop_music(true);
}
int common_num_cutscenes_valid(int movie_type)
{
int num_valid_cutscenes = 0;
for (uint i = 0; i < The_mission.cutscenes.size(); i++) {
if (movie_type == The_mission.cutscenes[i].type) {
if (!eval_sexp( The_mission.cutscenes[i].formula )) {
continue;
}
num_valid_cutscenes++;
}
}
return num_valid_cutscenes;
}
void common_maybe_play_cutscene(int movie_type, bool restart_music, int music)
{
bool music_off = false;
for (uint i = 0; i < The_mission.cutscenes.size(); i++) {
if (movie_type == The_mission.cutscenes[i].type) {
if (!eval_sexp( The_mission.cutscenes[i].formula )) {
continue;
}
if ( strlen(The_mission.cutscenes[i].filename) ) {
common_music_close();
music_off = true;
movie::play(The_mission.cutscenes[i].filename); //Play the movie!
}
}
}
if (music_off && restart_music) {
common_music_init(music);
}
}
void common_play_cutscene(const char* filename, bool restart_music, int music)
{
bool music_off = false;
common_music_close();
music_off = true;
movie::play(filename); // Play the movie!
if (music_off && restart_music) {
common_music_init(music);
}
};
// function that sets the current palette to the interface palette. This function
// needs to be followed by common_free_interface_palette() to restore the game palette.
void common_set_interface_palette(const char *filename)
{
static char buf[MAX_FILENAME_LEN + 1] = {0};
if (!filename)
filename = NOX("palette01");
Assert(strlen(filename) <= MAX_FILENAME_LEN);
if ( (InterfacePaletteBitmap != -1) && !stricmp(filename, buf) )
return; // already set to this palette
strcpy_s(buf, filename);
// unload the interface bitmap from memory
if (InterfacePaletteBitmap != -1) {
bm_release(InterfacePaletteBitmap);
InterfacePaletteBitmap = -1;
}
// ugh - we don't need this anymore
/*
InterfacePaletteBitmap = bm_load(filename);
if (InterfacePaletteBitmap < 0) {
Error(LOCATION, "Could not load in \"%s\"!", filename);
}
*/
}
// release the interface palette .pcx file, and restore the game palette
void common_free_interface_palette()
{
// unload the interface bitmap from memory
if (InterfacePaletteBitmap != -1) {
bm_release(InterfacePaletteBitmap);
InterfacePaletteBitmap = -1;
}
}
// Init timers used for flashing buttons
void common_flash_button_init()
{
Flash_timer = ui_timestamp(MSC_FLASH_AFTER_TIME);
Flash_toggle = UI_TIMESTAMP::immediate();
Flash_bright = 0;
}
// determine if we should draw a button as bright
int common_flash_bright()
{
if ( ui_timestamp_elapsed(Flash_timer) ) {
if ( ui_timestamp_elapsed(Flash_toggle) ) {
Flash_toggle = ui_timestamp(MSC_FLASH_INTERVAL);
Flash_bright ^= 1;
}
}
return Flash_bright;
}
// set the necessary pointers
void common_set_team_pointers(int team)
{
Assert( (team >= 0) && (team < MAX_TVT_TEAMS) );
Wss_slots = Wss_slots_teams[team];
Ss_pool = Ss_pool_teams[team];
Wl_pool = Wl_pool_teams[team];
ss_set_team_pointers(team);
wl_set_team_pointers(team);
}
// reset the necessary pointers to defaults
void common_reset_team_pointers()
{
ss_reset_team_pointers();
wl_reset_team_pointers();
// these are done last so that we can make use of the Assert()'s in the above
// functions to make sure the screens are exited and this is safe
Wss_slots = NULL;
Ss_pool = NULL;
Wl_pool = NULL;
}
// common_select_init() will load in animations and bitmaps that are common to the
// briefing/ship select/weapon select screens. The global Common_select_inited is set
// after this function is called once, and is only cleared when common_select_close()
// is called. This prevents multiple loadings of animations/bitmaps.
//
// This function also sets the palette based on the file palette01.pcx
void common_select_init(bool API_Access)
{
if ( Common_select_inited ) {
nprintf(("Alan","common_select_init() returning without doing anything\n"));
return;
}
nprintf(("Alan","entering common_select_init()\n"));
// No anims are playing
Background_playing = 0;
Background_anim = NULL;
Current_screen = Next_screen = ON_BRIEFING_SELECT;
// load in the icons for the wing slots
load_wing_icons(NOX("iconwing01"));
Current_screen = Next_screen = ON_BRIEFING_SELECT;
Commit_pressed = 0;
Common_select_inited = 1;
// this handles the case where the player played a multiplayer game but now is in single player (in one instance
// of FreeSpace)
if(!(Game_mode & GM_MULTIPLAYER)){
chatbox_close();
}
// get the value of the team
Common_team = 0; // assume the first team -- we'll change this value if we need to
if ( (Game_mode & GM_MULTIPLAYER) && IS_MISSION_MULTI_TEAMS )
Common_team = Net_player->p_info.team;
common_set_team_pointers(Common_team);
ship_select_common_init(API_Access);
weapon_select_common_init(API_Access);
if (!API_Access) {
common_flash_button_init();
}
if ( Game_mode & GM_MULTIPLAYER ) {
multi_ts_common_init();
}
// restore loadout from Player_loadout if this is the same mission as the one previously played
if ( !(Game_mode & GM_MULTIPLAYER) ) {
if ( !stricmp(Player_loadout.filename, Game_current_mission_filename) ) {
wss_maybe_restore_loadout();
ss_synch_interface();
wl_synch_interface();
}
}
if (!API_Access) {
ss_reset_selected_ship();
Drop_icon_mflag = 0;
Drop_on_wing_mflag = 0;
}
// init colors
gr_init_alphacolor(&Icon_colors[ICON_FRAME_NORMAL], 32, 128, 128, 255);
gr_init_alphacolor(&Icon_colors[ICON_FRAME_HOT], 48, 160, 160, 255);
gr_init_alphacolor(&Icon_colors[ICON_FRAME_SELECTED], 64, 192, 192, 255);
gr_init_alphacolor(&Icon_colors[ICON_FRAME_PLAYER], 192, 128, 64, 255);
gr_init_alphacolor(&Icon_colors[ICON_FRAME_DISABLED], 175, 175, 175, 255);
gr_init_alphacolor(&Icon_colors[ICON_FRAME_DISABLED_HIGH], 100, 100, 100, 255);
// init shaders
gr_create_shader(&Icon_shaders[ICON_FRAME_NORMAL], 32, 128, 128, 255);
gr_create_shader(&Icon_shaders[ICON_FRAME_HOT], 48, 160, 160, 255);
gr_create_shader(&Icon_shaders[ICON_FRAME_SELECTED], 64, 192, 192, 255);
gr_create_shader(&Icon_shaders[ICON_FRAME_PLAYER], 192, 128, 64, 255);
gr_create_shader(&Icon_shaders[ICON_FRAME_DISABLED], 175, 175, 175, 255);
gr_create_shader(&Icon_shaders[ICON_FRAME_DISABLED_HIGH], 100, 100, 100, 255);
}
void common_reset_buttons()
{
int i;
UI_BUTTON *b;
for ( i = 0; i < NUM_COMMON_BUTTONS; i++ ) {
b = &Common_buttons[Current_screen-1][gr_screen.res][i].button;
b->reset_status();
}
switch(Current_screen) {
case ON_BRIEFING_SELECT:
Common_buttons[Current_screen-1][gr_screen.res][COMMON_BRIEFING_REGION].button.skip_first_highlight_callback();
break;
case ON_SHIP_SELECT:
Common_buttons[Current_screen-1][gr_screen.res][COMMON_SS_REGION].button.skip_first_highlight_callback();
break;
case ON_WEAPON_SELECT:
Common_buttons[Current_screen-1][gr_screen.res][COMMON_WEAPON_REGION].button.skip_first_highlight_callback();
break;
}
}
// common_select_do() is called once per loop in the interface screens and is used
// for drawing and changing the common animations and blitting common bitmaps.
int common_select_do(float /*frametime*/)
{
int k, new_k;
if ( help_overlay_active(Briefing_overlay_id) || help_overlay_active(Ship_select_overlay_id) || help_overlay_active(Weapon_select_overlay_id) ) {
Common_buttons[0][gr_screen.res][COMMON_HELP_BUTTON].button.reset_status();
Common_buttons[1][gr_screen.res][COMMON_HELP_BUTTON].button.reset_status();
Common_buttons[2][gr_screen.res][COMMON_HELP_BUTTON].button.reset_status();
Active_ui_window->set_ignore_gadgets(1);
} else {
Active_ui_window->set_ignore_gadgets(0);
}
k = chatbox_process();
if ( Game_mode & GM_NORMAL ) {
new_k = Active_ui_window->process(k);
} else {
new_k = Active_ui_window->process(k, 0);
}
if ( (k > 0) || (new_k > 0) || B1_JUST_RELEASED ) {
if ( help_overlay_active(Briefing_overlay_id) || help_overlay_active(Ship_select_overlay_id) || help_overlay_active(Weapon_select_overlay_id) ) {
help_overlay_set_state(Briefing_overlay_id, gr_screen.res, 0);
help_overlay_set_state(Ship_select_overlay_id, gr_screen.res, 0);
help_overlay_set_state(Weapon_select_overlay_id, gr_screen.res, 0);
Active_ui_window->set_ignore_gadgets(0);
k = 0;
new_k = 0;
}
}
// test for mouse buttons, must be done after Active_ui_window->process()
// has been called to work properly
//
Drop_icon_mflag = 0;
Drop_on_wing_mflag = 0;
Brief_mouse_up_flag = 0;
Mouse_down_last_frame = 0;
// if the left mouse button was released...
if ( B1_RELEASED ) {
Drop_icon_mflag = 1;
Drop_on_wing_mflag = 1;
}
// if the left mouse button was pressed...
if ( B1_PRESSED ) {
Mouse_down_last_frame = 1;
}
// basically a "click", only check for the click here to avoid action-on-over on briefing map
if ( B1_JUST_PRESSED ) {
Brief_mouse_up_flag = 1;
}
// reset timers for flashing buttons if key pressed
if ( (k>0) || (new_k>0) ) {
common_flash_button_init();
}
common_music_do();
/*
if ( Background_playing ) {
if ( Background_anim_instance->frame_num == BUTTON_SLIDE_IN_FRAME ) {
gamesnd_play_iface(SND_BTN_SLIDE);
}
if ( Background_anim_instance->frame_num == Background_anim_instance->stop_at ) {
// Free up the big honking background animation, since we won't be playing it again
anim_release_render_instance(Background_anim_instance);
anim_free(Background_anim);
Background_playing = 0;
Current_screen = Next_screen = ON_BRIEFING_SELECT;
}
}
*/
if ( Current_screen != Next_screen ) {
switch( Next_screen ) {
case ON_BRIEFING_SELECT:
gameseq_post_event( GS_EVENT_START_BRIEFING );
break;
case ON_SHIP_SELECT:
// go to the specialized multiplayer team/ship select screen
if(Game_mode & GM_MULTIPLAYER){
gameseq_post_event(GS_EVENT_TEAM_SELECT);
}
// go to the normal ship select screen
else {
gameseq_post_event(GS_EVENT_SHIP_SELECTION);
}
break;
case ON_WEAPON_SELECT:
if ( !wss_slots_all_empty() ) {
gameseq_post_event(GS_EVENT_WEAPON_SELECTION);
} else {
common_show_no_ship_error();
}
break;
} // end switch
}
return new_k;
}
// -------------------------------------------------------------------------------------
// common_render()
//
void common_render(float frametime)
{
if ( !Background_playing ) {
GR_MAYBE_CLEAR_RES(Brief_background_bitmap);
gr_set_bitmap(Brief_background_bitmap);
gr_bitmap(0, 0, GR_RESIZE_MENU);
}
anim_render_all(0, frametime);
anim_render_all(ON_SHIP_SELECT, frametime);
}
// -------------------------------------------------------------------------------------
// common_render_selected_screen_button()
//
// A very ugly piece of special purpose code. This is used to draw the pressed button
// frame for whatever stage of the briefing/ship select/weapons loadout we are on.
//
void common_render_selected_screen_button()
{
Common_buttons[Next_screen-1][gr_screen.res][Next_screen-1].button.draw_forced(2);
}
// -------------------------------------------------------------------------------------
// common_button_do() do the button action for the specified pressed button
//
void common_button_do(int i)
{
if ( i == COMMON_COMMIT_BUTTON ) {
Commit_pressed = 1;
return;
}
if ( Background_playing )
return;
switch ( i ) {
case COMMON_BRIEFING_BUTTON:
if ( Current_screen != ON_BRIEFING_SELECT ) {
gamesnd_play_iface(InterfaceSounds::SCREEN_MODE_PRESSED);
Next_screen = ON_BRIEFING_SELECT;
}
break;
case COMMON_WEAPON_BUTTON:
if ( Current_screen != ON_WEAPON_SELECT ) {
if ( !wss_slots_all_empty() ) {
gamesnd_play_iface(InterfaceSounds::SCREEN_MODE_PRESSED);
Next_screen = ON_WEAPON_SELECT;
} else {
common_show_no_ship_error();
}
}
break;
case COMMON_SS_BUTTON:
if ( Current_screen != ON_SHIP_SELECT ) {
gamesnd_play_iface(InterfaceSounds::SCREEN_MODE_PRESSED);
Next_screen = ON_SHIP_SELECT;
}
break;
case COMMON_OPTIONS_BUTTON:
gamesnd_play_iface(InterfaceSounds::SWITCH_SCREENS);
gameseq_post_event( GS_EVENT_OPTIONS_MENU );
break;
case COMMON_HELP_BUTTON:
gamesnd_play_iface(InterfaceSounds::HELP_PRESSED);
launch_context_help();
break;
} // end switch
}
// common_check_keys() will check for keypresses common to all the interface screens.
void common_check_keys(int k)
{
switch (k) {
case KEY_ESC: {
if ( Current_screen == ON_BRIEFING_SELECT ) {
if ( brief_get_closeup_icon() != NULL ) {
brief_turn_off_closeup_icon();
break;
}
}
// prompt the host of a multiplayer game
if(Game_mode & GM_MULTIPLAYER){
multi_quit_game(PROMPT_ALL);
} else {
// go through the single player quit process
// return to the main menu
/*
int return_to_menu, pf_flags;
pf_flags = PF_USE_AFFIRMATIVE_ICON|PF_USE_NEGATIVE_ICON;
return_to_menu = popup(pf_flags, 2, POPUP_NO, POPUP_YES, XSTR( "Do you want to return to the Main Hall?\n(Your campaign position will be saved)", -1));
if ( return_to_menu == 1 ) {
gameseq_post_event(GS_EVENT_MAIN_MENU);
}
*/
gameseq_post_event(GS_EVENT_MAIN_MENU);
}
break;
}
case KEY_CTRLED + KEY_ENTER:
Commit_pressed = 1;
break;
case KEY_B:
if ( Current_screen != ON_BRIEFING_SELECT && !Background_playing ) {
Next_screen = ON_BRIEFING_SELECT;
}
break;
case KEY_W:
if ( brief_only_allow_briefing() ) {
gamesnd_play_iface(InterfaceSounds::GENERAL_FAIL);
break;
}
if ( Current_screen != ON_WEAPON_SELECT && !Background_playing ) {
if ( !wss_slots_all_empty() ) {
Next_screen = ON_WEAPON_SELECT;
} else {
common_show_no_ship_error();
}
}
break;
case KEY_S:
if ( brief_only_allow_briefing() ) {
gamesnd_play_iface(InterfaceSounds::GENERAL_FAIL);
break;
}
if ( Current_screen != ON_SHIP_SELECT && !Background_playing ) {
Next_screen = ON_SHIP_SELECT;
}
break;
case KEY_SHIFTED+KEY_TAB:
if ( brief_only_allow_briefing() ) {
gamesnd_play_iface(InterfaceSounds::GENERAL_FAIL);
break;
}
if ( !Background_playing ) {
switch ( Current_screen ) {
case ON_BRIEFING_SELECT:
if ( !wss_slots_all_empty() ) {
Next_screen = ON_WEAPON_SELECT;
} else {
common_show_no_ship_error();
}
break;
case ON_SHIP_SELECT:
Next_screen = ON_BRIEFING_SELECT;
break;
case ON_WEAPON_SELECT:
Next_screen = ON_SHIP_SELECT;
break;
default:
Int3();
break;
} // end switch
}
break;
case KEY_TAB:
if ( brief_only_allow_briefing() ) {
gamesnd_play_iface(InterfaceSounds::GENERAL_FAIL);
break;
}
if ( !Background_playing ) {
switch ( Current_screen ) {
case ON_BRIEFING_SELECT:
Next_screen = ON_SHIP_SELECT;
break;
case ON_SHIP_SELECT:
if ( !wss_slots_all_empty() ) {
Next_screen = ON_WEAPON_SELECT;
} else {
common_show_no_ship_error();
}
break;
case ON_WEAPON_SELECT:
Next_screen = ON_BRIEFING_SELECT;
break;
default:
Int3();
break;
} // end switch
}
break;
case KEY_P:
if ( Anim_paused )
Anim_paused = 0;
else
Anim_paused = 1;
break;
} // end switch
}
// common_select_close() will release the memory for animations and bitmaps that
// were loaded in common_select_init(). This function will abort if the Common_select_inited
// flag is not set. The last thing common_select_close() does in clear the Common_select_inited
// flag.
//
// weapon_select_close() and ship_select_close() are both called, since common_select_close()
// is the function that is called the interface screens are finally exited.
void common_select_close()
{
if ( !Common_select_inited ) {
nprintf(("Alan","common_select_close() returning without doing anything\n"));
return;
}
nprintf(("Alan","entering common_select_close()\n"));
// catch open anims that weapon_select_init_team() opened when not in weapon_select - taylor
// *** not the same as weapon_select_close() ***
weapon_select_close_team();
weapon_select_close();
if(Game_mode & GM_MULTIPLAYER){
multi_ts_close();
}
ship_select_close();
brief_close();
common_free_interface_palette();