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 
60 extern char *campaign_types[MAX_CAMPAIGN_TYPES];
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 {
76 	char	name[NAME_LENGTH];
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
96 	char			*mission_branch_brief_anim;
97 	char			*mission_branch_brief_sound;
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
103 	scoring_struct	stats;
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 
campaign()130 	campaign()
131 		: desc(NULL), num_missions(0), variables(NULL)
132 	{
133 		name[0] = 0;
134 		filename[0] = 0;
135 	}
136 };
137 
138 extern campaign Campaign;
139 
140 // campaign wasn't ended
141 extern int Campaign_ending_via_supernova;
142 
143 // structure for players.  Holds the campaign name, number of missions flown in the campaign, and result
144 // of the missions flown.  This structure is stored in the player file and thus is persistent across
145 // games
146 typedef struct campaign_info
147 {
148 	int		num_missions_completed;
149 	char	filename[NAME_LENGTH];
150 	ubyte	missions_completed[MAX_CAMPAIGN_MISSIONS];
151 } campaign_info;
152 
153 // extern'ed so the mission loading can get a list of campains.  Only use this
154 // data after mission_campaign_build_list() is called
155 #define MAX_CAMPAIGNS	128
156 extern char *Campaign_names[MAX_CAMPAIGNS];
157 extern char *Campaign_file_names[MAX_CAMPAIGNS];
158 extern char *Campaign_descs[MAX_CAMPAIGNS];
159 extern int	Num_campaigns;
160 extern int	Campaign_names_inited;
161 extern SCP_vector<SCP_string> Ignored_campaigns;
162 
163 extern char Default_campaign_file_name[MAX_FILENAME_LEN - 4];
164 
165 // if the campaign file is missing this will get set for us to check against
166 extern int Campaign_file_missing;
167 
168 /*
169  * initialise Player_loadout with default values
170  */
171 void player_loadout_init();
172 
173 // called at game startup time to load the default single player campaign
174 void mission_campaign_init( void );
175 
176 // called to reload the default campaign
177 int mission_campaign_load_by_name( char *filename );
178 int mission_campaign_load_by_name_csfe( char *filename, char *callsign );
179 
180 
181 // load up and initialize a new campaign
182 int mission_campaign_load( char *filename, player *pl = NULL, int load_savefile = 1 );
183 
184 // function to save the state of the campaign between missions or to load a campaign save file
185 extern int mission_campaign_save( void );
186 
187 // declaration for local campaign save game load function
188 extern void mission_campaign_savefile_delete( char *cfilename );
189 extern void mission_campaign_delete_all_savefiles( char *pilot_name );
190 
191 // if a given campaign is a multiplayer campaign, we can load and save the multiplayer info portion with these functions
192 extern int mission_campaign_parse_is_multi(char *filename, char *name);
193 
194 // function which sets up internal variable for player to play next mission in the campaign
195 extern int mission_campaign_next_mission( void );
196 
197 // function which is called with the current mission in this campaign is over
198 extern void mission_campaign_mission_over( bool do_next_mission = true );
199 
200 // frees all memory at game close time
201 extern void mission_campaign_clear( void );
202 
203 // read in a campaign file.  Used by Fred.
204 int mission_campaign_load_fred(char *filename, char *name_verify = NULL);
205 
206 // used by Fred to get a mission's list of goals.
207 void read_mission_goal_list(int num);
208 
209 void mission_campaign_build_list(bool desc = false, bool sort = true, bool multiplayer = false);
210 void mission_campaign_free_list();
211 
212 // returns index of mission with passed name
213 extern int mission_campaign_find_mission( char *name );
214 
215 // maybe play a movie.  type indicates before or after mission
216 extern void mission_campaign_maybe_play_movie(int type);
217 
218 // save persistent information
219 extern void mission_campaign_save_persistent( int type, int index );
220 
221 void mission_campaign_savefile_generate_root(char *filename, player *pl = NULL);
222 
223 int mission_campaign_savefile_save();
224 
225 // The following are functions I added to set up the globals and then
226 // execute the corresponding mission_campaign_savefile functions.
227 
228 // Saves the campaign camp under the player name pname
229 int campaign_savefile_save(char *pname);
230 // Deletes the campaign save camp under the player name pname
231 void campaign_delete_save( char *cfn, char *pname);
232 // Loads campaign camp from fname under player name pname
233 void campaign_savefile_load(char *fname, char *pname);
234 
235 // get name and type of specified campaign file
236 int mission_campaign_get_info(const char *filename, char *name, int *type, int *max_players, char **desc = NULL);
237 
238 // get a listing of missions in a campaign
239 int mission_campaign_get_mission_list(const char *filename, char **list, int max);
240 
241 // load up a campaign for the current player.
242 int mission_load_up_campaign( player *p = NULL );
243 
244 // stores mission goals and events in Campaign struct
245 void mission_campaign_store_goals_and_events_and_variables();
246 
247 // evaluates next mission and possible loop mission
248 void mission_campaign_eval_next_mission();
249 
250 // returns to the beginning of the previous mission
251 int mission_campaign_previous_mission();
252 
253 // proceeds to next mission in campaign
254 void mission_campaign_skip_to_next(int start_game = 1);
255 
256 // break out of loop
257 void mission_campaign_exit_loop();
258 
259 // jump to specified mission
260 void mission_campaign_jump_to_mission(char *name);
261 
262 // stuff for the end of the campaign of the single player game
263 void mission_campaign_end_init();
264 void mission_campaign_end_close();
265 void mission_campaign_end_do();
266 
267 // Goober5000 - save persistent variables
268 extern void mission_campaign_save_player_persistent_variables();
269 
270 extern void mission_campaign_load_failure_popup();
271 
272 // End CSFE stuff
273 #endif
274