Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
38F00.c
Go to the documentation of this file.
1#include "common.h"
2
3API_CALLABLE(func_8005DB00);
4API_CALLABLE(func_8005DD54);
5API_CALLABLE(func_8005DDF0);
6
8 Call(func_8005DB00)
10 End
11};
12
55
60
87
88API_CALLABLE(func_8005DB00) {
89 Npc* npc;
90 f32 targetDir, npcYaw;
91 PlayerStatus* playerStatus;
92 PartnerStatus* partnerStatus;
93
94 npc = get_npc_unsafe(script->owner1.enemy->npcID);
95 playerStatus = &gPlayerStatus;
96 partnerStatus = &gPartnerStatus;
97
98 if (isInitialCall) {
99 script->functionTemp[0] = 0;
100 }
101
102 switch (script->functionTemp[0]) {
103 case 0:
105 npc->duration = evt_get_variable(script, LVar1);
106 script->functionTemp[1] = evt_get_variable(script, LVar2);
107 script->functionTemp[2] = evt_get_variable(script, LVar3) / 2;
108 npc->curAnim = script->varTable[10];
109 script->functionTemp[0] = 1;
110 break;
111 case 1:
112 if (partnerStatus->actingPartner != PARTNER_BOW) {
113 if (npc->duration != 0 && npc->duration != script->functionTemp[0]) {
114 return ApiStatus_BLOCK;
115 }
116
117 if (npc->duration == 0) {
118 if (sqrtf(SQ((playerStatus->pos.x - npc->pos.x)) +
119 SQ((playerStatus->pos.y - npc->pos.y)) +
120 SQ((playerStatus->pos.z - npc->pos.z))) <= npc->planarFlyDist) {
121 targetDir = atan2(npc->pos.x, npc->pos.z, playerStatus->pos.x, playerStatus->pos.z);
122 npcYaw = script->functionTemp[1] == -1 ? npc->yaw : script->functionTemp[1];
123
124 if (fabsf(get_clamped_angle_diff(npcYaw, targetDir)) < script->functionTemp[2]) {
125 script->varTable[0] = 1;
126 return ApiStatus_DONE2;
127 }
128 }
129 } else {
130 if (dist2D(npc->pos.x, npc->pos.z, playerStatus->pos.x, playerStatus->pos.z) <= npc->planarFlyDist) {
131 targetDir = atan2(npc->pos.x, npc->pos.z, playerStatus->pos.x, playerStatus->pos.z);
132 npcYaw = script->functionTemp[1] == -1 ? npc->yaw : script->functionTemp[1];
133
134 if (fabsf(get_clamped_angle_diff(npcYaw, targetDir)) < script->functionTemp[2]) {
135 script->varTable[0] = 1;
136 return ApiStatus_DONE2;
137 }
138 }
139 }
140 }
141 break;
142 }
143 return ApiStatus_BLOCK;
144}
145
146API_CALLABLE(func_8005DD54) {
147 f32 angle = clamp_angle(script->varTable[0]);
148
149 script->varTable[0] = angle;
150 if (angle >= 180.0f) {
151 angle -= 180.0f;
152 }
153 if (angle >= 90.0f) {
154 angle = 180.0f - angle;
155 }
156 script->varTable[2] = (s32) (((90.0f - angle) * 95.0f) / 90.0f) + 160;
157 return ApiStatus_DONE2;
158}
159
160API_CALLABLE(func_8005DDF0) {
161 if (gCurrentEncounter.unk_08 != -1) {
162 return ApiStatus_DONE1;
163 } else {
164 return ApiStatus_BLOCK;
165 }
166}
EvtScript D_800939A4
Definition 38F00.c:56
EvtScript D_800939B4
Definition 38F00.c:61
EvtScript EVS_800936C0
Definition 38F00.c:7
EvtScript EVS_NpcHitRecoil
Definition 38F00.c:13
Bytecode EvtScript[]
#define sqrtf
#define clamp_angle
#define atan2
@ IMGFX_SET_COLOR
Definition enums.h:5123
@ NPC_SELF
Definition enums.h:2526
@ PARTNER_BOW
Definition enums.h:2894
@ NPC_FLAG_FLYING
Definition enums.h:3001
@ NPC_FLAG_JUMPING
Definition enums.h:3009
@ NPC_FLAG_GRAVITY
Definition enums.h:3007
@ NPC_FLAG_IGNORE_CAMERA_FOR_YAW
Definition enums.h:3016
#define ApiStatus_DONE2
Definition evt.h:118
#define ApiStatus_DONE1
Definition evt.h:117
#define ApiStatus_BLOCK
Definition evt.h:116
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1690
f32 fabsf(f32 f)
f32 dist2D(f32 ax, f32 ay, f32 bx, f32 by)
Definition 43F0.c:670
f32 evt_get_float_variable(Evt *script, Bytecode var)
Definition evt.c:1930
f32 get_clamped_angle_diff(f32, f32)
Definition 43F0.c:606
Npc * get_npc_unsafe(s32 npcID)
Definition npc.c:995
EncounterStatus gCurrentEncounter
Definition encounter.c:176
ApiStatus GetNpcPos(Evt *script, b32 isInitialCall)
ApiStatus SetNpcImgFXParams(Evt *script, b32 isInitialCall)
ApiStatus SetNpcAnimation(Evt *script, b32 isInitialCall)
ApiStatus BindNpcAI(Evt *script, b32 isInitialCall)
ApiStatus SetNpcRotation(Evt *script, b32 isInitialCall)
ApiStatus SetNpcPos(Evt *script, b32 isInitialCall)
ApiStatus SetSelfVar(Evt *script, b32 isInitialCall)
ApiStatus SetNpcFlagBits(Evt *script, b32 isInitialCall)
ApiStatus GetSelfVar(Evt *script, b32 isInitialCall)
#define Ref(sym)
Address/pointer constant.
Definition macros.h:60
#define Set(VAR, INT_VALUE)
Sets the given variable to a given value casted to an integer.
Definition macros.h:365
#define End
Signals the end of EVT script data. A script missing this will likely crash on load.
Definition macros.h:213
#define Add(VAR, INT_VALUE)
Definition macros.h:376
#define EndLoop
Marks the end of a loop.
Definition macros.h:248
#define EndIf
Marks the end of an if statement or an else block.
Definition macros.h:298
#define LVar2
Definition macros.h:150
#define LVar1
Definition macros.h:149
#define Wait(NUM_FRAMES)
Blocks for the given number of frames.
Definition macros.h:254
#define SQ(x)
Definition macros.h:166
#define IfEq(LVAR, RVAR)
Marks the beginning of an if statement that only executes if LVAR == RVAR.
Definition macros.h:269
#define Call(FUNC, ARGS...)
Calls a given C EVT API function with any number of arguments.
Definition macros.h:576
#define Loop(TIMES)
Marks the beginning of a loop.
Definition macros.h:245
#define LVar3
Definition macros.h:151
#define LVar0
Definition macros.h:148
#define Return
Kills the current EVT thread.
Definition macros.h:217
AnimID curAnim
f32 planarFlyDist
Vec3f pos
s16 duration
PartnerStatus gPartnerStatus
Definition partners.c:42
PlayerStatus gPlayerStatus
Definition 77480.c:39