2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/MenuUI/ReadyRoom.cpp $
15 * Ready Room code, which is the UI screen for selecting Campaign/mission to play next mainly.
18 * Revision 1.5 2004/07/04 11:39:06 taylor
19 * fix missing debrief text, crash on exit, path separator's, warning fixes, no GR_SOFT
21 * Revision 1.4 2003/05/25 02:30:42 taylor
24 * Revision 1.3 2002/06/09 04:41:22 relnev
25 * added copyright header
27 * Revision 1.2 2002/06/02 04:26:34 relnev
30 * Revision 1.1.1.1 2002/05/03 03:28:09 root
34 * 20 9/30/99 5:59p Jefff
35 * fixed compile error in OEM ver
37 * 19 9/08/99 12:28p Jefff
39 * 18 9/06/99 6:38p Dave
40 * Improved CD detection code.
42 * 17 9/02/99 2:33p Jefff
43 * column heading coordinate changes
45 * 16 8/22/99 4:16p Jefff
46 * scroll button coord fixes
48 * 15 7/20/99 1:49p Dave
49 * Peter Drake build. Fixed some release build warnings.
51 * 14 7/19/99 2:13p Dave
52 * Added some new strings for Heiko.
54 * 13 7/15/99 9:20a Andsager
55 * FS2_DEMO initial checkin
57 * 12 7/09/99 5:54p Dave
58 * Seperated cruiser types into individual types. Added tons of new
59 * briefing icons. Campaign screen.
61 * 11 2/01/99 5:55p Dave
62 * Removed the idea of explicit bitmaps for buttons. Fixed text
63 * highlighting for disabled gadgets.
65 * 10 1/30/99 9:01p Dave
68 * 9 1/30/99 5:08p Dave
69 * More new hi-res stuff.Support for nice D3D textures.
71 * 8 1/29/99 12:47a Dave
72 * Put in sounds for beam weapon. A bunch of interface screens (tech
75 * 7 12/11/98 4:35p Andsager
76 * Fix sim room bug when no standalone missions
78 * 6 12/07/98 5:02p Dan
79 * Removed improper use of bitmap filename with extension,
81 * 5 10/13/98 9:28a Dave
82 * Started neatening up freespace.h. Many variables renamed and
83 * reorganized. Added AlphaColors.[h,cpp]
97 #include "gamesequence.h"
98 #include "missioncampaign.h"
101 #include "missionscreencommon.h"
102 #include "freespace.h"
103 #include "missionparse.h"
105 #include "managepilot.h"
107 #include "contexthelp.h"
108 #include "cfilesystem.h"
109 #include "freespace.h"
110 #include "alphacolors.h"
112 #define MAX_MISSIONS 1024
114 int Mission_list_coords[GR_NUM_RESOLUTIONS][4] = {
127 int Campaign_list_coords[GR_NUM_RESOLUTIONS][4] = {
141 // x coordinate offsets for data when campaign tab active
143 #define C_SUBTEXT_X 19
145 // x coordinate offsets for data when mission tab active
148 #define MODE_CAMPAIGNS 0
149 #define MODE_MISSIONS 1
151 #define MAX_LINES 200
152 #define MAX_DESC_LINES 200
153 #define NUM_BUTTONS 11
154 #define LIST_BUTTONS_MAX 40
156 #define SCROLL_UP_BUTTON 0
157 #define SCROLL_DOWN_BUTTON 1
158 #define MISSION_TAB 2
159 #define CAMPAIGN_TAB 3
160 #define HELP_BUTTON 4
161 #define COMMIT_BUTTON 5
162 #define OPTIONS_BUTTON 6
163 #define TECH_DATABASE_BUTTON 7
164 #define SIMULATOR_BUTTON 8
165 #define CUTSCENES_BUTTON 9
166 #define CREDITS_BUTTON 10
168 #define CAMPAIGN_MISSION_HASH_SIZE 307
170 struct sim_room_buttons {
174 UI_BUTTON button; // because we have a class inside this struct, we need the constructor below..
176 sim_room_buttons(char *name, int x1, int y1, int xt1, int yt1, int h) : filename(name), x(x1), y(y1), xt(xt1), yt(yt1), hotspot(h) {}
179 static sim_room_buttons Buttons[GR_NUM_RESOLUTIONS][NUM_BUTTONS] = {
183 sim_room_buttons("LMB_04", 7, 135, -1, -1, 4), // up arrows
184 sim_room_buttons("LMB_05", 7, 182, -1, -1, 5), // down arrows
185 sim_room_buttons("LMB_06", 23, 396, -1, -1, 6), // single missions
186 sim_room_buttons("LMB_07", 198, 396, -1, -1, 7), // campaign missions
187 sim_room_buttons("LMB_08", 469, 427, -1, -1, 8), // help
188 sim_room_buttons("LMB_09", 554, 411, -1, -1, 9), // commit
189 sim_room_buttons("LMB_10", 447, 452, -1, -1, 10), // options
191 sim_room_buttons("TDB_00", 0, 0, -1, -1, 0), // technical database
192 sim_room_buttons("TDB_01", 0, 19, -1, -1, 1), // mission simulator
193 sim_room_buttons("TDB_02", 0, 35, -1, -1, 2), // cutscenes
194 sim_room_buttons("TDB_03", 0, 56, -1, -1, 3), // credits
196 sim_room_buttons("LMB_04", 1, 99, -1, -1, 4),
197 sim_room_buttons("LMB_05", 1, 381, -1, -1, 5),
198 sim_room_buttons("LMB_06", 6, 438, 40, 445, 6),
199 sim_room_buttons("LMB_07", 6, 457, 40, 462, 7),
200 sim_room_buttons("LMB_08", 534, 426, 500, 440, 8),
201 sim_room_buttons("LMB_09", 571, 426, 572, 413, 9),
202 sim_room_buttons("LMB_10", 534, 455, 480, 462, 10),
204 sim_room_buttons("TDB_00", 7, 3, 37, 7, 0),
205 sim_room_buttons("TDB_01", 7, 18, 37, 23, 1),
206 sim_room_buttons("TDB_02", 7, 34, 37, 38, 2),
207 sim_room_buttons("TDB_03", 7, 49, 37, 54, 3),
211 sim_room_buttons("2_LMB_04", 2, 159, -1, -1, 4),
212 sim_room_buttons("2_LMB_05", 2, 609, -1, -1, 5),
213 sim_room_buttons("2_LMB_06", 10, 701, 64, 712, 6),
214 sim_room_buttons("2_LMB_07", 10, 732, 64, 739, 7),
215 sim_room_buttons("2_LMB_08", 854, 681, 800, 704, 8),
216 sim_room_buttons("2_LMB_09", 914, 681, 915, 660, 9),
217 sim_room_buttons("2_LMB_10", 854, 728, 800, 728, 10),
219 sim_room_buttons("2_TDB_00", 12, 5, 59, 12, 0),
220 sim_room_buttons("2_TDB_01", 12, 31, 59, 37, 1),
221 sim_room_buttons("2_TDB_02", 12, 56, 59, 62, 2),
222 sim_room_buttons("2_TDB_03", 12, 81, 59, 88, 3),
227 char *Sim_filename[GR_NUM_RESOLUTIONS] = {
231 char *Sim_mask_filename[GR_NUM_RESOLUTIONS] = {
236 char *Campaign_filename[GR_NUM_RESOLUTIONS] = {
240 char *Campaign_mask_filename[GR_NUM_RESOLUTIONS] = {
245 // misc text. ("Mission" and "Filename"
247 #define NUM_SIM_MISC_TEXT 0
249 #define NUM_SIM_MISC_TEXT 2
251 #define SIM_MISC_TEXT_MISSION 0
252 #define SIM_MISC_TEXT_FILENAME 1
253 int Sim_misc_text_coords[GR_NUM_RESOLUTIONS][NUM_SIM_MISC_TEXT][2] = {
255 // nothing needed for FS1
262 // nothing needed for FS1
270 // readyroom text line stuff
271 #define READYROOM_LINE_CAMPAIGN 1
272 #define READYROOM_LINE_CMISSION 2
273 #define READYROOM_LINE_MISSION 3
275 #define READYROOM_FLAG_FROM_VOLITION (1<<0) // volition made
277 #define READYROOM_FLAG_FROM_MDISK (1<<1) // mission disk
280 int type; // see READYROOM_LINE_* defines above
283 int x; // X coordinate of line
284 int y; // Y coordinate of line
285 int flags; // special flags, see READYROOM_FLAG_* defines above
286 } sim_room_lines[MAX_LINES];
288 static char Cur_campaign[MAX_FILENAME_LEN];
289 static char *Mission_filenames[MAX_MISSIONS];
290 static char *Standalone_mission_names[MAX_MISSIONS];
291 static int Standalone_mission_flags[MAX_MISSIONS];
292 static char *Campaign_missions[MAX_MISSIONS];
293 static char *Campaign_mission_names[MAX_CAMPAIGN_MISSIONS];
294 static int Campaign_mission_flags[MAX_MISSIONS];
295 static char *Campaign_descs[MAX_CAMPAIGNS];
296 static char *Campaign_descs_temp[MAX_CAMPAIGNS];
297 static char *Campaign_file_names_temp[MAX_CAMPAIGNS];
298 static int Standalone_mission_names_inited = 0;
299 static int Campaign_names_inited = 0;
300 static int Campaign_mission_names_inited = 0;
301 static int Num_standalone_missions;
302 static int Num_campaign_missions;
303 static int Scroll_offset;
304 static int Selected_line;
305 static int Num_lines;
306 static int Num_campaign_missions_with_info = 0;
307 static int Num_standalone_missions_with_info = 0;
314 static int Background_bitmap;
315 static UI_WINDOW Ui_window;
316 static UI_BUTTON List_buttons[LIST_BUTTONS_MAX]; // buttons for each line of text in list
318 typedef struct hash_node {
323 static hash_node *Campaign_mission_hash_table[CAMPAIGN_MISSION_HASH_SIZE];
324 static int Hash_table_inited;
326 // special icons (1.04 + stuff)
328 #define NUM_MISSION_ICONS 2
330 #define NUM_MISSION_ICONS 1
332 #define MISSION_ICON_VOLITION 0 // mini volition death's head :)
334 #define MISSION_ICON_MDISK 1 // Silent Threat mini icon
337 // icon offsets (see LIST_ defines above
338 //#define MISSION_ICON_VOLITION_X (46)
339 #define MISSION_ICON_VOLITION_Y_OFFSET (-1)
341 #define MISSION_ICON_MDISK_Y_OFFSET (0)
345 static int Sim_volition_icon_x[GR_NUM_RESOLUTIONS] = {
355 static int Sim_silent_icon_x[GR_NUM_RESOLUTIONS] = {
361 // special icons themselves
362 int Mission_icon_bitmaps[NUM_MISSION_ICONS];
364 char *Mission_icon_bitmap_filenames[NUM_MISSION_ICONS] = {
373 void sim_room_load_mission_icons();
374 void sim_room_unload_mission_icons();
375 void sim_room_blit_icons(int line_index, int y_start, fs_builtin_mission *fb = NULL, int is_md = 0);
377 // Finds a hash value for mission filename
379 // returns hash value
380 int hash_filename(char *filename) {
381 unsigned __int64 hash_val = 0;
382 char *ptr = filename;
384 // Dont hash .fsm extension, convert all to upper case
385 for (int i=0; i < ((signed int)(strlen(filename)) - 4); i++) {
386 hash_val = (hash_val << 4) + toupper(*ptr++);
389 return int(hash_val % CAMPAIGN_MISSION_HASH_SIZE);
392 // insert filename into Campaign_mission_hash_table
394 // returns 1 if successful, 0 if could not allocate memory
395 int hash_insert(char *filename) {
396 int hash_val = hash_filename(filename);
399 // Check if table empty
400 if (Campaign_mission_hash_table[hash_val] == NULL) {
401 Campaign_mission_hash_table[hash_val] = new hash_node;
403 cur_node = Campaign_mission_hash_table[hash_val];
405 if (cur_node == NULL) {
406 // Unable to allocate memory
410 // Walk down list to first empty node
411 cur_node = Campaign_mission_hash_table[hash_val];
412 while (cur_node->next != NULL) {
413 cur_node = cur_node->next;
417 cur_node->next = new hash_node;
419 if (cur_node->next == NULL) {
420 // unable to allocate memory
423 cur_node = cur_node->next;
428 cur_node->next = NULL;
429 cur_node->filename = filename;
435 // Checks if a filename already exitst in the hash table
437 // returns 1 if found (collision), 0 if no collision
438 int campaign_mission_hash_collision(char *filename)
440 int hash_val = hash_filename(filename);
441 hash_node *cur_node = Campaign_mission_hash_table[hash_val];
443 if (cur_node == NULL) {
448 if (!stricmp(filename, cur_node->filename)) {
452 cur_node = cur_node->next;
453 } while (cur_node != NULL);
455 // Ran out of stuff to check
459 // builds hash table of campaign mission filenames
461 // returns 1 if successful, 0 if not successful
462 int build_campaign_mission_filename_hash_table()
465 // Go through all campaign missions
466 for (int i=0; i<Num_campaign_missions; i++) {
467 rval = hash_insert(Campaign_missions[i]);
477 // deletes hash table nodes
479 void campaign_mission_hash_table_delete()
483 for (int i=0; i<CAMPAIGN_MISSION_HASH_SIZE; i++) {
484 // Look for entries into array
485 if (Campaign_mission_hash_table[i] != NULL) {
486 cur_node = Campaign_mission_hash_table[i];
488 // Walk down the list deleting self
489 while (cur_node->next != NULL) {
490 hash_node *temp = cur_node->next;
497 Campaign_mission_hash_table[i] = NULL;
503 // add a line of sim_room smuck to end of list
504 int sim_room_line_add(int type, char *name, char *filename, int x, int y, int flags)
506 if (Num_lines >= MAX_LINES)
509 sim_room_lines[Num_lines].type = type;
510 sim_room_lines[Num_lines].name = name;
511 sim_room_lines[Num_lines].filename = filename;
512 sim_room_lines[Num_lines].x = x;
513 sim_room_lines[Num_lines].y = y;
514 sim_room_lines[Num_lines].flags = flags;
518 // filter out all multiplayer campaigns
519 int campaign_room_campaign_filter(char *filename)
521 int type, max_players;
522 char name[NAME_LENGTH], *desc = NULL;
525 // also need to check if this is the builtin campaign
526 if ( game_find_builtin_mission(filename) && mission_campaign_get_info(filename, name, &type, &max_players, &desc) ) {
528 if ( mission_campaign_get_info(filename, name, &type, &max_players, &desc) ) {
530 if ( type == CAMPAIGN_TYPE_SINGLE ) {
531 Campaign_file_names_temp[Num_campaigns] = strdup(filename);
532 Campaign_descs_temp[Num_campaigns++] = desc;
544 // build up a list of all missions in all campaigns.
545 int sim_room_campaign_mission_filter(char *filename)
549 num = mission_campaign_get_mission_list(filename, &Campaign_missions[Num_campaign_missions], MAX_CAMPAIGN_MISSIONS - Num_campaign_missions);
553 Num_campaign_missions += num;
557 // filter out all missions already used in existing campaigns
558 int sim_room_standalone_mission_filter(char *filename)
561 char mission_name[255];
563 // Check if a campaign mission (single and multi)
564 if (campaign_mission_hash_collision(filename)) {
568 // Check if a standalone multi mission OR Mdisk mission with data
569 type = mission_parse_is_multi(filename, mission_name);
570 if (type && !(type & MISSION_TYPE_SINGLE))
576 // builds up list of standalone missions and adds them to missions simulator
577 // processes one mission per frame
579 // returns 1 if finished with all missions, 0 otherwise
581 int build_standalone_mission_list_do_frame()
583 int font_height = gr_get_font_height();
584 char filename[MAX_FILENAME_LEN];
587 // When no standalone missions in data directory
588 if (Num_standalone_missions == 0) {
589 Standalone_mission_names_inited = 1;
593 // Set global variable so we we'll have list available next time
594 Standalone_mission_names[Num_standalone_missions_with_info] = NULL;
595 Standalone_mission_flags[Num_standalone_missions_with_info] = 0;
597 if (Num_standalone_missions > 0) { // sanity check
598 if (strlen(Mission_filenames[Num_standalone_missions_with_info]) < MAX_FILENAME_LEN - 4) { // sanity check?
599 strcpy(filename, Mission_filenames[Num_standalone_missions_with_info]);
603 sprintf(str, XSTR("Single Mission\n\n%s",989), filename);
604 popup_change_text(str);
606 // tack on an extension
607 strcat(filename, FS_MISSION_FILE_EXT);
608 if (!get_mission_info(filename)) {
609 Standalone_mission_names[Num_standalone_missions_with_info] = strdup(The_mission.name);
610 Standalone_mission_flags[Num_standalone_missions_with_info] = The_mission.game_type;
611 int y = Num_lines * (font_height + 2);
613 // determine some extra information
615 fs_builtin_mission *fb = game_find_builtin_mission(filename);
616 if((fb != NULL) && (fb->flags & FSB_FROM_VOLITION)){
617 flags |= READYROOM_FLAG_FROM_VOLITION;
620 if((fb != NULL) && (fb->flags & FSB_FROM_MDISK)){
621 flags |= READYROOM_FLAG_FROM_MDISK;
626 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);
630 Num_standalone_missions_with_info++;
633 if (Num_standalone_missions_with_info == Num_standalone_missions) {
634 Standalone_mission_names_inited = 1;
641 // builds up list of already played missions in a campaign and adds them to missions simulator
642 // processes one mission per frame
644 // returns 1 if finished with all missions, 0 otherwise
646 int build_campaign_mission_list_do_frame()
648 int font_height = gr_get_font_height();
651 // When no campaign files in data directory
652 if (Campaign.num_missions == 0) {
653 Campaign_mission_names_inited = 1;
659 sprintf(str, XSTR("Campaign Mission\n\n%s",990), Campaign.missions[Num_campaign_missions_with_info].name);
660 popup_change_text(str);
662 // Set global variable so we we'll have list available next time
663 Campaign_mission_names[Num_campaign_missions_with_info] = NULL;
664 Campaign_mission_flags[Num_campaign_missions_with_info] = 0;
666 // Only allow missions already completed
667 if (Campaign.missions[Num_campaign_missions_with_info].completed) {
668 if (!get_mission_info(Campaign.missions[Num_campaign_missions_with_info].name)) {
670 Campaign_mission_names[Num_campaign_missions_with_info] = strdup(The_mission.name);
671 Campaign_mission_flags[Num_campaign_missions_with_info] = The_mission.game_type;
672 int y = Num_campaign_missions_with_info * (font_height + 2);
674 // determine some extra information
676 fs_builtin_mission *fb = game_find_builtin_mission(Campaign.missions[Num_campaign_missions_with_info].name);
677 if((fb != NULL) && (fb->flags & FSB_FROM_VOLITION)){
678 flags |= READYROOM_FLAG_FROM_VOLITION;
682 if((fb != NULL) && (fb->flags & FSB_FROM_MDISK)){
683 flags |= READYROOM_FLAG_FROM_MDISK;
687 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);
691 Num_campaign_missions_with_info++;
693 if (Num_campaign_missions_with_info == Campaign.num_missions) {
694 Campaign_mission_names_inited = 1;
701 // Builds list of either (1) standalone missions or (2) already played missions in current campaign
702 // First time through, it builds list, next time it uses precompiled list
703 void sim_room_build_listing()
706 int font_height = gr_get_font_height();
707 char full_filename[256];
710 list_y = Mission_list_coords[gr_screen.res][1];
711 list_h = Mission_list_coords[gr_screen.res][3];
713 // Stand alone single player missions.
714 if (Player->readyroom_listing_mode == MODE_MISSIONS) {
715 if (Hash_table_inited) {
716 if (!Standalone_mission_names_inited) { // Is this the first time through
717 // build_list_do_frame builds list and adds sim room line and sets Standalone_mission_names_inited
718 popup_till_condition(build_standalone_mission_list_do_frame, POPUP_CANCEL, XSTR("Loading missions", 991) );
720 for (i=0; i<Num_standalone_missions_with_info; i++) {
721 if (Standalone_mission_names[i]) {
722 // determine some extra information
724 memset(full_filename, 0, 256);
725 strcpy(full_filename, cf_add_ext(Mission_filenames[i], FS_MISSION_FILE_EXT));
726 fs_builtin_mission *fb = game_find_builtin_mission(full_filename);
727 if((fb != NULL) && (fb->flags & FSB_FROM_VOLITION)){
728 flags |= READYROOM_FLAG_FROM_VOLITION;
732 if((fb != NULL) && (fb->flags & FSB_FROM_MDISK)){
733 flags |= READYROOM_FLAG_FROM_MDISK;
737 sim_room_line_add(READYROOM_LINE_MISSION, Standalone_mission_names[i], Mission_filenames[i], list_x1 + M_TEXT_X, y, flags);
738 y += font_height + 2;
745 list_y += font_height + 2;
746 list_h -= font_height - 2;
748 if (!Campaign_mission_names_inited) { // Is this the first time through
749 popup_till_condition(build_campaign_mission_list_do_frame, POPUP_CANCEL, XSTR("Loading campaign missions",992));
750 // builds list, adds sim room line and sets Campaign_mission_names_inited
752 for (i=0; i<Num_campaign_missions_with_info; i++) {
753 if (Campaign_mission_names[i]) {
754 // determine some extra information
756 memset(full_filename, 0, 256);
757 strcpy(full_filename, cf_add_ext(Campaign.missions[i].name, FS_MISSION_FILE_EXT));
758 fs_builtin_mission *fb = game_find_builtin_mission(full_filename);
759 if((fb != NULL) && (fb->flags & FSB_FROM_VOLITION)){
760 flags |= READYROOM_FLAG_FROM_VOLITION;
764 if((fb != NULL) && (fb->flags & FSB_FROM_MDISK)){
765 flags |= READYROOM_FLAG_FROM_MDISK;
769 sim_room_line_add(READYROOM_LINE_CMISSION, Campaign_mission_names[i], Campaign.missions[i].name, list_x1 + C_SUBTEXT_X, y, flags);
777 int sim_room_line_query_visible(int n)
781 if ((n < 0) || (n >= Num_lines))
784 y = sim_room_lines[n].y - sim_room_lines[Scroll_offset].y;
785 if ((y < 0) || (y + gr_get_font_height() > list_h))
791 void sim_room_scroll_screen_up()
793 if (Player->readyroom_listing_mode != MODE_MISSIONS) {
796 gamesnd_play_iface(SND_SCROLL);
799 gamesnd_play_iface(SND_GENERAL_FAIL);
806 Assert(Selected_line > Scroll_offset);
807 while (!sim_room_line_query_visible(Selected_line))
810 gamesnd_play_iface(SND_SCROLL);
813 gamesnd_play_iface(SND_GENERAL_FAIL);
816 void sim_room_scroll_line_up()
820 if (Selected_line < Scroll_offset)
821 Scroll_offset = Selected_line;
823 gamesnd_play_iface(SND_SCROLL);
826 gamesnd_play_iface(SND_GENERAL_FAIL);
829 void sim_room_scroll_screen_down()
831 if (Player->readyroom_listing_mode != MODE_MISSIONS) {
832 if (sim_room_lines[Num_lines - 1].y + gr_get_font_height() > sim_room_lines[Scroll_offset].y + list_h) {
834 gamesnd_play_iface(SND_SCROLL);
837 gamesnd_play_iface(SND_GENERAL_FAIL);
842 if (sim_room_lines[Num_lines - 1].y + gr_get_font_height() > sim_room_lines[Scroll_offset].y + list_h) {
844 while (!sim_room_line_query_visible(Selected_line)) {
846 Assert(Selected_line < Num_lines);
849 gamesnd_play_iface(SND_SCROLL);
852 gamesnd_play_iface(SND_GENERAL_FAIL);
855 void sim_room_scroll_line_down()
857 if (Selected_line < Num_lines - 1) {
860 Assert(Selected_line > Scroll_offset);
861 while (!sim_room_line_query_visible(Selected_line))
864 gamesnd_play_iface(SND_SCROLL);
867 gamesnd_play_iface(SND_GENERAL_FAIL);
870 // returns: 0 = success, !0 = aborted or failed
871 int ready_room_reset_campaign()
875 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) );
878 mission_campaign_savefile_delete(Campaign.filename);
879 mission_campaign_load(Campaign.filename);
886 // Decide if we should offer choice to resume this savegame
887 int sim_room_can_resume_savegame(char *savegame_filename)
889 #ifdef FREESPACE_SAVERESTORE_SYSTEM
890 char savegame_mission[MAX_FILENAME_LEN];
892 if (state_read_description(savegame_filename, NULL, savegame_mission)) {
896 if (stricmp(Game_current_mission_filename, savegame_mission)) {
906 // Decide wether to resume a save game or not
907 // exit: 1 => savegame has been restored
908 // 0 => no restore, proceed to briefing
909 // -1 => don't start mission at all
910 int sim_room_maybe_resume_savegame()
912 // MWA -- 3/26/98 -- removed all savegame references in game
916 char savegame_filename[_MAX_FNAME];
917 int popup_rval = -1, resume_savegame = 0;
919 // Generate the save-game filename for this campaign
920 memset(savegame_filename, 0, _MAX_FNAME);
921 mission_campaign_savefile_generate_root(savegame_filename);
922 strcat(savegame_filename, NOX("svg"));
924 // Decide if we should offer choice to resume this savegame
925 if ( sim_room_can_resume_savegame(savegame_filename) ) {
926 popup_rval = popup(0, 3, XSTR("&Cancel",-1), XSTR("&Overwrite",-1), XSTR("&Resume",-1), XSTR("A save game for this mission exists.", -1));
927 switch ( popup_rval ) {
930 resume_savegame = -1;
940 resume_savegame = -1;
947 if (resume_savegame == 1) {
948 if ( state_restore_all(savegame_filename) == -1 ) {
949 popup_rval = popup(PF_TITLE_BIG | PF_TITLE_RED, 2, POPUP_NO, POPUP_YES, XSTR("Error\nSaved misison could not be loaded.\nDo you wish to start this mission from the beginning?", -1));
950 if (popup_rval == 1) {
953 resume_savegame = -1;
961 // If we are resuming this savegame, then delete the file
962 if (resume_savegame == 1) {
963 cf_delete(savegame_filename);
966 return resume_savegame;
970 int readyroom_continue_campaign()
972 if (mission_campaign_next_mission()) { // is campaign and next mission valid?
974 #if defined(FS2_DEMO) || defined(FS1_DEMO)
975 int reset_campaign = 0;
976 reset_campaign = popup(PF_BODY_BIG, 2, POPUP_NO, POPUP_YES, XSTR( "Demo Campaign Is Over. Would you like to play the campaign again?", 111) );
977 if ( reset_campaign == 1 ) {
978 mission_campaign_savefile_delete(Campaign.filename);
979 mission_campaign_load(Campaign.filename);
980 mission_campaign_next_mission();
985 gamesnd_play_iface(SND_GENERAL_FAIL);
987 // make it the bottom button so that the graphic looks right
988 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) );
990 popup(0, 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) );
997 if(!game_do_cd_mission_check(Game_current_mission_filename)){
1001 // set the bit for campaign mode
1002 Game_mode |= GM_CAMPAIGN_MODE;
1003 gameseq_post_event( GS_EVENT_START_GAME );
1008 void sim_room_commit()
1010 if ((Selected_line >= Num_lines) || !sim_room_lines[Selected_line].filename) {
1011 gamesnd_play_iface(SND_GENERAL_FAIL);
1015 strncpy(Game_current_mission_filename, sim_room_lines[Selected_line].filename, MAX_FILENAME_LEN);
1017 Game_mode &= ~(GM_CAMPAIGN_MODE); // be sure this bit is clear
1020 if(game_do_cd_mission_check(Game_current_mission_filename)){
1021 // don't resume savegame, proceed to briefing
1022 gameseq_post_event(GS_EVENT_START_GAME);
1023 gamesnd_play_iface(SND_COMMIT_PRESSED);
1027 int sim_room_button_pressed(int n)
1030 case SCROLL_UP_BUTTON:
1031 sim_room_scroll_screen_up();
1034 case SCROLL_DOWN_BUTTON:
1035 sim_room_scroll_screen_down();
1040 game_feature_not_in_demo_popup();
1041 // gamesnd_play_iface(SND_GENERAL_FAIL);
1044 Player->readyroom_listing_mode = MODE_MISSIONS;
1045 Selected_line = Scroll_offset = 0;
1046 gamesnd_play_iface(SND_USER_SELECT);
1047 sim_room_build_listing();
1052 Player->readyroom_listing_mode = MODE_CAMPAIGNS;
1054 gamesnd_play_iface(SND_USER_SELECT);
1055 sim_room_build_listing();
1063 launch_context_help();
1064 gamesnd_play_iface(SND_HELP_PRESSED);
1067 case OPTIONS_BUTTON:
1068 gamesnd_play_iface(SND_SWITCH_SCREENS);
1069 gameseq_post_event(GS_EVENT_OPTIONS_MENU);
1072 case TECH_DATABASE_BUTTON:
1073 gamesnd_play_iface(SND_SWITCH_SCREENS);
1074 gameseq_post_event(GS_EVENT_TECH_MENU);
1077 case CUTSCENES_BUTTON:
1078 gamesnd_play_iface(SND_SWITCH_SCREENS);
1079 gameseq_post_event(GS_EVENT_GOTO_VIEW_CUTSCENES_SCREEN);
1082 case CREDITS_BUTTON:
1083 gamesnd_play_iface(SND_SWITCH_SCREENS);
1084 gameseq_post_event(GS_EVENT_CREDITS);
1091 // ---------------------------------------------------------------------
1092 // mission_sim_room_init()
1094 // Initialize the sim_room assignment screen system. Called when GS_STATE_sim_room_SCREEN
1097 void sim_room_init()
1100 sim_room_buttons *b;
1101 char wild_card[256];
1103 list_x1 = Mission_list_coords[gr_screen.res][0];
1104 list_x2 = Campaign_list_coords[gr_screen.res][0];
1105 list_y = Mission_list_coords[gr_screen.res][1];
1106 list_w1 = Mission_list_coords[gr_screen.res][2];
1107 list_w2 = Campaign_list_coords[gr_screen.res][2];
1108 list_h = Mission_list_coords[gr_screen.res][3];
1110 // force mode to valid range. I once had a bogus value here. Don't know how that happened, though.
1111 if (Player->readyroom_listing_mode != MODE_MISSIONS)
1112 Player->readyroom_listing_mode = MODE_CAMPAIGNS;
1114 *Game_current_mission_filename = 0;
1115 common_set_interface_palette("InterfacePalette"); // set the interface palette
1116 Ui_window.create(0, 0, gr_screen.max_w, gr_screen.max_h, 0);
1117 Ui_window.set_mask_bmap(Sim_mask_filename[gr_screen.res]);
1119 for (i=0; i<NUM_BUTTONS; i++) {
1120 b = &Buttons[gr_screen.res][i];
1122 b->button.create(&Ui_window, "", b->x, b->y, 60, 30, (i < 2), 1);
1123 // set up callback for when a mouse first goes over a button
1124 b->button.set_highlight_action(common_play_highlight_sound);
1125 b->button.set_bmaps(b->filename);
1126 b->button.link_hotspot(b->hotspot);
1130 // screen/button specific text
1131 Ui_window.add_XSTR("Single Missions", 1060, Buttons[gr_screen.res][MISSION_TAB].xt, Buttons[gr_screen.res][MISSION_TAB].yt, &Buttons[gr_screen.res][MISSION_TAB].button, UI_XSTR_COLOR_GREEN);
1132 Ui_window.add_XSTR("Campaign Missions", 1061, Buttons[gr_screen.res][CAMPAIGN_TAB].xt, Buttons[gr_screen.res][CAMPAIGN_TAB].yt, &Buttons[gr_screen.res][CAMPAIGN_TAB].button, UI_XSTR_COLOR_GREEN);
1133 Ui_window.add_XSTR("Help", 928, Buttons[gr_screen.res][HELP_BUTTON].xt, Buttons[gr_screen.res][HELP_BUTTON].yt, &Buttons[gr_screen.res][HELP_BUTTON].button, UI_XSTR_COLOR_GREEN);
1134 Ui_window.add_XSTR("Commit", 1062, Buttons[gr_screen.res][COMMIT_BUTTON].xt, Buttons[gr_screen.res][COMMIT_BUTTON].yt, &Buttons[gr_screen.res][COMMIT_BUTTON].button, UI_XSTR_COLOR_PINK);
1135 Ui_window.add_XSTR("Options", 1036, Buttons[gr_screen.res][OPTIONS_BUTTON].xt, Buttons[gr_screen.res][OPTIONS_BUTTON].yt, &Buttons[gr_screen.res][OPTIONS_BUTTON].button, UI_XSTR_COLOR_GREEN);
1137 // common tab button text
1138 Ui_window.add_XSTR("Technical Database", 1055, Buttons[gr_screen.res][TECH_DATABASE_BUTTON].xt, Buttons[gr_screen.res][TECH_DATABASE_BUTTON].yt, &Buttons[gr_screen.res][TECH_DATABASE_BUTTON].button, UI_XSTR_COLOR_GREEN);
1139 Ui_window.add_XSTR("Mission Simulator", 1056, Buttons[gr_screen.res][SIMULATOR_BUTTON].xt, Buttons[gr_screen.res][SIMULATOR_BUTTON].yt, &Buttons[gr_screen.res][SIMULATOR_BUTTON].button, UI_XSTR_COLOR_GREEN);
1140 Ui_window.add_XSTR("Cutscenes", 1057, Buttons[gr_screen.res][CUTSCENES_BUTTON].xt, Buttons[gr_screen.res][CUTSCENES_BUTTON].yt, &Buttons[gr_screen.res][CUTSCENES_BUTTON].button, UI_XSTR_COLOR_GREEN);
1141 Ui_window.add_XSTR("Credits", 1058, Buttons[gr_screen.res][CREDITS_BUTTON].xt, Buttons[gr_screen.res][CREDITS_BUTTON].yt, &Buttons[gr_screen.res][CREDITS_BUTTON].button, UI_XSTR_COLOR_GREEN);
1143 // misc text - not associated with any buttons
1144 Ui_window.add_XSTR("Mission", 1063, Sim_misc_text_coords[gr_screen.res][SIM_MISC_TEXT_MISSION][0], Sim_misc_text_coords[gr_screen.res][SIM_MISC_TEXT_MISSION][1], NULL, UI_XSTR_COLOR_GREEN);
1145 Ui_window.add_XSTR("Filename", 1064, Sim_misc_text_coords[gr_screen.res][SIM_MISC_TEXT_FILENAME][0], Sim_misc_text_coords[gr_screen.res][SIM_MISC_TEXT_FILENAME][1], NULL, UI_XSTR_COLOR_GREEN);
1148 for (i=0; i<LIST_BUTTONS_MAX; i++) {
1149 List_buttons[i].create(&Ui_window, "", 0, 0, 60, 30, 0, 1);
1150 List_buttons[i].hide();
1151 List_buttons[i].disable();
1154 // set up sim_rooms for buttons so we draw the correct animation frame when a key is pressed
1155 Buttons[gr_screen.res][SCROLL_UP_BUTTON].button.set_hotkey(KEY_PAGEUP);
1156 Buttons[gr_screen.res][SCROLL_DOWN_BUTTON].button.set_hotkey(KEY_PAGEDOWN);
1157 Buttons[gr_screen.res][COMMIT_BUTTON].button.set_hotkey(KEY_CTRLED | KEY_ENTER);
1159 Background_bitmap = bm_load(Sim_filename[gr_screen.res]);
1161 // load in help overlay bitmap
1162 help_overlay_load(SIM_ROOM_OVERLAY);
1163 help_overlay_set_state(SIM_ROOM_OVERLAY,0);
1165 Scroll_offset = Selected_line = 0;
1167 strcpy(Cur_campaign, Player->current_campaign);
1168 mission_load_up_campaign();
1169 mission_campaign_next_mission();
1171 Num_campaigns = Num_campaign_missions = 0;
1172 Get_file_list_filter = sim_room_campaign_mission_filter;
1173 memset(wild_card, 0, 256);
1174 strcpy(wild_card, NOX("*"));
1175 strcat(wild_card, FS_CAMPAIGN_FILE_EXT);
1176 Num_campaigns = cf_get_file_list(MAX_CAMPAIGNS, Campaign_file_names, CF_TYPE_MISSIONS, wild_card, CF_SORT_NAME);
1178 Hash_table_inited = 0;
1179 if (build_campaign_mission_filename_hash_table()) {
1180 Hash_table_inited = 1;
1184 GR_MAYBE_CLEAR_RES(Background_bitmap);
1185 if(Background_bitmap != -1){
1186 gr_set_bitmap(Background_bitmap);
1192 Get_file_list_filter = sim_room_standalone_mission_filter;
1193 memset(wild_card, 0, 256);
1194 strcpy(wild_card, NOX("*"));
1195 strcat(wild_card, FS_MISSION_FILE_EXT);
1196 Num_standalone_missions = cf_get_file_list(MAX_MISSIONS, Mission_filenames, CF_TYPE_MISSIONS, wild_card, CF_SORT_NAME);
1198 Num_campaign_missions_with_info = Num_standalone_missions_with_info = Standalone_mission_names_inited = Campaign_names_inited = Campaign_mission_names_inited = 0;
1199 sim_room_build_listing();
1201 // load special mission icons
1202 sim_room_load_mission_icons();
1205 // ---------------------------------------------------------------------
1208 // Cleanup the sim_room assignment screen system. Called when GS_STATE_sim_room_SCREEN
1211 void sim_room_close()
1215 for (i=0; i<Num_campaign_missions; i++) {
1216 if (Campaign_missions[i] != NULL) {
1217 free(Campaign_missions[i]);
1218 Campaign_missions[i] = NULL;
1222 if (Background_bitmap >= 0)
1223 bm_unload(Background_bitmap);
1225 if (Standalone_mission_names_inited){
1226 for (i=0; i<Num_standalone_missions; i++){
1227 if (Standalone_mission_names[i] != NULL) {
1228 free(Standalone_mission_names[i]);
1229 Standalone_mission_names[i] = NULL;
1231 Standalone_mission_flags[i] = 0;
1235 if (Campaign_names_inited) {
1236 for (i=0; i<Num_campaigns; i++) {
1237 if (Campaign_names[i] != NULL) {
1238 free(Campaign_names[i]);
1239 Campaign_names[i] = NULL;
1244 if (Campaign_mission_names_inited) {
1245 for (i=0; i<Campaign.num_missions; i++) {
1246 if (Campaign_mission_names[i] != NULL) {
1247 free(Campaign_mission_names[i]);
1248 Campaign_mission_names[i] = NULL;
1253 for (i=0; i<Num_campaigns; i++) {
1254 if (Campaign_file_names[i] != NULL) {
1255 free(Campaign_file_names[i]);
1256 Campaign_file_names[i] = NULL;
1261 for (i=0; i<Num_standalone_missions; i++) {
1262 if (Mission_filenames[i] != NULL) {
1263 free(Mission_filenames[i]);
1264 Mission_filenames[i] = NULL;
1268 // unload the overlay bitmap
1269 help_overlay_unload(SIM_ROOM_OVERLAY);
1271 campaign_mission_hash_table_delete();
1273 Ui_window.destroy();
1274 common_free_interface_palette(); // restore game palette
1277 // unload special mission icons
1278 sim_room_unload_mission_icons();
1281 // ---------------------------------------------------------------------
1282 // sim_room_do_frame()
1284 // Called once per frame to process user input for the sim_room Assignment Screen
1286 void sim_room_do_frame(float frametime)
1289 int i, k, y, z, line;
1290 int font_height = gr_get_font_height();
1291 int select_tease_line = -1; // line mouse is down on, but won't be selected until button released
1294 for (i=0; i<Num_campaigns; i++)
1295 if (!stricmp(Campaign_file_names[i], Campaign.filename)) {
1300 if ( help_overlay_active(SIM_ROOM_OVERLAY) ) {
1301 Buttons[gr_screen.res][HELP_BUTTON].button.reset_status();
1302 Ui_window.set_ignore_gadgets(1);
1305 k = Ui_window.process() & ~KEY_DEBUGGED;
1307 if ( (k > 0) || B1_JUST_RELEASED ) {
1308 if ( help_overlay_active(SIM_ROOM_OVERLAY) ) {
1309 help_overlay_set_state(SIM_ROOM_OVERLAY, 0);
1310 Ui_window.set_ignore_gadgets(0);
1315 if ( !help_overlay_active(SIM_ROOM_OVERLAY) ) {
1316 Ui_window.set_ignore_gadgets(0);
1320 case KEY_DOWN: // scroll list down
1321 sim_room_scroll_line_down();
1324 case KEY_UP: // scroll list up
1325 sim_room_scroll_line_up();
1329 gameseq_post_event(GS_EVENT_MAIN_MENU);
1332 case KEY_CTRLED | KEY_UP:
1333 sim_room_button_pressed(TECH_DATABASE_BUTTON);
1336 case KEY_CTRLED | KEY_DOWN:
1337 sim_room_button_pressed(CUTSCENES_BUTTON);
1341 if (Player->readyroom_listing_mode == MODE_CAMPAIGNS)
1342 Player->readyroom_listing_mode = MODE_MISSIONS;
1344 Player->readyroom_listing_mode = MODE_CAMPAIGNS;
1346 Selected_line = Scroll_offset = 0;
1347 gamesnd_play_iface(SND_USER_SELECT);
1348 sim_room_build_listing();
1352 gamesnd_play_iface(SND_SWITCH_SCREENS);
1353 gameseq_post_event(GS_EVENT_OPTIONS_MENU);
1357 for (i=0; i<NUM_BUTTONS; i++){
1358 if (Buttons[gr_screen.res][i].button.pressed()){
1359 if (sim_room_button_pressed(i)){
1365 for (i=0; i<LIST_BUTTONS_MAX; i++) {
1366 if (List_buttons[i].is_mouse_on())
1367 select_tease_line = i + Scroll_offset;
1369 if (List_buttons[i].pressed()) {
1370 Selected_line = i + Scroll_offset;
1371 gamesnd_play_iface(SND_USER_SELECT);
1375 GR_MAYBE_CLEAR_RES(Background_bitmap);
1376 if (Background_bitmap >= 0) {
1377 gr_set_bitmap(Background_bitmap);
1383 for (i=TECH_DATABASE_BUTTON; i<=CREDITS_BUTTON; i++){
1384 if (Buttons[gr_screen.res][i].button.button_down()){
1389 if (i > CREDITS_BUTTON){
1390 Buttons[gr_screen.res][SIMULATOR_BUTTON].button.draw_forced(2);
1393 if (!Buttons[gr_screen.res][CAMPAIGN_TAB].button.button_down() && !Buttons[gr_screen.res][MISSION_TAB].button.button_down()) {
1394 if (Player->readyroom_listing_mode == MODE_CAMPAIGNS){
1395 Buttons[gr_screen.res][CAMPAIGN_TAB].button.draw_forced(2);
1396 } else if (Player->readyroom_listing_mode == MODE_MISSIONS){
1397 Buttons[gr_screen.res][MISSION_TAB].button.draw_forced(2);
1402 if (Player->readyroom_listing_mode == MODE_CAMPAIGNS) {
1403 gr_set_color_fast(&Color_text_heading);
1404 strcpy(buf, Campaign.name);
1405 gr_force_fit_string(buf, 255, list_w1);
1406 gr_printf(list_x1, Mission_list_coords[gr_screen.res][1], buf);
1408 if (Campaign.filename) {
1409 sprintf(buf, NOX("%s%s"), Campaign.filename, FS_CAMPAIGN_FILE_EXT);
1410 gr_force_fit_string(buf, 255, list_w2);
1411 gr_printf(list_x2, Mission_list_coords[gr_screen.res][1], buf);
1413 // blit the proper icons if necessary
1414 char full_name[256];
1415 memset(full_name, 0, 256);
1416 strcpy(full_name, cf_add_ext(Campaign.filename,FS_CAMPAIGN_FILE_EXT));
1417 fs_builtin_mission *fb = game_find_builtin_mission(full_name);
1419 // sim_room_blit_icons(0, Mission_list_coords[gr_screen.res][1], fb, 0);
1424 line = Scroll_offset;
1425 while (sim_room_line_query_visible(line)) {
1426 y = list_y + sim_room_lines[line].y - sim_room_lines[Scroll_offset].y;
1428 if (sim_room_lines[line].type != READYROOM_LINE_CAMPAIGN) {
1429 List_buttons[line - Scroll_offset].update_dimensions(list_x1, y, list_x2 + list_w2 - list_x1, font_height);
1430 List_buttons[line - Scroll_offset].enable();
1433 List_buttons[line - Scroll_offset].disable();
1435 if (line == Selected_line)
1436 gr_set_color_fast(&Color_text_selected);
1437 else if (line == select_tease_line)
1438 gr_set_color_fast(&Color_text_subselected);
1440 gr_set_color_fast(&Color_text_normal);
1442 strcpy(buf, sim_room_lines[line].name);
1443 gr_force_fit_string(buf, 255, list_x1 + list_w1 - sim_room_lines[line].x);
1444 gr_printf(sim_room_lines[line].x, y, buf);
1446 if (sim_room_lines[line].filename) {
1447 strcpy(buf, sim_room_lines[line].filename);
1448 gr_force_fit_string(buf, 255, list_w2);
1449 gr_printf(list_x2, y, buf);
1452 // blit additional icon information
1453 sim_room_blit_icons(line, y);
1458 i = line - Scroll_offset;
1459 while (i < LIST_BUTTONS_MAX)
1460 List_buttons[i++].disable();
1462 // blit help overlay if active
1463 help_overlay_maybe_blit(SIM_ROOM_OVERLAY);
1468 void sim_room_blit_icons(int line_index, int y_start, fs_builtin_mission *fb, int is_md)
1470 int is_from_volition = 0;
1472 // determine icon status
1474 is_from_volition = (sim_room_lines[line_index].flags & READYROOM_FLAG_FROM_VOLITION) ? 1 : 0;
1476 is_md = (sim_room_lines[line_index].flags & READYROOM_FLAG_FROM_MDISK) ? 1 : 0;
1479 is_from_volition = (fb->flags & FSB_FROM_VOLITION) ? 1 : 0;
1481 is_md = (fb->flags & FSB_FROM_MDISK) ? 1 : 0;
1485 // if the line is flagged as a volition file
1486 if(is_from_volition && (Mission_icon_bitmaps[MISSION_ICON_VOLITION] >= 0)){
1487 gr_set_bitmap(Mission_icon_bitmaps[MISSION_ICON_VOLITION]);
1488 gr_bitmap(Sim_volition_icon_x[gr_screen.res], y_start + MISSION_ICON_VOLITION_Y_OFFSET);
1492 if(is_md && (Mission_icon_bitmaps[MISSION_ICON_MDISK] >= 0)){
1493 gr_set_bitmap(Mission_icon_bitmaps[MISSION_ICON_MDISK]);
1494 gr_bitmap(Sim_silent_icon_x[gr_screen.res], y_start + MISSION_ICON_MDISK_Y_OFFSET);
1499 /// Campaign room stuff below
1500 int Cr_list_coords[GR_NUM_RESOLUTIONS][4] = {
1513 int Cr_info_coords[GR_NUM_RESOLUTIONS][4] = {
1526 #define CR_NUM_BUTTONS 6
1528 #define CR_SCROLL_UP_BUTTON 0
1529 #define CR_SCROLL_DOWN_BUTTON 1
1530 #define CR_SCROLL_INFO_UP_BUTTON 2
1531 #define CR_SCROLL_INFO_DOWN_BUTTON 3
1532 #define CR_RESET_BUTTON 4
1533 #define CR_COMMIT_BUTTON 5
1535 #define MAX_INFO_LINES 20
1537 #define MAX_INFO_LINE_LEN 256
1539 ui_button_info Cr_buttons[GR_NUM_RESOLUTIONS][CR_NUM_BUTTONS] = {
1542 ui_button_info("CAB_00", 0, 95, -1, -1, 0), // scroll up
1543 ui_button_info("CAB_01", 0, 142, -1, -1, 1), // scroll down
1544 ui_button_info("CAB_02", 17, 259, -1, -1, 2), // info scroll up
1545 ui_button_info("CAB_03", 17, 307, -1, -1, 3), // info scroll down
1546 ui_button_info("CAB_07", 545, 323, -1, -1, 7), // reset
1547 ui_button_info("CAB_04", 561, 411, -1, -1, 4), // select
1549 ui_button_info("CAB_00", 2, 42, -1, -1, 0),
1550 ui_button_info("CAB_01", 2, 89, -1, -1, 1),
1551 ui_button_info("CAB_02", 2, 279, -1, -1, 2),
1552 ui_button_info("CAB_03", 2, 325, -1, -1, 3),
1553 ui_button_info("CAB_04", 579, 353, -1, -1, 4),
1554 ui_button_info("CAB_05", 575, 434, -1, -1, 5),
1558 ui_button_info("2_CAB_00", 3, 68, -1, -1, 0),
1559 ui_button_info("2_CAB_01", 3, 142, -1, -1, 1),
1560 ui_button_info("2_CAB_02", 3, 446, -1, -1, 2),
1561 ui_button_info("2_CAB_03", 3, 520, -1, -1, 3),
1562 ui_button_info("2_CAB_04", 927, 565, -1, -1, 4),
1563 ui_button_info("2_CAB_05", 920, 694, -1, -1, 5),
1569 #define CR_NUM_TEXT 0
1571 #define CR_NUM_TEXT 3
1573 UI_XSTR Cr_text[GR_NUM_RESOLUTIONS][CR_NUM_TEXT] = {
1575 // not needed for FS1
1577 { "Restart", 1403, 569, 326, UI_XSTR_COLOR_GREEN, -1, &Cr_buttons[0][CR_RESET_BUTTON].button },
1578 { "Campaign", 1404, 569, 337, UI_XSTR_COLOR_GREEN, -1, &Cr_buttons[0][CR_RESET_BUTTON].button },
1579 { "Select", 1409, 568, 413, UI_XSTR_COLOR_PINK, -1, &Cr_buttons[0][CR_COMMIT_BUTTON].button },
1583 // not needed for FS1
1585 { "Restart", 1403, 922, 523, UI_XSTR_COLOR_GREEN, -1, &Cr_buttons[1][CR_RESET_BUTTON].button },
1586 { "Campaign", 1404, 922, 538, UI_XSTR_COLOR_GREEN, -1, &Cr_buttons[1][CR_RESET_BUTTON].button },
1587 { "Select", 1409, 921, 665, UI_XSTR_COLOR_PINK, -1, &Cr_buttons[1][CR_COMMIT_BUTTON].button },
1592 static int Num_desc_lines;
1593 static int Desc_scroll_offset;
1594 static int Selected_campaign_index;
1595 static int Active_campaign_index;
1597 char *Info_text_ptrs[MAX_INFO_LINES];
1598 int Num_info_lines, Info_text_line_size[MAX_INFO_LINES];
1600 void campaign_room_build_listing()
1602 int c, i, y, type, max_players;
1603 int font_height = gr_get_font_height();
1604 char name[NAME_LENGTH];
1607 if (!Campaign_names_inited) {
1608 for (i=0; i<Num_campaigns; i++) {
1609 Campaign_names[i] = NULL;
1610 if ( mission_campaign_get_info(Campaign_file_names[i], name, &type, &max_players) ) {
1612 if((game_find_builtin_mission(name) == NULL) && !strstr(name, "peterdrake")){
1615 Campaign_names[i] = strdup(name);
1618 if (type == CAMPAIGN_TYPE_SINGLE){
1619 Campaign_names[i] = strdup(name);
1625 Campaign_names_inited = 1;
1628 for (c=0; c<Num_campaigns; c++) {
1629 if (Campaign_names[c]) {
1631 // determine some extra information
1633 fs_builtin_mission *fb = game_find_builtin_mission(Campaign_file_names[c]);
1635 if(fb->flags & FSB_FROM_VOLITION){
1636 flags |= READYROOM_FLAG_FROM_VOLITION;
1639 if(fb->flags & FSB_FROM_MDISK){
1640 flags |= READYROOM_FLAG_FROM_MDISK;
1645 sim_room_line_add(READYROOM_LINE_CAMPAIGN, Campaign_names[c], Campaign_file_names[c], Cr_list_coords[gr_screen.res][0], y, flags);
1646 y += font_height + 2;
1651 void set_new_campaign_line(int n)
1655 Selected_campaign_index = n;
1656 str = Campaign_descs[Selected_campaign_index];
1659 Num_info_lines = split_str(str, Cr_info_coords[gr_screen.res][2], Info_text_line_size, Info_text_ptrs, MAX_INFO_LINES);
1660 Assert(Num_info_lines >= 0);
1663 Desc_scroll_offset = 0;
1666 void campaign_room_scroll_info_up()
1668 if (Desc_scroll_offset) {
1669 Desc_scroll_offset--;
1670 gamesnd_play_iface(SND_SCROLL);
1673 gamesnd_play_iface(SND_GENERAL_FAIL);
1676 void campaign_room_scroll_info_down()
1678 if ( (Num_info_lines - Desc_scroll_offset) * gr_get_font_height() > Cr_info_coords[gr_screen.res][3]) {
1679 Desc_scroll_offset++;
1680 gamesnd_play_iface(SND_SCROLL);
1683 gamesnd_play_iface(SND_GENERAL_FAIL);
1686 // returns: 0 = success, !0 = aborted or failed
1687 int campaign_room_reset_campaign(int n)
1692 // 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), Campaign_names[n]);
1693 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));
1695 filename = (char *) malloc(strlen(Campaign_file_names[n]) + 5);
1696 strcpy(filename, Campaign_file_names[n]);
1697 strcat(filename, FS_CAMPAIGN_FILE_EXT);
1699 mission_campaign_savefile_delete(filename);
1700 mission_campaign_load(filename);
1701 mission_campaign_next_mission();
1708 void campaign_room_commit()
1710 if (Selected_campaign_index < 0) {
1711 gamesnd_play_iface(SND_GENERAL_FAIL);
1715 if (stricmp(Campaign_file_names[Selected_campaign_index], Campaign.filename)) { // new campaign selected
1716 if ((Active_campaign_index >= 0) && campaign_room_reset_campaign(Active_campaign_index)) {
1717 gamesnd_play_iface(SND_GENERAL_FAIL);
1721 mission_campaign_savefile_delete(Campaign_file_names[Selected_campaign_index]);
1722 mission_campaign_load(Campaign_file_names[Selected_campaign_index]);
1723 strcpy(Player->current_campaign, Campaign.filename); // track new campaign for player
1726 if (mission_campaign_next_mission()) { // is campaign and next mission valid?
1727 gamesnd_play_iface(SND_GENERAL_FAIL);
1731 gameseq_post_event(GS_EVENT_MAIN_MENU);
1732 gamesnd_play_iface(SND_COMMIT_PRESSED);
1735 int campaign_room_button_pressed(int n)
1738 case CR_SCROLL_UP_BUTTON:
1739 sim_room_scroll_screen_up();
1742 case CR_SCROLL_DOWN_BUTTON:
1743 sim_room_scroll_screen_down();
1746 case CR_SCROLL_INFO_UP_BUTTON:
1747 campaign_room_scroll_info_up();
1750 case CR_SCROLL_INFO_DOWN_BUTTON:
1751 campaign_room_scroll_info_down();
1754 case CR_COMMIT_BUTTON:
1755 campaign_room_commit();
1759 case CR_HELP_BUTTON:
1760 launch_context_help();
1761 gamesnd_play_iface(SND_HELP_PRESSED);
1764 case CR_OPTIONS_BUTTON:
1765 gamesnd_play_iface(SND_SWITCH_SCREENS);
1766 gameseq_post_event(GS_EVENT_OPTIONS_MENU);
1770 case CR_RESET_BUTTON:
1771 if ( (Active_campaign_index < 0) || (Active_campaign_index >= Num_campaigns) )
1772 gamesnd_play_iface(SND_GENERAL_FAIL);
1773 else if (campaign_room_reset_campaign(Active_campaign_index))
1774 gamesnd_play_iface(SND_GENERAL_FAIL);
1776 gamesnd_play_iface(SND_USER_SELECT);
1784 void campaign_room_init()
1786 int i, j, load_failed;
1788 char wild_card[256];
1790 list_h = Mission_list_coords[gr_screen.res][3];
1793 common_set_interface_palette("InterfacePalette"); // set the interface palette
1795 Ui_window.create(0, 0, gr_screen.max_w, gr_screen.max_h, 0);
1796 Ui_window.set_mask_bmap(Campaign_mask_filename[gr_screen.res]);
1798 for (i=0; i<CR_NUM_BUTTONS; i++) {
1799 b = &Cr_buttons[gr_screen.res][i];
1801 b->button.create(&Ui_window, "", b->x, b->y, 60, 30, (i < 2), 1);
1802 // set up callback for when a mouse first goes over a button
1803 b->button.set_highlight_action(common_play_highlight_sound);
1804 b->button.set_bmaps(b->filename);
1805 b->button.link_hotspot(b->hotspot);
1808 for (i=0; i<LIST_BUTTONS_MAX; i++) {
1809 List_buttons[i].create(&Ui_window, "", 0, 0, 60, 30, 0, 1);
1810 List_buttons[i].hide();
1811 List_buttons[i].disable();
1815 for(i=0; i<CR_NUM_TEXT; i++){
1816 Ui_window.add_XSTR(&Cr_text[gr_screen.res][i]);
1819 // set up sim_rooms for buttons so we draw the correct animation frame when a key is pressed
1820 Cr_buttons[gr_screen.res][CR_SCROLL_UP_BUTTON].button.set_hotkey(KEY_PAGEUP);
1821 Cr_buttons[gr_screen.res][CR_SCROLL_DOWN_BUTTON].button.set_hotkey(KEY_PAGEDOWN);
1822 Cr_buttons[gr_screen.res][CR_RESET_BUTTON].button.set_hotkey(KEY_DELETE);
1823 Cr_buttons[gr_screen.res][CR_COMMIT_BUTTON].button.set_hotkey(KEY_CTRLED | KEY_ENTER);
1824 // Cr_buttons[gr_screen.res][CR_HELP_BUTTON].button.set_hotkey(KEY_F2);
1826 Background_bitmap = bm_load(Campaign_filename[gr_screen.res]);
1828 // load in help overlay bitmap
1829 help_overlay_load(CAMPAIGN_ROOM_OVERLAY);
1830 help_overlay_set_state(CAMPAIGN_ROOM_OVERLAY,0);
1834 Desc_scroll_offset = Scroll_offset = 0;
1835 load_failed = mission_load_up_campaign();
1837 mission_campaign_next_mission();
1840 Campaign.filename[0] = 0;
1841 Campaign.num_missions = 0;
1846 Get_file_list_filter = campaign_room_campaign_filter;
1847 memset(wild_card, 0, 256);
1848 strcpy(wild_card, NOX("*"));
1849 strcat(wild_card, FS_CAMPAIGN_FILE_EXT);
1850 Num_campaigns = cf_get_file_list(MAX_CAMPAIGNS, Campaign_file_names, CF_TYPE_MISSIONS, wild_card, CF_SORT_NAME);
1852 for (i=0; i<Num_campaigns; i++) {
1853 for (j=0; j<Num_campaigns; j++) {
1854 if (Campaign_file_names_temp[j]) {
1855 if (!strncmp(Campaign_file_names[i], Campaign_file_names_temp[j], strlen(Campaign_file_names_temp[j]) - 4)) {
1856 Campaign_descs[i] = Campaign_descs_temp[j];
1857 free(Campaign_file_names_temp[j]);
1858 Campaign_file_names_temp[j] = NULL;
1864 Assert(j < Num_campaigns); // Campaign not found? How is that possible?
1867 Campaign_names_inited = 0;
1868 campaign_room_build_listing();
1870 Selected_campaign_index = Active_campaign_index = -1;
1872 for (i=0; i<Num_campaigns; i++)
1873 if (!stricmp(Campaign_file_names[i], Campaign.filename)) {
1874 set_new_campaign_line(i);
1875 Active_campaign_index = i;
1881 void campaign_room_close()
1885 for (i=0; i<Num_campaigns; i++)
1886 if (Campaign_descs[i])
1887 free(Campaign_descs[i]);
1889 if (Background_bitmap >= 0)
1890 bm_unload(Background_bitmap);
1892 if (Campaign_names_inited)
1893 for (i=0; i<Num_campaigns; i++)
1894 if (Campaign_names[i])
1895 free(Campaign_names[i]);
1897 for (i=0; i<Num_campaigns; i++)
1898 free(Campaign_file_names[i]);
1900 // unload the overlay bitmap
1901 help_overlay_unload(CAMPAIGN_ROOM_OVERLAY);
1903 Ui_window.destroy();
1904 common_free_interface_palette(); // restore game palette
1908 void campaign_room_do_frame(float frametime)
1911 char line_text[MAX_INFO_LINE_LEN];
1913 int font_height = gr_get_font_height();
1914 int select_tease_line = -1; // line mouse is down on, but won't be selected until button released
1916 if ( help_overlay_active(CAMPAIGN_ROOM_OVERLAY) ) {
1917 // Cr_buttons[gr_screen.res][CR_HELP_BUTTON].button.reset_status();
1918 Ui_window.set_ignore_gadgets(1);
1921 k = Ui_window.process() & ~KEY_DEBUGGED;
1923 if ( (k > 0) || B1_JUST_RELEASED ) {
1924 if ( help_overlay_active(CAMPAIGN_ROOM_OVERLAY) ) {
1925 help_overlay_set_state(CAMPAIGN_ROOM_OVERLAY, 0);
1926 Ui_window.set_ignore_gadgets(0);
1931 if ( !help_overlay_active(CAMPAIGN_ROOM_OVERLAY) ) {
1932 Ui_window.set_ignore_gadgets(0);
1936 case KEY_DOWN: // scroll list down
1937 if (Selected_campaign_index < Num_campaigns - 1) {
1938 set_new_campaign_line(Selected_campaign_index + 1);
1939 gamesnd_play_iface(SND_SCROLL);
1942 gamesnd_play_iface(SND_GENERAL_FAIL);
1946 case KEY_UP: // scroll list up
1947 if (Selected_campaign_index < 0)
1948 Selected_campaign_index = 1;
1950 if (Selected_campaign_index) {
1951 set_new_campaign_line(Selected_campaign_index - 1);
1952 gamesnd_play_iface(SND_SCROLL);
1955 gamesnd_play_iface(SND_GENERAL_FAIL);
1960 gameseq_post_event(GS_EVENT_MAIN_MENU);
1964 for (i=0; i<CR_NUM_BUTTONS; i++){
1965 if (Cr_buttons[gr_screen.res][i].button.pressed()){
1966 if (campaign_room_button_pressed(i)){
1972 for (i=0; i<LIST_BUTTONS_MAX; i++) {
1973 if (List_buttons[i].is_mouse_on()){
1974 select_tease_line = i + Scroll_offset;
1977 if (List_buttons[i].pressed()) {
1978 set_new_campaign_line(i + Scroll_offset);
1979 gamesnd_play_iface(SND_USER_SELECT);
1983 GR_MAYBE_CLEAR_RES(Background_bitmap);
1984 if (Background_bitmap >= 0) {
1985 gr_set_bitmap(Background_bitmap);
1992 line = Scroll_offset;
1993 while (sim_room_line_query_visible(line)) {
1994 y = Cr_list_coords[gr_screen.res][1] + sim_room_lines[line].y - sim_room_lines[Scroll_offset].y;
1996 List_buttons[line - Scroll_offset].update_dimensions(Cr_list_coords[gr_screen.res][0], y, Cr_list_coords[gr_screen.res][2], font_height);
1997 List_buttons[line - Scroll_offset].enable();
1999 if (!stricmp(sim_room_lines[line].filename, Campaign.filename)) {
2000 gr_set_color_fast(&Color_white);
2001 i = y + font_height / 2 - 1;
2002 gr_circle(Cr_list_coords[gr_screen.res][0] - 6, i, 5);
2004 gr_set_color_fast(&Color_bright_white);
2005 gr_line(Cr_list_coords[gr_screen.res][0] - 10, i, Cr_list_coords[gr_screen.res][0] - 8, i);
2006 gr_line(Cr_list_coords[gr_screen.res][0] - 6, i - 4, Cr_list_coords[gr_screen.res][0] - 6, i - 2);
2007 gr_line(Cr_list_coords[gr_screen.res][0] - 4, i, Cr_list_coords[gr_screen.res][0] - 2, i);
2008 gr_line(Cr_list_coords[gr_screen.res][0] - 6, i + 2, Cr_list_coords[gr_screen.res][0] - 6, i + 4);
2011 if (line == Selected_campaign_index)
2012 gr_set_color_fast(&Color_text_selected);
2013 else if (line == select_tease_line)
2014 gr_set_color_fast(&Color_text_subselected);
2016 gr_set_color_fast(&Color_text_normal);
2018 strcpy(buf, sim_room_lines[line].name);
2019 gr_force_fit_string(buf, 255, Cr_list_coords[gr_screen.res][0] + Cr_list_coords[gr_screen.res][2] - sim_room_lines[line].x);
2020 gr_printf(sim_room_lines[line].x, y, buf);
2024 i = line - Scroll_offset;
2025 while (i < LIST_BUTTONS_MAX)
2026 List_buttons[i++].disable();
2029 i = Desc_scroll_offset;
2030 gr_set_color_fast(&Color_text_normal);
2032 while (y + font_height <= Cr_info_coords[gr_screen.res][3]) {
2033 if (i >= Num_info_lines)
2036 Assert(Info_text_line_size[i] < MAX_INFO_LINE_LEN);
2037 strncpy(line_text, Info_text_ptrs[i], Info_text_line_size[i]);
2038 line_text[Info_text_line_size[i]] = 0;
2039 drop_white_space(line_text);
2040 gr_string(Cr_info_coords[gr_screen.res][0], Cr_info_coords[gr_screen.res][1] + y, line_text);
2045 // blit help overlay if active
2046 help_overlay_maybe_blit(CAMPAIGN_ROOM_OVERLAY);
2051 void sim_room_load_mission_icons()
2056 for(idx=0; idx<NUM_MISSION_ICONS; idx++){
2057 Mission_icon_bitmaps[idx] = -1;
2058 Mission_icon_bitmaps[idx] = bm_load(Mission_icon_bitmap_filenames[idx]);
2062 void sim_room_unload_mission_icons()
2066 // unload all bitmaps
2067 for(idx=0; idx<NUM_MISSION_ICONS; idx++){
2068 if(Mission_icon_bitmaps[idx] >= 0){
2069 bm_unload(Mission_icon_bitmaps[idx]);
2070 Mission_icon_bitmaps[idx] = -1;