Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
npc_api.c File Reference

Go to the source code of this file.

Functions

Npcresolve_npc (Evt *script, s32 npcIdOrPtr)
 
void set_npc_animation (Npc *npc, u32 animID)
 
ApiStatus _npc_jump_to (Evt *script, s32 isInitialCall, s32 snapYaw)
 

Variables

s32 wExtraPartnerID
 
s32 wExtraPartnerNpcID
 

Function Documentation

◆ resolve_npc()

Npc * resolve_npc ( Evt * script,
s32 npcIdOrPtr )

Definition at line 8 of file npc_api.c.

8 {
9 if (npcIdOrPtr == NPC_SELF) {
10 return get_npc_safe(script->owner2.npcID);
11 } else if (npcIdOrPtr >= EVT_LIMIT) {
12 return get_npc_safe(npcIdOrPtr);
13 } else {
14 return (Npc*) npcIdOrPtr;
15 }
16}
union Evt::@9 owner2
Initially -1.
@ NPC_SELF
Definition enums.h:2526
Npc * get_npc_safe(s32 npcID)
Definition npc.c:1010
#define EVT_LIMIT
Definition macros.h:47

Referenced by _npc_jump_to().

◆ set_npc_animation()

void set_npc_animation ( Npc * npc,
u32 animID )

Definition at line 18 of file npc_api.c.

18 {
19 PlayerData* playerData = &gPlayerData;
20
21 if (PARTNER_ANIM_STILL <= animID && animID <= PARTNER_ANIM_HURT) {
22 npc->curAnim = gPartnerAnimations[playerData->curPartner].anims[animID - PARTNER_ANIM_STILL];
23 } else if (ENEMY_ANIM_IDLE <= animID && animID <= ENEMY_ANIM_F) {
24 npc->curAnim = get_enemy(npc->npcID)->animList[animID - ENEMY_ANIM_IDLE];
25 } else {
26 npc->curAnim = animID;
27 }
28}
@ PARTNER_ANIM_STILL
Definition enums.h:3414
@ PARTNER_ANIM_HURT
Definition enums.h:3422
@ ENEMY_ANIM_F
Definition enums.h:3454
@ ENEMY_ANIM_IDLE
Definition enums.h:3439
Enemy * get_enemy(s32 npcID)
Looks for an enemy matching the specified npcID.
Definition npc.c:2540
s32 * animList
Definition npc.h:341
AnimID curAnim
PlayerData gPlayerData
Definition 77480.c:40
PartnerAnimations gPartnerAnimations[12]
Definition partners.c:343

Referenced by _show_message().

◆ _npc_jump_to()

ApiStatus _npc_jump_to ( Evt * script,
s32 isInitialCall,
s32 snapYaw )

Definition at line 290 of file npc_api.c.

290 {
291 Bytecode* args = script->ptrReadPos;
292 f32* yaw = &script->functionTempF[2];
293 Npc* npc;
294
295 if (isInitialCall) {
296 script->functionTemp[0] = 0;
297 }
298
299 if (script->functionTemp[0] == 0) {
300 s32 npcID = evt_get_variable(script, *args++);
301 f32 goalX = evt_get_variable(script, *args++);
302 f32 goalY = evt_get_variable(script, *args++);
303 f32 goalZ = evt_get_variable(script, *args++);
304 s32 duration = evt_get_variable(script, *args++);
305 f32 dist;
306
307 npc = resolve_npc(script, npcID);
308
309 if (npc == NULL) {
310 return ApiStatus_DONE2;
311 }
312
313 script->functionTempPtr[1] = npc;
314 npc->moveToPos.x = goalX;
315 npc->moveToPos.y = goalY;
316 npc->moveToPos.z = goalZ;
317
318 npc->duration = duration;
319 dist = dist2D(npc->pos.x, npc->pos.z, npc->moveToPos.x, npc->moveToPos.z);
320 *yaw = 0.0f;
321 if (dist > 2.0) {
322 *yaw = atan2(npc->pos.x, npc->pos.z, npc->moveToPos.x, npc->moveToPos.z);
323 if (snapYaw == 0) {
324 npc->yaw = *yaw;
325 }
326 }
327
328 goalY = npc->moveToPos.y - npc->pos.y;
329
330 if (npc->duration == 0) {
331 npc->duration = dist / npc->moveSpeed;
332 } else {
333 npc->moveSpeed = dist / npc->duration;
334 }
335
336 npc->flags |= NPC_FLAG_JUMPING;
337 npc->jumpVel = (npc->jumpScale * npc->duration * 0.5f) + (goalY / npc->duration);
338 script->functionTemp[0] =1;
339 }
340
341 npc = script->functionTempPtr[1];
342 npc_move_heading(npc, npc->moveSpeed, *yaw);
343
344 npc->pos.y += npc->jumpVel;
345 npc->jumpVel -= npc->jumpScale;
346
347 npc->duration--;
348 if (npc->duration < 0) {
349 npc->jumpVel = 0.0f;
350 npc->pos.x = npc->moveToPos.x;
351 npc->pos.y = npc->moveToPos.y;
352 npc->pos.z = npc->moveToPos.z;
353 npc->flags &= ~NPC_FLAG_JUMPING;
355 return ApiStatus_DONE1;
356 }
357 return ApiStatus_BLOCK;
358}
Bytecode * ptrReadPos
#define atan2
@ SURFACE_INTERACT_LAND
Definition enums.h:4686
@ NPC_FLAG_JUMPING
Definition enums.h:3009
#define ApiStatus_DONE2
Definition evt.h:118
s32 Bytecode
Definition evt.h:7
#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 dist2D(f32 ax, f32 ay, f32 bx, f32 by)
Definition 43F0.c:670
void npc_surface_spawn_fx(Npc *npc, SurfaceInteractMode mode)
Definition surfaces.c:394
void npc_move_heading(Npc *npc, f32 speed, f32 yaw)
Definition npc.c:986
Npc * resolve_npc(Evt *script, s32 npcIdOrPtr)
Definition npc_api.c:8
f32 jumpScale
f32 jumpVel
s32 flags
Vec3f moveToPos
Vec3f pos
f32 moveSpeed
s16 duration

Variable Documentation

◆ wExtraPartnerID

s32 wExtraPartnerID
extern

Definition at line 32 of file script_list.c.

◆ wExtraPartnerNpcID

s32 wExtraPartnerNpcID
extern

Definition at line 33 of file script_list.c.