papermario/src/state_battle.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

212 lines
6.1 KiB
C
Raw Normal View History

#include "common.h"
#include "nu/nusys.h"
2021-10-18 17:58:32 +02:00
#include "hud_element.h"
#include "ld_addrs.h"
#include "sprite.h"
#include "battle/battle.h"
#include "model.h"
#include "game_modes.h"
Modern gcc + shiftability work (#942) * wip changes for modern gcc * more * wip * blah * Define explicit size for symbol * Clean up evt_handle_exec1 * wip * . * fixes & VLA macro * VLA innit * wipz * Fix potential UB * meowp * meowp2 * fixies * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "e1f0b17917" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "e1f0b17917" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * fixules * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "3ba3277e57" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "3ba3277e57" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * more shiftability + symbols work * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "02879e52a7" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "02879e52a7" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * more * revert bss changes for now, new heaps overlay for aligning stuff to 0x1000 (not sure how necessary that is, so maybe will revert later on) * 'fixing' jp shift build * more * more syms * more progress * more * ididid * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "de54da38f5" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "de54da38f5" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "a27dc436a6" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "a27dc436a6" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * blah * stuff's broken, but at least it's maybe cleaner * modern gcc back * revert * shifting all overlays - works so far * progs * another * modern gcc flag, re-enabled all ifdef shift stuff * fixies * progress * fixes, matching build * heaps3 overlay and some symbol names * changies * PR comments & cleanup
2023-02-14 14:14:14 +01:00
extern u16 gFrameBuf0[];
extern u16 gFrameBuf1[];
extern u16 gFrameBuf2[];
Modern gcc + shiftability work (#942) * wip changes for modern gcc * more * wip * blah * Define explicit size for symbol * Clean up evt_handle_exec1 * wip * . * fixes & VLA macro * VLA innit * wipz * Fix potential UB * meowp * meowp2 * fixies * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "e1f0b17917" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "e1f0b17917" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * fixules * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "3ba3277e57" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "3ba3277e57" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * more shiftability + symbols work * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "02879e52a7" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "02879e52a7" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * more * revert bss changes for now, new heaps overlay for aligning stuff to 0x1000 (not sure how necessary that is, so maybe will revert later on) * 'fixing' jp shift build * more * more syms * more progress * more * ididid * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "de54da38f5" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "de54da38f5" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "a27dc436a6" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "a27dc436a6" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * blah * stuff's broken, but at least it's maybe cleaner * modern gcc back * revert * shifting all overlays - works so far * progs * another * modern gcc flag, re-enabled all ifdef shift stuff * fixies * progress * fixes, matching build * heaps3 overlay and some symbol names * changies * PR comments & cleanup
2023-02-14 14:14:14 +01:00
u16* bFrameBuffers[] = {
gFrameBuf0, gFrameBuf1, gFrameBuf2
};
s32 D_800778AC[] = {
0x00000000, 0xFFFFFF00, 0xFFFFFF00, 0x00000000, 0x00000000
};
BSS s8 D_800A0900;
BSS s32 D_800A0904;
BSS s32 D_800A0908;
2020-08-04 08:49:11 +02:00
#if defined(SHIFT) || VERSION_IQUE
Modern gcc + shiftability work (#942) * wip changes for modern gcc * more * wip * blah * Define explicit size for symbol * Clean up evt_handle_exec1 * wip * . * fixes & VLA macro * VLA innit * wipz * Fix potential UB * meowp * meowp2 * fixies * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "e1f0b17917" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "e1f0b17917" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * fixules * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "3ba3277e57" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "3ba3277e57" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * more shiftability + symbols work * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "02879e52a7" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "02879e52a7" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * more * revert bss changes for now, new heaps overlay for aligning stuff to 0x1000 (not sure how necessary that is, so maybe will revert later on) * 'fixing' jp shift build * more * more syms * more progress * more * ididid * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "de54da38f5" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "de54da38f5" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "a27dc436a6" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "a27dc436a6" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * blah * stuff's broken, but at least it's maybe cleaner * modern gcc back * revert * shifting all overlays - works so far * progs * another * modern gcc flag, re-enabled all ifdef shift stuff * fixies * progress * fixes, matching build * heaps3 overlay and some symbol names * changies * PR comments & cleanup
2023-02-14 14:14:14 +01:00
#define shim_battle_heap_create_obfuscated battle_heap_create
#endif
extern ShapeFile gMapShapeData;
void state_init_battle(void) {
D_800A0900 = 5;
}
2020-08-04 08:49:11 +02:00
void state_step_battle(void) {
u32 currentBattleSelection;
u32 currentBattleIndex;
if (D_800A0900 == 5) {
if (nuGfxCfb[1] != nuGfxCfb_ptr) {
return;
}
D_800A0900--;
gOverrideFlags |= GLOBAL_OVERRIDES_DISABLE_DRAW_FRAME;
nuContRmbForceStop();
}
if (D_800A0900 >= 0) {
if (D_800A0900 > 0) {
D_800A0900--;
return;
}
D_800A0900 = -1;
nuGfxSetCfb(bFrameBuffers, 2);
nuContRmbForceStopEnd();
sfx_stop_env_sounds();
func_8003B1A8();
gGameStatusPtr->isBattle = TRUE;
backup_map_collision_data();
#if !VERSION_IQUE
load_obfuscation_shims();
#endif
shim_battle_heap_create_obfuscated();
sfx_clear_env_sounds(0);
currentBattleSelection = UNPACK_BTL_AREA(gCurrentBattleID);
currentBattleIndex = UNPACK_BTL_INDEX(gCurrentBattleID);
if (gGameStatusPtr->peachFlags & PEACH_FLAG_IS_PEACH ||
(currentBattleSelection == BTL_AREA_KKJ && currentBattleIndex == 0)) {
gGameStatusPtr->peachFlags |= PEACH_FLAG_IS_PEACH;
spr_init_sprites(PLAYER_SPRITES_PEACH_BATTLE);
} else {
spr_init_sprites(PLAYER_SPRITES_MARIO_BATTLE);
}
clear_model_data();
clear_sprite_shading_data();
reset_background_settings();
clear_entity_models();
clear_animator_list();
clear_worker_list();
hud_element_set_aux_cache(NULL, 0);
hud_element_clear_cache();
reset_status_bar();
clear_item_entity_data();
clear_script_list();
clear_npcs();
clear_entity_data(TRUE);
clear_trigger_data();
DMA_COPY_SEGMENT(battle_code);
initialize_battle();
btl_save_world_cameras();
load_battle_section();
D_800A0904 = gPlayerStatusPtr->animFlags;
gPlayerStatusPtr->animFlags &= ~PA_FLAG_PULSE_STONE_VISIBLE;
D_800A0908 = get_time_freeze_mode();
set_time_freeze_mode(TIME_FREEZE_NORMAL);
gOverrideFlags &= ~GLOBAL_OVERRIDES_DISABLE_DRAW_FRAME;
if (D_800A0900 >= 0) {
return;
}
}
update_encounters();
btl_update();
update_npcs();
update_item_entities();
update_effects();
iterate_models();
update_cameras();
}
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) {
btl_draw_ui();
2020-08-15 09:01:33 +02:00
}
}
void state_init_end_battle(void) {
gOverrideFlags |= GLOBAL_OVERRIDES_DISABLE_DRAW_FRAME;
2020-08-15 09:01:33 +02:00
nuContRmbForceStop();
D_800A0900 = 5;
}
void state_step_end_battle(void) {
PlayerStatus* playerStatus = &gPlayerStatus;
PlayerData* playerData = &gPlayerData;
MapSettings* mapSettings;
MapConfig* mapConfig;
if (D_800A0900 >= 0) {
D_800A0900--;
if (D_800A0900 == 0) {
D_800A0900 = -1;
Modern gcc + shiftability work (#942) * wip changes for modern gcc * more * wip * blah * Define explicit size for symbol * Clean up evt_handle_exec1 * wip * . * fixes & VLA macro * VLA innit * wipz * Fix potential UB * meowp * meowp2 * fixies * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "e1f0b17917" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "e1f0b17917" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * fixules * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "3ba3277e57" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "3ba3277e57" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * more shiftability + symbols work * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "02879e52a7" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "02879e52a7" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * more * revert bss changes for now, new heaps overlay for aligning stuff to 0x1000 (not sure how necessary that is, so maybe will revert later on) * 'fixing' jp shift build * more * more syms * more progress * more * ididid * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "de54da38f5" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "de54da38f5" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "a27dc436a6" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "a27dc436a6" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * blah * stuff's broken, but at least it's maybe cleaner * modern gcc back * revert * shifting all overlays - works so far * progs * another * modern gcc flag, re-enabled all ifdef shift stuff * fixies * progress * fixes, matching build * heaps3 overlay and some symbol names * changies * PR comments & cleanup
2023-02-14 14:14:14 +01:00
nuGfxSetCfb(bFrameBuffers, 3);
gOverrideFlags &= ~GLOBAL_OVERRIDES_DISABLE_DRAW_FRAME;
nuContRmbForceStopEnd();
sfx_stop_env_sounds();
mapSettings = get_current_map_settings();
mapConfig = &gAreas[gGameStatusPtr->areaID].maps[gGameStatusPtr->mapID];
btl_restore_world_cameras();
gGameStatusPtr->isBattle = FALSE;
func_8005AF84();
func_8002ACDC();
sfx_clear_env_sounds(1);
gGameStatusPtr->peachFlags &= ~PEACH_FLAG_IS_PEACH;
battle_heap_create();
spr_init_sprites(gGameStatusPtr->playerSpriteSet);
init_model_data();
init_sprite_shading_data();
init_entity_models();
reset_animator_list();
init_worker_list();
hud_element_set_aux_cache(0, 0);
init_hud_element_list();
init_item_entity_list();
init_script_list();
init_npc_list();
init_entity_data();
init_trigger_list();
if (gGameStatusPtr->demoBattleFlags & DEMO_BTL_FLAG_ENABLED) {
npc_reload_all();
playerStatus->animFlags = D_800A0904;
set_game_mode(GAME_MODE_DEMO);
} else {
void* mapShape;
u32 sizeTemp;
partner_init_after_battle(playerData->curPartner);
load_map_script_lib();
mapShape = load_asset_by_name(wMapShapeName, &sizeTemp);
Modern gcc + shiftability work (#942) * wip changes for modern gcc * more * wip * blah * Define explicit size for symbol * Clean up evt_handle_exec1 * wip * . * fixes & VLA macro * VLA innit * wipz * Fix potential UB * meowp * meowp2 * fixies * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "e1f0b17917" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "e1f0b17917" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * fixules * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "3ba3277e57" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "3ba3277e57" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * more shiftability + symbols work * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "02879e52a7" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "02879e52a7" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * more * revert bss changes for now, new heaps overlay for aligning stuff to 0x1000 (not sure how necessary that is, so maybe will revert later on) * 'fixing' jp shift build * more * more syms * more progress * more * ididid * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "de54da38f5" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "de54da38f5" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "a27dc436a6" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "a27dc436a6" git-subrepo: version: "0.4.5" origin: "https://github.com/ingydotnet/git-subrepo" commit: "aa416e4" * blah * stuff's broken, but at least it's maybe cleaner * modern gcc back * revert * shifting all overlays - works so far * progs * another * modern gcc flag, re-enabled all ifdef shift stuff * fixies * progress * fixes, matching build * heaps3 overlay and some symbol names * changies * PR comments & cleanup
2023-02-14 14:14:14 +01:00
decode_yay0(mapShape, &gMapShapeData);
general_heap_free(mapShape);
initialize_collision();
restore_map_collision_data();
if (mapConfig->dmaStart != NULL) {
dma_copy(mapConfig->dmaStart, mapConfig->dmaEnd, mapConfig->dmaDest);
}
load_map_bg(mapConfig->bgName);
if (mapSettings->background != NULL) {
set_background(mapSettings->background);
} else {
set_background_size(296, 200, 12, 20);
}
mdl_load_all_textures(mapSettings->modelTreeRoot, get_asset_offset(wMapTexName, &sizeTemp), sizeTemp);
mdl_calculate_model_sizes();
npc_reload_all();
playerStatus->animFlags = D_800A0904;
if (D_800A0908 != 0) {
set_time_freeze_mode(D_800A0908);
}
set_game_mode(GAME_MODE_WORLD);
}
}
}
}
2020-08-15 09:01:33 +02:00
void state_drawUI_end_battle(void) {
2020-08-18 18:43:55 +02:00
}