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