Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
hit_lava.c
Go to the documentation of this file.
1#include "common.h"
2#include "effects.h"
3#include "sprite/player.h"
4
5enum {
17};
18
20 PlayerStatus* playerStatus = &gPlayerStatus;
21 f32 resetPosX, resetPosY, resetPosZ;
22 f32 returnRadians;
23 f32 dx, dy;
24 f32 componentSpeed;
25 s32 completeAxes; // number of axes along which the 'return motion' is complete
26
27 static f32 LaunchVelocity;
28 static f32 LaunchInterpPhase; // used to interp launch velocity
29 static f32 ReturnAngle;
30 static f32 InitialPosY;
31
32 if (playerStatus->flags & PS_FLAG_ACTION_STATE_CHANGED) {
33 playerStatus->flags &= ~PS_FLAG_ACTION_STATE_CHANGED;
34 playerStatus->flags |= (PS_FLAG_SCRIPTED_FALL | PS_FLAG_FLYING);
36 playerStatus->flags |= PS_FLAG_HIT_FIRE;
37 if (playerStatus->hazardType == HAZARD_TYPE_LAVA) {
39 playerStatus->curStateTime = 2;
40 } else {
41 playerStatus->actionSubstate = SUBSTATE_INIT;
42 }
43 InitialPosY = playerStatus->pos.y;
44 playerStatus->curSpeed = 0.0f;
45 LaunchVelocity = 0.0f;
46
48 LaunchInterpPhase = 90.0f;
49 subtract_hp(1);
53 }
54
55 switch (playerStatus->actionSubstate) {
57 if (--playerStatus->curStateTime == -1) {
58 playerStatus->actionSubstate = SUBSTATE_INIT;
59 }
60 break;
62 if (--playerStatus->curStateTime == -1) {
63 playerStatus->actionSubstate = SUBSTATE_INIT;
64 }
65 playerStatus->pos.y -= 4.0f;
66 break;
67 case SUBSTATE_INIT:
68 if (playerStatus->hazardType == HAZARD_TYPE_LAVA) {
69 fx_smoke_burst(0, playerStatus->pos.x, playerStatus->pos.y, playerStatus->pos.z, 1.0f, 40);
70 }
71 suggest_player_anim_always_forward(ANIM_MarioW2_TouchedLava);
72 playerStatus->gravityIntegrator[1] = 0.0f;
73 playerStatus->timeInAir = 0;
74 playerStatus->peakJumpTime = 0;
75 playerStatus->actionSubstate = SUBSTATE_LAUNCH;
76 playerStatus->curStateTime = 1;
77 playerStatus->gravityIntegrator[0] = 20.0f;
78 playerStatus->gravityIntegrator[2] = 250.0f;
79 playerStatus->gravityIntegrator[3] = InitialPosY;
80 playerStatus->jumpFromPos.x = playerStatus->pos.x;
81 playerStatus->jumpFromPos.z = playerStatus->pos.z;
82 playerStatus->jumpFromHeight = playerStatus->pos.y;
83 playerStatus->flags |= PS_FLAG_JUMPING;
84 break;
86 if (--playerStatus->curStateTime <= 0) {
87 playerStatus->actionSubstate++;
88 }
89 break;
90 case SUBSTATE_LAUNCH:
91 if (playerStatus->hazardType == HAZARD_TYPE_LAVA && (playerStatus->timeInAir % 2) == 0) {
92 fx_smoke_burst(0, playerStatus->pos.x, playerStatus->pos.y, playerStatus->pos.z, 0.7f, 18);
93 }
94 if (playerStatus->pos.y < playerStatus->gravityIntegrator[3] + playerStatus->gravityIntegrator[2]) {
95 sin_cos_rad(DEG_TO_RAD(LaunchInterpPhase), &dx, &dy);
96 LaunchVelocity = sin_rad(DEG_TO_RAD(LaunchInterpPhase)) * 16.0f;
97 if (LaunchVelocity < -1.0f) {
98 LaunchVelocity = -1.0f;
99 }
100 playerStatus->pos.y += LaunchVelocity;
101 LaunchInterpPhase += 3.0f;
102 if (LaunchInterpPhase > 180.0f) {
103 LaunchInterpPhase = 180.0f;
104 playerStatus->actionSubstate++;
105 }
106 } else {
107 playerStatus->pos.y = playerStatus->gravityIntegrator[3] + playerStatus->gravityIntegrator[2];
108 playerStatus->actionSubstate++;
109 }
110 break;
112 if (playerStatus->hazardType == HAZARD_TYPE_LAVA && (playerStatus->timeInAir % 2) == 0) {
113 fx_smoke_burst(0, playerStatus->pos.x, playerStatus->pos.y, playerStatus->pos.z, 0.7f, 18);
114 }
115 if (get_lava_reset_pos(&resetPosX, &resetPosY, &resetPosZ) == 0) {
116 resetPosX = playerStatus->pos.x;
117 resetPosZ = playerStatus->pos.z;
118 }
119 playerStatus->lastGoodPos.x = resetPosX;
120 playerStatus->lastGoodPos.z = resetPosZ;
121 playerStatus->jumpApexHeight = playerStatus->pos.y;
123 playerStatus->actionSubstate++;
124 break;
126 ReturnAngle = atan2(playerStatus->pos.x, playerStatus->pos.z, playerStatus->lastGoodPos.x, playerStatus->lastGoodPos.z);
127 playerStatus->curSpeed = get_xz_dist_to_player(playerStatus->lastGoodPos.x, playerStatus->lastGoodPos.z) / 18.0f;
128 playerStatus->actionSubstate++;
129 break;
131 ReturnAngle = atan2(playerStatus->pos.x, playerStatus->pos.z, playerStatus->lastGoodPos.x, playerStatus->lastGoodPos.z);
132 returnRadians = DEG_TO_RAD(ReturnAngle);
133 // update motion along x axis
134 componentSpeed = playerStatus->curSpeed * sin_rad(returnRadians);
135 playerStatus->pos.x += componentSpeed;
136 completeAxes = 0;
137 if (componentSpeed >= 0.0f) {
138 if (playerStatus->lastGoodPos.x <= playerStatus->pos.x) {
139 playerStatus->pos.x = playerStatus->lastGoodPos.x;
140 completeAxes++;
141 }
142 } else {
143 if (playerStatus->pos.x <= playerStatus->lastGoodPos.x) {
144 playerStatus->pos.x = playerStatus->lastGoodPos.x;
145 completeAxes++;
146 }
147 }
148 // update motion along z axis
149 componentSpeed = playerStatus->curSpeed * cos_rad(returnRadians);
150 playerStatus->pos.z -= componentSpeed;
151 if (componentSpeed >= 0.0f) {
152 if (playerStatus->pos.z <= playerStatus->lastGoodPos.z) {
153 playerStatus->pos.z = playerStatus->lastGoodPos.z;
154 completeAxes++;
155 }
156 } else {
157 if (playerStatus->lastGoodPos.z <= playerStatus->pos.z) {
158 playerStatus->pos.z = playerStatus->lastGoodPos.z;
159 completeAxes++;
160 }
161 }
162 // if both axes are done, continue to next substate
163 if (completeAxes == 2) {
164 playerStatus->actionSubstate++;
165 }
166 break;
167 case SUBSTATE_HOVER:
168 if (playerStatus->hazardType == HAZARD_TYPE_LAVA && (playerStatus->timeInAir % 2) == 0) {
169 fx_smoke_burst(0, playerStatus->pos.x, playerStatus->pos.y, playerStatus->pos.z, 0.7f, 18);
170 }
171 playerStatus->pos.y = player_check_collision_below(player_fall_distance(), &completeAxes);
172 if (completeAxes >= 0) {
174 start_rumble(256, 50);
176 gCameras[CAM_DEFAULT].moveFlags &= ~CAMERA_MOVE_NO_INTERP_Y;
178 suggest_player_anim_always_forward(ANIM_MarioW2_Thrown);
179 playerStatus->flags &= ~PS_FLAG_HIT_FIRE;
180 playerStatus->flags &= ~PS_FLAG_FLYING;
181 playerStatus->hazardType = HAZARD_TYPE_NONE;
182 playerStatus->gravityIntegrator[0] = 6.0f;
183 playerStatus->pos.y += 6.0f;
184 playerStatus->actionSubstate++;
185 }
186 break;
187 case SUBSTATE_BOUNCE:
188 playerStatus->gravityIntegrator[0] -= 1.0;
189 playerStatus->pos.y = player_check_collision_below(playerStatus->gravityIntegrator[0], &completeAxes);
190 if (completeAxes >= 0) {
191 playerStatus->curStateTime = 10;
192 playerStatus->actionSubstate++;
193 }
194 break;
196 if (--playerStatus->curStateTime <= 0) {
198 playerStatus->flags &= ~PS_FLAG_SCRIPTED_FALL;
199 gOverrideFlags &= ~GLOBAL_OVERRIDES_40;
200 }
201 break;
202 }
203 if (playerStatus->actionSubstate < SUBSTATE_BOUNCE) {
204 playerStatus->timeInAir++;
205 }
206}
f32 gravityIntegrator[4]
#define atan2
@ CAM_SHAKE_DECAYING_VERTICAL
Definition enums.h:1809
@ PS_FLAG_JUMPING
Definition enums.h:3035
@ PS_FLAG_ACTION_STATE_CHANGED
Definition enums.h:3084
@ PS_FLAG_FLYING
Definition enums.h:3037
@ PS_FLAG_SCRIPTED_FALL
Definition enums.h:3071
@ PS_FLAG_HIT_FIRE
Definition enums.h:3050
@ HAZARD_TYPE_LAVA
Definition enums.h:3500
@ HAZARD_TYPE_NONE
Definition enums.h:3499
@ PA_FLAG_INTERRUPT_USE_PARTNER
forces actions with bow, parakarry, watt, and lakilester to end (sushie not tested)
Definition enums.h:3093
@ SOUND_PLAYER_COLLAPSE
Definition enums.h:1312
@ SOUND_TOUCH_LAVA
Definition enums.h:723
@ ACTION_STATE_LAND
Definition enums.h:2437
@ CAMERA_MOVE_IGNORE_PLAYER_Y
Definition enums.h:4732
@ CAMERA_MOVE_NO_INTERP_Y
Definition enums.h:4733
@ SOUND_SPACE_DEFAULT
Definition enums.h:1737
@ GLOBAL_OVERRIDES_40
Definition enums.h:4325
@ CAM_DEFAULT
Definition enums.h:1800
void start_rumble(s32, s32)
Definition rumble.c:15
s32 get_lava_reset_pos(f32 *x, f32 *y, f32 *z)
Definition map_api.c:597
void suggest_player_anim_always_forward(AnimID anim)
Definition 77480.c:913
f32 player_check_collision_below(f32, s32 *colliderID)
Definition 7BB60.c:470
f32 cos_rad(f32 x)
Definition 43F0.c:717
s32 phys_adjust_cam_on_landing(void)
Definition 7E9D0.c:46
void set_action_state(s32 actionState)
Definition 7E9D0.c:209
void subtract_hp(s32 amt)
Definition inventory.c:2192
void exec_ShakeCamX(s32 arg0, s32 arg1, s32 arg2, f32 arg3)
Definition cam_api.c:374
f32 sin_rad(f32 x)
Definition 43F0.c:713
void sin_cos_rad(f32 rad, f32 *outSinTheta, f32 *outCosTheta)
Definition 43F0.c:706
f32 get_xz_dist_to_player(f32, f32)
Definition 77480.c:960
void open_status_bar_slowly(void)
Definition inventory.c:1420
f32 player_fall_distance(void)
Definition 7BB60.c:461
void action_update_hit_lava(void)
Definition hit_lava.c:19
@ SUBSTATE_END_LAUNCH
Definition hit_lava.c:9
@ SUBSTATE_HOVER
Definition hit_lava.c:12
@ SUBSTATE_DELAY_INIT
Definition hit_lava.c:16
@ SUBSTATE_INIT
Definition hit_lava.c:6
@ SUBSTATE_DELAY_INIT_SINK
Definition hit_lava.c:15
@ SUBSTATE_BOUNCE
Definition hit_lava.c:13
@ SUBSTATE_RETURN_INIT
Definition hit_lava.c:10
@ SUBSTATE_DELAY_DONE
Definition hit_lava.c:14
@ SUBSTATE_LAUNCH
Definition hit_lava.c:8
@ SUBSTATE_DELAY_LAUNCH
Definition hit_lava.c:7
@ SUBSTATE_RETURN_MOTION
Definition hit_lava.c:11
void sfx_play_sound_at_player(s32 soundID, s32 arg1)
Definition sfx.c:521
#define DEG_TO_RAD(deg)
Definition macros.h:134
#define LOAD_INTEGRATOR_FALL(ptr)
Definition macros.h:186
s32 gOverrideFlags
Definition main_loop.c:11
Camera gCameras[4]
Definition cam_main.c:17
PlayerStatus gPlayerStatus
Definition 77480.c:39