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

Go to the source code of this file.

Enumerations

enum  { BTL_SUBSTATE_AWAIT = 2 }
 

Functions

void btl_state_update_enemy_striking_first (void)
 
void btl_state_draw_enemy_striking_first (void)
 

Enumeration Type Documentation

◆ anonymous enum

Enumerator
BTL_SUBSTATE_AWAIT 

Definition at line 3 of file enemy_first_strike.c.

3 {
4 // BTL_SUBSTATE_INIT = 0,
6};
@ BTL_SUBSTATE_AWAIT

Function Documentation

◆ btl_state_update_enemy_striking_first()

void btl_state_update_enemy_striking_first ( void )

Definition at line 8 of file enemy_first_strike.c.

8 {
10 Actor* player = battleStatus->playerActor;
11 Actor* partner = battleStatus->partnerActor;
12 Evt* script;
13 Actor* actor;
14 u16* enemyIDs;
15 s16 activeEnemyActorID;
17 s32 count;
18 s32 flags;
20 s32 i;
21 s32 j;
22
23 switch (gBattleSubState) {
26 battleStatus->stateFreezeCount = 0;
27 battleStatus->lastAttackDamage = 0;
28 battleStatus->curDamageSource = DMG_SRC_DEFAULT;
32 if (partner != NULL) {
34 }
37 count = 0;
38
39 for (i = 0; i < ARRAY_COUNT(battleStatus->enemyActors); i++) {
40 actor = battleStatus->enemyActors[i];
41 if (actor != NULL) {
42 battleStatus->enemyIDs[count] = i | ACTOR_ENEMY0;
43 count++;
44 }
45 }
46
47 battleStatus->numEnemyActors = count;
48
49 enemyIDs = battleStatus->enemyIDs;
50 for (i = 0; i < count - 1; i++) {
51 for (j = i + 1; j < count; j++) {
52 s32 iVal = enemyIDs[i];
53 s32 jVal = enemyIDs[j];
54
55 if (battleStatus->enemyActors[iVal & 0xFF]->turnPriority <
56 battleStatus->enemyActors[jVal & 0xFF]->turnPriority)
57 {
58 enemyIDs[i] = jVal;
59 enemyIDs[j] = iVal;
60 }
61 }
62 }
63
64 battleStatus->nextEnemyIndex = 0;
65 nextEnemyIdx = 0;
67
68 while (TRUE) {
69 actor = battleStatus->enemyActors[battleStatus->enemyIDs[nextEnemyIdx] & 0xFF];
70 if (actor == NULL || (actor->flags & flags)) {
72 if (nextEnemyIdx >= battleStatus->numEnemyActors) {
73 nextEnemyIdx = 0;
74 }
75 } else {
76 break;
77 }
78 }
79
80 activeEnemyActorID = battleStatus->enemyIDs[nextEnemyIdx];
82 battleStatus->curTurnEnemy = actor;
83 battleStatus->activeEnemyActorID = activeEnemyActorID;
84 if (nextEnemyIdx >= battleStatus->numEnemyActors) {
85 nextEnemyIdx = 0;
86 }
87 battleStatus->nextEnemyIndex = nextEnemyIdx;
88 btl_cam_target_actor(battleStatus->activeEnemyActorID);
89 actor = battleStatus->curTurnEnemy;
91 battleStatus->battlePhase = PHASE_FIRST_STRIKE;
93 script->owner1.actorID = battleStatus->activeEnemyActorID;
94 actor->takeTurnScript = script;
95 actor->takeTurnScriptID = script->id;
98 break;
100 if (BattleSubstateDelay != 0) {
102 } else {
104 }
105
106 // wait for current enemy TakeTurn script to finish
107 actor = battleStatus->curTurnEnemy;
108 if (actor->takeTurnScript != NULL && does_script_exist(actor->takeTurnScriptID)) {
109 break;
110 }
111 actor->takeTurnScript = NULL;
112
113 // wait for player HandleEvent script to finish (may have been triggered by enemy Take Turn)
114 if (player->handleEventScript != NULL && does_script_exist(player->handleEventScriptID)) {
115 break;
116 }
117 player->handleEventScript = NULL;
118
119 // wait for partner HandleEvent script to finish (may have been triggered by enemy Take Turn)
120 if (partner != NULL) {
121 if (partner->handleEventScript != NULL && does_script_exist(partner->handleEventScriptID)) {
122 break;
123 }
124 partner->handleEventScript = NULL;
125 }
126
127 // wait for all enemy TakeTurn scripts to finish
129
130 for (i = 0; i < ARRAY_COUNT(battleStatus->enemyActors); i++) {
131 actor = battleStatus->enemyActors[i];
132 if (actor != NULL && actor->takeTurnScript != NULL) {
135 } else {
136 actor->takeTurnScript = NULL;
137 }
138 }
139 }
140
141 if (waitingForScript) {
142 break;
143 }
144
145 // wait for all enemy HandleEvent scripts to finish
147
148 for (i = 0; i < ARRAY_COUNT(battleStatus->enemyActors); i++) {
149 actor = battleStatus->enemyActors[i];
150 if (actor != NULL && actor->handleEventScript != NULL) {
153 } else {
154 actor->handleEventScript = NULL;
155 }
156 }
157 }
158
159 if (waitingForScript) {
160 break;
161 }
162
163 // reset state
165 for (i = 0; i < ARRAY_COUNT(battleStatus->enemyActors); i++) {
166 actor = battleStatus->enemyActors[i];
167 if (actor != NULL) {
169 }
170 }
171
172 if (battleStatus->stateFreezeCount == 0) {
174 return;
175 }
177 }
178 break;
179 }
180}
BSS s32 PopupMenu_SelectedIndex
BSS b32 BattleCanShowFirstStrike
BSS s32 BattleSubstateDelay
struct Evt * takeTurnScript
struct Evt * handleEventScript
s32 takeTurnScriptID
s32 handleEventScriptID
EvtScript * takeTurnSource
s8 flags
Definition demo_api.c:15
@ PHASE_FIRST_STRIKE
Definition enums.h:2092
@ BS_FLAGS2_IS_FIRST_STRIKE
Definition enums.h:3651
@ BS_FLAGS2_IGNORE_DARKNESS
Definition enums.h:3648
@ BATTLE_STATE_BEGIN_TURN
Definition enums.h:3669
@ DMG_SRC_DEFAULT
Definition enums.h:2014
@ ACTOR_ENEMY0
Definition enums.h:2120
@ ACTOR_FLAG_TARGET_ONLY
Battle ends even if undefeated. No turn.
Definition enums.h:3368
@ ACTOR_FLAG_NO_ATTACK
Skip attack turn.
Definition enums.h:3373
@ EVT_PRIORITY_A
Definition evt.h:154
s32 btl_check_player_defeated(void)
Definition 190B20.c:661
void reset_actor_turn_info(void)
Definition 190B20.c:710
void btl_cam_target_actor(s32)
Definition camera.c:1926
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
@ BTL_SUBSTATE_INIT
Definition states.h:8
PlayerData gPlayerData
Definition 77480.c:39
BattleStatus gBattleStatus
Definition battle.cpp:14
s32 gBattleSubState
Definition battle.cpp:17

Referenced by btl_update().

◆ btl_state_draw_enemy_striking_first()

void btl_state_draw_enemy_striking_first ( void )

Definition at line 182 of file enemy_first_strike.c.

182 {
184 if (BattleScreenFadeAmt == 0) {
186 } else {
188 if (BattleScreenFadeAmt < 0) {
190 }
191
193 }
194 }
195}
s32 BattleScreenFadeAmt
Definition 16C8E0.c:50
@ OVERLAY_NONE
Definition enums.h:2373
@ OVERLAY_SCREEN_COLOR
Definition enums.h:2374
void set_screen_overlay_params_front(u8, f32)

Referenced by btl_draw_ui().