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