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