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"
|
2021-03-19 11:25:14 +01:00
|
|
|
|
2021-07-08 17:53:00 +02:00
|
|
|
s32 D_800778A0[] = {
|
2021-11-07 17:58:57 +01:00
|
|
|
&D_8038F800, &D_803B5000, &heap_battleHead,
|
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
|
|
|
|
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;
|
|
|
|
u32 temp;
|
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;
|
2021-03-19 11:25:14 +01:00
|
|
|
nuGfxSetCfb(&D_800778A0, 2);
|
|
|
|
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();
|
2021-03-19 11:25:14 +01:00
|
|
|
func_8002D160();
|
|
|
|
func_802B20B4();
|
2021-06-30 04:27:12 +02:00
|
|
|
sfx_clear_env_sounds(0);
|
2021-03-19 11:25:14 +01:00
|
|
|
|
2021-10-25 13:53:47 +02:00
|
|
|
currentBattleSelection = gCurrentBattleSection;
|
|
|
|
temp = D_800DC4EB;
|
2021-04-26 19:47:38 +02:00
|
|
|
|
2021-10-25 13:53:47 +02:00
|
|
|
if (gGameStatusPtr->peachFlags & 1 || (currentBattleSelection == 0x26 && temp == 0)) {
|
2021-04-26 19:47:38 +02:00
|
|
|
gGameStatusPtr->peachFlags |= 1;
|
2021-06-30 04:27:12 +02:00
|
|
|
spr_init_sprites(6);
|
2021-03-19 11:25:14 +01:00
|
|
|
} else {
|
2021-06-30 04:27:12 +02:00
|
|
|
spr_init_sprites(5);
|
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();
|
|
|
|
clear_generic_entity_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();
|
2021-04-23 13:55:30 +02:00
|
|
|
dma_copy(&_16C8E0_ROM_START, &_16C8E0_ROM_END, &_16C8E0_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;
|
2021-11-11 05:30:59 +01:00
|
|
|
gPlayerStatusPtr->animFlags &= ~PLAYER_STATUS_ANIM_FLAGS_40;
|
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();
|
|
|
|
func_80116674();
|
|
|
|
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) {
|
|
|
|
MapConfig* mapConfig;
|
|
|
|
Map* map;
|
|
|
|
|
|
|
|
D_800A0900 = -1;
|
|
|
|
nuGfxSetCfb(D_800778A0, 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();
|
|
|
|
mapConfig = get_current_map_header();
|
|
|
|
map = &gAreas[gGameStatusPtr->areaID].maps[gGameStatusPtr->mapID];
|
|
|
|
btl_restore_world_cameras(gGameStatusPtr);
|
|
|
|
gGameStatusPtr->isBattle = FALSE;
|
|
|
|
func_8005AF84();
|
|
|
|
func_8002ACDC();
|
|
|
|
sfx_clear_env_sounds(1);
|
|
|
|
gGameStatusPtr->peachFlags &= ~0x1;
|
|
|
|
battle_heap_create();
|
|
|
|
spr_init_sprites(gGameStatusPtr->playerSpriteSet);
|
|
|
|
init_model_data();
|
|
|
|
init_sprite_shading_data();
|
|
|
|
init_entity_models();
|
|
|
|
reset_animator_list();
|
|
|
|
init_generic_entity_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();
|
|
|
|
mapShape = load_asset_by_name(&wMapShapeName, &sizeTemp);
|
|
|
|
decode_yay0(mapShape, &D_80210000);
|
|
|
|
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
|
|
|
|
|
|
|
if (map->dmaStart != NULL) {
|
|
|
|
dma_copy(map->dmaStart, map->dmaEnd, map->dmaDest);
|
|
|
|
}
|
|
|
|
|
|
|
|
load_map_bg(map->bgName);
|
|
|
|
if (mapConfig->background != NULL) {
|
|
|
|
read_background_size(mapConfig->background);
|
|
|
|
} else {
|
|
|
|
set_background_size(296, 200, 12, 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
load_model_textures(mapConfig->modelTreeRoot, get_asset_offset(&wMapTexName, &sizeTemp), sizeTemp);
|
|
|
|
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
|
|
|
}
|