Switch age fix (#2676)

* specific scenarios for switch age button, non rando

* Working fix for vanilla swordless change age

* Fix now works for randomiser

* Fixed room load on change age transition

* Removed potentially unnecessary function call

Need to investigate this more, maybe wait for more room documentation.

* Suggested Edits

Moves setting cvar back into mods.cpp and makes clear the condition expected for the no sword flag
This commit is contained in:
inspectredc 2023-04-07 22:05:12 +01:00 committed by GitHub
parent 0f6147f41d
commit 1fa31410c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 12 deletions

View File

@ -163,23 +163,29 @@ void RegisterSwitchAge() {
static bool warped = false;
static Vec3f playerPos;
static int16_t playerYaw;
static RoomContext* roomCtx;
static s32 roomNum;
if (!gPlayState) return;
if (CVarGetInteger("gSwitchAge", 0) != 0) {
CVarSetInteger("gSwitchAge", 0);
if (CVarGetInteger("gSwitchAge", 0) && !warped) {
playerPos = GET_PLAYER(gPlayState)->actor.world.pos;
playerYaw = GET_PLAYER(gPlayState)->actor.shape.rot.y;
roomCtx = &gPlayState->roomCtx;
roomNum = roomCtx->curRoom.num;
ReloadSceneTogglingLinkAge();
warped = true;
}
if (warped && gPlayState->sceneLoadFlag != 0x0014 && gSaveContext.nextTransitionType == 255) {
if (warped && gPlayState->sceneLoadFlag != 0x0014 &&
gSaveContext.nextTransitionType == 255) {
GET_PLAYER(gPlayState)->actor.shape.rot.y = playerYaw;
GET_PLAYER(gPlayState)->actor.world.pos = playerPos;
func_8009728C(gPlayState, roomCtx, roomNum); //load original room
//func_800973FC(gPlayState, &gPlayState->roomCtx); // commit to room load?
func_80097534(gPlayState, roomCtx); // load map for new room (unloading the previous room)
warped = false;
CVarSetInteger("gSwitchAge", 0);
}
});
}

View File

@ -1411,17 +1411,18 @@ void Inventory_SwapAgeEquipment(void) {
u16 temp;
if (LINK_AGE_IN_YEARS == YEARS_CHILD) {
// When becoming adult, remove swordless flag since we'll get master sword
// Only in rando to keep swordless link bugs in vanilla
if (gSaveContext.n64ddFlag) {
gSaveContext.infTable[29] &= ~1;
}
for (i = 0; i < ARRAY_COUNT(gSaveContext.equips.buttonItems); i++) {
if (i != 0) {
gSaveContext.childEquips.buttonItems[i] = gSaveContext.equips.buttonItems[i];
} else {
gSaveContext.childEquips.buttonItems[i] = ITEM_SWORD_KOKIRI;
if (CVarGetInteger("gSwitchAge", 0) &&
(gSaveContext.infTable[29] & 1)) {
gSaveContext.childEquips.buttonItems[i] = ITEM_NONE;
} else {
gSaveContext.childEquips.buttonItems[i] = ITEM_SWORD_KOKIRI;
}
}
if (i != 0) {
@ -1429,6 +1430,12 @@ void Inventory_SwapAgeEquipment(void) {
}
}
// When becoming adult, remove swordless flag since we'll get master sword
// Only in rando to keep swordless link bugs in vanilla
if (gSaveContext.n64ddFlag) {
gSaveContext.infTable[29] &= ~1;
}
gSaveContext.childEquips.equipment = gSaveContext.equips.equipment;
if (gSaveContext.adultEquips.buttonItems[0] == ITEM_NONE) {
@ -1493,7 +1500,8 @@ void Inventory_SwapAgeEquipment(void) {
gSaveContext.adultEquips.equipment = gSaveContext.equips.equipment;
if (gSaveContext.childEquips.buttonItems[0] != ITEM_NONE) {
if (gSaveContext.childEquips.buttonItems[0] != ITEM_NONE ||
CVarGetInteger("gSwitchAge", 0)) {
for (i = 0; i < ARRAY_COUNT(gSaveContext.equips.buttonItems); i++) {
gSaveContext.equips.buttonItems[i] = gSaveContext.childEquips.buttonItems[i];
@ -1533,6 +1541,16 @@ void Inventory_SwapAgeEquipment(void) {
}
gSaveContext.equips.equipment = 0x1111;
}
if (CVarGetInteger("gSwitchAge", 0) &&
(gSaveContext.equips.buttonItems[0] == ITEM_NONE)) {
gSaveContext.infTable[29] |= 1;
if (gSaveContext.childEquips.equipment == 0) {
// force equip kokiri tunic and boots in scenario gSaveContext.childEquips.equipment is uninitialized
gSaveContext.equips.equipment &= 0xFFF0;
gSaveContext.equips.equipment |= 0x1100;
}
}
}
temp = gEquipMasks[EQUIP_SHIELD] & gSaveContext.equips.equipment;