2021-03-19 11:25:14 +01:00
|
|
|
#include "common.h"
|
2021-08-16 20:14:58 +02:00
|
|
|
#include "nu/nusys.h"
|
2021-10-18 17:58:32 +02:00
|
|
|
#include "hud_element.h"
|
2021-10-25 13:53:47 +02:00
|
|
|
#include "ld_addrs.h"
|
2021-10-29 18:48:20 +02:00
|
|
|
#include "sprite.h"
|
2022-09-24 21:34:16 +02:00
|
|
|
#include "battle/battle.h"
|
2022-10-16 16:22:18 +02:00
|
|
|
#include "model.h"
|
2021-03-19 11:25:14 +01:00
|
|
|
|
2023-02-14 14:14:14 +01:00
|
|
|
extern u16 gFrameBuf0[];
|
|
|
|
extern u16 gFrameBuf1[];
|
|
|
|
extern u16 gFrameBuf2[];
|
|
|
|
u16* bFrameBuffers[] = {
|
|
|
|
gFrameBuf0, gFrameBuf1, gFrameBuf2
|
2021-08-16 20:14:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
s32 D_800778AC[] = {
|
2022-05-28 17:15:51 +02:00
|
|
|
0x00000000, 0xFFFFFF00, 0xFFFFFF00, 0x00000000, 0x00000000
|
2021-07-12 11:15:00 +02:00
|
|
|
};
|
|
|
|
|
2021-07-08 17:53:00 +02:00
|
|
|
// BSS
|
2021-03-19 11:25:14 +01:00
|
|
|
extern s32 D_800A0904;
|
|
|
|
extern s32 D_800A0908;
|
2020-08-04 08:49:11 +02:00
|
|
|
|
2023-02-14 14:14:14 +01:00
|
|
|
#ifdef SHIFT
|
|
|
|
#define shim_battle_heap_create_obfuscated battle_heap_create
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern ShapeFile gMapShapeData;
|
|
|
|
|
2021-06-30 04:27:12 +02:00
|
|
|
void state_init_battle(void) {
|
2020-08-12 20:48:51 +02:00
|
|
|
D_800A0900 = 5;
|
|
|
|
}
|
2020-08-04 08:49:11 +02:00
|
|
|
|
2021-06-30 04:27:12 +02:00
|
|
|
void state_step_battle(void) {
|
2021-10-25 13:53:47 +02:00
|
|
|
u32 currentBattleSelection;
|
2022-11-22 05:12:28 +01:00
|
|
|
u32 currentBattleIndex;
|
2021-03-19 11:25:14 +01:00
|
|
|
|
2021-04-23 13:55:30 +02:00
|
|
|
if (D_800A0900 == 5) {
|
2021-07-31 16:32:19 +02:00
|
|
|
if (nuGfxCfb[1] != nuGfxCfb_ptr) {
|
2021-03-19 11:25:14 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-04-26 19:47:38 +02:00
|
|
|
D_800A0900--;
|
2022-02-19 15:39:34 +01:00
|
|
|
gOverrideFlags |= GLOBAL_OVERRIDES_8;
|
2021-03-19 11:25:14 +01:00
|
|
|
nuContRmbForceStop();
|
|
|
|
}
|
|
|
|
|
2021-04-23 13:55:30 +02:00
|
|
|
if (D_800A0900 >= 0) {
|
|
|
|
if (D_800A0900 > 0) {
|
2021-04-26 19:47:38 +02:00
|
|
|
D_800A0900--;
|
2021-06-30 04:27:12 +02:00
|
|
|
return;
|
2021-03-19 11:25:14 +01:00
|
|
|
} else {
|
2021-04-23 13:55:30 +02:00
|
|
|
D_800A0900 = -1;
|
2023-02-14 14:14:14 +01:00
|
|
|
nuGfxSetCfb(bFrameBuffers, 2);
|
2021-03-19 11:25:14 +01:00
|
|
|
nuContRmbForceStopEnd();
|
2021-03-26 15:46:45 +01:00
|
|
|
sfx_stop_env_sounds();
|
2021-03-19 11:25:14 +01:00
|
|
|
func_8003B1A8();
|
2021-03-23 03:25:48 +01:00
|
|
|
gGameStatusPtr->isBattle = TRUE;
|
2022-01-08 11:11:20 +01:00
|
|
|
backup_map_collision_data();
|
2023-02-21 15:37:27 +01:00
|
|
|
|
|
|
|
#if VERSION_CN
|
|
|
|
battle_heap_create();
|
|
|
|
#else
|
2023-02-02 12:23:17 +01:00
|
|
|
load_obfuscation_shims();
|
|
|
|
shim_battle_heap_create_obfuscated();
|
2023-02-21 15:37:27 +01:00
|
|
|
#endif
|
|
|
|
|
2021-06-30 04:27:12 +02:00
|
|
|
sfx_clear_env_sounds(0);
|
2021-03-19 11:25:14 +01:00
|
|
|
|
2022-11-22 05:12:28 +01:00
|
|
|
currentBattleSelection = UNPACK_BTL_AREA(gCurrentBattleID);
|
|
|
|
currentBattleIndex = UNPACK_BTL_INDEX(gCurrentBattleID);
|
2021-04-26 19:47:38 +02:00
|
|
|
|
2022-11-22 05:12:28 +01:00
|
|
|
if (gGameStatusPtr->peachFlags & PEACH_STATUS_FLAG_IS_PEACH ||
|
|
|
|
(currentBattleSelection == BTL_AREA_KKJ && currentBattleIndex == 0)) {
|
2022-09-24 21:34:16 +02:00
|
|
|
gGameStatusPtr->peachFlags |= PEACH_STATUS_FLAG_IS_PEACH;
|
2022-11-22 05:12:28 +01:00
|
|
|
spr_init_sprites(PLAYER_SPRITES_PEACH_BATTLE);
|
2021-03-19 11:25:14 +01:00
|
|
|
} else {
|
2022-11-22 05:12:28 +01:00
|
|
|
spr_init_sprites(PLAYER_SPRITES_MARIO_BATTLE);
|
2021-03-19 11:25:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
clear_model_data();
|
2021-06-30 04:27:12 +02:00
|
|
|
clear_sprite_shading_data();
|
|
|
|
reset_background_settings();
|
2021-03-19 11:25:14 +01:00
|
|
|
clear_entity_models();
|
2021-06-30 04:27:12 +02:00
|
|
|
clear_animator_list();
|
2022-11-22 05:12:28 +01:00
|
|
|
clear_worker_list();
|
2022-03-26 12:47:10 +01:00
|
|
|
hud_element_set_aux_cache(NULL, 0);
|
|
|
|
hud_element_clear_cache();
|
2021-03-19 11:25:14 +01:00
|
|
|
reset_status_menu();
|
|
|
|
clear_item_entity_data();
|
|
|
|
clear_script_list();
|
2021-06-30 04:27:12 +02:00
|
|
|
clear_npcs();
|
2021-03-19 11:25:14 +01:00
|
|
|
clear_entity_data(1);
|
|
|
|
clear_trigger_data();
|
2023-02-02 12:23:17 +01:00
|
|
|
dma_copy(battle_code_ROM_START, battle_code_ROM_END, battle_code_VRAM);
|
2021-03-19 11:25:14 +01:00
|
|
|
initialize_battle();
|
2021-06-30 04:27:12 +02:00
|
|
|
btl_save_world_cameras();
|
2021-03-19 11:25:14 +01:00
|
|
|
load_battle_section();
|
|
|
|
D_800A0904 = gPlayerStatusPtr->animFlags;
|
2023-03-06 08:44:48 +01:00
|
|
|
gPlayerStatusPtr->animFlags &= ~PA_FLAG_PULSE_STONE_VISIBLE;
|
2021-04-23 13:55:30 +02:00
|
|
|
D_800A0908 = get_time_freeze_mode();
|
2021-07-24 18:34:55 +02:00
|
|
|
set_time_freeze_mode(TIME_FREEZE_NORMAL);
|
2022-02-19 15:39:34 +01:00
|
|
|
gOverrideFlags &= ~GLOBAL_OVERRIDES_8;
|
2021-03-19 11:25:14 +01:00
|
|
|
|
|
|
|
if (D_800A0900 >= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-30 04:27:12 +02:00
|
|
|
update_encounters();
|
|
|
|
btl_update();
|
|
|
|
update_npcs();
|
2021-03-19 11:25:14 +01:00
|
|
|
update_item_entities();
|
|
|
|
update_effects();
|
2023-01-22 16:35:43 +01:00
|
|
|
iterate_models();
|
2021-03-19 11:25:14 +01:00
|
|
|
update_cameras();
|
|
|
|
}
|
|
|
|
|
2021-06-30 04:27:12 +02:00
|
|
|
void state_drawUI_battle(void) {
|
2021-02-06 16:20:35 +01:00
|
|
|
draw_encounter_ui();
|
2020-08-15 09:01:33 +02:00
|
|
|
if (D_800A0900 < 0) {
|
2021-06-30 04:27:12 +02:00
|
|
|
btl_draw_ui();
|
2020-08-15 09:01:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-30 04:27:12 +02:00
|
|
|
void state_init_end_battle(void) {
|
2022-02-19 15:39:34 +01:00
|
|
|
gOverrideFlags |= GLOBAL_OVERRIDES_8;
|
2020-08-15 09:01:33 +02:00
|
|
|
nuContRmbForceStop();
|
|
|
|
D_800A0900 = 5;
|
|
|
|
}
|
|
|
|
|
2021-08-16 20:14:58 +02:00
|
|
|
void state_step_end_battle(void) {
|
|
|
|
PlayerStatus* playerStatus = &gPlayerStatus;
|
|
|
|
PlayerData* playerData = &gPlayerData;
|
|
|
|
|
|
|
|
if (D_800A0900 >= 0) {
|
|
|
|
D_800A0900--;
|
|
|
|
if (D_800A0900 == 0) {
|
2022-09-08 14:12:26 +02:00
|
|
|
MapSettings* mapSettings;
|
2021-08-16 20:14:58 +02:00
|
|
|
MapConfig* mapConfig;
|
|
|
|
|
|
|
|
D_800A0900 = -1;
|
2023-02-14 14:14:14 +01:00
|
|
|
nuGfxSetCfb(bFrameBuffers, 3);
|
2022-02-19 15:39:34 +01:00
|
|
|
gOverrideFlags &= ~GLOBAL_OVERRIDES_8;
|
2021-08-16 20:14:58 +02:00
|
|
|
nuContRmbForceStopEnd();
|
|
|
|
sfx_stop_env_sounds();
|
2022-09-08 14:12:26 +02:00
|
|
|
mapSettings = get_current_map_settings();
|
|
|
|
mapConfig = &gAreas[gGameStatusPtr->areaID].maps[gGameStatusPtr->mapID];
|
2022-10-16 16:22:18 +02:00
|
|
|
btl_restore_world_cameras();
|
2021-08-16 20:14:58 +02:00
|
|
|
gGameStatusPtr->isBattle = FALSE;
|
|
|
|
func_8005AF84();
|
|
|
|
func_8002ACDC();
|
|
|
|
sfx_clear_env_sounds(1);
|
2022-09-24 21:34:16 +02:00
|
|
|
gGameStatusPtr->peachFlags &= ~PEACH_STATUS_FLAG_IS_PEACH;
|
2021-08-16 20:14:58 +02:00
|
|
|
battle_heap_create();
|
|
|
|
spr_init_sprites(gGameStatusPtr->playerSpriteSet);
|
|
|
|
init_model_data();
|
|
|
|
init_sprite_shading_data();
|
|
|
|
init_entity_models();
|
|
|
|
reset_animator_list();
|
2022-11-22 05:12:28 +01:00
|
|
|
init_worker_list();
|
2022-03-26 12:47:10 +01:00
|
|
|
hud_element_set_aux_cache(0, 0);
|
2021-08-16 20:14:58 +02:00
|
|
|
init_hud_element_list();
|
|
|
|
init_item_entity_list();
|
|
|
|
init_script_list();
|
|
|
|
init_npc_list();
|
2022-07-17 18:38:19 +02:00
|
|
|
init_entity_data();
|
2021-08-16 20:14:58 +02:00
|
|
|
init_trigger_list();
|
|
|
|
|
|
|
|
if (gGameStatusPtr->demoFlags & 1) {
|
|
|
|
npc_reload_all();
|
|
|
|
playerStatus->animFlags = D_800A0904;
|
2022-02-19 15:39:34 +01:00
|
|
|
set_game_mode(GAME_MODE_DEMO);
|
2021-08-16 20:14:58 +02:00
|
|
|
} else {
|
|
|
|
void* mapShape;
|
|
|
|
u32 sizeTemp;
|
|
|
|
|
|
|
|
partner_init_after_battle(playerData->currentPartner);
|
|
|
|
load_map_script_lib();
|
2022-10-16 16:22:18 +02:00
|
|
|
mapShape = load_asset_by_name(wMapShapeName, &sizeTemp);
|
2023-02-14 14:14:14 +01:00
|
|
|
decode_yay0(mapShape, &gMapShapeData);
|
2021-08-16 20:14:58 +02:00
|
|
|
general_heap_free(mapShape);
|
|
|
|
initialize_collision();
|
2022-01-08 11:11:20 +01:00
|
|
|
restore_map_collision_data();
|
2021-08-16 20:14:58 +02:00
|
|
|
|
2022-09-08 14:12:26 +02:00
|
|
|
if (mapConfig->dmaStart != NULL) {
|
|
|
|
dma_copy(mapConfig->dmaStart, mapConfig->dmaEnd, mapConfig->dmaDest);
|
2021-08-16 20:14:58 +02:00
|
|
|
}
|
|
|
|
|
2022-09-08 14:12:26 +02:00
|
|
|
load_map_bg(mapConfig->bgName);
|
|
|
|
if (mapSettings->background != NULL) {
|
|
|
|
read_background_size(mapSettings->background);
|
2021-08-16 20:14:58 +02:00
|
|
|
} else {
|
|
|
|
set_background_size(296, 200, 12, 20);
|
|
|
|
}
|
|
|
|
|
2022-10-16 16:22:18 +02:00
|
|
|
load_model_textures(mapSettings->modelTreeRoot, get_asset_offset(wMapTexName, &sizeTemp), sizeTemp);
|
2021-08-16 20:14:58 +02:00
|
|
|
calculate_model_sizes();
|
|
|
|
npc_reload_all();
|
|
|
|
|
|
|
|
playerStatus->animFlags = D_800A0904;
|
|
|
|
if (D_800A0908 != 0) {
|
|
|
|
set_time_freeze_mode(D_800A0908);
|
|
|
|
}
|
2022-02-19 15:39:34 +01:00
|
|
|
set_game_mode(GAME_MODE_CHANGE_MAP);
|
2021-08-16 20:14:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-15 09:01:33 +02:00
|
|
|
|
2021-06-30 04:27:12 +02:00
|
|
|
void state_drawUI_end_battle(void) {
|
2020-08-18 18:43:55 +02:00
|
|
|
}
|