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

Go to the source code of this file.

Enumerations

enum  { BTL_SUBSTATE_AWAIT_ENEMY_SCRIPTS = 5 , BTL_SUBSTATE_AWAIT_ENEMY_DEATH = 10 }
 

Functions

void btl_merlee_on_start_turn (void)
 
void btl_state_update_begin_turn (void)
 
void btl_state_draw_begin_turn (void)
 

Enumeration Type Documentation

◆ anonymous enum

Enumerator
BTL_SUBSTATE_AWAIT_ENEMY_SCRIPTS 
BTL_SUBSTATE_AWAIT_ENEMY_DEATH 

Definition at line 6 of file turn_begin.c.

6 {
7 // BTL_SUBSTATE_INIT = 0,
10};
@ BTL_SUBSTATE_AWAIT_ENEMY_SCRIPTS
Definition turn_begin.c:8
@ BTL_SUBSTATE_AWAIT_ENEMY_DEATH
Definition turn_begin.c:9

Function Documentation

◆ btl_merlee_on_start_turn()

void btl_merlee_on_start_turn ( void )

Definition at line 9 of file btl_states_actions.c.

9 {
13
15 && battleStatus->nextMerleeSpellType != MERLEE_SPELL_EXP_BOOST
16 && battleStatus->nextMerleeSpellType != MERLEE_SPELL_COIN_BOOST
17 && playerData->merleeCastsLeft > 0
18 ) {
19 if (playerData->merleeTurnCount <= 0) {
20 s32 temp = rand_int(100);
21
22 if (currentEncounter->curEnemy != NULL) {
23 if (currentEncounter->curEnemy->flags & ACTOR_FLAG_NO_HEALTH_BAR) {
24 // 46/101 ≈ 45.5%
25 if (temp <= 45) {
26 playerData->merleeSpellType = MERLEE_SPELL_ATK_BOOST;
27 } else if (temp <= 90) { // 45/101 ≈ 44.6%
28 playerData->merleeSpellType = MERLEE_SPELL_DEF_BOOST;
29 } else { // 10/101 ≈ 9.9%
30 playerData->merleeSpellType = MERLEE_SPELL_EXP_BOOST;
31 }
32 } else if (temp <= 30) { // 31/101 ≈ 30.7%
33 playerData->merleeSpellType = MERLEE_SPELL_ATK_BOOST;
34 } else if (temp <= 60) { // 30/101 ≈ 29.7%
35 playerData->merleeSpellType = MERLEE_SPELL_DEF_BOOST;
36 } else if (temp <= 80) { // 20/101 ≈ 19.8%
37 playerData->merleeSpellType = MERLEE_SPELL_EXP_BOOST;
38 } else { // 20/101 ≈ 19.8%
39 playerData->merleeSpellType = MERLEE_SPELL_COIN_BOOST;
40 }
41 } else if (temp <= 30) { // 31/101 ≈ 30.7%
42 playerData->merleeSpellType = MERLEE_SPELL_ATK_BOOST;
43 } else if (temp <= 60) { // 30/101 ≈ 29.7%
44 playerData->merleeSpellType = MERLEE_SPELL_DEF_BOOST;
45 } else if (temp <= 80) { // 20/101 ≈ 19.8%
46 playerData->merleeSpellType = MERLEE_SPELL_EXP_BOOST;
47 } else { // 20/101 ≈ 19.8%
48 playerData->merleeSpellType = MERLEE_SPELL_COIN_BOOST;
49 }
50
51 temp = rand_int(10) + 6;
52 playerData->merleeTurnCount = temp;
53 }
54
55 if (playerData->merleeTurnCount >= 2) {
56 playerData->merleeTurnCount--;
57 } else {
58 playerData->merleeTurnCount = 0;
59 battleStatus->nextMerleeSpellType = playerData->merleeSpellType;
60 playerData->merleeCastsLeft--;
61 }
62 }
63}
BSS s32 PopupMenu_SelectedIndex
#define rand_int
@ MERLEE_SPELL_COIN_BOOST
Definition enums.h:1940
@ MERLEE_SPELL_EXP_BOOST
Definition enums.h:1939
@ MERLEE_SPELL_ATK_BOOST
Definition enums.h:1937
@ MERLEE_SPELL_DEF_BOOST
Definition enums.h:1938
@ BS_FLAGS2_PEACH_BATTLE
Definition enums.h:3643
@ ACTOR_FLAG_NO_HEALTH_BAR
Definition enums.h:3371
EncounterStatus gCurrentEncounter
Definition encounter.c:175
PlayerData gPlayerData
Definition 77480.c:39
BattleStatus gBattleStatus
Definition battle.cpp:14

Referenced by btl_state_update_begin_turn().

◆ btl_state_update_begin_turn()

void btl_state_update_begin_turn ( void )

Definition at line 12 of file turn_begin.c.

12 {
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}
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
@ 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_merlee_on_start_turn(void)
GameStatus * gGameStatusPtr
Definition main_loop.c:31
s32 gBattleSubState
Definition battle.cpp:17

Referenced by btl_update().

◆ btl_state_draw_begin_turn()

void btl_state_draw_begin_turn ( void )

Definition at line 186 of file turn_begin.c.

186 {
187}

Referenced by btl_draw_ui().