13 char *
gAI_Actions[] = {
"nothing",
"move",
"walk",
"jump",
"attack", 0};
14 char *
gAI_Conditions[] = {
"distance_player",
"distance_object",
"object_check",
"link_ai",
"link_action", 0};
29 if(!ent->mData || !ent)
31 printf(
"MoveAI given a null paramerter \n");
34 flags = ent->mData->mFlags;
46 ent->mData = ent->mData->mLink;
65 if(!ent->mData || !ent)
67 printf(
"MoveAI given a null paramerter \n");
70 flags = ent->mData->mFlags;
83 Vec2Add(&temp_vec2, &ent->mVelocity, &ent->mVelocity);
89 ent->mData = ent->mData->mLink;
110 if(!ent->mData || !ent)
112 printf(
"MoveAI given a null paramerter \n");
115 flags = ent->mData->mFlags;
128 Vec2Add(&temp_vec2, &ent->mVelocity, &ent->mVelocity);
134 ent->mData = ent->mData->mLink;
151 if(!ent->mData || !ent)
153 printf(
"MoveAI given a null paramerter \n");
156 flags = ent->mData->mFlags;
165 if(ent->mVelocity.y == 0)
171 if( (ent->mVelocity.x == temp_vec2.
x) & (ent->mVelocity.y == temp_vec2.
y) )
176 Vec2Add(&temp_vec2, &ent->mVelocity, &ent->mVelocity);
185 ent->mData = ent->mData->mLink;
205 if(!ent->mData || !ent)
207 printf(
"MoveAI given a null paramerter \n");
210 flags = ent->mData->mFlags;
218 if(ent->mData->mObject)
223 temp_ent->mVelocity.x = ent->mData->mVariables[
AI_VAR_DIR_X];
224 temp_ent->mVelocity.y = ent->mData->mVariables[
AI_VAR_DIR_Y];
225 Spawn(ent, temp_ent);
234 ent->mData = ent->mData->mLink;
244 switch(data->mAction)
261 ai_function_t *
ParseAI(object_t *obj,
char *g_str,
char **variables)
263 int i, j, k,children, position, variables_i, gravity;
264 ai_function_t *retVal;
266 object_t *temp_obj, *action_obj, *variables_obj;
267 char *temp_str, *type_str, *cond_str,**variables_str;
284 printf(
"No thinks in ai : %s \n", obj->name);
291 printf(
"No types in ai : %s \n", obj->name);
295 children =
CountMem(temp_obj->children,
sizeof(object_t));
296 retVal = (ai_function_t*) malloc(
sizeof(ai_function_t)*(children+1));
297 memset(retVal, 0,
sizeof(ai_function_t)*(children+1));
298 for(i = 0; i < children; i++)
304 if(temp_str) free(temp_str);
311 if(!action_obj && !action_tok)
328 variables_str = NULL;
332 variables_str = (
char**) malloc(
sizeof(
char*)*(variables_i+1));
333 variables_str[variables_i] = NULL;
334 for(k = 0; k < variables_i; k++)
336 temp_str =
JsmnToString(&variables_obj->values[k], g_str);
337 variables_str[k] = temp_str ? variables[
StrToInt(temp_str)] : NULL;
338 if(temp_str) free(temp_str);
344 if(cond_str) free(cond_str);
352 for(i = 0; i < children; i++)
359 retVal[i].mLink = (i+1 == children) ? retVal: &retVal[i+1];
368 retVal[i].mObjectCheck = temp_str;
376 int i, j, k,children, position, variables, gravity;
377 ai_function_t *retVal;
379 object_t *temp_obj, *action_obj, *variables_obj;
380 char *temp_str, *type_str, **variables_str;
396 printf(
"No thinks in ai : %s \n", obj->name);
402 printf(
"No types in ai : %s \n", obj->name);
405 position = temp_tok - obj->keys;
408 children =
CountMem(temp_obj->children,
sizeof(object_t));
409 retVal = (ai_function_t*) malloc(
sizeof(ai_function_t)*(children+1));
410 memset(retVal, 0,
sizeof(ai_function_t)*(children+1));
411 for(i = 0; i < children; i++)
418 if(temp_str) free(temp_str);
425 if(!action_obj && !action_tok)
441 variables_str = NULL;
445 variables_str = (
char**) malloc(
sizeof(
char*)*(variables+1));
446 variables_str[variables] = NULL;
447 for(k = 0; k < variables; k++)
449 variables_str[k] =
JsmnToString(&variables_obj->values[k],g_str);
454 if(temp_str) free(temp_str);
462 for(i = 0; i < children; i++)
466 retVal[i].mLink = (i+1 == children) ? retVal: &retVal[i+1];
475 retVal[i].mObjectCheck = temp_str;
519 if(!action_type || !
function)
537 }
else if( (temp_vec2 =
ParseToVec2(obj, g_str)) != NULL)
557 }
else if( (temp_vec2 =
ParseToVec2(obj, g_str)) != NULL)
577 }
else if( (temp_vec2 =
ParseToVec2(obj, g_str)) != NULL)
603 ai_function_t *temp_ai;
607 if(!condition || !
function)
633 if(!temp_str || !temp_tok)
638 function->mLink =
ParseAI(temp_obj, temp_str, variables_str);
650 printf(
"Tried to init AI system, while already inited \n");
658 printf(
"AI malloc error \n");
672 printf(
"AI not initialized before shutdown called \n");
int CountMem(void *src, int size_type)
void Vec2MultiplyScalar(vec2_t *A, int B, vec2_t *C)
object_t * FindObject(object_t *obj, char *name)
char * JsmnToString(jsmntok_t *token, char *g_str)
ai_conditions_t StrToAI_Condition(const char *str)
vec2_t * ParseToVec2(struct object_s *object, char *str)
void SetAI_Var(ai_function_t *function, char *data_str, ai_variables_t var_type)
int ConvertFileToUseable(char *fileName, jsmn_parser *parser, char **stringStorage, jsmntok_t **jsmnStorage)
unsigned int gCurrentTime
ai_function_t * ParsePresetAI(object_t *obj, char *g_str)
int CountObjectMembers(object_t *obj, char *g_str)
entity_t * FindCachedEntity(const char *name)
void Spawn(entity_t *targ, entity_t *info)
ai_function_t * gVariableAIs
void NothingAI(entity_t *ent)
#define AI_FUNCTION_OBJECT
ai_variables_t StrToVariableType(const char *str)
void SetAI_Check(ai_function_t *function, char **variables_str, char *data_str, ai_conditions_t condition)
jsmntok_t * FindKey(jsmntok_t *token, char *key, char *g_str)
void SetAI_Action(ai_function_t *function, object_t *obj, jsmntok_t *tok, char *g_str, ai_actions_t action_type)
#define AI_TYPE_VARIABLE_STR
void MoveAI(entity_t *ent)
#define AI_TYPE_PRESET_STR
#define AI_BASE_THINK_FRAMES
void WalkAI(entity_t *ent)
void AttackAI(entity_t *ent)
void JumpAI(entity_t *ent)
void(*)(entity_t *) GetFunctionAI(ai_function_t *data)
char * FindValue(struct object_s *obj, char *key, char *g_str)
void Vec2Add(vec2_t *A, vec2_t *B, vec2_t *C)
ai_actions_t StrToAI_Action(const char *str)
object_t * ParseToObject(jsmntok_t *token, char *g_str)
ai_function_t * gPresetAIs
ai_type_t StrToAI_Type(const char *str)
ai_function_t * ParseAI(object_t *obj, char *g_str, char **variables)