| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#include "ai_context.h" |
| 29 |
|
| 30 |
|
| 31 |
AIContext *AIContextNew(void) |
| 32 |
{ |
| 33 |
AIContext *c; |
| 34 |
CCALLOC(c, sizeof *c); |
| 35 |
c->EnemyId = -1; |
| 36 |
c->GunRangeScalar = 1.0; |
| 37 |
return c; |
| 38 |
} |
| 39 |
void AIContextDestroy(AIContext *c) |
| 40 |
{ |
| 41 |
if (c) |
| 42 |
{ |
| 43 |
CachedPathDestroy(&c->Goto.Path); |
| 44 |
} |
| 45 |
CFREE(c); |
| 46 |
} |
| 47 |
|
| 48 |
const char *AIStateGetChatterText(const AIState s) |
| 49 |
{ |
| 50 |
switch (s) |
| 51 |
{ |
| 52 |
case AI_STATE_NONE: |
| 53 |
return ""; |
| 54 |
case AI_STATE_IDLE: |
| 55 |
return "zzz"; |
| 56 |
case AI_STATE_DIE: |
| 57 |
return "blarg"; |
| 58 |
case AI_STATE_FOLLOW: |
| 59 |
return "let's go!"; |
| 60 |
case AI_STATE_HUNT: |
| 61 |
return "!"; |
| 62 |
case AI_STATE_TRACK: |
| 63 |
return "?"; |
| 64 |
case AI_STATE_FLEE: |
| 65 |
return "aah!"; |
| 66 |
case AI_STATE_CONFUSED: |
| 67 |
return "???"; |
| 68 |
case AI_STATE_NEXT_OBJECTIVE: |
| 69 |
return "objective"; |
| 70 |
default: |
| 71 |
CASSERT(false, "Unknown AI state"); |
| 72 |
return ""; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
bool AIContextShowChatter(const AIChatterFrequency f) |
| 77 |
{ |
| 78 |
switch (f) |
| 79 |
{ |
| 80 |
case AICHATTER_NONE: |
| 81 |
return false; |
| 82 |
case AICHATTER_SELDOM: |
| 83 |
return RAND_INT(0, 100) > 90; |
| 84 |
case AICHATTER_OFTEN: |
| 85 |
return RAND_INT(0, 100) > 50; |
| 86 |
case AICHATTER_ALWAYS: |
| 87 |
return true; |
| 88 |
default: |
| 89 |
CASSERT(false, "unknown chatter frequency"); |
| 90 |
return true; |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
bool AIContextSetState(AIContext *c, const AIState s) |
| 95 |
{ |
| 96 |
c->lastState = c->State; |
| 97 |
c->State = s; |
| 98 |
return s != c->lastState; |
| 99 |
} |