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