From 34ba7d6cff3967f0d7d819772b3720b5312c27ec Mon Sep 17 00:00:00 2001 From: MokhaLeee Date: Thu, 11 Jul 2024 11:59:12 +0800 Subject: [PATCH 1/7] review on mu in process --- include/constants/songs.h | 139 ++++++ include/mu.h | 226 +++++---- include/types.h | 6 - include/variables.h | 34 +- ldscript.txt | 30 +- src/bmsave-misc.c | 55 +-- src/mu.c | 982 ++++++++++++++++---------------------- src/worldmap_gmapunit.c | 5 +- 8 files changed, 745 insertions(+), 732 deletions(-) create mode 100644 include/constants/songs.h diff --git a/include/constants/songs.h b/include/constants/songs.h new file mode 100644 index 000000000..3aa06849f --- /dev/null +++ b/include/constants/songs.h @@ -0,0 +1,139 @@ +#pragma once + +enum song_idx { + SONG_01 = 0x01, + SONG_02 = 0x02, + SONG_03 = 0x03, + SONG_04 = 0x04, + SONG_05 = 0x05, + SONG_06 = 0x06, + SONG_09 = 0x09, + SONG_0A = 0x0A, + SONG_0C = 0x0C, + SONG_0E = 0x0E, + SONG_0F = 0x0F, + SONG_11 = 0x11, + SONG_12 = 0x12, + SONG_13 = 0x13, + SONG_14 = 0x14, + SONG_22 = 0x22, + SONG_23 = 0x23, + SONG_24 = 0x24, + SONG_25 = 0x25, + SONG_26 = 0x26, + SONG_27 = 0x27, + SONG_28 = 0x28, + SONG_29 = 0x29, + SONG_2A = 0x2A, + SONG_2B = 0x2B, + SONG_2C = 0x2C, + SONG_31 = 0x31, + SONG_32 = 0x32, + SONG_33 = 0x33, + SONG_34 = 0x34, + SONG_37 = 0x37, + SONG_3B = 0x3B, + SONG_3C = 0x3C, + SONG_3D = 0x3D, + SONG_3E = 0x3E, + SONG_3F = 0x3F, + SONG_43 = 0x43, + SONG_44 = 0x44, + SONG_45 = 0x45, + SONG_5A = 0x5A, + SONG_5B = 0x5B, + SONG_5C = 0x5C, + SONG_60 = 0x60, // save success + SONG_61 = 0x61, + SONG_65 = 0x65, + SONG_66 = 0x66, + SONG_67 = 0x67, // change selection in menu/help box + SONG_68 = 0x68, + SONG_69 = 0x69, + SONG_6A = 0x6A, + SONG_6B = 0x6B, + SONG_6C = 0x6C, + SONG_6E = 0x6E, + SONG_6F = 0x6F, // stat screen page slide + SONG_70 = 0x70, // help box open + SONG_71 = 0x71, // help box close + SONG_73 = 0x73, + SONG_74 = 0x74, // exp bar thingy + SONG_75 = 0x75, + SONG_76 = 0x76, + SONG_77 = 0x77, + SONG_78 = 0x78, // open minimap + SONG_79 = 0x79, // close minimap + SONG_7A = 0x7A, + SONG_7B = 0x7B, // sioerror + SONG_82 = 0x82, // manim + SONG_83 = 0x83, // manim + SONG_84 = 0x84, // manim + SONG_85 = 0x85, // manim + SONG_86 = 0x86, + SONG_87 = 0x87, + SONG_88 = 0x88, // manim + SONG_89 = 0x89, + SONG_8A = 0x8A, // manim + SONG_8B = 0x8B, // manim + SONG_8C = 0x8C, + SONG_8D = 0x8D, // manim (unlock?) + SONG_90 = 0x90, + SONG_91 = 0x91, + SONG_96 = 0x96, + SONG_97 = 0x97, + SONG_9A = 0x9A, + SONG_9B = 0x9B, + SONG_9C = 0x9C, + SONG_A0 = 0xA0, + SONG_A4 = 0xA4, + SONG_A5 = 0xA5, + SONG_A6 = 0xA6, + SONG_A8 = 0xA8, // dance sfx + SONG_A9 = 0xA9, // play (bard) sfx + SONG_AA = 0xAA, + SONG_AB = 0xAB, + SONG_AC = 0xAC, + SONG_AF = 0xAF, // obstacle destroy (end) + SONG_B0 = 0xB0, // obstacle destroy (mid) + SONG_B1 = 0xB1, + SONG_B3 = 0xB3, + SONG_B4 = 0xB4, // manim + SONG_B5 = 0xB5, // manim + SONG_B6 = 0xB6, + SONG_B7 = 0xB7, // manim poison + SONG_BA = 0xBA, + SONG_BB = 0xBB, + SONG_BC = 0xBC, + SONG_BD = 0xBD, // chapter 14x timed map change sound A + SONG_BE = 0xBE, // chapter 14x timed map change sound B + SONG_BF = 0xBF, + SONG_C4 = 0xC4, + SONG_C6 = 0xC6, + SONG_C8 = 0xC8, // stat screen unit slide, also miss + SONG_D2 = 0xD2, + SONG_D5 = 0xD5, + SONG_D6 = 0xD6, + SONG_D8 = 0xD8, // crit? + SONG_EC = 0xEC, // no damage + SONG_FD = 0xFD, // manim + SONG_10F = 0x10F, + SONG_269 = 0x269, + SONG_26A = 0x26A, + SONG_2E0 = 0x2E0, + SONG_302 = 0x302, + SONG_303 = 0x303, + SONG_304 = 0x304, + SONG_305 = 0x305, + SONG_306 = 0x306, + SONG_307 = 0x307, + SONG_308 = 0x308, + SONG_309 = 0x309, + SONG_30A = 0x30A, + SONG_30B = 0x30B, + SONG_30C = 0x30C, + SONG_30D = 0x30D, + SONG_30E = 0x30E, + SONG_30F = 0x30F, + SONG_3BB = 0x3BB, +}; diff --git a/include/mu.h b/include/mu.h index 6b409b45a..f32312a5d 100644 --- a/include/mu.h +++ b/include/mu.h @@ -31,20 +31,22 @@ enum { MU_SUBPIXEL_PRECISION = 4, }; -enum { +enum +{ // Possible MU States - MU_STATE_NOSTATE, - MU_STATE_NONACTIVE, + MU_STATE_NONE, + MU_STATE_INACTIVE, MU_STATE_MOVEMENT, - MU_STATE_WAITING, + MU_STATE_SLEEPING, MU_STATE_UNK4, MU_STATE_BUMPING, - MU_STATE_UI_DISPLAY, + MU_STATE_DISPLAY_UI, MU_STATE_DEATHFADE, }; -enum { +enum +{ // MU command identifiers MU_COMMAND_END = -1, // end @@ -74,7 +76,8 @@ enum { MU_COMMAND_CAMERA_OFF, }; -enum { +enum +{ // MU facing identifiers MU_FACING_LEFT = FACING_LEFT, @@ -90,15 +93,16 @@ enum { MU_FACING_STANDING = 15, }; -enum { +enum +{ // MU flash identifiers - MU_FLASH_0, - MU_FLASH_1, - MU_FLASH_2, - MU_FLASH_3, - MU_FLASH_4, - MU_FLASH_5, + MU_FLASH_WHITE, + MU_FLASH_BLACK, + MU_FLASH_RED, + MU_FLASH_GREEN, + MU_FLASH_BLUE, + MU_FLASH_YELLOW, }; struct MUConfig; @@ -131,6 +135,10 @@ struct MUProc { /* 52 */ short ySubOffset; }; +#define MU_GetDisplayXOrg(proc) ((((proc)->xSubPosition + (proc)->xSubOffset) >> MU_SUBPIXEL_PRECISION) + 8) +#define MU_GetDisplayYOrg(proc) ((((proc)->ySubPosition + (proc)->ySubOffset) >> MU_SUBPIXEL_PRECISION) + 8) + + struct MUConfig { /* 00 */ u8 muIndex; /* 01 */ u8 paletteIndex; @@ -138,9 +146,11 @@ struct MUConfig { /* 04 */ u8 currentCommand; /* 05 */ s8 commands[MU_COMMAND_MAX_COUNT]; /* 45 */ // 3 byte padding - /* 48 */ struct MUProc* pMUProc; + /* 48 */ struct MUProc * pMUProc; }; +#define MU_AdvanceGetCommand(proc) (proc->pMUConfig->commands[proc->pMUConfig->currentCommand++]) + struct MUStepSoundProc { PROC_HEADER; @@ -188,96 +198,138 @@ struct MUFlashEffectProc /* 30 */ u8 timer; }; -typedef void(*MUStateHandlerFunc)(struct MUProc*); - -extern struct ProcCmd CONST_DATA gProcScr_MoveUnit[]; -extern struct ProcCmd CONST_DATA gProcScr_MUDeathFade[]; -extern struct ProcCmd CONST_DATA gProcScr_MUBlinkEffect[]; -extern struct ProcCmd CONST_DATA gProcScr_MU_89A2CF8[]; +struct MuInfo { + const void * img; + const void * anim; +}; -// Buffer for MU graphics -// what to do with this? -extern u8 gMUGfxBuffer[]; +extern CONST_DATA struct MuInfo unit_icon_move_table[]; +#define gMuInfoTable unit_icon_move_table -// FUNCTIONS +typedef void (* MuStateFunc)(struct MUProc *); void MU_Init(); - -struct MUProc* MU_CreateExt(struct Unit* pUnit, unsigned classIndex, unsigned palId); -struct MUProc* MU_Create(struct Unit* pUnit); - -void MU_ManualUpdate(struct MUProc* proc); - -void MU_EnableAttractCamera(struct MUProc* proc); -void MU_DisableAttractCamera(struct MUProc* proc); - -struct MUProc* MU_CreateForUI(struct Unit* pUnit, int x, int y); - -void MU_8078524(struct MUProc* proc); - -void MU_SetFacing(struct MUProc* proc, int facingId); -void MU_SetDefaultFacing(struct MUProc* proc); +struct MUProc * MU_CreateExt(struct Unit* pUnit, unsigned jid, unsigned palId); +struct MUProc * MU_Create(struct Unit* pUnit); +void MU_ManualUpdate(struct MUProc * proc); +void MU_EnableAttractCamera(struct MUProc * proc); +void MU_DisableAttractCamera(struct MUProc * proc); +struct MUProc * MU_CreateForUI(struct Unit* pUnit, int x, int y); +void MU_8078524(struct MUProc * proc); +struct MUProc * MU_CreateInternal(u16 x, u16 y, u16 jid, int objTileId, unsigned palId); +void MU_SetFacing(struct MUProc * proc, int facingId); +void MU_SetDefaultFacing(struct MUProc * proc); void MU_SetDefaultFacing_Auto(void); void MU_StartMoveScript_Auto(const u8 commands[MU_COMMAND_MAX_COUNT]); - s8 MU_Exists(void); s8 MU_IsAnyActive(void); - -s8 MU_IsActive(struct MUProc* proc); -void MU_StartMoveScript(struct MUProc* proc, const u8 commands[MU_COMMAND_MAX_COUNT]); - -struct MUProc* MU_CreateScripted(u16 x, u16 y, u16 classIndex, unsigned palId, const u8 commands[MU_COMMAND_MAX_COUNT]); - +s8 MU_IsActive(struct MUProc * proc); +void MU_StartMoveScript(struct MUProc * proc, const u8 commands[MU_COMMAND_MAX_COUNT]); +struct MUProc * MU_CreateScripted(u16 x, u16 y, u16 jid, unsigned palId, const u8 commands[MU_COMMAND_MAX_COUNT]); +void MuStepSe_Init(struct MUStepSoundProc * proc); +void MuStepSe_PlaySeA(struct MUStepSoundProc * proc); +void MuStepSe_PlaySeB(struct MUStepSoundProc * proc); void MU_StartStepSfx(int soundId, int b, int hPosition); - -void MU_PlayStepSfx(struct MUProc* proc); - +void MU_PlayStepSfx(struct MUProc * proc); +void MU_8078894(struct MUProc * proc); +void MU_InterpretCommandScript(struct MUProc * proc); void MU_StartFogBumpFx(int x, int y); +void MuFogBump_Init(struct MUFogBumpFxProc * proc); +void MuFogBump_ScaleLoop(struct MUFogBumpFxProc * proc); +void MuFogBump_EndLoop(struct MUFogBumpFxProc * proc); u8 MU_IsFogBumpFxActive(void); - +void Mu_OnStateBump(struct MUProc * proc); +void Mu_OnStateMoving(struct MUProc * proc); +void Mu_OnStateSleeping(struct MUProc * proc); +void Mu_OnStateNone(struct MUProc * proc); +void Mu_OnStateDoNothing(struct MUProc * proc); +void Mu_OnStateMovement(struct MUProc * proc); +void MU_AdvanceStepSfx(struct MUProc * proc); +void MU_OnLoop(struct MUProc * proc); +void MU_OnEnd(struct MUProc * proc); void MU_EndAll(void); -void MU_End(struct MUProc* proc); - +void MU_End(struct MUProc * proc); +void MU_EndInternal(struct MUProc * proc); +void MU_80790CC(struct MUProc * proc); void MU_AllDisable(void); void MU_AllEnable(void); - -void MU_GetComputedEndPosition(int* xOut, int* yOut, const u8* commands); - +void MU_GetComputedEndPosition(int * xOut, int * yOut, const u8 * commands); s8 MU_CanStart(void); - void MU_AllRestartAnimations(void); - -u8 MU_ComputeDisplayPosition(struct MUProc* proc, struct Vec2* out); - -void MU_SetMoveConfig(struct MUProc* proc, u16 config); - -void MU_StartDeathFade(struct MUProc* muProc); -void MU_StartBlinkEffect(struct MUProc* muProc); -void MU_StartPixelEffect(struct MUProc* muProc); - -void MU_Hide(struct MUProc* proc); -void MU_Show(struct MUProc* proc); - -void MU_SetDisplayPosition(struct MUProc* proc, int x, int y); -void MU_SetDisplayOffset(struct MUProc* proc, int xOff, int yOff); - -void MU_StartFlashFade(struct MUProc* proc, int flashType); -void MU_8079858(struct MUProc* muProc); - -void MU_StartActionAnim(struct MUProc* proc); -void MU_StartDelayedFaceTarget(struct MUProc* proc); -void MU_StartFastMoveAnim(struct MUProc* proc); -void MU_StartCritFlash(struct MUProc* muProc, int flashType); -void MU_StartHitFlash(struct MUProc* muProc, int flashType); - +static struct MUConfig * MU_GenerateConfigDefault(int objTileId, u8 * outIndex); +static struct MUConfig * MU_GenerateConfigOther(int objTileId, u8 * outIndex); +u8 MU_ComputeDisplayPosition(struct MUProc * proc, struct Vec2 * out); +void MU_DisplayAsSMS(struct MUProc * proc); +void MU_DisplayAsMMS(struct MUProc * proc); +u16 MU_GetMovementSpeed(struct MUProc * proc); +void MU_SetMoveConfig(struct MUProc * proc, u16 config); +void* MU_GetGfxBufferById(int muIndex); +const void * MU_GetSheetGfx(struct MUProc * proc); +const void * MU_GetAnimationByClassId(u16 classId); +void MU_StartDeathFade(struct MUProc * muProc); +void MU_DeathFade_OnLoop(struct MUEffectProc * proc); +void MU_BlinkEffect_OnLoop(struct MUEffectProc * proc); +void MU_StartBlinkEffect(struct MUProc * muProc); +void MU_SetupPixelEffect(u32* data, int frame); +void MU_PixelEffect_OnLoop(struct MUEffectProc * proc); +void MU_StartPixelEffect(struct MUProc * muProc); +void MU_Hide(struct MUProc * proc); +void MU_Show(struct MUProc * proc); +void MU_SetDisplayPosition(struct MUProc * proc, int x, int y); +void MU_SetDisplayOffset(struct MUProc * proc, int xOff, int yOff); +void MU_StartFlashFade(struct MUProc * proc, int flashType); +void MU_8079858(struct MUProc * muProc); +void MU_807988C(struct MUEffectProc * proc); +void MU_StartActionAnim(struct MUProc * proc); +void MU_EndSelectionApAnim(int argAp); +void MU_StartDelayedFaceTarget(struct MUProc * proc); +void MU_EndRefaceApAnim(int argAp); +void MU_EndFasterApAnim(int argAp); +void MU_StartFastMoveAnim(struct MUProc * proc); +void MU_StartCritFlash(struct MUProc * muProc, int flashType); +void MU_CritFlash_Init(struct MUFlashEffectProc * proc); +void MU_CritFlash_SetFadedPalette(struct MUFlashEffectProc * proc); +void MU_CritFlash_SetRegularPalette(struct MUFlashEffectProc * proc); +void MU_CritFlash_StartFadeBack_maybe(struct MUFlashEffectProc * proc); +void MU_CritFlash_SpriteShakeLoop(struct MUFlashEffectProc * proc); +void MU_CritFlash_RestorePalette(struct MUFlashEffectProc * proc); +void MU_StartHitFlash(struct MUProc * muProc, int flashType); +void MU_HitFlash_RestorePalette(struct MUFlashEffectProc * proc); void MU_AllForceSetMaxMoveSpeed(void); +void MU_ForceSetMaxMoveSpeed(ProcPtr proc); +void MU_SetSpecialSprite(struct MUProc * proc, int displayedClassId, const u16 * palette); +void MU_SetPaletteId(struct MUProc * proc, unsigned paletteId); +struct MUProc * MU_GetByIndex(int muIndex); +struct MUProc * MU_GetByUnit(struct Unit* unit); +void MU_SortObjLayers(void); -void MU_SetSpecialSprite(struct MUProc* proc, int displayedClassId, const u16* palette); - -void MU_SetPaletteId(struct MUProc* proc, unsigned paletteId); - -struct MUProc* MU_GetByUnit(struct Unit* unit); +extern u8 gMUGfxBuffer[MU_GFX_MAX_SIZE * MU_MAX_COUNT]; -void MU_SortObjLayers(void); +extern struct ProcCmd CONST_DATA gProcScr_MoveUnit[]; +extern struct ProcCmd CONST_DATA gProcScr_MUDeathFade[]; +extern struct ProcCmd CONST_DATA gProcScr_MUBlinkEffect[]; +extern struct ProcCmd CONST_DATA gProcScr_MU_89A2CF8[]; +extern u16 CONST_DATA MuSoundScr_Foot[]; +extern u16 CONST_DATA MuSoundScr_FootHeavy[]; +extern u16 CONST_DATA MuSoundScr_Mounted[]; +extern u16 CONST_DATA MuSoundScr_Wyvern[]; +extern u16 CONST_DATA MuSoundScr_Pegasus[]; +extern u16 CONST_DATA MuSoundScr_Unused1[]; +extern u16 CONST_DATA MuSoundScr_Zombie[]; +extern u16 CONST_DATA MuSoundScr_Skeleton[]; +extern u16 CONST_DATA MuSoundScr_Mogall[]; +extern u16 CONST_DATA MuSoundScr_Spider[]; +extern u16 CONST_DATA MuSoundScr_Dog[]; +extern u16 CONST_DATA MuSoundScr_Gorgon[]; +extern u16 CONST_DATA MuSoundScr_Unused2[]; +extern u16 CONST_DATA MuSoundScr_Boat[]; +extern u16 CONST_DATA MuSoundScr_Myrrh[]; +// extern ??? gUnknown_089A2C28 +// extern ??? gProcScr_MoveUnit +extern CONST_DATA struct ProcCmd gProcScr_MUDeathFade[]; +extern CONST_DATA struct ProcCmd gProcScr_MUBlinkEffect[]; +extern CONST_DATA struct ProcCmd gProcScr_MU_89A2CF8[]; + +extern const u16 * CONST_DATA MUFlashColorLookup[]; #endif // GUARD_MU_H diff --git a/include/types.h b/include/types.h index f92776a50..c6bce8e84 100644 --- a/include/types.h +++ b/include/types.h @@ -381,12 +381,6 @@ struct SMSHandle /* 0B */ s8 config; }; -struct MMSData -{ - const void* pGraphics; - const void* pAnimation; -}; - struct MapChange { /* 00 */ s8 id; diff --git a/include/variables.h b/include/variables.h index 7c38df0e6..187048c23 100644 --- a/include/variables.h +++ b/include/variables.h @@ -55,7 +55,7 @@ extern u16 gUiTmScratchC[]; // extern ??? gMUGfxBuffer // extern ??? gUnknown_02007838 // extern ??? gUnknown_020078D8 -// extern ??? gUnknown_02008000 +// extern ??? sGameStartSaveBuf // extern ??? gUnknown_020087A0 // extern ??? gUnknown_0200A2D8 // extern ??? gUnknown_0200A300 @@ -824,38 +824,6 @@ extern u16 CONST_DATA Pal_MapClear[]; /* a palatte */ extern u8 gUnknown_089A234C[]; // "combat record" img extern u8 gUnknown_089A27B4[]; // "combat record" tsa extern u16 gUnknown_089A28E0[]; // "combat record" pal -// extern ??? gUnknown_089A2920 -// extern ??? gUnknown_089A2938 -// extern ??? gUnknown_089A2968 -// extern ??? gUnknown_089A2988 -// extern ??? gMUSfxDef_Foot -// extern ??? gMUSfxDef_Heavy -// extern ??? gMUSfxDef_Mounted -// extern ??? gMUSfxDef_Wyvern -// extern ??? gMUSfxDef_Pegasus -// extern ??? gMUSfxDef_Zombie -// extern ??? gMUSfxDef_Skeleton -// extern ??? gMUSfxDef_Mogall -// extern ??? gMUSfxDef_Spider -// extern ??? gMUSfxDef_Dog -// extern ??? gMUSfxDef_Gorgon -// extern ??? gMUSfxDef_Boat -// extern ??? gMUSfxDef_Myrrh -// extern ??? gUnknown_089A2C28 -// extern ??? gProcScr_MoveUnit -// extern ??? gUnknown_089A2C68 -// extern ??? gUnknown_089A2C70 -// extern ??? gUnknown_089A2C78 -// extern ??? gUnknown_089A2C7A -extern CONST_DATA struct ProcCmd gProcScr_MUDeathFade[]; -extern CONST_DATA struct ProcCmd gProcScr_MUBlinkEffect[]; -// extern ??? gUnknown_089A2CA8 -// extern ??? gUnknown_089A2CE8 -extern CONST_DATA struct ProcCmd gProcScr_MU_89A2CF8[]; -// extern ??? gUnknown_089A2D10 -// extern ??? gUnknown_089A2D98 -#define gMMSDataTable unit_icon_move_table -extern CONST_DATA struct MMSData gMMSDataTable[]; // Moving Map Sprite Table // extern ??? Img_TalkBubble extern u16 Pal_TalkBubble[]; diff --git a/ldscript.txt b/ldscript.txt index 2e7210309..524499d00 100644 --- a/ldscript.txt +++ b/ldscript.txt @@ -70,16 +70,7 @@ SECTIONS . = 0x003BFC; . = ALIGN(4); src/statscreen.o(ewram_overlay_0); . = ALIGN(4); src/uichapterstatus.o(ewram_overlay_0); - . = 0x004BE0; gMUGfxBuffer = .; - . = 0x007838; gUnknown_02007838 = .; - . = 0x0078D8; gUnknown_020078D8 = .; - . = 0x008000; gUnknown_02008000 = .; - . = 0x0087A0; gUnknown_020087A0 = .; - . = 0x00A2D8; gUnknown_0200A2D8 = .; - . = 0x00A300; gUnknown_0200A300 = .; - . = 0x00AF00; gUnknown_0200AF00 = .; - . = 0x00C300; gUnknown_0200C300 = .; - . = 0x00CB00; gUnknown_0200CB00 = .; + . = ALIGN(4); src/mu.o(ewram_overlay_0); . = 0x00D3E0; gSortedUnitsBuf = .; . = 0x00D6E0; gSortedUnits = .; . = 0x00D7E0; gUnknown_0200D7E0 = .; @@ -149,10 +140,22 @@ SECTIONS . = 0x01F19C; gSoundRoomVolumeGraphBuffer = .; } + ewram_overlay_gamestartsave __ewram_start (NOLOAD) : ALIGN(4) + { + . = 0x008000; + . = ALIGN(4); src/bmsave-misc.o(ewram_overlay_gamestartsave); + } + ewram_overlay_gamestart __ewram_start (NOLOAD) : ALIGN(4) { . = 0x000000; . = ALIGN(4); src/opinfo.o(ewram_overlay_gamestart); + . = 0x007838; gUnknown_02007838 = .; + . = 0x0078D8; gUnknown_020078D8 = .; + . = 0x00A2D8; gUnknown_0200A2D8 = .; + . = 0x00A300; gUnknown_0200A300 = .; + . = 0x00C300; gUnknown_0200C300 = .; + . = 0x00CB00; gUnknown_0200CB00 = .; . = 0x01CDD4; gUnk_OpSubtitle_0201CDD4 = .; . = 0x01DB00; gUnk_Opinfo_0201DB00 = .; . = 0x01DB28; gUnk_OpInfo_0201DB28 = .; @@ -183,6 +186,13 @@ SECTIONS . = 0x001188; gUnk_Sio_02001188 = .; } + ewram_overlay_worldmap __ewram_start (NOLOAD) : ALIGN(4) + { + . = 0x000000; + . = 0x0087A0; gUnknown_020087A0 = .; + . = 0x00AF00; gUnknown_0200AF00 = .; + } + ewram_data __ewram_start (NOLOAD) : ALIGN(4) { . = 0x20188; gGenericBuffer = .; /* TODO: is this part of hardware.o ? */ diff --git a/src/bmsave-misc.c b/src/bmsave-misc.c index 27f55719c..83ea60c54 100644 --- a/src/bmsave-misc.c +++ b/src/bmsave-misc.c @@ -6,6 +6,8 @@ #include "bonusclaim.h" #include "bmsave.h" +EWRAM_OVERLAY(gamestartsave) u8 sGameStartSaveBuf[0x8000] = { 0 }; + //! FE8U = 0x080A720C void CopyGlobalSaveInfo(struct GlobalSaveInfo * src, struct GlobalSaveInfo * dst) { @@ -94,8 +96,6 @@ void sub_80A7360(struct GameRankSaveDataPacks* src, struct GameRankSaveDataPacks return; } -extern u8 gUnknown_02008000[]; - //! FE8U = 0x080A7374 void EraseInvalidSaveData(void) { @@ -127,42 +127,43 @@ void EraseInvalidSaveData(void) WriteGlobalSaveInfo(&((struct SaveBlocksEwram*)((void *)ewram + 0x8000))->globalSaveInfo); /* Erase the suspand data */ - for (i = 0; i < 2; i++) { + for (i = 0; i < 2; i++) + { CpuFastFill(0, (void *)ewram + 0x8000, sizeof(struct SuspendSaveBlock)); sub_80A72B0(&ewram_->suspendSaveBlocks[i], (void *)ewram + 0x8000); WriteAndVerifySramFast((void *)ewram + 0x8000, &sram->suspendSaveBlocks[i], sizeof(struct SuspendSaveBlock)); } /* Erase the save data */ - for (i = 0; i < 3; i++) { - CpuFastFill(0, gUnknown_02008000, sizeof(struct GameSaveBlock)); - sub_80A72EC(&ewram_->gameSaveBlocks[i], (struct GameSaveBlock*)gUnknown_02008000); - WriteAndVerifySramFast(gUnknown_02008000, &sram->gameSaveBlocks[i], sizeof(struct GameSaveBlock)); + for (i = 0; i < 3; i++) + { + CpuFastFill(0, sGameStartSaveBuf, sizeof(struct GameSaveBlock)); + sub_80A72EC(&ewram_->gameSaveBlocks[i], (struct GameSaveBlock*)sGameStartSaveBuf); + WriteAndVerifySramFast(sGameStartSaveBuf, &sram->gameSaveBlocks[i], sizeof(struct GameSaveBlock)); } // GameRankSaveDataPacks - CpuFastFill(0, gUnknown_02008000, sizeof(struct GameRankSaveDataPacks)); - sub_80A7360(&ewram_->gameRankSave, (struct GameRankSaveDataPacks*)gUnknown_02008000); - SaveRankings(gUnknown_02008000); + CpuFastFill(0, sGameStartSaveBuf, sizeof(struct GameRankSaveDataPacks)); + sub_80A7360(&ewram_->gameRankSave, (struct GameRankSaveDataPacks*)sGameStartSaveBuf); + SaveRankings(sGameStartSaveBuf); - CpuFastFill(0, gUnknown_02008000, sizeof(struct SoundRoomSaveData)); - sub_80A734C(&ewram_->soundRoomSave, (struct SoundRoomSaveData*)gUnknown_02008000); - WriteSoundRoomSaveData((struct SoundRoomSaveData *)gUnknown_02008000); + CpuFastFill(0, sGameStartSaveBuf, sizeof(struct SoundRoomSaveData)); + sub_80A734C(&ewram_->soundRoomSave, (struct SoundRoomSaveData*)sGameStartSaveBuf); + WriteSoundRoomSaveData((struct SoundRoomSaveData *)sGameStartSaveBuf); // "bmsave_unkstruct2", flags for viewing CGs? - CpuFastFill(0, gUnknown_02008000, sizeof(struct bmsave_unkstruct2)); - sub_80A733C(&ewram_->unkstruct2, (struct bmsave_unkstruct2*)gUnknown_02008000); - WriteLinkArenaStruct2((struct bmsave_unkstruct2*)gUnknown_02008000); - - CpuFastFill(0, gUnknown_02008000, sizeof(struct BonusClaimSaveData)); - sub_80A7328(&ewram_->bonusClaim, (struct BonusClaimSaveData*)gUnknown_02008000); - SaveBonusContentData(gUnknown_02008000); - - for (i = 0; i < SAVE_ID_MAX; i++) { - CpuFastFill(0, gUnknown_02008000, sizeof(struct SaveBlockInfo)); - SetGlobalSaveInfoPtr(&ewram_->saveBlockInfo[i], (struct SaveBlockInfo*)gUnknown_02008000); - WriteSaveBlockInfo((struct SaveBlockInfo *)gUnknown_02008000, i); + CpuFastFill(0, sGameStartSaveBuf, sizeof(struct bmsave_unkstruct2)); + sub_80A733C(&ewram_->unkstruct2, (struct bmsave_unkstruct2*)sGameStartSaveBuf); + WriteLinkArenaStruct2((struct bmsave_unkstruct2*)sGameStartSaveBuf); + + CpuFastFill(0, sGameStartSaveBuf, sizeof(struct BonusClaimSaveData)); + sub_80A7328(&ewram_->bonusClaim, (struct BonusClaimSaveData*)sGameStartSaveBuf); + SaveBonusContentData(sGameStartSaveBuf); + + for (i = 0; i < SAVE_ID_MAX; i++) + { + CpuFastFill(0, sGameStartSaveBuf, sizeof(struct SaveBlockInfo)); + SetGlobalSaveInfoPtr(&ewram_->saveBlockInfo[i], (struct SaveBlockInfo*)sGameStartSaveBuf); + WriteSaveBlockInfo((struct SaveBlockInfo *)sGameStartSaveBuf, i); } - - return; } diff --git a/src/mu.c b/src/mu.c index 5099ae680..9eb15f53c 100644 --- a/src/mu.c +++ b/src/mu.c @@ -2,7 +2,7 @@ #include "constants/items.h" #include "constants/classes.h" - +#include "constants/songs.h" #include "ap.h" #include "bm.h" #include "bmio.h" @@ -21,407 +21,133 @@ #include "soundwrapper.h" #include "spellassoc.h" -/* - "MOVEUNIT" proc and related functions. - Handles managing and displaying moving map sprites. -*/ - -struct MUProc * MU_CreateInternal(u16 x, u16 y, u16 classIndex, int objTileId, unsigned palId); - -void MU_StepSound_OnInit(struct MUStepSoundProc* proc); -void MU_StepSound_OnFirstSound(struct MUStepSoundProc* proc); -void MU_StepSound_OnSecondSound(struct MUStepSoundProc* proc); - -void MU_8078894(struct MUProc* proc); - -void MU_InterpretCommandScript(struct MUProc* proc); - -void MU_FogBumpFx_FirstFrame(struct MUFogBumpFxProc* proc); -void MU_FogBumpFx_TransitionInLoop(struct MUFogBumpFxProc* proc); -void MU_FogBumpFx_DisplayLoop(struct MUFogBumpFxProc* proc); - -void MU_State_WaitForFogBump(struct MUProc* proc); -void MU_State_StartMovement(struct MUProc* proc); -void MU_State_WaitForTimer(struct MUProc* proc); -void MU_State_None(struct MUProc* proc); -void MU_State_NoOp(struct MUProc* proc); -void MU_State_DuringMovement(struct MUProc* proc); - -void MU_AdvanceStepSfx(struct MUProc* proc); - -void MU_OnLoop(struct MUProc* proc); -void MU_OnEnd(struct MUProc* proc); - -void MU_EndInternal(struct MUProc* proc); - -void MU_80790CC(struct MUProc* proc); - -static struct MUConfig* MU_GenerateConfigDefault(int objTileId, u8* outIndex); -static struct MUConfig* MU_GenerateConfigOther(int objTileId, u8* outIndex); - -void MU_DisplayAsSMS(struct MUProc* proc); -void MU_DisplayAsMMS(struct MUProc* proc); - -static u16 MU_GetMovementSpeed(struct MUProc* proc); - -void* MU_GetGfxBufferById(int muIndex); - -const void * MU_GetSheetGfx(struct MUProc* proc); -const void * MU_GetAnimationByClassId(u16 classId); - -void MU_DeathFade_OnLoop(struct MUEffectProc* proc); - -void MU_BlinkEffect_OnLoop(struct MUEffectProc* proc); - -void MU_SetupPixelEffect(u32* data, int frame); - -void MU_PixelEffect_OnLoop(struct MUEffectProc* proc); - -void MU_807988C(struct MUEffectProc* proc); - -void MU_EndSelectionApAnim(int argAp); -void MU_EndRefaceApAnim(int argAp); -void MU_EndFasterApAnim(int argAp); - -void MU_CritFlash_Init(struct MUFlashEffectProc* proc); -void MU_CritFlash_SetFadedPalette(struct MUFlashEffectProc* proc); -void MU_CritFlash_SetRegularPalette(struct MUFlashEffectProc* proc); -void MU_CritFlash_StartFadeBack_maybe(struct MUFlashEffectProc* proc); -void MU_CritFlash_SpriteShakeLoop(struct MUFlashEffectProc* proc); -void MU_CritFlash_RestorePalette(struct MUFlashEffectProc* proc); - -void MU_HitFlash_RestorePalette(struct MUFlashEffectProc* proc); - -void MU_ForceSetMaxMoveSpeed(ProcPtr proc); - -struct MUProc * MU_GetByIndex(int muIndex); - -#define MU_GetDisplayXOrg(proc) ((((proc)->xSubPosition + (proc)->xSubOffset) >> MU_SUBPIXEL_PRECISION) + 8) -#define MU_GetDisplayYOrg(proc) ((((proc)->ySubPosition + (proc)->ySubOffset) >> MU_SUBPIXEL_PRECISION) + 8) - -#define MU_AdvanceGetCommand(proc) (proc->pMUConfig->commands[proc->pMUConfig->currentCommand++]) - -// NON-CONST DATA - -// Buffer for graphics -// I do not know how to handle this :/ -extern u8 gMUGfxBuffer[MU_GFX_MAX_SIZE * MU_MAX_COUNT]; - +EWRAM_OVERLAY(0) int Unk_2004BDC = 0; +EWRAM_OVERLAY(0) u8 gMUGfxBuffer[MU_GFX_MAX_SIZE * MU_MAX_COUNT] = { 0 }; static struct MUConfig sMUConfigArray[MU_MAX_COUNT]; -// CONST DATA - -#ifndef CONST_DATA -# define CONST_DATA const __attribute__((section(".data"))) -#endif // CONST_DATA - -static const u16* CONST_DATA sMUFlashColorLookup[] = { - Pal_AllWhite, - Pal_AllBlack, - Pal_AllRed, - Pal_AllGreen, - Pal_AllBlue, - Pal_AllYellow, +const u16 * CONST_DATA MUFlashColorLookup[] = { + [MU_FLASH_WHITE] = Pal_AllWhite, + [MU_FLASH_BLACK] = Pal_AllBlack, + [MU_FLASH_RED] = Pal_AllRed, + [MU_FLASH_GREEN] = Pal_AllGreen, + [MU_FLASH_BLUE] = Pal_AllBlue, + [MU_FLASH_YELLOW] = Pal_AllYellow, }; -// gProc_MUStepSound - struct ProcCmd CONST_DATA ProcScr_MUStepSound[] = { - PROC_CALL(MU_StepSound_OnInit), - - PROC_SLEEP(0), - PROC_CALL(MU_StepSound_OnFirstSound), - - PROC_SLEEP(0), - PROC_CALL(MU_StepSound_OnSecondSound), - + struct ProcCmd CONST_DATA ProcScr_MuStepSe[] = { + PROC_CALL(MuStepSe_Init), + PROC_YIELD, + PROC_CALL(MuStepSe_PlaySeA), + PROC_YIELD, + PROC_CALL(MuStepSe_PlaySeB), PROC_END }; - struct ProcCmd CONST_DATA ProcScr_MUFogBumpFx[] = { - PROC_CALL(MU_FogBumpFx_FirstFrame), - PROC_REPEAT(MU_FogBumpFx_TransitionInLoop), - PROC_REPEAT(MU_FogBumpFx_DisplayLoop), - + struct ProcCmd CONST_DATA ProcScr_MuFogBump[] = { + PROC_CALL(MuFogBump_Init), + PROC_REPEAT(MuFogBump_ScaleLoop), + PROC_REPEAT(MuFogBump_EndLoop), PROC_END }; -// gDirectionMoveOffsetLookup -static short CONST_DATA sDirectionMoveOffsetLookup[] = { +static short CONST_DATA sMoveOffsetLut[] = { -1, 0, // left +1, 0, // right - 0, +1, // up - 0, -1, // down + 0, +1, // up + 0, -1, // down }; -// START MU SFX DEFINITIONS - -// feet sounds -u16 CONST_DATA gMUSfxDef_Foot[] = { - 0x10, // loop duration (in frames) - 0x02, // idk - - 0x96, // TODO: USE SOUND ID DEFINITION - - // 7 frames of no sounds - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - - 0x97, // TODO: USE SOUND ID DEFINITION - - // 7 frames of no sounds - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, +u16 CONST_DATA MuSoundScr_Foot[] = { + 0x10, 2, + SONG_96, 0, 0, 0, 0, 0, 0, 0, + SONG_97, 0, 0, 0, 0, 0, 0, 0, }; -// heavy sounds -u16 CONST_DATA gMUSfxDef_Heavy[] = { - 0x20, // loop duration (in frames) - 0x02, // idk - - 0xA4, // TODO: USE SOUND ID DEFINITION - - // 15 frames of no sounds - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - - 0xA5, // TODO: USE SOUND ID DEFINITION - - // 15 frames of no sounds - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, +u16 CONST_DATA MuSoundScr_FootHeavy[] = { + 0x20, 2, + SONG_A4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + SONG_A5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -// mounted sounds -u16 CONST_DATA gMUSfxDef_Mounted[] = { - 0x15, // loop duration (in frames) - 0x03, // idk - - 0x9A, // TODO: USE SOUND ID DEFINITION - - // 2 frames of no sounds - 0x00, 0x00, - - 0x9B, // TODO: USE SOUND ID DEFINITION - - // 6 frames of no sounds - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - - 0x9C, // TODO: USE SOUND ID DEFINITION - - // 10 frames of no sounds - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, +u16 CONST_DATA MuSoundScr_Mounted[] = { + 0x15, 3, + SONG_9A, 0, 0, + SONG_9B, 0, 0, 0, 0, 0, 0, + SONG_9C, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -// wyvern sounds -u16 CONST_DATA gMUSfxDef_Wyvern[] = { - 0x14, // loop duration (in frames) - 0x01, // idk - - 0xA0, // TODO: USE SOUND ID DEFINITION - - // 19 frames of no sounds - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, +u16 CONST_DATA MuSoundScr_Wyvern[] = { + 0x14, 1, + SONG_A0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -// pegasi sounds -u16 CONST_DATA gMUSfxDef_Pegasus[] = { - 0x14, // loop duration (in frames) - 0x01, // idk - - 0xA6, // TODO: USE SOUND ID DEFINITION - - // 19 frames of no sounds - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, +u16 CONST_DATA MuSoundScr_Pegasus[] = { + 0x14, 1, + SONG_A6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -// unused sounds -u16 CONST_DATA gMUSfxDef_Unused_089A2A86[] = { - 0x14, // loop duration (in frames) - 0x01, // idk - - 0x2E0, // TODO: USE SOUND ID DEFINITION - - // 19 frames of no sounds - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, +u16 CONST_DATA MuSoundScr_Unused1[] = { + 0x14, 1, + SONG_2E0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -// zombie sounds -u16 CONST_DATA gMUSfxDef_Zombie[] = { - 0x0F, // loop duration (in frames) - 0x01, // idk - - 0x302, // TODO: USE SOUND ID DEFINITION - - // 14 frames of no sounds - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, +u16 CONST_DATA MuSoundScr_Zombie[] = { + 0x0F, 1, + SONG_302, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -// skelly sounds -u16 CONST_DATA gMUSfxDef_Skeleton[] = { - 0x0F, // loop duration (in frames) - 0x01, // idk - - 0x304, // TODO: USE SOUND ID DEFINITION - - // 14 frames of no sounds - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, +u16 CONST_DATA MuSoundScr_Skeleton[] = { + 0x0F, 1, + SONG_304, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -// mogall sounds -u16 CONST_DATA gMUSfxDef_Mogall[] = { - 0x14, // loop duration (in frames) - 0x01, // idk - - 0x306, // TODO: USE SOUND ID DEFINITION - - // 19 frames of no sounds - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, +u16 CONST_DATA MuSoundScr_Mogall[] = { + 0x14, 1, + SONG_306, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -// spider sounds -u16 CONST_DATA gMUSfxDef_Spider[] = { - 0x0A, // loop duration (in frames) - 0x01, // idk - - 0x308, // TODO: USE SOUND ID DEFINITION - - // 9 frames of no sounds - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, +u16 CONST_DATA MuSoundScr_Spider[] = { + 0x0A, 1, + SONG_308, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -// dog sounds -u16 CONST_DATA gMUSfxDef_Dog[] = { - 0x15, // loop duration (in frames) - 0x01, // idk - - 0x30A, // TODO: USE SOUND ID DEFINITION - - // 2 frames of no sounds - 0x00, 0x00, - - 0x30A, // TODO: USE SOUND ID DEFINITION - - // 6 frames of no sounds - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - - 0x30A, // TODO: USE SOUND ID DEFINITION - - // 10 frames of no sounds - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, +u16 CONST_DATA MuSoundScr_Dog[] = { + 0x15, 1, + SONG_30A, 0, 0, + SONG_30A, 0, 0, 0, 0, 0, 0, + SONG_30A, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -// gorgon sounds -u16 CONST_DATA gMUSfxDef_Gorgon[] = { - 0x0F, // loop duration (in frames) - 0x01, // idk - - 0x30C, // TODO: USE SOUND ID DEFINITION - - // 14 frames of no sounds - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, +u16 CONST_DATA MuSoundScr_Gorgon[] = { + 0x0F, 1, + SONG_30C, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -// Unused/Unreferenced step sounds -u16 CONST_DATA gMUSfxDef_Unused_089A2BCE[] = { - 0x20, // loop duration (in frames) - 0x02, // idk - - 0x2E0, // TODO: USE SOUND ID DEFINITION - - // 31 frames of no sounds - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, +u16 CONST_DATA MuSoundScr_Unused2[] = { + 0x20, 2, + SONG_2E0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -// boat sounds -u16 CONST_DATA gMUSfxDef_Boat[] = { - 0x18, // loop duration (in frames) - 0x01, // idk - - 0x30F, // TODO: USE SOUND ID DEFINITION - - // 11 frames of no sounds - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - - 0x30E, // TODO: USE SOUND ID DEFINITION - - // 11 frames of no sounds - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, +u16 CONST_DATA MuSoundScr_Boat[] = { + 0x18, 1, + SONG_30F, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + SONG_30E, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -// myrrh sounds -u16 CONST_DATA gMUSfxDef_Myrrh[] = { - 0x10, // loop duration (in frames) - 0x01, // idk - - 0x3BB, // TODO: USE SOUND ID DEFINITION - - // 15 frames of no sounds - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, +u16 CONST_DATA MuSoundScr_Myrrh[] = { + 0x10, 1, + SONG_3BB, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -// END MU SFX DEFINITIONS - -// MU state handler function pointer lookup -static MUStateHandlerFunc CONST_DATA sMUStateHandlerFuncLookup[] = { - MU_State_None, - MU_State_NoOp, - MU_State_DuringMovement, - MU_State_WaitForTimer, - MU_State_StartMovement, - MU_State_WaitForFogBump, - MU_State_NoOp, - MU_State_NoOp, +static MuStateFunc CONST_DATA sMuStateFuncs[] = { + [MU_STATE_NONE] = Mu_OnStateNone, + [MU_STATE_INACTIVE] = Mu_OnStateDoNothing, + [MU_STATE_MOVEMENT] = Mu_OnStateMovement, + [MU_STATE_SLEEPING] = Mu_OnStateSleeping, + [MU_STATE_UNK4] = Mu_OnStateMoving, + [MU_STATE_BUMPING] = Mu_OnStateBump, + [MU_STATE_DISPLAY_UI] = Mu_OnStateDoNothing, + [MU_STATE_DEATHFADE] = Mu_OnStateDoNothing, }; struct ProcCmd CONST_DATA gProcScr_MoveUnit[] = { @@ -526,19 +252,21 @@ struct ProcCmd CONST_DATA gProcScr_MU_89A2CF8[] = { // END CONST DATA -void MU_Init(void) { +void MU_Init(void) +{ int i; for (i = 0; i < MU_MAX_COUNT; ++i) sMUConfigArray[i].muIndex = 0; } -struct MUProc* MU_CreateExt(struct Unit* pUnit, unsigned classIndex, unsigned palId) { - struct MUProc* proc = MU_CreateInternal( +struct MUProc * MU_CreateExt(struct Unit* pUnit, unsigned jid, unsigned palId) +{ + struct MUProc * proc = MU_CreateInternal( pUnit->xPos, pUnit->yPos, - classIndex, + jid, -1, palId @@ -550,26 +278,28 @@ struct MUProc* MU_CreateExt(struct Unit* pUnit, unsigned classIndex, unsigned pa return proc; } -struct MUProc* MU_Create(struct Unit* pUnit) { - struct MUProc* proc; +struct MUProc * MU_Create(struct Unit* pUnit) +{ + struct MUProc * proc; - unsigned classIndex = pUnit->pClassData->number; + unsigned jid = pUnit->pClassData->number; - if (pUnit->state & US_IN_BALLISTA) { + if (pUnit->state & US_IN_BALLISTA) + { struct Trap* blst = GetTrap(pUnit->ballistaIndex); switch (blst->extra) { case ITEM_BALLISTA_REGULAR: - classIndex = CLASS_BLST_REGULAR_USED; + jid = CLASS_BLST_REGULAR_USED; break; case ITEM_BALLISTA_LONG: - classIndex = CLASS_BLST_LONG_USED; + jid = CLASS_BLST_LONG_USED; break; case ITEM_BALLISTA_KILLER: - classIndex = CLASS_BLST_KILLER_USED; + jid = CLASS_BLST_KILLER_USED; break; } // switch (blst->extra) @@ -579,7 +309,7 @@ struct MUProc* MU_Create(struct Unit* pUnit) { pUnit->xPos, pUnit->yPos, - classIndex, + jid, -1, GetUnitSpritePalette(pUnit) @@ -591,20 +321,24 @@ struct MUProc* MU_Create(struct Unit* pUnit) { return proc; } -void MU_ManualUpdate(struct MUProc* proc) { +void MU_ManualUpdate(struct MUProc * proc) +{ MU_OnLoop(proc); } -void MU_EnableAttractCamera(struct MUProc* proc) { +void MU_EnableAttractCamera(struct MUProc * proc) +{ proc->boolAttractCamera = TRUE; } -void MU_DisableAttractCamera(struct MUProc* proc) { +void MU_DisableAttractCamera(struct MUProc * proc) +{ proc->boolAttractCamera = FALSE; } -struct MUProc* MU_CreateForUI(struct Unit* pUnit, int x, int y) { - struct MUProc* proc = MU_Create(pUnit); +struct MUProc * MU_CreateForUI(struct Unit* pUnit, int x, int y) +{ + struct MUProc * proc = MU_Create(pUnit); if (!proc) return NULL; @@ -612,21 +346,23 @@ struct MUProc* MU_CreateForUI(struct Unit* pUnit, int x, int y) { proc->xSubPosition = x << MU_SUBPIXEL_PRECISION; proc->ySubPosition = y << MU_SUBPIXEL_PRECISION; - proc->stateId = MU_STATE_UI_DISPLAY; + proc->stateId = MU_STATE_DISPLAY_UI; return proc; } -void MU_8078524(struct MUProc* proc) { +void MU_8078524(struct MUProc * proc) +{ SMS_80266F0( GetClassSMSId(proc->displayedClassId), proc->muIndex ); } -struct MUProc * MU_CreateInternal(u16 x, u16 y, u16 classIndex, int objTileId, unsigned palId) { - struct MUConfig* config; - struct MUProc* proc; +struct MUProc * MU_CreateInternal(u16 x, u16 y, u16 jid, int objTileId, unsigned palId) +{ + struct MUConfig * config; + struct MUProc * proc; struct APHandle* ap; u8 soundTimer = 0; @@ -649,7 +385,7 @@ struct MUProc * MU_CreateInternal(u16 x, u16 y, u16 classIndex, int objTileId, u return NULL; proc->pUnit = NULL; - proc->stateId = MU_STATE_NONACTIVE; + proc->stateId = MU_STATE_INACTIVE; proc->xSubPosition = (x * 16) << MU_SUBPIXEL_PRECISION; proc->ySubPosition = (y * 16) << MU_SUBPIXEL_PRECISION; @@ -662,7 +398,7 @@ struct MUProc * MU_CreateInternal(u16 x, u16 y, u16 classIndex, int objTileId, u proc->moveTimer = 0; proc->stepSoundTimer = soundTimer; - proc->displayedClassId = classIndex; + proc->displayedClassId = jid; proc->boolIsHidden = 0; proc->pGfxVRAM = OBJ_VRAM0 + (0x20 * objTileId); @@ -676,7 +412,7 @@ struct MUProc * MU_CreateInternal(u16 x, u16 y, u16 classIndex, int objTileId, u config->paletteIndex = palId; - ap = AP_Create(MU_GetAnimationByClassId(classIndex), 10); + ap = AP_Create(MU_GetAnimationByClassId(jid), 10); AP_SwitchAnimation(ap, MU_FACING_SELECTED); Decompress( @@ -695,7 +431,8 @@ struct MUProc * MU_CreateInternal(u16 x, u16 y, u16 classIndex, int objTileId, u return proc; } -void MU_SetFacing(struct MUProc* proc, int facingId) { +void MU_SetFacing(struct MUProc * proc, int facingId) +{ proc->facingId = facingId; if (facingId == MU_FACING_STANDING) @@ -704,44 +441,49 @@ void MU_SetFacing(struct MUProc* proc, int facingId) { AP_SwitchAnimation(proc->pAPHandle, proc->facingId); } -void MU_SetDefaultFacing(struct MUProc* proc) { +void MU_SetDefaultFacing(struct MUProc * proc) +{ if (GetClassData(proc->displayedClassId)->attributes & CA_MOUNTEDAID) MU_SetFacing(proc, 1); else MU_SetFacing(proc, 2); } -void MU_SetDefaultFacing_Auto(void) { - struct MUProc* proc = Proc_Find(gProcScr_MoveUnit); +void MU_SetDefaultFacing_Auto(void) +{ + struct MUProc * proc = Proc_Find(gProcScr_MoveUnit); if (proc) MU_SetDefaultFacing(proc); } -void MU_StartMoveScript_Auto(const u8 commands[MU_COMMAND_MAX_COUNT]) { - struct MUProc* proc = Proc_Find(gProcScr_MoveUnit); +void MU_StartMoveScript_Auto(const u8 commands[MU_COMMAND_MAX_COUNT]) +{ + struct MUProc * proc = Proc_Find(gProcScr_MoveUnit); if (proc) MU_StartMoveScript(proc, commands); } -s8 MU_Exists(void) { +s8 MU_Exists(void) +{ return Proc_Find(gProcScr_MoveUnit) ? TRUE : FALSE; } -s8 MU_IsAnyActive(void) { +s8 MU_IsAnyActive(void) +{ int i; - for (i = 0; i < MU_MAX_COUNT; ++i) { + for (i = 0; i < MU_MAX_COUNT; ++i) + { #ifndef NONMATCHING asm(""::"r"(&sMUConfigArray[i].muIndex)); asm(""::"r"(&sMUConfigArray[i].pMUProc)); #endif if (sMUConfigArray[i].muIndex == 0) continue; while (0) ; - if (sMUConfigArray[i].pMUProc->stateId != MU_STATE_NONACTIVE) { + if (sMUConfigArray[i].pMUProc->stateId != MU_STATE_INACTIVE) return TRUE; - } } if (i >= MU_MAX_COUNT) @@ -750,14 +492,16 @@ s8 MU_IsAnyActive(void) { return TRUE; } -s8 MU_IsActive(struct MUProc* proc) { - if (proc->pMUConfig->muIndex && proc->stateId != MU_STATE_NONACTIVE) +s8 MU_IsActive(struct MUProc * proc) +{ + if (proc->pMUConfig->muIndex && proc->stateId != MU_STATE_INACTIVE) return TRUE; return FALSE; } -void MU_StartMoveScript(struct MUProc* proc, const u8 commands[MU_COMMAND_MAX_COUNT]) { +void MU_StartMoveScript(struct MUProc * proc, const u8 commands[MU_COMMAND_MAX_COUNT]) +{ int i; for (i = 0; i < 0x40; ++i) @@ -769,8 +513,9 @@ void MU_StartMoveScript(struct MUProc* proc, const u8 commands[MU_COMMAND_MAX_CO MU_PlayStepSfx(proc); } -struct MUProc* MU_CreateScripted(u16 x, u16 y, u16 classIndex, unsigned palId, const u8 commands[MU_COMMAND_MAX_COUNT]) { - struct MUProc* proc = MU_CreateInternal(x, y, classIndex, -1, palId); +struct MUProc * MU_CreateScripted(u16 x, u16 y, u16 jid, unsigned palId, const u8 commands[MU_COMMAND_MAX_COUNT]) +{ + struct MUProc * proc = MU_CreateInternal(x, y, jid, -1, palId); if (!proc) return NULL; @@ -779,7 +524,8 @@ struct MUProc* MU_CreateScripted(u16 x, u16 y, u16 classIndex, unsigned palId, c return proc; } -void MU_StepSound_OnInit(struct MUStepSoundProc* proc) { +void MuStepSe_Init(struct MUStepSoundProc * proc) +{ proc->idSound1 = 0; proc->xSound1 = 0; @@ -787,47 +533,55 @@ void MU_StepSound_OnInit(struct MUStepSoundProc* proc) { proc->xSound2 = 0; } -void MU_StepSound_OnFirstSound(struct MUStepSoundProc* proc) { +void MuStepSe_PlaySeA(struct MUStepSoundProc * proc) +{ PlaySeSpacial(proc->idSound1, proc->xSound1); } -void MU_StepSound_OnSecondSound(struct MUStepSoundProc* proc) { +void MuStepSe_PlaySeB(struct MUStepSoundProc * proc) +{ if (proc->idSound2) PlaySeSpacial(proc->idSound2, proc->xSound2); } -void MU_StartStepSfx(int soundId, int b, int hPosition) { - struct MUStepSoundProc* proc; +void MU_StartStepSfx(int soundId, int b, int hPosition) +{ + struct MUStepSoundProc * proc; - proc = Proc_Find(ProcScr_MUStepSound); + proc = Proc_Find(ProcScr_MuStepSe); if (!proc) - proc = Proc_Start(ProcScr_MUStepSound, PROC_TREE_3); + proc = Proc_Start(ProcScr_MuStepSe, PROC_TREE_3); - if (!proc->idSound1) { + if (!proc->idSound1) + { proc->idSound1 = soundId; proc->xSound1 = hPosition; - } else if (!proc->u60_buggedmaybe) { // TODO: FIXME: Is this a bug? u60_buggedmaybe is never initialized + } + else if (!proc->u60_buggedmaybe) // TODO: FIXME: Is this a bug? u60_buggedmaybe is never initialized + { proc->idSound2 = soundId + b; proc->xSound2 = hPosition; } } -void MU_PlayStepSfx(struct MUProc* proc) { +void MU_PlayStepSfx(struct MUProc * proc) +{ MU_AdvanceStepSfx(proc); } -void MU_8078894(struct MUProc* proc) {} +void MU_8078894(struct MUProc * proc) {} -void MU_InterpretCommandScript(struct MUProc* proc) { - while (TRUE) { +void MU_InterpretCommandScript(struct MUProc * proc) +{ + while (TRUE) + { short command = MU_AdvanceGetCommand(proc); switch (command) { - case MU_COMMAND_WAIT: proc->moveTimer = MU_AdvanceGetCommand(proc); - proc->stateId = MU_STATE_WAITING; + proc->stateId = MU_STATE_SLEEPING; return; @@ -898,9 +652,10 @@ void MU_InterpretCommandScript(struct MUProc* proc) { } // while (TRUE) } -void MU_StartFogBumpFx(int x, int y) { +void MU_StartFogBumpFx(int x, int y) +{ struct APHandle* ap; - struct MUFogBumpFxProc* proc; + struct MUFogBumpFxProc * proc; Decompress( Img_GmapSoguSprites, @@ -912,7 +667,7 @@ void MU_StartFogBumpFx(int x, int y) { ap->tileBase = 0x1180; AP_SwitchAnimation(ap, MU_FACING_LEFT); - proc = Proc_Start(ProcScr_MUFogBumpFx, PROC_TREE_3); + proc = Proc_Start(ProcScr_MuFogBump, PROC_TREE_3); proc->pAPHandle = ap; @@ -920,7 +675,8 @@ void MU_StartFogBumpFx(int x, int y) { proc->yDisplay = y - 4; } -void MU_FogBumpFx_FirstFrame(struct MUFogBumpFxProc* proc) { +void MuFogBump_Init(struct MUFogBumpFxProc * proc) +{ PlaySoundEffect(0x77); proc->timer = 0; @@ -937,7 +693,8 @@ void MU_FogBumpFx_FirstFrame(struct MUFogBumpFxProc* proc) { ); } -void MU_FogBumpFx_TransitionInLoop(struct MUFogBumpFxProc* proc) { +void MuFogBump_ScaleLoop(struct MUFogBumpFxProc * proc) +{ int scale; if (proc->timer++ >= 8) @@ -962,7 +719,8 @@ void MU_FogBumpFx_TransitionInLoop(struct MUFogBumpFxProc* proc) { ); } -void MU_FogBumpFx_DisplayLoop(struct MUFogBumpFxProc* proc) { +void MuFogBump_EndLoop(struct MUFogBumpFxProc * proc) +{ if (proc->timer++ >= 40) Proc_Break(proc); @@ -974,43 +732,49 @@ void MU_FogBumpFx_DisplayLoop(struct MUFogBumpFxProc* proc) { ); } -u8 MU_IsFogBumpFxActive(void) { - return Proc_Find(ProcScr_MUFogBumpFx) ? TRUE : FALSE; +u8 MU_IsFogBumpFxActive(void) +{ + return Proc_Find(ProcScr_MuFogBump) ? TRUE : FALSE; } -void MU_State_WaitForFogBump(struct MUProc* proc) { +void Mu_OnStateBump(struct MUProc * proc) +{ if (!MU_IsFogBumpFxActive()) - proc->stateId = MU_STATE_WAITING; + proc->stateId = MU_STATE_SLEEPING; } -void MU_State_StartMovement(struct MUProc* proc) { +void Mu_OnStateMoving(struct MUProc * proc) +{ proc->stateId = MU_STATE_MOVEMENT; } -void MU_State_WaitForTimer(struct MUProc* proc) { +void Mu_OnStateSleeping(struct MUProc * proc) +{ if (proc->moveTimer == 0) proc->stateId = MU_STATE_MOVEMENT; else proc->moveTimer--; } -void MU_State_None(struct MUProc* proc) {} +void Mu_OnStateNone(struct MUProc * proc) {} -void MU_State_NoOp(struct MUProc* proc) {} +void Mu_OnStateDoNothing(struct MUProc * proc) {} -void MU_State_DuringMovement(struct MUProc* proc) { +void Mu_OnStateMovement(struct MUProc * proc) +{ unsigned moveSpeed = MU_GetMovementSpeed(proc); proc->moveTimer = moveSpeed + proc->moveTimer; - proc->xSubPosition += moveSpeed * sDirectionMoveOffsetLookup[proc->facingId * 2 + 0]; - proc->ySubPosition += moveSpeed * sDirectionMoveOffsetLookup[proc->facingId * 2 + 1]; + proc->xSubPosition += moveSpeed * sMoveOffsetLut[proc->facingId * 2 + 0]; + proc->ySubPosition += moveSpeed * sMoveOffsetLut[proc->facingId * 2 + 1]; - if ((proc->moveTimer / 16) >= 16) { + if ((proc->moveTimer / 16) >= 16) + { proc->moveTimer -= 0x100; - proc->xSubPosition -= proc->moveTimer * sDirectionMoveOffsetLookup[proc->facingId * 2 + 0]; - proc->ySubPosition -= proc->moveTimer * sDirectionMoveOffsetLookup[proc->facingId * 2 + 1]; + proc->xSubPosition -= proc->moveTimer * sMoveOffsetLut[proc->facingId * 2 + 0]; + proc->ySubPosition -= proc->moveTimer * sMoveOffsetLut[proc->facingId * 2 + 1]; proc->moveTimer = 0; @@ -1018,7 +782,8 @@ void MU_State_DuringMovement(struct MUProc* proc) { proc->ySubPosition &= ~0xF; } - if (proc->boolAttractCamera && !Proc_Find(gProcScr_CamMove)) { + if (proc->boolAttractCamera && !Proc_Find(gProcScr_CamMove)) + { gBmSt.camera.x = GetCameraAdjustedX(proc->xSubPosition >> MU_SUBPIXEL_PRECISION); gBmSt.camera.y = GetCameraAdjustedY(proc->ySubPosition >> MU_SUBPIXEL_PRECISION); } @@ -1027,81 +792,83 @@ void MU_State_DuringMovement(struct MUProc* proc) { MU_AdvanceStepSfx(proc); } -void MU_AdvanceStepSfx(struct MUProc* proc) { - const u16* pStepSoundDefinition; +void MU_AdvanceStepSfx(struct MUProc * proc) +{ + const u16 * pStepSoundDefinition; unsigned cursor; struct Vec2 position; - if (GetClassData(proc->displayedClassId)->attributes & CA_MOUNTEDAID) { + if (GetClassData(proc->displayedClassId)->attributes & CA_MOUNTEDAID) + { switch (proc->displayedClassId) { - case CLASS_WYVERN_RIDER: case CLASS_WYVERN_RIDER_F: case CLASS_WYVERN_LORD: case CLASS_WYVERN_LORD_F: case CLASS_WYVERN_KNIGHT: case CLASS_WYVERN_KNIGHT_F: - pStepSoundDefinition = gMUSfxDef_Wyvern; + pStepSoundDefinition = MuSoundScr_Wyvern; break; case CLASS_MOGALL: case CLASS_ARCH_MOGALL: - pStepSoundDefinition = gMUSfxDef_Mogall; + pStepSoundDefinition = MuSoundScr_Mogall; break; case CLASS_PEGASUS_KNIGHT: case CLASS_FALCON_KNIGHT: - pStepSoundDefinition = gMUSfxDef_Pegasus; + pStepSoundDefinition = MuSoundScr_Pegasus; break; default: // Any other mounted class - pStepSoundDefinition = gMUSfxDef_Mounted; + pStepSoundDefinition = MuSoundScr_Mounted; break; } // proc->displayedClassId - } else { + } + else + { switch (proc->displayedClassId) { - case CLASS_REVENANT: case CLASS_ENTOUMBED: - pStepSoundDefinition = gMUSfxDef_Zombie; + pStepSoundDefinition = MuSoundScr_Zombie; break; case CLASS_BONEWALKER: case CLASS_BONEWALKER_BOW: case CLASS_WIGHT: case CLASS_WIGHT_BOW: - pStepSoundDefinition = gMUSfxDef_Skeleton; + pStepSoundDefinition = MuSoundScr_Skeleton; break; case CLASS_BAEL: case CLASS_ELDER_BAEL: - pStepSoundDefinition = gMUSfxDef_Spider; + pStepSoundDefinition = MuSoundScr_Spider; break; case CLASS_MAUTHEDOOG: case CLASS_GWYLLGI: - pStepSoundDefinition = gMUSfxDef_Dog; + pStepSoundDefinition = MuSoundScr_Dog; break; case CLASS_TARVOS: case CLASS_MAELDUIN: - pStepSoundDefinition = gMUSfxDef_Mounted; + pStepSoundDefinition = MuSoundScr_Mounted; break; case CLASS_MOGALL: case CLASS_ARCH_MOGALL: - pStepSoundDefinition = gMUSfxDef_Mogall; + pStepSoundDefinition = MuSoundScr_Mogall; break; case CLASS_GORGON: - pStepSoundDefinition = gMUSfxDef_Gorgon; + pStepSoundDefinition = MuSoundScr_Gorgon; break; case CLASS_GARGOYLE: case CLASS_DEATHGOYLE: - pStepSoundDefinition = gMUSfxDef_Wyvern; + pStepSoundDefinition = MuSoundScr_Wyvern; break; case CLASS_ARMOR_KNIGHT: @@ -1115,15 +882,15 @@ void MU_AdvanceStepSfx(struct MUProc* proc) { case CLASS_BLST_REGULAR_USED: case CLASS_BLST_LONG_USED: case CLASS_BLST_KILLER_USED: - pStepSoundDefinition = gMUSfxDef_Heavy; + pStepSoundDefinition = MuSoundScr_FootHeavy; break; case CLASS_FLEET: - pStepSoundDefinition = gMUSfxDef_Boat; + pStepSoundDefinition = MuSoundScr_Boat; break; case CLASS_MANAKETE_MYRRH: - pStepSoundDefinition = gMUSfxDef_Myrrh; + pStepSoundDefinition = MuSoundScr_Myrrh; break; case CLASS_FALLEN_PRINCE: @@ -1131,7 +898,7 @@ void MU_AdvanceStepSfx(struct MUProc* proc) { return; // no sounds default: // Any other non-mounted class - pStepSoundDefinition = gMUSfxDef_Foot; + pStepSoundDefinition = MuSoundScr_Foot; break; } // switch (proc->displayedClassId) @@ -1140,7 +907,8 @@ void MU_AdvanceStepSfx(struct MUProc* proc) { cursor = DivRem(proc->stepSoundTimer++, pStepSoundDefinition[0]); MU_ComputeDisplayPosition(proc, &position); - if (pStepSoundDefinition[2 + cursor]) { + if (pStepSoundDefinition[2 + cursor]) + { MU_StartStepSfx( pStepSoundDefinition[2 + cursor], // sound id pStepSoundDefinition[1], // something @@ -1154,10 +922,10 @@ void MU_OnLoop(struct MUProc * proc) if (proc->stateId) { if (proc->moveTimer == 0) - if ((u8)(proc->stateId - MU_STATE_MOVEMENT) <= (MU_STATE_WAITING - MU_STATE_MOVEMENT)) + if ((u8)(proc->stateId - MU_STATE_MOVEMENT) <= (MU_STATE_SLEEPING - MU_STATE_MOVEMENT)) MU_InterpretCommandScript(proc); - sMUStateHandlerFuncLookup[proc->stateId](proc); + sMuStateFuncs[proc->stateId](proc); } if (proc->facingId == MU_FACING_STANDING) @@ -1166,40 +934,48 @@ void MU_OnLoop(struct MUProc * proc) MU_DisplayAsMMS(proc); } -void MU_OnEnd(struct MUProc* proc) { +void MU_OnEnd(struct MUProc * proc) +{ proc->pMUConfig->muIndex = 0; AP_Delete(proc->pAPHandle); } -void MU_EndAll(void) { +void MU_EndAll(void) +{ Proc_EndEach(gProcScr_MoveUnit); } -void MU_End(struct MUProc* proc) { +void MU_End(struct MUProc * proc) +{ MU_EndInternal(proc); } -void MU_EndInternal(struct MUProc* proc) { +void MU_EndInternal(struct MUProc * proc) +{ Proc_End(proc); } -void MU_80790CC(struct MUProc* proc) { +void MU_80790CC(struct MUProc * proc) +{ MU_8078894(proc); - proc->stateId = MU_STATE_NONACTIVE; + proc->stateId = MU_STATE_INACTIVE; } -void MU_AllDisable(void) { +void MU_AllDisable(void) +{ Proc_BlockEachMarked(4); } -void MU_AllEnable(void) { +void MU_AllEnable(void) +{ Proc_UnblockEachMarked(4); } -void MU_GetComputedEndPosition(int* xOut, int* yOut, const u8* commands) { - while (TRUE) { +void MU_GetComputedEndPosition(int * xOut, int * yOut, const u8 * commands) +{ + while (TRUE) + { switch (*commands++) { - case MU_COMMAND_END: return; @@ -1230,7 +1006,8 @@ void MU_GetComputedEndPosition(int* xOut, int* yOut, const u8* commands) { } } -s8 MU_CanStart(void) { +s8 MU_CanStart(void) +{ int i; for (i = 0; i < MU_MAX_COUNT; ++i) @@ -1240,21 +1017,26 @@ s8 MU_CanStart(void) { return FALSE; } -void MU_AllRestartAnimations(void) { +void MU_AllRestartAnimations(void) +{ int i; - for (i = 0; i < MU_MAX_COUNT; ++i) { - if (sMUConfigArray[i].muIndex) { + for (i = 0; i < MU_MAX_COUNT; ++i) + { + if (sMUConfigArray[i].muIndex) + { sMUConfigArray[i].pMUProc->pAPHandle->frameTimer = 0; sMUConfigArray[i].pMUProc->pAPHandle->frameInterval = 0x100; } } } -static struct MUConfig* MU_GenerateConfigDefault(int objTileId, u8* outIndex) { +struct MUConfig * MU_GenerateConfigDefault(int objTileId, u8* outIndex) +{ int i; - for (i = 0; i < MU_MAX_COUNT; ++i) { + for (i = 0; i < MU_MAX_COUNT; ++i) +{ if (sMUConfigArray[i].muIndex) continue; @@ -1269,10 +1051,12 @@ static struct MUConfig* MU_GenerateConfigDefault(int objTileId, u8* outIndex) { return NULL; } -static struct MUConfig* MU_GenerateConfigOther(int objTileId, u8* outIndex) { +struct MUConfig * MU_GenerateConfigOther(int objTileId, u8* outIndex) +{ int i; - for (i = 0; i < MU_MAX_COUNT; ++i) { + for (i = 0; i < MU_MAX_COUNT; ++i) + { if (sMUConfigArray[i].muIndex) continue; @@ -1287,11 +1071,15 @@ static struct MUConfig* MU_GenerateConfigOther(int objTileId, u8* outIndex) { return NULL; } -u8 MU_ComputeDisplayPosition(struct MUProc* proc, struct Vec2* out) { - if (proc->stateId == MU_STATE_UI_DISPLAY) { +u8 MU_ComputeDisplayPosition(struct MUProc * proc, struct Vec2 * out) +{ + if (proc->stateId == MU_STATE_DISPLAY_UI) + { out->x = (proc->xSubPosition + proc->xSubOffset) >> MU_SUBPIXEL_PRECISION; out->y = (proc->ySubPosition + proc->ySubOffset) >> MU_SUBPIXEL_PRECISION; - } else { + } + else + { short x = ((proc->xSubPosition + proc->xSubOffset) >> MU_SUBPIXEL_PRECISION) - gBmSt.camera.x + 8; short y = ((proc->ySubPosition + proc->ySubOffset) >> MU_SUBPIXEL_PRECISION) - gBmSt.camera.y + 8; @@ -1311,8 +1099,10 @@ u8 MU_ComputeDisplayPosition(struct MUProc* proc, struct Vec2* out) { return TRUE; } -void MU_DisplayAsSMS(struct MUProc* proc) { - if (!proc->boolIsHidden) { +void MU_DisplayAsSMS(struct MUProc * proc) +{ + if (!proc->boolIsHidden) + { struct Vec2 position; if (!MU_ComputeDisplayPosition(proc, &position)) @@ -1345,8 +1135,10 @@ void MU_DisplayAsSMS(struct MUProc* proc) { } } -void MU_DisplayAsMMS(struct MUProc* proc) { - if (!proc->boolIsHidden) { +void MU_DisplayAsMMS(struct MUProc * proc) +{ + if (!proc->boolIsHidden) + { struct Vec2 position; if (!MU_ComputeDisplayPosition(proc, &position)) @@ -1355,7 +1147,7 @@ void MU_DisplayAsMMS(struct MUProc* proc) { position.x &= 0x01FF; position.y &= 0x00FF; - if (proc->stateId != MU_STATE_UI_DISPLAY) + if (proc->stateId != MU_STATE_DISPLAY_UI) if (proc->pUnit && UNIT_FACTION(proc->pUnit) == FACTION_RED) if (gPlaySt.chapterVisionRange != 0) if (!gBmMapFog[MU_GetDisplayYOrg(proc) >> 4][MU_GetDisplayXOrg(proc) >> 4]) @@ -1373,7 +1165,8 @@ void MU_DisplayAsMMS(struct MUProc* proc) { } } -static u16 MU_GetMovementSpeed(struct MUProc* proc) { +u16 MU_GetMovementSpeed(struct MUProc * proc) +{ int config = proc->moveConfig; if (config & 0x80) @@ -1382,8 +1175,10 @@ static u16 MU_GetMovementSpeed(struct MUProc* proc) { if (proc->boolForceMaxSpeed) return 0x100; - if (config != 0x40) { - if (config != 0x00) { + if (config != 0x40) + { + if (config != 0x00) + { int speed = config; if (speed & 0x40) @@ -1407,27 +1202,32 @@ static u16 MU_GetMovementSpeed(struct MUProc* proc) { return 16 * sMUBaseMoveSpeedLookup[GetClassData(proc->displayedClassId)->slowWalking]; } -void MU_SetMoveConfig(struct MUProc* proc, u16 config) { +void MU_SetMoveConfig(struct MUProc * proc, u16 config) +{ if (config > 0x100) proc->moveConfig = 0x100; else proc->moveConfig = config; } -void* MU_GetGfxBufferById(int muIndex) { +void* MU_GetGfxBufferById(int muIndex) +{ return gMUGfxBuffer + (sMUBufferIdLookup[muIndex] * MU_GFX_MAX_SIZE); } -const void * MU_GetSheetGfx(struct MUProc* proc) { - return gMMSDataTable[proc->displayedClassId - 1].pGraphics; +const void * MU_GetSheetGfx(struct MUProc * proc) +{ + return gMuInfoTable[proc->displayedClassId - 1].img; } -const void * MU_GetAnimationByClassId(u16 classId) { - return gMMSDataTable[classId - 1].pAnimation; +const void * MU_GetAnimationByClassId(u16 classId) +{ + return gMuInfoTable[classId - 1].anim; } -void MU_StartDeathFade(struct MUProc* muProc) { - struct MUEffectProc* proc; +void MU_StartDeathFade(struct MUProc * muProc) +{ + struct MUEffectProc * proc; muProc->stateId = MU_STATE_DEATHFADE; @@ -1447,25 +1247,29 @@ void MU_StartDeathFade(struct MUProc* muProc) { PlaySoundEffect(0xD6); // TODO: SOUND DEFINITIONS - if (muProc->pUnit->state & US_IN_BALLISTA) { + if (muProc->pUnit->state & US_IN_BALLISTA) + { TryRemoveUnitFromBallista(muProc->pUnit); HideUnitSprite(muProc->pUnit); } } -void MU_DeathFade_OnLoop(struct MUEffectProc* proc) { +void MU_DeathFade_OnLoop(struct MUEffectProc * proc) +{ short time = (proc->timeLeft--) >> 1; SetBlendConfig(0, (u8) time, 0x10, 0); - if (proc->timeLeft == 0) { + if (proc->timeLeft == 0) + { MU_End(proc->pMUProc); Proc_Break(proc); } } -void MU_BlinkEffect_OnLoop(struct MUEffectProc* proc) { - struct MUProc* muProc = (struct MUProc*) proc->proc_parent; +void MU_BlinkEffect_OnLoop(struct MUEffectProc * proc) +{ + struct MUProc * muProc = (struct MUProc *) proc->proc_parent; int boolHidden = FALSE; if ((proc->timeLeft & 0x7) < 4) @@ -1473,14 +1277,16 @@ void MU_BlinkEffect_OnLoop(struct MUEffectProc* proc) { muProc->boolIsHidden = boolHidden; - if (--proc->timeLeft < 0) { + if (--proc->timeLeft < 0) + { Proc_Break(proc); muProc->boolIsHidden = TRUE; } } -void MU_StartBlinkEffect(struct MUProc* muProc) { - struct MUEffectProc* proc; +void MU_StartBlinkEffect(struct MUProc * muProc) +{ + struct MUEffectProc * proc; muProc->stateId = MU_STATE_DEATHFADE; @@ -1495,7 +1301,8 @@ void MU_StartBlinkEffect(struct MUProc* muProc) { PlaySoundEffect(0xD6); // TODO: SOUND DEFINITIONS } -void MU_SetupPixelEffect(u32* data, int frame) { +void MU_SetupPixelEffect(u32* data, int frame) +{ static u32 sKeptPixelsWordMask; static u32 sClearedPixelWordMask; @@ -1506,8 +1313,10 @@ void MU_SetupPixelEffect(u32* data, int frame) { sKeptPixelsWordMask = ~(sClearedPixelWordMask = (0xF << (pixel * 4))); - for (i = 0; i < 4; ++i) { - for (j = 0; j < 4; ++j) { + for (i = 0; i < 4; ++i) + { + for (j = 0; j < 4; ++j) + { data[wordId] &= sKeptPixelsWordMask; data += 8; @@ -1517,9 +1326,10 @@ void MU_SetupPixelEffect(u32* data, int frame) { } } -void MU_PixelEffect_OnLoop(struct MUEffectProc* proc) { +void MU_PixelEffect_OnLoop(struct MUEffectProc * proc) +{ MU_SetupPixelEffect( - MU_GetGfxBufferById(((struct MUProc*)(proc->proc_parent))->muIndex), + MU_GetGfxBufferById(((struct MUProc *)(proc->proc_parent))->muIndex), proc->frameIndex ); @@ -1532,14 +1342,16 @@ void MU_PixelEffect_OnLoop(struct MUEffectProc* proc) { (0x80 * 0x20) ); - if (--proc->timeLeft == 0) { + if (--proc->timeLeft == 0) + { MU_End(proc->pMUProc); Proc_Break(proc); } } -void MU_StartPixelEffect(struct MUProc* muProc) { - struct MUEffectProc* proc; +void MU_StartPixelEffect(struct MUProc * muProc) +{ + struct MUEffectProc * proc; muProc->stateId = MU_STATE_DEATHFADE; @@ -1556,38 +1368,44 @@ void MU_StartPixelEffect(struct MUProc* muProc) { PlaySoundEffect(0xD6); // TODO: SOUND DEFINITIONS } -void MU_Hide(struct MUProc* proc) { +void MU_Hide(struct MUProc * proc) +{ proc->boolIsHidden = TRUE; } -void MU_Show(struct MUProc* proc) { +void MU_Show(struct MUProc * proc) +{ proc->boolIsHidden = FALSE; } -void MU_SetDisplayPosition(struct MUProc* proc, int x, int y) { +void MU_SetDisplayPosition(struct MUProc * proc, int x, int y) +{ proc->xSubPosition = x << MU_SUBPIXEL_PRECISION; proc->ySubPosition = y << MU_SUBPIXEL_PRECISION; } -void MU_SetDisplayOffset(struct MUProc* proc, int xOff, int yOff) { +void MU_SetDisplayOffset(struct MUProc * proc, int xOff, int yOff) +{ proc->xSubOffset = xOff << MU_SUBPIXEL_PRECISION; proc->ySubOffset = yOff << MU_SUBPIXEL_PRECISION; } -void MU_StartFlashFade(struct MUProc* proc, int flashType) { +void MU_StartFlashFade(struct MUProc * proc, int flashType) +{ proc->pAPHandle->tileBase = proc->pMUConfig->objTileIndex + (MU_FADE_OBJ_PAL << 12) + proc->objPriorityBits; ApplyPalette(PAL_OBJ(proc->pMUConfig->paletteIndex), 0x10 + MU_FADE_OBJ_PAL); StartPalFade( - sMUFlashColorLookup[flashType], + MUFlashColorLookup[flashType], 0x15, 8, (struct Proc*) proc ); } -void MU_8079858(struct MUProc* muProc) { - struct MUEffectProc* proc; +void MU_8079858(struct MUProc * muProc) +{ + struct MUEffectProc * proc; StartPalFade( PAL_OBJ(muProc->pMUConfig->paletteIndex), @@ -1599,14 +1417,16 @@ void MU_8079858(struct MUProc* muProc) { proc->pMUProc = muProc; } -void MU_807988C(struct MUEffectProc* proc) { - struct MUProc* muProc = proc->pMUProc; +void MU_807988C(struct MUEffectProc * proc) +{ + struct MUProc * muProc = proc->pMUProc; muProc->pAPHandle->tileBase = ((muProc->pMUConfig->paletteIndex & 0xF) << 12) + muProc->pMUConfig->objTileIndex + muProc->objPriorityBits; } -void MU_StartActionAnim(struct MUProc* proc) { +void MU_StartActionAnim(struct MUProc * proc) +{ AP_SwitchAnimation(proc->pAPHandle, MU_FACING_SELECTED); proc->pAPHandle->frameTimer = 0; @@ -1615,21 +1435,24 @@ void MU_StartActionAnim(struct MUProc* proc) { CallDelayedArg(MU_EndSelectionApAnim, (int) proc->pAPHandle, 30); } -void MU_EndSelectionApAnim(int argAp) { +void MU_EndSelectionApAnim(int argAp) +{ struct APHandle* ap = (struct APHandle*) argAp; ap->frameTimer = 0; ap->frameInterval = 0; } -void MU_StartDelayedFaceTarget(struct MUProc* proc) { +void MU_StartDelayedFaceTarget(struct MUProc * proc) +{ proc->pAPHandle->frameTimer = 0; proc->pAPHandle->frameInterval = 0x100; CallDelayedArg(MU_EndRefaceApAnim, (int) proc->pAPHandle, 30); } -void MU_EndRefaceApAnim(int argAp) { +void MU_EndRefaceApAnim(int argAp) +{ struct APHandle* ap = (struct APHandle*) argAp; int actor1 = gManimSt.subjectActorId; @@ -1644,77 +1467,88 @@ void MU_EndRefaceApAnim(int argAp) { ap->frameInterval = 0; } -void MU_StartFastMoveAnim(struct MUProc* proc) { +void MU_StartFastMoveAnim(struct MUProc * proc) +{ proc->pAPHandle->frameTimer = 0; proc->pAPHandle->frameInterval = 0x40; CallDelayedArg(MU_EndFasterApAnim, (int) proc->pAPHandle, 20); } -void MU_EndFasterApAnim(int argAp) { +void MU_EndFasterApAnim(int argAp) +{ struct APHandle* ap = (struct APHandle*) argAp; ap->frameTimer = 0; ap->frameInterval = 0; } -void MU_StartCritFlash(struct MUProc* muProc, int flashType) { - struct MUFlashEffectProc* proc; +void MU_StartCritFlash(struct MUProc * muProc, int flashType) +{ + struct MUFlashEffectProc * proc; - ApplyPalette(sMUFlashColorLookup[flashType], 0x10 + MU_FADE_OBJ_PAL); + ApplyPalette(MUFlashColorLookup[flashType], 0x10 + MU_FADE_OBJ_PAL); proc = Proc_Start(ProcScr_MUCritFlash, muProc); proc->pMUProc = muProc; } -void MU_CritFlash_Init(struct MUFlashEffectProc* proc) { +void MU_CritFlash_Init(struct MUFlashEffectProc * proc) +{ proc->timer = 0; } -void MU_CritFlash_SetFadedPalette(struct MUFlashEffectProc* proc) { - struct MUProc* muProc = proc->pMUProc; +void MU_CritFlash_SetFadedPalette(struct MUFlashEffectProc * proc) +{ + struct MUProc * muProc = proc->pMUProc; muProc->pAPHandle->tileBase = (MU_FADE_OBJ_PAL << 12) + muProc->pMUConfig->objTileIndex + muProc->objPriorityBits; } -void MU_CritFlash_SetRegularPalette(struct MUFlashEffectProc* proc) { - struct MUProc* muProc = proc->pMUProc; +void MU_CritFlash_SetRegularPalette(struct MUFlashEffectProc * proc) +{ + struct MUProc * muProc = proc->pMUProc; muProc->pAPHandle->tileBase = ((muProc->pMUConfig->paletteIndex & 0xF) << 12) + muProc->pMUConfig->objTileIndex + muProc->objPriorityBits; } -void MU_CritFlash_StartFadeBack_maybe(struct MUFlashEffectProc* proc) { +void MU_CritFlash_StartFadeBack_maybe(struct MUFlashEffectProc * proc) +{ StartPalFade( PAL_OBJ(proc->pMUProc->pMUConfig->paletteIndex), 0x15, 0x14, (struct Proc*) proc ); } -void MU_CritFlash_SpriteShakeLoop(struct MUFlashEffectProc* proc) { +void MU_CritFlash_SpriteShakeLoop(struct MUFlashEffectProc * proc) +{ proc->timer++; MU_SetDisplayOffset(proc->pMUProc, ((proc->timer & 1) ? 2 : -2), 0); - if (proc->timer >= 12) { + if (proc->timer >= 12) + { MU_SetDisplayOffset(proc->pMUProc, 0, 0); Proc_Break(proc); } } -void MU_CritFlash_RestorePalette(struct MUFlashEffectProc* proc) { - struct MUProc* muProc = proc->pMUProc; +void MU_CritFlash_RestorePalette(struct MUFlashEffectProc * proc) +{ + struct MUProc * muProc = proc->pMUProc; muProc->pAPHandle->tileBase = ((muProc->pMUConfig->paletteIndex & 0xF) << 12) + muProc->pMUConfig->objTileIndex + muProc->objPriorityBits; } -void MU_StartHitFlash(struct MUProc* muProc, int flashType) { - struct MUFlashEffectProc* proc; +void MU_StartHitFlash(struct MUProc * muProc, int flashType) +{ + struct MUFlashEffectProc * proc; - ApplyPalette(sMUFlashColorLookup[flashType], 0x10 + MU_FADE_OBJ_PAL); + ApplyPalette(MUFlashColorLookup[flashType], 0x10 + MU_FADE_OBJ_PAL); muProc->pAPHandle->tileBase = (MU_FADE_OBJ_PAL << 12) + muProc->pMUConfig->objTileIndex + muProc->objPriorityBits; @@ -1729,22 +1563,26 @@ void MU_StartHitFlash(struct MUProc* muProc, int flashType) { proc->pMUProc = muProc; } -void MU_HitFlash_RestorePalette(struct MUFlashEffectProc* proc) { - struct MUProc* muProc = proc->pMUProc; +void MU_HitFlash_RestorePalette(struct MUFlashEffectProc * proc) +{ + struct MUProc * muProc = proc->pMUProc; muProc->pAPHandle->tileBase = ((muProc->pMUConfig->paletteIndex & 0xF) << 12) + muProc->pMUConfig->objTileIndex + muProc->objPriorityBits; } -void MU_AllForceSetMaxMoveSpeed(void) { +void MU_AllForceSetMaxMoveSpeed(void) +{ Proc_ForEach(gProcScr_MoveUnit, MU_ForceSetMaxMoveSpeed); } -void MU_ForceSetMaxMoveSpeed(ProcPtr proc) { - ((struct MUProc*)(proc))->boolForceMaxSpeed = TRUE; +void MU_ForceSetMaxMoveSpeed(ProcPtr proc) +{ + ((struct MUProc *)(proc))->boolForceMaxSpeed = TRUE; } -void MU_SetSpecialSprite(struct MUProc* proc, int displayedClassId, const u16* palette) { +void MU_SetSpecialSprite(struct MUProc * proc, int displayedClassId, const u16 * palette) +{ proc->pAPHandle->frameTimer = 0; proc->pAPHandle->frameInterval = 0; @@ -1763,25 +1601,29 @@ void MU_SetSpecialSprite(struct MUProc* proc, int displayedClassId, const u16* p ApplyPalette(palette, 0x10 + proc->pMUConfig->paletteIndex); } -void MU_SetPaletteId(struct MUProc* proc, unsigned paletteId) { +void MU_SetPaletteId(struct MUProc * proc, unsigned paletteId) +{ proc->pMUConfig->paletteIndex = paletteId; proc->pAPHandle->tileBase = proc->pMUConfig->objTileIndex + ((paletteId % 0x10) << 12) + proc->objPriorityBits; } -struct MUProc * MU_GetByIndex(int muIndex) { +struct MUProc * MU_GetByIndex(int muIndex) +{ if (!sMUConfigArray[muIndex].muIndex) return NULL; return sMUConfigArray[muIndex].pMUProc; } -struct MUProc* MU_GetByUnit(struct Unit* unit) { +struct MUProc * MU_GetByUnit(struct Unit* unit) +{ int i; - for (i = 0; i < MU_MAX_COUNT; ++i) { - struct MUProc* proc = MU_GetByIndex(i); + for (i = 0; i < MU_MAX_COUNT; ++i) + { + struct MUProc * proc = MU_GetByIndex(i); if (proc->pUnit == unit) return proc; @@ -1790,31 +1632,37 @@ struct MUProc* MU_GetByUnit(struct Unit* unit) { return NULL; } -void MU_SortObjLayers(void) { - struct MUProc* procs[MU_MAX_COUNT]; +void MU_SortObjLayers(void) +{ + struct MUProc * procs[MU_MAX_COUNT]; s8 i, j; s8 count; // Clear proc list - CpuFill32(0, procs, MU_MAX_COUNT * sizeof(struct MUProc*)); + CpuFill32(0, procs, MU_MAX_COUNT * sizeof(struct MUProc *)); count = 0; // Building proc list - for (i = 0; i < MU_MAX_COUNT; ++i) { - struct MUProc* proc = MU_GetByIndex(i); + for (i = 0; i < MU_MAX_COUNT; ++i) + { + struct MUProc * proc = MU_GetByIndex(i); - if (proc) { + if (proc) + { procs[count] = proc; count++; } } // Sorting proc list - for (i = 0; i < (count - 1); ++i) { - for (j = (i + 1); j < count; ++j) { - if (procs[j]->ySubPosition < procs[i]->ySubPosition) { - struct MUProc* tmp = procs[i]; + for (i = 0; i < (count - 1); ++i) + { + for (j = (i + 1); j < count; ++j) + { + if (procs[j]->ySubPosition < procs[i]->ySubPosition) + { + struct MUProc * tmp = procs[i]; procs[i] = procs[j]; procs[j] = tmp; diff --git a/src/worldmap_gmapunit.c b/src/worldmap_gmapunit.c index edb95041f..4ff004428 100644 --- a/src/worldmap_gmapunit.c +++ b/src/worldmap_gmapunit.c @@ -6,6 +6,7 @@ #include "bmunit.h" #include "bmudisp.h" #include "ctc.h" +#include "mu.h" #include "spline.h" #include "worldmap.h" @@ -16,13 +17,13 @@ void SMS_DisplayOne(int class, int layer, int x, int y, int oam2, int isBlend); //! FE8U = 0x080BAC1C const void * MMS_GetGfx(u16 idx) { - return gMMSDataTable[idx - 1].pGraphics; + return gMuInfoTable[idx - 1].img; } //! FE8U = 0x080BAC30 const void * MMS_GetROMTCS2(u16 idx) { - return gMMSDataTable[idx - 1].pAnimation; + return gMuInfoTable[idx - 1].anim; } //! FE8U = 0x080BAC44 From 789afb3653b8ed41961d61fbecaa962ae25307b3 Mon Sep 17 00:00:00 2001 From: MokhaLeee Date: Thu, 11 Jul 2024 12:34:01 +0800 Subject: [PATCH 2/7] mu review in process --- include/bmmind.h | 2 +- include/bmudisp.h | 2 +- include/bmunit.h | 6 + include/mapanim.h | 6 +- include/mu.h | 249 ++++++----- include/muctrl.h | 2 +- include/proc.h | 2 +- include/sio.h | 4 +- include/statscreen.h | 2 +- src/bmio.c | 8 +- src/bmmenu.c | 4 +- src/bmmind.c | 12 +- src/bmshop.c | 4 +- src/bmtrap.c | 8 +- src/bmudisp.c | 4 +- src/bmusailment.c | 2 +- src/classchg-event.c | 2 +- src/classchg-sel.c | 2 +- src/cp_perform.c | 16 +- src/data_classes.c | 48 +-- src/event.c | 2 +- src/eventscr.c | 8 +- src/eventscr3.c | 4 +- src/koido.c | 16 +- src/main.c | 2 +- src/mapanim_api.c | 16 +- src/mapanim_eventbattle.c | 2 +- src/mapanim_spellassoc.c | 44 +- src/mu.c | 859 ++++++++++++++++++-------------------- src/muctrl.c | 16 +- src/playerphase.c | 16 +- src/prep_itemsupply.c | 4 +- src/sio_battlemap.c | 68 +-- src/sio_mu.c | 52 +-- src/statscreen.c | 2 +- src/uiarena.c | 8 +- src/unit_facing.c | 2 +- src/worldmap_main.c | 2 +- src/worldmap_status_ui.c | 4 +- 39 files changed, 734 insertions(+), 778 deletions(-) diff --git a/include/bmmind.h b/include/bmmind.h index 0fc21ed48..f8cb6194e 100644 --- a/include/bmmind.h +++ b/include/bmmind.h @@ -58,7 +58,7 @@ struct CombatActionProc { /* 29 */ u8 unk_29[0x54-0x29]; - /* 54 */ struct MUProc* unk_54; + /* 54 */ struct MuProc* unk_54; /* 58 */ u8 unk_58[0x64-0x58]; /* 64 */ s16 unitIdA; diff --git a/include/bmudisp.h b/include/bmudisp.h index 866232f34..518b56a8a 100644 --- a/include/bmudisp.h +++ b/include/bmudisp.h @@ -6,7 +6,7 @@ void SetupMapSpritesPalettes(void); // ??? sub_8026670(???); void ResetUnitSprites(void); // ??? ResetUnitSpritesB(???); -int SMS_80266F0(int smsId, int frameId); +int StartUiSMS(int smsId, int frameId); int SMS_SomethingGmapUnit(int smsId, int frameId, int slot); int UseUnitSprite(u32); int ApplyUnitSpriteImage16x16(int, u32); diff --git a/include/bmunit.h b/include/bmunit.h index 0c39c0295..1ee2800ab 100644 --- a/include/bmunit.h +++ b/include/bmunit.h @@ -117,6 +117,12 @@ struct ClassData /* 50 */ const void * _pU50; }; +enum { + // ClassData::slowWalking + UNIT_WALKSPEED_FAST, + UNIT_WALKSPEED_SLOW, +}; + struct Unit { /* 00 */ const struct CharacterData* pCharacterData; diff --git a/include/mapanim.h b/include/mapanim.h index 15b3bcfd2..1bc9d4ebe 100644 --- a/include/mapanim.h +++ b/include/mapanim.h @@ -180,7 +180,7 @@ struct MapAnimStarfxConf { struct MapAnimActorState { /* 00 */ struct Unit * unit; /* 04 */ struct BattleUnit * bu; - /* 08 */ struct MUProc * mu; + /* 08 */ struct MuProc * mu; /* 0C */ u8 hp_max; /* 0D */ u8 hp_cur; /* 0E */ u16 hp_displayed_q4; @@ -821,8 +821,8 @@ void sub_8081348(void); void sub_8081384(void); void sub_80813C0(void); void MapAnim_BeginSubjectFastAnim(void); -void MapAnimMoveUnitTowardsTargetExt(struct MUProc * mu1, struct MUProc * mu2); -void MapAnimMoveUnitAwayFromTargetExt(struct MUProc * mu1, struct MUProc * mu2); +void MapAnimMoveUnitTowardsTargetExt(struct MuProc * mu1, struct MuProc * mu2); +void MapAnimMoveUnitAwayFromTargetExt(struct MuProc * mu1, struct MuProc * mu2); void MapAnim_MoveSubjectsTowardsTarget(void); void MapAnim_MoveSubjectsAwayFromTarget(void); void MapAnim_MoveCameraOnSubject(ProcPtr proc); diff --git a/include/mu.h b/include/mu.h index f32312a5d..785a40886 100644 --- a/include/mu.h +++ b/include/mu.h @@ -105,66 +105,65 @@ enum MU_FLASH_YELLOW, }; -struct MUConfig; +struct MuConfig; -struct MUProc { +struct MuProc { PROC_HEADER; - /* 2C */ struct Unit * pUnit; - /* 30 */ struct APHandle * pAPHandle; - /* 34 */ struct MUConfig * pMUConfig; + /* 2C */ struct Unit * unit; + /* 30 */ struct APHandle * sprite_anim; + /* 34 */ struct MuConfig * config; /* 38 */ void* pGfxVRAM; /* 3C */ u8 muIndex; /* 3D */ u8 _u3D; - /* 3E */ u8 boolAttractCamera; - /* 3F */ u8 stateId; - /* 40 */ u8 boolIsHidden; - /* 41 */ u8 displayedClassId; - /* 42 */ s8 facingId; - /* 43 */ u8 stepSoundTimer; + /* 3E */ u8 cam_b; + /* 3F */ u8 state; + /* 40 */ u8 hidden_b; + /* 41 */ u8 jid; + /* 42 */ s8 facing; + /* 43 */ u8 step_sound_clock; /* 44 */ u8 boolForceMaxSpeed; - /* 46 */ u16 objPriorityBits; - /* 48 */ u16 moveTimer; + /* 46 */ u16 layer; + /* 48 */ u16 move_clock_q4; /* 4A */ short moveConfig; // Coordinates are in 16th of pixel - /* 4C */ short xSubPosition; - /* 4E */ short ySubPosition; - /* 50 */ short xSubOffset; - /* 52 */ short ySubOffset; + /* 4C */ short x_q4; + /* 4E */ short y_q4; + /* 50 */ short x_offset_q4; + /* 52 */ short y_offset_q4; }; -#define MU_GetDisplayXOrg(proc) ((((proc)->xSubPosition + (proc)->xSubOffset) >> MU_SUBPIXEL_PRECISION) + 8) -#define MU_GetDisplayYOrg(proc) ((((proc)->ySubPosition + (proc)->ySubOffset) >> MU_SUBPIXEL_PRECISION) + 8) +#define MU_GetDisplayXOrg(proc) ((((proc)->x_q4 + (proc)->x_offset_q4) >> MU_SUBPIXEL_PRECISION) + 8) +#define MU_GetDisplayYOrg(proc) ((((proc)->y_q4 + (proc)->y_offset_q4) >> MU_SUBPIXEL_PRECISION) + 8) -struct MUConfig { +struct MuConfig { /* 00 */ u8 muIndex; - /* 01 */ u8 paletteIndex; - /* 02 */ u16 objTileIndex; + /* 01 */ u8 pal; + /* 02 */ u16 chr; /* 04 */ u8 currentCommand; /* 05 */ s8 commands[MU_COMMAND_MAX_COUNT]; /* 45 */ // 3 byte padding - /* 48 */ struct MUProc * pMUProc; + /* 48 */ struct MuProc * mu; }; -#define MU_AdvanceGetCommand(proc) (proc->pMUConfig->commands[proc->pMUConfig->currentCommand++]) +#define MU_AdvanceGetCommand(proc) (proc->config->commands[proc->config->currentCommand++]) -struct MUStepSoundProc +struct MuStepSoundProc { PROC_HEADER; + STRUCT_PAD(0x29, 0x58); - /* 29 */ STRUCT_PAD(0x29, 0x58); - - /* 58 */ u32 idSound1; - /* 5C */ u32 idSound2; + /* 58 */ u32 song1; + /* 5C */ u32 song2; /* 60 */ u32 u60_buggedmaybe; // Checked for in MU_StartStepSfx but never initialized - /* 64 */ s16 xSound1; - /* 66 */ s16 xSound2; + /* 64 */ s16 x1; + /* 66 */ s16 x2; }; -struct MUFogBumpFxProc +struct MuFogBumpProc { PROC_HEADER; @@ -172,29 +171,29 @@ struct MUFogBumpFxProc /* 30 */ int yDisplay; /* 34 */ STRUCT_PAD(0x34, 0x50); - /* 50 */ struct APHandle * pAPHandle; + /* 50 */ struct APHandle * sprite_anim; /* 54 */ STRUCT_PAD(0x54, 0x64); /* 64 */ s16 timer; }; -struct MUEffectProc +struct MuEffectProc { PROC_HEADER; /* 29 */ STRUCT_PAD(0x29, 0x54); - /* 54 */ struct MUProc * pMUProc; + /* 54 */ struct MuProc * mu; /* 58 */ STRUCT_PAD(0x58, 0x64); /* 64 */ s16 timeLeft; /* 66 */ s16 frameIndex; }; -struct MUFlashEffectProc +struct MuFlashEffectProc { PROC_HEADER; - /* 2C */ struct MUProc * pMUProc; + /* 2C */ struct MuProc * mu; /* 30 */ u8 timer; }; @@ -206,109 +205,109 @@ struct MuInfo { extern CONST_DATA struct MuInfo unit_icon_move_table[]; #define gMuInfoTable unit_icon_move_table -typedef void (* MuStateFunc)(struct MUProc *); - -void MU_Init(); -struct MUProc * MU_CreateExt(struct Unit* pUnit, unsigned jid, unsigned palId); -struct MUProc * MU_Create(struct Unit* pUnit); -void MU_ManualUpdate(struct MUProc * proc); -void MU_EnableAttractCamera(struct MUProc * proc); -void MU_DisableAttractCamera(struct MUProc * proc); -struct MUProc * MU_CreateForUI(struct Unit* pUnit, int x, int y); -void MU_8078524(struct MUProc * proc); -struct MUProc * MU_CreateInternal(u16 x, u16 y, u16 jid, int objTileId, unsigned palId); -void MU_SetFacing(struct MUProc * proc, int facingId); -void MU_SetDefaultFacing(struct MUProc * proc); -void MU_SetDefaultFacing_Auto(void); -void MU_StartMoveScript_Auto(const u8 commands[MU_COMMAND_MAX_COUNT]); -s8 MU_Exists(void); -s8 MU_IsAnyActive(void); -s8 MU_IsActive(struct MUProc * proc); -void MU_StartMoveScript(struct MUProc * proc, const u8 commands[MU_COMMAND_MAX_COUNT]); -struct MUProc * MU_CreateScripted(u16 x, u16 y, u16 jid, unsigned palId, const u8 commands[MU_COMMAND_MAX_COUNT]); -void MuStepSe_Init(struct MUStepSoundProc * proc); -void MuStepSe_PlaySeA(struct MUStepSoundProc * proc); -void MuStepSe_PlaySeB(struct MUStepSoundProc * proc); +typedef void (* MuStateFunc)(struct MuProc *); + +void InitMus(); +struct MuProc * StartMuExt(struct Unit * unit, unsigned jid, unsigned palId); +struct MuProc * StartMu(struct Unit * unit); +void UpdateMu(struct MuProc * proc); +void EnableMuCamera(struct MuProc * proc); +void DisableMuCamera(struct MuProc * proc); +struct MuProc * StartUiMu(struct Unit * unit, int x, int y); +void StartUiStandingMu(struct MuProc * proc); +struct MuProc * StartMuInternal(u16 x, u16 y, u16 jid, int objTileId, unsigned palId); +void SetMuFacing(struct MuProc * proc, int facing); +void SetMuDefaultFacing(struct MuProc * proc); +void SetAutoMuDefaultFacing(void); +void SetAutoMuMoveScript(const u8 commands[MU_COMMAND_MAX_COUNT]); +s8 MuExists(void); +s8 MuExistsActive(void); +s8 IsMuActive(struct MuProc * proc); +void SetMuMoveScript(struct MuProc * proc, const u8 commands[MU_COMMAND_MAX_COUNT]); +struct MuProc * StartMuScripted(u16 x, u16 y, u16 jid, int palId, const u8 commands[MU_COMMAND_MAX_COUNT]); +void MuStepSe_Init(struct MuStepSoundProc * proc); +void MuStepSe_PlaySeA(struct MuStepSoundProc * proc); +void MuStepSe_PlaySeB(struct MuStepSoundProc * proc); void MU_StartStepSfx(int soundId, int b, int hPosition); -void MU_PlayStepSfx(struct MUProc * proc); -void MU_8078894(struct MUProc * proc); -void MU_InterpretCommandScript(struct MUProc * proc); +void PlayMuStepSe(struct MuProc * proc); +void MU_8078894(struct MuProc * proc); +void MU_InterpretCommandScript(struct MuProc * proc); void MU_StartFogBumpFx(int x, int y); -void MuFogBump_Init(struct MUFogBumpFxProc * proc); -void MuFogBump_ScaleLoop(struct MUFogBumpFxProc * proc); -void MuFogBump_EndLoop(struct MUFogBumpFxProc * proc); +void MuFogBump_Init(struct MuFogBumpProc * proc); +void MuFogBump_ScaleLoop(struct MuFogBumpProc * proc); +void MuFogBump_EndLoop(struct MuFogBumpProc * proc); u8 MU_IsFogBumpFxActive(void); -void Mu_OnStateBump(struct MUProc * proc); -void Mu_OnStateMoving(struct MUProc * proc); -void Mu_OnStateSleeping(struct MUProc * proc); -void Mu_OnStateNone(struct MUProc * proc); -void Mu_OnStateDoNothing(struct MUProc * proc); -void Mu_OnStateMovement(struct MUProc * proc); -void MU_AdvanceStepSfx(struct MUProc * proc); -void MU_OnLoop(struct MUProc * proc); -void MU_OnEnd(struct MUProc * proc); +void Mu_OnStateBump(struct MuProc * proc); +void Mu_OnStateMoving(struct MuProc * proc); +void Mu_OnStateSleeping(struct MuProc * proc); +void Mu_OnStateNone(struct MuProc * proc); +void Mu_OnStateDoNothing(struct MuProc * proc); +void Mu_OnStateMovement(struct MuProc * proc); +void MU_AdvanceStepSfx(struct MuProc * proc); +void MU_OnLoop(struct MuProc * proc); +void MU_OnEnd(struct MuProc * proc); void MU_EndAll(void); -void MU_End(struct MUProc * proc); -void MU_EndInternal(struct MUProc * proc); -void MU_80790CC(struct MUProc * proc); +void MU_End(struct MuProc * proc); +void MU_EndInternal(struct MuProc * proc); +void MU_80790CC(struct MuProc * proc); void MU_AllDisable(void); void MU_AllEnable(void); void MU_GetComputedEndPosition(int * xOut, int * yOut, const u8 * commands); s8 MU_CanStart(void); void MU_AllRestartAnimations(void); -static struct MUConfig * MU_GenerateConfigDefault(int objTileId, u8 * outIndex); -static struct MUConfig * MU_GenerateConfigOther(int objTileId, u8 * outIndex); -u8 MU_ComputeDisplayPosition(struct MUProc * proc, struct Vec2 * out); -void MU_DisplayAsSMS(struct MUProc * proc); -void MU_DisplayAsMMS(struct MUProc * proc); -u16 MU_GetMovementSpeed(struct MUProc * proc); -void MU_SetMoveConfig(struct MUProc * proc, u16 config); -void* MU_GetGfxBufferById(int muIndex); -const void * MU_GetSheetGfx(struct MUProc * proc); -const void * MU_GetAnimationByClassId(u16 classId); -void MU_StartDeathFade(struct MUProc * muProc); -void MU_DeathFade_OnLoop(struct MUEffectProc * proc); -void MU_BlinkEffect_OnLoop(struct MUEffectProc * proc); -void MU_StartBlinkEffect(struct MUProc * muProc); +static struct MuConfig * GetDefaultMuConfig(int objTileId, u8 * outIndex); +static struct MuConfig * GetNewMuConfig(int objTileId, u8 * outIndex); +u8 MU_ComputeDisplayPosition(struct MuProc * proc, struct Vec2 * out); +void MU_DisplayAsSMS(struct MuProc * proc); +void MU_DisplayAsMMS(struct MuProc * proc); +u16 MU_GetMovementSpeed(struct MuProc * proc); +void MU_SetMoveConfig(struct MuProc * proc, u16 config); +void* GetMuImgBufById(int muIndex); +const void * GetMuImg(struct MuProc * proc); +const void * GetMuAnimForJid(u16 classId); +void MU_StartDeathFade(struct MuProc * muProc); +void MuDeathFade_OnLoop(struct MuEffectProc * proc); +void MUBlinkEffect_OnLoop(struct MuEffectProc * proc); +void MU_StartBlinkEffect(struct MuProc * muProc); void MU_SetupPixelEffect(u32* data, int frame); -void MU_PixelEffect_OnLoop(struct MUEffectProc * proc); -void MU_StartPixelEffect(struct MUProc * muProc); -void MU_Hide(struct MUProc * proc); -void MU_Show(struct MUProc * proc); -void MU_SetDisplayPosition(struct MUProc * proc, int x, int y); -void MU_SetDisplayOffset(struct MUProc * proc, int xOff, int yOff); -void MU_StartFlashFade(struct MUProc * proc, int flashType); -void MU_8079858(struct MUProc * muProc); -void MU_807988C(struct MUEffectProc * proc); -void MU_StartActionAnim(struct MUProc * proc); +void MuPixelEffect_OnLoop(struct MuEffectProc * proc); +void MU_StartPixelEffect(struct MuProc * muProc); +void MU_Hide(struct MuProc * proc); +void MU_Show(struct MuProc * proc); +void MU_SetDisplayPosition(struct MuProc * proc, int x, int y); +void MU_SetDisplayOffset(struct MuProc * proc, int xOff, int yOff); +void MU_StartFlashFade(struct MuProc * proc, int flashType); +void MU_8079858(struct MuProc * muProc); +void MuRestorePalInfo_Apply(struct MuEffectProc * proc); +void MU_StartActionAnim(struct MuProc * proc); void MU_EndSelectionApAnim(int argAp); -void MU_StartDelayedFaceTarget(struct MUProc * proc); +void MU_StartDelayedFaceTarget(struct MuProc * proc); void MU_EndRefaceApAnim(int argAp); void MU_EndFasterApAnim(int argAp); -void MU_StartFastMoveAnim(struct MUProc * proc); -void MU_StartCritFlash(struct MUProc * muProc, int flashType); -void MU_CritFlash_Init(struct MUFlashEffectProc * proc); -void MU_CritFlash_SetFadedPalette(struct MUFlashEffectProc * proc); -void MU_CritFlash_SetRegularPalette(struct MUFlashEffectProc * proc); -void MU_CritFlash_StartFadeBack_maybe(struct MUFlashEffectProc * proc); -void MU_CritFlash_SpriteShakeLoop(struct MUFlashEffectProc * proc); -void MU_CritFlash_RestorePalette(struct MUFlashEffectProc * proc); -void MU_StartHitFlash(struct MUProc * muProc, int flashType); -void MU_HitFlash_RestorePalette(struct MUFlashEffectProc * proc); +void MU_StartFastMoveAnim(struct MuProc * proc); +void MU_StartCritFlash(struct MuProc * muProc, int flashType); +void MuCritFlash_Init(struct MuFlashEffectProc * proc); +void MuCritFlash_SetFadedPalette(struct MuFlashEffectProc * proc); +void MuCritFlash_SetRegularPalette(struct MuFlashEffectProc * proc); +void MuCritFlash_StartFadeBack_maybe(struct MuFlashEffectProc * proc); +void MuCritFlash_SpriteShakeLoop(struct MuFlashEffectProc * proc); +void MuCritFlash_RestorePalette(struct MuFlashEffectProc * proc); +void MU_StartHitFlash(struct MuProc * muProc, int flashType); +void MuHitFlash_RestorePalette(struct MuFlashEffectProc * proc); void MU_AllForceSetMaxMoveSpeed(void); void MU_ForceSetMaxMoveSpeed(ProcPtr proc); -void MU_SetSpecialSprite(struct MUProc * proc, int displayedClassId, const u16 * palette); -void MU_SetPaletteId(struct MUProc * proc, unsigned paletteId); -struct MUProc * MU_GetByIndex(int muIndex); -struct MUProc * MU_GetByUnit(struct Unit* unit); +void MU_SetSpecialSprite(struct MuProc * proc, int jid, const u16 * palette); +void MU_SetPaletteId(struct MuProc * proc, unsigned paletteId); +struct MuProc * MU_GetByIndex(int muIndex); +struct MuProc * MU_GetByUnit(struct Unit * unit); void MU_SortObjLayers(void); extern u8 gMUGfxBuffer[MU_GFX_MAX_SIZE * MU_MAX_COUNT]; -extern struct ProcCmd CONST_DATA gProcScr_MoveUnit[]; -extern struct ProcCmd CONST_DATA gProcScr_MUDeathFade[]; -extern struct ProcCmd CONST_DATA gProcScr_MUBlinkEffect[]; -extern struct ProcCmd CONST_DATA gProcScr_MU_89A2CF8[]; +extern struct ProcCmd CONST_DATA ProcScr_Mu[]; +extern struct ProcCmd CONST_DATA ProcScr_MuDeathFade[]; +extern struct ProcCmd CONST_DATA ProcScr_MuBlinkEffect[]; +extern struct ProcCmd CONST_DATA ProcScr_MuRestorePalInfo[]; extern u16 CONST_DATA MuSoundScr_Foot[]; extern u16 CONST_DATA MuSoundScr_FootHeavy[]; extern u16 CONST_DATA MuSoundScr_Mounted[]; @@ -325,10 +324,10 @@ extern u16 CONST_DATA MuSoundScr_Unused2[]; extern u16 CONST_DATA MuSoundScr_Boat[]; extern u16 CONST_DATA MuSoundScr_Myrrh[]; // extern ??? gUnknown_089A2C28 -// extern ??? gProcScr_MoveUnit -extern CONST_DATA struct ProcCmd gProcScr_MUDeathFade[]; -extern CONST_DATA struct ProcCmd gProcScr_MUBlinkEffect[]; -extern CONST_DATA struct ProcCmd gProcScr_MU_89A2CF8[]; +// extern ??? ProcScr_Mu +extern CONST_DATA struct ProcCmd ProcScr_MuDeathFade[]; +extern CONST_DATA struct ProcCmd ProcScr_MuBlinkEffect[]; +extern CONST_DATA struct ProcCmd ProcScr_MuRestorePalInfo[]; extern const u16 * CONST_DATA MUFlashColorLookup[]; diff --git a/include/muctrl.h b/include/muctrl.h index bfc680451..da1205e20 100644 --- a/include/muctrl.h +++ b/include/muctrl.h @@ -20,7 +20,7 @@ struct MuCtrlProc { /* 00 */ PROC_HEADER; /* 2C */ struct Unit * unit; - /* 30 */ struct MUProc * muProc; + /* 30 */ struct MuProc * muProc; /* 34 */ const struct REDA * redas; /* 38 */ u16 redaCount; /* 3A */ u16 unk_3a; diff --git a/include/proc.h b/include/proc.h index cff36be7e..22542e149 100644 --- a/include/proc.h +++ b/include/proc.h @@ -106,7 +106,7 @@ enum PROC_MARK_1 = 0x01, PROC_MARK_2 = 0x02, PROC_MARK_3 = 0x03, - PROC_MARK_4 = 0x04, + PROC_MARK_MU = 0x04, PROC_MARK_5 = 0x05, PROC_MARK_6 = 0x06, PROC_MARK_7 = 0x07, diff --git a/include/sio.h b/include/sio.h index e32b964c8..995be090b 100644 --- a/include/sio.h +++ b/include/sio.h @@ -498,7 +498,7 @@ void Clear_0203DDDC(void); // ??? sub_804BEB8(???); // ??? sub_804BED8(???); // ??? sub_804BF30(???); -void StartLinkArenaMUDeathFade(struct MUProc *); +void StartLinkArenaMUDeathFade(struct MuProc *); // ??? sub_804BFAC(???); // ??? sub_804BFF8(???); // ??? SioWarp_Init(???); @@ -511,7 +511,7 @@ void StartLinkArenaMUDeathFade(struct MUProc *); // ??? SioWarpFx_ShowMoveUnit(???); // ??? SioWarpFx_804C1D8(???); // ??? SioWarpFx_AwaitSioWarp(???); -ProcPtr StartSioWarpFx(struct Unit *, struct MUProc *, int, int, int, int, ProcPtr); +ProcPtr StartSioWarpFx(struct Unit *, struct MuProc *, int, int, int, int, ProcPtr); // ??? sub_804C260(???); void PutLinkArenaButtonSpriteAt(int, int); // ??? LAButtonSprites_Loop(???); diff --git a/include/statscreen.h b/include/statscreen.h index 1d9a6fb89..2cae37d29 100644 --- a/include/statscreen.h +++ b/include/statscreen.h @@ -101,7 +101,7 @@ struct StatScreenSt /* 06 */ short yDispOff; /* 08 */ s8 inTransition; /* 0C */ struct Unit* unit; - /* 10 */ struct MUProc* mu; + /* 10 */ struct MuProc* mu; /* 14 */ const struct HelpBoxInfo* help; /* 18 */ struct Text text[STATSCREEN_TEXT_MAX]; }; diff --git a/src/bmio.c b/src/bmio.c index 7deb251d7..ba4c09227 100644 --- a/src/bmio.c +++ b/src/bmio.c @@ -1165,8 +1165,8 @@ void RefreshBMapDisplay_FromBattle(void) { void BMapDispResume_FromBattleDelayed(void) { LoadObjUIGfx(); - MU_Create(&gBattleActor.unit); - MU_SetDefaultFacing_Auto(); + StartMu(&gBattleActor.unit); + SetAutoMuDefaultFacing(); Proc_Start(sProc_DelayedBMapDispResume, PROC_TREE_3); } @@ -1295,8 +1295,8 @@ void MapMain_ResumeFromAction(struct BMapMainProc* mapMain) { HideUnitSprite(GetUnit(gActionData.subjectIndex)); - MU_Create(gActiveUnit); - MU_SetDefaultFacing_Auto(); + StartMu(gActiveUnit); + SetAutoMuDefaultFacing(); } void MapMain_ResumeFromBskPhase(struct BMapMainProc* mapMain) { diff --git a/src/bmmenu.c b/src/bmmenu.c index 3896fd726..36fb71dde 100644 --- a/src/bmmenu.c +++ b/src/bmmenu.c @@ -2203,7 +2203,7 @@ u8 RideCommandEffect(struct MenuProc* menu, struct MenuItemProc* menuItem) { RideBallista(gActiveUnit); MU_EndAll(); - MU_Create(gActiveUnit); + StartMu(gActiveUnit); return MENU_ACT_SKIPCURSOR | MENU_ACT_END | MENU_ACT_SND6A | MENU_ACT_CLEAR; } @@ -2226,7 +2226,7 @@ u8 ExitCommandEffect(struct MenuProc* menu, struct MenuItemProc* menuItem) { TryRemoveUnitFromBallista(gActiveUnit); MU_EndAll(); - MU_Create(gActiveUnit); + StartMu(gActiveUnit); return MENU_ACT_SKIPCURSOR | MENU_ACT_END | MENU_ACT_SND6A | MENU_ACT_CLEAR; } diff --git a/src/bmmind.c b/src/bmmind.c index 169f392da..5b4cffb8c 100644 --- a/src/bmmind.c +++ b/src/bmmind.c @@ -33,7 +33,7 @@ EWRAM_DATA struct ActionData gActionData = { 0 }; struct ProcCmd CONST_DATA sProcScr_AfterDropAction[] = { PROC_SLEEP(0), - PROC_WHILE(MU_IsAnyActive), + PROC_WHILE(MuExistsActive), PROC_CALL_2(AfterDrop_CheckTrapAfterDropMaybe), PROC_CALL(sub_80321C8), @@ -217,7 +217,7 @@ s8 ActionDrop(ProcPtr proc) { if (gBmMapHidden[gActionData.yOther][gActionData.xOther] & HIDDEN_BIT_UNIT) { gWorkingMovementScript[0] = MU_COMMAND_BUMP; gWorkingMovementScript[1] = MU_COMMAND_HALT; - MU_StartMoveScript_Auto(gWorkingMovementScript); + SetAutoMuMoveScript(gWorkingMovementScript); return 0; } @@ -559,12 +559,12 @@ bool DidUnitDie(struct Unit* unit) { //! FE8U = 0x080327B4 void BATTLE_PostCombatDeathFades(struct CombatActionProc* proc) { - struct MUProc* muProc; + struct MuProc* muProc; proc->unk_54 = NULL; if (DidUnitDie(&gBattleActor.unit)) { - muProc = Proc_Find(gProcScr_MoveUnit); + muProc = Proc_Find(ProcScr_Mu); MU_StartDeathFade(muProc); proc->unk_54 = muProc; @@ -578,12 +578,12 @@ void BATTLE_PostCombatDeathFades(struct CombatActionProc* proc) { TryRemoveUnitFromBallista(target); RefreshUnitSprites(); - muProc = MU_Create(&gBattleTarget.unit); + muProc = StartMu(&gBattleTarget.unit); gWorkingMovementScript[0] = GetFacingDirection(gBattleActor.unit.xPos, gBattleActor.unit.yPos, gBattleTarget.unit.xPos, gBattleTarget.unit.yPos); gWorkingMovementScript[1] = MU_COMMAND_HALT; - MU_StartMoveScript(muProc, gWorkingMovementScript); + SetMuMoveScript(muProc, gWorkingMovementScript); MU_StartDeathFade(muProc); proc->unk_54 = muProc; diff --git a/src/bmshop.c b/src/bmshop.c index 93e651e6d..601a2c9fd 100644 --- a/src/bmshop.c +++ b/src/bmshop.c @@ -801,7 +801,7 @@ void Shop_ExitShopDialogue(struct ProcShop * proc) void Shop_OnExit(void) { Proc_EndEach(gProcScr_GoldBox); - Proc_ForEach(gProcScr_MoveUnit, (ProcFunc) MU_Show); + Proc_ForEach(ProcScr_Mu, (ProcFunc) MU_Show); } void Shop_PrepEntryDialogue(struct ProcShop * proc) @@ -904,7 +904,7 @@ void Shop_Init(struct ProcShop * proc) else StartBgm(0x35, 0); - Proc_ForEach(gProcScr_MoveUnit, (ProcFunc) MU_Hide); + Proc_ForEach(ProcScr_Mu, (ProcFunc) MU_Hide); InitShopScreenConfig(); diff --git a/src/bmtrap.c b/src/bmtrap.c index 8699dce8b..5ba2b41a8 100644 --- a/src/bmtrap.c +++ b/src/bmtrap.c @@ -24,7 +24,7 @@ struct ProcCmd CONST_DATA sProcScr_ExecTrap8[] = { PROC_SLEEP(1), - PROC_WHILE(MU_IsAnyActive), + PROC_WHILE(MuExistsActive), PROC_CALL(RegisterTrapDeathBWL), PROC_CALL(ExecFireTileTrapAnim1), PROC_YIELD, @@ -40,7 +40,7 @@ struct ProcCmd CONST_DATA sProcScr_ExecTrap8[] = { struct ProcCmd CONST_DATA sProcScr_ExecTrapMine[] = { PROC_SLEEP(1), - PROC_WHILE(MU_IsAnyActive), + PROC_WHILE(MuExistsActive), PROC_CALL(RegisterTrapDeathBWL), PROC_CALL(ExecFireTileTrapAnim2), PROC_YIELD, @@ -83,8 +83,8 @@ void ApplyTrapDamageAnim(struct ProcBmTrap * proc) case 1: MU_EndAll(); - MU_Create(gActiveUnit); - MU_SetDefaultFacing_Auto(); + StartMu(gActiveUnit); + SetAutoMuDefaultFacing(); break; case 2: diff --git a/src/bmudisp.c b/src/bmudisp.c index 620c8bf6d..e86521bce 100644 --- a/src/bmudisp.c +++ b/src/bmudisp.c @@ -401,7 +401,7 @@ void ResetUnitSpritesB(void) { } //! FE8U = 0x080266F0 -int SMS_80266F0(int smsId, int frameId) { +int StartUiSMS(int smsId, int frameId) { int slot = gSomeSMSLookupTable_859B66C[frameId]; @@ -1313,7 +1313,7 @@ void UnitSpriteHoverUpdate(void) { gMapSpriteSwitchHoverTimer++; if (gMapSpriteSwitchHoverTimer == 5) { - MU_Create(unit); + StartMu(unit); HideUnitSprite(unit); return; diff --git a/src/bmusailment.c b/src/bmusailment.c index 481ad13c9..5e60c16a3 100644 --- a/src/bmusailment.c +++ b/src/bmusailment.c @@ -213,7 +213,7 @@ void KillAllRedUnits_Loop(struct UnknownBMUSAilmentProc* proc) { proc->unk_4C++; Proc_Goto(proc, 0); } else { - MU_StartDeathFade(MU_Create(unit)); + MU_StartDeathFade(StartMu(unit)); proc->unk_4C++; Proc_Break(proc); } diff --git a/src/classchg-event.c b/src/classchg-event.c index 08379446c..cc787b4cd 100644 --- a/src/classchg-event.c +++ b/src/classchg-event.c @@ -21,7 +21,7 @@ void sub_80CD62C(void) RefreshBMapGraphics(); RefreshEntityBmMaps(); MU_EndAll(); - MU_Create(gActiveUnit); + StartMu(gActiveUnit); RenderBmMap(); RefreshUnitSprites(); } diff --git a/src/classchg-sel.c b/src/classchg-sel.c index 1bedacf54..95796dd76 100644 --- a/src/classchg-sel.c +++ b/src/classchg-sel.c @@ -435,7 +435,7 @@ void PrepClassChgOnCancel(struct ProcPromoSel *proc) RenderBmMap(); RefreshUnitSprites(); MU_EndAll(); - MU_Create(gActiveUnit); + StartMu(gActiveUnit); } } diff --git a/src/cp_perform.c b/src/cp_perform.c index 09b74fa5f..b28025beb 100644 --- a/src/cp_perform.c +++ b/src/cp_perform.c @@ -73,7 +73,7 @@ struct ProcCmd CONST_DATA gProcScr_CpPerform[] = { PROC_SLEEP(0), PROC_CALL(CpPerform_BeginUnitMovement), - PROC_WHILE(MU_IsAnyActive), + PROC_WHILE(MuExistsActive), PROC_CALL(CpPerform_MoveCameraOntoTarget), PROC_SLEEP(0), @@ -167,9 +167,9 @@ void CpPerform_BeginUnitMovement(struct CpPerformProc* proc) { gAiDecision.yMove = gActionData.yMove; if (proc->isUnitVisible) { - MU_Create(gActiveUnit); - MU_SetDefaultFacing_Auto(); - MU_StartMoveScript_Auto(gWorkingMovementScript); + StartMu(gActiveUnit); + SetAutoMuDefaultFacing(); + SetAutoMuMoveScript(gWorkingMovementScript); } return; @@ -234,7 +234,7 @@ void AiStartEscapeAction(struct CpPerformProc* proc) { }; if ((gAiDecision.xTarget != 5) && (proc->isUnitVisible)) { - MU_StartMoveScript_Auto(scripts[gAiDecision.xTarget]); + SetAutoMuMoveScript(scripts[gAiDecision.xTarget]); } return; @@ -435,8 +435,8 @@ void CpPerform_MoveCameraOntoTarget(struct CpPerformProc* proc) { RideBallista(gActiveUnit); - MU_Create(gActiveUnit); - MU_SetDefaultFacing_Auto(); + StartMu(gActiveUnit); + SetAutoMuDefaultFacing(); } break; @@ -602,7 +602,7 @@ s8 AiDummyAction(struct CpPerformProc* proc) { } s8 AiEscapeAction(struct CpPerformProc* proc) { - if (!MU_IsAnyActive()) { + if (!MuExistsActive()) { gActiveUnit->pCharacterData = NULL; return 1; } diff --git a/src/data_classes.c b/src/data_classes.c index ef3a10f9c..1066f27a0 100644 --- a/src/data_classes.c +++ b/src/data_classes.c @@ -479,7 +479,7 @@ CONST_DATA struct ClassData gClassData[] = { .number = CLASS_ARMOR_KNIGHT, .promotion = CLASS_GENERAL, .SMSId = 0x6, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x76, .sort_order = 0xc, @@ -536,7 +536,7 @@ CONST_DATA struct ClassData gClassData[] = { .number = CLASS_ARMOR_KNIGHT_F, .promotion = CLASS_GENERAL_F, .SMSId = 0x6, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x76, .sort_order = 0xc, @@ -593,7 +593,7 @@ CONST_DATA struct ClassData gClassData[] = { .number = CLASS_GENERAL, .promotion = CLASS_ARMOR_KNIGHT, .SMSId = 0x7, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x77, .sort_order = 0xd, @@ -654,7 +654,7 @@ CONST_DATA struct ClassData gClassData[] = { .number = CLASS_GENERAL_F, .promotion = CLASS_ARMOR_KNIGHT_F, .SMSId = 0x7, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x77, .sort_order = 0xd, @@ -2575,7 +2575,7 @@ CONST_DATA struct ClassData gClassData[] = { .number = CLASS_SHAMAN, .promotion = CLASS_DRUID, .SMSId = 0x26, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x7e, .sort_order = 0x1b, @@ -2632,7 +2632,7 @@ CONST_DATA struct ClassData gClassData[] = { .number = CLASS_SHAMAN_F, .promotion = CLASS_DRUID_F, .SMSId = 0x26, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x7e, .sort_order = 0x1b, @@ -2689,7 +2689,7 @@ CONST_DATA struct ClassData gClassData[] = { .number = CLASS_DRUID, .promotion = CLASS_SHAMAN, .SMSId = 0x27, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x7f, .sort_order = 0x1c, @@ -2750,7 +2750,7 @@ CONST_DATA struct ClassData gClassData[] = { .number = CLASS_DRUID_F, .promotion = CLASS_SHAMAN_F, .SMSId = 0x27, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x7f, .sort_order = 0x1c, @@ -3036,7 +3036,7 @@ CONST_DATA struct ClassData gClassData[] = { .number = CLASS_GREAT_KNIGHT, .promotion = CLASS_ARMOR_KNIGHT, .SMSId = 0x2b, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x96, .sort_order = 0x22, @@ -3097,7 +3097,7 @@ CONST_DATA struct ClassData gClassData[] = { .number = CLASS_GREAT_KNIGHT_F, .promotion = CLASS_ARMOR_KNIGHT_F, .SMSId = 0x2b, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x96, .sort_order = 0x22, @@ -6105,7 +6105,7 @@ CONST_DATA struct ClassData gClassData[] = { .descTextId = 0x351, .number = CLASS_CIVILIAN_M1, .SMSId = 0x5e, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x5e, .baseHP = 8, @@ -6155,7 +6155,7 @@ CONST_DATA struct ClassData gClassData[] = { .descTextId = 0x351, .number = CLASS_CIVILIAN_F1, .SMSId = 0x5f, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x63, .baseHP = 7, @@ -6205,7 +6205,7 @@ CONST_DATA struct ClassData gClassData[] = { .descTextId = 0x351, .number = CLASS_CIVILIAN_M2, .SMSId = 0x60, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x59, .baseHP = 10, @@ -6255,7 +6255,7 @@ CONST_DATA struct ClassData gClassData[] = { .descTextId = 0x351, .number = CLASS_CIVILIAN_F2, .SMSId = 0x61, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x62, .baseHP = 9, @@ -6305,7 +6305,7 @@ CONST_DATA struct ClassData gClassData[] = { .descTextId = 0x351, .number = CLASS_CIVILIAN_M3, .SMSId = 0x60, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x5c, .baseHP = 12, @@ -6355,7 +6355,7 @@ CONST_DATA struct ClassData gClassData[] = { .descTextId = 0x351, .number = CLASS_CIVILIAN_F3, .SMSId = 0x61, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x61, .baseHP = 10, @@ -6403,7 +6403,7 @@ CONST_DATA struct ClassData gClassData[] = { [CLASS_PEER - 1] = { .number = CLASS_PEER, .SMSId = 0x62, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x1, .baseHP = 10, @@ -6453,7 +6453,7 @@ CONST_DATA struct ClassData gClassData[] = { .descTextId = 0x353, .number = CLASS_QUEEN, .SMSId = 0x63, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x1, .baseHP = 10, @@ -6501,7 +6501,7 @@ CONST_DATA struct ClassData gClassData[] = { [CLASS_PRINCE - 1] = { .number = CLASS_PRINCE, .SMSId = 0x64, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x1, .baseHP = 10, @@ -6551,7 +6551,7 @@ CONST_DATA struct ClassData gClassData[] = { .descTextId = 0x353, .number = CLASS_QUEEN_2, .SMSId = 0x65, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x1, .baseHP = 10, @@ -6643,7 +6643,7 @@ CONST_DATA struct ClassData gClassData[] = { [CLASS_FALLEN_PRINCE - 1] = { .number = CLASS_FALLEN_PRINCE, .SMSId = 0x67, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x1, .baseHP = 10, @@ -6691,7 +6691,7 @@ CONST_DATA struct ClassData gClassData[] = { [CLASS_TENT - 1] = { .number = CLASS_TENT, .SMSId = 0x68, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x1, .baseHP = 15, @@ -6743,7 +6743,7 @@ CONST_DATA struct ClassData gClassData[] = { .descTextId = 0x352, .number = CLASS_PONTIFEX, .SMSId = 0x69, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x1, .baseHP = 10, @@ -6791,7 +6791,7 @@ CONST_DATA struct ClassData gClassData[] = { [CLASS_FALLEN_PEER - 1] = { .number = CLASS_FALLEN_PEER, .SMSId = 0x6a, - .slowWalking = 0x1, + .slowWalking = UNIT_WALKSPEED_SLOW, .defaultPortraitId = 0x1, .baseHP = 10, diff --git a/src/event.c b/src/event.c index d7bb3a595..81b51a0ea 100644 --- a/src/event.c +++ b/src/event.c @@ -419,7 +419,7 @@ bool8 EventEngine_CanStartSkip(struct EventEngineProc* proc) { // Events_CanSkip if (IsBattleDeamonActive()) return FALSE; - if (Proc_Find(gProcScr_MUDeathFade)) + if (Proc_Find(ProcScr_MuDeathFade)) return FALSE; return TRUE; diff --git a/src/eventscr.c b/src/eventscr.c index db54e3bbd..da96f11ba 100644 --- a/src/eventscr.c +++ b/src/eventscr.c @@ -3433,12 +3433,12 @@ u8 Event34_MessWithUnitState(struct EventEngineProc * proc) case EVSUBCMD_KILL: if (!EVENT_IS_SKIPPING(proc)) { - struct MUProc * muProc; + struct MuProc * muProc; HideUnitSprite(unit); unit->state |= US_HIDDEN; - muProc = MU_Create(unit); - MU_SetDefaultFacing_Auto(); + muProc = StartMu(unit); + SetAutoMuDefaultFacing(); MU_StartDeathFade(muProc); return EVC_ADVANCE_YIELD; @@ -3448,7 +3448,7 @@ u8 Event34_MessWithUnitState(struct EventEngineProc * proc) case EVSUBCMD_DISA_IF: { - s8 a = Proc_Find(gProcScr_MUDeathFade) != 0; + s8 a = Proc_Find(ProcScr_MuDeathFade) != 0; if (-a | a) return EVC_STOP_YIELD; } diff --git a/src/eventscr3.c b/src/eventscr3.c index 8cc1e7999..47be31743 100644 --- a/src/eventscr3.c +++ b/src/eventscr3.c @@ -328,8 +328,8 @@ void StartEventBattle(struct Unit * unitA, struct Unit * unitB, u8 isBallista, s { UnitBeginAction(unitA); HideUnitSprite(gActiveUnit); - MU_Create(gActiveUnit); - MU_SetDefaultFacing_Auto(); + StartMu(gActiveUnit); + SetAutoMuDefaultFacing(); if ((GetItemType(unitA->items[0]) == ITYPE_STAFF) || (item != 0)) { diff --git a/src/koido.c b/src/koido.c index bc4b31967..da43a2066 100644 --- a/src/koido.c +++ b/src/koido.c @@ -14,7 +14,7 @@ struct KoidoProc { /* 2C */ int direction; /* 30 */ struct Unit* unit; - /* 34 */ struct MUProc* proc_mu; + /* 34 */ struct MuProc* proc_mu; /* 38 */ u8 mu_commands[0x03]; /* 3B */ u8 unk_3B; /* 3C */ s8 config; @@ -57,21 +57,21 @@ int GetSomeFacingDirection(int x0, int y0, int x1, int y1) return FACING_RIGHT; } -struct MUProc* Make6CMOVEUNITForUnitBeingRescued(struct Unit* unit) +struct MuProc* Make6CMOVEUNITForUnitBeingRescued(struct Unit* unit) { const u32 attributes = UNIT_CATTRIBUTES(unit); if (!(CA_MOUNTEDAID & attributes)) - return MU_Create(unit); + return StartMu(unit); else return (CA_FEMALE & attributes) - ? MU_CreateExt(unit, CLASS_CIVILIAN_F2,0xC) - : MU_CreateExt(unit, CLASS_CIVILIAN_M2,0xC); + ? StartMuExt(unit, CLASS_CIVILIAN_F2,0xC) + : StartMuExt(unit, CLASS_CIVILIAN_M2,0xC); } void Loop6C_KOIDO(struct KoidoProc* proc) { - if (MU_IsAnyActive()) + if (MuExistsActive()) return; if (2 != proc->config) @@ -88,12 +88,12 @@ void Loop6C_KOIDO(struct KoidoProc* proc) static inline void Make6CKOIDO_common(struct Unit* unit, int config, struct KoidoProc *proc) { - struct MUProc *proc_mu; + struct MuProc *proc_mu; proc->config = config; proc_mu = Make6CMOVEUNITForUnitBeingRescued(unit); proc->proc_mu = proc_mu; - MU_StartMoveScript(proc_mu, proc->mu_commands); + SetMuMoveScript(proc_mu, proc->mu_commands); } void Make6CKOIDO(struct Unit* unit, int direction, int config, ProcPtr parent) diff --git a/src/main.c b/src/main.c index 42ba2d214..180de5efa 100755 --- a/src/main.c +++ b/src/main.c @@ -55,7 +55,7 @@ void AgbMain() SramInit(); Proc_Init(); AP_ClearAll(); - MU_Init(); + InitMus(); SetLCGRNValue(0x42D690E9); InitRN(AdvanceGetLCGRNValue()); DisableKeyComboResetEN(); diff --git a/src/mapanim_api.c b/src/mapanim_api.c index 38a23838d..99dd1931d 100644 --- a/src/mapanim_api.c +++ b/src/mapanim_api.c @@ -21,10 +21,10 @@ void MakeBattleMOVEUNIT(int maActor, struct BattleUnit* bu, struct Unit* unit) gManimSt.actor[maActor].unit = unit; gManimSt.actor[maActor].bu = bu; - gManimSt.actor[maActor].mu = MU_Create(unit); + gManimSt.actor[maActor].mu = StartMu(unit); - gManimSt.actor[maActor].mu->pAPHandle->frameTimer = 0; - gManimSt.actor[maActor].mu->pAPHandle->frameInterval = 0; + gManimSt.actor[maActor].mu->sprite_anim->frameTimer = 0; + gManimSt.actor[maActor].mu->sprite_anim->frameInterval = 0; if (BUNIT_IS_OBSTACLE(bu)) MU_Hide(gManimSt.actor[maActor].mu); @@ -47,19 +47,19 @@ void SetBattleAnimFacing(int maActor, int maOpponent, int facing) gManimSt.actor[maActor].unit->xPos, gManimSt.actor[maActor].unit->yPos, gManimSt.actor[maOpponent].unit->xPos, gManimSt.actor[maOpponent].unit->yPos); - MU_SetFacing(gManimSt.actor[maActor].mu, muFacing); + SetMuFacing(gManimSt.actor[maActor].mu, muFacing); break; case MA_FACING_DEFAULT: - MU_SetDefaultFacing(gManimSt.actor[maActor].mu); + SetMuDefaultFacing(gManimSt.actor[maActor].mu); break; case MA_FACING_UNK: muFacing = GetFacingDirection( gManimSt.actor[maActor].unit->xPos, gManimSt.actor[maActor].unit->yPos, 0, 0); - MU_SetFacing(gManimSt.actor[maActor].mu, muFacing); + SetMuFacing(gManimSt.actor[maActor].mu, muFacing); break; } // switch (facing) } @@ -127,7 +127,7 @@ void sub_807B4D0(void) // Apply for (i = 0; i < count; ++i) - gManimSt.actor[array[i]].mu->pAPHandle->objLayer = gUnknown_08205714[i]; + gManimSt.actor[array[i]].mu->sprite_anim->objLayer = gUnknown_08205714[i]; } void BeginMapAnimForPoisonDmg(void) @@ -360,7 +360,7 @@ CONST_DATA struct ProcCmd gProc_MapAnimEnd[] = { PROC_CALL(MapAnimProc_DisplayDeahQuote), PROC_WHILE(BattleEventEngineExists), PROC_CALL(MapAnmiProc_DisplayDeathFade), - PROC_WHILE_EXISTS(gProcScr_MUDeathFade), + PROC_WHILE_EXISTS(ProcScr_MuDeathFade), PROC_CALL(DeleteBattleAnimInfoThing), PROC_SLEEP(0x1), PROC_CALL(MapAnimProc_DisplayItemStealingPopup), diff --git a/src/mapanim_eventbattle.c b/src/mapanim_eventbattle.c index 440a5aa2a..2fdac2615 100644 --- a/src/mapanim_eventbattle.c +++ b/src/mapanim_eventbattle.c @@ -52,7 +52,7 @@ PROC_LABEL(0x0), PROC_GOTO(0x0), PROC_LABEL(0x1), PROC_CALL(MapAnmiProc_DisplayDeathFade), - PROC_WHILE_EXISTS(gProcScr_MUDeathFade), + PROC_WHILE_EXISTS(ProcScr_MuDeathFade), PROC_CALL(DeleteBattleAnimInfoThing), PROC_SLEEP(0x1), PROC_CALL(UnlockGame), diff --git a/src/mapanim_spellassoc.c b/src/mapanim_spellassoc.c index 61364eb9d..e1d389f68 100644 --- a/src/mapanim_spellassoc.c +++ b/src/mapanim_spellassoc.c @@ -39,9 +39,9 @@ void sub_80812C0(void) else CallDelayed(sub_8081384, 0xC); - gManimSt.actor[gManimSt.subjectActorId].mu->pAPHandle->frameTimer = 0; - gManimSt.actor[gManimSt.subjectActorId].mu->pAPHandle->frameInterval = 0x100; - AP_SwitchAnimation(gManimSt.actor[gManimSt.subjectActorId].mu->pAPHandle, 0x5); + gManimSt.actor[gManimSt.subjectActorId].mu->sprite_anim->frameTimer = 0; + gManimSt.actor[gManimSt.subjectActorId].mu->sprite_anim->frameInterval = 0x100; + AP_SwitchAnimation(gManimSt.actor[gManimSt.subjectActorId].mu->sprite_anim, 0x5); } void sub_8081348(void) @@ -58,8 +58,8 @@ void sub_8081384(void) void sub_80813C0(void) { - gManimSt.actor[gManimSt.subjectActorId].mu->pAPHandle->frameTimer = 0; - gManimSt.actor[gManimSt.subjectActorId].mu->pAPHandle->frameInterval = 0; + gManimSt.actor[gManimSt.subjectActorId].mu->sprite_anim->frameTimer = 0; + gManimSt.actor[gManimSt.subjectActorId].mu->sprite_anim->frameInterval = 0; } void MapAnim_BeginSubjectFastAnim(void) @@ -67,12 +67,12 @@ void MapAnim_BeginSubjectFastAnim(void) MU_StartFastMoveAnim(gManimSt.actor[gManimSt.subjectActorId].mu); } -void MapAnimMoveUnitTowardsTargetExt(struct MUProc * mu1, struct MUProc * mu2) +void MapAnimMoveUnitTowardsTargetExt(struct MuProc * mu1, struct MuProc * mu2) { int x1, x2, y1, y2, distance; - x1 = mu1->xSubPosition; - x2 = mu2->xSubPosition; + x1 = mu1->x_q4; + x2 = mu2->x_q4; distance = x2 - x1; if (distance <= 0) @@ -86,10 +86,10 @@ void MapAnimMoveUnitTowardsTargetExt(struct MUProc * mu1, struct MUProc * mu2) else x1 = x1 + 0x10; - mu1->xSubPosition = x1; + mu1->x_q4 = x1; - y1 = mu1->ySubPosition; - y2 = mu2->ySubPosition; + y1 = mu1->y_q4; + y2 = mu2->y_q4; distance = y2 - y1; if (distance <= 0) @@ -103,15 +103,15 @@ void MapAnimMoveUnitTowardsTargetExt(struct MUProc * mu1, struct MUProc * mu2) else y1 = y1 + 0x10; - mu1->ySubPosition = y1; + mu1->y_q4 = y1; } -void MapAnimMoveUnitAwayFromTargetExt(struct MUProc * mu1, struct MUProc * mu2) +void MapAnimMoveUnitAwayFromTargetExt(struct MuProc * mu1, struct MuProc * mu2) { int x1, x2, y1, y2, distance; - x1 = mu1->xSubPosition; - x2 = mu2->xSubPosition; + x1 = mu1->x_q4; + x2 = mu2->x_q4; distance = x1 - x2; if (distance <= 0) @@ -125,10 +125,10 @@ void MapAnimMoveUnitAwayFromTargetExt(struct MUProc * mu1, struct MUProc * mu2) else x1 = x1 + 0x10; - mu1->xSubPosition = x1; + mu1->x_q4 = x1; - y1 = mu1->ySubPosition; - y2 = mu2->ySubPosition; + y1 = mu1->y_q4; + y2 = mu2->y_q4; distance = y1 - y2; if (distance <= 0) @@ -142,12 +142,12 @@ void MapAnimMoveUnitAwayFromTargetExt(struct MUProc * mu1, struct MUProc * mu2) else y1 = y1 + 0x10; - mu1->ySubPosition = y1; + mu1->y_q4 = y1; } void MapAnim_MoveSubjectsTowardsTarget(void) { - struct MUProc * mu, * mu2; + struct MuProc * mu, * mu2; mu = gManimSt.actor[gManimSt.subjectActorId].mu; mu2 = gManimSt.actor[gManimSt.targetActorId].mu; @@ -165,7 +165,7 @@ void MapAnim_MoveSubjectsTowardsTarget(void) void MapAnim_MoveSubjectsAwayFromTarget(void) { - struct MUProc * mu, * mu2; + struct MuProc * mu, * mu2; mu = gManimSt.actor[gManimSt.subjectActorId].mu; mu2 = gManimSt.actor[gManimSt.targetActorId].mu; @@ -520,7 +520,7 @@ void SpellWarpMuShow(ProcPtr proc) void SpellWarpSetNewPosition(ProcPtr proc) { struct Unit * unit = gManimSt.actor[gManimSt.targetActorId].unit; - struct MUProc * mu = gManimSt.actor[gManimSt.targetActorId].mu; + struct MuProc * mu = gManimSt.actor[gManimSt.targetActorId].mu; MU_SetDisplayPosition( mu, diff --git a/src/mu.c b/src/mu.c index 9eb15f53c..286d88535 100644 --- a/src/mu.c +++ b/src/mu.c @@ -18,12 +18,13 @@ #include "mu.h" #include "bmlib.h" #include "proc.h" +#include "ctc.h" #include "soundwrapper.h" #include "spellassoc.h" EWRAM_OVERLAY(0) int Unk_2004BDC = 0; EWRAM_OVERLAY(0) u8 gMUGfxBuffer[MU_GFX_MAX_SIZE * MU_MAX_COUNT] = { 0 }; -static struct MUConfig sMUConfigArray[MU_MAX_COUNT]; +static struct MuConfig sMuConfig[MU_MAX_COUNT]; const u16 * CONST_DATA MUFlashColorLookup[] = { [MU_FLASH_WHITE] = Pal_AllWhite, @@ -150,48 +151,40 @@ static MuStateFunc CONST_DATA sMuStateFuncs[] = { [MU_STATE_DEATHFADE] = Mu_OnStateDoNothing, }; -struct ProcCmd CONST_DATA gProcScr_MoveUnit[] = { +struct ProcCmd CONST_DATA ProcScr_Mu[] = { PROC_NAME("MOVEUNIT"), - PROC_MARK(4), + PROC_MARK(PROC_MARK_MU), PROC_SET_END_CB(MU_OnEnd), PROC_REPEAT(MU_OnLoop) }; -// obj tile id offset by MU id -static u16 CONST_DATA sMUObjTileOffsetLookup_Default[MU_MAX_COUNT] = { - 0x0000, 0x0010, 0x0008, 0x0018 +static u16 CONST_DATA sMuChrOffLut_Default[MU_MAX_COUNT] = { + 0x00, 0x10, 0x08, 0x18 }; -// obj tile id offset by MU id (variant?) -static u16 CONST_DATA sMUObjTileOffsetLookup_Other[MU_MAX_COUNT] = { - 0x0000, 0x0008, 0x0004, 0x0010 +static u16 CONST_DATA sMuChrOffLut[MU_MAX_COUNT] = { + 0x00, 0x08, 0x04, 0x10 }; -// Base Movement Speed Lookup -static u8 CONST_DATA sMUBaseMoveSpeedLookup[2] = { - 2, // fast class base movement speed - 1 // slow class base movement speed +static u8 CONST_DATA sMuWalkSpeedLut[2] = { + [UNIT_WALKSPEED_FAST] = 2, + [UNIT_WALKSPEED_SLOW] = 1, }; -// Buffer index by MU index (config) lookup -static u8 CONST_DATA sMUBufferIdLookup[MU_MAX_COUNT+1] = { - 0, // dummy entry (this array is 1-indexed) - +static u8 CONST_DATA sMuImgBufOffLut[MU_MAX_COUNT + 1] = { + 0, // dummy because active ids start at 1 0, 2, 1, 3 }; -// gProc_MUDeathFadeEffect -struct ProcCmd CONST_DATA gProcScr_MUDeathFade[] = { - PROC_REPEAT(MU_DeathFade_OnLoop), +struct ProcCmd CONST_DATA ProcScr_MuDeathFade[] = { + PROC_REPEAT(MuDeathFade_OnLoop), PROC_SLEEP(15), - PROC_END }; -// gProc_MUBlinkingEffect -struct ProcCmd CONST_DATA gProcScr_MUBlinkEffect[] = { - PROC_REPEAT(MU_BlinkEffect_OnLoop), +struct ProcCmd CONST_DATA ProcScr_MuBlinkEffect[] = { + PROC_REPEAT(MUBlinkEffect_OnLoop), PROC_END }; @@ -204,92 +197,77 @@ CONST_DATA vu8 static sUnknown_089A2CA8[0x40] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F }; - struct ProcCmd CONST_DATA ProcScr_MUPixelEffect[] = { - PROC_REPEAT(MU_PixelEffect_OnLoop), + struct ProcCmd CONST_DATA ProcScr_MuPixelEffect[] = { + PROC_REPEAT(MuPixelEffect_OnLoop), PROC_END }; -struct ProcCmd CONST_DATA gProcScr_MU_89A2CF8[] = { +struct ProcCmd CONST_DATA ProcScr_MuRestorePalInfo[] = { PROC_SLEEP(8), - PROC_CALL(MU_807988C), - + PROC_CALL(MuRestorePalInfo_Apply), PROC_END }; - struct ProcCmd CONST_DATA ProcScr_MUCritFlash[] = { - PROC_CALL(MU_CritFlash_Init), + struct ProcCmd CONST_DATA ProcScr_MuCritFlash[] = { + PROC_CALL(MuCritFlash_Init), PROC_SLEEP(1), - PROC_CALL(MU_CritFlash_SetFadedPalette), + PROC_CALL(MuCritFlash_SetFadedPalette), PROC_SLEEP(2), - PROC_CALL(MU_CritFlash_SetRegularPalette), + PROC_CALL(MuCritFlash_SetRegularPalette), PROC_SLEEP(3), - PROC_CALL(MU_CritFlash_SetFadedPalette), + PROC_CALL(MuCritFlash_SetFadedPalette), PROC_SLEEP(2), - PROC_CALL(MU_CritFlash_SetRegularPalette), + PROC_CALL(MuCritFlash_SetRegularPalette), PROC_SLEEP(3), - PROC_CALL(MU_CritFlash_SetFadedPalette), + PROC_CALL(MuCritFlash_SetFadedPalette), PROC_SLEEP(1), - PROC_CALL(MU_CritFlash_StartFadeBack_maybe), - PROC_REPEAT(MU_CritFlash_SpriteShakeLoop), + PROC_CALL(MuCritFlash_StartFadeBack_maybe), + PROC_REPEAT(MuCritFlash_SpriteShakeLoop), PROC_SLEEP(17), - PROC_CALL(MU_CritFlash_RestorePalette), + PROC_CALL(MuCritFlash_RestorePalette), PROC_END }; - struct ProcCmd CONST_DATA ProcScr_MUHitFlash[] = { + struct ProcCmd CONST_DATA ProcScr_MuHitFlash[] = { PROC_SLEEP(17), - PROC_CALL(MU_HitFlash_RestorePalette), + PROC_CALL(MuHitFlash_RestorePalette), PROC_END }; -// END CONST DATA - -void MU_Init(void) +void InitMus(void) { int i; - for (i = 0; i < MU_MAX_COUNT; ++i) - sMUConfigArray[i].muIndex = 0; + sMuConfig[i].muIndex = 0; } -struct MUProc * MU_CreateExt(struct Unit* pUnit, unsigned jid, unsigned palId) +struct MuProc * StartMuExt(struct Unit * unit, unsigned jid, unsigned pal) { - struct MUProc * proc = MU_CreateInternal( - pUnit->xPos, - pUnit->yPos, - - jid, - - -1, - palId - ); - - proc->pUnit = pUnit; - proc->boolAttractCamera = TRUE; - + struct MuProc * proc; + + proc = StartMuInternal(unit->xPos, unit->yPos, jid, -1, pal); + proc->unit = unit; + proc->cam_b = true; return proc; } -struct MUProc * MU_Create(struct Unit* pUnit) +struct MuProc * StartMu(struct Unit * unit) { - struct MUProc * proc; + struct MuProc * proc; - unsigned jid = pUnit->pClassData->number; + unsigned jid = UNIT_CLASS_ID(unit); - if (pUnit->state & US_IN_BALLISTA) + if (unit->state & US_IN_BALLISTA) { - struct Trap* blst = GetTrap(pUnit->ballistaIndex); - - switch (blst->extra) { - + switch (GetTrap(unit->ballistaIndex)->extra) { case ITEM_BALLISTA_REGULAR: jid = CLASS_BLST_REGULAR_USED; break; @@ -305,294 +283,267 @@ struct MUProc * MU_Create(struct Unit* pUnit) } // switch (blst->extra) } - proc = MU_CreateInternal( - pUnit->xPos, - pUnit->yPos, - - jid, - - -1, - GetUnitSpritePalette(pUnit) - ); - - proc->pUnit = pUnit; - proc->boolAttractCamera = TRUE; - + proc = StartMuInternal(unit->xPos, unit->yPos, jid, -1, GetUnitSpritePalette(unit)); + proc->unit = unit; + proc->cam_b = true; return proc; } -void MU_ManualUpdate(struct MUProc * proc) +void UpdateMu(struct MuProc * proc) { MU_OnLoop(proc); } -void MU_EnableAttractCamera(struct MUProc * proc) +void EnableMuCamera(struct MuProc * proc) { - proc->boolAttractCamera = TRUE; + proc->cam_b = true; } -void MU_DisableAttractCamera(struct MUProc * proc) +void DisableMuCamera(struct MuProc * proc) { - proc->boolAttractCamera = FALSE; + proc->cam_b = false; } -struct MUProc * MU_CreateForUI(struct Unit* pUnit, int x, int y) +struct MuProc * StartUiMu(struct Unit * unit, int x, int y) { - struct MUProc * proc = MU_Create(pUnit); + struct MuProc * proc = StartMu(unit); if (!proc) return NULL; - proc->xSubPosition = x << MU_SUBPIXEL_PRECISION; - proc->ySubPosition = y << MU_SUBPIXEL_PRECISION; - - proc->stateId = MU_STATE_DISPLAY_UI; - + proc->x_q4 = x << MU_SUBPIXEL_PRECISION; + proc->y_q4 = y << MU_SUBPIXEL_PRECISION; + proc->state = MU_STATE_DISPLAY_UI; return proc; } -void MU_8078524(struct MUProc * proc) +void StartUiStandingMu(struct MuProc * proc) { - SMS_80266F0( - GetClassSMSId(proc->displayedClassId), + StartUiSMS( + GetClassSMSId(proc->jid), proc->muIndex ); } -struct MUProc * MU_CreateInternal(u16 x, u16 y, u16 jid, int objTileId, unsigned palId) +struct MuProc * StartMuInternal(u16 x, u16 y, u16 jid, int objTileId, unsigned palId) { - struct MUConfig * config; - struct MUProc * proc; - struct APHandle* ap; + struct MuConfig * config; + struct MuProc * proc; + struct APHandle * ap; - u8 soundTimer = 0; - u8 muIndex = 0; + u8 delay = 0; + u8 slot = 0; if (objTileId == -1) - config = MU_GenerateConfigDefault(objTileId = MU_BASE_OBJ_TILE, &muIndex); + config = GetDefaultMuConfig(objTileId = MU_BASE_OBJ_TILE, &slot); else - config = MU_GenerateConfigOther(objTileId, &muIndex); + config = GetNewMuConfig(objTileId, &slot); if (!config) return NULL; - if (Proc_Find(gProcScr_MoveUnit)) - soundTimer = -2; + if (Proc_Find(ProcScr_Mu)) + delay = -2; - proc = Proc_Start(gProcScr_MoveUnit, PROC_TREE_5); + proc = Proc_Start(ProcScr_Mu, PROC_TREE_5); if (!proc) return NULL; - proc->pUnit = NULL; - proc->stateId = MU_STATE_INACTIVE; - - proc->xSubPosition = (x * 16) << MU_SUBPIXEL_PRECISION; - proc->ySubPosition = (y * 16) << MU_SUBPIXEL_PRECISION; - - proc->xSubOffset = 0; - proc->ySubOffset = 0; - - proc->facingId = MU_FACING_UNK11; - - proc->moveTimer = 0; - proc->stepSoundTimer = soundTimer; - - proc->displayedClassId = jid; - proc->boolIsHidden = 0; - + proc->unit = NULL; + proc->state = MU_STATE_INACTIVE; + proc->x_q4 = (x * 16) << MU_SUBPIXEL_PRECISION; + proc->y_q4 = (y * 16) << MU_SUBPIXEL_PRECISION; + proc->x_offset_q4 = 0; + proc->y_offset_q4 = 0; + proc->facing = MU_FACING_UNK11; + proc->move_clock_q4 = 0; + proc->step_sound_clock = delay; + proc->jid = jid; + proc->hidden_b = 0; proc->pGfxVRAM = OBJ_VRAM0 + (0x20 * objTileId); - - proc->muIndex = muIndex; - - proc->objPriorityBits = 0x800; - + proc->muIndex = slot; + proc->layer = OAM2_LAYER(2); proc->moveConfig = 0; - proc->boolForceMaxSpeed = FALSE; - - config->paletteIndex = palId; + proc->boolForceMaxSpeed = false; + config->pal = palId; - ap = AP_Create(MU_GetAnimationByClassId(jid), 10); + ap = AP_Create(GetMuAnimForJid(jid), 10); AP_SwitchAnimation(ap, MU_FACING_SELECTED); Decompress( - MU_GetSheetGfx(proc), - MU_GetGfxBufferById(config->muIndex) + GetMuImg(proc), + GetMuImgBufById(config->muIndex) ); - ap->pGraphics = MU_GetGfxBufferById(config->muIndex); - ap->tileBase = ((config->paletteIndex & 0xF) << 12) + config->objTileIndex + proc->objPriorityBits; - - proc->pAPHandle = ap; - proc->pMUConfig = config; - - config->pMUProc = proc; + ap->pGraphics = GetMuImgBufById(config->muIndex); + ap->tileBase = OAM2_PAL(config->pal) + config->chr + proc->layer; + proc->sprite_anim = ap; + proc->config = config; + config->mu = proc; return proc; } -void MU_SetFacing(struct MUProc * proc, int facingId) +void SetMuFacing(struct MuProc * proc, int facing) { - proc->facingId = facingId; + proc->facing = facing; - if (facingId == MU_FACING_STANDING) + if (facing == MU_FACING_STANDING) sub_8027068(proc->muIndex, proc->pGfxVRAM); else - AP_SwitchAnimation(proc->pAPHandle, proc->facingId); + AP_SwitchAnimation(proc->sprite_anim, proc->facing); } -void MU_SetDefaultFacing(struct MUProc * proc) +void SetMuDefaultFacing(struct MuProc * proc) { - if (GetClassData(proc->displayedClassId)->attributes & CA_MOUNTEDAID) - MU_SetFacing(proc, 1); + if (GetClassData(proc->jid)->attributes & CA_MOUNTEDAID) + SetMuFacing(proc, 1); else - MU_SetFacing(proc, 2); + SetMuFacing(proc, 2); } -void MU_SetDefaultFacing_Auto(void) +void SetAutoMuDefaultFacing(void) { - struct MUProc * proc = Proc_Find(gProcScr_MoveUnit); - + struct MuProc * proc = Proc_Find(ProcScr_Mu); if (proc) - MU_SetDefaultFacing(proc); + SetMuDefaultFacing(proc); } -void MU_StartMoveScript_Auto(const u8 commands[MU_COMMAND_MAX_COUNT]) +void SetAutoMuMoveScript(const u8 commands[MU_COMMAND_MAX_COUNT]) { - struct MUProc * proc = Proc_Find(gProcScr_MoveUnit); - + struct MuProc * proc = Proc_Find(ProcScr_Mu); if (proc) - MU_StartMoveScript(proc, commands); + SetMuMoveScript(proc, commands); } -s8 MU_Exists(void) +bool MuExists(void) { - return Proc_Find(gProcScr_MoveUnit) ? TRUE : FALSE; + return Proc_Find(ProcScr_Mu) ? true : false; } -s8 MU_IsAnyActive(void) +bool MuExistsActive(void) { int i; for (i = 0; i < MU_MAX_COUNT; ++i) { #ifndef NONMATCHING - asm(""::"r"(&sMUConfigArray[i].muIndex)); - asm(""::"r"(&sMUConfigArray[i].pMUProc)); + asm(""::"r"(&sMuConfig[i].muIndex)); + asm(""::"r"(&sMuConfig[i].mu)); #endif - if (sMUConfigArray[i].muIndex == 0) continue; + if (sMuConfig[i].muIndex == 0) continue; while (0) ; - if (sMUConfigArray[i].pMUProc->stateId != MU_STATE_INACTIVE) - return TRUE; + if (sMuConfig[i].mu->state != MU_STATE_INACTIVE) + return true; } if (i >= MU_MAX_COUNT) - return FALSE; + return false; - return TRUE; + return true; } -s8 MU_IsActive(struct MUProc * proc) +bool IsMuActive(struct MuProc * mu) { - if (proc->pMUConfig->muIndex && proc->stateId != MU_STATE_INACTIVE) - return TRUE; + if (mu->config->muIndex && mu->state != MU_STATE_INACTIVE) + return true; - return FALSE; + return false; } -void MU_StartMoveScript(struct MUProc * proc, const u8 commands[MU_COMMAND_MAX_COUNT]) +void SetMuMoveScript(struct MuProc * mu, const u8 commands[MU_COMMAND_MAX_COUNT]) { int i; for (i = 0; i < 0x40; ++i) - proc->pMUConfig->commands[i] = commands[i]; + mu->config->commands[i] = commands[i]; - proc->pMUConfig->currentCommand = 0; - proc->stateId = MU_STATE_MOVEMENT; + mu->config->currentCommand = 0; + mu->state = MU_STATE_MOVEMENT; - MU_PlayStepSfx(proc); + PlayMuStepSe(mu); } -struct MUProc * MU_CreateScripted(u16 x, u16 y, u16 jid, unsigned palId, const u8 commands[MU_COMMAND_MAX_COUNT]) +struct MuProc * StartMuScripted(u16 x, u16 y, u16 jid, int pal, const u8 commands[MU_COMMAND_MAX_COUNT]) { - struct MUProc * proc = MU_CreateInternal(x, y, jid, -1, palId); - + struct MuProc * proc = StartMuInternal(x, y, jid, -1, pal); if (!proc) return NULL; - MU_StartMoveScript(proc, commands); + SetMuMoveScript(proc, commands); return proc; } -void MuStepSe_Init(struct MUStepSoundProc * proc) +void MuStepSe_Init(struct MuStepSoundProc * proc) { - proc->idSound1 = 0; - proc->xSound1 = 0; + proc->song1 = 0; + proc->x1 = 0; - proc->idSound2 = 0; - proc->xSound2 = 0; + proc->song2 = 0; + proc->x2 = 0; } -void MuStepSe_PlaySeA(struct MUStepSoundProc * proc) +void MuStepSe_PlaySeA(struct MuStepSoundProc * proc) { - PlaySeSpacial(proc->idSound1, proc->xSound1); + PlaySeSpacial(proc->song1, proc->x1); } -void MuStepSe_PlaySeB(struct MUStepSoundProc * proc) +void MuStepSe_PlaySeB(struct MuStepSoundProc * proc) { - if (proc->idSound2) - PlaySeSpacial(proc->idSound2, proc->xSound2); + if (proc->song2) + PlaySeSpacial(proc->song2, proc->x2); } void MU_StartStepSfx(int soundId, int b, int hPosition) { - struct MUStepSoundProc * proc; + struct MuStepSoundProc * proc; proc = Proc_Find(ProcScr_MuStepSe); if (!proc) proc = Proc_Start(ProcScr_MuStepSe, PROC_TREE_3); - if (!proc->idSound1) + if (!proc->song1) { - proc->idSound1 = soundId; - proc->xSound1 = hPosition; + proc->song1 = soundId; + proc->x1 = hPosition; } else if (!proc->u60_buggedmaybe) // TODO: FIXME: Is this a bug? u60_buggedmaybe is never initialized { - proc->idSound2 = soundId + b; - proc->xSound2 = hPosition; + proc->song2 = soundId + b; + proc->x2 = hPosition; } } -void MU_PlayStepSfx(struct MUProc * proc) +void PlayMuStepSe(struct MuProc * proc) { MU_AdvanceStepSfx(proc); } -void MU_8078894(struct MUProc * proc) {} +void MU_8078894(struct MuProc * proc) {} -void MU_InterpretCommandScript(struct MUProc * proc) +void MU_InterpretCommandScript(struct MuProc * proc) { - while (TRUE) + while (true) { short command = MU_AdvanceGetCommand(proc); switch (command) { case MU_COMMAND_WAIT: - proc->moveTimer = MU_AdvanceGetCommand(proc); - proc->stateId = MU_STATE_SLEEPING; + proc->move_clock_q4 = MU_AdvanceGetCommand(proc); + proc->state = MU_STATE_SLEEPING; return; case MU_COMMAND_BUMP: MU_8078894(proc); - proc->stateId = MU_STATE_BUMPING; + proc->state = MU_STATE_BUMPING; MU_StartFogBumpFx( - (proc->xSubPosition >> MU_SUBPIXEL_PRECISION) - gBmSt.camera.x, - (proc->ySubPosition >> MU_SUBPIXEL_PRECISION) - gBmSt.camera.y + (proc->x_q4 >> MU_SUBPIXEL_PRECISION) - gBmSt.camera.x, + (proc->y_q4 >> MU_SUBPIXEL_PRECISION) - gBmSt.camera.y ); return; @@ -614,11 +565,11 @@ void MU_InterpretCommandScript(struct MUProc * proc) case MU_COMMAND_MOVE_UP: command = command - MU_COMMAND_MOVE_BASE; - if (command != proc->facingId) { - MU_GetAnimationByClassId(proc->displayedClassId); // TODO: FIXME: is this a bug? - MU_SetFacing(proc, command); + if (command != proc->facing) { + GetMuAnimForJid(proc->jid); // TODO: FIXME: is this a bug? + SetMuFacing(proc, command); - proc->stateId = MU_STATE_MOVEMENT; + proc->state = MU_STATE_MOVEMENT; } return; @@ -629,9 +580,9 @@ void MU_InterpretCommandScript(struct MUProc * proc) case MU_COMMAND_FACE_UP: command = command - MU_COMMAND_FACE_BASE; - if (command != proc->facingId) { - MU_GetAnimationByClassId(proc->displayedClassId); // TODO: FIXME: is this a bug? - MU_SetFacing(proc, command); + if (command != proc->facing) { + GetMuAnimForJid(proc->jid); // TODO: FIXME: is this a bug? + SetMuFacing(proc, command); } break; @@ -641,21 +592,21 @@ void MU_InterpretCommandScript(struct MUProc * proc) break; case MU_COMMAND_CAMERA_ON: - MU_EnableAttractCamera(proc); + EnableMuCamera(proc); break; case MU_COMMAND_CAMERA_OFF: - MU_DisableAttractCamera(proc); + DisableMuCamera(proc); break; } // switch (command) - } // while (TRUE) + } // while (true) } void MU_StartFogBumpFx(int x, int y) { - struct APHandle* ap; - struct MUFogBumpFxProc * proc; + struct APHandle * ap; + struct MuFogBumpProc * proc; Decompress( Img_GmapSoguSprites, @@ -669,13 +620,13 @@ void MU_StartFogBumpFx(int x, int y) proc = Proc_Start(ProcScr_MuFogBump, PROC_TREE_3); - proc->pAPHandle = ap; + proc->sprite_anim = ap; proc->xDisplay = x + 8; proc->yDisplay = y - 4; } -void MuFogBump_Init(struct MUFogBumpFxProc * proc) +void MuFogBump_Init(struct MuFogBumpProc * proc) { PlaySoundEffect(0x77); @@ -693,7 +644,7 @@ void MuFogBump_Init(struct MUFogBumpFxProc * proc) ); } -void MuFogBump_ScaleLoop(struct MUFogBumpFxProc * proc) +void MuFogBump_ScaleLoop(struct MuFogBumpProc * proc) { int scale; @@ -712,20 +663,20 @@ void MuFogBump_ScaleLoop(struct MUFogBumpFxProc * proc) ); AP_Update( - proc->pAPHandle, + proc->sprite_anim, (proc->xDisplay - 8), (proc->yDisplay - 8) | 0x300 ); } -void MuFogBump_EndLoop(struct MUFogBumpFxProc * proc) +void MuFogBump_EndLoop(struct MuFogBumpProc * proc) { if (proc->timer++ >= 40) Proc_Break(proc); AP_Update( - proc->pAPHandle, + proc->sprite_anim, (proc->xDisplay), (proc->yDisplay) | 0x100 @@ -734,74 +685,74 @@ void MuFogBump_EndLoop(struct MUFogBumpFxProc * proc) u8 MU_IsFogBumpFxActive(void) { - return Proc_Find(ProcScr_MuFogBump) ? TRUE : FALSE; + return Proc_Find(ProcScr_MuFogBump) ? true : false; } -void Mu_OnStateBump(struct MUProc * proc) +void Mu_OnStateBump(struct MuProc * proc) { if (!MU_IsFogBumpFxActive()) - proc->stateId = MU_STATE_SLEEPING; + proc->state = MU_STATE_SLEEPING; } -void Mu_OnStateMoving(struct MUProc * proc) +void Mu_OnStateMoving(struct MuProc * proc) { - proc->stateId = MU_STATE_MOVEMENT; + proc->state = MU_STATE_MOVEMENT; } -void Mu_OnStateSleeping(struct MUProc * proc) +void Mu_OnStateSleeping(struct MuProc * proc) { - if (proc->moveTimer == 0) - proc->stateId = MU_STATE_MOVEMENT; + if (proc->move_clock_q4 == 0) + proc->state = MU_STATE_MOVEMENT; else - proc->moveTimer--; + proc->move_clock_q4--; } -void Mu_OnStateNone(struct MUProc * proc) {} +void Mu_OnStateNone(struct MuProc * proc) {} -void Mu_OnStateDoNothing(struct MUProc * proc) {} +void Mu_OnStateDoNothing(struct MuProc * proc) {} -void Mu_OnStateMovement(struct MUProc * proc) +void Mu_OnStateMovement(struct MuProc * proc) { unsigned moveSpeed = MU_GetMovementSpeed(proc); - proc->moveTimer = moveSpeed + proc->moveTimer; + proc->move_clock_q4 = moveSpeed + proc->move_clock_q4; - proc->xSubPosition += moveSpeed * sMoveOffsetLut[proc->facingId * 2 + 0]; - proc->ySubPosition += moveSpeed * sMoveOffsetLut[proc->facingId * 2 + 1]; + proc->x_q4 += moveSpeed * sMoveOffsetLut[proc->facing * 2 + 0]; + proc->y_q4 += moveSpeed * sMoveOffsetLut[proc->facing * 2 + 1]; - if ((proc->moveTimer / 16) >= 16) + if ((proc->move_clock_q4 / 16) >= 16) { - proc->moveTimer -= 0x100; + proc->move_clock_q4 -= 0x100; - proc->xSubPosition -= proc->moveTimer * sMoveOffsetLut[proc->facingId * 2 + 0]; - proc->ySubPosition -= proc->moveTimer * sMoveOffsetLut[proc->facingId * 2 + 1]; + proc->x_q4 -= proc->move_clock_q4 * sMoveOffsetLut[proc->facing * 2 + 0]; + proc->y_q4 -= proc->move_clock_q4 * sMoveOffsetLut[proc->facing * 2 + 1]; - proc->moveTimer = 0; + proc->move_clock_q4 = 0; - proc->xSubPosition &= ~0xF; - proc->ySubPosition &= ~0xF; + proc->x_q4 &= ~0xF; + proc->y_q4 &= ~0xF; } - if (proc->boolAttractCamera && !Proc_Find(gProcScr_CamMove)) + if (proc->cam_b && !Proc_Find(gProcScr_CamMove)) { - gBmSt.camera.x = GetCameraAdjustedX(proc->xSubPosition >> MU_SUBPIXEL_PRECISION); - gBmSt.camera.y = GetCameraAdjustedY(proc->ySubPosition >> MU_SUBPIXEL_PRECISION); + gBmSt.camera.x = GetCameraAdjustedX(proc->x_q4 >> MU_SUBPIXEL_PRECISION); + gBmSt.camera.y = GetCameraAdjustedY(proc->y_q4 >> MU_SUBPIXEL_PRECISION); } if (!(proc->moveConfig & 0x80)) MU_AdvanceStepSfx(proc); } -void MU_AdvanceStepSfx(struct MUProc * proc) +void MU_AdvanceStepSfx(struct MuProc * proc) { const u16 * pStepSoundDefinition; unsigned cursor; struct Vec2 position; - if (GetClassData(proc->displayedClassId)->attributes & CA_MOUNTEDAID) + if (GetClassData(proc->jid)->attributes & CA_MOUNTEDAID) { - switch (proc->displayedClassId) { + switch (proc->jid) { case CLASS_WYVERN_RIDER: case CLASS_WYVERN_RIDER_F: case CLASS_WYVERN_LORD: @@ -825,11 +776,11 @@ void MU_AdvanceStepSfx(struct MUProc * proc) pStepSoundDefinition = MuSoundScr_Mounted; break; - } // proc->displayedClassId + } // proc->jid } else { - switch (proc->displayedClassId) { + switch (proc->jid) { case CLASS_REVENANT: case CLASS_ENTOUMBED: pStepSoundDefinition = MuSoundScr_Zombie; @@ -901,10 +852,10 @@ void MU_AdvanceStepSfx(struct MUProc * proc) pStepSoundDefinition = MuSoundScr_Foot; break; - } // switch (proc->displayedClassId) + } // switch (proc->jid) } - cursor = DivRem(proc->stepSoundTimer++, pStepSoundDefinition[0]); + cursor = DivRem(proc->step_sound_clock++, pStepSoundDefinition[0]); MU_ComputeDisplayPosition(proc, &position); if (pStepSoundDefinition[2 + cursor]) @@ -917,48 +868,48 @@ void MU_AdvanceStepSfx(struct MUProc * proc) } } -void MU_OnLoop(struct MUProc * proc) +void MU_OnLoop(struct MuProc * proc) { - if (proc->stateId) + if (proc->state) { - if (proc->moveTimer == 0) - if ((u8)(proc->stateId - MU_STATE_MOVEMENT) <= (MU_STATE_SLEEPING - MU_STATE_MOVEMENT)) + if (proc->move_clock_q4 == 0) + if ((u8)(proc->state - MU_STATE_MOVEMENT) <= (MU_STATE_SLEEPING - MU_STATE_MOVEMENT)) MU_InterpretCommandScript(proc); - sMuStateFuncs[proc->stateId](proc); + sMuStateFuncs[proc->state](proc); } - if (proc->facingId == MU_FACING_STANDING) + if (proc->facing == MU_FACING_STANDING) MU_DisplayAsSMS(proc); else MU_DisplayAsMMS(proc); } -void MU_OnEnd(struct MUProc * proc) +void MU_OnEnd(struct MuProc * proc) { - proc->pMUConfig->muIndex = 0; - AP_Delete(proc->pAPHandle); + proc->config->muIndex = 0; + AP_Delete(proc->sprite_anim); } void MU_EndAll(void) { - Proc_EndEach(gProcScr_MoveUnit); + Proc_EndEach(ProcScr_Mu); } -void MU_End(struct MUProc * proc) +void MU_End(struct MuProc * proc) { MU_EndInternal(proc); } -void MU_EndInternal(struct MUProc * proc) +void MU_EndInternal(struct MuProc * proc) { Proc_End(proc); } -void MU_80790CC(struct MUProc * proc) +void MU_80790CC(struct MuProc * proc) { MU_8078894(proc); - proc->stateId = MU_STATE_INACTIVE; + proc->state = MU_STATE_INACTIVE; } void MU_AllDisable(void) @@ -973,7 +924,7 @@ void MU_AllEnable(void) void MU_GetComputedEndPosition(int * xOut, int * yOut, const u8 * commands) { - while (TRUE) + while (true) { switch (*commands++) { case MU_COMMAND_END: @@ -1011,10 +962,10 @@ s8 MU_CanStart(void) int i; for (i = 0; i < MU_MAX_COUNT; ++i) - if (sMUConfigArray[i].muIndex == 0) - return TRUE; + if (sMuConfig[i].muIndex == 0) + return true; - return FALSE; + return false; } void MU_AllRestartAnimations(void) @@ -1023,85 +974,85 @@ void MU_AllRestartAnimations(void) for (i = 0; i < MU_MAX_COUNT; ++i) { - if (sMUConfigArray[i].muIndex) + if (sMuConfig[i].muIndex) { - sMUConfigArray[i].pMUProc->pAPHandle->frameTimer = 0; - sMUConfigArray[i].pMUProc->pAPHandle->frameInterval = 0x100; + sMuConfig[i].mu->sprite_anim->frameTimer = 0; + sMuConfig[i].mu->sprite_anim->frameInterval = 0x100; } } } -struct MUConfig * MU_GenerateConfigDefault(int objTileId, u8* outIndex) +struct MuConfig * GetDefaultMuConfig(int objTileId, u8 * outIndex) { int i; for (i = 0; i < MU_MAX_COUNT; ++i) -{ - if (sMUConfigArray[i].muIndex) + { + if (sMuConfig[i].muIndex) continue; - sMUConfigArray[i].muIndex = i + 1; - sMUConfigArray[i].objTileIndex = sMUObjTileOffsetLookup_Default[i] + objTileId; + sMuConfig[i].muIndex = i + 1; + sMuConfig[i].chr = sMuChrOffLut_Default[i] + objTileId; *outIndex = i; - return sMUConfigArray + i; + return sMuConfig + i; } return NULL; } -struct MUConfig * MU_GenerateConfigOther(int objTileId, u8* outIndex) +struct MuConfig * GetNewMuConfig(int objTileId, u8 * outIndex) { int i; for (i = 0; i < MU_MAX_COUNT; ++i) { - if (sMUConfigArray[i].muIndex) + if (sMuConfig[i].muIndex) continue; - sMUConfigArray[i].muIndex = i + 1; - sMUConfigArray[i].objTileIndex = sMUObjTileOffsetLookup_Other[i] + objTileId; + sMuConfig[i].muIndex = i + 1; + sMuConfig[i].chr = sMuChrOffLut[i] + objTileId; *outIndex = i; - return sMUConfigArray + i; + return sMuConfig + i; } return NULL; } -u8 MU_ComputeDisplayPosition(struct MUProc * proc, struct Vec2 * out) +u8 MU_ComputeDisplayPosition(struct MuProc * proc, struct Vec2 * out) { - if (proc->stateId == MU_STATE_DISPLAY_UI) + if (proc->state == MU_STATE_DISPLAY_UI) { - out->x = (proc->xSubPosition + proc->xSubOffset) >> MU_SUBPIXEL_PRECISION; - out->y = (proc->ySubPosition + proc->ySubOffset) >> MU_SUBPIXEL_PRECISION; + out->x = (proc->x_q4 + proc->x_offset_q4) >> MU_SUBPIXEL_PRECISION; + out->y = (proc->y_q4 + proc->y_offset_q4) >> MU_SUBPIXEL_PRECISION; } else { - short x = ((proc->xSubPosition + proc->xSubOffset) >> MU_SUBPIXEL_PRECISION) - gBmSt.camera.x + 8; - short y = ((proc->ySubPosition + proc->ySubOffset) >> MU_SUBPIXEL_PRECISION) - gBmSt.camera.y + 8; + short x = ((proc->x_q4 + proc->x_offset_q4) >> MU_SUBPIXEL_PRECISION) - gBmSt.camera.x + 8; + short y = ((proc->y_q4 + proc->y_offset_q4) >> MU_SUBPIXEL_PRECISION) - gBmSt.camera.y + 8; out->x = x; out->y = y + 8; if ((u16)(x + 16) > 0x110) - return FALSE; + return false; if (y < -0x10) - return FALSE; + return false; if (y > 0xB0) - return FALSE; + return false; } - return TRUE; + return true; } -void MU_DisplayAsSMS(struct MUProc * proc) +void MU_DisplayAsSMS(struct MuProc * proc) { - if (!proc->boolIsHidden) + if (!proc->hidden_b) { struct Vec2 position; @@ -1111,7 +1062,7 @@ void MU_DisplayAsSMS(struct MUProc * proc) position.x &= 0x01FF; position.y &= 0x00FF; - if (proc->stateId == MU_STATE_DEATHFADE) + if (proc->state == MU_STATE_DEATHFADE) position.y |= 0x400; sub_8026FF4( @@ -1120,24 +1071,24 @@ void MU_DisplayAsSMS(struct MUProc * proc) ); sub_8027DB4( - proc->pAPHandle->objLayer, + proc->sprite_anim->objLayer, position.x - 8, position.y - 16, ((((unsigned)(proc->pGfxVRAM - OBJ_VRAM0) & 0x1FFFF) >> 5) - | ((proc->pMUConfig->paletteIndex & 0xF) << 12)) - + proc->objPriorityBits, + | ((proc->config->pal & 0xF) << 12)) + + proc->layer, - proc->displayedClassId, + proc->jid, proc->muIndex ); } } -void MU_DisplayAsMMS(struct MUProc * proc) +void MU_DisplayAsMMS(struct MuProc * proc) { - if (!proc->boolIsHidden) + if (!proc->hidden_b) { struct Vec2 position; @@ -1147,17 +1098,17 @@ void MU_DisplayAsMMS(struct MUProc * proc) position.x &= 0x01FF; position.y &= 0x00FF; - if (proc->stateId != MU_STATE_DISPLAY_UI) - if (proc->pUnit && UNIT_FACTION(proc->pUnit) == FACTION_RED) + if (proc->state != MU_STATE_DISPLAY_UI) + if (proc->unit && UNIT_FACTION(proc->unit) == FACTION_RED) if (gPlaySt.chapterVisionRange != 0) if (!gBmMapFog[MU_GetDisplayYOrg(proc) >> 4][MU_GetDisplayXOrg(proc) >> 4]) return; // whew - if (proc->stateId == MU_STATE_DEATHFADE) + if (proc->state == MU_STATE_DEATHFADE) position.y |= 0x400; AP_Update( - proc->pAPHandle, + proc->sprite_anim, position.x, position.y @@ -1165,7 +1116,7 @@ void MU_DisplayAsMMS(struct MUProc * proc) } } -u16 MU_GetMovementSpeed(struct MUProc * proc) +u16 MU_GetMovementSpeed(struct MuProc * proc) { int config = proc->moveConfig; @@ -1199,10 +1150,10 @@ u16 MU_GetMovementSpeed(struct MUProc * proc) return 0x40; } - return 16 * sMUBaseMoveSpeedLookup[GetClassData(proc->displayedClassId)->slowWalking]; + return 16 * sMuWalkSpeedLut[GetClassData(proc->jid)->slowWalking]; } -void MU_SetMoveConfig(struct MUProc * proc, u16 config) +void MU_SetMoveConfig(struct MuProc * proc, u16 config) { if (config > 0x100) proc->moveConfig = 0x100; @@ -1210,51 +1161,51 @@ void MU_SetMoveConfig(struct MUProc * proc, u16 config) proc->moveConfig = config; } -void* MU_GetGfxBufferById(int muIndex) +void* GetMuImgBufById(int muIndex) { - return gMUGfxBuffer + (sMUBufferIdLookup[muIndex] * MU_GFX_MAX_SIZE); + return gMUGfxBuffer + (sMuImgBufOffLut[muIndex] * MU_GFX_MAX_SIZE); } -const void * MU_GetSheetGfx(struct MUProc * proc) +const void * GetMuImg(struct MuProc * proc) { - return gMuInfoTable[proc->displayedClassId - 1].img; + return gMuInfoTable[proc->jid - 1].img; } -const void * MU_GetAnimationByClassId(u16 classId) +const void * GetMuAnimForJid(u16 classId) { return gMuInfoTable[classId - 1].anim; } -void MU_StartDeathFade(struct MUProc * muProc) +void MU_StartDeathFade(struct MuProc * muProc) { - struct MUEffectProc * proc; + struct MuEffectProc * proc; - muProc->stateId = MU_STATE_DEATHFADE; + muProc->state = MU_STATE_DEATHFADE; - proc = Proc_Start(gProcScr_MUDeathFade, muProc); + proc = Proc_Start(ProcScr_MuDeathFade, muProc); - proc->pMUProc = muProc; + proc->mu = muProc; proc->timeLeft = 0x20; SetBlendConfig(0, 0x10, 0x10, 0); - muProc->pAPHandle->frameTimer = 0; - muProc->pAPHandle->frameInterval = 0; + muProc->sprite_anim->frameTimer = 0; + muProc->sprite_anim->frameInterval = 0; MU_StartHitFlash(muProc, 0); - muProc->pAPHandle->objLayer = 0xD; + muProc->sprite_anim->objLayer = 0xD; PlaySoundEffect(0xD6); // TODO: SOUND DEFINITIONS - if (muProc->pUnit->state & US_IN_BALLISTA) + if (muProc->unit->state & US_IN_BALLISTA) { - TryRemoveUnitFromBallista(muProc->pUnit); - HideUnitSprite(muProc->pUnit); + TryRemoveUnitFromBallista(muProc->unit); + HideUnitSprite(muProc->unit); } } -void MU_DeathFade_OnLoop(struct MUEffectProc * proc) +void MuDeathFade_OnLoop(struct MuEffectProc * proc) { short time = (proc->timeLeft--) >> 1; @@ -1262,41 +1213,41 @@ void MU_DeathFade_OnLoop(struct MUEffectProc * proc) if (proc->timeLeft == 0) { - MU_End(proc->pMUProc); + MU_End(proc->mu); Proc_Break(proc); } } -void MU_BlinkEffect_OnLoop(struct MUEffectProc * proc) +void MUBlinkEffect_OnLoop(struct MuEffectProc * proc) { - struct MUProc * muProc = (struct MUProc *) proc->proc_parent; - int boolHidden = FALSE; + struct MuProc * muProc = (struct MuProc *) proc->proc_parent; + int boolHidden = false; if ((proc->timeLeft & 0x7) < 4) - boolHidden = TRUE; + boolHidden = true; - muProc->boolIsHidden = boolHidden; + muProc->hidden_b = boolHidden; if (--proc->timeLeft < 0) { Proc_Break(proc); - muProc->boolIsHidden = TRUE; + muProc->hidden_b = true; } } -void MU_StartBlinkEffect(struct MUProc * muProc) +void MU_StartBlinkEffect(struct MuProc * muProc) { - struct MUEffectProc * proc; + struct MuEffectProc * proc; - muProc->stateId = MU_STATE_DEATHFADE; + muProc->state = MU_STATE_DEATHFADE; - proc = Proc_Start(gProcScr_MUBlinkEffect, muProc); + proc = Proc_Start(ProcScr_MuBlinkEffect, muProc); - proc->pMUProc = muProc; + proc->mu = muProc; proc->timeLeft = 0x40; - muProc->pAPHandle->frameTimer = 0; - muProc->pAPHandle->frameInterval = 0; + muProc->sprite_anim->frameTimer = 0; + muProc->sprite_anim->frameInterval = 0; PlaySoundEffect(0xD6); // TODO: SOUND DEFINITIONS } @@ -1326,10 +1277,10 @@ void MU_SetupPixelEffect(u32* data, int frame) } } -void MU_PixelEffect_OnLoop(struct MUEffectProc * proc) +void MuPixelEffect_OnLoop(struct MuEffectProc * proc) { MU_SetupPixelEffect( - MU_GetGfxBufferById(((struct MUProc *)(proc->proc_parent))->muIndex), + GetMuImgBufById(((struct MuProc *)(proc->proc_parent))->muIndex), proc->frameIndex ); @@ -1344,58 +1295,58 @@ void MU_PixelEffect_OnLoop(struct MUEffectProc * proc) if (--proc->timeLeft == 0) { - MU_End(proc->pMUProc); + MU_End(proc->mu); Proc_Break(proc); } } -void MU_StartPixelEffect(struct MUProc * muProc) +void MU_StartPixelEffect(struct MuProc * muProc) { - struct MUEffectProc * proc; + struct MuEffectProc * proc; - muProc->stateId = MU_STATE_DEATHFADE; + muProc->state = MU_STATE_DEATHFADE; - proc = Proc_Start(ProcScr_MUPixelEffect, muProc); + proc = Proc_Start(ProcScr_MuPixelEffect, muProc); - proc->pMUProc = muProc; + proc->mu = muProc; proc->timeLeft = 0x40; proc->frameIndex = 0; - muProc->pAPHandle->frameTimer = 0; - muProc->pAPHandle->frameInterval = 0; + muProc->sprite_anim->frameTimer = 0; + muProc->sprite_anim->frameInterval = 0; PlaySoundEffect(0xD6); // TODO: SOUND DEFINITIONS } -void MU_Hide(struct MUProc * proc) +void MU_Hide(struct MuProc * proc) { - proc->boolIsHidden = TRUE; + proc->hidden_b = true; } -void MU_Show(struct MUProc * proc) +void MU_Show(struct MuProc * proc) { - proc->boolIsHidden = FALSE; + proc->hidden_b = false; } -void MU_SetDisplayPosition(struct MUProc * proc, int x, int y) +void MU_SetDisplayPosition(struct MuProc * proc, int x, int y) { - proc->xSubPosition = x << MU_SUBPIXEL_PRECISION; - proc->ySubPosition = y << MU_SUBPIXEL_PRECISION; + proc->x_q4 = x << MU_SUBPIXEL_PRECISION; + proc->y_q4 = y << MU_SUBPIXEL_PRECISION; } -void MU_SetDisplayOffset(struct MUProc * proc, int xOff, int yOff) +void MU_SetDisplayOffset(struct MuProc * proc, int xOff, int yOff) { - proc->xSubOffset = xOff << MU_SUBPIXEL_PRECISION; - proc->ySubOffset = yOff << MU_SUBPIXEL_PRECISION; + proc->x_offset_q4 = xOff << MU_SUBPIXEL_PRECISION; + proc->y_offset_q4 = yOff << MU_SUBPIXEL_PRECISION; } -void MU_StartFlashFade(struct MUProc * proc, int flashType) +void MU_StartFlashFade(struct MuProc * proc, int flashType) { - proc->pAPHandle->tileBase = - proc->pMUConfig->objTileIndex + (MU_FADE_OBJ_PAL << 12) + proc->objPriorityBits; + proc->sprite_anim->tileBase = + proc->config->chr + (MU_FADE_OBJ_PAL << 12) + proc->layer; - ApplyPalette(PAL_OBJ(proc->pMUConfig->paletteIndex), 0x10 + MU_FADE_OBJ_PAL); + ApplyPalette(PAL_OBJ(proc->config->pal), 0x10 + MU_FADE_OBJ_PAL); StartPalFade( MUFlashColorLookup[flashType], @@ -1403,57 +1354,57 @@ void MU_StartFlashFade(struct MUProc * proc, int flashType) ); } -void MU_8079858(struct MUProc * muProc) +void MU_8079858(struct MuProc * muProc) { - struct MUEffectProc * proc; + struct MuEffectProc * proc; StartPalFade( - PAL_OBJ(muProc->pMUConfig->paletteIndex), + PAL_OBJ(muProc->config->pal), 0x15, 8, (struct Proc*) muProc ); - proc = Proc_Start(gProcScr_MU_89A2CF8, PROC_TREE_3); + proc = Proc_Start(ProcScr_MuRestorePalInfo, PROC_TREE_3); - proc->pMUProc = muProc; + proc->mu = muProc; } -void MU_807988C(struct MUEffectProc * proc) +void MuRestorePalInfo_Apply(struct MuEffectProc * proc) { - struct MUProc * muProc = proc->pMUProc; + struct MuProc * muProc = proc->mu; - muProc->pAPHandle->tileBase = - ((muProc->pMUConfig->paletteIndex & 0xF) << 12) + muProc->pMUConfig->objTileIndex + muProc->objPriorityBits; + muProc->sprite_anim->tileBase = + ((muProc->config->pal & 0xF) << 12) + muProc->config->chr + muProc->layer; } -void MU_StartActionAnim(struct MUProc * proc) +void MU_StartActionAnim(struct MuProc * proc) { - AP_SwitchAnimation(proc->pAPHandle, MU_FACING_SELECTED); + AP_SwitchAnimation(proc->sprite_anim, MU_FACING_SELECTED); - proc->pAPHandle->frameTimer = 0; - proc->pAPHandle->frameInterval = 0x100; + proc->sprite_anim->frameTimer = 0; + proc->sprite_anim->frameInterval = 0x100; - CallDelayedArg(MU_EndSelectionApAnim, (int) proc->pAPHandle, 30); + CallDelayedArg(MU_EndSelectionApAnim, (int) proc->sprite_anim, 30); } void MU_EndSelectionApAnim(int argAp) { - struct APHandle* ap = (struct APHandle*) argAp; + struct APHandle * ap = (struct APHandle *) argAp; ap->frameTimer = 0; ap->frameInterval = 0; } -void MU_StartDelayedFaceTarget(struct MUProc * proc) +void MU_StartDelayedFaceTarget(struct MuProc * proc) { - proc->pAPHandle->frameTimer = 0; - proc->pAPHandle->frameInterval = 0x100; + proc->sprite_anim->frameTimer = 0; + proc->sprite_anim->frameInterval = 0x100; - CallDelayedArg(MU_EndRefaceApAnim, (int) proc->pAPHandle, 30); + CallDelayedArg(MU_EndRefaceApAnim, (int) proc->sprite_anim, 30); } void MU_EndRefaceApAnim(int argAp) { - struct APHandle* ap = (struct APHandle*) argAp; + struct APHandle * ap = (struct APHandle *) argAp; int actor1 = gManimSt.subjectActorId; int actor2 = 1 - actor1; @@ -1467,165 +1418,165 @@ void MU_EndRefaceApAnim(int argAp) ap->frameInterval = 0; } -void MU_StartFastMoveAnim(struct MUProc * proc) +void MU_StartFastMoveAnim(struct MuProc * proc) { - proc->pAPHandle->frameTimer = 0; - proc->pAPHandle->frameInterval = 0x40; + proc->sprite_anim->frameTimer = 0; + proc->sprite_anim->frameInterval = 0x40; - CallDelayedArg(MU_EndFasterApAnim, (int) proc->pAPHandle, 20); + CallDelayedArg(MU_EndFasterApAnim, (int) proc->sprite_anim, 20); } void MU_EndFasterApAnim(int argAp) { - struct APHandle* ap = (struct APHandle*) argAp; + struct APHandle * ap = (struct APHandle *) argAp; ap->frameTimer = 0; ap->frameInterval = 0; } -void MU_StartCritFlash(struct MUProc * muProc, int flashType) +void MU_StartCritFlash(struct MuProc * muProc, int flashType) { - struct MUFlashEffectProc * proc; + struct MuFlashEffectProc * proc; ApplyPalette(MUFlashColorLookup[flashType], 0x10 + MU_FADE_OBJ_PAL); - proc = Proc_Start(ProcScr_MUCritFlash, muProc); + proc = Proc_Start(ProcScr_MuCritFlash, muProc); - proc->pMUProc = muProc; + proc->mu = muProc; } -void MU_CritFlash_Init(struct MUFlashEffectProc * proc) +void MuCritFlash_Init(struct MuFlashEffectProc * proc) { proc->timer = 0; } -void MU_CritFlash_SetFadedPalette(struct MUFlashEffectProc * proc) +void MuCritFlash_SetFadedPalette(struct MuFlashEffectProc * proc) { - struct MUProc * muProc = proc->pMUProc; + struct MuProc * muProc = proc->mu; - muProc->pAPHandle->tileBase = - (MU_FADE_OBJ_PAL << 12) + muProc->pMUConfig->objTileIndex + muProc->objPriorityBits; + muProc->sprite_anim->tileBase = + (MU_FADE_OBJ_PAL << 12) + muProc->config->chr + muProc->layer; } -void MU_CritFlash_SetRegularPalette(struct MUFlashEffectProc * proc) +void MuCritFlash_SetRegularPalette(struct MuFlashEffectProc * proc) { - struct MUProc * muProc = proc->pMUProc; + struct MuProc * muProc = proc->mu; - muProc->pAPHandle->tileBase = - ((muProc->pMUConfig->paletteIndex & 0xF) << 12) + muProc->pMUConfig->objTileIndex + muProc->objPriorityBits; + muProc->sprite_anim->tileBase = + ((muProc->config->pal & 0xF) << 12) + muProc->config->chr + muProc->layer; } -void MU_CritFlash_StartFadeBack_maybe(struct MUFlashEffectProc * proc) +void MuCritFlash_StartFadeBack_maybe(struct MuFlashEffectProc * proc) { StartPalFade( - PAL_OBJ(proc->pMUProc->pMUConfig->paletteIndex), + PAL_OBJ(proc->mu->config->pal), 0x15, 0x14, (struct Proc*) proc ); } -void MU_CritFlash_SpriteShakeLoop(struct MUFlashEffectProc * proc) +void MuCritFlash_SpriteShakeLoop(struct MuFlashEffectProc * proc) { proc->timer++; - MU_SetDisplayOffset(proc->pMUProc, ((proc->timer & 1) ? 2 : -2), 0); + MU_SetDisplayOffset(proc->mu, ((proc->timer & 1) ? 2 : -2), 0); if (proc->timer >= 12) { - MU_SetDisplayOffset(proc->pMUProc, 0, 0); + MU_SetDisplayOffset(proc->mu, 0, 0); Proc_Break(proc); } } -void MU_CritFlash_RestorePalette(struct MUFlashEffectProc * proc) +void MuCritFlash_RestorePalette(struct MuFlashEffectProc * proc) { - struct MUProc * muProc = proc->pMUProc; + struct MuProc * muProc = proc->mu; - muProc->pAPHandle->tileBase = - ((muProc->pMUConfig->paletteIndex & 0xF) << 12) + muProc->pMUConfig->objTileIndex + muProc->objPriorityBits; + muProc->sprite_anim->tileBase = + ((muProc->config->pal & 0xF) << 12) + muProc->config->chr + muProc->layer; } -void MU_StartHitFlash(struct MUProc * muProc, int flashType) +void MU_StartHitFlash(struct MuProc * muProc, int flashType) { - struct MUFlashEffectProc * proc; + struct MuFlashEffectProc * proc; ApplyPalette(MUFlashColorLookup[flashType], 0x10 + MU_FADE_OBJ_PAL); - muProc->pAPHandle->tileBase = - (MU_FADE_OBJ_PAL << 12) + muProc->pMUConfig->objTileIndex + muProc->objPriorityBits; + muProc->sprite_anim->tileBase = + (MU_FADE_OBJ_PAL << 12) + muProc->config->chr + muProc->layer; StartPalFade( - PAL_OBJ(muProc->pMUConfig->paletteIndex), + PAL_OBJ(muProc->config->pal), 0x15, 0x14, (struct Proc*) muProc ); - proc = Proc_Start(ProcScr_MUHitFlash, muProc); + proc = Proc_Start(ProcScr_MuHitFlash, muProc); - proc->pMUProc = muProc; + proc->mu = muProc; } -void MU_HitFlash_RestorePalette(struct MUFlashEffectProc * proc) +void MuHitFlash_RestorePalette(struct MuFlashEffectProc * proc) { - struct MUProc * muProc = proc->pMUProc; + struct MuProc * muProc = proc->mu; - muProc->pAPHandle->tileBase = - ((muProc->pMUConfig->paletteIndex & 0xF) << 12) + muProc->pMUConfig->objTileIndex + muProc->objPriorityBits; + muProc->sprite_anim->tileBase = + ((muProc->config->pal & 0xF) << 12) + muProc->config->chr + muProc->layer; } void MU_AllForceSetMaxMoveSpeed(void) { - Proc_ForEach(gProcScr_MoveUnit, MU_ForceSetMaxMoveSpeed); + Proc_ForEach(ProcScr_Mu, MU_ForceSetMaxMoveSpeed); } void MU_ForceSetMaxMoveSpeed(ProcPtr proc) { - ((struct MUProc *)(proc))->boolForceMaxSpeed = TRUE; + ((struct MuProc *)(proc))->boolForceMaxSpeed = true; } -void MU_SetSpecialSprite(struct MUProc * proc, int displayedClassId, const u16 * palette) +void MU_SetSpecialSprite(struct MuProc * proc, int jid, const u16 * palette) { - proc->pAPHandle->frameTimer = 0; - proc->pAPHandle->frameInterval = 0; + proc->sprite_anim->frameTimer = 0; + proc->sprite_anim->frameInterval = 0; - proc->displayedClassId = displayedClassId; + proc->jid = jid; AP_SetDefinition( - proc->pAPHandle, - MU_GetAnimationByClassId(proc->displayedClassId) + proc->sprite_anim, + GetMuAnimForJid(proc->jid) ); Decompress( - MU_GetSheetGfx(proc), - MU_GetGfxBufferById(proc->pMUConfig->muIndex) + GetMuImg(proc), + GetMuImgBufById(proc->config->muIndex) ); - ApplyPalette(palette, 0x10 + proc->pMUConfig->paletteIndex); + ApplyPalette(palette, 0x10 + proc->config->pal); } -void MU_SetPaletteId(struct MUProc * proc, unsigned paletteId) +void MU_SetPaletteId(struct MuProc * proc, unsigned paletteId) { - proc->pMUConfig->paletteIndex = paletteId; + proc->config->pal = paletteId; - proc->pAPHandle->tileBase = - proc->pMUConfig->objTileIndex + ((paletteId % 0x10) << 12) + proc->objPriorityBits; + proc->sprite_anim->tileBase = + proc->config->chr + ((paletteId % 0x10) << 12) + proc->layer; } -struct MUProc * MU_GetByIndex(int muIndex) +struct MuProc * MU_GetByIndex(int muIndex) { - if (!sMUConfigArray[muIndex].muIndex) + if (!sMuConfig[muIndex].muIndex) return NULL; - return sMUConfigArray[muIndex].pMUProc; + return sMuConfig[muIndex].mu; } -struct MUProc * MU_GetByUnit(struct Unit* unit) +struct MuProc * MU_GetByUnit(struct Unit * unit) { int i; for (i = 0; i < MU_MAX_COUNT; ++i) { - struct MUProc * proc = MU_GetByIndex(i); + struct MuProc * proc = MU_GetByIndex(i); - if (proc->pUnit == unit) + if (proc->unit == unit) return proc; } @@ -1634,19 +1585,19 @@ struct MUProc * MU_GetByUnit(struct Unit* unit) void MU_SortObjLayers(void) { - struct MUProc * procs[MU_MAX_COUNT]; + struct MuProc * procs[MU_MAX_COUNT]; s8 i, j; s8 count; // Clear proc list - CpuFill32(0, procs, MU_MAX_COUNT * sizeof(struct MUProc *)); + CpuFill32(0, procs, MU_MAX_COUNT * sizeof(struct MuProc *)); count = 0; // Building proc list for (i = 0; i < MU_MAX_COUNT; ++i) { - struct MUProc * proc = MU_GetByIndex(i); + struct MuProc * proc = MU_GetByIndex(i); if (proc) { @@ -1660,9 +1611,9 @@ void MU_SortObjLayers(void) { for (j = (i + 1); j < count; ++j) { - if (procs[j]->ySubPosition < procs[i]->ySubPosition) + if (procs[j]->y_q4 < procs[i]->y_q4) { - struct MUProc * tmp = procs[i]; + struct MuProc * tmp = procs[i]; procs[i] = procs[j]; procs[j] = tmp; @@ -1672,5 +1623,5 @@ void MU_SortObjLayers(void) // Set obj layer based on order for (i = 0; i < count; ++i) - procs[i]->pAPHandle->objLayer = 10 - i; + procs[i]->sprite_anim->objLayer = 10 - i; } diff --git a/src/muctrl.c b/src/muctrl.c index 163e3d083..1afceca11 100644 --- a/src/muctrl.c +++ b/src/muctrl.c @@ -124,7 +124,7 @@ void MuCtr_InitDefinedMove(struct MuCtrlProc * proc, struct Unit * unit, const s AdjustNewUnitPosition(unit, &pos, flags); proc->unit = unit; - proc->muProc = MU_Create(unit); + proc->muProc = StartMu(unit); proc->redas = redas; proc->redaCount = count; proc->unk_3a = 0; @@ -291,11 +291,11 @@ s8 sub_807A0E4(struct MuCtrlProc * proc) //! FE8U = 0x0807A194 s8 sub_807A194(struct MuCtrlProc * proc) { - struct MUProc * muProc = proc->muProc; + struct MuProc * muProc = proc->muProc; MU_SortObjLayers(); - if (!MU_IsActive(muProc)) + if (!IsMuActive(muProc)) { struct Unit * unit = proc->unit; unit->xPos = proc->unk_42; @@ -319,7 +319,7 @@ s8 sub_807A194(struct MuCtrlProc * proc) //! FE8U = 0x0807A1FC void MuCtr_OnEnd(struct MuCtrlProc * proc) { - struct MUProc * muProc = proc->muProc; + struct MuProc * muProc = proc->muProc; struct Unit * unit = proc->unit; if ((muProc->boolForceMaxSpeed != 0) && (proc->redaCount != 0)) @@ -452,10 +452,10 @@ void MuCtr_ExecREDA_807A358(struct MuCtrlProc * proc) if ((proc->unk_42 != pos.x) || (proc->unk_43 != pos.y)) { - struct MUProc * muProc = proc->muProc; + struct MuProc * muProc = proc->muProc; MU_Show(muProc); - MU_StartMoveScript(muProc, commands); + SetMuMoveScript(muProc, commands); config = reda->flags; @@ -468,11 +468,11 @@ void MuCtr_ExecREDA_807A358(struct MuCtrlProc * proc) if ((flagsB & 4) != 0) { - MU_EnableAttractCamera(muProc); + EnableMuCamera(muProc); } else { - MU_DisableAttractCamera(muProc); + DisableMuCamera(muProc); } HideUnitSprite(unit); diff --git a/src/playerphase.c b/src/playerphase.c index 8e8574f7c..f41ed3688 100755 --- a/src/playerphase.c +++ b/src/playerphase.c @@ -699,7 +699,7 @@ void PlayerPhase_BackToMove(ProcPtr proc) HideUnitSprite(gActiveUnit); MU_EndAll(); - MU_Create(gActiveUnit); + StartMu(gActiveUnit); Proc_Goto(proc, 1); @@ -834,8 +834,8 @@ bool TryMakeCantoUnit(ProcPtr proc) gActiveUnit->state &= ~US_UNSELECTABLE; MU_EndAll(); - MU_Create(gActiveUnit); - MU_SetDefaultFacing_Auto(); + StartMu(gActiveUnit); + SetAutoMuDefaultFacing(); if (gPlaySt.chapterVisionRange != 0) { @@ -1074,7 +1074,7 @@ void PlayerPhase_DisplayUnitMovement(void) { GetMovementScriptFromPath(); UnitApplyWorkingMovementScript(gActiveUnit, gActiveUnit->xPos, gActiveUnit->yPos); - MU_StartMoveScript_Auto(gWorkingMovementScript); + SetAutoMuMoveScript(gWorkingMovementScript); return; } @@ -1082,7 +1082,7 @@ void PlayerPhase_DisplayUnitMovement(void) //! FE8U = 0x0801D64C void PlayerPhase_WaitForUnitMovement(ProcPtr proc) { - if (!MU_IsAnyActive()) + if (!MuExistsActive()) { Proc_Break(proc); } @@ -1134,19 +1134,19 @@ void PlayerPhase_ReReadGameSaveGfx(void) //! FE8U = 0x0801D70C void MakeMoveunitForActiveUnit(void) { - if (!MU_Exists()) + if (!MuExists()) { if (UNIT_FACTION(gActiveUnit) == gPlaySt.faction) { if ((gActiveUnit->statusIndex != UNIT_STATUS_SLEEP) && (gActiveUnit->statusIndex != UNIT_STATUS_BERSERK)) { - MU_Create(gActiveUnit); + StartMu(gActiveUnit); HideUnitSprite(gActiveUnit); } } } - MU_SetDefaultFacing_Auto(); + SetAutoMuDefaultFacing(); return; } diff --git a/src/prep_itemsupply.c b/src/prep_itemsupply.c index 5b646b902..198eef137 100644 --- a/src/prep_itemsupply.c +++ b/src/prep_itemsupply.c @@ -1195,8 +1195,8 @@ void sub_809EB14(void) { if (gActiveUnit) { HideUnitSprite(gActiveUnit); - MU_Create(gActiveUnit); - MU_SetDefaultFacing_Auto(); + StartMu(gActiveUnit); + SetAutoMuDefaultFacing(); } return; diff --git a/src/sio_battlemap.c b/src/sio_battlemap.c index ce89bf81e..a7a88026e 100644 --- a/src/sio_battlemap.c +++ b/src/sio_battlemap.c @@ -42,7 +42,7 @@ struct SioBattleMapProc /* 34 */ int unk_34; /* 38 */ int unk_38; /* 3C */ STRUCT_PAD(0x3C, 0x54); - /* 54 */ struct MUProc * unk_54; + /* 54 */ struct MuProc * unk_54; /* 58 */ int unk_58; /* 5C */ int unk_5c; }; @@ -58,7 +58,7 @@ extern u8 gUnknown_03001818[]; extern struct Vec2 gUnknown_0300182C; extern int gUnknown_03001830; extern u8 gUnknown_03001834[]; -extern struct MUProc * gUnknown_03001838[]; +extern struct MuProc * gUnknown_03001838[]; extern u16 gUnknown_03001840[]; extern u8 gUnknown_080D9F28[][4]; @@ -228,9 +228,9 @@ void sub_80493D0(u8 a, int b, u8 * c, int * xOut, int * yOut) if ((unit->state & US_BIT9) == 0) { - gUnknown_03001838[b] = MU_Create(unit); - MU_DisableAttractCamera(gUnknown_03001838[b]); - MU_StartMoveScript(gUnknown_03001838[b], gUnknown_080D9FA0 + index); + gUnknown_03001838[b] = StartMu(unit); + DisableMuCamera(gUnknown_03001838[b]); + SetMuMoveScript(gUnknown_03001838[b], gUnknown_080D9FA0 + index); } unit->state |= US_HIDDEN; @@ -561,12 +561,12 @@ void sub_80498F4(void) { struct Unit * unit = GetUnit(gUnknown_03001818[gUnk_Sio_0203DD90.unk_04]); - gUnknown_03001838[0] = MU_Create(unit); + gUnknown_03001838[0] = StartMu(unit); MU_SetDisplayPosition(gUnknown_03001838[0], unit->xPos * 16, (unit->yPos - 1) * 16); - MU_DisableAttractCamera(gUnknown_03001838[0]); - MU_SetFacing(gUnknown_03001838[0], 3); + DisableMuCamera(gUnknown_03001838[0]); + SetMuFacing(gUnknown_03001838[0], 3); return; } @@ -871,7 +871,7 @@ void sub_8049C18(void) return; } - MU_DisableAttractCamera(MU_Create(unitB)); + DisableMuCamera(StartMu(unitB)); HideUnitSprite(unitB); return; @@ -958,9 +958,9 @@ void sub_8049D24(struct SioBattleMapProc * proc) PlaySoundEffect(0x69); MU_EndAll(); - gUnknown_03001838[0] = MU_Create(gActiveUnit); - MU_DisableAttractCamera(gUnknown_03001838[0]); - MU_StartMoveScript(gUnknown_03001838[0], gUnknown_080D9FB5); + gUnknown_03001838[0] = StartMu(gActiveUnit); + DisableMuCamera(gUnknown_03001838[0]); + SetMuMoveScript(gUnknown_03001838[0], gUnknown_080D9FB5); proc->unk_2c = gActiveUnit->xPos; proc->unk_30 = gActiveUnit->yPos - 1; @@ -1342,7 +1342,7 @@ void sub_804A44C(struct SioBattleMapProc * proc) { if ((unit->state & US_BIT9) != 0) { - gUnknown_03001838[1] = (void *)MU_Create(unit); + gUnknown_03001838[1] = (void *)StartMu(unit); proc->unk_34 = unit->xPos; proc->unk_38 = unit->yPos; unit->state &= ~US_BIT9; @@ -1399,7 +1399,7 @@ void sub_804A5A4(void) if (gUnknown_03001834[2] == 1) { - MU_StartMoveScript(gUnknown_03001838[0], gUnknown_080D9FB7); + SetMuMoveScript(gUnknown_03001838[0], gUnknown_080D9FB7); unitA->xPos = 7; } @@ -1416,7 +1416,7 @@ void sub_804A614(ProcPtr proc) struct Unit * unitA; struct Unit * unitB; - if (MU_IsAnyActive() == 1) + if (MuExistsActive() == 1) { return; } @@ -1515,8 +1515,8 @@ void sub_804A7C0(ProcPtr proc) } else { - gUnknown_03001838[0] = (void *)MU_Create(unitA); - MU_DisableAttractCamera(gUnknown_03001838[0]); + gUnknown_03001838[0] = (void *)StartMu(unitA); + DisableMuCamera(gUnknown_03001838[0]); unitA->state |= US_HIDDEN; @@ -1532,8 +1532,8 @@ void sub_804A7C0(ProcPtr proc) } else { - gUnknown_03001838[1] = (void *)MU_Create(unitB); - MU_DisableAttractCamera(gUnknown_03001838[1]); + gUnknown_03001838[1] = (void *)StartMu(unitB); + DisableMuCamera(gUnknown_03001838[1]); unitB->state |= US_HIDDEN; @@ -1837,7 +1837,7 @@ void sub_804ABCC(struct SioProc85AA4CC * proc) //! FE8U = 0x0804AC68 void sub_804AC68(struct Unit * unit, int idx, int * xOut, int * yOut) { - gUnknown_03001838[idx] = MU_Create(unit); + gUnknown_03001838[idx] = StartMu(unit); *xOut = unit->xPos; *yOut = unit->yPos; @@ -2289,7 +2289,7 @@ void sub_804B250(ProcPtr proc) return; } - if (MU_IsAnyActive() != 0) + if (MuExistsActive() != 0) { return; } @@ -2543,7 +2543,7 @@ void sub_804B604(struct SioBattleMapProc * proc) void sub_804B624(struct SioBattleMapProc * proc) { struct Unit * unit; - struct MUProc * pMuProc; + struct MuProc * mu; while (1) { @@ -2573,16 +2573,16 @@ void sub_804B624(struct SioBattleMapProc * proc) RefreshUnitSprites(); HideUnitSprite(unit); - pMuProc = MU_Create(unit); + mu = StartMu(unit); gWorkingMovementScript[0] = MU_COMMAND_MOVE_DOWN; gWorkingMovementScript[1] = MU_COMMAND_HALT; - MU_StartMoveScript(pMuProc, gWorkingMovementScript); + SetMuMoveScript(mu, gWorkingMovementScript); - StartLinkArenaMUDeathFade(pMuProc); + StartLinkArenaMUDeathFade(mu); - proc->unk_54 = pMuProc; + proc->unk_54 = mu; proc->unk_58++; unit->state &= ~US_BIT9; @@ -2749,13 +2749,13 @@ void sub_804B800(void) //! FE8U = 0x0804B850 void sub_804B850(struct SioBattleMapProc * proc) { - struct MUProc * pMuProc; + struct MuProc * mu; if (gBattleActor.unit.curHP == 0) { - pMuProc = Proc_Find(gProcScr_MoveUnit); - StartLinkArenaMUDeathFade(pMuProc); - proc->unk_54 = pMuProc; + mu = Proc_Find(ProcScr_Mu); + StartLinkArenaMUDeathFade(mu); + proc->unk_54 = mu; } if (gBattleTarget.unit.curHP == 0) @@ -2764,16 +2764,16 @@ void sub_804B850(struct SioBattleMapProc * proc) HideUnitSprite(GetUnit(gBattleTarget.unit.index)); - pMuProc = MU_Create(&gBattleTarget.unit); + mu = StartMu(&gBattleTarget.unit); gWorkingMovementScript[0] = GetFacingDirection( gBattleActor.unit.xPos, gBattleActor.unit.yPos, gBattleTarget.unit.xPos, gBattleTarget.unit.yPos); gWorkingMovementScript[1] = MU_COMMAND_HALT; - MU_StartMoveScript(pMuProc, gWorkingMovementScript); - StartLinkArenaMUDeathFade(pMuProc); + SetMuMoveScript(mu, gWorkingMovementScript); + StartLinkArenaMUDeathFade(mu); - proc->unk_54 = pMuProc; + proc->unk_54 = mu; } return; diff --git a/src/sio_mu.c b/src/sio_mu.c index 96b052414..d057321b0 100644 --- a/src/sio_mu.c +++ b/src/sio_mu.c @@ -13,7 +13,7 @@ struct SioProc85AA83C { /* 00 */ PROC_HEADER; /* 29 */ STRUCT_PAD(0x29, 0x2C); - /* 2C */ struct MUProc * muProc; + /* 2C */ struct MuProc * muProc; }; struct SioWarpProc @@ -21,7 +21,7 @@ struct SioWarpProc /* 00 */ PROC_HEADER; /* 29 */ STRUCT_PAD(0x29, 0x2C); /* 2C */ struct Unit * unit; - /* 30 */ struct MUProc * muProc; + /* 30 */ struct MuProc * muProc; /* 34 */ int x; /* 38 */ int y; /* 3C */ int facing; @@ -54,14 +54,14 @@ extern struct ProcCmd ProcScr_085AA83C[]; // clang-format on //! FE8U = 0x0804BED8 -void sub_804BED8(struct MUProc * muProc, int kind) +void sub_804BED8(struct MuProc * muProc, int kind) { struct SioProc85AA83C * proc; ApplyPalette(PalArray_SolidColors[kind], 0x16); - muProc->pAPHandle->tileBase = muProc->pMUConfig->objTileIndex + 0x6800; - StartPalFade(gPaletteBuffer + (muProc->pMUConfig->paletteIndex + 0x10) * 0x10, 0x16, 0x14, muProc); + muProc->sprite_anim->tileBase = muProc->config->chr + 0x6800; + StartPalFade(gPaletteBuffer + (muProc->config->pal + 0x10) * 0x10, 0x16, 0x14, muProc); proc = Proc_Start(ProcScr_085AA83C, muProc); proc->muProc = muProc; @@ -72,8 +72,8 @@ void sub_804BED8(struct MUProc * muProc, int kind) //! FE8U = 0x0804BF30 void sub_804BF30(struct SioProc85AA83C * proc) { - proc->muProc->pAPHandle->tileBase = - OAM2_PAL(proc->muProc->pMUConfig->paletteIndex) + proc->muProc->pMUConfig->objTileIndex + 0x800; + proc->muProc->sprite_anim->tileBase = + OAM2_PAL(proc->muProc->config->pal) + proc->muProc->config->chr + 0x800; return; } @@ -89,24 +89,24 @@ struct ProcCmd CONST_DATA ProcScr_085AA83C[] = // clang-format on //! FE8U = 0x0804BF4C -void StartLinkArenaMUDeathFade(struct MUProc * muProc) +void StartLinkArenaMUDeathFade(struct MuProc * muProc) { - struct MUEffectProc * muEffectProc; + struct MuEffectProc * muEffectProc; - muProc->stateId = MU_STATE_DEATHFADE; + muProc->state = MU_STATE_DEATHFADE; - muEffectProc = Proc_Start(gProcScr_MUDeathFade, muProc); - muEffectProc->pMUProc = muProc; + muEffectProc = Proc_Start(ProcScr_MuDeathFade, muProc); + muEffectProc->mu = muProc; muEffectProc->timeLeft = 32; SetBlendConfig(0, 16, 16, 0); - muProc->pAPHandle->frameTimer = 0; - muProc->pAPHandle->frameInterval = 0; + muProc->sprite_anim->frameTimer = 0; + muProc->sprite_anim->frameInterval = 0; sub_804BED8(muProc, 0); - muProc->pAPHandle->objLayer = 13; + muProc->sprite_anim->objLayer = 13; PlaySoundEffect(0xd6); @@ -114,24 +114,24 @@ void StartLinkArenaMUDeathFade(struct MUProc * muProc) } //! FE8U = 0x0804BFAC -void sub_804BFAC(struct MUProc * muProc, int palIdx) +void sub_804BFAC(struct MuProc * muProc, int palIdx) { - muProc->pAPHandle->tileBase = muProc->pMUConfig->objTileIndex + 0x6800; + muProc->sprite_anim->tileBase = muProc->config->chr + 0x6800; - ApplyPalette(gPaletteBuffer + (muProc->pMUConfig->paletteIndex + 0x10) * 0x10, 0x16); + ApplyPalette(gPaletteBuffer + (muProc->config->pal + 0x10) * 0x10, 0x16); StartPalFade(PalArray_SolidColors[palIdx], 0x16, 8, muProc); return; } //! FE8U = 0x0804BFF8 -void sub_804BFF8(struct MUProc * muProc) +void sub_804BFF8(struct MuProc * muProc) { - struct MUEffectProc * muEffectProc; + struct MuEffectProc * muEffectProc; - StartPalFade(gPaletteBuffer + (muProc->pMUConfig->paletteIndex + 0x10) * 0x10, 0x16, 8, muProc); - muEffectProc = Proc_Start(gProcScr_MU_89A2CF8, PROC_TREE_3); - muEffectProc->pMUProc = muProc; + StartPalFade(gPaletteBuffer + (muProc->config->pal + 0x10) * 0x10, 0x16, 8, muProc); + muEffectProc = Proc_Start(ProcScr_MuRestorePalInfo, PROC_TREE_3); + muEffectProc->mu = muProc; return; } @@ -270,7 +270,7 @@ void SioWarpFx_ShowMoveUnit(struct SioWarpProc * proc) { if (proc->facing != -1) { - MU_SetFacing(proc->muProc, proc->facing); + SetMuFacing(proc->muProc, proc->facing); } MU_Show(proc->muProc); @@ -329,7 +329,7 @@ struct ProcCmd CONST_DATA ProcScr_SIOWARPFX[] = // clang-format on //! FE8U = 0x0804C208 -ProcPtr StartSioWarpFx(struct Unit * unit, struct MUProc * muProc, int x, int y, int facing, u8 playStepSe, ProcPtr parent) +ProcPtr StartSioWarpFx(struct Unit * unit, struct MuProc * muProc, int x, int y, int facing, u8 playStepSe, ProcPtr parent) { struct SioWarpProc * proc; @@ -373,7 +373,7 @@ struct ProcCmd CONST_DATA ProcScr_SioWarpFxPartial[] = // clang-format on //! FE8U = 0x0804C260 -ProcPtr sub_804C260(struct Unit * unit, struct MUProc * muProc, int x, int y, int facing, u8 playStepSe, ProcPtr parent) +ProcPtr sub_804C260(struct Unit * unit, struct MuProc * muProc, int x, int y, int facing, u8 playStepSe, ProcPtr parent) { struct SioWarpProc * proc; diff --git a/src/statscreen.c b/src/statscreen.c index 3d357a1fb..4ee110101 100644 --- a/src/statscreen.c +++ b/src/statscreen.c @@ -1625,7 +1625,7 @@ void StatScreen_Display(struct Proc* proc) // Display Map Sprite MU_EndAll(); - gStatScreen.mu = MU_CreateForUI(gStatScreen.unit, 80, 138); + gStatScreen.mu = StartUiMu(gStatScreen.unit, 80, 138); // Draw left panel labels and info diff --git a/src/uiarena.c b/src/uiarena.c index a68fbd1da..4ac74aba3 100644 --- a/src/uiarena.c +++ b/src/uiarena.c @@ -52,7 +52,7 @@ void StartArenaResultsScreen(void) { //! FE8U = 0x080B57A0 void ArenaUi_Init(ProcPtr proc) { - Proc_ForEach(gProcScr_MoveUnit, (ProcFunc) MU_Hide); + Proc_ForEach(ProcScr_Mu, (ProcFunc) MU_Hide); InitShopScreenConfig(); @@ -127,8 +127,8 @@ void ArenaUi_Init(ProcPtr proc) { //! FE8U = 0x080B5970 void sub_80B5970(void) { UpdateUnitFromBattle(gArenaState.playerUnit, &gBattleActor); - MU_Create(gActiveUnit); - MU_SetDefaultFacing_Auto(); + StartMu(gActiveUnit); + SetAutoMuDefaultFacing(); return; } @@ -296,7 +296,7 @@ void ArenaUi_ShowGoldBoxOnVictoryOrDraw(ProcPtr proc) { //! FE8U = 0x080B5BE4 void ArenaUi_OnEnd(void) { Proc_EndEach(gProcScr_GoldBox); - Proc_ForEach(gProcScr_MoveUnit, (ProcFunc) MU_Show); + Proc_ForEach(ProcScr_Mu, (ProcFunc) MU_Show); return; } diff --git a/src/unit_facing.c b/src/unit_facing.c index 96627fa21..54786efef 100644 --- a/src/unit_facing.c +++ b/src/unit_facing.c @@ -8,5 +8,5 @@ void ChangeActiveUnitFacing(int xLook, int yLook) { + MU_COMMAND_FACE_BASE; gWorkingMovementScript[0] = direction; gWorkingMovementScript[1] = MU_COMMAND_HALT; - MU_StartMoveScript_Auto(gWorkingMovementScript); + SetAutoMuMoveScript(gWorkingMovementScript); } diff --git a/src/worldmap_main.c b/src/worldmap_main.c index cfa460ad8..6566ebb0a 100644 --- a/src/worldmap_main.c +++ b/src/worldmap_main.c @@ -320,7 +320,7 @@ void SetupGraphicSystemsForWorldMap(void) ResetFaces(); SetupFaceGfxData(gUnknown_08A3D728); ResetUnitSprites(); - MU_Init(); + InitMus(); SetupMapSpritesPalettes(); gBmSt.camera.x = 0; diff --git a/src/worldmap_status_ui.c b/src/worldmap_status_ui.c index cf4d6b284..754467831 100644 --- a/src/worldmap_status_ui.c +++ b/src/worldmap_status_ui.c @@ -140,7 +140,7 @@ struct WorldmapStatusProc { /* 00 */ PROC_HEADER; /* 2C */ struct Unit * unit; - /* 30 */ struct MUProc * muProc; + /* 30 */ struct MuProc * muProc; /* 34 */ struct Text text[2]; }; @@ -307,7 +307,7 @@ void WorldmapStatus_InitDetails(struct WorldmapStatusProc * proc) } MU_EndAll(); - proc->muProc = MU_CreateForUI(proc->unit, 216, 135); + proc->muProc = StartUiMu(proc->unit, 216, 135); PutWorldmapStatusDetails(proc); From 5916290a71692015b8dfdca3327efefb2bb5decd Mon Sep 17 00:00:00 2001 From: MokhaLeee Date: Thu, 11 Jul 2024 13:22:20 +0800 Subject: [PATCH 3/7] mu-review in process --- include/ap.h | 8 + include/ctc.h | 7 + include/mu.h | 145 ++++----- include/proc.h | 2 + include/worldmap.h | 4 +- src/bmidoten.c | 48 +-- src/bmmind.c | 6 +- src/bmpatharrowdisp.c | 32 +- src/bmshop.c | 4 +- src/cp_perform.c | 8 +- src/eventscr.c | 2 +- src/koido.c | 8 +- src/mapanim.c | 2 +- src/mapanim_api.c | 2 +- src/mapanim_eventbattle.c | 2 +- src/mapanim_spellassoc.c | 20 +- src/mu.c | 614 ++++++++++++++++---------------------- src/muctrl.c | 8 +- src/sio_battlemap.c | 32 +- src/sio_mu.c | 8 +- src/statscreen.c | 6 +- src/uiarena.c | 4 +- src/unit_facing.c | 4 +- src/worldmap_draw.c | 4 +- src/worldmap_main.c | 2 +- src/worldmap_mapmu.c | 6 +- src/worldmap_rm.c | 4 +- src/worldmap_timemons.c | 4 +- 28 files changed, 467 insertions(+), 529 deletions(-) diff --git a/include/ap.h b/include/ap.h index d6eba456d..8eae8fbb1 100644 --- a/include/ap.h +++ b/include/ap.h @@ -46,4 +46,12 @@ void APProc_Delete(struct APProc * proc); void APProc_DeleteAll(void); bool APProc_Exists(void); +#define ResetSpriteAnimClock(anim) \ + (anim)->frameTimer = 0; \ + (anim)->frameInterval = 0x100 + +#define FreezeSpriteAnim(anim) \ + (anim)->frameTimer = 0; \ + (anim)->frameInterval = 0 + #endif // GUARD_AP_H diff --git a/include/ctc.h b/include/ctc.h index f38e3aad2..0910d0871 100644 --- a/include/ctc.h +++ b/include/ctc.h @@ -90,4 +90,11 @@ void PushSpriteLayerObjects(int layer); struct SpriteProc * StartSpriteRefresher(ProcPtr parent, int layer, int x, int y, const u16* object, int tileref); void MoveSpriteRefresher(struct SpriteProc* proc, int x, int y); +#define SetObjAffineAuto(id, angle, x_scale, y_scale) \ + SetObjAffine((id), \ + Div(+COS((angle)) << 4, (x_scale)), \ + Div(-SIN((angle)) << 4, (y_scale)), \ + Div(+SIN((angle)) << 4, (x_scale)), \ + Div(+COS((angle)) << 4, (y_scale))) + #endif // GUARD_CTC_H diff --git a/include/mu.h b/include/mu.h index 785a40886..7d4a10328 100644 --- a/include/mu.h +++ b/include/mu.h @@ -16,16 +16,18 @@ enum { MU_MAX_COUNT = 4, // Maximum move command count - MU_COMMAND_MAX_COUNT = 0x40, + MOVE_CMD_MAX_COUNT = 0x40, // Maximum size of uncompressed MU sprite sheet MU_GFX_MAX_SIZE = 0x2200, // Default base obj tile index for storing sprites in VRAM - MU_BASE_OBJ_TILE = 0x380, + OBCHR_MU_180 = 0x180, + OBCHR_MU_380 = 0x380, // obj palette id used for MU fade effects - MU_FADE_OBJ_PAL = 5, + OBPAL_MU_1 = 1, + OBPAL_MU_FADE = 5, // Number of bits used to keep track of subpixels MU_SUBPIXEL_PRECISION = 4, @@ -49,31 +51,31 @@ enum { // MU command identifiers - MU_COMMAND_END = -1, // end + MOVE_CMD_END = -1, // end - MU_COMMAND_MOVE_BASE, + MOVE_CMD_MOVE_BASE, - MU_COMMAND_MOVE_LEFT = MU_COMMAND_MOVE_BASE + FACING_LEFT, - MU_COMMAND_MOVE_RIGHT = MU_COMMAND_MOVE_BASE + FACING_RIGHT, - MU_COMMAND_MOVE_DOWN = MU_COMMAND_MOVE_BASE + FACING_DOWN, - MU_COMMAND_MOVE_UP = MU_COMMAND_MOVE_BASE + FACING_UP, + MOVE_CMD_MOVE_LEFT = MOVE_CMD_MOVE_BASE + FACING_LEFT, + MOVE_CMD_MOVE_RIGHT = MOVE_CMD_MOVE_BASE + FACING_RIGHT, + MOVE_CMD_MOVE_DOWN = MOVE_CMD_MOVE_BASE + FACING_DOWN, + MOVE_CMD_MOVE_UP = MOVE_CMD_MOVE_BASE + FACING_UP, - MU_COMMAND_HALT, + MOVE_CMD_HALT, - MU_COMMAND_FACE_BASE, + MOVE_CMD_FACE_BASE, - MU_COMMAND_FACE_LEFT = MU_COMMAND_FACE_BASE + FACING_LEFT, - MU_COMMAND_FACE_RIGHT = MU_COMMAND_FACE_BASE + FACING_RIGHT, - MU_COMMAND_FACE_DOWN = MU_COMMAND_FACE_BASE + FACING_DOWN, - MU_COMMAND_FACE_UP = MU_COMMAND_FACE_BASE + FACING_UP, + MOVE_CMD_FACE_LEFT = MOVE_CMD_FACE_BASE + FACING_LEFT, + MOVE_CMD_FACE_RIGHT = MOVE_CMD_FACE_BASE + FACING_RIGHT, + MOVE_CMD_FACE_DOWN = MOVE_CMD_FACE_BASE + FACING_DOWN, + MOVE_CMD_FACE_UP = MOVE_CMD_FACE_BASE + FACING_UP, - MU_COMMAND_WAIT, - MU_COMMAND_BUMP, - MU_COMMAND_UNK11, - MU_COMMAND_SET_SPEED, + MOVE_CMD_SLEEP, + MOVE_CMD_BUMP, + MOVE_CMD_UNK11, + MOVE_CMD_SET_SPEED, - MU_COMMAND_CAMERA_ON, - MU_COMMAND_CAMERA_OFF, + MOVE_CMD_CAMERA_ON, + MOVE_CMD_CAMERA_OFF, }; enum @@ -115,7 +117,7 @@ struct MuProc { /* 34 */ struct MuConfig * config; /* 38 */ void* pGfxVRAM; - /* 3C */ u8 muIndex; + /* 3C */ u8 slot; /* 3D */ u8 _u3D; /* 3E */ u8 cam_b; /* 3F */ u8 state; @@ -140,16 +142,20 @@ struct MuProc { struct MuConfig { - /* 00 */ u8 muIndex; + /* 00 */ u8 slot; /* 01 */ u8 pal; /* 02 */ u16 chr; - /* 04 */ u8 currentCommand; - /* 05 */ s8 commands[MU_COMMAND_MAX_COUNT]; + /* 04 */ u8 pc; + /* 05 */ s8 movescr[MOVE_CMD_MAX_COUNT]; /* 45 */ // 3 byte padding /* 48 */ struct MuProc * mu; }; -#define MU_AdvanceGetCommand(proc) (proc->config->commands[proc->config->currentCommand++]) +enum mu_config_ctrl_bits { + MU_CONFIG_SPPED_SLOW = 0x40, + MU_CONFIG_SPPED_NORMAL = 0x80, + MU_CONFIG_SPPED_FAST = 0x100, +}; struct MuStepSoundProc { @@ -158,7 +164,7 @@ struct MuStepSoundProc /* 58 */ u32 song1; /* 5C */ u32 song2; - /* 60 */ u32 u60_buggedmaybe; // Checked for in MU_StartStepSfx but never initialized + /* 60 */ u32 unk60; /* 64 */ s16 x1; /* 66 */ s16 x2; }; @@ -167,13 +173,14 @@ struct MuFogBumpProc { PROC_HEADER; - /* 2C */ int xDisplay; - /* 30 */ int yDisplay; + /* 2C */ int x, y; + + STRUCT_PAD(0x34, 0x50); - /* 34 */ STRUCT_PAD(0x34, 0x50); /* 50 */ struct APHandle * sprite_anim; - /* 54 */ STRUCT_PAD(0x54, 0x64); + STRUCT_PAD(0x54, 0x64); + /* 64 */ s16 timer; }; @@ -219,73 +226,73 @@ struct MuProc * StartMuInternal(u16 x, u16 y, u16 jid, int objTileId, unsigned p void SetMuFacing(struct MuProc * proc, int facing); void SetMuDefaultFacing(struct MuProc * proc); void SetAutoMuDefaultFacing(void); -void SetAutoMuMoveScript(const u8 commands[MU_COMMAND_MAX_COUNT]); +void SetAutoMuMoveScript(const u8 commands[MOVE_CMD_MAX_COUNT]); s8 MuExists(void); s8 MuExistsActive(void); s8 IsMuActive(struct MuProc * proc); -void SetMuMoveScript(struct MuProc * proc, const u8 commands[MU_COMMAND_MAX_COUNT]); -struct MuProc * StartMuScripted(u16 x, u16 y, u16 jid, int palId, const u8 commands[MU_COMMAND_MAX_COUNT]); +void SetMuMoveScript(struct MuProc * proc, const u8 commands[MOVE_CMD_MAX_COUNT]); +struct MuProc * StartMuScripted(u16 x, u16 y, u16 jid, int palId, const u8 commands[MOVE_CMD_MAX_COUNT]); void MuStepSe_Init(struct MuStepSoundProc * proc); void MuStepSe_PlaySeA(struct MuStepSoundProc * proc); void MuStepSe_PlaySeB(struct MuStepSoundProc * proc); -void MU_StartStepSfx(int soundId, int b, int hPosition); +void StartPlayMuStepSe(int song, int alt_offset, int x); void PlayMuStepSe(struct MuProc * proc); -void MU_8078894(struct MuProc * proc); -void MU_InterpretCommandScript(struct MuProc * proc); -void MU_StartFogBumpFx(int x, int y); +void EndMuMovement(struct MuProc * proc); +void RunMuMoveScript(struct MuProc * proc); +void StartMuFogBump(int x, int y); void MuFogBump_Init(struct MuFogBumpProc * proc); void MuFogBump_ScaleLoop(struct MuFogBumpProc * proc); void MuFogBump_EndLoop(struct MuFogBumpProc * proc); u8 MU_IsFogBumpFxActive(void); void Mu_OnStateBump(struct MuProc * proc); -void Mu_OnStateMoving(struct MuProc * proc); +void Mu_OnStateUnk4(struct MuProc * proc); void Mu_OnStateSleeping(struct MuProc * proc); void Mu_OnStateNone(struct MuProc * proc); void Mu_OnStateDoNothing(struct MuProc * proc); void Mu_OnStateMovement(struct MuProc * proc); -void MU_AdvanceStepSfx(struct MuProc * proc); +void UpdateMuStepSounds(struct MuProc * proc); void MU_OnLoop(struct MuProc * proc); void MU_OnEnd(struct MuProc * proc); void MU_EndAll(void); void MU_End(struct MuProc * proc); void MU_EndInternal(struct MuProc * proc); -void MU_80790CC(struct MuProc * proc); +void HaltMu(struct MuProc * proc); void MU_AllDisable(void); void MU_AllEnable(void); -void MU_GetComputedEndPosition(int * xOut, int * yOut, const u8 * commands); -s8 MU_CanStart(void); -void MU_AllRestartAnimations(void); +void ApplyMoveScriptToCoordinates(int * xOut, int * yOut, const u8 * commands); +s8 CanStartMu(void); +void ResetMuAnims(void); static struct MuConfig * GetDefaultMuConfig(int objTileId, u8 * outIndex); static struct MuConfig * GetNewMuConfig(int objTileId, u8 * outIndex); -u8 MU_ComputeDisplayPosition(struct MuProc * proc, struct Vec2 * out); -void MU_DisplayAsSMS(struct MuProc * proc); -void MU_DisplayAsMMS(struct MuProc * proc); -u16 MU_GetMovementSpeed(struct MuProc * proc); -void MU_SetMoveConfig(struct MuProc * proc, u16 config); -void* GetMuImgBufById(int muIndex); +u8 GetMuDisplayPosition(struct MuProc * proc, struct Vec2 * out); +void PutMuSMS(struct MuProc * proc); +void PutMu(struct MuProc * proc); +u16 GetMuQ4MovementSpeed(struct MuProc * proc); +void SetMuConfig(struct MuProc * proc, u16 config); +void* GetMuImgBufById(int slot); const void * GetMuImg(struct MuProc * proc); const void * GetMuAnimForJid(u16 classId); void MU_StartDeathFade(struct MuProc * muProc); void MuDeathFade_OnLoop(struct MuEffectProc * proc); -void MUBlinkEffect_OnLoop(struct MuEffectProc * proc); -void MU_StartBlinkEffect(struct MuProc * muProc); +void MuBlink_OnLoop(struct MuEffectProc * proc); +void StartBlinkMu(struct MuProc * muProc); void MU_SetupPixelEffect(u32* data, int frame); void MuPixelEffect_OnLoop(struct MuEffectProc * proc); void MU_StartPixelEffect(struct MuProc * muProc); -void MU_Hide(struct MuProc * proc); -void MU_Show(struct MuProc * proc); -void MU_SetDisplayPosition(struct MuProc * proc, int x, int y); -void MU_SetDisplayOffset(struct MuProc * proc, int xOff, int yOff); -void MU_StartFlashFade(struct MuProc * proc, int flashType); -void MU_8079858(struct MuProc * muProc); +void HideMu(struct MuProc * proc); +void ShowMu(struct MuProc * proc); +void SetMuScreenPosition(struct MuProc * proc, int x, int y); +void SetMuScreenOffset(struct MuProc * proc, int xOff, int yOff); +void StartMuFadeIntoFlash(struct MuProc * proc, int flashType); +void StartMuFadeFromFlash(struct MuProc * muProc); void MuRestorePalInfo_Apply(struct MuEffectProc * proc); -void MU_StartActionAnim(struct MuProc * proc); -void MU_EndSelectionApAnim(int argAp); -void MU_StartDelayedFaceTarget(struct MuProc * proc); -void MU_EndRefaceApAnim(int argAp); -void MU_EndFasterApAnim(int argAp); -void MU_StartFastMoveAnim(struct MuProc * proc); -void MU_StartCritFlash(struct MuProc * muProc, int flashType); +void StartMuActionAnim(struct MuProc * proc); +void MuActionAnimFinishFunc(int arg); +void StartMuDelayedFaceDefender(struct MuProc * proc); +void MuDelayedFaceDefenderFunc(int arg); +void MuSlowDownAnimFreezeFunc(int arg); +void StartMuSpeedUpAnim(struct MuProc * proc); +void StartMuCritFlash(struct MuProc * muProc, int flashType); void MuCritFlash_Init(struct MuFlashEffectProc * proc); void MuCritFlash_SetFadedPalette(struct MuFlashEffectProc * proc); void MuCritFlash_SetRegularPalette(struct MuFlashEffectProc * proc); @@ -298,7 +305,7 @@ void MU_AllForceSetMaxMoveSpeed(void); void MU_ForceSetMaxMoveSpeed(ProcPtr proc); void MU_SetSpecialSprite(struct MuProc * proc, int jid, const u16 * palette); void MU_SetPaletteId(struct MuProc * proc, unsigned paletteId); -struct MuProc * MU_GetByIndex(int muIndex); +struct MuProc * MU_GetByIndex(int slot); struct MuProc * MU_GetByUnit(struct Unit * unit); void MU_SortObjLayers(void); @@ -306,7 +313,7 @@ extern u8 gMUGfxBuffer[MU_GFX_MAX_SIZE * MU_MAX_COUNT]; extern struct ProcCmd CONST_DATA ProcScr_Mu[]; extern struct ProcCmd CONST_DATA ProcScr_MuDeathFade[]; -extern struct ProcCmd CONST_DATA ProcScr_MuBlinkEffect[]; +extern struct ProcCmd CONST_DATA ProcScr_MuBlink[]; extern struct ProcCmd CONST_DATA ProcScr_MuRestorePalInfo[]; extern u16 CONST_DATA MuSoundScr_Foot[]; extern u16 CONST_DATA MuSoundScr_FootHeavy[]; @@ -326,9 +333,9 @@ extern u16 CONST_DATA MuSoundScr_Myrrh[]; // extern ??? gUnknown_089A2C28 // extern ??? ProcScr_Mu extern CONST_DATA struct ProcCmd ProcScr_MuDeathFade[]; -extern CONST_DATA struct ProcCmd ProcScr_MuBlinkEffect[]; +extern CONST_DATA struct ProcCmd ProcScr_MuBlink[]; extern CONST_DATA struct ProcCmd ProcScr_MuRestorePalInfo[]; -extern const u16 * CONST_DATA MUFlashColorLookup[]; +extern const u16 * CONST_DATA gMuFlashPalLut[]; #endif // GUARD_MU_H diff --git a/include/proc.h b/include/proc.h index 22542e149..06479ca9a 100644 --- a/include/proc.h +++ b/include/proc.h @@ -159,4 +159,6 @@ int CountProcs(const struct ProcCmd * script); void Proc_FindBegin(struct ProcFindIterator* it, const struct ProcCmd* script); ProcPtr Proc_FindNext(struct ProcFindIterator* it); +#define Proc_Exists(script) (Proc_Find((script)) ? true : false) + #endif // GUARD_PROC_H diff --git a/include/worldmap.h b/include/worldmap.h index 10592aa9b..5bb4adb40 100644 --- a/include/worldmap.h +++ b/include/worldmap.h @@ -826,8 +826,8 @@ ProcPtr StartGmMu(ProcPtr); // ??? GmMu_SetUnit(???); void GmMu_RemoveUnit(struct GMapMuProc *, int); // ??? sub_80BDD94(???); -void GmMu_ShowUnit(struct GMapMuProc *, int); -void GmMu_HideUnit(struct GMapMuProc *, int); +void GmShowMuUnit(struct GMapMuProc *, int); +void GmHideMuUnit(struct GMapMuProc *, int); void sub_80BDEB4(struct GMapMuProc *, struct UnknownSub80BDEB4 *); void sub_80BDFA4(struct GMapMuProc *, struct UnknownSub80BDFA4 *); void GmMu_PauseMovement(struct GMapMuProc *, int); diff --git a/src/bmidoten.c b/src/bmidoten.c index df6ca9af4..809a65e2f 100644 --- a/src/bmidoten.c +++ b/src/bmidoten.c @@ -171,24 +171,24 @@ void GenerateBestMovementScript(int x, int y, u8 output[]) // Build neighbor cost list if (x == (gBmMapSize.x - 1)) - neighbourCosts[MU_COMMAND_MOVE_LEFT] |= 0xFF; + neighbourCosts[MOVE_CMD_MOVE_LEFT] |= 0xFF; else - neighbourCosts[MU_COMMAND_MOVE_LEFT] = gWorkingBmMap[y][x+1]; + neighbourCosts[MOVE_CMD_MOVE_LEFT] = gWorkingBmMap[y][x+1]; if (x == 0) - neighbourCosts[MU_COMMAND_MOVE_RIGHT] |= 0xFF; + neighbourCosts[MOVE_CMD_MOVE_RIGHT] |= 0xFF; else - neighbourCosts[MU_COMMAND_MOVE_RIGHT] = gWorkingBmMap[y][x-1]; + neighbourCosts[MOVE_CMD_MOVE_RIGHT] = gWorkingBmMap[y][x-1]; if (y == (gBmMapSize.y - 1)) - neighbourCosts[MU_COMMAND_MOVE_UP] |= 0xFF; + neighbourCosts[MOVE_CMD_MOVE_UP] |= 0xFF; else - neighbourCosts[MU_COMMAND_MOVE_UP] = gWorkingBmMap[y+1][x]; + neighbourCosts[MOVE_CMD_MOVE_UP] = gWorkingBmMap[y+1][x]; if (y == 0) - neighbourCosts[MU_COMMAND_MOVE_DOWN] |= 0xFF; + neighbourCosts[MOVE_CMD_MOVE_DOWN] |= 0xFF; else - neighbourCosts[MU_COMMAND_MOVE_DOWN] = gWorkingBmMap[y-1][x]; + neighbourCosts[MOVE_CMD_MOVE_DOWN] = gWorkingBmMap[y-1][x]; // find best cost @@ -238,19 +238,19 @@ void GenerateBestMovementScript(int x, int y, u8 output[]) switch (nextDirection) { - case MU_COMMAND_MOVE_LEFT: + case MOVE_CMD_MOVE_LEFT: x++; break; - case MU_COMMAND_MOVE_RIGHT: + case MOVE_CMD_MOVE_RIGHT: x--; break; - case MU_COMMAND_MOVE_UP: + case MOVE_CMD_MOVE_UP: y++; break; - case MU_COMMAND_MOVE_DOWN: + case MOVE_CMD_MOVE_DOWN: y--; break; @@ -263,19 +263,19 @@ void GenerateBestMovementScript(int x, int y, u8 output[]) void RevertMovementScript(u8* begin, u8* end) { - u8 buffer[MU_COMMAND_MAX_COUNT]; + u8 buffer[MOVE_CMD_MAX_COUNT]; u8* it = buffer; while (end > begin) *it++ = *--end; - *it = MU_COMMAND_HALT; + *it = MOVE_CMD_HALT; - for (it = buffer; *it != MU_COMMAND_HALT;) + for (it = buffer; *it != MOVE_CMD_HALT;) *begin++ = *it++; - *begin = MU_COMMAND_HALT; + *begin = MOVE_CMD_HALT; } void UnitApplyWorkingMovementScript(struct Unit* unit, int x, int y) @@ -289,19 +289,19 @@ void UnitApplyWorkingMovementScript(struct Unit* unit, int x, int y) switch (*it) { - case MU_COMMAND_MOVE_UP: // up + case MOVE_CMD_MOVE_UP: // up y--; break; - case MU_COMMAND_MOVE_DOWN: // down + case MOVE_CMD_MOVE_DOWN: // down y++; break; - case MU_COMMAND_MOVE_LEFT: // left + case MOVE_CMD_MOVE_LEFT: // left x--; break; - case MU_COMMAND_MOVE_RIGHT: // right + case MOVE_CMD_MOVE_RIGHT: // right x++; break; @@ -311,7 +311,7 @@ void UnitApplyWorkingMovementScript(struct Unit* unit, int x, int y) { if (gBmMapHidden[y][x] & HIDDEN_BIT_TRAP) { - *++it = MU_COMMAND_HALT; + *++it = MOVE_CMD_HALT; gActionData.unitActionType = UNIT_ACTION_TRAPPED; gActionData.xMove = x; @@ -323,15 +323,15 @@ void UnitApplyWorkingMovementScript(struct Unit* unit, int x, int y) if (gBmMapHidden[y][x] & HIDDEN_BIT_UNIT) { - *it++ = MU_COMMAND_BUMP; - *it++ = MU_COMMAND_HALT; + *it++ = MOVE_CMD_BUMP; + *it++ = MOVE_CMD_HALT; gActionData.unitActionType = UNIT_ACTION_TRAPPED; return; } - if (*it == MU_COMMAND_HALT) + if (*it == MOVE_CMD_HALT) break; it++; diff --git a/src/bmmind.c b/src/bmmind.c index 5b4cffb8c..447e43736 100644 --- a/src/bmmind.c +++ b/src/bmmind.c @@ -215,8 +215,8 @@ s8 ActionDrop(ProcPtr proc) { struct Unit* target = GetUnit(gActionData.targetIndex); if (gBmMapHidden[gActionData.yOther][gActionData.xOther] & HIDDEN_BIT_UNIT) { - gWorkingMovementScript[0] = MU_COMMAND_BUMP; - gWorkingMovementScript[1] = MU_COMMAND_HALT; + gWorkingMovementScript[0] = MOVE_CMD_BUMP; + gWorkingMovementScript[1] = MOVE_CMD_HALT; SetAutoMuMoveScript(gWorkingMovementScript); return 0; } @@ -581,7 +581,7 @@ void BATTLE_PostCombatDeathFades(struct CombatActionProc* proc) { muProc = StartMu(&gBattleTarget.unit); gWorkingMovementScript[0] = GetFacingDirection(gBattleActor.unit.xPos, gBattleActor.unit.yPos, gBattleTarget.unit.xPos, gBattleTarget.unit.yPos); - gWorkingMovementScript[1] = MU_COMMAND_HALT; + gWorkingMovementScript[1] = MOVE_CMD_HALT; SetMuMoveScript(muProc, gWorkingMovementScript); MU_StartDeathFade(muProc); diff --git a/src/bmpatharrowdisp.c b/src/bmpatharrowdisp.c index 3b4913971..9e71d8668 100644 --- a/src/bmpatharrowdisp.c +++ b/src/bmpatharrowdisp.c @@ -79,31 +79,31 @@ void GetPathFromMovementScript(void) { if (cmd <= 0xa) { switch (cmd) { - case MU_COMMAND_END + 1: - case MU_COMMAND_HALT + 1: + case MOVE_CMD_END + 1: + case MOVE_CMD_HALT + 1: return; - case MU_COMMAND_FACE_LEFT + 1: - case MU_COMMAND_FACE_RIGHT + 1: - case MU_COMMAND_FACE_DOWN + 1: - case MU_COMMAND_FACE_UP + 1: - case MU_COMMAND_WAIT + 1: + case MOVE_CMD_FACE_LEFT + 1: + case MOVE_CMD_FACE_RIGHT + 1: + case MOVE_CMD_FACE_DOWN + 1: + case MOVE_CMD_FACE_UP + 1: + case MOVE_CMD_SLEEP + 1: continue; - case MU_COMMAND_MOVE_LEFT + 1: + case MOVE_CMD_MOVE_LEFT + 1: AddPointToPathArrowProc( gpPathArrowProc->pathX[gpPathArrowProc->pathLen] - 1, gpPathArrowProc->pathY[gpPathArrowProc->pathLen]); break; - case MU_COMMAND_MOVE_RIGHT + 1: + case MOVE_CMD_MOVE_RIGHT + 1: AddPointToPathArrowProc( gpPathArrowProc->pathX[gpPathArrowProc->pathLen] + 1, gpPathArrowProc->pathY[gpPathArrowProc->pathLen]); break; - case MU_COMMAND_MOVE_UP + 1: + case MOVE_CMD_MOVE_UP + 1: AddPointToPathArrowProc( gpPathArrowProc->pathX[gpPathArrowProc->pathLen], gpPathArrowProc->pathY[gpPathArrowProc->pathLen] - 1); break; - case MU_COMMAND_MOVE_DOWN + 1: + case MOVE_CMD_MOVE_DOWN + 1: AddPointToPathArrowProc( gpPathArrowProc->pathX[gpPathArrowProc->pathLen], gpPathArrowProc->pathY[gpPathArrowProc->pathLen] + 1); @@ -125,20 +125,20 @@ void GetMovementScriptFromPath(void) { newX = gpPathArrowProc->pathX[i]; x = gpPathArrowProc->pathX[i - 1]; if (newX < x) { - gWorkingMovementScript[i - 1] = MU_COMMAND_MOVE_LEFT; + gWorkingMovementScript[i - 1] = MOVE_CMD_MOVE_LEFT; } else if (newX > x) { - gWorkingMovementScript[i - 1] = MU_COMMAND_MOVE_RIGHT; + gWorkingMovementScript[i - 1] = MOVE_CMD_MOVE_RIGHT; } else if (gpPathArrowProc->pathY[i] < gpPathArrowProc->pathY[i - 1]) { - gWorkingMovementScript[i - 1] = MU_COMMAND_MOVE_UP; + gWorkingMovementScript[i - 1] = MOVE_CMD_MOVE_UP; } else { - gWorkingMovementScript[i - 1] = MU_COMMAND_MOVE_DOWN; + gWorkingMovementScript[i - 1] = MOVE_CMD_MOVE_DOWN; } } - gWorkingMovementScript[i - 1] = MU_COMMAND_HALT; + gWorkingMovementScript[i - 1] = MOVE_CMD_HALT; } void GenerateMovementMapForActiveUnit(void) { diff --git a/src/bmshop.c b/src/bmshop.c index 601a2c9fd..ad31fcfa3 100644 --- a/src/bmshop.c +++ b/src/bmshop.c @@ -801,7 +801,7 @@ void Shop_ExitShopDialogue(struct ProcShop * proc) void Shop_OnExit(void) { Proc_EndEach(gProcScr_GoldBox); - Proc_ForEach(ProcScr_Mu, (ProcFunc) MU_Show); + Proc_ForEach(ProcScr_Mu, (ProcFunc) ShowMu); } void Shop_PrepEntryDialogue(struct ProcShop * proc) @@ -904,7 +904,7 @@ void Shop_Init(struct ProcShop * proc) else StartBgm(0x35, 0); - Proc_ForEach(ProcScr_Mu, (ProcFunc) MU_Hide); + Proc_ForEach(ProcScr_Mu, (ProcFunc) HideMu); InitShopScreenConfig(); diff --git a/src/cp_perform.c b/src/cp_perform.c index b28025beb..85983161d 100644 --- a/src/cp_perform.c +++ b/src/cp_perform.c @@ -227,10 +227,10 @@ void AiStartCombatAction(struct CpPerformProc* proc) { void AiStartEscapeAction(struct CpPerformProc* proc) { u8 scripts[4][3] = { - { MU_COMMAND_MOVE_LEFT, MU_COMMAND_MOVE_LEFT, MU_COMMAND_HALT }, - { MU_COMMAND_MOVE_RIGHT, MU_COMMAND_MOVE_RIGHT, MU_COMMAND_HALT }, - { MU_COMMAND_MOVE_DOWN, MU_COMMAND_MOVE_DOWN, MU_COMMAND_HALT }, - { MU_COMMAND_MOVE_UP, MU_COMMAND_MOVE_UP, MU_COMMAND_HALT }, + { MOVE_CMD_MOVE_LEFT, MOVE_CMD_MOVE_LEFT, MOVE_CMD_HALT }, + { MOVE_CMD_MOVE_RIGHT, MOVE_CMD_MOVE_RIGHT, MOVE_CMD_HALT }, + { MOVE_CMD_MOVE_DOWN, MOVE_CMD_MOVE_DOWN, MOVE_CMD_HALT }, + { MOVE_CMD_MOVE_UP, MOVE_CMD_MOVE_UP, MOVE_CMD_HALT }, }; if ((gAiDecision.xTarget != 5) && (proc->isUnitVisible)) { diff --git a/src/eventscr.c b/src/eventscr.c index da96f11ba..3bc7ec5fd 100644 --- a/src/eventscr.c +++ b/src/eventscr.c @@ -2858,7 +2858,7 @@ u8 TryPrepareEventUnitMovement(struct EventEngineProc * proc, int x, int y) return FALSE; // Failed to start camera movement } - if (!MU_CanStart()) + if (!CanStartMu()) return FALSE; // No room to make MU for the moving unit return TRUE; // Yay! diff --git a/src/koido.c b/src/koido.c index da43a2066..2e5383df4 100644 --- a/src/koido.c +++ b/src/koido.c @@ -102,9 +102,9 @@ void Make6CKOIDO(struct Unit* unit, int direction, int config, ProcPtr parent) proc->unit = unit; proc->direction = direction; - proc->mu_commands[0] = MU_COMMAND_CAMERA_OFF; + proc->mu_commands[0] = MOVE_CMD_CAMERA_OFF; proc->mu_commands[1] = direction; - proc->mu_commands[2] = MU_COMMAND_HALT; + proc->mu_commands[2] = MOVE_CMD_HALT; Make6CKOIDO_common(unit, config, proc); } @@ -115,9 +115,9 @@ void Make6CKOIDOAMM(struct Unit* unit, int direction) proc->unit = unit; proc->direction = direction; - proc->mu_commands[0] = MU_COMMAND_CAMERA_OFF; + proc->mu_commands[0] = MOVE_CMD_CAMERA_OFF; proc->mu_commands[1] = direction; - proc->mu_commands[2] = MU_COMMAND_HALT; + proc->mu_commands[2] = MOVE_CMD_HALT; Make6CKOIDO_common(unit, 0, proc); } diff --git a/src/mapanim.c b/src/mapanim.c index d16ea57bc..195afd47d 100644 --- a/src/mapanim.c +++ b/src/mapanim.c @@ -86,7 +86,7 @@ void _InitFontForUIDefault(void) { } void MapAnim_Cleanup(void) { - MU_AllRestartAnimations(); + ResetMuAnims(); ResetTextFont(); DeleteBattleAnimInfoThing(); InitBmBgLayers(); diff --git a/src/mapanim_api.c b/src/mapanim_api.c index 99dd1931d..fd23f20aa 100644 --- a/src/mapanim_api.c +++ b/src/mapanim_api.c @@ -27,7 +27,7 @@ void MakeBattleMOVEUNIT(int maActor, struct BattleUnit* bu, struct Unit* unit) gManimSt.actor[maActor].mu->sprite_anim->frameInterval = 0; if (BUNIT_IS_OBSTACLE(bu)) - MU_Hide(gManimSt.actor[maActor].mu); + HideMu(gManimSt.actor[maActor].mu); switch (unit->statusIndex) { diff --git a/src/mapanim_eventbattle.c b/src/mapanim_eventbattle.c index 2fdac2615..ff65c72da 100644 --- a/src/mapanim_eventbattle.c +++ b/src/mapanim_eventbattle.c @@ -26,7 +26,7 @@ void MapEventBattle_SetUpHitData(ProcPtr proc) void MapEventBattle_OnEnd(void) { - MU_AllRestartAnimations(); + ResetMuAnims(); ResetTextFont(); DeleteBattleAnimInfoThing(); InitBmBgLayers(); diff --git a/src/mapanim_spellassoc.c b/src/mapanim_spellassoc.c index e1d389f68..c1b5104fa 100644 --- a/src/mapanim_spellassoc.c +++ b/src/mapanim_spellassoc.c @@ -24,12 +24,12 @@ const struct ProcCmd * GetItemAnim6CCode(void) void MapAnim_AnimateSubjectIdle(ProcPtr proc) { - MU_StartActionAnim(gManimSt.actor[gManimSt.subjectActorId].mu); + StartMuActionAnim(gManimSt.actor[gManimSt.subjectActorId].mu); } void MapAnim_SubjectResetAnim(ProcPtr proc) { - MU_StartDelayedFaceTarget(gManimSt.actor[gManimSt.subjectActorId].mu); + StartMuDelayedFaceDefender(gManimSt.actor[gManimSt.subjectActorId].mu); } void sub_80812C0(void) @@ -64,7 +64,7 @@ void sub_80813C0(void) void MapAnim_BeginSubjectFastAnim(void) { - MU_StartFastMoveAnim(gManimSt.actor[gManimSt.subjectActorId].mu); + StartMuSpeedUpAnim(gManimSt.actor[gManimSt.subjectActorId].mu); } void MapAnimMoveUnitTowardsTargetExt(struct MuProc * mu1, struct MuProc * mu2) @@ -291,7 +291,7 @@ void MapAnim_BeginRoundSpecificAnims(ProcPtr proc) gManimSt.actor[map_target].unit->xPos * 0x10 - gBmSt.camera.x ); - MU_StartCritFlash( + StartMuCritFlash( gManimSt.actor[map_target].mu, GetSpellAssocFlashColor(gManimSt.actor[map_actor].bu->weaponBefore) ); @@ -302,7 +302,7 @@ void MapAnim_BeginRoundSpecificAnims(ProcPtr proc) gManimSt.actor[map_target].unit->xPos * 0x10 - gBmSt.camera.x ); - MU_StartFastMoveAnim(gManimSt.actor[map_actor].mu); + StartMuSpeedUpAnim(gManimSt.actor[map_actor].mu); } else { @@ -477,17 +477,17 @@ void MapAnimCallSpellAssocRepair(ProcPtr proc) void SpellWarpStartFlashFade(ProcPtr proc) { - MU_StartFlashFade(gManimSt.actor[gManimSt.targetActorId].mu, 0); + StartMuFadeIntoFlash(gManimSt.actor[gManimSt.targetActorId].mu, 0); } void sub_8081CF8(ProcPtr proc) { - MU_8079858(gManimSt.actor[gManimSt.targetActorId].mu); + StartMuFadeFromFlash(gManimSt.actor[gManimSt.targetActorId].mu); } void SpellWarpMuHide(ProcPtr proc) { - MU_Hide(gManimSt.actor[gManimSt.targetActorId].mu); + HideMu(gManimSt.actor[gManimSt.targetActorId].mu); } void SpellWarpStartExplosion(ProcPtr proc) @@ -514,7 +514,7 @@ void SpellWarpStartImplosion(ProcPtr proc) void SpellWarpMuShow(ProcPtr proc) { - MU_Show(gManimSt.actor[gManimSt.targetActorId].mu); + ShowMu(gManimSt.actor[gManimSt.targetActorId].mu); } void SpellWarpSetNewPosition(ProcPtr proc) @@ -522,7 +522,7 @@ void SpellWarpSetNewPosition(ProcPtr proc) struct Unit * unit = gManimSt.actor[gManimSt.targetActorId].unit; struct MuProc * mu = gManimSt.actor[gManimSt.targetActorId].mu; - MU_SetDisplayPosition( + SetMuScreenPosition( mu, gManimSt.xtarget * 0x10, gManimSt.ytarget * 0x10); diff --git a/src/mu.c b/src/mu.c index 286d88535..b925b7a96 100644 --- a/src/mu.c +++ b/src/mu.c @@ -26,7 +26,7 @@ EWRAM_OVERLAY(0) int Unk_2004BDC = 0; EWRAM_OVERLAY(0) u8 gMUGfxBuffer[MU_GFX_MAX_SIZE * MU_MAX_COUNT] = { 0 }; static struct MuConfig sMuConfig[MU_MAX_COUNT]; -const u16 * CONST_DATA MUFlashColorLookup[] = { +const u16 * CONST_DATA gMuFlashPalLut[] = { [MU_FLASH_WHITE] = Pal_AllWhite, [MU_FLASH_BLACK] = Pal_AllBlack, [MU_FLASH_RED] = Pal_AllRed, @@ -145,7 +145,7 @@ static MuStateFunc CONST_DATA sMuStateFuncs[] = { [MU_STATE_INACTIVE] = Mu_OnStateDoNothing, [MU_STATE_MOVEMENT] = Mu_OnStateMovement, [MU_STATE_SLEEPING] = Mu_OnStateSleeping, - [MU_STATE_UNK4] = Mu_OnStateMoving, + [MU_STATE_UNK4] = Mu_OnStateUnk4, [MU_STATE_BUMPING] = Mu_OnStateBump, [MU_STATE_DISPLAY_UI] = Mu_OnStateDoNothing, [MU_STATE_DEATHFADE] = Mu_OnStateDoNothing, @@ -183,8 +183,8 @@ struct ProcCmd CONST_DATA ProcScr_MuDeathFade[] = { PROC_END }; -struct ProcCmd CONST_DATA ProcScr_MuBlinkEffect[] = { - PROC_REPEAT(MUBlinkEffect_OnLoop), +struct ProcCmd CONST_DATA ProcScr_MuBlink[] = { + PROC_REPEAT(MuBlink_OnLoop), PROC_END }; @@ -246,7 +246,7 @@ void InitMus(void) { int i; for (i = 0; i < MU_MAX_COUNT; ++i) - sMuConfig[i].muIndex = 0; + sMuConfig[i].slot = 0; } struct MuProc * StartMuExt(struct Unit * unit, unsigned jid, unsigned pal) @@ -321,7 +321,7 @@ void StartUiStandingMu(struct MuProc * proc) { StartUiSMS( GetClassSMSId(proc->jid), - proc->muIndex + proc->slot ); } @@ -335,7 +335,7 @@ struct MuProc * StartMuInternal(u16 x, u16 y, u16 jid, int objTileId, unsigned p u8 slot = 0; if (objTileId == -1) - config = GetDefaultMuConfig(objTileId = MU_BASE_OBJ_TILE, &slot); + config = GetDefaultMuConfig(objTileId = OBCHR_MU_380, &slot); else config = GetNewMuConfig(objTileId, &slot); @@ -362,7 +362,7 @@ struct MuProc * StartMuInternal(u16 x, u16 y, u16 jid, int objTileId, unsigned p proc->jid = jid; proc->hidden_b = 0; proc->pGfxVRAM = OBJ_VRAM0 + (0x20 * objTileId); - proc->muIndex = slot; + proc->slot = slot; proc->layer = OAM2_LAYER(2); proc->moveConfig = 0; proc->boolForceMaxSpeed = false; @@ -373,10 +373,10 @@ struct MuProc * StartMuInternal(u16 x, u16 y, u16 jid, int objTileId, unsigned p Decompress( GetMuImg(proc), - GetMuImgBufById(config->muIndex) + GetMuImgBufById(config->slot) ); - ap->pGraphics = GetMuImgBufById(config->muIndex); + ap->pGraphics = GetMuImgBufById(config->slot); ap->tileBase = OAM2_PAL(config->pal) + config->chr + proc->layer; proc->sprite_anim = ap; @@ -390,7 +390,7 @@ void SetMuFacing(struct MuProc * proc, int facing) proc->facing = facing; if (facing == MU_FACING_STANDING) - sub_8027068(proc->muIndex, proc->pGfxVRAM); + sub_8027068(proc->slot, proc->pGfxVRAM); else AP_SwitchAnimation(proc->sprite_anim, proc->facing); } @@ -410,7 +410,7 @@ void SetAutoMuDefaultFacing(void) SetMuDefaultFacing(proc); } -void SetAutoMuMoveScript(const u8 commands[MU_COMMAND_MAX_COUNT]) +void SetAutoMuMoveScript(const u8 commands[MOVE_CMD_MAX_COUNT]) { struct MuProc * proc = Proc_Find(ProcScr_Mu); if (proc) @@ -429,10 +429,10 @@ bool MuExistsActive(void) for (i = 0; i < MU_MAX_COUNT; ++i) { #ifndef NONMATCHING - asm(""::"r"(&sMuConfig[i].muIndex)); + asm(""::"r"(&sMuConfig[i].slot)); asm(""::"r"(&sMuConfig[i].mu)); #endif - if (sMuConfig[i].muIndex == 0) continue; + if (sMuConfig[i].slot == 0) continue; while (0) ; if (sMuConfig[i].mu->state != MU_STATE_INACTIVE) return true; @@ -446,26 +446,26 @@ bool MuExistsActive(void) bool IsMuActive(struct MuProc * mu) { - if (mu->config->muIndex && mu->state != MU_STATE_INACTIVE) + if (mu->config->slot && mu->state != MU_STATE_INACTIVE) return true; return false; } -void SetMuMoveScript(struct MuProc * mu, const u8 commands[MU_COMMAND_MAX_COUNT]) +void SetMuMoveScript(struct MuProc * mu, const u8 commands[MOVE_CMD_MAX_COUNT]) { int i; for (i = 0; i < 0x40; ++i) - mu->config->commands[i] = commands[i]; + mu->config->movescr[i] = commands[i]; - mu->config->currentCommand = 0; + mu->config->pc = 0; mu->state = MU_STATE_MOVEMENT; PlayMuStepSe(mu); } -struct MuProc * StartMuScripted(u16 x, u16 y, u16 jid, int pal, const u8 commands[MU_COMMAND_MAX_COUNT]) +struct MuProc * StartMuScripted(u16 x, u16 y, u16 jid, int pal, const u8 commands[MOVE_CMD_MAX_COUNT]) { struct MuProc * proc = StartMuInternal(x, y, jid, -1, pal); if (!proc) @@ -495,7 +495,7 @@ void MuStepSe_PlaySeB(struct MuStepSoundProc * proc) PlaySeSpacial(proc->song2, proc->x2); } -void MU_StartStepSfx(int soundId, int b, int hPosition) +void StartPlayMuStepSe(int song, int alt_offset, int x) { struct MuStepSoundProc * proc; @@ -506,96 +506,96 @@ void MU_StartStepSfx(int soundId, int b, int hPosition) if (!proc->song1) { - proc->song1 = soundId; - proc->x1 = hPosition; + proc->song1 = song; + proc->x1 = x; } - else if (!proc->u60_buggedmaybe) // TODO: FIXME: Is this a bug? u60_buggedmaybe is never initialized +#if BUGFIX + else if (!proc->song2) +#else + else if (!proc->unk60) +#endif { - proc->song2 = soundId + b; - proc->x2 = hPosition; + proc->song2 = song + alt_offset; + proc->x2 = x; } } void PlayMuStepSe(struct MuProc * proc) { - MU_AdvanceStepSfx(proc); + UpdateMuStepSounds(proc); } -void MU_8078894(struct MuProc * proc) {} +void EndMuMovement(struct MuProc * proc) {} -void MU_InterpretCommandScript(struct MuProc * proc) +void RunMuMoveScript(struct MuProc * proc) { while (true) { - short command = MU_AdvanceGetCommand(proc); + short command = proc->config->movescr[proc->config->pc++]; switch (command) { - case MU_COMMAND_WAIT: - proc->move_clock_q4 = MU_AdvanceGetCommand(proc); + case MOVE_CMD_SLEEP: + proc->move_clock_q4 = proc->config->movescr[proc->config->pc++]; proc->state = MU_STATE_SLEEPING; - return; - case MU_COMMAND_BUMP: - MU_8078894(proc); - + case MOVE_CMD_BUMP: + EndMuMovement(proc); proc->state = MU_STATE_BUMPING; - - MU_StartFogBumpFx( + StartMuFogBump( (proc->x_q4 >> MU_SUBPIXEL_PRECISION) - gBmSt.camera.x, (proc->y_q4 >> MU_SUBPIXEL_PRECISION) - gBmSt.camera.y ); - return; - case MU_COMMAND_HALT: - MU_80790CC(proc); - + case MOVE_CMD_HALT: + HaltMu(proc); return; - case MU_COMMAND_END: - MU_8078894(proc); + case MOVE_CMD_END: + EndMuMovement(proc); MU_End(proc); - return; - case MU_COMMAND_MOVE_LEFT: - case MU_COMMAND_MOVE_RIGHT: - case MU_COMMAND_MOVE_DOWN: - case MU_COMMAND_MOVE_UP: - command = command - MU_COMMAND_MOVE_BASE; - - if (command != proc->facing) { - GetMuAnimForJid(proc->jid); // TODO: FIXME: is this a bug? - SetMuFacing(proc, command); - + case MOVE_CMD_MOVE_LEFT: + case MOVE_CMD_MOVE_RIGHT: + case MOVE_CMD_MOVE_DOWN: + case MOVE_CMD_MOVE_UP: + command = command - MOVE_CMD_MOVE_BASE; + if (command != proc->facing) + { +#if !BUGFIX + GetMuAnimForJid(proc->jid); +#endif + SetMuFacing(proc, command - MOVE_CMD_MOVE_BASE); proc->state = MU_STATE_MOVEMENT; } - return; - case MU_COMMAND_FACE_LEFT: - case MU_COMMAND_FACE_RIGHT: - case MU_COMMAND_FACE_DOWN: - case MU_COMMAND_FACE_UP: - command = command - MU_COMMAND_FACE_BASE; - - if (command != proc->facing) { - GetMuAnimForJid(proc->jid); // TODO: FIXME: is this a bug? + case MOVE_CMD_FACE_LEFT: + case MOVE_CMD_FACE_RIGHT: + case MOVE_CMD_FACE_DOWN: + case MOVE_CMD_FACE_UP: + command = command - MOVE_CMD_FACE_BASE; + if (command != proc->facing) + { +#if !BUGFIX + GetMuAnimForJid(proc->jid); +#endif SetMuFacing(proc, command); } break; - case MU_COMMAND_SET_SPEED: - proc->moveConfig = MU_AdvanceGetCommand(proc); + case MOVE_CMD_SET_SPEED: + proc->moveConfig = proc->config->movescr[proc->config->pc++]; break; - case MU_COMMAND_CAMERA_ON: + case MOVE_CMD_CAMERA_ON: EnableMuCamera(proc); break; - case MU_COMMAND_CAMERA_OFF: + case MOVE_CMD_CAMERA_OFF: DisableMuCamera(proc); break; @@ -603,45 +603,32 @@ void MU_InterpretCommandScript(struct MuProc * proc) } // while (true) } -void MU_StartFogBumpFx(int x, int y) +void StartMuFogBump(int x, int y) { struct APHandle * ap; struct MuFogBumpProc * proc; Decompress( Img_GmapSoguSprites, - OBJ_VRAM0 + 0x20 * 0x180 + OBJ_VRAM0 + CHR_SIZE * OBCHR_MU_180 ); ap = AP_Create(ApHandle_GmapSoguSprites, 2); - - ap->tileBase = 0x1180; + ap->tileBase = OAM2_CHR(OBCHR_MU_180) + OAM2_PAL(OBPAL_MU_1); AP_SwitchAnimation(ap, MU_FACING_LEFT); proc = Proc_Start(ProcScr_MuFogBump, PROC_TREE_3); - proc->sprite_anim = ap; - - proc->xDisplay = x + 8; - proc->yDisplay = y - 4; + proc->x = x + 8; + proc->y = y - 4; } void MuFogBump_Init(struct MuFogBumpProc * proc) { - PlaySoundEffect(0x77); + PlaySoundEffect(SONG_77); proc->timer = 0; - - // TODO: maybe a macro that takes angle/xScale/yScale? - - SetObjAffine( - 0, // oam rotscale index - - Div(+COS(0) * 16, 0x200), // pa - Div(-SIN(0) * 16, 0x200), // pb - Div(+SIN(0) * 16, 0x200), // pc - Div(+COS(0) * 16, 0x200) // pd - ); + SetObjAffineAuto(0, 0, 0x200, 0x200); } void MuFogBump_ScaleLoop(struct MuFogBumpProc * proc) @@ -651,23 +638,13 @@ void MuFogBump_ScaleLoop(struct MuFogBumpProc * proc) if (proc->timer++ >= 8) Proc_Break(proc); - scale = Interpolate(5, 0x200, 0x100, proc->timer, 8); - - SetObjAffine( - 0, // oam rotscale index - - Div(+COS(0) * 16, scale), // pa - Div(-SIN(0) * 16, scale), // pb - Div(+SIN(0) * 16, scale), // pc - Div(+COS(0) * 16, scale) // pd - ); + scale = Interpolate(INTERPOLATE_RCUBIC, 0x200, 0x100, proc->timer, 8); + SetObjAffineAuto(0, 0, scale, scale); AP_Update( proc->sprite_anim, - - (proc->xDisplay - 8), - (proc->yDisplay - 8) | 0x300 - ); + (proc->x - 8), + (proc->y - 8) | OAM0_AFFINE_ENABLE | OAM0_DOUBLESIZE); } void MuFogBump_EndLoop(struct MuFogBumpProc * proc) @@ -677,15 +654,13 @@ void MuFogBump_EndLoop(struct MuFogBumpProc * proc) AP_Update( proc->sprite_anim, - - (proc->xDisplay), - (proc->yDisplay) | 0x100 - ); + (proc->x), + (proc->y) | OAM0_AFFINE_ENABLE); } u8 MU_IsFogBumpFxActive(void) { - return Proc_Find(ProcScr_MuFogBump) ? true : false; + return Proc_Exists(ProcScr_MuFogBump); } void Mu_OnStateBump(struct MuProc * proc) @@ -694,7 +669,7 @@ void Mu_OnStateBump(struct MuProc * proc) proc->state = MU_STATE_SLEEPING; } -void Mu_OnStateMoving(struct MuProc * proc) +void Mu_OnStateUnk4(struct MuProc * proc) { proc->state = MU_STATE_MOVEMENT; } @@ -713,7 +688,7 @@ void Mu_OnStateDoNothing(struct MuProc * proc) {} void Mu_OnStateMovement(struct MuProc * proc) { - unsigned moveSpeed = MU_GetMovementSpeed(proc); + unsigned moveSpeed = GetMuQ4MovementSpeed(proc); proc->move_clock_q4 = moveSpeed + proc->move_clock_q4; @@ -739,15 +714,15 @@ void Mu_OnStateMovement(struct MuProc * proc) gBmSt.camera.y = GetCameraAdjustedY(proc->y_q4 >> MU_SUBPIXEL_PRECISION); } - if (!(proc->moveConfig & 0x80)) - MU_AdvanceStepSfx(proc); + if (!(proc->moveConfig & MU_CONFIG_SPPED_NORMAL)) + UpdateMuStepSounds(proc); } -void MU_AdvanceStepSfx(struct MuProc * proc) +void UpdateMuStepSounds(struct MuProc * proc) { - const u16 * pStepSoundDefinition; + const u16 * scr; - unsigned cursor; + int pc; struct Vec2 position; if (GetClassData(proc->jid)->attributes & CA_MOUNTEDAID) @@ -759,67 +734,66 @@ void MU_AdvanceStepSfx(struct MuProc * proc) case CLASS_WYVERN_LORD_F: case CLASS_WYVERN_KNIGHT: case CLASS_WYVERN_KNIGHT_F: - pStepSoundDefinition = MuSoundScr_Wyvern; + scr = MuSoundScr_Wyvern; break; case CLASS_MOGALL: case CLASS_ARCH_MOGALL: - pStepSoundDefinition = MuSoundScr_Mogall; + scr = MuSoundScr_Mogall; break; case CLASS_PEGASUS_KNIGHT: case CLASS_FALCON_KNIGHT: - pStepSoundDefinition = MuSoundScr_Pegasus; + scr = MuSoundScr_Pegasus; break; default: // Any other mounted class - pStepSoundDefinition = MuSoundScr_Mounted; + scr = MuSoundScr_Mounted; break; - - } // proc->jid + } } else { switch (proc->jid) { case CLASS_REVENANT: case CLASS_ENTOUMBED: - pStepSoundDefinition = MuSoundScr_Zombie; + scr = MuSoundScr_Zombie; break; case CLASS_BONEWALKER: case CLASS_BONEWALKER_BOW: case CLASS_WIGHT: case CLASS_WIGHT_BOW: - pStepSoundDefinition = MuSoundScr_Skeleton; + scr = MuSoundScr_Skeleton; break; case CLASS_BAEL: case CLASS_ELDER_BAEL: - pStepSoundDefinition = MuSoundScr_Spider; + scr = MuSoundScr_Spider; break; case CLASS_MAUTHEDOOG: case CLASS_GWYLLGI: - pStepSoundDefinition = MuSoundScr_Dog; + scr = MuSoundScr_Dog; break; case CLASS_TARVOS: case CLASS_MAELDUIN: - pStepSoundDefinition = MuSoundScr_Mounted; + scr = MuSoundScr_Mounted; break; case CLASS_MOGALL: case CLASS_ARCH_MOGALL: - pStepSoundDefinition = MuSoundScr_Mogall; + scr = MuSoundScr_Mogall; break; case CLASS_GORGON: - pStepSoundDefinition = MuSoundScr_Gorgon; + scr = MuSoundScr_Gorgon; break; case CLASS_GARGOYLE: case CLASS_DEATHGOYLE: - pStepSoundDefinition = MuSoundScr_Wyvern; + scr = MuSoundScr_Wyvern; break; case CLASS_ARMOR_KNIGHT: @@ -833,15 +807,15 @@ void MU_AdvanceStepSfx(struct MuProc * proc) case CLASS_BLST_REGULAR_USED: case CLASS_BLST_LONG_USED: case CLASS_BLST_KILLER_USED: - pStepSoundDefinition = MuSoundScr_FootHeavy; + scr = MuSoundScr_FootHeavy; break; case CLASS_FLEET: - pStepSoundDefinition = MuSoundScr_Boat; + scr = MuSoundScr_Boat; break; case CLASS_MANAKETE_MYRRH: - pStepSoundDefinition = MuSoundScr_Myrrh; + scr = MuSoundScr_Myrrh; break; case CLASS_FALLEN_PRINCE: @@ -849,22 +823,18 @@ void MU_AdvanceStepSfx(struct MuProc * proc) return; // no sounds default: // Any other non-mounted class - pStepSoundDefinition = MuSoundScr_Foot; + scr = MuSoundScr_Foot; break; } // switch (proc->jid) } - cursor = DivRem(proc->step_sound_clock++, pStepSoundDefinition[0]); - MU_ComputeDisplayPosition(proc, &position); + pc = DivRem(proc->step_sound_clock++, scr[0]); + GetMuDisplayPosition(proc, &position); - if (pStepSoundDefinition[2 + cursor]) + if (scr[2 + pc]) { - MU_StartStepSfx( - pStepSoundDefinition[2 + cursor], // sound id - pStepSoundDefinition[1], // something - position.x // horizontal position - ); + StartPlayMuStepSe(scr[2 + pc], scr[1], position.x); } } @@ -873,21 +843,21 @@ void MU_OnLoop(struct MuProc * proc) if (proc->state) { if (proc->move_clock_q4 == 0) - if ((u8)(proc->state - MU_STATE_MOVEMENT) <= (MU_STATE_SLEEPING - MU_STATE_MOVEMENT)) - MU_InterpretCommandScript(proc); + if (proc->state == MU_STATE_SLEEPING || proc->state == MU_STATE_MOVEMENT) + RunMuMoveScript(proc); sMuStateFuncs[proc->state](proc); } if (proc->facing == MU_FACING_STANDING) - MU_DisplayAsSMS(proc); + PutMuSMS(proc); else - MU_DisplayAsMMS(proc); + PutMu(proc); } void MU_OnEnd(struct MuProc * proc) { - proc->config->muIndex = 0; + proc->config->slot = 0; AP_Delete(proc->sprite_anim); } @@ -906,78 +876,76 @@ void MU_EndInternal(struct MuProc * proc) Proc_End(proc); } -void MU_80790CC(struct MuProc * proc) +void HaltMu(struct MuProc * proc) { - MU_8078894(proc); + EndMuMovement(proc); proc->state = MU_STATE_INACTIVE; } void MU_AllDisable(void) { - Proc_BlockEachMarked(4); + Proc_BlockEachMarked(PROC_MARK_MU); } void MU_AllEnable(void) { - Proc_UnblockEachMarked(4); + Proc_UnblockEachMarked(PROC_MARK_MU); } -void MU_GetComputedEndPosition(int * xOut, int * yOut, const u8 * commands) +void ApplyMoveScriptToCoordinates(int * x, int * y, u8 const * movescr) { - while (true) + while (TRUE) { - switch (*commands++) { - case MU_COMMAND_END: + switch (*movescr++) { + case MOVE_CMD_END: + case MOVE_CMD_HALT: return; - case MU_COMMAND_MOVE_LEFT: - (*xOut)--; + case MOVE_CMD_MOVE_LEFT: + (*x)--; break; - case MU_COMMAND_MOVE_RIGHT: - (*xOut)++; + case MOVE_CMD_MOVE_RIGHT: + (*x)++; break; - case MU_COMMAND_MOVE_UP: - (*yOut)--; + case MOVE_CMD_MOVE_UP: + (*y)--; break; - case MU_COMMAND_MOVE_DOWN: - (*yOut)++; + case MOVE_CMD_MOVE_DOWN: + (*y)++; break; - case MU_COMMAND_HALT: - return; + case MOVE_CMD_SLEEP: + movescr++; + break; - case MU_COMMAND_WAIT: - commands++; + default: break; } } } -s8 MU_CanStart(void) +bool CanStartMu(void) { int i; - for (i = 0; i < MU_MAX_COUNT; ++i) - if (sMuConfig[i].muIndex == 0) + if (sMuConfig[i].slot == 0) return true; return false; } -void MU_AllRestartAnimations(void) +void ResetMuAnims(void) { int i; - for (i = 0; i < MU_MAX_COUNT; ++i) { - if (sMuConfig[i].muIndex) + if (sMuConfig[i].slot != 0) { - sMuConfig[i].mu->sprite_anim->frameTimer = 0; - sMuConfig[i].mu->sprite_anim->frameInterval = 0x100; + ResetSpriteAnimClock(sMuConfig[i].mu->sprite_anim); } } } @@ -985,44 +953,38 @@ void MU_AllRestartAnimations(void) struct MuConfig * GetDefaultMuConfig(int objTileId, u8 * outIndex) { int i; - for (i = 0; i < MU_MAX_COUNT; ++i) { - if (sMuConfig[i].muIndex) + if (sMuConfig[i].slot) continue; - sMuConfig[i].muIndex = i + 1; + sMuConfig[i].slot = i + 1; sMuConfig[i].chr = sMuChrOffLut_Default[i] + objTileId; *outIndex = i; - return sMuConfig + i; } - return NULL; } struct MuConfig * GetNewMuConfig(int objTileId, u8 * outIndex) { int i; - for (i = 0; i < MU_MAX_COUNT; ++i) { - if (sMuConfig[i].muIndex) + if (sMuConfig[i].slot) continue; - sMuConfig[i].muIndex = i + 1; + sMuConfig[i].slot = i + 1; sMuConfig[i].chr = sMuChrOffLut[i] + objTileId; *outIndex = i; - return sMuConfig + i; } - return NULL; } -u8 MU_ComputeDisplayPosition(struct MuProc * proc, struct Vec2 * out) +u8 GetMuDisplayPosition(struct MuProc * proc, struct Vec2 * out) { if (proc->state == MU_STATE_DISPLAY_UI) { @@ -1037,86 +999,74 @@ u8 MU_ComputeDisplayPosition(struct MuProc * proc, struct Vec2 * out) out->x = x; out->y = y + 8; - if ((u16)(x + 16) > 0x110) - return false; - - if (y < -0x10) - return false; - - if (y > 0xB0) + if (x < -0x10 || x > 0x100 || y < -0x10 || y > 0xB0) return false; } - return true; } -void MU_DisplayAsSMS(struct MuProc * proc) +void PutMuSMS(struct MuProc * proc) { if (!proc->hidden_b) { - struct Vec2 position; + struct Vec2 pos; - if (!MU_ComputeDisplayPosition(proc, &position)) + if (!GetMuDisplayPosition(proc, &pos)) return; - position.x &= 0x01FF; - position.y &= 0x00FF; + pos.x = OAM1_X(pos.x); + pos.y = OAM0_Y(pos.y); if (proc->state == MU_STATE_DEATHFADE) - position.y |= 0x400; + pos.y |= OAM0_BLEND; sub_8026FF4( - proc->muIndex, + proc->slot, proc->pGfxVRAM ); sub_8027DB4( proc->sprite_anim->objLayer, - position.x - 8, - position.y - 16, + pos.x - 8, + pos.y - 16, ((((unsigned)(proc->pGfxVRAM - OBJ_VRAM0) & 0x1FFFF) >> 5) | ((proc->config->pal & 0xF) << 12)) + proc->layer, proc->jid, - proc->muIndex + proc->slot ); } } -void MU_DisplayAsMMS(struct MuProc * proc) +void PutMu(struct MuProc * proc) { if (!proc->hidden_b) { - struct Vec2 position; + struct Vec2 pos; - if (!MU_ComputeDisplayPosition(proc, &position)) + if (!GetMuDisplayPosition(proc, &pos)) return; - position.x &= 0x01FF; - position.y &= 0x00FF; + pos.x = OAM1_X(pos.x); + pos.y = OAM0_Y(pos.y); if (proc->state != MU_STATE_DISPLAY_UI) if (proc->unit && UNIT_FACTION(proc->unit) == FACTION_RED) if (gPlaySt.chapterVisionRange != 0) - if (!gBmMapFog[MU_GetDisplayYOrg(proc) >> 4][MU_GetDisplayXOrg(proc) >> 4]) + if (gBmMapFog[MU_GetDisplayYOrg(proc) >> 4][MU_GetDisplayXOrg(proc) >> 4] == 0) return; // whew if (proc->state == MU_STATE_DEATHFADE) - position.y |= 0x400; - - AP_Update( - proc->sprite_anim, + pos.y |= OAM0_BLEND; - position.x, - position.y - ); + AP_Update(proc->sprite_anim, pos.x, pos.y); } } -u16 MU_GetMovementSpeed(struct MuProc * proc) +u16 GetMuQ4MovementSpeed(struct MuProc * proc) { int config = proc->moveConfig; @@ -1153,7 +1103,7 @@ u16 MU_GetMovementSpeed(struct MuProc * proc) return 16 * sMuWalkSpeedLut[GetClassData(proc->jid)->slowWalking]; } -void MU_SetMoveConfig(struct MuProc * proc, u16 config) +void SetMuConfig(struct MuProc * proc, u16 config) { if (config > 0x100) proc->moveConfig = 0x100; @@ -1161,9 +1111,9 @@ void MU_SetMoveConfig(struct MuProc * proc, u16 config) proc->moveConfig = config; } -void* GetMuImgBufById(int muIndex) +void* GetMuImgBufById(int slot) { - return gMUGfxBuffer + (sMuImgBufOffLut[muIndex] * MU_GFX_MAX_SIZE); + return gMUGfxBuffer + (sMuImgBufOffLut[slot] * MU_GFX_MAX_SIZE); } const void * GetMuImg(struct MuProc * proc) @@ -1171,46 +1121,34 @@ const void * GetMuImg(struct MuProc * proc) return gMuInfoTable[proc->jid - 1].img; } -const void * GetMuAnimForJid(u16 classId) +const void * GetMuAnimForJid(u16 jid) { - return gMuInfoTable[classId - 1].anim; + return gMuInfoTable[jid - 1].anim; } -void MU_StartDeathFade(struct MuProc * muProc) +void MU_StartDeathFade(struct MuProc * mu) { struct MuEffectProc * proc; - - muProc->state = MU_STATE_DEATHFADE; - - proc = Proc_Start(ProcScr_MuDeathFade, muProc); - - proc->mu = muProc; + mu->state = MU_STATE_DEATHFADE; + proc = Proc_Start(ProcScr_MuDeathFade, mu); + proc->mu = mu; proc->timeLeft = 0x20; - SetBlendConfig(0, 0x10, 0x10, 0); + FreezeSpriteAnim(mu->sprite_anim); + MU_StartHitFlash(mu, MU_FLASH_WHITE); + mu->sprite_anim->objLayer = 13; + PlaySoundEffect(SONG_D6); - muProc->sprite_anim->frameTimer = 0; - muProc->sprite_anim->frameInterval = 0; - - MU_StartHitFlash(muProc, 0); - - muProc->sprite_anim->objLayer = 0xD; - - PlaySoundEffect(0xD6); // TODO: SOUND DEFINITIONS - - if (muProc->unit->state & US_IN_BALLISTA) + if (mu->unit->state & US_IN_BALLISTA) { - TryRemoveUnitFromBallista(muProc->unit); - HideUnitSprite(muProc->unit); + TryRemoveUnitFromBallista(mu->unit); + HideUnitSprite(mu->unit); } } void MuDeathFade_OnLoop(struct MuEffectProc * proc) { - short time = (proc->timeLeft--) >> 1; - - SetBlendConfig(0, (u8) time, 0x10, 0); - + SetBlendConfig(0, (proc->timeLeft--) >> 1, 0x10, 0); if (proc->timeLeft == 0) { MU_End(proc->mu); @@ -1218,36 +1156,36 @@ void MuDeathFade_OnLoop(struct MuEffectProc * proc) } } -void MUBlinkEffect_OnLoop(struct MuEffectProc * proc) +void MuBlink_OnLoop(struct MuEffectProc * proc) { - struct MuProc * muProc = (struct MuProc *) proc->proc_parent; + struct MuProc * mu = (struct MuProc *) proc->proc_parent; int boolHidden = false; if ((proc->timeLeft & 0x7) < 4) boolHidden = true; - muProc->hidden_b = boolHidden; + mu->hidden_b = boolHidden; if (--proc->timeLeft < 0) { Proc_Break(proc); - muProc->hidden_b = true; + mu->hidden_b = true; } } -void MU_StartBlinkEffect(struct MuProc * muProc) +void StartBlinkMu(struct MuProc * mu) { struct MuEffectProc * proc; - muProc->state = MU_STATE_DEATHFADE; + mu->state = MU_STATE_DEATHFADE; - proc = Proc_Start(ProcScr_MuBlinkEffect, muProc); + proc = Proc_Start(ProcScr_MuBlink, mu); - proc->mu = muProc; + proc->mu = mu; proc->timeLeft = 0x40; - muProc->sprite_anim->frameTimer = 0; - muProc->sprite_anim->frameInterval = 0; + mu->sprite_anim->frameTimer = 0; + mu->sprite_anim->frameInterval = 0; PlaySoundEffect(0xD6); // TODO: SOUND DEFINITIONS } @@ -1280,7 +1218,7 @@ void MU_SetupPixelEffect(u32* data, int frame) void MuPixelEffect_OnLoop(struct MuEffectProc * proc) { MU_SetupPixelEffect( - GetMuImgBufById(((struct MuProc *)(proc->proc_parent))->muIndex), + GetMuImgBufById(((struct MuProc *)(proc->proc_parent))->slot), proc->frameIndex ); @@ -1289,7 +1227,7 @@ void MuPixelEffect_OnLoop(struct MuEffectProc * proc) // TODO: FIXME: This may be bugged? RegisterDataMove( gMUGfxBuffer, - OBJ_VRAM0 + (MU_BASE_OBJ_TILE * 0x20), + OBJ_VRAM0 + (OBCHR_MU_380 * CHR_SIZE), (0x80 * 0x20) ); @@ -1300,149 +1238,125 @@ void MuPixelEffect_OnLoop(struct MuEffectProc * proc) } } -void MU_StartPixelEffect(struct MuProc * muProc) +void MU_StartPixelEffect(struct MuProc * mu) { struct MuEffectProc * proc; - muProc->state = MU_STATE_DEATHFADE; + mu->state = MU_STATE_DEATHFADE; - proc = Proc_Start(ProcScr_MuPixelEffect, muProc); + proc = Proc_Start(ProcScr_MuPixelEffect, mu); - proc->mu = muProc; + proc->mu = mu; proc->timeLeft = 0x40; proc->frameIndex = 0; - muProc->sprite_anim->frameTimer = 0; - muProc->sprite_anim->frameInterval = 0; + mu->sprite_anim->frameTimer = 0; + mu->sprite_anim->frameInterval = 0; PlaySoundEffect(0xD6); // TODO: SOUND DEFINITIONS } -void MU_Hide(struct MuProc * proc) +void HideMu(struct MuProc * proc) { proc->hidden_b = true; } -void MU_Show(struct MuProc * proc) +void ShowMu(struct MuProc * proc) { proc->hidden_b = false; } -void MU_SetDisplayPosition(struct MuProc * proc, int x, int y) +void SetMuScreenPosition(struct MuProc * proc, int x, int y) { proc->x_q4 = x << MU_SUBPIXEL_PRECISION; proc->y_q4 = y << MU_SUBPIXEL_PRECISION; } -void MU_SetDisplayOffset(struct MuProc * proc, int xOff, int yOff) +void SetMuScreenOffset(struct MuProc * proc, int xOff, int yOff) { proc->x_offset_q4 = xOff << MU_SUBPIXEL_PRECISION; proc->y_offset_q4 = yOff << MU_SUBPIXEL_PRECISION; } -void MU_StartFlashFade(struct MuProc * proc, int flashType) +void StartMuFadeIntoFlash(struct MuProc * proc, int flashType) { proc->sprite_anim->tileBase = - proc->config->chr + (MU_FADE_OBJ_PAL << 12) + proc->layer; + proc->config->chr + OAM2_PAL(OBPAL_MU_FADE) + proc->layer; - ApplyPalette(PAL_OBJ(proc->config->pal), 0x10 + MU_FADE_OBJ_PAL); + ApplyPalette(PAL_OBJ(proc->config->pal), 0x10 + OBPAL_MU_FADE); StartPalFade( - MUFlashColorLookup[flashType], - 0x15, 8, (struct Proc*) proc - ); + gMuFlashPalLut[flashType], + 0x15, 8, proc); } -void MU_8079858(struct MuProc * muProc) +void StartMuFadeFromFlash(struct MuProc * mu) { struct MuEffectProc * proc; - StartPalFade( - PAL_OBJ(muProc->config->pal), - 0x15, 8, (struct Proc*) muProc + PAL_OBJ(mu->config->pal), + 0x15, 8, mu ); proc = Proc_Start(ProcScr_MuRestorePalInfo, PROC_TREE_3); - - proc->mu = muProc; + proc->mu = mu; } void MuRestorePalInfo_Apply(struct MuEffectProc * proc) { - struct MuProc * muProc = proc->mu; - - muProc->sprite_anim->tileBase = - ((muProc->config->pal & 0xF) << 12) + muProc->config->chr + muProc->layer; + struct MuProc * mu = proc->mu; + mu->sprite_anim->tileBase = + mu->config->chr + OAM2_PAL(mu->config->pal) + mu->layer; } -void MU_StartActionAnim(struct MuProc * proc) +void StartMuActionAnim(struct MuProc * proc) { AP_SwitchAnimation(proc->sprite_anim, MU_FACING_SELECTED); - - proc->sprite_anim->frameTimer = 0; - proc->sprite_anim->frameInterval = 0x100; - - CallDelayedArg(MU_EndSelectionApAnim, (int) proc->sprite_anim, 30); + ResetSpriteAnimClock(proc->sprite_anim); + CallDelayedArg(MuActionAnimFinishFunc, (int) proc->sprite_anim, 30); } -void MU_EndSelectionApAnim(int argAp) +void MuActionAnimFinishFunc(int arg) { - struct APHandle * ap = (struct APHandle *) argAp; - - ap->frameTimer = 0; - ap->frameInterval = 0; + FreezeSpriteAnim((struct APHandle *) arg); } -void MU_StartDelayedFaceTarget(struct MuProc * proc) +void StartMuDelayedFaceDefender(struct MuProc * proc) { - proc->sprite_anim->frameTimer = 0; - proc->sprite_anim->frameInterval = 0x100; - - CallDelayedArg(MU_EndRefaceApAnim, (int) proc->sprite_anim, 30); + ResetSpriteAnimClock(proc->sprite_anim); + CallDelayedArg(MuDelayedFaceDefenderFunc, (int) proc->sprite_anim, 30); } -void MU_EndRefaceApAnim(int argAp) +void MuDelayedFaceDefenderFunc(int arg) { - struct APHandle * ap = (struct APHandle *) argAp; - - int actor1 = gManimSt.subjectActorId; - int actor2 = 1 - actor1; - SetBattleAnimFacing( - actor1, actor2, - GetSpellAssocFacing(gManimSt.actor[0].bu->weaponBefore) - ); + gManimSt.subjectActorId, + 1 - gManimSt.subjectActorId, + GetSpellAssocFacing(gManimSt.actor[0].bu->weaponBefore)); - ap->frameTimer = 0; - ap->frameInterval = 0; + FreezeSpriteAnim((struct APHandle *) arg); } -void MU_StartFastMoveAnim(struct MuProc * proc) +void StartMuSpeedUpAnim(struct MuProc * proc) { proc->sprite_anim->frameTimer = 0; proc->sprite_anim->frameInterval = 0x40; - CallDelayedArg(MU_EndFasterApAnim, (int) proc->sprite_anim, 20); + CallDelayedArg(MuSlowDownAnimFreezeFunc, (int) proc->sprite_anim, 20); } -void MU_EndFasterApAnim(int argAp) +void MuSlowDownAnimFreezeFunc(int arg) { - struct APHandle * ap = (struct APHandle *) argAp; - - ap->frameTimer = 0; - ap->frameInterval = 0; + FreezeSpriteAnim((struct APHandle *) arg); } -void MU_StartCritFlash(struct MuProc * muProc, int flashType) +void StartMuCritFlash(struct MuProc * mu, int flashType) { struct MuFlashEffectProc * proc; - - ApplyPalette(MUFlashColorLookup[flashType], 0x10 + MU_FADE_OBJ_PAL); - - proc = Proc_Start(ProcScr_MuCritFlash, muProc); - - proc->mu = muProc; + ApplyPalette(gMuFlashPalLut[flashType], 0x10 + OBPAL_MU_FADE); + proc = Proc_Start(ProcScr_MuCritFlash, mu); + proc->mu = mu; } void MuCritFlash_Init(struct MuFlashEffectProc * proc) @@ -1452,25 +1366,25 @@ void MuCritFlash_Init(struct MuFlashEffectProc * proc) void MuCritFlash_SetFadedPalette(struct MuFlashEffectProc * proc) { - struct MuProc * muProc = proc->mu; + struct MuProc * mu = proc->mu; - muProc->sprite_anim->tileBase = - (MU_FADE_OBJ_PAL << 12) + muProc->config->chr + muProc->layer; + mu->sprite_anim->tileBase = + (OBPAL_MU_FADE << 12) + mu->config->chr + mu->layer; } void MuCritFlash_SetRegularPalette(struct MuFlashEffectProc * proc) { - struct MuProc * muProc = proc->mu; + struct MuProc * mu = proc->mu; - muProc->sprite_anim->tileBase = - ((muProc->config->pal & 0xF) << 12) + muProc->config->chr + muProc->layer; + mu->sprite_anim->tileBase = + ((mu->config->pal & 0xF) << 12) + mu->config->chr + mu->layer; } void MuCritFlash_StartFadeBack_maybe(struct MuFlashEffectProc * proc) { StartPalFade( PAL_OBJ(proc->mu->config->pal), - 0x15, 0x14, (struct Proc*) proc + 0x15, 0x14, proc ); } @@ -1478,48 +1392,48 @@ void MuCritFlash_SpriteShakeLoop(struct MuFlashEffectProc * proc) { proc->timer++; - MU_SetDisplayOffset(proc->mu, ((proc->timer & 1) ? 2 : -2), 0); + SetMuScreenOffset(proc->mu, ((proc->timer & 1) ? 2 : -2), 0); if (proc->timer >= 12) { - MU_SetDisplayOffset(proc->mu, 0, 0); + SetMuScreenOffset(proc->mu, 0, 0); Proc_Break(proc); } } void MuCritFlash_RestorePalette(struct MuFlashEffectProc * proc) { - struct MuProc * muProc = proc->mu; + struct MuProc * mu = proc->mu; - muProc->sprite_anim->tileBase = - ((muProc->config->pal & 0xF) << 12) + muProc->config->chr + muProc->layer; + mu->sprite_anim->tileBase = + ((mu->config->pal & 0xF) << 12) + mu->config->chr + mu->layer; } -void MU_StartHitFlash(struct MuProc * muProc, int flashType) +void MU_StartHitFlash(struct MuProc * mu, int flashType) { struct MuFlashEffectProc * proc; - ApplyPalette(MUFlashColorLookup[flashType], 0x10 + MU_FADE_OBJ_PAL); + ApplyPalette(gMuFlashPalLut[flashType], 0x10 + OBPAL_MU_FADE); - muProc->sprite_anim->tileBase = - (MU_FADE_OBJ_PAL << 12) + muProc->config->chr + muProc->layer; + mu->sprite_anim->tileBase = + (OBPAL_MU_FADE << 12) + mu->config->chr + mu->layer; StartPalFade( - PAL_OBJ(muProc->config->pal), - 0x15, 0x14, (struct Proc*) muProc + PAL_OBJ(mu->config->pal), + 0x15, 0x14, mu ); - proc = Proc_Start(ProcScr_MuHitFlash, muProc); + proc = Proc_Start(ProcScr_MuHitFlash, mu); - proc->mu = muProc; + proc->mu = mu; } void MuHitFlash_RestorePalette(struct MuFlashEffectProc * proc) { - struct MuProc * muProc = proc->mu; + struct MuProc * mu = proc->mu; - muProc->sprite_anim->tileBase = - ((muProc->config->pal & 0xF) << 12) + muProc->config->chr + muProc->layer; + mu->sprite_anim->tileBase = + ((mu->config->pal & 0xF) << 12) + mu->config->chr + mu->layer; } void MU_AllForceSetMaxMoveSpeed(void) @@ -1546,7 +1460,7 @@ void MU_SetSpecialSprite(struct MuProc * proc, int jid, const u16 * palette) Decompress( GetMuImg(proc), - GetMuImgBufById(proc->config->muIndex) + GetMuImgBufById(proc->config->slot) ); ApplyPalette(palette, 0x10 + proc->config->pal); @@ -1560,12 +1474,12 @@ void MU_SetPaletteId(struct MuProc * proc, unsigned paletteId) proc->config->chr + ((paletteId % 0x10) << 12) + proc->layer; } -struct MuProc * MU_GetByIndex(int muIndex) +struct MuProc * MU_GetByIndex(int slot) { - if (!sMuConfig[muIndex].muIndex) + if (!sMuConfig[slot].slot) return NULL; - return sMuConfig[muIndex].mu; + return sMuConfig[slot].mu; } struct MuProc * MU_GetByUnit(struct Unit * unit) diff --git a/src/muctrl.c b/src/muctrl.c index 1afceca11..e5000deb8 100644 --- a/src/muctrl.c +++ b/src/muctrl.c @@ -147,7 +147,7 @@ void MuCtr_InitDefinedMove(struct MuCtrlProc * proc, struct Unit * unit, const s gBmMapOther[y][x] = 0; gBmMapOther[pos.y][pos.x] = unit->pCharacterData->number; - MU_Hide(proc->muProc); + HideMu(proc->muProc); } //! FE8U = 0x08079F84 @@ -280,7 +280,7 @@ s8 sub_807A0E4(struct MuCtrlProc * proc) ShowUnitSprite(unit); unit->state &= ~US_HIDDEN; - MU_Hide(proc->muProc); + HideMu(proc->muProc); gBmMapUnit[unit->yPos][unit->xPos] = unit->index; RefreshUnitSprites(); } @@ -454,7 +454,7 @@ void MuCtr_ExecREDA_807A358(struct MuCtrlProc * proc) { struct MuProc * muProc = proc->muProc; - MU_Show(muProc); + ShowMu(muProc); SetMuMoveScript(muProc, commands); config = reda->flags; @@ -464,7 +464,7 @@ void MuCtr_ExecREDA_807A358(struct MuCtrlProc * proc) config |= 0x40; } - MU_SetMoveConfig(muProc, config); + SetMuConfig(muProc, config); if ((flagsB & 4) != 0) { diff --git a/src/sio_battlemap.c b/src/sio_battlemap.c index a7a88026e..a102263a9 100644 --- a/src/sio_battlemap.c +++ b/src/sio_battlemap.c @@ -196,17 +196,17 @@ void sub_80493D0(u8 a, int b, u8 * c, int * xOut, int * yOut) u8 gUnknown_080D9FA0[8] = { - MU_COMMAND_MOVE_UP, - MU_COMMAND_HALT, + MOVE_CMD_MOVE_UP, + MOVE_CMD_HALT, - MU_COMMAND_MOVE_LEFT, - MU_COMMAND_HALT, + MOVE_CMD_MOVE_LEFT, + MOVE_CMD_HALT, - MU_COMMAND_MOVE_DOWN, - MU_COMMAND_HALT, + MOVE_CMD_MOVE_DOWN, + MOVE_CMD_HALT, - MU_COMMAND_MOVE_RIGHT, - MU_COMMAND_HALT, + MOVE_CMD_MOVE_RIGHT, + MOVE_CMD_HALT, }; s8 gUnknown_080D9FA8[8] = @@ -563,7 +563,7 @@ void sub_80498F4(void) gUnknown_03001838[0] = StartMu(unit); - MU_SetDisplayPosition(gUnknown_03001838[0], unit->xPos * 16, (unit->yPos - 1) * 16); + SetMuScreenPosition(gUnknown_03001838[0], unit->xPos * 16, (unit->yPos - 1) * 16); DisableMuCamera(gUnknown_03001838[0]); SetMuFacing(gUnknown_03001838[0], 3); @@ -937,8 +937,8 @@ void sub_8049D24(struct SioBattleMapProc * proc) u8 gUnknown_080D9FB5[2] = { - MU_COMMAND_MOVE_UP, - MU_COMMAND_HALT, + MOVE_CMD_MOVE_UP, + MOVE_CMD_HALT, }; // clang-format on @@ -1386,8 +1386,8 @@ void sub_804A5A4(void) u8 gUnknown_080D9FB7[2] = { - MU_COMMAND_MOVE_RIGHT, - MU_COMMAND_HALT, + MOVE_CMD_MOVE_RIGHT, + MOVE_CMD_HALT, }; // clang-format on @@ -2575,8 +2575,8 @@ void sub_804B624(struct SioBattleMapProc * proc) mu = StartMu(unit); - gWorkingMovementScript[0] = MU_COMMAND_MOVE_DOWN; - gWorkingMovementScript[1] = MU_COMMAND_HALT; + gWorkingMovementScript[0] = MOVE_CMD_MOVE_DOWN; + gWorkingMovementScript[1] = MOVE_CMD_HALT; SetMuMoveScript(mu, gWorkingMovementScript); @@ -2768,7 +2768,7 @@ void sub_804B850(struct SioBattleMapProc * proc) gWorkingMovementScript[0] = GetFacingDirection( gBattleActor.unit.xPos, gBattleActor.unit.yPos, gBattleTarget.unit.xPos, gBattleTarget.unit.yPos); - gWorkingMovementScript[1] = MU_COMMAND_HALT; + gWorkingMovementScript[1] = MOVE_CMD_HALT; SetMuMoveScript(mu, gWorkingMovementScript); StartLinkArenaMUDeathFade(mu); diff --git a/src/sio_mu.c b/src/sio_mu.c index d057321b0..65582e3d9 100644 --- a/src/sio_mu.c +++ b/src/sio_mu.c @@ -149,7 +149,7 @@ void SioWarp_Init(struct SioWarpProc * proc) if (proc->playStepSe) { - MU_StartStepSfx(0x7f, 2, proc->x * 8); + StartPlayMuStepSe(0x7f, 2, proc->x * 8); } return; @@ -250,14 +250,14 @@ void SioWarpFx_804C178(struct SioWarpProc * proc) //! FE8U = 0x0804C188 void SioWarpFx_HideMoveUnit(struct SioWarpProc * proc) { - MU_Hide(proc->muProc); + HideMu(proc->muProc); return; } //! FE8U = 0x0804C194 void SioWarpFx_SetMUPosition(struct SioWarpProc * proc) { - MU_SetDisplayPosition(proc->muProc, proc->x * 16, proc->y * 16); + SetMuScreenPosition(proc->muProc, proc->x * 16, proc->y * 16); proc->unit->xPos = proc->x; proc->unit->yPos = proc->y; @@ -273,7 +273,7 @@ void SioWarpFx_ShowMoveUnit(struct SioWarpProc * proc) SetMuFacing(proc->muProc, proc->facing); } - MU_Show(proc->muProc); + ShowMu(proc->muProc); return; } diff --git a/src/statscreen.c b/src/statscreen.c index 4ee110101..50dc0dc79 100644 --- a/src/statscreen.c +++ b/src/statscreen.c @@ -1138,7 +1138,7 @@ void UnitSlide_FadeOutLoop(struct StatScreenEffectProc* proc) { SetBlendConfig(1, proc->timer, 0x10 - proc->timer, 0); - MU_SetDisplayPosition(gStatScreen.mu, + SetMuScreenPosition(gStatScreen.mu, 80, 138 + gStatScreen.yDispOff); gStatScreen.yDispOff = Interpolate(2, proc->yDispInit, proc->yDispFinal, proc->timer, 0x10); @@ -1177,7 +1177,7 @@ void UnitSlide_FadeInLoop(struct StatScreenEffectProc* proc) { SetBlendConfig(1, 0x10 - proc->timer, proc->timer, 0); - MU_SetDisplayPosition(gStatScreen.mu, + SetMuScreenPosition(gStatScreen.mu, 80, 138 + gStatScreen.yDispOff); gStatScreen.yDispOff = Interpolate(5, proc->yDispInit, proc->yDispFinal, proc->timer, 0x10); @@ -1199,7 +1199,7 @@ void UnitSlide_SetNewUnit(struct StatScreenEffectProc* proc) void ClearSlide(struct Proc* proc) { if (gStatScreen.mu) - MU_SetDisplayPosition(gStatScreen.mu, + SetMuScreenPosition(gStatScreen.mu, 80, 138); gLCDControlBuffer.bg0cnt.priority = 1; diff --git a/src/uiarena.c b/src/uiarena.c index 4ac74aba3..aec5264bc 100644 --- a/src/uiarena.c +++ b/src/uiarena.c @@ -52,7 +52,7 @@ void StartArenaResultsScreen(void) { //! FE8U = 0x080B57A0 void ArenaUi_Init(ProcPtr proc) { - Proc_ForEach(ProcScr_Mu, (ProcFunc) MU_Hide); + Proc_ForEach(ProcScr_Mu, (ProcFunc) HideMu); InitShopScreenConfig(); @@ -296,7 +296,7 @@ void ArenaUi_ShowGoldBoxOnVictoryOrDraw(ProcPtr proc) { //! FE8U = 0x080B5BE4 void ArenaUi_OnEnd(void) { Proc_EndEach(gProcScr_GoldBox); - Proc_ForEach(ProcScr_Mu, (ProcFunc) MU_Show); + Proc_ForEach(ProcScr_Mu, (ProcFunc) ShowMu); return; } diff --git a/src/unit_facing.c b/src/unit_facing.c index 54786efef..0c71b0f27 100644 --- a/src/unit_facing.c +++ b/src/unit_facing.c @@ -5,8 +5,8 @@ void ChangeActiveUnitFacing(int xLook, int yLook) { int direction = GetFacingDirection(gActiveUnit->xPos, gActiveUnit->yPos, xLook, yLook) - + MU_COMMAND_FACE_BASE; + + MOVE_CMD_FACE_BASE; gWorkingMovementScript[0] = direction; - gWorkingMovementScript[1] = MU_COMMAND_HALT; + gWorkingMovementScript[1] = MOVE_CMD_HALT; SetAutoMuMoveScript(gWorkingMovementScript); } diff --git a/src/worldmap_draw.c b/src/worldmap_draw.c index 96592f5ae..1e83f15d6 100644 --- a/src/worldmap_draw.c +++ b/src/worldmap_draw.c @@ -23,13 +23,13 @@ void RemoveGmUnit(int index) //! FE8U = 0x080BF554 void ShowGmUnit(int index) { - GmMu_ShowUnit(GM_MU, index); + GmShowMuUnit(GM_MU, index); } //! FE8U = 0x080BF570 void HideGmUnit(int index) { - GmMu_HideUnit(GM_MU, index); + GmHideMuUnit(GM_MU, index); } //! FE8U = 0x080BF58C diff --git a/src/worldmap_main.c b/src/worldmap_main.c index 6566ebb0a..418a672e9 100644 --- a/src/worldmap_main.c +++ b/src/worldmap_main.c @@ -470,7 +470,7 @@ void sub_80B9028(struct WorldMapMainProc * proc) GmMu_SetPosition(proc->unk_54, i, *a, *b); - GmMu_ShowUnit(proc->unk_54, i); + GmShowMuUnit(proc->unk_54, i); } return; diff --git a/src/worldmap_mapmu.c b/src/worldmap_mapmu.c index a9af03141..1c4d5e6ce 100644 --- a/src/worldmap_mapmu.c +++ b/src/worldmap_mapmu.c @@ -638,7 +638,7 @@ void sub_80BDD94(struct GMapMuProc * muProc, int index) } //! FE8U = 0x080BDDC4 -void GmMu_ShowUnit(struct GMapMuProc * muProc, int index) +void GmShowMuUnit(struct GMapMuProc * muProc, int index) { struct GMapMuPrimProc * muPrimProc; int i; @@ -667,7 +667,7 @@ void GmMu_ShowUnit(struct GMapMuProc * muProc, int index) } //! FE8U = 0x080BDE3C -void GmMu_HideUnit(struct GMapMuProc * muProc, int index) +void GmHideMuUnit(struct GMapMuProc * muProc, int index) { struct GMapMuPrimProc * muPrimProc; int i; @@ -1073,7 +1073,7 @@ void sub_80BE45C(struct GMapMuPrimProc * proc) if (sfxLut[divRem + 2] != 0) { - MU_StartStepSfx(sfxLut[divRem + 2], sfxLut[1], (s16)hPos); + StartPlayMuStepSe(sfxLut[divRem + 2], sfxLut[1], (s16)hPos); } return; diff --git a/src/worldmap_rm.c b/src/worldmap_rm.c index 1c2d40366..0f21a728b 100644 --- a/src/worldmap_rm.c +++ b/src/worldmap_rm.c @@ -252,13 +252,13 @@ void GmapRm_RemoveUnits(struct ProcGmapRm * proc) else proc->flag &= ~GMAPRM_FLAG_3; - GmMu_HideUnit(GM_MU, WM_MU_0); + GmHideMuUnit(GM_MU, WM_MU_0); } void GmapRm_DisplayLeaderUnit(struct ProcGmapRm * proc) { if (proc->flag & GMAPRM_FLAG_3) - GmMu_ShowUnit(GM_MU, WM_MU_0); + GmShowMuUnit(GM_MU, WM_MU_0); } void GmapRm_80C2320(struct ProcGmapRm * proc) diff --git a/src/worldmap_timemons.c b/src/worldmap_timemons.c index d431efdd3..9f6a3a674 100644 --- a/src/worldmap_timemons.c +++ b/src/worldmap_timemons.c @@ -285,7 +285,7 @@ void GmapTimeMons_ExecMonsterMergeMu(struct ProcGmapTimeMons * proc) wm_uid = i + 4; SetGmClassUnit(wm_uid, proc->confs[i].jid, WM_FACTION_RED, proc->confs[i].node); gGMData.units[wm_uid].state |= GM_UNIT_STATE_B0; - GmMu_ShowUnit(GM_MU, wm_uid); + GmShowMuUnit(GM_MU, wm_uid); } Proc_Break(proc); } @@ -375,7 +375,7 @@ void WmShowMonsters(void) *&y = gWMNodeData[gGMData.units[i].location].y; GmMu_SetPosition(GM_MU, i, x, y); - GmMu_ShowUnit(GM_MU, i); + GmShowMuUnit(GM_MU, i); } } From 8d0d030f6fdfe058851e15ce835e3b401cb40a65 Mon Sep 17 00:00:00 2001 From: MokhaLeee Date: Thu, 11 Jul 2024 10:41:18 +0000 Subject: [PATCH 4/7] in process --- include/bmmap.h | 3 + include/bmudisp.h | 4 +- include/mu.h | 20 ++--- include/muctrl.h | 9 +-- src/banim-ekrbattleending.c | 2 +- src/bmidoten.c | 10 +-- src/bmio.c | 10 +-- src/bmitemuse.c | 4 +- src/bmmap.c | 4 +- src/bmtarget.c | 12 +-- src/bmtrap.c | 4 +- src/bmudisp.c | 108 +++++++++++---------------- src/bmusemind.c | 2 +- src/bonusclaim.c | 2 +- src/chapterintrofx.c | 2 +- src/chapterintrofx_title.c | 2 +- src/classchg-main.c | 2 +- src/cp_0803E2F4.c | 24 +++--- src/cp_battle.c | 14 ++-- src/cp_script.c | 6 +- src/cp_staff.c | 6 +- src/cp_utility.c | 22 +++--- src/cpextra_80407F0.c | 10 +-- src/eventscr.c | 2 +- src/eventscr_utils.c | 2 +- src/fogmap.c | 6 +- src/mapanim.c | 4 +- src/mapanim_api.c | 2 +- src/mapanim_spellassoc.c | 2 +- src/mu.c | 53 +++++++------- src/muctrl.c | 141 ++++++++++++++---------------------- src/prep_itemscreen.c | 2 +- src/prep_itemuse.c | 2 +- src/prep_sallycursor.c | 2 +- src/prep_unitselect.c | 2 +- src/sio_battlemap.c | 4 +- src/sio_teamlist.c | 2 +- src/sio_term.c | 2 +- src/statscreen.c | 2 +- src/uichapterstatus.c | 4 +- src/uisupport.c | 4 +- src/unitlistscreen.c | 2 +- src/worldmap_main.c | 2 +- src/worldmap_status_ui.c | 2 +- 44 files changed, 238 insertions(+), 288 deletions(-) diff --git a/include/bmmap.h b/include/bmmap.h index 7189c7222..26b9cc9c9 100644 --- a/include/bmmap.h +++ b/include/bmmap.h @@ -40,6 +40,9 @@ extern u8 ** gBmMapOther; extern u8 * gTilesetTerrainLookup; extern u16 ** gBmMapBaseTiles; +#define gMapRangeSigned ((s8 **) gBmMapRange) +#define gMapMovementSigned ((s8 **) gBmMapMovement) + enum { // Magic values for gBmMapMovement diff --git a/include/bmudisp.h b/include/bmudisp.h index 518b56a8a..013fea884 100644 --- a/include/bmudisp.h +++ b/include/bmudisp.h @@ -1,8 +1,10 @@ #ifndef GUARD_BM_UDISP_H #define GUARD_BM_UDISP_H +#define UNITSPRITE_MAX 0xD0 + // ??? sub_8026618(???); -void SetupMapSpritesPalettes(void); +void ApplyUnitSpritePalettes(void); // ??? sub_8026670(???); void ResetUnitSprites(void); // ??? ResetUnitSpritesB(???); diff --git a/include/mu.h b/include/mu.h index 7d4a10328..2edbe8522 100644 --- a/include/mu.h +++ b/include/mu.h @@ -125,7 +125,7 @@ struct MuProc { /* 41 */ u8 jid; /* 42 */ s8 facing; /* 43 */ u8 step_sound_clock; - /* 44 */ u8 boolForceMaxSpeed; + /* 44 */ u8 fast_walk_b; /* 46 */ u16 layer; /* 48 */ u16 move_clock_q4; /* 4A */ short moveConfig; @@ -299,15 +299,15 @@ void MuCritFlash_SetRegularPalette(struct MuFlashEffectProc * proc); void MuCritFlash_StartFadeBack_maybe(struct MuFlashEffectProc * proc); void MuCritFlash_SpriteShakeLoop(struct MuFlashEffectProc * proc); void MuCritFlash_RestorePalette(struct MuFlashEffectProc * proc); -void MU_StartHitFlash(struct MuProc * muProc, int flashType); -void MuHitFlash_RestorePalette(struct MuFlashEffectProc * proc); -void MU_AllForceSetMaxMoveSpeed(void); -void MU_ForceSetMaxMoveSpeed(ProcPtr proc); -void MU_SetSpecialSprite(struct MuProc * proc, int jid, const u16 * palette); -void MU_SetPaletteId(struct MuProc * proc, unsigned paletteId); -struct MuProc * MU_GetByIndex(int slot); -struct MuProc * MU_GetByUnit(struct Unit * unit); -void MU_SortObjLayers(void); +void StartMuHitFlash(struct MuProc * muProc, int flashType); +void MuFlashFadeFrom_RestorePal(struct MuFlashEffectProc * proc); +void SetMuMaxWalkSpeed(void); +void MuMaxWalkSpeedFunc(ProcPtr proc); +void SetMuSpecialSprite(struct MuProc * proc, int jid, const u16 * palette); +void SetMuPal(struct MuProc * proc, unsigned paletteId); +struct MuProc * GetMu(int slot); +struct MuProc * GetUnitMu(struct Unit * unit); +void SortMus(void); extern u8 gMUGfxBuffer[MU_GFX_MAX_SIZE * MU_MAX_COUNT]; diff --git a/include/muctrl.h b/include/muctrl.h index da1205e20..295c67ea8 100644 --- a/include/muctrl.h +++ b/include/muctrl.h @@ -23,11 +23,10 @@ struct MuCtrlProc /* 30 */ struct MuProc * muProc; /* 34 */ const struct REDA * redas; /* 38 */ u16 redaCount; - /* 3A */ u16 unk_3a; + /* 3A */ u16 timer; /* 3C */ s16 delayFrames; /* 3E */ u16 flags; - /* 40 */ s8 unk_40; - /* 41 */ s8 unk_41; + /* 40 */ s8 x, y; /* 42 */ s8 unk_42; /* 43 */ s8 unk_43; /* 44 */ struct REDA reda_cur; @@ -39,7 +38,7 @@ void MuCtr_StartDefinedMove(struct Unit * unit, const struct REDA * redas, s16 c void MuCtr_StartMoveTowards(struct Unit *, s8, s8, u8, u16); void MuCtr_InitDefinedMove(struct MuCtrlProc * proc, struct Unit * unit, const struct REDA * redas, s16 count, u16 flags); s8 MuCtrExists(void); -void MU_AllForceSetMaxMoveSpeed_(void); +void SetMuMaxWalkSpeed_(void); void MoveUnitExt(struct Unit* unit, const struct REDA * redas, s16 count, u16 flags); void MoveUnit_(struct Unit *, s8, s8, u16); void GenUnitDefinitionFinalPosition(const struct UnitDefinition* uDef, s8* xOut, s8* yOut, s8 findNearest); @@ -58,6 +57,6 @@ extern s8 gUnknown_03001C34; extern u8 gUnknown_03001C35; extern u16 gUnknown_03001C36; -extern struct ProcCmd gProcScr_MuCtrl[]; +extern struct ProcCmd ProcScr_MuCtrl[]; #endif // GUARD_MUCTRL_H diff --git a/src/banim-ekrbattleending.c b/src/banim-ekrbattleending.c index 90c69c45b..0c0f520f5 100644 --- a/src/banim-ekrbattleending.c +++ b/src/banim-ekrbattleending.c @@ -155,7 +155,7 @@ void ekrBattleEnding_8056310(struct ProcEkrBattleEnding * proc) BMapDispResume_FromBattleDelayed(); RefreshUnitSprites(); ForceSyncUnitSpriteSheet(); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); SetBlendConfig(3, 0, 0, 4); SetBlendTargetA(0, 0, 0, 1, 0); diff --git a/src/bmidoten.c b/src/bmidoten.c index 809a65e2f..e0028d0b0 100644 --- a/src/bmidoten.c +++ b/src/bmidoten.c @@ -348,19 +348,19 @@ void MarkMovementMapEdges(void) { if (gBmMapMovement[iy][ix] > MAP_MOVEMENT_MAX) continue; - if ((s8) gBmMapMovement[iy][ix] == gMovMapFillState.maxMovementValue) + if (gMapMovementSigned[iy][ix] == gMovMapFillState.maxMovementValue) continue; - if ((s8) gBmMapMovement[iy][ix - 1] < 0 && (ix != 0)) + if (gMapMovementSigned[iy][ix - 1] < 0 && (ix != 0)) gBmMapMovement[iy][ix - 1] = gMovMapFillState.maxMovementValue; - if ((s8) gBmMapMovement[iy][ix + 1] < 0 && (ix != (gBmMapSize.x - 1))) + if (gMapMovementSigned[iy][ix + 1] < 0 && (ix != (gBmMapSize.x - 1))) gBmMapMovement[iy][ix + 1] = gMovMapFillState.maxMovementValue; - if ((s8) gBmMapMovement[iy - 1][ix] < 0 && (iy != 0)) + if (gMapMovementSigned[iy - 1][ix] < 0 && (iy != 0)) gBmMapMovement[iy - 1][ix] = gMovMapFillState.maxMovementValue; - if ((s8) gBmMapMovement[iy + 1][ix] < 0 && (iy != (gBmMapSize.y - 1))) + if (gMapMovementSigned[iy + 1][ix] < 0 && (iy != (gBmMapSize.y - 1))) gBmMapMovement[iy + 1][ix] = gMovMapFillState.maxMovementValue; } } diff --git a/src/bmio.c b/src/bmio.c index ba4c09227..99ccfad58 100644 --- a/src/bmio.c +++ b/src/bmio.c @@ -978,7 +978,7 @@ void StartBattleMap(struct GameCtrlProc* gameCtrl) { ClearBattleMapState(); sub_80156D4(); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); ResetChapterFlags(); ResetUnitSprites(); ResetMenuOverrides(); @@ -1045,7 +1045,7 @@ void RestartBattleMap(void) { SetInterrupt_LCDVBlank(OnVBlank); sub_80156D4(); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); ResetUnitSprites(); ClearTraps(); @@ -1098,7 +1098,7 @@ void GameCtrl_StartResumedGame(struct GameCtrlProc* gameCtrl) { ); ReadGameSaveCoreGfx(); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); ResetUnitSprites(); InitChapterMap(gPlaySt.chapterIndex); @@ -1146,7 +1146,7 @@ void RefreshBMapDisplay_FromBattle(void) { SetInterrupt_LCDVBlank(OnVBlank); ReadGameSaveCoreGfx(); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); ClearBg0Bg1(); @@ -1176,7 +1176,7 @@ void InitMoreBMapGraphics(void) { AllocWeatherParticles(gPlaySt.chapterWeatherId); RenderBmMap(); RefreshUnitSprites(); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); ForceSyncUnitSpriteSheet(); InitSystemTextFont(); } diff --git a/src/bmitemuse.c b/src/bmitemuse.c index 083e4257a..2f46dfc7d 100644 --- a/src/bmitemuse.c +++ b/src/bmitemuse.c @@ -678,7 +678,7 @@ void WarpSelect_OnInit(struct WarpSelectProc* proc) void WarpSelect_OnIdle(struct WarpSelectProc* proc) { - s8 warpAllowed = ((s8**) gBmMapMovement)[gBmSt.playerCursor.y][gBmSt.playerCursor.x] != -1; + s8 warpAllowed = gMapMovementSigned[gBmSt.playerCursor.y][gBmSt.playerCursor.x] != -1; HandlePlayerCursorMovement(); @@ -1034,7 +1034,7 @@ void TorchSelect_OnIdle(struct WarpSelectProc* proc) int xTorch = gBmSt.playerCursor.x; int yTorch = gBmSt.playerCursor.y; - s8 canTorch = ((s8**) gBmMapRange)[yTorch][xTorch]; + s8 canTorch = gMapRangeSigned[yTorch][xTorch]; HandlePlayerCursorMovement(); diff --git a/src/bmmap.c b/src/bmmap.c index 4029b8986..8eb326f48 100644 --- a/src/bmmap.c +++ b/src/bmmap.c @@ -345,7 +345,7 @@ void DisplayMovementViewTile(u16* bg, int xBmMap, int yBmMap, int xTileMap, int // TODO: tile macros? // TODO: are the movement and range maps s8[][]? - if (((s8**)(gBmMapMovement))[yBmMap][xBmMap] >= 0) { + if (gMapMovementSigned[yBmMap][xBmMap] >= 0) { bg[0x00 + 0] = 0x4280; bg[0x00 + 1] = 0x4281; bg[0x20 + 0] = 0x4282; @@ -354,7 +354,7 @@ void DisplayMovementViewTile(u16* bg, int xBmMap, int yBmMap, int xTileMap, int return; } - if (((s8**)(gBmMapRange))[yBmMap][xBmMap]) { + if (gMapRangeSigned[yBmMap][xBmMap]) { if (bg[0]) { bg[0x00 + 0] = 0x5284; bg[0x00 + 1] = 0x5285; diff --git a/src/bmtarget.c b/src/bmtarget.c index 9b07d9d60..e6dd5a726 100644 --- a/src/bmtarget.c +++ b/src/bmtarget.c @@ -27,7 +27,7 @@ void ForEachUnitInMovement(void(*func)(struct Unit* unit)) { for (iy = gBmMapSize.y - 1; iy >= 0; iy--) { for (ix = gBmMapSize.x - 1; ix >= 0; ix--) { - if (((s8**)gBmMapMovement)[iy][ix] == 0) { + if (gMapMovementSigned[iy][ix] == 0) { continue; } @@ -49,7 +49,7 @@ void ForEachUnitInRange(void(*func)(struct Unit* unit)) { for (iy = gBmMapSize.y - 1; iy >= 0; iy--) { for (ix = gBmMapSize.x - 1; ix >= 0; ix--) { - if (((s8**)gBmMapRange)[iy][ix] == 0) { + if (gMapRangeSigned[iy][ix] == 0) { continue; } @@ -71,7 +71,7 @@ void ForEachPosInRange(void(*func)(int x, int y)) { for (iy = gBmMapSize.y - 1; iy >= 0; iy--) { for (ix = gBmMapSize.x - 1; ix >= 0; ix--) { - if (((s8**)gBmMapRange)[iy][ix] == 0) { + if (gMapRangeSigned[iy][ix] == 0) { continue; } @@ -156,15 +156,15 @@ void TryAddTrapsToTargetList() { continue; } - if ((gBmMapTerrain[trap->yPos][trap->xPos] == TERRAIN_WALL_1B) && (((s8**)gBmMapRange)[trap->yPos][trap->xPos] != 0)) { + if ((gBmMapTerrain[trap->yPos][trap->xPos] == TERRAIN_WALL_1B) && (gMapRangeSigned[trap->yPos][trap->xPos] != 0)) { AddTarget(trap->xPos, trap->yPos, 0, trap->extra); } - if ((gBmMapTerrain[trap->yPos + 1][trap->xPos] == TERRAIN_WALL_1B) && (((s8**)gBmMapRange)[trap->yPos + 1][trap->xPos] != 0)) { + if ((gBmMapTerrain[trap->yPos + 1][trap->xPos] == TERRAIN_WALL_1B) && (gMapRangeSigned[trap->yPos + 1][trap->xPos] != 0)) { AddTarget(trap->xPos, trap->yPos + 1, 0, trap->extra); } - if ((gBmMapTerrain[trap->yPos][trap->xPos] == TERRAIN_SNAG) && (((s8**)gBmMapRange)[trap->yPos][trap->xPos] != 0)) { + if ((gBmMapTerrain[trap->yPos][trap->xPos] == TERRAIN_SNAG) && (gMapRangeSigned[trap->yPos][trap->xPos] != 0)) { AddTarget(trap->xPos, trap->yPos, 0, trap->extra); } } diff --git a/src/bmtrap.c b/src/bmtrap.c index 5ba2b41a8..900d03adc 100644 --- a/src/bmtrap.c +++ b/src/bmtrap.c @@ -88,7 +88,7 @@ void ApplyTrapDamageAnim(struct ProcBmTrap * proc) break; case 2: - MU_End(MU_GetByUnit(unit)); + MU_End(GetUnitMu(unit)); break; } @@ -226,7 +226,7 @@ bool ExecTrapAfterWarp(ProcPtr proc) bool ExecTrapAfterDropAction(ProcPtr proc, struct Unit * unit) { if (!GetPickTrapType(unit)) { - MU_End(MU_GetByUnit(unit)); + MU_End(GetUnitMu(unit)); RenderBmMap(); RefreshEntityBmMaps(); ForceSyncUnitSpriteSheet(); diff --git a/src/bmudisp.c b/src/bmudisp.c index e86521bce..334a9452f 100644 --- a/src/bmudisp.c +++ b/src/bmudisp.c @@ -14,6 +14,7 @@ #include "bmlib.h" #include "constants/terrains.h" #include "constants/event-flags.h" +#include "constants/video-global.h" /** * Display standing map sprites and various tile/unit markers @@ -21,7 +22,7 @@ extern UnitIconWait unit_icon_wait_table[]; -u8 EWRAM_DATA gSMSGfxIndexLookup[0xD0] = {}; +u8 EWRAM_DATA gUnitSpriteSlots[0xD0] = {}; u8 EWRAM_DATA gSMSGfxBuffer[3][8*0x20*0x20] = {}; @@ -343,88 +344,67 @@ u16 CONST_DATA sSprite_32x32_Window[] = { #define GetInfo(id) (unit_icon_wait_table[(id) & ((1<<7)-1)]) -//! FE8U = 0x08026618 -void sub_8026618(void) { +void sub_8026618(void) +{ gSMSSyncFlag++; - return; } -//! FE8U = 0x08026628 -void SetupMapSpritesPalettes(void) { - +void ApplyUnitSpritePalettes(void) +{ ApplyPalettes(gPal_MapSprite, 0x1C, 4); - if (gBmSt.gameStateBits & 0x40) { - ApplyPalette(gPal_MapSpriteArena, 0x1B); - } else { - ApplyPalette(gPal_NotMapSprite, 0x1B); - } - - return; + if (gBmSt.gameStateBits & BM_FLAG_LINKARENA) + ApplyPalette(gPal_MapSpriteArena, 0x10 + OBJPAL_UNITSPRITE_PURPLE); + else + ApplyPalette(gPal_NotMapSprite, 0x10 + OBJPAL_UNITSPRITE_PURPLE); } -//! FE8U = 0x08026670 -void sub_8026670(void) { +void sub_8026670(void) +{ ApplyPalette(gPal_MapSpriteSepia, 0x1E); - - return; } -//! FE8U = 0x08026688 -void ResetUnitSprites(void) { - +void ResetUnitSprites(void) +{ int i; - - for (i = 0xD0-1; i >= 0; i--) { - gSMSGfxIndexLookup[i] |= 0xff; - } + for (i = UNITSPRITE_MAX - 1; i >= 0; i--) + gUnitSpriteSlots[i] |= 0xFF; gSMS32xGfxIndexCounter = 0; - gSMS16xGfxIndexCounter = 0x40-1; - - return; + gSMS16xGfxIndexCounter = 0x40 - 1; } -//! FE8U = 0x080266BC -void ResetUnitSpritesB(void) { - +void ResetUnitSpritesB(void) +{ int i; - for (i = 0xD0-1; i >= 0; i--) { - gSMSGfxIndexLookup[i] |= 0xff; - } + for (i = UNITSPRITE_MAX - 1; i >= 0; i--) + gUnitSpriteSlots[i] |= 0xFF; gSMS32xGfxIndexCounter = 0; - gSMS16xGfxIndexCounter = 0x60-1; - - return; + gSMS16xGfxIndexCounter = 0x60 - 1; } -//! FE8U = 0x080266F0 -int StartUiSMS(int smsId, int frameId) { - +int StartUiSMS(int smsId, int frameId) +{ int slot = gSomeSMSLookupTable_859B66C[frameId]; - Decompress(GetInfo(smsId).sheet, gpSMSGfxDecompBuffer); switch (GetInfo(smsId).size) { - case UNIT_ICON_SIZE_16x16: - gSMSGfxIndexLookup[frameId] = SomethingSMS_16x16(slot, smsId) / 2; + case UNIT_ICON_SIZE_16x16: + gUnitSpriteSlots[frameId] = SomethingSMS_16x16(slot, smsId) / 2; + break; - break; - - case UNIT_ICON_SIZE_16x32: - gSMSGfxIndexLookup[frameId] = ApplyUnitSpriteImage16x32(slot, smsId) / 2; - - break; - - case UNIT_ICON_SIZE_32x32: - gSMSGfxIndexLookup[frameId] = ApplyUnitSpriteImage32x32(slot, smsId) / 2; + case UNIT_ICON_SIZE_16x32: + gUnitSpriteSlots[frameId] = ApplyUnitSpriteImage16x32(slot, smsId) / 2; + break; - break; + case UNIT_ICON_SIZE_32x32: + gUnitSpriteSlots[frameId] = ApplyUnitSpriteImage32x32(slot, smsId) / 2; + break; } - return gSMSGfxIndexLookup[frameId] << 1; + return gUnitSpriteSlots[frameId] << 1; } //! FE8U = 0x0802677C @@ -434,41 +414,41 @@ int SMS_SomethingGmapUnit(int smsId, int frameId, int slot) { switch (GetInfo(smsId).size) { case UNIT_ICON_SIZE_16x16: - gSMSGfxIndexLookup[frameId] = SomethingSMS_16x16(slot, smsId) / 2; + gUnitSpriteSlots[frameId] = SomethingSMS_16x16(slot, smsId) / 2; break; case UNIT_ICON_SIZE_16x32: - gSMSGfxIndexLookup[frameId] = ApplyUnitSpriteImage16x32(slot, smsId) / 2; + gUnitSpriteSlots[frameId] = ApplyUnitSpriteImage16x32(slot, smsId) / 2; break; case UNIT_ICON_SIZE_32x32: - gSMSGfxIndexLookup[frameId] = ApplyUnitSpriteImage32x32(slot, smsId) / 2; + gUnitSpriteSlots[frameId] = ApplyUnitSpriteImage32x32(slot, smsId) / 2; break; } - return gSMSGfxIndexLookup[frameId] << 1; + return gUnitSpriteSlots[frameId] << 1; } //! FE8U = 0x080267FC int UseUnitSprite(u32 id) { - if (gSMSGfxIndexLookup[id] == 0xFF) { + if (gUnitSpriteSlots[id] == 0xFF) { Decompress(GetInfo(id).sheet, gpSMSGfxDecompBuffer); switch (GetInfo(id).size) { case UNIT_ICON_SIZE_16x16: - gSMSGfxIndexLookup[id] = ApplyUnitSpriteImage16x16(gSMS16xGfxIndexCounter, id) / 2; + gUnitSpriteSlots[id] = ApplyUnitSpriteImage16x16(gSMS16xGfxIndexCounter, id) / 2; gSMS16xGfxIndexCounter -= 1; break; case UNIT_ICON_SIZE_16x32: - gSMSGfxIndexLookup[id] = ApplyUnitSpriteImage16x32(gSMS32xGfxIndexCounter, id) / 2; + gUnitSpriteSlots[id] = ApplyUnitSpriteImage16x32(gSMS32xGfxIndexCounter, id) / 2; gSMS32xGfxIndexCounter += 2; break; @@ -478,7 +458,7 @@ int UseUnitSprite(u32 id) { gSMS32xGfxIndexCounter += 2; } - gSMSGfxIndexLookup[id] = ApplyUnitSpriteImage32x32(gSMS32xGfxIndexCounter, id) / 2; + gUnitSpriteSlots[id] = ApplyUnitSpriteImage32x32(gSMS32xGfxIndexCounter, id) / 2; gSMS32xGfxIndexCounter += 4; break; @@ -488,7 +468,7 @@ int UseUnitSprite(u32 id) { } - return gSMSGfxIndexLookup[id] << 1; + return gUnitSpriteSlots[id] << 1; } //! FE8U = 0x080268C8 @@ -658,7 +638,7 @@ void sub_8026C1C(struct Unit* param_1, int param_2) { } if (param_2 == 0x3f) { - gSMSGfxIndexLookup[sp04] |= 0xff; + gUnitSpriteSlots[sp04] |= 0xff; } return; } diff --git a/src/bmusemind.c b/src/bmusemind.c index 165aff1b8..f1a0d64de 100644 --- a/src/bmusemind.c +++ b/src/bmusemind.c @@ -237,7 +237,7 @@ int PostWarpStaff_ExecTrap(ProcPtr proc) { } int sub_802EF80() { - MU_End(MU_GetByUnit(GetUnit(gActionData.targetIndex))); + MU_End(GetUnitMu(GetUnit(gActionData.targetIndex))); RefreshEntityBmMaps(); RenderBmMap(); diff --git a/src/bonusclaim.c b/src/bonusclaim.c index 49d3caf97..54bcfbc8a 100644 --- a/src/bonusclaim.c +++ b/src/bonusclaim.c @@ -302,7 +302,7 @@ void SetupBonusClaimTargets(struct BonusClaimProc * proc) } proc->targets = count + 1; - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); ForceSyncUnitSpriteSheet(); } diff --git a/src/chapterintrofx.c b/src/chapterintrofx.c index 31bee5311..b4163ec2d 100644 --- a/src/chapterintrofx.c +++ b/src/chapterintrofx.c @@ -782,7 +782,7 @@ void ChapterIntro_InitMapDisplay() { UnpackChapterMapGraphics(gPlaySt.chapterIndex); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); LoadObjUIGfx(); var = GetROMChapterStruct(gPlaySt.chapterIndex)->initialPosX; diff --git a/src/chapterintrofx_title.c b/src/chapterintrofx_title.c index d15e9d542..2f77e3a6a 100755 --- a/src/chapterintrofx_title.c +++ b/src/chapterintrofx_title.c @@ -79,7 +79,7 @@ void ChapterIntroTitle_End(struct ChapterIntroFXProc *proc) BG_EnableSyncByMask(BG2_SYNC_BIT); DisableMapPaletteAnimations(); UnpackChapterMapGraphics(gPlaySt.chapterIndex); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); LoadObjUIGfx(); x = GetCameraCenteredX(GetROMChapterStruct(gPlaySt.chapterIndex)->initialPosX * 0x10); diff --git a/src/classchg-main.c b/src/classchg-main.c index a1e216771..774c82a80 100644 --- a/src/classchg-main.c +++ b/src/classchg-main.c @@ -172,7 +172,7 @@ void PromoMain_HandlePrepEndEffect(struct ProcPromoMain *proc) case PROMO_HANDLER_TYPE_PREP: BMapDispResume(); RefreshUnitSprites(); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); ForceSyncUnitSpriteSheet(); InitSystemTextFont(); break; diff --git a/src/cp_0803E2F4.c b/src/cp_0803E2F4.c index de58a8db9..0677de3a7 100644 --- a/src/cp_0803E2F4.c +++ b/src/cp_0803E2F4.c @@ -94,7 +94,7 @@ void AiFillDangerMap(void) { for (iy = gBmMapSize.y - 1; iy >= 0; iy--) { for (ix = gBmMapSize.x - 1; ix >= 0; ix--) { - if (((s8**)(gBmMapRange))[iy][ix] == 0) { + if (gMapRangeSigned[iy][ix] == 0) { continue; } @@ -173,7 +173,7 @@ s8 AiTryGetNearestHealPoint(struct Vec2* out) { count = AiCountNearbyEnemyUnits(ix, iy); - if ((count <= currentCount) && (((s8**)(gBmMapMovement))[iy][ix] <= currentMove)) { + if ((count <= currentCount) && (gMapMovementSigned[iy][ix] <= currentMove)) { currentCount = count; currentMove = gBmMapMovement[iy][ix]; out->x = ix; @@ -287,7 +287,7 @@ s8 AiTryMoveTowardsEscape(void) { if (escapePoint != NULL) { - if (((s8**)(gBmMapMovement))[escapePoint->y][escapePoint->x] <= UNIT_MOV(gActiveUnit)) { + if (gMapMovementSigned[escapePoint->y][escapePoint->x] <= UNIT_MOV(gActiveUnit)) { AiTryMoveTowards(escapePoint->x, escapePoint->y, 0, -1, 1); AiSetDecision(gAiDecision.xMove, gAiDecision.yMove, AI_ACTION_ESCAPE, escapePoint->x, escapePoint->y, escapePoint->facing, 0); @@ -330,8 +330,8 @@ const struct AiEscapePt* GetEscapePointStructThingMaybe(void) { continue; } - if (resultMove > ((s8**)(gBmMapMovement))[list[i].y][list[i].x]) { - resultMove = ((s8**)(gBmMapMovement))[list[i].y][list[i].x]; + if (resultMove > gMapMovementSigned[list[i].y][list[i].x]) { + resultMove = gMapMovementSigned[list[i].y][list[i].x]; result = list + i; } } @@ -666,7 +666,7 @@ s8 sub_803EEB0(int x, int y) { for (ix = gBmMapSize.x - 1; ix >= 0; ix--) { struct Unit* unit; - if (((s8**)(gBmMapMovement))[iy][ix] == 0) { + if (gMapMovementSigned[iy][ix] == 0) { continue; } @@ -725,7 +725,7 @@ s8 AiFunc_CountEnemiesInRange(const void * arg) for (iy = gBmMapSize.y - 1; iy >= 0; iy--) { for (ix = gBmMapSize.x - 1; ix >= 0; ix--) { - if (((s8**)(gBmMapRange))[iy][ix] == 0) { + if (gMapRangeSigned[iy][ix] == 0) { continue; } @@ -792,7 +792,7 @@ s8 sub_803F15C(const struct Unknown_Sub80315C* input) { if ((input->unk_05 != 0) && (item != 0)) { AiFloodMovementAndRange(gActiveUnit, move, item); - if (((s8**)(gBmMapRange))[yUnk][xUnk] == 0) { + if (gMapRangeSigned[yUnk][xUnk] == 0) { gActiveUnit->xPos = xPrev; gActiveUnit->yPos = yPrev; AiTryMoveTowards(xUnk, yUnk, 0, 0xff, 1); @@ -824,17 +824,17 @@ s8 sub_803F15C(const struct Unknown_Sub80315C* input) { for (ix = gBmMapSize.x - 1; ix >= 0; ix--) { if (item != 0) { - if ((((s8**)(gBmMapMovement))[iy][ix] < MAP_MOVEMENT_MAX) && (((s8**)(gBmMapRange))[iy][ix] != 0) ) { + if ((gMapMovementSigned[iy][ix] < MAP_MOVEMENT_MAX) && (gMapRangeSigned[iy][ix] != 0) ) { continue; } - ((s8**)(gBmMapMovement))[iy][ix] = -1; + gMapMovementSigned[iy][ix] = -1; } else { - if ((((s8**)(gBmMapMovement))[iy][ix] < MAP_MOVEMENT_MAX) && (((s8**)(gBmMapRange))[iy][ix] < MAP_MOVEMENT_MAX) ) { + if ((gMapMovementSigned[iy][ix] < MAP_MOVEMENT_MAX) && (gMapRangeSigned[iy][ix] < MAP_MOVEMENT_MAX) ) { continue; } - ((s8**)(gBmMapMovement))[iy][ix] = -1; + gMapMovementSigned[iy][ix] = -1; } } diff --git a/src/cp_battle.c b/src/cp_battle.c index be6cc89ca..faf20429d 100644 --- a/src/cp_battle.c +++ b/src/cp_battle.c @@ -293,9 +293,9 @@ s8 AiAttemptBallistaCombat(s8 (*isEnemy)(struct Unit* unit), struct AiCombatSimu if (item != 0) { ballistaCount++; - ((s8**)(gBmMapMovement))[iy][ix] = item; + gMapMovementSigned[iy][ix] = item; } else { - ((s8**)(gBmMapMovement))[iy][ix] = -1; + gMapMovementSigned[iy][ix] = -1; } } } @@ -360,7 +360,7 @@ s8 AiAttemptBallistaCombat(s8 (*isEnemy)(struct Unit* unit), struct AiCombatSimu //! FE8U = 0x0803DB08 u8 AiAttemptStealAction_GetMovementAt(int x, int y) { - if (((s8**)(gBmMapMovement))[y][x] >= MAP_MOVEMENT_MAX) { + if (gMapMovementSigned[y][x] >= MAP_MOVEMENT_MAX) { return -1; } @@ -457,7 +457,7 @@ s8 AiSimulateBestBattleAgainstTarget(struct AiCombatSimulationSt* st) { continue; } - if (((s8**)(gBmMapRange))[iy][ix] == 0) { + if (gMapRangeSigned[iy][ix] == 0) { continue; } @@ -499,11 +499,11 @@ s8 AiSimulateBestBallistaBattleAgainstTarget(struct AiCombatSimulationSt* st, u1 continue; } - if (((s8**)(gBmMapMovement))[iy][ix] != (u8)item) { + if (gMapMovementSigned[iy][ix] != (u8)item) { continue; } - if (((s8**)(gBmMapRange))[iy][ix] == 0) { + if (gMapRangeSigned[iy][ix] == 0) { continue; } @@ -537,7 +537,7 @@ u32 AiGetCombatPositionScore(int x, int y, struct AiCombatSimulationSt* st) { score = AiGetInRangeCombatPositionScoreComponent(x, y, GetUnit(st->targetId)); score += AiGetTerrainCombatPositionScoreComponent(x, y); score += AiGetFriendZoneCombatPositionScoreComponent(x, y); - score -= ((s8**)(gBmMapMovement))[y][x]; + score -= gMapMovementSigned[y][x]; score -= gBmMapOther[y][x] / 8; score += 0x7FFFFFFF; diff --git a/src/cp_script.c b/src/cp_script.c index 47d720545..fb3aa42af 100644 --- a/src/cp_script.c +++ b/src/cp_script.c @@ -636,7 +636,7 @@ void AiScriptCmd_17_DoEscape(u8* pc) { //! FE8U = 0x0803CF60 int sub_803CF60(int x, int y) { - return ((AiGetTerrainCombatPositionScoreComponent(x, y) + AiGetFriendZoneCombatPositionScoreComponent(x, y)) - ((s8**)(gBmMapMovement))[y][x] - gBmMapOther[y][x] / 8) + 0x7FFFFFFF; + return ((AiGetTerrainCombatPositionScoreComponent(x, y) + AiGetFriendZoneCombatPositionScoreComponent(x, y)) - gMapMovementSigned[y][x] - gBmMapOther[y][x] / 8) + 0x7FFFFFFF; } //! FE8U = 0x0803CFB4 @@ -675,7 +675,7 @@ s8 sub_803CFB4(int x, int y, struct Vec2* out, u8* itemSlotOut) { continue; } - if (((s8**)(gBmMapRange))[iy][ix] == 0) { + if (gMapRangeSigned[iy][ix] == 0) { continue; } @@ -736,7 +736,7 @@ s8 sub_803D124(const u8* terrainList, u32 flags, struct Vec2* out) { } } - if (best <= ((s8**)(gBmMapRange))[iy][ix]) { + if (best <= gMapRangeSigned[iy][ix]) { continue; } diff --git a/src/cp_staff.c b/src/cp_staff.c index 5e854664f..2d9e6adcc 100644 --- a/src/cp_staff.c +++ b/src/cp_staff.c @@ -703,7 +703,7 @@ s8 sub_8040668(struct Vec2* out) { continue; } - if (tmpRangeA > ((s8**)(gBmMapRange))[iy][ix]) { + if (tmpRangeA > gMapRangeSigned[iy][ix]) { tmpRangeA = gBmMapRange[iy][ix]; } } else { @@ -711,11 +711,11 @@ s8 sub_8040668(struct Vec2* out) { continue; } - if (((s8**)(gBmMapMovement))[iy][ix] <= MAP_MOVEMENT_MAX) { + if (gMapMovementSigned[iy][ix] <= MAP_MOVEMENT_MAX) { continue; } - if (tmpRangeB > ((s8**)(gBmMapRange))[iy][ix]) { + if (tmpRangeB > gMapRangeSigned[iy][ix]) { xDecision = ix; yDecision = iy; tmpRangeB = gBmMapRange[iy][ix]; diff --git a/src/cp_utility.c b/src/cp_utility.c index 6c50e22a8..9d3a48630 100644 --- a/src/cp_utility.c +++ b/src/cp_utility.c @@ -165,7 +165,7 @@ s8 AiFindTargetInReachByClassId(int classId, struct Vec2* out) { continue; } - if (bestDistance < ((s8**)gBmMapRange)[unit->yPos][unit->xPos]) { + if (bestDistance < gMapRangeSigned[unit->yPos][unit->xPos]) { continue; } @@ -412,7 +412,7 @@ s8 AiFindClosestTerrainPosition(const u8* terrainList, int flags, struct Vec2* o } } - if (bestDistance <= ((s8**) gBmMapRange)[iy][ix]) { + if (bestDistance <= gMapRangeSigned[iy][ix]) { continue; } @@ -433,7 +433,7 @@ s8 AiFindClosestTerrainPosition(const u8* terrainList, int flags, struct Vec2* o //! FE8U = 0x0803AE3C u8 AiGetPositionRange(int x, int y) { - if (((s8**) gBmMapRange)[y][x] >= MAP_MOVEMENT_MAX) { + if (gMapRangeSigned[y][x] >= MAP_MOVEMENT_MAX) { return 0xFF; } @@ -479,7 +479,7 @@ s8 AiFindClosestTerrainAdjacentPosition(const u8* terrainList, int flags, struct continue; } - if (bestDistance <= ((s8**) gBmMapRange)[tmp.y][tmp.x]) { + if (bestDistance <= gMapRangeSigned[tmp.y][tmp.x]) { continue; } @@ -579,7 +579,7 @@ s8 AiFindClosestUnlockPosition(int flags, struct Vec2* outA, struct Vec2* outB) } } - if (bestDistance <= ((s8**)gBmMapRange)[tmp.y][tmp.x]) { + if (bestDistance <= gMapRangeSigned[tmp.y][tmp.x]) { continue; } @@ -618,7 +618,7 @@ int AiCountUnitsInRange(void) { for (iy = gBmMapSize.y - 1; iy >= 0; iy--) { for (ix = gBmMapSize.x - 1; ix >= 0; ix--) { - if (((s8**)gBmMapRange)[iy][ix] == 0) { + if (gMapRangeSigned[iy][ix] == 0) { continue; } @@ -643,7 +643,7 @@ int AiCountEnemyUnitsInRange(void) { for (iy = gBmMapSize.y - 1; iy >= 0; iy--) { for (ix = gBmMapSize.x - 1; ix >= 0; ix--) { - if (((s8**)gBmMapRange)[iy][ix] == 0) { + if (gMapRangeSigned[iy][ix] == 0) { continue; } @@ -672,7 +672,7 @@ int AiCountAlliedUnitsInRange(void) { for (iy = gBmMapSize.y - 1; iy >= 0; iy--) { for (ix = gBmMapSize.x - 1; ix >= 0; ix--) { - if (((s8**)gBmMapRange)[iy][ix] == 0) { + if (gMapRangeSigned[iy][ix] == 0) { continue; } @@ -1425,7 +1425,7 @@ void SaveNumberOfAlliedUnitsIn0To8Range(struct Unit* unit) { for (iy = gBmMapSize.y - 1; iy >= 0; iy--) { for (ix = gBmMapSize.x - 1; ix >= 0; ix--) { - if (((s8**) gBmMapMovement)[iy][ix] == 0) { + if (gMapMovementSigned[iy][ix] == 0) { continue; } @@ -1474,7 +1474,7 @@ s8 sub_803C284(struct Vec2* out) { continue; } - if (((s8**) gBmMapRange)[iy][ix] == 0) { + if (gMapRangeSigned[iy][ix] == 0) { continue; } @@ -1535,7 +1535,7 @@ int sub_803C3B0(void) { for (iy = gBmMapSize.y - 1; iy >= 0; iy--) { for (ix = gBmMapSize.x - 1; ix >= 0; ix--) { - if (((s8**) gBmMapRange)[iy][ix] == 0) { + if (gMapRangeSigned[iy][ix] == 0) { continue; } diff --git a/src/cpextra_80407F0.c b/src/cpextra_80407F0.c index d11cdf8c7..9ff34a685 100644 --- a/src/cpextra_80407F0.c +++ b/src/cpextra_80407F0.c @@ -188,7 +188,7 @@ void AiSpecialItemAntitoxin(int item) { u8 sub_8040AE0(int x, int y) { - if ((s8)gBmMapRange[y][x] >= MAP_MOVEMENT_MAX) { + if (gMapRangeSigned[y][x] >= MAP_MOVEMENT_MAX) { return -1; } @@ -213,7 +213,7 @@ s8 sub_8040B38(struct Unit* unit, struct Vec2* pos) { sub_8040E98(unit); - if ((s8)gBmMapRange[pos->y][pos->x] >= MAP_MOVEMENT_MAX) { + if (gMapRangeSigned[pos->y][pos->x] >= MAP_MOVEMENT_MAX) { return 0; } @@ -239,7 +239,7 @@ s8 sub_8040BB4(struct Unit* unit, u32 flags, struct Vec2* posA, struct Vec2* pos InitAiMoveMapForUnit(unit); sub_8040F88(unit); - if ((AiFindClosestUnlockPosition(flags | 1, posA, posB) == 1) && ((s8)gBmMapMovement[posA->y][posA->x] < MAP_MOVEMENT_MAX)) { + if ((AiFindClosestUnlockPosition(flags | 1, posA, posB) == 1) && (gMapMovementSigned[posA->y][posA->x] < MAP_MOVEMENT_MAX)) { return 1; } else { @@ -247,7 +247,7 @@ s8 sub_8040BB4(struct Unit* unit, u32 flags, struct Vec2* posA, struct Vec2* pos if (AiFindClosestUnlockPosition(flags, posA, posB) == 1) { - if (((s8)gBmMapMovement[posA->y][posA->x] < MAP_MOVEMENT_MAX) && (gBmMapUnit[posA->y][posA->x] == 0)) { + if ((gMapMovementSigned[posA->y][posA->x] < MAP_MOVEMENT_MAX) && (gBmMapUnit[posA->y][posA->x] == 0)) { return 0; } @@ -478,7 +478,7 @@ int AiDetermineNightmareEffectiveness(int* numValidTargets, int* numHit, u8 thre for (iy = gBmMapSize.y - 1; iy >= 0; iy--) { for (ix = gBmMapSize.x - 1; ix >= 0; ix--) { - if (!(((s8**)(gBmMapRange))[iy][ix])) { + if (!(gMapRangeSigned[iy][ix])) { continue; } diff --git a/src/eventscr.c b/src/eventscr.c index 3bc7ec5fd..95e470766 100644 --- a/src/eventscr.c +++ b/src/eventscr.c @@ -3064,7 +3064,7 @@ u8 Event30_ENUN(struct EventEngineProc * proc) { if (EVENT_IS_SKIPPING(proc)) { - MU_AllForceSetMaxMoveSpeed_(); + SetMuMaxWalkSpeed_(); } if (MuCtrExists() == 1) diff --git a/src/eventscr_utils.c b/src/eventscr_utils.c index 2a3df8b8e..02d62240b 100644 --- a/src/eventscr_utils.c +++ b/src/eventscr_utils.c @@ -287,7 +287,7 @@ void ChangeUnitSpritePalette(u16 packed_pal) return; - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); switch (packed_pal & 0xf) { case 2: diff --git a/src/fogmap.c b/src/fogmap.c index c1d04a1f6..90009c766 100644 --- a/src/fogmap.c +++ b/src/fogmap.c @@ -55,7 +55,7 @@ void FillWarpRangeMap(struct Unit *unit_act, struct Unit *unit_tar) { 0 == gBmMapUnit[y][x]) continue; - ((s8**)gBmMapMovement)[y][x] = -1; + gMapMovementSigned[y][x] = -1; } } } else { @@ -69,9 +69,9 @@ void FillWarpRangeMap(struct Unit *unit_act, struct Unit *unit_tar) { 0 != gBmMapFog[y][x]) continue; - ((s8**)gBmMapMovement)[y][x] = -1; + gMapMovementSigned[y][x] = -1; } } } - ((s8**)gBmMapMovement)[unit_act->yPos][unit_act->xPos] = -1; + gMapMovementSigned[unit_act->yPos][unit_act->xPos] = -1; } diff --git a/src/mapanim.c b/src/mapanim.c index 195afd47d..605070c65 100644 --- a/src/mapanim.c +++ b/src/mapanim.c @@ -324,8 +324,8 @@ void SetBattleMuPaletteByIndex(int actorNum) if (GetItemIndex(gManimSt.actor[actorNum].bu->weaponBefore) != ITEM_DIVINESTONE) return; - MU_SetPaletteId(gManimSt.actor[actorNum].mu, BM_OBJPAL_BANIM_SPECIALMU + actorNum); - MU_SetSpecialSprite(gManimSt.actor[actorNum].mu, CLASS_MANAKETE, gUnknown_089A8F74); + SetMuPal(gManimSt.actor[actorNum].mu, BM_OBJPAL_BANIM_SPECIALMU + actorNum); + SetMuSpecialSprite(gManimSt.actor[actorNum].mu, CLASS_MANAKETE, gUnknown_089A8F74); } void SetBattleMuPalette(void) diff --git a/src/mapanim_api.c b/src/mapanim_api.c index fd23f20aa..b527fb027 100644 --- a/src/mapanim_api.c +++ b/src/mapanim_api.c @@ -33,7 +33,7 @@ void MakeBattleMOVEUNIT(int maActor, struct BattleUnit* bu, struct Unit* unit) case UNIT_STATUS_PETRIFY: case UNIT_STATUS_13: - MU_SetPaletteId(gManimSt.actor[maActor].mu, BM_OBJPAL_UNIT_GRAYED); + SetMuPal(gManimSt.actor[maActor].mu, BM_OBJPAL_UNIT_GRAYED); break; } // switch (unit->statusIndex) } diff --git a/src/mapanim_spellassoc.c b/src/mapanim_spellassoc.c index c1b5104fa..a68fc1934 100644 --- a/src/mapanim_spellassoc.c +++ b/src/mapanim_spellassoc.c @@ -311,7 +311,7 @@ void MapAnim_BeginRoundSpecificAnims(ProcPtr proc) gManimSt.actor[map_target].unit->xPos * 0x10 - gBmSt.camera.x ); - MU_StartHitFlash( + StartMuHitFlash( gManimSt.actor[map_target].mu, GetSpellAssocFlashColor(gManimSt.actor[map_actor].bu->weaponBefore) ); diff --git a/src/mu.c b/src/mu.c index b925b7a96..4dabac0e6 100644 --- a/src/mu.c +++ b/src/mu.c @@ -238,7 +238,7 @@ struct ProcCmd CONST_DATA ProcScr_MuRestorePalInfo[] = { struct ProcCmd CONST_DATA ProcScr_MuHitFlash[] = { PROC_SLEEP(17), - PROC_CALL(MuHitFlash_RestorePalette), + PROC_CALL(MuFlashFadeFrom_RestorePal), PROC_END }; @@ -365,7 +365,7 @@ struct MuProc * StartMuInternal(u16 x, u16 y, u16 jid, int objTileId, unsigned p proc->slot = slot; proc->layer = OAM2_LAYER(2); proc->moveConfig = 0; - proc->boolForceMaxSpeed = false; + proc->fast_walk_b = false; config->pal = palId; ap = AP_Create(GetMuAnimForJid(jid), 10); @@ -1073,7 +1073,7 @@ u16 GetMuQ4MovementSpeed(struct MuProc * proc) if (config & 0x80) config += 0x80; // I don't really get that one - if (proc->boolForceMaxSpeed) + if (proc->fast_walk_b) return 0x100; if (config != 0x40) @@ -1135,7 +1135,7 @@ void MU_StartDeathFade(struct MuProc * mu) proc->timeLeft = 0x20; SetBlendConfig(0, 0x10, 0x10, 0); FreezeSpriteAnim(mu->sprite_anim); - MU_StartHitFlash(mu, MU_FLASH_WHITE); + StartMuHitFlash(mu, MU_FLASH_WHITE); mu->sprite_anim->objLayer = 13; PlaySoundEffect(SONG_D6); @@ -1369,7 +1369,7 @@ void MuCritFlash_SetFadedPalette(struct MuFlashEffectProc * proc) struct MuProc * mu = proc->mu; mu->sprite_anim->tileBase = - (OBPAL_MU_FADE << 12) + mu->config->chr + mu->layer; + OAM2_PAL(OBPAL_MU_FADE) + mu->config->chr + mu->layer; } void MuCritFlash_SetRegularPalette(struct MuFlashEffectProc * proc) @@ -1377,14 +1377,14 @@ void MuCritFlash_SetRegularPalette(struct MuFlashEffectProc * proc) struct MuProc * mu = proc->mu; mu->sprite_anim->tileBase = - ((mu->config->pal & 0xF) << 12) + mu->config->chr + mu->layer; + OAM2_PAL(mu->config->pal) + mu->config->chr + mu->layer; } void MuCritFlash_StartFadeBack_maybe(struct MuFlashEffectProc * proc) { StartPalFade( PAL_OBJ(proc->mu->config->pal), - 0x15, 0x14, proc + 0x10 + OBPAL_MU_FADE, 20, proc ); } @@ -1409,14 +1409,14 @@ void MuCritFlash_RestorePalette(struct MuFlashEffectProc * proc) ((mu->config->pal & 0xF) << 12) + mu->config->chr + mu->layer; } -void MU_StartHitFlash(struct MuProc * mu, int flashType) +void StartMuHitFlash(struct MuProc * mu, int flashType) { struct MuFlashEffectProc * proc; ApplyPalette(gMuFlashPalLut[flashType], 0x10 + OBPAL_MU_FADE); mu->sprite_anim->tileBase = - (OBPAL_MU_FADE << 12) + mu->config->chr + mu->layer; + OAM2_PAL(OBPAL_MU_FADE) + mu->config->chr + mu->layer; StartPalFade( PAL_OBJ(mu->config->pal), @@ -1428,25 +1428,25 @@ void MU_StartHitFlash(struct MuProc * mu, int flashType) proc->mu = mu; } -void MuHitFlash_RestorePalette(struct MuFlashEffectProc * proc) +void MuFlashFadeFrom_RestorePal(struct MuFlashEffectProc * proc) { struct MuProc * mu = proc->mu; mu->sprite_anim->tileBase = - ((mu->config->pal & 0xF) << 12) + mu->config->chr + mu->layer; + OAM2_PAL(mu->config->pal) + mu->config->chr + mu->layer; } -void MU_AllForceSetMaxMoveSpeed(void) +void SetMuMaxWalkSpeed(void) { - Proc_ForEach(ProcScr_Mu, MU_ForceSetMaxMoveSpeed); + Proc_ForEach(ProcScr_Mu, MuMaxWalkSpeedFunc); } -void MU_ForceSetMaxMoveSpeed(ProcPtr proc) +void MuMaxWalkSpeedFunc(ProcPtr proc) { - ((struct MuProc *)(proc))->boolForceMaxSpeed = true; + ((struct MuProc *)(proc))->fast_walk_b = true; } -void MU_SetSpecialSprite(struct MuProc * proc, int jid, const u16 * palette) +void SetMuSpecialSprite(struct MuProc * proc, int jid, const u16 * pal) { proc->sprite_anim->frameTimer = 0; proc->sprite_anim->frameInterval = 0; @@ -1463,18 +1463,18 @@ void MU_SetSpecialSprite(struct MuProc * proc, int jid, const u16 * palette) GetMuImgBufById(proc->config->slot) ); - ApplyPalette(palette, 0x10 + proc->config->pal); + ApplyPalette(pal, 0x10 + proc->config->pal); } -void MU_SetPaletteId(struct MuProc * proc, unsigned paletteId) +void SetMuPal(struct MuProc * proc, unsigned paletteId) { proc->config->pal = paletteId; proc->sprite_anim->tileBase = - proc->config->chr + ((paletteId % 0x10) << 12) + proc->layer; + proc->config->chr + OAM2_PAL(paletteId % 0x10) + proc->layer; } -struct MuProc * MU_GetByIndex(int slot) +struct MuProc * GetMu(int slot) { if (!sMuConfig[slot].slot) return NULL; @@ -1482,27 +1482,24 @@ struct MuProc * MU_GetByIndex(int slot) return sMuConfig[slot].mu; } -struct MuProc * MU_GetByUnit(struct Unit * unit) +struct MuProc * GetUnitMu(struct Unit * unit) { int i; - for (i = 0; i < MU_MAX_COUNT; ++i) { - struct MuProc * proc = MU_GetByIndex(i); + struct MuProc * proc = GetMu(i); if (proc->unit == unit) return proc; } - return NULL; } -void MU_SortObjLayers(void) +void SortMus(void) { struct MuProc * procs[MU_MAX_COUNT]; - s8 i, j; - s8 count; + s8 i, j, count; // Clear proc list CpuFill32(0, procs, MU_MAX_COUNT * sizeof(struct MuProc *)); @@ -1511,7 +1508,7 @@ void MU_SortObjLayers(void) // Building proc list for (i = 0; i < MU_MAX_COUNT; ++i) { - struct MuProc * proc = MU_GetByIndex(i); + struct MuProc * proc = GetMu(i); if (proc) { diff --git a/src/muctrl.c b/src/muctrl.c index e5000deb8..9410ea5e9 100644 --- a/src/muctrl.c +++ b/src/muctrl.c @@ -44,7 +44,6 @@ struct REDA * CopyEventMoveREDAs(const struct REDA * redas, u8 count) void ClearEventMoveBuffer(const struct REDA * redas) { u8 i; - for (i = 0; i < 4; i++) { if (gEventREDAs.buf[i] == redas) @@ -58,22 +57,20 @@ void ClearEventMoveBuffer(const struct REDA * redas) //! FE8U = 0x08079D74 void MuCtr_StartDefinedMove(struct Unit * unit, const struct REDA * redas, s16 count, u16 flags) { - struct MuCtrlProc * proc = Proc_Start(gProcScr_MuCtrl, PROC_TREE_5); - - switch (count) - { - case 0: - redas = NULL; - break; - - case 1: - proc->reda_cur = *redas; - redas = &proc->reda_cur; - break; - - default: - redas = CopyEventMoveREDAs(redas, count); - break; + struct MuCtrlProc * proc = Proc_Start(ProcScr_MuCtrl, PROC_TREE_5); + switch (count) { + case 0: + redas = NULL; + break; + + case 1: + proc->reda_cur = *redas; + redas = &proc->reda_cur; + break; + + default: + redas = CopyEventMoveREDAs(redas, count); + break; } MuCtr_InitDefinedMove(proc, unit, redas, count, flags); @@ -86,7 +83,7 @@ void MuCtr_StartMoveTowards(struct Unit * unit, s8 x, s8 y, u8 flagsA, u16 flags int x_; int y_; - struct MuCtrlProc * proc = Proc_Start(gProcScr_MuCtrl, PROC_TREE_5); + struct MuCtrlProc * proc = Proc_Start(ProcScr_MuCtrl, PROC_TREE_5); reda = &proc->reda_cur; @@ -102,8 +99,6 @@ void MuCtr_StartMoveTowards(struct Unit * unit, s8 x, s8 y, u8 flagsA, u16 flags reda->delayFrames = 0; MuCtr_InitDefinedMove(proc, unit, reda, 1, flagsB); - - return; } //! FE8U = 0x08079E78 @@ -127,11 +122,11 @@ void MuCtr_InitDefinedMove(struct MuCtrlProc * proc, struct Unit * unit, const s proc->muProc = StartMu(unit); proc->redas = redas; proc->redaCount = count; - proc->unk_3a = 0; + proc->timer = 0; proc->delayFrames = redas->delayFrames; proc->flags = flags; - proc->unk_40 = pos.x; - proc->unk_41 = pos.y; + proc->x = pos.x; + proc->y = pos.y; proc->unk_42 = x; proc->unk_43 = y; @@ -153,14 +148,13 @@ void MuCtr_InitDefinedMove(struct MuCtrlProc * proc, struct Unit * unit, const s //! FE8U = 0x08079F84 s8 MuCtrExists(void) { - return Proc_Find(gProcScr_MuCtrl) ? 1 : 0; + return Proc_Find(ProcScr_MuCtrl) ? 1 : 0; } //! FE8U = 0x08079F9C -void MU_AllForceSetMaxMoveSpeed_(void) +void SetMuMaxWalkSpeed_(void) { - MU_AllForceSetMaxMoveSpeed(); - return; + SetMuMaxWalkSpeed(); } //! FE8U = 0x08079FA8 @@ -189,8 +183,6 @@ void MoveUnitExt(struct Unit * unit, const struct REDA * redas, s16 count, u16 f RefreshEntityBmMaps(); RefreshUnitSprites(); } - - return; } //! FE8U = 0x0807A014 @@ -202,8 +194,6 @@ void MoveUnit_(struct Unit * unit, s8 x, s8 y, u16 flags) reda.y = y; MoveUnitExt(unit, &reda, 1, flags); - - return; } //! FE8U = 0x0807A054 @@ -246,35 +236,31 @@ void GenUnitDefinitionFinalPosition(const struct UnitDefinition * def, s8 * xOut //! FE8U = 0x0807A0E4 s8 sub_807A0E4(struct MuCtrlProc * proc) { - const struct REDA * reda = proc->redas + proc->unk_3a; + const struct REDA * reda = proc->redas + proc->timer; - MU_SortObjLayers(); + SortMus(); - if (proc->muProc->boolForceMaxSpeed != 0) + if (proc->muProc->fast_walk_b != 0) { Proc_Goto(proc, 1); - return 0; + return false; } if (sub_807A294(reda->a, reda->b) == 1) { if (gKeyStatusPtr->heldKeys & A_BUTTON) - { proc->delayFrames -= 4; - } else - { proc->delayFrames--; - } if (proc->delayFrames < 1) { MuCtr_ExecREDA_807A358(proc); - return 0; + return false; } } - if (proc->unk_3a != 0) + if (proc->timer != 0) { struct Unit * unit = proc->unit; @@ -285,15 +271,15 @@ s8 sub_807A0E4(struct MuCtrlProc * proc) RefreshUnitSprites(); } - return 1; + return true; } //! FE8U = 0x0807A194 -s8 sub_807A194(struct MuCtrlProc * proc) +bool sub_807A194(struct MuCtrlProc * proc) { struct MuProc * muProc = proc->muProc; - MU_SortObjLayers(); + SortMus(); if (!IsMuActive(muProc)) { @@ -301,19 +287,19 @@ s8 sub_807A194(struct MuCtrlProc * proc) unit->xPos = proc->unk_42; unit->yPos = proc->unk_43; - proc->unk_3a++; + proc->timer++; - if ((proc->unk_3a < proc->redaCount && muProc->boolForceMaxSpeed == 0)) + if ((proc->timer < proc->redaCount && muProc->fast_walk_b == 0)) { - proc->delayFrames = (proc->unk_3a + proc->redas)->delayFrames; - return 0; + proc->delayFrames = (proc->timer + proc->redas)->delayFrames; + return false; } Proc_Goto(proc, 1); - return 0; + return false; } - return 1; + return true; } //! FE8U = 0x0807A1FC @@ -322,14 +308,14 @@ void MuCtr_OnEnd(struct MuCtrlProc * proc) struct MuProc * muProc = proc->muProc; struct Unit * unit = proc->unit; - if ((muProc->boolForceMaxSpeed != 0) && (proc->redaCount != 0)) + if ((muProc->fast_walk_b != 0) && (proc->redaCount != 0)) { - MoveUnit_(unit, proc->unk_40, proc->unk_41, proc->flags & 0xFFFE); + MoveUnit_(unit, proc->x, proc->y, proc->flags & 0xFFFE); } else { - unit->xPos = proc->unk_40; - unit->yPos = proc->unk_41; + unit->xPos = proc->x; + unit->yPos = proc->y; UnitFinalizeMovement(unit); ShowUnitSprite(unit); @@ -342,7 +328,7 @@ void MuCtr_OnEnd(struct MuCtrlProc * proc) } MU_End(muProc); - MU_SortObjLayers(); + SortMus(); ClearEventMoveBuffer(proc->redas); @@ -351,7 +337,7 @@ void MuCtr_OnEnd(struct MuCtrlProc * proc) // clang-format off -struct ProcCmd CONST_DATA gProcScr_MuCtrl[] = +struct ProcCmd CONST_DATA ProcScr_MuCtrl[] = { PROC_NAME("E_MuCtr"), PROC_SET_END_CB(MuCtr_OnEnd), @@ -376,19 +362,19 @@ s8 sub_807A294(u8 pid, u16 b) { if (pid == 0) { - return 1; + return true; } gUnknown_03001C35 = pid; - gUnknown_03001C34 = 1; + gUnknown_03001C34 = true; - Proc_ForEach(gProcScr_MuCtrl, (ProcFunc)sub_807A300); + Proc_ForEach(ProcScr_MuCtrl, (ProcFunc)sub_807A300); if ((gUnknown_03001C34 == 0) && (b != 0xFFFF)) { gUnknown_03001C36 = b; gUnknown_03001C34 = 0; - Proc_ForEach(gProcScr_MuCtrl, (ProcFunc)sub_807A324); + Proc_ForEach(ProcScr_MuCtrl, (ProcFunc)sub_807A324); } return gUnknown_03001C34; @@ -398,21 +384,14 @@ s8 sub_807A294(u8 pid, u16 b) void sub_807A300(struct MuCtrlProc * proc) { if (proc->unit->pCharacterData->number == gUnknown_03001C35) - { gUnknown_03001C34 = 0; - } - - return; } //! FE8U = 0x0807A324 void sub_807A324(struct MuCtrlProc * proc) { - if (proc->unit->pCharacterData->number == gUnknown_03001C35 && gUnknown_03001C36 < proc->unk_3a) - { - gUnknown_03001C34 = 1; - } - return; + if (proc->unit->pCharacterData->number == gUnknown_03001C35 && gUnknown_03001C36 < proc->timer) + gUnknown_03001C34 = true; } //! FE8U = 0x0807A358 @@ -423,13 +402,13 @@ void MuCtr_ExecREDA_807A358(struct MuCtrlProc * proc) struct Vec2 pos; struct Unit * unit = proc->unit; - const struct REDA * reda = proc->redas + proc->unk_3a; + const struct REDA * reda = proc->redas + proc->timer; u16 flagsA = proc->flags; int flagsB = flagsA; - gBmMapOther[proc->unk_41][proc->unk_40] = 0; + gBmMapOther[proc->y][proc->x] = 0; - if (proc->unk_3a < (proc->redaCount - 1)) + if (proc->timer < (proc->redaCount - 1)) { pos.x = reda->x; pos.y = reda->y; @@ -437,8 +416,8 @@ void MuCtr_ExecREDA_807A358(struct MuCtrlProc * proc) } else { - pos.x = proc->unk_40; - pos.y = proc->unk_41; + pos.x = proc->x; + pos.y = proc->y; if ((flagsA & 2) != 0) { @@ -448,7 +427,7 @@ void MuCtr_ExecREDA_807A358(struct MuCtrlProc * proc) commands = sub_807A644(unit, &pos, flagsB & 1); - gBmMapOther[proc->unk_41][proc->unk_40] = unit->pCharacterData->number; + gBmMapOther[proc->y][proc->x] = unit->pCharacterData->number; if ((proc->unk_42 != pos.x) || (proc->unk_43 != pos.y)) { @@ -514,29 +493,19 @@ void AdjustNewUnitPosition(struct Unit * unit, struct Vec2 * pos, u16 flags) s8 yCur = pos->y + iy; if ((ix == 0) && (iy == 0)) - { continue; - } if (gBmMapUnit[yCur][xCur] != 0) - { continue; - } if (gBmMapOther[yCur][xCur] != 0) - { continue; - } if (gBmMapHidden[yCur][xCur] != 0) - { continue; - } - if (((s8 **)gBmMapRange)[yCur][xCur] < 0) - { + if (gMapRangeSigned[yCur][xCur] < 0) continue; - } buf[idx].x = xCur; buf[idx].y = yCur; diff --git a/src/prep_itemscreen.c b/src/prep_itemscreen.c index e4c609bdd..17536fc85 100644 --- a/src/prep_itemscreen.c +++ b/src/prep_itemscreen.c @@ -333,7 +333,7 @@ void PrepItemScreen_SetupGfx(struct PrepItemScreenProc * proc) BG_SetPosition(2, -40, (proc->unk_34 - 4) & 0xff); BG_EnableSyncByMask(7); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); CpuFastFill(0, PAL_OBJ(0x0B), 0x20); ForceSyncUnitSpriteSheet(); diff --git a/src/prep_itemuse.c b/src/prep_itemuse.c index 2856d9237..f8a4e6e0a 100644 --- a/src/prep_itemuse.c +++ b/src/prep_itemuse.c @@ -383,7 +383,7 @@ void PrepItemUse_InitDisplay(struct ProcPrepItemUse *proc) ResetIconGraphics_(); LoadUiFrameGraphics(); LoadObjUIGfx(); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); BG_SetPosition(BG_0, 0,0); BG_SetPosition(BG_1, 0,0); diff --git a/src/prep_sallycursor.c b/src/prep_sallycursor.c index a5f97faef..0c32ddae5 100644 --- a/src/prep_sallycursor.c +++ b/src/prep_sallycursor.c @@ -953,7 +953,7 @@ void PrepScreen_StartUnitSwap(struct ProcPrepSallyCursor * proc) //! FE8U = 0x08033C90 void PrepScreen_UnitSwapIdle(struct ProcPrepSallyCursor * proc) { - s8 r7 = ((s8 **)gBmMapRange)[gBmSt.playerCursor.y][gBmSt.playerCursor.x]; + s8 r7 = gMapRangeSigned[gBmSt.playerCursor.y][gBmSt.playerCursor.x]; u32 xLoc; u32 yLoc; diff --git a/src/prep_unitselect.c b/src/prep_unitselect.c index 2f147304e..9d0fbd713 100644 --- a/src/prep_unitselect.c +++ b/src/prep_unitselect.c @@ -155,7 +155,7 @@ void PrepUnit_InitGfx() void PrepUnit_InitSMS(struct ProcPrepUnit *proc) { - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); CpuFastFill(0, PAL_OBJ(0x0B), 0x20); MakePrepUnitList(); PrepAutoCapDeployUnits(proc->proc_parent); diff --git a/src/sio_battlemap.c b/src/sio_battlemap.c index a102263a9..0924afca3 100644 --- a/src/sio_battlemap.c +++ b/src/sio_battlemap.c @@ -459,7 +459,7 @@ void sub_80497A0(void) sub_80156D4(); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); ForceSyncUnitSpriteSheet(); sub_8049788(); @@ -540,7 +540,7 @@ void sub_8049828(void) ReadGameSaveCoreGfx(); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); ResetUnitSprites(); RefreshUnitSprites(); diff --git a/src/sio_teamlist.c b/src/sio_teamlist.c index a3a344714..7433bb92f 100644 --- a/src/sio_teamlist.c +++ b/src/sio_teamlist.c @@ -521,7 +521,7 @@ void SioTeamList_SetupGfx(struct SioTeamListProc * proc) sub_8043164(); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); ResetUnitSprites(); ForceSyncUnitSpriteSheet(); diff --git a/src/sio_term.c b/src/sio_term.c index 002c5bad6..4b06d1eba 100644 --- a/src/sio_term.c +++ b/src/sio_term.c @@ -239,7 +239,7 @@ void sub_8046D6C(struct SioTermProc * proc) gPlaySt.config.windowColor = 0; gLinkArenaSt.unk_04 = proc->unk_48; - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); sub_80496A4(); BG_SetPosition(BG_1, 0, 0); diff --git a/src/statscreen.c b/src/statscreen.c index 50dc0dc79..b32d0d9a6 100644 --- a/src/statscreen.c +++ b/src/statscreen.c @@ -1513,7 +1513,7 @@ void StatScreen_InitDisplay(struct Proc* proc) BG_EnableSyncByMask(BG2_SYNC_BIT); sub_80156D4(); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); // TODO: port the macros from mapanim wip diff --git a/src/uichapterstatus.c b/src/uichapterstatus.c index 76e1eafec..7cd5be3fa 100644 --- a/src/uichapterstatus.c +++ b/src/uichapterstatus.c @@ -476,7 +476,7 @@ void sub_808DEF0(s8 flag) { CpuFastFill16(0, PAL_OBJ(0xD), 0x20); EnablePaletteSync(); } else { - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); } return; @@ -550,7 +550,7 @@ void ChapterStatus_Init(struct ChapterStatusProc* proc) { proc->numEnemyUnits = CountUnitsByFaction(FACTION_RED); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); for (i = 0; i < 2; i++) { if (proc->units[i] == 0) { diff --git a/src/uisupport.c b/src/uisupport.c index 133e03205..9f7907f52 100644 --- a/src/uisupport.c +++ b/src/uisupport.c @@ -509,7 +509,7 @@ void SupportScreen_SetupGraphics(struct SupportScreenProc* proc) { StartMuralBackgroundExt(proc, 0, 18, 2, 0); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); ResetUnitSprites(); sub_80A0EC0((void*)proc); @@ -1309,7 +1309,7 @@ void SupportSubScreen_SetupGraphics(struct SubScreenProc* proc) { LoadUiFrameGraphics(); LoadObjUIGfx(); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); sub_80A221C(); LoadIconPalettes(0xd); diff --git a/src/unitlistscreen.c b/src/unitlistscreen.c index d02a2a910..e49b4f0fb 100644 --- a/src/unitlistscreen.c +++ b/src/unitlistscreen.c @@ -907,7 +907,7 @@ void sub_8090D80(struct UnitListScreenProc * proc) ResetText(); ResetTextFont(); ResetIconGraphics(); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); CpuFastFill(0, gPaletteBuffer + 0x1B0, PLTT_SIZE_4BPP); diff --git a/src/worldmap_main.c b/src/worldmap_main.c index 418a672e9..ee19e275c 100644 --- a/src/worldmap_main.c +++ b/src/worldmap_main.c @@ -321,7 +321,7 @@ void SetupGraphicSystemsForWorldMap(void) SetupFaceGfxData(gUnknown_08A3D728); ResetUnitSprites(); InitMus(); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); gBmSt.camera.x = 0; gBmSt.camera.y = 0; diff --git a/src/worldmap_status_ui.c b/src/worldmap_status_ui.c index 754467831..da1e90bb9 100644 --- a/src/worldmap_status_ui.c +++ b/src/worldmap_status_ui.c @@ -340,7 +340,7 @@ void WorldmapStatus_InitGfx(void) BG_EnableSyncByMask(BG0_SYNC_BIT | BG1_SYNC_BIT | BG2_SYNC_BIT); ReadGameSaveCoreGfx(); - SetupMapSpritesPalettes(); + ApplyUnitSpritePalettes(); StartMuralBackground(NULL, (void *)0x0600B000, -1); Decompress(gUnknown_08A986C0, (void *)0x06003000); From 61b2defbeb9ddfc80695692ec197f03db3643ade Mon Sep 17 00:00:00 2001 From: MokhaLeee Date: Thu, 11 Jul 2024 10:56:19 +0000 Subject: [PATCH 5/7] in process --- include/bmudisp.h | 7 +- include/eventcall.h | 19 ++- include/variables.h | 2 +- src/bmudisp.c | 258 +++++++++++++++++++--------------------- src/eventcall.c | 32 ++--- src/worldmap_gmapunit.c | 2 +- 6 files changed, 159 insertions(+), 161 deletions(-) diff --git a/include/bmudisp.h b/include/bmudisp.h index 013fea884..0628d2a08 100644 --- a/include/bmudisp.h +++ b/include/bmudisp.h @@ -2,6 +2,7 @@ #define GUARD_BM_UDISP_H #define UNITSPRITE_MAX 0xD0 +#define UNITSPRITE_ID_BITS 7 // ??? sub_8026618(???); void ApplyUnitSpritePalettes(void); @@ -9,13 +10,13 @@ void ApplyUnitSpritePalettes(void); void ResetUnitSprites(void); // ??? ResetUnitSpritesB(???); int StartUiSMS(int smsId, int frameId); -int SMS_SomethingGmapUnit(int smsId, int frameId, int slot); +int StartWorldMapSMS(int smsId, int frameId, int slot); int UseUnitSprite(u32); +int ApplyUnitSpriteUiImage16x16(int, u32); int ApplyUnitSpriteImage16x16(int, u32); -int SomethingSMS_16x16(int, u32); int ApplyUnitSpriteImage16x32(int, u32); int ApplyUnitSpriteImage32x32(int, u32); -void sub_8026C1C(struct Unit*, int); +void TornOutUnitSprite(struct Unit*, int); void SyncUnitSpriteSheet(void); void ForceSyncUnitSpriteSheet(void); void sub_8026FF4(int id, u8* ptr); diff --git a/include/eventcall.h b/include/eventcall.h index 05edd70d6..ecb95fd0d 100644 --- a/include/eventcall.h +++ b/include/eventcall.h @@ -93,9 +93,22 @@ void StartEventQuakefx(ProcPtr proc); void EndEventQuakefx(ProcPtr proc); void SetEventId_0x84(ProcPtr); void UnsetEventId_0x84(ProcPtr); -void sub_8085988(struct EventEngineProc * proc); -void sub_8085990(struct EventEngineProc * proc); -void sub_80859D0(ProcPtr proc, ProcPtr parent); + +struct ProcUnitTornOut { + PROC_HEADER; + STRUCT_PAD(0x29, 0x4C); + + /* 4C */ s16 counter; + + STRUCT_PAD(0x4E, 0x54); + + /* 54 */ struct Unit * unit; +}; + +void UnitTornOut_Init(struct ProcUnitTornOut * proc); +void UnitTornOut_Loop(struct ProcUnitTornOut * proc); +void StartUnitTornOut(struct Unit * unit, ProcPtr parent); + void nullsub_20(ProcPtr); void WorldFlushInit(struct ProcWorldFlush * proc); void WorldFlushOut(struct ProcWorldFlush * proc); diff --git a/include/variables.h b/include/variables.h index 187048c23..cd4aacf6b 100644 --- a/include/variables.h +++ b/include/variables.h @@ -835,7 +835,7 @@ extern struct ProcCmd ProcScr_ForceAsyncButtonB[]; extern struct ProcCmd ProcScr_EventHorizontalQuakefx[]; extern struct ProcCmd ProcScr_EventVerticalQuakefx[]; extern struct ProcCmd ProcScr_EventQuakefx[]; -extern struct ProcCmd ProcScr_089EE068[]; +extern struct ProcCmd ProcScr_UnitTornOut[]; extern struct ProcCmd ProcScr_WorldFlush[]; extern u16 CONST_DATA Obj_089EE99C[]; extern u16 CONST_DATA *ImgLut_EventMapAnimMaskfx[]; /* images */ diff --git a/src/bmudisp.c b/src/bmudisp.c index 334a9452f..8177b3076 100644 --- a/src/bmudisp.c +++ b/src/bmudisp.c @@ -36,7 +36,7 @@ int EWRAM_DATA gSMSSyncFlag = 0; int EWRAM_DATA gMapSpriteSwitchHoverTimer = 0; -u8* CONST_DATA gpSMSGfxDecompBuffer = gGenericBuffer; +u8* CONST_DATA UnitSpriteUnpackBuf = gGenericBuffer; int CONST_DATA gSomeSMSLookupTable_859B66C[] = { 0, 8, @@ -388,11 +388,11 @@ void ResetUnitSpritesB(void) int StartUiSMS(int smsId, int frameId) { int slot = gSomeSMSLookupTable_859B66C[frameId]; - Decompress(GetInfo(smsId).sheet, gpSMSGfxDecompBuffer); + Decompress(GetInfo(smsId).sheet, UnitSpriteUnpackBuf); switch (GetInfo(smsId).size) { case UNIT_ICON_SIZE_16x16: - gUnitSpriteSlots[frameId] = SomethingSMS_16x16(slot, smsId) / 2; + gUnitSpriteSlots[frameId] = ApplyUnitSpriteUiImage16x16(slot, smsId) / 2; break; case UNIT_ICON_SIZE_16x32: @@ -407,95 +407,87 @@ int StartUiSMS(int smsId, int frameId) return gUnitSpriteSlots[frameId] << 1; } -//! FE8U = 0x0802677C -int SMS_SomethingGmapUnit(int smsId, int frameId, int slot) { - - Decompress(GetInfo(smsId).sheet, gpSMSGfxDecompBuffer); +int StartWorldMapSMS(int smsId, int frameId, int slot) +{ + Decompress(GetInfo(smsId).sheet, UnitSpriteUnpackBuf); switch (GetInfo(smsId).size) { - case UNIT_ICON_SIZE_16x16: - gUnitSpriteSlots[frameId] = SomethingSMS_16x16(slot, smsId) / 2; - - break; - - case UNIT_ICON_SIZE_16x32: - - gUnitSpriteSlots[frameId] = ApplyUnitSpriteImage16x32(slot, smsId) / 2; - - break; + case UNIT_ICON_SIZE_16x16: + gUnitSpriteSlots[frameId] = ApplyUnitSpriteUiImage16x16(slot, smsId) / 2; + break; - case UNIT_ICON_SIZE_32x32: - gUnitSpriteSlots[frameId] = ApplyUnitSpriteImage32x32(slot, smsId) / 2; + case UNIT_ICON_SIZE_16x32: + gUnitSpriteSlots[frameId] = ApplyUnitSpriteImage16x32(slot, smsId) / 2; + break; - break; + case UNIT_ICON_SIZE_32x32: + gUnitSpriteSlots[frameId] = ApplyUnitSpriteImage32x32(slot, smsId) / 2; + break; } return gUnitSpriteSlots[frameId] << 1; } -//! FE8U = 0x080267FC -int UseUnitSprite(u32 id) { - - if (gUnitSpriteSlots[id] == 0xFF) { - - Decompress(GetInfo(id).sheet, gpSMSGfxDecompBuffer); +int UseUnitSprite(u32 id) +{ + if (gUnitSpriteSlots[id] == 0xFF) + { + Decompress(GetInfo(id).sheet, UnitSpriteUnpackBuf); switch (GetInfo(id).size) { - case UNIT_ICON_SIZE_16x16: - gUnitSpriteSlots[id] = ApplyUnitSpriteImage16x16(gSMS16xGfxIndexCounter, id) / 2; - gSMS16xGfxIndexCounter -= 1; + case UNIT_ICON_SIZE_16x16: + gUnitSpriteSlots[id] = ApplyUnitSpriteImage16x16(gSMS16xGfxIndexCounter, id) / 2; + gSMS16xGfxIndexCounter -= 1; + break; - break; + case UNIT_ICON_SIZE_16x32: + gUnitSpriteSlots[id] = ApplyUnitSpriteImage16x32(gSMS32xGfxIndexCounter, id) / 2; + gSMS32xGfxIndexCounter += 2; + break; - case UNIT_ICON_SIZE_16x32: - gUnitSpriteSlots[id] = ApplyUnitSpriteImage16x32(gSMS32xGfxIndexCounter, id) / 2; + case UNIT_ICON_SIZE_32x32: + if ((gSMS32xGfxIndexCounter & 0x1E) == 0x1E) gSMS32xGfxIndexCounter += 2; - break; - - case UNIT_ICON_SIZE_32x32: - if ((gSMS32xGfxIndexCounter & 0x1e) == 0x1e) { - gSMS32xGfxIndexCounter += 2; - } - - gUnitSpriteSlots[id] = ApplyUnitSpriteImage32x32(gSMS32xGfxIndexCounter, id) / 2; - gSMS32xGfxIndexCounter += 4; - - break; + gUnitSpriteSlots[id] = ApplyUnitSpriteImage32x32(gSMS32xGfxIndexCounter, id) / 2; + gSMS32xGfxIndexCounter += 4; + break; } gSMSSyncFlag++; } - return gUnitSpriteSlots[id] << 1; } -//! FE8U = 0x080268C8 -int ApplyUnitSpriteImage16x16(int slot, u32 id) { +int ApplyUnitSpriteImage16x16(int slot, u32 id) +{ int i; - int outOff = sSlotToChrLut[slot] * CHR_SIZE; - id = ((id >> 7) ^ 1) & 1; + id = ((id >> UNITSPRITE_ID_BITS) ^ 1) & 1; - for (i = 0; i < 3; i++) { + for (i = 0; i < 3; i++) + { int imgOff = (i * id) * 4 * CHR_SIZE; - CpuFastCopy(gpSMSGfxDecompBuffer + 0 * CHR_SIZE + imgOff, gSMSGfxBuffer[i] + 0 * CHR_SIZE * CHR_LINE + outOff, 2 * CHR_SIZE); - CpuFastCopy(gpSMSGfxDecompBuffer + 2 * CHR_SIZE + imgOff, gSMSGfxBuffer[i] + 1 * CHR_SIZE * CHR_LINE + outOff, 2 * CHR_SIZE); + CpuFastCopy( + UnitSpriteUnpackBuf + 0 * CHR_SIZE + imgOff, + gSMSGfxBuffer[i] + 0 * CHR_SIZE * CHR_LINE + outOff, 2 * CHR_SIZE); + CpuFastCopy( + UnitSpriteUnpackBuf + 2 * CHR_SIZE + imgOff, + gSMSGfxBuffer[i] + 1 * CHR_SIZE * CHR_LINE + outOff, 2 * CHR_SIZE); } - return sSlotToChrLut[slot]; } -//! FE8U = 0x0802695C -int SomethingSMS_16x16(int slot, u32 id) { +int ApplyUnitSpriteUiImage16x16(int slot, u32 id) +{ int i; - int outOff = sSlotToChrLut[slot] * CHR_SIZE; - id = ((id >> 7) ^ 1) & 1; + id = ((id >> UNITSPRITE_ID_BITS) ^ 1) & 1; - for (i = 0; i < 3; i++) { + for (i = 0; i < 3; i++) + { int imgOff = (i * id) * 4 * CHR_SIZE; CpuFastFill( @@ -510,63 +502,59 @@ int SomethingSMS_16x16(int slot, u32 id) { ); CpuFastCopy( - gpSMSGfxDecompBuffer + 0 * CHR_SIZE + imgOff, + UnitSpriteUnpackBuf + 0 * CHR_SIZE + imgOff, gSMSGfxBuffer[i] + 2 * CHR_SIZE * CHR_LINE + outOff, 2 * CHR_SIZE ); CpuFastCopy( - gpSMSGfxDecompBuffer + 2 * CHR_SIZE + imgOff, + UnitSpriteUnpackBuf + 2 * CHR_SIZE + imgOff, gSMSGfxBuffer[i] + 3 * CHR_SIZE * CHR_LINE + outOff, 2 * CHR_SIZE ); } - return sSlotToChrLut[slot]; } -//! FE8U = 0x08026A38 -int ApplyUnitSpriteImage16x32(int slot, u32 id) { - +int ApplyUnitSpriteImage16x32(int slot, u32 id) +{ int i; int outOff = sSlotToChrLut[slot] * CHR_SIZE; - id = ((id >> 7) ^ 1) & 1; + id = ((id >> UNITSPRITE_ID_BITS) ^ 1) & 1; - for (i = 0; i < 3; i++) { + for (i = 0; i < 3; i++) + { int imgOff = (i * id) * 8 * CHR_SIZE; - CpuFastCopy(gpSMSGfxDecompBuffer + 0 * CHR_SIZE + imgOff, gSMSGfxBuffer[i] + 0 * CHR_SIZE * CHR_LINE + outOff, 2 * CHR_SIZE); - CpuFastCopy(gpSMSGfxDecompBuffer + 2 * CHR_SIZE + imgOff, gSMSGfxBuffer[i] + 1 * CHR_SIZE * CHR_LINE + outOff, 2 * CHR_SIZE); - CpuFastCopy(gpSMSGfxDecompBuffer + 4 * CHR_SIZE + imgOff, gSMSGfxBuffer[i] + 2 * CHR_SIZE * CHR_LINE + outOff, 2 * CHR_SIZE); - CpuFastCopy(gpSMSGfxDecompBuffer + 6 * CHR_SIZE + imgOff, gSMSGfxBuffer[i] + 3 * CHR_SIZE * CHR_LINE + outOff, 2 * CHR_SIZE); + CpuFastCopy(UnitSpriteUnpackBuf + 0 * CHR_SIZE + imgOff, gSMSGfxBuffer[i] + 0 * CHR_SIZE * CHR_LINE + outOff, 2 * CHR_SIZE); + CpuFastCopy(UnitSpriteUnpackBuf + 2 * CHR_SIZE + imgOff, gSMSGfxBuffer[i] + 1 * CHR_SIZE * CHR_LINE + outOff, 2 * CHR_SIZE); + CpuFastCopy(UnitSpriteUnpackBuf + 4 * CHR_SIZE + imgOff, gSMSGfxBuffer[i] + 2 * CHR_SIZE * CHR_LINE + outOff, 2 * CHR_SIZE); + CpuFastCopy(UnitSpriteUnpackBuf + 6 * CHR_SIZE + imgOff, gSMSGfxBuffer[i] + 3 * CHR_SIZE * CHR_LINE + outOff, 2 * CHR_SIZE); } - return sSlotToChrLut[slot]; } -//! FE8U = 0x08026B28 -int ApplyUnitSpriteImage32x32(int slot, u32 id) { +int ApplyUnitSpriteImage32x32(int slot, u32 id) +{ int i; - int outOff = sSlotToChrLut[slot] * CHR_SIZE; - id = ((id >> 7) ^ 1) & 1; + id = ((id >> UNITSPRITE_ID_BITS) ^ 1) & 1; - for (i = 0; i < 3; i++) { + for (i = 0; i < 3; i++) + { int imgOff = (i * id) * 16 * CHR_SIZE; - CpuFastCopy(gpSMSGfxDecompBuffer + 0 * CHR_SIZE + imgOff, gSMSGfxBuffer[i] + 0 * CHR_SIZE * CHR_LINE + outOff, 4 * CHR_SIZE); - CpuFastCopy(gpSMSGfxDecompBuffer + 4 * CHR_SIZE + imgOff, gSMSGfxBuffer[i] + 1 * CHR_SIZE * CHR_LINE + outOff, 4 * CHR_SIZE); - CpuFastCopy(gpSMSGfxDecompBuffer + 8 * CHR_SIZE + imgOff, gSMSGfxBuffer[i] + 2 * CHR_SIZE * CHR_LINE + outOff, 4 * CHR_SIZE); - CpuFastCopy(gpSMSGfxDecompBuffer + 12 * CHR_SIZE + imgOff, gSMSGfxBuffer[i] + 3 * CHR_SIZE * CHR_LINE + outOff, 4 * CHR_SIZE); + CpuFastCopy(UnitSpriteUnpackBuf + 0 * CHR_SIZE + imgOff, gSMSGfxBuffer[i] + 0 * CHR_SIZE * CHR_LINE + outOff, 4 * CHR_SIZE); + CpuFastCopy(UnitSpriteUnpackBuf + 4 * CHR_SIZE + imgOff, gSMSGfxBuffer[i] + 1 * CHR_SIZE * CHR_LINE + outOff, 4 * CHR_SIZE); + CpuFastCopy(UnitSpriteUnpackBuf + 8 * CHR_SIZE + imgOff, gSMSGfxBuffer[i] + 2 * CHR_SIZE * CHR_LINE + outOff, 4 * CHR_SIZE); + CpuFastCopy(UnitSpriteUnpackBuf + 12 * CHR_SIZE + imgOff, gSMSGfxBuffer[i] + 3 * CHR_SIZE * CHR_LINE + outOff, 4 * CHR_SIZE); } - return sSlotToChrLut[slot]; } -//! FE8U = 0x08026C1C -void sub_8026C1C(struct Unit* param_1, int param_2) { +void TornOutUnitSprite(struct Unit * param_1, int param_2) { u8 r4; u16 r6; int r7; @@ -586,84 +574,78 @@ void sub_8026C1C(struct Unit* param_1, int param_2) { if (i >= 0) r4 = 0; switch (GetInfo(sp04).size) { - case 0: - for (i = 0; i < 3; i++) { - for (j = 0; j < 2; j++) { - { int offset = 0 * CHR_SIZE * CHR_LINE + j * CHR_SIZE; gSMSGfxBuffer[i][r7 + offset + (r6 >> 1)] &= 0xf << (!(r6 & 1) << 2); } - { int offset = 1 * CHR_SIZE * CHR_LINE + j * CHR_SIZE; gSMSGfxBuffer[i][r7 + offset + (r6 >> 1)] &= 0xf << (!(r6 & 1) << 2); } - } + case 0: + for (i = 0; i < 3; i++) + { + for (j = 0; j < 2; j++) + { + { int offset = 0 * CHR_SIZE * CHR_LINE + j * CHR_SIZE; gSMSGfxBuffer[i][r7 + offset + (r6 >> 1)] &= 0xf << (!(r6 & 1) << 2); } + { int offset = 1 * CHR_SIZE * CHR_LINE + j * CHR_SIZE; gSMSGfxBuffer[i][r7 + offset + (r6 >> 1)] &= 0xf << (!(r6 & 1) << 2); } } + } - CpuFastCopy(&gSMSGfxBuffer[r4][r7 + 0 * CHR_SIZE * CHR_LINE], (u8*)(r7 + 0x06011000), 2 * CHR_SIZE); - CpuFastCopy(&gSMSGfxBuffer[r4][r7 + 1 * CHR_SIZE * CHR_LINE], (u8*)(r7 + 0x06011400), 2 * CHR_SIZE); - - break; + CpuFastCopy(&gSMSGfxBuffer[r4][r7 + 0 * CHR_SIZE * CHR_LINE], (u8*)(r7 + 0x06011000), 2 * CHR_SIZE); + CpuFastCopy(&gSMSGfxBuffer[r4][r7 + 1 * CHR_SIZE * CHR_LINE], (u8*)(r7 + 0x06011400), 2 * CHR_SIZE); + break; - case 1: - for (i = 0; i < 3; i++) { - int var = 2; // for reordering the unrolled expressions - for (j = 0; j < 2; j++) { - { int offset = 0 * CHR_SIZE * CHR_LINE + j * CHR_SIZE; gSMSGfxBuffer[i][r7 + offset + (r6 >> 1)] &= 0xf << (!(r6 & 1) << var); } - { int offset = 1 * CHR_SIZE * CHR_LINE + j * CHR_SIZE; gSMSGfxBuffer[i][r7 + offset + (r6 >> 1)] &= 0xf << (!(r6 & 1) << 2); } - { int offset = 2 * CHR_SIZE * CHR_LINE + j * CHR_SIZE; gSMSGfxBuffer[i][r7 + offset + (r6 >> 1)] &= 0xf << (!(r6 & 1) << 2); } - { int offset = 3 * CHR_SIZE * CHR_LINE + j * CHR_SIZE; gSMSGfxBuffer[i][r7 + offset + (r6 >> 1)] &= 0xf << (!(r6 & 1) << 2); } - } + case 1: + for (i = 0; i < 3; i++) + { + int var = 2; // for reordering the unrolled expressions + for (j = 0; j < 2; j++) + { + { int offset = 0 * CHR_SIZE * CHR_LINE + j * CHR_SIZE; gSMSGfxBuffer[i][r7 + offset + (r6 >> 1)] &= 0xf << (!(r6 & 1) << var); } + { int offset = 1 * CHR_SIZE * CHR_LINE + j * CHR_SIZE; gSMSGfxBuffer[i][r7 + offset + (r6 >> 1)] &= 0xf << (!(r6 & 1) << 2); } + { int offset = 2 * CHR_SIZE * CHR_LINE + j * CHR_SIZE; gSMSGfxBuffer[i][r7 + offset + (r6 >> 1)] &= 0xf << (!(r6 & 1) << 2); } + { int offset = 3 * CHR_SIZE * CHR_LINE + j * CHR_SIZE; gSMSGfxBuffer[i][r7 + offset + (r6 >> 1)] &= 0xf << (!(r6 & 1) << 2); } } + } - CpuFastCopy(&gSMSGfxBuffer[r4][r7 + 0 * CHR_SIZE * CHR_LINE], (u8*)(r7 + 0x06011000), 2 * CHR_SIZE); - CpuFastCopy(&gSMSGfxBuffer[r4][r7 + 1 * CHR_SIZE * CHR_LINE], (u8*)(r7 + 0x06011400), 2 * CHR_SIZE); - CpuFastCopy(&gSMSGfxBuffer[r4][r7 + 2 * CHR_SIZE * CHR_LINE], (u8*)(r7 + 0x06011800), 2 * CHR_SIZE); - CpuFastCopy(&gSMSGfxBuffer[r4][r7 + 3 * CHR_SIZE * CHR_LINE], (u8*)(r7 + 0x06011C00), 2 * CHR_SIZE); - - break; + CpuFastCopy(&gSMSGfxBuffer[r4][r7 + 0 * CHR_SIZE * CHR_LINE], (u8*)(r7 + 0x06011000), 2 * CHR_SIZE); + CpuFastCopy(&gSMSGfxBuffer[r4][r7 + 1 * CHR_SIZE * CHR_LINE], (u8*)(r7 + 0x06011400), 2 * CHR_SIZE); + CpuFastCopy(&gSMSGfxBuffer[r4][r7 + 2 * CHR_SIZE * CHR_LINE], (u8*)(r7 + 0x06011800), 2 * CHR_SIZE); + CpuFastCopy(&gSMSGfxBuffer[r4][r7 + 3 * CHR_SIZE * CHR_LINE], (u8*)(r7 + 0x06011C00), 2 * CHR_SIZE); + break; - case 2: - for (i = 0; i < 3; i++) { - int var = 2; - for (j = 0; j < 4; j++) { - { int offset = 0 * CHR_SIZE * CHR_LINE + j * CHR_SIZE; gSMSGfxBuffer[i][r7 + offset + (r6 >> 1)] &= 0xf << (!(r6 & 1) << var); } - { int offset = 1 * CHR_SIZE * CHR_LINE + j * CHR_SIZE; gSMSGfxBuffer[i][r7 + offset + (r6 >> 1)] &= 0xf << (!(r6 & 1) << 2); } - { int offset = 2 * CHR_SIZE * CHR_LINE + j * CHR_SIZE; gSMSGfxBuffer[i][r7 + offset + (r6 >> 1)] &= 0xf << (!(r6 & 1) << 2); } - { int offset = 3 * CHR_SIZE * CHR_LINE + j * CHR_SIZE; gSMSGfxBuffer[i][r7 + offset + (r6 >> 1)] &= 0xf << (!(r6 & 1) << 2); } - } + case 2: + for (i = 0; i < 3; i++) + { + int var = 2; + for (j = 0; j < 4; j++) + { + { int offset = 0 * CHR_SIZE * CHR_LINE + j * CHR_SIZE; gSMSGfxBuffer[i][r7 + offset + (r6 >> 1)] &= 0xf << (!(r6 & 1) << var); } + { int offset = 1 * CHR_SIZE * CHR_LINE + j * CHR_SIZE; gSMSGfxBuffer[i][r7 + offset + (r6 >> 1)] &= 0xf << (!(r6 & 1) << 2); } + { int offset = 2 * CHR_SIZE * CHR_LINE + j * CHR_SIZE; gSMSGfxBuffer[i][r7 + offset + (r6 >> 1)] &= 0xf << (!(r6 & 1) << 2); } + { int offset = 3 * CHR_SIZE * CHR_LINE + j * CHR_SIZE; gSMSGfxBuffer[i][r7 + offset + (r6 >> 1)] &= 0xf << (!(r6 & 1) << 2); } } + } - CpuFastCopy(&gSMSGfxBuffer[r4][r7 + 0 * CHR_SIZE * CHR_LINE], (u8*)(r7 + 0x06011000), 4 * CHR_SIZE); - CpuFastCopy(&gSMSGfxBuffer[r4][r7 + 1 * CHR_SIZE * CHR_LINE], (u8*)(r7 + 0x06011400), 4 * CHR_SIZE); - CpuFastCopy(&gSMSGfxBuffer[r4][r7 + 2 * CHR_SIZE * CHR_LINE], (u8*)(r7 + 0x06011800), 4 * CHR_SIZE); - CpuFastCopy(&gSMSGfxBuffer[r4][r7 + 3 * CHR_SIZE * CHR_LINE], (u8*)(r7 + 0x06011C00), 4 * CHR_SIZE); - - break; - + CpuFastCopy(&gSMSGfxBuffer[r4][r7 + 0 * CHR_SIZE * CHR_LINE], (u8*)(r7 + 0x06011000), 4 * CHR_SIZE); + CpuFastCopy(&gSMSGfxBuffer[r4][r7 + 1 * CHR_SIZE * CHR_LINE], (u8*)(r7 + 0x06011400), 4 * CHR_SIZE); + CpuFastCopy(&gSMSGfxBuffer[r4][r7 + 2 * CHR_SIZE * CHR_LINE], (u8*)(r7 + 0x06011800), 4 * CHR_SIZE); + CpuFastCopy(&gSMSGfxBuffer[r4][r7 + 3 * CHR_SIZE * CHR_LINE], (u8*)(r7 + 0x06011C00), 4 * CHR_SIZE); + break; } - if (param_2 == 0x3f) { + if (param_2 == 0x3f) gUnitSpriteSlots[sp04] |= 0xff; - } - return; } -//! FE8U = 0x08026F2C -void SyncUnitSpriteSheet(void) { +void SyncUnitSpriteSheet(void) +{ int frame = GetGameClock() % 72; - if (frame == 0) { + if (frame == 0) CpuFastCopy(gSMSGfxBuffer[0], (void*)0x06011000, sizeof(gSMSGfxBuffer[0])); - } - if (frame == 32) { + if (frame == 32) CpuFastCopy(gSMSGfxBuffer[1], (void*)0x06011000, sizeof(gSMSGfxBuffer[1])); - } - if (frame == 36) { + if (frame == 36) CpuFastCopy(gSMSGfxBuffer[2], (void*)0x06011000, sizeof(gSMSGfxBuffer[2])); - } - if (frame == 68) { + if (frame == 68) CpuFastCopy(gSMSGfxBuffer[1], (void*)0x06011000, sizeof(gSMSGfxBuffer[1])); - } - - return; } //! FE8U = 0x08026F94 diff --git a/src/eventcall.c b/src/eventcall.c index bb3e16d57..bb75cbc63 100644 --- a/src/eventcall.c +++ b/src/eventcall.c @@ -410,37 +410,39 @@ void UnsetEventId_0x84(ProcPtr proc) ClearFlag(0x84); } -void sub_8085988(struct EventEngineProc * proc) +void UnitTornOut_Init(struct ProcUnitTornOut * proc) { - proc->unitLoadCount = 0; + proc->counter = 0; } -void sub_8085990(struct EventEngineProc * proc) +void UnitTornOut_Loop(struct ProcUnitTornOut * proc) { struct Unit * unit = proc->unit; - int count = proc->unitLoadCount; - sub_8026C1C(unit, count); - - if (63 == proc->unitLoadCount++) { + int count = proc->counter; + + TornOutUnitSprite(unit, count); + + if (proc->counter++ == 63) + { unit->state |= US_HIDDEN | US_NOT_DEPLOYED; RefreshEntityBmMaps(); RefreshUnitSprites(); Proc_Break(proc); - } + } } -CONST_DATA struct ProcCmd ProcScr_089EE068[] = { +CONST_DATA struct ProcCmd ProcScr_UnitTornOut[] = { PROC_YIELD, - PROC_CALL(sub_8085988), - PROC_REPEAT(sub_8085990), + PROC_CALL(UnitTornOut_Init), + PROC_REPEAT(UnitTornOut_Loop), PROC_END }; -void sub_80859D0(ProcPtr proc, ProcPtr parent) +void StartUnitTornOut(struct Unit * unit, ProcPtr parent) { - struct Proc89EE068 *_proc; - _proc = Proc_Start(ProcScr_089EE068, parent); - _proc->unk_proc = proc; + struct ProcUnitTornOut * proc; + proc = Proc_Start(ProcScr_UnitTornOut, parent); + proc->unit = unit; } void nullsub_20(ProcPtr proc) diff --git a/src/worldmap_gmapunit.c b/src/worldmap_gmapunit.c index 4ff004428..c931e9e41 100644 --- a/src/worldmap_gmapunit.c +++ b/src/worldmap_gmapunit.c @@ -179,7 +179,7 @@ int NewMapUnit(struct GMapUnitContainerProc * container, u16 classId, int factio mapUnitProc->unk_38 = classId; mapUnitProc->unk_3a = classId; - SMS_SomethingGmapUnit(GetClassSMSId(classId), mapUnitProc->index, gUnknown_08205F7C[mapUnitProc->index]); + StartWorldMapSMS(GetClassSMSId(classId), mapUnitProc->index, gUnknown_08205F7C[mapUnitProc->index]); mapUnitProc->unk_2c = 8; ap = AP_Create(MMS_GetROMTCS2(classId), 8); From 451cbcd3422bafee61cbced95c15fa78aac14ff8 Mon Sep 17 00:00:00 2001 From: MokhaLeee Date: Thu, 11 Jul 2024 11:25:09 +0000 Subject: [PATCH 6/7] review done --- include/bmudisp.h | 8 +- include/bmunit.h | 2 +- include/eventcall.h | 2 +- include/mu.h | 16 +- include/types.h | 2 +- src/banim-efxmagic-healstaves.c | 2 +- src/banim-efxstatusunit.c | 2 +- src/banim-ekrbattlestarting.c | 2 +- src/bmbattle.c | 2 +- src/bmdifficulty.c | 2 +- src/bmmenu.c | 4 +- src/bmmind.c | 8 +- src/bmtrap.c | 8 +- src/bmudisp.c | 790 ++++++++++++++------------------ src/bmusailment.c | 8 +- src/bmusemind.c | 2 +- src/classchg-event.c | 2 +- src/classchg-handler.c | 2 +- src/classchg-sel.c | 2 +- src/cp_perform.c | 4 +- src/event.c | 2 +- src/eventcall.c | 12 +- src/eventscr.c | 10 +- src/eventscr3.c | 2 +- src/gamecontrol.c | 2 +- src/gameoverbgfx.c | 2 +- src/koido.c | 2 +- src/mapanim.c | 2 +- src/mapanim_debug.c | 2 +- src/mapanim_specialeffect.c | 4 +- src/mapanim_spellassoc.c | 2 +- src/mu.c | 28 +- src/muctrl.c | 2 +- src/playerphase.c | 24 +- src/prep_atmenu.c | 2 +- src/prep_itemsupply.c | 2 +- src/prep_sallycursor.c | 6 +- src/sio_battlemap.c | 36 +- src/statscreen.c | 4 +- src/uiarena.c | 2 +- src/unitlistscreen.c | 4 +- src/worldmap_gmapunit.c | 2 +- src/worldmap_status_ui.c | 4 +- 43 files changed, 451 insertions(+), 577 deletions(-) diff --git a/include/bmudisp.h b/include/bmudisp.h index 0628d2a08..ad4d0c564 100644 --- a/include/bmudisp.h +++ b/include/bmudisp.h @@ -16,16 +16,16 @@ int ApplyUnitSpriteUiImage16x16(int, u32); int ApplyUnitSpriteImage16x16(int, u32); int ApplyUnitSpriteImage16x32(int, u32); int ApplyUnitSpriteImage32x32(int, u32); -void TornOutUnitSprite(struct Unit*, int); +void TornOutUnitSprite(struct Unit * unit, int time); void SyncUnitSpriteSheet(void); void ForceSyncUnitSpriteSheet(void); void sub_8026FF4(int id, u8* ptr); -void sub_8027068(int id, u8* ptr); -void sub_80270DC(int frameId, u8* dst); +void SetStandingMuFacing(int id, u8* ptr); +void SetStandingMuFacingWM(int frameId, u8* dst); int GetUnitDisplayedSpritePalette(const struct Unit * unit); int GetUnitSpritePalette(const struct Unit* unit); void RefreshUnitSprites(void); -struct SMSHandle* AddUnitSprite(int); +struct SMSHandle * AddUnitSprite(int); void PutUnitSpritesOam(void); // ??? PutChapterMarkedTileIconOam(???); void PutUnitSpriteIconsOam(void); diff --git a/include/bmunit.h b/include/bmunit.h index 1ee2800ab..087974fff 100644 --- a/include/bmunit.h +++ b/include/bmunit.h @@ -170,7 +170,7 @@ struct Unit /* 3A */ u8 _u3A; /* 3B */ u8 _u3B; - /* 3C */ struct SMSHandle* pMapSpriteHandle; + /* 3C */ struct SMSHandle * pMapSpriteHandle; /* 40 */ u16 ai_config; // a bitmask /* 42 */ u8 ai1; // enum to gAi1ScriptTable diff --git a/include/eventcall.h b/include/eventcall.h index ecb95fd0d..8970ff6db 100644 --- a/include/eventcall.h +++ b/include/eventcall.h @@ -98,7 +98,7 @@ struct ProcUnitTornOut { PROC_HEADER; STRUCT_PAD(0x29, 0x4C); - /* 4C */ s16 counter; + /* 4C */ s16 timer; STRUCT_PAD(0x4E, 0x54); diff --git a/include/mu.h b/include/mu.h index 2edbe8522..3d8500cae 100644 --- a/include/mu.h +++ b/include/mu.h @@ -251,19 +251,19 @@ void Mu_OnStateNone(struct MuProc * proc); void Mu_OnStateDoNothing(struct MuProc * proc); void Mu_OnStateMovement(struct MuProc * proc); void UpdateMuStepSounds(struct MuProc * proc); -void MU_OnLoop(struct MuProc * proc); +void Mu_OnLoop(struct MuProc * proc); void MU_OnEnd(struct MuProc * proc); -void MU_EndAll(void); -void MU_End(struct MuProc * proc); -void MU_EndInternal(struct MuProc * proc); +void EndAllMus(void); +void EndMu(struct MuProc * proc); +void EndMuExt(struct MuProc * proc); void HaltMu(struct MuProc * proc); -void MU_AllDisable(void); -void MU_AllEnable(void); +void LockMus(void); +void ReleaseMus(void); void ApplyMoveScriptToCoordinates(int * xOut, int * yOut, const u8 * commands); s8 CanStartMu(void); void ResetMuAnims(void); -static struct MuConfig * GetDefaultMuConfig(int objTileId, u8 * outIndex); -static struct MuConfig * GetNewMuConfig(int objTileId, u8 * outIndex); +struct MuConfig * GetDefaultMuConfig(int objTileId, u8 * outIndex); +struct MuConfig * GetNewMuConfig(int objTileId, u8 * outIndex); u8 GetMuDisplayPosition(struct MuProc * proc, struct Vec2 * out); void PutMuSMS(struct MuProc * proc); void PutMu(struct MuProc * proc); diff --git a/include/types.h b/include/types.h index c6bce8e84..d905d3c22 100644 --- a/include/types.h +++ b/include/types.h @@ -370,7 +370,7 @@ enum struct SMSHandle { - /* 00 */ struct SMSHandle* pNext; + /* 00 */ struct SMSHandle * pNext; /* 04 */ short xDisplay; /* 06 */ short yDisplay; diff --git a/src/banim-efxmagic-healstaves.c b/src/banim-efxmagic-healstaves.c index 64a2372c8..b992fe5ed 100644 --- a/src/banim-efxmagic-healstaves.c +++ b/src/banim-efxmagic-healstaves.c @@ -1687,7 +1687,7 @@ void efxRest_Loop_Main(struct ProcEfx * proc) RefreshEntityBmMaps(); RefreshUnitSprites(); - MU_EndAll(); + EndAllMus(); } SetUnitEfxDebuff(anim, 0); diff --git a/src/banim-efxstatusunit.c b/src/banim-efxstatusunit.c index 1961858b5..2b1587918 100644 --- a/src/banim-efxstatusunit.c +++ b/src/banim-efxstatusunit.c @@ -224,7 +224,7 @@ void EfxStatusUnitMain(struct ProcEfxStatusUnit *proc) RefreshEntityBmMaps(); RefreshUnitSprites(); - MU_EndAll(); + EndAllMus(); break; case UNIT_STATUS_SILENCED: diff --git a/src/banim-ekrbattlestarting.c b/src/banim-ekrbattlestarting.c index 3d30ac086..253ef6002 100644 --- a/src/banim-ekrbattlestarting.c +++ b/src/banim-ekrbattlestarting.c @@ -154,7 +154,7 @@ void ekrBaStart_SreenFailIn(struct ProcEkrBattleStarting *proc) SetWin0Box(0, 0, 0xF0, 0xA0); EfxPalBlackInOut(gPaletteBuffer, 0x6, 0xA, 0x4); EnablePaletteSync(); - MU_EndAll(); + EndAllMus(); Proc_Break(proc); } } diff --git a/src/bmbattle.c b/src/bmbattle.c index d8bdb707b..c7936aa4b 100644 --- a/src/bmbattle.c +++ b/src/bmbattle.c @@ -2033,7 +2033,7 @@ void BeginBattleAnimations(void) { SetBanimLinkArenaFlag(0); BeginAnimsOnBattleAnimations(); } else { - MU_EndAll(); + EndAllMus(); RenderBmMap(); BeginBattleMapAnims(); diff --git a/src/bmdifficulty.c b/src/bmdifficulty.c index d33455287..2a12abf07 100644 --- a/src/bmdifficulty.c +++ b/src/bmdifficulty.c @@ -474,7 +474,7 @@ struct ProcCmd CONST_DATA sProcScr_DisplayDungeonRecord_AfterDungeonClear[] = { PROC_CALL(StartMidFadeToBlack), PROC_REPEAT(WaitForFade), PROC_CALL(BMapDispSuspend), - PROC_CALL(MU_EndAll), + PROC_CALL(EndAllMus), PROC_SLEEP(0), PROC_CALL(sub_8038230), PROC_CALL(SetupDungeonRecordUi), diff --git a/src/bmmenu.c b/src/bmmenu.c index 36fb71dde..fa59a0873 100644 --- a/src/bmmenu.c +++ b/src/bmmenu.c @@ -2202,7 +2202,7 @@ u8 RideCommandEffect(struct MenuProc* menu, struct MenuItemProc* menuItem) { gActionData.unitActionType = UNIT_ACTION_RIDE_BALLISTA; RideBallista(gActiveUnit); - MU_EndAll(); + EndAllMus(); StartMu(gActiveUnit); return MENU_ACT_SKIPCURSOR | MENU_ACT_END | MENU_ACT_SND6A | MENU_ACT_CLEAR; @@ -2225,7 +2225,7 @@ u8 ExitCommandEffect(struct MenuProc* menu, struct MenuItemProc* menuItem) { gActionData.unitActionType = UNIT_ACTION_EXIT_BALLISTA; TryRemoveUnitFromBallista(gActiveUnit); - MU_EndAll(); + EndAllMus(); StartMu(gActiveUnit); return MENU_ACT_SKIPCURSOR | MENU_ACT_END | MENU_ACT_SND6A | MENU_ACT_CLEAR; diff --git a/src/bmmind.c b/src/bmmind.c index 447e43736..d75ad51ba 100644 --- a/src/bmmind.c +++ b/src/bmmind.c @@ -400,7 +400,7 @@ s8 ActionSteal(ProcPtr proc) { gBattleTarget.weapon = item; BattleApplyMiscAction(proc); - MU_EndAll(); + EndAllMus(); BeginMapAnimForSteal(); return 0; @@ -411,7 +411,7 @@ s8 ActionSummon(ProcPtr proc) { InitBattleUnit(&gBattleActor, gActiveUnit); BattleApplyMiscAction(proc); - MU_EndAll(); + EndAllMus(); BeginMapAnimForSummon(); return 0; @@ -422,7 +422,7 @@ s8 ActionSummonDK(ProcPtr proc) { InitBattleUnit(&gBattleActor, gActiveUnit); BattleApplyMiscAction(proc); - MU_EndAll(); + EndAllMus(); BeginMapAnimForSummonDK(); return 0; @@ -594,7 +594,7 @@ void BATTLE_PostCombatDeathFades(struct CombatActionProc* proc) { //! FE8U = 0x08032860 void BATTLE_DeleteLinkedMOVEUNIT(struct CombatActionProc* proc) { - MU_End(proc->unk_54); + EndMu(proc->unk_54); return; } diff --git a/src/bmtrap.c b/src/bmtrap.c index 900d03adc..d97e21db9 100644 --- a/src/bmtrap.c +++ b/src/bmtrap.c @@ -78,17 +78,17 @@ void ApplyTrapDamageAnim(struct ProcBmTrap * proc) switch (proc->post_exec_type) { case 0: - MU_EndAll(); + EndAllMus(); break; case 1: - MU_EndAll(); + EndAllMus(); StartMu(gActiveUnit); SetAutoMuDefaultFacing(); break; case 2: - MU_End(GetUnitMu(unit)); + EndMu(GetUnitMu(unit)); break; } @@ -226,7 +226,7 @@ bool ExecTrapAfterWarp(ProcPtr proc) bool ExecTrapAfterDropAction(ProcPtr proc, struct Unit * unit) { if (!GetPickTrapType(unit)) { - MU_End(GetUnitMu(unit)); + EndMu(GetUnitMu(unit)); RenderBmMap(); RefreshEntityBmMaps(); ForceSyncUnitSpriteSheet(); diff --git a/src/bmudisp.c b/src/bmudisp.c index 8177b3076..4be7616df 100644 --- a/src/bmudisp.c +++ b/src/bmudisp.c @@ -30,7 +30,7 @@ int EWRAM_DATA gSMS16xGfxIndexCounter = 0; int EWRAM_DATA gSMS32xGfxIndexCounter = 0; struct SMSHandle EWRAM_DATA gSMSHandleArray[100] = {}; -struct SMSHandle* EWRAM_DATA gSMSHandleIt = NULL; +struct SMSHandle * EWRAM_DATA gSMSHandleIt = NULL; int EWRAM_DATA gSMSSyncFlag = 0; @@ -554,16 +554,17 @@ int ApplyUnitSpriteImage32x32(int slot, u32 id) return sSlotToChrLut[slot]; } -void TornOutUnitSprite(struct Unit * param_1, int param_2) { +void TornOutUnitSprite(struct Unit * unit, int timer) +{ u8 r4; u16 r6; int r7; int i, j; - int sp04; + int slot; - sp04 = GetUnitSMSId(param_1); - r7 = UseUnitSprite(sp04) * 0x20; - r6 = gUnknown_0859B73C[param_2]; + slot = GetUnitSMSId(unit); + r7 = UseUnitSprite(slot) * 0x20; + r6 = gUnknown_0859B73C[timer]; r4 = 0; i = GetGameClock() % 0x48; @@ -573,7 +574,7 @@ void TornOutUnitSprite(struct Unit * param_1, int param_2) { if (i >= 0x20) r4 = 1; if (i >= 0) r4 = 0; - switch (GetInfo(sp04).size) { + switch (GetInfo(slot).size) { case 0: for (i = 0; i < 3; i++) { @@ -627,8 +628,8 @@ void TornOutUnitSprite(struct Unit * param_1, int param_2) { break; } - if (param_2 == 0x3f) - gUnitSpriteSlots[sp04] |= 0xff; + if (timer == 0x3f) + gUnitSpriteSlots[slot] |= 0xff; } void SyncUnitSpriteSheet(void) @@ -648,35 +649,36 @@ void SyncUnitSpriteSheet(void) CpuFastCopy(gSMSGfxBuffer[1], (void*)0x06011000, sizeof(gSMSGfxBuffer[1])); } -//! FE8U = 0x08026F94 -void ForceSyncUnitSpriteSheet(void) { +void ForceSyncUnitSpriteSheet(void) +{ int frame; - gSMSSyncFlag = 0; frame = GetGameClock() % 72; - if (frame >= 68) { + if (frame >= 68) + { RegisterDataMove(gSMSGfxBuffer[1], (void*)0x06011000, sizeof(gSMSGfxBuffer[1])); return; } - if (frame >= 36) { + if (frame >= 36) + { RegisterDataMove(gSMSGfxBuffer[2], (void*)0x06011000, sizeof(gSMSGfxBuffer[2])); return; } - if (frame >= 32) { + if (frame >= 32) + { RegisterDataMove(gSMSGfxBuffer[1], (void*)0x06011000, sizeof(gSMSGfxBuffer[1])); return; } - if (frame >= 0) { + if (frame >= 0) + { RegisterDataMove(gSMSGfxBuffer[0], (void*)0x06011000, sizeof(gSMSGfxBuffer[0])); return; } - - return; } //! FE8U = 0x08026FF4 @@ -686,31 +688,27 @@ void sub_8026FF4(int frameId, u8* dst) { int frame = GetGameClock() % 72; - u8* src = NULL; + u8 * src = NULL; - if (frame == 0) { + if (frame == 0) src = gSMSGfxBuffer[0]; - } - if (frame == 32) { + if (frame == 32) src = gSMSGfxBuffer[1]; - } - if (frame == 36) { + if (frame == 36) src = gSMSGfxBuffer[2]; - } - if (frame == 68) { + if (frame == 68) src = gSMSGfxBuffer[1]; - } - if (src == NULL) { + if (src == NULL) return; - } off = gSomeSMSLookupTable_859B66C[frameId] * CHR_SIZE; - for (i = 0; i <= 3; i++) { + for (i = 0; i <= 3; i++) + { u32 a = off + 0 * CHR_SIZE + i * CHR_SIZE * CHR_LINE; u32 b = off + 1 * CHR_SIZE + i * CHR_SIZE * CHR_LINE; CpuFastCopy( @@ -719,12 +717,10 @@ void sub_8026FF4(int frameId, u8* dst) { 2 * CHR_SIZE ); } - - return; } -//! FE8U = 0x08027068 -void sub_8027068(int frameId, u8* dst) { +void SetStandingMuFacing(int frameId, u8 * dst) +{ int i; int off; @@ -732,19 +728,17 @@ void sub_8027068(int frameId, u8* dst) { u8* src = NULL; - if (frame >= 68) { + if (frame >= 68) src = gSMSGfxBuffer[1]; - } else if (frame >= 36) { + else if (frame >= 36) src = gSMSGfxBuffer[2]; - } else if (frame >= 32) { + else if (frame >= 32) src = gSMSGfxBuffer[1]; - } else if (frame >= 0) { + else if (frame >= 0) src = gSMSGfxBuffer[0]; - } - if (src == NULL) { + if (src == NULL) return; - } off = gSomeSMSLookupTable_859B66C[frameId] * 0x20; @@ -758,83 +752,74 @@ void sub_8027068(int frameId, u8* dst) { 2 * CHR_SIZE ); } - - return; } -//! FE8U = 0x080270DC -void sub_80270DC(int frameId, u8* dst) { +void SetStandingMuFacingWM(int frameId, u8 * dst) +{ int a; int i; int frame = GetGameClock() % 72; u8* src = NULL; do { - if (frame >= 68) { + if (frame >= 68) src = gSMSGfxBuffer[1]; - } else if (frame >= 36) { + else if (frame >= 36) src = gSMSGfxBuffer[2]; - } else if (frame >= 32) { + else if (frame >= 32) src = gSMSGfxBuffer[1]; - } else if (frame >= 0) { + else if (frame >= 0) src = gSMSGfxBuffer[0]; - } } while (0); - if (src == NULL) { + if (src == NULL) return; - } - for (a = frameId * CHR_SIZE, i = 0; i <= 3; a += CHR_SIZE * CHR_LINE, i++) { + for (a = frameId * CHR_SIZE, i = 0; i <= 3; a += CHR_SIZE * CHR_LINE, i++) + { RegisterDataMove( src + (a), dst + (a), 4 * CHR_SIZE); } - - return; } -//! FE8U = 0x0802713C -int GetUnitDisplayedSpritePalette(const struct Unit* unit) { - - if (unit->state & US_BIT27) { +int GetUnitDisplayedSpritePalette(const struct Unit * unit) +{ + if (unit->state & US_BIT27) return 0xB; - } - if (unit->state & US_UNSELECTABLE) { + if (unit->state & US_UNSELECTABLE) return 0xF; - } return GetUnitSpritePalette(unit); } -//! FE8U = 0x08027168 -int GetUnitSpritePalette(const struct Unit* unit) { - +int GetUnitSpritePalette(const struct Unit * unit) +{ switch (UNIT_FACTION(unit)) { - case FACTION_BLUE: - return 0xC; + case FACTION_BLUE: + return 0xC; - case FACTION_RED: - return 0xD; + case FACTION_RED: + return 0xD; - case FACTION_GREEN: - return 0xE; + case FACTION_GREEN: + return 0xE; - case FACTION_PURPLE: - return 0xB; + case FACTION_PURPLE: + return 0xB; } } -//! FE8U = 0x080271A0 -void RefreshUnitSprites(void) { - struct SMSHandle* smsHandle; +void RefreshUnitSprites(void) +{ + struct SMSHandle * smsHandle; - struct Trap* trap; + struct Trap * trap; int i; u16 oam2 = 0; - struct SMSHandle* nullHandle = NULL; + struct SMSHandle * nullHandle = NULL; gSMSHandleIt = &gSMSHandleArray[0]; @@ -843,26 +828,23 @@ void RefreshUnitSprites(void) { gSMSHandleIt = &gSMSHandleArray[1]; - for (i = 1; i < 0xC6; i++) { - struct Unit* unit = GetUnit(i); + for (i = 1; i < FACTION_PURPLE + 6; i++) + { + struct Unit * unit = GetUnit(i); - if (!UNIT_IS_VALID(unit)) { + if (!UNIT_IS_VALID(unit)) continue; - } unit->pMapSpriteHandle = NULL; - if (unit->state & (US_HIDDEN | US_BIT9)) { + if (unit->state & (US_HIDDEN | US_BIT9)) continue; - } - if (gBmMapUnit[unit->yPos][unit->xPos] == 0) { + if (gBmMapUnit[unit->yPos][unit->xPos] == 0) continue; - } - if (unit->statusIndex == UNIT_STATUS_PETRIFY || unit->statusIndex == UNIT_STATUS_13) { + if (unit->statusIndex == UNIT_STATUS_PETRIFY || unit->statusIndex == UNIT_STATUS_13) unit->state |= US_UNSELECTABLE; - } smsHandle = AddUnitSprite(unit->yPos * 16); @@ -884,20 +866,22 @@ void RefreshUnitSprites(void) { unit->pMapSpriteHandle = smsHandle; } - for (trap = GetTrap(0); trap->type != 0; trap++) { - if (trap->type == 1 && trap->data[1] == 0) { + for (trap = GetTrap(0); trap->type != 0; trap++) + { + if (trap->type == 1 && trap->data[1] == 0) + { switch (trap->extra) { - case 0x35: - oam2 = UseUnitSprite(0x5b) - 0x4000 + 0x80; - break; + case 0x35: + oam2 = UseUnitSprite(0x5b) - 0x4000 + 0x80; + break; - case 0x36: - oam2 = UseUnitSprite(0x5c) - 0x4000 + 0x80; - break; + case 0x36: + oam2 = UseUnitSprite(0x5c) - 0x4000 + 0x80; + break; - case 0x37: - oam2 = UseUnitSprite(0x5d) - 0x4000 + 0x80; - break; + case 0x37: + oam2 = UseUnitSprite(0x5d) - 0x4000 + 0x80; + break; } smsHandle = AddUnitSprite(trap->yPos * 16); @@ -910,7 +894,8 @@ void RefreshUnitSprites(void) { smsHandle->config = GetInfo(0x5b).size; } - if (trap->type == 0xd) { + if (trap->type == 0xd) + { smsHandle = AddUnitSprite(trap->yPos * 16); smsHandle->yDisplay = trap->yPos * 16; smsHandle->xDisplay = trap->xPos * 16; @@ -921,20 +906,17 @@ void RefreshUnitSprites(void) { } } - if (gSMSSyncFlag != 0) { + if (gSMSSyncFlag != 0) ForceSyncUnitSpriteSheet(); - } - - - return; } -//! FE8U = 0x0802736C -struct SMSHandle* AddUnitSprite(int y) { - struct SMSHandle* it = gSMSHandleArray; +struct SMSHandle * AddUnitSprite(int y) +{ + struct SMSHandle * it = gSMSHandleArray; while (1) { - if (it->pNext == NULL || it->pNext->yDisplay < y) { + if (it->pNext == NULL || it->pNext->yDisplay < y) + { gSMSHandleIt->pNext = it->pNext; gSMSHandleIt = (it->pNext = gSMSHandleIt) + 1; @@ -943,75 +925,66 @@ struct SMSHandle* AddUnitSprite(int y) { it = it->pNext; } - - return; } -//! FE8U = 0x080273A4 -void PutUnitSpritesOam(void) { - - struct SMSHandle* it = gSMSHandleArray->pNext; +void PutUnitSpritesOam(void) +{ + struct SMSHandle * it = gSMSHandleArray->pNext; PutUnitSpriteIconsOam(); - if (it == NULL) { + if (it == NULL) return; - } - for (; it != NULL; it = it->pNext) { + for (; it != NULL; it = it->pNext) + { int r3 = 0; int x = it->xDisplay - gBmSt.camera.x; int y = it->yDisplay - gBmSt.camera.y; - if (x < -16 || x > DISPLAY_WIDTH) { + if (x < -16 || x > DISPLAY_WIDTH) continue; - } - if (y < -32 || y > DISPLAY_HEIGHT) { + if (y < -32 || y > DISPLAY_HEIGHT) continue; - } - if (it->config & 0x80) { + if (it->config & 0x80) continue; - } - if (it->config & 0x40) { + if (it->config & 0x40) r3 = GetGameClock() & 2; - } switch ((it->config & 0xf)) { - case 0: - CallARM_PushToSecondaryOAM(OAM1_X(x+r3+0x200), OAM0_Y(0x100+y), gObject_16x16, it->oam2Base + OAM2_LAYER(2)); - break; + case 0: + CallARM_PushToSecondaryOAM(OAM1_X(x+r3+0x200), OAM0_Y(0x100+y), gObject_16x16, it->oam2Base + OAM2_LAYER(2)); + break; - case 1: - CallARM_PushToSecondaryOAM(OAM1_X(x+r3+0x200), OAM0_Y(0x100+y - 16), gObject_16x32, it->oam2Base + OAM2_LAYER(2)); - break; + case 1: + CallARM_PushToSecondaryOAM(OAM1_X(x+r3+0x200), OAM0_Y(0x100+y - 16), gObject_16x32, it->oam2Base + OAM2_LAYER(2)); + break; - case 2: - CallARM_PushToSecondaryOAM(OAM1_X((x-8)+r3+0x200), OAM0_Y(0x100+y - 16), gObject_32x32, it->oam2Base + OAM2_LAYER(2)); - break; + case 2: + CallARM_PushToSecondaryOAM(OAM1_X((x-8)+r3+0x200), OAM0_Y(0x100+y - 16), gObject_32x32, it->oam2Base + OAM2_LAYER(2)); + break; - case 3: - CallARM_PushToSecondaryOAM(OAM1_X(x+r3+0x200), OAM0_Y(0x100+y), gObject_16x16, it->oam2Base + OAM2_LAYER(3));; - break; + case 3: + CallARM_PushToSecondaryOAM(OAM1_X(x+r3+0x200), OAM0_Y(0x100+y), gObject_16x16, it->oam2Base + OAM2_LAYER(3));; + break; - case 4: - CallARM_PushToSecondaryOAM(OAM1_X(x+r3+0x200), OAM0_Y(0x100+y - 16), gObject_16x32, it->oam2Base + OAM2_LAYER(3)); - break; + case 4: + CallARM_PushToSecondaryOAM(OAM1_X(x+r3+0x200), OAM0_Y(0x100+y - 16), gObject_16x32, it->oam2Base + OAM2_LAYER(3)); + break; - case 5: - CallARM_PushToSecondaryOAM(OAM1_X((x-8)+r3+0x200), OAM0_Y(0x100+y - 16), gObject_32x32, it->oam2Base + OAM2_LAYER(3)); - break; + case 5: + CallARM_PushToSecondaryOAM(OAM1_X((x-8)+r3+0x200), OAM0_Y(0x100+y - 16), gObject_32x32, it->oam2Base + OAM2_LAYER(3)); + break; } } - - return; } -//! FE8U = 0x08027530 -void PutChapterMarkedTileIconOam(void) { +void PutChapterMarkedTileIconOam(void) +{ int x; int y; int xTile; @@ -1023,40 +996,32 @@ void PutChapterMarkedTileIconOam(void) { shouldDisplay = (GetGameClock() & 0x1f) < 0x14 ? 1 : 0; - if (xTile == 0xFF) { + if (xTile == 0xFF) return; - } - if (shouldDisplay == 0) { + if (shouldDisplay == 0) return; - } - if (gBmMapFog[yTile][xTile] == 0) { + if (gBmMapFog[yTile][xTile] == 0) return; - } - if (gBmMapTerrain[yTile][xTile] == TERRAIN_ROOF) { + if (gBmMapTerrain[yTile][xTile] == TERRAIN_ROOF) return; - } x = xTile * 16 - gBmSt.camera.x; y = yTile * 16 - gBmSt.camera.y; - if (x < -16 || x > DISPLAY_WIDTH) { + if (x < -16 || x > DISPLAY_WIDTH) return; - } - if (y < -16 || y > DISPLAY_HEIGHT) { + if (y < -16 || y > DISPLAY_HEIGHT) return; - } CallARM_PushToSecondaryOAM(OAM1_X(0x200+x + 4), OAM0_Y(0x100+y + 7), gObject_8x8, 0xC51); - - return; } -//! FE8U = 0x080275E8 -void PutUnitSpriteIconsOam(void) { +void PutUnitSpriteIconsOam(void) +{ u8 protectCharacterId; int i; int x; @@ -1092,506 +1057,416 @@ void PutUnitSpriteIconsOam(void) { PutChapterMarkedTileIconOam(); - for (i = 1; i < 0xc0; i++) { - struct Unit* unit = GetUnit(i); + for (i = 1; i < 0xc0; i++) + { + struct Unit * unit = GetUnit(i); - if (!UNIT_IS_VALID(unit)) { + if (!UNIT_IS_VALID(unit)) continue; - } - if (unit->state & US_HIDDEN) { + if (unit->state & US_HIDDEN) continue; - } - if (GetUnitSpriteHideFlag(unit) != 0) { + if (GetUnitSpriteHideFlag(unit) != 0) continue; - } switch (unit->statusIndex) { - case UNIT_STATUS_POISON: - x = unit->xPos * 16 - gBmSt.camera.x; - y = unit->yPos * 16 - gBmSt.camera.y; - - if (x < -16 || x > DISPLAY_WIDTH) { - break; - } - - if (y < -16 || y > DISPLAY_HEIGHT) { - break; - } - - CallARM_PushToSecondaryOAM(OAM1_X(0x200+x - 2), OAM0_Y(0x100+y - 4), sPoisonIconSprites[poisonIconFrame], 0); + case UNIT_STATUS_POISON: + x = unit->xPos * 16 - gBmSt.camera.x; + y = unit->yPos * 16 - gBmSt.camera.y; + if (x < -16 || x > DISPLAY_WIDTH) break; - case UNIT_STATUS_SILENCED: - x = unit->xPos * 16 - gBmSt.camera.x; - y = unit->yPos * 16 - gBmSt.camera.y; - - if (x < -16 || x > DISPLAY_WIDTH) { - break; - } + if (y < -16 || y > DISPLAY_HEIGHT) + break; - if (y < -16 || y > DISPLAY_HEIGHT) { - break; - } + CallARM_PushToSecondaryOAM(OAM1_X(0x200+x - 2), OAM0_Y(0x100+y - 4), sPoisonIconSprites[poisonIconFrame], 0); + break; - CallARM_PushToSecondaryOAM(OAM1_X(0x200+x - 2), OAM0_Y(0x100+y - 4), sSilenceIconSprites[silenceIconFrame], 0); + case UNIT_STATUS_SILENCED: + x = unit->xPos * 16 - gBmSt.camera.x; + y = unit->yPos * 16 - gBmSt.camera.y; + if (x < -16 || x > DISPLAY_WIDTH) break; - case UNIT_STATUS_SLEEP: - x = unit->xPos * 16 - gBmSt.camera.x; - y = unit->yPos * 16 - gBmSt.camera.y; - - if (x < -16 || x > DISPLAY_WIDTH) { - break; - } + if (y < -16 || y > DISPLAY_HEIGHT) + break; - if (y < -16 || y > DISPLAY_HEIGHT) { - break; - } + CallARM_PushToSecondaryOAM(OAM1_X(0x200+x - 2), OAM0_Y(0x100+y - 4), sSilenceIconSprites[silenceIconFrame], 0); + break; - CallARM_PushToSecondaryOAM(OAM1_X(0x200+x + 2), OAM0_Y(0x100+y), sSleepIconSprites[sleepIconFrame], 0); + case UNIT_STATUS_SLEEP: + x = unit->xPos * 16 - gBmSt.camera.x; + y = unit->yPos * 16 - gBmSt.camera.y; + if (x < -16 || x > DISPLAY_WIDTH) break; - case UNIT_STATUS_BERSERK: - x = unit->xPos * 16 - gBmSt.camera.x; - y = unit->yPos * 16 - gBmSt.camera.y; - - if (x < -16 || x > DISPLAY_WIDTH) { - break; - } + if (y < -16 || y > DISPLAY_HEIGHT) + break; - if (y < -16 || y > DISPLAY_HEIGHT) { - break; - } + CallARM_PushToSecondaryOAM(OAM1_X(0x200+x + 2), OAM0_Y(0x100+y), sSleepIconSprites[sleepIconFrame], 0); + break; - CallARM_PushToSecondaryOAM(OAM1_X(0x200+x + 1), OAM0_Y(0x100+y - 5), sBerserkIconSprites[berserkIconFrame], 0); + case UNIT_STATUS_BERSERK: + x = unit->xPos * 16 - gBmSt.camera.x; + y = unit->yPos * 16 - gBmSt.camera.y; + if (x < -16 || x > DISPLAY_WIDTH) break; - case UNIT_STATUS_ATTACK: - case UNIT_STATUS_DEFENSE: - case UNIT_STATUS_CRIT: - case UNIT_STATUS_AVOID: - if (!displayRescueIcon) { - continue; - } + if (y < -16 || y > DISPLAY_HEIGHT) + break; - x = unit->xPos * 16 - gBmSt.camera.x; - y = unit->yPos * 16 - gBmSt.camera.y; + CallARM_PushToSecondaryOAM(OAM1_X(0x200+x + 1), OAM0_Y(0x100+y - 5), sBerserkIconSprites[berserkIconFrame], 0); + break; - if (x < -16 || x > DISPLAY_WIDTH) { - break; - } + case UNIT_STATUS_ATTACK: + case UNIT_STATUS_DEFENSE: + case UNIT_STATUS_CRIT: + case UNIT_STATUS_AVOID: + if (!displayRescueIcon) + continue; - if (y < -16 || y > DISPLAY_HEIGHT) { - break; - } + x = unit->xPos * 16 - gBmSt.camera.x; + y = unit->yPos * 16 - gBmSt.camera.y; - CallARM_PushToSecondaryOAM(OAM1_X(0x200+x - 1), OAM0_Y(0x100+y - 5), sSprite_0859B968, 0); + if (x < -16 || x > DISPLAY_WIDTH) break; - case UNIT_STATUS_SICK: - case UNIT_STATUS_RECOVER: + if (y < -16 || y > DISPLAY_HEIGHT) break; + + CallARM_PushToSecondaryOAM(OAM1_X(0x200+x - 1), OAM0_Y(0x100+y - 5), sSprite_0859B968, 0); + break; + + case UNIT_STATUS_SICK: + case UNIT_STATUS_RECOVER: + break; } - if (!displayRescueIcon) { + if (!displayRescueIcon) continue; - } - if (unit->state & US_RESCUING) { + if (unit->state & US_RESCUING) + { x = unit->xPos * 16 - gBmSt.camera.x; y = unit->yPos * 16 - gBmSt.camera.y; - if (x < -16 || x > DISPLAY_WIDTH) { + if (x < -16 || x > DISPLAY_WIDTH) continue; - } - if (y < -16 || y > DISPLAY_HEIGHT) { + if (y < -16 || y > DISPLAY_HEIGHT) continue; - } CallARM_PushToSecondaryOAM(OAM1_X(0x200+x + 9), OAM0_Y(0x100+y + 7), gObject_8x8, (rescuePalLut[unit->rescue >> 6] & 0xf) * 0x1000 + 0x803); - } else if ((UNIT_FACTION(unit) != FACTION_BLUE) && (UNIT_CATTRIBUTES(unit) & CA_BOSS)) { + } + else if ((UNIT_FACTION(unit) != FACTION_BLUE) && (UNIT_CATTRIBUTES(unit) & CA_BOSS)) + { x = unit->xPos * 16 - gBmSt.camera.x; y = unit->yPos * 16 - gBmSt.camera.y; - if (x < -16 || x > DISPLAY_WIDTH) { + if (x < -16 || x > DISPLAY_WIDTH) continue; - } - if (y < -16 || y > DISPLAY_HEIGHT) { + if (y < -16 || y > DISPLAY_HEIGHT) continue; - } CallARM_PushToSecondaryOAM(OAM1_X(0x200+x + 9), OAM0_Y(0x100+y + 7), gObject_8x8, 0x810); - } else if (protectCharacterId == unit->pCharacterData->number) { + } + else if (protectCharacterId == unit->pCharacterData->number) + { x = unit->xPos * 16 - gBmSt.camera.x; y = unit->yPos * 16 - gBmSt.camera.y; - if (x < -16 || x > DISPLAY_WIDTH) { + if (x < -16 || x > DISPLAY_WIDTH) continue; - } - if (y < -16 || y > DISPLAY_HEIGHT) { + if (y < -16 || y > DISPLAY_HEIGHT) continue; - } CallARM_PushToSecondaryOAM(OAM1_X(0x200+x + 9), OAM0_Y(0x100+y + 7), gObject_8x8, 0x811); } } - - return; } -//! FE8U = 0x08027A30 -void sub_8027A30(void) { +void sub_8027A30(void) +{ gBmSt.cursorPrevious.x = -1; return; } -//! FE8U = 0x08027A40 -void ResetUnitSpriteHover(void) { +void ResetUnitSpriteHover(void) +{ gMapSpriteSwitchHoverTimer = 0; return; } -//! FE8U = 0x08027A4C -void UnitSpriteHoverUpdate(void) { - struct Unit* unit; +void UnitSpriteHoverUpdate(void) +{ + struct Unit * unit; unit = GetUnit(gBmMapUnit[gBmSt.playerCursor.y][gBmSt.playerCursor.x]); - - if (unit) { + if (unit) + { if (!(unit->state & US_UNSELECTABLE) && (UNIT_FACTION(unit) == FACTION_BLUE) && unit->statusIndex != UNIT_STATUS_BERSERK - && unit->statusIndex != UNIT_STATUS_SLEEP) { - + && unit->statusIndex != UNIT_STATUS_SLEEP) + { gMapSpriteSwitchHoverTimer++; - if (gMapSpriteSwitchHoverTimer == 5) { + if (gMapSpriteSwitchHoverTimer == 5) + { StartMu(unit); HideUnitSprite(unit); - return; } } } - if (gBmSt.cursorPrevious.x != gBmSt.playerCursor.x || gBmSt.cursorPrevious.y != gBmSt.playerCursor.y) { + if (gBmSt.cursorPrevious.x != gBmSt.playerCursor.x || gBmSt.cursorPrevious.y != gBmSt.playerCursor.y) + { gMapSpriteSwitchHoverTimer = 0; - unit = GetUnit(gBmMapUnit[gBmSt.cursorPrevious.y][gBmSt.cursorPrevious.x]); - - if (unit) { - MU_EndAll(); + if (unit) + { + EndAllMus(); ShowUnitSprite(unit); } } - - return; } -//! FE8U = 0x08027B0C -s8 IsUnitSpriteHoverEnabledAt(int x, int y) { - - struct Unit* unit = GetUnit(gBmMapUnit[y][x]); +bool IsUnitSpriteHoverEnabledAt(int x, int y) +{ + struct Unit * unit = GetUnit(gBmMapUnit[y][x]); - if (!unit) { - return 0; - } + if (!unit) + return false; - if (unit->state & US_UNSELECTABLE) { - return 0; - } + if (unit->state & US_UNSELECTABLE) + return false; - if (UNIT_FACTION(unit) != FACTION_BLUE) { - return 0; - } + if (UNIT_FACTION(unit) != FACTION_BLUE) + return false; - if (unit->statusIndex != UNIT_STATUS_BERSERK && unit->statusIndex != UNIT_STATUS_SLEEP) { - return 1; - } + if (unit->statusIndex != UNIT_STATUS_BERSERK && unit->statusIndex != UNIT_STATUS_SLEEP) + return true; - return 0; + return false; } -//! FE8U = 0x08027B60 -void PutUnitSprite(int layer, int x, int y, struct Unit* unit) { +void PutUnitSprite(int layer, int x, int y, struct Unit * unit) +{ u32 id = GetUnitSMSId(unit); int chr = UseUnitSprite(id); - if (x < -16 || x > DISPLAY_WIDTH) { + if (x < -16 || x > DISPLAY_WIDTH) return; - } - if (y < -32 || y > DISPLAY_HEIGHT) { + if (y < -32 || y > DISPLAY_HEIGHT) return; - } switch (GetInfo(id).size) { - case UNIT_ICON_SIZE_16x16: - PutSprite(layer, x, y, gObject_16x16, (GetUnitDisplayedSpritePalette(unit) & 0xf) * 0x1000 + 0x880 + chr); - - break; - - case UNIT_ICON_SIZE_16x32: - PutSprite(layer, x, y - 16, gObject_16x32, (GetUnitDisplayedSpritePalette(unit) & 0xf) * 0x1000 + 0x880 + chr); - - break; + case UNIT_ICON_SIZE_16x16: + PutSprite(layer, x, y, gObject_16x16, (GetUnitDisplayedSpritePalette(unit) & 0xf) * 0x1000 + 0x880 + chr); + break; - case UNIT_ICON_SIZE_32x32: - PutSprite(layer, x - 8, y - 16, gObject_32x32, (GetUnitDisplayedSpritePalette(unit) & 0xf) * 0x1000 + 0x880 + chr); + case UNIT_ICON_SIZE_16x32: + PutSprite(layer, x, y - 16, gObject_16x32, (GetUnitDisplayedSpritePalette(unit) & 0xf) * 0x1000 + 0x880 + chr); + break; - break; + case UNIT_ICON_SIZE_32x32: + PutSprite(layer, x - 8, y - 16, gObject_32x32, (GetUnitDisplayedSpritePalette(unit) & 0xf) * 0x1000 + 0x880 + chr); + break; } - - return; } -//! FE8U = 0x08027C48 -void PutUnitSpriteForClassId(int layer, int x, int y, u16 oam2, int class) { +void PutUnitSpriteForClassId(int layer, int x, int y, u16 oam2, int class) +{ u32 id = GetClassSMSId(class); int chr = UseUnitSprite(id) + 0x80; - if (x < -16 || x > DISPLAY_WIDTH) { + if (x < -16 || x > DISPLAY_WIDTH) return; - } - if (y < -32 || y > DISPLAY_HEIGHT) { + if (y < -32 || y > DISPLAY_HEIGHT) return; - } switch (GetInfo(id).size) { - case UNIT_ICON_SIZE_16x16: - PutSprite(layer, x, y, gObject_16x16, oam2 + chr); - - break; - - case UNIT_ICON_SIZE_16x32: - PutSprite(layer, x, y - 16, gObject_16x32, oam2 + chr); - - break; + case UNIT_ICON_SIZE_16x16: + PutSprite(layer, x, y, gObject_16x16, oam2 + chr); + break; - case UNIT_ICON_SIZE_32x32: - PutSprite(layer, x - 8, y - 16, gObject_32x32, oam2 + chr); + case UNIT_ICON_SIZE_16x32: + PutSprite(layer, x, y - 16, gObject_16x32, oam2 + chr); + break; - break; + case UNIT_ICON_SIZE_32x32: + PutSprite(layer, x - 8, y - 16, gObject_32x32, oam2 + chr); + break; } - - return; } -//! FE8U = 0x08027CFC -void sub_8027CFC(int layer, int x, int y, int class) { +void sub_8027CFC(int layer, int x, int y, int class) +{ u32 id = GetClassSMSId(class); int chr = UseUnitSprite(id) + 0x80; - if (x < -16 || x > DISPLAY_WIDTH) { + if (x < -16 || x > DISPLAY_WIDTH) return; - } - if (y < -32 || y > DISPLAY_HEIGHT) { + if (y < -32 || y > DISPLAY_HEIGHT) return; - } switch (GetInfo(id).size) { - case UNIT_ICON_SIZE_16x16: - PutSpriteExt(layer, x, y + OAM0_WINDOW, gObject_16x16, chr); - - break; - - case UNIT_ICON_SIZE_16x32: - PutSpriteExt(layer, x, OAM0_Y(y - 16) + OAM0_WINDOW, gObject_16x32, chr); - - break; + case UNIT_ICON_SIZE_16x16: + PutSpriteExt(layer, x, y + OAM0_WINDOW, gObject_16x16, chr); + break; - case UNIT_ICON_SIZE_32x32: - PutSpriteExt(layer, OAM1_X(x - 8), OAM0_Y(y - 16) + OAM0_WINDOW, gObject_32x32, chr); + case UNIT_ICON_SIZE_16x32: + PutSpriteExt(layer, x, OAM0_Y(y - 16) + OAM0_WINDOW, gObject_16x32, chr); + break; - break; + case UNIT_ICON_SIZE_32x32: + PutSpriteExt(layer, OAM1_X(x - 8), OAM0_Y(y - 16) + OAM0_WINDOW, gObject_32x32, chr); + break; } - - return; } -//! FE8U = 0x08027DB4 -void sub_8027DB4(int layer, int x, int y, u16 oam2, int class, int idx) { +void sub_8027DB4(int layer, int x, int y, u16 oam2, int class, int idx) +{ u32 id = GetClassSMSId(class); int chr = gSomeSMSLookupTable_859B66C[idx] + 1; - if (x < -16 || x > DISPLAY_WIDTH) { + if (x < -16 || x > DISPLAY_WIDTH) return; - } - if (y < -32 || y > DISPLAY_HEIGHT) { + if (y < -32 || y > DISPLAY_HEIGHT) return; - } switch (GetInfo(id).size) { - case UNIT_ICON_SIZE_16x16: - case UNIT_ICON_SIZE_16x32: - PutSprite(layer, x, y - 16, gObject_16x32, (oam2) + chr); - - break; - - case UNIT_ICON_SIZE_32x32: - PutSprite(layer, x - 8, y - 16, gObject_32x32, (oam2) + chr); - - break; + case UNIT_ICON_SIZE_16x16: + case UNIT_ICON_SIZE_16x32: + PutSprite(layer, x, y - 16, gObject_16x32, (oam2) + chr); + break; + case UNIT_ICON_SIZE_32x32: + PutSprite(layer, x - 8, y - 16, gObject_32x32, (oam2) + chr); + break; } - - return; } -//! FE8U = 0x08027E4C -void sub_8027E4C(int layer, int x, int y, int oam2, struct Unit* unit) { +void sub_8027E4C(int layer, int x, int y, int oam2, struct Unit * unit) +{ u32 id = GetUnitSMSId(unit); int chr = UseUnitSprite(id) + 0x80; - if (x < -16 || x > DISPLAY_WIDTH) { + if (x < -16 || x > DISPLAY_WIDTH) return; - } - if (y < -32 || y > DISPLAY_HEIGHT) { + if (y < -32 || y > DISPLAY_HEIGHT) return; - } switch (GetInfo(id).size) { - case UNIT_ICON_SIZE_16x16: - PutSprite(layer, x, y, gObject_16x16, oam2 + (GetUnitSpritePalette(unit) & 0xf) * 0x1000 + chr); - - break; - - case UNIT_ICON_SIZE_16x32: - PutSprite(layer, x, y - 16, gObject_16x32, oam2 + (GetUnitSpritePalette(unit) & 0xf) * 0x1000 + chr); - - break; + case UNIT_ICON_SIZE_16x16: + PutSprite(layer, x, y, gObject_16x16, oam2 + (GetUnitSpritePalette(unit) & 0xf) * 0x1000 + chr); + break; - case UNIT_ICON_SIZE_32x32: - PutSprite(layer, x - 8, y - 16, gObject_32x32, oam2 + (GetUnitSpritePalette(unit) & 0xf) * 0x1000 + chr); + case UNIT_ICON_SIZE_16x32: + PutSprite(layer, x, y - 16, gObject_16x32, oam2 + (GetUnitSpritePalette(unit) & 0xf) * 0x1000 + chr); + break; - break; + case UNIT_ICON_SIZE_32x32: + PutSprite(layer, x - 8, y - 16, gObject_32x32, oam2 + (GetUnitSpritePalette(unit) & 0xf) * 0x1000 + chr); + break; } - - - return; } -//! FE8U = 0x08027F28 void SMS_DisplayOne(int class, int layer, int x, int y, int oam2, s8 isBlend) { - - if (x < -16 || x > DISPLAY_WIDTH+16) { + if (x < -16 || x > DISPLAY_WIDTH+16) return; - } - if (y < -32 || y > DISPLAY_HEIGHT+32) { + if (y < -32 || y > DISPLAY_HEIGHT+32) return; - } switch (GetInfo(GetClassSMSId(class)).size) { - case UNIT_ICON_SIZE_16x16: - PutSpriteExt(layer, OAM1_X(x - 8), isBlend ? OAM0_Y(y - 16) | OAM0_BLEND : OAM0_Y(y - 16), gObject_16x16, oam2 + 0x40); - break; - - case UNIT_ICON_SIZE_16x32: - PutSpriteExt(layer, OAM1_X(x - 8), isBlend ? OAM0_Y(y - 32) | OAM0_BLEND : OAM0_Y(y - 32), gObject_16x32, oam2); - - break; + case UNIT_ICON_SIZE_16x16: + PutSpriteExt(layer, OAM1_X(x - 8), isBlend ? OAM0_Y(y - 16) | OAM0_BLEND : OAM0_Y(y - 16), gObject_16x16, oam2 + 0x40); + break; - case UNIT_ICON_SIZE_32x32: + case UNIT_ICON_SIZE_16x32: + PutSpriteExt(layer, OAM1_X(x - 8), isBlend ? OAM0_Y(y - 32) | OAM0_BLEND : OAM0_Y(y - 32), gObject_16x32, oam2); + break; - PutSpriteExt(layer, OAM1_X(x - 16), isBlend ? OAM0_Y(y - 32) | OAM0_BLEND : OAM0_Y(y - 32), gObject_32x32, oam2); - break; + case UNIT_ICON_SIZE_32x32: + PutSpriteExt(layer, OAM1_X(x - 16), isBlend ? OAM0_Y(y - 32) | OAM0_BLEND : OAM0_Y(y - 32), gObject_32x32, oam2); + break; } - - return; } -//! FE8U = 0x08028014 -void PutBlendWindowUnitSprite(int layer, int x, int y, int oam2, struct Unit* unit) { +void PutBlendWindowUnitSprite(int layer, int x, int y, int oam2, struct Unit * unit) +{ u32 id = GetUnitSMSId(unit); int chr = UseUnitSprite(id) + 0x80; - if (x < -16 || x > DISPLAY_WIDTH) { + if (x < -16 || x > DISPLAY_WIDTH) return; - } - if (y < -32 || y > DISPLAY_HEIGHT) { + if (y < -32 || y > DISPLAY_HEIGHT) return; - } - switch (GetInfo(id).size) { - case UNIT_ICON_SIZE_16x16: - PutSprite(layer, x, y, sSprite_16x16_Blend, oam2 + chr); - PutSprite(layer, x, y, sSprite_16x16_Window, oam2 + chr); - - break; - - case UNIT_ICON_SIZE_16x32: - PutSprite(layer, x, y - 16, sSprite_16x32_Blend, oam2 + chr); - PutSprite(layer, x, y - 16, sSprite_16x32_Window, oam2 + chr); - - break; + case UNIT_ICON_SIZE_16x16: + PutSprite(layer, x, y, sSprite_16x16_Blend, oam2 + chr); + PutSprite(layer, x, y, sSprite_16x16_Window, oam2 + chr); + break; - case UNIT_ICON_SIZE_32x32: - PutSprite(layer, x - 8, y - 16, sSprite_32x32_Blend, oam2 + chr); - PutSprite(layer, x - 8, y - 16, sSprite_32x32_Window, oam2 + chr); + case UNIT_ICON_SIZE_16x32: + PutSprite(layer, x, y - 16, sSprite_16x32_Blend, oam2 + chr); + PutSprite(layer, x, y - 16, sSprite_16x32_Window, oam2 + chr); + break; - break; + case UNIT_ICON_SIZE_32x32: + PutSprite(layer, x - 8, y - 16, sSprite_32x32_Blend, oam2 + chr); + PutSprite(layer, x - 8, y - 16, sSprite_32x32_Window, oam2 + chr); + break; } - - return; } -//! FE8U = 0x08028100 -void sub_8028100(void) { +void sub_8028100(void) +{ gSMSHandleArray[0].pNext = NULL; - return; } -//! FE8U = 0x0802810C -void HideUnitSprite(struct Unit* unit) { - - if (!unit) { +void HideUnitSprite(struct Unit * unit) +{ + if (!unit) RefreshUnitSprites(); - } - if (!unit->pMapSpriteHandle) { + if (!unit->pMapSpriteHandle) return; - } unit->pMapSpriteHandle->config |= 0x80; - - return; } //! FE8U = 0x08028130 -void ShowUnitSprite(struct Unit* unit) { - - if (!unit->pMapSpriteHandle) { +void ShowUnitSprite(struct Unit * unit) +{ + if (!unit->pMapSpriteHandle) return; - } unit->pMapSpriteHandle->config &= ~(0x80); - - return; } -//! FE8U = 0x08028144 -u8 GetUnitSpriteHideFlag(struct Unit* unit) { - if (!unit->pMapSpriteHandle) { +u8 GetUnitSpriteHideFlag(struct Unit * unit) +{ + if (!unit->pMapSpriteHandle) return 0x80; - } return unit->pMapSpriteHandle->config & 0x80; } @@ -1599,7 +1474,8 @@ u8 GetUnitSpriteHideFlag(struct Unit* unit) { //! FE8U = 0x08028160 // attempt with 1D array gets very close // https://decomp.me/scratch/wkkkM -void sub_8028160(u32 (*r8)[1][1], int r5, int r9, int d) { +void sub_8028160(u32 (*r8)[1][1], int r5, int r9, int d) +{ int i, j; int r6 = gUnknown_0859B73C[d]; diff --git a/src/bmusailment.c b/src/bmusailment.c index 5e60c16a3..0cb68db0a 100644 --- a/src/bmusailment.c +++ b/src/bmusailment.c @@ -228,7 +228,7 @@ PROC_LABEL(0), PROC_REPEAT(KillAllRedUnits_Loop), PROC_SLEEP(32), - PROC_CALL(MU_EndAll), + PROC_CALL(EndAllMus), PROC_GOTO(0), @@ -555,7 +555,7 @@ void TerrainHealDisplay_Display(struct UnknownBMUSAilmentProc* proc) { } void FinishDamageDisplay() { - MU_EndAll(); + EndAllMus(); if (gBattleActor.unit.curHP != 0) { ShowUnitSprite(GetUnit(gActionData.subjectIndex)); @@ -675,7 +675,7 @@ void SetClassToHatchingGorgonEgg(struct Unit* unit) { RefreshEntityBmMaps(); RenderBmMap(); RefreshUnitSprites(); - MU_EndAll(); + EndAllMus(); } return; @@ -792,7 +792,7 @@ void StatusDecayDisplay_Next(struct UnknownBMUSAilmentProc* proc) { RefreshEntityBmMaps(); RenderBmMap(); RefreshUnitSprites(); - MU_EndAll(); + EndAllMus(); } SetUnitStatus(GetUnit(gActionData.subjectIndex), 0); diff --git a/src/bmusemind.c b/src/bmusemind.c index f1a0d64de..815daf7e0 100644 --- a/src/bmusemind.c +++ b/src/bmusemind.c @@ -237,7 +237,7 @@ int PostWarpStaff_ExecTrap(ProcPtr proc) { } int sub_802EF80() { - MU_End(GetUnitMu(GetUnit(gActionData.targetIndex))); + EndMu(GetUnitMu(GetUnit(gActionData.targetIndex))); RefreshEntityBmMaps(); RenderBmMap(); diff --git a/src/classchg-event.c b/src/classchg-event.c index cc787b4cd..3cbc697b3 100644 --- a/src/classchg-event.c +++ b/src/classchg-event.c @@ -20,7 +20,7 @@ void sub_80CD62C(void) BMapDispResume(); RefreshBMapGraphics(); RefreshEntityBmMaps(); - MU_EndAll(); + EndAllMus(); StartMu(gActiveUnit); RenderBmMap(); RefreshUnitSprites(); diff --git a/src/classchg-handler.c b/src/classchg-handler.c index 5e392939a..a3371942c 100644 --- a/src/classchg-handler.c +++ b/src/classchg-handler.c @@ -243,5 +243,5 @@ void StartBmPromotion(ProcPtr proc) new_proc->unit = GetUnit(gActionData.subjectIndex); new_proc->item_slot = gActionData.itemSlotIndex; BMapDispSuspend(); - MU_EndAll(); + EndAllMus(); } diff --git a/src/classchg-sel.c b/src/classchg-sel.c index 95796dd76..54987126a 100644 --- a/src/classchg-sel.c +++ b/src/classchg-sel.c @@ -434,7 +434,7 @@ void PrepClassChgOnCancel(struct ProcPromoSel *proc) RefreshEntityBmMaps(); RenderBmMap(); RefreshUnitSprites(); - MU_EndAll(); + EndAllMus(); StartMu(gActiveUnit); } } diff --git a/src/cp_perform.c b/src/cp_perform.c index 85983161d..6e87bee7c 100644 --- a/src/cp_perform.c +++ b/src/cp_perform.c @@ -188,7 +188,7 @@ void AiRefreshMap() { NewBMXFADE(1); - MU_EndAll(); + EndAllMus(); RefreshEntityBmMaps(); ShowUnitSprite(gActiveUnit); @@ -428,7 +428,7 @@ void CpPerform_MoveCameraOntoTarget(struct CpPerformProc* proc) { } if (((s8)gAiDecision.itemSlot == -1) && !(gActiveUnit->state & US_IN_BALLISTA)) { - MU_EndAll(); + EndAllMus(); gActiveUnit->xPos = gAiDecision.xMove; gActiveUnit->yPos = gAiDecision.yMove; diff --git a/src/event.c b/src/event.c index 81b51a0ea..3ba522e46 100644 --- a/src/event.c +++ b/src/event.c @@ -141,7 +141,7 @@ void EventEngine_OnEnd(struct EventEngineProc* proc) { ChangeUnitSpritePalette(proc->mapSpritePalIdOverride); if (proc->evStateBits & EV_STATE_CHANGEGM) { - MU_EndAll(); + EndAllMus(); EndBMapMain(); memset((u8*)(gEventCallQueue), 0, 0x80); } diff --git a/src/eventcall.c b/src/eventcall.c index bb75cbc63..2237d925b 100644 --- a/src/eventcall.c +++ b/src/eventcall.c @@ -48,7 +48,7 @@ CONST_DATA struct ProcCmd ProcScr_BmGameOver[] = { PROC_SLEEP(0xA), PROC_CALL(StartSlowFadeToBlack), PROC_SLEEP(0x50), - PROC_CALL(MU_EndAll), + PROC_CALL(EndAllMus), PROC_CALL(SkilGameOverForToturialExtraMap), PROC_CALL(StartGameOverScreen), PROC_YIELD, @@ -166,7 +166,7 @@ void ResetAllPlayerUnitState(void) } RefreshEntityBmMaps(); - MU_EndAll(); + EndAllMus(); } void TryLockParentProc(ProcPtr proc) @@ -412,17 +412,17 @@ void UnsetEventId_0x84(ProcPtr proc) void UnitTornOut_Init(struct ProcUnitTornOut * proc) { - proc->counter = 0; + proc->timer = 0; } void UnitTornOut_Loop(struct ProcUnitTornOut * proc) { struct Unit * unit = proc->unit; - int count = proc->counter; + int timer = proc->timer; - TornOutUnitSprite(unit, count); + TornOutUnitSprite(unit, timer); - if (proc->counter++ == 63) + if (proc->timer++ == 63) { unit->state |= US_HIDDEN | US_NOT_DEPLOYED; RefreshEntityBmMaps(); diff --git a/src/eventscr.c b/src/eventscr.c index 95e470766..153d53590 100644 --- a/src/eventscr.c +++ b/src/eventscr.c @@ -1871,7 +1871,7 @@ u8 Event23_DisaleMapDisp(struct EventEngineProc * proc) if (!(proc->evStateBits & EV_STATE_GFXLOCKED)) { BMapDispSuspend(); - MU_AllDisable(); + LockMus(); } proc->evStateBits |= EV_STATE_GFXLOCKED; @@ -1884,7 +1884,7 @@ u8 Event24_EnableMapDisp(struct EventEngineProc * proc) if (proc->evStateBits & EV_STATE_GFXLOCKED) { BMapDispResume(); - MU_AllEnable(); + ReleaseMus(); } proc->evStateBits &= ~EV_STATE_GFXLOCKED; @@ -3389,7 +3389,7 @@ u8 Event34_MessWithUnitState(struct EventEngineProc * proc) break; case EVSUBCMD_CLEA: - MU_EndAll(); + EndAllMus(); for (i = FACTION_BLUE + 1; i < FACTION_GREEN; i++) { @@ -3405,7 +3405,7 @@ u8 Event34_MessWithUnitState(struct EventEngineProc * proc) break; case EVSUBCMD_CLEN: - MU_EndAll(); + EndAllMus(); for (i = FACTION_GREEN + 1; i < FACTION_RED; i++) { @@ -3418,7 +3418,7 @@ u8 Event34_MessWithUnitState(struct EventEngineProc * proc) break; case EVSUBCMD_CLEE: - MU_EndAll(); + EndAllMus(); for (i = FACTION_RED + 1; i < FACTION_PURPLE; i++) { struct Unit * it = GetUnit(i); diff --git a/src/eventscr3.c b/src/eventscr3.c index 47be31743..90f6decf8 100644 --- a/src/eventscr3.c +++ b/src/eventscr3.c @@ -193,7 +193,7 @@ void StartScriptBattleAnim(s8 useMapAnims) } else { - MU_EndAll(); + EndAllMus(); RenderBmMap(); BeginBattleMapAnims(); gBattleStats.config |= BATTLE_CONFIG_MAPANIMS; diff --git a/src/gamecontrol.c b/src/gamecontrol.c index ea999956e..92620642a 100644 --- a/src/gamecontrol.c +++ b/src/gamecontrol.c @@ -540,7 +540,7 @@ void sub_8009CC0(ProcPtr proc) void GameControl_PostChapterSwitch(struct GameCtrlProc* proc) { - MU_EndAll(); + EndAllMus(); switch (proc->nextAction) { case GAME_ACTION_EVENT_RETURN: diff --git a/src/gameoverbgfx.c b/src/gameoverbgfx.c index bb91c48a8..6da5571ea 100644 --- a/src/gameoverbgfx.c +++ b/src/gameoverbgfx.c @@ -78,7 +78,7 @@ struct ProcCmd CONST_DATA ProcScr_GameOverScreen_RandomScroll[] = { struct ProcCmd CONST_DATA ProcScr_GameOverScreen[] = { PROC_SET_END_CB(GameOverScreen_End), PROC_CALL(GameOverScreen_Init), - PROC_CALL(MU_EndAll), + PROC_CALL(EndAllMus), PROC_START_CHILD(ProcScr_GameOverScreen_RandomScroll), PROC_REPEAT(GameOverScreen_LoopFadeIn), PROC_CALL(GameOverScreen_BeginIdle), diff --git a/src/koido.c b/src/koido.c index 2e5383df4..582ca7975 100644 --- a/src/koido.c +++ b/src/koido.c @@ -75,7 +75,7 @@ void Loop6C_KOIDO(struct KoidoProc* proc) return; if (2 != proc->config) - MU_End(proc->proc_mu); + EndMu(proc->proc_mu); Proc_Break(proc); diff --git a/src/mapanim.c b/src/mapanim.c index 605070c65..54848e40e 100644 --- a/src/mapanim.c +++ b/src/mapanim.c @@ -93,7 +93,7 @@ void MapAnim_Cleanup(void) { LoadUiFrameGraphics(); LoadObjUIGfx(); if (EventEngineExists()) - MU_EndAll(); + EndAllMus(); } void MapAnim_AdvanceBattleRound(void) { diff --git a/src/mapanim_debug.c b/src/mapanim_debug.c index 7e5c0392e..93ee51ee5 100644 --- a/src/mapanim_debug.c +++ b/src/mapanim_debug.c @@ -170,7 +170,7 @@ void MADebug_InitScreen(struct MADebugProc* proc) { int i, j; - MU_EndAll(); + EndAllMus(); ResetText(); SetBlendConfig(2, 8, 8, 0); diff --git a/src/mapanim_specialeffect.c b/src/mapanim_specialeffect.c index a79bed0a6..c4d149100 100644 --- a/src/mapanim_specialeffect.c +++ b/src/mapanim_specialeffect.c @@ -159,7 +159,7 @@ void MapAnim_Poison2ResetMap(void) RefreshEntityBmMaps(); RenderBmMap(); RefreshUnitSprites(); - MU_EndAll(); + EndAllMus(); } CONST_DATA struct ProcCmd ProcScr_MapAnimGorgonHatch[] = @@ -320,7 +320,7 @@ void LoadGorgonFromEgg(struct MAEffectProc * proc) RefreshEntityBmMaps(); RenderBmMap(); RefreshUnitSprites(); - MU_EndAll(); + EndAllMus(); } //! FE8U = 0x0807D09C diff --git a/src/mapanim_spellassoc.c b/src/mapanim_spellassoc.c index a68fc1934..c426970ca 100644 --- a/src/mapanim_spellassoc.c +++ b/src/mapanim_spellassoc.c @@ -546,7 +546,7 @@ void sub_8081E60(ProcPtr proc) RefreshEntityBmMaps(); RenderBmMap(); RefreshUnitSprites(); - MU_EndAll(); + EndAllMus(); } CONST_DATA struct ProcCmd ProcScr_MapAnimDefaultItemEffect[] = { diff --git a/src/mu.c b/src/mu.c index 4dabac0e6..f4d56faf1 100644 --- a/src/mu.c +++ b/src/mu.c @@ -156,7 +156,7 @@ struct ProcCmd CONST_DATA ProcScr_Mu[] = { PROC_MARK(PROC_MARK_MU), PROC_SET_END_CB(MU_OnEnd), - PROC_REPEAT(MU_OnLoop) + PROC_REPEAT(Mu_OnLoop) }; static u16 CONST_DATA sMuChrOffLut_Default[MU_MAX_COUNT] = { @@ -291,7 +291,7 @@ struct MuProc * StartMu(struct Unit * unit) void UpdateMu(struct MuProc * proc) { - MU_OnLoop(proc); + Mu_OnLoop(proc); } void EnableMuCamera(struct MuProc * proc) @@ -390,7 +390,7 @@ void SetMuFacing(struct MuProc * proc, int facing) proc->facing = facing; if (facing == MU_FACING_STANDING) - sub_8027068(proc->slot, proc->pGfxVRAM); + SetStandingMuFacing(proc->slot, proc->pGfxVRAM); else AP_SwitchAnimation(proc->sprite_anim, proc->facing); } @@ -554,7 +554,7 @@ void RunMuMoveScript(struct MuProc * proc) case MOVE_CMD_END: EndMuMovement(proc); - MU_End(proc); + EndMu(proc); return; case MOVE_CMD_MOVE_LEFT: @@ -833,12 +833,10 @@ void UpdateMuStepSounds(struct MuProc * proc) GetMuDisplayPosition(proc, &position); if (scr[2 + pc]) - { StartPlayMuStepSe(scr[2 + pc], scr[1], position.x); - } } -void MU_OnLoop(struct MuProc * proc) +void Mu_OnLoop(struct MuProc * proc) { if (proc->state) { @@ -861,17 +859,17 @@ void MU_OnEnd(struct MuProc * proc) AP_Delete(proc->sprite_anim); } -void MU_EndAll(void) +void EndAllMus(void) { Proc_EndEach(ProcScr_Mu); } -void MU_End(struct MuProc * proc) +void EndMu(struct MuProc * proc) { - MU_EndInternal(proc); + EndMuExt(proc); } -void MU_EndInternal(struct MuProc * proc) +void EndMuExt(struct MuProc * proc) { Proc_End(proc); } @@ -882,12 +880,12 @@ void HaltMu(struct MuProc * proc) proc->state = MU_STATE_INACTIVE; } -void MU_AllDisable(void) +void LockMus(void) { Proc_BlockEachMarked(PROC_MARK_MU); } -void MU_AllEnable(void) +void ReleaseMus(void) { Proc_UnblockEachMarked(PROC_MARK_MU); } @@ -1151,7 +1149,7 @@ void MuDeathFade_OnLoop(struct MuEffectProc * proc) SetBlendConfig(0, (proc->timeLeft--) >> 1, 0x10, 0); if (proc->timeLeft == 0) { - MU_End(proc->mu); + EndMu(proc->mu); Proc_Break(proc); } } @@ -1233,7 +1231,7 @@ void MuPixelEffect_OnLoop(struct MuEffectProc * proc) if (--proc->timeLeft == 0) { - MU_End(proc->mu); + EndMu(proc->mu); Proc_Break(proc); } } diff --git a/src/muctrl.c b/src/muctrl.c index 9410ea5e9..f262500db 100644 --- a/src/muctrl.c +++ b/src/muctrl.c @@ -327,7 +327,7 @@ void MuCtr_OnEnd(struct MuCtrlProc * proc) RefreshUnitSprites(); } - MU_End(muProc); + EndMu(muProc); SortMus(); ClearEventMoveBuffer(proc->redas); diff --git a/src/playerphase.c b/src/playerphase.c index f41ed3688..48a74b699 100755 --- a/src/playerphase.c +++ b/src/playerphase.c @@ -126,7 +126,7 @@ PROC_LABEL(6), PROC_LABEL(8), PROC_YIELD, - PROC_CALL(MU_EndAll), + PROC_CALL(EndAllMus), PROC_GOTO(0), @@ -265,7 +265,7 @@ void PlayerPhase_MainIdle(ProcPtr proc) if (CanShowUnitStatScreen(GetUnit(gBmMapUnit[gBmSt.playerCursor.y][gBmSt.playerCursor.x]))) { - MU_EndAll(); + EndAllMus(); EndPlayerPhaseSideWindows(); SetStatScreenConfig( @@ -295,7 +295,7 @@ void PlayerPhase_MainIdle(ProcPtr proc) if (unit) { - MU_EndAll(); + EndAllMus(); ShowUnitSprite(unit); } @@ -330,7 +330,7 @@ void PlayerPhase_MainIdle(ProcPtr proc) if (unit) { - MU_EndAll(); + EndAllMus(); ShowUnitSprite(unit); } @@ -567,7 +567,7 @@ void PlayerPhase_RangeDisplayIdle(ProcPtr proc) case ACT_CANCEL: if (gActiveUnit) { - MU_EndAll(); + EndAllMus(); gActiveUnit->state &= ~US_HIDDEN; @@ -614,7 +614,7 @@ void PlayerPhase_RangeDisplayIdle(ProcPtr proc) break; } - MU_EndAll(); + EndAllMus(); SetStatScreenConfig( STATSCREEN_CONFIG_NONDEAD | STATSCREEN_CONFIG_NONBENCHED | STATSCREEN_CONFIG_NONUNK9 | STATSCREEN_CONFIG_NONROOFED | STATSCREEN_CONFIG_NONUNK16); @@ -698,7 +698,7 @@ void PlayerPhase_BackToMove(ProcPtr proc) } HideUnitSprite(gActiveUnit); - MU_EndAll(); + EndAllMus(); StartMu(gActiveUnit); Proc_Goto(proc, 1); @@ -833,7 +833,7 @@ bool TryMakeCantoUnit(ProcPtr proc) gActiveUnit->state |= US_HAS_MOVED; gActiveUnit->state &= ~US_UNSELECTABLE; - MU_EndAll(); + EndAllMus(); StartMu(gActiveUnit); SetAutoMuDefaultFacing(); @@ -904,7 +904,7 @@ void PlayerPhase_FinishAction(ProcPtr proc) if (ShouldCallEndEvent()) { - MU_EndAll(); + EndAllMus(); RefreshEntityBmMaps(); RenderBmMap(); @@ -917,7 +917,7 @@ void PlayerPhase_FinishAction(ProcPtr proc) return; } - MU_EndAll(); + EndAllMus(); return; } @@ -931,7 +931,7 @@ void sub_801D404(void) RefreshEntityBmMaps(); RenderBmMap(); RefreshUnitSprites(); - MU_EndAll(); + EndAllMus(); } return; @@ -1165,7 +1165,7 @@ void ClearActiveUnit(struct Unit * unit) if (gActiveUnit != NULL) { - MU_EndAll(); + EndAllMus(); gActiveUnit->state &= ~US_HIDDEN; } diff --git a/src/prep_atmenu.c b/src/prep_atmenu.c index c6aeecb69..fa184e6eb 100644 --- a/src/prep_atmenu.c +++ b/src/prep_atmenu.c @@ -585,7 +585,7 @@ PROC_LABEL(0x6), PROC_YIELD, PROC_CALL(AtMenu_ResetBmUiEffect), PROC_YIELD, - PROC_CALL(MU_EndAll), + PROC_CALL(EndAllMus), PROC_CALL(AtMenu_UnlockGame), PROC_CALL(EndAllProcChildren), PROC_END diff --git a/src/prep_itemsupply.c b/src/prep_itemsupply.c index 198eef137..a9c8b2a34 100644 --- a/src/prep_itemsupply.c +++ b/src/prep_itemsupply.c @@ -1183,7 +1183,7 @@ void StartPrepItemSupplyProc(struct Unit * unit, ProcPtr parent) void sub_809EAF4(void) { if (gActiveUnit) { - MU_EndAll(); + EndAllMus(); ShowUnitSprite(gActiveUnit); } diff --git a/src/prep_sallycursor.c b/src/prep_sallycursor.c index 0c32ddae5..744150407 100644 --- a/src/prep_sallycursor.c +++ b/src/prep_sallycursor.c @@ -827,7 +827,7 @@ void PrepScreenProc_MapIdle(struct ProcPrepSallyCursor * proc) { if (CanShowUnitStatScreen(GetUnit(gBmMapUnit[gBmSt.playerCursor.y][gBmSt.playerCursor.x]))) { - MU_EndAll(); + EndAllMus(); EndPlayerPhaseSideWindows(); SetStatScreenConfig( STATSCREEN_CONFIG_NONDEAD | STATSCREEN_CONFIG_NONBENCHED | STATSCREEN_CONFIG_NONUNK9 | @@ -1102,7 +1102,7 @@ void PrepScreenProc_MapMovementLoop(ProcPtr proc) if (gKeyStatusPtr->newKeys & (A_BUTTON | B_BUTTON)) { - MU_EndAll(); + EndAllMus(); gActiveUnit->state &= ~US_HIDDEN; gBmSt.gameStateBits &= ~BM_FLAG_3; @@ -1129,7 +1129,7 @@ void PrepScreenProc_MapMovementLoop(ProcPtr proc) struct Unit * unit = GetUnit(uid); if (CanShowUnitStatScreen(unit)) { - MU_EndAll(); + EndAllMus(); SetStatScreenConfig( STATSCREEN_CONFIG_NONDEAD | STATSCREEN_CONFIG_NONBENCHED | STATSCREEN_CONFIG_NONUNK9 | STATSCREEN_CONFIG_NONROOFED | STATSCREEN_CONFIG_NONUNK16); diff --git a/src/sio_battlemap.c b/src/sio_battlemap.c index 0924afca3..40eec280a 100644 --- a/src/sio_battlemap.c +++ b/src/sio_battlemap.c @@ -852,7 +852,7 @@ void sub_8049C18(void) if (unitA != NULL) { - MU_EndAll(); + EndAllMus(); ShowUnitSprite(unitA); } @@ -956,7 +956,7 @@ void sub_8049D24(struct SioBattleMapProc * proc) if (((gActiveUnitId >> 6) == gSioSt->selfId) && (sub_8049C94(gActiveUnit) == 1)) { PlaySoundEffect(0x69); - MU_EndAll(); + EndAllMus(); gUnknown_03001838[0] = StartMu(gActiveUnit); DisableMuCamera(gUnknown_03001838[0]); @@ -984,7 +984,7 @@ void sub_8049D24(struct SioBattleMapProc * proc) { if ((gActiveUnit->state & US_BIT9) == 0) { - MU_EndAll(); + EndAllMus(); Proc_Goto(proc, 4); return; } @@ -1086,7 +1086,7 @@ void sub_8049F44(struct SioBattleMapProc * proc) { PlaySoundEffect(0x6b); - MU_End(gUnknown_03001838[0]); + EndMu(gUnknown_03001838[0]); GetUnit(gUnknown_03001818[gUnk_Sio_0203DD90.unk_04])->state &= ~US_HIDDEN; sub_80492D8(); @@ -1105,7 +1105,7 @@ void sub_8049F44(struct SioBattleMapProc * proc) { if ((gActiveUnit->state & US_BIT9) == 0) { - MU_EndAll(); + EndAllMus(); Proc_Goto(proc, 6); return; } @@ -1320,7 +1320,7 @@ void sub_804A44C(struct SioBattleMapProc * proc) { if ((unit->state & US_BIT9) == 0) { - MU_End(gUnknown_03001838[1]); + EndMu(gUnknown_03001838[1]); } else { @@ -1392,7 +1392,7 @@ void sub_804A5A4(void) // clang-format on - MU_End(gUnknown_03001838[1]); + EndMu(gUnknown_03001838[1]); unitB = GetUnit(gUnknown_03001818[gUnk_Sio_0203DD90.unk_05]); unitB->state &= ~US_HIDDEN; @@ -1465,7 +1465,7 @@ void sub_804A6A4(ProcPtr proc) SetUnitStatus(unitA, 0); SetUnitStatus(unitB, 0); - MU_EndAll(); + EndAllMus(); if (GetUnitCurrentHp(unitA) != 0) { @@ -1677,8 +1677,8 @@ void sub_804A9A4(ProcPtr proc) //! FE8U = 0x0804AA88 void sub_804AA88(void) { - MU_EndAll(); - MU_EndAll(); + EndAllMus(); + EndAllMus(); sub_8049594(); sub_80495F4(); @@ -1806,7 +1806,7 @@ void sub_804ABCC(struct SioProc85AA4CC * proc) if ((unit->state & US_BIT9) == 0) { - MU_End(gUnknown_03001838[0]); + EndMu(gUnknown_03001838[0]); } else { @@ -1880,7 +1880,7 @@ void sub_804ACC4(struct SioProc85AA4CC * proc) if ((unitA->state & US_BIT9) == 0) { - MU_End(gUnknown_03001838[1]); + EndMu(gUnknown_03001838[1]); } else { @@ -2375,7 +2375,7 @@ void sub_804B3D0(ProcPtr proc) return; } - MU_EndAll(); + EndAllMus(); sub_8049350(6, gPlaySt.faction, 0, 0); return; @@ -2391,7 +2391,7 @@ void sub_804B408(ProcPtr proc) return; } - MU_EndAll(); + EndAllMus(); sub_8049350(7, gPlaySt.faction, 0, 0); return; @@ -2406,8 +2406,8 @@ void sub_804B43C(struct SioBattleMapProc * proc) return; } - MU_EndAll(); - MU_EndAll(); + EndAllMus(); + EndAllMus(); gLinkArenaSt.unk_0B = 1; @@ -2594,7 +2594,7 @@ void sub_804B624(struct SioBattleMapProc * proc) //! FE8U = 0x0804B6AC void sub_804B6AC(struct SioBattleMapProc * proc) { - MU_End(proc->unk_54); + EndMu(proc->unk_54); return; } @@ -2737,7 +2737,7 @@ void sub_804B800(void) return; } - MU_EndAll(); + EndAllMus(); RenderBmMap(); BeginBattleMapAnims(); diff --git a/src/statscreen.c b/src/statscreen.c index b32d0d9a6..7e3bdcc88 100644 --- a/src/statscreen.c +++ b/src/statscreen.c @@ -302,7 +302,7 @@ PROC_LABEL(10), PROC_CALL(StatScreen_OnClose), PROC_CALL(BMapDispResume), - PROC_CALL(MU_EndAll), + PROC_CALL(EndAllMus), PROC_CALL(EndGreenText), PROC_END, @@ -1624,7 +1624,7 @@ void StatScreen_Display(struct Proc* proc) // Display Map Sprite - MU_EndAll(); + EndAllMus(); gStatScreen.mu = StartUiMu(gStatScreen.unit, 80, 138); // Draw left panel labels and info diff --git a/src/uiarena.c b/src/uiarena.c index aec5264bc..d63917486 100644 --- a/src/uiarena.c +++ b/src/uiarena.c @@ -214,7 +214,7 @@ void ArenaUi_StartArenaBattle(ProcPtr proc) { gActiveUnit->state |= US_HAS_MOVED; PidStatsAddBattleAmt(gActiveUnit); - MU_EndAll(); + EndAllMus(); gActionData.trapType = 0; diff --git a/src/unitlistscreen.c b/src/unitlistscreen.c index e49b4f0fb..089440449 100644 --- a/src/unitlistscreen.c +++ b/src/unitlistscreen.c @@ -78,7 +78,7 @@ PROC_LABEL(1), PROC_CALL(BMapDispResume), PROC_CALL(RefreshBMapGraphics), - PROC_CALL(MU_EndAll), + PROC_CALL(EndAllMus), PROC_CALL(StartFastFadeFromBlack), PROC_REPEAT(WaitForFade), @@ -541,7 +541,7 @@ void sub_8090514(s8 flag) //! FE8U = 0x08090620 void UnitList_StartStatScreen(struct UnitListScreenProc * proc) { - MU_EndAll(); + EndAllMus(); Proc_End(proc->pSpriteProc); Proc_End(proc->pMuralProc); EndGreenText(); diff --git a/src/worldmap_gmapunit.c b/src/worldmap_gmapunit.c index c931e9e41..34dfaf5b7 100644 --- a/src/worldmap_gmapunit.c +++ b/src/worldmap_gmapunit.c @@ -87,7 +87,7 @@ void GmapUnit_Loop(struct GMapUnitProc * proc) if (proc->animId == 4) { int oam2; - sub_80270DC(gUnknown_08205F7C[proc->index], (void *)(0x06010000 + proc->unk_30 * 0x20)); + SetStandingMuFacingWM(gUnknown_08205F7C[proc->index], (void *)(0x06010000 + proc->unk_30 * 0x20)); oam2 = proc->unk_30 + OAM2_PAL(proc->pal) + gUnknown_08205F7C[proc->index] + proc->unk_2e; SMS_DisplayOne(proc->unk_38, proc->unk_2c, xOam1, yOam0, oam2, proc->flags & GMAPUNIT_FLAG_BLEND); diff --git a/src/worldmap_status_ui.c b/src/worldmap_status_ui.c index da1e90bb9..da853c214 100644 --- a/src/worldmap_status_ui.c +++ b/src/worldmap_status_ui.c @@ -306,7 +306,7 @@ void WorldmapStatus_InitDetails(struct WorldmapStatusProc * proc) ApplyPalette(gUnknown_08A01F04, 2); } - MU_EndAll(); + EndAllMus(); proc->muProc = StartUiMu(proc->unit, 216, 135); PutWorldmapStatusDetails(proc); @@ -481,7 +481,7 @@ struct ProcCmd CONST_DATA gProcScr_WorldmapStatusUi[] = PROC_CALL(WorldmapStatus_80C0FA4), - PROC_CALL(MU_EndAll), + PROC_CALL(EndAllMus), PROC_CALL(BMapDispResume), PROC_CALL(UnlockGame), From b5723d20b5a21cbb791003699ffe89f87b30bcec Mon Sep 17 00:00:00 2001 From: MokhaLeee Date: Thu, 11 Jul 2024 11:29:23 +0000 Subject: [PATCH 7/7] update gbafe --- include/gbafe.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/gbafe.h b/include/gbafe.h index 9c91bbe95..75c008340 100644 --- a/include/gbafe.h +++ b/include/gbafe.h @@ -12,6 +12,7 @@ #include "constants/worldmap.h" #include "constants/classes.h" #include "constants/faces.h" +#include "constants/songs.h" #include "constants/video-banim.h" #include "constants/video-wm.h" #include "constants/video-global.h"