Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
GrooveGuyAI.inc.c
Go to the documentation of this file.
1#include "common.h"
2#include "npc.h"
3#include "sprite/npc/GrooveGuy.h"
4
5void N(GrooveGuyAI_02)(Evt* script, MobileAISettings* aiSettings, EnemyDetectVolume* territory) {
6 Enemy* enemy = script->owner1.enemy;
7 Npc* npc = get_npc_unsafe(enemy->npcID);
8
9 npc->duration = 0;
10 set_npc_yaw(npc, 270.0f);
11 enemy->varTable[0] = 0;
12 script->functionTemp[0] = 3;
13}
14
15void N(GrooveGuyAI_03)(Evt* script, MobileAISettings* aiSettings, EnemyDetectVolume* territory) {
16 Enemy* enemy = script->owner1.enemy;
17 Npc* npc = get_npc_unsafe((s32) enemy->npcID);
18 s32 phase;
19
20 switch (enemy->varTable[0]) {
21 case 0:
22 enemy->varTable[0] = 1;
23 enemy->varTable[1] = 0;
24 npc->curAnim = ANIM_GrooveGuy_Anim0C;
25 set_npc_yaw(npc, 270.0f);
26 npc->rot.y = 0.0f;
27 // fallthrough
28 case 1:
29 phase = enemy->varTable[1] % 16;
30 if (phase < 4) {
31 npc->curAnim = ANIM_GrooveGuy_Anim0C;
32 } else if (phase < 8) {
33 npc->curAnim = ANIM_GrooveGuy_Anim0B;
34 } else if (phase < 12) {
35 npc->curAnim = ANIM_GrooveGuy_Anim0C;
36 } else if (phase < 16) {
37 npc->curAnim = ANIM_GrooveGuy_Anim0D;
38 }
39 enemy->varTable[1]++;
40 if (enemy->varTable[1] >= 0x41) {
41 enemy->varTable[0] = 2;
42 }
43 break;
44 case 2:
45 enemy->varTable[0] = 3;
46 enemy->varTable[1] = 0;
47 npc->rot.y = 0.0f;
48 npc->curAnim = ANIM_GrooveGuy_Anim0C;
49 // fallthrough
50 case 3:
51 npc->rot.y += 35.0;
52 if (npc->rot.y > 360.0) {
53 npc->rot.y -= 360.0;
54 }
55 enemy->varTable[1]++;
56 if (enemy->varTable[1] >= 0x2E) {
57 enemy->varTable[0] = 4;
58 }
59 break;
60 }
61 if (enemy->varTable[0] == 4) {
62 npc->rot.y = 0.0f;
63 set_npc_yaw(npc, 270.0f);
64 script->functionTemp[0] = 0;
65 }
66}
67
68API_CALLABLE(N(GrooveGuyAI_Main)) {
69 Enemy* enemy = script->owner1.enemy;
70 Npc* npc = get_npc_unsafe(enemy->npcID);
71 EnemyDetectVolume territory;
72 EnemyDetectVolume* territoryPtr = &territory;
73 Bytecode* args = script->ptrReadPos;
74 MobileAISettings* aiSettings = (MobileAISettings*) evt_get_variable(script, *args++);
75 f32 posX;
76 f32 posY;
77 f32 posZ;
78 f32 hitDepth;
79
80 territory.skipPlayerDetectChance = 0;
81 territory.shape = enemy->territory->wander.detectShape;
82 territory.pointX = enemy->territory->wander.detectPos.x;
83 territory.pointZ = enemy->territory->wander.detectPos.z;
84 territory.sizeX = enemy->territory->wander.detectSize.x;
85 territory.sizeZ = enemy->territory->wander.detectSize.z;
86 territory.halfHeight = 65.0f;
87 territory.detectFlags = 0;
88
89 if (isInitialCall || enemy->aiFlags & AI_FLAG_SUSPEND) {
90 script->functionTemp[0] = 0;
91 npc->duration = 0;
93
94 npc->flags &= ~NPC_FLAG_JUMPING;
95 if (!enemy->territory->wander.isFlying) {
96 npc->flags |= NPC_FLAG_GRAVITY;
97 npc->flags &= ~NPC_FLAG_FLYING;
98 } else {
99 npc->flags &= ~NPC_FLAG_GRAVITY;
100 npc->flags |= NPC_FLAG_FLYING;
101 }
102
103 if (enemy->aiFlags & AI_FLAG_SUSPEND) {
104 script->functionTemp[0] = 99;
105 script->functionTemp[1] = 0;
106 } else if (enemy->flags & ENEMY_FLAG_BEGIN_WITH_CHASING) {
107 script->functionTemp[0] = 12;
108 }
109 enemy->aiFlags &= ~AI_FLAG_SUSPEND;
110 enemy->flags &= ~ENEMY_FLAG_BEGIN_WITH_CHASING;
111
112 hitDepth = 100.0f;
113 posX = npc->pos.x;
114 posY = npc->pos.y + npc->collisionHeight;
115 posZ = npc->pos.z;
116 if (npc_raycast_down_sides(npc->collisionChannel, &posX, &posY, &posZ, &hitDepth)) {
117 npc->pos.y = posY;
118 }
119 }
120
121 switch (script->functionTemp[0]) {
122 case 0x0:
123 basic_ai_wander_init(script, aiSettings, territoryPtr);
124 // fallthrough
125 case 0x1:
126 basic_ai_wander(script, aiSettings, territoryPtr);
127 break;
128 case 0x2:
129 N(GrooveGuyAI_02)(script, aiSettings, territoryPtr);
130 // fallthrough
131 case 0x3:
132 N(GrooveGuyAI_03)(script, aiSettings, territoryPtr);
133 break;
134 case 0xA:
135 basic_ai_found_player_jump_init(script, aiSettings, territoryPtr);
136 // fallthrough
137 case 0xB:
138 basic_ai_found_player_jump(script, aiSettings, territoryPtr);
139 break;
140 case 0xC:
141 basic_ai_chase_init(script, aiSettings, territoryPtr);
142 // fallthrough
143 case 0xD:
144 basic_ai_chase(script, aiSettings, territoryPtr);
145 if (script->functionTemp[0] != 0xE) {
146 break;
147 }
148 case 0xE:
149 basic_ai_lose_player(script, aiSettings, territoryPtr);
150 break;
151 case 0x63:
152 basic_ai_suspend(script);
153 break;
154 }
155 return 0;
156}
void N GrooveGuyAI_03(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N GrooveGuyAI_02(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
#define npc_raycast_down_sides
@ ENEMY_ANIM_INDEX_IDLE
Definition enums.h:3426
@ AI_FLAG_SUSPEND
Definition enums.h:4571
@ 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
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1690
void basic_ai_chase_init(Evt *script, MobileAISettings *npcAISettings, EnemyDetectVolume *territory)
Definition 23680.c:769
void basic_ai_lose_player(Evt *script, MobileAISettings *npcAISettings, EnemyDetectVolume *territory)
Definition 23680.c:847
void basic_ai_wander(Evt *script, MobileAISettings *npcAISettings, EnemyDetectVolume *territory)
Definition 23680.c:588
void basic_ai_chase(Evt *script, MobileAISettings *npcAISettings, EnemyDetectVolume *territory)
Definition 23680.c:804
void basic_ai_found_player_jump_init(Evt *script, MobileAISettings *npcAISettings, EnemyDetectVolume *territory)
Definition 23680.c:735
void basic_ai_wander_init(Evt *script, MobileAISettings *npcAISettings, EnemyDetectVolume *territory)
Definition 23680.c:567
void basic_ai_found_player_jump(Evt *script, MobileAISettings *npcAISettings, EnemyDetectVolume *territory)
Definition 23680.c:748
void basic_ai_suspend(Evt *script)
Definition 25AF0.c:13
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
s32 * animList
Definition npc.h:341
Npc * get_npc_unsafe(s32 npcID)
Definition npc.c:995
s16 detectFlags
Definition npc.h:207
u32 aiFlags
Definition npc.h:332
void set_npc_yaw(Npc *npc, f32 yaw)
Definition npc.c:1246
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
s32 collisionChannel
s16 collisionHeight
Vec3f rot
Vec3f pos
s16 duration