Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
MagikoopaSpellAI.inc.c
Go to the documentation of this file.
1#include "common.h"
2#include "effects.h"
3
4s32 N(MagikoopaAI_CanShootSpell)(Evt* script, f32 arg1, f32 arg2, EnemyDetectVolume* territory) {
5 Enemy* enemy = script->owner1.enemy;
6 Npc* npc = get_npc_unsafe(enemy->npcID);
7 Camera* camera = &gCameras[gCurrentCamID];
8
9 if (basic_ai_check_player_dist(territory, enemy, arg1, arg2, 0)) {
10 f32 angle;
11 f32 t1;
12
13 if (clamp_angle(get_clamped_angle_diff(camera->curYaw, npc->yaw)) < 180.0) {
14 angle = 90.0f;
15 } else {
16 angle = 270.0f;
17 }
18
19 t1 = atan2(npc->pos.x, npc->pos.z, gPlayerStatusPtr->pos.x, gPlayerStatusPtr->pos.z);
20 if (fabsf(get_clamped_angle_diff(angle, t1)) > 75.0) {
21 return -1;
22 }
23
24 t1 = atan2(0.0f, npc->pos.y, fabsf(npc->pos.x - gPlayerStatusPtr->pos.x), gPlayerStatusPtr->pos.y);
25 if (fabsf(t1 - 90.0) > 70.0) {
26 return -1;
27 }
28
30 return -1;
31 }
32
33 if ((get_enemy(enemy->npcID + 1)->varTable[0] == 0)) {
34 return 1;
35 }
36 }
37
38 return -1;
39}
40
41API_CALLABLE(N(MagikoopaAI_SpellMain)) {
42 Enemy* enemy = script->owner1.enemy;
43 Npc sp20;
44 Npc* sp20Ptr = &sp20;
45 s32 timer = 0;
46 Npc* npc1 = get_npc_unsafe(enemy->npcID);
47 Npc* npc2 = get_npc_unsafe(get_enemy(enemy->npcID - 1)->npcID);
48 f32 t1;
49 f32 t2;
50
51 if (isInitialCall || (enemy->aiFlags & AI_FLAG_SUSPEND)) {
52 script->functionTemp[0] = 0;
53 npc1->duration = 0;
57 npc1->scale.x = 0.4f;
58 npc1->scale.y = 0.4f;
59 if (enemy->aiFlags & AI_FLAG_SUSPEND) {
60 enemy->aiFlags &= ~AI_FLAG_SUSPEND;
61 }
62 }
63
64 switch (script->functionTemp[0]) {
65 case 0:
66 enemy->varTable[3] = NULL;
67 npc1->collisionDiameter = 20;
68 npc1->collisionHeight = 20;
69 npc1->pos.x = NPC_DISPOSE_POS_X;
70 npc1->pos.y = NPC_DISPOSE_POS_Y;
71 npc1->pos.z = NPC_DISPOSE_POS_Z;
72 enemy->varTable[0] = 0;
73 script->functionTemp[0] = 1;
74 // fallthrough
75 case 1:
76 if (enemy->varTable[0] == 1) {
77 s32 duration;
78
79 enemy->varTable[0] = 2;
80 sp20Ptr->pos.x = npc2->pos.x;
81 sp20Ptr->pos.y = npc2->pos.y;
82 sp20Ptr->pos.z = npc2->pos.z;
83 npc_move_heading(sp20Ptr, enemy->varTable[2], 270.0f - npc2->renderYaw);
84 npc1->pos.x = sp20Ptr->pos.x;
85 npc1->pos.y = npc2->pos.y + enemy->varTable[1];
86 npc1->pos.z = sp20Ptr->pos.z;
87 enemy->hitboxIsActive = TRUE;
88 enemy->unk_10.x = npc1->pos.x;
89 enemy->unk_10.y = npc1->pos.y;
90 enemy->unk_10.z = npc1->pos.z;
91 npc1->moveSpeed = 3.6f;
92
93 t1 = fabsf(npc1->pos.x - gPlayerStatusPtr->pos.x);
94 t2 = atan2(0.0f, npc1->pos.y, t1, (gPlayerStatusPtr->pos.y + 10.0)) - 90.0;
95 npc1->jumpVel = cosine(t2) * npc1->moveSpeed;
96 npc1->yaw = atan2(npc1->pos.x, npc1->pos.z, gPlayerStatusPtr->pos.x, gPlayerStatusPtr->pos.z);
97 duration = dist3D(npc1->pos.x, npc1->pos.y, npc1->pos.z,
100 if (duration <= 0) {
101 duration = 1;
102 }
103 enemy->varTable[3] = (s32)fx_shape_spell(0, npc1->pos.x, npc1->pos.y + 14.0f, npc1->pos.z,
105 gPlayerStatusPtr->pos.y + 10.0f + 14.0f,
106 gPlayerStatusPtr->pos.z, duration);
107 npc1->duration = duration;
108 script->functionTemp[0] = 2;
109 }
110 break;
111 case 2:
112 npc1->duration--;
113 if (npc1->duration <= 0) {
114 timer = 20;
115 }
116 if (timer == 0) {
117 npc_move_heading(npc1, npc1->moveSpeed, npc1->yaw);
118 npc1->pos.y += npc1->jumpVel;
119 break;
120 }
121 // fallthrough
122 case 3:
123 npc1->jumpVel = 0.0f;
124 npc1->moveSpeed = 0.0f;
125 npc1->pos.y -= npc1->collisionHeight * 0.5;
126 enemy->varTable[0] = 3;
127 npc1->duration = 0;
128 script->functionTemp[0] = 4;
129 break;
130 case 4:
131 npc1->duration++;
132 if (npc1->duration < 7) {
133 npc1->pos.y -= 3.5;
134 npc1->collisionDiameter = ((f32) npc1->duration * 7.0) + 20.0;
135 npc1->collisionHeight = ((f32) npc1->duration * 7.0) + 20.0;
136 } else if (npc1->duration == 7) {
137 npc1->pos.x = NPC_DISPOSE_POS_X;
138 npc1->pos.y = NPC_DISPOSE_POS_Y;
139 npc1->pos.z = NPC_DISPOSE_POS_Z;
140 npc1->collisionDiameter = 20;
141 npc1->collisionHeight = 20;
142 } else if (npc1->duration >= 16) {
143 enemy->varTable[0] = 0;
144 script->functionTemp[0] = 0;
145 }
146 break;
147 }
148 return ApiStatus_BLOCK;
149}
s32 N MagikoopaAI_CanShootSpell(Evt *script, f32 arg1, f32 arg2, EnemyDetectVolume *territory)
#define clamp_angle
#define atan2
@ AI_FLAG_SUSPEND
Definition enums.h:4571
@ ENEMY_FLAG_IGNORE_HAMMER
Definition enums.h:4547
@ ENEMY_FLAG_IGNORE_PARTNER
Definition enums.h:4549
@ ENEMY_FLAG_PROJECTILE
Definition enums.h:4527
@ ENEMY_FLAG_IGNORE_JUMP
Definition enums.h:4546
@ ENEMY_FLAG_ACTIVE_WHILE_OFFSCREEN
Definition enums.h:4542
@ PARTNER_BOW
Definition enums.h:2894
@ PARTNER_SUSHIE
Definition enums.h:2892
@ NPC_FLAG_IGNORE_PLAYER_COLLISION
Definition enums.h:3006
@ NPC_FLAG_FLIP_INSTANTLY
Definition enums.h:3019
@ NPC_FLAG_INVISIBLE
Definition enums.h:2999
@ NPC_FLAG_IGNORE_CAMERA_FOR_YAW
Definition enums.h:3016
#define ApiStatus_BLOCK
Definition evt.h:116
f32 fabsf(f32 f)
f32 dist3D(f32 ax, f32 ay, f32 az, f32 bx, f32 by, f32 bz)
Definition 43F0.c:677
f32 cosine(s16 arg0)
Definition 43F0.c:354
f32 get_clamped_angle_diff(f32, f32)
Definition 43F0.c:606
s32 flags
Definition npc.h:295
s32 basic_ai_check_player_dist(EnemyDetectVolume *arg0, Enemy *arg1, f32 arg2, f32 arg3, b8 arg4)
Definition 23680.c:429
s16 npcID
Definition npc.h:300
Enemy * get_enemy(s32 npcID)
Looks for an enemy matching the specified npcID.
Definition npc.c:2540
Npc * get_npc_unsafe(s32 npcID)
Definition npc.c:995
Vec3s unk_10
Definition npc.h:302
s8 hitboxIsActive
Definition npc.h:299
u32 aiFlags
Definition npc.h:332
void npc_move_heading(Npc *npc, f32 speed, f32 yaw)
Definition npc.c:986
Definition npc.h:294
#define NPC_DISPOSE_POS_Z
Definition macros.h:161
#define NPC_DISPOSE_POS_X
Definition macros.h:159
#define NPC_DISPOSE_POS_Y
Definition macros.h:160
s16 collisionDiameter
Vec3f scale
f32 jumpVel
s32 flags
f32 renderYaw
s16 collisionHeight
Vec3f pos
f32 moveSpeed
s16 duration
PlayerStatus * gPlayerStatusPtr
PartnerStatus gPartnerStatus
Definition partners.c:42
Camera gCameras[4]
Definition cam_main.c:17
s16 gCurrentCamID
Definition cam_main.c:13