]> icculus.org git repositories - taylor/freespace2.git/blob - include/missioncampaign.h
rendering functions mostly done; more complete shader setup
[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.4  2003/06/11 18:30:32  taylor
19  * plug memory leaks
20  *
21  * Revision 1.3  2003/05/25 02:30:42  taylor
22  * Freespace 1 support
23  *
24  * Revision 1.2  2002/06/09 04:41:13  relnev
25  * added copyright header
26  *
27  * Revision 1.1.1.1  2002/05/03 03:28:12  root
28  * Initial import.
29  *
30  * 
31  * 16    9/30/99 6:02p Jefff
32  * Changes for OEM
33  * 
34  * 15    9/09/99 11:40p Dave
35  * Handle an SDL_assert() in beam code. Added supernova sounds. Play the right
36  * 2 end movies properly, based upon what the player did in the mission.
37  * 
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.
42  * 
43  * 13    9/06/99 9:45p Jefff
44  * break out of loop and skip mission support
45  * 
46  * 12    9/06/99 6:38p Dave
47  * Improved CD detection code.
48  * 
49  * 11    8/27/99 12:04a Dave
50  * Campaign loop screen.
51  * 
52  * 10    7/15/99 9:20a Andsager
53  * FS2_DEMO initial checkin
54  * 
55  * 9     4/25/99 3:02p Dave
56  * Build defines for the E3 build.
57  * 
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
61  * response packets.
62  * 
63  * 7     12/12/98 3:17p Andsager
64  * Clean up mission eval, goal, event and mission scoring.
65  * 
66  * 6     12/10/98 9:59a Andsager
67  * Fix some bugs with mission loops
68  * 
69  * 5     12/09/98 1:56p Andsager
70  * Initial checkin of mission loop
71  * 
72  * 4     11/05/98 5:55p Dave
73  * Big pass at reducing #includes
74  * 
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
78  * directory.
79  * 
80  * 2     10/07/98 10:53a Dave
81  * Initial checkin.
82  * 
83  * 1     10/07/98 10:49a Dave
84  * 
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.
89  * 
90  * 46    6/05/98 9:54a Lawrance
91  * OEM changes
92  * 
93  * 45    5/21/98 9:25p Allender
94  * endgame movie always viewable at end of campaign
95  * 
96  * 44    5/13/98 5:14p Allender
97  * red alert support to go back to previous mission
98  * 
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.
102  * 
103  * 42    4/28/98 5:25p Sandeep
104  * 
105  * 41    4/27/98 7:30p Hoffoss
106  * Added campaign descriptions to campaign files and changed campaign room
107  * to display them.
108  * 
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
113  * 
114  * 39    4/13/98 10:25p Hoffoss
115  * Added a flag for subspace missions, and for aboard the Galatea or
116  * Bastion.
117  * 
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.
121  * 
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
127  * condition.
128  * 
129  * 36    4/02/98 11:40a Lawrance
130  * check for #ifdef DEMO instead of #ifdef DEMO_RELEASE
131  * 
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
136  * 
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)
140  * 
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.
144  * 
145  * 32    3/17/98 4:17p Allender
146  * made Fred/FreeSpace use the same campaign loading code
147  * 
148  * 31    3/02/98 5:22p Hoffoss
149  * Removed ready room and added campaign room.
150  * 
151  * 30    2/26/98 10:07p Hoffoss
152  * Rewrote state saving and restoring to fix bugs and simplify the code.
153  * 
154  * 29    2/23/98 11:08p Dave
155  * Finished up multiplayer campaign support. Seems bug-free.
156  * 
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).
160  * 
161  * 27    2/05/98 10:14p Lawrance
162  * Implement Save and Quit
163  * 
164  * 26    12/19/97 2:59p Allender
165  * more stuff to get persistent ships/weapons across campaign missions
166  * 
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.
171  * 
172  * 24    12/18/97 5:12p Allender
173  * initial support for ship/weapon persistence
174  * 
175  * 23    12/05/97 1:55p Allender
176  * delete campaign save files when pilot is deleted
177  * 
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
181  * comapaign.
182  * 
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
187  * problem.
188  * 
189  * 20    11/16/97 1:11p Hoffoss
190  * Coded up readyroom screen, first pass.
191  * 
192  * 19    11/15/97 2:37p Dave
193  * More multiplayer campaign support.
194  * 
195  * 18    11/13/97 5:03p Sandeep
196  * added CSFE support
197  * 
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.
202  * 
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
206  * 
207  * 15    11/06/97 4:36p Allender
208  * campaign work to add a briefing cutscene to play before the briefing.
209  * 
210  * 14    10/21/97 4:50p Allender
211  * goal/event sexpression support.  Fixed campaign save file, sexpressions
212  * handling, sexpression editing, etc
213  * 
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
218  * 
219  * 12    9/18/97 10:18p Lawrance
220  * add function to extract the mission names from a campaign file
221  * 
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.
225  * 
226  * 10    8/13/97 5:49p Hoffoss
227  * Fixed bugs, made additions.
228  * 
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.
232  * 
233  * 8     5/09/97 9:49a Hoffoss
234  * Added campaign loading for Fred and 2 new tokens to campaign file
235  * format.
236  * 
237  * 7     4/25/97 1:55p Allender
238  * added close() routine to free memory at game shutdown
239  * 
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
244  * 
245  * 5     4/23/97 3:21p Allender
246  * more campaign stuff -- mission branching through campaign file now
247  * works!!!!
248  * 
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.
252  * 
253  * 3     4/18/97 9:59a Allender
254  * more campaign stuff.  All campaign related varaibles now stored in
255  * campaign structure
256  * 
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
260  * 
261  * 1     4/15/97 2:11p Allender
262  *
263  * $NoKeywords: $
264  */
265
266 #ifndef _MISSION_CAMPAIGN_H
267 #define _MISSION_CAMPAIGN_H
268
269 #include "parselo.h"
270 #include "cfile.h"
271 #include "ship.h"
272 #include "weapon.h"
273 #include "scoring.h"
274
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"
288 #else
289         #define BUILTIN_CAMPAIGN                "FreeSpace2"
290         #define BUILTIN_CAMPAIGN_NAME   "The Main Freespace2 Campaign"
291 #endif
292
293 #define MAX_CAMPAIGN_MISSIONS   100                     // maximum number of missions in a campaign
294
295 #define CAMPAIGN_ERROR_CORRUPT                  -1
296 #define CAMPAIGN_ERROR_SEXP_EXHAUSTED   -2
297
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
300 // missions.
301 #define CAMPAIGN_TYPE_SINGLE                    0
302 #define CAMPAIGN_TYPE_MULTI_COOP                1
303 #define CAMPAIGN_TYPE_MULTI_TEAMS       2
304
305 #define MAX_CAMPAIGN_TYPES                              3
306
307 // type of movies we may be able to play
308 #define CAMPAIGN_MOVIE_PRE_MISSION              1
309 #define CMAPAIGN_MOVIE_POST_MISSION             2
310
311 #define CAMPAIGN_SINGLE_PLAYER_SIG     0xddddeeee
312 #define CAMPAIGN_MULTI_PLAYER_SIG      0xeeeeffff
313
314 // defines for possibly persistent information
315 #define CAMPAIGN_PERSISTENT_SHIP                        1
316 #define CAMPAIGN_PERSISTENT_WEAPON              2
317
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
320
321 #define CAMPAIGN_LOOP_MISSION_UNINITIALIZED     -2
322
323 extern const char *campaign_types[MAX_CAMPAIGN_TYPES];
324
325 // structure for a campaign definition.  It contains the mission names and other interesting
326 // information about a campaign and the mission strucuture within.
327
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);
331 } mgoal;
332
333 typedef struct mevent {
334         char    name[NAME_LENGTH];
335         char    status;
336 } mevent;
337
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)
355         int                             flags;
356         scoring_struct  stats;
357 } cmission;
358
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
377 } campaign;
378
379 extern campaign Campaign;
380
381 // campaign wasn't ended
382 extern int Campaign_ended_in_mission;
383
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
386 // games
387 typedef struct campaign_info
388 {
389         char            filename[NAME_LENGTH];
390         int             num_missions_completed;
391         ubyte           missions_completed[MAX_CAMPAIGN_MISSIONS];
392 } campaign_info;
393
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;
400
401 // called at game startup time to load the default single player campaign
402 void mission_campaign_init( void );
403
404 // called to reload the default campaign
405 int mission_campaign_load_by_name( const char *filename );
406 int mission_campaign_load_by_name_csfe( const char *filename, const char *callsign );
407
408
409 // load up and initialize a new campaign
410 int mission_campaign_load( const char *filename, int load_savefile = 1 );
411
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 );
414
415 // declaration for local campaign save game load function
416 extern void mission_campaign_savefile_load( const char *cfilename );
417 extern void mission_campaign_savefile_delete( const char *cfilename, int is_multi = -1 );
418 extern void mission_campaign_delete_all_savefiles( const char *pilot_name, int is_multi );
419
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(const char *filename, char *name, const int max_len);
422
423 // function which sets up internal variable for player to play next mission in the campaign
424 extern int mission_campaign_next_mission( void );
425
426 // function which is called with the current mission in this campaign is over
427 extern void mission_campaign_mission_over( void );
428
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
432
433 // read in a campaign file.  Used by Fred.
434 int mission_campaign_load_fred(const char *filename, const char *name_verify = NULL);
435
436 // used by Fred to get a mission's list of goals.
437 void read_mission_goal_list(int num);
438
439 // returns index of mission with passed name
440 extern int mission_campaign_find_mission( const char *name );
441
442 // maybe play a movie.  type indicates before or after mission
443 extern void mission_campaign_maybe_play_movie(int type);
444
445 // save persistent information
446 extern void mission_campaign_save_persistent( int type, int index );
447
448 void mission_campaign_savefile_generate_root(char *filename, const int max_len);
449
450 // The following are functions I added to set up the globals and then
451 // execute the corresponding mission_campaign_savefile functions.
452
453 // Saves the campaign camp under the player name pname
454 int campaign_savefile_save(const char *pname);
455 // Deletes the campaign save camp under the player name pname
456 void campaign_delete_save( const char *cfn, const char *pname);
457 // Loads campaign camp from fname under player name pname
458 void campaign_savefile_load(const char *fname, const char *pname);
459
460 // get name and type of specified campaign file
461 int mission_campaign_get_info(const char *filename, char *name, int *type, int *max_players, char **desc = NULL);
462
463 // get a listing of missions in a campaign
464 int mission_campaign_get_mission_list(const char *filename, char **list, int max);
465
466 // load up a campaign for the current player.
467 int mission_load_up_campaign();
468
469 // stores mission goals and events in Campaign struct
470 void mission_campaign_store_goals_and_events();
471
472 // evaluates next mission and possible loop mission
473 void mission_campaign_eval_next_mission();
474
475 // returns to the beginning of the previous mission
476 int mission_campaign_previous_mission();
477
478 // proceeds to next mission in campaign
479 void mission_campaign_skip_to_next(int start_game = 1);
480
481 // break out of loop
482 void mission_campaign_exit_loop();
483
484 // jump to specified mission
485 void mission_campaign_jump_to_mission(const char *name);
486
487 // stuff for the end of the campaign of the single player game
488 void mission_campaign_end_init();
489 void mission_campaign_end_close();
490 void mission_campaign_end_do();
491
492 // End CSFE stuff
493 #endif
494