Dumb-ways-to-memorize
2D game
ai_interpret.h
Go to the documentation of this file.
1 #ifndef __AI_INTERPRET_H
2 #define __AI_INTERPRET_H
3 
4 #include "globals.h"
5 #include "parseobject.h"
6 
7 
8 #define MAX_AI 255
9 #define AI_PATH "AI/"
10 #define AI_FUNCTION_OBJECT "Think"
11 #define AI_VAR_G_STR "Variables"
12 #define AI_TYPE_STR "AI_Type"
13 #define AI_TYPE_PRESET_STR "preset"
14 #define AI_TYPE_VARIABLE_STR "variable"
15 #define AI_TYPE_RECURSIVE_STR "AI_Recursive"
16 #define AI_VAR_GRAVITY_STR "gravity"
17 
18 #define AI_VAR_STR "variables"
19 extern char *gAI_Variables[]; /**< The variables to be parsed for ai data */
20 
21 extern char *gAI_Actions[]; /**< The actions that are related to ai functions */
22 
23 #define AI_CHECK_STR "condition"
24 extern char *gAI_Conditions[]; /**< The conditions for the ai function to be executed */
25 
26 #define AI_BASE_JUMP -5
27 #define AI_BASE_SPEED 1
28 #define AI_BASE_THINK_FRAMES 1
29 #define AI_BASE_DAMAGE 5
30 
31 /** Defines the enum for ai_types*/
32 typedef enum
33 {
35  AI_TYPE_PRESET = 0x1, /**< An enum constant representing the ai type preset option */
36  AI_TYPE_VARIABLE, /**< An enum constant representing the ai type variable , which states there needs to be more values given */
37  AI_TYPE_RECURSIVE /**< An enum constant representing the ai type recursive option, which values turn into more functions */
38 }ai_type_t;
39 
40 /** Defines the enum for the variables in mVariables */
41 typedef enum
42 {
43  AI_VAR_SPEED, /**< An enum constant representing the ai variable speed option */
44  AI_VAR_FRAMES, /**< An enum constant representing the ai variable for the amount of frames this action happens*/
45  AI_VAR_TIME, /**< An enum constant representing the ai variable for the amount of times to repeat this action */
46  AI_VAR_DAMAGE, /**< An enum constant representing the ai variable for the damage this action should be */
47  AI_VAR_DIR_X, /**< An enum constant representing the ai variable for the x direction */
48  AI_VAR_DIR_Y, /**< An enum constant representing the ai variable for the y direction */
49  AI_VAR_CHECK, /**< An enum constant representing the ai variable for whether there is a condition that needs to be met b4 the action can be done */
51 
53 
54 /** Defines the enum for what flags are set on the ai */
55 typedef enum
56 {
60 
61 }ai_flags_t;
62 
63 /** Defines the enum for action types */
64 typedef enum
65 {
72 
74 
75 typedef enum
76 {
83 
85 
86 typedef struct ai_function_s ai_function_t;
87 
88 /**
89  * The structure for ai, pointer to this is declared in each entity.
90  * FighterThink is the only think that uses this structure.
91  *
92  * @author Anthony Rios
93  * @date 3/30/2016
94  */
95 
97 {
98  ai_type_t mType; /**< The type of ai (preset, variable, recursive)*/
99  ai_actions_t mAction; /**< The action type of this function, to get the action think function for entity */
100  int mFlags; /**< The flags defined in ai_flags_t */
101  int mVariables[7]; /**< The 7 currently parsed or default values in this function
102  1 - speed; 2 - frames; 3 - time; 4 - damage; [5,6] - direction; 7 - check;*/
103  char *mObject; /**< Optional - The object/entity to spawn during an action */
104  char *mObjectCheck; /**< Optional - The object/entity that you need to find, in order for condition to be valid */
105  ai_function_t *mLink; /**< The link to the next ai_function to set */
106 
107 };
108 
109 extern ai_function_t *gVariableAIs; /**< The AI's of type variable */
110 extern ai_function_t *gPresetAIs; /**< The AI's of type preset */
111 
112 /**
113  * Parses AI behavior using the variables given and the AI obj/file specified.
114  *
115  * @param [in,out] obj If non-null, the object.
116  * @param [in,out] g_str If non-null, the string.
117  * @param [in,out] variables If non-null, the variables.
118  *
119  * @return null if it fails, else a pointer to an ai_function_t.
120  *
121  * @author Anthony Rios
122  * @date 3/29/2016
123  */
124 ai_function_t *ParseAI(object_t *obj, char *g_str, char **variables);
125 
126 /**
127  * Parse a preset AI, with values determined by whats in the file.
128  *
129  * @param [in,out] obj If non-null, the object.
130  * @param [in,out] g_str If non-null, the string.
131  *
132  * @return null if it fails, else a pointer to an ai_function_t.
133  *
134  * @author Anthony Rios
135  * @date 3/29/2016
136  */
137 ai_function_t *ParsePresetAI(object_t *obj, char *g_str);
138 
139 /**
140  * Sets AI variables in ai_function->mVariables.
141  *
142  * @param [in,out] function If non-null, the function.
143  * @param [in,out] data_str If non-null, the data string.
144  * @param [in,out] var_type If non-null, the variable type.
145  *
146  * @author Anthony Rios
147  * @date 3/29/2016
148  */
149 void SetAI_Var(ai_function_t* function, char * data_str, ai_variables_t var_type);
150 
151 /**
152  * Sets AI action defined in ai_actions to the ai_function
153  *
154  * @param [in,out] function If non-null, the function.
155  * @param [in,out] obj If non-null, the object.
156  * @param [in,out] tok If non-null, the tok.
157  * @param [in,out] g_str If non-null, the string.
158  * @param [in,out] action_type If non-null, the action type.
159  *
160  * @author Anthony Rios
161  * @date 3/29/2016
162  */
163 void SetAI_Action(ai_function_t* function, object_t * obj, jsmntok_t* tok, char* g_str, ai_actions_t action_type);
164 
165 /**
166  * Sets checks that need to occur for the ai_function to be called.
167  *
168  * @param [in,out] function If non-null, the function.
169  * @param [in,out] variables_str If non-null, the variables string.
170  * @param [in,out] data_str If non-null, the data string.
171  * @param [in,out] check_str If non-null, the condition type.
172  *
173  * @author Anthony Rios
174  * @date 3/29/2016
175  */
176 void SetAI_Check(ai_function_t* function, char** variables_str, char * data_str, ai_conditions_t condition);
177 
178 /**
179  * Init AI system, similar to Entity init, for now....
180  *
181  * @return An int.
182  *
183  * @author Anthony Rios
184  * @date 3/29/2016
185  */
186 int InitAISystem();
187 
188 /**
189  * Shutdown AI system, just frees the global variables simple.
190  *
191  * @author Anthony Rios
192  * @date 3/30/2016
193  */
194 
195 void ShutdownAISystem();
196 
197 /**
198  * Converts a str to an AI type.
199  *
200  * @param str The string.
201  *
202  * @return str as an ai_type_t.
203  *
204  * @author Anthony Rios
205  * @date 3/29/2016
206  */
207 ai_type_t StrToAI_Type(const char *str);
208 
209 ai_actions_t StrToAI_Action(const char *str);
210 
211 ai_conditions_t StrToAI_Condition(const char *str);
212 
213 ai_variables_t StrToVariableType(const char *str);
214 
215 #endif
Definition: jsmn.h:40
ai_type_t mType
Definition: ai_interpret.h:98
ai_actions_t mAction
Definition: ai_interpret.h:99
ai_conditions_t
Definition: ai_interpret.h:75
ai_function_t * mLink
Definition: ai_interpret.h:105
ai_flags_t
Definition: ai_interpret.h:55
void SetAI_Var(ai_function_t *function, char *data_str, ai_variables_t var_type)
Definition: ai_interpret.c:481
ai_variables_t StrToVariableType(const char *str)
Definition: ai_interpret.c:717
void SetAI_Check(ai_function_t *function, char **variables_str, char *data_str, ai_conditions_t condition)
Definition: ai_interpret.c:601
ai_function_t * ParseAI(object_t *obj, char *g_str, char **variables)
Definition: ai_interpret.c:261
ai_function_t * ParsePresetAI(object_t *obj, char *g_str)
Definition: ai_interpret.c:374
void ShutdownAISystem()
Definition: ai_interpret.c:668
ai_actions_t
Definition: ai_interpret.h:64
ai_variables_t
Definition: ai_interpret.h:41
char * mObjectCheck
Definition: ai_interpret.h:104
ai_actions_t StrToAI_Action(const char *str)
Definition: ai_interpret.c:691
void SetAI_Action(ai_function_t *function, object_t *obj, jsmntok_t *tok, char *g_str, ai_actions_t action_type)
Definition: ai_interpret.c:516
ai_conditions_t StrToAI_Condition(const char *str)
Definition: ai_interpret.c:704
int InitAISystem()
Definition: ai_interpret.c:646
ai_function_t * gPresetAIs
Definition: ai_interpret.c:10
char * gAI_Actions[]
Definition: ai_interpret.c:13
ai_type_t StrToAI_Type(const char *str)
Definition: ai_interpret.c:679
int mVariables[7]
Definition: ai_interpret.h:101
char * gAI_Variables[]
Definition: ai_interpret.c:12
ai_type_t
Definition: ai_interpret.h:32
char * gAI_Conditions[]
Definition: ai_interpret.c:14
ai_function_t * gVariableAIs
Definition: ai_interpret.c:9