Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
TackleAI.inc.c
Go to the documentation of this file.
1#ifndef _TACKLE_AI_H
2#define _TACKLE_AI_H
3// TackleAI
4// used by Koopas, Koopatrols, Spinys, Buzzy Beetles
5
6#include "common.h"
7#include "npc.h"
8#include "effects.h"
9#include "sprite/npc/BonyBeetle.h"
10
11// prerequisites
13
14API_CALLABLE(N(TackleAI_Main)) {
15 Enemy* enemy = script->owner1.enemy;
16 Npc* npc = get_npc_unsafe(enemy->npcID);
17 Bytecode* args = script->ptrReadPos;
18 EnemyDetectVolume territory;
19 EnemyDetectVolume* territoryPtr = &territory;
20 MobileAISettings* aiSettings = (MobileAISettings*)evt_get_variable(script, *args++);
21
22 territory.skipPlayerDetectChance = 0;
23 territory.shape = enemy->territory->wander.detectShape;
24 territory.pointX = enemy->territory->wander.detectPos.x;
25 territory.pointZ = enemy->territory->wander.detectPos.z;
26 territory.sizeX = enemy->territory->wander.detectSize.x;
27 territory.sizeZ = enemy->territory->wander.detectSize.z;
28 territory.halfHeight = 100.0f;
29 territory.detectFlags = 0;
30
31 if (isInitialCall) {
32 enemy->varTable[6] = npc->collisionHeight;
33 enemy->varTable[8] = 0;
34 enemy->instigatorValue = 0;
36 }
37
38 if (isInitialCall || (enemy->aiFlags & AI_FLAG_SUSPEND)) {
39 script->AI_TEMP_STATE = 0;
40 npc->duration = 0;
41 enemy->hitboxIsActive = FALSE;
43 npc->flags &= ~NPC_FLAG_JUMPING;
44 npc->collisionHeight = enemy->varTable[6];
45 enemy->varTable[9] = 0;
46
47 if (!enemy->territory->wander.isFlying) {
48 npc->flags |= NPC_FLAG_GRAVITY;
49 npc->flags &= ~NPC_FLAG_FLYING;
50 } else {
51 npc->flags &= ~NPC_FLAG_GRAVITY;
52 npc->flags |= NPC_FLAG_FLYING;
53 }
54
55 if (enemy->aiFlags & AI_FLAG_SUSPEND) {
56 EffectInstance* emoteTemp;
57
58 script->AI_TEMP_STATE = 99;
59 script->functionTemp[1] = 0;
60 fx_emote(EMOTE_QUESTION, npc, 0.0f, npc->collisionHeight, 1.0f, 2.0f, -20.0f, 40, &emoteTemp);
61 enemy->aiFlags &= ~AI_FLAG_SUSPEND;
62 } else if (enemy->flags & ENEMY_FLAG_BEGIN_WITH_CHASING) {
63 script->AI_TEMP_STATE = 12;
64 enemy->flags &= ~ENEMY_FLAG_BEGIN_WITH_CHASING;
65 }
66 }
67
68 if (enemy->varTable[9] > 0) {
69 enemy->varTable[9]--;
70 if (enemy->varTable[9] == 0) {
71 if (npc->curAnim == ANIM_BonyBeetle_Anim2E ||
72 npc->curAnim == ANIM_BonyBeetle_Anim2F)
73 {
74 npc->curAnim = ANIM_BonyBeetle_Anim0C;
75 }
76 } else {
77 return ApiStatus_BLOCK;
78 }
79 }
80
81 switch (script->AI_TEMP_STATE) {
82 case 0:
83 basic_ai_wander_init(script, aiSettings, territoryPtr);
84 npc->collisionHeight = enemy->varTable[6];
85 case 1:
86 basic_ai_wander(script, aiSettings, territoryPtr);
87 break;
88 case 2:
89 basic_ai_loiter_init(script, aiSettings, territoryPtr);
90 if (enemy->varTable[7] == 6) {
91 if (rand_int(100) < 33) {
92 if (enemy->varTable[8] != 0) {
93 enemy->varTable[8] = 0;
94 enemy->instigatorValue = 0;
95 npc->curAnim = ANIM_BonyBeetle_Anim2F;
96 } else {
97 enemy->varTable[8] = 1;
98 enemy->instigatorValue = 1;
99 npc->curAnim = ANIM_BonyBeetle_Anim2E;
100 }
101 enemy->varTable[9] = 7;
102 return ApiStatus_BLOCK;
103 }
104 }
105 case 3:
106 basic_ai_loiter(script, aiSettings, territoryPtr);
107 break;
108 case 12:
109 N(set_script_owner_npc_anim)(script, aiSettings, territoryPtr);
110 case 13:
111 N(UnkDistFunc)(script, aiSettings, territoryPtr);
112 break;
113 case 14:
114 N(UnkNpcAIFunc12)(script, aiSettings, territoryPtr);
115 break;
116 case 15:
117 N(set_script_owner_npc_col_height)(script, aiSettings, territoryPtr);
118 break;
119 case 99:
120 basic_ai_suspend(script);
121 break;
122 }
123
124 if (enemy->varTable[7] == 6) {
125 if (enemy->varTable[8] != 0) {
126 enemy->instigatorValue = 1;
127 } else {
128 enemy->instigatorValue = 0;
129 }
130 if (enemy->varTable[8] != 0) {
131 switch (npc->curAnim) {
132 case ANIM_BonyBeetle_Anim04:
133 case ANIM_BonyBeetle_Anim0C:
134 case ANIM_BonyBeetle_Anim0E:
135 case ANIM_BonyBeetle_Anim10:
136 case ANIM_BonyBeetle_Anim12:
137 case ANIM_BonyBeetle_Anim16:
138 case ANIM_BonyBeetle_Anim18:
139 npc->curAnim++;
140 break;
141 }
142 }
143 }
144
145 return ApiStatus_BLOCK;
146}
147
148#endif
void N UnkNpcAIFunc12(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
ApiStatus N UnkDistFunc(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N set_script_owner_npc_col_height(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N set_script_owner_npc_anim(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
#define rand_int
@ EMOTE_QUESTION
Definition enums.h:497
@ ENEMY_ANIM_INDEX_IDLE
Definition enums.h:3426
@ AI_FLAG_SUSPEND
Definition enums.h:4571
@ AI_FLAG_SKIP_EMOTE_AFTER_FLEE
Definition enums.h:4572
@ ENEMY_FLAG_BEGIN_WITH_CHASING
Definition enums.h:4551
@ NPC_FLAG_FLYING
Definition enums.h:3001
@ NPC_FLAG_GRAVITY
Definition enums.h:3007
s32 Bytecode
Definition evt.h:7
#define ApiStatus_BLOCK
Definition evt.h:116
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1690
void basic_ai_wander(Evt *script, MobileAISettings *npcAISettings, EnemyDetectVolume *territory)
Definition 23680.c:588
void basic_ai_wander_init(Evt *script, MobileAISettings *npcAISettings, EnemyDetectVolume *territory)
Definition 23680.c:567
void basic_ai_loiter_init(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
Definition 23680.c:681
void basic_ai_suspend(Evt *script)
Definition 25AF0.c:13
void basic_ai_loiter(Evt *script, MobileAISettings *npcAISettings, EnemyDetectVolume *territory)
Definition 23680.c:691
enum TerritoryShape shape
Definition npc.h:201
s32 flags
Definition npc.h:295
VecXZi detectSize
Definition npc.h:216
enum TerritoryShape detectShape
Definition npc.h:217
s16 npcID
Definition npc.h:300
s8 instigatorValue
Definition npc.h:334
s32 * animList
Definition npc.h:341
Npc * get_npc_unsafe(s32 npcID)
Definition npc.c:995
s8 hitboxIsActive
Definition npc.h:299
s16 detectFlags
Definition npc.h:207
u32 aiFlags
Definition npc.h:332
s32 skipPlayerDetectChance
Definition npc.h:200
EnemyTerritoryWander wander
Definition npc.h:232
EnemyTerritory * territory
Definition npc.h:342
Definition npc.h:294
s32 flags
AnimID curAnim
s16 collisionHeight
s16 duration