Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
turn_end.c
Go to the documentation of this file.
1#include "states.h"
2
3enum {
4 // BTL_SUBSTATE_INIT = 0,
11};
12
16 Actor* player = battleStatus->playerActor;
17 Actor* partner = battleStatus->partnerActor;
18 Actor* actor;
19 Evt* script;
20 s32 i;
21
23 s32 cond = FALSE;
24
25 for (i = 0; i < ARRAY_COUNT(battleStatus->enemyActors); i++) {
26 actor = battleStatus->enemyActors[i];
27 if (actor != NULL && actor->handleEventScript != NULL) {
29 cond = TRUE;
30 } else {
31 actor->handleEventScript = NULL;
32 }
33 }
34 }
35
36 if (!cond) {
37 for (i = 0; i < ARRAY_COUNT(battleStatus->enemyActors); i++) {
38 actor = battleStatus->enemyActors[i];
39 if (actor != NULL && actor->takeTurnScript != NULL) {
41 cond = TRUE;
42 } else {
43 actor->takeTurnScript = NULL;
44 }
45 }
46 }
47
48 if (!cond) {
51 }
52 }
53 }
54
60 } else {
65 partner->state.curPos.x = partner->homePos.x;
66 partner->state.curPos.z = partner->homePos.z;
67 partner->state.goalPos.x = player->homePos.x;
68 partner->state.goalPos.z = player->homePos.z;
69 partner->state.moveTime = 4;
70 partner->state.angle = 0.0f;
72 }
73 }
74
76 if (partner->state.moveTime != 0) {
77 partner->curPos.x += (partner->state.goalPos.x - partner->curPos.x) / partner->state.moveTime;
78 partner->curPos.z += (partner->state.goalPos.z - partner->curPos.z) / partner->state.moveTime;
79 player->curPos.x += (partner->state.curPos.x - player->curPos.x) / partner->state.moveTime;
80 player->curPos.z += (partner->state.curPos.z - player->curPos.z) / partner->state.moveTime;
81 }
82 partner->curPos.z -= sin_rad(DEG_TO_RAD(partner->state.angle)) * 16.0f;
83 partner->yaw = clamp_angle(partner->state.angle);
84 player->curPos.z += sin_rad(DEG_TO_RAD(partner->state.angle)) * 16.0f;
85 player->yaw = clamp_angle(partner->state.angle);
86 partner->state.angle += 90.0f;
87 if (partner->state.moveTime != 0) {
88 partner->state.moveTime--;
89 } else {
90 partner->curPos.x = partner->state.goalPos.x;
91 partner->curPos.z = partner->state.goalPos.z;
92 player->curPos.x = partner->state.curPos.x;
93 player->curPos.z = partner->state.curPos.z;
94 partner->homePos.x = partner->curPos.x;
95 partner->homePos.z = partner->curPos.z;
96 player->homePos.x = player->curPos.x;
97 player->homePos.z = player->curPos.z;
102 } else {
104 }
106 }
107 }
108
111 player->disableDismissTimer = 0;
113 if (partner != NULL) {
115 partner->disableDismissTimer = 0;
116 }
117
120 playerData->starPower += SP_PER_SEG;
121 if (playerData->starPower > playerData->maxStarPower * SP_PER_BAR) {
122 playerData->starPower = playerData->maxStarPower * SP_PER_BAR;
123 }
124
125 for (i = 0; i < ARRAY_COUNT(battleStatus->enemyActors); i++) {
126 actor = battleStatus->enemyActors[i];
127 if (actor != NULL && actor->handlePhaseSource != NULL) {
128 battleStatus->battlePhase = PHASE_ENEMY_END;
130 actor->handlePhaseScript = script;
131 actor->handlePhaseScriptID = script->id;
132 script->owner1.enemyID = i | ACTOR_ENEMY0;
133 }
134 }
135
136 if (partner != NULL && partner->handlePhaseSource != NULL) {
137 battleStatus->battlePhase = PHASE_ENEMY_END;
138 script = start_script(partner->handlePhaseSource, EVT_PRIORITY_A, 0);
139 partner->handlePhaseScript = script;
140 partner->handlePhaseScriptID = script->id;
141 script->owner1.actorID = ACTOR_PARTNER;
142 }
144 }
145
146 // wait for all end turn scripts to finish executing
149
150 for (i = 0; i < ARRAY_COUNT(battleStatus->enemyActors); i++) {
151 actor = battleStatus->enemyActors[i];
152 if (actor != NULL && actor->handlePhaseSource != NULL && does_script_exist(actor->handlePhaseScriptID)) {
154 }
155 }
156
157 if (partner != NULL && partner->handlePhaseSource != NULL && does_script_exist(partner->handlePhaseScriptID)) {
159 }
160
161 if (!waitingForScript) {
164 }
165 }
166
167 // proceed to next turn
168 switch (gBattleSubState) {
172 break;
173 }
174}
175
177}
BSS s32 PopupMenu_SelectedIndex
struct Evt * handlePhaseScript
struct Evt * takeTurnScript
s8 disableDismissTimer
struct Evt * handleEventScript
s32 takeTurnScriptID
EvtScript * handlePhaseSource
Vec3f homePos
s32 handleEventScriptID
Vec3f curPos
s32 handlePhaseScriptID
#define clamp_angle
@ BS_FLAGS1_PLAYER_IN_BACK
Definition enums.h:3622
@ PHASE_ENEMY_END
Definition enums.h:2100
@ BS_FLAGS2_PEACH_BATTLE
Definition enums.h:3643
@ BTL_CAM_DEFAULT
Definition enums.h:4409
@ BATTLE_STATE_BEGIN_TURN
Definition enums.h:3669
@ ACTOR_PARTNER
Definition enums.h:2119
@ ACTOR_ENEMY0
Definition enums.h:2120
@ ACTOR_FLAG_SHOW_STATUS_ICONS
Definition enums.h:3377
@ ACTOR_FLAG_USING_IDLE_ANIM
Definition enums.h:3376
@ EVT_PRIORITY_A
Definition evt.h:154
void btl_set_player_idle_anims(void)
void btl_cam_use_preset(s32)
Definition camera.c:1919
Evt * start_script(EvtScript *source, s32 priority, s32 initialState)
s32 does_script_exist(s32 id)
f32 sin_rad(f32 x)
Definition 43F0.c:711
void btl_set_state(s32 battleState)
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define DEG_TO_RAD(deg)
Definition macros.h:146
#define SP_PER_SEG
Definition macros.h:103
#define SP_PER_BAR
Definition macros.h:102
@ BTL_SUBSTATE_INIT
Definition states.h:8
void btl_state_update_end_turn(void)
Definition turn_end.c:13
@ BTL_SUBSTATE_CHECK_FOR_SWAP
Definition turn_end.c:5
@ BTL_SUBSTATE_BEGIN_NEXT
Definition turn_end.c:7
@ BTL_SUBSTATE_PERFORM_SWAP
Definition turn_end.c:9
@ BTL_SUBSTATE_AWAIT_SCRIPTS
Definition turn_end.c:6
@ BTL_SUBSTATE_START_SCRIPTS
Definition turn_end.c:10
@ BTL_SUBSTATE_UNUSED_4
Definition turn_end.c:8
void btl_state_draw_end_turn(void)
Definition turn_end.c:176
PlayerData gPlayerData
Definition 77480.c:39
BattleStatus gBattleStatus
Definition battle.cpp:14
s32 gBattleSubState
Definition battle.cpp:17