Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Magic #1199

Merged
merged 39 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7782db3
Magic docs WIP
engineer124 Apr 19, 2022
b5e6ac8
More docs, first round finished
engineer124 Apr 19, 2022
bf2858b
Better docs
engineer124 Apr 19, 2022
bdda1e5
More renaming
engineer124 Apr 19, 2022
6bd46b2
Simpler name
engineer124 Apr 19, 2022
354c594
Another small adjustment
engineer124 Apr 19, 2022
e359fce
rm if(1)
engineer124 Apr 19, 2022
80de240
Better names again after in-game testing
engineer124 Apr 21, 2022
522ee08
Change comments
engineer124 Apr 21, 2022
764a102
change comment
engineer124 Apr 21, 2022
9125e97
Merge branch 'master' into magic
engineer124 Apr 23, 2022
e2eada8
Big rename based on all the suggestions
engineer124 Apr 24, 2022
f05f8c2
Merge branch 'master' into magic
engineer124 Apr 24, 2022
26adeef
Small touch-up
engineer124 Apr 24, 2022
bd3174d
Merge branch 'master' into magic
engineer124 May 7, 2022
0146061
More PR Suggestions
engineer124 May 7, 2022
aa10f47
RESTORE_IDLE -> RESET
engineer124 May 7, 2022
fe133ce
More docs
engineer124 May 7, 2022
9779f9e
Capitalization
engineer124 May 7, 2022
727a5bd
PR suggestions
engineer124 May 7, 2022
5919acc
Make declaration consistent
engineer124 May 7, 2022
d647ba1
Health_ChangeBy (amount)
engineer124 May 7, 2022
d992fb5
Merge branch 'master' into magic
engineer124 May 18, 2022
2ce2812
PR Suggestions
engineer124 May 18, 2022
e0776f5
Missed one
engineer124 May 18, 2022
a920403
Merge branch 'master' into magic
engineer124 May 21, 2022
743bb67
More PR Suggestions
engineer124 May 21, 2022
ad2fbd9
Change comment
engineer124 May 21, 2022
ca12b3d
Add another clarity comment
engineer124 May 21, 2022
6a9468a
Merge branch 'master' into magic
engineer124 May 22, 2022
b9e8936
Discord discussions on `magicFillTarget`
engineer124 May 22, 2022
af5d5c9
Comments
engineer124 May 22, 2022
34a7451
grammar
engineer124 May 22, 2022
72306ba
More comment clarity
engineer124 May 22, 2022
c540364
Another bad comment
engineer124 May 22, 2022
c7225d1
PR suggestions, improved comments
engineer124 May 22, 2022
a7a0d00
One more comment
engineer124 May 23, 2022
2bd92ab
one more thing
engineer124 May 23, 2022
b34a259
bar -> meter
engineer124 May 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions assets/xml/textures/parameter_static.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
<Texture Name="gAmmoDigit8Tex" OutName="ammo_digit_8" Format="ia8" Width="8" Height="8" Offset="0x37C0"/>
<Texture Name="gAmmoDigit9Tex" OutName="ammo_digit_9" Format="ia8" Width="8" Height="8" Offset="0x3800"/>
<Texture Name="gUnusedAmmoDigitHalfTex" OutName="unused_ammo_digit_half" Format="ia8" Width="16" Height="8" Offset="0x3840"/>
<Texture Name="gMagicBarEndTex" OutName="magic_bar_end" Format="ia8" Width="8" Height="16" Offset="0x38C0"/>
<Texture Name="gMagicBarMidTex" OutName="magic_bar_mid" Format="ia8" Width="24" Height="16" Offset="0x3940"/>
<Texture Name="gMagicBarFillTex" OutName="magic_bar_fill" Format="ia8" Width="8" Height="8" Offset="0x3AC0"/>
<Texture Name="gMagicMeterEndTex" OutName="magic_meter_end" Format="ia8" Width="8" Height="16" Offset="0x38C0"/>
<Texture Name="gMagicMeterMidTex" OutName="magic_meter_mid" Format="ia8" Width="24" Height="16" Offset="0x3940"/>
<Texture Name="gMagicMeterFillTex" OutName="magic_meter_fill" Format="ia8" Width="8" Height="8" Offset="0x3AC0"/>
</File>
</Root>
6 changes: 3 additions & 3 deletions include/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1026,12 +1026,12 @@ s32 Inventory_ConsumeFairy(PlayState* play);
void Interface_SetDoAction(PlayState* play, u16 action);
void Interface_SetNaviCall(PlayState* play, u16 naviCallState);
void Interface_LoadActionLabelB(PlayState* play, u16 action);
s32 Health_ChangeBy(PlayState* play, s16 healthChange);
s32 Health_ChangeBy(PlayState* play, s16 amount);
void Rupees_ChangeBy(s16 rupeeChange);
void Inventory_ChangeAmmo(s16 item, s16 ammoChange);
void Magic_Fill(PlayState* play);
void func_800876C8(PlayState* play);
s32 func_80087708(PlayState* play, s16 arg1, s16 arg2);
void Magic_Reset(PlayState* play);
s32 Magic_RequestChange(PlayState* play, s16 amount, s16 type);
void func_80088AA0(s16 arg0);
void func_80088AF0(PlayState* play);
void func_80088B34(s16 arg0);
Expand Down
6 changes: 3 additions & 3 deletions include/regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_BAR_SMALL_Y XREG(48)
#define R_MAGIC_BAR_X XREG(49)
#define R_MAGIC_BAR_LARGE_Y XREG(50)
#define R_MAGIC_METER_Y_HIGHER XREG(48)
#define R_MAGIC_METER_X XREG(49)
#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)
Expand Down
2 changes: 1 addition & 1 deletion include/z64.h
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ typedef struct {
/* 0x022A */ s16 beatingHeartOscillator;
/* 0x022C */ s16 beatingHeartOscillatorDirection;
/* 0x022E */ s16 unk_22E;
/* 0x0230 */ s16 unk_230;
/* 0x0230 */ s16 lensMagicConsumptionTimer; // 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;
Expand Down
44 changes: 35 additions & 9 deletions include/z64save.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@
#include "ultra64.h"
#include "z64math.h"

typedef enum {
/* 0x0 */ MAGIC_STATE_IDLE, // Regular gameplay
/* 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
/* 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 full capacity
/* 0x9 */ MAGIC_STATE_FILL, // Add magic until magicFillTarget 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_NORMAL_METER 0x30
#define MAGIC_DOUBLE_METER (2 * MAGIC_NORMAL_METER)

typedef struct {
/* 0x00 */ u8 buttonItems[4];
/* 0x04 */ u8 cButtonSlots[3];
Expand Down Expand Up @@ -87,14 +113,14 @@ 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; // current magic available for use
/* 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;
Comment on lines +121 to +123
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realise this was used extensively in the repo, but now I'm wondering if we want to name variables like this interrogatively... does the is actually do anything here, that the plain past participle doesn't?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this specific instance, doubleMagicAcquired alone can be inferred to be a boolean-like value (it still uses the 0/1 in calculating magicCapacity so it's not a true bool), but as you mentioned, is is just a common and fast way to identify that something is boolean without thinking about it, at least that was my understanding of the convention

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also as a side note, not related to this comment but something I wanted to note:
doubleDefense -> isDoubleDefenseAcquired (or without the is) would be consistent with isDoubleMagicAcquired but I refrained from changing it for now

Copy link
Contributor

@EllipticEllipsis EllipticEllipsis May 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we were going by the game it should be "half damage" (or possibly "enhanced defence") anyway:

"I'm going to enhance your \n"
COLOR(LIGHTBLUE) "defensive power" COLOR(DEFAULT) "."
[...]
"Your " COLOR(LIGHTBLUE) "defensive power" COLOR(DEFAULT) " is enhanced!"
[...]
"Your defensive power has been \n"
"enhanced! Damage inflicted by \n"
"enemies will be " COLOR(RED) "reduced by half" COLOR(DEFAULT) "."

(I suppose we could say the same thing for magic, actually, it never explicitly says it doubles, although that's obvious from the bar size)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo this is a case where the common colloquial name makes more sense. no one says half damage or enhanced defense

Copy link
Contributor

@EllipticEllipsis EllipticEllipsis May 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look into this, since I was curious. I looked at 4 guidebooks (3 English, 1 the official one, 1 Japanese) and the first page of Google results for walkthroughs, including 4 GameFAQs guides. A large majority say one or more of

  • half damage
  • enhanced defense
  • doubled health

and only 2 (of about 20) say double/doubled defense. I was pretty surprised by this myself, since the tiny speedrunning corner of the world does seem to call always call it "double defense", probably because of the alliteration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to add a different perspective, I come from the randomizer community and never heard of any of those terms, it's only ever been "double defense" for me

Copy link
Collaborator

@Dragorn421 Dragorn421 May 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other related names in decomp: FAIRY_UPGRADE_HALF_DAMAGE (hi elliptic), gGreatFairyDoubleDefenceCs (hi louis)

I would be okay with normalizing all of that to "half damage", with a comment on the save context struct member like // double defense

"double defense" probably is so popular because it rolls so well off the tongue

/* 0x003D */ u8 doubleDefense;
/* 0x003E */ u8 bgsFlag;
/* 0x003F */ u8 ocarinaGameRoundNum;
Expand Down Expand Up @@ -156,11 +182,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; // 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 (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
/* 0x1404 */ u16 minigameState;
Expand Down
2 changes: 1 addition & 1 deletion src/code/z_actor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,7 @@ void func_80030488(PlayState* play) {
void Actor_DisableLens(PlayState* play) {
if (play->actorCtx.lensActive) {
play->actorCtx.lensActive = false;
func_800876C8(play);
Magic_Reset(play);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/code/z_construct.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void func_801109B0(PlayState* play) {
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->lensMagicConsumptionTimer = 16;
interfaceCtx->unk_1F4 = 0.0f;
interfaceCtx->unk_228 = XREG(95);
interfaceCtx->minimapAlpha = 0;
Expand Down Expand Up @@ -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_Y_HIGHER = 34;
R_MAGIC_METER_X = 18;
R_MAGIC_METER_Y_LOWER = 42;
R_MAGIC_FILL_X = 26;
XREG(52) = 0;
XREG(53) = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/code/z_elf_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/code/z_kaleido_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ void KaleidoSetup_Update(PlayState* play) {
if (pauseCtx->state == 0 && pauseCtx->debugState == 0 && play->gameOverCtx.state == GAMEOVER_INACTIVE &&
play->transitionTrigger == TRANS_TRIGGER_OFF && play->transitionMode == TRANS_MODE_OFF &&
gSaveContext.cutsceneIndex < 0xFFF0 && gSaveContext.nextCutsceneIndex < 0xFFF0 && !Play_InCsMode(play) &&
play->shootingGalleryStatus <= 1 && gSaveContext.unk_13F0 != 8 && gSaveContext.unk_13F0 != 9 &&
play->shootingGalleryStatus <= 1 && gSaveContext.magicState != MAGIC_STATE_STEP_CAPACITY &&
gSaveContext.magicState != MAGIC_STATE_FILL &&
(play->sceneNum != SCENE_BOWLING || !Flags_GetSwitch(play, 0x38))) {

if (CHECK_BTN_ALL(input->cur.button, BTN_L) && CHECK_BTN_ALL(input->press.button, BTN_CUP)) {
Expand Down
Loading