]> icculus.org git repositories - taylor/freespace2.git/blob - src/mission/missionload.cpp
fix control binding
[taylor/freespace2.git] / src / mission / missionload.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
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
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Mission/MissionLoad.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * C source module for mission loading
16  *
17  * $Log$
18  * Revision 1.3  2005/03/31 00:04:25  taylor
19  * fix directory separator (thanks Pierre\!)
20  *
21  * Revision 1.2  2002/06/09 04:41:22  relnev
22  * added copyright header
23  *
24  * Revision 1.1.1.1  2002/05/03 03:28:09  root
25  * Initial import.
26  *
27  * 
28  * 5     7/20/99 1:49p Dave
29  * Peter Drake build. Fixed some release build warnings.
30  * 
31  * 4     10/13/98 9:28a Dave
32  * Started neatening up freespace.h. Many variables renamed and
33  * reorganized. Added AlphaColors.[h,cpp]
34  * 
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
38  * directory.
39  * 
40  * 2     10/07/98 10:53a Dave
41  * Initial checkin.
42  * 
43  * 1     10/07/98 10:49a Dave
44  * 
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
48  * missions folder)
49  * 
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
54  * correct locations
55  * 
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.
59  * 
60  * 99    2/23/98 6:55p Lawrance
61  * Rip out obsolete code.
62  * 
63  * 98    2/23/98 8:53a John
64  * String externalization
65  * 
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.
69  * 
70  * 96    1/17/98 8:49p Hoffoss
71  * Fixed mission_load() calls to handle failure correctly.
72  * 
73  * 95    12/28/97 1:34p John
74  * Fixed yet another mission filename bug
75  * 
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.
79  * 
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.
84  * 
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
88  * 
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
92  * 
93  * 90    10/31/97 11:27a John
94  * appended path for j:\tmp missions
95  * 
96  * 89    10/31/97 11:19a John
97  * added filter catagory for j:\tmp\*.fsm
98  * 
99  * 88    10/12/97 5:22p Lawrance
100  * have ESC back out of mission load screen
101  * 
102  * 87    9/18/97 10:19p Lawrance
103  * Add a mission campaign filter to the load screen
104  * 
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
109  * 
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.
113  * 
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.
117  * 
118  * 83    7/28/97 10:53a Lawrance
119  * initialize a timestamp
120  * 
121  * 82    7/17/97 4:25p John
122  * First, broken, stage of changing config stuff
123  * 
124  * 81    7/05/97 1:47p Lawrance
125  * write pilot file when a mission is loaded
126  * 
127  * 80    6/26/97 5:53p Lawrance
128  * save recently played missions, allow player to choose from list
129  * 
130  * 79    6/12/97 12:39p John
131  * made ui use freespace colors
132  * 
133  * 78    6/12/97 11:35a John
134  * more menu backgrounds
135  * 
136  * 77    5/14/97 1:33p Allender
137  * remmoved extern declaration
138  * 
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
142  * fucntion.
143  * 
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
147  * 
148  * 74    5/12/97 12:27p John
149  * Restructured Graphics Library to add support for multiple renderers.
150  * 
151  * 73    4/28/97 5:43p Lawrance
152  * allow hotkey assignment screen to work from ship selection
153  * 
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
158  * 
159  * 71    4/23/97 4:46p Allender
160  * remove unused code
161  * 
162  * 70    4/23/97 3:21p Allender
163  * more campaign stuff -- mission branching through campaign file now
164  * works!!!!
165  * 
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.
169  * 
170  * 68    4/18/97 9:59a Allender
171  * more campaign stuff.  All campaign related varaibles now stored in
172  * campaign structure
173  * 
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
177  * 
178  * 66    4/15/97 4:37p Lawrance
179  * removed unused variables
180  *
181 */
182
183 #include "missionload.h"
184 #include "missiongoals.h"
185 #include "missionparse.h"    
186 #include "missionshipchoice.h"
187 #include "missionlog.h"
188 #include "missionmessage.h"
189 #include "cfile.h"
190 #include "osapi.h"
191 #include "vecmat.h"
192 #include "player.h"
193 #include "object.h"
194 #include "ship.h"
195 #include "ailocal.h"
196 #include "managepilot.h"
197 #include "hud.h"
198 #include "freespace.h"
199 #include "key.h"
200 #include "2d.h"
201 #include "line.h"
202 #include "timer.h"
203 #include "math.h"
204 #include "linklist.h"
205 #include "mouse.h"
206 #include "weapon.h"
207 #include "gamesequence.h"
208 #include "ui.h"
209 #include "sexp.h"
210 #include "missionhotkey.h"
211 #include "missioncampaign.h"
212 #include "cfilesystem.h"
213 #include "alphacolors.h"
214
215
216 extern mission The_mission;  // need to send this info to the briefing
217
218 // -----------------------------------------------
219 // For recording most recent missions played
220 // -----------------------------------------------
221 char    Recent_missions[MAX_RECENT_MISSIONS][MAX_FILENAME_LEN];
222 int     Num_recent_missions;
223
224
225 // -----------------------------------------------------
226 // ml_update_recent_missions()
227 //
228 //      Update the Recent_missions[][] array
229 //
230 void ml_update_recent_missions(char *filename)
231 {
232         char    tmp[MAX_RECENT_MISSIONS][MAX_FILENAME_LEN], *p;
233         int     i,j;
234         
235
236         for ( i = 0; i < Num_recent_missions; i++ ) {
237                 SDL_strlcpy( tmp[i], Recent_missions[i], SDL_arraysize(tmp[0]) );
238         }
239
240         // get a pointer to just the basename of the filename (including extension)
241         p = strrchr(filename, DIR_SEPARATOR_CHAR);
242         if ( p == NULL ) {
243                 p = filename;
244         } else {
245                 p++;
246         }
247
248         SDL_assert(strlen(p) < MAX_FILENAME_LEN);
249         SDL_strlcpy( Recent_missions[0], p, SDL_arraysize(Recent_missions[0]) );
250
251         j = 1;
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 ) {
256                                 break;
257                         }
258                 }
259         }
260
261         Num_recent_missions = j;
262         SDL_assert(Num_recent_missions <= MAX_RECENT_MISSIONS);
263 }
264
265 // Mission_load takes no parameters.
266 // It expects the following global variables to be set correctly:
267 //   Game_current_mission_filename
268
269 // returns -1 if failed, 0 if successful
270 int mission_load()
271 {
272         char filename[128], *ext;       
273
274         mprintf(("MISSION LOAD: '%s'\n", Game_current_mission_filename));
275
276         SDL_strlcpy(filename, Game_current_mission_filename, SDL_arraysize(filename));
277         ext = SDL_strchr(filename, '.');
278         if (ext) {
279                 mprintf(( "Hmmm... Extension passed to mission_load...\n" ));
280                 *ext = 0;                               // remove any extension!
281         }
282
283         SDL_strlcat(filename, FS_MISSION_FILE_EXT, SDL_arraysize(filename));
284
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.
290
291         if ( parse_main(filename) )
292                 return -1;
293
294         if (Select_default_ship) {
295                 if ( create_default_player_ship() ) {
296                         Int3();
297                 }
298         }
299
300         ml_update_recent_missions(Game_current_mission_filename);  // update recently played missions list
301         write_pilot_file();
302         return 0;
303 }