From 7782db3463a572132824b3abcd36b7505c1ff1a0 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Tue, 19 Apr 2022 10:51:26 +1000 Subject: [PATCH 01/33] Magic docs WIP --- include/functions.h | 4 +- include/z64.h | 2 +- include/z64save.h | 40 ++- src/code/z_actor.c | 2 +- src/code/z_construct.c | 2 +- src/code/z_kaleido_setup.c | 3 +- src/code/z_parameter.c | 229 +++++++++--------- src/code/z_play.c | 2 +- src/code/z_player_lib.c | 3 +- .../actors/ovl_Arrow_Fire/z_arrow_fire.c | 2 +- .../actors/ovl_Arrow_Ice/z_arrow_ice.c | 2 +- .../actors/ovl_Arrow_Light/z_arrow_light.c | 2 +- .../ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c | 10 +- .../actors/ovl_Boss_Ganon/z_boss_ganon.c | 2 +- .../actors/ovl_En_M_Thunder/z_en_m_thunder.c | 13 +- .../actors/ovl_En_Torch2/z_en_torch2.c | 2 +- src/overlays/actors/ovl_En_Zl3/z_en_zl3.c | 2 +- .../actors/ovl_Magic_Dark/z_magic_dark.c | 2 +- .../actors/ovl_Magic_Fire/z_magic_fire.c | 2 +- .../actors/ovl_Magic_Wind/z_magic_wind.c | 2 +- .../actors/ovl_Oceff_Spot/z_oceff_spot.c | 2 +- .../actors/ovl_Oceff_Storm/z_oceff_storm.c | 2 +- .../actors/ovl_Oceff_Wipe/z_oceff_wipe.c | 2 +- .../actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c | 2 +- .../actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c | 2 +- .../actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c | 2 +- .../actors/ovl_player_actor/z_player.c | 27 ++- .../ovl_file_choose/z_file_choose.c | 13 +- src/overlays/gamestates/ovl_select/z_select.c | 7 +- .../ovl_kaleido_scope/z_kaleido_scope_PAL.c | 12 +- 30 files changed, 216 insertions(+), 183 deletions(-) diff --git a/include/functions.h b/include/functions.h index 5a800b058ca..004d932b6b5 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1043,8 +1043,8 @@ s32 Health_ChangeBy(GlobalContext* globalCtx, s16 healthChange); void Rupees_ChangeBy(s16 rupeeChange); void Inventory_ChangeAmmo(s16 item, s16 ammoChange); void Magic_Fill(GlobalContext* globalCtx); -void func_800876C8(GlobalContext* globalCtx); -s32 func_80087708(GlobalContext* globalCtx, s16 arg1, s16 arg2); +void Magic_ResetState(GlobalContext* globalCtx); +s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 arg1, s16 arg2); void func_80088AA0(s16 arg0); void func_80088AF0(GlobalContext* globalCtx); void func_80088B34(s16 arg0); diff --git a/include/z64.h b/include/z64.h index 18d4f08e50f..aab9d2344b7 100644 --- a/include/z64.h +++ b/include/z64.h @@ -699,7 +699,7 @@ typedef struct { /* 0x022A */ s16 beatingHeartOscillator; /* 0x022C */ s16 beatingHeartOscillatorDirection; /* 0x022E */ s16 unk_22E; - /* 0x0230 */ s16 unk_230; + /* 0x0230 */ s16 lensMagicDepletionTimer; // number of frames until magic is depleted 1 unit while lens is active /* 0x0232 */ s16 counterDigits[4]; // used for key and rupee counters /* 0x023A */ u8 numHorseBoosts; /* 0x023C */ u16 unk_23C; diff --git a/include/z64save.h b/include/z64save.h index a321c13ab2c..e8e71d745ce 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -4,6 +4,32 @@ #include "ultra64.h" #include "z64math.h" +typedef enum MagicState { + /* 00 */ MAGIC_STATE_DEFAULT, // Normal + /* 01 */ MAGIC_STATE_1, + /* 02 */ MAGIC_STATE_2, + /* 03 */ MAGIC_STATE_BORDER_FREEZE_DARK_LINK, // Using magic attacks other than the spin attack + /* 04 */ MAGIC_STATE_BORDER_YELLOW_TARGET, // Yellow part of the bar indicating the amount of magic to be subtracted + /* 05 */ MAGIC_STATE_RESET, + /* 06 */ MAGIC_STATE_BORDER_STANDARD, + /* 07 */ MAGIC_STATE_LENS_CONSUME, // Lens + /* 08 */ MAGIC_STATE_INIT, // Init magic, starting a new load + /* 09 */ MAGIC_STATE_FILL, // Fill to max + /* 10 */ MAGIC_STATE_ADD // Add +} MagicState; + +typedef enum MagicChange { + /* 00 */ MAGIC_CHANGE_0, // Consume Magic (spell & spin attack) + /* 01 */ MAGIC_CHANGE_1, // Unused + /* 02 */ MAGIC_CHANGE_2, // Consume Magic Alt + /* 03 */ MAGIC_CHANGE_3, // Lens + /* 04 */ MAGIC_CHANGE_4, // Consume Magic (spell & spin attack) + /* 05 */ MAGIC_CHANGE_ADD +} MagicChange; + +#define MAGIC_HALF_BAR 0x30 +#define MAGIC_FULL_BAR 0x60 + typedef struct { /* 0x00 */ u8 buttonItems[4]; /* 0x04 */ u8 cButtonSlots[3]; @@ -74,8 +100,8 @@ typedef struct { /* 0x002C */ s16 n64ddFlag; /* 0x002E */ s16 healthCapacity; // "max_life" /* 0x0030 */ s16 health; // "now_life" - /* 0x0032 */ s8 magicLevel; - /* 0x0033 */ s8 magic; + /* 0x0032 */ s8 magicLevel; // 0 for no magic/new load, 1 for magic, 2 for double magic + /* 0x0033 */ s8 magic; // true magic value available /* 0x0034 */ s16 rupees; /* 0x0036 */ u16 swordHealth; /* 0x0038 */ u16 naviTimer; @@ -143,11 +169,11 @@ typedef struct { /* 0x13EA */ u16 unk_13EA; // also alpha type? /* 0x13EC */ u16 unk_13EC; // alpha type counter? /* 0x13EE */ u16 unk_13EE; // previous alpha type? - /* 0x13F0 */ s16 unk_13F0; // magic related - /* 0x13F2 */ s16 unk_13F2; // magic related - /* 0x13F4 */ s16 unk_13F4; // magic related - /* 0x13F6 */ s16 unk_13F6; // magic related - /* 0x13F8 */ s16 unk_13F8; // magic related + /* 0x13F0 */ s16 magicState; + /* 0x13F2 */ s16 magicStateStored; // stores the previous magic state so it can be restored + /* 0x13F4 */ s16 magicMaxDrawn; // Only differs from magicMax in a new save load, where magicMaxDrawn is slowly stepped from 0 to magicMax + /* 0x13F6 */ s16 magicMax; + /* 0x13F8 */ s16 yellowMagic; // preview of the magic about to be consumed /* 0x13FA */ u16 eventInf[4]; // "event_inf" /* 0x1402 */ u16 mapIndex; // intended for maps/minimaps but commonly used as the dungeon index /* 0x1404 */ u16 minigameState; diff --git a/src/code/z_actor.c b/src/code/z_actor.c index b59039a8589..450f4008e9d 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -1949,7 +1949,7 @@ void func_80030488(GlobalContext* globalCtx) { void Actor_DisableLens(GlobalContext* globalCtx) { if (globalCtx->actorCtx.lensActive) { globalCtx->actorCtx.lensActive = false; - func_800876C8(globalCtx); + Magic_ResetState(globalCtx); } } diff --git a/src/code/z_construct.c b/src/code/z_construct.c index 7c3947f7454..d686bee49c7 100644 --- a/src/code/z_construct.c +++ b/src/code/z_construct.c @@ -18,7 +18,7 @@ void func_801109B0(GlobalContext* globalCtx) { interfaceCtx->unk_1FA = interfaceCtx->unk_261 = interfaceCtx->unk_1FC = 0; interfaceCtx->unk_1EC = interfaceCtx->unk_1EE = interfaceCtx->unk_1F0 = 0; interfaceCtx->unk_22E = 0; - interfaceCtx->unk_230 = 16; + interfaceCtx->lensMagicDepletionTimer = 16; interfaceCtx->unk_1F4 = 0.0f; interfaceCtx->unk_228 = XREG(95); interfaceCtx->minimapAlpha = 0; diff --git a/src/code/z_kaleido_setup.c b/src/code/z_kaleido_setup.c index 7fad9e06078..adf5712aa2e 100644 --- a/src/code/z_kaleido_setup.c +++ b/src/code/z_kaleido_setup.c @@ -15,7 +15,8 @@ void KaleidoSetup_Update(GlobalContext* globalCtx) { if (pauseCtx->state == 0 && pauseCtx->debugState == 0 && globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE && globalCtx->sceneLoadFlag == 0 && globalCtx->transitionMode == 0 && gSaveContext.cutsceneIndex < 0xFFF0 && gSaveContext.nextCutsceneIndex < 0xFFF0 && !Gameplay_InCsMode(globalCtx) && - globalCtx->shootingGalleryStatus <= 1 && gSaveContext.unk_13F0 != 8 && gSaveContext.unk_13F0 != 9 && + globalCtx->shootingGalleryStatus <= 1 && gSaveContext.magicState != MAGIC_STATE_INIT && + gSaveContext.magicState != MAGIC_STATE_FILL && (globalCtx->sceneNum != SCENE_BOWLING || !Flags_GetSwitch(globalCtx, 0x38))) { if (CHECK_BTN_ALL(input->cur.button, BTN_L) && CHECK_BTN_ALL(input->press.button, BTN_CUP)) { diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index f8e7766da84..5085e0cded9 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -1672,11 +1672,11 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { Health_ChangeBy(globalCtx, 0x10); return item; } else if (item == ITEM_MAGIC_SMALL) { - if (gSaveContext.unk_13F0 != 10) { + if (gSaveContext.magicState != MAGIC_STATE_ADD) { Magic_Fill(globalCtx); } - func_80087708(globalCtx, 12, 5); + Magic_ChangeBy(globalCtx, 12, MAGIC_CHANGE_ADD); if (!(gSaveContext.infTable[25] & 0x100)) { gSaveContext.infTable[25] |= 0x100; @@ -1685,11 +1685,11 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { return item; } else if (item == ITEM_MAGIC_LARGE) { - if (gSaveContext.unk_13F0 != 10) { + if (gSaveContext.magicState != MAGIC_STATE_ADD) { Magic_Fill(globalCtx); } - func_80087708(globalCtx, 24, 5); + Magic_ChangeBy(globalCtx, 24, MAGIC_CHANGE_ADD); if (!(gSaveContext.infTable[25] & 0x100)) { gSaveContext.infTable[25] |= 0x100; @@ -2240,110 +2240,113 @@ void Inventory_ChangeAmmo(s16 item, s16 ammoChange) { void Magic_Fill(GlobalContext* globalCtx) { if (gSaveContext.magicAcquired) { - gSaveContext.unk_13F2 = gSaveContext.unk_13F0; - gSaveContext.unk_13F6 = (gSaveContext.doubleMagic * 0x30) + 0x30; - gSaveContext.unk_13F0 = 9; + gSaveContext.magicStateStored = gSaveContext.magicState; + gSaveContext.magicMax = (gSaveContext.doubleMagic + 1) * MAGIC_HALF_BAR; + gSaveContext.magicState = MAGIC_STATE_FILL; } } -void func_800876C8(GlobalContext* globalCtx) { - if ((gSaveContext.unk_13F0 != 8) && (gSaveContext.unk_13F0 != 9)) { - if (gSaveContext.unk_13F0 == 10) { - gSaveContext.unk_13F2 = gSaveContext.unk_13F0; +void Magic_ResetState(GlobalContext* globalCtx) { + if ((gSaveContext.magicState != MAGIC_STATE_INIT) && (gSaveContext.magicState != MAGIC_STATE_FILL)) { + if (gSaveContext.magicState == MAGIC_STATE_ADD) { + gSaveContext.magicStateStored = gSaveContext.magicState; } - gSaveContext.unk_13F0 = 5; + gSaveContext.magicState = MAGIC_STATE_RESET; } } -s32 func_80087708(GlobalContext* globalCtx, s16 arg1, s16 arg2) { +s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType) { if (!gSaveContext.magicAcquired) { - return 0; + return false; } - if ((arg2 != 5) && (gSaveContext.magic - arg1) < 0) { - if (gSaveContext.unk_13F4 != 0) { + if ((changeType != MAGIC_CHANGE_ADD) && (gSaveContext.magic - magicChange) < 0) { + if (gSaveContext.magicMaxDrawn != 0) { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); } - return 0; + return false; } - switch (arg2) { - case 0: - case 2: - if ((gSaveContext.unk_13F0 == 0) || (gSaveContext.unk_13F0 == 7)) { - if (gSaveContext.unk_13F0 == 7) { + switch (changeType) { + case MAGIC_CHANGE_0: + case MAGIC_CHANGE_2: + if ((gSaveContext.magicState == MAGIC_STATE_DEFAULT) || + (gSaveContext.magicState == MAGIC_STATE_LENS_CONSUME)) { + if (gSaveContext.magicState == MAGIC_STATE_LENS_CONSUME) { globalCtx->actorCtx.lensActive = false; } - gSaveContext.unk_13F8 = gSaveContext.magic - arg1; - gSaveContext.unk_13F0 = 1; - return 1; + gSaveContext.yellowMagic = gSaveContext.magic - magicChange; + gSaveContext.magicState = MAGIC_STATE_1; + return true; } else { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); - return 0; + return false; } - case 1: - if ((gSaveContext.unk_13F0 == 0) || (gSaveContext.unk_13F0 == 7)) { - if (gSaveContext.unk_13F0 == 7) { + case MAGIC_CHANGE_1: + if ((gSaveContext.magicState == MAGIC_STATE_DEFAULT) || + (gSaveContext.magicState == MAGIC_STATE_LENS_CONSUME)) { + if (gSaveContext.magicState == MAGIC_STATE_LENS_CONSUME) { globalCtx->actorCtx.lensActive = false; } - gSaveContext.unk_13F8 = gSaveContext.magic - arg1; - gSaveContext.unk_13F0 = 6; - return 1; + gSaveContext.yellowMagic = gSaveContext.magic - magicChange; + gSaveContext.magicState = MAGIC_STATE_BORDER_STANDARD; + return true; } else { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); - return 0; + return false; } - case 3: - if (gSaveContext.unk_13F0 == 0) { + case MAGIC_CHANGE_3: + if (gSaveContext.magicState == MAGIC_STATE_DEFAULT) { if (gSaveContext.magic != 0) { - globalCtx->interfaceCtx.unk_230 = 80; - gSaveContext.unk_13F0 = 7; - return 1; + globalCtx->interfaceCtx.lensMagicDepletionTimer = 80; + gSaveContext.magicState = MAGIC_STATE_LENS_CONSUME; + return true; } else { - return 0; + return false; } } else { - if (gSaveContext.unk_13F0 == 7) { - return 1; + if (gSaveContext.magicState == MAGIC_STATE_LENS_CONSUME) { + return true; } else { - return 0; + return false; } } - case 4: - if ((gSaveContext.unk_13F0 == 0) || (gSaveContext.unk_13F0 == 7)) { - if (gSaveContext.unk_13F0 == 7) { + case MAGIC_CHANGE_4: + if ((gSaveContext.magicState == MAGIC_STATE_DEFAULT) || + (gSaveContext.magicState == MAGIC_STATE_LENS_CONSUME)) { + if (gSaveContext.magicState == MAGIC_STATE_LENS_CONSUME) { globalCtx->actorCtx.lensActive = false; } - gSaveContext.unk_13F8 = gSaveContext.magic - arg1; - gSaveContext.unk_13F0 = 4; - return 1; + gSaveContext.yellowMagic = gSaveContext.magic - magicChange; + gSaveContext.magicState = MAGIC_STATE_BORDER_YELLOW_TARGET; + return true; } else { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); - return 0; + return false; } - case 5: - if (gSaveContext.unk_13F4 >= gSaveContext.magic) { - gSaveContext.unk_13F8 = gSaveContext.magic + arg1; + case MAGIC_CHANGE_ADD: + if (gSaveContext.magic <= gSaveContext.magicMaxDrawn) { + gSaveContext.yellowMagic = gSaveContext.magic + magicChange; - if (gSaveContext.unk_13F8 >= gSaveContext.unk_13F4) { - gSaveContext.unk_13F8 = gSaveContext.unk_13F4; + if (gSaveContext.yellowMagic >= gSaveContext.magicMaxDrawn) { + gSaveContext.yellowMagic = gSaveContext.magicMaxDrawn; } - gSaveContext.unk_13F0 = 10; - return 1; + gSaveContext.magicState = MAGIC_STATE_ADD; + return true; } break; } - return 0; + return false; } void Interface_UpdateMagicBar(GlobalContext* globalCtx) { static s16 sMagicBorderColors[][3] = { { 255, 255, 255 }, { 150, 150, 150 }, - { 255, 255, 150 }, - { 255, 255, 50 }, + { 255, 255, 150 }, // unused color + { 255, 255, 50 }, // unused color }; static s16 sMagicBorderIndices[] = { 0, 1, 1, 0 }; static s16 sMagicBorderRatio = 2; @@ -2355,27 +2358,27 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { s16 borderChangeB; s16 temp; - switch (gSaveContext.unk_13F0) { - case 8: - temp = gSaveContext.magicLevel * 0x30; - if (gSaveContext.unk_13F4 != temp) { - if (gSaveContext.unk_13F4 < temp) { - gSaveContext.unk_13F4 += 8; - if (gSaveContext.unk_13F4 > temp) { - gSaveContext.unk_13F4 = temp; + switch (gSaveContext.magicState) { + case MAGIC_STATE_INIT: + temp = gSaveContext.magicLevel * MAGIC_HALF_BAR; + if (gSaveContext.magicMaxDrawn != temp) { + if (gSaveContext.magicMaxDrawn < temp) { + gSaveContext.magicMaxDrawn += 8; + if (gSaveContext.magicMaxDrawn > temp) { + gSaveContext.magicMaxDrawn = temp; } } else { - gSaveContext.unk_13F4 -= 8; - if (gSaveContext.unk_13F4 <= temp) { - gSaveContext.unk_13F4 = temp; + gSaveContext.magicMaxDrawn -= 8; + if (gSaveContext.magicMaxDrawn <= temp) { + gSaveContext.magicMaxDrawn = temp; } } } else { - gSaveContext.unk_13F0 = 9; + gSaveContext.magicState = MAGIC_STATE_FILL; } break; - case 9: + case MAGIC_STATE_FILL: gSaveContext.magic += 4; if (gSaveContext.gameMode == 0 && gSaveContext.sceneSetupIndex < 4) { @@ -2384,32 +2387,34 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { } // "Storage MAGIC_NOW=%d (%d)" - osSyncPrintf("蓄電 MAGIC_NOW=%d (%d)\n", gSaveContext.magic, gSaveContext.unk_13F6); - if (gSaveContext.magic >= gSaveContext.unk_13F6) { - gSaveContext.magic = gSaveContext.unk_13F6; - gSaveContext.unk_13F0 = gSaveContext.unk_13F2; - gSaveContext.unk_13F2 = 0; + osSyncPrintf("蓄電 MAGIC_NOW=%d (%d)\n", gSaveContext.magic, gSaveContext.magicMax); + if (gSaveContext.magic >= gSaveContext.magicMax) { + gSaveContext.magic = gSaveContext.magicMax; + gSaveContext.magicState = gSaveContext.magicStateStored; + gSaveContext.magicStateStored = MAGIC_STATE_DEFAULT; } break; - case 1: + case MAGIC_STATE_1: sMagicBorderRatio = 2; - gSaveContext.unk_13F0 = 2; + gSaveContext.magicState = MAGIC_STATE_2; break; - case 2: + case MAGIC_STATE_2: gSaveContext.magic -= 2; if (gSaveContext.magic <= 0) { gSaveContext.magic = 0; - gSaveContext.unk_13F0 = 3; + gSaveContext.magicState = MAGIC_STATE_BORDER_FREEZE_DARK_LINK; sMagicBorderR = sMagicBorderG = sMagicBorderB = 255; - } else if (gSaveContext.magic == gSaveContext.unk_13F8) { - gSaveContext.unk_13F0 = 3; + } else if (gSaveContext.magic == gSaveContext.yellowMagic) { + gSaveContext.magicState = MAGIC_STATE_BORDER_FREEZE_DARK_LINK; sMagicBorderR = sMagicBorderG = sMagicBorderB = 255; } - case 3: - case 4: - case 6: + // fallthrough + + case MAGIC_STATE_BORDER_FREEZE_DARK_LINK: + case MAGIC_STATE_BORDER_YELLOW_TARGET: + case MAGIC_STATE_BORDER_STANDARD: temp = sMagicBorderIndices[sMagicBorderStep]; borderChangeR = ABS(sMagicBorderR - sMagicBorderColors[temp][0]) / sMagicBorderRatio; borderChangeG = ABS(sMagicBorderG - sMagicBorderColors[temp][1]) / sMagicBorderRatio; @@ -2446,12 +2451,12 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { } break; - case 5: + case MAGIC_STATE_RESET: sMagicBorderR = sMagicBorderG = sMagicBorderB = 255; - gSaveContext.unk_13F0 = 0; + gSaveContext.magicState = MAGIC_STATE_DEFAULT; break; - case 7: + case MAGIC_STATE_LENS_CONSUME: if ((globalCtx->pauseCtx.state == 0) && (globalCtx->pauseCtx.debugState == 0) && (msgCtx->msgMode == MSGMODE_NONE) && (globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE) && (globalCtx->sceneLoadFlag == 0) && (globalCtx->transitionMode == 0) && !Gameplay_InCsMode(globalCtx)) { @@ -2463,15 +2468,15 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { globalCtx->actorCtx.lensActive = false; Audio_PlaySoundGeneral(NA_SE_SY_GLASSMODE_OFF, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); - gSaveContext.unk_13F0 = 0; + gSaveContext.magicState = MAGIC_STATE_DEFAULT; sMagicBorderR = sMagicBorderG = sMagicBorderB = 255; break; } - interfaceCtx->unk_230--; - if (interfaceCtx->unk_230 == 0) { + interfaceCtx->lensMagicDepletionTimer--; + if (interfaceCtx->lensMagicDepletionTimer == 0) { gSaveContext.magic--; - interfaceCtx->unk_230 = 80; + interfaceCtx->lensMagicDepletionTimer = 80; } } @@ -2511,18 +2516,18 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { } break; - case 10: + case MAGIC_STATE_ADD: gSaveContext.magic += 4; Audio_PlaySoundGeneral(NA_SE_SY_GAUGE_UP - SFX_FLAG, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); - if (gSaveContext.magic >= gSaveContext.unk_13F8) { - gSaveContext.magic = gSaveContext.unk_13F8; - gSaveContext.unk_13F0 = gSaveContext.unk_13F2; - gSaveContext.unk_13F2 = 0; + if (gSaveContext.magic >= gSaveContext.yellowMagic) { + gSaveContext.magic = gSaveContext.yellowMagic; + gSaveContext.magicState = gSaveContext.magicStateStored; + gSaveContext.magicStateStored = MAGIC_STATE_DEFAULT; } break; default: - gSaveContext.unk_13F0 = 0; + gSaveContext.magicState = MAGIC_STATE_DEFAULT; break; } } @@ -2535,9 +2540,9 @@ void Interface_DrawMagicBar(GlobalContext* globalCtx) { if (gSaveContext.magicLevel != 0) { if (gSaveContext.healthCapacity > 0xA0) { - magicBarY = R_MAGIC_BAR_LARGE_Y; + magicBarY = R_MAGIC_BAR_LARGE_Y; // two rows of hearts } else { - magicBarY = R_MAGIC_BAR_SMALL_Y; + magicBarY = R_MAGIC_BAR_SMALL_Y; // one row of hearts } func_80094520(globalCtx->state.gfxCtx); @@ -2549,21 +2554,21 @@ void Interface_DrawMagicBar(GlobalContext* globalCtx) { Gfx_TextureIA8(OVERLAY_DISP, gMagicBarEndTex, 8, 16, R_MAGIC_BAR_X, magicBarY, 8, 16, 1 << 10, 1 << 10); OVERLAY_DISP = Gfx_TextureIA8(OVERLAY_DISP, gMagicBarMidTex, 24, 16, R_MAGIC_BAR_X + 8, magicBarY, - gSaveContext.unk_13F4, 16, 1 << 10, 1 << 10); + gSaveContext.magicMaxDrawn, 16, 1 << 10, 1 << 10); gDPLoadTextureBlock(OVERLAY_DISP++, gMagicBarEndTex, G_IM_FMT_IA, G_IM_SIZ_8b, 8, 16, 0, G_TX_MIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, 3, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPTextureRectangle(OVERLAY_DISP++, ((R_MAGIC_BAR_X + gSaveContext.unk_13F4) + 8) << 2, magicBarY << 2, - ((R_MAGIC_BAR_X + gSaveContext.unk_13F4) + 16) << 2, (magicBarY + 16) << 2, G_TX_RENDERTILE, - 256, 0, 1 << 10, 1 << 10); + gSPTextureRectangle(OVERLAY_DISP++, ((R_MAGIC_BAR_X + gSaveContext.magicMaxDrawn) + 8) << 2, magicBarY << 2, + ((R_MAGIC_BAR_X + gSaveContext.magicMaxDrawn) + 16) << 2, (magicBarY + 16) << 2, + G_TX_RENDERTILE, 256, 0, 1 << 10, 1 << 10); gDPPipeSync(OVERLAY_DISP++); gDPSetCombineLERP(OVERLAY_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, 0, 0, 0, PRIMITIVE, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, 0, 0, 0, PRIMITIVE); gDPSetEnvColor(OVERLAY_DISP++, 0, 0, 0, 255); - if (gSaveContext.unk_13F0 == 4) { + if (gSaveContext.magicState == MAGIC_STATE_BORDER_YELLOW_TARGET) { // Yellow part of the bar indicating the amount of magic to be subtracted gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 250, 250, 0, interfaceCtx->magicAlpha); @@ -2581,8 +2586,8 @@ void Interface_DrawMagicBar(GlobalContext* globalCtx) { interfaceCtx->magicAlpha); gSPTextureRectangle(OVERLAY_DISP++, R_MAGIC_FILL_X << 2, (magicBarY + 3) << 2, - (R_MAGIC_FILL_X + gSaveContext.unk_13F8) << 2, (magicBarY + 10) << 2, G_TX_RENDERTILE, - 0, 0, 1 << 10, 1 << 10); + (R_MAGIC_FILL_X + gSaveContext.yellowMagic) << 2, (magicBarY + 10) << 2, + G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); } else { // Fill the whole bar with the normal magic color gDPSetPrimColor(OVERLAY_DISP++, 0, 0, R_MAGIC_FILL_COLOR(0), R_MAGIC_FILL_COLOR(1), R_MAGIC_FILL_COLOR(2), @@ -4046,15 +4051,15 @@ void Interface_Update(GlobalContext* globalCtx) { (msgCtx->msgMode == MSGMODE_NONE) && (globalCtx->sceneLoadFlag == 0) && (globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE) && (globalCtx->transitionMode == 0) && ((globalCtx->csCtx.state == CS_STATE_IDLE) || !Player_InCsMode(globalCtx))) { - if ((gSaveContext.magicAcquired != 0) && (gSaveContext.magicLevel == 0)) { + if (gSaveContext.magicAcquired && (gSaveContext.magicLevel == 0)) { gSaveContext.magicLevel = gSaveContext.doubleMagic + 1; - gSaveContext.unk_13F0 = 8; + gSaveContext.magicState = MAGIC_STATE_INIT; osSyncPrintf(VT_FGCOL(YELLOW)); osSyncPrintf("魔法スター─────ト!!!!!!!!!\n"); // "Magic Start!!!!!!!!!" osSyncPrintf("MAGIC_MAX=%d\n", gSaveContext.magicLevel); osSyncPrintf("MAGIC_NOW=%d\n", gSaveContext.magic); - osSyncPrintf("Z_MAGIC_NOW_NOW=%d\n", gSaveContext.unk_13F6); - osSyncPrintf("Z_MAGIC_NOW_MAX=%d\n", gSaveContext.unk_13F4); + osSyncPrintf("Z_MAGIC_NOW_NOW=%d\n", gSaveContext.magicMax); + osSyncPrintf("Z_MAGIC_NOW_MAX=%d\n", gSaveContext.magicMaxDrawn); osSyncPrintf(VT_RST); } diff --git a/src/code/z_play.c b/src/code/z_play.c index 7a3fed57c30..d47b30939ef 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -259,7 +259,7 @@ void Gameplay_Init(GameState* thisx) { if (gSaveContext.gameMode != 0 || gSaveContext.cutsceneIndex >= 0xFFF0) { gSaveContext.nayrusLoveTimer = 0; - func_800876C8(globalCtx); + Magic_ResetState(globalCtx); gSaveContext.sceneSetupIndex = (gSaveContext.cutsceneIndex & 0xF) + 4; } else if (!LINK_IS_ADULT && IS_DAY) { gSaveContext.sceneSetupIndex = 0; diff --git a/src/code/z_player_lib.c b/src/code/z_player_lib.c index 30ea4a4acdf..978e49a4566 100644 --- a/src/code/z_player_lib.c +++ b/src/code/z_player_lib.c @@ -483,7 +483,8 @@ s32 Player_InBlockingCsMode(GlobalContext* globalCtx, Player* this) { return (this->stateFlags1 & (PLAYER_STATE1_7 | PLAYER_STATE1_29)) || (this->csMode != 0) || (globalCtx->sceneLoadFlag == 0x14) || (this->stateFlags1 & PLAYER_STATE1_0) || (this->stateFlags3 & PLAYER_STATE3_7) || - ((gSaveContext.unk_13F0 != 0) && (Player_ActionToMagicSpell(this, this->itemActionParam) >= 0)); + ((gSaveContext.magicState != MAGIC_STATE_DEFAULT) && + (Player_ActionToMagicSpell(this, this->itemActionParam) >= 0)); } s32 Player_InCsMode(GlobalContext* globalCtx) { diff --git a/src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c b/src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c index b519b13cb14..6045c1faf31 100644 --- a/src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c +++ b/src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c @@ -54,7 +54,7 @@ void ArrowFire_Init(Actor* thisx, GlobalContext* globalCtx) { } void ArrowFire_Destroy(Actor* thisx, GlobalContext* globalCtx) { - func_800876C8(globalCtx); + Magic_ResetState(globalCtx); LOG_STRING("消滅", "../z_arrow_fire.c", 421); // "Disappearance" } diff --git a/src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c b/src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c index bc728b0e0f3..c6e549661ee 100644 --- a/src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c +++ b/src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c @@ -55,7 +55,7 @@ void ArrowIce_Init(Actor* thisx, GlobalContext* globalCtx) { } void ArrowIce_Destroy(Actor* thisx, GlobalContext* globalCtx) { - func_800876C8(globalCtx); + Magic_ResetState(globalCtx); LOG_STRING("消滅", "../z_arrow_ice.c", 415); // "Disappearance" } diff --git a/src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c b/src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c index f8a743e8932..7ca98fda196 100644 --- a/src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c +++ b/src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c @@ -55,7 +55,7 @@ void ArrowLight_Init(Actor* thisx, GlobalContext* globalCtx) { } void ArrowLight_Destroy(Actor* thisx, GlobalContext* globalCtx) { - func_800876C8(globalCtx); + Magic_ResetState(globalCtx); LOG_STRING("消滅", "../z_arrow_light.c", 403); // "Disappearance" } diff --git a/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c b/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c index 18679d19547..3f555c3cb7c 100644 --- a/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c +++ b/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c @@ -467,7 +467,7 @@ void BgDyYoseizo_HealPlayer_NoReward(BgDyYoseizo* this, GlobalContext* globalCtx this->refillTimer = 200; } - if (((gSaveContext.healthCapacity == gSaveContext.health) && (gSaveContext.magic == gSaveContext.unk_13F4)) || + if (((gSaveContext.healthCapacity == gSaveContext.health) && (gSaveContext.magic == gSaveContext.magicMaxDrawn)) || (this->refillTimer == 1)) { this->healingTimer--; if (this->healingTimer == 90) { @@ -711,7 +711,7 @@ void BgDyYoseizo_Give_Reward(BgDyYoseizo* this, GlobalContext* globalCtx) { switch (actionIndex) { case FAIRY_UPGRADE_MAGIC: gSaveContext.magicAcquired = true; - gSaveContext.unk_13F6 = 0x30; + gSaveContext.magicMax = MAGIC_HALF_BAR; Interface_ChangeAlpha(9); break; case FAIRY_UPGRADE_DOUBLE_MAGIC: @@ -719,7 +719,7 @@ void BgDyYoseizo_Give_Reward(BgDyYoseizo* this, GlobalContext* globalCtx) { gSaveContext.magicAcquired = true; } gSaveContext.doubleMagic = true; - gSaveContext.unk_13F6 = 0x60; + gSaveContext.magicMax = MAGIC_FULL_BAR; gSaveContext.magicLevel = 0; Interface_ChangeAlpha(9); break; @@ -752,8 +752,8 @@ void BgDyYoseizo_Give_Reward(BgDyYoseizo* this, GlobalContext* globalCtx) { itemPos.x, itemPos.y, itemPos.z, 0, 0, 0, sExItemTypes[actionIndex]); if (this->item != NULL) { - if (gSaveContext.magicAcquired == 0) { - gSaveContext.magicAcquired = 1; + if (!gSaveContext.magicAcquired) { + gSaveContext.magicAcquired = true; } else { Magic_Fill(globalCtx); } diff --git a/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c b/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c index d7f114d2f35..6236a4cbcc5 100644 --- a/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c +++ b/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c @@ -1191,7 +1191,7 @@ void BossGanon_SetupTowerCutscene(BossGanon* this, GlobalContext* globalCtx) { this->csTimer = 0; this->csState = 100; this->unk_198 = 1; - gSaveContext.magic = gSaveContext.unk_13F4; + gSaveContext.magic = gSaveContext.magicMaxDrawn; gSaveContext.health = gSaveContext.healthCapacity; } else { this->actionFunc = BossGanon_SetupTowerCutscene; diff --git a/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c b/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c index 352e0afb231..4438a56b044 100644 --- a/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c +++ b/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c @@ -84,9 +84,9 @@ void EnMThunder_Init(Actor* thisx, GlobalContext* globalCtx2) { this->unk_1CA = 0; if (player->stateFlags2 & PLAYER_STATE2_17) { - if (!gSaveContext.magicAcquired || gSaveContext.unk_13F0 || + if (!gSaveContext.magicAcquired || (gSaveContext.magicState != MAGIC_STATE_DEFAULT) || (((this->actor.params & 0xFF00) >> 8) && - !(func_80087708(globalCtx, (this->actor.params & 0xFF00) >> 8, 0)))) { + !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_CHANGE_0)))) { Audio_PlaySoundGeneral(NA_SE_IT_ROLLING_CUT, &player->actor.projectedPos, 4, &D_801333E0, &D_801333E0, &D_801333E8); Audio_PlaySoundGeneral(NA_SE_IT_SWORD_SWING_HARD, &player->actor.projectedPos, 4, &D_801333E0, &D_801333E0, @@ -115,7 +115,7 @@ void EnMThunder_Destroy(Actor* thisx, GlobalContext* globalCtx) { EnMThunder* this = (EnMThunder*)thisx; if (this->unk_1CA != 0) { - func_800876C8(globalCtx); + Magic_ResetState(globalCtx); } Collider_DestroyCylinder(globalCtx, &this->collider); @@ -157,8 +157,9 @@ void func_80A9F408(EnMThunder* this, GlobalContext* globalCtx) { if (this->unk_1CA == 0) { if (player->unk_858 >= 0.1f) { - if ((gSaveContext.unk_13F0) || (((this->actor.params & 0xFF00) >> 8) && - !(func_80087708(globalCtx, (this->actor.params & 0xFF00) >> 8, 4)))) { + if ((gSaveContext.magicState != MAGIC_STATE_DEFAULT) || + (((this->actor.params & 0xFF00) >> 8) && + !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_CHANGE_4)))) { func_80A9F350(this, globalCtx); func_80A9EFE0(this, func_80A9F350); this->unk_1C8 = 0; @@ -192,7 +193,7 @@ void func_80A9F408(EnMThunder* this, GlobalContext* globalCtx) { } else { player->stateFlags2 &= ~PLAYER_STATE2_17; if ((this->actor.params & 0xFF00) >> 8) { - gSaveContext.unk_13F0 = 1; + gSaveContext.magicState = MAGIC_STATE_1; } if (player->unk_858 < 0.85f) { this->collider.info.toucher.dmgFlags = D_80AA044C[this->unk_1C7]; diff --git a/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c b/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c index c70eb25ae40..c086c857d33 100644 --- a/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c +++ b/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c @@ -532,7 +532,7 @@ void EnTorch2_Update(Actor* thisx, GlobalContext* globalCtx2) { // Causes Dark Link to shield in place when Link is using magic attacks other than the spin attack - if ((gSaveContext.unk_13F0 == 3) && + if ((gSaveContext.magicState == MAGIC_STATE_BORDER_FREEZE_DARK_LINK) && (player->meleeWeaponState == 0 || !((player->meleeWeaponAnimation >= PLAYER_MWA_SPIN_ATTACK_1H) && (player->meleeWeaponAnimation <= PLAYER_MWA_BIG_SPIN_2H)))) { sStickTilt = 0.0f; diff --git a/src/overlays/actors/ovl_En_Zl3/z_en_zl3.c b/src/overlays/actors/ovl_En_Zl3/z_en_zl3.c index 58a7ee540c2..7beef63b008 100644 --- a/src/overlays/actors/ovl_En_Zl3/z_en_zl3.c +++ b/src/overlays/actors/ovl_En_Zl3/z_en_zl3.c @@ -1812,7 +1812,7 @@ void func_80B5772C(EnZl3* this, GlobalContext* globalCtx) { } void func_80B57754(EnZl3* this, GlobalContext* globalCtx) { - if (gSaveContext.unk_13F0 == 0) { + if (gSaveContext.magicState == MAGIC_STATE_DEFAULT) { Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_OCEFF_WIPE4, this->actor.world.pos.x, this->actor.world.pos.y, this->actor.world.pos.z, 0, 0, 0, 1); func_80B56DA4(this); diff --git a/src/overlays/actors/ovl_Magic_Dark/z_magic_dark.c b/src/overlays/actors/ovl_Magic_Dark/z_magic_dark.c index 3d102885a0e..15c86218bec 100644 --- a/src/overlays/actors/ovl_Magic_Dark/z_magic_dark.c +++ b/src/overlays/actors/ovl_Magic_Dark/z_magic_dark.c @@ -64,7 +64,7 @@ void MagicDark_Init(Actor* thisx, GlobalContext* globalCtx) { void MagicDark_Destroy(Actor* thisx, GlobalContext* globalCtx) { if (gSaveContext.nayrusLoveTimer == 0) { - func_800876C8(globalCtx); + Magic_ResetState(globalCtx); } } diff --git a/src/overlays/actors/ovl_Magic_Fire/z_magic_fire.c b/src/overlays/actors/ovl_Magic_Fire/z_magic_fire.c index fb3447af6d5..978dbcb86f8 100644 --- a/src/overlays/actors/ovl_Magic_Fire/z_magic_fire.c +++ b/src/overlays/actors/ovl_Magic_Fire/z_magic_fire.c @@ -92,7 +92,7 @@ void MagicFire_Init(Actor* thisx, GlobalContext* globalCtx) { } void MagicFire_Destroy(Actor* thisx, GlobalContext* globalCtx) { - func_800876C8(globalCtx); + Magic_ResetState(globalCtx); } void MagicFire_UpdateBeforeCast(Actor* thisx, GlobalContext* globalCtx) { diff --git a/src/overlays/actors/ovl_Magic_Wind/z_magic_wind.c b/src/overlays/actors/ovl_Magic_Wind/z_magic_wind.c index 6ac1ee46560..7eb3d0dd634 100644 --- a/src/overlays/actors/ovl_Magic_Wind/z_magic_wind.c +++ b/src/overlays/actors/ovl_Magic_Wind/z_magic_wind.c @@ -69,7 +69,7 @@ void MagicWind_Init(Actor* thisx, GlobalContext* globalCtx) { void MagicWind_Destroy(Actor* thisx, GlobalContext* globalCtx) { MagicWind* this = (MagicWind*)thisx; SkelCurve_Destroy(globalCtx, &this->skelCurve); - func_800876C8(globalCtx); + Magic_ResetState(globalCtx); // "wipe out" LOG_STRING("消滅", "../z_magic_wind.c", 505); } diff --git a/src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c b/src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c index 810838fb506..fb7f104cfc3 100644 --- a/src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c +++ b/src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c @@ -69,7 +69,7 @@ void OceffSpot_Destroy(Actor* thisx, GlobalContext* globalCtx) { LightContext_RemoveLight(globalCtx, &globalCtx->lightCtx, this->lightNode1); LightContext_RemoveLight(globalCtx, &globalCtx->lightCtx, this->lightNode2); - func_800876C8(globalCtx); + Magic_ResetState(globalCtx); if ((gSaveContext.nayrusLoveTimer != 0) && (globalCtx->actorCtx.actorLists[ACTORCAT_PLAYER].length != 0)) { player->stateFlags3 |= PLAYER_STATE3_6; } diff --git a/src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c b/src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c index ad0aebf89b6..ebfe3f8987a 100644 --- a/src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c +++ b/src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c @@ -59,7 +59,7 @@ void OceffStorm_Destroy(Actor* thisx, GlobalContext* globalCtx) { OceffStorm* this = (OceffStorm*)thisx; Player* player = GET_PLAYER(globalCtx); - func_800876C8(globalCtx); + Magic_ResetState(globalCtx); if (gSaveContext.nayrusLoveTimer != 0) { player->stateFlags3 |= PLAYER_STATE3_6; } diff --git a/src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c b/src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c index a39b5206a9d..13d4e884661 100644 --- a/src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c +++ b/src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c @@ -39,7 +39,7 @@ void OceffWipe_Destroy(Actor* thisx, GlobalContext* globalCtx) { OceffWipe* this = (OceffWipe*)thisx; Player* player = GET_PLAYER(globalCtx); - func_800876C8(globalCtx); + Magic_ResetState(globalCtx); if (gSaveContext.nayrusLoveTimer != 0) { player->stateFlags3 |= PLAYER_STATE3_6; } diff --git a/src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c b/src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c index 66637178bc2..df2e93cc263 100644 --- a/src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c +++ b/src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c @@ -39,7 +39,7 @@ void OceffWipe2_Destroy(Actor* thisx, GlobalContext* globalCtx) { OceffWipe2* this = (OceffWipe2*)thisx; Player* player = GET_PLAYER(globalCtx); - func_800876C8(globalCtx); + Magic_ResetState(globalCtx); if (gSaveContext.nayrusLoveTimer != 0) { player->stateFlags3 |= PLAYER_STATE3_6; } diff --git a/src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c b/src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c index 0b7ca33c3db..7a85ed5808f 100644 --- a/src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c +++ b/src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c @@ -42,7 +42,7 @@ void OceffWipe3_Destroy(Actor* thisx, GlobalContext* globalCtx) { OceffWipe3* this = (OceffWipe3*)thisx; Player* player = GET_PLAYER(globalCtx); - func_800876C8(globalCtx); + Magic_ResetState(globalCtx); if (gSaveContext.nayrusLoveTimer != 0) { player->stateFlags3 |= PLAYER_STATE3_6; } diff --git a/src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c b/src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c index 27011c4474f..eccf21c8e3d 100644 --- a/src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c +++ b/src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c @@ -38,7 +38,7 @@ void OceffWipe4_Init(Actor* thisx, GlobalContext* globalCtx) { void OceffWipe4_Destroy(Actor* thisx, GlobalContext* globalCtx) { OceffWipe4* this = (OceffWipe4*)thisx; - func_800876C8(globalCtx); + Magic_ResetState(globalCtx); } void OceffWipe4_Update(Actor* thisx, GlobalContext* globalCtx) { diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index af79764ad74..e47e5d4f5b6 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -2174,7 +2174,7 @@ s32 func_8083442C(Player* this, GlobalContext* globalCtx) { s32 magicArrowType; if ((this->heldItemActionParam >= PLAYER_AP_BOW_FIRE) && (this->heldItemActionParam <= PLAYER_AP_BOW_0E) && - (gSaveContext.unk_13F0 != 0)) { + (gSaveContext.magicState != MAGIC_STATE_DEFAULT)) { func_80078884(NA_SE_SY_ERROR); } else { func_80833638(this, func_808351D4); @@ -2190,7 +2190,7 @@ s32 func_8083442C(Player* this, GlobalContext* globalCtx) { if (this->unk_860 >= 0) { if ((magicArrowType >= 0) && (magicArrowType <= 2) && - !func_80087708(globalCtx, sMagicArrowCosts[magicArrowType], 0)) { + !Magic_ChangeBy(globalCtx, sMagicArrowCosts[magicArrowType], MAGIC_CHANGE_0)) { arrowType = ARROW_NORMAL; } @@ -2885,7 +2885,7 @@ void func_80835F44(GlobalContext* globalCtx, Player* this, s32 item) { } if (actionParam == PLAYER_AP_LENS) { - if (func_80087708(globalCtx, 0, 3)) { + if (Magic_ChangeBy(globalCtx, 0, MAGIC_CHANGE_3)) { if (globalCtx->actorCtx.lensActive) { Actor_DisableLens(globalCtx); } else { @@ -2910,7 +2910,7 @@ void func_80835F44(GlobalContext* globalCtx, Player* this, s32 item) { temp = Player_ActionToMagicSpell(this, actionParam); if (temp >= 0) { if (((actionParam == PLAYER_AP_FARORES_WIND) && (gSaveContext.respawn[RESPAWN_MODE_TOP].data > 0)) || - ((gSaveContext.unk_13F4 != 0) && (gSaveContext.unk_13F0 == 0) && + ((gSaveContext.magicMaxDrawn != 0) && (gSaveContext.magicState == MAGIC_STATE_DEFAULT) && (gSaveContext.magic >= sMagicSpellCosts[temp]))) { this->itemActionParam = actionParam; this->unk_6AD = 4; @@ -4849,7 +4849,7 @@ void func_8083AF44(GlobalContext* globalCtx, Player* this, s32 magicSpell) { func_80835DE4(globalCtx, this, func_808507F4, 0); this->unk_84F = magicSpell - 3; - func_80087708(globalCtx, sMagicSpellCosts[magicSpell], 4); + Magic_ChangeBy(globalCtx, sMagicSpellCosts[magicSpell], MAGIC_CHANGE_4); LinkAnimation_PlayOnceSetSpeed(globalCtx, &this->skelAnime, &gPlayerAnim_002D28, 0.83f); @@ -9368,7 +9368,7 @@ void Player_Init(Actor* thisx, GlobalContext* globalCtx2) { } if (gSaveContext.nayrusLoveTimer != 0) { - gSaveContext.unk_13F0 = 3; + gSaveContext.magicState = MAGIC_STATE_BORDER_FREEZE_DARK_LINK; func_80846A00(globalCtx, this, 1); this->stateFlags3 &= ~PLAYER_STATE3_6; } @@ -10155,8 +10155,9 @@ void Player_UpdateCommon(Player* this, GlobalContext* globalCtx, Input* input) { func_80848C74(globalCtx, this); } - if ((this->stateFlags3 & PLAYER_STATE3_6) && (gSaveContext.nayrusLoveTimer != 0) && (gSaveContext.unk_13F0 == 0)) { - gSaveContext.unk_13F0 = 3; + if ((this->stateFlags3 & PLAYER_STATE3_6) && (gSaveContext.nayrusLoveTimer != 0) && + (gSaveContext.magicState == MAGIC_STATE_DEFAULT)) { + gSaveContext.magicState = MAGIC_STATE_BORDER_FREEZE_DARK_LINK; func_80846A00(globalCtx, this, 1); this->stateFlags3 &= ~PLAYER_STATE3_6; } @@ -10746,7 +10747,7 @@ void Player_Destroy(Actor* thisx, GlobalContext* globalCtx) { Collider_DestroyQuad(globalCtx, &this->meleeWeaponQuads[1]); Collider_DestroyQuad(globalCtx, &this->shieldQuad); - func_800876C8(globalCtx); + Magic_ResetState(globalCtx); gSaveContext.linkAge = globalCtx->linkAgeOnLoad; } @@ -12354,7 +12355,7 @@ void func_8084EAC0(Player* this, GlobalContext* globalCtx) { func_8083C0E8(this, globalCtx); func_8005B1A4(Gameplay_GetCamera(globalCtx, 0)); } else if (this->unk_850 == 1) { - if ((gSaveContext.healthAccumulator == 0) && (gSaveContext.unk_13F0 != 9)) { + if ((gSaveContext.healthAccumulator == 0) && (gSaveContext.magicState != MAGIC_STATE_FILL)) { func_80832B78(globalCtx, this, &gPlayerAnim_002660); this->unk_850 = 2; Player_UpdateBottleHeld(globalCtx, this, ITEM_BOTTLE, PLAYER_AP_BOTTLE); @@ -13095,7 +13096,7 @@ static struct_80832924 D_80854A8C[][2] = { void func_808507F4(Player* this, GlobalContext* globalCtx) { if (LinkAnimation_Update(globalCtx, &this->skelAnime)) { if (this->unk_84F < 0) { - if ((this->itemActionParam == PLAYER_AP_NAYRUS_LOVE) || (gSaveContext.unk_13F0 == 0)) { + if ((this->itemActionParam == PLAYER_AP_NAYRUS_LOVE) || (gSaveContext.magicState == MAGIC_STATE_DEFAULT)) { func_80839FFC(this, globalCtx); func_8005B1A4(Gameplay_GetCamera(globalCtx, 0)); } @@ -13106,10 +13107,10 @@ void func_808507F4(Player* this, GlobalContext* globalCtx) { if (func_80846A00(globalCtx, this, this->unk_84F) != NULL) { this->stateFlags1 |= PLAYER_STATE1_28 | PLAYER_STATE1_29; if ((this->unk_84F != 0) || (gSaveContext.respawn[RESPAWN_MODE_TOP].data <= 0)) { - gSaveContext.unk_13F0 = 1; + gSaveContext.magicState = MAGIC_STATE_1; } } else { - func_800876C8(globalCtx); + Magic_ResetState(globalCtx); } } else { LinkAnimation_PlayLoopSetSpeed(globalCtx, &this->skelAnime, D_80854A64[this->unk_84F], 0.83f); diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index e1f4110c357..8be17a4b260 100644 --- a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -1461,8 +1461,8 @@ void FileChoose_LoadGame(GameState* thisx) { gSaveContext.unk_13EE = 0x32; gSaveContext.nayrusLoveTimer = 0; gSaveContext.healthAccumulator = 0; - gSaveContext.unk_13F0 = 0; - gSaveContext.unk_13F2 = 0; + gSaveContext.magicState = MAGIC_STATE_DEFAULT; + gSaveContext.magicStateStored = MAGIC_STATE_DEFAULT; gSaveContext.forcedSeqId = NA_BGM_GENERAL_SFX; gSaveContext.skyboxTime = 0; gSaveContext.nextTransition = 0xFF; @@ -1476,16 +1476,15 @@ void FileChoose_LoadGame(GameState* thisx) { gSaveContext.buttonStatus[3] = gSaveContext.buttonStatus[4] = BTN_ENABLED; gSaveContext.unk_13E7 = gSaveContext.unk_13E8 = gSaveContext.unk_13EA = gSaveContext.unk_13EC = - gSaveContext.unk_13F4 = 0; + gSaveContext.magicMaxDrawn = 0; - gSaveContext.unk_13F6 = gSaveContext.magic; - gSaveContext.magic = 0; - gSaveContext.magicLevel = gSaveContext.magic; + gSaveContext.magicMax = gSaveContext.magic; + gSaveContext.magicLevel = gSaveContext.magic = 0; if (1) {} osSyncPrintf(VT_FGCOL(GREEN)); - osSyncPrintf("Z_MAGIC_NOW_NOW=%d MAGIC_NOW=%d\n", ((void)0, gSaveContext.unk_13F6), gSaveContext.magic); + osSyncPrintf("Z_MAGIC_NOW_NOW=%d MAGIC_NOW=%d\n", ((void)0, gSaveContext.magicMax), gSaveContext.magic); osSyncPrintf(VT_RST); gSaveContext.naviTimer = 0; diff --git a/src/overlays/gamestates/ovl_select/z_select.c b/src/overlays/gamestates/ovl_select/z_select.c index ba742459f8a..5e787ea2bc2 100644 --- a/src/overlays/gamestates/ovl_select/z_select.c +++ b/src/overlays/gamestates/ovl_select/z_select.c @@ -20,10 +20,9 @@ void Select_LoadGame(SelectContext* this, s32 entranceIndex) { osSyncPrintf(VT_RST); if (gSaveContext.fileNum == 0xFF) { Sram_InitDebugSave(); - gSaveContext.unk_13F6 = gSaveContext.magic; - gSaveContext.magic = 0; - gSaveContext.unk_13F4 = 0; - gSaveContext.magicLevel = gSaveContext.magic; + gSaveContext.magicMax = gSaveContext.magic; + gSaveContext.magicMaxDrawn = 0; + gSaveContext.magicLevel = gSaveContext.magic = 0; } gSaveContext.buttonStatus[0] = gSaveContext.buttonStatus[1] = gSaveContext.buttonStatus[2] = gSaveContext.buttonStatus[3] = gSaveContext.buttonStatus[4] = BTN_ENABLED; diff --git a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c index 357a170a42b..a8a31d4365d 100644 --- a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c +++ b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c @@ -3385,16 +3385,16 @@ void KaleidoScope_Update(GlobalContext* globalCtx) { gSaveContext.health = 0x30; Audio_QueueSeqCmd(0xF << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0xA); gSaveContext.healthAccumulator = 0; - gSaveContext.unk_13F0 = 0; - gSaveContext.unk_13F2 = 0; + gSaveContext.magicState = MAGIC_STATE_DEFAULT; + gSaveContext.magicStateStored = MAGIC_STATE_DEFAULT; osSyncPrintf(VT_FGCOL(YELLOW)); osSyncPrintf("MAGIC_NOW=%d ", gSaveContext.magic); - osSyncPrintf("Z_MAGIC_NOW_NOW=%d → ", gSaveContext.unk_13F6); - gSaveContext.unk_13F4 = 0; - gSaveContext.unk_13F6 = gSaveContext.magic; + osSyncPrintf("Z_MAGIC_NOW_NOW=%d → ", gSaveContext.magicMax); + gSaveContext.magicMaxDrawn = 0; + gSaveContext.magicMax = gSaveContext.magic; gSaveContext.magicLevel = gSaveContext.magic = 0; osSyncPrintf("MAGIC_NOW=%d ", gSaveContext.magic); - osSyncPrintf("Z_MAGIC_NOW_NOW=%d\n", gSaveContext.unk_13F6); + osSyncPrintf("Z_MAGIC_NOW_NOW=%d\n", gSaveContext.magicMax); osSyncPrintf(VT_RST); } else { globalCtx->state.running = 0; From b5e6ac8cac1de5de652bdc6f1270cbd47752d108 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Tue, 19 Apr 2022 11:05:53 +1000 Subject: [PATCH 02/33] More docs, first round finished --- include/functions.h | 2 +- include/z64save.h | 16 ++++++++-------- src/code/z_parameter.c | 18 +++++++++--------- .../actors/ovl_En_M_Thunder/z_en_m_thunder.c | 6 +++--- .../actors/ovl_player_actor/z_player.c | 8 ++++---- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/include/functions.h b/include/functions.h index 004d932b6b5..4bfc4c2d31c 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1044,7 +1044,7 @@ void Rupees_ChangeBy(s16 rupeeChange); void Inventory_ChangeAmmo(s16 item, s16 ammoChange); void Magic_Fill(GlobalContext* globalCtx); void Magic_ResetState(GlobalContext* globalCtx); -s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 arg1, s16 arg2); +s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType); void func_80088AA0(s16 arg0); void func_80088AF0(GlobalContext* globalCtx); void func_80088B34(s16 arg0); diff --git a/include/z64save.h b/include/z64save.h index e8e71d745ce..09ed168ea33 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -6,8 +6,8 @@ typedef enum MagicState { /* 00 */ MAGIC_STATE_DEFAULT, // Normal - /* 01 */ MAGIC_STATE_1, - /* 02 */ MAGIC_STATE_2, + /* 01 */ MAGIC_STATE_CHARGE_SETUP, + /* 02 */ MAGIC_STATE_CHARGE, /* 03 */ MAGIC_STATE_BORDER_FREEZE_DARK_LINK, // Using magic attacks other than the spin attack /* 04 */ MAGIC_STATE_BORDER_YELLOW_TARGET, // Yellow part of the bar indicating the amount of magic to be subtracted /* 05 */ MAGIC_STATE_RESET, @@ -19,16 +19,16 @@ typedef enum MagicState { } MagicState; typedef enum MagicChange { - /* 00 */ MAGIC_CHANGE_0, // Consume Magic (spell & spin attack) - /* 01 */ MAGIC_CHANGE_1, // Unused - /* 02 */ MAGIC_CHANGE_2, // Consume Magic Alt - /* 03 */ MAGIC_CHANGE_3, // Lens - /* 04 */ MAGIC_CHANGE_4, // Consume Magic (spell & spin attack) + /* 00 */ MAGIC_CHANGE_CONSUME_CHARGE, // Consume Magic (spell & spin attack) + /* 01 */ MAGIC_CHANGE_CONSUME_NOW_NO_YELLOW, // Unused + /* 02 */ MAGIC_CHANGE_CONSUME_CHARGE_ALT, // Consume Magic Alt + /* 03 */ MAGIC_CHANGE_CONSUME_LENS, // Lens + /* 04 */ MAGIC_CHANGE_CONSUME_NOW, // Consume Magic (spell & spin attack) /* 05 */ MAGIC_CHANGE_ADD } MagicChange; #define MAGIC_HALF_BAR 0x30 -#define MAGIC_FULL_BAR 0x60 +#define MAGIC_FULL_BAR (2 * MAGIC_HALF_BAR) typedef struct { /* 0x00 */ u8 buttonItems[4]; diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index 5085e0cded9..b83efb28ad4 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2268,21 +2268,21 @@ s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType) { } switch (changeType) { - case MAGIC_CHANGE_0: - case MAGIC_CHANGE_2: + case MAGIC_CHANGE_CONSUME_CHARGE: + case MAGIC_CHANGE_CONSUME_CHARGE_ALT: if ((gSaveContext.magicState == MAGIC_STATE_DEFAULT) || (gSaveContext.magicState == MAGIC_STATE_LENS_CONSUME)) { if (gSaveContext.magicState == MAGIC_STATE_LENS_CONSUME) { globalCtx->actorCtx.lensActive = false; } gSaveContext.yellowMagic = gSaveContext.magic - magicChange; - gSaveContext.magicState = MAGIC_STATE_1; + gSaveContext.magicState = MAGIC_STATE_CHARGE_SETUP; return true; } else { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); return false; } - case MAGIC_CHANGE_1: + case MAGIC_CHANGE_CONSUME_NOW_NO_YELLOW: if ((gSaveContext.magicState == MAGIC_STATE_DEFAULT) || (gSaveContext.magicState == MAGIC_STATE_LENS_CONSUME)) { if (gSaveContext.magicState == MAGIC_STATE_LENS_CONSUME) { @@ -2295,7 +2295,7 @@ s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType) { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); return false; } - case MAGIC_CHANGE_3: + case MAGIC_CHANGE_CONSUME_LENS: if (gSaveContext.magicState == MAGIC_STATE_DEFAULT) { if (gSaveContext.magic != 0) { globalCtx->interfaceCtx.lensMagicDepletionTimer = 80; @@ -2311,7 +2311,7 @@ s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType) { return false; } } - case MAGIC_CHANGE_4: + case MAGIC_CHANGE_CONSUME_NOW: if ((gSaveContext.magicState == MAGIC_STATE_DEFAULT) || (gSaveContext.magicState == MAGIC_STATE_LENS_CONSUME)) { if (gSaveContext.magicState == MAGIC_STATE_LENS_CONSUME) { @@ -2395,12 +2395,12 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { } break; - case MAGIC_STATE_1: + case MAGIC_STATE_CHARGE_SETUP: sMagicBorderRatio = 2; - gSaveContext.magicState = MAGIC_STATE_2; + gSaveContext.magicState = MAGIC_STATE_CHARGE; break; - case MAGIC_STATE_2: + case MAGIC_STATE_CHARGE: gSaveContext.magic -= 2; if (gSaveContext.magic <= 0) { gSaveContext.magic = 0; diff --git a/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c b/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c index 4438a56b044..4a4c06ec16b 100644 --- a/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c +++ b/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c @@ -86,7 +86,7 @@ void EnMThunder_Init(Actor* thisx, GlobalContext* globalCtx2) { if (player->stateFlags2 & PLAYER_STATE2_17) { if (!gSaveContext.magicAcquired || (gSaveContext.magicState != MAGIC_STATE_DEFAULT) || (((this->actor.params & 0xFF00) >> 8) && - !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_CHANGE_0)))) { + !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_CHANGE_CONSUME_CHARGE)))) { Audio_PlaySoundGeneral(NA_SE_IT_ROLLING_CUT, &player->actor.projectedPos, 4, &D_801333E0, &D_801333E0, &D_801333E8); Audio_PlaySoundGeneral(NA_SE_IT_SWORD_SWING_HARD, &player->actor.projectedPos, 4, &D_801333E0, &D_801333E0, @@ -159,7 +159,7 @@ void func_80A9F408(EnMThunder* this, GlobalContext* globalCtx) { if (player->unk_858 >= 0.1f) { if ((gSaveContext.magicState != MAGIC_STATE_DEFAULT) || (((this->actor.params & 0xFF00) >> 8) && - !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_CHANGE_4)))) { + !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_CHANGE_CONSUME_NOW)))) { func_80A9F350(this, globalCtx); func_80A9EFE0(this, func_80A9F350); this->unk_1C8 = 0; @@ -193,7 +193,7 @@ void func_80A9F408(EnMThunder* this, GlobalContext* globalCtx) { } else { player->stateFlags2 &= ~PLAYER_STATE2_17; if ((this->actor.params & 0xFF00) >> 8) { - gSaveContext.magicState = MAGIC_STATE_1; + gSaveContext.magicState = MAGIC_STATE_CHARGE_SETUP; } if (player->unk_858 < 0.85f) { this->collider.info.toucher.dmgFlags = D_80AA044C[this->unk_1C7]; diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index e47e5d4f5b6..a433885fadd 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -2190,7 +2190,7 @@ s32 func_8083442C(Player* this, GlobalContext* globalCtx) { if (this->unk_860 >= 0) { if ((magicArrowType >= 0) && (magicArrowType <= 2) && - !Magic_ChangeBy(globalCtx, sMagicArrowCosts[magicArrowType], MAGIC_CHANGE_0)) { + !Magic_ChangeBy(globalCtx, sMagicArrowCosts[magicArrowType], MAGIC_CHANGE_CONSUME_CHARGE)) { arrowType = ARROW_NORMAL; } @@ -2885,7 +2885,7 @@ void func_80835F44(GlobalContext* globalCtx, Player* this, s32 item) { } if (actionParam == PLAYER_AP_LENS) { - if (Magic_ChangeBy(globalCtx, 0, MAGIC_CHANGE_3)) { + if (Magic_ChangeBy(globalCtx, 0, MAGIC_CHANGE_CONSUME_LENS)) { if (globalCtx->actorCtx.lensActive) { Actor_DisableLens(globalCtx); } else { @@ -4849,7 +4849,7 @@ void func_8083AF44(GlobalContext* globalCtx, Player* this, s32 magicSpell) { func_80835DE4(globalCtx, this, func_808507F4, 0); this->unk_84F = magicSpell - 3; - Magic_ChangeBy(globalCtx, sMagicSpellCosts[magicSpell], MAGIC_CHANGE_4); + Magic_ChangeBy(globalCtx, sMagicSpellCosts[magicSpell], MAGIC_CHANGE_CONSUME_NOW); LinkAnimation_PlayOnceSetSpeed(globalCtx, &this->skelAnime, &gPlayerAnim_002D28, 0.83f); @@ -13107,7 +13107,7 @@ void func_808507F4(Player* this, GlobalContext* globalCtx) { if (func_80846A00(globalCtx, this, this->unk_84F) != NULL) { this->stateFlags1 |= PLAYER_STATE1_28 | PLAYER_STATE1_29; if ((this->unk_84F != 0) || (gSaveContext.respawn[RESPAWN_MODE_TOP].data <= 0)) { - gSaveContext.magicState = MAGIC_STATE_1; + gSaveContext.magicState = MAGIC_STATE_CHARGE_SETUP; } } else { Magic_ResetState(globalCtx); From bf2858b27c227f9ae0b1e9de2419f8f56f1282ac Mon Sep 17 00:00:00 2001 From: engineer124 Date: Tue, 19 Apr 2022 23:25:55 +1000 Subject: [PATCH 03/33] Better docs --- include/z64save.h | 58 +++--- src/code/z_elf_message.c | 2 +- src/code/z_kaleido_setup.c | 4 +- src/code/z_parameter.c | 187 +++++++++--------- src/code/z_player_lib.c | 2 +- src/code/z_sram.c | 16 +- .../ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c | 27 +-- .../actors/ovl_Boss_Ganon/z_boss_ganon.c | 2 +- .../actors/ovl_En_M_Thunder/z_en_m_thunder.c | 10 +- src/overlays/actors/ovl_En_Owl/z_en_owl.c | 2 +- .../actors/ovl_En_Torch2/z_en_torch2.c | 2 +- src/overlays/actors/ovl_En_Zl3/z_en_zl3.c | 2 +- .../actors/ovl_player_actor/z_player.c | 23 +-- .../ovl_file_choose/z_file_choose.c | 10 +- src/overlays/gamestates/ovl_select/z_select.c | 4 +- .../ovl_kaleido_scope/z_kaleido_scope_PAL.c | 12 +- 16 files changed, 184 insertions(+), 179 deletions(-) diff --git a/include/z64save.h b/include/z64save.h index 09ed168ea33..50481db22da 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -4,28 +4,28 @@ #include "ultra64.h" #include "z64math.h" -typedef enum MagicState { - /* 00 */ MAGIC_STATE_DEFAULT, // Normal - /* 01 */ MAGIC_STATE_CHARGE_SETUP, - /* 02 */ MAGIC_STATE_CHARGE, - /* 03 */ MAGIC_STATE_BORDER_FREEZE_DARK_LINK, // Using magic attacks other than the spin attack - /* 04 */ MAGIC_STATE_BORDER_YELLOW_TARGET, // Yellow part of the bar indicating the amount of magic to be subtracted - /* 05 */ MAGIC_STATE_RESET, - /* 06 */ MAGIC_STATE_BORDER_STANDARD, - /* 07 */ MAGIC_STATE_LENS_CONSUME, // Lens - /* 08 */ MAGIC_STATE_INIT, // Init magic, starting a new load - /* 09 */ MAGIC_STATE_FILL, // Fill to max - /* 10 */ MAGIC_STATE_ADD // Add -} MagicState; - -typedef enum MagicChange { - /* 00 */ MAGIC_CHANGE_CONSUME_CHARGE, // Consume Magic (spell & spin attack) - /* 01 */ MAGIC_CHANGE_CONSUME_NOW_NO_YELLOW, // Unused - /* 02 */ MAGIC_CHANGE_CONSUME_CHARGE_ALT, // Consume Magic Alt - /* 03 */ MAGIC_CHANGE_CONSUME_LENS, // Lens - /* 04 */ MAGIC_CHANGE_CONSUME_NOW, // Consume Magic (spell & spin attack) - /* 05 */ MAGIC_CHANGE_ADD -} MagicChange; +typedef enum MagicBarAction { + /* 00 */ MAGIC_BAR_ACTION_IDLE, // Regular gameplay + /* 01 */ MAGIC_BAR_ACTION_CHARGE_SETUP, + /* 02 */ MAGIC_BAR_ACTION_CHARGE, + /* 03 */ MAGIC_BAR_ACTION_BORDER_FREEZE_DARK_LINK, // Using magic attacks other than the spin attack + /* 04 */ MAGIC_BAR_ACTION_BORDER_YELLOW_TARGET, // Yellow part of the bar indicating the amount of magic to be subtracted + /* 05 */ MAGIC_BAR_ACTION_RESET, // Reset colors and return to idle + /* 06 */ MAGIC_BAR_ACTION_BORDER_STANDARD, + /* 07 */ MAGIC_BAR_ACTION_LENS_CONSUME, // Magic slowly consumed by lens. + /* 08 */ MAGIC_BAR_ACTION_GROW_WIDE, // Init magic on a new load, grow from a width of 0 to magicCapacity + /* 09 */ MAGIC_BAR_ACTION_FILL, // Fill to full capacity + /* 10 */ MAGIC_BAR_ACTION_ADD // Add requested magic +} MagicBarAction; + +typedef enum MagicBarChange { + /* 00 */ MAGIC_BAR_CONSUME_CHARGE, // Consume Magic (spell & spin attack) + /* 01 */ MAGIC_BAR_CONSUME_NO_PREVIEW, // Unused + /* 02 */ MAGIC_BAR_CONSUME_CHARGE_ALT, // Consume Magic Alt + /* 03 */ MAGIC_BAR_CONSUME_LENS, // Lens + /* 04 */ MAGIC_BAR_CONSUME_PREVIEW, // Consume Magic (spell & spin attack) + /* 05 */ MAGIC_BAR_ADD +} MagicBarChange; #define MAGIC_HALF_BAR 0x30 #define MAGIC_FULL_BAR (2 * MAGIC_HALF_BAR) @@ -105,9 +105,9 @@ typedef struct { /* 0x0034 */ s16 rupees; /* 0x0036 */ u16 swordHealth; /* 0x0038 */ u16 naviTimer; - /* 0x003A */ u8 magicAcquired; + /* 0x003A */ u8 isMagicAcquired; /* 0x003B */ char unk_3B[0x01]; - /* 0x003C */ u8 doubleMagic; + /* 0x003C */ u8 isDoubleMagicAcquired; /* 0x003D */ u8 doubleDefense; /* 0x003E */ u8 bgsFlag; /* 0x003F */ u8 ocarinaGameRoundNum; @@ -169,11 +169,11 @@ typedef struct { /* 0x13EA */ u16 unk_13EA; // also alpha type? /* 0x13EC */ u16 unk_13EC; // alpha type counter? /* 0x13EE */ u16 unk_13EE; // previous alpha type? - /* 0x13F0 */ s16 magicState; - /* 0x13F2 */ s16 magicStateStored; // stores the previous magic state so it can be restored - /* 0x13F4 */ s16 magicMaxDrawn; // Only differs from magicMax in a new save load, where magicMaxDrawn is slowly stepped from 0 to magicMax - /* 0x13F6 */ s16 magicMax; - /* 0x13F8 */ s16 yellowMagic; // preview of the magic about to be consumed + /* 0x13F0 */ s16 magicBarAction; + /* 0x13F2 */ s16 magicBarActionStored; // stores the previous magic state while magic is increasing. Allows magicBarAction to be restored afterwards + /* 0x13F4 */ s16 magicCapacityDrawn; // Only differs from magicCapacity in a new save load, where magicCapacityDrawn is slowly stepped from 0 to magicCapacity + /* 0x13F6 */ s16 magicCapacity; // Maximum magic available + /* 0x13F8 */ s16 magicTarget; // Target for magic to step to when adding or consuming magic /* 0x13FA */ u16 eventInf[4]; // "event_inf" /* 0x1402 */ u16 mapIndex; // intended for maps/minimaps but commonly used as the dungeon index /* 0x1404 */ u16 minigameState; diff --git a/src/code/z_elf_message.c b/src/code/z_elf_message.c index 370fe8d419b..c1db943a462 100644 --- a/src/code/z_elf_message.c +++ b/src/code/z_elf_message.c @@ -54,7 +54,7 @@ u32 ElfMessage_CheckCondition(ElfMessage* msg) { return ((msg->byte0 & 1) == 1) == (CHECK_QUEST_ITEM(msg->byte3 - ITEM_MEDALLION_FOREST + QUEST_MEDALLION_FOREST) != 0); case (ELF_MSG_CONDITION_MAGIC << 4): - return ((msg->byte0 & 1) == 1) == (((void)0, gSaveContext.magicAcquired) != 0); + return ((msg->byte0 & 1) == 1) == (((void)0, gSaveContext.isMagicAcquired) != 0); } } diff --git a/src/code/z_kaleido_setup.c b/src/code/z_kaleido_setup.c index adf5712aa2e..0207d9e003e 100644 --- a/src/code/z_kaleido_setup.c +++ b/src/code/z_kaleido_setup.c @@ -15,8 +15,8 @@ void KaleidoSetup_Update(GlobalContext* globalCtx) { if (pauseCtx->state == 0 && pauseCtx->debugState == 0 && globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE && globalCtx->sceneLoadFlag == 0 && globalCtx->transitionMode == 0 && gSaveContext.cutsceneIndex < 0xFFF0 && gSaveContext.nextCutsceneIndex < 0xFFF0 && !Gameplay_InCsMode(globalCtx) && - globalCtx->shootingGalleryStatus <= 1 && gSaveContext.magicState != MAGIC_STATE_INIT && - gSaveContext.magicState != MAGIC_STATE_FILL && + globalCtx->shootingGalleryStatus <= 1 && gSaveContext.magicBarAction != MAGIC_BAR_ACTION_GROW_WIDE && + gSaveContext.magicBarAction != MAGIC_BAR_ACTION_FILL && (globalCtx->sceneNum != SCENE_BOWLING || !Flags_GetSwitch(globalCtx, 0x38))) { if (CHECK_BTN_ALL(input->cur.button, BTN_L) && CHECK_BTN_ALL(input->press.button, BTN_CUP)) { diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index b83efb28ad4..cced68e2cb4 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -1672,11 +1672,11 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { Health_ChangeBy(globalCtx, 0x10); return item; } else if (item == ITEM_MAGIC_SMALL) { - if (gSaveContext.magicState != MAGIC_STATE_ADD) { + if (gSaveContext.magicBarAction != MAGIC_BAR_ACTION_ADD) { Magic_Fill(globalCtx); } - Magic_ChangeBy(globalCtx, 12, MAGIC_CHANGE_ADD); + Magic_ChangeBy(globalCtx, 12, MAGIC_BAR_ADD); if (!(gSaveContext.infTable[25] & 0x100)) { gSaveContext.infTable[25] |= 0x100; @@ -1685,11 +1685,11 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { return item; } else if (item == ITEM_MAGIC_LARGE) { - if (gSaveContext.magicState != MAGIC_STATE_ADD) { + if (gSaveContext.magicBarAction != MAGIC_BAR_ACTION_ADD) { Magic_Fill(globalCtx); } - Magic_ChangeBy(globalCtx, 24, MAGIC_CHANGE_ADD); + Magic_ChangeBy(globalCtx, 24, MAGIC_BAR_ADD); if (!(gSaveContext.infTable[25] & 0x100)) { gSaveContext.infTable[25] |= 0x100; @@ -2239,100 +2239,101 @@ void Inventory_ChangeAmmo(s16 item, s16 ammoChange) { } void Magic_Fill(GlobalContext* globalCtx) { - if (gSaveContext.magicAcquired) { - gSaveContext.magicStateStored = gSaveContext.magicState; - gSaveContext.magicMax = (gSaveContext.doubleMagic + 1) * MAGIC_HALF_BAR; - gSaveContext.magicState = MAGIC_STATE_FILL; + if (gSaveContext.isMagicAcquired) { + gSaveContext.magicBarActionStored = gSaveContext.magicBarAction; + gSaveContext.magicCapacity = (gSaveContext.isDoubleMagicAcquired + 1) * MAGIC_HALF_BAR; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_FILL; } } void Magic_ResetState(GlobalContext* globalCtx) { - if ((gSaveContext.magicState != MAGIC_STATE_INIT) && (gSaveContext.magicState != MAGIC_STATE_FILL)) { - if (gSaveContext.magicState == MAGIC_STATE_ADD) { - gSaveContext.magicStateStored = gSaveContext.magicState; + if ((gSaveContext.magicBarAction != MAGIC_BAR_ACTION_GROW_WIDE) && + (gSaveContext.magicBarAction != MAGIC_BAR_ACTION_FILL)) { + if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_ADD) { + gSaveContext.magicBarActionStored = gSaveContext.magicBarAction; } - gSaveContext.magicState = MAGIC_STATE_RESET; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_RESET; } } s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType) { - if (!gSaveContext.magicAcquired) { + if (!gSaveContext.isMagicAcquired) { return false; } - if ((changeType != MAGIC_CHANGE_ADD) && (gSaveContext.magic - magicChange) < 0) { - if (gSaveContext.magicMaxDrawn != 0) { + if ((changeType != MAGIC_BAR_ADD) && (gSaveContext.magic - magicChange) < 0) { + if (gSaveContext.magicCapacityDrawn != 0) { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); } return false; } switch (changeType) { - case MAGIC_CHANGE_CONSUME_CHARGE: - case MAGIC_CHANGE_CONSUME_CHARGE_ALT: - if ((gSaveContext.magicState == MAGIC_STATE_DEFAULT) || - (gSaveContext.magicState == MAGIC_STATE_LENS_CONSUME)) { - if (gSaveContext.magicState == MAGIC_STATE_LENS_CONSUME) { + case MAGIC_BAR_CONSUME_CHARGE: + case MAGIC_BAR_CONSUME_CHARGE_ALT: + if ((gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE) || + (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME)) { + if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME) { globalCtx->actorCtx.lensActive = false; } - gSaveContext.yellowMagic = gSaveContext.magic - magicChange; - gSaveContext.magicState = MAGIC_STATE_CHARGE_SETUP; + gSaveContext.magicTarget = gSaveContext.magic - magicChange; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CHARGE_SETUP; return true; } else { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); return false; } - case MAGIC_CHANGE_CONSUME_NOW_NO_YELLOW: - if ((gSaveContext.magicState == MAGIC_STATE_DEFAULT) || - (gSaveContext.magicState == MAGIC_STATE_LENS_CONSUME)) { - if (gSaveContext.magicState == MAGIC_STATE_LENS_CONSUME) { + case MAGIC_BAR_CONSUME_NO_PREVIEW: + if ((gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE) || + (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME)) { + if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME) { globalCtx->actorCtx.lensActive = false; } - gSaveContext.yellowMagic = gSaveContext.magic - magicChange; - gSaveContext.magicState = MAGIC_STATE_BORDER_STANDARD; + gSaveContext.magicTarget = gSaveContext.magic - magicChange; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_STANDARD; return true; } else { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); return false; } - case MAGIC_CHANGE_CONSUME_LENS: - if (gSaveContext.magicState == MAGIC_STATE_DEFAULT) { + case MAGIC_BAR_CONSUME_LENS: + if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE) { if (gSaveContext.magic != 0) { globalCtx->interfaceCtx.lensMagicDepletionTimer = 80; - gSaveContext.magicState = MAGIC_STATE_LENS_CONSUME; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_LENS_CONSUME; return true; } else { return false; } } else { - if (gSaveContext.magicState == MAGIC_STATE_LENS_CONSUME) { + if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME) { return true; } else { return false; } } - case MAGIC_CHANGE_CONSUME_NOW: - if ((gSaveContext.magicState == MAGIC_STATE_DEFAULT) || - (gSaveContext.magicState == MAGIC_STATE_LENS_CONSUME)) { - if (gSaveContext.magicState == MAGIC_STATE_LENS_CONSUME) { + case MAGIC_BAR_CONSUME_PREVIEW: + if ((gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE) || + (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME)) { + if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME) { globalCtx->actorCtx.lensActive = false; } - gSaveContext.yellowMagic = gSaveContext.magic - magicChange; - gSaveContext.magicState = MAGIC_STATE_BORDER_YELLOW_TARGET; + gSaveContext.magicTarget = gSaveContext.magic - magicChange; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_YELLOW_TARGET; return true; } else { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); return false; } - case MAGIC_CHANGE_ADD: - if (gSaveContext.magic <= gSaveContext.magicMaxDrawn) { - gSaveContext.yellowMagic = gSaveContext.magic + magicChange; + case MAGIC_BAR_ADD: + if (gSaveContext.magic <= gSaveContext.magicCapacityDrawn) { + gSaveContext.magicTarget = gSaveContext.magic + magicChange; - if (gSaveContext.yellowMagic >= gSaveContext.magicMaxDrawn) { - gSaveContext.yellowMagic = gSaveContext.magicMaxDrawn; + if (gSaveContext.magicTarget >= gSaveContext.magicCapacityDrawn) { + gSaveContext.magicTarget = gSaveContext.magicCapacityDrawn; } - gSaveContext.magicState = MAGIC_STATE_ADD; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_ADD; return true; } break; @@ -2358,27 +2359,29 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { s16 borderChangeB; s16 temp; - switch (gSaveContext.magicState) { - case MAGIC_STATE_INIT: - temp = gSaveContext.magicLevel * MAGIC_HALF_BAR; - if (gSaveContext.magicMaxDrawn != temp) { - if (gSaveContext.magicMaxDrawn < temp) { - gSaveContext.magicMaxDrawn += 8; - if (gSaveContext.magicMaxDrawn > temp) { - gSaveContext.magicMaxDrawn = temp; + switch (gSaveContext.magicBarAction) { + case MAGIC_BAR_ACTION_GROW_WIDE: + // Step magicCapacityDrawn to what is magicCapacity + // This changes the width of the magic bar drawn + temp = gSaveContext.magicLevel * MAGIC_HALF_BAR; // magicCapacity + if (gSaveContext.magicCapacityDrawn != temp) { + if (gSaveContext.magicCapacityDrawn < temp) { + gSaveContext.magicCapacityDrawn += 8; + if (gSaveContext.magicCapacityDrawn > temp) { + gSaveContext.magicCapacityDrawn = temp; } } else { - gSaveContext.magicMaxDrawn -= 8; - if (gSaveContext.magicMaxDrawn <= temp) { - gSaveContext.magicMaxDrawn = temp; + gSaveContext.magicCapacityDrawn -= 8; + if (gSaveContext.magicCapacityDrawn <= temp) { + gSaveContext.magicCapacityDrawn = temp; } } } else { - gSaveContext.magicState = MAGIC_STATE_FILL; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_FILL; } break; - case MAGIC_STATE_FILL: + case MAGIC_BAR_ACTION_FILL: gSaveContext.magic += 4; if (gSaveContext.gameMode == 0 && gSaveContext.sceneSetupIndex < 4) { @@ -2387,34 +2390,34 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { } // "Storage MAGIC_NOW=%d (%d)" - osSyncPrintf("蓄電 MAGIC_NOW=%d (%d)\n", gSaveContext.magic, gSaveContext.magicMax); - if (gSaveContext.magic >= gSaveContext.magicMax) { - gSaveContext.magic = gSaveContext.magicMax; - gSaveContext.magicState = gSaveContext.magicStateStored; - gSaveContext.magicStateStored = MAGIC_STATE_DEFAULT; + osSyncPrintf("蓄電 MAGIC_NOW=%d (%d)\n", gSaveContext.magic, gSaveContext.magicCapacity); + if (gSaveContext.magic >= gSaveContext.magicCapacity) { + gSaveContext.magic = gSaveContext.magicCapacity; + gSaveContext.magicBarAction = gSaveContext.magicBarActionStored; + gSaveContext.magicBarActionStored = MAGIC_BAR_ACTION_IDLE; } break; - case MAGIC_STATE_CHARGE_SETUP: + case MAGIC_BAR_ACTION_CHARGE_SETUP: sMagicBorderRatio = 2; - gSaveContext.magicState = MAGIC_STATE_CHARGE; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CHARGE; break; - case MAGIC_STATE_CHARGE: + case MAGIC_BAR_ACTION_CHARGE: gSaveContext.magic -= 2; if (gSaveContext.magic <= 0) { gSaveContext.magic = 0; - gSaveContext.magicState = MAGIC_STATE_BORDER_FREEZE_DARK_LINK; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_FREEZE_DARK_LINK; sMagicBorderR = sMagicBorderG = sMagicBorderB = 255; - } else if (gSaveContext.magic == gSaveContext.yellowMagic) { - gSaveContext.magicState = MAGIC_STATE_BORDER_FREEZE_DARK_LINK; + } else if (gSaveContext.magic == gSaveContext.magicTarget) { + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_FREEZE_DARK_LINK; sMagicBorderR = sMagicBorderG = sMagicBorderB = 255; } // fallthrough - case MAGIC_STATE_BORDER_FREEZE_DARK_LINK: - case MAGIC_STATE_BORDER_YELLOW_TARGET: - case MAGIC_STATE_BORDER_STANDARD: + case MAGIC_BAR_ACTION_BORDER_FREEZE_DARK_LINK: + case MAGIC_BAR_ACTION_BORDER_YELLOW_TARGET: + case MAGIC_BAR_ACTION_BORDER_STANDARD: temp = sMagicBorderIndices[sMagicBorderStep]; borderChangeR = ABS(sMagicBorderR - sMagicBorderColors[temp][0]) / sMagicBorderRatio; borderChangeG = ABS(sMagicBorderG - sMagicBorderColors[temp][1]) / sMagicBorderRatio; @@ -2451,12 +2454,12 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { } break; - case MAGIC_STATE_RESET: + case MAGIC_BAR_ACTION_RESET: sMagicBorderR = sMagicBorderG = sMagicBorderB = 255; - gSaveContext.magicState = MAGIC_STATE_DEFAULT; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_IDLE; break; - case MAGIC_STATE_LENS_CONSUME: + case MAGIC_BAR_ACTION_LENS_CONSUME: if ((globalCtx->pauseCtx.state == 0) && (globalCtx->pauseCtx.debugState == 0) && (msgCtx->msgMode == MSGMODE_NONE) && (globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE) && (globalCtx->sceneLoadFlag == 0) && (globalCtx->transitionMode == 0) && !Gameplay_InCsMode(globalCtx)) { @@ -2468,7 +2471,7 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { globalCtx->actorCtx.lensActive = false; Audio_PlaySoundGeneral(NA_SE_SY_GLASSMODE_OFF, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); - gSaveContext.magicState = MAGIC_STATE_DEFAULT; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_IDLE; sMagicBorderR = sMagicBorderG = sMagicBorderB = 255; break; } @@ -2516,18 +2519,18 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { } break; - case MAGIC_STATE_ADD: + case MAGIC_BAR_ACTION_ADD: gSaveContext.magic += 4; Audio_PlaySoundGeneral(NA_SE_SY_GAUGE_UP - SFX_FLAG, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); - if (gSaveContext.magic >= gSaveContext.yellowMagic) { - gSaveContext.magic = gSaveContext.yellowMagic; - gSaveContext.magicState = gSaveContext.magicStateStored; - gSaveContext.magicStateStored = MAGIC_STATE_DEFAULT; + if (gSaveContext.magic >= gSaveContext.magicTarget) { + gSaveContext.magic = gSaveContext.magicTarget; + gSaveContext.magicBarAction = gSaveContext.magicBarActionStored; + gSaveContext.magicBarActionStored = MAGIC_BAR_ACTION_IDLE; } break; default: - gSaveContext.magicState = MAGIC_STATE_DEFAULT; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_IDLE; break; } } @@ -2554,21 +2557,21 @@ void Interface_DrawMagicBar(GlobalContext* globalCtx) { Gfx_TextureIA8(OVERLAY_DISP, gMagicBarEndTex, 8, 16, R_MAGIC_BAR_X, magicBarY, 8, 16, 1 << 10, 1 << 10); OVERLAY_DISP = Gfx_TextureIA8(OVERLAY_DISP, gMagicBarMidTex, 24, 16, R_MAGIC_BAR_X + 8, magicBarY, - gSaveContext.magicMaxDrawn, 16, 1 << 10, 1 << 10); + gSaveContext.magicCapacityDrawn, 16, 1 << 10, 1 << 10); gDPLoadTextureBlock(OVERLAY_DISP++, gMagicBarEndTex, G_IM_FMT_IA, G_IM_SIZ_8b, 8, 16, 0, G_TX_MIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, 3, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPTextureRectangle(OVERLAY_DISP++, ((R_MAGIC_BAR_X + gSaveContext.magicMaxDrawn) + 8) << 2, magicBarY << 2, - ((R_MAGIC_BAR_X + gSaveContext.magicMaxDrawn) + 16) << 2, (magicBarY + 16) << 2, - G_TX_RENDERTILE, 256, 0, 1 << 10, 1 << 10); + gSPTextureRectangle(OVERLAY_DISP++, ((R_MAGIC_BAR_X + gSaveContext.magicCapacityDrawn) + 8) << 2, + magicBarY << 2, ((R_MAGIC_BAR_X + gSaveContext.magicCapacityDrawn) + 16) << 2, + (magicBarY + 16) << 2, G_TX_RENDERTILE, 256, 0, 1 << 10, 1 << 10); gDPPipeSync(OVERLAY_DISP++); gDPSetCombineLERP(OVERLAY_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, 0, 0, 0, PRIMITIVE, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, 0, 0, 0, PRIMITIVE); gDPSetEnvColor(OVERLAY_DISP++, 0, 0, 0, 255); - if (gSaveContext.magicState == MAGIC_STATE_BORDER_YELLOW_TARGET) { + if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_BORDER_YELLOW_TARGET) { // Yellow part of the bar indicating the amount of magic to be subtracted gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 250, 250, 0, interfaceCtx->magicAlpha); @@ -2586,7 +2589,7 @@ void Interface_DrawMagicBar(GlobalContext* globalCtx) { interfaceCtx->magicAlpha); gSPTextureRectangle(OVERLAY_DISP++, R_MAGIC_FILL_X << 2, (magicBarY + 3) << 2, - (R_MAGIC_FILL_X + gSaveContext.yellowMagic) << 2, (magicBarY + 10) << 2, + (R_MAGIC_FILL_X + gSaveContext.magicTarget) << 2, (magicBarY + 10) << 2, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); } else { // Fill the whole bar with the normal magic color @@ -4051,15 +4054,15 @@ void Interface_Update(GlobalContext* globalCtx) { (msgCtx->msgMode == MSGMODE_NONE) && (globalCtx->sceneLoadFlag == 0) && (globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE) && (globalCtx->transitionMode == 0) && ((globalCtx->csCtx.state == CS_STATE_IDLE) || !Player_InCsMode(globalCtx))) { - if (gSaveContext.magicAcquired && (gSaveContext.magicLevel == 0)) { - gSaveContext.magicLevel = gSaveContext.doubleMagic + 1; - gSaveContext.magicState = MAGIC_STATE_INIT; + if (gSaveContext.isMagicAcquired && (gSaveContext.magicLevel == 0)) { + gSaveContext.magicLevel = gSaveContext.isDoubleMagicAcquired + 1; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_GROW_WIDE; osSyncPrintf(VT_FGCOL(YELLOW)); osSyncPrintf("魔法スター─────ト!!!!!!!!!\n"); // "Magic Start!!!!!!!!!" osSyncPrintf("MAGIC_MAX=%d\n", gSaveContext.magicLevel); osSyncPrintf("MAGIC_NOW=%d\n", gSaveContext.magic); - osSyncPrintf("Z_MAGIC_NOW_NOW=%d\n", gSaveContext.magicMax); - osSyncPrintf("Z_MAGIC_NOW_MAX=%d\n", gSaveContext.magicMaxDrawn); + osSyncPrintf("Z_MAGIC_NOW_NOW=%d\n", gSaveContext.magicCapacity); + osSyncPrintf("Z_MAGIC_NOW_MAX=%d\n", gSaveContext.magicCapacityDrawn); osSyncPrintf(VT_RST); } diff --git a/src/code/z_player_lib.c b/src/code/z_player_lib.c index 978e49a4566..d3dbba16639 100644 --- a/src/code/z_player_lib.c +++ b/src/code/z_player_lib.c @@ -483,7 +483,7 @@ s32 Player_InBlockingCsMode(GlobalContext* globalCtx, Player* this) { return (this->stateFlags1 & (PLAYER_STATE1_7 | PLAYER_STATE1_29)) || (this->csMode != 0) || (globalCtx->sceneLoadFlag == 0x14) || (this->stateFlags1 & PLAYER_STATE1_0) || (this->stateFlags3 & PLAYER_STATE3_7) || - ((gSaveContext.magicState != MAGIC_STATE_DEFAULT) && + ((gSaveContext.magicBarAction != MAGIC_BAR_ACTION_IDLE) && (Player_ActionToMagicSpell(this, this->itemActionParam) >= 0)); } diff --git a/src/code/z_sram.c b/src/code/z_sram.c index f2844a88a29..5ea8894490b 100644 --- a/src/code/z_sram.c +++ b/src/code/z_sram.c @@ -17,9 +17,9 @@ typedef struct { /* 0x18 */ s16 rupees; /* 0x1A */ u16 swordHealth; /* 0x1C */ u16 naviTimer; - /* 0x1E */ u8 magicAcquired; + /* 0x1E */ u8 isMagicAcquired; /* 0x1F */ u8 unk_1F; - /* 0x20 */ u8 doubleMagic; + /* 0x20 */ u8 isDoubleMagicAcquired; /* 0x21 */ u8 doubleDefense; /* 0x22 */ u8 bgsFlag; /* 0x23 */ u8 ocarinaGameRoundNum; @@ -104,13 +104,13 @@ static SavePlayerData sNewSavePlayerData = { 0x30, // healthCapacity 0x30, // defense 0, // magicLevel - 0x30, // magic + MAGIC_HALF_BAR, // magic 0, // rupees 0, // swordHealth 0, // naviTimer - 0, // magicAcquired + false, // isMagicAcquired 0, // unk_1F - 0, // doubleMagic + false, // isDoubleMagicAcquired 0, // doubleDefense 0, // bgsFlag 0, // ocarinaGameRoundNum @@ -187,13 +187,13 @@ static SavePlayerData sDebugSavePlayerData = { 0xE0, // healthCapacity 0xE0, // health 0, // magicLevel - 0x30, // magic + MAGIC_HALF_BAR, // magic 150, // rupees 8, // swordHealth 0, // naviTimer - 1, // magicAcquired + true, // isMagicAcquired 0, // unk_1F - 0, // doubleMagic + false, // isDoubleMagicAcquired 0, // doubleDefense 0, // bgsFlag 0, // ocarinaGameRoundNum diff --git a/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c b/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c index 3f555c3cb7c..dd8a17d856d 100644 --- a/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c +++ b/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c @@ -181,12 +181,12 @@ void BgDyYoseizo_CheckMagicAcquired(BgDyYoseizo* this, GlobalContext* globalCtx) if (Flags_GetSwitch(globalCtx, 0x38)) { globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_04; if (globalCtx->sceneNum == SCENE_DAIYOUSEI_IZUMI) { - if (!gSaveContext.magicAcquired && (this->fountainType != FAIRY_UPGRADE_MAGIC)) { + if (!gSaveContext.isMagicAcquired && (this->fountainType != FAIRY_UPGRADE_MAGIC)) { Actor_Kill(&this->actor); return; } } else { - if (!gSaveContext.magicAcquired) { + if (!gSaveContext.isMagicAcquired) { Actor_Kill(&this->actor); return; } @@ -225,7 +225,7 @@ void BgDyYoseizo_ChooseType(BgDyYoseizo* this, GlobalContext* globalCtx) { } else { switch (this->fountainType) { case FAIRY_UPGRADE_MAGIC: - if (!gSaveContext.magicAcquired || BREG(2)) { + if (!gSaveContext.isMagicAcquired || BREG(2)) { // "Spin Attack speed UP" osSyncPrintf(VT_FGCOL(GREEN) " ☆☆☆☆☆ 回転切り速度UP ☆☆☆☆☆ \n" VT_RST); this->givingSpell = true; @@ -233,7 +233,7 @@ void BgDyYoseizo_ChooseType(BgDyYoseizo* this, GlobalContext* globalCtx) { } break; case FAIRY_UPGRADE_DOUBLE_MAGIC: - if (!gSaveContext.doubleMagic) { + if (!gSaveContext.isDoubleMagicAcquired) { // "Magic Meter doubled" osSyncPrintf(VT_FGCOL(YELLOW) " ☆☆☆☆☆ 魔法ゲージメーター倍増 ☆☆☆☆☆ \n" VT_RST); this->givingSpell = true; @@ -467,7 +467,8 @@ void BgDyYoseizo_HealPlayer_NoReward(BgDyYoseizo* this, GlobalContext* globalCtx this->refillTimer = 200; } - if (((gSaveContext.healthCapacity == gSaveContext.health) && (gSaveContext.magic == gSaveContext.magicMaxDrawn)) || + if (((gSaveContext.healthCapacity == gSaveContext.health) && + (gSaveContext.magic == gSaveContext.magicCapacityDrawn)) || (this->refillTimer == 1)) { this->healingTimer--; if (this->healingTimer == 90) { @@ -710,16 +711,16 @@ void BgDyYoseizo_Give_Reward(BgDyYoseizo* this, GlobalContext* globalCtx) { switch (actionIndex) { case FAIRY_UPGRADE_MAGIC: - gSaveContext.magicAcquired = true; - gSaveContext.magicMax = MAGIC_HALF_BAR; + gSaveContext.isMagicAcquired = true; + gSaveContext.magicCapacity = MAGIC_HALF_BAR; Interface_ChangeAlpha(9); break; case FAIRY_UPGRADE_DOUBLE_MAGIC: - if (!gSaveContext.magicAcquired) { - gSaveContext.magicAcquired = true; + if (!gSaveContext.isMagicAcquired) { + gSaveContext.isMagicAcquired = true; } - gSaveContext.doubleMagic = true; - gSaveContext.magicMax = MAGIC_FULL_BAR; + gSaveContext.isDoubleMagicAcquired = true; + gSaveContext.magicCapacity = MAGIC_FULL_BAR; gSaveContext.magicLevel = 0; Interface_ChangeAlpha(9); break; @@ -752,8 +753,8 @@ void BgDyYoseizo_Give_Reward(BgDyYoseizo* this, GlobalContext* globalCtx) { itemPos.x, itemPos.y, itemPos.z, 0, 0, 0, sExItemTypes[actionIndex]); if (this->item != NULL) { - if (!gSaveContext.magicAcquired) { - gSaveContext.magicAcquired = true; + if (!gSaveContext.isMagicAcquired) { + gSaveContext.isMagicAcquired = true; } else { Magic_Fill(globalCtx); } diff --git a/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c b/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c index 6236a4cbcc5..abec315c220 100644 --- a/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c +++ b/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c @@ -1191,7 +1191,7 @@ void BossGanon_SetupTowerCutscene(BossGanon* this, GlobalContext* globalCtx) { this->csTimer = 0; this->csState = 100; this->unk_198 = 1; - gSaveContext.magic = gSaveContext.magicMaxDrawn; + gSaveContext.magic = gSaveContext.magicCapacityDrawn; gSaveContext.health = gSaveContext.healthCapacity; } else { this->actionFunc = BossGanon_SetupTowerCutscene; diff --git a/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c b/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c index 4a4c06ec16b..2d6431e0f65 100644 --- a/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c +++ b/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c @@ -84,9 +84,9 @@ void EnMThunder_Init(Actor* thisx, GlobalContext* globalCtx2) { this->unk_1CA = 0; if (player->stateFlags2 & PLAYER_STATE2_17) { - if (!gSaveContext.magicAcquired || (gSaveContext.magicState != MAGIC_STATE_DEFAULT) || + if (!gSaveContext.isMagicAcquired || (gSaveContext.magicBarAction != MAGIC_BAR_ACTION_IDLE) || (((this->actor.params & 0xFF00) >> 8) && - !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_CHANGE_CONSUME_CHARGE)))) { + !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_BAR_CONSUME_CHARGE)))) { Audio_PlaySoundGeneral(NA_SE_IT_ROLLING_CUT, &player->actor.projectedPos, 4, &D_801333E0, &D_801333E0, &D_801333E8); Audio_PlaySoundGeneral(NA_SE_IT_SWORD_SWING_HARD, &player->actor.projectedPos, 4, &D_801333E0, &D_801333E0, @@ -157,9 +157,9 @@ void func_80A9F408(EnMThunder* this, GlobalContext* globalCtx) { if (this->unk_1CA == 0) { if (player->unk_858 >= 0.1f) { - if ((gSaveContext.magicState != MAGIC_STATE_DEFAULT) || + if ((gSaveContext.magicBarAction != MAGIC_BAR_ACTION_IDLE) || (((this->actor.params & 0xFF00) >> 8) && - !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_CHANGE_CONSUME_NOW)))) { + !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_BAR_CONSUME_PREVIEW)))) { func_80A9F350(this, globalCtx); func_80A9EFE0(this, func_80A9F350); this->unk_1C8 = 0; @@ -193,7 +193,7 @@ void func_80A9F408(EnMThunder* this, GlobalContext* globalCtx) { } else { player->stateFlags2 &= ~PLAYER_STATE2_17; if ((this->actor.params & 0xFF00) >> 8) { - gSaveContext.magicState = MAGIC_STATE_CHARGE_SETUP; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CHARGE_SETUP; } if (player->unk_858 < 0.85f) { this->collider.info.toucher.dmgFlags = D_80AA044C[this->unk_1C7]; diff --git a/src/overlays/actors/ovl_En_Owl/z_en_owl.c b/src/overlays/actors/ovl_En_Owl/z_en_owl.c index 484bca17b04..d662e3f1fda 100644 --- a/src/overlays/actors/ovl_En_Owl/z_en_owl.c +++ b/src/overlays/actors/ovl_En_Owl/z_en_owl.c @@ -617,7 +617,7 @@ void func_80ACB274(EnOwl* this, GlobalContext* globalCtx) { void EnOwl_WaitDeathMountainShortcut(EnOwl* this, GlobalContext* globalCtx) { EnOwl_LookAtLink(this, globalCtx); - if (!gSaveContext.magicAcquired) { + if (!gSaveContext.isMagicAcquired) { if (func_80ACA558(this, globalCtx, 0x3062)) { Audio_PlayFanfare(NA_BGM_OWL); this->actionFunc = func_80ACB274; diff --git a/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c b/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c index c086c857d33..abc8996954f 100644 --- a/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c +++ b/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c @@ -532,7 +532,7 @@ void EnTorch2_Update(Actor* thisx, GlobalContext* globalCtx2) { // Causes Dark Link to shield in place when Link is using magic attacks other than the spin attack - if ((gSaveContext.magicState == MAGIC_STATE_BORDER_FREEZE_DARK_LINK) && + if ((gSaveContext.magicBarAction == MAGIC_BAR_ACTION_BORDER_FREEZE_DARK_LINK) && (player->meleeWeaponState == 0 || !((player->meleeWeaponAnimation >= PLAYER_MWA_SPIN_ATTACK_1H) && (player->meleeWeaponAnimation <= PLAYER_MWA_BIG_SPIN_2H)))) { sStickTilt = 0.0f; diff --git a/src/overlays/actors/ovl_En_Zl3/z_en_zl3.c b/src/overlays/actors/ovl_En_Zl3/z_en_zl3.c index 7beef63b008..0a3db2ae39c 100644 --- a/src/overlays/actors/ovl_En_Zl3/z_en_zl3.c +++ b/src/overlays/actors/ovl_En_Zl3/z_en_zl3.c @@ -1812,7 +1812,7 @@ void func_80B5772C(EnZl3* this, GlobalContext* globalCtx) { } void func_80B57754(EnZl3* this, GlobalContext* globalCtx) { - if (gSaveContext.magicState == MAGIC_STATE_DEFAULT) { + if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE) { Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_OCEFF_WIPE4, this->actor.world.pos.x, this->actor.world.pos.y, this->actor.world.pos.z, 0, 0, 0, 1); func_80B56DA4(this); diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index a433885fadd..76b95aa1f3a 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -2174,7 +2174,7 @@ s32 func_8083442C(Player* this, GlobalContext* globalCtx) { s32 magicArrowType; if ((this->heldItemActionParam >= PLAYER_AP_BOW_FIRE) && (this->heldItemActionParam <= PLAYER_AP_BOW_0E) && - (gSaveContext.magicState != MAGIC_STATE_DEFAULT)) { + (gSaveContext.magicBarAction != MAGIC_BAR_ACTION_IDLE)) { func_80078884(NA_SE_SY_ERROR); } else { func_80833638(this, func_808351D4); @@ -2190,7 +2190,7 @@ s32 func_8083442C(Player* this, GlobalContext* globalCtx) { if (this->unk_860 >= 0) { if ((magicArrowType >= 0) && (magicArrowType <= 2) && - !Magic_ChangeBy(globalCtx, sMagicArrowCosts[magicArrowType], MAGIC_CHANGE_CONSUME_CHARGE)) { + !Magic_ChangeBy(globalCtx, sMagicArrowCosts[magicArrowType], MAGIC_BAR_CONSUME_CHARGE)) { arrowType = ARROW_NORMAL; } @@ -2885,7 +2885,7 @@ void func_80835F44(GlobalContext* globalCtx, Player* this, s32 item) { } if (actionParam == PLAYER_AP_LENS) { - if (Magic_ChangeBy(globalCtx, 0, MAGIC_CHANGE_CONSUME_LENS)) { + if (Magic_ChangeBy(globalCtx, 0, MAGIC_BAR_CONSUME_LENS)) { if (globalCtx->actorCtx.lensActive) { Actor_DisableLens(globalCtx); } else { @@ -2910,7 +2910,7 @@ void func_80835F44(GlobalContext* globalCtx, Player* this, s32 item) { temp = Player_ActionToMagicSpell(this, actionParam); if (temp >= 0) { if (((actionParam == PLAYER_AP_FARORES_WIND) && (gSaveContext.respawn[RESPAWN_MODE_TOP].data > 0)) || - ((gSaveContext.magicMaxDrawn != 0) && (gSaveContext.magicState == MAGIC_STATE_DEFAULT) && + ((gSaveContext.magicCapacityDrawn != 0) && (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE) && (gSaveContext.magic >= sMagicSpellCosts[temp]))) { this->itemActionParam = actionParam; this->unk_6AD = 4; @@ -4849,7 +4849,7 @@ void func_8083AF44(GlobalContext* globalCtx, Player* this, s32 magicSpell) { func_80835DE4(globalCtx, this, func_808507F4, 0); this->unk_84F = magicSpell - 3; - Magic_ChangeBy(globalCtx, sMagicSpellCosts[magicSpell], MAGIC_CHANGE_CONSUME_NOW); + Magic_ChangeBy(globalCtx, sMagicSpellCosts[magicSpell], MAGIC_BAR_CONSUME_PREVIEW); LinkAnimation_PlayOnceSetSpeed(globalCtx, &this->skelAnime, &gPlayerAnim_002D28, 0.83f); @@ -9368,7 +9368,7 @@ void Player_Init(Actor* thisx, GlobalContext* globalCtx2) { } if (gSaveContext.nayrusLoveTimer != 0) { - gSaveContext.magicState = MAGIC_STATE_BORDER_FREEZE_DARK_LINK; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_FREEZE_DARK_LINK; func_80846A00(globalCtx, this, 1); this->stateFlags3 &= ~PLAYER_STATE3_6; } @@ -10156,8 +10156,8 @@ void Player_UpdateCommon(Player* this, GlobalContext* globalCtx, Input* input) { } if ((this->stateFlags3 & PLAYER_STATE3_6) && (gSaveContext.nayrusLoveTimer != 0) && - (gSaveContext.magicState == MAGIC_STATE_DEFAULT)) { - gSaveContext.magicState = MAGIC_STATE_BORDER_FREEZE_DARK_LINK; + (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE)) { + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_FREEZE_DARK_LINK; func_80846A00(globalCtx, this, 1); this->stateFlags3 &= ~PLAYER_STATE3_6; } @@ -12355,7 +12355,7 @@ void func_8084EAC0(Player* this, GlobalContext* globalCtx) { func_8083C0E8(this, globalCtx); func_8005B1A4(Gameplay_GetCamera(globalCtx, 0)); } else if (this->unk_850 == 1) { - if ((gSaveContext.healthAccumulator == 0) && (gSaveContext.magicState != MAGIC_STATE_FILL)) { + if ((gSaveContext.healthAccumulator == 0) && (gSaveContext.magicBarAction != MAGIC_BAR_ACTION_FILL)) { func_80832B78(globalCtx, this, &gPlayerAnim_002660); this->unk_850 = 2; Player_UpdateBottleHeld(globalCtx, this, ITEM_BOTTLE, PLAYER_AP_BOTTLE); @@ -13096,7 +13096,8 @@ static struct_80832924 D_80854A8C[][2] = { void func_808507F4(Player* this, GlobalContext* globalCtx) { if (LinkAnimation_Update(globalCtx, &this->skelAnime)) { if (this->unk_84F < 0) { - if ((this->itemActionParam == PLAYER_AP_NAYRUS_LOVE) || (gSaveContext.magicState == MAGIC_STATE_DEFAULT)) { + if ((this->itemActionParam == PLAYER_AP_NAYRUS_LOVE) || + (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE)) { func_80839FFC(this, globalCtx); func_8005B1A4(Gameplay_GetCamera(globalCtx, 0)); } @@ -13107,7 +13108,7 @@ void func_808507F4(Player* this, GlobalContext* globalCtx) { if (func_80846A00(globalCtx, this, this->unk_84F) != NULL) { this->stateFlags1 |= PLAYER_STATE1_28 | PLAYER_STATE1_29; if ((this->unk_84F != 0) || (gSaveContext.respawn[RESPAWN_MODE_TOP].data <= 0)) { - gSaveContext.magicState = MAGIC_STATE_CHARGE_SETUP; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CHARGE_SETUP; } } else { Magic_ResetState(globalCtx); diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index 8be17a4b260..8e6e26063ad 100644 --- a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -1461,8 +1461,8 @@ void FileChoose_LoadGame(GameState* thisx) { gSaveContext.unk_13EE = 0x32; gSaveContext.nayrusLoveTimer = 0; gSaveContext.healthAccumulator = 0; - gSaveContext.magicState = MAGIC_STATE_DEFAULT; - gSaveContext.magicStateStored = MAGIC_STATE_DEFAULT; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_IDLE; + gSaveContext.magicBarActionStored = MAGIC_BAR_ACTION_IDLE; gSaveContext.forcedSeqId = NA_BGM_GENERAL_SFX; gSaveContext.skyboxTime = 0; gSaveContext.nextTransition = 0xFF; @@ -1476,15 +1476,15 @@ void FileChoose_LoadGame(GameState* thisx) { gSaveContext.buttonStatus[3] = gSaveContext.buttonStatus[4] = BTN_ENABLED; gSaveContext.unk_13E7 = gSaveContext.unk_13E8 = gSaveContext.unk_13EA = gSaveContext.unk_13EC = - gSaveContext.magicMaxDrawn = 0; + gSaveContext.magicCapacityDrawn = 0; - gSaveContext.magicMax = gSaveContext.magic; + gSaveContext.magicCapacity = gSaveContext.magic; gSaveContext.magicLevel = gSaveContext.magic = 0; if (1) {} osSyncPrintf(VT_FGCOL(GREEN)); - osSyncPrintf("Z_MAGIC_NOW_NOW=%d MAGIC_NOW=%d\n", ((void)0, gSaveContext.magicMax), gSaveContext.magic); + osSyncPrintf("Z_MAGIC_NOW_NOW=%d MAGIC_NOW=%d\n", ((void)0, gSaveContext.magicCapacity), gSaveContext.magic); osSyncPrintf(VT_RST); gSaveContext.naviTimer = 0; diff --git a/src/overlays/gamestates/ovl_select/z_select.c b/src/overlays/gamestates/ovl_select/z_select.c index 5e787ea2bc2..631c92e8a04 100644 --- a/src/overlays/gamestates/ovl_select/z_select.c +++ b/src/overlays/gamestates/ovl_select/z_select.c @@ -20,8 +20,8 @@ void Select_LoadGame(SelectContext* this, s32 entranceIndex) { osSyncPrintf(VT_RST); if (gSaveContext.fileNum == 0xFF) { Sram_InitDebugSave(); - gSaveContext.magicMax = gSaveContext.magic; - gSaveContext.magicMaxDrawn = 0; + gSaveContext.magicCapacity = gSaveContext.magic; + gSaveContext.magicCapacityDrawn = 0; gSaveContext.magicLevel = gSaveContext.magic = 0; } gSaveContext.buttonStatus[0] = gSaveContext.buttonStatus[1] = gSaveContext.buttonStatus[2] = diff --git a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c index a8a31d4365d..0db71fcfea2 100644 --- a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c +++ b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c @@ -3385,16 +3385,16 @@ void KaleidoScope_Update(GlobalContext* globalCtx) { gSaveContext.health = 0x30; Audio_QueueSeqCmd(0xF << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0xA); gSaveContext.healthAccumulator = 0; - gSaveContext.magicState = MAGIC_STATE_DEFAULT; - gSaveContext.magicStateStored = MAGIC_STATE_DEFAULT; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_IDLE; + gSaveContext.magicBarActionStored = MAGIC_BAR_ACTION_IDLE; osSyncPrintf(VT_FGCOL(YELLOW)); osSyncPrintf("MAGIC_NOW=%d ", gSaveContext.magic); - osSyncPrintf("Z_MAGIC_NOW_NOW=%d → ", gSaveContext.magicMax); - gSaveContext.magicMaxDrawn = 0; - gSaveContext.magicMax = gSaveContext.magic; + osSyncPrintf("Z_MAGIC_NOW_NOW=%d → ", gSaveContext.magicCapacity); + gSaveContext.magicCapacityDrawn = 0; + gSaveContext.magicCapacity = gSaveContext.magic; gSaveContext.magicLevel = gSaveContext.magic = 0; osSyncPrintf("MAGIC_NOW=%d ", gSaveContext.magic); - osSyncPrintf("Z_MAGIC_NOW_NOW=%d\n", gSaveContext.magicMax); + osSyncPrintf("Z_MAGIC_NOW_NOW=%d\n", gSaveContext.magicCapacity); osSyncPrintf(VT_RST); } else { globalCtx->state.running = 0; From bdda1e52b20cefa4e3294a1be1ac35057ea9c07a Mon Sep 17 00:00:00 2001 From: engineer124 Date: Tue, 19 Apr 2022 23:54:29 +1000 Subject: [PATCH 04/33] More renaming --- include/functions.h | 2 +- include/z64save.h | 30 +++++++-------- src/code/z_actor.c | 2 +- src/code/z_parameter.c | 37 ++++++++++--------- src/code/z_play.c | 2 +- .../actors/ovl_Arrow_Fire/z_arrow_fire.c | 2 +- .../actors/ovl_Arrow_Ice/z_arrow_ice.c | 2 +- .../actors/ovl_Arrow_Light/z_arrow_light.c | 2 +- .../actors/ovl_En_M_Thunder/z_en_m_thunder.c | 6 +-- .../actors/ovl_En_Torch2/z_en_torch2.c | 2 +- .../actors/ovl_Magic_Dark/z_magic_dark.c | 2 +- .../actors/ovl_Magic_Fire/z_magic_fire.c | 2 +- .../actors/ovl_Magic_Wind/z_magic_wind.c | 2 +- .../actors/ovl_Oceff_Spot/z_oceff_spot.c | 2 +- .../actors/ovl_Oceff_Storm/z_oceff_storm.c | 2 +- .../actors/ovl_Oceff_Wipe/z_oceff_wipe.c | 2 +- .../actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c | 2 +- .../actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c | 2 +- .../actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c | 2 +- .../actors/ovl_player_actor/z_player.c | 12 +++--- 20 files changed, 60 insertions(+), 57 deletions(-) diff --git a/include/functions.h b/include/functions.h index 4bfc4c2d31c..a563b00c229 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1043,7 +1043,7 @@ s32 Health_ChangeBy(GlobalContext* globalCtx, s16 healthChange); void Rupees_ChangeBy(s16 rupeeChange); void Inventory_ChangeAmmo(s16 item, s16 ammoChange); void Magic_Fill(GlobalContext* globalCtx); -void Magic_ResetState(GlobalContext* globalCtx); +void Magic_RestoreMagicBarIdleAction(GlobalContext* globalCtx); s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType); void func_80088AA0(s16 arg0); void func_80088AF0(GlobalContext* globalCtx); diff --git a/include/z64save.h b/include/z64save.h index 50481db22da..1fd374bb0fd 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -6,24 +6,24 @@ typedef enum MagicBarAction { /* 00 */ MAGIC_BAR_ACTION_IDLE, // Regular gameplay - /* 01 */ MAGIC_BAR_ACTION_CHARGE_SETUP, - /* 02 */ MAGIC_BAR_ACTION_CHARGE, - /* 03 */ MAGIC_BAR_ACTION_BORDER_FREEZE_DARK_LINK, // Using magic attacks other than the spin attack - /* 04 */ MAGIC_BAR_ACTION_BORDER_YELLOW_TARGET, // Yellow part of the bar indicating the amount of magic to be subtracted - /* 05 */ MAGIC_BAR_ACTION_RESET, // Reset colors and return to idle - /* 06 */ MAGIC_BAR_ACTION_BORDER_STANDARD, + /* 01 */ MAGIC_BAR_ACTION_CHARGE_PENALTY_SETUP, + /* 02 */ MAGIC_BAR_ACTION_CHARGE_PENALTY, // Consume a small amount of magic before flashing the border + /* 03 */ MAGIC_BAR_ACTION_FLASH_BORDER_1, // Flashes border and freezes Dark Link + /* 04 */ MAGIC_BAR_ACTION_FLASH_BORDER_2, // Flashes border and draws yellow magic to target consumption + /* 05 */ MAGIC_BAR_ACTION_RESTORE_IDLE, // Reset colors and return to idle + /* 06 */ MAGIC_BAR_ACTION_FLASH_BORDER_3, // Flashes border with no additional behaviour /* 07 */ MAGIC_BAR_ACTION_LENS_CONSUME, // Magic slowly consumed by lens. /* 08 */ MAGIC_BAR_ACTION_GROW_WIDE, // Init magic on a new load, grow from a width of 0 to magicCapacity - /* 09 */ MAGIC_BAR_ACTION_FILL, // Fill to full capacity + /* 09 */ MAGIC_BAR_ACTION_FILL, // Fill to either full capacity or another action takes over /* 10 */ MAGIC_BAR_ACTION_ADD // Add requested magic } MagicBarAction; typedef enum MagicBarChange { - /* 00 */ MAGIC_BAR_CONSUME_CHARGE, // Consume Magic (spell & spin attack) - /* 01 */ MAGIC_BAR_CONSUME_NO_PREVIEW, // Unused - /* 02 */ MAGIC_BAR_CONSUME_CHARGE_ALT, // Consume Magic Alt - /* 03 */ MAGIC_BAR_CONSUME_LENS, // Lens - /* 04 */ MAGIC_BAR_CONSUME_PREVIEW, // Consume Magic (spell & spin attack) + /* 00 */ MAGIC_BAR_CONSUME_WITH_PENALTY, // Consume Magic, includes a small penality of consumption is magic consumption is not followed through (spin attack, magic arrows) + /* 01 */ MAGIC_BAR_CONSUME_NO_PREVIEW, // Unused, consumes magic without drawing yellow magic to target consumption + /* 02 */ MAGIC_BAR_CONSUME_WITH_PENALTY_ALT, // Unused, identical behaviour to MAGIC_BAR_CONSUME_WITH_PENALTY + /* 03 */ MAGIC_BAR_CONSUME_LENS, // Lens consumption + /* 04 */ MAGIC_BAR_CONSUME_PREVIEW, // Consume Magic and draws yellow magic to target consumption /* 05 */ MAGIC_BAR_ADD } MagicBarChange; @@ -101,7 +101,7 @@ typedef struct { /* 0x002E */ s16 healthCapacity; // "max_life" /* 0x0030 */ s16 health; // "now_life" /* 0x0032 */ s8 magicLevel; // 0 for no magic/new load, 1 for magic, 2 for double magic - /* 0x0033 */ s8 magic; // true magic value available + /* 0x0033 */ s8 magic; // current magic available for use /* 0x0034 */ s16 rupees; /* 0x0036 */ u16 swordHealth; /* 0x0038 */ u16 naviTimer; @@ -169,8 +169,8 @@ typedef struct { /* 0x13EA */ u16 unk_13EA; // also alpha type? /* 0x13EC */ u16 unk_13EC; // alpha type counter? /* 0x13EE */ u16 unk_13EE; // previous alpha type? - /* 0x13F0 */ s16 magicBarAction; - /* 0x13F2 */ s16 magicBarActionStored; // stores the previous magic state while magic is increasing. Allows magicBarAction to be restored afterwards + /* 0x13F0 */ s16 magicBarAction; // Next action magic bar will take on each frame + /* 0x13F2 */ s16 magicBarActionStored; // stores the previous magic action while magic is increasing. Allows magicBarAction to be restored afterwards /* 0x13F4 */ s16 magicCapacityDrawn; // Only differs from magicCapacity in a new save load, where magicCapacityDrawn is slowly stepped from 0 to magicCapacity /* 0x13F6 */ s16 magicCapacity; // Maximum magic available /* 0x13F8 */ s16 magicTarget; // Target for magic to step to when adding or consuming magic diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 450f4008e9d..5611e9fbfbd 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -1949,7 +1949,7 @@ void func_80030488(GlobalContext* globalCtx) { void Actor_DisableLens(GlobalContext* globalCtx) { if (globalCtx->actorCtx.lensActive) { globalCtx->actorCtx.lensActive = false; - Magic_ResetState(globalCtx); + Magic_RestoreMagicBarIdleAction(globalCtx); } } diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index cced68e2cb4..845fe0f8dc9 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2246,13 +2246,13 @@ void Magic_Fill(GlobalContext* globalCtx) { } } -void Magic_ResetState(GlobalContext* globalCtx) { +void Magic_RestoreMagicBarIdleAction(GlobalContext* globalCtx) { if ((gSaveContext.magicBarAction != MAGIC_BAR_ACTION_GROW_WIDE) && (gSaveContext.magicBarAction != MAGIC_BAR_ACTION_FILL)) { if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_ADD) { gSaveContext.magicBarActionStored = gSaveContext.magicBarAction; } - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_RESET; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_RESTORE_IDLE; } } @@ -2269,15 +2269,15 @@ s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType) { } switch (changeType) { - case MAGIC_BAR_CONSUME_CHARGE: - case MAGIC_BAR_CONSUME_CHARGE_ALT: + case MAGIC_BAR_CONSUME_WITH_PENALTY: + case MAGIC_BAR_CONSUME_WITH_PENALTY_ALT: if ((gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE) || (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME)) { if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME) { globalCtx->actorCtx.lensActive = false; } gSaveContext.magicTarget = gSaveContext.magic - magicChange; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CHARGE_SETUP; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CHARGE_PENALTY_SETUP; return true; } else { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); @@ -2290,7 +2290,7 @@ s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType) { globalCtx->actorCtx.lensActive = false; } gSaveContext.magicTarget = gSaveContext.magic - magicChange; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_STANDARD; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_FLASH_BORDER_3; return true; } else { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); @@ -2319,7 +2319,7 @@ s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType) { globalCtx->actorCtx.lensActive = false; } gSaveContext.magicTarget = gSaveContext.magic - magicChange; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_YELLOW_TARGET; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_FLASH_BORDER_2; return true; } else { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); @@ -2382,6 +2382,7 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { break; case MAGIC_BAR_ACTION_FILL: + // Fill to either full capacity or another action takes over gSaveContext.magic += 4; if (gSaveContext.gameMode == 0 && gSaveContext.sceneSetupIndex < 4) { @@ -2398,26 +2399,26 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { } break; - case MAGIC_BAR_ACTION_CHARGE_SETUP: + case MAGIC_BAR_ACTION_CHARGE_PENALTY_SETUP: sMagicBorderRatio = 2; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CHARGE; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CHARGE_PENALTY; break; - case MAGIC_BAR_ACTION_CHARGE: + case MAGIC_BAR_ACTION_CHARGE_PENALTY: gSaveContext.magic -= 2; if (gSaveContext.magic <= 0) { gSaveContext.magic = 0; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_FREEZE_DARK_LINK; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_FLASH_BORDER_1; sMagicBorderR = sMagicBorderG = sMagicBorderB = 255; } else if (gSaveContext.magic == gSaveContext.magicTarget) { - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_FREEZE_DARK_LINK; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_FLASH_BORDER_1; sMagicBorderR = sMagicBorderG = sMagicBorderB = 255; } // fallthrough - case MAGIC_BAR_ACTION_BORDER_FREEZE_DARK_LINK: - case MAGIC_BAR_ACTION_BORDER_YELLOW_TARGET: - case MAGIC_BAR_ACTION_BORDER_STANDARD: + case MAGIC_BAR_ACTION_FLASH_BORDER_1: + case MAGIC_BAR_ACTION_FLASH_BORDER_2: + case MAGIC_BAR_ACTION_FLASH_BORDER_3: temp = sMagicBorderIndices[sMagicBorderStep]; borderChangeR = ABS(sMagicBorderR - sMagicBorderColors[temp][0]) / sMagicBorderRatio; borderChangeG = ABS(sMagicBorderG - sMagicBorderColors[temp][1]) / sMagicBorderRatio; @@ -2454,7 +2455,7 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { } break; - case MAGIC_BAR_ACTION_RESET: + case MAGIC_BAR_ACTION_RESTORE_IDLE: sMagicBorderR = sMagicBorderG = sMagicBorderB = 255; gSaveContext.magicBarAction = MAGIC_BAR_ACTION_IDLE; break; @@ -2468,6 +2469,7 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { (gSaveContext.equips.buttonItems[2] != ITEM_LENS) && (gSaveContext.equips.buttonItems[3] != ITEM_LENS)) || !globalCtx->actorCtx.lensActive) { + // Force lens off and restore magic bar to idle action globalCtx->actorCtx.lensActive = false; Audio_PlaySoundGeneral(NA_SE_SY_GLASSMODE_OFF, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); @@ -2571,7 +2573,7 @@ void Interface_DrawMagicBar(GlobalContext* globalCtx) { ENVIRONMENT, TEXEL0, ENVIRONMENT, 0, 0, 0, PRIMITIVE); gDPSetEnvColor(OVERLAY_DISP++, 0, 0, 0, 255); - if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_BORDER_YELLOW_TARGET) { + if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_FLASH_BORDER_2) { // Yellow part of the bar indicating the amount of magic to be subtracted gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 250, 250, 0, interfaceCtx->magicAlpha); @@ -4050,6 +4052,7 @@ void Interface_Update(GlobalContext* globalCtx) { WREG(7) = interfaceCtx->unk_1F4; + // Update Magic if ((globalCtx->pauseCtx.state == 0) && (globalCtx->pauseCtx.debugState == 0) && (msgCtx->msgMode == MSGMODE_NONE) && (globalCtx->sceneLoadFlag == 0) && (globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE) && (globalCtx->transitionMode == 0) && diff --git a/src/code/z_play.c b/src/code/z_play.c index d47b30939ef..2d95bc4f186 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -259,7 +259,7 @@ void Gameplay_Init(GameState* thisx) { if (gSaveContext.gameMode != 0 || gSaveContext.cutsceneIndex >= 0xFFF0) { gSaveContext.nayrusLoveTimer = 0; - Magic_ResetState(globalCtx); + Magic_RestoreMagicBarIdleAction(globalCtx); gSaveContext.sceneSetupIndex = (gSaveContext.cutsceneIndex & 0xF) + 4; } else if (!LINK_IS_ADULT && IS_DAY) { gSaveContext.sceneSetupIndex = 0; diff --git a/src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c b/src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c index 6045c1faf31..29bb8c26128 100644 --- a/src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c +++ b/src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c @@ -54,7 +54,7 @@ void ArrowFire_Init(Actor* thisx, GlobalContext* globalCtx) { } void ArrowFire_Destroy(Actor* thisx, GlobalContext* globalCtx) { - Magic_ResetState(globalCtx); + Magic_RestoreMagicBarIdleAction(globalCtx); LOG_STRING("消滅", "../z_arrow_fire.c", 421); // "Disappearance" } diff --git a/src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c b/src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c index c6e549661ee..6bff38f3cfa 100644 --- a/src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c +++ b/src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c @@ -55,7 +55,7 @@ void ArrowIce_Init(Actor* thisx, GlobalContext* globalCtx) { } void ArrowIce_Destroy(Actor* thisx, GlobalContext* globalCtx) { - Magic_ResetState(globalCtx); + Magic_RestoreMagicBarIdleAction(globalCtx); LOG_STRING("消滅", "../z_arrow_ice.c", 415); // "Disappearance" } diff --git a/src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c b/src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c index 7ca98fda196..557f2a18e26 100644 --- a/src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c +++ b/src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c @@ -55,7 +55,7 @@ void ArrowLight_Init(Actor* thisx, GlobalContext* globalCtx) { } void ArrowLight_Destroy(Actor* thisx, GlobalContext* globalCtx) { - Magic_ResetState(globalCtx); + Magic_RestoreMagicBarIdleAction(globalCtx); LOG_STRING("消滅", "../z_arrow_light.c", 403); // "Disappearance" } diff --git a/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c b/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c index 2d6431e0f65..8b84bd5adab 100644 --- a/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c +++ b/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c @@ -86,7 +86,7 @@ void EnMThunder_Init(Actor* thisx, GlobalContext* globalCtx2) { if (player->stateFlags2 & PLAYER_STATE2_17) { if (!gSaveContext.isMagicAcquired || (gSaveContext.magicBarAction != MAGIC_BAR_ACTION_IDLE) || (((this->actor.params & 0xFF00) >> 8) && - !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_BAR_CONSUME_CHARGE)))) { + !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_BAR_CONSUME_WITH_PENALTY)))) { Audio_PlaySoundGeneral(NA_SE_IT_ROLLING_CUT, &player->actor.projectedPos, 4, &D_801333E0, &D_801333E0, &D_801333E8); Audio_PlaySoundGeneral(NA_SE_IT_SWORD_SWING_HARD, &player->actor.projectedPos, 4, &D_801333E0, &D_801333E0, @@ -115,7 +115,7 @@ void EnMThunder_Destroy(Actor* thisx, GlobalContext* globalCtx) { EnMThunder* this = (EnMThunder*)thisx; if (this->unk_1CA != 0) { - Magic_ResetState(globalCtx); + Magic_RestoreMagicBarIdleAction(globalCtx); } Collider_DestroyCylinder(globalCtx, &this->collider); @@ -193,7 +193,7 @@ void func_80A9F408(EnMThunder* this, GlobalContext* globalCtx) { } else { player->stateFlags2 &= ~PLAYER_STATE2_17; if ((this->actor.params & 0xFF00) >> 8) { - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CHARGE_SETUP; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CHARGE_PENALTY_SETUP; } if (player->unk_858 < 0.85f) { this->collider.info.toucher.dmgFlags = D_80AA044C[this->unk_1C7]; diff --git a/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c b/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c index abc8996954f..9fed5c21e02 100644 --- a/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c +++ b/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c @@ -532,7 +532,7 @@ void EnTorch2_Update(Actor* thisx, GlobalContext* globalCtx2) { // Causes Dark Link to shield in place when Link is using magic attacks other than the spin attack - if ((gSaveContext.magicBarAction == MAGIC_BAR_ACTION_BORDER_FREEZE_DARK_LINK) && + if ((gSaveContext.magicBarAction == MAGIC_BAR_ACTION_FLASH_BORDER_1) && (player->meleeWeaponState == 0 || !((player->meleeWeaponAnimation >= PLAYER_MWA_SPIN_ATTACK_1H) && (player->meleeWeaponAnimation <= PLAYER_MWA_BIG_SPIN_2H)))) { sStickTilt = 0.0f; diff --git a/src/overlays/actors/ovl_Magic_Dark/z_magic_dark.c b/src/overlays/actors/ovl_Magic_Dark/z_magic_dark.c index 15c86218bec..27d54a7eb08 100644 --- a/src/overlays/actors/ovl_Magic_Dark/z_magic_dark.c +++ b/src/overlays/actors/ovl_Magic_Dark/z_magic_dark.c @@ -64,7 +64,7 @@ void MagicDark_Init(Actor* thisx, GlobalContext* globalCtx) { void MagicDark_Destroy(Actor* thisx, GlobalContext* globalCtx) { if (gSaveContext.nayrusLoveTimer == 0) { - Magic_ResetState(globalCtx); + Magic_RestoreMagicBarIdleAction(globalCtx); } } diff --git a/src/overlays/actors/ovl_Magic_Fire/z_magic_fire.c b/src/overlays/actors/ovl_Magic_Fire/z_magic_fire.c index 978dbcb86f8..41dc2406914 100644 --- a/src/overlays/actors/ovl_Magic_Fire/z_magic_fire.c +++ b/src/overlays/actors/ovl_Magic_Fire/z_magic_fire.c @@ -92,7 +92,7 @@ void MagicFire_Init(Actor* thisx, GlobalContext* globalCtx) { } void MagicFire_Destroy(Actor* thisx, GlobalContext* globalCtx) { - Magic_ResetState(globalCtx); + Magic_RestoreMagicBarIdleAction(globalCtx); } void MagicFire_UpdateBeforeCast(Actor* thisx, GlobalContext* globalCtx) { diff --git a/src/overlays/actors/ovl_Magic_Wind/z_magic_wind.c b/src/overlays/actors/ovl_Magic_Wind/z_magic_wind.c index 7eb3d0dd634..0c48f4294d3 100644 --- a/src/overlays/actors/ovl_Magic_Wind/z_magic_wind.c +++ b/src/overlays/actors/ovl_Magic_Wind/z_magic_wind.c @@ -69,7 +69,7 @@ void MagicWind_Init(Actor* thisx, GlobalContext* globalCtx) { void MagicWind_Destroy(Actor* thisx, GlobalContext* globalCtx) { MagicWind* this = (MagicWind*)thisx; SkelCurve_Destroy(globalCtx, &this->skelCurve); - Magic_ResetState(globalCtx); + Magic_RestoreMagicBarIdleAction(globalCtx); // "wipe out" LOG_STRING("消滅", "../z_magic_wind.c", 505); } diff --git a/src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c b/src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c index fb7f104cfc3..ae26376df46 100644 --- a/src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c +++ b/src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c @@ -69,7 +69,7 @@ void OceffSpot_Destroy(Actor* thisx, GlobalContext* globalCtx) { LightContext_RemoveLight(globalCtx, &globalCtx->lightCtx, this->lightNode1); LightContext_RemoveLight(globalCtx, &globalCtx->lightCtx, this->lightNode2); - Magic_ResetState(globalCtx); + Magic_RestoreMagicBarIdleAction(globalCtx); if ((gSaveContext.nayrusLoveTimer != 0) && (globalCtx->actorCtx.actorLists[ACTORCAT_PLAYER].length != 0)) { player->stateFlags3 |= PLAYER_STATE3_6; } diff --git a/src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c b/src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c index ebfe3f8987a..7291cd0323c 100644 --- a/src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c +++ b/src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c @@ -59,7 +59,7 @@ void OceffStorm_Destroy(Actor* thisx, GlobalContext* globalCtx) { OceffStorm* this = (OceffStorm*)thisx; Player* player = GET_PLAYER(globalCtx); - Magic_ResetState(globalCtx); + Magic_RestoreMagicBarIdleAction(globalCtx); if (gSaveContext.nayrusLoveTimer != 0) { player->stateFlags3 |= PLAYER_STATE3_6; } diff --git a/src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c b/src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c index 13d4e884661..700b45b18dc 100644 --- a/src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c +++ b/src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c @@ -39,7 +39,7 @@ void OceffWipe_Destroy(Actor* thisx, GlobalContext* globalCtx) { OceffWipe* this = (OceffWipe*)thisx; Player* player = GET_PLAYER(globalCtx); - Magic_ResetState(globalCtx); + Magic_RestoreMagicBarIdleAction(globalCtx); if (gSaveContext.nayrusLoveTimer != 0) { player->stateFlags3 |= PLAYER_STATE3_6; } diff --git a/src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c b/src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c index df2e93cc263..d622deabc17 100644 --- a/src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c +++ b/src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c @@ -39,7 +39,7 @@ void OceffWipe2_Destroy(Actor* thisx, GlobalContext* globalCtx) { OceffWipe2* this = (OceffWipe2*)thisx; Player* player = GET_PLAYER(globalCtx); - Magic_ResetState(globalCtx); + Magic_RestoreMagicBarIdleAction(globalCtx); if (gSaveContext.nayrusLoveTimer != 0) { player->stateFlags3 |= PLAYER_STATE3_6; } diff --git a/src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c b/src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c index 7a85ed5808f..6ebcd1a2821 100644 --- a/src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c +++ b/src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c @@ -42,7 +42,7 @@ void OceffWipe3_Destroy(Actor* thisx, GlobalContext* globalCtx) { OceffWipe3* this = (OceffWipe3*)thisx; Player* player = GET_PLAYER(globalCtx); - Magic_ResetState(globalCtx); + Magic_RestoreMagicBarIdleAction(globalCtx); if (gSaveContext.nayrusLoveTimer != 0) { player->stateFlags3 |= PLAYER_STATE3_6; } diff --git a/src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c b/src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c index eccf21c8e3d..b6f76ac19e7 100644 --- a/src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c +++ b/src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c @@ -38,7 +38,7 @@ void OceffWipe4_Init(Actor* thisx, GlobalContext* globalCtx) { void OceffWipe4_Destroy(Actor* thisx, GlobalContext* globalCtx) { OceffWipe4* this = (OceffWipe4*)thisx; - Magic_ResetState(globalCtx); + Magic_RestoreMagicBarIdleAction(globalCtx); } void OceffWipe4_Update(Actor* thisx, GlobalContext* globalCtx) { diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index 76b95aa1f3a..259a995972e 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -2190,7 +2190,7 @@ s32 func_8083442C(Player* this, GlobalContext* globalCtx) { if (this->unk_860 >= 0) { if ((magicArrowType >= 0) && (magicArrowType <= 2) && - !Magic_ChangeBy(globalCtx, sMagicArrowCosts[magicArrowType], MAGIC_BAR_CONSUME_CHARGE)) { + !Magic_ChangeBy(globalCtx, sMagicArrowCosts[magicArrowType], MAGIC_BAR_CONSUME_WITH_PENALTY)) { arrowType = ARROW_NORMAL; } @@ -9368,7 +9368,7 @@ void Player_Init(Actor* thisx, GlobalContext* globalCtx2) { } if (gSaveContext.nayrusLoveTimer != 0) { - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_FREEZE_DARK_LINK; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_FLASH_BORDER_1; func_80846A00(globalCtx, this, 1); this->stateFlags3 &= ~PLAYER_STATE3_6; } @@ -10157,7 +10157,7 @@ void Player_UpdateCommon(Player* this, GlobalContext* globalCtx, Input* input) { if ((this->stateFlags3 & PLAYER_STATE3_6) && (gSaveContext.nayrusLoveTimer != 0) && (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE)) { - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_FREEZE_DARK_LINK; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_FLASH_BORDER_1; func_80846A00(globalCtx, this, 1); this->stateFlags3 &= ~PLAYER_STATE3_6; } @@ -10747,7 +10747,7 @@ void Player_Destroy(Actor* thisx, GlobalContext* globalCtx) { Collider_DestroyQuad(globalCtx, &this->meleeWeaponQuads[1]); Collider_DestroyQuad(globalCtx, &this->shieldQuad); - Magic_ResetState(globalCtx); + Magic_RestoreMagicBarIdleAction(globalCtx); gSaveContext.linkAge = globalCtx->linkAgeOnLoad; } @@ -13108,10 +13108,10 @@ void func_808507F4(Player* this, GlobalContext* globalCtx) { if (func_80846A00(globalCtx, this, this->unk_84F) != NULL) { this->stateFlags1 |= PLAYER_STATE1_28 | PLAYER_STATE1_29; if ((this->unk_84F != 0) || (gSaveContext.respawn[RESPAWN_MODE_TOP].data <= 0)) { - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CHARGE_SETUP; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CHARGE_PENALTY_SETUP; } } else { - Magic_ResetState(globalCtx); + Magic_RestoreMagicBarIdleAction(globalCtx); } } else { LinkAnimation_PlayLoopSetSpeed(globalCtx, &this->skelAnime, D_80854A64[this->unk_84F], 0.83f); From 6bd46b2d77c091a506c287ea1743cf6bac950a80 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Wed, 20 Apr 2022 00:04:29 +1000 Subject: [PATCH 05/33] Simpler name --- include/functions.h | 2 +- src/code/z_actor.c | 2 +- src/code/z_parameter.c | 2 +- src/code/z_play.c | 2 +- src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c | 2 +- src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c | 2 +- src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c | 2 +- src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c | 2 +- src/overlays/actors/ovl_Magic_Dark/z_magic_dark.c | 2 +- src/overlays/actors/ovl_Magic_Fire/z_magic_fire.c | 2 +- src/overlays/actors/ovl_Magic_Wind/z_magic_wind.c | 2 +- src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c | 2 +- src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c | 2 +- src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c | 2 +- src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c | 2 +- src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c | 2 +- src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c | 2 +- src/overlays/actors/ovl_player_actor/z_player.c | 4 ++-- 18 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/functions.h b/include/functions.h index a563b00c229..5b7c538b346 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1043,7 +1043,7 @@ s32 Health_ChangeBy(GlobalContext* globalCtx, s16 healthChange); void Rupees_ChangeBy(s16 rupeeChange); void Inventory_ChangeAmmo(s16 item, s16 ammoChange); void Magic_Fill(GlobalContext* globalCtx); -void Magic_RestoreMagicBarIdleAction(GlobalContext* globalCtx); +void Magic_ResetMagicBarAction(GlobalContext* globalCtx); s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType); void func_80088AA0(s16 arg0); void func_80088AF0(GlobalContext* globalCtx); diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 5611e9fbfbd..cea54086cb5 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -1949,7 +1949,7 @@ void func_80030488(GlobalContext* globalCtx) { void Actor_DisableLens(GlobalContext* globalCtx) { if (globalCtx->actorCtx.lensActive) { globalCtx->actorCtx.lensActive = false; - Magic_RestoreMagicBarIdleAction(globalCtx); + Magic_ResetMagicBarAction(globalCtx); } } diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index 845fe0f8dc9..64daa61fbc6 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2246,7 +2246,7 @@ void Magic_Fill(GlobalContext* globalCtx) { } } -void Magic_RestoreMagicBarIdleAction(GlobalContext* globalCtx) { +void Magic_ResetMagicBarAction(GlobalContext* globalCtx) { if ((gSaveContext.magicBarAction != MAGIC_BAR_ACTION_GROW_WIDE) && (gSaveContext.magicBarAction != MAGIC_BAR_ACTION_FILL)) { if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_ADD) { diff --git a/src/code/z_play.c b/src/code/z_play.c index 2d95bc4f186..1d5bd5e7e54 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -259,7 +259,7 @@ void Gameplay_Init(GameState* thisx) { if (gSaveContext.gameMode != 0 || gSaveContext.cutsceneIndex >= 0xFFF0) { gSaveContext.nayrusLoveTimer = 0; - Magic_RestoreMagicBarIdleAction(globalCtx); + Magic_ResetMagicBarAction(globalCtx); gSaveContext.sceneSetupIndex = (gSaveContext.cutsceneIndex & 0xF) + 4; } else if (!LINK_IS_ADULT && IS_DAY) { gSaveContext.sceneSetupIndex = 0; diff --git a/src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c b/src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c index 29bb8c26128..4077a07cda6 100644 --- a/src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c +++ b/src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c @@ -54,7 +54,7 @@ void ArrowFire_Init(Actor* thisx, GlobalContext* globalCtx) { } void ArrowFire_Destroy(Actor* thisx, GlobalContext* globalCtx) { - Magic_RestoreMagicBarIdleAction(globalCtx); + Magic_ResetMagicBarAction(globalCtx); LOG_STRING("消滅", "../z_arrow_fire.c", 421); // "Disappearance" } diff --git a/src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c b/src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c index 6bff38f3cfa..ebe16a83297 100644 --- a/src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c +++ b/src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c @@ -55,7 +55,7 @@ void ArrowIce_Init(Actor* thisx, GlobalContext* globalCtx) { } void ArrowIce_Destroy(Actor* thisx, GlobalContext* globalCtx) { - Magic_RestoreMagicBarIdleAction(globalCtx); + Magic_ResetMagicBarAction(globalCtx); LOG_STRING("消滅", "../z_arrow_ice.c", 415); // "Disappearance" } diff --git a/src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c b/src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c index 557f2a18e26..48e469d9f2f 100644 --- a/src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c +++ b/src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c @@ -55,7 +55,7 @@ void ArrowLight_Init(Actor* thisx, GlobalContext* globalCtx) { } void ArrowLight_Destroy(Actor* thisx, GlobalContext* globalCtx) { - Magic_RestoreMagicBarIdleAction(globalCtx); + Magic_ResetMagicBarAction(globalCtx); LOG_STRING("消滅", "../z_arrow_light.c", 403); // "Disappearance" } diff --git a/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c b/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c index 8b84bd5adab..9cf0e3dc986 100644 --- a/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c +++ b/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c @@ -115,7 +115,7 @@ void EnMThunder_Destroy(Actor* thisx, GlobalContext* globalCtx) { EnMThunder* this = (EnMThunder*)thisx; if (this->unk_1CA != 0) { - Magic_RestoreMagicBarIdleAction(globalCtx); + Magic_ResetMagicBarAction(globalCtx); } Collider_DestroyCylinder(globalCtx, &this->collider); diff --git a/src/overlays/actors/ovl_Magic_Dark/z_magic_dark.c b/src/overlays/actors/ovl_Magic_Dark/z_magic_dark.c index 27d54a7eb08..e8290e5df06 100644 --- a/src/overlays/actors/ovl_Magic_Dark/z_magic_dark.c +++ b/src/overlays/actors/ovl_Magic_Dark/z_magic_dark.c @@ -64,7 +64,7 @@ void MagicDark_Init(Actor* thisx, GlobalContext* globalCtx) { void MagicDark_Destroy(Actor* thisx, GlobalContext* globalCtx) { if (gSaveContext.nayrusLoveTimer == 0) { - Magic_RestoreMagicBarIdleAction(globalCtx); + Magic_ResetMagicBarAction(globalCtx); } } diff --git a/src/overlays/actors/ovl_Magic_Fire/z_magic_fire.c b/src/overlays/actors/ovl_Magic_Fire/z_magic_fire.c index 41dc2406914..5cfe2be8709 100644 --- a/src/overlays/actors/ovl_Magic_Fire/z_magic_fire.c +++ b/src/overlays/actors/ovl_Magic_Fire/z_magic_fire.c @@ -92,7 +92,7 @@ void MagicFire_Init(Actor* thisx, GlobalContext* globalCtx) { } void MagicFire_Destroy(Actor* thisx, GlobalContext* globalCtx) { - Magic_RestoreMagicBarIdleAction(globalCtx); + Magic_ResetMagicBarAction(globalCtx); } void MagicFire_UpdateBeforeCast(Actor* thisx, GlobalContext* globalCtx) { diff --git a/src/overlays/actors/ovl_Magic_Wind/z_magic_wind.c b/src/overlays/actors/ovl_Magic_Wind/z_magic_wind.c index 0c48f4294d3..8d95efdd6b3 100644 --- a/src/overlays/actors/ovl_Magic_Wind/z_magic_wind.c +++ b/src/overlays/actors/ovl_Magic_Wind/z_magic_wind.c @@ -69,7 +69,7 @@ void MagicWind_Init(Actor* thisx, GlobalContext* globalCtx) { void MagicWind_Destroy(Actor* thisx, GlobalContext* globalCtx) { MagicWind* this = (MagicWind*)thisx; SkelCurve_Destroy(globalCtx, &this->skelCurve); - Magic_RestoreMagicBarIdleAction(globalCtx); + Magic_ResetMagicBarAction(globalCtx); // "wipe out" LOG_STRING("消滅", "../z_magic_wind.c", 505); } diff --git a/src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c b/src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c index ae26376df46..bd28776461b 100644 --- a/src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c +++ b/src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c @@ -69,7 +69,7 @@ void OceffSpot_Destroy(Actor* thisx, GlobalContext* globalCtx) { LightContext_RemoveLight(globalCtx, &globalCtx->lightCtx, this->lightNode1); LightContext_RemoveLight(globalCtx, &globalCtx->lightCtx, this->lightNode2); - Magic_RestoreMagicBarIdleAction(globalCtx); + Magic_ResetMagicBarAction(globalCtx); if ((gSaveContext.nayrusLoveTimer != 0) && (globalCtx->actorCtx.actorLists[ACTORCAT_PLAYER].length != 0)) { player->stateFlags3 |= PLAYER_STATE3_6; } diff --git a/src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c b/src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c index 7291cd0323c..859ca503554 100644 --- a/src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c +++ b/src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c @@ -59,7 +59,7 @@ void OceffStorm_Destroy(Actor* thisx, GlobalContext* globalCtx) { OceffStorm* this = (OceffStorm*)thisx; Player* player = GET_PLAYER(globalCtx); - Magic_RestoreMagicBarIdleAction(globalCtx); + Magic_ResetMagicBarAction(globalCtx); if (gSaveContext.nayrusLoveTimer != 0) { player->stateFlags3 |= PLAYER_STATE3_6; } diff --git a/src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c b/src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c index 700b45b18dc..9e24f515941 100644 --- a/src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c +++ b/src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c @@ -39,7 +39,7 @@ void OceffWipe_Destroy(Actor* thisx, GlobalContext* globalCtx) { OceffWipe* this = (OceffWipe*)thisx; Player* player = GET_PLAYER(globalCtx); - Magic_RestoreMagicBarIdleAction(globalCtx); + Magic_ResetMagicBarAction(globalCtx); if (gSaveContext.nayrusLoveTimer != 0) { player->stateFlags3 |= PLAYER_STATE3_6; } diff --git a/src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c b/src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c index d622deabc17..70b1f471224 100644 --- a/src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c +++ b/src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c @@ -39,7 +39,7 @@ void OceffWipe2_Destroy(Actor* thisx, GlobalContext* globalCtx) { OceffWipe2* this = (OceffWipe2*)thisx; Player* player = GET_PLAYER(globalCtx); - Magic_RestoreMagicBarIdleAction(globalCtx); + Magic_ResetMagicBarAction(globalCtx); if (gSaveContext.nayrusLoveTimer != 0) { player->stateFlags3 |= PLAYER_STATE3_6; } diff --git a/src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c b/src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c index 6ebcd1a2821..b2e38fff508 100644 --- a/src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c +++ b/src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c @@ -42,7 +42,7 @@ void OceffWipe3_Destroy(Actor* thisx, GlobalContext* globalCtx) { OceffWipe3* this = (OceffWipe3*)thisx; Player* player = GET_PLAYER(globalCtx); - Magic_RestoreMagicBarIdleAction(globalCtx); + Magic_ResetMagicBarAction(globalCtx); if (gSaveContext.nayrusLoveTimer != 0) { player->stateFlags3 |= PLAYER_STATE3_6; } diff --git a/src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c b/src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c index b6f76ac19e7..ca692b05d95 100644 --- a/src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c +++ b/src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c @@ -38,7 +38,7 @@ void OceffWipe4_Init(Actor* thisx, GlobalContext* globalCtx) { void OceffWipe4_Destroy(Actor* thisx, GlobalContext* globalCtx) { OceffWipe4* this = (OceffWipe4*)thisx; - Magic_RestoreMagicBarIdleAction(globalCtx); + Magic_ResetMagicBarAction(globalCtx); } void OceffWipe4_Update(Actor* thisx, GlobalContext* globalCtx) { diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index 259a995972e..5d48b33f644 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -10747,7 +10747,7 @@ void Player_Destroy(Actor* thisx, GlobalContext* globalCtx) { Collider_DestroyQuad(globalCtx, &this->meleeWeaponQuads[1]); Collider_DestroyQuad(globalCtx, &this->shieldQuad); - Magic_RestoreMagicBarIdleAction(globalCtx); + Magic_ResetMagicBarAction(globalCtx); gSaveContext.linkAge = globalCtx->linkAgeOnLoad; } @@ -13111,7 +13111,7 @@ void func_808507F4(Player* this, GlobalContext* globalCtx) { gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CHARGE_PENALTY_SETUP; } } else { - Magic_RestoreMagicBarIdleAction(globalCtx); + Magic_ResetMagicBarAction(globalCtx); } } else { LinkAnimation_PlayLoopSetSpeed(globalCtx, &this->skelAnime, D_80854A64[this->unk_84F], 0.83f); From 354c594752d9935f1d00bbabb89375b3c85a83d1 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Wed, 20 Apr 2022 00:07:56 +1000 Subject: [PATCH 06/33] Another small adjustment --- include/z64save.h | 2 +- src/code/z_parameter.c | 2 +- src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c | 2 +- src/overlays/actors/ovl_player_actor/z_player.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/z64save.h b/include/z64save.h index 1fd374bb0fd..10a82333c4a 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -23,7 +23,7 @@ typedef enum MagicBarChange { /* 01 */ MAGIC_BAR_CONSUME_NO_PREVIEW, // Unused, consumes magic without drawing yellow magic to target consumption /* 02 */ MAGIC_BAR_CONSUME_WITH_PENALTY_ALT, // Unused, identical behaviour to MAGIC_BAR_CONSUME_WITH_PENALTY /* 03 */ MAGIC_BAR_CONSUME_LENS, // Lens consumption - /* 04 */ MAGIC_BAR_CONSUME_PREVIEW, // Consume Magic and draws yellow magic to target consumption + /* 04 */ MAGIC_BAR_CONSUME_WITH_PREVIEW, // Consume Magic and draws yellow magic to target consumption /* 05 */ MAGIC_BAR_ADD } MagicBarChange; diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index 64daa61fbc6..35ff979ae9b 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2312,7 +2312,7 @@ s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType) { return false; } } - case MAGIC_BAR_CONSUME_PREVIEW: + case MAGIC_BAR_CONSUME_WITH_PREVIEW: if ((gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE) || (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME)) { if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME) { diff --git a/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c b/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c index 9cf0e3dc986..3bcf50cba11 100644 --- a/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c +++ b/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c @@ -159,7 +159,7 @@ void func_80A9F408(EnMThunder* this, GlobalContext* globalCtx) { if (player->unk_858 >= 0.1f) { if ((gSaveContext.magicBarAction != MAGIC_BAR_ACTION_IDLE) || (((this->actor.params & 0xFF00) >> 8) && - !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_BAR_CONSUME_PREVIEW)))) { + !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_BAR_CONSUME_WITH_PREVIEW)))) { func_80A9F350(this, globalCtx); func_80A9EFE0(this, func_80A9F350); this->unk_1C8 = 0; diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index 5d48b33f644..146551c8bfb 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -4849,7 +4849,7 @@ void func_8083AF44(GlobalContext* globalCtx, Player* this, s32 magicSpell) { func_80835DE4(globalCtx, this, func_808507F4, 0); this->unk_84F = magicSpell - 3; - Magic_ChangeBy(globalCtx, sMagicSpellCosts[magicSpell], MAGIC_BAR_CONSUME_PREVIEW); + Magic_ChangeBy(globalCtx, sMagicSpellCosts[magicSpell], MAGIC_BAR_CONSUME_WITH_PREVIEW); LinkAnimation_PlayOnceSetSpeed(globalCtx, &this->skelAnime, &gPlayerAnim_002D28, 0.83f); From e359fce7ea96ad06aa10dcb5f2b54f03b72e4139 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Wed, 20 Apr 2022 00:13:42 +1000 Subject: [PATCH 07/33] rm if(1) --- src/overlays/gamestates/ovl_file_choose/z_file_choose.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index 8e6e26063ad..b804935ed66 100644 --- a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -1481,8 +1481,6 @@ void FileChoose_LoadGame(GameState* thisx) { gSaveContext.magicCapacity = gSaveContext.magic; gSaveContext.magicLevel = gSaveContext.magic = 0; - if (1) {} - osSyncPrintf(VT_FGCOL(GREEN)); osSyncPrintf("Z_MAGIC_NOW_NOW=%d MAGIC_NOW=%d\n", ((void)0, gSaveContext.magicCapacity), gSaveContext.magic); osSyncPrintf(VT_RST); From 80de240436091c17b427f4d41e84b72f5a154751 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Thu, 21 Apr 2022 11:38:52 +1000 Subject: [PATCH 08/33] Better names again after in-game testing --- include/z64save.h | 20 +++---- src/code/z_parameter.c | 53 ++++++++++++------- .../actors/ovl_En_M_Thunder/z_en_m_thunder.c | 6 +-- .../actors/ovl_En_Torch2/z_en_torch2.c | 2 +- .../actors/ovl_player_actor/z_player.c | 10 ++-- 5 files changed, 53 insertions(+), 38 deletions(-) diff --git a/include/z64save.h b/include/z64save.h index 10a82333c4a..96ab3fa7dad 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -6,12 +6,12 @@ typedef enum MagicBarAction { /* 00 */ MAGIC_BAR_ACTION_IDLE, // Regular gameplay - /* 01 */ MAGIC_BAR_ACTION_CHARGE_PENALTY_SETUP, - /* 02 */ MAGIC_BAR_ACTION_CHARGE_PENALTY, // Consume a small amount of magic before flashing the border - /* 03 */ MAGIC_BAR_ACTION_FLASH_BORDER_1, // Flashes border and freezes Dark Link - /* 04 */ MAGIC_BAR_ACTION_FLASH_BORDER_2, // Flashes border and draws yellow magic to target consumption + /* 01 */ MAGIC_BAR_ACTION_CONSUME_SETUP, // Sets the speed in which magic border flashes + /* 02 */ MAGIC_BAR_ACTION_CONSUME, // Consume magic until target is reached or no more magic is available + /* 03 */ MAGIC_BAR_ACTION_BORDER_CHANGE_1, // Flashes border and freezes Dark Link + /* 04 */ MAGIC_BAR_ACTION_BORDER_CHANGE_2, // Flashes border and draws yellow magic to preview target consumption /* 05 */ MAGIC_BAR_ACTION_RESTORE_IDLE, // Reset colors and return to idle - /* 06 */ MAGIC_BAR_ACTION_FLASH_BORDER_3, // Flashes border with no additional behaviour + /* 06 */ MAGIC_BAR_ACTION_BORDER_CHANGE_3, // Flashes border with no additional behaviour /* 07 */ MAGIC_BAR_ACTION_LENS_CONSUME, // Magic slowly consumed by lens. /* 08 */ MAGIC_BAR_ACTION_GROW_WIDE, // Init magic on a new load, grow from a width of 0 to magicCapacity /* 09 */ MAGIC_BAR_ACTION_FILL, // Fill to either full capacity or another action takes over @@ -19,12 +19,12 @@ typedef enum MagicBarAction { } MagicBarAction; typedef enum MagicBarChange { - /* 00 */ MAGIC_BAR_CONSUME_WITH_PENALTY, // Consume Magic, includes a small penality of consumption is magic consumption is not followed through (spin attack, magic arrows) - /* 01 */ MAGIC_BAR_CONSUME_NO_PREVIEW, // Unused, consumes magic without drawing yellow magic to target consumption - /* 02 */ MAGIC_BAR_CONSUME_WITH_PENALTY_ALT, // Unused, identical behaviour to MAGIC_BAR_CONSUME_WITH_PENALTY + /* 00 */ MAGIC_BAR_CONSUME_NOW, // Consume Magic immediately without preview + /* 01 */ MAGIC_BAR_CONSUME_WAIT_NO_PREVIEW, // Sets consume target but waits to consume. No yellow magic preview to target consumption. Unused + /* 02 */ MAGIC_BAR_CONSUME_NOW_ALT, // Identical behaviour to MAGIC_BAR_CONSUME_NOW. Unused /* 03 */ MAGIC_BAR_CONSUME_LENS, // Lens consumption - /* 04 */ MAGIC_BAR_CONSUME_WITH_PREVIEW, // Consume Magic and draws yellow magic to target consumption - /* 05 */ MAGIC_BAR_ADD + /* 04 */ MAGIC_BAR_CONSUME_WAIT_PREVIEW, // Sets consume target but waits to consume. Draws yellow magic to target consumption + /* 05 */ MAGIC_BAR_ADD // Sets a target to add magic } MagicBarChange; #define MAGIC_HALF_BAR 0x30 diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index 35ff979ae9b..301343afe3d 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2269,33 +2269,39 @@ s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType) { } switch (changeType) { - case MAGIC_BAR_CONSUME_WITH_PENALTY: - case MAGIC_BAR_CONSUME_WITH_PENALTY_ALT: + case MAGIC_BAR_CONSUME_NOW: + case MAGIC_BAR_CONSUME_NOW_ALT: + // Consume magic immediately if ((gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE) || (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME)) { if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME) { globalCtx->actorCtx.lensActive = false; } gSaveContext.magicTarget = gSaveContext.magic - magicChange; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CHARGE_PENALTY_SETUP; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CONSUME_SETUP; return true; } else { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); return false; } - case MAGIC_BAR_CONSUME_NO_PREVIEW: + + case MAGIC_BAR_CONSUME_WAIT_NO_PREVIEW: + // Sets consume target but waits to consume. + // No yellow magic to preview target consumption. + // Unused if ((gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE) || (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME)) { if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME) { globalCtx->actorCtx.lensActive = false; } gSaveContext.magicTarget = gSaveContext.magic - magicChange; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_FLASH_BORDER_3; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_CHANGE_3; return true; } else { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); return false; } + case MAGIC_BAR_CONSUME_LENS: if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE) { if (gSaveContext.magic != 0) { @@ -2312,20 +2318,25 @@ s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType) { return false; } } - case MAGIC_BAR_CONSUME_WITH_PREVIEW: + + case MAGIC_BAR_CONSUME_WAIT_PREVIEW: + // Sets consume target but waits to consume. + // Preview consumption with a yellow bar if ((gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE) || (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME)) { if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME) { globalCtx->actorCtx.lensActive = false; } gSaveContext.magicTarget = gSaveContext.magic - magicChange; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_FLASH_BORDER_2; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_CHANGE_2; return true; } else { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); return false; } + case MAGIC_BAR_ADD: + // Sets target for magic to be added to if (gSaveContext.magic <= gSaveContext.magicCapacityDrawn) { gSaveContext.magicTarget = gSaveContext.magic + magicChange; @@ -2357,7 +2368,7 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { s16 borderChangeR; s16 borderChangeG; s16 borderChangeB; - s16 temp; + s16 temp; // magicCapacity or magicBorderIndex switch (gSaveContext.magicBarAction) { case MAGIC_BAR_ACTION_GROW_WIDE: @@ -2382,7 +2393,7 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { break; case MAGIC_BAR_ACTION_FILL: - // Fill to either full capacity or another action takes over + // Add magic until full capacity is reached gSaveContext.magic += 4; if (gSaveContext.gameMode == 0 && gSaveContext.sceneSetupIndex < 4) { @@ -2392,6 +2403,7 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { // "Storage MAGIC_NOW=%d (%d)" osSyncPrintf("蓄電 MAGIC_NOW=%d (%d)\n", gSaveContext.magic, gSaveContext.magicCapacity); + if (gSaveContext.magic >= gSaveContext.magicCapacity) { gSaveContext.magic = gSaveContext.magicCapacity; gSaveContext.magicBarAction = gSaveContext.magicBarActionStored; @@ -2399,26 +2411,28 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { } break; - case MAGIC_BAR_ACTION_CHARGE_PENALTY_SETUP: + case MAGIC_BAR_ACTION_CONSUME_SETUP: + // Sets the speed in which magic border flashes sMagicBorderRatio = 2; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CHARGE_PENALTY; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CONSUME; break; - case MAGIC_BAR_ACTION_CHARGE_PENALTY: + case MAGIC_BAR_ACTION_CONSUME: + // Consume magic until target is reached or no more magic is available gSaveContext.magic -= 2; if (gSaveContext.magic <= 0) { gSaveContext.magic = 0; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_FLASH_BORDER_1; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_CHANGE_1; sMagicBorderR = sMagicBorderG = sMagicBorderB = 255; } else if (gSaveContext.magic == gSaveContext.magicTarget) { - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_FLASH_BORDER_1; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_CHANGE_1; sMagicBorderR = sMagicBorderG = sMagicBorderB = 255; } - // fallthrough + // fallthrough (flash border while magic is being consumed) - case MAGIC_BAR_ACTION_FLASH_BORDER_1: - case MAGIC_BAR_ACTION_FLASH_BORDER_2: - case MAGIC_BAR_ACTION_FLASH_BORDER_3: + case MAGIC_BAR_ACTION_BORDER_CHANGE_1: + case MAGIC_BAR_ACTION_BORDER_CHANGE_2: + case MAGIC_BAR_ACTION_BORDER_CHANGE_3: temp = sMagicBorderIndices[sMagicBorderStep]; borderChangeR = ABS(sMagicBorderR - sMagicBorderColors[temp][0]) / sMagicBorderRatio; borderChangeG = ABS(sMagicBorderG - sMagicBorderColors[temp][1]) / sMagicBorderRatio; @@ -2522,6 +2536,7 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { break; case MAGIC_BAR_ACTION_ADD: + // Add magic until target is reached gSaveContext.magic += 4; Audio_PlaySoundGeneral(NA_SE_SY_GAUGE_UP - SFX_FLAG, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); if (gSaveContext.magic >= gSaveContext.magicTarget) { @@ -2573,7 +2588,7 @@ void Interface_DrawMagicBar(GlobalContext* globalCtx) { ENVIRONMENT, TEXEL0, ENVIRONMENT, 0, 0, 0, PRIMITIVE); gDPSetEnvColor(OVERLAY_DISP++, 0, 0, 0, 255); - if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_FLASH_BORDER_2) { + if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_BORDER_CHANGE_2) { // Yellow part of the bar indicating the amount of magic to be subtracted gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 250, 250, 0, interfaceCtx->magicAlpha); diff --git a/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c b/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c index 3bcf50cba11..a084af7e89e 100644 --- a/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c +++ b/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c @@ -86,7 +86,7 @@ void EnMThunder_Init(Actor* thisx, GlobalContext* globalCtx2) { if (player->stateFlags2 & PLAYER_STATE2_17) { if (!gSaveContext.isMagicAcquired || (gSaveContext.magicBarAction != MAGIC_BAR_ACTION_IDLE) || (((this->actor.params & 0xFF00) >> 8) && - !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_BAR_CONSUME_WITH_PENALTY)))) { + !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_BAR_CONSUME_NOW)))) { Audio_PlaySoundGeneral(NA_SE_IT_ROLLING_CUT, &player->actor.projectedPos, 4, &D_801333E0, &D_801333E0, &D_801333E8); Audio_PlaySoundGeneral(NA_SE_IT_SWORD_SWING_HARD, &player->actor.projectedPos, 4, &D_801333E0, &D_801333E0, @@ -159,7 +159,7 @@ void func_80A9F408(EnMThunder* this, GlobalContext* globalCtx) { if (player->unk_858 >= 0.1f) { if ((gSaveContext.magicBarAction != MAGIC_BAR_ACTION_IDLE) || (((this->actor.params & 0xFF00) >> 8) && - !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_BAR_CONSUME_WITH_PREVIEW)))) { + !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_BAR_CONSUME_WAIT_PREVIEW)))) { func_80A9F350(this, globalCtx); func_80A9EFE0(this, func_80A9F350); this->unk_1C8 = 0; @@ -193,7 +193,7 @@ void func_80A9F408(EnMThunder* this, GlobalContext* globalCtx) { } else { player->stateFlags2 &= ~PLAYER_STATE2_17; if ((this->actor.params & 0xFF00) >> 8) { - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CHARGE_PENALTY_SETUP; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CONSUME_SETUP; } if (player->unk_858 < 0.85f) { this->collider.info.toucher.dmgFlags = D_80AA044C[this->unk_1C7]; diff --git a/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c b/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c index 9fed5c21e02..011041480dc 100644 --- a/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c +++ b/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c @@ -532,7 +532,7 @@ void EnTorch2_Update(Actor* thisx, GlobalContext* globalCtx2) { // Causes Dark Link to shield in place when Link is using magic attacks other than the spin attack - if ((gSaveContext.magicBarAction == MAGIC_BAR_ACTION_FLASH_BORDER_1) && + if ((gSaveContext.magicBarAction == MAGIC_BAR_ACTION_BORDER_CHANGE_1) && (player->meleeWeaponState == 0 || !((player->meleeWeaponAnimation >= PLAYER_MWA_SPIN_ATTACK_1H) && (player->meleeWeaponAnimation <= PLAYER_MWA_BIG_SPIN_2H)))) { sStickTilt = 0.0f; diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index 146551c8bfb..18f6c698f77 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -2190,7 +2190,7 @@ s32 func_8083442C(Player* this, GlobalContext* globalCtx) { if (this->unk_860 >= 0) { if ((magicArrowType >= 0) && (magicArrowType <= 2) && - !Magic_ChangeBy(globalCtx, sMagicArrowCosts[magicArrowType], MAGIC_BAR_CONSUME_WITH_PENALTY)) { + !Magic_ChangeBy(globalCtx, sMagicArrowCosts[magicArrowType], MAGIC_BAR_CONSUME_NOW)) { arrowType = ARROW_NORMAL; } @@ -4849,7 +4849,7 @@ void func_8083AF44(GlobalContext* globalCtx, Player* this, s32 magicSpell) { func_80835DE4(globalCtx, this, func_808507F4, 0); this->unk_84F = magicSpell - 3; - Magic_ChangeBy(globalCtx, sMagicSpellCosts[magicSpell], MAGIC_BAR_CONSUME_WITH_PREVIEW); + Magic_ChangeBy(globalCtx, sMagicSpellCosts[magicSpell], MAGIC_BAR_CONSUME_WAIT_PREVIEW); LinkAnimation_PlayOnceSetSpeed(globalCtx, &this->skelAnime, &gPlayerAnim_002D28, 0.83f); @@ -9368,7 +9368,7 @@ void Player_Init(Actor* thisx, GlobalContext* globalCtx2) { } if (gSaveContext.nayrusLoveTimer != 0) { - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_FLASH_BORDER_1; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_CHANGE_1; func_80846A00(globalCtx, this, 1); this->stateFlags3 &= ~PLAYER_STATE3_6; } @@ -10157,7 +10157,7 @@ void Player_UpdateCommon(Player* this, GlobalContext* globalCtx, Input* input) { if ((this->stateFlags3 & PLAYER_STATE3_6) && (gSaveContext.nayrusLoveTimer != 0) && (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE)) { - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_FLASH_BORDER_1; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_CHANGE_1; func_80846A00(globalCtx, this, 1); this->stateFlags3 &= ~PLAYER_STATE3_6; } @@ -13108,7 +13108,7 @@ void func_808507F4(Player* this, GlobalContext* globalCtx) { if (func_80846A00(globalCtx, this, this->unk_84F) != NULL) { this->stateFlags1 |= PLAYER_STATE1_28 | PLAYER_STATE1_29; if ((this->unk_84F != 0) || (gSaveContext.respawn[RESPAWN_MODE_TOP].data <= 0)) { - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CHARGE_PENALTY_SETUP; + gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CONSUME_SETUP; } } else { Magic_ResetMagicBarAction(globalCtx); From 522ee08cb8fd5e413c474c3d765650086f0fb52c Mon Sep 17 00:00:00 2001 From: engineer124 Date: Thu, 21 Apr 2022 12:06:21 +1000 Subject: [PATCH 09/33] Change comments --- include/z64.h | 2 +- src/code/z_parameter.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/z64.h b/include/z64.h index aab9d2344b7..7d68c2e754c 100644 --- a/include/z64.h +++ b/include/z64.h @@ -699,7 +699,7 @@ typedef struct { /* 0x022A */ s16 beatingHeartOscillator; /* 0x022C */ s16 beatingHeartOscillatorDirection; /* 0x022E */ s16 unk_22E; - /* 0x0230 */ s16 lensMagicDepletionTimer; // number of frames until magic is depleted 1 unit while lens is active + /* 0x0230 */ s16 lensMagicDepletionTimer; // When lens is active, magic is depleted 1 unit when the timer reaches 0 /* 0x0232 */ s16 counterDigits[4]; // used for key and rupee counters /* 0x023A */ u8 numHorseBoosts; /* 0x023C */ u16 unk_23C; diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index 301343afe3d..2b8f0c46f0c 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2475,6 +2475,7 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { break; case MAGIC_BAR_ACTION_LENS_CONSUME: + // Slowly consume magic while lens is on if ((globalCtx->pauseCtx.state == 0) && (globalCtx->pauseCtx.debugState == 0) && (msgCtx->msgMode == MSGMODE_NONE) && (globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE) && (globalCtx->sceneLoadFlag == 0) && (globalCtx->transitionMode == 0) && !Gameplay_InCsMode(globalCtx)) { From 764a102a863d828c3d72227a49bac6d553b60bd9 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Thu, 21 Apr 2022 14:18:30 +1000 Subject: [PATCH 10/33] change comment --- include/z64save.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/z64save.h b/include/z64save.h index 96ab3fa7dad..9c820df07b8 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -14,7 +14,7 @@ typedef enum MagicBarAction { /* 06 */ MAGIC_BAR_ACTION_BORDER_CHANGE_3, // Flashes border with no additional behaviour /* 07 */ MAGIC_BAR_ACTION_LENS_CONSUME, // Magic slowly consumed by lens. /* 08 */ MAGIC_BAR_ACTION_GROW_WIDE, // Init magic on a new load, grow from a width of 0 to magicCapacity - /* 09 */ MAGIC_BAR_ACTION_FILL, // Fill to either full capacity or another action takes over + /* 09 */ MAGIC_BAR_ACTION_FILL, // Add magic until full capacity is reached /* 10 */ MAGIC_BAR_ACTION_ADD // Add requested magic } MagicBarAction; From e2eada86e72517ca2b32c97a11a5f2a759a355e5 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sun, 24 Apr 2022 11:34:22 +1000 Subject: [PATCH 11/33] Big rename based on all the suggestions --- assets/xml/textures/parameter_static.xml | 6 +- include/functions.h | 2 +- include/regs.h | 6 +- include/z64.h | 2 +- include/z64save.h | 48 ++--- src/code/z_actor.c | 2 +- src/code/z_construct.c | 8 +- src/code/z_kaleido_setup.c | 4 +- src/code/z_parameter.c | 177 +++++++++--------- src/code/z_play.c | 2 +- src/code/z_player_lib.c | 2 +- .../actors/ovl_Arrow_Fire/z_arrow_fire.c | 2 +- .../actors/ovl_Arrow_Ice/z_arrow_ice.c | 2 +- .../actors/ovl_Arrow_Light/z_arrow_light.c | 2 +- .../actors/ovl_En_M_Thunder/z_en_m_thunder.c | 12 +- .../actors/ovl_En_Torch2/z_en_torch2.c | 2 +- src/overlays/actors/ovl_En_Zl3/z_en_zl3.c | 2 +- .../actors/ovl_Magic_Dark/z_magic_dark.c | 2 +- .../actors/ovl_Magic_Fire/z_magic_fire.c | 2 +- .../actors/ovl_Magic_Wind/z_magic_wind.c | 2 +- .../actors/ovl_Oceff_Spot/z_oceff_spot.c | 2 +- .../actors/ovl_Oceff_Storm/z_oceff_storm.c | 2 +- .../actors/ovl_Oceff_Wipe/z_oceff_wipe.c | 2 +- .../actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c | 2 +- .../actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c | 2 +- .../actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c | 2 +- .../actors/ovl_player_actor/z_player.c | 27 ++- .../ovl_file_choose/z_file_choose.c | 4 +- .../ovl_kaleido_scope/z_kaleido_scope_PAL.c | 4 +- 29 files changed, 170 insertions(+), 164 deletions(-) diff --git a/assets/xml/textures/parameter_static.xml b/assets/xml/textures/parameter_static.xml index bd4173431c0..2df06512f34 100644 --- a/assets/xml/textures/parameter_static.xml +++ b/assets/xml/textures/parameter_static.xml @@ -53,8 +53,8 @@ - - - + + + diff --git a/include/functions.h b/include/functions.h index 5b7c538b346..1dea8c10b9e 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1043,7 +1043,7 @@ s32 Health_ChangeBy(GlobalContext* globalCtx, s16 healthChange); void Rupees_ChangeBy(s16 rupeeChange); void Inventory_ChangeAmmo(s16 item, s16 ammoChange); void Magic_Fill(GlobalContext* globalCtx); -void Magic_ResetMagicBarAction(GlobalContext* globalCtx); +void Magic_Reset(GlobalContext* globalCtx); s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType); void func_80088AA0(s16 arg0); void func_80088AF0(GlobalContext* globalCtx); diff --git a/include/regs.h b/include/regs.h index 74b8a43dfe6..d479c953dbb 100644 --- a/include/regs.h +++ b/include/regs.h @@ -93,9 +93,9 @@ #define R_A_ICON_Y XREG(19) #define R_A_ICON_X XREG(20) #define R_A_BTN_COLOR(i) XREG(22 + i) -#define R_MAGIC_BAR_SMALL_Y XREG(48) -#define R_MAGIC_BAR_X XREG(49) -#define R_MAGIC_BAR_LARGE_Y XREG(50) +#define R_MAGIC_METER_SMALL_Y XREG(48) +#define R_MAGIC_METER_X XREG(49) +#define R_MAGIC_METER_LARGE_Y XREG(50) #define R_MAGIC_FILL_X XREG(51) #define R_ENV_LIGHT1_DIR(i) cREG(3 + i) #define R_ENV_LIGHT2_DIR(i) cREG(6 + i) diff --git a/include/z64.h b/include/z64.h index 7d68c2e754c..e24bc34527b 100644 --- a/include/z64.h +++ b/include/z64.h @@ -699,7 +699,7 @@ typedef struct { /* 0x022A */ s16 beatingHeartOscillator; /* 0x022C */ s16 beatingHeartOscillatorDirection; /* 0x022E */ s16 unk_22E; - /* 0x0230 */ s16 lensMagicDepletionTimer; // When lens is active, magic is depleted 1 unit when the timer reaches 0 + /* 0x0230 */ s16 magicConsuptionTimer; // When lens is active, 1 unit of magic is consumed every time the timer reaches 0 /* 0x0232 */ s16 counterDigits[4]; // used for key and rupee counters /* 0x023A */ u8 numHorseBoosts; /* 0x023C */ u16 unk_23C; diff --git a/include/z64save.h b/include/z64save.h index 9c820df07b8..9fd3529a891 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -4,28 +4,28 @@ #include "ultra64.h" #include "z64math.h" -typedef enum MagicBarAction { - /* 00 */ MAGIC_BAR_ACTION_IDLE, // Regular gameplay - /* 01 */ MAGIC_BAR_ACTION_CONSUME_SETUP, // Sets the speed in which magic border flashes - /* 02 */ MAGIC_BAR_ACTION_CONSUME, // Consume magic until target is reached or no more magic is available - /* 03 */ MAGIC_BAR_ACTION_BORDER_CHANGE_1, // Flashes border and freezes Dark Link - /* 04 */ MAGIC_BAR_ACTION_BORDER_CHANGE_2, // Flashes border and draws yellow magic to preview target consumption - /* 05 */ MAGIC_BAR_ACTION_RESTORE_IDLE, // Reset colors and return to idle - /* 06 */ MAGIC_BAR_ACTION_BORDER_CHANGE_3, // Flashes border with no additional behaviour - /* 07 */ MAGIC_BAR_ACTION_LENS_CONSUME, // Magic slowly consumed by lens. - /* 08 */ MAGIC_BAR_ACTION_GROW_WIDE, // Init magic on a new load, grow from a width of 0 to magicCapacity - /* 09 */ MAGIC_BAR_ACTION_FILL, // Add magic until full capacity is reached - /* 10 */ MAGIC_BAR_ACTION_ADD // Add requested magic -} MagicBarAction; - -typedef enum MagicBarChange { - /* 00 */ MAGIC_BAR_CONSUME_NOW, // Consume Magic immediately without preview - /* 01 */ MAGIC_BAR_CONSUME_WAIT_NO_PREVIEW, // Sets consume target but waits to consume. No yellow magic preview to target consumption. Unused - /* 02 */ MAGIC_BAR_CONSUME_NOW_ALT, // Identical behaviour to MAGIC_BAR_CONSUME_NOW. Unused - /* 03 */ MAGIC_BAR_CONSUME_LENS, // Lens consumption - /* 04 */ MAGIC_BAR_CONSUME_WAIT_PREVIEW, // Sets consume target but waits to consume. Draws yellow magic to target consumption - /* 05 */ MAGIC_BAR_ADD // Sets a target to add magic -} MagicBarChange; +typedef enum { + /* 0x0 */ MAGIC_STATE_IDLE, // Regular gameplay + /* 0x1 */ MAGIC_STATE_CONSUME_SETUP, // Sets the speed in which magic border flashes + /* 0x2 */ MAGIC_STATE_CONSUME, // Consume magic until target is reached or no more magic is available + /* 0x3 */ MAGIC_STATE_BORDER_CHANGE_1, // Flashes border and freezes Dark Link + /* 0x4 */ MAGIC_STATE_BORDER_CHANGE_2, // Flashes border and draws yellow magic to preview target consumption + /* 0x5 */ MAGIC_STATE_RESTORE_IDLE, // Reset colors and return to idle + /* 0x6 */ MAGIC_STATE_BORDER_CHANGE_3, // Flashes border with no additional behaviour + /* 0x7 */ MAGIC_STATE_CONSUME_LENS, // Magic slowly consumed by lens. + /* 0x8 */ MAGIC_STATE_GROW_METER, // Init magic on a new load, grow from a width of 0 to magicCapacity + /* 0x9 */ MAGIC_STATE_FILL, // Add magic until full capacity is reached + /* 0xA */ MAGIC_STATE_ADD // Add requested magic +} MagicState; + +typedef enum { + /* 0 */ MAGIC_CONSUME_NOW, // Consume Magic immediately without preview + /* 1 */ MAGIC_CONSUME_WAIT_NO_PREVIEW, // Sets consume target but waits to consume. No yellow magic preview to target consumption. Unused + /* 2 */ MAGIC_CONSUME_NOW_ALT, // Identical behaviour to MAGIC_CONSUME_NOW. Unused + /* 3 */ MAGIC_CONSUME_LENS, // Lens consumption + /* 4 */ MAGIC_CONSUME_WAIT_PREVIEW, // Sets consume target but waits to consume. Draws yellow magic to target consumption + /* 5 */ MAGIC_ADD // Sets a target to add magic +} MagicChangeType; #define MAGIC_HALF_BAR 0x30 #define MAGIC_FULL_BAR (2 * MAGIC_HALF_BAR) @@ -169,8 +169,8 @@ typedef struct { /* 0x13EA */ u16 unk_13EA; // also alpha type? /* 0x13EC */ u16 unk_13EC; // alpha type counter? /* 0x13EE */ u16 unk_13EE; // previous alpha type? - /* 0x13F0 */ s16 magicBarAction; // Next action magic bar will take on each frame - /* 0x13F2 */ s16 magicBarActionStored; // stores the previous magic action while magic is increasing. Allows magicBarAction to be restored afterwards + /* 0x13F0 */ s16 magicState; // Determines magic meter behavior on each frame + /* 0x13F2 */ s16 magicStateStored; // Stores the previous magic state while magic is increasing. Allows magicState to be restored afterwards /* 0x13F4 */ s16 magicCapacityDrawn; // Only differs from magicCapacity in a new save load, where magicCapacityDrawn is slowly stepped from 0 to magicCapacity /* 0x13F6 */ s16 magicCapacity; // Maximum magic available /* 0x13F8 */ s16 magicTarget; // Target for magic to step to when adding or consuming magic diff --git a/src/code/z_actor.c b/src/code/z_actor.c index cea54086cb5..77edf329bb7 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -1949,7 +1949,7 @@ void func_80030488(GlobalContext* globalCtx) { void Actor_DisableLens(GlobalContext* globalCtx) { if (globalCtx->actorCtx.lensActive) { globalCtx->actorCtx.lensActive = false; - Magic_ResetMagicBarAction(globalCtx); + Magic_Reset(globalCtx); } } diff --git a/src/code/z_construct.c b/src/code/z_construct.c index d686bee49c7..a7e2b44514d 100644 --- a/src/code/z_construct.c +++ b/src/code/z_construct.c @@ -18,7 +18,7 @@ void func_801109B0(GlobalContext* globalCtx) { interfaceCtx->unk_1FA = interfaceCtx->unk_261 = interfaceCtx->unk_1FC = 0; interfaceCtx->unk_1EC = interfaceCtx->unk_1EE = interfaceCtx->unk_1F0 = 0; interfaceCtx->unk_22E = 0; - interfaceCtx->lensMagicDepletionTimer = 16; + interfaceCtx->magicConsuptionTimer = 16; interfaceCtx->unk_1F4 = 0.0f; interfaceCtx->unk_228 = XREG(95); interfaceCtx->minimapAlpha = 0; @@ -382,9 +382,9 @@ void func_80111070(void) { XREG(45) = 36; XREG(46) = 16; XREG(47) = 8; - R_MAGIC_BAR_SMALL_Y = 34; - R_MAGIC_BAR_X = 18; - R_MAGIC_BAR_LARGE_Y = 42; + R_MAGIC_METER_SMALL_Y = 34; + R_MAGIC_METER_X = 18; + R_MAGIC_METER_LARGE_Y = 42; R_MAGIC_FILL_X = 26; XREG(52) = 0; XREG(53) = 1; diff --git a/src/code/z_kaleido_setup.c b/src/code/z_kaleido_setup.c index 0207d9e003e..d7db1c258d9 100644 --- a/src/code/z_kaleido_setup.c +++ b/src/code/z_kaleido_setup.c @@ -15,8 +15,8 @@ void KaleidoSetup_Update(GlobalContext* globalCtx) { if (pauseCtx->state == 0 && pauseCtx->debugState == 0 && globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE && globalCtx->sceneLoadFlag == 0 && globalCtx->transitionMode == 0 && gSaveContext.cutsceneIndex < 0xFFF0 && gSaveContext.nextCutsceneIndex < 0xFFF0 && !Gameplay_InCsMode(globalCtx) && - globalCtx->shootingGalleryStatus <= 1 && gSaveContext.magicBarAction != MAGIC_BAR_ACTION_GROW_WIDE && - gSaveContext.magicBarAction != MAGIC_BAR_ACTION_FILL && + globalCtx->shootingGalleryStatus <= 1 && gSaveContext.magicState != MAGIC_STATE_GROW_METER && + gSaveContext.magicState != MAGIC_STATE_FILL && (globalCtx->sceneNum != SCENE_BOWLING || !Flags_GetSwitch(globalCtx, 0x38))) { if (CHECK_BTN_ALL(input->cur.button, BTN_L) && CHECK_BTN_ALL(input->press.button, BTN_CUP)) { diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index b3c11fb87cd..4d3f7c52d39 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -1689,11 +1689,14 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { Health_ChangeBy(globalCtx, 0x10); return item; } else if (item == ITEM_MAGIC_SMALL) { - if (gSaveContext.magicBarAction != MAGIC_BAR_ACTION_ADD) { + if (gSaveContext.magicState != MAGIC_STATE_ADD) { + // This function is only used to store the magicState + // Setting the state to FILL gets immediately overwritten + // in Magic_ChangeBy i.e. magic is added not filled Magic_Fill(globalCtx); } - Magic_ChangeBy(globalCtx, 12, MAGIC_BAR_ADD); + Magic_ChangeBy(globalCtx, 12, MAGIC_ADD); if (!(gSaveContext.infTable[25] & 0x100)) { gSaveContext.infTable[25] |= 0x100; @@ -1702,11 +1705,14 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { return item; } else if (item == ITEM_MAGIC_LARGE) { - if (gSaveContext.magicBarAction != MAGIC_BAR_ACTION_ADD) { + if (gSaveContext.magicState != MAGIC_STATE_ADD) { + // This function is only used to store the magicState + // Setting the state to FILL gets immediately overwritten + // in Magic_ChangeBy i.e. magic is added not filled Magic_Fill(globalCtx); } - Magic_ChangeBy(globalCtx, 24, MAGIC_BAR_ADD); + Magic_ChangeBy(globalCtx, 24, MAGIC_ADD); if (!(gSaveContext.infTable[25] & 0x100)) { gSaveContext.infTable[25] |= 0x100; @@ -2257,19 +2263,18 @@ void Inventory_ChangeAmmo(s16 item, s16 ammoChange) { void Magic_Fill(GlobalContext* globalCtx) { if (gSaveContext.isMagicAcquired) { - gSaveContext.magicBarActionStored = gSaveContext.magicBarAction; + gSaveContext.magicStateStored = gSaveContext.magicState; gSaveContext.magicCapacity = (gSaveContext.isDoubleMagicAcquired + 1) * MAGIC_HALF_BAR; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_FILL; + gSaveContext.magicState = MAGIC_STATE_FILL; } } -void Magic_ResetMagicBarAction(GlobalContext* globalCtx) { - if ((gSaveContext.magicBarAction != MAGIC_BAR_ACTION_GROW_WIDE) && - (gSaveContext.magicBarAction != MAGIC_BAR_ACTION_FILL)) { - if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_ADD) { - gSaveContext.magicBarActionStored = gSaveContext.magicBarAction; +void Magic_Reset(GlobalContext* globalCtx) { + if ((gSaveContext.magicState != MAGIC_STATE_GROW_METER) && (gSaveContext.magicState != MAGIC_STATE_FILL)) { + if (gSaveContext.magicState == MAGIC_STATE_ADD) { + gSaveContext.magicStateStored = gSaveContext.magicState; } - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_RESTORE_IDLE; + gSaveContext.magicState = MAGIC_STATE_RESTORE_IDLE; } } @@ -2278,7 +2283,7 @@ s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType) { return false; } - if ((changeType != MAGIC_BAR_ADD) && (gSaveContext.magic - magicChange) < 0) { + if ((changeType != MAGIC_ADD) && (gSaveContext.magic - magicChange) < 0) { if (gSaveContext.magicCapacityDrawn != 0) { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); } @@ -2286,73 +2291,73 @@ s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType) { } switch (changeType) { - case MAGIC_BAR_CONSUME_NOW: - case MAGIC_BAR_CONSUME_NOW_ALT: + case MAGIC_CONSUME_NOW: + case MAGIC_CONSUME_NOW_ALT: // Consume magic immediately - if ((gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE) || - (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME)) { - if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME) { + if ((gSaveContext.magicState == MAGIC_STATE_IDLE) || + (gSaveContext.magicState == MAGIC_STATE_CONSUME_LENS)) { + if (gSaveContext.magicState == MAGIC_STATE_CONSUME_LENS) { globalCtx->actorCtx.lensActive = false; } gSaveContext.magicTarget = gSaveContext.magic - magicChange; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CONSUME_SETUP; + gSaveContext.magicState = MAGIC_STATE_CONSUME_SETUP; return true; } else { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); return false; } - case MAGIC_BAR_CONSUME_WAIT_NO_PREVIEW: + case MAGIC_CONSUME_WAIT_NO_PREVIEW: // Sets consume target but waits to consume. // No yellow magic to preview target consumption. // Unused - if ((gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE) || - (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME)) { - if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME) { + if ((gSaveContext.magicState == MAGIC_STATE_IDLE) || + (gSaveContext.magicState == MAGIC_STATE_CONSUME_LENS)) { + if (gSaveContext.magicState == MAGIC_STATE_CONSUME_LENS) { globalCtx->actorCtx.lensActive = false; } gSaveContext.magicTarget = gSaveContext.magic - magicChange; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_CHANGE_3; + gSaveContext.magicState = MAGIC_STATE_BORDER_CHANGE_3; return true; } else { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); return false; } - case MAGIC_BAR_CONSUME_LENS: - if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE) { + case MAGIC_CONSUME_LENS: + if (gSaveContext.magicState == MAGIC_STATE_IDLE) { if (gSaveContext.magic != 0) { - globalCtx->interfaceCtx.lensMagicDepletionTimer = 80; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_LENS_CONSUME; + globalCtx->interfaceCtx.magicConsuptionTimer = 80; + gSaveContext.magicState = MAGIC_STATE_CONSUME_LENS; return true; } else { return false; } } else { - if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME) { + if (gSaveContext.magicState == MAGIC_STATE_CONSUME_LENS) { return true; } else { return false; } } - case MAGIC_BAR_CONSUME_WAIT_PREVIEW: + case MAGIC_CONSUME_WAIT_PREVIEW: // Sets consume target but waits to consume. // Preview consumption with a yellow bar - if ((gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE) || - (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME)) { - if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_LENS_CONSUME) { + if ((gSaveContext.magicState == MAGIC_STATE_IDLE) || + (gSaveContext.magicState == MAGIC_STATE_CONSUME_LENS)) { + if (gSaveContext.magicState == MAGIC_STATE_CONSUME_LENS) { globalCtx->actorCtx.lensActive = false; } gSaveContext.magicTarget = gSaveContext.magic - magicChange; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_CHANGE_2; + gSaveContext.magicState = MAGIC_STATE_BORDER_CHANGE_2; return true; } else { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); return false; } - case MAGIC_BAR_ADD: + case MAGIC_ADD: // Sets target for magic to be added to if (gSaveContext.magic <= gSaveContext.magicCapacityDrawn) { gSaveContext.magicTarget = gSaveContext.magic + magicChange; @@ -2361,7 +2366,7 @@ s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType) { gSaveContext.magicTarget = gSaveContext.magicCapacityDrawn; } - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_ADD; + gSaveContext.magicState = MAGIC_STATE_ADD; return true; } break; @@ -2370,7 +2375,7 @@ s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType) { return false; } -void Interface_UpdateMagicBar(GlobalContext* globalCtx) { +void Magic_Update(GlobalContext* globalCtx) { static s16 sMagicBorderColors[][3] = { { 255, 255, 255 }, { 150, 150, 150 }, @@ -2387,8 +2392,8 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { s16 borderChangeB; s16 temp; // magicCapacity or magicBorderIndex - switch (gSaveContext.magicBarAction) { - case MAGIC_BAR_ACTION_GROW_WIDE: + switch (gSaveContext.magicState) { + case MAGIC_STATE_GROW_METER: // Step magicCapacityDrawn to what is magicCapacity // This changes the width of the magic bar drawn temp = gSaveContext.magicLevel * MAGIC_HALF_BAR; // magicCapacity @@ -2405,11 +2410,11 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { } } } else { - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_FILL; + gSaveContext.magicState = MAGIC_STATE_FILL; } break; - case MAGIC_BAR_ACTION_FILL: + case MAGIC_STATE_FILL: // Add magic until full capacity is reached gSaveContext.magic += 4; @@ -2423,33 +2428,33 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { if (gSaveContext.magic >= gSaveContext.magicCapacity) { gSaveContext.magic = gSaveContext.magicCapacity; - gSaveContext.magicBarAction = gSaveContext.magicBarActionStored; - gSaveContext.magicBarActionStored = MAGIC_BAR_ACTION_IDLE; + gSaveContext.magicState = gSaveContext.magicStateStored; + gSaveContext.magicStateStored = MAGIC_STATE_IDLE; } break; - case MAGIC_BAR_ACTION_CONSUME_SETUP: + case MAGIC_STATE_CONSUME_SETUP: // Sets the speed in which magic border flashes sMagicBorderRatio = 2; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CONSUME; + gSaveContext.magicState = MAGIC_STATE_CONSUME; break; - case MAGIC_BAR_ACTION_CONSUME: + case MAGIC_STATE_CONSUME: // Consume magic until target is reached or no more magic is available gSaveContext.magic -= 2; if (gSaveContext.magic <= 0) { gSaveContext.magic = 0; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_CHANGE_1; + gSaveContext.magicState = MAGIC_STATE_BORDER_CHANGE_1; sMagicBorderR = sMagicBorderG = sMagicBorderB = 255; } else if (gSaveContext.magic == gSaveContext.magicTarget) { - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_CHANGE_1; + gSaveContext.magicState = MAGIC_STATE_BORDER_CHANGE_1; sMagicBorderR = sMagicBorderG = sMagicBorderB = 255; } // fallthrough (flash border while magic is being consumed) - case MAGIC_BAR_ACTION_BORDER_CHANGE_1: - case MAGIC_BAR_ACTION_BORDER_CHANGE_2: - case MAGIC_BAR_ACTION_BORDER_CHANGE_3: + case MAGIC_STATE_BORDER_CHANGE_1: + case MAGIC_STATE_BORDER_CHANGE_2: + case MAGIC_STATE_BORDER_CHANGE_3: temp = sMagicBorderIndices[sMagicBorderStep]; borderChangeR = ABS(sMagicBorderR - sMagicBorderColors[temp][0]) / sMagicBorderRatio; borderChangeG = ABS(sMagicBorderG - sMagicBorderColors[temp][1]) / sMagicBorderRatio; @@ -2486,12 +2491,12 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { } break; - case MAGIC_BAR_ACTION_RESTORE_IDLE: + case MAGIC_STATE_RESTORE_IDLE: sMagicBorderR = sMagicBorderG = sMagicBorderB = 255; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_IDLE; + gSaveContext.magicState = MAGIC_STATE_IDLE; break; - case MAGIC_BAR_ACTION_LENS_CONSUME: + case MAGIC_STATE_CONSUME_LENS: // Slowly consume magic while lens is on if ((globalCtx->pauseCtx.state == 0) && (globalCtx->pauseCtx.debugState == 0) && (msgCtx->msgMode == MSGMODE_NONE) && (globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE) && @@ -2505,15 +2510,15 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { globalCtx->actorCtx.lensActive = false; Audio_PlaySoundGeneral(NA_SE_SY_GLASSMODE_OFF, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_IDLE; + gSaveContext.magicState = MAGIC_STATE_IDLE; sMagicBorderR = sMagicBorderG = sMagicBorderB = 255; break; } - interfaceCtx->lensMagicDepletionTimer--; - if (interfaceCtx->lensMagicDepletionTimer == 0) { + interfaceCtx->magicConsuptionTimer--; + if (interfaceCtx->magicConsuptionTimer == 0) { gSaveContext.magic--; - interfaceCtx->lensMagicDepletionTimer = 80; + interfaceCtx->magicConsuptionTimer = 80; } } @@ -2553,34 +2558,34 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { } break; - case MAGIC_BAR_ACTION_ADD: + case MAGIC_STATE_ADD: // Add magic until target is reached gSaveContext.magic += 4; Audio_PlaySoundGeneral(NA_SE_SY_GAUGE_UP - SFX_FLAG, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); if (gSaveContext.magic >= gSaveContext.magicTarget) { gSaveContext.magic = gSaveContext.magicTarget; - gSaveContext.magicBarAction = gSaveContext.magicBarActionStored; - gSaveContext.magicBarActionStored = MAGIC_BAR_ACTION_IDLE; + gSaveContext.magicState = gSaveContext.magicStateStored; + gSaveContext.magicStateStored = MAGIC_STATE_IDLE; } break; default: - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_IDLE; + gSaveContext.magicState = MAGIC_STATE_IDLE; break; } } -void Interface_DrawMagicBar(GlobalContext* globalCtx) { +void Magic_Draw(GlobalContext* globalCtx) { InterfaceContext* interfaceCtx = &globalCtx->interfaceCtx; - s16 magicBarY; + s16 magicMeterY; OPEN_DISPS(globalCtx->state.gfxCtx, "../z_parameter.c", 2650); if (gSaveContext.magicLevel != 0) { if (gSaveContext.healthCapacity > 0xA0) { - magicBarY = R_MAGIC_BAR_LARGE_Y; // two rows of hearts + magicMeterY = R_MAGIC_METER_LARGE_Y; // two rows of hearts } else { - magicBarY = R_MAGIC_BAR_SMALL_Y; // one row of hearts + magicMeterY = R_MAGIC_METER_SMALL_Y; // one row of hearts } func_80094520(globalCtx->state.gfxCtx); @@ -2588,34 +2593,34 @@ void Interface_DrawMagicBar(GlobalContext* globalCtx) { gDPSetPrimColor(OVERLAY_DISP++, 0, 0, sMagicBorderR, sMagicBorderG, sMagicBorderB, interfaceCtx->magicAlpha); gDPSetEnvColor(OVERLAY_DISP++, 100, 50, 50, 255); - OVERLAY_DISP = - Gfx_TextureIA8(OVERLAY_DISP, gMagicBarEndTex, 8, 16, R_MAGIC_BAR_X, magicBarY, 8, 16, 1 << 10, 1 << 10); + OVERLAY_DISP = Gfx_TextureIA8(OVERLAY_DISP, gMagicMeterEndTex, 8, 16, R_MAGIC_METER_X, magicMeterY, 8, 16, + 1 << 10, 1 << 10); - OVERLAY_DISP = Gfx_TextureIA8(OVERLAY_DISP, gMagicBarMidTex, 24, 16, R_MAGIC_BAR_X + 8, magicBarY, + OVERLAY_DISP = Gfx_TextureIA8(OVERLAY_DISP, gMagicMeterMidTex, 24, 16, R_MAGIC_METER_X + 8, magicMeterY, gSaveContext.magicCapacityDrawn, 16, 1 << 10, 1 << 10); - gDPLoadTextureBlock(OVERLAY_DISP++, gMagicBarEndTex, G_IM_FMT_IA, G_IM_SIZ_8b, 8, 16, 0, + gDPLoadTextureBlock(OVERLAY_DISP++, gMagicMeterEndTex, G_IM_FMT_IA, G_IM_SIZ_8b, 8, 16, 0, G_TX_MIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, 3, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPTextureRectangle(OVERLAY_DISP++, ((R_MAGIC_BAR_X + gSaveContext.magicCapacityDrawn) + 8) << 2, - magicBarY << 2, ((R_MAGIC_BAR_X + gSaveContext.magicCapacityDrawn) + 16) << 2, - (magicBarY + 16) << 2, G_TX_RENDERTILE, 256, 0, 1 << 10, 1 << 10); + gSPTextureRectangle(OVERLAY_DISP++, ((R_MAGIC_METER_X + gSaveContext.magicCapacityDrawn) + 8) << 2, + magicMeterY << 2, ((R_MAGIC_METER_X + gSaveContext.magicCapacityDrawn) + 16) << 2, + (magicMeterY + 16) << 2, G_TX_RENDERTILE, 256, 0, 1 << 10, 1 << 10); gDPPipeSync(OVERLAY_DISP++); gDPSetCombineLERP(OVERLAY_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, 0, 0, 0, PRIMITIVE, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, 0, 0, 0, PRIMITIVE); gDPSetEnvColor(OVERLAY_DISP++, 0, 0, 0, 255); - if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_BORDER_CHANGE_2) { + if (gSaveContext.magicState == MAGIC_STATE_BORDER_CHANGE_2) { // Yellow part of the bar indicating the amount of magic to be subtracted gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 250, 250, 0, interfaceCtx->magicAlpha); - gDPLoadMultiBlock_4b(OVERLAY_DISP++, gMagicBarFillTex, 0, G_TX_RENDERTILE, G_IM_FMT_I, 16, 16, 0, + gDPLoadMultiBlock_4b(OVERLAY_DISP++, gMagicMeterFillTex, 0, G_TX_RENDERTILE, G_IM_FMT_I, 16, 16, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPTextureRectangle(OVERLAY_DISP++, R_MAGIC_FILL_X << 2, (magicBarY + 3) << 2, - (R_MAGIC_FILL_X + gSaveContext.magic) << 2, (magicBarY + 10) << 2, G_TX_RENDERTILE, 0, + gSPTextureRectangle(OVERLAY_DISP++, R_MAGIC_FILL_X << 2, (magicMeterY + 3) << 2, + (R_MAGIC_FILL_X + gSaveContext.magic) << 2, (magicMeterY + 10) << 2, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); // Fill the rest of the bar with the normal magic color @@ -2623,20 +2628,20 @@ void Interface_DrawMagicBar(GlobalContext* globalCtx) { gDPSetPrimColor(OVERLAY_DISP++, 0, 0, R_MAGIC_FILL_COLOR(0), R_MAGIC_FILL_COLOR(1), R_MAGIC_FILL_COLOR(2), interfaceCtx->magicAlpha); - gSPTextureRectangle(OVERLAY_DISP++, R_MAGIC_FILL_X << 2, (magicBarY + 3) << 2, - (R_MAGIC_FILL_X + gSaveContext.magicTarget) << 2, (magicBarY + 10) << 2, + gSPTextureRectangle(OVERLAY_DISP++, R_MAGIC_FILL_X << 2, (magicMeterY + 3) << 2, + (R_MAGIC_FILL_X + gSaveContext.magicTarget) << 2, (magicMeterY + 10) << 2, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); } else { // Fill the whole bar with the normal magic color gDPSetPrimColor(OVERLAY_DISP++, 0, 0, R_MAGIC_FILL_COLOR(0), R_MAGIC_FILL_COLOR(1), R_MAGIC_FILL_COLOR(2), interfaceCtx->magicAlpha); - gDPLoadMultiBlock_4b(OVERLAY_DISP++, gMagicBarFillTex, 0, G_TX_RENDERTILE, G_IM_FMT_I, 16, 16, 0, + gDPLoadMultiBlock_4b(OVERLAY_DISP++, gMagicMeterFillTex, 0, G_TX_RENDERTILE, G_IM_FMT_I, 16, 16, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPTextureRectangle(OVERLAY_DISP++, R_MAGIC_FILL_X << 2, (magicBarY + 3) << 2, - (R_MAGIC_FILL_X + gSaveContext.magic) << 2, (magicBarY + 10) << 2, G_TX_RENDERTILE, 0, + gSPTextureRectangle(OVERLAY_DISP++, R_MAGIC_FILL_X << 2, (magicMeterY + 3) << 2, + (R_MAGIC_FILL_X + gSaveContext.magic) << 2, (magicMeterY + 10) << 2, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); } } @@ -3180,7 +3185,7 @@ void Interface_Draw(GlobalContext* globalCtx) { 16, svar3, 206, 8, 16, 1 << 10, 1 << 10); } - Interface_DrawMagicBar(globalCtx); + Magic_Draw(globalCtx); Minimap_Draw(globalCtx); if ((R_PAUSE_MENU_MODE != 2) && (R_PAUSE_MENU_MODE != 3)) { @@ -4086,9 +4091,11 @@ void Interface_Update(GlobalContext* globalCtx) { (msgCtx->msgMode == MSGMODE_NONE) && (globalCtx->sceneLoadFlag == 0) && (globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE) && (globalCtx->transitionMode == 0) && ((globalCtx->csCtx.state == CS_STATE_IDLE) || !Player_InCsMode(globalCtx))) { + // Condition for updating magic + if (gSaveContext.isMagicAcquired && (gSaveContext.magicLevel == 0)) { gSaveContext.magicLevel = gSaveContext.isDoubleMagicAcquired + 1; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_GROW_WIDE; + gSaveContext.magicState = MAGIC_STATE_GROW_METER; osSyncPrintf(VT_FGCOL(YELLOW)); osSyncPrintf("魔法スター─────ト!!!!!!!!!\n"); // "Magic Start!!!!!!!!!" osSyncPrintf("MAGIC_MAX=%d\n", gSaveContext.magicLevel); @@ -4098,7 +4105,7 @@ void Interface_Update(GlobalContext* globalCtx) { osSyncPrintf(VT_RST); } - Interface_UpdateMagicBar(globalCtx); + Magic_Update(globalCtx); } if (gSaveContext.timer1State == 0) { diff --git a/src/code/z_play.c b/src/code/z_play.c index a6d05087734..58d34b0403b 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -259,7 +259,7 @@ void Gameplay_Init(GameState* thisx) { if (gSaveContext.gameMode != 0 || gSaveContext.cutsceneIndex >= 0xFFF0) { gSaveContext.nayrusLoveTimer = 0; - Magic_ResetMagicBarAction(globalCtx); + Magic_Reset(globalCtx); gSaveContext.sceneSetupIndex = (gSaveContext.cutsceneIndex & 0xF) + 4; } else if (!LINK_IS_ADULT && IS_DAY) { gSaveContext.sceneSetupIndex = 0; diff --git a/src/code/z_player_lib.c b/src/code/z_player_lib.c index d3dbba16639..c1e1d10bdcc 100644 --- a/src/code/z_player_lib.c +++ b/src/code/z_player_lib.c @@ -483,7 +483,7 @@ s32 Player_InBlockingCsMode(GlobalContext* globalCtx, Player* this) { return (this->stateFlags1 & (PLAYER_STATE1_7 | PLAYER_STATE1_29)) || (this->csMode != 0) || (globalCtx->sceneLoadFlag == 0x14) || (this->stateFlags1 & PLAYER_STATE1_0) || (this->stateFlags3 & PLAYER_STATE3_7) || - ((gSaveContext.magicBarAction != MAGIC_BAR_ACTION_IDLE) && + ((gSaveContext.magicState != MAGIC_STATE_IDLE) && (Player_ActionToMagicSpell(this, this->itemActionParam) >= 0)); } diff --git a/src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c b/src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c index 4077a07cda6..da5e3d238e0 100644 --- a/src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c +++ b/src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c @@ -54,7 +54,7 @@ void ArrowFire_Init(Actor* thisx, GlobalContext* globalCtx) { } void ArrowFire_Destroy(Actor* thisx, GlobalContext* globalCtx) { - Magic_ResetMagicBarAction(globalCtx); + Magic_Reset(globalCtx); LOG_STRING("消滅", "../z_arrow_fire.c", 421); // "Disappearance" } diff --git a/src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c b/src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c index ebe16a83297..5a43303d018 100644 --- a/src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c +++ b/src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c @@ -55,7 +55,7 @@ void ArrowIce_Init(Actor* thisx, GlobalContext* globalCtx) { } void ArrowIce_Destroy(Actor* thisx, GlobalContext* globalCtx) { - Magic_ResetMagicBarAction(globalCtx); + Magic_Reset(globalCtx); LOG_STRING("消滅", "../z_arrow_ice.c", 415); // "Disappearance" } diff --git a/src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c b/src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c index 48e469d9f2f..58f4db02576 100644 --- a/src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c +++ b/src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c @@ -55,7 +55,7 @@ void ArrowLight_Init(Actor* thisx, GlobalContext* globalCtx) { } void ArrowLight_Destroy(Actor* thisx, GlobalContext* globalCtx) { - Magic_ResetMagicBarAction(globalCtx); + Magic_Reset(globalCtx); LOG_STRING("消滅", "../z_arrow_light.c", 403); // "Disappearance" } diff --git a/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c b/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c index a084af7e89e..582c0f1fe00 100644 --- a/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c +++ b/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c @@ -84,9 +84,9 @@ void EnMThunder_Init(Actor* thisx, GlobalContext* globalCtx2) { this->unk_1CA = 0; if (player->stateFlags2 & PLAYER_STATE2_17) { - if (!gSaveContext.isMagicAcquired || (gSaveContext.magicBarAction != MAGIC_BAR_ACTION_IDLE) || + if (!gSaveContext.isMagicAcquired || (gSaveContext.magicState != MAGIC_STATE_IDLE) || (((this->actor.params & 0xFF00) >> 8) && - !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_BAR_CONSUME_NOW)))) { + !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_CONSUME_NOW)))) { Audio_PlaySoundGeneral(NA_SE_IT_ROLLING_CUT, &player->actor.projectedPos, 4, &D_801333E0, &D_801333E0, &D_801333E8); Audio_PlaySoundGeneral(NA_SE_IT_SWORD_SWING_HARD, &player->actor.projectedPos, 4, &D_801333E0, &D_801333E0, @@ -115,7 +115,7 @@ void EnMThunder_Destroy(Actor* thisx, GlobalContext* globalCtx) { EnMThunder* this = (EnMThunder*)thisx; if (this->unk_1CA != 0) { - Magic_ResetMagicBarAction(globalCtx); + Magic_Reset(globalCtx); } Collider_DestroyCylinder(globalCtx, &this->collider); @@ -157,9 +157,9 @@ void func_80A9F408(EnMThunder* this, GlobalContext* globalCtx) { if (this->unk_1CA == 0) { if (player->unk_858 >= 0.1f) { - if ((gSaveContext.magicBarAction != MAGIC_BAR_ACTION_IDLE) || + if ((gSaveContext.magicState != MAGIC_STATE_IDLE) || (((this->actor.params & 0xFF00) >> 8) && - !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_BAR_CONSUME_WAIT_PREVIEW)))) { + !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_CONSUME_WAIT_PREVIEW)))) { func_80A9F350(this, globalCtx); func_80A9EFE0(this, func_80A9F350); this->unk_1C8 = 0; @@ -193,7 +193,7 @@ void func_80A9F408(EnMThunder* this, GlobalContext* globalCtx) { } else { player->stateFlags2 &= ~PLAYER_STATE2_17; if ((this->actor.params & 0xFF00) >> 8) { - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CONSUME_SETUP; + gSaveContext.magicState = MAGIC_STATE_CONSUME_SETUP; } if (player->unk_858 < 0.85f) { this->collider.info.toucher.dmgFlags = D_80AA044C[this->unk_1C7]; diff --git a/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c b/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c index 011041480dc..b974d2d88ce 100644 --- a/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c +++ b/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c @@ -532,7 +532,7 @@ void EnTorch2_Update(Actor* thisx, GlobalContext* globalCtx2) { // Causes Dark Link to shield in place when Link is using magic attacks other than the spin attack - if ((gSaveContext.magicBarAction == MAGIC_BAR_ACTION_BORDER_CHANGE_1) && + if ((gSaveContext.magicState == MAGIC_STATE_BORDER_CHANGE_1) && (player->meleeWeaponState == 0 || !((player->meleeWeaponAnimation >= PLAYER_MWA_SPIN_ATTACK_1H) && (player->meleeWeaponAnimation <= PLAYER_MWA_BIG_SPIN_2H)))) { sStickTilt = 0.0f; diff --git a/src/overlays/actors/ovl_En_Zl3/z_en_zl3.c b/src/overlays/actors/ovl_En_Zl3/z_en_zl3.c index 0a3db2ae39c..9f02a71d226 100644 --- a/src/overlays/actors/ovl_En_Zl3/z_en_zl3.c +++ b/src/overlays/actors/ovl_En_Zl3/z_en_zl3.c @@ -1812,7 +1812,7 @@ void func_80B5772C(EnZl3* this, GlobalContext* globalCtx) { } void func_80B57754(EnZl3* this, GlobalContext* globalCtx) { - if (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE) { + if (gSaveContext.magicState == MAGIC_STATE_IDLE) { Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_OCEFF_WIPE4, this->actor.world.pos.x, this->actor.world.pos.y, this->actor.world.pos.z, 0, 0, 0, 1); func_80B56DA4(this); diff --git a/src/overlays/actors/ovl_Magic_Dark/z_magic_dark.c b/src/overlays/actors/ovl_Magic_Dark/z_magic_dark.c index e8290e5df06..d288b57f81f 100644 --- a/src/overlays/actors/ovl_Magic_Dark/z_magic_dark.c +++ b/src/overlays/actors/ovl_Magic_Dark/z_magic_dark.c @@ -64,7 +64,7 @@ void MagicDark_Init(Actor* thisx, GlobalContext* globalCtx) { void MagicDark_Destroy(Actor* thisx, GlobalContext* globalCtx) { if (gSaveContext.nayrusLoveTimer == 0) { - Magic_ResetMagicBarAction(globalCtx); + Magic_Reset(globalCtx); } } diff --git a/src/overlays/actors/ovl_Magic_Fire/z_magic_fire.c b/src/overlays/actors/ovl_Magic_Fire/z_magic_fire.c index 5cfe2be8709..ed9b444c3a2 100644 --- a/src/overlays/actors/ovl_Magic_Fire/z_magic_fire.c +++ b/src/overlays/actors/ovl_Magic_Fire/z_magic_fire.c @@ -92,7 +92,7 @@ void MagicFire_Init(Actor* thisx, GlobalContext* globalCtx) { } void MagicFire_Destroy(Actor* thisx, GlobalContext* globalCtx) { - Magic_ResetMagicBarAction(globalCtx); + Magic_Reset(globalCtx); } void MagicFire_UpdateBeforeCast(Actor* thisx, GlobalContext* globalCtx) { diff --git a/src/overlays/actors/ovl_Magic_Wind/z_magic_wind.c b/src/overlays/actors/ovl_Magic_Wind/z_magic_wind.c index 8d95efdd6b3..e578e6ae91f 100644 --- a/src/overlays/actors/ovl_Magic_Wind/z_magic_wind.c +++ b/src/overlays/actors/ovl_Magic_Wind/z_magic_wind.c @@ -69,7 +69,7 @@ void MagicWind_Init(Actor* thisx, GlobalContext* globalCtx) { void MagicWind_Destroy(Actor* thisx, GlobalContext* globalCtx) { MagicWind* this = (MagicWind*)thisx; SkelCurve_Destroy(globalCtx, &this->skelCurve); - Magic_ResetMagicBarAction(globalCtx); + Magic_Reset(globalCtx); // "wipe out" LOG_STRING("消滅", "../z_magic_wind.c", 505); } diff --git a/src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c b/src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c index bd28776461b..470cf72def8 100644 --- a/src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c +++ b/src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c @@ -69,7 +69,7 @@ void OceffSpot_Destroy(Actor* thisx, GlobalContext* globalCtx) { LightContext_RemoveLight(globalCtx, &globalCtx->lightCtx, this->lightNode1); LightContext_RemoveLight(globalCtx, &globalCtx->lightCtx, this->lightNode2); - Magic_ResetMagicBarAction(globalCtx); + Magic_Reset(globalCtx); if ((gSaveContext.nayrusLoveTimer != 0) && (globalCtx->actorCtx.actorLists[ACTORCAT_PLAYER].length != 0)) { player->stateFlags3 |= PLAYER_STATE3_6; } diff --git a/src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c b/src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c index 859ca503554..e42ad7beb33 100644 --- a/src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c +++ b/src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c @@ -59,7 +59,7 @@ void OceffStorm_Destroy(Actor* thisx, GlobalContext* globalCtx) { OceffStorm* this = (OceffStorm*)thisx; Player* player = GET_PLAYER(globalCtx); - Magic_ResetMagicBarAction(globalCtx); + Magic_Reset(globalCtx); if (gSaveContext.nayrusLoveTimer != 0) { player->stateFlags3 |= PLAYER_STATE3_6; } diff --git a/src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c b/src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c index 9e24f515941..81c250dac20 100644 --- a/src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c +++ b/src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c @@ -39,7 +39,7 @@ void OceffWipe_Destroy(Actor* thisx, GlobalContext* globalCtx) { OceffWipe* this = (OceffWipe*)thisx; Player* player = GET_PLAYER(globalCtx); - Magic_ResetMagicBarAction(globalCtx); + Magic_Reset(globalCtx); if (gSaveContext.nayrusLoveTimer != 0) { player->stateFlags3 |= PLAYER_STATE3_6; } diff --git a/src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c b/src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c index 70b1f471224..b3202b87205 100644 --- a/src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c +++ b/src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c @@ -39,7 +39,7 @@ void OceffWipe2_Destroy(Actor* thisx, GlobalContext* globalCtx) { OceffWipe2* this = (OceffWipe2*)thisx; Player* player = GET_PLAYER(globalCtx); - Magic_ResetMagicBarAction(globalCtx); + Magic_Reset(globalCtx); if (gSaveContext.nayrusLoveTimer != 0) { player->stateFlags3 |= PLAYER_STATE3_6; } diff --git a/src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c b/src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c index b2e38fff508..e927ca5f2e4 100644 --- a/src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c +++ b/src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c @@ -42,7 +42,7 @@ void OceffWipe3_Destroy(Actor* thisx, GlobalContext* globalCtx) { OceffWipe3* this = (OceffWipe3*)thisx; Player* player = GET_PLAYER(globalCtx); - Magic_ResetMagicBarAction(globalCtx); + Magic_Reset(globalCtx); if (gSaveContext.nayrusLoveTimer != 0) { player->stateFlags3 |= PLAYER_STATE3_6; } diff --git a/src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c b/src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c index ca692b05d95..027ee7a4d90 100644 --- a/src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c +++ b/src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c @@ -38,7 +38,7 @@ void OceffWipe4_Init(Actor* thisx, GlobalContext* globalCtx) { void OceffWipe4_Destroy(Actor* thisx, GlobalContext* globalCtx) { OceffWipe4* this = (OceffWipe4*)thisx; - Magic_ResetMagicBarAction(globalCtx); + Magic_Reset(globalCtx); } void OceffWipe4_Update(Actor* thisx, GlobalContext* globalCtx) { diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index bac51902c9b..3d6cd334cbf 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -2174,7 +2174,7 @@ s32 func_8083442C(Player* this, GlobalContext* globalCtx) { s32 magicArrowType; if ((this->heldItemActionParam >= PLAYER_AP_BOW_FIRE) && (this->heldItemActionParam <= PLAYER_AP_BOW_0E) && - (gSaveContext.magicBarAction != MAGIC_BAR_ACTION_IDLE)) { + (gSaveContext.magicState != MAGIC_STATE_IDLE)) { func_80078884(NA_SE_SY_ERROR); } else { func_80833638(this, func_808351D4); @@ -2190,7 +2190,7 @@ s32 func_8083442C(Player* this, GlobalContext* globalCtx) { if (this->unk_860 >= 0) { if ((magicArrowType >= 0) && (magicArrowType <= 2) && - !Magic_ChangeBy(globalCtx, sMagicArrowCosts[magicArrowType], MAGIC_BAR_CONSUME_NOW)) { + !Magic_ChangeBy(globalCtx, sMagicArrowCosts[magicArrowType], MAGIC_CONSUME_NOW)) { arrowType = ARROW_NORMAL; } @@ -2885,7 +2885,7 @@ void func_80835F44(GlobalContext* globalCtx, Player* this, s32 item) { } if (actionParam == PLAYER_AP_LENS) { - if (Magic_ChangeBy(globalCtx, 0, MAGIC_BAR_CONSUME_LENS)) { + if (Magic_ChangeBy(globalCtx, 0, MAGIC_CONSUME_LENS)) { if (globalCtx->actorCtx.lensActive) { Actor_DisableLens(globalCtx); } else { @@ -2910,7 +2910,7 @@ void func_80835F44(GlobalContext* globalCtx, Player* this, s32 item) { temp = Player_ActionToMagicSpell(this, actionParam); if (temp >= 0) { if (((actionParam == PLAYER_AP_FARORES_WIND) && (gSaveContext.respawn[RESPAWN_MODE_TOP].data > 0)) || - ((gSaveContext.magicCapacityDrawn != 0) && (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE) && + ((gSaveContext.magicCapacityDrawn != 0) && (gSaveContext.magicState == MAGIC_STATE_IDLE) && (gSaveContext.magic >= sMagicSpellCosts[temp]))) { this->itemActionParam = actionParam; this->unk_6AD = 4; @@ -4849,7 +4849,7 @@ void func_8083AF44(GlobalContext* globalCtx, Player* this, s32 magicSpell) { func_80835DE4(globalCtx, this, func_808507F4, 0); this->unk_84F = magicSpell - 3; - Magic_ChangeBy(globalCtx, sMagicSpellCosts[magicSpell], MAGIC_BAR_CONSUME_WAIT_PREVIEW); + Magic_ChangeBy(globalCtx, sMagicSpellCosts[magicSpell], MAGIC_CONSUME_WAIT_PREVIEW); LinkAnimation_PlayOnceSetSpeed(globalCtx, &this->skelAnime, &gPlayerAnim_002D28, 0.83f); @@ -9368,7 +9368,7 @@ void Player_Init(Actor* thisx, GlobalContext* globalCtx2) { } if (gSaveContext.nayrusLoveTimer != 0) { - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_CHANGE_1; + gSaveContext.magicState = MAGIC_STATE_BORDER_CHANGE_1; func_80846A00(globalCtx, this, 1); this->stateFlags3 &= ~PLAYER_STATE3_6; } @@ -10156,8 +10156,8 @@ void Player_UpdateCommon(Player* this, GlobalContext* globalCtx, Input* input) { } if ((this->stateFlags3 & PLAYER_STATE3_6) && (gSaveContext.nayrusLoveTimer != 0) && - (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE)) { - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_BORDER_CHANGE_1; + (gSaveContext.magicState == MAGIC_STATE_IDLE)) { + gSaveContext.magicState = MAGIC_STATE_BORDER_CHANGE_1; func_80846A00(globalCtx, this, 1); this->stateFlags3 &= ~PLAYER_STATE3_6; } @@ -10747,7 +10747,7 @@ void Player_Destroy(Actor* thisx, GlobalContext* globalCtx) { Collider_DestroyQuad(globalCtx, &this->meleeWeaponQuads[1]); Collider_DestroyQuad(globalCtx, &this->shieldQuad); - Magic_ResetMagicBarAction(globalCtx); + Magic_Reset(globalCtx); gSaveContext.linkAge = globalCtx->linkAgeOnLoad; } @@ -12355,7 +12355,7 @@ void func_8084EAC0(Player* this, GlobalContext* globalCtx) { func_8083C0E8(this, globalCtx); func_8005B1A4(Gameplay_GetCamera(globalCtx, 0)); } else if (this->unk_850 == 1) { - if ((gSaveContext.healthAccumulator == 0) && (gSaveContext.magicBarAction != MAGIC_BAR_ACTION_FILL)) { + if ((gSaveContext.healthAccumulator == 0) && (gSaveContext.magicState != MAGIC_STATE_FILL)) { func_80832B78(globalCtx, this, &gPlayerAnim_002660); this->unk_850 = 2; Player_UpdateBottleHeld(globalCtx, this, ITEM_BOTTLE, PLAYER_AP_BOTTLE); @@ -13096,8 +13096,7 @@ static struct_80832924 D_80854A8C[][2] = { void func_808507F4(Player* this, GlobalContext* globalCtx) { if (LinkAnimation_Update(globalCtx, &this->skelAnime)) { if (this->unk_84F < 0) { - if ((this->itemActionParam == PLAYER_AP_NAYRUS_LOVE) || - (gSaveContext.magicBarAction == MAGIC_BAR_ACTION_IDLE)) { + if ((this->itemActionParam == PLAYER_AP_NAYRUS_LOVE) || (gSaveContext.magicState == MAGIC_STATE_IDLE)) { func_80839FFC(this, globalCtx); func_8005B1A4(Gameplay_GetCamera(globalCtx, 0)); } @@ -13108,10 +13107,10 @@ void func_808507F4(Player* this, GlobalContext* globalCtx) { if (func_80846A00(globalCtx, this, this->unk_84F) != NULL) { this->stateFlags1 |= PLAYER_STATE1_28 | PLAYER_STATE1_29; if ((this->unk_84F != 0) || (gSaveContext.respawn[RESPAWN_MODE_TOP].data <= 0)) { - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_CONSUME_SETUP; + gSaveContext.magicState = MAGIC_STATE_CONSUME_SETUP; } } else { - Magic_ResetMagicBarAction(globalCtx); + Magic_Reset(globalCtx); } } else { LinkAnimation_PlayLoopSetSpeed(globalCtx, &this->skelAnime, D_80854A64[this->unk_84F], 0.83f); diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index b804935ed66..e7829b3140c 100644 --- a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -1461,8 +1461,8 @@ void FileChoose_LoadGame(GameState* thisx) { gSaveContext.unk_13EE = 0x32; gSaveContext.nayrusLoveTimer = 0; gSaveContext.healthAccumulator = 0; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_IDLE; - gSaveContext.magicBarActionStored = MAGIC_BAR_ACTION_IDLE; + gSaveContext.magicState = MAGIC_STATE_IDLE; + gSaveContext.magicStateStored = MAGIC_STATE_IDLE; gSaveContext.forcedSeqId = NA_BGM_GENERAL_SFX; gSaveContext.skyboxTime = 0; gSaveContext.nextTransition = 0xFF; diff --git a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c index 0db71fcfea2..b04a12d8de3 100644 --- a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c +++ b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c @@ -3385,8 +3385,8 @@ void KaleidoScope_Update(GlobalContext* globalCtx) { gSaveContext.health = 0x30; Audio_QueueSeqCmd(0xF << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0xA); gSaveContext.healthAccumulator = 0; - gSaveContext.magicBarAction = MAGIC_BAR_ACTION_IDLE; - gSaveContext.magicBarActionStored = MAGIC_BAR_ACTION_IDLE; + gSaveContext.magicState = MAGIC_STATE_IDLE; + gSaveContext.magicStateStored = MAGIC_STATE_IDLE; osSyncPrintf(VT_FGCOL(YELLOW)); osSyncPrintf("MAGIC_NOW=%d ", gSaveContext.magic); osSyncPrintf("Z_MAGIC_NOW_NOW=%d → ", gSaveContext.magicCapacity); From 26adeef3138036629b3d2841cfa4a464817cc378 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sun, 24 Apr 2022 11:43:04 +1000 Subject: [PATCH 12/33] Small touch-up --- assets/xml/textures/parameter_static.xml | 6 +++--- src/code/z_parameter.c | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/assets/xml/textures/parameter_static.xml b/assets/xml/textures/parameter_static.xml index 2df06512f34..4fd642c7cf4 100644 --- a/assets/xml/textures/parameter_static.xml +++ b/assets/xml/textures/parameter_static.xml @@ -53,8 +53,8 @@ - - - + + + diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index ef256a17476..75c53e54bfc 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -1690,9 +1690,9 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { return item; } else if (item == ITEM_MAGIC_SMALL) { if (gSaveContext.magicState != MAGIC_STATE_ADD) { - // This function is only used to store the magicState - // Setting the state to FILL gets immediately overwritten - // in Magic_ChangeBy i.e. magic is added not filled + // This function is only used to store the magicState. + // Setting the state to FILL gets immediately overwritten in Magic_ChangeBy. + // I.e. magic is added not filled Magic_Fill(globalCtx); } @@ -1706,9 +1706,9 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { return item; } else if (item == ITEM_MAGIC_LARGE) { if (gSaveContext.magicState != MAGIC_STATE_ADD) { - // This function is only used to store the magicState - // Setting the state to FILL gets immediately overwritten - // in Magic_ChangeBy i.e. magic is added not filled + // This function is only used to store the magicState. + // Setting the state to FILL gets immediately overwritten in Magic_ChangeBy. + // I.e. magic is added not filled. Magic_Fill(globalCtx); } From 01460616c616303276351a15c8fce423c7f2bce2 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sat, 7 May 2022 16:57:04 +1000 Subject: [PATCH 13/33] More PR Suggestions --- include/functions.h | 2 +- include/regs.h | 4 ++-- include/z64save.h | 2 +- src/code/z_construct.c | 4 ++-- src/code/z_parameter.c | 22 +++++++++---------- .../actors/ovl_En_M_Thunder/z_en_m_thunder.c | 4 ++-- .../actors/ovl_player_actor/z_player.c | 6 ++--- .../ovl_file_choose/z_file_choose.c | 2 +- .../ovl_kaleido_scope/z_kaleido_scope_PAL.c | 2 +- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/functions.h b/include/functions.h index 1fe434da01e..cf74a026192 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1041,7 +1041,7 @@ void Rupees_ChangeBy(s16 rupeeChange); void Inventory_ChangeAmmo(s16 item, s16 ammoChange); void Magic_Fill(GlobalContext* globalCtx); void Magic_Reset(GlobalContext* globalCtx); -s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType); +s32 Magic_RequestChange(GlobalContext* globalCtx, s16 magicChange, s16 changeType); void func_80088AA0(s16 arg0); void func_80088AF0(GlobalContext* globalCtx); void func_80088B34(s16 arg0); diff --git a/include/regs.h b/include/regs.h index fd2a15e6be7..15a8e083107 100644 --- a/include/regs.h +++ b/include/regs.h @@ -95,9 +95,9 @@ #define R_A_ICON_Y XREG(19) #define R_A_ICON_X XREG(20) #define R_A_BTN_COLOR(i) XREG(22 + i) -#define R_MAGIC_METER_SMALL_Y XREG(48) +#define R_MAGIC_METER_Y_HIGHER XREG(48) #define R_MAGIC_METER_X XREG(49) -#define R_MAGIC_METER_LARGE_Y XREG(50) +#define R_MAGIC_METER_Y_LOWER XREG(50) #define R_MAGIC_FILL_X XREG(51) #define R_ENV_LIGHT1_DIR(i) cREG(3 + i) #define R_ENV_LIGHT2_DIR(i) cREG(6 + i) diff --git a/include/z64save.h b/include/z64save.h index e7aa909fd3e..78d30ebc456 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -170,7 +170,7 @@ typedef struct { /* 0x13EC */ u16 unk_13EC; // alpha type counter? /* 0x13EE */ u16 unk_13EE; // previous alpha type? /* 0x13F0 */ s16 magicState; // Determines magic meter behavior on each frame - /* 0x13F2 */ s16 magicStateStored; // Stores the previous magic state while magic is increasing. Allows magicState to be restored afterwards + /* 0x13F2 */ s16 prevMagicState; // used to resume the previous state after adding for filling magic /* 0x13F4 */ s16 magicCapacityDrawn; // Only differs from magicCapacity in a new save load, where magicCapacityDrawn is slowly stepped from 0 to magicCapacity /* 0x13F6 */ s16 magicCapacity; // Maximum magic available /* 0x13F8 */ s16 magicTarget; // Target for magic to step to when adding or consuming magic diff --git a/src/code/z_construct.c b/src/code/z_construct.c index e1398238d3b..2876ced2d2d 100644 --- a/src/code/z_construct.c +++ b/src/code/z_construct.c @@ -382,9 +382,9 @@ void func_80111070(void) { XREG(45) = 36; XREG(46) = 16; XREG(47) = 8; - R_MAGIC_METER_SMALL_Y = 34; + R_MAGIC_METER_Y_HIGHER = 34; R_MAGIC_METER_X = 18; - R_MAGIC_METER_LARGE_Y = 42; + R_MAGIC_METER_Y_LOWER = 42; R_MAGIC_FILL_X = 26; XREG(52) = 0; XREG(53) = 1; diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index fb63c64ca7f..2898dc71005 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -1705,7 +1705,7 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { Magic_Fill(globalCtx); } - Magic_ChangeBy(globalCtx, 12, MAGIC_ADD); + Magic_RequestChange(globalCtx, 12, MAGIC_ADD); if (!GET_INFTABLE(INFTABLE_198)) { SET_INFTABLE(INFTABLE_198); @@ -1721,7 +1721,7 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { Magic_Fill(globalCtx); } - Magic_ChangeBy(globalCtx, 24, MAGIC_ADD); + Magic_RequestChange(globalCtx, 24, MAGIC_ADD); if (!GET_INFTABLE(INFTABLE_198)) { SET_INFTABLE(INFTABLE_198); @@ -2274,7 +2274,7 @@ void Inventory_ChangeAmmo(s16 item, s16 ammoChange) { void Magic_Fill(GlobalContext* globalCtx) { if (gSaveContext.isMagicAcquired) { - gSaveContext.magicStateStored = gSaveContext.magicState; + gSaveContext.prevMagicState = gSaveContext.magicState; gSaveContext.magicCapacity = (gSaveContext.isDoubleMagicAcquired + 1) * MAGIC_HALF_BAR; gSaveContext.magicState = MAGIC_STATE_FILL; } @@ -2283,13 +2283,13 @@ void Magic_Fill(GlobalContext* globalCtx) { void Magic_Reset(GlobalContext* globalCtx) { if ((gSaveContext.magicState != MAGIC_STATE_GROW_METER) && (gSaveContext.magicState != MAGIC_STATE_FILL)) { if (gSaveContext.magicState == MAGIC_STATE_ADD) { - gSaveContext.magicStateStored = gSaveContext.magicState; + gSaveContext.prevMagicState = gSaveContext.magicState; } gSaveContext.magicState = MAGIC_STATE_RESTORE_IDLE; } } -s32 Magic_ChangeBy(GlobalContext* globalCtx, s16 magicChange, s16 changeType) { +s32 Magic_RequestChange(GlobalContext* globalCtx, s16 magicChange, s16 changeType) { if (!gSaveContext.isMagicAcquired) { return false; } @@ -2443,8 +2443,8 @@ void Magic_Update(GlobalContext* globalCtx) { if (gSaveContext.magic >= gSaveContext.magicCapacity) { gSaveContext.magic = gSaveContext.magicCapacity; - gSaveContext.magicState = gSaveContext.magicStateStored; - gSaveContext.magicStateStored = MAGIC_STATE_IDLE; + gSaveContext.magicState = gSaveContext.prevMagicState; + gSaveContext.prevMagicState = MAGIC_STATE_IDLE; } break; @@ -2581,8 +2581,8 @@ void Magic_Update(GlobalContext* globalCtx) { &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); if (gSaveContext.magic >= gSaveContext.magicTarget) { gSaveContext.magic = gSaveContext.magicTarget; - gSaveContext.magicState = gSaveContext.magicStateStored; - gSaveContext.magicStateStored = MAGIC_STATE_IDLE; + gSaveContext.magicState = gSaveContext.prevMagicState; + gSaveContext.prevMagicState = MAGIC_STATE_IDLE; } break; @@ -2600,9 +2600,9 @@ void Magic_Draw(GlobalContext* globalCtx) { if (gSaveContext.magicLevel != 0) { if (gSaveContext.healthCapacity > 0xA0) { - magicMeterY = R_MAGIC_METER_LARGE_Y; // two rows of hearts + magicMeterY = R_MAGIC_METER_Y_LOWER; // two rows of hearts } else { - magicMeterY = R_MAGIC_METER_SMALL_Y; // one row of hearts + magicMeterY = R_MAGIC_METER_Y_HIGHER; // one row of hearts } func_80094520(globalCtx->state.gfxCtx); diff --git a/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c b/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c index 06ee6bf9ca2..d054c342ca8 100644 --- a/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c +++ b/src/overlays/actors/ovl_En_M_Thunder/z_en_m_thunder.c @@ -86,7 +86,7 @@ void EnMThunder_Init(Actor* thisx, GlobalContext* globalCtx2) { if (player->stateFlags2 & PLAYER_STATE2_17) { if (!gSaveContext.isMagicAcquired || (gSaveContext.magicState != MAGIC_STATE_IDLE) || (((this->actor.params & 0xFF00) >> 8) && - !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_CONSUME_NOW)))) { + !(Magic_RequestChange(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_CONSUME_NOW)))) { Audio_PlaySoundGeneral(NA_SE_IT_ROLLING_CUT, &player->actor.projectedPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); Audio_PlaySoundGeneral(NA_SE_IT_SWORD_SWING_HARD, &player->actor.projectedPos, 4, @@ -159,7 +159,7 @@ void func_80A9F408(EnMThunder* this, GlobalContext* globalCtx) { if (player->unk_858 >= 0.1f) { if ((gSaveContext.magicState != MAGIC_STATE_IDLE) || (((this->actor.params & 0xFF00) >> 8) && - !(Magic_ChangeBy(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_CONSUME_WAIT_PREVIEW)))) { + !(Magic_RequestChange(globalCtx, (this->actor.params & 0xFF00) >> 8, MAGIC_CONSUME_WAIT_PREVIEW)))) { func_80A9F350(this, globalCtx); func_80A9EFE0(this, func_80A9F350); this->unk_1C8 = 0; diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index f87cb6cad34..5a27fbe5d71 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -2190,7 +2190,7 @@ s32 func_8083442C(Player* this, GlobalContext* globalCtx) { if (this->unk_860 >= 0) { if ((magicArrowType >= 0) && (magicArrowType <= 2) && - !Magic_ChangeBy(globalCtx, sMagicArrowCosts[magicArrowType], MAGIC_CONSUME_NOW)) { + !Magic_RequestChange(globalCtx, sMagicArrowCosts[magicArrowType], MAGIC_CONSUME_NOW)) { arrowType = ARROW_NORMAL; } @@ -2882,7 +2882,7 @@ void func_80835F44(GlobalContext* globalCtx, Player* this, s32 item) { (globalCtx->actorCtx.actorLists[ACTORCAT_EXPLOSIVE].length >= 3)))))) { func_80078884(NA_SE_SY_ERROR); } else if (actionParam == PLAYER_AP_LENS) { - if (Magic_ChangeBy(globalCtx, 0, MAGIC_CONSUME_LENS)) { + if (Magic_RequestChange(globalCtx, 0, MAGIC_CONSUME_LENS)) { if (globalCtx->actorCtx.lensActive) { Actor_DisableLens(globalCtx); } else { @@ -4833,7 +4833,7 @@ void func_8083AF44(GlobalContext* globalCtx, Player* this, s32 magicSpell) { func_80835DE4(globalCtx, this, func_808507F4, 0); this->unk_84F = magicSpell - 3; - Magic_ChangeBy(globalCtx, sMagicSpellCosts[magicSpell], MAGIC_CONSUME_WAIT_PREVIEW); + Magic_RequestChange(globalCtx, sMagicSpellCosts[magicSpell], MAGIC_CONSUME_WAIT_PREVIEW); LinkAnimation_PlayOnceSetSpeed(globalCtx, &this->skelAnime, &gPlayerAnim_002D28, 0.83f); diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index a19edd6fb4e..830a724b11a 100644 --- a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -1474,7 +1474,7 @@ void FileChoose_LoadGame(GameState* thisx) { gSaveContext.nayrusLoveTimer = 0; gSaveContext.healthAccumulator = 0; gSaveContext.magicState = MAGIC_STATE_IDLE; - gSaveContext.magicStateStored = MAGIC_STATE_IDLE; + gSaveContext.prevMagicState = MAGIC_STATE_IDLE; gSaveContext.forcedSeqId = NA_BGM_GENERAL_SFX; gSaveContext.skyboxTime = 0; gSaveContext.nextTransitionType = TRANS_NEXT_TYPE_DEFAULT; diff --git a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c index b2e7ac8ad93..6a8d6c4fa72 100644 --- a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c +++ b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c @@ -3395,7 +3395,7 @@ void KaleidoScope_Update(GlobalContext* globalCtx) { Audio_QueueSeqCmd(0xF << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0xA); gSaveContext.healthAccumulator = 0; gSaveContext.magicState = MAGIC_STATE_IDLE; - gSaveContext.magicStateStored = MAGIC_STATE_IDLE; + gSaveContext.prevMagicState = MAGIC_STATE_IDLE; osSyncPrintf(VT_FGCOL(YELLOW)); osSyncPrintf("MAGIC_NOW=%d ", gSaveContext.magic); osSyncPrintf("Z_MAGIC_NOW_NOW=%d → ", gSaveContext.magicCapacity); From aa10f4704ffeb8cbb4655f3c5113c713716d79c1 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sat, 7 May 2022 16:58:19 +1000 Subject: [PATCH 14/33] RESTORE_IDLE -> RESET --- include/z64save.h | 2 +- src/code/z_parameter.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/z64save.h b/include/z64save.h index 78d30ebc456..f1e59cfb3a0 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -10,7 +10,7 @@ typedef enum { /* 0x2 */ MAGIC_STATE_CONSUME, // Consume magic until target is reached or no more magic is available /* 0x3 */ MAGIC_STATE_METER_FLASH_1, // Flashes border and freezes Dark Link /* 0x4 */ MAGIC_STATE_METER_FLASH_2, // Flashes border and draws yellow magic to preview target consumption - /* 0x5 */ MAGIC_STATE_RESTORE_IDLE, // Reset colors and return to idle + /* 0x5 */ MAGIC_STATE_RESET, // Reset colors and return to idle /* 0x6 */ MAGIC_STATE_METER_FLASH_3, // Flashes border with no additional behaviour /* 0x7 */ MAGIC_STATE_CONSUME_LENS, // Magic slowly consumed by lens. /* 0x8 */ MAGIC_STATE_GROW_METER, // Init magic on a new load, grow from a width of 0 to magicCapacity diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index 2898dc71005..8b5087f3c46 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2285,7 +2285,7 @@ void Magic_Reset(GlobalContext* globalCtx) { if (gSaveContext.magicState == MAGIC_STATE_ADD) { gSaveContext.prevMagicState = gSaveContext.magicState; } - gSaveContext.magicState = MAGIC_STATE_RESTORE_IDLE; + gSaveContext.magicState = MAGIC_STATE_RESET; } } @@ -2506,7 +2506,7 @@ void Magic_Update(GlobalContext* globalCtx) { } break; - case MAGIC_STATE_RESTORE_IDLE: + case MAGIC_STATE_RESET: sMagicBorderR = sMagicBorderG = sMagicBorderB = 255; gSaveContext.magicState = MAGIC_STATE_IDLE; break; From fe133cece34c86383ac15ca6702d9db9faa40f64 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sat, 7 May 2022 17:21:02 +1000 Subject: [PATCH 15/33] More docs --- include/z64save.h | 2 +- src/code/z_parameter.c | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/z64save.h b/include/z64save.h index f1e59cfb3a0..cb2dc5357fe 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -170,7 +170,7 @@ typedef struct { /* 0x13EC */ u16 unk_13EC; // alpha type counter? /* 0x13EE */ u16 unk_13EE; // previous alpha type? /* 0x13F0 */ s16 magicState; // Determines magic meter behavior on each frame - /* 0x13F2 */ s16 prevMagicState; // used to resume the previous state after adding for filling magic + /* 0x13F2 */ s16 prevMagicState; // used to resume the previous state after adding or filling magic /* 0x13F4 */ s16 magicCapacityDrawn; // Only differs from magicCapacity in a new save load, where magicCapacityDrawn is slowly stepped from 0 to magicCapacity /* 0x13F6 */ s16 magicCapacity; // Maximum magic available /* 0x13F8 */ s16 magicTarget; // Target for magic to step to when adding or consuming magic diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index 8b5087f3c46..cc54a06ee60 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2289,12 +2289,17 @@ void Magic_Reset(GlobalContext* globalCtx) { } } -s32 Magic_RequestChange(GlobalContext* globalCtx, s16 magicChange, s16 changeType) { +/** + * Request to either increase or consume magic. + * amount is the positive-valued amount to either increase or decrease magic + * type is how the magic is increased or consumed + */ +s32 Magic_RequestChange(GlobalContext* globalCtx, s16 amount, s16 type) { if (!gSaveContext.isMagicAcquired) { return false; } - if ((changeType != MAGIC_ADD) && (gSaveContext.magic - magicChange) < 0) { + if ((type != MAGIC_ADD) && (gSaveContext.magic - amount) < 0) { if (gSaveContext.magicCapacityDrawn != 0) { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); @@ -2302,7 +2307,7 @@ s32 Magic_RequestChange(GlobalContext* globalCtx, s16 magicChange, s16 changeTyp return false; } - switch (changeType) { + switch (type) { case MAGIC_CONSUME_NOW: case MAGIC_CONSUME_NOW_ALT: // Consume magic immediately @@ -2311,7 +2316,7 @@ s32 Magic_RequestChange(GlobalContext* globalCtx, s16 magicChange, s16 changeTyp if (gSaveContext.magicState == MAGIC_STATE_CONSUME_LENS) { globalCtx->actorCtx.lensActive = false; } - gSaveContext.magicTarget = gSaveContext.magic - magicChange; + gSaveContext.magicTarget = gSaveContext.magic - amount; gSaveContext.magicState = MAGIC_STATE_CONSUME_SETUP; return true; } else { @@ -2329,7 +2334,7 @@ s32 Magic_RequestChange(GlobalContext* globalCtx, s16 magicChange, s16 changeTyp if (gSaveContext.magicState == MAGIC_STATE_CONSUME_LENS) { globalCtx->actorCtx.lensActive = false; } - gSaveContext.magicTarget = gSaveContext.magic - magicChange; + gSaveContext.magicTarget = gSaveContext.magic - amount; gSaveContext.magicState = MAGIC_STATE_METER_FLASH_3; return true; } else { @@ -2363,7 +2368,7 @@ s32 Magic_RequestChange(GlobalContext* globalCtx, s16 magicChange, s16 changeTyp if (gSaveContext.magicState == MAGIC_STATE_CONSUME_LENS) { globalCtx->actorCtx.lensActive = false; } - gSaveContext.magicTarget = gSaveContext.magic - magicChange; + gSaveContext.magicTarget = gSaveContext.magic - amount; gSaveContext.magicState = MAGIC_STATE_METER_FLASH_2; return true; } else { @@ -2375,7 +2380,7 @@ s32 Magic_RequestChange(GlobalContext* globalCtx, s16 magicChange, s16 changeTyp case MAGIC_ADD: // Sets target for magic to be added to if (gSaveContext.magic <= gSaveContext.magicCapacityDrawn) { - gSaveContext.magicTarget = gSaveContext.magic + magicChange; + gSaveContext.magicTarget = gSaveContext.magic + amount; if (gSaveContext.magicTarget >= gSaveContext.magicCapacityDrawn) { gSaveContext.magicTarget = gSaveContext.magicCapacityDrawn; @@ -2466,7 +2471,6 @@ void Magic_Update(GlobalContext* globalCtx) { sMagicBorderR = sMagicBorderG = sMagicBorderB = 255; } // fallthrough (flash border while magic is being consumed) - case MAGIC_STATE_METER_FLASH_1: case MAGIC_STATE_METER_FLASH_2: case MAGIC_STATE_METER_FLASH_3: From 9779f9e43b30c72403cd9b12958ded64d0f89f9a Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sat, 7 May 2022 17:37:36 +1000 Subject: [PATCH 16/33] Capitalization --- include/z64save.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/z64save.h b/include/z64save.h index cb2dc5357fe..2988521df33 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -169,11 +169,11 @@ typedef struct { /* 0x13EA */ u16 unk_13EA; // also alpha type? /* 0x13EC */ u16 unk_13EC; // alpha type counter? /* 0x13EE */ u16 unk_13EE; // previous alpha type? - /* 0x13F0 */ s16 magicState; // Determines magic meter behavior on each frame + /* 0x13F0 */ s16 magicState; // determines magic meter behavior on each frame /* 0x13F2 */ s16 prevMagicState; // used to resume the previous state after adding or filling magic - /* 0x13F4 */ s16 magicCapacityDrawn; // Only differs from magicCapacity in a new save load, where magicCapacityDrawn is slowly stepped from 0 to magicCapacity - /* 0x13F6 */ s16 magicCapacity; // Maximum magic available - /* 0x13F8 */ s16 magicTarget; // Target for magic to step to when adding or consuming magic + /* 0x13F4 */ s16 magicCapacityDrawn; // only differs from magicCapacity in a new save load, where magicCapacityDrawn is slowly stepped from 0 to magicCapacity + /* 0x13F6 */ s16 magicCapacity; // maximum magic available + /* 0x13F8 */ s16 magicTarget; // target for magic to step to when adding or consuming magic /* 0x13FA */ u16 eventInf[4]; // "event_inf" /* 0x1402 */ u16 mapIndex; // intended for maps/minimaps but commonly used as the dungeon index /* 0x1404 */ u16 minigameState; From 727a5bd5540dfb81d6c31ab2f561aeb865d74849 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sat, 7 May 2022 20:22:13 +1000 Subject: [PATCH 17/33] PR suggestions --- include/z64save.h | 6 +++--- src/code/z_parameter.c | 16 ++++++++-------- src/code/z_sram.c | 4 ++-- .../actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/z64save.h b/include/z64save.h index 2988521df33..783f8465a00 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -6,7 +6,7 @@ typedef enum { /* 0x0 */ MAGIC_STATE_IDLE, // Regular gameplay - /* 0x1 */ MAGIC_STATE_CONSUME_SETUP, // Sets the speed in which magic border flashes + /* 0x1 */ MAGIC_STATE_CONSUME_SETUP, // Sets the speed at which magic border flashes /* 0x2 */ MAGIC_STATE_CONSUME, // Consume magic until target is reached or no more magic is available /* 0x3 */ MAGIC_STATE_METER_FLASH_1, // Flashes border and freezes Dark Link /* 0x4 */ MAGIC_STATE_METER_FLASH_2, // Flashes border and draws yellow magic to preview target consumption @@ -27,8 +27,8 @@ typedef enum { /* 5 */ MAGIC_ADD // Sets a target to add magic } MagicChangeType; -#define MAGIC_HALF_BAR 0x30 -#define MAGIC_FULL_BAR (2 * MAGIC_HALF_BAR) +#define MAGIC_NORMAL_METER 0x30 +#define MAGIC_DOUBLE_METER (2 * MAGIC_NORMAL_METER) typedef struct { /* 0x00 */ u8 buttonItems[4]; diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index cc54a06ee60..96d82b218f3 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -1700,7 +1700,7 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { } else if (item == ITEM_MAGIC_SMALL) { if (gSaveContext.magicState != MAGIC_STATE_ADD) { // This function is only used to store the magicState. - // Setting the state to FILL gets immediately overwritten in Magic_ChangeBy. + // Setting the state to FILL gets immediately overwritten in Magic_RequestChange. // I.e. magic is added not filled Magic_Fill(globalCtx); } @@ -1716,7 +1716,7 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { } else if (item == ITEM_MAGIC_LARGE) { if (gSaveContext.magicState != MAGIC_STATE_ADD) { // This function is only used to store the magicState. - // Setting the state to FILL gets immediately overwritten in Magic_ChangeBy. + // Setting the state to FILL gets immediately overwritten in Magic_RequestChange. // I.e. magic is added not filled. Magic_Fill(globalCtx); } @@ -2275,7 +2275,7 @@ void Inventory_ChangeAmmo(s16 item, s16 ammoChange) { void Magic_Fill(GlobalContext* globalCtx) { if (gSaveContext.isMagicAcquired) { gSaveContext.prevMagicState = gSaveContext.magicState; - gSaveContext.magicCapacity = (gSaveContext.isDoubleMagicAcquired + 1) * MAGIC_HALF_BAR; + gSaveContext.magicCapacity = (gSaveContext.isDoubleMagicAcquired + 1) * MAGIC_NORMAL_METER; gSaveContext.magicState = MAGIC_STATE_FILL; } } @@ -2291,7 +2291,7 @@ void Magic_Reset(GlobalContext* globalCtx) { /** * Request to either increase or consume magic. - * amount is the positive-valued amount to either increase or decrease magic + * amount is the positive-valued amount to either increase or decrease magic by * type is how the magic is increased or consumed */ s32 Magic_RequestChange(GlobalContext* globalCtx, s16 amount, s16 type) { @@ -2378,7 +2378,7 @@ s32 Magic_RequestChange(GlobalContext* globalCtx, s16 amount, s16 type) { } case MAGIC_ADD: - // Sets target for magic to be added to + // Sets target for magic to increase to if (gSaveContext.magic <= gSaveContext.magicCapacityDrawn) { gSaveContext.magicTarget = gSaveContext.magic + amount; @@ -2416,7 +2416,7 @@ void Magic_Update(GlobalContext* globalCtx) { case MAGIC_STATE_GROW_METER: // Step magicCapacityDrawn to what is magicCapacity // This changes the width of the magic bar drawn - temp = gSaveContext.magicLevel * MAGIC_HALF_BAR; // magicCapacity + temp = gSaveContext.magicLevel * MAGIC_NORMAL_METER; // magicCapacity if (gSaveContext.magicCapacityDrawn != temp) { if (gSaveContext.magicCapacityDrawn < temp) { gSaveContext.magicCapacityDrawn += 8; @@ -2454,7 +2454,7 @@ void Magic_Update(GlobalContext* globalCtx) { break; case MAGIC_STATE_CONSUME_SETUP: - // Sets the speed in which magic border flashes + // Sets the speed at which magic border flashes sMagicBorderRatio = 2; gSaveContext.magicState = MAGIC_STATE_CONSUME; break; @@ -2526,7 +2526,7 @@ void Magic_Update(GlobalContext* globalCtx) { (gSaveContext.equips.buttonItems[2] != ITEM_LENS) && (gSaveContext.equips.buttonItems[3] != ITEM_LENS)) || !globalCtx->actorCtx.lensActive) { - // Force lens off and restore magic bar to idle action + // Force lens off and set magic meter state to idle globalCtx->actorCtx.lensActive = false; Audio_PlaySoundGeneral(NA_SE_SY_GLASSMODE_OFF, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); diff --git a/src/code/z_sram.c b/src/code/z_sram.c index 5cbbcbfd322..97f79d5ecb1 100644 --- a/src/code/z_sram.c +++ b/src/code/z_sram.c @@ -104,7 +104,7 @@ static SavePlayerData sNewSavePlayerData = { 0x30, // healthCapacity 0x30, // defense 0, // magicLevel - MAGIC_HALF_BAR, // magic + MAGIC_NORMAL_METER, // magic 0, // rupees 0, // swordHealth 0, // naviTimer @@ -189,7 +189,7 @@ static SavePlayerData sDebugSavePlayerData = { 0xE0, // healthCapacity 0xE0, // health 0, // magicLevel - MAGIC_HALF_BAR, // magic + MAGIC_NORMAL_METER, // magic 150, // rupees 8, // swordHealth 0, // naviTimer diff --git a/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c b/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c index 1826ed034bc..c5c5a7383ce 100644 --- a/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c +++ b/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c @@ -712,7 +712,7 @@ void BgDyYoseizo_Give_Reward(BgDyYoseizo* this, GlobalContext* globalCtx) { switch (actionIndex) { case FAIRY_UPGRADE_MAGIC: gSaveContext.isMagicAcquired = true; - gSaveContext.magicCapacity = MAGIC_HALF_BAR; + gSaveContext.magicCapacity = MAGIC_NORMAL_METER; Interface_ChangeAlpha(9); break; case FAIRY_UPGRADE_DOUBLE_MAGIC: @@ -720,7 +720,7 @@ void BgDyYoseizo_Give_Reward(BgDyYoseizo* this, GlobalContext* globalCtx) { gSaveContext.isMagicAcquired = true; } gSaveContext.isDoubleMagicAcquired = true; - gSaveContext.magicCapacity = MAGIC_FULL_BAR; + gSaveContext.magicCapacity = MAGIC_DOUBLE_METER; gSaveContext.magicLevel = 0; Interface_ChangeAlpha(9); break; From 5919acc0423a8fc7eee90d788989aeeaca6027e6 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sat, 7 May 2022 21:33:09 +1000 Subject: [PATCH 18/33] Make declaration consistent --- include/functions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/functions.h b/include/functions.h index cf74a026192..25851a42948 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1041,7 +1041,7 @@ void Rupees_ChangeBy(s16 rupeeChange); void Inventory_ChangeAmmo(s16 item, s16 ammoChange); void Magic_Fill(GlobalContext* globalCtx); void Magic_Reset(GlobalContext* globalCtx); -s32 Magic_RequestChange(GlobalContext* globalCtx, s16 magicChange, s16 changeType); +s32 Magic_RequestChange(GlobalContext* globalCtx, s16 amount, s16 type); void func_80088AA0(s16 arg0); void func_80088AF0(GlobalContext* globalCtx); void func_80088B34(s16 arg0); From d647ba10edaab8496499a3f3ae93ffcb48b2ff16 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sat, 7 May 2022 21:36:11 +1000 Subject: [PATCH 19/33] Health_ChangeBy (amount) --- include/functions.h | 2 +- src/code/z_parameter.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/functions.h b/include/functions.h index 25851a42948..a2d2cdadc12 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1036,7 +1036,7 @@ s32 Inventory_ConsumeFairy(GlobalContext* globalCtx); void Interface_SetDoAction(GlobalContext* globalCtx, u16 action); void Interface_SetNaviCall(GlobalContext* globalCtx, u16 naviCallState); void Interface_LoadActionLabelB(GlobalContext* globalCtx, u16 action); -s32 Health_ChangeBy(GlobalContext* globalCtx, s16 healthChange); +s32 Health_ChangeBy(GlobalContext* globalCtx, s16 amount); void Rupees_ChangeBy(s16 rupeeChange); void Inventory_ChangeAmmo(s16 item, s16 ammoChange); void Magic_Fill(GlobalContext* globalCtx); diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index 96d82b218f3..31bd4ec75a6 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2157,25 +2157,25 @@ void Interface_LoadActionLabelB(GlobalContext* globalCtx, u16 action) { interfaceCtx->unk_1FA = true; } -s32 Health_ChangeBy(GlobalContext* globalCtx, s16 healthChange) { +s32 Health_ChangeBy(GlobalContext* globalCtx, s16 amount) { u16 heartCount; u16 healthLevel; // "***** Fluctuation=%d (now=%d, max=%d) ***" - osSyncPrintf("***** 増減=%d (now=%d, max=%d) ***", healthChange, gSaveContext.health, + osSyncPrintf("***** 増減=%d (now=%d, max=%d) ***", amount, gSaveContext.health, gSaveContext.healthCapacity); // clang-format off - if (healthChange > 0) { Audio_PlaySoundGeneral(NA_SE_SY_HP_RECOVER, &gSfxDefaultPos, 4, + if (amount > 0) { Audio_PlaySoundGeneral(NA_SE_SY_HP_RECOVER, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); - } else if (gSaveContext.doubleDefense && (healthChange < 0)) { - healthChange >>= 1; - osSyncPrintf("ハート減少半分!!=%d\n", healthChange); // "Heart decrease halved!!=%d" + } else if (gSaveContext.doubleDefense && (amount < 0)) { + amount >>= 1; + osSyncPrintf("ハート減少半分!!=%d\n", amount); // "Heart decrease halved!!=%d" } // clang-format on - gSaveContext.health += healthChange; + gSaveContext.health += amount; if (gSaveContext.health > gSaveContext.healthCapacity) { gSaveContext.health = gSaveContext.healthCapacity; From 2ce281281c888f77b9fe7734ebb10541d0ecd108 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Wed, 18 May 2022 14:37:54 +1000 Subject: [PATCH 20/33] PR Suggestions --- include/z64save.h | 4 ++-- src/code/z_kaleido_setup.c | 2 +- src/code/z_parameter.c | 20 ++++++++++++-------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/include/z64save.h b/include/z64save.h index 32151ff9995..7fa0197d758 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -13,7 +13,7 @@ typedef enum { /* 0x5 */ MAGIC_STATE_RESET, // Reset colors and return to idle /* 0x6 */ MAGIC_STATE_METER_FLASH_3, // Flashes border with no additional behaviour /* 0x7 */ MAGIC_STATE_CONSUME_LENS, // Magic slowly consumed by lens. - /* 0x8 */ MAGIC_STATE_GROW_METER, // Init magic on a new load, grow from a width of 0 to magicCapacity + /* 0x8 */ MAGIC_STATE_SYNC_METER_WIDTH, // Init magic on a new load, grow from a width of 0 to magicCapacity /* 0x9 */ MAGIC_STATE_FILL, // Add magic until full capacity is reached /* 0xA */ MAGIC_STATE_ADD // Add requested magic } MagicState; @@ -184,7 +184,7 @@ typedef struct { /* 0x13EE */ u16 unk_13EE; // previous alpha type? /* 0x13F0 */ s16 magicState; // determines magic meter behavior on each frame /* 0x13F2 */ s16 prevMagicState; // used to resume the previous state after adding or filling magic - /* 0x13F4 */ s16 magicCapacityDrawn; // only differs from magicCapacity in a new save load, where magicCapacityDrawn is slowly stepped from 0 to magicCapacity + /* 0x13F4 */ s16 magicCapacityDrawn; // only differs from magicCapacity in a new save load, where magicCapacityDrawn is gradually increased from 0 to magicCapacity to show the meter size growing to its actual maximum value. /* 0x13F6 */ s16 magicCapacity; // maximum magic available /* 0x13F8 */ s16 magicTarget; // target for magic to step to when adding or consuming magic /* 0x13FA */ u16 eventInf[4]; // "event_inf" diff --git a/src/code/z_kaleido_setup.c b/src/code/z_kaleido_setup.c index 4a59cb2b2d3..6319f4096fd 100644 --- a/src/code/z_kaleido_setup.c +++ b/src/code/z_kaleido_setup.c @@ -15,7 +15,7 @@ void KaleidoSetup_Update(GlobalContext* globalCtx) { if (pauseCtx->state == 0 && pauseCtx->debugState == 0 && globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE && globalCtx->transitionTrigger == TRANS_TRIGGER_OFF && globalCtx->transitionMode == TRANS_MODE_OFF && gSaveContext.cutsceneIndex < 0xFFF0 && gSaveContext.nextCutsceneIndex < 0xFFF0 && !Play_InCsMode(globalCtx) && - globalCtx->shootingGalleryStatus <= 1 && gSaveContext.magicState != MAGIC_STATE_GROW_METER && + globalCtx->shootingGalleryStatus <= 1 && gSaveContext.magicState != MAGIC_STATE_SYNC_METER_WIDTH && gSaveContext.magicState != MAGIC_STATE_FILL && (globalCtx->sceneNum != SCENE_BOWLING || !Flags_GetSwitch(globalCtx, 0x38))) { diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index 63d82334d50..80b8cc46e34 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2155,6 +2155,9 @@ void Interface_LoadActionLabelB(GlobalContext* globalCtx, u16 action) { interfaceCtx->unk_1FA = true; } +/** + * Returns false if player is out of health + */ s32 Health_ChangeBy(GlobalContext* globalCtx, s16 amount) { u16 heartCount; u16 healthLevel; @@ -2279,7 +2282,7 @@ void Magic_Fill(GlobalContext* globalCtx) { } void Magic_Reset(GlobalContext* globalCtx) { - if ((gSaveContext.magicState != MAGIC_STATE_GROW_METER) && (gSaveContext.magicState != MAGIC_STATE_FILL)) { + if ((gSaveContext.magicState != MAGIC_STATE_SYNC_METER_WIDTH) && (gSaveContext.magicState != MAGIC_STATE_FILL)) { if (gSaveContext.magicState == MAGIC_STATE_ADD) { gSaveContext.prevMagicState = gSaveContext.magicState; } @@ -2290,7 +2293,8 @@ void Magic_Reset(GlobalContext* globalCtx) { /** * Request to either increase or consume magic. * amount is the positive-valued amount to either increase or decrease magic by - * type is how the magic is increased or consumed + * type is how the magic is increased or consumed. + * Returns false if the request failed */ s32 Magic_RequestChange(GlobalContext* globalCtx, s16 amount, s16 type) { if (!gSaveContext.isMagicAcquired) { @@ -2397,8 +2401,8 @@ void Magic_Update(GlobalContext* globalCtx) { static s16 sMagicBorderColors[][3] = { { 255, 255, 255 }, { 150, 150, 150 }, - { 255, 255, 150 }, // unused color - { 255, 255, 50 }, // unused color + { 255, 255, 150 }, // unused + { 255, 255, 50 }, // unused }; static s16 sMagicBorderIndices[] = { 0, 1, 1, 0 }; static s16 sMagicBorderRatio = 2; @@ -2411,7 +2415,7 @@ void Magic_Update(GlobalContext* globalCtx) { s16 temp; // magicCapacity or magicBorderIndex switch (gSaveContext.magicState) { - case MAGIC_STATE_GROW_METER: + case MAGIC_STATE_SYNC_METER_WIDTH: // Step magicCapacityDrawn to what is magicCapacity // This changes the width of the magic bar drawn temp = gSaveContext.magicLevel * MAGIC_NORMAL_METER; // magicCapacity @@ -2594,7 +2598,7 @@ void Magic_Update(GlobalContext* globalCtx) { } } -void Magic_Draw(GlobalContext* globalCtx) { +void Magic_DrawMeter(GlobalContext* globalCtx) { InterfaceContext* interfaceCtx = &globalCtx->interfaceCtx; s16 magicMeterY; @@ -3197,7 +3201,7 @@ void Interface_Draw(GlobalContext* globalCtx) { 16, svar3, 206, 8, 16, 1 << 10, 1 << 10); } - Magic_Draw(globalCtx); + Magic_DrawMeter(globalCtx); Minimap_Draw(globalCtx); if ((R_PAUSE_MENU_MODE != 2) && (R_PAUSE_MENU_MODE != 3)) { @@ -4121,7 +4125,7 @@ void Interface_Update(GlobalContext* globalCtx) { if (gSaveContext.isMagicAcquired && (gSaveContext.magicLevel == 0)) { gSaveContext.magicLevel = gSaveContext.isDoubleMagicAcquired + 1; - gSaveContext.magicState = MAGIC_STATE_GROW_METER; + gSaveContext.magicState = MAGIC_STATE_SYNC_METER_WIDTH; osSyncPrintf(VT_FGCOL(YELLOW)); osSyncPrintf("魔法スター─────ト!!!!!!!!!\n"); // "Magic Start!!!!!!!!!" osSyncPrintf("MAGIC_MAX=%d\n", gSaveContext.magicLevel); From e0776f5dca4e9ee247cdd0e6fac8974910a630b0 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Wed, 18 May 2022 14:42:54 +1000 Subject: [PATCH 21/33] Missed one --- src/code/z_parameter.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index 80b8cc46e34..ddab8ae59b7 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2167,9 +2167,8 @@ s32 Health_ChangeBy(GlobalContext* globalCtx, s16 amount) { gSaveContext.healthCapacity); // clang-format off - if (amount > 0) { Audio_PlaySoundGeneral(NA_SE_SY_HP_RECOVER, &gSfxDefaultPos, 4, - &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, - &gSfxDefaultReverb); + if (amount > 0) { Audio_PlaySoundGeneral(NA_SE_SY_HP_RECOVER, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, + &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); } else if (gSaveContext.doubleDefense && (amount < 0)) { amount >>= 1; osSyncPrintf("ハート減少半分!!=%d\n", amount); // "Heart decrease halved!!=%d" From 743bb671005f4422bba2acfbe0a8d16c5fa0f199 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sat, 21 May 2022 23:26:37 +1000 Subject: [PATCH 22/33] More PR Suggestions --- include/z64save.h | 6 +- src/code/z_kaleido_setup.c | 2 +- src/code/z_parameter.c | 56 +++++++++---------- .../ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c | 7 +-- .../actors/ovl_Boss_Ganon/z_boss_ganon.c | 2 +- .../actors/ovl_player_actor/z_player.c | 2 +- .../ovl_file_choose/z_file_choose.c | 6 +- src/overlays/gamestates/ovl_select/z_select.c | 4 +- .../ovl_kaleido_scope/z_kaleido_scope_PAL.c | 8 +-- 9 files changed, 46 insertions(+), 47 deletions(-) diff --git a/include/z64save.h b/include/z64save.h index 42fff2a4d7d..480f05560af 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -13,7 +13,7 @@ typedef enum { /* 0x5 */ MAGIC_STATE_RESET, // Reset colors and return to idle /* 0x6 */ MAGIC_STATE_METER_FLASH_3, // Flashes border with no additional behaviour /* 0x7 */ MAGIC_STATE_CONSUME_LENS, // Magic slowly consumed by lens. - /* 0x8 */ MAGIC_STATE_SYNC_METER_WIDTH, // Init magic on a new load, grow from a width of 0 to magicCapacity + /* 0x8 */ MAGIC_STATE_STEP_CAPACITY, // step magicCapacity to magicCapacityTarget /* 0x9 */ MAGIC_STATE_FILL, // Add magic until full capacity is reached /* 0xA */ MAGIC_STATE_ADD // Add requested magic } MagicState; @@ -184,8 +184,8 @@ typedef struct { /* 0x13EE */ u16 unk_13EE; // previous alpha type? /* 0x13F0 */ s16 magicState; // determines magic meter behavior on each frame /* 0x13F2 */ s16 prevMagicState; // used to resume the previous state after adding or filling magic - /* 0x13F4 */ s16 magicCapacityDrawn; // only differs from magicCapacity in a new save load, where magicCapacityDrawn is gradually increased from 0 to magicCapacity to show the meter size growing to its actual maximum value. - /* 0x13F6 */ s16 magicCapacity; // maximum magic available + /* 0x13F4 */ s16 magicCapacity; // maximum magic available. Determines magic bar width. Reset to 0 on save and quit, brought back to full width by stepping to magicCapacityTarget + /* 0x13F6 */ s16 magicCapacityTarget; // target for maximum magic available. Target is set when obtaining magic, filling magic full, and on save and quit. /* 0x13F8 */ s16 magicTarget; // target for magic to step to when adding or consuming magic /* 0x13FA */ u16 eventInf[4]; // "event_inf" /* 0x1402 */ u16 mapIndex; // intended for maps/minimaps but commonly used as the dungeon index diff --git a/src/code/z_kaleido_setup.c b/src/code/z_kaleido_setup.c index 6319f4096fd..ad2fc7107b6 100644 --- a/src/code/z_kaleido_setup.c +++ b/src/code/z_kaleido_setup.c @@ -15,7 +15,7 @@ void KaleidoSetup_Update(GlobalContext* globalCtx) { if (pauseCtx->state == 0 && pauseCtx->debugState == 0 && globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE && globalCtx->transitionTrigger == TRANS_TRIGGER_OFF && globalCtx->transitionMode == TRANS_MODE_OFF && gSaveContext.cutsceneIndex < 0xFFF0 && gSaveContext.nextCutsceneIndex < 0xFFF0 && !Play_InCsMode(globalCtx) && - globalCtx->shootingGalleryStatus <= 1 && gSaveContext.magicState != MAGIC_STATE_SYNC_METER_WIDTH && + globalCtx->shootingGalleryStatus <= 1 && gSaveContext.magicState != MAGIC_STATE_STEP_CAPACITY && gSaveContext.magicState != MAGIC_STATE_FILL && (globalCtx->sceneNum != SCENE_BOWLING || !Flags_GetSwitch(globalCtx, 0x38))) { diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index b09d67e6b48..e1de7a1a788 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2275,13 +2275,13 @@ void Inventory_ChangeAmmo(s16 item, s16 ammoChange) { void Magic_Fill(GlobalContext* globalCtx) { if (gSaveContext.isMagicAcquired) { gSaveContext.prevMagicState = gSaveContext.magicState; - gSaveContext.magicCapacity = (gSaveContext.isDoubleMagicAcquired + 1) * MAGIC_NORMAL_METER; + gSaveContext.magicCapacityTarget = (gSaveContext.isDoubleMagicAcquired + 1) * MAGIC_NORMAL_METER; gSaveContext.magicState = MAGIC_STATE_FILL; } } void Magic_Reset(GlobalContext* globalCtx) { - if ((gSaveContext.magicState != MAGIC_STATE_SYNC_METER_WIDTH) && (gSaveContext.magicState != MAGIC_STATE_FILL)) { + if ((gSaveContext.magicState != MAGIC_STATE_STEP_CAPACITY) && (gSaveContext.magicState != MAGIC_STATE_FILL)) { if (gSaveContext.magicState == MAGIC_STATE_ADD) { gSaveContext.prevMagicState = gSaveContext.magicState; } @@ -2301,7 +2301,7 @@ s32 Magic_RequestChange(GlobalContext* globalCtx, s16 amount, s16 type) { } if ((type != MAGIC_ADD) && (gSaveContext.magic - amount) < 0) { - if (gSaveContext.magicCapacityDrawn != 0) { + if (gSaveContext.magicCapacity != 0) { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); } @@ -2380,11 +2380,11 @@ s32 Magic_RequestChange(GlobalContext* globalCtx, s16 amount, s16 type) { case MAGIC_ADD: // Sets target for magic to increase to - if (gSaveContext.magic <= gSaveContext.magicCapacityDrawn) { + if (gSaveContext.magic <= gSaveContext.magicCapacity) { gSaveContext.magicTarget = gSaveContext.magic + amount; - if (gSaveContext.magicTarget >= gSaveContext.magicCapacityDrawn) { - gSaveContext.magicTarget = gSaveContext.magicCapacityDrawn; + if (gSaveContext.magicTarget >= gSaveContext.magicCapacity) { + gSaveContext.magicTarget = gSaveContext.magicCapacity; } gSaveContext.magicState = MAGIC_STATE_ADD; @@ -2411,23 +2411,23 @@ void Magic_Update(GlobalContext* globalCtx) { s16 borderChangeR; s16 borderChangeG; s16 borderChangeB; - s16 temp; // magicCapacity or magicBorderIndex + s16 temp; // magicCapacityTarget or magicBorderIndex switch (gSaveContext.magicState) { - case MAGIC_STATE_SYNC_METER_WIDTH: - // Step magicCapacityDrawn to what is magicCapacity + case MAGIC_STATE_STEP_CAPACITY: + // Step magicCapacity to what is magicCapacityTarget // This changes the width of the magic bar drawn - temp = gSaveContext.magicLevel * MAGIC_NORMAL_METER; // magicCapacity - if (gSaveContext.magicCapacityDrawn != temp) { - if (gSaveContext.magicCapacityDrawn < temp) { - gSaveContext.magicCapacityDrawn += 8; - if (gSaveContext.magicCapacityDrawn > temp) { - gSaveContext.magicCapacityDrawn = temp; + temp = gSaveContext.magicLevel * MAGIC_NORMAL_METER; // magicCapacityTarget + if (gSaveContext.magicCapacity != temp) { + if (gSaveContext.magicCapacity < temp) { + gSaveContext.magicCapacity += 8; + if (gSaveContext.magicCapacity > temp) { + gSaveContext.magicCapacity = temp; } } else { - gSaveContext.magicCapacityDrawn -= 8; - if (gSaveContext.magicCapacityDrawn <= temp) { - gSaveContext.magicCapacityDrawn = temp; + gSaveContext.magicCapacity -= 8; + if (gSaveContext.magicCapacity <= temp) { + gSaveContext.magicCapacity = temp; } } } else { @@ -2445,10 +2445,10 @@ void Magic_Update(GlobalContext* globalCtx) { } // "Storage MAGIC_NOW=%d (%d)" - osSyncPrintf("蓄電 MAGIC_NOW=%d (%d)\n", gSaveContext.magic, gSaveContext.magicCapacity); + osSyncPrintf("蓄電 MAGIC_NOW=%d (%d)\n", gSaveContext.magic, gSaveContext.magicCapacityTarget); - if (gSaveContext.magic >= gSaveContext.magicCapacity) { - gSaveContext.magic = gSaveContext.magicCapacity; + if (gSaveContext.magic >= gSaveContext.magicCapacityTarget) { + gSaveContext.magic = gSaveContext.magicCapacityTarget; gSaveContext.magicState = gSaveContext.prevMagicState; gSaveContext.prevMagicState = MAGIC_STATE_IDLE; } @@ -2619,14 +2619,14 @@ void Magic_DrawMeter(GlobalContext* globalCtx) { 1 << 10, 1 << 10); OVERLAY_DISP = Gfx_TextureIA8(OVERLAY_DISP, gMagicMeterMidTex, 24, 16, R_MAGIC_METER_X + 8, magicMeterY, - gSaveContext.magicCapacityDrawn, 16, 1 << 10, 1 << 10); + gSaveContext.magicCapacity, 16, 1 << 10, 1 << 10); gDPLoadTextureBlock(OVERLAY_DISP++, gMagicMeterEndTex, G_IM_FMT_IA, G_IM_SIZ_8b, 8, 16, 0, G_TX_MIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, 3, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPTextureRectangle(OVERLAY_DISP++, ((R_MAGIC_METER_X + gSaveContext.magicCapacityDrawn) + 8) << 2, - magicMeterY << 2, ((R_MAGIC_METER_X + gSaveContext.magicCapacityDrawn) + 16) << 2, - (magicMeterY + 16) << 2, G_TX_RENDERTILE, 256, 0, 1 << 10, 1 << 10); + gSPTextureRectangle(OVERLAY_DISP++, ((R_MAGIC_METER_X + gSaveContext.magicCapacity) + 8) << 2, magicMeterY << 2, + ((R_MAGIC_METER_X + gSaveContext.magicCapacity) + 16) << 2, (magicMeterY + 16) << 2, + G_TX_RENDERTILE, 256, 0, 1 << 10, 1 << 10); gDPPipeSync(OVERLAY_DISP++); gDPSetCombineLERP(OVERLAY_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, 0, 0, 0, PRIMITIVE, PRIMITIVE, @@ -4124,13 +4124,13 @@ void Interface_Update(GlobalContext* globalCtx) { if (gSaveContext.isMagicAcquired && (gSaveContext.magicLevel == 0)) { gSaveContext.magicLevel = gSaveContext.isDoubleMagicAcquired + 1; - gSaveContext.magicState = MAGIC_STATE_SYNC_METER_WIDTH; + gSaveContext.magicState = MAGIC_STATE_STEP_CAPACITY; osSyncPrintf(VT_FGCOL(YELLOW)); osSyncPrintf("魔法スター─────ト!!!!!!!!!\n"); // "Magic Start!!!!!!!!!" osSyncPrintf("MAGIC_MAX=%d\n", gSaveContext.magicLevel); osSyncPrintf("MAGIC_NOW=%d\n", gSaveContext.magic); - osSyncPrintf("Z_MAGIC_NOW_NOW=%d\n", gSaveContext.magicCapacity); - osSyncPrintf("Z_MAGIC_NOW_MAX=%d\n", gSaveContext.magicCapacityDrawn); + osSyncPrintf("Z_MAGIC_NOW_NOW=%d\n", gSaveContext.magicCapacityTarget); + osSyncPrintf("Z_MAGIC_NOW_MAX=%d\n", gSaveContext.magicCapacity); osSyncPrintf(VT_RST); } diff --git a/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c b/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c index 5ca0900dca8..c94d419380d 100644 --- a/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c +++ b/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c @@ -467,8 +467,7 @@ void BgDyYoseizo_HealPlayer_NoReward(BgDyYoseizo* this, GlobalContext* globalCtx this->refillTimer = 200; } - if (((gSaveContext.healthCapacity == gSaveContext.health) && - (gSaveContext.magic == gSaveContext.magicCapacityDrawn)) || + if (((gSaveContext.healthCapacity == gSaveContext.health) && (gSaveContext.magic == gSaveContext.magicCapacity)) || (this->refillTimer == 1)) { this->healingTimer--; if (this->healingTimer == 90) { @@ -712,7 +711,7 @@ void BgDyYoseizo_Give_Reward(BgDyYoseizo* this, GlobalContext* globalCtx) { switch (actionIndex) { case FAIRY_UPGRADE_MAGIC: gSaveContext.isMagicAcquired = true; - gSaveContext.magicCapacity = MAGIC_NORMAL_METER; + gSaveContext.magicCapacityTarget = MAGIC_NORMAL_METER; Interface_ChangeAlpha(9); break; case FAIRY_UPGRADE_DOUBLE_MAGIC: @@ -720,7 +719,7 @@ void BgDyYoseizo_Give_Reward(BgDyYoseizo* this, GlobalContext* globalCtx) { gSaveContext.isMagicAcquired = true; } gSaveContext.isDoubleMagicAcquired = true; - gSaveContext.magicCapacity = MAGIC_DOUBLE_METER; + gSaveContext.magicCapacityTarget = MAGIC_DOUBLE_METER; gSaveContext.magicLevel = 0; Interface_ChangeAlpha(9); break; diff --git a/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c b/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c index e9648ca0b03..937f46aaa9a 100644 --- a/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c +++ b/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c @@ -1191,7 +1191,7 @@ void BossGanon_SetupTowerCutscene(BossGanon* this, GlobalContext* globalCtx) { this->csTimer = 0; this->csState = 100; this->unk_198 = 1; - gSaveContext.magic = gSaveContext.magicCapacityDrawn; + gSaveContext.magic = gSaveContext.magicCapacity; gSaveContext.health = gSaveContext.healthCapacity; } else { this->actionFunc = BossGanon_SetupTowerCutscene; diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index bf4c5dfadcf..298f0d47736 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -2903,7 +2903,7 @@ void func_80835F44(GlobalContext* globalCtx, Player* this, s32 item) { } } else if ((temp = Player_ActionToMagicSpell(this, actionParam)) >= 0) { if (((actionParam == PLAYER_AP_FARORES_WIND) && (gSaveContext.respawn[RESPAWN_MODE_TOP].data > 0)) || - ((gSaveContext.magicCapacityDrawn != 0) && (gSaveContext.magicState == MAGIC_STATE_IDLE) && + ((gSaveContext.magicCapacity != 0) && (gSaveContext.magicState == MAGIC_STATE_IDLE) && (gSaveContext.magic >= sMagicSpellCosts[temp]))) { this->itemActionParam = actionParam; this->unk_6AD = 4; diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index f2c51a300b6..863c5b4afcf 100644 --- a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -1488,13 +1488,13 @@ void FileChoose_LoadGame(GameState* thisx) { gSaveContext.buttonStatus[3] = gSaveContext.buttonStatus[4] = BTN_ENABLED; gSaveContext.unk_13E7 = gSaveContext.unk_13E8 = gSaveContext.unk_13EA = gSaveContext.unk_13EC = - gSaveContext.magicCapacityDrawn = 0; + gSaveContext.magicCapacity = 0; - gSaveContext.magicCapacity = gSaveContext.magic; + gSaveContext.magicCapacityTarget = gSaveContext.magic; gSaveContext.magicLevel = gSaveContext.magic = 0; osSyncPrintf(VT_FGCOL(GREEN)); - osSyncPrintf("Z_MAGIC_NOW_NOW=%d MAGIC_NOW=%d\n", ((void)0, gSaveContext.magicCapacity), gSaveContext.magic); + osSyncPrintf("Z_MAGIC_NOW_NOW=%d MAGIC_NOW=%d\n", ((void)0, gSaveContext.magicCapacityTarget), gSaveContext.magic); osSyncPrintf(VT_RST); gSaveContext.naviTimer = 0; diff --git a/src/overlays/gamestates/ovl_select/z_select.c b/src/overlays/gamestates/ovl_select/z_select.c index 4073c48fd0f..f42e0eff5c8 100644 --- a/src/overlays/gamestates/ovl_select/z_select.c +++ b/src/overlays/gamestates/ovl_select/z_select.c @@ -20,8 +20,8 @@ void Select_LoadGame(SelectContext* this, s32 entranceIndex) { osSyncPrintf(VT_RST); if (gSaveContext.fileNum == 0xFF) { Sram_InitDebugSave(); - gSaveContext.magicCapacity = gSaveContext.magic; - gSaveContext.magicCapacityDrawn = 0; + gSaveContext.magicCapacityTarget = gSaveContext.magic; + gSaveContext.magicCapacity = 0; gSaveContext.magicLevel = gSaveContext.magic = 0; } gSaveContext.buttonStatus[0] = gSaveContext.buttonStatus[1] = gSaveContext.buttonStatus[2] = diff --git a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c index fe102220669..b9ba92a74ca 100644 --- a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c +++ b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c @@ -3407,12 +3407,12 @@ void KaleidoScope_Update(GlobalContext* globalCtx) { gSaveContext.prevMagicState = MAGIC_STATE_IDLE; osSyncPrintf(VT_FGCOL(YELLOW)); osSyncPrintf("MAGIC_NOW=%d ", gSaveContext.magic); - osSyncPrintf("Z_MAGIC_NOW_NOW=%d → ", gSaveContext.magicCapacity); - gSaveContext.magicCapacityDrawn = 0; - gSaveContext.magicCapacity = gSaveContext.magic; + osSyncPrintf("Z_MAGIC_NOW_NOW=%d → ", gSaveContext.magicCapacityTarget); + gSaveContext.magicCapacity = 0; + gSaveContext.magicCapacityTarget = gSaveContext.magic; gSaveContext.magicLevel = gSaveContext.magic = 0; osSyncPrintf("MAGIC_NOW=%d ", gSaveContext.magic); - osSyncPrintf("Z_MAGIC_NOW_NOW=%d\n", gSaveContext.magicCapacity); + osSyncPrintf("Z_MAGIC_NOW_NOW=%d\n", gSaveContext.magicCapacityTarget); osSyncPrintf(VT_RST); } else { globalCtx->state.running = false; From ad2fbd90754512e1b938557f906cb922a6749409 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sat, 21 May 2022 23:28:12 +1000 Subject: [PATCH 23/33] Change comment --- include/z64save.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/z64save.h b/include/z64save.h index 480f05560af..fc29834f370 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -185,7 +185,7 @@ typedef struct { /* 0x13F0 */ s16 magicState; // determines magic meter behavior on each frame /* 0x13F2 */ s16 prevMagicState; // used to resume the previous state after adding or filling magic /* 0x13F4 */ s16 magicCapacity; // maximum magic available. Determines magic bar width. Reset to 0 on save and quit, brought back to full width by stepping to magicCapacityTarget - /* 0x13F6 */ s16 magicCapacityTarget; // target for maximum magic available. Target is set when obtaining magic, filling magic full, and on save and quit. + /* 0x13F6 */ s16 magicCapacityTarget; // target for maximum magic available. Target is set when upgrading magic, filling magic, and on save and quit. /* 0x13F8 */ s16 magicTarget; // target for magic to step to when adding or consuming magic /* 0x13FA */ u16 eventInf[4]; // "event_inf" /* 0x1402 */ u16 mapIndex; // intended for maps/minimaps but commonly used as the dungeon index From ca12b3d3d6ff818d5f59341d684416f9076a16c8 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sat, 21 May 2022 23:31:55 +1000 Subject: [PATCH 24/33] Add another clarity comment --- src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c b/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c index c94d419380d..f2b2423f15a 100644 --- a/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c +++ b/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c @@ -720,7 +720,7 @@ void BgDyYoseizo_Give_Reward(BgDyYoseizo* this, GlobalContext* globalCtx) { } gSaveContext.isDoubleMagicAcquired = true; gSaveContext.magicCapacityTarget = MAGIC_DOUBLE_METER; - gSaveContext.magicLevel = 0; + gSaveContext.magicLevel = 0; // Setting magicLevel to 0 triggers magicCapacity to step to magicCapacityTarget Interface_ChangeAlpha(9); break; case FAIRY_UPGRADE_HALF_DAMAGE: From b9e8936f647a64dcad6a8794b756e8e61fa62b5a Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sun, 22 May 2022 21:01:44 +1000 Subject: [PATCH 25/33] Discord discussions on `magicFillTarget` --- include/z64save.h | 6 +++--- src/code/z_parameter.c | 18 +++++++++--------- .../actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c | 9 +++++---- .../gamestates/ovl_file_choose/z_file_choose.c | 6 ++++-- src/overlays/gamestates/ovl_select/z_select.c | 2 +- .../ovl_kaleido_scope/z_kaleido_scope_PAL.c | 6 +++--- 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/include/z64save.h b/include/z64save.h index fc29834f370..1b86af66f15 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -13,7 +13,7 @@ typedef enum { /* 0x5 */ MAGIC_STATE_RESET, // Reset colors and return to idle /* 0x6 */ MAGIC_STATE_METER_FLASH_3, // Flashes border with no additional behaviour /* 0x7 */ MAGIC_STATE_CONSUME_LENS, // Magic slowly consumed by lens. - /* 0x8 */ MAGIC_STATE_STEP_CAPACITY, // step magicCapacity to magicCapacityTarget + /* 0x8 */ MAGIC_STATE_STEP_CAPACITY, // step magicCapacity to (gSaveContext.magicLevel * MAGIC_NORMAL_METER) /* 0x9 */ MAGIC_STATE_FILL, // Add magic until full capacity is reached /* 0xA */ MAGIC_STATE_ADD // Add requested magic } MagicState; @@ -184,8 +184,8 @@ typedef struct { /* 0x13EE */ u16 unk_13EE; // previous alpha type? /* 0x13F0 */ s16 magicState; // determines magic meter behavior on each frame /* 0x13F2 */ s16 prevMagicState; // used to resume the previous state after adding or filling magic - /* 0x13F4 */ s16 magicCapacity; // maximum magic available. Determines magic bar width. Reset to 0 on save and quit, brought back to full width by stepping to magicCapacityTarget - /* 0x13F6 */ s16 magicCapacityTarget; // target for maximum magic available. Target is set when upgrading magic, filling magic, and on save and quit. + /* 0x13F4 */ s16 magicCapacity; // maximum magic available + /* 0x13F6 */ s16 magicFillTarget; // target used to fill magic. Target can either be capacity for Magic_Fill and upgrades, or previous magic from a save and quit during a load from file-select /* 0x13F8 */ s16 magicTarget; // target for magic to step to when adding or consuming magic /* 0x13FA */ u16 eventInf[4]; // "event_inf" /* 0x1402 */ u16 mapIndex; // intended for maps/minimaps but commonly used as the dungeon index diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index fd31226168f..a8a54637efd 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2275,7 +2275,7 @@ void Inventory_ChangeAmmo(s16 item, s16 ammoChange) { void Magic_Fill(PlayState* play) { if (gSaveContext.isMagicAcquired) { gSaveContext.prevMagicState = gSaveContext.magicState; - gSaveContext.magicCapacityTarget = (gSaveContext.isDoubleMagicAcquired + 1) * MAGIC_NORMAL_METER; + gSaveContext.magicFillTarget = (gSaveContext.isDoubleMagicAcquired + 1) * MAGIC_NORMAL_METER; gSaveContext.magicState = MAGIC_STATE_FILL; } } @@ -2411,13 +2411,13 @@ void Magic_Update(PlayState* play) { s16 borderChangeR; s16 borderChangeG; s16 borderChangeB; - s16 temp; // magicCapacityTarget or magicBorderIndex + s16 temp; // magicFillTarget or magicBorderIndex switch (gSaveContext.magicState) { case MAGIC_STATE_STEP_CAPACITY: - // Step magicCapacity to what is magicCapacityTarget + // Step magicCapacity to the capacity determined by magicLevel // This changes the width of the magic bar drawn - temp = gSaveContext.magicLevel * MAGIC_NORMAL_METER; // magicCapacityTarget + temp = gSaveContext.magicLevel * MAGIC_NORMAL_METER; if (gSaveContext.magicCapacity != temp) { if (gSaveContext.magicCapacity < temp) { gSaveContext.magicCapacity += 8; @@ -2436,7 +2436,7 @@ void Magic_Update(PlayState* play) { break; case MAGIC_STATE_FILL: - // Add magic until full capacity is reached + // Add magic until magicFillTarget is reached gSaveContext.magic += 4; if (gSaveContext.gameMode == 0 && gSaveContext.sceneSetupIndex < 4) { @@ -2445,10 +2445,10 @@ void Magic_Update(PlayState* play) { } // "Storage MAGIC_NOW=%d (%d)" - osSyncPrintf("蓄電 MAGIC_NOW=%d (%d)\n", gSaveContext.magic, gSaveContext.magicCapacityTarget); + osSyncPrintf("蓄電 MAGIC_NOW=%d (%d)\n", gSaveContext.magic, gSaveContext.magicFillTarget); - if (gSaveContext.magic >= gSaveContext.magicCapacityTarget) { - gSaveContext.magic = gSaveContext.magicCapacityTarget; + if (gSaveContext.magic >= gSaveContext.magicFillTarget) { + gSaveContext.magic = gSaveContext.magicFillTarget; gSaveContext.magicState = gSaveContext.prevMagicState; gSaveContext.prevMagicState = MAGIC_STATE_IDLE; } @@ -4126,7 +4126,7 @@ void Interface_Update(PlayState* play) { osSyncPrintf("魔法スター─────ト!!!!!!!!!\n"); // "Magic Start!!!!!!!!!" osSyncPrintf("MAGIC_MAX=%d\n", gSaveContext.magicLevel); osSyncPrintf("MAGIC_NOW=%d\n", gSaveContext.magic); - osSyncPrintf("Z_MAGIC_NOW_NOW=%d\n", gSaveContext.magicCapacityTarget); + osSyncPrintf("Z_MAGIC_NOW_NOW=%d\n", gSaveContext.magicFillTarget); osSyncPrintf("Z_MAGIC_NOW_MAX=%d\n", gSaveContext.magicCapacity); osSyncPrintf(VT_RST); } diff --git a/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c b/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c index c7a503fe637..7738a78b34b 100644 --- a/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c +++ b/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c @@ -710,7 +710,8 @@ void BgDyYoseizo_Give_Reward(BgDyYoseizo* this, PlayState* play) { switch (actionIndex) { case FAIRY_UPGRADE_MAGIC: gSaveContext.isMagicAcquired = true; - gSaveContext.magicCapacityTarget = MAGIC_NORMAL_METER; + gSaveContext.magicFillTarget = MAGIC_NORMAL_METER; + // magicLevel is already 0 triggers magicCapacity to step to magicFillTarget Interface_ChangeAlpha(9); break; case FAIRY_UPGRADE_DOUBLE_MAGIC: @@ -718,9 +719,9 @@ void BgDyYoseizo_Give_Reward(BgDyYoseizo* this, PlayState* play) { gSaveContext.isMagicAcquired = true; } gSaveContext.isDoubleMagicAcquired = true; - gSaveContext.magicCapacityTarget = MAGIC_DOUBLE_METER; - gSaveContext.magicLevel = - 0; // Setting magicLevel to 0 triggers magicCapacity to step to magicCapacityTarget + gSaveContext.magicFillTarget = MAGIC_DOUBLE_METER; + // Setting magicLevel to 0 triggers magicCapacity to step to magicFillTarget + gSaveContext.magicLevel = 0; Interface_ChangeAlpha(9); break; case FAIRY_UPGRADE_HALF_DAMAGE: diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index 6903ccb43bd..10d57c021c8 100644 --- a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -1490,11 +1490,13 @@ void FileChoose_LoadGame(GameState* thisx) { gSaveContext.unk_13E7 = gSaveContext.unk_13E8 = gSaveContext.unk_13EA = gSaveContext.unk_13EC = gSaveContext.magicCapacity = 0; - gSaveContext.magicCapacityTarget = gSaveContext.magic; + // Set the fill target to be the magic from the previous save + gSaveContext.magicFillTarget = gSaveContext.magic; + // Set magicLevel and magic to 0 so the magic meter and magic grows from nothing to the state before the save gSaveContext.magicLevel = gSaveContext.magic = 0; osSyncPrintf(VT_FGCOL(GREEN)); - osSyncPrintf("Z_MAGIC_NOW_NOW=%d MAGIC_NOW=%d\n", ((void)0, gSaveContext.magicCapacityTarget), gSaveContext.magic); + osSyncPrintf("Z_MAGIC_NOW_NOW=%d MAGIC_NOW=%d\n", ((void)0, gSaveContext.magicFillTarget), gSaveContext.magic); osSyncPrintf(VT_RST); gSaveContext.naviTimer = 0; diff --git a/src/overlays/gamestates/ovl_select/z_select.c b/src/overlays/gamestates/ovl_select/z_select.c index 3bb407eb0a2..1eb37393326 100644 --- a/src/overlays/gamestates/ovl_select/z_select.c +++ b/src/overlays/gamestates/ovl_select/z_select.c @@ -20,7 +20,7 @@ void Select_LoadGame(SelectContext* this, s32 entranceIndex) { osSyncPrintf(VT_RST); if (gSaveContext.fileNum == 0xFF) { Sram_InitDebugSave(); - gSaveContext.magicCapacityTarget = gSaveContext.magic; + gSaveContext.magicFillTarget = gSaveContext.magic; gSaveContext.magicCapacity = 0; gSaveContext.magicLevel = gSaveContext.magic = 0; } diff --git a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c index 518b61427b7..795d0c0eac7 100644 --- a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c +++ b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c @@ -3407,12 +3407,12 @@ void KaleidoScope_Update(PlayState* play) { gSaveContext.prevMagicState = MAGIC_STATE_IDLE; osSyncPrintf(VT_FGCOL(YELLOW)); osSyncPrintf("MAGIC_NOW=%d ", gSaveContext.magic); - osSyncPrintf("Z_MAGIC_NOW_NOW=%d → ", gSaveContext.magicCapacityTarget); + osSyncPrintf("Z_MAGIC_NOW_NOW=%d → ", gSaveContext.magicFillTarget); gSaveContext.magicCapacity = 0; - gSaveContext.magicCapacityTarget = gSaveContext.magic; + gSaveContext.magicFillTarget = gSaveContext.magic; gSaveContext.magicLevel = gSaveContext.magic = 0; osSyncPrintf("MAGIC_NOW=%d ", gSaveContext.magic); - osSyncPrintf("Z_MAGIC_NOW_NOW=%d\n", gSaveContext.magicCapacityTarget); + osSyncPrintf("Z_MAGIC_NOW_NOW=%d\n", gSaveContext.magicFillTarget); osSyncPrintf(VT_RST); } else { play->state.running = false; From af5d5c97e0aec1b18aa1bc3432d2438a176c6a80 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sun, 22 May 2022 21:05:04 +1000 Subject: [PATCH 26/33] Comments --- include/z64save.h | 2 +- src/code/z_parameter.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/z64save.h b/include/z64save.h index 1b86af66f15..eaf2599ae29 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -14,7 +14,7 @@ typedef enum { /* 0x6 */ MAGIC_STATE_METER_FLASH_3, // Flashes border with no additional behaviour /* 0x7 */ MAGIC_STATE_CONSUME_LENS, // Magic slowly consumed by lens. /* 0x8 */ MAGIC_STATE_STEP_CAPACITY, // step magicCapacity to (gSaveContext.magicLevel * MAGIC_NORMAL_METER) - /* 0x9 */ MAGIC_STATE_FILL, // Add magic until full capacity is reached + /* 0x9 */ MAGIC_STATE_FILL, // Add magic until magicFillTarget is reached. /* 0xA */ MAGIC_STATE_ADD // Add requested magic } MagicState; diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index a8a54637efd..765eaf3e94e 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2431,6 +2431,8 @@ void Magic_Update(PlayState* play) { } } } else { + // Once the capacity has reached its target, + // follow up by filling magic to magicFillTarget gSaveContext.magicState = MAGIC_STATE_FILL; } break; From 34a7451763fc3b9ec313761e11bbde48eff11d2f Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sun, 22 May 2022 21:10:48 +1000 Subject: [PATCH 27/33] grammar --- src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c b/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c index 7738a78b34b..6f4ba727c4e 100644 --- a/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c +++ b/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c @@ -711,7 +711,7 @@ void BgDyYoseizo_Give_Reward(BgDyYoseizo* this, PlayState* play) { case FAIRY_UPGRADE_MAGIC: gSaveContext.isMagicAcquired = true; gSaveContext.magicFillTarget = MAGIC_NORMAL_METER; - // magicLevel is already 0 triggers magicCapacity to step to magicFillTarget + // magicLevel is already 0, which triggers magicCapacity to step to magicFillTarget Interface_ChangeAlpha(9); break; case FAIRY_UPGRADE_DOUBLE_MAGIC: From 72306ba71acf517e21cd1a665137e1b4aa9571db Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sun, 22 May 2022 21:13:55 +1000 Subject: [PATCH 28/33] More comment clarity --- src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c b/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c index 6f4ba727c4e..9bc2c3309f7 100644 --- a/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c +++ b/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c @@ -711,7 +711,7 @@ void BgDyYoseizo_Give_Reward(BgDyYoseizo* this, PlayState* play) { case FAIRY_UPGRADE_MAGIC: gSaveContext.isMagicAcquired = true; gSaveContext.magicFillTarget = MAGIC_NORMAL_METER; - // magicLevel is already 0, which triggers magicCapacity to step to magicFillTarget + // magicLevel is already 0, which triggers magicCapacity to grow Interface_ChangeAlpha(9); break; case FAIRY_UPGRADE_DOUBLE_MAGIC: @@ -720,7 +720,7 @@ void BgDyYoseizo_Give_Reward(BgDyYoseizo* this, PlayState* play) { } gSaveContext.isDoubleMagicAcquired = true; gSaveContext.magicFillTarget = MAGIC_DOUBLE_METER; - // Setting magicLevel to 0 triggers magicCapacity to step to magicFillTarget + // Setting magicLevel to 0 triggers magicCapacity to grow gSaveContext.magicLevel = 0; Interface_ChangeAlpha(9); break; From c54036486db270b5044e876ab4f12b50b144c23a Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sun, 22 May 2022 21:16:49 +1000 Subject: [PATCH 29/33] Another bad comment --- src/code/z_parameter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index 765eaf3e94e..9438b6af442 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2411,7 +2411,7 @@ void Magic_Update(PlayState* play) { s16 borderChangeR; s16 borderChangeG; s16 borderChangeB; - s16 temp; // magicFillTarget or magicBorderIndex + s16 temp; // target for magicCapacity or magicBorderIndex switch (gSaveContext.magicState) { case MAGIC_STATE_STEP_CAPACITY: From c7225d1db6c1e7a26b4eadc2e109c051af3118d1 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Mon, 23 May 2022 00:16:23 +1000 Subject: [PATCH 30/33] PR suggestions, improved comments --- include/z64save.h | 4 ++-- src/code/z_parameter.c | 16 +++++++--------- .../actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c | 2 +- .../gamestates/ovl_file_choose/z_file_choose.c | 5 +++-- src/overlays/gamestates/ovl_select/z_select.c | 3 +++ 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/include/z64save.h b/include/z64save.h index eaf2599ae29..3894993187d 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -13,7 +13,7 @@ typedef enum { /* 0x5 */ MAGIC_STATE_RESET, // Reset colors and return to idle /* 0x6 */ MAGIC_STATE_METER_FLASH_3, // Flashes border with no additional behaviour /* 0x7 */ MAGIC_STATE_CONSUME_LENS, // Magic slowly consumed by lens. - /* 0x8 */ MAGIC_STATE_STEP_CAPACITY, // step magicCapacity to (gSaveContext.magicLevel * MAGIC_NORMAL_METER) + /* 0x8 */ MAGIC_STATE_STEP_CAPACITY, // Step `magicCapacity` to full capacity /* 0x9 */ MAGIC_STATE_FILL, // Add magic until magicFillTarget is reached. /* 0xA */ MAGIC_STATE_ADD // Add requested magic } MagicState; @@ -185,7 +185,7 @@ typedef struct { /* 0x13F0 */ s16 magicState; // determines magic meter behavior on each frame /* 0x13F2 */ s16 prevMagicState; // used to resume the previous state after adding or filling magic /* 0x13F4 */ s16 magicCapacity; // maximum magic available - /* 0x13F6 */ s16 magicFillTarget; // target used to fill magic. Target can either be capacity for Magic_Fill and upgrades, or previous magic from a save and quit during a load from file-select + /* 0x13F6 */ s16 magicFillTarget; // target used to fill magic. Target can either be full capacity (Magic_Fill, magic upgrades), or the saved magic amount after loading a file /* 0x13F8 */ s16 magicTarget; // target for magic to step to when adding or consuming magic /* 0x13FA */ u16 eventInf[4]; // "event_inf" /* 0x1402 */ u16 mapIndex; // intended for maps/minimaps but commonly used as the dungeon index diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index 9438b6af442..394400ec60f 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2291,9 +2291,9 @@ void Magic_Reset(PlayState* play) { /** * Request to either increase or consume magic. - * amount is the positive-valued amount to either increase or decrease magic by - * type is how the magic is increased or consumed. - * Returns false if the request failed + * @param amount the positive-valued amount to either increase or decrease magic by + * @param type how the magic is increased or consumed. + * @return false if the request failed */ s32 Magic_RequestChange(PlayState* play, s16 amount, s16 type) { if (!gSaveContext.isMagicAcquired) { @@ -2353,12 +2353,10 @@ s32 Magic_RequestChange(PlayState* play, s16 amount, s16 type) { } else { return false; } + } else if (gSaveContext.magicState == MAGIC_STATE_CONSUME_LENS) { + return true; } else { - if (gSaveContext.magicState == MAGIC_STATE_CONSUME_LENS) { - return true; - } else { - return false; - } + return false; } case MAGIC_CONSUME_WAIT_PREVIEW: @@ -2411,7 +2409,7 @@ void Magic_Update(PlayState* play) { s16 borderChangeR; s16 borderChangeG; s16 borderChangeB; - s16 temp; // target for magicCapacity or magicBorderIndex + s16 temp; // target for magicCapacity, or magicBorderIndex switch (gSaveContext.magicState) { case MAGIC_STATE_STEP_CAPACITY: diff --git a/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c b/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c index 9bc2c3309f7..9d83094db26 100644 --- a/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c +++ b/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c @@ -711,7 +711,7 @@ void BgDyYoseizo_Give_Reward(BgDyYoseizo* this, PlayState* play) { case FAIRY_UPGRADE_MAGIC: gSaveContext.isMagicAcquired = true; gSaveContext.magicFillTarget = MAGIC_NORMAL_METER; - // magicLevel is already 0, which triggers magicCapacity to grow + // magicLevel is already 0, setting isMagicAcquired to true triggers magicCapacity to grow Interface_ChangeAlpha(9); break; case FAIRY_UPGRADE_DOUBLE_MAGIC: diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index 10d57c021c8..fe531f7ecad 100644 --- a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -1490,9 +1490,10 @@ void FileChoose_LoadGame(GameState* thisx) { gSaveContext.unk_13E7 = gSaveContext.unk_13E8 = gSaveContext.unk_13EA = gSaveContext.unk_13EC = gSaveContext.magicCapacity = 0; - // Set the fill target to be the magic from the previous save + // Set the fill target to be the saved magic amount gSaveContext.magicFillTarget = gSaveContext.magic; - // Set magicLevel and magic to 0 so the magic meter and magic grows from nothing to the state before the save + // Set `magicLevel` and `magic` to 0 so `magicCapacity` then `magic` grows from nothing to respectively the full + // capacity and `magicFillTarget` gSaveContext.magicLevel = gSaveContext.magic = 0; osSyncPrintf(VT_FGCOL(GREEN)); diff --git a/src/overlays/gamestates/ovl_select/z_select.c b/src/overlays/gamestates/ovl_select/z_select.c index 1eb37393326..3d4ed22c452 100644 --- a/src/overlays/gamestates/ovl_select/z_select.c +++ b/src/overlays/gamestates/ovl_select/z_select.c @@ -20,7 +20,10 @@ void Select_LoadGame(SelectContext* this, s32 entranceIndex) { osSyncPrintf(VT_RST); if (gSaveContext.fileNum == 0xFF) { Sram_InitDebugSave(); + // Set the fill target to be the saved magic amount gSaveContext.magicFillTarget = gSaveContext.magic; + // Set `magicLevel` and `magic` to 0 so `magicCapacity` then `magic` grows from nothing + // to respectively the full capacity and `magicFillTarget` gSaveContext.magicCapacity = 0; gSaveContext.magicLevel = gSaveContext.magic = 0; } From a7a0d007a5efc7f674acc625ad7e7c6c824701e8 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Mon, 23 May 2022 12:30:22 +1000 Subject: [PATCH 31/33] One more comment --- include/z64save.h | 2 +- src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/z64save.h b/include/z64save.h index 3894993187d..16a5a8e9d0b 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -185,7 +185,7 @@ typedef struct { /* 0x13F0 */ s16 magicState; // determines magic meter behavior on each frame /* 0x13F2 */ s16 prevMagicState; // used to resume the previous state after adding or filling magic /* 0x13F4 */ s16 magicCapacity; // maximum magic available - /* 0x13F6 */ s16 magicFillTarget; // target used to fill magic. Target can either be full capacity (Magic_Fill, magic upgrades), or the saved magic amount after loading a file + /* 0x13F6 */ s16 magicFillTarget; // target used to fill magic. Target can either be full capacity (Magic_Fill, magic upgrades), or the saved magic amount (loading a file, game over) /* 0x13F8 */ s16 magicTarget; // target for magic to step to when adding or consuming magic /* 0x13FA */ u16 eventInf[4]; // "event_inf" /* 0x1402 */ u16 mapIndex; // intended for maps/minimaps but commonly used as the dungeon index diff --git a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c index 795d0c0eac7..f31ca63c5a0 100644 --- a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c +++ b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c @@ -3409,7 +3409,10 @@ void KaleidoScope_Update(PlayState* play) { osSyncPrintf("MAGIC_NOW=%d ", gSaveContext.magic); osSyncPrintf("Z_MAGIC_NOW_NOW=%d → ", gSaveContext.magicFillTarget); gSaveContext.magicCapacity = 0; + // Set the fill target to be the magic amount before game over gSaveContext.magicFillTarget = gSaveContext.magic; + // Set `magicLevel` and `magic` to 0 so `magicCapacity` then `magic` grows from nothing + // to respectively the full capacity and `magicFillTarget` gSaveContext.magicLevel = gSaveContext.magic = 0; osSyncPrintf("MAGIC_NOW=%d ", gSaveContext.magic); osSyncPrintf("Z_MAGIC_NOW_NOW=%d\n", gSaveContext.magicFillTarget); From 2bd92ab3accd56530065fb885c33ca557c245f2d Mon Sep 17 00:00:00 2001 From: engineer124 Date: Mon, 23 May 2022 12:32:00 +1000 Subject: [PATCH 32/33] one more thing --- src/code/z_parameter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index 394400ec60f..8f846886ef0 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2156,7 +2156,7 @@ void Interface_LoadActionLabelB(PlayState* play, u16 action) { } /** - * Returns false if player is out of health + * @return false if player is out of health */ s32 Health_ChangeBy(PlayState* play, s16 amount) { u16 heartCount; From b34a259f2e8109f3c5d5f19e45f2d7dab3aee416 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Mon, 23 May 2022 17:05:34 +1000 Subject: [PATCH 33/33] bar -> meter --- src/code/z_parameter.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index 8f846886ef0..4b4a6a4f85c 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2414,7 +2414,7 @@ void Magic_Update(PlayState* play) { switch (gSaveContext.magicState) { case MAGIC_STATE_STEP_CAPACITY: // Step magicCapacity to the capacity determined by magicLevel - // This changes the width of the magic bar drawn + // This changes the width of the magic meter drawn temp = gSaveContext.magicLevel * MAGIC_NORMAL_METER; if (gSaveContext.magicCapacity != temp) { if (gSaveContext.magicCapacity < temp) { @@ -2633,7 +2633,7 @@ void Magic_DrawMeter(PlayState* play) { gDPSetEnvColor(OVERLAY_DISP++, 0, 0, 0, 255); if (gSaveContext.magicState == MAGIC_STATE_METER_FLASH_2) { - // Yellow part of the bar indicating the amount of magic to be subtracted + // Yellow part of the meter indicating the amount of magic to be subtracted gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 250, 250, 0, interfaceCtx->magicAlpha); gDPLoadMultiBlock_4b(OVERLAY_DISP++, gMagicMeterFillTex, 0, G_TX_RENDERTILE, G_IM_FMT_I, 16, 16, 0, @@ -2644,7 +2644,7 @@ void Magic_DrawMeter(PlayState* play) { (R_MAGIC_FILL_X + gSaveContext.magic) << 2, (magicMeterY + 10) << 2, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); - // Fill the rest of the bar with the normal magic color + // Fill the rest of the meter with the normal magic color gDPPipeSync(OVERLAY_DISP++); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, R_MAGIC_FILL_COLOR(0), R_MAGIC_FILL_COLOR(1), R_MAGIC_FILL_COLOR(2), interfaceCtx->magicAlpha); @@ -2653,7 +2653,7 @@ void Magic_DrawMeter(PlayState* play) { (R_MAGIC_FILL_X + gSaveContext.magicTarget) << 2, (magicMeterY + 10) << 2, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); } else { - // Fill the whole bar with the normal magic color + // Fill the whole meter with the normal magic color gDPSetPrimColor(OVERLAY_DISP++, 0, 0, R_MAGIC_FILL_COLOR(0), R_MAGIC_FILL_COLOR(1), R_MAGIC_FILL_COLOR(2), interfaceCtx->magicAlpha);