Dumb-ways-to-memorize
2D game
ai_interpret.c
Go to the documentation of this file.
1 #include "ai_interpret.h"
2 #include "entity.h"
3 #include "parseentity.h"
4 #include "parsepowerup.h"
5 #include "mystrings.h"
6 #include <stdio.h>
7 #include <stdlib.h>
8 
9 ai_function_t * gVariableAIs = NULL;
10 ai_function_t * gPresetAIs = NULL;
11 
12 char *gAI_Variables[] = {"speed", "frames", "time", "damage", 0};
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};
15 
16 /**
17  * AI that does nothing for its think, except make sure values are set.
18  *
19  * @param [in,out] ent If non-null, the ent.
20  *
21  * @author Anthony Rios
22  * @date 3/29/2016
23  */
24 
25 void NothingAI(entity_t *ent)
26 {
27  int flags;
28  vec2_t temp_vec2;
29  if(!ent->mData || !ent)
30  {
31  printf("MoveAI given a null paramerter \n");
32  return;
33  }
34  flags = ent->mData->mFlags;
35 
36  //Standard Vars
37  ent->mCollisionType = COLLISION_TYPE_RAGDOLL;
38  ent->mNextThink = gCurrentTime + ent->mData->mVariables[AI_VAR_FRAMES]*FRAME_DELAY;
39  ent->mDamage = ent->mData->mVariables[AI_VAR_DAMAGE];
40  ent->mWeight = (flags & AI_FLAG_GRAVITY) ? 0 : FindCachedEntity(ent->mName)->mWeight;
41 
42  //Check Data
43  if( --ent->mData->mVariables[AI_VAR_TIME] == 0)
44  {
45  ent->mData->mVariables[AI_VAR_TIME] = 1;
46  ent->mData = ent->mData->mLink;
47  }
48 }
49 
50 /**
51  * AI to Move ent from point A to B w/o collisions.
52  *
53  * @param [in,out] ent If non-null, the ent.
54  *
55  * @author Anthony Rios
56  * @date 3/29/2016
57  *
58  * @Todo Learn how to lerp.
59  */
60 
61 void MoveAI(entity_t *ent)
62 {
63  int flags;
64  vec2_t temp_vec2;
65  if(!ent->mData || !ent)
66  {
67  printf("MoveAI given a null paramerter \n");
68  return;
69  }
70  flags = ent->mData->mFlags;
71 
72  //Standard Vars
73  ent->mCollisionType = COLLISION_TYPE_CLIP;
74  ent->mNextThink = gCurrentTime + ent->mData->mVariables[AI_VAR_FRAMES]*FRAME_DELAY;
75  ent->mDamage = ent->mData->mVariables[AI_VAR_DAMAGE];
76  ent->mWeight = (flags & AI_FLAG_GRAVITY) ? 0 : FindCachedEntity(ent->mName)->mWeight;
77 
78  //Move
79  temp_vec2.x = ent->mData->mVariables[AI_VAR_DIR_X];
80  temp_vec2.y = ent->mData->mVariables[AI_VAR_DIR_Y];
81  //TODO: normalize temp_vec2
82  Vec2MultiplyScalar(&temp_vec2,ent->mData->mVariables[AI_VAR_SPEED],&temp_vec2);
83  Vec2Add(&temp_vec2, &ent->mVelocity, &ent->mVelocity);
84 
85  //Check Data
86  if( --ent->mData->mVariables[AI_VAR_TIME] == 0)
87  {
88  ent->mData->mVariables[AI_VAR_TIME] = 1;
89  ent->mData = ent->mData->mLink;
90  }
91 
92 
93 }
94 
95 /**
96  * AI to "walk" entity from point A to B w/ collisions.
97  *
98  * @param [in,out] ent If non-null, the ent.
99  *
100  * @author Anthony Rios
101  * @date 3/29/2016
102  *
103  * @todo Lerp
104  */
105 
106 void WalkAI(entity_t *ent)
107 {
108  int flags;
109  vec2_t temp_vec2;
110  if(!ent->mData || !ent)
111  {
112  printf("MoveAI given a null paramerter \n");
113  return;
114  }
115  flags = ent->mData->mFlags;
116 
117  //Standard Vars
118  ent->mCollisionType = COLLISION_TYPE_RAGDOLL;
119  ent->mNextThink = gCurrentTime + ent->mData->mVariables[AI_VAR_FRAMES]*FRAME_DELAY;
120  ent->mDamage = ent->mData->mVariables[AI_VAR_DAMAGE];
121  ent->mWeight = (flags & AI_FLAG_GRAVITY) ? 0 : FindCachedEntity(ent->mName)->mWeight;
122 
123  //Move
124  temp_vec2.x = ent->mData->mVariables[AI_VAR_DIR_X];
125  temp_vec2.y = ent->mData->mVariables[AI_VAR_DIR_Y];
126  //TODO: normalize temp_vec2
127  Vec2MultiplyScalar(&temp_vec2,ent->mData->mVariables[AI_VAR_SPEED],&temp_vec2);
128  Vec2Add(&temp_vec2, &ent->mVelocity, &ent->mVelocity);
129 
130  //Check Data
131  if( --ent->mData->mVariables[AI_VAR_TIME] == 0)
132  {
133  ent->mData->mVariables[AI_VAR_TIME] = 1;
134  ent->mData = ent->mData->mLink;
135  }
136 }
137 
138 /**
139  * AI to change velocity of the entity, defaults to a jumping movement.
140  *
141  * @param [in,out] ent If non-null, the ent.
142  *
143  * @author Anthony Rios
144  * @date 3/29/2016
145  */
146 
147 void JumpAI(entity_t *ent)
148 {
149  int flags;
150  vec2_t temp_vec2;
151  if(!ent->mData || !ent)
152  {
153  printf("MoveAI given a null paramerter \n");
154  return;
155  }
156  flags = ent->mData->mFlags;
157 
158  //Standard Vars
159  ent->mCollisionType = COLLISION_TYPE_RAGDOLL;
160  ent->mNextThink = gCurrentTime + ent->mData->mVariables[AI_VAR_FRAMES]*FRAME_DELAY;
161  ent->mDamage = ent->mData->mVariables[AI_VAR_DAMAGE];
162  ent->mWeight = (flags & AI_FLAG_GRAVITY) ? 0 : FindCachedEntity(ent->mName)->mWeight;
163 
164  //Move
165  if(ent->mVelocity.y == 0)
166  {
167  temp_vec2.x = ent->mData->mVariables[AI_VAR_DIR_X];
168  temp_vec2.y = ent->mData->mVariables[AI_VAR_DIR_Y];
169  //TODO: normalize temp_vec2
170  Vec2MultiplyScalar(&temp_vec2,ent->mData->mVariables[AI_VAR_SPEED],&temp_vec2);
171  if( (ent->mVelocity.x == temp_vec2.x) & (ent->mVelocity.y == temp_vec2.y) )
172  {
173  ;
174  } else
175  {
176  Vec2Add(&temp_vec2, &ent->mVelocity, &ent->mVelocity);
177  }
178 
179  }
180 
181  //Check Data
182  if( --ent->mData->mVariables[AI_VAR_TIME] == 0)
183  {
184  ent->mData->mVariables[AI_VAR_TIME] = 1;
185  ent->mData = ent->mData->mLink;
186  }
187 }
188 
189 /**
190  * AI for entity attacks, "spawns" a hit box / entity in front of Entity
191  *
192  * @note Currently Untested
193  *
194  * @param [in,out] ent If non-null, the ent.
195  *
196  * @author Anthony Rios
197  * @date 3/29/2016
198  */
199 
200 void AttackAI(entity_t *ent)
201 {
202  int flags;
203  vec2_t temp_vec2;
204  entity_t *temp_ent;
205  if(!ent->mData || !ent)
206  {
207  printf("MoveAI given a null paramerter \n");
208  return;
209  }
210  flags = ent->mData->mFlags;
211 
212  //Standard Vars
213  ent->mCollisionType = COLLISION_TYPE_RAGDOLL;
214  ent->mNextThink = SDL_GetTicks() + ent->mData->mVariables[AI_VAR_FRAMES]*FRAME_DELAY;
215  ent->mDamage = ent->mData->mVariables[AI_VAR_DAMAGE];
216  ent->mWeight = (flags & AI_FLAG_GRAVITY) ? 0 : FindCachedEntity(ent->mName)->mWeight;
217 
218  if(ent->mData->mObject)
219  {
220  temp_ent = FindCachedEntity(ent->mData->mObject);
221  if(temp_ent)
222  {
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);
226  }
227 
228  }
229 
230  //Check Data
231  if( --ent->mData->mVariables[AI_VAR_TIME] == 0)
232  {
233  ent->mData->mVariables[AI_VAR_TIME] = 1;
234  ent->mData = ent->mData->mLink;
235  }
236 }
237 
238 void (*GetFunctionAI(ai_function_t *data))(entity_t *)
239 {
240  if(!data)
241  {
242  return NULL;
243  }
244  switch(data->mAction)
245  {
246  case(AI_ACTION_NOTHING) :
247  return NothingAI;
248  case(AI_ACTION_MOVE):
249  return MoveAI;
250  case(AI_ACTION_WALK):
251  return WalkAI;
252  case(AI_ACTION_JUMP):
253  return JumpAI;
254  case(AI_ACTION_ATTACK):
255  return AttackAI;
256  default:
257  return NULL;
258  }
259 }
260 
261 ai_function_t *ParseAI(object_t *obj, char *g_str, char **variables)
262 {
263  int i, j, k,children, position, variables_i, gravity;
264  ai_function_t *retVal;
265  jsmntok_t *temp_tok, *action_tok;
266  object_t *temp_obj, *action_obj, *variables_obj;
267  char *temp_str, *type_str, *cond_str,**variables_str;
268  if(!obj || !g_str)
269  {
270  return NULL;
271  }
272 
273  if(FindObject(obj, AI_VAR_STR))
274  {
275  gravity = 1;
276  } else
277  {
278  gravity = 0;
279  }
280 
281  temp_obj = FindObject(obj, AI_FUNCTION_OBJECT);
282  if(!temp_obj)
283  {
284  printf("No thinks in ai : %s \n", obj->name);
285  return NULL;
286  }
287 
288  type_str = FindValue(obj, AI_TYPE_STR, g_str);
289  if(!type_str)
290  {
291  printf("No types in ai : %s \n", obj->name);
292  return NULL;
293  }
294 
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++)
299  {
300  for(j = 0; gAI_Variables[j]; j++ )
301  {
302  temp_str = FindValue(&temp_obj->children[i], gAI_Variables[j], g_str);
303  SetAI_Var(&retVal[i], variables[StrToInt(temp_str)], (ai_variables_t)j );
304  if(temp_str) free(temp_str);
305  temp_str = NULL;
306  }
307  for(j = 0; gAI_Actions[j]; j++ )
308  {
309  action_obj = FindObject(&temp_obj->children[i], gAI_Actions[j]);
310  action_tok = FindKey(temp_obj->children[i].keys, gAI_Actions[j], g_str);
311  if(!action_obj && !action_tok)
312  {
313  continue;
314  }
315 
316  SetAI_Action(&retVal[i],action_obj, action_tok, g_str, (ai_actions_t)j );
317  }
318  for(j = 0; gAI_Conditions[j]; j++)
319  {
320  cond_str = FindValue(&temp_obj->children[i], gAI_Conditions[j], g_str);
321  if(!cond_str)
322  {
323  continue;
324  }
325  variables_obj = FindObject(&temp_obj->children[i], AI_VAR_STR);
326  if(!variables_obj)
327  {
328  variables_str = NULL;
329  } else
330  {
331  variables_i = CountObjectMembers(variables_obj, g_str);
332  variables_str = (char**) malloc(sizeof(char*)*(variables_i+1));
333  variables_str[variables_i] = NULL;
334  for(k = 0; k < variables_i; k++)
335  {
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);
339  temp_str = NULL;
340  }
341  }
342 
343  SetAI_Check(&retVal[i], variables_str, variables[StrToInt(cond_str)], (ai_conditions_t)j );
344  if(cond_str) free(cond_str);
345  cond_str = NULL;
346  }
347  retVal[i].mFlags |= gravity ? AI_FLAG_GRAVITY : 0;
348  retVal[i].mType = StrToAI_Type(type_str);
349  }
350 
351  //Linking and conditionals
352  for(i = 0; i < children; i++)
353  {
354  if(retVal[i].mLink)
355  {
356  continue;
357  } else
358  {
359  retVal[i].mLink = (i+1 == children) ? retVal: &retVal[i+1];
360  }
361  if(retVal[i].mFlags & AI_FLAG_CHECK_OBJECT)
362  {
363  temp_str = FindValue(&temp_obj->children[i], gAI_Conditions[AI_CONDITION_OBJECT_NAME], g_str);
364  if(!temp_str)
365  {
366  continue;
367  }
368  retVal[i].mObjectCheck = temp_str;
369  }
370  }
371  return retVal;
372 }
373 
374 ai_function_t* ParsePresetAI(object_t* obj, char* g_str)
375 {
376  int i, j, k,children, position, variables, gravity;
377  ai_function_t *retVal;
378  jsmntok_t *temp_tok, *action_tok;
379  object_t *temp_obj, *action_obj, *variables_obj;
380  char *temp_str, *type_str, **variables_str;
381  if(!obj || !g_str)
382  {
383  return NULL;
384  }
385 
386  if(FindObject(obj, AI_VAR_STR))
387  {
388  gravity = 1;
389  } else
390  {
391  gravity = 0;
392  }
393  temp_obj = FindObject(obj, AI_FUNCTION_OBJECT);
394  if(!temp_obj)
395  {
396  printf("No thinks in ai : %s \n", obj->name);
397  return NULL;
398  }
399  temp_tok = FindKey(obj->keys, AI_TYPE_STR, g_str);
400  if(!temp_tok)
401  {
402  printf("No types in ai : %s \n", obj->name);
403  return NULL;
404  }
405  position = temp_tok - obj->keys;
406  type_str = JsmnToString(&obj->values[position], g_str);
407 
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++)
412  {
413  for(j = 0; gAI_Variables[j]; j++ )
414  {
415  temp_str = FindValue(&temp_obj->children[i], gAI_Variables[j] ,g_str);
416 
417  SetAI_Var(&retVal[i], temp_str, (ai_variables_t)j );
418  if(temp_str) free(temp_str);
419  temp_str = NULL;
420  }
421  for(j = 0; gAI_Actions[j]; j++ )
422  {
423  action_obj = FindObject(&temp_obj->children[i], gAI_Actions[j]);
424  action_tok = FindKey(temp_obj->children[i].keys, gAI_Actions[j], g_str);
425  if(!action_obj && !action_tok)
426  {
427  continue;
428  }
429  SetAI_Action(&retVal[i],action_obj, action_tok, g_str, (ai_actions_t)j );
430  }
431  for(j = 0; gAI_Conditions[j]; j++)
432  {
433  temp_str = FindValue(&temp_obj->children[i], gAI_Conditions[j] ,g_str);
434  if(!temp_str)
435  {
436  continue;
437  }
438  variables_obj = FindObject(&temp_obj->children[i], AI_VAR_STR);
439  if(!variables_obj)
440  {
441  variables_str = NULL;
442  } else
443  {
444  variables = CountObjectMembers(variables_obj, g_str);
445  variables_str = (char**) malloc(sizeof(char*)*(variables+1));
446  variables_str[variables] = NULL;
447  for(k = 0; k < variables; k++)
448  {
449  variables_str[k] = JsmnToString(&variables_obj->values[k],g_str);
450  }
451  }
452 
453  SetAI_Check(&retVal[i], variables_str, temp_str, (ai_conditions_t)j );
454  if(temp_str) free(temp_str);
455  temp_str = NULL;
456  }
457  retVal[i].mFlags |= gravity ? AI_FLAG_GRAVITY : 0;
458  retVal[i].mType = StrToAI_Type(type_str);
459  }
460 
461  //Linking and conditionals
462  for(i = 0; i < children; i++)
463  {
464  if(!retVal[i].mLink)
465  {
466  retVal[i].mLink = (i+1 == children) ? retVal: &retVal[i+1];
467  }
468  if(retVal[i].mFlags & AI_FLAG_CHECK_OBJECT)
469  {
470  temp_str = FindValue(&temp_obj->children[i], gAI_Conditions[AI_CONDITION_OBJECT_NAME], g_str);
471  if(!temp_str)
472  {
473  continue;
474  }
475  retVal[i].mObjectCheck = temp_str;
476  }
477  }
478  return retVal;
479 }
480 
481 void SetAI_Var(ai_function_t* function, char* data_str, ai_variables_t var_type)
482 {
483  if(!var_type)
484  {
485  return;
486  }
487 
488  switch(var_type)
489  {
490  case AI_VAR_SPEED:
491  {
492  function->mVariables[AI_VAR_SPEED] = data_str ? StrToInt(data_str) : AI_BASE_SPEED;
493  break;
494  }
495  case AI_VAR_FRAMES:
496  {
497  function->mVariables[AI_VAR_FRAMES] = data_str ? StrToInt(data_str) : AI_BASE_THINK_FRAMES;
498  break;
499  }
500  case AI_VAR_TIME:
501  {
502  function->mVariables[AI_VAR_TIME] = data_str ? StrToInt(data_str) : 1;
503  break;
504  }
505  case AI_VAR_DAMAGE:
506  {
507  function->mVariables[AI_VAR_DAMAGE] = data_str ? StrToInt(data_str) : AI_BASE_DAMAGE;
508  break;
509  }
510  default:
511  break;
512  }
513 
514 }
515 
516 void SetAI_Action(ai_function_t* function, object_t* obj, jsmntok_t* tok, char* g_str, ai_actions_t action_type)
517 {
518  vec2_t *temp_vec2;
519  if(!action_type || !function)
520  {
521  return;
522  }
523  switch(action_type)
524  {
525  case AI_ACTION_NOTHING:
526  {
527  function->mAction = AI_ACTION_NOTHING;
528  break;
529  }
530  case AI_ACTION_MOVE:
531  {
532  if(!obj)
533  {
534  function->mVariables[AI_VAR_DIR_X] = 0;
535  function->mVariables[AI_VAR_DIR_Y] = 0;
536 
537  } else if( (temp_vec2 = ParseToVec2(obj, g_str)) != NULL)
538  {
539  function->mVariables[AI_VAR_DIR_X] = temp_vec2->x;
540  function->mVariables[AI_VAR_DIR_X] = temp_vec2->y;
541  } else
542  {
543  function->mVariables[AI_VAR_DIR_X] = 0;
544  function->mVariables[AI_VAR_DIR_Y] = 0;
545  }
546 
547  function->mAction = AI_ACTION_MOVE;
548  break;
549  }
550  case AI_ACTION_WALK:
551  {
552  if(!obj)
553  {
554  function->mVariables[AI_VAR_DIR_X] = 0;
555  function->mVariables[AI_VAR_DIR_Y] = 0;
556 
557  } else if( (temp_vec2 = ParseToVec2(obj, g_str)) != NULL)
558  {
559  function->mVariables[AI_VAR_DIR_X] = temp_vec2->x;
560  function->mVariables[AI_VAR_DIR_X] = temp_vec2->y;
561  } else
562  {
563  function->mVariables[AI_VAR_DIR_X] = 0;
564  function->mVariables[AI_VAR_DIR_Y] = 0;
565  }
566 
567  function->mAction = AI_ACTION_WALK;
568  break;
569  }
570  case AI_ACTION_JUMP:
571  {
572  if(!obj)
573  {
574  function->mVariables[AI_VAR_DIR_X] = 0;
575  function->mVariables[AI_VAR_DIR_Y] = AI_BASE_JUMP;
576 
577  } else if( (temp_vec2 = ParseToVec2(obj, g_str)) != NULL)
578  {
579  function->mVariables[AI_VAR_DIR_X] = temp_vec2->x;
580  function->mVariables[AI_VAR_DIR_X] = temp_vec2->y;
581  } else
582  {
583  function->mVariables[AI_VAR_DIR_X] = 0;
584  function->mVariables[AI_VAR_DIR_Y] = AI_BASE_JUMP;
585  }
586 
587  function->mAction = AI_ACTION_JUMP;
588  break;
589  }
590  case AI_ACTION_ATTACK:
591  {
592  function->mAction = AI_ACTION_ATTACK;
593  function->mObject = JsmnToString(tok, g_str);
594  break;
595  }
596  default:
597  break;
598  }
599 }
600 
601 void SetAI_Check(ai_function_t* function, char** variables_str, char* data_str, ai_conditions_t condition)
602 {
603  ai_function_t *temp_ai;
604  object_t *temp_obj;
605  jsmntok_t *temp_tok;
606  char *temp_str;
607  if(!condition || !function)
608  {
609  return;
610  }
611  switch(condition)
612  {
614  {
615  function->mVariables[AI_VAR_CHECK] = StrToInt(data_str);
616  break;
617  }
619  {
620  function->mVariables[AI_VAR_CHECK] = StrToInt(data_str);
621  function->mFlags |= AI_FLAG_CHECK_PLAYER;
622  break;
623  }
625  {
626  function->mVariables[AI_VAR_CHECK] = StrToInt(data_str);
627  function->mFlags |= AI_FLAG_CHECK_OBJECT;
628  break;
629  }
631  {
632  ConvertFileToUseable(data_str, NULL, &temp_str, &temp_tok);
633  if(!temp_str || !temp_tok)
634  {
635  return;
636  }
637  temp_obj = ParseToObject(temp_tok, temp_str);
638  function->mLink = ParseAI(temp_obj, temp_str, variables_str);
639  break;
640  }
641  default:
642  break;
643  }
644 }
645 
647 {
648  if(gVariableAIs)
649  {
650  printf("Tried to init AI system, while already inited \n");
651  return -1;
652  }
653  gVariableAIs = (ai_function_t*) malloc(sizeof(ai_function_t)*(MAX_AI+1));
654  gPresetAIs = (ai_function_t*) malloc(sizeof(ai_function_t)*(MAX_AI+1));
655 
656  if(!gVariableAIs || !gPresetAIs)
657  {
658  printf("AI malloc error \n");
659  return -1;
660  }
661 
662  memset(gVariableAIs, 0, sizeof(ai_function_t)*(MAX_AI+1));
663  memset(gPresetAIs, 0, sizeof(ai_function_t)*(MAX_AI+1));
664  atexit(ShutdownAISystem);
665  return 0;
666 }
667 
669 {
670  if(!gVariableAIs || !gPresetAIs)
671  {
672  printf("AI not initialized before shutdown called \n");
673  return;
674  }
675  free(gVariableAIs);
676  free(gPresetAIs);
677 }
678 
679 ai_type_t StrToAI_Type(const char *str)
680 {
681  if(!strcmp(str, AI_TYPE_PRESET_STR))
682  {
683  return AI_TYPE_PRESET;
684  } else if(!strcmp(str, AI_TYPE_VARIABLE_STR))
685  {
686  return AI_TYPE_VARIABLE;
687  }
688  return AI_TYPE_NULL;
689 }
690 
691 ai_actions_t StrToAI_Action(const char* str)
692 {
693  int i;
694  for(i = 0; gAI_Actions[i]; i++)
695  {
696  if(!strcmp(gAI_Actions[i], str))
697  {
698  return (ai_actions_t)i;
699  }
700  }
701  return AI_ACTION_MAX;
702 }
703 
705 {
706  int i;
707  for(i = 0; gAI_Conditions[i]; i++)
708  {
709  if(!strcmp(gAI_Conditions[i], str))
710  {
711  return (ai_conditions_t)i;
712  }
713  }
714  return AI_CONDITION_MAX;
715 }
716 
718 {
719  int i;
720  for(i = 0; gAI_Variables[i]; i++)
721  {
722  if(!strcmp(gAI_Variables[i], str))
723  {
724  return (ai_variables_t)i;
725  }
726  }
727  return AI_VAR_MAX;
728 }
Definition: jsmn.h:40
int CountMem(void *src, int size_type)
Definition: mymath.c:51
int y
Definition: globals.h:22
void Vec2MultiplyScalar(vec2_t *A, int B, vec2_t *C)
Definition: mymath.c:41
#define AI_BASE_DAMAGE
Definition: ai_interpret.h:29
#define AI_BASE_JUMP
Definition: ai_interpret.h:26
object_t * FindObject(object_t *obj, char *name)
Definition: parseobject.c:120
ai_conditions_t
Definition: ai_interpret.h:75
char * JsmnToString(jsmntok_t *token, char *g_str)
Definition: mystrings.c:34
#define AI_VAR_STR
Definition: ai_interpret.h:18
ai_conditions_t StrToAI_Condition(const char *str)
Definition: ai_interpret.c:704
vec2_t * ParseToVec2(struct object_s *object, char *str)
int StrToInt(char *str)
Definition: mystrings.c:92
void SetAI_Var(ai_function_t *function, char *data_str, ai_variables_t var_type)
Definition: ai_interpret.c:481
int ConvertFileToUseable(char *fileName, jsmn_parser *parser, char **stringStorage, jsmntok_t **jsmnStorage)
Definition: mystrings.c:192
unsigned int gCurrentTime
Definition: game.c:50
ai_function_t * ParsePresetAI(object_t *obj, char *g_str)
Definition: ai_interpret.c:374
int CountObjectMembers(object_t *obj, char *g_str)
Definition: parseobject.c:144
entity_t * FindCachedEntity(const char *name)
Definition: entity.c:301
void Spawn(entity_t *targ, entity_t *info)
Definition: parsepowerup.c:41
ai_function_t * gVariableAIs
Definition: ai_interpret.c:9
void ShutdownAISystem()
Definition: ai_interpret.c:668
void NothingAI(entity_t *ent)
Definition: ai_interpret.c:25
#define AI_FUNCTION_OBJECT
Definition: ai_interpret.h:10
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
char * gAI_Conditions[]
Definition: ai_interpret.c:14
jsmntok_t * FindKey(jsmntok_t *token, char *key, char *g_str)
Definition: mystrings.c:10
ai_actions_t
Definition: ai_interpret.h:64
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
#define AI_TYPE_VARIABLE_STR
Definition: ai_interpret.h:14
ai_variables_t
Definition: ai_interpret.h:41
void MoveAI(entity_t *ent)
Definition: ai_interpret.c:61
#define AI_TYPE_STR
Definition: ai_interpret.h:12
#define AI_TYPE_PRESET_STR
Definition: ai_interpret.h:13
#define AI_BASE_THINK_FRAMES
Definition: ai_interpret.h:28
char * gAI_Variables[]
Definition: ai_interpret.c:12
#define MAX_AI
Definition: ai_interpret.h:8
void WalkAI(entity_t *ent)
Definition: ai_interpret.c:106
#define FRAME_DELAY
Definition: globals.h:135
int x
Definition: globals.h:21
void AttackAI(entity_t *ent)
Definition: ai_interpret.c:200
void JumpAI(entity_t *ent)
Definition: ai_interpret.c:147
void(*)(entity_t *) GetFunctionAI(ai_function_t *data)
Definition: ai_interpret.c:238
char * FindValue(struct object_s *obj, char *key, char *g_str)
Definition: mystrings.c:53
#define AI_BASE_SPEED
Definition: ai_interpret.h:27
void Vec2Add(vec2_t *A, vec2_t *B, vec2_t *C)
Definition: mymath.c:20
ai_type_t
Definition: ai_interpret.h:32
ai_actions_t StrToAI_Action(const char *str)
Definition: ai_interpret.c:691
int InitAISystem()
Definition: ai_interpret.c:646
object_t * ParseToObject(jsmntok_t *token, char *g_str)
Definition: parseobject.c:8
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
ai_function_t * ParseAI(object_t *obj, char *g_str, char **variables)
Definition: ai_interpret.c:261
Definition: globals.h:19