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/MissionCampaign.h $
15 * header file for dealing with campaigns
18 * Revision 1.4 2003/06/11 18:30:32 taylor
21 * Revision 1.3 2003/05/25 02:30:42 taylor
24 * Revision 1.2 2002/06/09 04:41:13 relnev
25 * added copyright header
27 * Revision 1.1.1.1 2002/05/03 03:28:12 root
31 * 16 9/30/99 6:02p Jefff
34 * 15 9/09/99 11:40p Dave
35 * Handle an Assert() in beam code. Added supernova sounds. Play the right
36 * 2 end movies properly, based upon what the player did in the mission.
38 * 14 9/07/99 6:55p Jefff
39 * functionality to break out of a loop. hacked functionality to jump to
40 * a specific mission in a campaign -- doesnt grant ships/weapons from
41 * skipped missions tho.
43 * 13 9/06/99 9:45p Jefff
44 * break out of loop and skip mission support
46 * 12 9/06/99 6:38p Dave
47 * Improved CD detection code.
49 * 11 8/27/99 12:04a Dave
50 * Campaign loop screen.
52 * 10 7/15/99 9:20a Andsager
53 * FS2_DEMO initial checkin
55 * 9 4/25/99 3:02p Dave
56 * Build defines for the E3 build.
58 * 8 2/25/99 4:19p Dave
59 * Added multiplayer_beta defines. Added cd_check define. Fixed a few
60 * release build warnings. Added more data to the squad war request and
63 * 7 12/12/98 3:17p Andsager
64 * Clean up mission eval, goal, event and mission scoring.
66 * 6 12/10/98 9:59a Andsager
67 * Fix some bugs with mission loops
69 * 5 12/09/98 1:56p Andsager
70 * Initial checkin of mission loop
72 * 4 11/05/98 5:55p Dave
73 * Big pass at reducing #includes
75 * 3 10/07/98 6:27p Dave
76 * Globalized mission and campaign file extensions. Removed Silent Threat
77 * special code. Moved \cache \players and \multidata into the \data
80 * 2 10/07/98 10:53a Dave
83 * 1 10/07/98 10:49a Dave
85 * 47 9/10/98 1:17p Dave
86 * Put in code to flag missions and campaigns as being MD or not in Fred
87 * and Freespace. Put in multiplayer support for filtering out MD
88 * missions. Put in multiplayer popups for warning of non-valid missions.
90 * 46 6/05/98 9:54a Lawrance
93 * 45 5/21/98 9:25p Allender
94 * endgame movie always viewable at end of campaign
96 * 44 5/13/98 5:14p Allender
97 * red alert support to go back to previous mission
99 * 43 5/12/98 4:16p Hoffoss
100 * Fixed bug where not all missions in all campaigns were being filtered
101 * out of stand alone mission listing in simulator room.
103 * 42 4/28/98 5:25p Sandeep
105 * 41 4/27/98 7:30p Hoffoss
106 * Added campaign descriptions to campaign files and changed campaign room
109 * 40 4/25/98 7:40p Allender
110 * fixd some small hotkey stuff. Worked on turret orientation being
111 * correct for multiplayer. new sexpression called end-campaign will will
112 * end the main campaign
114 * 39 4/13/98 10:25p Hoffoss
115 * Added a flag for subspace missions, and for aboard the Galatea or
118 * 38 4/08/98 6:16p Hoffoss
119 * Added a description field to campaign structure, since the campaign
120 * room has a window for this. We'll need to add this in sometime.
122 * 37 4/06/98 6:37p Dave
123 * Put in max_observers netgame server option. Make sure host is always
124 * defaulted to alpha 1 or zeta 1. Changed create game so that MAX_PLAYERS
125 * can always join but need to be kicked before commit can happen. Put in
126 * support for server ending a game and notifying clients of a special
129 * 36 4/02/98 11:40a Lawrance
130 * check for #ifdef DEMO instead of #ifdef DEMO_RELEASE
132 * 35 3/31/98 12:23a Allender
133 * changed macro names of campaign types to be more descriptive. Added
134 * "team" to objectives dialog for team v. team missions. Added two
135 * distinct multiplayer campaign types
137 * 34 3/30/98 10:37p Allender
138 * added demo.fsc as default campaign for demo. Delete obsolete pilots
139 * (including their campaign save games)
141 * 33 3/26/98 5:24p Allender
142 * put in respawn edit box into mission notes dialog. Made loading of
143 * missions/campaign happen when first entering the game setup screen.
145 * 32 3/17/98 4:17p Allender
146 * made Fred/FreeSpace use the same campaign loading code
148 * 31 3/02/98 5:22p Hoffoss
149 * Removed ready room and added campaign room.
151 * 30 2/26/98 10:07p Hoffoss
152 * Rewrote state saving and restoring to fix bugs and simplify the code.
154 * 29 2/23/98 11:08p Dave
155 * Finished up multiplayer campaign support. Seems bug-free.
157 * 28 2/10/98 5:51p Hoffoss
158 * Changed campaign stuff so new pilots start out with no active campaign
159 * (will get set in readyroom before user can move beyond the readyroom).
161 * 27 2/05/98 10:14p Lawrance
162 * Implement Save and Quit
164 * 26 12/19/97 2:59p Allender
165 * more stuff to get persistent ships/weapons across campaign missions
167 * 25 12/19/97 12:03p Allender
168 * Added GM_CAMPAIGN_MODE to indicate when player is in a campaign or not.
169 * Started adding FreeSpace support for carrying of ship/weapon types
170 * across missions in a campaign.
172 * 24 12/18/97 5:12p Allender
173 * initial support for ship/weapon persistence
175 * 23 12/05/97 1:55p Allender
176 * delete campaign save files when pilot is deleted
178 * 22 11/20/97 7:19p Hoffoss
179 * Renamed mission_campaign_do_new() to mission_campaign_load(). Changed
180 * readyroom to not lose campaign savefile until commiting to a different
183 * 21 11/20/97 5:36p Dave
184 * Hooked in a bunch of main hall changes (including sound). Made it
185 * possible to reposition (rewind/ffwd)
186 * sound buffer pointers. Fixed animation direction change framerate
189 * 20 11/16/97 1:11p Hoffoss
190 * Coded up readyroom screen, first pass.
192 * 19 11/15/97 2:37p Dave
193 * More multiplayer campaign support.
195 * 18 11/13/97 5:03p Sandeep
198 * 17 11/12/97 4:40p Dave
199 * Put in multiplayer campaign support parsing, loading and saving. Made
200 * command-line variables better named. Changed some things on the initial
201 * pilot select screen.
203 * 16 11/11/97 4:57p Dave
204 * Put in support for single vs. multiplayer pilots. Began work on
205 * multiplayer campaign saving. Put in initial player select screen
207 * 15 11/06/97 4:36p Allender
208 * campaign work to add a briefing cutscene to play before the briefing.
210 * 14 10/21/97 4:50p Allender
211 * goal/event sexpression support. Fixed campaign save file, sexpressions
212 * handling, sexpression editing, etc
214 * 13 10/20/97 5:13p Allender
215 * new subsystem sabotage/repair/set sexpressions. Added new event/goal
216 * status checking sexpressions (not fully implemented yet). Change
217 * campaign save files to save all events as well as goals
219 * 12 9/18/97 10:18p Lawrance
220 * add function to extract the mission names from a campaign file
222 * 11 8/21/97 10:58p Hoffoss
223 * Fixed bug in mission scanning for campaign editor, and added mission
224 * notes to sexp help window in campaign editor when mission is selected.
226 * 10 8/13/97 5:49p Hoffoss
227 * Fixed bugs, made additions.
229 * 9 8/08/97 5:18p Jasen
230 * Fixed bug with current campaign in pilot file has been deleted. Now it
231 * defaults back to default if current doesn't exist.
233 * 8 5/09/97 9:49a Hoffoss
234 * Added campaign loading for Fred and 2 new tokens to campaign file
237 * 7 4/25/97 1:55p Allender
238 * added close() routine to free memory at game shutdown
240 * 6 4/25/97 11:31a Allender
241 * Campaign state now saved in campaign save file in player directory.
242 * Made some global variables follow naming convention. Solidified
243 * continuing campaigns based on new structure
245 * 5 4/23/97 3:21p Allender
246 * more campaign stuff -- mission branching through campaign file now
249 * 4 4/22/97 10:44a Allender
250 * more campaign stuff. Info about multiple campaigns now stored in
251 * player file -- not saving some player information in save games.
253 * 3 4/18/97 9:59a Allender
254 * more campaign stuff. All campaign related varaibles now stored in
257 * 2 4/17/97 9:02p Allender
258 * campaign stuff. All campaign material stored in external file.
259 * Continuing campaign won't work at this point
261 * 1 4/15/97 2:11p Allender
266 #ifndef _MISSION_CAMPAIGN_H
267 #define _MISSION_CAMPAIGN_H
275 // name of the builtin campaign.
276 #if defined(FS2_DEMO) || defined(FS1_DEMO)
277 #define BUILTIN_CAMPAIGN "demo"
278 #define BUILTIN_CAMPAIGN_NAME "DEMO Campaign"
279 #elif defined(OEM_BUILD)
280 #define BUILTIN_CAMPAIGN "FreeSpace2OEM"
281 #define BUILTIN_CAMPAIGN_NAME "OEM Campaign"
282 #elif defined(E3_BUILD)
283 #define BUILTIN_CAMPAIGN "E3"
284 #define BUILTIN_CAMPAIGN_NAME "E3 Campaign"
285 #elif defined(MAKE_FS1)
286 #define BUILTIN_CAMPAIGN "FreeSpace"
287 #define BUILTIN_CAMPAIGN_NAME "The Main Freespace Campaign"
289 #define BUILTIN_CAMPAIGN "FreeSpace2"
290 #define BUILTIN_CAMPAIGN_NAME "The Main Freespace2 Campaign"
293 #define MAX_CAMPAIGN_MISSIONS 100 // maximum number of missions in a campaign
295 #define CAMPAIGN_ERROR_CORRUPT -1
296 #define CAMPAIGN_ERROR_SEXP_EXHAUSTED -2
298 // types of campaigns -- these defines match the string literals listed below which
299 // are found in the campaign files. I don't think that we need campaigns for furball
301 #define CAMPAIGN_TYPE_SINGLE 0
302 #define CAMPAIGN_TYPE_MULTI_COOP 1
303 #define CAMPAIGN_TYPE_MULTI_TEAMS 2
305 #define MAX_CAMPAIGN_TYPES 3
307 // type of movies we may be able to play
308 #define CAMPAIGN_MOVIE_PRE_MISSION 1
309 #define CMAPAIGN_MOVIE_POST_MISSION 2
311 #define CAMPAIGN_SINGLE_PLAYER_SIG 0xddddeeee
312 #define CAMPAIGN_MULTI_PLAYER_SIG 0xeeeeffff
314 // defines for possibly persistent information
315 #define CAMPAIGN_PERSISTENT_SHIP 1
316 #define CAMPAIGN_PERSISTENT_WEAPON 2
318 #define CMISSION_FLAG_BASTION (1<<0) // set if stationed on Bastion, else Galatea
319 #define CMISSION_FLAG_SKIPPED (1<<1) // set if skipped, else not
321 #define CAMPAIGN_LOOP_MISSION_UNINITIALIZED -2
323 extern char *campaign_types[MAX_CAMPAIGN_TYPES];
325 // structure for a campaign definition. It contains the mission names and other interesting
326 // information about a campaign and the mission strucuture within.
328 typedef struct mgoal {
329 char name[NAME_LENGTH]; // name of the goal (same as name in the mission_goal structure
330 char status; // failed, satisfied, or incomplete (same as goal completion);
333 typedef struct mevent {
334 char name[NAME_LENGTH];
338 typedef struct cmission {
339 char *name; // name of the mission
340 char *notes; // mission notes for mission (used by Fred)
341 char briefing_cutscene[NAME_LENGTH]; // name of the cutscene to be played before this mission
342 int formula; // sexpression used to determine mission branching.
343 int completed; // has the player completed this mission
344 int num_goals; // number of goals this mission had
345 mgoal *goals; // malloced array of mgoals (of num_goals size) which has the goal completion status
346 int num_events; // number of events this mission had
347 mevent *events; // malloced array of mevents (of num_events) size) which has event completion status
348 int has_mission_loop; // whether current mission has side loop
349 int mission_loop_formula;// formula to determine whether to allow a side loop
350 char *mission_loop_desc; // message in popup
351 char *mission_loop_brief_anim;
352 char *mission_loop_brief_sound;
353 int level; // what level of the tree it's on (Fred)
354 int pos; // what x position on level it's on (Fred)
356 scoring_struct stats;
359 typedef struct campaign {
360 char name[NAME_LENGTH]; // name of the campaign
361 char filename[MAX_FILENAME_LEN]; // filename the campaign info is in
362 char *desc; // description of campaign
363 int type; // type of campaign
364 int num_missions; // number of missions in the campaign
365 int num_missions_completed; // number of missions in the campaign that have been flown
366 int current_mission; // the current mission that the player is playing. Only valid during the mission
367 int next_mission; // number of the next mission to fly when comtinuing the campaign. Always valid
368 int prev_mission; // mission that we just came from. Always valid
369 int loop_enabled; // whether mission loop is chosen - true during a loop, false otherwise
370 int loop_mission; // mission number of misssion loop (if any)
371 int loop_reentry; // mission number to return to after loop is finished
372 int realign_required; // are any missions missing alignment info? (Fred)
373 int num_players; // valid in multiplayer campaigns -- number of players campaign supports.
374 ubyte ships_allowed[MAX_SHIP_TYPES]; // which ships the player can use
375 ubyte weapons_allowed[MAX_WEAPON_TYPES]; // which weapons the player can use
376 cmission missions[MAX_CAMPAIGN_MISSIONS]; // decription of the missions
379 extern campaign Campaign;
381 // campaign wasn't ended
382 extern int Campaign_ended_in_mission;
384 // structure for players. Holds the campaign name, number of missions flown in the campaign, and result
385 // of the missions flown. This structure is stored in the player file and thus is persistent across
387 typedef struct campaign_info
389 char filename[NAME_LENGTH];
390 int num_missions_completed;
391 ubyte missions_completed[MAX_CAMPAIGN_MISSIONS];
394 // extern'ed so the mission loading can get a list of campains. Only use this
395 // data after mission_campaign_build_list() is called
396 #define MAX_CAMPAIGNS 128
397 extern char *Campaign_names[MAX_CAMPAIGNS];
398 extern char *Campaign_file_names[MAX_CAMPAIGNS];
399 extern int Num_campaigns;
401 // called at game startup time to load the default single player campaign
402 void mission_campaign_init( void );
404 // called to reload the default campaign
405 int mission_campaign_load_by_name( char *filename );
406 int mission_campaign_load_by_name_csfe( char *filename, char *callsign );
409 // load up and initialize a new campaign
410 int mission_campaign_load( char *filename, int load_savefile = 1 );
412 // function to save the state of the campaign between missions or to load a campaign save file
413 extern int mission_campaign_save( void );
415 // declaration for local campaign save game load function
416 extern void mission_campaign_savefile_load( char *cfilename );
417 extern void mission_campaign_savefile_delete( char *cfilename, int is_multi = -1 );
418 extern void mission_campaign_delete_all_savefiles( char *pilot_name, int is_multi );
420 // if a given campaign is a multiplayer campaign, we can load and save the multiplayer info portion with these functions
421 extern int mission_campaign_parse_is_multi(char *filename, char *name);
423 // function which sets up internal variable for player to play next mission in the campaign
424 extern int mission_campaign_next_mission( void );
426 // function which is called with the current mission in this campaign is over
427 extern void mission_campaign_mission_over( void );
429 // frees all memory at game close time
430 extern void mission_campaign_close( void ); // gets called in more than game close
431 extern void mission_campaign_shutdown( void ); // only called in game close
433 // read in a campaign file. Used by Fred.
434 int mission_campaign_load_fred(char *filename, char *name_verify = NULL);
436 // used by Fred to get a mission's list of goals.
437 void read_mission_goal_list(int num);
439 void mission_campaign_build_list( int multiplayer );
441 // returns index of mission with passed name
442 extern int mission_campaign_find_mission( char *name );
444 // maybe play a movie. type indicates before or after mission
445 extern void mission_campaign_maybe_play_movie(int type);
447 // save persistent information
448 extern void mission_campaign_save_persistent( int type, int index );
450 void mission_campaign_savefile_generate_root(char *filename);
452 // The following are functions I added to set up the globals and then
453 // execute the corresponding mission_campaign_savefile functions.
455 // Saves the campaign camp under the player name pname
456 int campaign_savefile_save(char *pname);
457 // Deletes the campaign save camp under the player name pname
458 void campaign_delete_save( char *cfn, char *pname);
459 // Loads campaign camp from fname under player name pname
460 void campaign_savefile_load(char *fname, char *pname);
462 // get name and type of specified campaign file
463 int mission_campaign_get_info(char *filename, char *name, int *type, int *max_players, char **desc = NULL);
465 // get a listing of missions in a campaign
466 int mission_campaign_get_mission_list(char *filename, char **list, int max);
468 // load up a campaign for the current player.
469 int mission_load_up_campaign();
471 // stores mission goals and events in Campaign struct
472 void mission_campaign_store_goals_and_events();
474 // evaluates next mission and possible loop mission
475 void mission_campaign_eval_next_mission();
477 // returns to the beginning of the previous mission
478 int mission_campaign_previous_mission();
480 // proceeds to next mission in campaign
481 void mission_campaign_skip_to_next(int start_game = 1);
484 void mission_campaign_exit_loop();
486 // jump to specified mission
487 void mission_campaign_jump_to_mission(char *name);
489 // stuff for the end of the campaign of the single player game
490 void mission_campaign_end_init();
491 void mission_campaign_end_close();
492 void mission_campaign_end_do();