Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
ShyGuyPatrolAI.inc.c
Go to the documentation of this file.
1#include "common.h"
2#include "npc.h"
3
5
6void N(ShyGuyPatrolAI_14)(Evt* script, MobileAISettings* aiSettings, EnemyDetectVolume* territoryPtr) {
7 Enemy* enemy = script->owner1.enemy;
8 Npc* npc = get_npc_unsafe(enemy->npcID);
9
10 npc->moveSpeed *= 0.6;
11 npc->curAnim = enemy->animList[12];
12 npc->duration = 5;
13 script->functionTemp[0] = 0xF;
14}
15
16void N(ShyGuyPatrolAI_15)(Evt* script, MobileAISettings* aiSettings, EnemyDetectVolume* territory) {
17 Enemy* enemy = script->owner1.enemy;
18 Npc* npc = get_npc_unsafe((s32) enemy->npcID);
19 f32 yaw = npc->yaw;
20
21 if (ai_check_fwd_collisions(npc, npc->moveSpeed, &yaw, NULL, NULL, NULL) == 0) {
22 npc_move_heading(npc, npc->moveSpeed, npc->yaw);
23 }
24
25 npc->duration--;
26 if (npc->duration == 0) {
27 npc->moveSpeed *= 0.6;
28
29 npc->curAnim = enemy->animList[11];
30 npc->duration = 10;
31 script->functionTemp[0] = 16;
32 }
33}
34
35void N(ShyGuyPatrolAI_16)(Evt* script, MobileAISettings* aiSettings, EnemyDetectVolume* territory) {
36 Enemy* enemy = script->owner1.enemy;
37 Npc* npc = get_npc_unsafe(enemy->npcID);
38 f32 yaw = npc->yaw;
39
40 if (ai_check_fwd_collisions(npc, npc->moveSpeed, &yaw, NULL, NULL, NULL) == 0) {
41 npc_move_heading(npc, npc->moveSpeed, npc->yaw);
42 }
43
44 npc->duration--;
45 if (npc->duration == 0) {
46 npc->duration = 30;
47 script->functionTemp[0] = 17;
48 }
49}
50
51void N(ShyGuyPatrolAI_17)(Evt* script, MobileAISettings* aiSettings, EnemyDetectVolume* territory) {
52 Enemy* enemy = script->owner1.enemy;
53 Npc* npc = get_npc_unsafe(enemy->npcID);
54
55 npc->duration--;
56 if (npc->duration == 0) {
58 script->functionTemp[0] = 0;
59 }
60}
61
62API_CALLABLE(N(ShyGuyPatrolAI_Main)) {
63 Enemy* enemy = script->owner1.enemy;
64 Npc* npc = get_npc_unsafe(enemy->npcID);
65 EnemyDetectVolume territory;
66 EnemyDetectVolume* territoryPtr = &territory;
67 Bytecode* args = script->ptrReadPos;
68 MobileAISettings* aiSettings = (MobileAISettings*) evt_get_variable(script, *args++);
69 f32 posX;
70 f32 posY;
71 f32 posZ;
72 f32 hitDepth;
73
74 territory.skipPlayerDetectChance = 0;
75 territory.shape = enemy->territory->patrol.detectShape;
76 territory.pointX = enemy->territory->patrol.detectPos.x;
77 territory.pointZ = enemy->territory->patrol.detectPos.z;
78 territory.sizeX = enemy->territory->patrol.detectSize.x;
79 territory.sizeZ = enemy->territory->patrol.detectSize.z;
80 territory.halfHeight = 65.0f;
81 territory.detectFlags = 0;
82
83 if (isInitialCall || enemy->aiFlags & AI_FLAG_SUSPEND) {
84 script->functionTemp[0] = 0;
85 npc->duration = 0;
87
88 npc->flags &= ~NPC_FLAG_JUMPING;
89 if (!enemy->territory->patrol.isFlying) {
90 npc->flags |= NPC_FLAG_GRAVITY;
91 npc->flags &= ~NPC_FLAG_FLYING;
92 } else {
93 npc->flags &= ~NPC_FLAG_GRAVITY;
94 npc->flags |= NPC_FLAG_FLYING;
95 }
96
97 if (enemy->aiFlags & AI_FLAG_SUSPEND) {
98 script->functionTemp[0] = 99;
99 script->functionTemp[1] = 0;
100 enemy->aiFlags &= ~AI_FLAG_SUSPEND;
101 } else if (enemy->flags & ENEMY_FLAG_BEGIN_WITH_CHASING) {
102 script->functionTemp[0] = 12;
103 enemy->flags &= ~ENEMY_FLAG_BEGIN_WITH_CHASING;
104 }
105
106 posX = npc->pos.x;
107 posY = npc->pos.y + npc->collisionHeight;
108 posZ = npc->pos.z;
109 hitDepth = 100.0f;
110 if (npc_raycast_down_sides(npc->collisionChannel, &posX, &posY, &posZ, &hitDepth)) {
111 npc->pos.y = posY;
112 }
113 }
114
115 switch (script->functionTemp[0]) {
116 case 0x0:
117 N(PatrolAI_MoveInit)(script, aiSettings, territoryPtr);
118 // fallthrough
119 case 0x1:
120 N(PatrolAI_Move)(script, aiSettings, territoryPtr);
121 break;
122 case 0x2:
123 N(PatrolAI_LoiterInit)(script, aiSettings, territoryPtr);
124 // fallthrough
125 case 0x3:
126 N(PatrolAI_Loiter)(script, aiSettings, territoryPtr);
127 break;
128 case 0x4:
129 N(PatrolAI_PostLoiter)(script, aiSettings, territoryPtr);
130 break;
131 case 0xA:
132 N(PatrolAI_JumpInit)(script, aiSettings, territoryPtr);
133 // fallthrough
134 case 0xB:
135 N(PatrolAI_Jump)(script, aiSettings, territoryPtr);
136 break;
137 case 0xC:
138 N(PatrolAI_ChaseInit)(script, aiSettings, territoryPtr);
139 // fallthrough
140 case 0xD:
141 N(PatrolAI_Chase)(script, aiSettings, territoryPtr);
142 break;
143 case 0xE:
144 N(ShyGuyPatrolAI_14)(script, aiSettings, territoryPtr);
145 if (script->functionTemp[0] != 0xF) {
146 break;
147 }
148 case 0xF:
149 N(ShyGuyPatrolAI_15)(script, aiSettings, territoryPtr);
150 if (script->functionTemp[0] != 0x10) {
151 break;
152 }
153 case 0x10:
154 N(ShyGuyPatrolAI_16)(script, aiSettings, territoryPtr);
155 if (script->functionTemp[0] != 0x11) {
156 break;
157 }
158 case 0x11:
159 N(ShyGuyPatrolAI_17)(script, aiSettings, territoryPtr);
160 break;
161 case 0x63:
162 basic_ai_suspend(script);
163 break;
164 }
165 return ApiStatus_BLOCK;
166}
void N ShyGuyPatrolAI_15(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N ShyGuyPatrolAI_16(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N ShyGuyPatrolAI_14(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territoryPtr)
void N ShyGuyPatrolAI_17(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N PatrolAI_MoveInit(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N PatrolAI_PostLoiter(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N PatrolAI_Loiter(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N PatrolAI_Jump(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N PatrolAI_JumpInit(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N PatrolAI_ChaseInit(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N PatrolAI_Chase(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N PatrolAI_Move(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
#define ApiStatus_BLOCK
Definition evt.h:116
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1690
void PatrolAI_LoiterInit(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
s32 ai_check_fwd_collisions(Npc *npc, f32 arg1, f32 *arg2, f32 *arg3, f32 *arg4, f32 *arg5)
Definition 25AF0.c:22
void basic_ai_suspend(Evt *script)
Definition 25AF0.c:13
enum TerritoryShape shape
Definition npc.h:201
s32 flags
Definition npc.h:295
s16 npcID
Definition npc.h:300
s32 * animList
Definition npc.h:341
Npc * get_npc_unsafe(s32 npcID)
Definition npc.c:995
VecXZi detectSize
Definition npc.h:226
s16 detectFlags
Definition npc.h:207
EnemyTerritoryPatrol patrol
Definition npc.h:233
u32 aiFlags
Definition npc.h:332
void npc_move_heading(Npc *npc, f32 speed, f32 yaw)
Definition npc.c:986
s32 skipPlayerDetectChance
Definition npc.h:200
enum TerritoryShape detectShape
Definition npc.h:227
EnemyTerritory * territory
Definition npc.h:342
Definition npc.h:294
s32 flags
AnimID curAnim
s32 collisionChannel
s16 collisionHeight
Vec3f pos
f32 moveSpeed
s16 duration