-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathreadyroom.cpp
More file actions
2029 lines (1657 loc) · 60.1 KB
/
readyroom.cpp
File metadata and controls
2029 lines (1657 loc) · 60.1 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 <cctype>
#include "cfile/cfile.h"
#include "freespace.h"
#include "gamehelp/contexthelp.h"
#include "gamesequence/gamesequence.h"
#include "gamesnd/gamesnd.h"
#include "globalincs/alphacolors.h"
#include "graphics/font.h"
#include "io/key.h"
#include "menuui/mainhallmenu.h"
#include "menuui/readyroom.h"
#include "menuui/techmenu.h" // for tech menu reset stuff
#include "mission/missionload.h"
#include "mission/missionparse.h"
#include "mission/missioncampaign.h"
#include "missionui/missionscreencommon.h"
#include "parse/parselo.h"
#include "pilotfile/pilotfile.h"
#include "playerman/managepilot.h"
#include "playerman/player.h"
#include "popup/popup.h"
#include "ui/ui.h"
#include "ui/uidefs.h"
#define MAX_MISSIONS 1024
int Mission_list_coords[GR_NUM_RESOLUTIONS][4] = {
{ // GR_640
33, 108, 402, 279
},
{ // GR_1024
43, 175, 402, 459
}
};
int Campaign_list_coords[GR_NUM_RESOLUTIONS][4] = {
{ // GR_640
491, 108, 115, 279
},
{ // GR_1024
491, 175, 115, 459
}
};
#define C_SUBTEXT_X 19
// x coordinate offsets for data when campaign tab active
#define C_TEXT_X 0
// x coordinate offsets for data when mission tab active
#define M_TEXT_X C_SUBTEXT_X //0
#define MODE_CAMPAIGNS 0
#define MODE_MISSIONS 1
#define MAX_LINES 200 // NOLINT(modernize-macro-to-enum)
#define NUM_BUTTONS 11
#define LIST_BUTTONS_MAX 42
#define SCROLL_UP_BUTTON 0
#define SCROLL_DOWN_BUTTON 1
#define MISSION_TAB 2
#define CAMPAIGN_TAB 3
#define HELP_BUTTON 4
#define COMMIT_BUTTON 5
#define OPTIONS_BUTTON 6
#define TECH_DATABASE_BUTTON 7
#define SIMULATOR_BUTTON 8
#define CUTSCENES_BUTTON 9
#define CREDITS_BUTTON 10
#define X_COORD 0
#define Y_COORD 1
#define W_COORD 2
#define H_COORD 3
#define CAMPAIGN_MISSION_HASH_SIZE 307
struct sim_room_buttons {
const char *filename;
int x, y, xt, yt;
int hotspot;
UI_BUTTON button; // because we have a class inside this struct, we need the constructor below..
sim_room_buttons(const char *name, int x1, int y1, int xt1, int yt1, int h) : filename(name), x(x1), y(y1), xt(xt1), yt(yt1), hotspot(h) {}
};
static sim_room_buttons Buttons[GR_NUM_RESOLUTIONS][NUM_BUTTONS] = {
//XSTR:OFF
{ // GR_640
sim_room_buttons("LMB_04", 1, 99, -1, -1, 4),
sim_room_buttons("LMB_05", 1, 381, -1, -1, 5),
sim_room_buttons("LMB_06", 6, 438, 40, 445, 6),
sim_room_buttons("LMB_07", 6, 457, 40, 462, 7),
sim_room_buttons("LMB_08", 534, 426, 500, 440, 8),
sim_room_buttons("LMB_09", 571, 426, 572, 413, 9),
sim_room_buttons("LMB_10", 534, 455, 480, 462, 10),
sim_room_buttons("TDB_00", 7, 3, 37, 7, 0),
sim_room_buttons("TDB_01", 7, 18, 37, 23, 1),
sim_room_buttons("TDB_02", 7, 34, 37, 38, 2),
sim_room_buttons("TDB_03", 7, 49, 37, 54, 3),
},
{ // GR_1024
sim_room_buttons("2_LMB_04", 2, 159, -1, -1, 4),
sim_room_buttons("2_LMB_05", 2, 609, -1, -1, 5),
sim_room_buttons("2_LMB_06", 10, 701, 64, 712, 6),
sim_room_buttons("2_LMB_07", 10, 732, 64, 739, 7),
sim_room_buttons("2_LMB_08", 854, 681, 800, 704, 8),
sim_room_buttons("2_LMB_09", 914, 681, 915, 660, 9),
sim_room_buttons("2_LMB_10", 854, 728, 780, 736, 10),
sim_room_buttons("2_TDB_00", 12, 5, 59, 12, 0),
sim_room_buttons("2_TDB_01", 12, 31, 59, 37, 1),
sim_room_buttons("2_TDB_02", 12, 56, 59, 62, 2),
sim_room_buttons("2_TDB_03", 12, 81, 59, 88, 3),
}
//XSTR:ON
};
SCP_vector<sim_mission> Sim_Missions;
SCP_vector<sim_mission> Sim_CMissions;
const char* Sim_filename[GR_NUM_RESOLUTIONS] = {
"LoadMission",
"2_LoadMission"
};
const char* Sim_mask_filename[GR_NUM_RESOLUTIONS] = {
"LoadMission-m",
"2_LoadMission-m"
};
const char* Campaign_filename[GR_NUM_RESOLUTIONS] = {
"Campaign",
"2_Campaign"
};
const char* Campaign_mask_filename[GR_NUM_RESOLUTIONS] = {
"Campaign-m",
"2_Campaign-m"
};
const char* Sim_room_slider_filename[GR_NUM_RESOLUTIONS] = {
"slider",
"2_slider"
};
// misc text. ("Mission" and "Filename"
#define NUM_SIM_MISC_TEXT 2
#define SIM_MISC_TEXT_MISSION 0
#define SIM_MISC_TEXT_FILENAME 1
int Sim_misc_text_coords[GR_NUM_RESOLUTIONS][NUM_SIM_MISC_TEXT][2] = {
{ // GR_640
{33, 95},
{491, 95}
},
{ // GR_1024
{43, 155},
{491, 155}
}
};
int Sim_room_slider_coords[GR_NUM_RESOLUTIONS][4] = {
{ // GR_640
4, 131, 20, 245
},
{ // GR_1024
5, 209, 32, 392
}
};
// readyroom text line stuff
#define READYROOM_LINE_CAMPAIGN 1
#define READYROOM_LINE_CMISSION 2
#define READYROOM_LINE_MISSION 3
#define READYROOM_FLAG_FROM_VOLITION (1<<0) // volition made
static struct {
int type; // see READYROOM_LINE_* defines above
const char *name;
const char *filename;
int x; // X coordinate of line
int y; // Y coordinate of line
int flags; // special flags, see READYROOM_FLAG_* defines above
} sim_room_lines[MAX_LINES];
static char Cur_campaign[MAX_FILENAME_LEN];
static char *Mission_filenames[MAX_MISSIONS] = { NULL };
static char *Standalone_mission_names[MAX_MISSIONS] = { NULL };
static int Standalone_mission_flags[MAX_MISSIONS];
static char *Campaign_missions[MAX_MISSIONS] = { NULL };
static char *Campaign_mission_names[MAX_CAMPAIGN_MISSIONS] = { NULL };
static int Campaign_mission_flags[MAX_MISSIONS];
static int Simroom_show_all = 0;
static int Standalone_mission_names_inited = 0;
static int Campaign_mission_names_inited = 0;
static int Num_standalone_missions;
static int Num_campaign_missions;
//static int Num_player_missions;
static int Scroll_offset;
static int Selected_line;
static int Num_lines;
static int Num_campaign_missions_with_info = 0;
static int Num_standalone_missions_with_info = 0;
static int list_x1;
static int list_x2;
static int list_y;
static int list_w1;
static int list_w2;
static int list_h;
static int Background_bitmap;
static int Campaign_background_bitmap_mask;
static UI_WINDOW Ui_window;
static UI_BUTTON List_buttons[LIST_BUTTONS_MAX]; // buttons for each line of text in list
int Sim_room_overlay_id;
int Campaign_room_overlay_id;
// globals
bool Campaign_room_no_campaigns = false;
// slider stuff
static UI_SLIDER2 Sim_room_slider;
typedef struct hash_node {
hash_node *next;
const char *filename;
} hash_node;
static hash_node *Campaign_mission_hash_table[CAMPAIGN_MISSION_HASH_SIZE];
static int Hash_table_inited;
// special icons (1.04 + stuff)
#define NUM_MISSION_ICONS 1
#define MISSION_ICON_VOLITION 0 // mini volition death's head :)
// icon offsets (see LIST_ defines above
//#define MISSION_ICON_VOLITION_X (46)
#define MISSION_ICON_VOLITION_Y_OFFSET (-1)
// icon offsets
static int Sim_volition_icon_x[GR_NUM_RESOLUTIONS] = {
38,
49
};
// special icons themselves
int Mission_icon_bitmaps[NUM_MISSION_ICONS];
//XSTR:OFF
const char *Mission_icon_bitmap_filenames[NUM_MISSION_ICONS] = {
"icon-volition"
};
//XSTR:ON
void sim_room_load_mission_icons();
void sim_room_unload_mission_icons();
void sim_room_blit_icons(int line_index, int y_start, fs_builtin_mission *fb = NULL, int is_md = 0);
const std::shared_ptr<scripting::Hook<>> OnCampaignBeginHook = scripting::Hook<>::Factory(
"On Campaign Begin", "Called when a campaign is started from the beginning or is reset",
{
{ "Campaign", "string", "The campaign filename (without the extension)" },
});
// Finds a hash value for mission filename
//
// returns hash value
int hash_filename(const char *filename) {
ulonglong hash_val = 0;
const char *ptr = filename;
// Don't hash .fsm extension, convert all to upper case
for (int i=0; i < ((signed int)(strlen(filename)) - 4); i++) {
hash_val = (hash_val << 4) + SCP_toupper(*ptr++);
}
return int(hash_val % CAMPAIGN_MISSION_HASH_SIZE);
}
// insert filename into Campaign_mission_hash_table
//
// returns 1 if successful, 0 if could not allocate memory
int hash_insert(const char *filename) {
int hash_val = hash_filename(filename);
hash_node *cur_node;
// Check if table empty
if (Campaign_mission_hash_table[hash_val] == NULL) {
Campaign_mission_hash_table[hash_val] = new hash_node;
cur_node = Campaign_mission_hash_table[hash_val];
if (cur_node == NULL) {
// Unable to allocate memory
return 0;
}
} else {
// Walk down list to first empty node
cur_node = Campaign_mission_hash_table[hash_val];
while (cur_node->next != NULL) {
cur_node = cur_node->next;
}
// Create new node
cur_node->next = new hash_node;
if (cur_node->next == NULL) {
// unable to allocate memory
return 0;
} else {
cur_node = cur_node->next;
}
}
// Initialize data
cur_node->next = NULL;
cur_node->filename = filename;
// Return successs
return 1;
}
// Checks if a filename already exitst in the hash table
//
// returns 1 if found (collision), 0 if no collision
int campaign_mission_hash_collision(const char *filename)
{
int hash_val = hash_filename(filename);
hash_node *cur_node = Campaign_mission_hash_table[hash_val];
if (cur_node == NULL) {
return 0;
}
do {
if (!stricmp(filename, cur_node->filename)) {
return 1;
}
cur_node = cur_node->next;
} while (cur_node != NULL);
// Ran out of stuff to check
return 0;
}
// builds hash table of campaign mission filenames
//
// returns 1 if successful, 0 if not successful
int build_campaign_mission_filename_hash_table()
{
int rval;
// Go through all campaign missions
for (int i=0; i<Num_campaign_missions; i++) {
rval = hash_insert(Campaign_missions[i]);
if (rval == 0) {
return 0;
}
}
// successful
return 1;
}
// deletes hash table nodes
//
void campaign_mission_hash_table_delete()
{
hash_node *cur_node;
for (int i=0; i<CAMPAIGN_MISSION_HASH_SIZE; i++) {
// Look for entries into array
if (Campaign_mission_hash_table[i] != NULL) {
cur_node = Campaign_mission_hash_table[i];
// Walk down the list deleting self
while (cur_node->next != NULL) {
hash_node *temp = cur_node->next;
delete cur_node;
cur_node = temp;
}
// Delete last node
delete cur_node;
Campaign_mission_hash_table[i] = NULL;
}
}
}
// add a line of sim_room smuck to end of list
int sim_room_line_add(int type, const char *name, const char *filename, int x, int y, int flags)
{
if (Num_lines >= MAX_LINES)
return 0;
sim_room_lines[Num_lines].type = type;
sim_room_lines[Num_lines].name = name;
sim_room_lines[Num_lines].filename = filename;
sim_room_lines[Num_lines].x = x;
sim_room_lines[Num_lines].y = y;
sim_room_lines[Num_lines].flags = flags;
return Num_lines++;
}
// build up a list of all missions in all campaigns.
int sim_room_campaign_mission_filter(const char *filename)
{
int num;
num = mission_campaign_get_mission_list(filename, &Campaign_missions[Num_campaign_missions], MAX_MISSIONS - Num_campaign_missions);
if (num < 0)
return 0;
Num_campaigns++;
Num_campaign_missions += num;
return 1;
}
// filter out all missions already used in existing campaigns
int sim_room_standalone_mission_filter(const char *filename)
{
int type;
char mission_name[255];
// Check if a campaign mission (single and multi)
if (campaign_mission_hash_collision(filename)) {
return 0;
}
// Check if a standalone multi mission OR Mdisk mission with data
type = mission_parse_is_multi(filename, mission_name);
if (type && !(type & MISSION_TYPE_SINGLE))
return 0;
return 1;
}
// builds up list of standalone missions and adds them to missions simulator
// processes one mission per frame
//
// returns 1 if finished with all missions, 0 otherwise
//
int build_standalone_mission_list_do_frame(bool API_Access)
{
int font_height = gr_get_font_height();
SCP_string popup_str;
bool lcl_weirdness = false;
// When no standalone missions in data directory
if (Num_standalone_missions == 0) {
Standalone_mission_names_inited = 1;
return 1;
}
// Set global variable so we we'll have list available next time
Standalone_mission_names[Num_standalone_missions_with_info] = NULL;
Standalone_mission_flags[Num_standalone_missions_with_info] = 0;
if (Num_standalone_missions > 0) { // sanity check
if (strlen(Mission_filenames[Num_standalone_missions_with_info]) < MAX_FILENAME_LEN - 4) { // sanity check?
// tack on an extension
auto filename = cf_add_ext(Mission_filenames[Num_standalone_missions_with_info], FS_MISSION_FILE_EXT);
// update popup
sprintf(popup_str, XSTR("Single Mission\n\n%s", 989), filename);
popup_change_text(popup_str.c_str());
// activate tstrings check
Lcl_unexpected_tstring_check = &lcl_weirdness;
// check if we can list the mission, if loading basic info didn't return an error code, and if we didn't find an XSTR mismatch
bool condition = !mission_is_ignored(filename) && !get_mission_info(filename) && !lcl_weirdness;
// maybe log
if (lcl_weirdness)
mprintf(("Skipping %s due to XSTR mismatch\n", filename));
// deactivate tstrings check
Lcl_unexpected_tstring_check = nullptr;
if (condition) {
Standalone_mission_names[Num_standalone_missions_with_info] = vm_strdup(The_mission.name);
Standalone_mission_flags[Num_standalone_missions_with_info] = The_mission.game_type;
int y = Num_lines * (font_height + 2);
//Add mission data to the API
if (API_Access) {
sim_mission api_mission;
api_mission.name = The_mission.name;
api_mission.filename = filename;
api_mission.mission_desc = The_mission.mission_desc;
api_mission.author = The_mission.author;
api_mission.visible = 1;
Sim_Missions.push_back(api_mission);
}
// determine some extra information
int flags = 0;
auto fb = game_find_builtin_mission(filename);
if((fb != NULL) && (fb->flags & FSB_FROM_VOLITION)){
flags |= READYROOM_FLAG_FROM_VOLITION;
}
// add the line
sim_room_line_add(READYROOM_LINE_MISSION, Standalone_mission_names[Num_standalone_missions_with_info], Mission_filenames[Num_standalone_missions_with_info], list_x1 + M_TEXT_X, y, flags);
}
}
Num_standalone_missions_with_info++;
}
if (Num_standalone_missions_with_info == Num_standalone_missions) {
Standalone_mission_names_inited = 1;
return 1;
} else {
return 0;
}
}
// builds up list of already played missions in a campaign and adds them to missions simulator
// processes one mission per frame
//
// returns 1 if finished with all missions, 0 otherwise
//
int build_campaign_mission_list_do_frame(bool API_Access)
{
int font_height = gr_get_font_height();
SCP_string popup_str;
static int valid_missions_with_info = 0; // we use this to avoid blank entries in the mission list
// When no campaign files in data directory
if (Campaign.num_missions == 0) {
Campaign_mission_names_inited = 1;
return 1;
}
// change popup
sprintf(popup_str, XSTR("Campaign Mission\n\n%s", 990), Campaign.missions[Num_campaign_missions_with_info].name);
popup_change_text(popup_str.c_str());
// Set global variable so we we'll have list available next time
Campaign_mission_names[Num_campaign_missions_with_info] = NULL;
Campaign_mission_flags[Num_campaign_missions_with_info] = 0;
// Only allow missions already completed
if (Campaign.missions[Num_campaign_missions_with_info].completed || (Simroom_show_all || API_Access))
{
if (!get_mission_info(Campaign.missions[Num_campaign_missions_with_info].name))
{
auto filename = Campaign.missions[Num_campaign_missions_with_info].name;
// add to list
Campaign_mission_names[Num_campaign_missions_with_info] = vm_strdup(The_mission.name);
Campaign_mission_flags[Num_campaign_missions_with_info] = The_mission.game_type;
int y = valid_missions_with_info * (font_height + 2);
// Add mission data to the API
if (API_Access) {
sim_mission api_mission;
api_mission.name = The_mission.name;
api_mission.filename = filename;
api_mission.mission_desc = The_mission.mission_desc;
api_mission.author = The_mission.author;
api_mission.visible = Campaign.missions[Num_campaign_missions_with_info].completed;
Sim_CMissions.push_back(api_mission);
}
// determine some extra information
int flags = 0;
auto fb = game_find_builtin_mission(Campaign.missions[Num_campaign_missions_with_info].name);
if((fb != NULL) && (fb->flags & FSB_FROM_VOLITION))
{
flags |= READYROOM_FLAG_FROM_VOLITION;
}
sim_room_line_add(READYROOM_LINE_CMISSION, Campaign_mission_names[Num_campaign_missions_with_info], Campaign.missions[Num_campaign_missions_with_info].name, list_x1 + C_SUBTEXT_X, y, flags);
valid_missions_with_info++;
}
}
Num_campaign_missions_with_info++;
if (Num_campaign_missions_with_info == Campaign.num_missions) {
valid_missions_with_info = 0;
Campaign_mission_names_inited = 1;
return 1;
} else {
return 0;
}
}
// Builds list of either (1) standalone missions or (2) already played missions in current campaign
// First time through, it builds list, next time it uses precompiled list
void sim_room_build_listing()
{
int i, y, max_num_entries_viewable;
int font_height = gr_get_font_height();
Num_lines = y = 0;
list_y = Mission_list_coords[gr_screen.res][1];
list_h = Mission_list_coords[gr_screen.res][3];
// Stand alone single player missions.
if (Player->readyroom_listing_mode == MODE_MISSIONS) {
if (Hash_table_inited) {
if (!Standalone_mission_names_inited) { // Is this the first time through
// build_list_do_frame builds list and adds sim room line and sets Standalone_mission_names_inited
popup_till_condition([]() -> int { return build_standalone_mission_list_do_frame(false); },
POPUP_CANCEL,
XSTR("Loading missions", 991));
} else {
for (i=0; i<Num_standalone_missions_with_info; i++) {
if (Standalone_mission_names[i]) {
// determine some extra information
int flags = 0;
auto full_filename = cf_add_ext(Mission_filenames[i], FS_MISSION_FILE_EXT);
auto fb = game_find_builtin_mission(full_filename);
if((fb != NULL) && (fb->flags & FSB_FROM_VOLITION)){
flags |= READYROOM_FLAG_FROM_VOLITION;
}
sim_room_line_add(READYROOM_LINE_MISSION, Standalone_mission_names[i], Mission_filenames[i], list_x1 + M_TEXT_X, y, flags);
y += font_height + 2;
}
}
}
}
} else {
// Campaign missions
list_y += font_height + 2;
list_h -= font_height - 2;
if (!Campaign_mission_names_inited) { // Is this the first time through
// builds list, adds sim room line and sets Campaign_mission_names_inited
popup_till_condition([]() -> int { return build_campaign_mission_list_do_frame(false); },
POPUP_CANCEL,
XSTR("Loading campaign missions", 992));
} else {
for (i=0; i<Num_campaign_missions_with_info; i++) {
if (Campaign_mission_names[i]) {
// determine some extra information
int flags = 0;
auto full_filename = cf_add_ext(Campaign.missions[i].name, FS_MISSION_FILE_EXT);
auto fb = game_find_builtin_mission(full_filename);
if((fb != NULL) && (fb->flags & FSB_FROM_VOLITION)){
flags |= READYROOM_FLAG_FROM_VOLITION;
}
sim_room_line_add(READYROOM_LINE_CMISSION, Campaign_mission_names[i], Campaign.missions[i].name, list_x1 + C_SUBTEXT_X, y, flags);
y += font_height + 2; // Goober5000 - added +2 to conform with above
}
}
}
}
// free up memory from parsing all of those missions
stop_parse();
// set appropriate slider size
max_num_entries_viewable = list_h / (font_height + 2);
Sim_room_slider.set_numberItems((Num_lines > max_num_entries_viewable) ? (Num_lines - max_num_entries_viewable) : 0);
}
void sim_room_reset_campaign_listing()
{
// only reset if we got fully inited in the first place
if (!Campaign_mission_names_inited)
return;
for (int i=0; i<Campaign.num_missions; i++) {
if (Campaign_mission_names[i]) {
vm_free(Campaign_mission_names[i]);
Campaign_mission_names[i] = NULL;
}
}
Campaign_mission_names_inited = 0;
Num_campaign_missions_with_info = 0;
sim_room_build_listing();
}
int sim_room_line_query_visible(int n)
{
int y;
if ((n < 0) || (n >= Num_lines))
return 0;
y = sim_room_lines[n].y - sim_room_lines[Scroll_offset].y;
if ((y < 0) || (y + gr_get_font_height() > list_h))
return 0;
return 1;
}
void sim_room_scroll_screen_up()
{
if (Scroll_offset > 0) {
Scroll_offset--;
if (Player->readyroom_listing_mode == MODE_MISSIONS)
{
Assert(Selected_line > Scroll_offset);
while (!sim_room_line_query_visible(Selected_line))
{
Selected_line--;
}
}
gamesnd_play_iface(InterfaceSounds::SCROLL);
} else
gamesnd_play_iface(InterfaceSounds::GENERAL_FAIL);
}
void sim_room_scroll_line_up()
{
if (Selected_line) {
Selected_line--;
if (Selected_line < Scroll_offset)
{
Scroll_offset = Selected_line;
Sim_room_slider.forceUp();
}
gamesnd_play_iface(InterfaceSounds::SCROLL);
} else
gamesnd_play_iface(InterfaceSounds::GENERAL_FAIL);
}
void sim_room_scroll_screen_down()
{
if (sim_room_lines[Num_lines - 1].y + gr_get_font_height() > sim_room_lines[Scroll_offset].y + list_h) {
Scroll_offset++;
if (Player->readyroom_listing_mode == MODE_MISSIONS)
{
while (!sim_room_line_query_visible(Selected_line))
{
Selected_line++;
Assert(Selected_line < Num_lines);
}
}
gamesnd_play_iface(InterfaceSounds::SCROLL);
} else
gamesnd_play_iface(InterfaceSounds::GENERAL_FAIL);
}
void sim_room_scroll_line_down()
{
if (Selected_line < Num_lines - 1) {
Selected_line++;
Assert(Selected_line > Scroll_offset);
while (!sim_room_line_query_visible(Selected_line))
{
Scroll_offset++;
Sim_room_slider.forceDown();
}
gamesnd_play_iface(InterfaceSounds::SCROLL);
} else
gamesnd_play_iface(InterfaceSounds::GENERAL_FAIL);
}
/* Goober5000 - why are there two nearly identical functions?
(campaign_room_reset_campaign and sim_room_reset_campaign)
Looks like this function should be deprecated...
// returns: 0 = success, !0 = aborted or failed
int sim_room_reset_campaign()
{
int z, rval = 1;
z = popup(PF_TITLE_BIG | PF_TITLE_RED, 2, POPUP_CANCEL, POPUP_OK, XSTR( "Warning\nThis will cause all progress in your\ncurrent campaign to be lost", 110) );
if (z) {
mission_campaign_savefile_delete(Campaign.filename);
mission_campaign_load(Campaign.filename);
rval = 0;
}
return rval;
}
*/
// Decide if we should offer choice to resume this savegame
int sim_room_can_resume_savegame(char * /*savegame_filename*/)
{
#ifdef FREESPACE_SAVERESTORE_SYSTEM
char savegame_mission[MAX_FILENAME_LEN];
if (state_read_description(savegame_filename, NULL, savegame_mission)) {
return 0;
}
if (stricmp(Game_current_mission_filename, savegame_mission)) {
return 0;
}
return 1;
#else
return 0;
#endif
}
int readyroom_continue_campaign()
{
// check for possible mission loop, need to do this before calling mission_campaign_next_mission()!
if ( !(Game_mode & GM_MULTIPLAYER) && !Campaign.loop_enabled && (Campaign.current_mission == -1) &&
(Campaign.prev_mission != -1) && (Campaign.next_mission != -1) )
{
if (Campaign.missions[Campaign.prev_mission].flags & CMISSION_FLAG_HAS_LOOP) {
// NOTE: the order of these calls is *very* important
// we must manually set the current mission to the *previous* mission and the mission name.
// this isn't the same thing that is done in mission_campaign_next_mission(), but it's
// cleaner to do this here than it is to hack that function to do the same thing
Campaign.current_mission = Campaign.prev_mission;
strcpy_s( Game_current_mission_filename, Campaign.missions[Campaign.current_mission].name );
// set the bit for campaign mode
Game_mode |= GM_CAMPAIGN_MODE;
// eval the mission (may be needed to setup loop mission stuff)
if (Campaign.loop_mission == CAMPAIGN_LOOP_MISSION_UNINITIALIZED)
mission_campaign_eval_next_mission();
// only proceed to loop if we have a loop
if (Campaign.loop_mission > 0) {
gameseq_post_event(GS_EVENT_LOOP_BRIEF);
return 0;
}
}
}
int mc_rval = mission_campaign_next_mission();
if (mc_rval == -1)
{ // is campaign and next mission valid?
gamesnd_play_iface(InterfaceSounds::GENERAL_FAIL);
popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR( "The campaign is over. To replay the campaign, either create a new pilot or restart the campaign in the campaign room.", 112) );
return -1;
}
else if(mc_rval == -2)
{
gamesnd_play_iface(InterfaceSounds::GENERAL_FAIL);
popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, NOX("The current campaign has no missions") );
return -1;
}
// set the bit for campaign mode
Game_mode |= GM_CAMPAIGN_MODE;
gameseq_post_event( GS_EVENT_START_GAME );
return 0;
}
void sim_room_commit()
{
if ((Selected_line >= Num_lines) || !sim_room_lines[Selected_line].filename) {
gamesnd_play_iface(InterfaceSounds::GENERAL_FAIL);
return;
}
strcpy_s(Game_current_mission_filename, sim_room_lines[Selected_line].filename);
Game_mode &= ~(GM_CAMPAIGN_MODE); // be sure this bit is clear
gameseq_post_event(GS_EVENT_START_GAME);
gamesnd_play_iface(InterfaceSounds::COMMIT_PRESSED);
}
int sim_room_button_pressed(int n)
{
switch (n) {
case SCROLL_UP_BUTTON:
sim_room_scroll_screen_up();
Sim_room_slider.forceUp();
break;
case SCROLL_DOWN_BUTTON:
sim_room_scroll_screen_down();
Sim_room_slider.forceDown();
break;
case MISSION_TAB:
Simroom_show_all = 0;
Player->readyroom_listing_mode = MODE_MISSIONS;
Selected_line = Scroll_offset = 0;
gamesnd_play_iface(InterfaceSounds::USER_SELECT);
sim_room_build_listing();
break;
case CAMPAIGN_TAB:
if ( !strlen(Campaign.filename) ) {
if (Campaign_load_failure == CAMPAIGN_ERROR_MISSING) {
popup(PF_USE_AFFIRMATIVE_ICON | PF_NO_NETWORKING, 1, POPUP_OK, XSTR("The currently active campaign cannot be found. Unable to switch to campaign mode.", 1612));
} else {
popup(PF_USE_AFFIRMATIVE_ICON | PF_NO_NETWORKING, 1, POPUP_OK, XSTR("The currently active campaign cannot be loaded. Unable to switch to campaign mode.", 1816));
}
break;
}
if (Player->readyroom_listing_mode != MODE_CAMPAIGNS)
Simroom_show_all = 0;
Player->readyroom_listing_mode = MODE_CAMPAIGNS;
Scroll_offset = 0;
gamesnd_play_iface(InterfaceSounds::USER_SELECT);
sim_room_build_listing();
break;
case COMMIT_BUTTON:
sim_room_commit();
break;
case HELP_BUTTON:
launch_context_help();
gamesnd_play_iface(InterfaceSounds::HELP_PRESSED);
break;
case OPTIONS_BUTTON:
gamesnd_play_iface(InterfaceSounds::SWITCH_SCREENS);
gameseq_post_event(GS_EVENT_OPTIONS_MENU);
return 1;
case TECH_DATABASE_BUTTON:
gamesnd_play_iface(InterfaceSounds::SWITCH_SCREENS);
gameseq_post_event(GS_EVENT_TECH_MENU);
return 1;
case CUTSCENES_BUTTON:
gamesnd_play_iface(InterfaceSounds::SWITCH_SCREENS);
gameseq_post_event(GS_EVENT_GOTO_VIEW_CUTSCENES_SCREEN);
return 1;
case CREDITS_BUTTON:
gamesnd_play_iface(InterfaceSounds::SWITCH_SCREENS);
gameseq_post_event(GS_EVENT_CREDITS);
return 1;
}
return 0;
}
// do nothing
void sim_room_scroll_capture()
{
}
// ---------------------------------------------------------------------
// mission_sim_room_init()
//
// Initialize the sim_room assignment screen system. Called when GS_STATE_sim_room_SCREEN
// is entered.
//
void sim_room_init()
{
int i;
sim_room_buttons *b;
char wild_card[8];
list_x1 = Mission_list_coords[gr_screen.res][0];
list_x2 = Campaign_list_coords[gr_screen.res][0];
list_y = Mission_list_coords[gr_screen.res][1];
list_w1 = Mission_list_coords[gr_screen.res][2];
list_w2 = Campaign_list_coords[gr_screen.res][2];
list_h = Mission_list_coords[gr_screen.res][3];
// force mode to valid range. I once had a bogus value here. Don't know how that happened, though.
if (Player->readyroom_listing_mode != MODE_MISSIONS)
Player->readyroom_listing_mode = MODE_CAMPAIGNS;
*Game_current_mission_filename = 0;
common_set_interface_palette("InterfacePalette"); // set the interface palette
Ui_window.create(0, 0, gr_screen.max_w_unscaled, gr_screen.max_h_unscaled, 0);