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.3 2002/06/09 04:41:22 relnev
19 * added copyright header
21 * Revision 1.2 2002/06/02 04:26:34 relnev
24 * Revision 1.1.1.1 2002/05/03 03:28:09 root
28 * 20 9/30/99 5:59p Jefff
29 * fixed compile error in OEM ver
31 * 19 9/08/99 12:28p Jefff
33 * 18 9/06/99 6:38p Dave
34 * Improved CD detection code.
36 * 17 9/02/99 2:33p Jefff
37 * column heading coordinate changes
39 * 16 8/22/99 4:16p Jefff
40 * scroll button coord fixes
42 * 15 7/20/99 1:49p Dave
43 * Peter Drake build. Fixed some release build warnings.
45 * 14 7/19/99 2:13p Dave
46 * Added some new strings for Heiko.
48 * 13 7/15/99 9:20a Andsager
49 * FS2_DEMO initial checkin
51 * 12 7/09/99 5:54p Dave
52 * Seperated cruiser types into individual types. Added tons of new
53 * briefing icons. Campaign screen.
55 * 11 2/01/99 5:55p Dave
56 * Removed the idea of explicit bitmaps for buttons. Fixed text
57 * highlighting for disabled gadgets.
59 * 10 1/30/99 9:01p Dave
62 * 9 1/30/99 5:08p Dave
63 * More new hi-res stuff.Support for nice D3D textures.
65 * 8 1/29/99 12:47a Dave
66 * Put in sounds for beam weapon. A bunch of interface screens (tech
69 * 7 12/11/98 4:35p Andsager
70 * Fix sim room bug when no standalone missions
72 * 6 12/07/98 5:02p Dan
73 * Removed improper use of bitmap filename with extension,
75 * 5 10/13/98 9:28a Dave
76 * Started neatening up freespace.h. Many variables renamed and
77 * reorganized. Added AlphaColors.[h,cpp]
91 #include "gamesequence.h"
92 #include "missioncampaign.h"
95 #include "missionscreencommon.h"
96 #include "freespace.h"
97 #include "missionparse.h"
99 #include "managepilot.h"
101 #include "contexthelp.h"
102 #include "cfilesystem.h"
103 #include "freespace.h"
104 #include "alphacolors.h"
106 #define MAX_MISSIONS 1024
108 int Mission_list_coords[GR_NUM_RESOLUTIONS][4] = {
117 int Campaign_list_coords[GR_NUM_RESOLUTIONS][4] = {
127 // x coordinate offsets for data when campaign tab active
129 #define C_SUBTEXT_X 19
131 // x coordinate offsets for data when mission tab active
134 #define MODE_CAMPAIGNS 0
135 #define MODE_MISSIONS 1
137 #define MAX_LINES 200
138 #define MAX_DESC_LINES 200
139 #define NUM_BUTTONS 11
140 #define LIST_BUTTONS_MAX 40
142 #define SCROLL_UP_BUTTON 0
143 #define SCROLL_DOWN_BUTTON 1
144 #define MISSION_TAB 2
145 #define CAMPAIGN_TAB 3
146 #define HELP_BUTTON 4
147 #define COMMIT_BUTTON 5
148 #define OPTIONS_BUTTON 6
149 #define TECH_DATABASE_BUTTON 7
150 #define SIMULATOR_BUTTON 8
151 #define CUTSCENES_BUTTON 9
152 #define CREDITS_BUTTON 10
154 #define CAMPAIGN_MISSION_HASH_SIZE 307
156 struct sim_room_buttons {
160 UI_BUTTON button; // because we have a class inside this struct, we need the constructor below..
162 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) {}
165 static sim_room_buttons Buttons[GR_NUM_RESOLUTIONS][NUM_BUTTONS] = {
168 sim_room_buttons("LMB_04", 1, 99, -1, -1, 4),
169 sim_room_buttons("LMB_05", 1, 381, -1, -1, 5),
170 sim_room_buttons("LMB_06", 6, 438, 40, 445, 6),
171 sim_room_buttons("LMB_07", 6, 457, 40, 462, 7),
172 sim_room_buttons("LMB_08", 534, 426, 500, 440, 8),
173 sim_room_buttons("LMB_09", 571, 426, 572, 413, 9),
174 sim_room_buttons("LMB_10", 534, 455, 480, 462, 10),
176 sim_room_buttons("TDB_00", 7, 3, 37, 7, 0),
177 sim_room_buttons("TDB_01", 7, 18, 37, 23, 1),
178 sim_room_buttons("TDB_02", 7, 34, 37, 38, 2),
179 sim_room_buttons("TDB_03", 7, 49, 37, 54, 3),
182 sim_room_buttons("2_LMB_04", 2, 159, -1, -1, 4),
183 sim_room_buttons("2_LMB_05", 2, 609, -1, -1, 5),
184 sim_room_buttons("2_LMB_06", 10, 701, 64, 712, 6),
185 sim_room_buttons("2_LMB_07", 10, 732, 64, 739, 7),
186 sim_room_buttons("2_LMB_08", 854, 681, 800, 704, 8),
187 sim_room_buttons("2_LMB_09", 914, 681, 915, 660, 9),
188 sim_room_buttons("2_LMB_10", 854, 728, 800, 728, 10),
190 sim_room_buttons("2_TDB_00", 12, 5, 59, 12, 0),
191 sim_room_buttons("2_TDB_01", 12, 31, 59, 37, 1),
192 sim_room_buttons("2_TDB_02", 12, 56, 59, 62, 2),
193 sim_room_buttons("2_TDB_03", 12, 81, 59, 88, 3),
198 char *Sim_filename[GR_NUM_RESOLUTIONS] = {
202 char *Sim_mask_filename[GR_NUM_RESOLUTIONS] = {
207 char *Campaign_filename[GR_NUM_RESOLUTIONS] = {
211 char *Campaign_mask_filename[GR_NUM_RESOLUTIONS] = {
216 // misc text. ("Mission" and "Filename"
217 #define NUM_SIM_MISC_TEXT 2
218 #define SIM_MISC_TEXT_MISSION 0
219 #define SIM_MISC_TEXT_FILENAME 1
220 int Sim_misc_text_coords[GR_NUM_RESOLUTIONS][NUM_SIM_MISC_TEXT][2] = {
231 // readyroom text line stuff
232 #define READYROOM_LINE_CAMPAIGN 1
233 #define READYROOM_LINE_CMISSION 2
234 #define READYROOM_LINE_MISSION 3
236 #define READYROOM_FLAG_FROM_VOLITION (1<<0) // volition made
238 int type; // see READYROOM_LINE_* defines above
241 int x; // X coordinate of line
242 int y; // Y coordinate of line
243 int flags; // special flags, see READYROOM_FLAG_* defines above
244 } sim_room_lines[MAX_LINES];
246 static char Cur_campaign[MAX_FILENAME_LEN];
247 static char *Mission_filenames[MAX_MISSIONS];
248 static char *Standalone_mission_names[MAX_MISSIONS];
249 static int Standalone_mission_flags[MAX_MISSIONS];
250 static char *Campaign_missions[MAX_MISSIONS];
251 static char *Campaign_mission_names[MAX_CAMPAIGN_MISSIONS];
252 static int Campaign_mission_flags[MAX_MISSIONS];
253 static char *Campaign_descs[MAX_CAMPAIGNS];
254 static char *Campaign_descs_temp[MAX_CAMPAIGNS];
255 static char *Campaign_file_names_temp[MAX_CAMPAIGNS];
256 static int Standalone_mission_names_inited = 0;
257 static int Campaign_names_inited = 0;
258 static int Campaign_mission_names_inited = 0;
259 static int Num_standalone_missions;
260 static int Num_campaign_missions;
261 static int Scroll_offset;
262 static int Selected_line;
263 static int Num_lines;
264 static int Num_campaign_missions_with_info = 0;
265 static int Num_standalone_missions_with_info = 0;
272 static int Background_bitmap;
273 static UI_WINDOW Ui_window;
274 static UI_BUTTON List_buttons[LIST_BUTTONS_MAX]; // buttons for each line of text in list
276 typedef struct hash_node {
281 static hash_node *Campaign_mission_hash_table[CAMPAIGN_MISSION_HASH_SIZE];
282 static int Hash_table_inited;
284 // special icons (1.04 + stuff)
285 #define NUM_MISSION_ICONS 1
286 #define MISSION_ICON_VOLITION 0 // mini volition death's head :)
288 // icon offsets (see LIST_ defines above
289 //#define MISSION_ICON_VOLITION_X (46)
290 #define MISSION_ICON_VOLITION_Y_OFFSET (-1)
293 static int Sim_volition_icon_x[GR_NUM_RESOLUTIONS] = {
298 // special icons themselves
299 int Mission_icon_bitmaps[NUM_MISSION_ICONS];
301 char *Mission_icon_bitmap_filenames[NUM_MISSION_ICONS] = {
305 void sim_room_load_mission_icons();
306 void sim_room_unload_mission_icons();
307 void sim_room_blit_icons(int line_index, int y_start, fs_builtin_mission *fb = NULL, int is_md = 0);
309 // Finds a hash value for mission filename
311 // returns hash value
312 int hash_filename(char *filename) {
313 unsigned __int64 hash_val = 0;
314 char *ptr = filename;
316 // Dont hash .fsm extension, convert all to upper case
317 for (int i=0; i < ((signed int)(strlen(filename)) - 4); i++) {
318 hash_val = (hash_val << 4) + toupper(*ptr++);
321 return int(hash_val % CAMPAIGN_MISSION_HASH_SIZE);
324 // insert filename into Campaign_mission_hash_table
326 // returns 1 if successful, 0 if could not allocate memory
327 int hash_insert(char *filename) {
328 int hash_val = hash_filename(filename);
331 // Check if table empty
332 if (Campaign_mission_hash_table[hash_val] == NULL) {
333 Campaign_mission_hash_table[hash_val] = new hash_node;
335 cur_node = Campaign_mission_hash_table[hash_val];
337 if (cur_node == NULL) {
338 // Unable to allocate memory
342 // Walk down list to first empty node
343 cur_node = Campaign_mission_hash_table[hash_val];
344 while (cur_node->next != NULL) {
345 cur_node = cur_node->next;
349 cur_node->next = new hash_node;
351 if (cur_node->next == NULL) {
352 // unable to allocate memory
355 cur_node = cur_node->next;
360 cur_node->next = NULL;
361 cur_node->filename = filename;
367 // Checks if a filename already exitst in the hash table
369 // returns 1 if found (collision), 0 if no collision
370 int campaign_mission_hash_collision(char *filename)
372 int hash_val = hash_filename(filename);
373 hash_node *cur_node = Campaign_mission_hash_table[hash_val];
375 if (cur_node == NULL) {
380 if (!stricmp(filename, cur_node->filename)) {
384 cur_node = cur_node->next;
385 } while (cur_node != NULL);
387 // Ran out of stuff to check
391 // builds hash table of campaign mission filenames
393 // returns 1 if successful, 0 if not successful
394 int build_campaign_mission_filename_hash_table()
397 // Go through all campaign missions
398 for (int i=0; i<Num_campaign_missions; i++) {
399 rval = hash_insert(Campaign_missions[i]);
409 // deletes hash table nodes
411 void campaign_mission_hash_table_delete()
415 for (int i=0; i<CAMPAIGN_MISSION_HASH_SIZE; i++) {
416 // Look for entries into array
417 if (Campaign_mission_hash_table[i] != NULL) {
418 cur_node = Campaign_mission_hash_table[i];
420 // Walk down the list deleting self
421 while (cur_node->next != NULL) {
422 hash_node *temp = cur_node->next;
429 Campaign_mission_hash_table[i] = NULL;
435 // add a line of sim_room smuck to end of list
436 int sim_room_line_add(int type, char *name, char *filename, int x, int y, int flags)
438 if (Num_lines >= MAX_LINES)
441 sim_room_lines[Num_lines].type = type;
442 sim_room_lines[Num_lines].name = name;
443 sim_room_lines[Num_lines].filename = filename;
444 sim_room_lines[Num_lines].x = x;
445 sim_room_lines[Num_lines].y = y;
446 sim_room_lines[Num_lines].flags = flags;
450 // filter out all multiplayer campaigns
451 int campaign_room_campaign_filter(char *filename)
453 int type, max_players;
454 char name[NAME_LENGTH], *desc = NULL;
457 // also need to check if this is the builtin campaign
458 if ( game_find_builtin_mission(filename) && mission_campaign_get_info(filename, name, &type, &max_players, &desc) ) {
460 if ( mission_campaign_get_info(filename, name, &type, &max_players, &desc) ) {
462 if ( type == CAMPAIGN_TYPE_SINGLE ) {
463 Campaign_file_names_temp[Num_campaigns] = strdup(filename);
464 Campaign_descs_temp[Num_campaigns++] = desc;
476 // build up a list of all missions in all campaigns.
477 int sim_room_campaign_mission_filter(char *filename)
481 num = mission_campaign_get_mission_list(filename, &Campaign_missions[Num_campaign_missions], MAX_CAMPAIGN_MISSIONS - Num_campaign_missions);
485 Num_campaign_missions += num;
489 // filter out all missions already used in existing campaigns
490 int sim_room_standalone_mission_filter(char *filename)
493 char mission_name[255];
495 // Check if a campaign mission (single and multi)
496 if (campaign_mission_hash_collision(filename)) {
500 // Check if a standalone multi mission OR Mdisk mission with data
501 type = mission_parse_is_multi(filename, mission_name);
502 if (type && !(type & MISSION_TYPE_SINGLE))
508 // builds up list of standalone missions and adds them to missions simulator
509 // processes one mission per frame
511 // returns 1 if finished with all missions, 0 otherwise
513 int build_standalone_mission_list_do_frame()
515 int font_height = gr_get_font_height();
516 char filename[MAX_FILENAME_LEN];
519 // When no standalone missions in data directory
520 if (Num_standalone_missions == 0) {
521 Standalone_mission_names_inited = 1;
525 // Set global variable so we we'll have list available next time
526 Standalone_mission_names[Num_standalone_missions_with_info] = NULL;
527 Standalone_mission_flags[Num_standalone_missions_with_info] = 0;
529 if (Num_standalone_missions > 0) { // sanity check
530 if (strlen(Mission_filenames[Num_standalone_missions_with_info]) < MAX_FILENAME_LEN - 4) { // sanity check?
531 strcpy(filename, Mission_filenames[Num_standalone_missions_with_info]);
535 sprintf(str, XSTR("Single Mission\n\n%s",989), filename);
536 popup_change_text(str);
538 // tack on an extension
539 strcat(filename, FS_MISSION_FILE_EXT);
540 if (!get_mission_info(filename)) {
541 Standalone_mission_names[Num_standalone_missions_with_info] = strdup(The_mission.name);
542 Standalone_mission_flags[Num_standalone_missions_with_info] = The_mission.game_type;
543 int y = Num_lines * (font_height + 2);
545 // determine some extra information
547 fs_builtin_mission *fb = game_find_builtin_mission(filename);
548 if((fb != NULL) && (fb->flags & FSB_FROM_VOLITION)){
549 flags |= READYROOM_FLAG_FROM_VOLITION;
553 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);
557 Num_standalone_missions_with_info++;
560 if (Num_standalone_missions_with_info == Num_standalone_missions) {
561 Standalone_mission_names_inited = 1;
568 // builds up list of already played missions in a campaign and adds them to missions simulator
569 // processes one mission per frame
571 // returns 1 if finished with all missions, 0 otherwise
573 int build_campaign_mission_list_do_frame()
575 int font_height = gr_get_font_height();
578 // When no campaign files in data directory
579 if (Campaign.num_missions == 0) {
580 Campaign_mission_names_inited = 1;
586 sprintf(str, XSTR("Campaign Mission\n\n%s",990), Campaign.missions[Num_campaign_missions_with_info].name);
587 popup_change_text(str);
589 // Set global variable so we we'll have list available next time
590 Campaign_mission_names[Num_campaign_missions_with_info] = NULL;
591 Campaign_mission_flags[Num_campaign_missions_with_info] = 0;
593 // Only allow missions already completed
594 if (Campaign.missions[Num_campaign_missions_with_info].completed) {
595 if (!get_mission_info(Campaign.missions[Num_campaign_missions_with_info].name)) {
597 Campaign_mission_names[Num_campaign_missions_with_info] = strdup(The_mission.name);
598 Campaign_mission_flags[Num_campaign_missions_with_info] = The_mission.game_type;
599 int y = Num_campaign_missions_with_info * (font_height + 2);
601 // determine some extra information
603 fs_builtin_mission *fb = game_find_builtin_mission(Campaign.missions[Num_campaign_missions_with_info].name);
604 if((fb != NULL) && (fb->flags & FSB_FROM_VOLITION)){
605 flags |= READYROOM_FLAG_FROM_VOLITION;
608 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);
612 Num_campaign_missions_with_info++;
614 if (Num_campaign_missions_with_info == Campaign.num_missions) {
615 Campaign_mission_names_inited = 1;
622 // Builds list of either (1) standalone missions or (2) already played missions in current campaign
623 // First time through, it builds list, next time it uses precompiled list
624 void sim_room_build_listing()
627 int font_height = gr_get_font_height();
628 char full_filename[256];
631 list_y = Mission_list_coords[gr_screen.res][1];
632 list_h = Mission_list_coords[gr_screen.res][3];
634 // Stand alone single player missions.
635 if (Player->readyroom_listing_mode == MODE_MISSIONS) {
636 if (Hash_table_inited) {
637 if (!Standalone_mission_names_inited) { // Is this the first time through
638 // build_list_do_frame builds list and adds sim room line and sets Standalone_mission_names_inited
639 popup_till_condition(build_standalone_mission_list_do_frame, POPUP_CANCEL, XSTR("Loading missions", 991) );
641 for (i=0; i<Num_standalone_missions_with_info; i++) {
642 if (Standalone_mission_names[i]) {
643 // determine some extra information
645 memset(full_filename, 0, 256);
646 strcpy(full_filename, cf_add_ext(Mission_filenames[i], FS_MISSION_FILE_EXT));
647 fs_builtin_mission *fb = game_find_builtin_mission(full_filename);
648 if((fb != NULL) && (fb->flags & FSB_FROM_VOLITION)){
649 flags |= READYROOM_FLAG_FROM_VOLITION;
652 sim_room_line_add(READYROOM_LINE_MISSION, Standalone_mission_names[i], Mission_filenames[i], list_x1 + M_TEXT_X, y, flags);
653 y += font_height + 2;
660 list_y += font_height + 2;
661 list_h -= font_height - 2;
663 if (!Campaign_mission_names_inited) { // Is this the first time through
664 popup_till_condition(build_campaign_mission_list_do_frame, POPUP_CANCEL, XSTR("Loading campaign missions",992));
665 // builds list, adds sim room line and sets Campaign_mission_names_inited
667 for (i=0; i<Num_campaign_missions_with_info; i++) {
668 if (Campaign_mission_names[i]) {
669 // determine some extra information
671 memset(full_filename, 0, 256);
672 strcpy(full_filename, cf_add_ext(Campaign.missions[i].name, FS_MISSION_FILE_EXT));
673 fs_builtin_mission *fb = game_find_builtin_mission(full_filename);
674 if((fb != NULL) && (fb->flags & FSB_FROM_VOLITION)){
675 flags |= READYROOM_FLAG_FROM_VOLITION;
678 sim_room_line_add(READYROOM_LINE_CMISSION, Campaign_mission_names[i], Campaign.missions[i].name, list_x1 + C_SUBTEXT_X, y, flags);
686 int sim_room_line_query_visible(int n)
690 if ((n < 0) || (n >= Num_lines))
693 y = sim_room_lines[n].y - sim_room_lines[Scroll_offset].y;
694 if ((y < 0) || (y + gr_get_font_height() > list_h))
700 void sim_room_scroll_screen_up()
702 if (Player->readyroom_listing_mode != MODE_MISSIONS) {
705 gamesnd_play_iface(SND_SCROLL);
708 gamesnd_play_iface(SND_GENERAL_FAIL);
715 Assert(Selected_line > Scroll_offset);
716 while (!sim_room_line_query_visible(Selected_line))
719 gamesnd_play_iface(SND_SCROLL);
722 gamesnd_play_iface(SND_GENERAL_FAIL);
725 void sim_room_scroll_line_up()
729 if (Selected_line < Scroll_offset)
730 Scroll_offset = Selected_line;
732 gamesnd_play_iface(SND_SCROLL);
735 gamesnd_play_iface(SND_GENERAL_FAIL);
738 void sim_room_scroll_screen_down()
740 if (Player->readyroom_listing_mode != MODE_MISSIONS) {
741 if (sim_room_lines[Num_lines - 1].y + gr_get_font_height() > sim_room_lines[Scroll_offset].y + list_h) {
743 gamesnd_play_iface(SND_SCROLL);
746 gamesnd_play_iface(SND_GENERAL_FAIL);
751 if (sim_room_lines[Num_lines - 1].y + gr_get_font_height() > sim_room_lines[Scroll_offset].y + list_h) {
753 while (!sim_room_line_query_visible(Selected_line)) {
755 Assert(Selected_line < Num_lines);
758 gamesnd_play_iface(SND_SCROLL);
761 gamesnd_play_iface(SND_GENERAL_FAIL);
764 void sim_room_scroll_line_down()
766 if (Selected_line < Num_lines - 1) {
769 Assert(Selected_line > Scroll_offset);
770 while (!sim_room_line_query_visible(Selected_line))
773 gamesnd_play_iface(SND_SCROLL);
776 gamesnd_play_iface(SND_GENERAL_FAIL);
779 // returns: 0 = success, !0 = aborted or failed
780 int ready_room_reset_campaign()
784 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) );
787 mission_campaign_savefile_delete(Campaign.filename);
788 mission_campaign_load(Campaign.filename);
795 // Decide if we should offer choice to resume this savegame
796 int sim_room_can_resume_savegame(char *savegame_filename)
798 #ifdef FREESPACE_SAVERESTORE_SYSTEM
799 char savegame_mission[MAX_FILENAME_LEN];
801 if (state_read_description(savegame_filename, NULL, savegame_mission)) {
805 if (stricmp(Game_current_mission_filename, savegame_mission)) {
815 // Decide wether to resume a save game or not
816 // exit: 1 => savegame has been restored
817 // 0 => no restore, proceed to briefing
818 // -1 => don't start mission at all
819 int sim_room_maybe_resume_savegame()
821 // MWA -- 3/26/98 -- removed all savegame references in game
825 char savegame_filename[_MAX_FNAME];
826 int popup_rval = -1, resume_savegame = 0;
828 // Generate the save-game filename for this campaign
829 memset(savegame_filename, 0, _MAX_FNAME);
830 mission_campaign_savefile_generate_root(savegame_filename);
831 strcat(savegame_filename, NOX("svg"));
833 // Decide if we should offer choice to resume this savegame
834 if ( sim_room_can_resume_savegame(savegame_filename) ) {
835 popup_rval = popup(0, 3, XSTR("&Cancel",-1), XSTR("&Overwrite",-1), XSTR("&Resume",-1), XSTR("A save game for this mission exists.", -1));
836 switch ( popup_rval ) {
839 resume_savegame = -1;
849 resume_savegame = -1;
856 if (resume_savegame == 1) {
857 if ( state_restore_all(savegame_filename) == -1 ) {
858 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));
859 if (popup_rval == 1) {
862 resume_savegame = -1;
870 // If we are resuming this savegame, then delete the file
871 if (resume_savegame == 1) {
872 cf_delete(savegame_filename);
875 return resume_savegame;
879 int readyroom_continue_campaign()
881 if (mission_campaign_next_mission()) { // is campaign and next mission valid?
884 int reset_campaign = 0;
885 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) );
886 if ( reset_campaign == 1 ) {
887 mission_campaign_savefile_delete(Campaign.filename);
888 mission_campaign_load(Campaign.filename);
889 mission_campaign_next_mission();
894 gamesnd_play_iface(SND_GENERAL_FAIL);
895 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) );
901 if(!game_do_cd_mission_check(Game_current_mission_filename)){
905 // set the bit for campaign mode
906 Game_mode |= GM_CAMPAIGN_MODE;
907 gameseq_post_event( GS_EVENT_START_GAME );
912 void sim_room_commit()
914 if ((Selected_line >= Num_lines) || !sim_room_lines[Selected_line].filename) {
915 gamesnd_play_iface(SND_GENERAL_FAIL);
919 strncpy(Game_current_mission_filename, sim_room_lines[Selected_line].filename, MAX_FILENAME_LEN);
921 Game_mode &= ~(GM_CAMPAIGN_MODE); // be sure this bit is clear
924 if(game_do_cd_mission_check(Game_current_mission_filename)){
925 // don't resume savegame, proceed to briefing
926 gameseq_post_event(GS_EVENT_START_GAME);
927 gamesnd_play_iface(SND_COMMIT_PRESSED);
931 int sim_room_button_pressed(int n)
934 case SCROLL_UP_BUTTON:
935 sim_room_scroll_screen_up();
938 case SCROLL_DOWN_BUTTON:
939 sim_room_scroll_screen_down();
944 game_feature_not_in_demo_popup();
945 // gamesnd_play_iface(SND_GENERAL_FAIL);
948 Player->readyroom_listing_mode = MODE_MISSIONS;
949 Selected_line = Scroll_offset = 0;
950 gamesnd_play_iface(SND_USER_SELECT);
951 sim_room_build_listing();
956 Player->readyroom_listing_mode = MODE_CAMPAIGNS;
958 gamesnd_play_iface(SND_USER_SELECT);
959 sim_room_build_listing();
967 launch_context_help();
968 gamesnd_play_iface(SND_HELP_PRESSED);
972 gamesnd_play_iface(SND_SWITCH_SCREENS);
973 gameseq_post_event(GS_EVENT_OPTIONS_MENU);
976 case TECH_DATABASE_BUTTON:
977 gamesnd_play_iface(SND_SWITCH_SCREENS);
978 gameseq_post_event(GS_EVENT_TECH_MENU);
981 case CUTSCENES_BUTTON:
982 gamesnd_play_iface(SND_SWITCH_SCREENS);
983 gameseq_post_event(GS_EVENT_GOTO_VIEW_CUTSCENES_SCREEN);
987 gamesnd_play_iface(SND_SWITCH_SCREENS);
988 gameseq_post_event(GS_EVENT_CREDITS);
995 // ---------------------------------------------------------------------
996 // mission_sim_room_init()
998 // Initialize the sim_room assignment screen system. Called when GS_STATE_sim_room_SCREEN
1001 void sim_room_init()
1004 sim_room_buttons *b;
1005 char wild_card[256];
1007 list_x1 = Mission_list_coords[gr_screen.res][0];
1008 list_x2 = Campaign_list_coords[gr_screen.res][0];
1009 list_y = Mission_list_coords[gr_screen.res][1];
1010 list_w1 = Mission_list_coords[gr_screen.res][2];
1011 list_w2 = Campaign_list_coords[gr_screen.res][2];
1012 list_h = Mission_list_coords[gr_screen.res][3];
1014 // force mode to valid range. I once had a bogus value here. Don't know how that happened, though.
1015 if (Player->readyroom_listing_mode != MODE_MISSIONS)
1016 Player->readyroom_listing_mode = MODE_CAMPAIGNS;
1018 *Game_current_mission_filename = 0;
1019 common_set_interface_palette("InterfacePalette"); // set the interface palette
1020 Ui_window.create(0, 0, gr_screen.max_w, gr_screen.max_h, 0);
1021 Ui_window.set_mask_bmap(Sim_mask_filename[gr_screen.res]);
1023 for (i=0; i<NUM_BUTTONS; i++) {
1024 b = &Buttons[gr_screen.res][i];
1026 b->button.create(&Ui_window, "", b->x, b->y, 60, 30, (i < 2), 1);
1027 // set up callback for when a mouse first goes over a button
1028 b->button.set_highlight_action(common_play_highlight_sound);
1029 b->button.set_bmaps(b->filename);
1030 b->button.link_hotspot(b->hotspot);
1033 // screen/button specific text
1034 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);
1035 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);
1036 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);
1037 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);
1038 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);
1040 // common tab button text
1041 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);
1042 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);
1043 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);
1044 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);
1046 // misc text - not associated with any buttons
1047 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);
1048 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);
1050 for (i=0; i<LIST_BUTTONS_MAX; i++) {
1051 List_buttons[i].create(&Ui_window, "", 0, 0, 60, 30, 0, 1);
1052 List_buttons[i].hide();
1053 List_buttons[i].disable();
1056 // set up sim_rooms for buttons so we draw the correct animation frame when a key is pressed
1057 Buttons[gr_screen.res][SCROLL_UP_BUTTON].button.set_hotkey(KEY_PAGEUP);
1058 Buttons[gr_screen.res][SCROLL_DOWN_BUTTON].button.set_hotkey(KEY_PAGEDOWN);
1059 Buttons[gr_screen.res][COMMIT_BUTTON].button.set_hotkey(KEY_CTRLED | KEY_ENTER);
1061 Background_bitmap = bm_load(Sim_filename[gr_screen.res]);
1063 // load in help overlay bitmap
1064 help_overlay_load(SIM_ROOM_OVERLAY);
1065 help_overlay_set_state(SIM_ROOM_OVERLAY,0);
1067 Scroll_offset = Selected_line = 0;
1069 strcpy(Cur_campaign, Player->current_campaign);
1070 mission_load_up_campaign();
1071 mission_campaign_next_mission();
1073 Num_campaigns = Num_campaign_missions = 0;
1074 Get_file_list_filter = sim_room_campaign_mission_filter;
1075 memset(wild_card, 0, 256);
1076 strcpy(wild_card, NOX("*"));
1077 strcat(wild_card, FS_CAMPAIGN_FILE_EXT);
1078 Num_campaigns = cf_get_file_list(MAX_CAMPAIGNS, Campaign_file_names, CF_TYPE_MISSIONS, wild_card, CF_SORT_NAME);
1080 Hash_table_inited = 0;
1081 if (build_campaign_mission_filename_hash_table()) {
1082 Hash_table_inited = 1;
1086 GR_MAYBE_CLEAR_RES(Background_bitmap);
1087 if(Background_bitmap != -1){
1088 gr_set_bitmap(Background_bitmap);
1094 Get_file_list_filter = sim_room_standalone_mission_filter;
1095 memset(wild_card, 0, 256);
1096 strcpy(wild_card, NOX("*"));
1097 strcat(wild_card, FS_MISSION_FILE_EXT);
1098 Num_standalone_missions = cf_get_file_list(MAX_MISSIONS, Mission_filenames, CF_TYPE_MISSIONS, wild_card, CF_SORT_NAME);
1100 Num_campaign_missions_with_info = Num_standalone_missions_with_info = Standalone_mission_names_inited = Campaign_names_inited = Campaign_mission_names_inited = 0;
1101 sim_room_build_listing();
1103 // load special mission icons
1104 sim_room_load_mission_icons();
1107 // ---------------------------------------------------------------------
1110 // Cleanup the sim_room assignment screen system. Called when GS_STATE_sim_room_SCREEN
1113 void sim_room_close()
1117 for (i=0; i<Num_campaign_missions; i++)
1118 if (Campaign_missions[i])
1119 free(Campaign_missions[i]);
1121 if (Background_bitmap >= 0)
1122 bm_unload(Background_bitmap);
1124 if (Standalone_mission_names_inited){
1125 for (i=0; i<Num_standalone_missions; i++){
1126 if (Standalone_mission_names[i]){
1127 free(Standalone_mission_names[i]);
1129 Standalone_mission_flags[i] = 0;
1133 if (Campaign_names_inited)
1134 for (i=0; i<Num_campaigns; i++)
1135 if (Campaign_names[i])
1136 free(Campaign_names[i]);
1138 if (Campaign_mission_names_inited)
1139 for (i=0; i<Campaign.num_missions; i++)
1140 if (Campaign_mission_names[i])
1141 free(Campaign_mission_names[i]);
1143 for (i=0; i<Num_campaigns; i++)
1144 free(Campaign_file_names[i]);
1146 for (i=0; i<Num_standalone_missions; i++)
1147 free(Mission_filenames[i]);
1149 // unload the overlay bitmap
1150 help_overlay_unload(SIM_ROOM_OVERLAY);
1152 campaign_mission_hash_table_delete();
1154 Ui_window.destroy();
1155 common_free_interface_palette(); // restore game palette
1158 // unload special mission icons
1159 sim_room_unload_mission_icons();
1162 // ---------------------------------------------------------------------
1163 // sim_room_do_frame()
1165 // Called once per frame to process user input for the sim_room Assignment Screen
1167 void sim_room_do_frame(float frametime)
1170 int i, k, y, z, line;
1171 int font_height = gr_get_font_height();
1172 int select_tease_line = -1; // line mouse is down on, but won't be selected until button released
1175 for (i=0; i<Num_campaigns; i++)
1176 if (!stricmp(Campaign_file_names[i], Campaign.filename)) {
1181 if ( help_overlay_active(SIM_ROOM_OVERLAY) ) {
1182 Buttons[gr_screen.res][HELP_BUTTON].button.reset_status();
1183 Ui_window.set_ignore_gadgets(1);
1186 k = Ui_window.process() & ~KEY_DEBUGGED;
1188 if ( (k > 0) || B1_JUST_RELEASED ) {
1189 if ( help_overlay_active(SIM_ROOM_OVERLAY) ) {
1190 help_overlay_set_state(SIM_ROOM_OVERLAY, 0);
1191 Ui_window.set_ignore_gadgets(0);
1196 if ( !help_overlay_active(SIM_ROOM_OVERLAY) ) {
1197 Ui_window.set_ignore_gadgets(0);
1201 case KEY_DOWN: // scroll list down
1202 sim_room_scroll_line_down();
1205 case KEY_UP: // scroll list up
1206 sim_room_scroll_line_up();
1210 gameseq_post_event(GS_EVENT_MAIN_MENU);
1213 case KEY_CTRLED | KEY_UP:
1214 sim_room_button_pressed(TECH_DATABASE_BUTTON);
1217 case KEY_CTRLED | KEY_DOWN:
1218 sim_room_button_pressed(CUTSCENES_BUTTON);
1222 if (Player->readyroom_listing_mode == MODE_CAMPAIGNS)
1223 Player->readyroom_listing_mode = MODE_MISSIONS;
1225 Player->readyroom_listing_mode = MODE_CAMPAIGNS;
1227 Selected_line = Scroll_offset = 0;
1228 gamesnd_play_iface(SND_USER_SELECT);
1229 sim_room_build_listing();
1233 gamesnd_play_iface(SND_SWITCH_SCREENS);
1234 gameseq_post_event(GS_EVENT_OPTIONS_MENU);
1238 for (i=0; i<NUM_BUTTONS; i++){
1239 if (Buttons[gr_screen.res][i].button.pressed()){
1240 if (sim_room_button_pressed(i)){
1246 for (i=0; i<LIST_BUTTONS_MAX; i++) {
1247 if (List_buttons[i].is_mouse_on())
1248 select_tease_line = i + Scroll_offset;
1250 if (List_buttons[i].pressed()) {
1251 Selected_line = i + Scroll_offset;
1252 gamesnd_play_iface(SND_USER_SELECT);
1256 GR_MAYBE_CLEAR_RES(Background_bitmap);
1257 if (Background_bitmap >= 0) {
1258 gr_set_bitmap(Background_bitmap);
1264 for (i=TECH_DATABASE_BUTTON; i<=CREDITS_BUTTON; i++){
1265 if (Buttons[gr_screen.res][i].button.button_down()){
1270 if (i > CREDITS_BUTTON){
1271 Buttons[gr_screen.res][SIMULATOR_BUTTON].button.draw_forced(2);
1274 if (!Buttons[gr_screen.res][CAMPAIGN_TAB].button.button_down() && !Buttons[gr_screen.res][MISSION_TAB].button.button_down()) {
1275 if (Player->readyroom_listing_mode == MODE_CAMPAIGNS){
1276 Buttons[gr_screen.res][CAMPAIGN_TAB].button.draw_forced(2);
1277 } else if (Player->readyroom_listing_mode == MODE_MISSIONS){
1278 Buttons[gr_screen.res][MISSION_TAB].button.draw_forced(2);
1283 if (Player->readyroom_listing_mode == MODE_CAMPAIGNS) {
1284 gr_set_color_fast(&Color_text_heading);
1285 strcpy(buf, Campaign.name);
1286 gr_force_fit_string(buf, 255, list_w1);
1287 gr_printf(list_x1, Mission_list_coords[gr_screen.res][1], buf);
1289 if (Campaign.filename) {
1290 sprintf(buf, NOX("%s%s"), Campaign.filename, FS_CAMPAIGN_FILE_EXT);
1291 gr_force_fit_string(buf, 255, list_w2);
1292 gr_printf(list_x2, Mission_list_coords[gr_screen.res][1], buf);
1294 // blit the proper icons if necessary
1295 char full_name[256];
1296 memset(full_name, 0, 256);
1297 strcpy(full_name, cf_add_ext(Campaign.filename,FS_CAMPAIGN_FILE_EXT));
1298 fs_builtin_mission *fb = game_find_builtin_mission(full_name);
1300 // sim_room_blit_icons(0, Mission_list_coords[gr_screen.res][1], fb, 0);
1305 line = Scroll_offset;
1306 while (sim_room_line_query_visible(line)) {
1307 y = list_y + sim_room_lines[line].y - sim_room_lines[Scroll_offset].y;
1309 if (sim_room_lines[line].type != READYROOM_LINE_CAMPAIGN) {
1310 List_buttons[line - Scroll_offset].update_dimensions(list_x1, y, list_x2 + list_w2 - list_x1, font_height);
1311 List_buttons[line - Scroll_offset].enable();
1314 List_buttons[line - Scroll_offset].disable();
1316 if (line == Selected_line)
1317 gr_set_color_fast(&Color_text_selected);
1318 else if (line == select_tease_line)
1319 gr_set_color_fast(&Color_text_subselected);
1321 gr_set_color_fast(&Color_text_normal);
1323 strcpy(buf, sim_room_lines[line].name);
1324 gr_force_fit_string(buf, 255, list_x1 + list_w1 - sim_room_lines[line].x);
1325 gr_printf(sim_room_lines[line].x, y, buf);
1327 if (sim_room_lines[line].filename) {
1328 strcpy(buf, sim_room_lines[line].filename);
1329 gr_force_fit_string(buf, 255, list_w2);
1330 gr_printf(list_x2, y, buf);
1333 // blit additional icon information
1334 sim_room_blit_icons(line, y);
1339 i = line - Scroll_offset;
1340 while (i < LIST_BUTTONS_MAX)
1341 List_buttons[i++].disable();
1343 // blit help overlay if active
1344 help_overlay_maybe_blit(SIM_ROOM_OVERLAY);
1349 void sim_room_blit_icons(int line_index, int y_start, fs_builtin_mission *fb, int is_md)
1351 int is_from_volition = 0;
1353 // determine icon status
1355 is_from_volition = (sim_room_lines[line_index].flags & READYROOM_FLAG_FROM_VOLITION) ? 1 : 0;
1357 is_from_volition = (fb->flags & FSB_FROM_VOLITION) ? 1 : 0;
1360 // if the line is flagged as a volition file
1361 if(is_from_volition && (Mission_icon_bitmaps[MISSION_ICON_VOLITION] >= 0)){
1362 gr_set_bitmap(Mission_icon_bitmaps[MISSION_ICON_VOLITION]);
1363 gr_bitmap(Sim_volition_icon_x[gr_screen.res], y_start + MISSION_ICON_VOLITION_Y_OFFSET);
1367 /// Campaign room stuff below
1368 int Cr_list_coords[GR_NUM_RESOLUTIONS][4] = {
1377 int Cr_info_coords[GR_NUM_RESOLUTIONS][4] = {
1386 #define CR_NUM_BUTTONS 6
1388 #define CR_SCROLL_UP_BUTTON 0
1389 #define CR_SCROLL_DOWN_BUTTON 1
1390 #define CR_SCROLL_INFO_UP_BUTTON 2
1391 #define CR_SCROLL_INFO_DOWN_BUTTON 3
1392 #define CR_RESET_BUTTON 4
1393 #define CR_COMMIT_BUTTON 5
1395 #define MAX_INFO_LINES 20
1397 #define MAX_INFO_LINE_LEN 256
1399 ui_button_info Cr_buttons[GR_NUM_RESOLUTIONS][CR_NUM_BUTTONS] = {
1401 ui_button_info("CAB_00", 2, 42, -1, -1, 0),
1402 ui_button_info("CAB_01", 2, 89, -1, -1, 1),
1403 ui_button_info("CAB_02", 2, 279, -1, -1, 2),
1404 ui_button_info("CAB_03", 2, 325, -1, -1, 3),
1405 ui_button_info("CAB_04", 579, 353, -1, -1, 4),
1406 ui_button_info("CAB_05", 575, 434, -1, -1, 5),
1409 ui_button_info("2_CAB_00", 3, 68, -1, -1, 0),
1410 ui_button_info("2_CAB_01", 3, 142, -1, -1, 1),
1411 ui_button_info("2_CAB_02", 3, 446, -1, -1, 2),
1412 ui_button_info("2_CAB_03", 3, 520, -1, -1, 3),
1413 ui_button_info("2_CAB_04", 927, 565, -1, -1, 4),
1414 ui_button_info("2_CAB_05", 920, 694, -1, -1, 5),
1419 #define CR_NUM_TEXT 3
1420 UI_XSTR Cr_text[GR_NUM_RESOLUTIONS][CR_NUM_TEXT] = {
1422 { "Restart", 1403, 569, 326, UI_XSTR_COLOR_GREEN, -1, &Cr_buttons[0][CR_RESET_BUTTON].button },
1423 { "Campaign", 1404, 569, 337, UI_XSTR_COLOR_GREEN, -1, &Cr_buttons[0][CR_RESET_BUTTON].button },
1424 { "Select", 1409, 568, 413, UI_XSTR_COLOR_PINK, -1, &Cr_buttons[0][CR_COMMIT_BUTTON].button },
1427 { "Restart", 1403, 922, 523, UI_XSTR_COLOR_GREEN, -1, &Cr_buttons[1][CR_RESET_BUTTON].button },
1428 { "Campaign", 1404, 922, 538, UI_XSTR_COLOR_GREEN, -1, &Cr_buttons[1][CR_RESET_BUTTON].button },
1429 { "Select", 1409, 921, 665, UI_XSTR_COLOR_PINK, -1, &Cr_buttons[1][CR_COMMIT_BUTTON].button },
1433 static int Num_desc_lines;
1434 static int Desc_scroll_offset;
1435 static int Selected_campaign_index;
1436 static int Active_campaign_index;
1438 char *Info_text_ptrs[MAX_INFO_LINES];
1439 int Num_info_lines, Info_text_line_size[MAX_INFO_LINES];
1441 void campaign_room_build_listing()
1443 int c, i, y, type, max_players;
1444 int font_height = gr_get_font_height();
1445 char name[NAME_LENGTH];
1448 if (!Campaign_names_inited) {
1449 for (i=0; i<Num_campaigns; i++) {
1450 Campaign_names[i] = NULL;
1451 if ( mission_campaign_get_info(Campaign_file_names[i], name, &type, &max_players) ) {
1453 if((game_find_builtin_mission(name) == NULL) && !strstr(name, "peterdrake")){
1456 Campaign_names[i] = strdup(name);
1459 if (type == CAMPAIGN_TYPE_SINGLE){
1460 Campaign_names[i] = strdup(name);
1466 Campaign_names_inited = 1;
1469 for (c=0; c<Num_campaigns; c++) {
1470 if (Campaign_names[c]) {
1472 // determine some extra information
1474 fs_builtin_mission *fb = game_find_builtin_mission(Campaign_file_names[c]);
1476 if(fb->flags & FSB_FROM_VOLITION){
1477 flags |= READYROOM_FLAG_FROM_VOLITION;
1481 sim_room_line_add(READYROOM_LINE_CAMPAIGN, Campaign_names[c], Campaign_file_names[c], Cr_list_coords[gr_screen.res][0], y, flags);
1482 y += font_height + 2;
1487 void set_new_campaign_line(int n)
1491 Selected_campaign_index = n;
1492 str = Campaign_descs[Selected_campaign_index];
1495 Num_info_lines = split_str(str, Cr_info_coords[gr_screen.res][2], Info_text_line_size, Info_text_ptrs, MAX_INFO_LINES);
1496 Assert(Num_info_lines >= 0);
1499 Desc_scroll_offset = 0;
1502 void campaign_room_scroll_info_up()
1504 if (Desc_scroll_offset) {
1505 Desc_scroll_offset--;
1506 gamesnd_play_iface(SND_SCROLL);
1509 gamesnd_play_iface(SND_GENERAL_FAIL);
1512 void campaign_room_scroll_info_down()
1514 if ( (Num_info_lines - Desc_scroll_offset) * gr_get_font_height() > Cr_info_coords[gr_screen.res][3]) {
1515 Desc_scroll_offset++;
1516 gamesnd_play_iface(SND_SCROLL);
1519 gamesnd_play_iface(SND_GENERAL_FAIL);
1522 // returns: 0 = success, !0 = aborted or failed
1523 int campaign_room_reset_campaign(int n)
1528 // 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]);
1529 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));
1531 filename = (char *) malloc(strlen(Campaign_file_names[n]) + 5);
1532 strcpy(filename, Campaign_file_names[n]);
1533 strcat(filename, FS_CAMPAIGN_FILE_EXT);
1535 mission_campaign_savefile_delete(filename);
1536 mission_campaign_load(filename);
1537 mission_campaign_next_mission();
1544 void campaign_room_commit()
1546 if (Selected_campaign_index < 0) {
1547 gamesnd_play_iface(SND_GENERAL_FAIL);
1551 if (stricmp(Campaign_file_names[Selected_campaign_index], Campaign.filename)) { // new campaign selected
1552 if ((Active_campaign_index >= 0) && campaign_room_reset_campaign(Active_campaign_index)) {
1553 gamesnd_play_iface(SND_GENERAL_FAIL);
1557 mission_campaign_savefile_delete(Campaign_file_names[Selected_campaign_index]);
1558 mission_campaign_load(Campaign_file_names[Selected_campaign_index]);
1559 strcpy(Player->current_campaign, Campaign.filename); // track new campaign for player
1562 if (mission_campaign_next_mission()) { // is campaign and next mission valid?
1563 gamesnd_play_iface(SND_GENERAL_FAIL);
1567 gameseq_post_event(GS_EVENT_MAIN_MENU);
1568 gamesnd_play_iface(SND_COMMIT_PRESSED);
1571 int campaign_room_button_pressed(int n)
1574 case CR_SCROLL_UP_BUTTON:
1575 sim_room_scroll_screen_up();
1578 case CR_SCROLL_DOWN_BUTTON:
1579 sim_room_scroll_screen_down();
1582 case CR_SCROLL_INFO_UP_BUTTON:
1583 campaign_room_scroll_info_up();
1586 case CR_SCROLL_INFO_DOWN_BUTTON:
1587 campaign_room_scroll_info_down();
1590 case CR_COMMIT_BUTTON:
1591 campaign_room_commit();
1595 case CR_HELP_BUTTON:
1596 launch_context_help();
1597 gamesnd_play_iface(SND_HELP_PRESSED);
1600 case CR_OPTIONS_BUTTON:
1601 gamesnd_play_iface(SND_SWITCH_SCREENS);
1602 gameseq_post_event(GS_EVENT_OPTIONS_MENU);
1606 case CR_RESET_BUTTON:
1607 if ( (Active_campaign_index < 0) || (Active_campaign_index >= Num_campaigns) )
1608 gamesnd_play_iface(SND_GENERAL_FAIL);
1609 else if (campaign_room_reset_campaign(Active_campaign_index))
1610 gamesnd_play_iface(SND_GENERAL_FAIL);
1612 gamesnd_play_iface(SND_USER_SELECT);
1620 void campaign_room_init()
1622 int i, j, load_failed;
1624 char wild_card[256];
1626 list_h = Mission_list_coords[gr_screen.res][3];
1628 // common_set_interface_palette("InterfacePalette"); // set the interface palette
1629 Ui_window.create(0, 0, gr_screen.max_w, gr_screen.max_h, 0);
1630 Ui_window.set_mask_bmap(Campaign_mask_filename[gr_screen.res]);
1632 for (i=0; i<CR_NUM_BUTTONS; i++) {
1633 b = &Cr_buttons[gr_screen.res][i];
1635 b->button.create(&Ui_window, "", b->x, b->y, 60, 30, (i < 2), 1);
1636 // set up callback for when a mouse first goes over a button
1637 b->button.set_highlight_action(common_play_highlight_sound);
1638 b->button.set_bmaps(b->filename);
1639 b->button.link_hotspot(b->hotspot);
1642 for (i=0; i<LIST_BUTTONS_MAX; i++) {
1643 List_buttons[i].create(&Ui_window, "", 0, 0, 60, 30, 0, 1);
1644 List_buttons[i].hide();
1645 List_buttons[i].disable();
1649 for(i=0; i<CR_NUM_TEXT; i++){
1650 Ui_window.add_XSTR(&Cr_text[gr_screen.res][i]);
1653 // set up sim_rooms for buttons so we draw the correct animation frame when a key is pressed
1654 Cr_buttons[gr_screen.res][CR_SCROLL_UP_BUTTON].button.set_hotkey(KEY_PAGEUP);
1655 Cr_buttons[gr_screen.res][CR_SCROLL_DOWN_BUTTON].button.set_hotkey(KEY_PAGEDOWN);
1656 Cr_buttons[gr_screen.res][CR_RESET_BUTTON].button.set_hotkey(KEY_DELETE);
1657 Cr_buttons[gr_screen.res][CR_COMMIT_BUTTON].button.set_hotkey(KEY_CTRLED | KEY_ENTER);
1658 // Cr_buttons[gr_screen.res][CR_HELP_BUTTON].button.set_hotkey(KEY_F2);
1660 Background_bitmap = bm_load(Campaign_filename[gr_screen.res]);
1662 // load in help overlay bitmap
1663 help_overlay_load(CAMPAIGN_ROOM_OVERLAY);
1664 help_overlay_set_state(CAMPAIGN_ROOM_OVERLAY,0);
1668 Desc_scroll_offset = Scroll_offset = 0;
1669 load_failed = mission_load_up_campaign();
1671 mission_campaign_next_mission();
1674 Campaign.filename[0] = 0;
1675 Campaign.num_missions = 0;
1680 Get_file_list_filter = campaign_room_campaign_filter;
1681 memset(wild_card, 0, 256);
1682 strcpy(wild_card, NOX("*"));
1683 strcat(wild_card, FS_CAMPAIGN_FILE_EXT);
1684 Num_campaigns = cf_get_file_list(MAX_CAMPAIGNS, Campaign_file_names, CF_TYPE_MISSIONS, wild_card, CF_SORT_NAME);
1686 for (i=0; i<Num_campaigns; i++) {
1687 for (j=0; j<Num_campaigns; j++) {
1688 if (Campaign_file_names_temp[j]) {
1689 if (!strncmp(Campaign_file_names[i], Campaign_file_names_temp[j], strlen(Campaign_file_names_temp[j]) - 4)) {
1690 Campaign_descs[i] = Campaign_descs_temp[j];
1691 free(Campaign_file_names_temp[j]);
1692 Campaign_file_names_temp[j] = NULL;
1698 Assert(j < Num_campaigns); // Campaign not found? How is that possible?
1701 Campaign_names_inited = 0;
1702 campaign_room_build_listing();
1704 Selected_campaign_index = Active_campaign_index = -1;
1706 for (i=0; i<Num_campaigns; i++)
1707 if (!stricmp(Campaign_file_names[i], Campaign.filename)) {
1708 set_new_campaign_line(i);
1709 Active_campaign_index = i;
1715 void campaign_room_close()
1719 for (i=0; i<Num_campaigns; i++)
1720 if (Campaign_descs[i])
1721 free(Campaign_descs[i]);
1723 if (Background_bitmap >= 0)
1724 bm_unload(Background_bitmap);
1726 if (Campaign_names_inited)
1727 for (i=0; i<Num_campaigns; i++)
1728 if (Campaign_names[i])
1729 free(Campaign_names[i]);
1731 for (i=0; i<Num_campaigns; i++)
1732 free(Campaign_file_names[i]);
1734 // unload the overlay bitmap
1735 help_overlay_unload(CAMPAIGN_ROOM_OVERLAY);
1737 Ui_window.destroy();
1738 common_free_interface_palette(); // restore game palette
1742 void campaign_room_do_frame(float frametime)
1745 char line_text[MAX_INFO_LINE_LEN];
1747 int font_height = gr_get_font_height();
1748 int select_tease_line = -1; // line mouse is down on, but won't be selected until button released
1750 if ( help_overlay_active(CAMPAIGN_ROOM_OVERLAY) ) {
1751 // Cr_buttons[gr_screen.res][CR_HELP_BUTTON].button.reset_status();
1752 Ui_window.set_ignore_gadgets(1);
1755 k = Ui_window.process() & ~KEY_DEBUGGED;
1757 if ( (k > 0) || B1_JUST_RELEASED ) {
1758 if ( help_overlay_active(CAMPAIGN_ROOM_OVERLAY) ) {
1759 help_overlay_set_state(CAMPAIGN_ROOM_OVERLAY, 0);
1760 Ui_window.set_ignore_gadgets(0);
1765 if ( !help_overlay_active(CAMPAIGN_ROOM_OVERLAY) ) {
1766 Ui_window.set_ignore_gadgets(0);
1770 case KEY_DOWN: // scroll list down
1771 if (Selected_campaign_index < Num_campaigns - 1) {
1772 set_new_campaign_line(Selected_campaign_index + 1);
1773 gamesnd_play_iface(SND_SCROLL);
1776 gamesnd_play_iface(SND_GENERAL_FAIL);
1780 case KEY_UP: // scroll list up
1781 if (Selected_campaign_index < 0)
1782 Selected_campaign_index = 1;
1784 if (Selected_campaign_index) {
1785 set_new_campaign_line(Selected_campaign_index - 1);
1786 gamesnd_play_iface(SND_SCROLL);
1789 gamesnd_play_iface(SND_GENERAL_FAIL);
1794 gameseq_post_event(GS_EVENT_MAIN_MENU);
1798 for (i=0; i<CR_NUM_BUTTONS; i++){
1799 if (Cr_buttons[gr_screen.res][i].button.pressed()){
1800 if (campaign_room_button_pressed(i)){
1806 for (i=0; i<LIST_BUTTONS_MAX; i++) {
1807 if (List_buttons[i].is_mouse_on()){
1808 select_tease_line = i + Scroll_offset;
1811 if (List_buttons[i].pressed()) {
1812 set_new_campaign_line(i + Scroll_offset);
1813 gamesnd_play_iface(SND_USER_SELECT);
1817 GR_MAYBE_CLEAR_RES(Background_bitmap);
1818 if (Background_bitmap >= 0) {
1819 gr_set_bitmap(Background_bitmap);
1826 line = Scroll_offset;
1827 while (sim_room_line_query_visible(line)) {
1828 y = Cr_list_coords[gr_screen.res][1] + sim_room_lines[line].y - sim_room_lines[Scroll_offset].y;
1830 List_buttons[line - Scroll_offset].update_dimensions(Cr_list_coords[gr_screen.res][0], y, Cr_list_coords[gr_screen.res][2], font_height);
1831 List_buttons[line - Scroll_offset].enable();
1833 if (!stricmp(sim_room_lines[line].filename, Campaign.filename)) {
1834 gr_set_color_fast(&Color_white);
1835 i = y + font_height / 2 - 1;
1836 gr_circle(Cr_list_coords[gr_screen.res][0] - 6, i, 5);
1838 gr_set_color_fast(&Color_bright_white);
1839 gr_line(Cr_list_coords[gr_screen.res][0] - 10, i, Cr_list_coords[gr_screen.res][0] - 8, i);
1840 gr_line(Cr_list_coords[gr_screen.res][0] - 6, i - 4, Cr_list_coords[gr_screen.res][0] - 6, i - 2);
1841 gr_line(Cr_list_coords[gr_screen.res][0] - 4, i, Cr_list_coords[gr_screen.res][0] - 2, i);
1842 gr_line(Cr_list_coords[gr_screen.res][0] - 6, i + 2, Cr_list_coords[gr_screen.res][0] - 6, i + 4);
1845 if (line == Selected_campaign_index)
1846 gr_set_color_fast(&Color_text_selected);
1847 else if (line == select_tease_line)
1848 gr_set_color_fast(&Color_text_subselected);
1850 gr_set_color_fast(&Color_text_normal);
1852 strcpy(buf, sim_room_lines[line].name);
1853 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);
1854 gr_printf(sim_room_lines[line].x, y, buf);
1858 i = line - Scroll_offset;
1859 while (i < LIST_BUTTONS_MAX)
1860 List_buttons[i++].disable();
1863 i = Desc_scroll_offset;
1864 gr_set_color_fast(&Color_text_normal);
1866 while (y + font_height <= Cr_info_coords[gr_screen.res][3]) {
1867 if (i >= Num_info_lines)
1870 Assert(Info_text_line_size[i] < MAX_INFO_LINE_LEN);
1871 strncpy(line_text, Info_text_ptrs[i], Info_text_line_size[i]);
1872 line_text[Info_text_line_size[i]] = 0;
1873 drop_white_space(line_text);
1874 gr_string(Cr_info_coords[gr_screen.res][0], Cr_info_coords[gr_screen.res][1] + y, line_text);
1879 // blit help overlay if active
1880 help_overlay_maybe_blit(CAMPAIGN_ROOM_OVERLAY);
1885 void sim_room_load_mission_icons()
1890 for(idx=0; idx<NUM_MISSION_ICONS; idx++){
1891 Mission_icon_bitmaps[idx] = -1;
1892 Mission_icon_bitmaps[idx] = bm_load(Mission_icon_bitmap_filenames[idx]);
1896 void sim_room_unload_mission_icons()
1900 // unload all bitmaps
1901 for(idx=0; idx<NUM_MISSION_ICONS; idx++){
1902 if(Mission_icon_bitmaps[idx] >= 0){
1903 bm_unload(Mission_icon_bitmaps[idx]);
1904 Mission_icon_bitmaps[idx] = -1;