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

Go to the source code of this file.

Macros

#define USE_STATE   functionTemp[0]
 

Enumerations

enum  { DIVE_STATE_NONE = 0 , DIVE_STATE_DELAY = 1 , DIVE_STATE_DIVING = 2 , DIVE_STATE_SURFACING = 3 }
 

Functions

void N get_movement_from_input (f32 *outAngle, f32 *outSpeed)
 
void N test_for_water_level (s32 ignoreFlags, f32 posX, f32 posY, f32 posZ, f32 yaw, f32 radius)
 
void N update_riding_physics (Npc *sushie)
 
HitIDtest_ray_to_wall_center (s32 unused, f32 *x, f32 *y, f32 *z, f32 length, f32 radius, f32 *yaw)
 
void N init (Npc *sushie)
 
void N try_cancel_tweester (Npc *sushie)
 
void N pre_battle (Npc *sushie)
 
void N post_battle (Npc *sushie)
 

Variables

EvtScript EVS_WorldSushie_UseAbility
 
EvtScript EVS_WorldSushie_TakeOut
 
EvtScript EVS_WorldSushie_Update
 
EvtScript EVS_WorldSushie_PutAway
 
EvtScript EVS_WorldSushie_EnterMap
 

Macro Definition Documentation

◆ USE_STATE

#define USE_STATE   functionTemp[0]

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
DIVE_STATE_NONE 
DIVE_STATE_DELAY 
DIVE_STATE_DIVING 
DIVE_STATE_SURFACING 

Definition at line 25 of file sushie.c.

25 {
30};
@ DIVE_STATE_DIVING
Definition sushie.c:28
@ DIVE_STATE_SURFACING
Definition sushie.c:29
@ DIVE_STATE_NONE
Definition sushie.c:26
@ DIVE_STATE_DELAY
Definition sushie.c:27

Function Documentation

◆ get_movement_from_input()

void N get_movement_from_input ( f32 * outAngle,
f32 * outSpeed )

Definition at line 60 of file sushie.c.

60 {
61 f32 moveAngle;
62 f32 moveSpeed;
63 f32 stickY = gPartnerStatus.stickY;
64 f32 stickX = gPartnerStatus.stickX;
65
66 N(InputStickX) = stickX;
67 N(InputStickY) = stickY;
68 moveAngle = clamp_angle(atan2(0.0f, 0.0f, stickX, -stickY) + gCameras[CAM_DEFAULT].curYaw);
69 moveSpeed = 0.0f;
70
71 if (dist2D(0.0f, 0.0f, N(InputStickX), -N(InputStickY)) >= 1.0) {
72 if (SQ(N(InputStickX)) + SQ(N(InputStickY)) > SQ(55)) {
73 if (N(DiveState) != DIVE_STATE_NONE) {
74 moveSpeed = 2.0f;
75 } else {
76 moveSpeed = 4.0f;
77 }
78 } else {
79 moveSpeed = 2.0f;
80 }
81 }
82
83 *outAngle = moveAngle;
84 *outSpeed = moveSpeed;
85}
#define clamp_angle
#define atan2
@ CAM_DEFAULT
Definition enums.h:1800
f32 dist2D(f32 ax, f32 ay, f32 bx, f32 by)
Definition 43F0.c:670
#define SQ(x)
Definition macros.h:166
PartnerStatus gPartnerStatus
Definition partners.c:42
Camera gCameras[4]
Definition cam_main.c:17

Referenced by update_riding_physics().

◆ test_for_water_level()

void N test_for_water_level ( s32 ignoreFlags,
f32 posX,
f32 posY,
f32 posZ,
f32 yaw,
f32 radius )

Definition at line 87 of file sushie.c.

87 {
88 CollisionStatus* collisionStatus = &gCollisionStatus;
89 f32 depth;
90
91 posY += 100.0f;
92 depth = 200.0f;
93
94 if (!npc_raycast_down_around(ignoreFlags, &posX, &posY, &posZ, &depth, yaw, radius)) {
95 collisionStatus->curFloor = NO_COLLIDER;
96 } else {
97 collisionStatus->curFloor = NpcHitQueryColliderID;
98 N(WaterSurfaceY) = posY;
99 }
100}
b32 npc_raycast_down_around(s32, f32 *, f32 *, f32 *, f32 *, f32, f32)
#define NO_COLLIDER
Definition macros.h:156
CollisionStatus gCollisionStatus
Definition 7BB60.c:6
s32 NpcHitQueryColliderID

Referenced by update_riding_physics().

◆ update_riding_physics()

void N update_riding_physics ( Npc * sushie)

Definition at line 102 of file sushie.c.

102 {
103 PlayerStatus* playerStatus = &gPlayerStatus;
104 PartnerStatus* partnerStatus = &gPartnerStatus;
105 CollisionStatus* collisionStatus = &gCollisionStatus;
106 f32 moveSpeedDamping;
107 f32 moveAngle, moveSpeed;
108 f32 sinAngle, cosAngle;
109 f32 x, y, z;
110 f32 depth;
111
112 // PART 1:
113 // determine movement speed and direction from input and inertia
114
115 N(get_movement_from_input)(&moveAngle, &moveSpeed);
116
117 if (N(DiveState) != DIVE_STATE_NONE) {
118 moveSpeedDamping = 80.0f;
119 } else {
120 moveSpeedDamping = 32.0f;
121 }
122
123 if (moveSpeed != 0.0f) {
124 f32 changeDirDamping = 8.0f;
125 f32 sameDirDamping = 32.0f;
126
127 if (N(InputStickX) * N(InertialStickX) > 0.0f) {
128 N(InertialStickX) += N(InputStickX) / sameDirDamping;
129 } else {
130 N(InertialStickX) += N(InputStickX) / changeDirDamping;
131 }
132 if (N(InputStickX) > 0.0f) {
133 if (N(InputStickX) < N(InertialStickX)) {
134 N(InertialStickX) = N(InputStickX);
135 }
136 } else {
137 if (N(InertialStickX) < N(InputStickX)) {
138 N(InertialStickX) = N(InputStickX);
139 }
140 }
141
142 if (N(InputStickY) * N(InertialStickY) > 0.0f) {
143 N(InertialStickY) += N(InputStickY) / sameDirDamping;
144 } else {
145 N(InertialStickY) += N(InputStickY) / changeDirDamping;
146 }
147 if (N(InputStickY) > 0.0f) {
148 if (N(InputStickY) < N(InertialStickY)) {
149 N(InertialStickY) = N(InputStickY);
150 }
151 } else {
152 if (N(InertialStickY) < N(InputStickY)) {
153 N(InertialStickY) = N(InputStickY);
154 }
155 }
156
157 moveAngle = clamp_angle(atan2(0.0f, 0.0f, N(InertialStickX), -N(InertialStickY)) + gCameras[CAM_DEFAULT].curYaw);
158 if (N(InertialMoveSpeed) <= moveSpeed) {
159 N(InertialMoveSpeed) += (moveSpeed - N(InertialMoveSpeed)) / moveSpeedDamping;
160 if (N(InertialMoveSpeed) > moveSpeed) {
161 N(InertialMoveSpeed) = moveSpeed;
162 }
163 } else {
164 N(InertialMoveSpeed) += (moveSpeed - N(InertialMoveSpeed)) / moveSpeedDamping;
165 }
166 moveSpeed = N(InertialMoveSpeed);
167 N(InertialMoveAngle) = moveAngle;
168 sin_cos_rad(DEG_TO_RAD(moveAngle), &sinAngle, &cosAngle);
169 N(UnusedMoveX) += ( moveSpeed * sinAngle) / moveSpeedDamping;
170 N(UnusedMoveZ) += (-moveSpeed * cosAngle) / moveSpeedDamping;
171 } else {
172 N(InertialMoveSpeed) -= 0.15;
173 if (N(InertialMoveSpeed) < 0.0f) {
174 N(InertialMoveSpeed) = 0.0f;
175 N(InertialStickY) = 0.0f;
176 N(InertialStickX) = 0.0f;
177 }
178 moveSpeed = N(InertialMoveSpeed);
179 moveAngle = N(InertialMoveAngle);
180 sin_cos_rad(DEG_TO_RAD(N(InertialMoveAngle)), &sinAngle, &cosAngle);
181 N(UnusedMoveX) = moveSpeed * sinAngle;
182 N(UnusedMoveZ) = -moveSpeed * cosAngle;
183 }
184
185 // PART 2:
186 // apply movement speed and direction to sushie
187
188 sushie->moveSpeed = moveSpeed;
189 if (moveSpeed != 0.0f) {
190 sushie->yaw = moveAngle;
191 x = sushie->pos.x;
192 z = sushie->pos.z;
193 y = sushie->moveToPos.y + -6.0f;
194 depth = (sushie->collisionHeight * 0.5f) + (playerStatus->colliderHeight * 0.8f);
196 sushie->moveSpeed, moveAngle, depth, sushie->collisionDiameter))
197 {
198 collisionStatus->pushingAgainstWall = NpcHitQueryColliderID;
200 N(TouchDockTime)++;
201 } else {
202 N(TouchDockTime) = 0;
203 }
204 sushie->pos.x += (x - sushie->pos.x) * 0.5f;
205 sushie->pos.z += (z - sushie->pos.z) * 0.5f;
206 } else {
207 npc_move_heading(sushie, moveSpeed, moveAngle);
208 collisionStatus->pushingAgainstWall = NO_COLLIDER;
209 }
210 moveSpeed = 2.0f;
211 moveAngle = clamp_angle(sushie->yaw - 30.0f);
212 x = sushie->pos.x;
213 z = sushie->pos.z;
214 y = sushie->moveToPos.y + -6.0f;
215 depth = (sushie->collisionHeight * 0.5f) + (playerStatus->colliderHeight * 0.8f);
217 moveSpeed, moveAngle, depth, sushie->collisionDiameter))
218 {
219 sushie->pos.x += (x - sushie->pos.x) / 5.0f;
220 sushie->pos.z += (z - sushie->pos.z) / 5.0f;
221 }
222 moveAngle = clamp_angle(sushie->yaw + 30.0f);
223 x = sushie->pos.x;
224 z = sushie->pos.z;
225 y = sushie->moveToPos.y + -6.0f;
226 depth = (sushie->collisionHeight * 0.5f) + (playerStatus->colliderHeight * 0.8f);
228 moveSpeed, moveAngle, depth, sushie->collisionDiameter))
229 {
230 sushie->pos.x += (x - sushie->pos.x) / 5.0f;
231 sushie->pos.z += (z - sushie->pos.z) / 5.0f;
232 }
233 }
234
235 // PART 3:
236 // update diving state
237
238 if (N(DiveState) == DIVE_STATE_NONE) {
239 N(test_for_water_level)(sushie->collisionChannel, sushie->pos.x, sushie->pos.y, sushie->pos.z,
240 sushie->yaw, sushie->collisionDiameter * 0.5f);
241 if (N(DiveState) == DIVE_STATE_NONE) {
242 sushie->moveSpeed = 3.0f;
243 sushie->moveToPos.y = N(WaterSurfaceY) - (sushie->collisionHeight * 0.5f);
244 N(DiveTime) = 0;
245 if (partnerStatus->pressedButtons & BUTTON_C_DOWN) {
246 N(DiveState) = DIVE_STATE_DELAY;
247 sushie->moveSpeed = 2.0f;
248 } else {
249 return;
250 }
251 }
252 }
253 if (N(DiveState) == DIVE_STATE_DELAY) {
254 if ((partnerStatus->curButtons & BUTTON_C_DOWN) && N(DiveTime) == 0) {
255 N(DiveState) = DIVE_STATE_DIVING;
256 }
257 }
258 N(DiveTime)++;
259 if (N(DiveState) == DIVE_STATE_DIVING) {
260 x = sushie->pos.x;
261 y = sushie->pos.y;
262 z = sushie->pos.z;
263 depth = sushie->collisionHeight;
264 if (npc_raycast_down_around(sushie->collisionChannel, &x, &y, &z, &depth, sushie->yaw, sushie->collisionDiameter)) {
265 moveSpeedDamping = ((N(WaterSurfaceY) - (playerStatus->colliderHeight * 2)) - sushie->moveToPos.y) * 0.1f;
266 sushie->moveToPos.y += moveSpeedDamping;
267 if (sushie->moveToPos.y < y + 5.0f) {
268 sushie->moveToPos.y = y + 5.0f;
269 }
270 } else {
271 moveSpeedDamping = ((N(WaterSurfaceY) - (playerStatus->colliderHeight * 2)) - sushie->moveToPos.y) * 0.1f;
272 sushie->moveToPos.y += moveSpeedDamping;
273 }
274 if (N(DiveTime) % 6 == 0) {
275 fx_rising_bubble(0, sushie->pos.x, sushie->moveToPos.y + (sushie->collisionHeight * 0.5f), sushie->pos.z,
276 (N(WaterSurfaceY) - sushie->moveToPos.y) - (sushie->collisionHeight * 0.5f));
277 }
278 if (N(DiveTime) == 1) {
279 suggest_player_anim_always_forward(ANIM_MarioW2_DiveSushie);
280 sushie->curAnim = ANIM_WorldSushie_Ride;
281 }
282 if (!N(IsUnderwater) && (playerStatus->pos.y + (playerStatus->colliderHeight * 0.5f) < N(WaterSurfaceY))) {
283 N(IsUnderwater) = TRUE;
284 playerStatus->renderMode = RENDER_MODE_ALPHATEST;
285 set_player_imgfx_all(playerStatus->trueAnimation, IMGFX_SET_WAVY, 2, 0, 0, 0, 0);
286 npc_set_imgfx_params(sushie, IMGFX_SET_WAVY, 2, 0, 0, 0, 0);
287 }
288 if (N(DiveTime) >= 10) {
289 if (!(partnerStatus->curButtons & BUTTON_C_DOWN) || N(DiveTime) >= 30) {
290 sushie->curAnim = ANIM_WorldSushie_Rise;
292 N(DiveState) = DIVE_STATE_SURFACING;
293 }
294 }
295 }
296
297 x = sushie->pos.x;
298 y = sushie->moveToPos.y;
299 z = sushie->pos.z;
300 depth = (sushie->collisionHeight * 0.5f) + playerStatus->colliderHeight;
301 if (npc_raycast_up_corners(sushie->collisionChannel, &x, &y, &z, &depth, sushie->yaw, sushie->collisionDiameter * 0.3f) > NO_COLLIDER) {
302#if VERSION_JP
303 sushie->moveToPos.y = y;
304#else
305 sushie->moveToPos.y += (((sushie->moveToPos.y - y) + depth) - ((sushie->collisionHeight * 0.5f) + playerStatus->colliderHeight)) * 0.2f;
306#endif
307 if (N(DiveTime) % 9 == 0) {
308 fx_rising_bubble(0, sushie->pos.x, sushie->moveToPos.y + (sushie->collisionHeight * 0.5f), sushie->pos.z,
309 (N(WaterSurfaceY) - sushie->moveToPos.y) - (sushie->collisionHeight * 0.5f));
310 }
311 } else if (N(DiveState) == DIVE_STATE_SURFACING) {
312 N(ResurfaceVelY) += 0.14;
313 if (N(ResurfaceVelY) > 1.8) {
314 N(ResurfaceVelY) = 1.8f;
315 }
316 sushie->moveToPos.y += N(ResurfaceVelY);
317 if (N(DiveTime) % 9 == 0) {
318 fx_rising_bubble(0, sushie->pos.x, sushie->moveToPos.y + sushie->collisionHeight * 0.5f, sushie->pos.z,
319 (N(WaterSurfaceY) - sushie->moveToPos.y) - sushie->collisionHeight * 0.5f);
320 }
321 if ((N(WaterSurfaceY) - sushie->moveToPos.y) - (sushie->collisionHeight * 0.5f) <= 0.0f) {
322 if (N(IsUnderwater)) {
323 N(IsUnderwater) = FALSE;
324 set_player_imgfx_all(ANIM_Mario1_Idle, IMGFX_CLEAR, 0, 0, 0, 0, 0);
325 npc_set_imgfx_params(sushie, IMGFX_CLEAR, 0, 0, 0, 0, 0);
326 }
327 N(DiveState) = DIVE_STATE_NONE;
328 sushie->curAnim = ANIM_WorldSushie_Ride;
329 sushie->moveToPos.y = N(WaterSurfaceY) - (sushie->collisionHeight * 0.5f);
330 suggest_player_anim_always_forward(ANIM_MarioW2_RideSushie);
331 }
332 }
333}
AnimID trueAnimation
Encoding back-facing sprite.
@ BUTTON_C_DOWN
Definition enums.h:2779
@ IMGFX_CLEAR
Definition enums.h:5117
@ IMGFX_SET_WAVY
Definition enums.h:5121
@ SURFACE_TYPE_DOCK_WALL
Definition enums.h:4674
@ COLLIDER_FLAGS_SURFACE_TYPE_MASK
Definition enums.h:4693
@ SOUND_ID_TRIGGER_CHANGE_SOUND
Definition enums.h:532
@ NPC_PARTNER
Definition enums.h:2528
@ SOUND_SUSHIE_DIVE
Definition enums.h:1011
@ RENDER_MODE_ALPHATEST
Definition enums.h:3276
@ SOUND_SPACE_DEFAULT
Definition enums.h:1737
void suggest_player_anim_always_forward(AnimID anim)
Definition 77480.c:913
s32 get_collider_flags(s32 colliderID)
Definition collision.c:481
HitID npc_raycast_up_corners(s32 ignoreFlags, f32 *posX, f32 *posY, f32 *posZ, f32 *hitDepth, f32 yaw, f32 radius)
b32 npc_test_move_taller_with_slipping(s32, f32 *, f32 *, f32 *, f32, f32, f32, f32)
void sin_cos_rad(f32 rad, f32 *outSinTheta, f32 *outCosTheta)
Definition 43F0.c:706
void npc_set_imgfx_params(Npc *npc, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6)
Definition npc.c:2162
void npc_move_heading(Npc *npc, f32 speed, f32 yaw)
Definition npc.c:986
void sfx_play_sound_at_npc(s32 soundID, s32 arg1, s32 npcID)
Definition sfx.c:527
#define DEG_TO_RAD(deg)
Definition macros.h:134
void set_player_imgfx_all(s32 animID, ImgFXType imgfxType, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6)
Definition sprite.c:995
s16 collisionDiameter
AnimID curAnim
Vec3f moveToPos
s32 collisionChannel
s16 collisionHeight
Vec3f pos
f32 moveSpeed
PlayerStatus gPlayerStatus
Definition 77480.c:39
void N test_for_water_level(s32 ignoreFlags, f32 posX, f32 posY, f32 posZ, f32 yaw, f32 radius)
Definition sushie.c:87
void N get_movement_from_input(f32 *outAngle, f32 *outSpeed)
Definition sushie.c:60

◆ test_ray_to_wall_center()

HitID N test_ray_to_wall_center ( s32 unused,
f32 * x,
f32 * y,
f32 * z,
f32 length,
f32 radius,
f32 * yaw )

Definition at line 335 of file sushie.c.

335 {
336 f32 sinAngle, cosAngle, totalLength;
337 f32 hitX, hitY, hitZ;
338 f32 hitNx, hitNy, hitNz;
339 s32 hitID;
340
341 sin_cos_rad(DEG_TO_RAD(*yaw), &sinAngle, &cosAngle);
342 cosAngle = -cosAngle;
343 totalLength = radius + length;
344 hitID = test_ray_colliders(COLLIDER_FLAG_IGNORE_PLAYER, *x, *y, *z, sinAngle, 0.0f, cosAngle,
345 &hitX, &hitY, &hitZ, &totalLength, &hitNx, &hitNy, &hitNz);
346
347 if (hitID > NO_COLLIDER) {
348 *yaw = atan2(0.0f, 0.0f, hitNx, hitNz);
349 }
350
351 return hitID;
352}
@ COLLIDER_FLAG_IGNORE_PLAYER
Definition enums.h:4696
s32 test_ray_colliders(s32 ignoreFlags, f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 dirZ, f32 *hitX, f32 *hitY, f32 *hitZ, f32 *hitDepth, f32 *hitNx, f32 *hitNy, f32 *hitNz)
Definition collision.c:768

◆ init()

void N init ( Npc * sushie)

Definition at line 746 of file sushie.c.

746 {
747 sushie->collisionHeight = 24;
748 sushie->collisionDiameter = 36;
750 N(IsRiding) = FALSE;
751 N(DiveState) = DIVE_STATE_NONE;
752 N(DiveTime) = 0;
753 N(TouchDockTime) = 0;
754 N(IsUnderwater) = FALSE;
755}

◆ try_cancel_tweester()

void N try_cancel_tweester ( Npc * sushie)

Definition at line 866 of file sushie.c.

866 {
867 if (TweesterTouchingPartner != NULL) {
869 sushie->flags = N(TweesterPhysicsPtr)->prevFlags;
870 N(TweesterPhysicsPtr)->state = TWEESTER_PARTNER_INIT;
872 }
873}
@ TWEESTER_PARTNER_INIT
Definition enums.h:2475
void partner_clear_player_tracking(Npc *partner)
Definition partners.c:2436
s32 flags
Entity * TweesterTouchingPartner
Definition 7B440.c:5

◆ pre_battle()

void N pre_battle ( Npc * sushie)

Definition at line 892 of file sushie.c.

892 {
893 PartnerStatus* partnerStatus = &gPartnerStatus;
894
895 if (N(IsRiding)) {
896 partnerStatus->npc = *sushie;
897 partnerStatus->shouldResumeAbility = TRUE;
902 }
903
904 partnerStatus->actingPartner = PARTNER_SUSHIE;
905}
@ PARTNER_SUSHIE
Definition enums.h:2892
@ ACTION_STATE_IDLE
Definition enums.h:2426
s32 enable_player_input(void)
Definition 77480.c:998
void set_action_state(s32 actionState)
Definition 7E9D0.c:209
s32 enable_player_static_collisions(void)
Definition 77480.c:980

◆ post_battle()

void N post_battle ( Npc * sushie)

Definition at line 907 of file sushie.c.

907 {
908 PartnerStatus* partnerStatus = &gPartnerStatus;
909
910 if (partnerStatus->shouldResumeAbility) {
911 *sushie = partnerStatus->npc;
913 }
914}
s32 partner_use_ability(void)
Definition partners.c:964

Variable Documentation

◆ EVS_WorldSushie_UseAbility

EvtScript EVS_WorldSushie_UseAbility
Initial value:
= {
Call(N(UseAbility))
}
#define End
Signals the end of EVT script data. A script missing this will likely crash on load.
Definition macros.h:213
#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

Definition at line 740 of file sushie.c.

740 {
741 Call(N(UseAbility))
742 Return
743 End
744};

◆ EVS_WorldSushie_TakeOut

EvtScript EVS_WorldSushie_TakeOut
Initial value:
= {
Call(N(TakeOut))
}

Definition at line 771 of file sushie.c.

771 {
772 Call(N(TakeOut))
773 Return
774 End
775};

◆ EVS_WorldSushie_Update

EvtScript EVS_WorldSushie_Update
Initial value:
= {
Call(N(Update))
}

Definition at line 860 of file sushie.c.

860 {
861 Call(N(Update))
862 Return
863 End
864};

◆ EVS_WorldSushie_PutAway

EvtScript EVS_WorldSushie_PutAway
Initial value:
= {
Call(N(PutAway))
}

Definition at line 886 of file sushie.c.

886 {
887 Call(N(PutAway))
888 Return
889 End
890};

◆ EVS_WorldSushie_EnterMap

EvtScript EVS_WorldSushie_EnterMap
Initial value:
= {
Call(N(EnterMap))
}

Definition at line 985 of file sushie.c.

985 {
986 Call(N(EnterMap))
987 Return
988 End
989};