Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
player_turn_end.c
Go to the documentation of this file.
1#include "states.h"
2#include "script_api/battle.h"
3
4enum {
5 // BTL_SUBSTATE_INIT = 0,
9};
10
13 Actor* player = battleStatus->playerActor;
14 Evt* script;
15
17 s32 hpRecovery = 0;
18 s32 fpRecovery = 0;
19
20 if (battleStatus->moveCategory == BTL_MENU_TYPE_ITEMS && battleStatus->itemUsesLeft >= 2) {
21 return;
22 }
23
24 if (player->stoneStatus == STATUS_KEY_STONE || battleStatus->outtaSightActive) {
25 return;
26 }
27
29 drainRecovery = battleStatus->hpDrainCount;
30 battleStatus->hpDrainCount = 0;
31 }
33
34 if (rand_int(100) < 50) {
36 }
37 if (rand_int(100) < 50) {
39 }
40 if (rand_int(100) < 50) {
42 }
43 if (drainRecovery + hpRecovery + fpRecovery == 0) {
44 return;
45 }
46
47 battleStatus->battlePhase = PHASE_PLAYER_HAPPY;
49 player->takeTurnScript = script;
50 player->takeTurnScriptID = script->id;
51 script->owner1.actorID = ACTOR_PLAYER;
52
53 script->varTable[10] = drainRecovery;
54 script->varTable[11] = hpRecovery;
55 script->varTable[12] = fpRecovery;
56
57 if (script->varTable[10] > 99) {
58 script->varTable[10] = 99;
59 }
60 if (script->varTable[11] > 99) {
61 script->varTable[11] = 99;
62 }
63 if (script->varTable[12] > 99) {
64 script->varTable[12] = 99;
65 }
66}
67
70 Actor* player = battleStatus->playerActor;
71 Actor* partner = battleStatus->partnerActor;
72 Evt* script;
73
77 }
78
80 // if a script is running from 'Happy!', wait for it to complete
81 if (player->takeTurnScript != NULL && does_script_exist(player->takeTurnScriptID)) {
82 return;
83 }
84 player->takeTurnScript = NULL;
85
86 // force peach to back position after turn end
88 player->state.curPos.x = player->homePos.x;
89 player->state.curPos.z = player->homePos.z;
90 player->state.goalPos.x = partner->homePos.x;
91 player->state.goalPos.z = partner->homePos.z;
92 player->state.moveTime = 4;
93 player->state.angle = 0.0f;
95 } else {
97 }
98 }
99
101 if (player->state.moveTime != 0) {
102 player->curPos.x += (player->state.goalPos.x - player->curPos.x) / player->state.moveTime;
103 player->curPos.z += (player->state.goalPos.z - player->curPos.z) / player->state.moveTime;
104 partner->curPos.x += (player->state.curPos.x - partner->curPos.x) / player->state.moveTime;
105 partner->curPos.z += (player->state.curPos.z - partner->curPos.z) / player->state.moveTime;
106 }
107 player->curPos.z += sin_rad(DEG_TO_RAD(player->state.angle)) * 16.0f;
108 player->yaw = clamp_angle(-player->state.angle);
109 partner->curPos.z -= sin_rad(DEG_TO_RAD(player->state.angle)) * 16.0f;
110 partner->yaw = clamp_angle(-player->state.angle);
111 player->state.angle += 90.0f;
112
113 if (player->state.moveTime != 0) {
114 player->state.moveTime--;
115 } else {
116 player->curPos.x = player->state.goalPos.x;
117 player->curPos.z = player->state.goalPos.z;
118 partner->curPos.x = player->state.curPos.x;
119 partner->curPos.z = player->state.curPos.z;
120 player->homePos.x = player->curPos.x;
121 player->homePos.z = player->curPos.z;
122 partner->homePos.x = partner->curPos.x;
123 partner->homePos.z = partner->curPos.z;
126 }
127 }
128
130 // dont bother with command loss if all enemies are defeated
132 return;
133 }
134
135 if (battleStatus->moveCategory == BTL_MENU_TYPE_ITEMS && battleStatus->itemUsesLeft >= 2) {
137 btl_cam_move(10);
139 } else {
141 }
142
143 // if the rest of the turn was canceled, proceed immediately to END_TURN
144 if (battleStatus->cancelTurnMode < 0) {
145 battleStatus->cancelTurnMode = 0;
146 battleStatus->itemUsesLeft = 0;
148 return;
149 }
150
151 if (battleStatus->itemUsesLeft != 0) {
152 battleStatus->itemUsesLeft--;
153 if (battleStatus->itemUsesLeft != 0) {
154 // double or triple dip has not run out yet, let the player choose another item
157 return;
158 }
159
161 if (battleStatus->hustleTurns != 0) {
162 battleStatus->hustleTurns--;
163 }
164 }
165
166 if (battleStatus->hustleTurns != 0 && (gBattleStatus.flags1 & BS_FLAGS1_HUSTLED)) {
169 return;
170 } else {
173 return;
174 }
175 }
176
178 if (battleStatus->hustleTurns != 0) {
179 battleStatus->hustleTurns--;
180 }
181 }
182
183 if (battleStatus->hustleTurns != 0 && (gBattleStatus.flags1 & BS_FLAGS1_HUSTLED)) {
186 } else {
190 } else {
192 }
193 }
194 }
195}
196
BSS s32 PopupMenu_SelectedIndex
struct Evt * takeTurnScript
ActorState state
s32 takeTurnScriptID
Vec3f homePos
Vec3f curPos
#define rand_int
#define clamp_angle
@ BS_FLAGS1_PLAYER_IN_BACK
Definition enums.h:3622
@ BS_FLAGS1_HUSTLED
Definition enums.h:3628
@ PHASE_PLAYER_HAPPY
Definition enums.h:2106
@ BTL_MENU_TYPE_ITEMS
Definition enums.h:3828
@ BS_FLAGS2_PLAYER_TURN_USED
Definition enums.h:3638
@ BS_FLAGS2_HAS_DRAINED_HP
Definition enums.h:3653
@ BS_FLAGS2_PEACH_BATTLE
Definition enums.h:3643
@ STATUS_KEY_STONE
Definition enums.h:2813
@ BTL_CAM_DEFAULT
Definition enums.h:4409
@ BATTLE_STATE_BEGIN_PARTNER_TURN
Definition enums.h:3672
@ BATTLE_STATE_PREPARE_MENU
Definition enums.h:3676
@ BATTLE_STATE_TRANSFER_TURN
Definition enums.h:3673
@ BATTLE_STATE_END_TURN
Definition enums.h:3670
@ ABILITY_HAPPY_HEART
Definition enums.h:454
@ ABILITY_CRAZY_HEART
Definition enums.h:467
@ ABILITY_HAPPY_FLOWER
Definition enums.h:488
@ ACTOR_PLAYER
Definition enums.h:2118
@ EVT_PRIORITY_A
Definition evt.h:154
s32 is_ability_active(s32 arg0)
Definition inventory.c:1735
void btl_cam_use_preset(s32)
Definition camera.c:1919
Evt * start_script(EvtScript *source, s32 priority, s32 initialState)
void btl_cam_move(s16)
Definition camera.c:1953
s32 does_script_exist(s32 id)
f32 sin_rad(f32 x)
Definition 43F0.c:711
void btl_set_state(s32 battleState)
s32 btl_check_enemies_defeated(void)
Definition 190B20.c:653
EvtScript EVS_Mario_HandlePhase
@ BTL_SUBSTATE_AWAIT_RECOVER
@ BTL_SUBSTATE_AWAIT_SWAP
@ BTL_SUBSTATE_DONE
void btl_state_update_end_player_turn(void)
void btl_state_draw_end_player_turn(void)
void btl_substate_try_hpfp_recovery(void)
#define DEG_TO_RAD(deg)
Definition macros.h:146
@ BTL_SUBSTATE_INIT
Definition states.h:8
@ BTL_SUBSTATE_PLAYER_CONTINUE_DIP
Definition states.h:12
BattleStatus gBattleStatus
Definition battle.cpp:14
s32 gBattleSubState
Definition battle.cpp:17