Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
FlyingMagikoopaAI.inc.c
Go to the documentation of this file.
1#include "common.h"
2#include "npc.h"
3
5
7 Enemy* enemy = script->owner1.enemy;
8 Npc* npc = get_npc_unsafe(enemy->npcID);
9
10 npc->duration = 30;
11 script->AI_TEMP_STATE = 11;
12}
13
15 Enemy* enemy = script->owner1.enemy;
16 Npc* npc = get_npc_unsafe(enemy->npcID);
17 f32 basePosY = (f32)enemy->varTable[1] / 100.0;
19
20 npc->pos.y = basePosY + sin_deg(enemy->varTable[0]) * 6.0;
21 enemy->varTable[0] = clamp_angle(enemy->varTable[0] + 10);
22
23 if (N(MagikoopaAI_CanShootSpell)(script, aiSettings->chaseRadius, aiSettings->chaseOffsetDist, volume) == 1) {
24 fx_emote(0, npc, 0.0f, npc->collisionHeight, 1.0f, 2.0f, -20.0f, 15, &emoteTemp);
26 npc->duration = 50;
27 script->AI_TEMP_STATE = 20;
28 } else {
29 npc->duration--;
30 if (npc->duration <= 0) {
31 npc->duration = 5;
32 script->AI_TEMP_STATE = 15;
33 }
34 }
35}
36
43
48 s32 isCCW;
49 f32 moveDist;
51
52 Enemy* enemy = arg0->owner1.enemy;
53 Npc* npc = get_npc_unsafe(enemy->npcID);
54 f32 posX, posY, posZ;
55 s32 result = RESULT_SEARCHING;
56 s32 iterations = 0;
57
58 npc->duration--;
59 if (npc->duration <= 0) {
60 randomDist = rand_int(30) + 180.0;
61 isCCW = false;
63 npc->yaw = atan2(npc->pos.x, npc->pos.z, enemy->territory->wander.centerPos.x, enemy->territory->wander.centerPos.z) - iterations;
64 moveDist = dist2D(npc->pos.x, npc->pos.z, enemy->territory->wander.centerPos.x, enemy->territory->wander.centerPos.z);
65 if (randomDist > moveDist) {
66 randomDist = moveDist;
67 }
68 } else {
69 npc->yaw = atan2(npc->pos.x, npc->pos.z, gPlayerStatusPtr->pos.x, gPlayerStatusPtr->pos.z);
70 if (npc->yaw < 180.0) {
71 baseYaw = (rand_int(10) + 90.0) - 5.0;
72 } else {
73 baseYaw = (rand_int(10) + 270.0) - 5.0;
74 }
76 while (true) {
77 if (isCCW) {
78 npc->yaw = baseYaw + angleAdjust;
79 } else {
80 npc->yaw = baseYaw - angleAdjust;
81 }
82 posX = npc->pos.x;
83 posY = npc->pos.y;
84 posZ = npc->pos.z;
85 if (npc_test_move_taller_with_slipping(0, &posX, &posY, &posZ,
87 moveDist = dist2D(npc->pos.x, npc->pos.z, posX, posZ);
88 distToHit = moveDist;
89 if (distToHit > 160.0) {
90 if (distToHit < randomDist) {
92 }
93 result = RESULT_OK_BLOCKED;
94 }
95 } else {
96 result = RESULT_OK_CLEAR;
97 }
98
99 if (result != RESULT_SEARCHING) {
100 break;
101 }
102
103 if (!isCCW) {
104 isCCW = true;
105 } else {
106 angleAdjust += 5;
107 iterations++;
108 isCCW = false;
109 }
110
111 if (iterations >= 7) {
112 result = RESULT_NONE_FOUND;
113 }
114 }
115 }
116 posX = npc->pos.x;
117 posZ = npc->pos.z;
118 add_vec2D_polar(&posX, &posZ, randomDist, npc->yaw);
119 npc->moveToPos.x = posX;
120 npc->moveToPos.y = npc->pos.y;
121 npc->moveToPos.z = posZ;
122 enemy->varTable[4] = npc->pos.x * 100.0;
123 enemy->varTable[6] = npc->pos.z * 100.0;
124 enemy->varTable[3] = rand_int(10) + 35;
125 npc->duration = 0;
126 npc->moveSpeed = 3.0f;
127 npc->jumpVel = 1.4f;
128 npc->jumpScale = 0.2f;
129 arg0->functionTemp[0] = 0x10;
130 }
131}
132
134 Enemy* enemy = script->owner1.enemy;
135 Npc* npc = get_npc_unsafe(enemy->npcID);
136 f32 basePosY = (f32)enemy->varTable[1] / 100.0;
137
138 enemy->varTable[0] = clamp_angle(enemy->varTable[0] + 10);
139 npc->pos.y = basePosY + sin_deg(enemy->varTable[0]) * 6.0;
140
141 if (npc->turnAroundYawAdjustment == 0) {
142 enemy->varTable[5] = npc->pos.y * 100.0;
143 script->functionTemp[0] = 17;
144 }
145}
146
148 Enemy* enemy = script->owner1.enemy;
149 Npc* npc = get_npc_unsafe(enemy->npcID);
150 f32 limitY = (f32)enemy->varTable[1] / 100.0;
151 f32 basePosY = (f32)enemy->varTable[5] / 100.0;
152 f32 startX = (f32)enemy->varTable[4] / 100.0;
153 f32 startZ = (f32)enemy->varTable[6] / 100.0;
154 f32 lerpX = update_lerp(EASING_SIN_OUT, startX, npc->moveToPos.x, npc->duration, enemy->varTable[3]);
155 f32 lerpZ = update_lerp(EASING_SIN_OUT, startZ, npc->moveToPos.z, npc->duration, enemy->varTable[3]);
156
157 npc->pos.x = lerpX;
158 npc->pos.z = lerpZ;
159 npc->pos.y = basePosY + sin_deg((s32)(npc->duration * (180.0 / (f32)enemy->varTable[3])) + 180) * 25.0;
160
161 npc->duration++;
162 if (npc->duration == (enemy->varTable[3] - 8)) {
163 npc->yaw = atan2(npc->pos.x, npc->pos.z, gPlayerStatusPtr->pos.x, gPlayerStatusPtr->pos.z);
164 }
165 if (limitY <= npc->pos.y) {
166 npc->pos.y = limitY;
167 enemy->varTable[0] = 0;
168 script->functionTemp[0] = 10;
169 } else if (npc->duration >= enemy->varTable[3]) {
170 if (enemy->varTable[0] >= 180.0) {
171 if (enemy->varTable[0] < 270.0) {
172 enemy->varTable[0] = clamp_angle(540 - enemy->varTable[0]);
173 }
174 }
175 script->functionTemp[0] = 10;
176 }
177}
178
180 Enemy* enemy = script->owner1.enemy;
181 Npc* npc = get_npc_unsafe(enemy->npcID);
182
183 npc->duration = 40;
184 script->functionTemp[0] = 21;
185}
186
188 Enemy* enemy = script->owner1.enemy;
189 Npc* npc = get_npc_unsafe(enemy->npcID);
190 f32 posX, posY, posZ;
192
193 npc->duration--;
194 if (npc->duration == 0) {
195 npc->curAnim = enemy->animList[0];
196 fx_emote(2, npc, 0.0f, npc->collisionHeight, 1.0f, 2.0f, -20.0f, 12, &emoteTemp);
197 npc->curAnim = enemy->animList[0];
198 npc->duration = 15;
199 script->functionTemp[0] = 50;
200 } else if ((N(MagikoopaAI_CanShootSpell)(script, aiSettings->chaseRadius, aiSettings->chaseOffsetDist, territory) == 1) && (npc->turnAroundYawAdjustment == 0)) {
201 ai_enemy_play_sound(npc, 0x20D4, 0);
202 npc->curAnim = enemy->animList[8];
203 posX = npc->pos.x;
204 posY = npc->pos.y + 29.0f;
205 posZ = npc->pos.z + 1.0f;
206 add_vec2D_polar(&posX, &posZ, 30.0f, 270.0f - npc->renderYaw);
207 fx_gather_energy_pink(0, posX, posY, posZ, 0.1f, 13);
208 npc->duration = 15;
209 script->functionTemp[0] = 22;
210 }
211}
212
214 Enemy* enemy = script->owner1.enemy;
215 Npc* npc = get_npc_unsafe(enemy->npcID);
216
217 npc->duration--;
218 if (npc->duration <= 0) {
219 npc->curAnim = enemy->animList[9];
220 npc->duration = 7;
221 script->functionTemp[0] = 0x17;
222 }
223}
224
226 Enemy* enemy = script->owner1.enemy;
227 Npc* npc = get_npc_unsafe(enemy->npcID);
228 s32 temp_s1;
230
231 npc->duration--;
232 if (npc->duration <= 0) {
233 temp_s1 = N(MagikoopaAI_CanShootSpell)(script, aiSettings->chaseRadius, aiSettings->chaseOffsetDist, territory);
234 if (temp_s1 != 1) {
235 fx_emote(2, npc, 0.0f, npc->collisionHeight, 1.0f, 2.0f, -20.0f, 12, &emoteTemp);
236 npc->curAnim = enemy->animList[0];
237 npc->duration = 15;
238 script->functionTemp[0] = 50;
239 } else {
241 get_enemy(enemy->npcID + 1)->varTable[0] = temp_s1;
242 npc->duration = 20;
243 script->functionTemp[0] = 24;
244 }
245 }
246}
247
249 Enemy* enemy = script->owner1.enemy;
250 Npc* npc = get_npc_unsafe(enemy->npcID);
251 f32 basePosY = (f32)enemy->varTable[1] / 100.0;
252
253 npc->pos.y = basePosY + sin_deg(enemy->varTable[0]) * 6.0;
254 enemy->varTable[0] = clamp_angle(enemy->varTable[0] + 10);
255
256 npc->duration--;
257 if (npc->duration <= 0) {
258 npc->curAnim = enemy->animList[0];
259 npc->duration = 3;
260 script->AI_TEMP_STATE = 50;
261 }
262}
263
265 Enemy* enemy = script->owner1.enemy;
266 Npc* npc = get_npc_unsafe(enemy->npcID);
267 f32 basePosY = (f32)enemy->varTable[1] / 100.0;
268
269 npc->pos.y = basePosY + sin_deg(enemy->varTable[0]) * 6.0;
270 enemy->varTable[0] = clamp_angle(enemy->varTable[0] + 10);
271
272 npc->duration--;
273 if (npc->duration <= 0) {
274 script->AI_TEMP_STATE = 10;
275 }
276}
277
278API_CALLABLE(N(FlyingMagikoopaAI_Main)) {
279 Bytecode* args = script->ptrReadPos;
280 Enemy* enemy = script->owner1.enemy;
281 Npc* npc = get_npc_unsafe(enemy->npcID);
282 EnemyDetectVolume territory;
283 EnemyDetectVolume* territoryPtr = &territory;
285
286 territory.skipPlayerDetectChance = 0;
287 territory.shape = enemy->territory->wander.detectShape;
288 territory.pointX = enemy->territory->wander.detectPos.x;
289 territory.pointZ = enemy->territory->wander.detectPos.z;
290 territory.sizeX = enemy->territory->wander.detectSize.x;
291 territory.sizeZ = enemy->territory->wander.detectSize.z;
292 territory.halfHeight = 120.0f;
293 territory.detectFlags = 0;
294
295 if (isInitialCall) {
296 npc->flags &= ~NPC_FLAG_GRAVITY;
297 npc->flags |= NPC_FLAG_FLYING;
300 enemy->varTable[1] = npc->pos.y * 100.0;
301 enemy->varTable[0] = 0;
302 enemy->varTable[2] = 0;
303 npc->duration = 0;
304 script->AI_TEMP_STATE = 10;
305 }
306
307 npc->verticalRenderOffset = -5;
308
309 if (enemy->aiFlags & AI_FLAG_SUSPEND) {
310 if (enemy->aiSuspendTime != 0) {
311 return ApiStatus_BLOCK;
312 }
313 enemy->aiFlags &= ~AI_FLAG_SUSPEND;
314 }
315
316 switch (script->AI_TEMP_STATE) {
317 case 10:
319 // fallthrough
320 case 11:
322 break;
323 case 15:
325 if (script->AI_TEMP_STATE != 16) {
326 break;
327 }
328 case 16:
330 if (script->AI_TEMP_STATE != 17) {
331 break;
332 }
333 case 17:
335 break;
336 case 20:
338 break;
339 case 21:
341 break;
342 case 22:
344 break;
345 case 23:
347 if (script->AI_TEMP_STATE != 24) {
348 break;
349 }
350 case 24:
352 break;
353 case 50:
355 break;
356 }
357 return ApiStatus_BLOCK;
358}
359
360API_CALLABLE(N(FlyingMagikoopaAI_OnHitInit)) {
361 Enemy* enemy = script->owner1.enemy;
362
364 return ApiStatus_DONE2;
365}
366
367API_CALLABLE(N(FlyingMagikoopaAI_OnHit)) {
368 Enemy* enemy = script->owner1.enemy;
369 Npc* npc = get_npc_unsafe(enemy->npcID);
370
371 if (enemy->varTable[0] == 2) {
372 npc->jumpVel = 0.0f;
373 npc->moveSpeed = 0.0f;
374 }
375 return ApiStatus_DONE2;
376}
377
BSS s32 PopupMenu_SelectedIndex
void N FlyingMagikoopaAI_22(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N FlyingMagikoopaAI_10(Evt *script, MobileAISettings *arg1, EnemyDetectVolume *arg2)
void N FlyingMagikoopaAI_24(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N FlyingMagikoopaAI_23(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N FlyingMagikoopaAI_16(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N FlyingMagikoopaAI_50(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
MagikoopaMoveResult
@ RESULT_OK_BLOCKED
@ RESULT_OK_CLEAR
@ RESULT_NONE_FOUND
@ RESULT_SEARCHING
void N FlyingMagikoopaAI_11(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *volume)
void N FlyingMagikoopaAI_20(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N FlyingMagikoopaAI_17(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N FlyingMagikoopaAI_15(Evt *arg0, MobileAISettings *arg1, EnemyDetectVolume *arg2)
void N FlyingMagikoopaAI_21(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
s32 N MagikoopaAI_CanShootSpell(Evt *script, f32 arg1, f32 arg2, EnemyDetectVolume *territory)
Vec3s pos
Definition demo_api.c:17
#define sin_deg
#define rand_int
#define clamp_angle
#define atan2
@ AI_FLAG_SUSPEND
Definition enums.h:4156
@ ENEMY_FLAG_ACTIVE_WHILE_OFFSCREEN
Definition enums.h:4127
@ EASING_SIN_OUT
Definition enums.h:521
@ SOUND_SPELL_CAST2
Definition enums.h:1502
@ SOUND_AI_ALERT_A
Definition enums.h:1081
@ SOUND_PARAM_MORE_QUIET
Definition enums.h:1749
@ NPC_FLAG_FLYING
Definition enums.h:3035
@ NPC_FLAG_FLIP_INSTANTLY
Definition enums.h:3053
#define ApiStatus_DONE2
Definition evt.h:119
s32 Bytecode
Definition evt.h:7
#define ApiStatus_BLOCK
Definition evt.h:117
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1730
f32 update_lerp(s32 easing, f32 start, f32 end, s32 elapsed, s32 duration)
Definition 43F0.c:735
b32 is_point_outside_territory(s32 shape, f32 pointX, f32 pointY, f32 centerX, f32 centerY, f32 sizeX, f32 sizeZ)
Definition 23680.c:412
void ai_enemy_play_sound(Npc *npc, s32 arg1, s32 arg2)
Definition 23680.c:543
s32 evt_set_variable(Evt *script, Bytecode var, s32 value)
Definition evt.c:1887
f32 dist2D(f32 ax, f32 ay, f32 bx, f32 by)
Definition 43F0.c:670
b32 npc_test_move_taller_with_slipping(s32, f32 *, f32 *, f32 *, f32, f32, f32, f32)
void add_vec2D_polar(f32 *x, f32 *y, f32 r, f32 theta)
Definition 43F0.c:685
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
Enemy * get_enemy(s32 npcID)
Looks for an enemy matching the specified npcID.
Definition npc.c:2537
s32 * animList
Definition npc.h:341
Enemy * curEnemy
Definition npc.h:394
VecXZi wanderSize
Definition npc.h:212
s8 aiSuspendTime
Definition npc.h:333
Npc * get_npc_unsafe(s32 npcID)
Definition npc.c:992
s16 detectFlags
Definition npc.h:207
EncounterStatus gCurrentEncounter
Definition encounter.c:175
enum TerritoryShape wanderShape
Definition npc.h:214
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
#define LVar0
Definition macros.h:149
s16 collisionDiameter
f32 jumpScale
f32 jumpVel
s32 flags
f32 renderYaw
AnimID curAnim
Vec3f moveToPos
s16 collisionHeight
s16 turnAroundYawAdjustment
s8 verticalRenderOffset
Vec3f pos
f32 moveSpeed
s16 duration
PlayerStatus * gPlayerStatusPtr