From a939ddc07bff553859a90af188cb49aa0eed5915 Mon Sep 17 00:00:00 2001 From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> Date: Fri, 3 Mar 2023 16:46:46 +1000 Subject: [PATCH] bring back the ability to lose your cap (#229) * bring back the ability to lose your cap * run autogen and add "cap" to the mario states guide * fix some indentation --- autogen/lua_definitions/structs.lua | 1 + docs/lua/guides/mario-state.md | 1 + docs/lua/structs.md | 1 + include/types.h | 1 + src/game/behaviors/cap.inc.c | 15 +++------------ src/game/behaviors/klepto.inc.c | 11 +++++------ src/game/behaviors/mr_blizzard.inc.c | 4 ++-- src/game/behaviors/ukiki.inc.c | 13 ++++++------- src/game/interaction.c | 4 ++-- src/game/mario.c | 10 ++++------ src/game/save_file.c | 8 ++++---- src/pc/lua/smlua_cobject_autogen.c | 1 + src/pc/network/network.c | 1 + 13 files changed, 32 insertions(+), 39 deletions(-) diff --git a/autogen/lua_definitions/structs.lua b/autogen/lua_definitions/structs.lua index 543af7ff..21d8f637 100644 --- a/autogen/lua_definitions/structs.lua +++ b/autogen/lua_definitions/structs.lua @@ -708,6 +708,7 @@ --- @field public animation MarioAnimation --- @field public area Area --- @field public bubbleObj Object +--- @field public cap integer --- @field public capTimer integer --- @field public ceil Surface --- @field public ceilHeight number diff --git a/docs/lua/guides/mario-state.md b/docs/lua/guides/mario-state.md index 4cd10a91..3caae6de 100644 --- a/docs/lua/guides/mario-state.md +++ b/docs/lua/guides/mario-state.md @@ -86,6 +86,7 @@ The `MarioState` structure contains 76 different variables, this guide will try |`knockbackTimer`|`integer`|Used for invincibilty when flying through the air after a bonk or being hit by another player. |`specialTripleJump`|`integer`|Can be used as a bool, sets whether or not to use the special triple jump unlocked after talking to Yoshi. |`wallNormal`|`Vec3f`|The angle of the current wall on the x, y, and z axis. +|`cap`|`integer`|Where Mario's cap is meant to be. Can be on Mario's head, the snowman's head in Snowman's Land, held by Klepto, or on Ukiki's head. ## Section 3: When should I use `gMarioStates`? Most of the time you won't be using `gMarioStates[0]` to access your Mario, but rather use a hook. A lot of hooks pass `m` through the function. What does this mean? Well, here is a example with comments to explain it as good as possible: diff --git a/docs/lua/structs.md b/docs/lua/structs.md index f64ac1c1..fc4333a6 100644 --- a/docs/lua/structs.md +++ b/docs/lua/structs.md @@ -1034,6 +1034,7 @@ | animation | [MarioAnimation](structs.md#MarioAnimation) | | | area | [Area](structs.md#Area) | | | bubbleObj | [Object](structs.md#Object) | | +| cap | `integer` | | | capTimer | `integer` | | | ceil | [Surface](structs.md#Surface) | | | ceilHeight | `number` | | diff --git a/include/types.h b/include/types.h index 003c11e5..defad47e 100644 --- a/include/types.h +++ b/include/types.h @@ -397,6 +397,7 @@ struct MarioState /*????*/ u8 specialTripleJump; /*????*/ Vec3f wallNormal; /*????*/ u8 visibleToEnemies; + /*????*/ u32 cap; }; struct TextureInfo diff --git a/src/game/behaviors/cap.inc.c b/src/game/behaviors/cap.inc.c index 066ff1fb..44e1ad50 100644 --- a/src/game/behaviors/cap.inc.c +++ b/src/game/behaviors/cap.inc.c @@ -193,28 +193,22 @@ void bhv_normal_cap_init(void) { o->oFriction = 0.89f; o->oBuoyancy = 0.9f; o->oOpacity = 0xFF; - - save_file_set_cap_pos(o->oPosX, o->oPosY, o->oPosZ); } void normal_cap_set_save_flags(void) { save_file_clear_flags(SAVE_FLAG_CAP_ON_GROUND); switch (gCurrCourseNum) { - case COURSE_SSL: - save_file_set_flags(SAVE_FLAG_CAP_ON_KLEPTO); - break; - case COURSE_SL: - save_file_set_flags(SAVE_FLAG_CAP_ON_MR_BLIZZARD); + gMarioStates[0].cap = SAVE_FLAG_CAP_ON_MR_BLIZZARD; break; case COURSE_TTM: - save_file_set_flags(SAVE_FLAG_CAP_ON_UKIKI); + gMarioStates[0].cap = SAVE_FLAG_CAP_ON_UKIKI; break; default: - save_file_set_flags(SAVE_FLAG_CAP_ON_KLEPTO); + gMarioStates[0].cap = SAVE_FLAG_CAP_ON_KLEPTO; break; } } @@ -251,9 +245,6 @@ void bhv_normal_cap_loop(void) { break; } - if ((s32) o->oForwardVel != 0) - save_file_set_cap_pos(o->oPosX, o->oPosY, o->oPosZ); - if (o->activeFlags == ACTIVE_FLAG_DEACTIVATED) normal_cap_set_save_flags(); diff --git a/src/game/behaviors/klepto.inc.c b/src/game/behaviors/klepto.inc.c index b4a3730d..e66baa2f 100644 --- a/src/game/behaviors/klepto.inc.c +++ b/src/game/behaviors/klepto.inc.c @@ -97,12 +97,11 @@ void bhv_klepto_init(void) { o->oKleptoStartPosY = o->oPosY; o->oKleptoStartPosZ = o->oPosZ; - // skip hat save flags - //if (save_file_get_flags() & SAVE_FLAG_CAP_ON_KLEPTO) { - // o->oAnimState = KLEPTO_ANIM_STATE_HOLDING_CAP; - //} else { + if (gMarioStates[0].cap & SAVE_FLAG_CAP_ON_KLEPTO) { + o->oAnimState = KLEPTO_ANIM_STATE_HOLDING_CAP; + } else { o->oAction = KLEPTO_ACT_WAIT_FOR_MARIO; - //} + } } struct SyncObject* so = sync_object_init(o, 4000.0f); @@ -419,7 +418,7 @@ void bhv_klepto_update(void) { u8 modelIndex = (np->overrideModelIndex < CT_MAX) ? np->overrideModelIndex : 0; u32 capModel = gCharacters[modelIndex].capModelId; - save_file_clear_flags(SAVE_FLAG_CAP_ON_KLEPTO); + gMarioStates[0].cap &= ~SAVE_FLAG_CAP_ON_KLEPTO; struct Object* cap = spawn_object(o, capModel, bhvNormalCap); if (cap != NULL) { diff --git a/src/game/behaviors/mr_blizzard.inc.c b/src/game/behaviors/mr_blizzard.inc.c index 63f61377..e5b8c210 100644 --- a/src/game/behaviors/mr_blizzard.inc.c +++ b/src/game/behaviors/mr_blizzard.inc.c @@ -60,7 +60,7 @@ void bhv_mr_blizzard_init(void) { } else { if (o->oBehParams2ndByte != MR_BLIZZARD_STYPE_NO_CAP) { // Cap wearing Mr. Blizzard from SL. - if (save_file_get_flags() & SAVE_FLAG_CAP_ON_MR_BLIZZARD) { + if (gMarioStates[0].cap & SAVE_FLAG_CAP_ON_MR_BLIZZARD) { o->oAnimState = 1; } } @@ -244,7 +244,7 @@ static void mr_blizzard_act_death(void) { // If Mr. Blizzard is wearing Mario's cap, clear // the save flag and spawn Mario's cap. if (o->oAnimState) { - save_file_clear_flags(SAVE_FLAG_CAP_ON_MR_BLIZZARD); + gMarioStates[0].cap &= ~SAVE_FLAG_CAP_ON_MR_BLIZZARD; cap = spawn_object_relative(0, 5, 105, 0, o, MODEL_MARIOS_CAP, bhvNormalCap); if (cap != NULL) { diff --git a/src/game/behaviors/ukiki.inc.c b/src/game/behaviors/ukiki.inc.c index 1762672f..0e0e987b 100644 --- a/src/game/behaviors/ukiki.inc.c +++ b/src/game/behaviors/ukiki.inc.c @@ -644,13 +644,12 @@ void cap_ukiki_held_loop(void) { * Initializatation for ukiki, determines if it has Mario's cap. */ void bhv_ukiki_init(void) { - // skip hat save flags - //if (o->oBehParams2ndByte == UKIKI_CAP) { - // if (save_file_get_flags() & SAVE_FLAG_CAP_ON_UKIKI) { - // o->oUkikiTextState = UKIKI_TEXT_HAS_CAP; - // o->oUkikiHasCap |= UKIKI_CAP_ON; - // } - //} + if (o->oBehParams2ndByte == UKIKI_CAP) { + if (gMarioStates[0].cap & SAVE_FLAG_CAP_ON_UKIKI) { + o->oUkikiTextState = UKIKI_TEXT_HAS_CAP; + o->oUkikiHasCap |= UKIKI_CAP_ON; + } + } sync_object_init(o, 4000.0f); sync_object_init_field(o, &o->oUkikiTauntCounter); diff --git a/src/game/interaction.c b/src/game/interaction.c index a65b6ece..cf6d375c 100644 --- a/src/game/interaction.c +++ b/src/game/interaction.c @@ -394,7 +394,7 @@ void mario_blow_off_cap(struct MarioState *m, f32 capSpeed) { struct Object *capObject; if (does_mario_have_normal_cap_on_head(m)) { - save_file_set_cap_pos(m->pos[0], m->pos[1], m->pos[2]); + m->cap = SAVE_FLAG_CAP_ON_MR_BLIZZARD; m->flags &= ~(MARIO_NORMAL_CAP | MARIO_CAP_ON_HEAD); @@ -426,7 +426,7 @@ u32 mario_lose_cap_to_enemy(struct MarioState* m, u32 arg) { u32 wasWearingCap = FALSE; if (does_mario_have_normal_cap_on_head(m)) { - save_file_set_flags(arg == 1 ? SAVE_FLAG_CAP_ON_KLEPTO : SAVE_FLAG_CAP_ON_UKIKI); + gMarioStates[0].cap = (arg == 1 ? SAVE_FLAG_CAP_ON_KLEPTO : SAVE_FLAG_CAP_ON_UKIKI); m->flags &= ~(MARIO_NORMAL_CAP | MARIO_CAP_ON_HEAD); wasWearingCap = TRUE; } diff --git a/src/game/mario.c b/src/game/mario.c index 33915df7..fbfb1247 100644 --- a/src/game/mario.c +++ b/src/game/mario.c @@ -2149,13 +2149,12 @@ void init_single_mario(struct MarioState* m) { m->invincTimer = 0; m->visibleToEnemies = TRUE; - - // always put the cap on head - /*if (save_file_get_flags() & (SAVE_FLAG_CAP_ON_GROUND | SAVE_FLAG_CAP_ON_KLEPTO | SAVE_FLAG_CAP_ON_UKIKI | SAVE_FLAG_CAP_ON_MR_BLIZZARD)) { + + if (m->cap & (SAVE_FLAG_CAP_ON_GROUND | SAVE_FLAG_CAP_ON_KLEPTO | SAVE_FLAG_CAP_ON_UKIKI | SAVE_FLAG_CAP_ON_MR_BLIZZARD)) { m->flags = 0; - } else {*/ + } else { m->flags = (MARIO_CAP_ON_HEAD | MARIO_NORMAL_CAP); - //} + } m->forwardVel = 0.0f; m->squishTimer = 0; @@ -2198,7 +2197,6 @@ void init_single_mario(struct MarioState* m) { m->action = (m->pos[1] <= (m->waterLevel - 100)) ? ACT_WATER_IDLE : ACT_IDLE; - mario_reset_bodystate(m); update_mario_info_for_cam(m); m->marioBodyState->punchState = 0; diff --git a/src/game/save_file.c b/src/game/save_file.c index a4435b96..8e2b9bec 100644 --- a/src/game/save_file.c +++ b/src/game/save_file.c @@ -706,16 +706,16 @@ u16 save_file_get_sound_mode(void) { } void save_file_move_cap_to_default_location(void) { - if (save_file_get_flags() & SAVE_FLAG_CAP_ON_GROUND) { + if (save_file_get_flags() & SAVE_FLAG_CAP_ON_GROUND || gMarioStates[0].cap == SAVE_FLAG_CAP_ON_GROUND) { switch (gSaveBuffer.files[gCurrSaveFileNum - 1][gSaveFileUsingBackupSlot].capLevel) { case LEVEL_SSL: - save_file_set_flags(SAVE_FLAG_CAP_ON_KLEPTO); + gMarioStates[0].cap = SAVE_FLAG_CAP_ON_KLEPTO; break; case LEVEL_SL: - save_file_set_flags(SAVE_FLAG_CAP_ON_MR_BLIZZARD); + gMarioStates[0].cap = SAVE_FLAG_CAP_ON_MR_BLIZZARD; break; case LEVEL_TTM: - save_file_set_flags(SAVE_FLAG_CAP_ON_UKIKI); + gMarioStates[0].cap = SAVE_FLAG_CAP_ON_UKIKI; break; } save_file_clear_flags(SAVE_FLAG_CAP_ON_GROUND); diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c index ac43d332..d372ebb2 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -821,6 +821,7 @@ static struct LuaObjectField sMarioStateFields[LUA_MARIO_STATE_FIELD_COUNT] = { { "animation", LVT_COBJECT_P, offsetof(struct MarioState, animation), false, LOT_MARIOANIMATION }, { "area", LVT_COBJECT_P, offsetof(struct MarioState, area), false, LOT_AREA }, { "bubbleObj", LVT_COBJECT_P, offsetof(struct MarioState, bubbleObj), false, LOT_OBJECT }, + { "cap", LVT_U32, offsetof(struct MarioState, cap), false, LOT_NONE }, { "capTimer", LVT_U16, offsetof(struct MarioState, capTimer), false, LOT_NONE }, { "ceil", LVT_COBJECT_P, offsetof(struct MarioState, ceil), false, LOT_SURFACE }, { "ceilHeight", LVT_F32, offsetof(struct MarioState, ceilHeight), false, LOT_NONE }, diff --git a/src/pc/network/network.c b/src/pc/network/network.c index 1705b476..026b1587 100644 --- a/src/pc/network/network.c +++ b/src/pc/network/network.c @@ -515,6 +515,7 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup) { network_player_init(); camera_set_use_course_specific_settings(true); free_vtx_scroll_targets(); + gMarioStates[0].cap = 0; struct Controller* cnt = gMarioStates[0].controller; cnt->rawStickX = 0;