Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
turn_begin.c
Go to the documentation of this file.
1#include "states.h"
2#include "battle/battle.h"
3
5
6enum {
7 // BTL_SUBSTATE_INIT = 0,
10};
11
14 Actor* partner = battleStatus->partnerActor;
15 Actor* player = battleStatus->playerActor;
16 Actor* enemy;
19 Evt* script;
21 u16 id1;
22 u16 id2;
23 s32 numEnemyActors;
24 s32 i;
25 s32 j;
26 s16* enemyIDs;
27
33 battleStatus->merleeAttackBoost = 0;
34 battleStatus->merleeDefenseBoost = 0;
36
38 player->disableDismissTimer = 0;
39 if (partner != NULL) {
41 partner->disableDismissTimer = 0;
42 }
43
44 if (battleStatus->hustleTurns != 0) {
46 }
47
48 numEnemyActors = 0;
49 for (i = 0; i < ARRAY_COUNT(battleStatus->enemyActors); i++) {
50 enemy = battleStatus->enemyActors[i];
51 if (enemy != NULL) {
52 battleStatus->enemyIDs[numEnemyActors] = i | ACTOR_ENEMY0;
53 numEnemyActors++;
54 }
55 }
56 battleStatus->numEnemyActors = numEnemyActors;
57
58 // sort enemies by x-position or turn priority
59 enemyIDs = battleStatus->enemyIDs;
60 for (i = 0; i < numEnemyActors - 1; i++) {
61 for (j = i + 1; j < numEnemyActors; j++) {
62 id1 = enemyIDs[i];
63 id2 = enemyIDs[j];
64 enemy1 = battleStatus->enemyActors[id1 & 0xFF];
65 enemy2 = battleStatus->enemyActors[id2 & 0xFF];
67 if (enemy1->homePos.x > enemy2->homePos.x) {
68 enemyIDs[i] = id2;
69 enemyIDs[j] = id1;
70 }
71 } else if (enemy1->turnPriority < enemy2->turnPriority) {
72 enemyIDs[i] = id2;
73 enemyIDs[j] = id1;
74 }
75 }
76 }
77 battleStatus->nextEnemyIndex = 0;
78
80
81 // clear rush flags to initialize
82 battleStatus->rushFlags = RUSH_FLAG_NONE;
84
85 // set rush flags based on danger/peril status
89 battleStatus->rushFlags |= RUSH_FLAG_MEGA;
90 }
92 if (!(battleStatus->rushFlags & RUSH_FLAG_MEGA)) {
94 battleStatus->rushFlags |= RUSH_FLAG_POWER;
95 }
96 }
97 }
98
100 battleStatus->jumpCharge = 0;
101 }
102
104 battleStatus->hammerCharge = 0;
105 }
106
109 return;
110 }
111
113 for (i = 0; i < ARRAY_COUNT(battleStatus->enemyActors); i++) {
114 enemy = battleStatus->enemyActors[i];
115 if (enemy != NULL && enemy->handleEventSource != NULL) {
117
118 enemy->handleEventScript = script;
119 script->owner1.actorID = i | ACTOR_ENEMY0;
120 enemy->handleEventScriptID = script->id;
121 enemy->lastEventType = EVENT_DEATH;
122 }
123 }
125 } else {
126 for (i = 0; i < ARRAY_COUNT(battleStatus->enemyActors); i++) {
127 enemy = battleStatus->enemyActors[i];
128 if (enemy != NULL && enemy->handlePhaseSource != NULL) {
129 battleStatus->battlePhase = PHASE_PLAYER_BEGIN;
131 enemy->handlePhaseScript = script;
132 enemy->handlePhaseScriptID = script->id;
133 script->owner1.actorID = i | ACTOR_ENEMY0;
134 }
135 }
136
137 partner = battleStatus->partnerActor;
138 if (partner != NULL && partner->handlePhaseSource != NULL) {
139 battleStatus->battlePhase = PHASE_PLAYER_BEGIN;
140 script = start_script(partner->handlePhaseSource, EVT_PRIORITY_A, 0);
141 partner->handlePhaseScript = script;
142 partner->handlePhaseScriptID = script->id;
143 script->owner1.actorID = ACTOR_PARTNER;
144 }
146 }
147 }
148
150 awaiting = FALSE;
151 for (i = 0; i < ARRAY_COUNT(battleStatus->enemyActors); i++) {
152 enemy = battleStatus->enemyActors[i];
153 if (enemy != NULL && enemy->handlePhaseSource != NULL && does_script_exist(enemy->handlePhaseScriptID)) {
154 awaiting = TRUE;
155 }
156 }
157 if (partner != NULL && partner->handlePhaseSource != NULL && does_script_exist(partner->handlePhaseScriptID)) {
158 awaiting = TRUE;
159 }
160
161 if (!awaiting) {
164 }
165 return;
166 }
167 }
168
170 awaiting = FALSE;
171 for (i = 0; i < ARRAY_COUNT(battleStatus->enemyActors); i++) {
172 enemy = battleStatus->enemyActors[i];
173 if (enemy != NULL && enemy->handleEventSource != NULL && does_script_exist(enemy->handleEventScriptID)) {
174 awaiting = TRUE;
175 }
176 }
177
178 if (!awaiting) {
181 }
182 }
183 }
184}
185
BSS s32 PopupMenu_SelectedIndex
struct Evt * handlePhaseScript
EvtScript * handleEventSource
s8 disableDismissTimer
struct Evt * handleEventScript
EvtScript * handlePhaseSource
s32 b32
s32 handleEventScriptID
s32 handlePhaseScriptID
union Evt::@10 owner1
Initially -1.
@ BS_FLAGS1_HUSTLED
Definition enums.h:3628
@ BS_FLAGS1_SORT_ENEMIES_BY_POSX
Definition enums.h:3629
@ BS_FLAGS1_JUMP_CHARGED
Definition enums.h:3631
@ BS_FLAGS1_HAMMER_CHARGED
Definition enums.h:3630
@ DEBUG_CONTACT_DIE_IN_BATTLE
Definition enums.h:3869
@ DEBUG_CONTACT_AUTO_FLEE
Definition enums.h:3870
@ RUSH_FLAG_NONE
Definition enums.h:4915
@ RUSH_FLAG_MEGA
Definition enums.h:4916
@ RUSH_FLAG_POWER
Definition enums.h:4917
@ PHASE_PLAYER_BEGIN
Definition enums.h:2099
@ BS_FLAGS2_HAS_RUSH
Definition enums.h:3654
@ BS_FLAGS2_PEACH_BATTLE
Definition enums.h:3643
@ BATTLE_STATE_RUN_AWAY
Definition enums.h:3688
@ BATTLE_STATE_BEGIN_PLAYER_TURN
Definition enums.h:3671
@ ABILITY_POWER_RUSH
Definition enums.h:466
@ ABILITY_MEGA_RUSH
Definition enums.h:456
@ 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
@ EVENT_DEATH
Definition enums.h:2186
@ EVT_PRIORITY_A
Definition evt.h:154
s32 is_ability_active(s32 arg0)
Definition inventory.c:1735
Evt * start_script(EvtScript *source, s32 priority, s32 initialState)
s32 does_script_exist(s32 id)
void btl_set_state(s32 battleState)
s32 btl_check_enemies_defeated(void)
Definition 190B20.c:653
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define PERIL_THRESHOLD
Definition battle.h:277
#define DANGER_THRESHOLD
Definition battle.h:276
@ BTL_SUBSTATE_INIT
Definition states.h:8
void btl_state_update_begin_turn(void)
Definition turn_begin.c:12
void btl_state_draw_begin_turn(void)
Definition turn_begin.c:186
void btl_merlee_on_start_turn(void)
@ BTL_SUBSTATE_AWAIT_ENEMY_SCRIPTS
Definition turn_begin.c:8
@ BTL_SUBSTATE_AWAIT_ENEMY_DEATH
Definition turn_begin.c:9
GameStatus * gGameStatusPtr
Definition main_loop.c:31
PlayerData gPlayerData
Definition 77480.c:39
BattleStatus gBattleStatus
Definition battle.cpp:14
s32 gBattleSubState
Definition battle.cpp:17