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 _MISSIONGOAL_H
13 #define _MISSIONGOAL_H
14 
15 #include "globalincs/pstypes.h"
16 #include "globalincs/globals.h"
17 
18 struct ai_goal;
19 struct ai_info;
20 
21 // defines for types of primary and secondary missions
22 
23 #define	MAX_GOALS			30		// maximum number of goals for any given mission
24 
25 // defines for types of goals.  We will use part of the int field of the mission_goal struct
26 // as a bit field for goal flags
27 
28 #define	PRIMARY_GOAL		0
29 #define	SECONDARY_GOAL		1
30 #define	BONUS_GOAL			2
31 
32 // defines for bitfields of type, (and mask to get the type field quickly)
33 #define	INVALID_GOAL		(1 << 16)			// is this goal valid or not?
34 #define	GOAL_TYPE_MASK		(0xffff)				// mask to get us the type
35 
36 // defines for goal status.  These status are also used in campaign file for marking goal status
37 // in campaign save file
38 #define	GOAL_FAILED			0		// status of goal
39 #define	GOAL_COMPLETE		1
40 #define	GOAL_INCOMPLETE	2
41 
42 #define	PRIMARY_GOALS_COMPLETE		1
43 #define	PRIMARY_GOALS_INCOMPLETE	0
44 #define	PRIMARY_GOALS_FAILED			-1
45 
46 extern const char *Goal_type_text(int n);
47 
48 // structures for primary and secondary goals
49 
50 #define	MAX_GOAL_TEXT	128
51 
52 #define	MGF_NO_MUSIC	(1<<0)		// don't play any event music when goal is achieved
53 
54 typedef struct mission_goal {
55 	char	name[NAME_LENGTH];			// used for storing status of goals in player file
56 	int  	type;								// primary/secondary/bonus
57 	int	satisfied;						// has this goal been satisfied
58 	char	message[MAX_GOAL_TEXT];		//	Brief description, such as "Destroy all vile aliens!"
59 	int	rating;							//	Some importance figure or something.
60 	int	formula;							//	Index in Sexp_nodes of this Sexp.
61 	int	score;							// score for this goal
62 	int	flags;							// MGF_
63 	int	team;								// which team is this objective for.
64 } mission_goal;
65 
66 extern mission_goal Mission_goals[MAX_GOALS];	// structure for the goals of this mission
67 extern int	Num_goals;									// number of goals for this mission
68 
69 // structures and defines for mission events
70 
71 #define MAX_MISSION_EVENTS		512
72 #define MISSION_EVENTS_WARN	100
73 
74 // defined for event states.  We will also use the satisfied/failed for saving event information
75 // in campaign save file
76 #define EVENT_UNBORN			0  // event can't be evaluated yet
77 #define EVENT_CURRENT		1  // event can currently be evaluated, but not satisfied or failed yet
78 #define EVENT_SATISFIED		2
79 #define EVENT_FAILED			3
80 #define EVENT_INCOMPLETE	4	// used in campaign save file.  used when event isn't satisfied yet
81 
82 #define MEF_CURRENT					(1 << 0)		// is event current or past current yet?
83 #define MEF_DIRECTIVE_SPECIAL		(1 << 1)		// used to mark a directive as true even though not fully satisfied
84 #define MEF_DIRECTIVE_TEMP_TRUE		(1 << 2)		// this directive is temporarily true.
85 #define MEF_USING_TRIGGER_COUNT		(1 << 3)		// Karajorma - use trigger count as well as repeat count to determine how many repeats this event has
86 
87 #define MAX_MISSION_EVENT_LOG_FLAGS		9			// this must be changed if a mission log flag is added below
88 
89 #define MLF_SEXP_TRUE				(1 << 0)
90 #define MLF_SEXP_FALSE				(1 << 1)
91 //#define MLF_SEXP_KNOWN_TRUE			(1 << 2)
92 #define MLF_SEXP_KNOWN_FALSE		(1 << 3)
93 #define MLF_FIRST_REPEAT_ONLY		(1 << 4)
94 #define MLF_LAST_REPEAT_ONLY		(1 << 5)
95 #define MLF_FIRST_TRIGGER_ONLY		(1 << 6)
96 #define MLF_LAST_TRIGGER_ONLY		(1 << 7)
97 #define MLF_STATE_CHANGE			(1 << 8)
98 
99 #define MLF_ALL_REPETITION_FLAGS (MLF_FIRST_REPEAT_ONLY | MLF_LAST_REPEAT_ONLY | MLF_FIRST_TRIGGER_ONLY | MLF_LAST_TRIGGER_ONLY)
100 
101 typedef struct mission_event {
102 	char	name[NAME_LENGTH];	// used for storing status of events in player file
103 	int	formula;					// index into sexpression array for this formula
104 	int	result;					// result of most recent evaluation of event
105 	int	repeat_count;			// number of times to test this goal
106 	int trigger_count;			// number of times to allow this goal to trigger
107 	int	interval;				// interval (in seconds) at which an evaulation is repeated once true.
108 	int	timestamp;				// set at 'interval' seconds when we start to eval.
109 	int	score;					// score for this event
110 	int	chain_delay;
111 	int	flags;
112 	char	*objective_text;
113 	char	*objective_key_text;
114 	int	count;					// object count for directive display
115 	int	satisfied_time;			// this is used to temporarily mark the directive as satisfied when the event isn't (e.g. for a destroyed wave when there are more waves later)
116 	int	born_on_date;			// timestamp at which event was born
117 	int	team;						// for multiplayer games
118 
119 	// event log stuff
120 	int mission_log_flags;		// flags that are used to determing which events are written to the log
121 	SCP_vector<SCP_string> event_log_buffer;
122 	SCP_vector<SCP_string> event_log_variable_buffer;
123 	SCP_vector<SCP_string> event_log_argument_buffer;
124 	SCP_vector<SCP_string> backup_log_buffer;
125 	int	previous_result;		// result of previous evaluation of event
126 
127 } mission_event;
128 
129 extern int Num_mission_events;
130 extern mission_event Mission_events[MAX_MISSION_EVENTS];
131 extern int Mission_goal_timestamp;
132 extern int Event_index;  // used by sexp code to tell what event it came from
133 extern bool Log_event;
134 extern bool Snapshot_all_events;
135 
136 // prototypes
137 void	mission_init_goals( void );
138 void	mission_show_goals_init();
139 void	mission_show_goals_close();
140 void	mission_show_goals_do_frame(float frametime);	// displays goals on screen
141 void	mission_eval_goals();									// evaluate player goals
142 int	mission_ai_goal_achievable( ai_goal *aigp );	// determines if an AI goal is achievable
143 void	mission_add_ai_goal( int sexp, ai_info *aip );	// adds a goal onto the given ai_info structure
144 int	mission_evaluate_primary_goals(void);	// determine if the primary goals for the mission are complete -- returns one of the above defines
145 int	mission_goals_met();
146 
147 // function used by single and multiplayer code to change the status on goals
148 void	mission_goal_status_change( int goal_num, int new_status);
149 
150 // functions used to change goal validity status
151 void mission_goal_mark_invalid( char *name );
152 void mission_goal_mark_valid( char *name );
153 
154 // function used to mark all goals as invalid, and incomplete goals as invalid.
155 extern void mission_goal_fail_all();
156 extern void mission_goal_fail_incomplete();
157 
158 void mission_goal_fetch_num_resolved(int desired_type, int *num_resolved, int *total, int team = -1);
159 int mission_goals_incomplete(int desired_type, int team = -1);
160 void mission_goal_mark_objectives_complete();
161 void mission_goal_mark_events_complete();
162 
163 int mission_get_event_status(int event);
164 void mission_event_shutdown();
165 void mission_goal_validation_change( int goal_num, int valid );
166 
167 // mark an event as directive special
168 void mission_event_set_directive_special(int event);
169 void mission_event_unset_directive_special(int event);
170 
171 void mission_goal_exit();
172 
173 int ML_objectives_init(int x, int y, int w, int h);
174 void ML_objectives_close();
175 void ML_objectives_do_frame(int scroll_offset);
176 void ML_render_objectives_key();			// renders objectives key on ingame objectives screen
177 
178 #endif
179