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/Mission/MissionLoad.cpp $
15 * C source module for mission loading
18 * Revision 1.3 2005/03/31 00:04:25 taylor
19 * fix directory separator (thanks Pierre\!)
21 * Revision 1.2 2002/06/09 04:41:22 relnev
22 * added copyright header
24 * Revision 1.1.1.1 2002/05/03 03:28:09 root
28 * 5 7/20/99 1:49p Dave
29 * Peter Drake build. Fixed some release build warnings.
31 * 4 10/13/98 9:28a Dave
32 * Started neatening up freespace.h. Many variables renamed and
33 * reorganized. Added AlphaColors.[h,cpp]
35 * 3 10/07/98 6:27p Dave
36 * Globalized mission and campaign file extensions. Removed Silent Threat
37 * special code. Moved \cache \players and \multidata into the \data
40 * 2 10/07/98 10:53a Dave
43 * 1 10/07/98 10:49a Dave
45 * 102 5/19/98 1:19p Allender
46 * new low level reliable socket reading code. Make all missions/campaign
47 * load/save to data missions folder (i.e. we are rid of the player
50 * 101 5/10/98 10:05p Allender
51 * only show cutscenes which have been seen before. Made Fred able to
52 * write missions anywhere, defaulting to player misison folder, not data
53 * mission folder. Fix FreeSpace code to properly read missions from
56 * 100 4/30/98 4:53p John
57 * Restructured and cleaned up cfile code. Added capability to read off
58 * of CD-ROM drive and out of multiple pack files.
60 * 99 2/23/98 6:55p Lawrance
61 * Rip out obsolete code.
63 * 98 2/23/98 8:53a John
64 * String externalization
66 * 97 1/19/98 9:37p Allender
67 * Great Compiler Warning Purge of Jan, 1998. Used pragma's in a couple
68 * of places since I was unsure of what to do with code.
70 * 96 1/17/98 8:49p Hoffoss
71 * Fixed mission_load() calls to handle failure correctly.
73 * 95 12/28/97 1:34p John
74 * Fixed yet another mission filename bug
76 * 94 12/28/97 12:42p John
77 * Put in support for reading archive files; Made missionload use the
78 * cf_get_file_list function. Moved demos directory out of data tree.
80 * 93 12/27/97 2:39p John
81 * Took out the outdated ui_getfilelist functions. Made the mission load
82 * screen use cf_get_filelist instead. Fixed a bug in mission load that
83 * crashed the program if there are no missions available.
85 * 92 12/23/97 12:00p Allender
86 * change write_pilot_file to *not* take is_single as a default parameter.
87 * causing multiplayer pilots to get written to the single player folder
89 * 91 11/11/97 4:57p Dave
90 * Put in support for single vs. multiplayer pilots. Began work on
91 * multiplayer campaign saving. Put in initial player select screen
93 * 90 10/31/97 11:27a John
94 * appended path for j:\tmp missions
96 * 89 10/31/97 11:19a John
97 * added filter catagory for j:\tmp\*.fsm
99 * 88 10/12/97 5:22p Lawrance
100 * have ESC back out of mission load screen
102 * 87 9/18/97 10:19p Lawrance
103 * Add a mission campaign filter to the load screen
105 * 86 9/16/97 2:41p Allender
106 * beginning of code to change way player starts are handled. Reordered
107 * some code when missions loading since player ship is now created at
108 * mission load time instead of before misison load
110 * 85 8/25/97 5:47p Mike
111 * Increase number of missions supported in mission load list (outside
112 * campaign) to 256 and SDL_assert() if there are more than 256.
114 * 84 8/20/97 5:19p Hoffoss
115 * Fixed bug where creating a new pilot causes the mission load mission
116 * list box to be empty.
118 * 83 7/28/97 10:53a Lawrance
119 * initialize a timestamp
121 * 82 7/17/97 4:25p John
122 * First, broken, stage of changing config stuff
124 * 81 7/05/97 1:47p Lawrance
125 * write pilot file when a mission is loaded
127 * 80 6/26/97 5:53p Lawrance
128 * save recently played missions, allow player to choose from list
130 * 79 6/12/97 12:39p John
131 * made ui use freespace colors
133 * 78 6/12/97 11:35a John
134 * more menu backgrounds
136 * 77 5/14/97 1:33p Allender
137 * remmoved extern declaration
139 * 76 5/12/97 4:59p Allender
140 * move the rest of the mission initialization functions into
141 * game_level_init(). All mission loading now going through this
144 * 75 5/12/97 3:21p Allender
145 * re-ordered mission load code into single function in Freespace.
146 * Simulation part now runs as seperate thread
148 * 74 5/12/97 12:27p John
149 * Restructured Graphics Library to add support for multiple renderers.
151 * 73 4/28/97 5:43p Lawrance
152 * allow hotkey assignment screen to work from ship selection
154 * 72 4/25/97 11:31a Allender
155 * Campaign state now saved in campaign save file in player directory.
156 * Made some global variables follow naming convention. Solidified
157 * continuing campaigns based on new structure
159 * 71 4/23/97 4:46p Allender
162 * 70 4/23/97 3:21p Allender
163 * more campaign stuff -- mission branching through campaign file now
166 * 69 4/22/97 10:44a Allender
167 * more campaign stuff. Info about multiple campaigns now stored in
168 * player file -- not saving some player information in save games.
170 * 68 4/18/97 9:59a Allender
171 * more campaign stuff. All campaign related varaibles now stored in
174 * 67 4/17/97 9:02p Allender
175 * new campaign stuff. all campaign related material stored in external
176 * file. Continuing campaign won't work at this time
178 * 66 4/15/97 4:37p Lawrance
179 * removed unused variables
183 #include "missionload.h"
184 #include "missiongoals.h"
185 #include "missionparse.h"
186 #include "missionshipchoice.h"
187 #include "missionlog.h"
188 #include "missionmessage.h"
196 #include "managepilot.h"
198 #include "freespace.h"
204 #include "linklist.h"
207 #include "gamesequence.h"
210 #include "missionhotkey.h"
211 #include "missioncampaign.h"
212 #include "cfilesystem.h"
213 #include "alphacolors.h"
216 extern mission The_mission; // need to send this info to the briefing
218 // -----------------------------------------------
219 // For recording most recent missions played
220 // -----------------------------------------------
221 char Recent_missions[MAX_RECENT_MISSIONS][MAX_FILENAME_LEN];
222 int Num_recent_missions;
225 // -----------------------------------------------------
226 // ml_update_recent_missions()
228 // Update the Recent_missions[][] array
230 void ml_update_recent_missions(char *filename)
232 char tmp[MAX_RECENT_MISSIONS][MAX_FILENAME_LEN], *p;
236 for ( i = 0; i < Num_recent_missions; i++ ) {
237 SDL_strlcpy( tmp[i], Recent_missions[i], SDL_arraysize(tmp[0]) );
240 // get a pointer to just the basename of the filename (including extension)
241 p = strrchr(filename, DIR_SEPARATOR_CHAR);
248 SDL_assert(strlen(p) < MAX_FILENAME_LEN);
249 SDL_strlcpy( Recent_missions[0], p, SDL_arraysize(Recent_missions[0]) );
252 for ( i = 0; i < Num_recent_missions; i++ ) {
253 if ( SDL_strcasecmp(Recent_missions[0], tmp[i]) ) {
254 SDL_strlcpy(Recent_missions[j++], tmp[i], SDL_arraysize(Recent_missions[0]));
255 if ( j >= MAX_RECENT_MISSIONS ) {
261 Num_recent_missions = j;
262 SDL_assert(Num_recent_missions <= MAX_RECENT_MISSIONS);
265 // Mission_load takes no parameters.
266 // It expects the following global variables to be set correctly:
267 // Game_current_mission_filename
269 // returns -1 if failed, 0 if successful
272 char filename[128], *ext;
274 mprintf(("MISSION LOAD: '%s'\n", Game_current_mission_filename));
276 SDL_strlcpy(filename, Game_current_mission_filename, SDL_arraysize(filename));
277 ext = SDL_strchr(filename, '.');
279 mprintf(( "Hmmm... Extension passed to mission_load...\n" ));
280 *ext = 0; // remove any extension!
283 SDL_strlcat(filename, FS_MISSION_FILE_EXT, SDL_arraysize(filename));
285 // does the magical mission parsing
286 // creates all objects, except for the player object
287 // save the player object later since the player may get
288 // to choose the type of ship that he is to fly
289 // return value of 0 indicates success, other is failure.
291 if ( parse_main(filename) )
294 if (Select_default_ship) {
295 if ( create_default_player_ship() ) {
300 ml_update_recent_missions(Game_current_mission_filename); // update recently played missions list