FS2_Open
Open source remastering of the Freespace 2 engine
missioncampaign.h
Go to the documentation of this file.
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 the
6  * source.
7  *
8 */
9 
10 
11 
12 #ifndef _MISSION_CAMPAIGN_H
13 #define _MISSION_CAMPAIGN_H
14 
15 #include "stats/scoring.h"
16 
17 struct sexp_variable;
18 
19 // name of the builtin campaign.
20 #define BUILTIN_CAMPAIGN "FreeSpace2"
21 
22 #define MAX_CAMPAIGN_MISSIONS 100 // maximum number of missions in a campaign
23 
24 #define CAMPAIGN_ERROR_CORRUPT -1
25 #define CAMPAIGN_ERROR_SEXP_EXHAUSTED -2
26 #define CAMPAIGN_ERROR_MISSING -3
27 #define CAMPAIGN_ERROR_SAVEFILE -4
28 #define CAMPAIGN_ERROR_IGNORED -5
29 
30 // types of campaigns -- these defines match the string literals listed below which
31 // are found in the campaign files. I don't think that we need campaigns for furball
32 // missions.
33 #define CAMPAIGN_TYPE_SINGLE 0
34 #define CAMPAIGN_TYPE_MULTI_COOP 1
35 #define CAMPAIGN_TYPE_MULTI_TEAMS 2
36 
37 #define MAX_CAMPAIGN_TYPES 3
38 
39 // type of movies we may be able to play
40 #define CAMPAIGN_MOVIE_PRE_MISSION 1
41 #define CMAPAIGN_MOVIE_POST_MISSION 2
42 
43 #define CAMPAIGN_SINGLE_PLAYER_SIG 0xddddeeee
44 #define CAMPAIGN_MULTI_PLAYER_SIG 0xeeeeffff
45 
46 // defines for possibly persistent information
47 #define CAMPAIGN_PERSISTENT_SHIP 1
48 #define CAMPAIGN_PERSISTENT_WEAPON 2
49 
50 // Goober5000 - Bastion flag is not needed anymore; there can now be more than two main halls;
51 // but the flag is kept in order to maintain compatibility with older campaigns
52 #define CMISSION_FLAG_BASTION (1<<0) // set if stationed on Bastion, else Galatea
53 
54 #define CMISSION_FLAG_SKIPPED (1<<1) // set if skipped, else not
55 #define CMISSION_FLAG_HAS_LOOP (1<<2) // mission loop, e.g. FS2 SOC loops
56 #define CMISSION_FLAG_HAS_FORK (1<<3) // campaign fork, e.g. Scroll or BWO (mutually exclusive with loop)
57 
58 #define CAMPAIGN_LOOP_MISSION_UNINITIALIZED -2
59 
61 
62 
63 // campaign flags - Goober5000
64 #define CF_DEFAULT_VALUE 0
65 #define CF_CUSTOM_TECH_DATABASE (1 << 0) // Goober5000
66 
67 // structure for a campaign definition. It contains the mission names and other interesting
68 // information about a campaign and the mission strucuture within.
69 
70 typedef struct mgoal {
71  char name[NAME_LENGTH]; // name of the goal (same as name in the mission_goal structure
72  char status; // failed, satisfied, or incomplete (same as goal completion);
73 } mgoal;
74 
75 typedef struct mevent {
77  char status;
78 } mevent;
79 
80 class cmission
81 {
82 public:
83  char *name; // name of the mission
84  char *notes; // mission notes for mission (used by Fred)
85  char briefing_cutscene[NAME_LENGTH]; // name of the cutscene to be played before this mission
86  int formula; // sexpression used to determine mission branching.
87  int completed; // has the player completed this mission
88  int num_goals; // number of goals this mission had
89  mgoal *goals; // malloced array of mgoals (of num_goals size) which has the goal completion status
90  int num_events; // number of events this mission had
91  mevent *events; // malloced array of mevents (of num_events size) which has event completion status
92  int num_variables; // number of variables this mission had - Goober5000
93  sexp_variable *variables; // malloced array of sexp_variables (of num_variables size) containing mission-persistent variables - Goober5000
94  int mission_loop_formula; // formula to determine whether to allow a side loop
95  char *mission_branch_desc; // message in popup
98  int level; // what level of the tree it's on (Fred)
99  int pos; // what x position on level it's on (Fred)
100  int flags;
101  SCP_string main_hall; // which main hall the player is in - converted to SCP_string by CommanderDJ
102  ubyte debrief_persona_index; // which persona is used for ranks/badges - Goober5000
104 };
105 
106 class campaign
107 {
108 public:
109  char name[NAME_LENGTH]; // name of the campaign
110  char filename[MAX_FILENAME_LEN]; // filename the campaign info is in
111  char *desc; // description of campaign
112  int type; // type of campaign
113  int flags; // flags - Goober5000
114  int num_missions; // number of missions in the campaign
115  int num_missions_completed; // number of missions in the campaign that have been flown
116  int current_mission; // the current mission that the player is playing. Only valid during the mission
117  int next_mission; // number of the next mission to fly when comtinuing the campaign. Always valid
118  int prev_mission; // mission that we just came from. Always valid
119  int loop_enabled; // whether mission loop is chosen - true during a loop, false otherwise
120  int loop_mission; // mission number of misssion loop (if any)
121  int loop_reentry; // mission number to return to after loop is finished
122  int realign_required; // are any missions missing alignment info? (Fred)
123  int num_players; // valid in multiplayer campaigns -- number of players campaign supports.
124  ubyte ships_allowed[MAX_SHIP_CLASSES]; // which ships the player can use
125  ubyte weapons_allowed[MAX_WEAPON_TYPES]; // which weapons the player can use
126  cmission missions[MAX_CAMPAIGN_MISSIONS]; // decription of the missions
127  int num_variables; // number of variables this campaign had - Goober5000
128  sexp_variable *variables; // malloced array of sexp_variables (of num_variables size) containing campaign-persistent variables - Goober5000
129  int redalert_num_variables; // These two variables hold the previous state of the above for restoration
130  sexp_variable *redalert_variables; // if you replay the previous mission in a Red Alert scenario. -MageKing17
131 
133  : desc(NULL), num_missions(0), variables(NULL)
134  {
135  name[0] = 0;
136  filename[0] = 0;
137  }
138 };
139 
140 extern campaign Campaign;
141 
142 // campaign wasn't ended
144 
145 // structure for players. Holds the campaign name, number of missions flown in the campaign, and result
146 // of the missions flown. This structure is stored in the player file and thus is persistent across
147 // games
148 typedef struct campaign_info
149 {
153 } campaign_info;
154 
155 // extern'ed so the mission loading can get a list of campains. Only use this
156 // data after mission_campaign_build_list() is called
157 #define MAX_CAMPAIGNS 128
158 extern char *Campaign_names[MAX_CAMPAIGNS];
159 extern char *Campaign_file_names[MAX_CAMPAIGNS];
160 extern char *Campaign_descs[MAX_CAMPAIGNS];
161 extern int Num_campaigns;
162 extern int Campaign_names_inited;
164 
166 
167 // if the campaign file is missing this will get set for us to check against
168 extern int Campaign_file_missing;
169 
170 /*
171  * initialise Player_loadout with default values
172  */
173 void player_loadout_init();
174 
175 // called at game startup time to load the default single player campaign
176 void mission_campaign_init( void );
177 
178 // called to reload the default campaign
180 int mission_campaign_load_by_name_csfe( char *filename, char *callsign );
181 
182 
183 // load up and initialize a new campaign
184 int mission_campaign_load( char *filename, player *pl = NULL, int load_savefile = 1, bool reset_stats = true );
185 
186 // function to save the state of the campaign between missions or to load a campaign save file
187 extern int mission_campaign_save( void );
188 
189 // declaration for local campaign save game load function
190 extern void mission_campaign_savefile_delete( char *cfilename );
191 extern void mission_campaign_delete_all_savefiles( char *pilot_name );
192 
193 // if a given campaign is a multiplayer campaign, we can load and save the multiplayer info portion with these functions
194 extern int mission_campaign_parse_is_multi(char *filename, char *name);
195 
196 // function which sets up internal variable for player to play next mission in the campaign
197 extern int mission_campaign_next_mission( void );
198 
199 // function which is called with the current mission in this campaign is over
200 extern void mission_campaign_mission_over( bool do_next_mission = true );
201 
202 // frees all memory at game close time
203 extern void mission_campaign_clear( void );
204 
205 // read in a campaign file. Used by Fred.
206 int mission_campaign_load_fred(char *filename, char *name_verify = NULL);
207 
208 // used by Fred to get a mission's list of goals.
209 void read_mission_goal_list(int num);
210 
211 void mission_campaign_build_list(bool desc = false, bool sort = true, bool multiplayer = false);
213 
214 // returns index of mission with passed name
215 extern int mission_campaign_find_mission( char *name );
216 
217 // maybe play a movie. type indicates before or after mission
218 extern void mission_campaign_maybe_play_movie(int type);
219 
220 // save persistent information
221 extern void mission_campaign_save_persistent( int type, int index );
222 
224 
226 
227 // The following are functions I added to set up the globals and then
228 // execute the corresponding mission_campaign_savefile functions.
229 
230 // Saves the campaign camp under the player name pname
231 int campaign_savefile_save(char *pname);
232 // Deletes the campaign save camp under the player name pname
233 void campaign_delete_save( char *cfn, char *pname);
234 // Loads campaign camp from fname under player name pname
235 void campaign_savefile_load(char *fname, char *pname);
236 
237 // get name and type of specified campaign file
238 int mission_campaign_get_info(const char *filename, char *name, int *type, int *max_players, char **desc = NULL);
239 
240 // get a listing of missions in a campaign
241 int mission_campaign_get_mission_list(const char *filename, char **list, int max);
242 
243 // load up a campaign for the current player.
244 int mission_load_up_campaign( player *p = NULL );
245 
246 // stores mission goals and events in Campaign struct
248 
249 // stores campaign-persistent variables
251 
252 // does both of the above
254 
255 // evaluates next mission and possible loop mission
257 
258 // returns to the beginning of the previous mission
260 
261 // proceeds to next mission in campaign
262 void mission_campaign_skip_to_next(int start_game = 1);
263 
264 // break out of loop
266 
267 // jump to specified mission
268 void mission_campaign_jump_to_mission(char *name, bool no_skip = false);
269 
270 // stuff for the end of the campaign of the single player game
274 
275 // Goober5000 - save persistent variables
277 
279 
280 // End CSFE stuff
281 #endif
#define MAX_FILENAME_LEN
Definition: pstypes.h:324
void mission_campaign_clear(void)
void mission_campaign_store_goals_and_events()
void mission_campaign_free_list()
void mission_campaign_skip_to_next(int start_game=1)
void mission_campaign_maybe_play_movie(int type)
void player_loadout_init()
#define MAX_CAMPAIGN_TYPES
int realign_required
GLuint index
Definition: Glext.h:5608
char * mission_branch_desc
int mission_loop_formula
struct campaign_info campaign_info
campaign Campaign
int Campaign_file_missing
ubyte debrief_persona_index
void mission_campaign_mission_over(bool do_next_mission=true)
struct mgoal mgoal
char * Campaign_names[MAX_CAMPAIGNS]
char briefing_cutscene[NAME_LENGTH]
int Campaign_names_inited
SCP_vector< SCP_string > Ignored_campaigns
int mission_campaign_get_mission_list(const char *filename, char **list, int max)
int mission_campaign_get_info(const char *filename, char *name, int *type, int *max_players, char **desc=NULL)
int Num_campaigns
std::basic_string< char, std::char_traits< char >, std::allocator< char > > SCP_string
Definition: vmallocator.h:21
ubyte ships_allowed[MAX_SHIP_CLASSES]
void mission_campaign_end_close()
int mission_campaign_next_mission(void)
char * name
GLenum type
Definition: Gl.h:1492
sexp_variable * redalert_variables
Definition: player.h:85
void mission_campaign_exit_loop()
struct mevent mevent
GLenum pname
Definition: Gl.h:1517
int mission_campaign_load_by_name_csfe(char *filename, char *callsign)
char * notes
ubyte weapons_allowed[MAX_WEAPON_TYPES]
#define MAX_SHIP_CLASSES
Definition: globals.h:48
int mission_campaign_parse_is_multi(char *filename, char *name)
char * Campaign_descs[MAX_CAMPAIGNS]
char * filename
void campaign_delete_save(char *cfn, char *pname)
void mission_campaign_store_variables()
#define MAX_CAMPAIGNS
ubyte missions_completed[MAX_CAMPAIGN_MISSIONS]
#define MAX_WEAPON_TYPES
Definition: globals.h:73
int Campaign_ending_via_supernova
void read_mission_goal_list(int num)
int num_variables
char * Campaign_file_names[MAX_CAMPAIGNS]
int campaign_savefile_save(char *pname)
char Default_campaign_file_name[MAX_FILENAME_LEN-4]
char * mission_branch_brief_anim
unsigned char ubyte
Definition: pstypes.h:62
void mission_campaign_savefile_generate_root(char *filename, player *pl=NULL)
int mission_campaign_save(void)
sexp_variable * variables
char filename[NAME_LENGTH]
char * campaign_types[MAX_CAMPAIGN_TYPES]
void mission_campaign_end_init()
int mission_campaign_load_by_name(char *filename)
void mission_campaign_save_player_persistent_variables()
GLuint const GLchar * name
Definition: Glext.h:5608
void mission_campaign_jump_to_mission(char *name, bool no_skip=false)
char * mission_branch_brief_sound
int current_mission
char status
GLuint GLuint num
Definition: Glext.h:9089
SCP_string main_hall
void mission_campaign_delete_all_savefiles(char *pilot_name)
#define NAME_LENGTH
Definition: globals.h:15
void mission_campaign_build_list(bool desc=false, bool sort=true, bool multiplayer=false)
mgoal * goals
GLfloat GLfloat p
Definition: Glext.h:8373
void mission_campaign_savefile_delete(char *cfilename)
mevent * events
int mission_campaign_load_fred(char *filename, char *name_verify=NULL)
void mission_campaign_store_goals_and_events_and_variables()
void mission_campaign_eval_next_mission()
int mission_campaign_find_mission(char *name)
#define MAX_CAMPAIGN_MISSIONS
char status
void mission_campaign_end_do()
void campaign_savefile_load(char *fname, char *pname)
char filename[MAX_FILENAME_LEN]
void mission_campaign_load_failure_popup()
scoring_struct stats
int mission_load_up_campaign(player *p=NULL)
int num_missions_completed
sexp_variable * variables
int mission_campaign_load(char *filename, player *pl=NULL, int load_savefile=1, bool reset_stats=true)
void mission_campaign_init(void)
int mission_campaign_previous_mission()
int mission_campaign_savefile_save()
void mission_campaign_save_persistent(int type, int index)
cmission missions[MAX_CAMPAIGN_MISSIONS]
int redalert_num_variables