Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
start_battle.c
Go to the documentation of this file.
1#include "states.h"
2#include "model.h"
3#include "script_api/battle.h"
4
8
14
15enum {
16 // BTL_SUBSTATE_INIT = 0,
21};
22
24
26 void* compressedAsset;
29 s32 size;
30
34
35 ASSERT(size <= 0x8000);
36
39 if (rootModel != NULL) {
41 }
43
44 if (stage->bg != NULL) {
45 load_map_bg(stage->bg);
47 }
48}
49
54 Stage* stage;
55 Actor* actor;
56 Evt* script;
58 s32 type;
59 s32 i;
60 s32 j;
61
62 s32* types;
63
65 if (gOverrideBattlePtr != NULL) {
67 }
68
69 if (gCurrentStagePtr == NULL) {
70 stage = battle->stage;
71 } else {
72 stage = gCurrentStagePtr->stage;
73 }
74
75 battleStatus->curStage = stage;
76 switch (gBattleSubState) {
78 #if DX_DEBUG_MENU
80 #endif
81
82 BattleEnemiesCreated = battle->formationSize;
84
85 load_stage_assets(stage);
86
89 }
90
91 battleStatus->controlScript = NULL;
92 battleStatus->camMovementScript = NULL;
93 battleStatus->unk_90 = 0;
94 battleStatus->preUpdateCallback = NULL;
95 battleStatus->initBattleCallback = NULL;
96 battleStatus->curSubmenu = 0;
97 battleStatus->lastSelectedAbility = 0;
98 battleStatus->curPartnerSubmenu = 0;
99 battleStatus->lastPartnerPowerSelection = 0;
100 battleStatus->totalStarPoints = 0;
101 battleStatus->pendingStarPoints = 0;
102 battleStatus->incrementStarPointDelay = 0;
103 battleStatus->damageTaken = 0;
104 battleStatus->nextMerleeSpellType = MERLEE_SPELL_NONE;
105 battleStatus->actionCommandMode = AC_MODE_NOT_LEARNED;
110 battleStatus->actionCommandMode = AC_MODE_LEARNED;
111 }
112 battleStatus->actionQuality = 0;
113 battleStatus->maxActionQuality = 0;
114 battleStatus->enabledMenusFlags = -1;
115 battleStatus->enabledStarPowersFlags = -1;
116 battleStatus->itemUsesLeft = 0;
117 battleStatus->hammerCharge = 0;
118 battleStatus->jumpCharge = 0;
119 battleStatus->unk_98 = 0;
120 battleStatus->hpDrainCount = 0;
122 if (currentEncounter->forbidFleeing) {
124 }
125 battleStatus->endBattleFadeOutRate = 10;
126 battleStatus->waitForState = BATTLE_STATE_NONE;
127 battleStatus->hammerLossTurns = -1;
128 battleStatus->jumpLossTurns = -1;
129 battleStatus->itemLossTurns = -1;
130 battleStatus->outtaSightActive = 0;
131 battleStatus->waterBlockTurnsLeft = 0;
132 battleStatus->waterBlockAmount = 0;
133 battleStatus->waterBlockEffect = NULL;
134 battleStatus->cloudNineTurnsLeft = 0;
135 battleStatus->cloudNineDodgeChance = 0;
136 battleStatus->cloudNineEffect = NULL;
137 battleStatus->reflectFlags = 0;
138 battleStatus->turboChargeTurnsLeft = 0;
139 battleStatus->turboChargeAmount = 0;
140 battleStatus->stateFreezeCount = 0;
141 battleStatus->merleeAttackBoost = 0;
142 battleStatus->merleeDefenseBoost = 0;
144 battleStatus->unk_433 = -1;
145 battleStatus->hustleTurns = 0;
146 battleStatus->nextActorOrdinal = 0;
147 battleStatus->cancelTurnMode = 0;
154
155 for (i = 0; i < ARRAY_COUNT(battleStatus->varTable); i++) {
156 battleStatus->varTable[i] = 0;
157 }
158
160 battleStatus->inputBitmask = 0xFFFFF & ~(BUTTON_START | 0xC0);
161 battleStatus->buffEffect = fx_partner_buff(0, 0.0f, 0.0f, 0.0f, 0.0f, 0);
165 battleStatus->camMovementScript = script;
166 battleStatus->camMovementScriptID = script->id;
168 break;
170 // wait for camera initialization to finish
171 if (does_script_exist(battleStatus->camMovementScriptID)) {
172 break;
173 }
174
175 if (stage->preBattle != NULL) {
177 battleStatus->controlScript = script;
178 battleStatus->controlScriptID = script->id;
179 }
180
183
184 for (i = 0; i < ARRAY_COUNT(battleStatus->enemyActors); i++) {
185 battleStatus->enemyActors[i] = NULL;
186 }
187 battleStatus->initialEnemyCount = 0;
188
189 for (i = 0; i < BattleEnemiesCreated; i++) {
190 create_actor(&(*battle->formation)[i]);
192 actor = battleStatus->enemyActors[i];
193
194 while (TRUE) {
195 type = *types;
196 if (type == -1) {
197 battleStatus->initialEnemyCount++;
198 break;
199 } else if (actor->actorType == type) {
200 break;
201 }
202 types++;
203 }
204
205 actor->instigatorValue = 0;
206 if (i == 0) {
207 actor->instigatorValue = currentEncounter->instigatorValue;
208 if (currentEncounter->dizzyAttack.status == STATUS_KEY_DIZZY) {
210 }
211 }
212 }
213
214 if (stage->stageEnemyCount != 0) {
215 if (stage->stageEnemyChance == 0 || (stage->stageEnemyChance > 0 && (rand_int(stage->stageEnemyChance) == 0))) {
217 for (j = 0; i < BattleEnemiesCreated; i++, j++) {
218 create_actor(&(*stage->stageFormation)[j]);
219 actor = battleStatus->enemyActors[i];
220 actor->instigatorValue = 0;
221 if (i == 0) {
222 actor->instigatorValue = 0;
223 if (currentEncounter->dizzyAttack.status == STATUS_KEY_DIZZY) {
225 }
226 }
227
228 }
229 }
230 }
231
233 actor = battleStatus->playerActor;
236 } else {
238 }
239 actor->takeTurnScript = script;
240 actor->takeTurnScriptID = script->id;
241 script->owner1.actorID = ACTOR_PLAYER;
244 break;
247 for (i = 0; i < BattleEnemiesCreated; i++) {
248 actor = battleStatus->enemyActors[i];
251 break;
252 } else {
253 actor->takeTurnScript = NULL;
254 }
255 }
256 if (enemyNotDone) {
257 break;
258 }
259
260 actor = battleStatus->playerActor;
262 break;
263 }
264 actor->takeTurnScript = NULL;
265
266 actor = battleStatus->partnerActor;
267 if (actor != NULL) {
269 break;
270 }
271 actor->takeTurnScript = NULL;
272 }
273
274 if (battle->onBattleStart != NULL) {
275 script = start_script(battle->onBattleStart, EVT_PRIORITY_A, 0);
276 battleStatus->controlScript = script;
277 battleStatus->controlScriptID = script->id;
278 }
279 if (battleStatus->darknessMode > BTL_DARKNESS_STATE_NONE) {
282 }
284 currentEncounter->firstStrikeType = FIRST_STRIKE_NONE;
285 }
286
287 switch (currentEncounter->firstStrikeType) {
290 break;
293 break;
294 default:
296 actor = battleStatus->playerActor;
299 } else {
301 }
302 actor->takeTurnScript = script;
303 actor->takeTurnScriptID = script->id;
304 script->owner1.actorID = ACTOR_PLAYER;
305 }
306
307 if (currentEncounter->curEnemy != NULL
308 && currentEncounter->curEnemy->encountered == ENCOUNTER_TRIGGER_SPIN
310 ) {
311 actor = battleStatus->enemyActors[0];
313 actor->takeTurnScript = script;
314 actor->takeTurnScriptID = script->id;
315 script->owner1.enemyID = ACTOR_ENEMY0;
316 }
317
321 break;
322 }
323 break;
325 if (BattleScreenFadeAmt == 0) {
327 break;
328 }
329
331 if (BattleSubstateDelay == 15) {
333 }
334
337 } else {
339 }
340
341 if (BattleScreenFadeAmt < 0) {
343 }
344 break;
346 if (battleStatus->stateFreezeCount == 0) {
349 }
350 break;
351 }
352}
353
s32 BattleScreenFadeAmt
Definition 16C8E0.c:50
Actor * create_actor(Formation formation)
Definition 190B20.c:1408
BSS s32 PopupMenu_SelectedIndex
@ AC_MODE_NOT_LEARNED
Definition action_cmd.h:60
@ AC_MODE_LEARNED
Definition action_cmd.h:61
BSS Battle * gCurrentBattlePtr
Definition battle.cpp:22
BSS s32 BattleSubstateDelay
struct Evt * takeTurnScript
s32 takeTurnScriptID
s8 instigatorValue
Bytecode EvtScript[]
#define rand_int
#define ASSERT(condition)
@ MERLEE_SPELL_NONE
Definition enums.h:1936
@ OVERLAY_NONE
Definition enums.h:2373
@ OVERLAY_SCREEN_COLOR
Definition enums.h:2374
@ BUTTON_START
Definition enums.h:2773
@ BS_FLAGS1_ACTORS_VISIBLE
Definition enums.h:3598
@ SCREEN_LAYER_FRONT
Definition enums.h:2368
@ SCREEN_LAYER_BACK
Definition enums.h:2369
@ DEMO_BTL_FLAG_ENABLED
Definition enums.h:3576
@ CAMERA_FLAG_DISABLED
Definition enums.h:4306
@ BS_FLAGS2_CAN_FLEE
Definition enums.h:3642
@ BS_FLAGS2_PEACH_BATTLE
Definition enums.h:3643
@ ENCOUNTER_TRIGGER_SPIN
Definition enums.h:270
@ STATUS_TURN_MOD_DIZZY
Definition enums.h:2837
@ STATUS_KEY_DIZZY
Definition enums.h:2805
@ BTL_CAM_DEFAULT
Definition enums.h:4409
@ BATTLE_STATE_ENEMY_FIRST_STRIKE
Definition enums.h:3668
@ BATTLE_STATE_FIRST_STRIKE
Definition enums.h:3666
@ BATTLE_STATE_BEGIN_TURN
Definition enums.h:3669
@ BATTLE_STATE_NONE
Definition enums.h:3664
@ ABILITY_CHILL_OUT
Definition enums.h:453
@ ABILITY_DIZZY_ATTACK
Definition enums.h:481
@ ACTOR_PLAYER
Definition enums.h:2118
@ ACTOR_ENEMY0
Definition enums.h:2120
@ FIRST_STRIKE_NONE
Definition enums.h:3492
@ FIRST_STRIKE_ENEMY
Definition enums.h:3494
@ FIRST_STRIKE_PLAYER
Definition enums.h:3493
@ BTL_DARKNESS_STATE_NONE
Definition enums.h:5950
@ CAM_TATTLE
Definition enums.h:1828
@ CAM_DEFAULT
Definition enums.h:1826
@ CAM_BATTLE
Definition enums.h:1827
@ EVT_PRIORITY_A
Definition evt.h:154
void load_partner_actor(void)
Definition 190B20.c:1154
void set_screen_overlay_params_back(u8, f32)
s32 is_ability_active(s32 arg0)
Definition inventory.c:1735
void setup_status_bar_for_battle(void)
Definition inventory.c:1471
void * load_asset_by_name(const char *assetName, u32 *decompressedSize)
Definition world.c:251
void set_background(BackgroundHeader *)
Definition background.c:40
void load_battle_hit_asset(const char *hitName)
Definition collision.c:166
void load_data_for_models(struct ModelNode *model, s32 romOffset, s32 size)
Definition model.c:3318
void set_screen_overlay_params_front(u8, f32)
void load_map_bg(char *optAssetName)
Definition background.c:14
s32 get_asset_offset(char *, s32 *)
Definition world.c:273
void btl_cam_use_preset(s32)
Definition camera.c:1919
Evt * start_script(EvtScript *source, s32 priority, s32 initialState)
void set_screen_overlay_color(s32, u8, u8, u8)
s32 general_heap_free(void *data)
Definition heap.c:18
void decode_yay0(void *src, void *dst)
s32 inflict_status_set_duration(Actor *actor, s32 statusTypeKey, s32 statusDurationKey, s32 duration)
Definition 190B20.c:2313
s32 does_script_exist(s32 id)
void load_player_actor(void)
Definition 190B20.c:940
void btl_set_state(s32 battleState)
void set_curtain_scale_goal(f32 scale)
Definition curtains.c:285
EvtScript EVS_ApplyDizzyAttack
ModelNode * root
Definition model.h:174
ShapeFileHeader header
Definition model.h:183
EncounterStatus gCurrentEncounter
Definition encounter.c:175
#define BSS
Definition macros.h:7
#define ARRAY_COUNT(arr)
Definition macros.h:40
EvtScript * preBattle
Definition battle.h:185
char * texture
Definition battle.h:182
const char * shape
Definition battle.h:183
Formation * stageFormation
Definition battle.h:190
s32 stageEnemyChance
Definition battle.h:191
Stage * stage
Definition battle.h:208
s32 stageEnemyCount
Definition battle.h:189
const char * hit
Definition battle.h:184
char * bg
Definition battle.h:187
Zero-terminated.
Definition battle.h:195
Zero-terminated.
Definition battle.h:206
BSS s32 BattleEnemiesCreated
@ BTL_SUBSTATE_CHECK_FIRST_STRIKE
@ BTL_SUBSTATE_CREATE_ENEMIES
@ BTL_SUBSTATE_DONE
@ BTL_SUBSTATE_FADE_IN
EvtScript EVS_PeachEnterStage
void btl_state_update_normal_start(void)
ShapeFile gMapShapeData
Definition heaps.c:16
EvtScript EVS_Peach_OnActorCreate
StageListRow * gCurrentStagePtr
Definition battle.cpp:12
void load_stage_assets(Stage *stage)
EvtScript EVS_MarioEnterStage
s32 bActorsIgnoreDuringCount[]
EvtScript EVS_OnBattleInit
Definition camera.c:1171
void btl_state_draw_normal_start(void)
EvtScript EVS_Mario_OnActorCreate
@ BTL_SUBSTATE_INIT
Definition states.h:8
s32 gCurrentBattleID
Definition battle.cpp:19
BackgroundHeader gBackgroundImage
GameStatus * gGameStatusPtr
Definition main_loop.c:31
struct Battle * gOverrideBattlePtr
Definition battle.cpp:21
Camera gCameras[4]
Definition cam_main.c:16
PlayerData gPlayerData
Definition 77480.c:39
BattleStatus gBattleStatus
Definition battle.cpp:14
s32 gCurrentCameraID
Definition cam_math.c:5
s32 gCurrentStageID
Definition battle.cpp:20
s32 gBattleSubState
Definition battle.cpp:17
StatusBar gStatusBar
Definition inventory.c:22