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.9 2005/08/12 09:01:11 taylor
19 * fix strange issue where campaign and single missions could end up mixed together in the same list
21 * Revision 1.8 2005/03/29 02:18:47 taylor
22 * Various 64-bit platform fixes
23 * Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too
24 * Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions)
25 * Streaming audio support (big thanks to Pierre Willenbrock!!)
26 * Removed dependance on strings.tbl for FS1 since we don't actually need it now
28 * Revision 1.7 2004/12/15 04:10:45 taylor
29 * outwnd_unix.cpp from fs2_open for logging to file in debug mode
30 * fixes for default function values
31 * always use vm_* functions for sanity sake
32 * make cfilearchiver 64-bit compatible
33 * fix crash on exit from double free()
34 * fix crash on startup from extra long GL extension string in debug
36 * Revision 1.6 2004/09/20 01:31:44 theoddone33
39 * Revision 1.5 2004/07/04 11:39:06 taylor
40 * fix missing debrief text, crash on exit, path separator's, warning fixes, no GR_SOFT
42 * Revision 1.4 2003/05/25 02:30:42 taylor
45 * Revision 1.3 2002/06/09 04:41:22 relnev
46 * added copyright header
48 * Revision 1.2 2002/06/02 04:26:34 relnev
51 * Revision 1.1.1.1 2002/05/03 03:28:09 root
55 * 20 9/30/99 5:59p Jefff
56 * fixed compile error in OEM ver
58 * 19 9/08/99 12:28p Jefff
60 * 18 9/06/99 6:38p Dave
61 * Improved CD detection code.
63 * 17 9/02/99 2:33p Jefff
64 * column heading coordinate changes
66 * 16 8/22/99 4:16p Jefff
67 * scroll button coord fixes
69 * 15 7/20/99 1:49p Dave
70 * Peter Drake build. Fixed some release build warnings.
72 * 14 7/19/99 2:13p Dave
73 * Added some new strings for Heiko.
75 * 13 7/15/99 9:20a Andsager
76 * FS2_DEMO initial checkin
78 * 12 7/09/99 5:54p Dave
79 * Seperated cruiser types into individual types. Added tons of new
80 * briefing icons. Campaign screen.
82 * 11 2/01/99 5:55p Dave
83 * Removed the idea of explicit bitmaps for buttons. Fixed text
84 * highlighting for disabled gadgets.
86 * 10 1/30/99 9:01p Dave
89 * 9 1/30/99 5:08p Dave
90 * More new hi-res stuff.Support for nice D3D textures.
92 * 8 1/29/99 12:47a Dave
93 * Put in sounds for beam weapon. A bunch of interface screens (tech
96 * 7 12/11/98 4:35p Andsager
97 * Fix sim room bug when no standalone missions
99 * 6 12/07/98 5:02p Dan
100 * Removed improper use of bitmap filename with extension,
102 * 5 10/13/98 9:28a Dave
103 * Started neatening up freespace.h. Many variables renamed and
104 * reorganized. Added AlphaColors.[h,cpp]
118 #include "gamesequence.h"
119 #include "missioncampaign.h"
122 #include "missionscreencommon.h"
123 #include "freespace.h"
124 #include "missionparse.h"
126 #include "managepilot.h"
128 #include "contexthelp.h"
129 #include "cfilesystem.h"
130 #include "freespace.h"
131 #include "alphacolors.h"
133 #define MAX_MISSIONS 1024
135 int Mission_list_coords[GR_NUM_RESOLUTIONS][4] = {
148 int Campaign_list_coords[GR_NUM_RESOLUTIONS][4] = {
162 // x coordinate offsets for data when campaign tab active
164 #define C_SUBTEXT_X 19
166 // x coordinate offsets for data when mission tab active
169 #define MODE_CAMPAIGNS 0
170 #define MODE_MISSIONS 1
172 #define MAX_LINES 200
173 #define MAX_DESC_LINES 200
174 #define NUM_BUTTONS 11
175 #define LIST_BUTTONS_MAX 40
177 #define SCROLL_UP_BUTTON 0
178 #define SCROLL_DOWN_BUTTON 1
179 #define MISSION_TAB 2
180 #define CAMPAIGN_TAB 3
181 #define HELP_BUTTON 4
182 #define COMMIT_BUTTON 5
183 #define OPTIONS_BUTTON 6
184 #define TECH_DATABASE_BUTTON 7
185 #define SIMULATOR_BUTTON 8
186 #define CUTSCENES_BUTTON 9
187 #define CREDITS_BUTTON 10
189 #define CAMPAIGN_MISSION_HASH_SIZE 307
191 struct sim_room_buttons {
192 const char *filename;
195 UI_BUTTON button; // because we have a class inside this struct, we need the constructor below..
197 sim_room_buttons(const char *name, int x1, int y1, int xt1, int yt1, int h) : filename(name), x(x1), y(y1), xt(xt1), yt(yt1), hotspot(h) {}
200 static sim_room_buttons Buttons[GR_NUM_RESOLUTIONS][NUM_BUTTONS] = {
204 sim_room_buttons("LMB_04", 7, 135, -1, -1, 4), // up arrows
205 sim_room_buttons("LMB_05", 7, 182, -1, -1, 5), // down arrows
206 sim_room_buttons("LMB_06", 23, 396, -1, -1, 6), // single missions
207 sim_room_buttons("LMB_07", 198, 396, -1, -1, 7), // campaign missions
208 sim_room_buttons("LMB_08", 469, 427, -1, -1, 8), // help
209 sim_room_buttons("LMB_09", 554, 411, -1, -1, 9), // commit
210 sim_room_buttons("LMB_10", 447, 452, -1, -1, 10), // options
212 sim_room_buttons("TDB_00", 0, 0, -1, -1, 0), // technical database
213 sim_room_buttons("TDB_01", 0, 19, -1, -1, 1), // mission simulator
214 sim_room_buttons("TDB_02", 0, 35, -1, -1, 2), // cutscenes
215 sim_room_buttons("TDB_03", 0, 56, -1, -1, 3), // credits
217 sim_room_buttons("LMB_04", 1, 99, -1, -1, 4),
218 sim_room_buttons("LMB_05", 1, 381, -1, -1, 5),
219 sim_room_buttons("LMB_06", 6, 438, 40, 445, 6),
220 sim_room_buttons("LMB_07", 6, 457, 40, 462, 7),
221 sim_room_buttons("LMB_08", 534, 426, 500, 440, 8),
222 sim_room_buttons("LMB_09", 571, 426, 572, 413, 9),
223 sim_room_buttons("LMB_10", 534, 455, 480, 462, 10),
225 sim_room_buttons("TDB_00", 7, 3, 37, 7, 0),
226 sim_room_buttons("TDB_01", 7, 18, 37, 23, 1),
227 sim_room_buttons("TDB_02", 7, 34, 37, 38, 2),
228 sim_room_buttons("TDB_03", 7, 49, 37, 54, 3),
232 sim_room_buttons("2_LMB_04", 2, 159, -1, -1, 4),
233 sim_room_buttons("2_LMB_05", 2, 609, -1, -1, 5),
234 sim_room_buttons("2_LMB_06", 10, 701, 64, 712, 6),
235 sim_room_buttons("2_LMB_07", 10, 732, 64, 739, 7),
236 sim_room_buttons("2_LMB_08", 854, 681, 800, 704, 8),
237 sim_room_buttons("2_LMB_09", 914, 681, 915, 660, 9),
238 sim_room_buttons("2_LMB_10", 854, 728, 800, 728, 10),
240 sim_room_buttons("2_TDB_00", 12, 5, 59, 12, 0),
241 sim_room_buttons("2_TDB_01", 12, 31, 59, 37, 1),
242 sim_room_buttons("2_TDB_02", 12, 56, 59, 62, 2),
243 sim_room_buttons("2_TDB_03", 12, 81, 59, 88, 3),
248 const char *Sim_filename[GR_NUM_RESOLUTIONS] = {
252 const char *Sim_mask_filename[GR_NUM_RESOLUTIONS] = {
257 const char *Campaign_filename[GR_NUM_RESOLUTIONS] = {
261 const char *Campaign_mask_filename[GR_NUM_RESOLUTIONS] = {
266 // misc text. ("Mission" and "Filename"
268 #define NUM_SIM_MISC_TEXT 2
269 #define SIM_MISC_TEXT_MISSION 0
270 #define SIM_MISC_TEXT_FILENAME 1
271 int Sim_misc_text_coords[GR_NUM_RESOLUTIONS][NUM_SIM_MISC_TEXT][2] = {
283 // readyroom text line stuff
284 #define READYROOM_LINE_CAMPAIGN 1
285 #define READYROOM_LINE_CMISSION 2
286 #define READYROOM_LINE_MISSION 3
288 #define READYROOM_FLAG_FROM_VOLITION (1<<0) // volition made
290 #define READYROOM_FLAG_FROM_MDISK (1<<1) // mission disk
293 int type; // see READYROOM_LINE_* defines above
295 const char *filename;
296 int x; // X coordinate of line
297 int y; // Y coordinate of line
298 int flags; // special flags, see READYROOM_FLAG_* defines above
299 } sim_room_lines[MAX_LINES];
301 static char Cur_campaign[MAX_FILENAME_LEN];
302 static char *Mission_filenames[MAX_MISSIONS];
303 static char *Standalone_mission_names[MAX_MISSIONS];
304 static int Standalone_mission_flags[MAX_MISSIONS];
305 static char *Campaign_missions[MAX_CAMPAIGN_MISSIONS];
306 static char *Campaign_mission_names[MAX_CAMPAIGN_MISSIONS];
307 static int Campaign_mission_flags[MAX_MISSIONS];
308 static char *Campaign_descs[MAX_CAMPAIGNS];
309 static char *Campaign_descs_temp[MAX_CAMPAIGNS];
310 static char *Campaign_file_names_temp[MAX_CAMPAIGNS];
311 static int Standalone_mission_names_inited = 0;
312 static int Campaign_names_inited = 0;
313 static int Campaign_mission_names_inited = 0;
314 static int Num_standalone_missions;
315 static int Num_campaign_missions;
316 static int Scroll_offset;
317 static int Selected_line;
318 static int Num_lines;
319 static int Num_campaign_missions_with_info = 0;
320 static int Num_standalone_missions_with_info = 0;
327 static int Background_bitmap;
328 static UI_WINDOW Ui_window;
329 static UI_BUTTON List_buttons[LIST_BUTTONS_MAX]; // buttons for each line of text in list
331 typedef struct hash_node {
333 const char *filename;
336 static hash_node *Campaign_mission_hash_table[CAMPAIGN_MISSION_HASH_SIZE];
337 static int Hash_table_inited;
339 // special icons (1.04 + stuff)
341 #define NUM_MISSION_ICONS 2
343 #define NUM_MISSION_ICONS 1
345 #define MISSION_ICON_VOLITION 0 // mini volition death's head :)
347 #define MISSION_ICON_MDISK 1 // Silent Threat mini icon
350 // icon offsets (see LIST_ defines above
351 //#define MISSION_ICON_VOLITION_X (46)
352 #define MISSION_ICON_VOLITION_Y_OFFSET (-1)
354 #define MISSION_ICON_MDISK_Y_OFFSET (0)
358 static int Sim_volition_icon_x[GR_NUM_RESOLUTIONS] = {
368 static int Sim_silent_icon_x[GR_NUM_RESOLUTIONS] = {
374 // special icons themselves
375 int Mission_icon_bitmaps[NUM_MISSION_ICONS];
377 const char *Mission_icon_bitmap_filenames[NUM_MISSION_ICONS] = {
386 void sim_room_load_mission_icons();
387 void sim_room_unload_mission_icons();
388 void sim_room_blit_icons(int line_index, int y_start, fs_builtin_mission *fb = NULL, int is_md = 0);
390 // Finds a hash value for mission filename
392 // returns hash value
393 int hash_filename(const char *filename) {
394 unsigned __int64 hash_val = 0;
395 const char *ptr = filename;
397 // Dont hash .fsm extension, convert all to upper case
398 for (int i=0; i < ((signed int)(strlen(filename)) - 4); i++) {
399 hash_val = (hash_val << 4) + toupper(*ptr++);
402 return int(hash_val % CAMPAIGN_MISSION_HASH_SIZE);
405 // insert filename into Campaign_mission_hash_table
407 // returns 1 if successful, 0 if could not allocate memory
408 int hash_insert(const char *filename) {
409 int hash_val = hash_filename(filename);
412 // Check if table empty
413 if (Campaign_mission_hash_table[hash_val] == NULL) {
414 Campaign_mission_hash_table[hash_val] = new hash_node;
416 cur_node = Campaign_mission_hash_table[hash_val];
418 if (cur_node == NULL) {
419 // Unable to allocate memory
423 // Walk down list to first empty node
424 cur_node = Campaign_mission_hash_table[hash_val];
425 while (cur_node->next != NULL) {
426 cur_node = cur_node->next;
430 cur_node->next = new hash_node;
432 if (cur_node->next == NULL) {
433 // unable to allocate memory
436 cur_node = cur_node->next;
441 cur_node->next = NULL;
442 cur_node->filename = filename;
448 // Checks if a filename already exitst in the hash table
450 // returns 1 if found (collision), 0 if no collision
451 int campaign_mission_hash_collision(const char *filename)
453 int hash_val = hash_filename(filename);
454 hash_node *cur_node = Campaign_mission_hash_table[hash_val];
456 if (cur_node == NULL) {
461 if (!stricmp(filename, cur_node->filename)) {
465 cur_node = cur_node->next;
466 } while (cur_node != NULL);
468 // Ran out of stuff to check
472 // builds hash table of campaign mission filenames
474 // returns 1 if successful, 0 if not successful
475 int build_campaign_mission_filename_hash_table()
478 // Go through all campaign missions
479 for (int i=0; i<Num_campaign_missions; i++) {
480 rval = hash_insert(Campaign_missions[i]);
490 // deletes hash table nodes
492 void campaign_mission_hash_table_delete()
496 for (int i=0; i<CAMPAIGN_MISSION_HASH_SIZE; i++) {
497 // Look for entries into array
498 if (Campaign_mission_hash_table[i] != NULL) {
499 cur_node = Campaign_mission_hash_table[i];
501 // Walk down the list deleting self
502 while (cur_node->next != NULL) {
503 hash_node *temp = cur_node->next;
510 Campaign_mission_hash_table[i] = NULL;
516 // add a line of sim_room smuck to end of list
517 int sim_room_line_add(int type, char *name, char *filename, int x, int y, int flags)
519 if (Num_lines >= MAX_LINES)
522 sim_room_lines[Num_lines].type = type;
523 sim_room_lines[Num_lines].name = name;
524 sim_room_lines[Num_lines].filename = filename;
525 sim_room_lines[Num_lines].x = x;
526 sim_room_lines[Num_lines].y = y;
527 sim_room_lines[Num_lines].flags = flags;
531 // filter out all multiplayer campaigns
532 int campaign_room_campaign_filter(const char *filename)
534 int type, max_players;
535 char name[NAME_LENGTH], *desc = NULL;
538 // also need to check if this is the builtin campaign
539 if ( game_find_builtin_mission(filename) && mission_campaign_get_info(filename, name, &type, &max_players, &desc) ) {
541 if ( mission_campaign_get_info(filename, name, &type, &max_players, &desc) ) {
543 if ( type == CAMPAIGN_TYPE_SINGLE ) {
544 Campaign_file_names_temp[Num_campaigns] = strdup(filename);
545 Campaign_descs_temp[Num_campaigns++] = desc;
557 // build up a list of all missions in all campaigns.
558 int sim_room_campaign_mission_filter(const char *filename)
562 num = mission_campaign_get_mission_list(filename, &Campaign_missions[Num_campaign_missions], MAX_CAMPAIGN_MISSIONS - Num_campaign_missions);
566 Num_campaign_missions += num;
570 // filter out all missions already used in existing campaigns
571 int sim_room_standalone_mission_filter(const char *filename)
574 char mission_name[255];
576 // Check if a campaign mission (single and multi)
577 if (campaign_mission_hash_collision(filename)) {
581 // Check if a standalone multi mission OR Mdisk mission with data
582 type = mission_parse_is_multi(filename, mission_name);
583 if (type && !(type & MISSION_TYPE_SINGLE))
589 // builds up list of standalone missions and adds them to missions simulator
590 // processes one mission per frame
592 // returns 1 if finished with all missions, 0 otherwise
594 int build_standalone_mission_list_do_frame()
596 int font_height = gr_get_font_height();
597 char filename[MAX_FILENAME_LEN];
600 // When no standalone missions in data directory
601 if (Num_standalone_missions == 0) {
602 Standalone_mission_names_inited = 1;
606 // Set global variable so we we'll have list available next time
607 Standalone_mission_names[Num_standalone_missions_with_info] = NULL;
608 Standalone_mission_flags[Num_standalone_missions_with_info] = 0;
610 if (Num_standalone_missions > 0) { // sanity check
611 if (strlen(Mission_filenames[Num_standalone_missions_with_info]) < MAX_FILENAME_LEN - 4) { // sanity check?
612 strcpy(filename, Mission_filenames[Num_standalone_missions_with_info]);
616 sprintf(str, XSTR("Single Mission\n\n%s",989), filename);
617 popup_change_text(str);
619 // tack on an extension
620 strcat(filename, FS_MISSION_FILE_EXT);
621 if (!get_mission_info(filename)) {
622 Standalone_mission_names[Num_standalone_missions_with_info] = strdup(The_mission.name);
623 Standalone_mission_flags[Num_standalone_missions_with_info] = The_mission.game_type;
624 int y = Num_lines * (font_height + 2);
626 // determine some extra information
628 fs_builtin_mission *fb = game_find_builtin_mission(filename);
629 if((fb != NULL) && (fb->flags & FSB_FROM_VOLITION)){
630 flags |= READYROOM_FLAG_FROM_VOLITION;
633 if((fb != NULL) && (fb->flags & FSB_FROM_MDISK)){
634 flags |= READYROOM_FLAG_FROM_MDISK;
639 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);
643 Num_standalone_missions_with_info++;
646 if (Num_standalone_missions_with_info == Num_standalone_missions) {
647 Standalone_mission_names_inited = 1;
654 // builds up list of already played missions in a campaign and adds them to missions simulator
655 // processes one mission per frame
657 // returns 1 if finished with all missions, 0 otherwise
659 int build_campaign_mission_list_do_frame()
661 int font_height = gr_get_font_height();
664 // When no campaign files in data directory
665 if (Campaign.num_missions == 0) {
666 Campaign_mission_names_inited = 1;
672 sprintf(str, XSTR("Campaign Mission\n\n%s",990), Campaign.missions[Num_campaign_missions_with_info].name);
673 popup_change_text(str);
675 // Set global variable so we we'll have list available next time
676 Campaign_mission_names[Num_campaign_missions_with_info] = NULL;
677 Campaign_mission_flags[Num_campaign_missions_with_info] = 0;
679 // Only allow missions already completed
680 if (Campaign.missions[Num_campaign_missions_with_info].completed) {
681 if (!get_mission_info(Campaign.missions[Num_campaign_missions_with_info].name)) {
683 Campaign_mission_names[Num_campaign_missions_with_info] = strdup(The_mission.name);
684 Campaign_mission_flags[Num_campaign_missions_with_info] = The_mission.game_type;
685 int y = Num_campaign_missions_with_info * (font_height + 2);
687 // determine some extra information
689 fs_builtin_mission *fb = game_find_builtin_mission(Campaign.missions[Num_campaign_missions_with_info].name);
690 if((fb != NULL) && (fb->flags & FSB_FROM_VOLITION)){
691 flags |= READYROOM_FLAG_FROM_VOLITION;
695 if((fb != NULL) && (fb->flags & FSB_FROM_MDISK)){
696 flags |= READYROOM_FLAG_FROM_MDISK;
700 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);
704 Num_campaign_missions_with_info++;
706 if (Num_campaign_missions_with_info == Campaign.num_missions) {
707 Campaign_mission_names_inited = 1;
714 // Builds list of either (1) standalone missions or (2) already played missions in current campaign
715 // First time through, it builds list, next time it uses precompiled list
716 void sim_room_build_listing()
719 int font_height = gr_get_font_height();
720 char full_filename[256];
723 list_y = Mission_list_coords[gr_screen.res][1];
724 list_h = Mission_list_coords[gr_screen.res][3];
726 // Stand alone single player missions.
727 if (Player->readyroom_listing_mode == MODE_MISSIONS) {
728 if (Hash_table_inited) {
729 if (!Standalone_mission_names_inited) { // Is this the first time through
730 // build_list_do_frame builds list and adds sim room line and sets Standalone_mission_names_inited
731 popup_till_condition(build_standalone_mission_list_do_frame, POPUP_CANCEL, XSTR("Loading missions", 991) );
733 for (i=0; i<Num_standalone_missions_with_info; i++) {
734 if (Standalone_mission_names[i]) {
735 // determine some extra information
737 memset(full_filename, 0, 256);
738 strcpy(full_filename, cf_add_ext(Mission_filenames[i], FS_MISSION_FILE_EXT));
739 fs_builtin_mission *fb = game_find_builtin_mission(full_filename);
740 if((fb != NULL) && (fb->flags & FSB_FROM_VOLITION)){
741 flags |= READYROOM_FLAG_FROM_VOLITION;
745 if((fb != NULL) && (fb->flags & FSB_FROM_MDISK)){
746 flags |= READYROOM_FLAG_FROM_MDISK;
750 sim_room_line_add(READYROOM_LINE_MISSION, Standalone_mission_names[i], Mission_filenames[i], list_x1 + M_TEXT_X, y, flags);
751 y += font_height + 2;
758 list_y += font_height + 2;
759 list_h -= font_height - 2;
761 if (!Campaign_mission_names_inited) { // Is this the first time through
762 popup_till_condition(build_campaign_mission_list_do_frame, POPUP_CANCEL, XSTR("Loading campaign missions",992));
763 // builds list, adds sim room line and sets Campaign_mission_names_inited
765 for (i=0; i<Num_campaign_missions_with_info; i++) {
766 if (Campaign_mission_names[i]) {
767 // determine some extra information
769 memset(full_filename, 0, 256);
770 strcpy(full_filename, cf_add_ext(Campaign.missions[i].name, FS_MISSION_FILE_EXT));
771 fs_builtin_mission *fb = game_find_builtin_mission(full_filename);
772 if((fb != NULL) && (fb->flags & FSB_FROM_VOLITION)){
773 flags |= READYROOM_FLAG_FROM_VOLITION;
777 if((fb != NULL) && (fb->flags & FSB_FROM_MDISK)){
778 flags |= READYROOM_FLAG_FROM_MDISK;
782 sim_room_line_add(READYROOM_LINE_CMISSION, Campaign_mission_names[i], Campaign.missions[i].name, list_x1 + C_SUBTEXT_X, y, flags);
790 int sim_room_line_query_visible(int n)
794 if ((n < 0) || (n >= Num_lines))
797 y = sim_room_lines[n].y - sim_room_lines[Scroll_offset].y;
798 if ((y < 0) || (y + gr_get_font_height() > list_h))
804 void sim_room_scroll_screen_up()
806 if (Player->readyroom_listing_mode != MODE_MISSIONS) {
809 gamesnd_play_iface(SND_SCROLL);
812 gamesnd_play_iface(SND_GENERAL_FAIL);
819 Assert(Selected_line > Scroll_offset);
820 while (!sim_room_line_query_visible(Selected_line))
823 gamesnd_play_iface(SND_SCROLL);
826 gamesnd_play_iface(SND_GENERAL_FAIL);
829 void sim_room_scroll_line_up()
833 if (Selected_line < Scroll_offset)
834 Scroll_offset = Selected_line;
836 gamesnd_play_iface(SND_SCROLL);
839 gamesnd_play_iface(SND_GENERAL_FAIL);
842 void sim_room_scroll_screen_down()
844 if (Player->readyroom_listing_mode != MODE_MISSIONS) {
845 if (sim_room_lines[Num_lines - 1].y + gr_get_font_height() > sim_room_lines[Scroll_offset].y + list_h) {
847 gamesnd_play_iface(SND_SCROLL);
850 gamesnd_play_iface(SND_GENERAL_FAIL);
855 if (sim_room_lines[Num_lines - 1].y + gr_get_font_height() > sim_room_lines[Scroll_offset].y + list_h) {
857 while (!sim_room_line_query_visible(Selected_line)) {
859 Assert(Selected_line < Num_lines);
862 gamesnd_play_iface(SND_SCROLL);
865 gamesnd_play_iface(SND_GENERAL_FAIL);
868 void sim_room_scroll_line_down()
870 if (Selected_line < Num_lines - 1) {
873 Assert(Selected_line > Scroll_offset);
874 while (!sim_room_line_query_visible(Selected_line))
877 gamesnd_play_iface(SND_SCROLL);
880 gamesnd_play_iface(SND_GENERAL_FAIL);
883 // returns: 0 = success, !0 = aborted or failed
884 int ready_room_reset_campaign()
888 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) );
891 mission_campaign_savefile_delete(Campaign.filename);
892 mission_campaign_load(Campaign.filename);
899 // Decide if we should offer choice to resume this savegame
900 int sim_room_can_resume_savegame(char *savegame_filename)
902 #ifdef FREESPACE_SAVERESTORE_SYSTEM
903 char savegame_mission[MAX_FILENAME_LEN];
905 if (state_read_description(savegame_filename, NULL, savegame_mission)) {
909 if (stricmp(Game_current_mission_filename, savegame_mission)) {
919 // Decide wether to resume a save game or not
920 // exit: 1 => savegame has been restored
921 // 0 => no restore, proceed to briefing
922 // -1 => don't start mission at all
923 int sim_room_maybe_resume_savegame()
925 // MWA -- 3/26/98 -- removed all savegame references in game
929 char savegame_filename[_MAX_FNAME];
930 int popup_rval = -1, resume_savegame = 0;
932 // Generate the save-game filename for this campaign
933 memset(savegame_filename, 0, _MAX_FNAME);
934 mission_campaign_savefile_generate_root(savegame_filename);
935 strcat(savegame_filename, NOX("svg"));
937 // Decide if we should offer choice to resume this savegame
938 if ( sim_room_can_resume_savegame(savegame_filename) ) {
939 popup_rval = popup(0, 3, XSTR("&Cancel",-1), XSTR("&Overwrite",-1), XSTR("&Resume",-1), XSTR("A save game for this mission exists.", -1));
940 switch ( popup_rval ) {
943 resume_savegame = -1;
953 resume_savegame = -1;
960 if (resume_savegame == 1) {
961 if ( state_restore_all(savegame_filename) == -1 ) {
962 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));
963 if (popup_rval == 1) {
966 resume_savegame = -1;
974 // If we are resuming this savegame, then delete the file
975 if (resume_savegame == 1) {
976 cf_delete(savegame_filename);
979 return resume_savegame;
983 int readyroom_continue_campaign()
985 if (mission_campaign_next_mission()) { // is campaign and next mission valid?
987 #if defined(FS2_DEMO) || defined(FS1_DEMO)
988 int reset_campaign = 0;
989 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) );
990 if ( reset_campaign == 1 ) {
991 mission_campaign_savefile_delete(Campaign.filename);
992 mission_campaign_load(Campaign.filename);
993 mission_campaign_next_mission();
998 gamesnd_play_iface(SND_GENERAL_FAIL);
1000 // make it the bottom button so that the graphic looks right
1001 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) );
1003 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) );
1010 if(!game_do_cd_mission_check(Game_current_mission_filename)){
1014 // set the bit for campaign mode
1015 Game_mode |= GM_CAMPAIGN_MODE;
1016 gameseq_post_event( GS_EVENT_START_GAME );
1021 void sim_room_commit()
1023 if ((Selected_line >= Num_lines) || !sim_room_lines[Selected_line].filename) {
1024 gamesnd_play_iface(SND_GENERAL_FAIL);
1028 strncpy(Game_current_mission_filename, sim_room_lines[Selected_line].filename, MAX_FILENAME_LEN);
1030 Game_mode &= ~(GM_CAMPAIGN_MODE); // be sure this bit is clear
1033 if(game_do_cd_mission_check(Game_current_mission_filename)){
1034 // don't resume savegame, proceed to briefing
1035 gameseq_post_event(GS_EVENT_START_GAME);
1036 gamesnd_play_iface(SND_COMMIT_PRESSED);
1040 int sim_room_button_pressed(int n)
1043 case SCROLL_UP_BUTTON:
1044 sim_room_scroll_screen_up();
1047 case SCROLL_DOWN_BUTTON:
1048 sim_room_scroll_screen_down();
1053 game_feature_not_in_demo_popup();
1054 // gamesnd_play_iface(SND_GENERAL_FAIL);
1057 Player->readyroom_listing_mode = MODE_MISSIONS;
1058 Selected_line = Scroll_offset = 0;
1059 gamesnd_play_iface(SND_USER_SELECT);
1060 sim_room_build_listing();
1065 Player->readyroom_listing_mode = MODE_CAMPAIGNS;
1067 gamesnd_play_iface(SND_USER_SELECT);
1068 sim_room_build_listing();
1076 launch_context_help();
1077 gamesnd_play_iface(SND_HELP_PRESSED);
1080 case OPTIONS_BUTTON:
1081 gamesnd_play_iface(SND_SWITCH_SCREENS);
1082 gameseq_post_event(GS_EVENT_OPTIONS_MENU);
1085 case TECH_DATABASE_BUTTON:
1086 gamesnd_play_iface(SND_SWITCH_SCREENS);
1087 gameseq_post_event(GS_EVENT_TECH_MENU);
1090 case CUTSCENES_BUTTON:
1091 gamesnd_play_iface(SND_SWITCH_SCREENS);
1092 gameseq_post_event(GS_EVENT_GOTO_VIEW_CUTSCENES_SCREEN);
1095 case CREDITS_BUTTON:
1096 gamesnd_play_iface(SND_SWITCH_SCREENS);
1097 gameseq_post_event(GS_EVENT_CREDITS);
1104 // ---------------------------------------------------------------------
1105 // mission_sim_room_init()
1107 // Initialize the sim_room assignment screen system. Called when GS_STATE_sim_room_SCREEN
1110 void sim_room_init()
1113 sim_room_buttons *b;
1114 char wild_card[256];
1116 list_x1 = Mission_list_coords[gr_screen.res][0];
1117 list_x2 = Campaign_list_coords[gr_screen.res][0];
1118 list_y = Mission_list_coords[gr_screen.res][1];
1119 list_w1 = Mission_list_coords[gr_screen.res][2];
1120 list_w2 = Campaign_list_coords[gr_screen.res][2];
1121 list_h = Mission_list_coords[gr_screen.res][3];
1123 // force mode to valid range. I once had a bogus value here. Don't know how that happened, though.
1124 if (Player->readyroom_listing_mode != MODE_MISSIONS)
1125 Player->readyroom_listing_mode = MODE_CAMPAIGNS;
1127 *Game_current_mission_filename = 0;
1128 common_set_interface_palette("InterfacePalette"); // set the interface palette
1129 Ui_window.create(0, 0, gr_screen.max_w, gr_screen.max_h, 0);
1130 Ui_window.set_mask_bmap(Sim_mask_filename[gr_screen.res]);
1132 for (i=0; i<NUM_BUTTONS; i++) {
1133 b = &Buttons[gr_screen.res][i];
1135 b->button.create(&Ui_window, "", b->x, b->y, 60, 30, (i < 2), 1);
1136 // set up callback for when a mouse first goes over a button
1137 b->button.set_highlight_action(common_play_highlight_sound);
1138 b->button.set_bmaps(b->filename);
1139 b->button.link_hotspot(b->hotspot);
1143 // screen/button specific text
1144 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);
1145 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);
1146 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);
1147 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);
1148 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);
1150 // common tab button text
1151 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);
1152 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);
1153 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);
1154 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);
1156 // misc text - not associated with any buttons
1157 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);
1158 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);
1161 for (i=0; i<LIST_BUTTONS_MAX; i++) {
1162 List_buttons[i].create(&Ui_window, "", 0, 0, 60, 30, 0, 1);
1163 List_buttons[i].hide();
1164 List_buttons[i].disable();
1167 // set up sim_rooms for buttons so we draw the correct animation frame when a key is pressed
1168 Buttons[gr_screen.res][SCROLL_UP_BUTTON].button.set_hotkey(SDLK_PAGEUP);
1169 Buttons[gr_screen.res][SCROLL_DOWN_BUTTON].button.set_hotkey(SDLK_PAGEDOWN);
1170 Buttons[gr_screen.res][COMMIT_BUTTON].button.set_hotkey(KEY_CTRLED | SDLK_RETURN);
1172 Background_bitmap = bm_load(Sim_filename[gr_screen.res]);
1174 // load in help overlay bitmap
1175 help_overlay_load(SIM_ROOM_OVERLAY);
1176 help_overlay_set_state(SIM_ROOM_OVERLAY,0);
1178 Scroll_offset = Selected_line = 0;
1180 strcpy(Cur_campaign, Player->current_campaign);
1181 mission_load_up_campaign();
1182 mission_campaign_next_mission();
1184 Num_campaigns = Num_campaign_missions = 0;
1185 Get_file_list_filter = sim_room_campaign_mission_filter;
1186 memset(wild_card, 0, 256);
1187 strcpy(wild_card, NOX("*"));
1188 strcat(wild_card, FS_CAMPAIGN_FILE_EXT);
1189 Num_campaigns = cf_get_file_list(MAX_CAMPAIGNS, Campaign_file_names, CF_TYPE_MISSIONS, wild_card, CF_SORT_NAME);
1191 Hash_table_inited = 0;
1192 if (build_campaign_mission_filename_hash_table()) {
1193 Hash_table_inited = 1;
1197 GR_MAYBE_CLEAR_RES(Background_bitmap);
1198 if(Background_bitmap != -1){
1199 gr_set_bitmap(Background_bitmap, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
1205 Get_file_list_filter = sim_room_standalone_mission_filter;
1206 memset(wild_card, 0, 256);
1207 strcpy(wild_card, NOX("*"));
1208 strcat(wild_card, FS_MISSION_FILE_EXT);
1209 Num_standalone_missions = cf_get_file_list(MAX_MISSIONS, Mission_filenames, CF_TYPE_MISSIONS, wild_card, CF_SORT_NAME);
1211 Num_campaign_missions_with_info = Num_standalone_missions_with_info = Standalone_mission_names_inited = Campaign_names_inited = Campaign_mission_names_inited = 0;
1212 sim_room_build_listing();
1214 // load special mission icons
1215 sim_room_load_mission_icons();
1218 // ---------------------------------------------------------------------
1221 // Cleanup the sim_room assignment screen system. Called when GS_STATE_sim_room_SCREEN
1224 void sim_room_close()
1228 for (i=0; i<Num_campaign_missions; i++) {
1229 if (Campaign_missions[i] != NULL) {
1230 free(Campaign_missions[i]);
1231 Campaign_missions[i] = NULL;
1235 if (Background_bitmap >= 0)
1236 bm_unload(Background_bitmap);
1238 if (Standalone_mission_names_inited){
1239 for (i=0; i<Num_standalone_missions; i++){
1240 if (Standalone_mission_names[i] != NULL) {
1241 free(Standalone_mission_names[i]);
1242 Standalone_mission_names[i] = NULL;
1244 Standalone_mission_flags[i] = 0;
1248 if (Campaign_names_inited) {
1249 for (i=0; i<Num_campaigns; i++) {
1250 if (Campaign_names[i] != NULL) {
1251 free(Campaign_names[i]);
1252 Campaign_names[i] = NULL;
1257 if (Campaign_mission_names_inited) {
1258 for (i=0; i<Campaign.num_missions; i++) {
1259 if (Campaign_mission_names[i] != NULL) {
1260 free(Campaign_mission_names[i]);
1261 Campaign_mission_names[i] = NULL;
1266 for (i=0; i<Num_campaigns; i++) {
1267 if (Campaign_file_names[i] != NULL) {
1268 free(Campaign_file_names[i]);
1269 Campaign_file_names[i] = NULL;
1274 for (i=0; i<Num_standalone_missions; i++) {
1275 if (Mission_filenames[i] != NULL) {
1276 free(Mission_filenames[i]);
1277 Mission_filenames[i] = NULL;
1281 // unload the overlay bitmap
1282 help_overlay_unload(SIM_ROOM_OVERLAY);
1284 campaign_mission_hash_table_delete();
1286 Ui_window.destroy();
1287 common_free_interface_palette(); // restore game palette
1290 // unload special mission icons
1291 sim_room_unload_mission_icons();
1294 // ---------------------------------------------------------------------
1295 // sim_room_do_frame()
1297 // Called once per frame to process user input for the sim_room Assignment Screen
1299 void sim_room_do_frame(float frametime)
1302 int i, k, y, z, line;
1303 int font_height = gr_get_font_height();
1304 int select_tease_line = -1; // line mouse is down on, but won't be selected until button released
1307 for (i=0; i<Num_campaigns; i++)
1308 if (!stricmp(Campaign_file_names[i], Campaign.filename)) {
1313 if ( help_overlay_active(SIM_ROOM_OVERLAY) ) {
1314 Buttons[gr_screen.res][HELP_BUTTON].button.reset_status();
1315 Ui_window.set_ignore_gadgets(1);
1318 k = Ui_window.process() & ~KEY_DEBUGGED;
1320 if ( (k > 0) || B1_JUST_RELEASED ) {
1321 if ( help_overlay_active(SIM_ROOM_OVERLAY) ) {
1322 help_overlay_set_state(SIM_ROOM_OVERLAY, 0);
1323 Ui_window.set_ignore_gadgets(0);
1328 if ( !help_overlay_active(SIM_ROOM_OVERLAY) ) {
1329 Ui_window.set_ignore_gadgets(0);
1333 case SDLK_DOWN: // scroll list down
1334 sim_room_scroll_line_down();
1337 case SDLK_UP: // scroll list up
1338 sim_room_scroll_line_up();
1342 gameseq_post_event(GS_EVENT_MAIN_MENU);
1345 case KEY_CTRLED | SDLK_UP:
1346 sim_room_button_pressed(TECH_DATABASE_BUTTON);
1349 case KEY_CTRLED | SDLK_DOWN:
1350 sim_room_button_pressed(CUTSCENES_BUTTON);
1354 if (Player->readyroom_listing_mode == MODE_CAMPAIGNS)
1355 Player->readyroom_listing_mode = MODE_MISSIONS;
1357 Player->readyroom_listing_mode = MODE_CAMPAIGNS;
1359 Selected_line = Scroll_offset = 0;
1360 gamesnd_play_iface(SND_USER_SELECT);
1361 sim_room_build_listing();
1365 gamesnd_play_iface(SND_SWITCH_SCREENS);
1366 gameseq_post_event(GS_EVENT_OPTIONS_MENU);
1370 for (i=0; i<NUM_BUTTONS; i++){
1371 if (Buttons[gr_screen.res][i].button.pressed()){
1372 if (sim_room_button_pressed(i)){
1378 for (i=0; i<LIST_BUTTONS_MAX; i++) {
1379 if (List_buttons[i].is_mouse_on())
1380 select_tease_line = i + Scroll_offset;
1382 if (List_buttons[i].pressed()) {
1383 Selected_line = i + Scroll_offset;
1384 gamesnd_play_iface(SND_USER_SELECT);
1388 GR_MAYBE_CLEAR_RES(Background_bitmap);
1389 if (Background_bitmap >= 0) {
1390 gr_set_bitmap(Background_bitmap, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
1396 for (i=TECH_DATABASE_BUTTON; i<=CREDITS_BUTTON; i++){
1397 if (Buttons[gr_screen.res][i].button.button_down()){
1402 if (i > CREDITS_BUTTON){
1403 Buttons[gr_screen.res][SIMULATOR_BUTTON].button.draw_forced(2);
1406 if (!Buttons[gr_screen.res][CAMPAIGN_TAB].button.button_down() && !Buttons[gr_screen.res][MISSION_TAB].button.button_down()) {
1407 if (Player->readyroom_listing_mode == MODE_CAMPAIGNS){
1408 Buttons[gr_screen.res][CAMPAIGN_TAB].button.draw_forced(2);
1409 } else if (Player->readyroom_listing_mode == MODE_MISSIONS){
1410 Buttons[gr_screen.res][MISSION_TAB].button.draw_forced(2);
1415 if (Player->readyroom_listing_mode == MODE_CAMPAIGNS) {
1416 gr_set_color_fast(&Color_text_heading);
1417 strcpy(buf, Campaign.name);
1418 gr_force_fit_string(buf, 255, list_w1);
1419 gr_printf(list_x1, Mission_list_coords[gr_screen.res][1], buf);
1421 if (Campaign.filename) {
1422 sprintf(buf, NOX("%s%s"), Campaign.filename, FS_CAMPAIGN_FILE_EXT);
1423 gr_force_fit_string(buf, 255, list_w2);
1424 gr_printf(list_x2, Mission_list_coords[gr_screen.res][1], buf);
1426 // blit the proper icons if necessary
1427 char full_name[256];
1428 memset(full_name, 0, 256);
1429 strcpy(full_name, cf_add_ext(Campaign.filename,FS_CAMPAIGN_FILE_EXT));
1430 fs_builtin_mission *fb = game_find_builtin_mission(full_name);
1432 // sim_room_blit_icons(0, Mission_list_coords[gr_screen.res][1], fb, 0);
1437 line = Scroll_offset;
1438 while (sim_room_line_query_visible(line)) {
1439 y = list_y + sim_room_lines[line].y - sim_room_lines[Scroll_offset].y;
1441 if (sim_room_lines[line].type != READYROOM_LINE_CAMPAIGN) {
1442 List_buttons[line - Scroll_offset].update_dimensions(list_x1, y, list_x2 + list_w2 - list_x1, font_height);
1443 List_buttons[line - Scroll_offset].enable();
1446 List_buttons[line - Scroll_offset].disable();
1448 if (line == Selected_line)
1449 gr_set_color_fast(&Color_text_selected);
1450 else if (line == select_tease_line)
1451 gr_set_color_fast(&Color_text_subselected);
1453 gr_set_color_fast(&Color_text_normal);
1455 strcpy(buf, sim_room_lines[line].name);
1456 gr_force_fit_string(buf, 255, list_x1 + list_w1 - sim_room_lines[line].x);
1457 gr_printf(sim_room_lines[line].x, y, buf);
1459 if (sim_room_lines[line].filename) {
1460 strcpy(buf, sim_room_lines[line].filename);
1461 gr_force_fit_string(buf, 255, list_w2);
1462 gr_printf(list_x2, y, buf);
1465 // blit additional icon information
1466 sim_room_blit_icons(line, y);
1471 i = line - Scroll_offset;
1472 while (i < LIST_BUTTONS_MAX)
1473 List_buttons[i++].disable();
1475 // blit help overlay if active
1476 help_overlay_maybe_blit(SIM_ROOM_OVERLAY);
1481 void sim_room_blit_icons(int line_index, int y_start, fs_builtin_mission *fb, int is_md)
1483 int is_from_volition = 0;
1485 // determine icon status
1487 is_from_volition = (sim_room_lines[line_index].flags & READYROOM_FLAG_FROM_VOLITION) ? 1 : 0;
1489 is_md = (sim_room_lines[line_index].flags & READYROOM_FLAG_FROM_MDISK) ? 1 : 0;
1492 is_from_volition = (fb->flags & FSB_FROM_VOLITION) ? 1 : 0;
1494 is_md = (fb->flags & FSB_FROM_MDISK) ? 1 : 0;
1498 // if the line is flagged as a volition file
1499 if(is_from_volition && (Mission_icon_bitmaps[MISSION_ICON_VOLITION] >= 0)){
1500 gr_set_bitmap(Mission_icon_bitmaps[MISSION_ICON_VOLITION], GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
1501 gr_bitmap(Sim_volition_icon_x[gr_screen.res], y_start + MISSION_ICON_VOLITION_Y_OFFSET);
1505 if(is_md && (Mission_icon_bitmaps[MISSION_ICON_MDISK] >= 0)){
1506 gr_set_bitmap(Mission_icon_bitmaps[MISSION_ICON_MDISK], GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
1507 gr_bitmap(Sim_silent_icon_x[gr_screen.res], y_start + MISSION_ICON_MDISK_Y_OFFSET);
1512 /// Campaign room stuff below
1513 int Cr_list_coords[GR_NUM_RESOLUTIONS][4] = {
1526 int Cr_info_coords[GR_NUM_RESOLUTIONS][4] = {
1539 #define CR_NUM_BUTTONS 6
1541 #define CR_SCROLL_UP_BUTTON 0
1542 #define CR_SCROLL_DOWN_BUTTON 1
1543 #define CR_SCROLL_INFO_UP_BUTTON 2
1544 #define CR_SCROLL_INFO_DOWN_BUTTON 3
1545 #define CR_RESET_BUTTON 4
1546 #define CR_COMMIT_BUTTON 5
1548 #define MAX_INFO_LINES 20
1550 #define MAX_INFO_LINE_LEN 256
1552 ui_button_info Cr_buttons[GR_NUM_RESOLUTIONS][CR_NUM_BUTTONS] = {
1555 ui_button_info("CAB_00", 0, 95, -1, -1, 0), // scroll up
1556 ui_button_info("CAB_01", 0, 142, -1, -1, 1), // scroll down
1557 ui_button_info("CAB_02", 17, 259, -1, -1, 2), // info scroll up
1558 ui_button_info("CAB_03", 17, 307, -1, -1, 3), // info scroll down
1559 ui_button_info("CAB_07", 545, 323, -1, -1, 7), // reset
1560 ui_button_info("CAB_04", 561, 411, -1, -1, 4), // select
1562 ui_button_info("CAB_00", 2, 42, -1, -1, 0),
1563 ui_button_info("CAB_01", 2, 89, -1, -1, 1),
1564 ui_button_info("CAB_02", 2, 279, -1, -1, 2),
1565 ui_button_info("CAB_03", 2, 325, -1, -1, 3),
1566 ui_button_info("CAB_04", 579, 353, -1, -1, 4),
1567 ui_button_info("CAB_05", 575, 434, -1, -1, 5),
1571 ui_button_info("2_CAB_00", 3, 68, -1, -1, 0),
1572 ui_button_info("2_CAB_01", 3, 142, -1, -1, 1),
1573 ui_button_info("2_CAB_02", 3, 446, -1, -1, 2),
1574 ui_button_info("2_CAB_03", 3, 520, -1, -1, 3),
1575 ui_button_info("2_CAB_04", 927, 565, -1, -1, 4),
1576 ui_button_info("2_CAB_05", 920, 694, -1, -1, 5),
1582 #define CR_NUM_TEXT 3
1584 UI_XSTR Cr_text[GR_NUM_RESOLUTIONS][CR_NUM_TEXT] = {
1586 { "Restart", 1403, 569, 326, UI_XSTR_COLOR_GREEN, -1, &Cr_buttons[0][CR_RESET_BUTTON].button },
1587 { "Campaign", 1404, 569, 337, UI_XSTR_COLOR_GREEN, -1, &Cr_buttons[0][CR_RESET_BUTTON].button },
1588 { "Select", 1409, 568, 413, UI_XSTR_COLOR_PINK, -1, &Cr_buttons[0][CR_COMMIT_BUTTON].button },
1591 { "Restart", 1403, 922, 523, UI_XSTR_COLOR_GREEN, -1, &Cr_buttons[1][CR_RESET_BUTTON].button },
1592 { "Campaign", 1404, 922, 538, UI_XSTR_COLOR_GREEN, -1, &Cr_buttons[1][CR_RESET_BUTTON].button },
1593 { "Select", 1409, 921, 665, UI_XSTR_COLOR_PINK, -1, &Cr_buttons[1][CR_COMMIT_BUTTON].button },
1598 static int Num_desc_lines;
1599 static int Desc_scroll_offset;
1600 static int Selected_campaign_index;
1601 static int Active_campaign_index;
1603 char *Info_text_ptrs[MAX_INFO_LINES];
1604 int Num_info_lines, Info_text_line_size[MAX_INFO_LINES];
1606 void campaign_room_build_listing()
1608 int c, i, y, type, max_players;
1609 int font_height = gr_get_font_height();
1610 char name[NAME_LENGTH];
1613 if (!Campaign_names_inited) {
1614 for (i=0; i<Num_campaigns; i++) {
1615 Campaign_names[i] = NULL;
1616 if ( mission_campaign_get_info(Campaign_file_names[i], name, &type, &max_players) ) {
1618 if((game_find_builtin_mission(name) == NULL) && !strstr(name, "peterdrake")){
1621 Campaign_names[i] = strdup(name);
1624 if (type == CAMPAIGN_TYPE_SINGLE){
1625 Campaign_names[i] = strdup(name);
1631 Campaign_names_inited = 1;
1634 for (c=0; c<Num_campaigns; c++) {
1635 if (Campaign_names[c]) {
1637 // determine some extra information
1639 fs_builtin_mission *fb = game_find_builtin_mission(Campaign_file_names[c]);
1641 if(fb->flags & FSB_FROM_VOLITION){
1642 flags |= READYROOM_FLAG_FROM_VOLITION;
1645 if(fb->flags & FSB_FROM_MDISK){
1646 flags |= READYROOM_FLAG_FROM_MDISK;
1651 sim_room_line_add(READYROOM_LINE_CAMPAIGN, Campaign_names[c], Campaign_file_names[c], Cr_list_coords[gr_screen.res][0], y, flags);
1652 y += font_height + 2;
1657 void set_new_campaign_line(int n)
1661 Selected_campaign_index = n;
1662 str = Campaign_descs[Selected_campaign_index];
1665 Num_info_lines = split_str(str, Cr_info_coords[gr_screen.res][2], Info_text_line_size, Info_text_ptrs, MAX_INFO_LINES);
1666 Assert(Num_info_lines >= 0);
1669 Desc_scroll_offset = 0;
1672 void campaign_room_scroll_info_up()
1674 if (Desc_scroll_offset) {
1675 Desc_scroll_offset--;
1676 gamesnd_play_iface(SND_SCROLL);
1679 gamesnd_play_iface(SND_GENERAL_FAIL);
1682 void campaign_room_scroll_info_down()
1684 if ( (Num_info_lines - Desc_scroll_offset) * gr_get_font_height() > Cr_info_coords[gr_screen.res][3]) {
1685 Desc_scroll_offset++;
1686 gamesnd_play_iface(SND_SCROLL);
1689 gamesnd_play_iface(SND_GENERAL_FAIL);
1692 // returns: 0 = success, !0 = aborted or failed
1693 int campaign_room_reset_campaign(int n)
1698 // 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]);
1699 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));
1701 filename = (char *) malloc(strlen(Campaign_file_names[n]) + 5);
1702 strcpy(filename, Campaign_file_names[n]);
1703 strcat(filename, FS_CAMPAIGN_FILE_EXT);
1705 mission_campaign_savefile_delete(filename);
1706 mission_campaign_load(filename);
1707 mission_campaign_next_mission();
1714 void campaign_room_commit()
1716 if (Selected_campaign_index < 0) {
1717 gamesnd_play_iface(SND_GENERAL_FAIL);
1721 if (stricmp(Campaign_file_names[Selected_campaign_index], Campaign.filename)) { // new campaign selected
1722 if ((Active_campaign_index >= 0) && campaign_room_reset_campaign(Active_campaign_index)) {
1723 gamesnd_play_iface(SND_GENERAL_FAIL);
1727 mission_campaign_savefile_delete(Campaign_file_names[Selected_campaign_index]);
1728 mission_campaign_load(Campaign_file_names[Selected_campaign_index]);
1729 strcpy(Player->current_campaign, Campaign.filename); // track new campaign for player
1732 if (mission_campaign_next_mission()) { // is campaign and next mission valid?
1733 gamesnd_play_iface(SND_GENERAL_FAIL);
1737 gameseq_post_event(GS_EVENT_MAIN_MENU);
1738 gamesnd_play_iface(SND_COMMIT_PRESSED);
1741 int campaign_room_button_pressed(int n)
1744 case CR_SCROLL_UP_BUTTON:
1745 sim_room_scroll_screen_up();
1748 case CR_SCROLL_DOWN_BUTTON:
1749 sim_room_scroll_screen_down();
1752 case CR_SCROLL_INFO_UP_BUTTON:
1753 campaign_room_scroll_info_up();
1756 case CR_SCROLL_INFO_DOWN_BUTTON:
1757 campaign_room_scroll_info_down();
1760 case CR_COMMIT_BUTTON:
1761 campaign_room_commit();
1765 case CR_HELP_BUTTON:
1766 launch_context_help();
1767 gamesnd_play_iface(SND_HELP_PRESSED);
1770 case CR_OPTIONS_BUTTON:
1771 gamesnd_play_iface(SND_SWITCH_SCREENS);
1772 gameseq_post_event(GS_EVENT_OPTIONS_MENU);
1776 case CR_RESET_BUTTON:
1777 if ( (Active_campaign_index < 0) || (Active_campaign_index >= Num_campaigns) )
1778 gamesnd_play_iface(SND_GENERAL_FAIL);
1779 else if (campaign_room_reset_campaign(Active_campaign_index))
1780 gamesnd_play_iface(SND_GENERAL_FAIL);
1782 gamesnd_play_iface(SND_USER_SELECT);
1790 void campaign_room_init()
1792 int i, j, load_failed;
1794 char wild_card[256];
1796 list_h = Mission_list_coords[gr_screen.res][3];
1799 common_set_interface_palette("InterfacePalette"); // set the interface palette
1801 Ui_window.create(0, 0, gr_screen.max_w, gr_screen.max_h, 0);
1802 Ui_window.set_mask_bmap(Campaign_mask_filename[gr_screen.res]);
1804 for (i=0; i<CR_NUM_BUTTONS; i++) {
1805 b = &Cr_buttons[gr_screen.res][i];
1807 b->button.create(&Ui_window, "", b->x, b->y, 60, 30, (i < 2), 1);
1808 // set up callback for when a mouse first goes over a button
1809 b->button.set_highlight_action(common_play_highlight_sound);
1810 b->button.set_bmaps(b->filename);
1811 b->button.link_hotspot(b->hotspot);
1814 for (i=0; i<LIST_BUTTONS_MAX; i++) {
1815 List_buttons[i].create(&Ui_window, "", 0, 0, 60, 30, 0, 1);
1816 List_buttons[i].hide();
1817 List_buttons[i].disable();
1822 for(i=0; i<CR_NUM_TEXT; i++){
1823 Ui_window.add_XSTR(&Cr_text[gr_screen.res][i]);
1827 // set up sim_rooms for buttons so we draw the correct animation frame when a key is pressed
1828 Cr_buttons[gr_screen.res][CR_SCROLL_UP_BUTTON].button.set_hotkey(SDLK_PAGEUP);
1829 Cr_buttons[gr_screen.res][CR_SCROLL_DOWN_BUTTON].button.set_hotkey(SDLK_PAGEDOWN);
1830 Cr_buttons[gr_screen.res][CR_RESET_BUTTON].button.set_hotkey(SDLK_DELETE);
1831 Cr_buttons[gr_screen.res][CR_COMMIT_BUTTON].button.set_hotkey(KEY_CTRLED | SDLK_RETURN);
1832 // Cr_buttons[gr_screen.res][CR_HELP_BUTTON].button.set_hotkey(KEY_F2);
1834 Background_bitmap = bm_load(Campaign_filename[gr_screen.res]);
1836 // load in help overlay bitmap
1837 help_overlay_load(CAMPAIGN_ROOM_OVERLAY);
1838 help_overlay_set_state(CAMPAIGN_ROOM_OVERLAY,0);
1842 Desc_scroll_offset = Scroll_offset = 0;
1843 load_failed = mission_load_up_campaign();
1845 mission_campaign_next_mission();
1848 Campaign.filename[0] = 0;
1849 Campaign.num_missions = 0;
1854 Get_file_list_filter = campaign_room_campaign_filter;
1855 memset(wild_card, 0, 256);
1856 strcpy(wild_card, NOX("*"));
1857 strcat(wild_card, FS_CAMPAIGN_FILE_EXT);
1858 Num_campaigns = cf_get_file_list(MAX_CAMPAIGNS, Campaign_file_names, CF_TYPE_MISSIONS, wild_card, CF_SORT_NAME);
1860 for (i=0; i<Num_campaigns; i++) {
1861 for (j=0; j<Num_campaigns; j++) {
1862 if (Campaign_file_names_temp[j]) {
1863 if (!strncmp(Campaign_file_names[i], Campaign_file_names_temp[j], strlen(Campaign_file_names_temp[j]) - 4)) {
1864 Campaign_descs[i] = Campaign_descs_temp[j];
1865 free(Campaign_file_names_temp[j]);
1866 Campaign_file_names_temp[j] = NULL;
1872 Assert(j < Num_campaigns); // Campaign not found? How is that possible?
1875 Campaign_names_inited = 0;
1876 campaign_room_build_listing();
1878 Selected_campaign_index = Active_campaign_index = -1;
1880 for (i=0; i<Num_campaigns; i++)
1881 if (!stricmp(Campaign_file_names[i], Campaign.filename)) {
1882 set_new_campaign_line(i);
1883 Active_campaign_index = i;
1889 void campaign_room_close()
1893 for (i=0; i<Num_campaigns; i++) {
1894 if (Campaign_descs[i] != NULL) {
1895 free(Campaign_descs[i]);
1896 Campaign_descs[i] = NULL;
1900 if (Background_bitmap >= 0)
1901 bm_unload(Background_bitmap);
1903 if (Campaign_names_inited) {
1904 for (i=0; i<Num_campaigns; i++) {
1905 if (Campaign_names[i] != NULL) {
1906 free(Campaign_names[i]);
1907 Campaign_names[i] = NULL;
1912 for (i=0; i<Num_campaigns; i++) {
1913 if (Campaign_file_names[i] != NULL) {
1914 free(Campaign_file_names[i]);
1915 Campaign_file_names[i] = NULL;
1919 // unload the overlay bitmap
1920 help_overlay_unload(CAMPAIGN_ROOM_OVERLAY);
1922 Ui_window.destroy();
1923 common_free_interface_palette(); // restore game palette
1927 void campaign_room_do_frame(float frametime)
1930 char line_text[MAX_INFO_LINE_LEN];
1932 int font_height = gr_get_font_height();
1933 int select_tease_line = -1; // line mouse is down on, but won't be selected until button released
1935 if ( help_overlay_active(CAMPAIGN_ROOM_OVERLAY) ) {
1936 // Cr_buttons[gr_screen.res][CR_HELP_BUTTON].button.reset_status();
1937 Ui_window.set_ignore_gadgets(1);
1940 k = Ui_window.process() & ~KEY_DEBUGGED;
1942 if ( (k > 0) || B1_JUST_RELEASED ) {
1943 if ( help_overlay_active(CAMPAIGN_ROOM_OVERLAY) ) {
1944 help_overlay_set_state(CAMPAIGN_ROOM_OVERLAY, 0);
1945 Ui_window.set_ignore_gadgets(0);
1950 if ( !help_overlay_active(CAMPAIGN_ROOM_OVERLAY) ) {
1951 Ui_window.set_ignore_gadgets(0);
1955 case SDLK_DOWN: // scroll list down
1956 if (Selected_campaign_index < Num_campaigns - 1) {
1957 set_new_campaign_line(Selected_campaign_index + 1);
1958 gamesnd_play_iface(SND_SCROLL);
1961 gamesnd_play_iface(SND_GENERAL_FAIL);
1965 case SDLK_UP: // scroll list up
1966 if (Selected_campaign_index < 0)
1967 Selected_campaign_index = 1;
1969 if (Selected_campaign_index) {
1970 set_new_campaign_line(Selected_campaign_index - 1);
1971 gamesnd_play_iface(SND_SCROLL);
1974 gamesnd_play_iface(SND_GENERAL_FAIL);
1979 gameseq_post_event(GS_EVENT_MAIN_MENU);
1983 for (i=0; i<CR_NUM_BUTTONS; i++){
1984 if (Cr_buttons[gr_screen.res][i].button.pressed()){
1985 if (campaign_room_button_pressed(i)){
1991 for (i=0; i<LIST_BUTTONS_MAX; i++) {
1992 if (List_buttons[i].is_mouse_on()){
1993 select_tease_line = i + Scroll_offset;
1996 if (List_buttons[i].pressed()) {
1997 set_new_campaign_line(i + Scroll_offset);
1998 gamesnd_play_iface(SND_USER_SELECT);
2002 GR_MAYBE_CLEAR_RES(Background_bitmap);
2003 if (Background_bitmap >= 0) {
2004 gr_set_bitmap(Background_bitmap, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
2011 line = Scroll_offset;
2012 while (sim_room_line_query_visible(line)) {
2013 y = Cr_list_coords[gr_screen.res][1] + sim_room_lines[line].y - sim_room_lines[Scroll_offset].y;
2015 List_buttons[line - Scroll_offset].update_dimensions(Cr_list_coords[gr_screen.res][0], y, Cr_list_coords[gr_screen.res][2], font_height);
2016 List_buttons[line - Scroll_offset].enable();
2018 if (!stricmp(sim_room_lines[line].filename, Campaign.filename)) {
2019 gr_set_color_fast(&Color_white);
2020 i = y + font_height / 2 - 1;
2021 gr_circle(Cr_list_coords[gr_screen.res][0] - 6, i, 5);
2023 gr_set_color_fast(&Color_bright_white);
2024 gr_line(Cr_list_coords[gr_screen.res][0] - 10, i, Cr_list_coords[gr_screen.res][0] - 8, i);
2025 gr_line(Cr_list_coords[gr_screen.res][0] - 6, i - 4, Cr_list_coords[gr_screen.res][0] - 6, i - 2);
2026 gr_line(Cr_list_coords[gr_screen.res][0] - 4, i, Cr_list_coords[gr_screen.res][0] - 2, i);
2027 gr_line(Cr_list_coords[gr_screen.res][0] - 6, i + 2, Cr_list_coords[gr_screen.res][0] - 6, i + 4);
2030 if (line == Selected_campaign_index)
2031 gr_set_color_fast(&Color_text_selected);
2032 else if (line == select_tease_line)
2033 gr_set_color_fast(&Color_text_subselected);
2035 gr_set_color_fast(&Color_text_normal);
2037 strcpy(buf, sim_room_lines[line].name);
2038 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);
2039 gr_printf(sim_room_lines[line].x, y, buf);
2043 i = line - Scroll_offset;
2044 while (i < LIST_BUTTONS_MAX)
2045 List_buttons[i++].disable();
2048 i = Desc_scroll_offset;
2049 gr_set_color_fast(&Color_text_normal);
2051 while (y + font_height <= Cr_info_coords[gr_screen.res][3]) {
2052 if (i >= Num_info_lines)
2055 Assert(Info_text_line_size[i] < MAX_INFO_LINE_LEN);
2056 strncpy(line_text, Info_text_ptrs[i], Info_text_line_size[i]);
2057 line_text[Info_text_line_size[i]] = 0;
2058 drop_white_space(line_text);
2059 gr_string(Cr_info_coords[gr_screen.res][0], Cr_info_coords[gr_screen.res][1] + y, line_text);
2064 // blit help overlay if active
2065 help_overlay_maybe_blit(CAMPAIGN_ROOM_OVERLAY);
2070 void sim_room_load_mission_icons()
2075 for(idx=0; idx<NUM_MISSION_ICONS; idx++){
2076 Mission_icon_bitmaps[idx] = -1;
2077 Mission_icon_bitmaps[idx] = bm_load(Mission_icon_bitmap_filenames[idx]);
2081 void sim_room_unload_mission_icons()
2085 // unload all bitmaps
2086 for(idx=0; idx<NUM_MISSION_ICONS; idx++){
2087 if(Mission_icon_bitmaps[idx] >= 0){
2088 bm_unload(Mission_icon_bitmaps[idx]);
2089 Mission_icon_bitmaps[idx] = -1;