Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
goompa.c
Go to the documentation of this file.
1#include "common.h"
2#include "goompa.h"
3#include "../src/world/partners.h"
4
5#define NAMESPACE world_goompa
6
7void N(init)(Npc* partner) {
8 partner->collisionHeight = 24;
9 partner->collisionDiameter = 20;
10}
11
12API_CALLABLE(N(TakeOut)) {
13 Npc* goompa = script->owner2.npc;
14
15 if (isInitialCall) {
17 }
18
19 if (partner_get_out(goompa)) {
20 return ApiStatus_DONE1;
21 } else {
22 return ApiStatus_BLOCK;
23 }
24}
25
27 Call(N(TakeOut))
28 Return
29 End
30};
31
32BSS TweesterPhysics N(TweesterPhysicsData);
33TweesterPhysics* N(TweesterPhysicsPtr) = &N(TweesterPhysicsData);
34
35API_CALLABLE(N(Update)) {
36 PlayerData* playerData = &gPlayerData;
37 Npc* goompa = script->owner2.npc;
38 f32 sinAngle, cosAngle, liftoffVelocity;
39 Entity* entity;
40
41 if (isInitialCall) {
42 partner_walking_enable(goompa, 1);
43 mem_clear(N(TweesterPhysicsPtr), sizeof(TweesterPhysics));
45 }
46
47 playerData->partnerUsedTime[PARTNER_GOOMPA]++;
49
50 if (entity == NULL) {
53 return ApiStatus_BLOCK;
54 }
55
56 switch (N(TweesterPhysicsPtr)->state) {
58 N(TweesterPhysicsPtr)->state++;
59 N(TweesterPhysicsPtr)->prevFlags = goompa->flags;
60 N(TweesterPhysicsPtr)->radius = fabsf(dist2D(goompa->pos.x, goompa->pos.z,
61 entity->pos.x, entity->pos.z));
62 N(TweesterPhysicsPtr)->angle = atan2(entity->pos.x, entity->pos.z, goompa->pos.x, goompa->pos.z);
63 N(TweesterPhysicsPtr)->angularVel = 6.0f;
64 N(TweesterPhysicsPtr)->liftoffVelPhase = 50.0f;
65 N(TweesterPhysicsPtr)->countdown = 120;
67 goompa->flags &= ~NPC_FLAG_GRAVITY;
69 sin_cos_rad(DEG_TO_RAD(N(TweesterPhysicsPtr)->angle), &sinAngle, &cosAngle);
70 goompa->pos.x = entity->pos.x + (sinAngle * N(TweesterPhysicsPtr)->radius);
71 goompa->pos.z = entity->pos.z - (cosAngle * N(TweesterPhysicsPtr)->radius);
72 N(TweesterPhysicsPtr)->angle = clamp_angle(N(TweesterPhysicsPtr)->angle - N(TweesterPhysicsPtr)->angularVel);
73
74 if (N(TweesterPhysicsPtr)->radius > 20.0f) {
75 N(TweesterPhysicsPtr)->radius--;
76 } else if (N(TweesterPhysicsPtr)->radius < 19.0f) {
77 N(TweesterPhysicsPtr)->radius++;
78 }
79
80 liftoffVelocity = sin_rad(DEG_TO_RAD(N(TweesterPhysicsPtr)->liftoffVelPhase)) * 3.0f;
81 N(TweesterPhysicsPtr)->liftoffVelPhase += 3.0f;
82
83 if (N(TweesterPhysicsPtr)->liftoffVelPhase > 150.0f) {
84 N(TweesterPhysicsPtr)->liftoffVelPhase = 150.0f;
85 }
86
87 goompa->pos.y += liftoffVelocity;
88 goompa->renderYaw = clamp_angle(360.0f - N(TweesterPhysicsPtr)->angle);
89 N(TweesterPhysicsPtr)->angularVel += 0.8;
90
91 if (N(TweesterPhysicsPtr)->angularVel > 40.0f) {
92 N(TweesterPhysicsPtr)->angularVel = 40.0f;
93 }
94
95 if (--N(TweesterPhysicsPtr)->countdown == 0) {
96 N(TweesterPhysicsPtr)->state++;
97 }
98 break;
100 goompa->flags = N(TweesterPhysicsPtr)->prevFlags;
101 N(TweesterPhysicsPtr)->countdown = 30;
102 N(TweesterPhysicsPtr)->state++;
103 break;
107
108 if (--N(TweesterPhysicsPtr)->countdown == 0) {
109 N(TweesterPhysicsPtr)->state = TWEESTER_PARTNER_INIT;
111 }
112 break;
113 }
114 return ApiStatus_BLOCK;
115}
116
118 Call(N(Update))
119 Return
120 End
121};
122
123void N(try_cancel_tweester)(Npc* goompa) {
124 if (TweesterTouchingPartner != NULL) {
126 goompa->flags = N(TweesterPhysicsPtr)->prevFlags;
127 N(TweesterPhysicsPtr)->state = TWEESTER_PARTNER_INIT;
129 }
130}
131
132API_CALLABLE(N(UseAbility)) {
133 return ApiStatus_DONE2;
134}
135
137 Call(N(UseAbility))
138 Return
139 End
140};
141
142API_CALLABLE(N(PutAway)) {
143 Npc* goompa = script->owner2.npc;
144
145 if (isInitialCall) {
146 partner_init_put_away(goompa);
147 }
148
149 if (partner_put_away(goompa)) {
150 return ApiStatus_DONE1;
151 } else {
152 return ApiStatus_BLOCK;
153 }
154}
155
157 Call(N(PutAway))
158 Return
159 End
160};
s32 partnerUsedTime[12]
Bytecode EvtScript[]
#define clamp_angle
#define atan2
#define mem_clear
@ TWEESTER_PARTNER_HOLD
Definition enums.h:2477
@ TWEESTER_PARTNER_ATTRACT
Definition enums.h:2476
@ TWEESTER_PARTNER_INIT
Definition enums.h:2475
@ TWEESTER_PARTNER_RELEASE
Definition enums.h:2478
@ PARTNER_GOOMPA
Definition enums.h:2890
@ NPC_FLAG_FLYING
Definition enums.h:3001
@ NPC_FLAG_IGNORE_WORLD_COLLISION
Definition enums.h:3004
@ NPC_FLAG_IGNORE_PLAYER_COLLISION
Definition enums.h:3006
@ 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
f32 fabsf(f32 f)
void partner_walking_update_motion(Npc *partner)
Definition partners.c:1202
void partner_clear_player_tracking(Npc *partner)
Definition partners.c:2436
void partner_walking_update_player_tracking(Npc *partner)
Definition partners.c:1175
f32 dist2D(f32 ax, f32 ay, f32 bx, f32 by)
Definition 43F0.c:670
void partner_walking_enable(Npc *partner, s32 val)
Definition partners.c:1133
f32 sin_rad(f32 x)
Definition 43F0.c:713
void sin_cos_rad(f32 rad, f32 *outSinTheta, f32 *outCosTheta)
Definition 43F0.c:706
s32 partner_init_get_out(Npc *npc)
Definition partners.c:2252
s32 partner_init_put_away(Npc *partner)
Definition partners.c:2178
s32 partner_put_away(Npc *partner)
Definition partners.c:2185
s32 partner_get_out(Npc *partner)
Definition partners.c:2259
#define End
Signals the end of EVT script data. A script missing this will likely crash on load.
Definition macros.h:213
#define BSS
Definition macros.h:7
#define DEG_TO_RAD(deg)
Definition macros.h:134
#define Call(FUNC, ARGS...)
Calls a given C EVT API function with any number of arguments.
Definition macros.h:576
#define Return
Kills the current EVT thread.
Definition macros.h:217
s32 flags
f32 renderYaw
Vec3f pos
Entity * TweesterTouchingPartner
Definition 7B440.c:5
PlayerData gPlayerData
Definition 77480.c:40
EvtScript EVS_WorldGoompa_TakeOut
Definition goompa.c:26
void N init(Npc *partner)
Definition goompa.c:7
EvtScript EVS_WorldGoompa_PutAway
Definition goompa.c:156
EvtScript EVS_WorldGoompa_UseAbility
Definition goompa.c:136
EvtScript EVS_WorldGoompa_Update
Definition goompa.c:117
void N try_cancel_tweester(Npc *goompa)
Definition goompa.c:123