Skip to content

Commit

Permalink
d_t_sw_area OK (#68)
Browse files Browse the repository at this point in the history
* Initial attempt

* Fix symbols for renamed story/itemflagMgrs

* Improvements xD

* OK with pragma

* Update variable name
  • Loading branch information
CovenEsme authored Oct 16, 2024
1 parent 1eaa124 commit 22a5cad
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 49 deletions.
2 changes: 2 additions & 0 deletions config/SOUE01/rels/d_t_sw_areaNP/splits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ REL/executor.c:

REL/d/t/d_t_sw_area.cpp:
.text start:0x00000070 end:0x000003DC
.rodata start:0x00000000 end:0x0000000C
.data start:0x00000000 end:0x0000008C
14 changes: 7 additions & 7 deletions config/SOUE01/rels/d_t_sw_areaNP/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ _prolog = .text:0x00000000; // type:function size:0x2C scope:global
_epilog = .text:0x00000030; // type:function size:0x2C scope:global
_unresolved = .text:0x00000060; // type:function size:0x4 scope:global
dTgSwArea_c_classInit__Fv = .text:0x00000070; // type:function size:0x4C
SwArea__init = .text:0x000000C0; // type:function size:0x98
SwAreaT__isValidStoryFlag = .text:0x00000160; // type:function size:0x20
SwAreaT__update = .text:0x00000180; // type:function size:0x1F8
create__11dTgSwArea_cFv = .text:0x000000C0; // type:function size:0x98
isValidStoryFlag__FUs = .text:0x00000160; // type:function size:0x20
actorExecute__11dTgSwArea_cFv = .text:0x00000180; // type:function size:0x1F8
__dt__11dTgSwArea_cFv = .text:0x00000380; // type:function size:0x5C
_ctors = .ctors:0x00000000; // type:label scope:global
_dtors = .dtors:0x00000000; // type:label scope:global
lbl_206_rodata_0 = .rodata:0x00000000; // type:object size:0xC data:float
lbl_206_rodata_0 = .rodata:0x00000000; // type:object size:0xC scope:local data:float
g_profile_SW_AREA_TAG = .data:0x00000000; // type:object size:0x10
lbl_206_data_10 = .data:0x00000010; // type:object size:0x4 data:4byte
lbl_206_data_14 = .data:0x00000014; // type:object size:0x4 data:4byte
lbl_206_data_18 = .data:0x00000018; // type:object size:0x74
sDefaultRotX__11dTgSwArea_c = .data:0x00000010; // type:object size:0x4 data:4byte
sDefaultRotZ__11dTgSwArea_c = .data:0x00000014; // type:object size:0x4 data:4byte
__vt__11dTgSwArea_c = .data:0x00000018; // type:object size:0x74
4 changes: 2 additions & 2 deletions config/SOUE01/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39944,8 +39944,8 @@ sTempFlags__16SceneflagManager = .sbss:0x805753E8; // type:object size:0x8
sInstance__15TBoxFlagManager = .sbss:0x805753F0; // type:object size:0x4 data:4byte
sTBoxFlags__15TBoxFlagManager = .sbss:0x805753F4; // type:object size:0x4
sInstance__18EnemyDefeatManager = .sbss:0x805753F8; // type:object size:0x4 data:4byte
sInstance__16StoryFlagManager = .sbss:0x805753FC; // type:object size:0x4 data:4byte
sInstance__15ItemFlagManager = .sbss:0x80575400; // type:object size:0x4 data:4byte
sInstance__16StoryflagManager = .sbss:0x805753FC; // type:object size:0x4 data:4byte
sInstance__15ItemflagManager = .sbss:0x80575400; // type:object size:0x4 data:4byte
DUNGEONFLAG_MANAGER = .sbss:0x80575404; // type:object size:0x4 data:4byte
sInstance__15SkipflagManager = .sbss:0x80575408; // type:object size:0x4 data:4byte
lbl_80575410 = .sbss:0x80575410; // type:object size:0x8 data:4byte
Expand Down
2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@ def nw4rLib(lib_name, objects, extra_cflags=[]):
Rel(NonMatching, "d_t_spore", "REL/d/t/d_t_spore.cpp"),
Rel(NonMatching, "d_t_stream", "REL/d/t/d_t_stream.cpp"),
Rel(NonMatching, "d_t_sword_battle_game", "REL/d/t/d_t_sword_battle_game.cpp"),
Rel(NonMatching, "d_t_sw_area", "REL/d/t/d_t_sw_area.cpp"),
Rel(Matching, "d_t_sw_area", "REL/d/t/d_t_sw_area.cpp"),
Rel(Matching, "d_t_tackle", "REL/d/t/d_t_tackle.cpp"),
Rel(NonMatching, "d_t_telop", "REL/d/t/d_t_telop.cpp"),
Rel(Matching, "d_t_timer", "REL/d/t/d_t_timer.cpp"),
Expand Down
38 changes: 36 additions & 2 deletions include/d/t/d_t_sw_area.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,48 @@
#ifndef D_T_SW_AREA_H
#define D_T_SW_AREA_H

#include "d/a/d_a_base.h"
#include "d/t/d_tg.h"
#include "m/m_mtx.h"

class dTgSwArea_c : public dAcBase_c {
class dTgSwArea_c : public dTg_c {
public:
dTgSwArea_c() {}
virtual ~dTgSwArea_c() {}

virtual int create() override;
virtual int actorExecute() override;

private:
u8 getSetSceneflag() {
return params;
}

u8 getUnsetSceneflag() {
return params >> 0x8;
}

u8 getIsPersistent() {
return params >> 0x10 & 1;
}

mAng getSetStoryflag() {
return rotation.x & 0x7FF;
}

mAng getUnsetStoryflag() {
return rotation.z & 0x7FF;
}

mMtx_c area;
u8 setSceneflag;
u8 unsetSceneflag;
bool isTemporary;
f32 scale;
u16 setStoryflag;
u16 unsetStoryflag;

static u32 sDefaultRotX;
static u32 sDefaultRotZ;
};

#endif
8 changes: 4 additions & 4 deletions include/toBeSorted/item_story_flag_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ class ItemStoryManagerBase {
u16 getFlag(u16 flag) const;
};

class StoryFlagManager : public ItemStoryManagerBase {
class StoryflagManager : public ItemStoryManagerBase {
FlagSpace storyFlags;

public:
static StoryFlagManager *sInstance;
static StoryflagManager *sInstance;
};

class ItemFlagManager : public ItemStoryManagerBase {
class ItemflagManager : public ItemStoryManagerBase {
FlagSpace itemFlags;

public:
static ItemFlagManager *sInstance;
static ItemflagManager *sInstance;
};

#endif
4 changes: 2 additions & 2 deletions src/REL/d/a/obj/d_a_obj_bamboo_island.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ static const char *const sBambooIslandNames[] = {
SPECIAL_ACTOR_PROFILE(OBJ_BAMBOO_ISLAND, dAcObambooIsland_c, fProfile::OBJ_BAMBOO_ISLAND, 0x01F9, 0, 3);

void dAcObambooIsland_c::rideCallback(dBgW *unknown, dAcObjBase_c *actor, dAcObjBase_c *interactor) {
if (interactor->isActorPlayer() && actor != nullptr && StoryFlagManager::sInstance->getCounterOrFlag(284) == 0) {
StoryFlagManager::sInstance->setFlag(284);
if (interactor->isActorPlayer() && actor != nullptr && StoryflagManager::sInstance->getCounterOrFlag(284) == 0) {
StoryflagManager::sInstance->setFlag(284);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/REL/d/a/obj/d_a_obj_junk_repairing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bool dAcOJunkRep_c::loadMdl(m3d::smdl_c &mdl, const char *name) {
}

bool dAcOJunkRep_c::getState() {
return StoryFlagManager::sInstance->getCounterOrFlag(0x143) == 1;
return StoryflagManager::sInstance->getCounterOrFlag(0x143) == 1;
}

bool dAcOJunkRep_c::createHeap() {
Expand Down
2 changes: 1 addition & 1 deletion src/REL/d/a/obj/d_a_obj_toD3_stone_figure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const char *dAcOtoD3StoneFigure_c::getModelName() const {
}

bool dAcOtoD3StoneFigure_c::isStoneOfTrialsPlaced() const {
return StoryFlagManager::sInstance->getCounterOrFlag(22);
return StoryflagManager::sInstance->getCounterOrFlag(22);
}

void dAcOtoD3StoneFigure_c::doInteraction(s32 arg) {
Expand Down
12 changes: 6 additions & 6 deletions src/REL/d/t/d_t_dowsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ int dTgDowsing_c::draw() {

bool dTgDowsing_c::checkDowsing() const {
if (!((mUntriggerStoryFlag == 0 || mUntriggerStoryFlag >= 0x7FF ||
!StoryFlagManager::sInstance->getCounterOrFlag(mUntriggerStoryFlag)) &&
!StoryflagManager::sInstance->getCounterOrFlag(mUntriggerStoryFlag)) &&
(mTriggerStoryFlag == 0 || mTriggerStoryFlag >= 0x7FF ||
StoryFlagManager::sInstance->getCounterOrFlag(mTriggerStoryFlag)))) {
StoryflagManager::sInstance->getCounterOrFlag(mTriggerStoryFlag)))) {
return false;
}

switch (mDowsingOption) {
case TRIAL_0:
return ItemFlagManager::sInstance->getFlag(187) && !StoryFlagManager::sInstance->getCounterOrFlag(93);
return ItemflagManager::sInstance->getFlag(187) && !StoryflagManager::sInstance->getCounterOrFlag(93);
case TRIAL_1:
return ItemFlagManager::sInstance->getFlag(188) && !StoryFlagManager::sInstance->getCounterOrFlag(97);
return ItemflagManager::sInstance->getFlag(188) && !StoryflagManager::sInstance->getCounterOrFlag(97);
case TRIAL_2:
return ItemFlagManager::sInstance->getFlag(189) && !StoryFlagManager::sInstance->getCounterOrFlag(98);
return ItemflagManager::sInstance->getFlag(189) && !StoryflagManager::sInstance->getCounterOrFlag(98);
case TRIAL_3:
return ItemFlagManager::sInstance->getFlag(193) && !StoryFlagManager::sInstance->getCounterOrFlag(99);
return ItemflagManager::sInstance->getFlag(193) && !StoryflagManager::sInstance->getCounterOrFlag(99);
case PROPELLER: return DowsingTarget::hasPropellerDowsing();
case WATER_BASIN: return DowsingTarget::hasWaterBasinDowsing();
case CRYSTAL_BALL: return DowsingTarget::hasCrystalBallDowsing();
Expand Down
2 changes: 1 addition & 1 deletion src/REL/d/t/d_t_genki_dws_tgt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
SPECIAL_ACTOR_PROFILE(TAG_GENKI_DOWSING_TARGET, dTgGenkiDwsTgt_c, fProfile::TAG_GENKI_DOWSING_TARGET, 0x02A5, 0, 0);

int dTgGenkiDwsTgt_c::create() {
u16 batQuestActivated = StoryFlagManager::sInstance->getCounterOrFlag(304);
u16 batQuestActivated = StoryflagManager::sInstance->getCounterOrFlag(304);
if (batQuestActivated == 0 || !ScGame::sInstance->currentSpawnInfo.isNight()) {
return FAILED;
}
Expand Down
76 changes: 76 additions & 0 deletions src/REL/d/t/d_t_sw_area.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,79 @@
#include "d/t/d_t_sw_area.h"
#include "d/a/d_a_player.h"
#include "toBeSorted/area_math.h"
#include "toBeSorted/sceneflag_manager.h"
#include "toBeSorted/item_story_flag_manager.h"

SPECIAL_ACTOR_PROFILE(SW_AREA_TAG, dTgSwArea_c, fProfile::SW_AREA_TAG, 0x292, 0, 0);

// sDefaultRotX got placed in .data despite being zero.
// There is a handy pragma for this but it's probably not
// the correct solution.
#pragma explicit_zero_data on
u32 dTgSwArea_c::sDefaultRotX = 0;
u32 dTgSwArea_c::sDefaultRotZ = 0;
#pragma explicit_zero_data off

int dTgSwArea_c::create() {
setSceneflag = getSetSceneflag();
unsetSceneflag = getUnsetSceneflag();
isTemporary = !getIsPersistent();

setStoryflag = getSetStoryflag();
unsetStoryflag = getUnsetStoryflag();
rotation.x = sDefaultRotX;
rotation.z = sDefaultRotZ;

matrixCreateFromPosRotYScale(area, position, rotation.y, mScale, nullptr, 0.0f);
return SUCCEEDED;
}

bool isValidStoryFlag(u16 storyflag) {
bool valid = false;

if (storyflag != 0 && storyflag < 0x7FF) {
valid = true;
}

return valid;
}

int dTgSwArea_c::actorExecute() {
if (checkIfVec3fInMatrix(area, dAcPy_c::LINK->position)) {
SceneflagManager::sInstance->setFlag(roomid, setSceneflag);
SceneflagManager::sInstance->unsetFlag(roomid, unsetSceneflag);

if (isValidStoryFlag(setStoryflag)) {
StoryflagManager::sInstance->setFlag(setStoryflag);
}

if (isValidStoryFlag(unsetStoryflag)) {
StoryflagManager::sInstance->unsetFlag(unsetStoryflag);
}

if (scale < 1.0f) {
scale = 50.0f;
matrixCreateFromPosRotYScale(area, position, rotation.y, mScale, nullptr, scale);
}
} else {
if (scale > 1.0f) {
scale = 0.0f;
matrixCreateFromPosRotYScale(area, position, rotation.y, mScale, nullptr, scale);
}

if (isTemporary) {
SceneflagManager::sInstance->unsetFlag(roomid, setSceneflag);
SceneflagManager::sInstance->setFlag(roomid, unsetSceneflag);

if (isValidStoryFlag(setStoryflag)) {
StoryflagManager::sInstance->unsetFlag(setStoryflag);
}

if (isValidStoryFlag(unsetStoryflag)) {
StoryflagManager::sInstance->setFlag(unsetStoryflag);
}
}
}

return SUCCEEDED;
}
6 changes: 3 additions & 3 deletions src/toBeSorted/counters/counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
}

/* 8016cd30 */ u16 Counter::getCommittedValue() {
return ItemFlagManager::sInstance->getCounterOrFlag(counterId | 0x4000);
return ItemflagManager::sInstance->getCounterOrFlag(counterId | 0x4000);
}

/* 8016cd50 */ u16 Counter::getUncommittedValue() {
return ItemFlagManager::sInstance->getUncommittedValue(counterId | 0x4000);
return ItemflagManager::sInstance->getUncommittedValue(counterId | 0x4000);
}

/* 8016cd70 */ void Counter::setValue(u16 num) {
ItemFlagManager::sInstance->setFlagOrCounterToValue(counterId | 0x4000, num);
ItemflagManager::sInstance->setFlagOrCounterToValue(counterId | 0x4000, num);
}
2 changes: 1 addition & 1 deletion src/toBeSorted/counters/rupee_counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct WalletStruct {
};
const WalletStruct *wallet = &wallet_definitions[3];
for (; i < 4; i++, wallet--) {
if (ItemFlagManager::sInstance->getFlag(wallet->flag)) {
if (ItemflagManager::sInstance->getFlag(wallet->flag)) {
return wallet->capacity;
}
}
Expand Down
36 changes: 18 additions & 18 deletions src/toBeSorted/dowsing_target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,63 +57,63 @@ void DowsingTarget::getPosition(mVec3_c &position) {
}

bool DowsingTarget::hasZeldaDowsing() {
return StoryFlagManager::sInstance->getCounterOrFlag(100);
return StoryflagManager::sInstance->getCounterOrFlag(100);
}

bool DowsingTarget::hasKikwiDowsing() {
return StoryFlagManager::sInstance->getCounterOrFlag(56) && !StoryFlagManager::sInstance->getCounterOrFlag(57);
return StoryflagManager::sInstance->getCounterOrFlag(56) && !StoryflagManager::sInstance->getCounterOrFlag(57);
}

bool DowsingTarget::hasKeyPieceDowsing() {
return StoryFlagManager::sInstance->getCounterOrFlag(106) && !StoryFlagManager::sInstance->getCounterOrFlag(120);
return StoryflagManager::sInstance->getCounterOrFlag(106) && !StoryflagManager::sInstance->getCounterOrFlag(120);
}

bool DowsingTarget::hasDesertNodeDowsing() {
return StoryFlagManager::sInstance->getCounterOrFlag(107) && !StoryFlagManager::sInstance->getCounterOrFlag(8);
return StoryflagManager::sInstance->getCounterOrFlag(107) && !StoryflagManager::sInstance->getCounterOrFlag(8);
}

bool DowsingTarget::hasAnyTrialDowsing() {
// TODO more complicated code
return ItemFlagManager::sInstance->getFlag(187) && !StoryFlagManager::sInstance->getCounterOrFlag(93) ||
ItemFlagManager::sInstance->getFlag(188) && !StoryFlagManager::sInstance->getCounterOrFlag(97) ||
ItemFlagManager::sInstance->getFlag(189) && !StoryFlagManager::sInstance->getCounterOrFlag(98) ||
ItemFlagManager::sInstance->getFlag(193) && !StoryFlagManager::sInstance->getCounterOrFlag(99);
return ItemflagManager::sInstance->getFlag(187) && !StoryflagManager::sInstance->getCounterOrFlag(93) ||
ItemflagManager::sInstance->getFlag(188) && !StoryflagManager::sInstance->getCounterOrFlag(97) ||
ItemflagManager::sInstance->getFlag(189) && !StoryflagManager::sInstance->getCounterOrFlag(98) ||
ItemflagManager::sInstance->getFlag(193) && !StoryflagManager::sInstance->getCounterOrFlag(99);
}

bool DowsingTarget::hasSacredWaterDowsing() {
return StoryFlagManager::sInstance->getCounterOrFlag(64) && !StoryFlagManager::sInstance->getCounterOrFlag(65);
return StoryflagManager::sInstance->getCounterOrFlag(64) && !StoryflagManager::sInstance->getCounterOrFlag(65);
}

bool DowsingTarget::hasSandshipDowsing() {
return StoryFlagManager::sInstance->getCounterOrFlag(271) && !StoryFlagManager::sInstance->getCounterOrFlag(14);
return StoryflagManager::sInstance->getCounterOrFlag(271) && !StoryflagManager::sInstance->getCounterOrFlag(14);
}

bool DowsingTarget::hasTadtoneDowsing() {
return StoryFlagManager::sInstance->getCounterOrFlag(81) && !StoryFlagManager::sInstance->getCounterOrFlag(18);
return StoryflagManager::sInstance->getCounterOrFlag(81) && !StoryflagManager::sInstance->getCounterOrFlag(18);
}

bool DowsingTarget::hasPropellerDowsing() {
return StoryFlagManager::sInstance->getCounterOrFlag(668);
return StoryflagManager::sInstance->getCounterOrFlag(668);
}

bool DowsingTarget::hasWaterBasinDowsing() {
return StoryFlagManager::sInstance->getCounterOrFlag(669);
return StoryflagManager::sInstance->getCounterOrFlag(669);
}

bool DowsingTarget::hasCrystalBallDowsing() {
return StoryFlagManager::sInstance->getCounterOrFlag(670);
return StoryflagManager::sInstance->getCounterOrFlag(670);
}

bool DowsingTarget::hasPumpkinDowsing() {
return StoryFlagManager::sInstance->getCounterOrFlag(680);
return StoryflagManager::sInstance->getCounterOrFlag(680);
}

bool DowsingTarget::hasNewPlantSpeciesDowsing() {
return StoryFlagManager::sInstance->getCounterOrFlag(681);
return StoryflagManager::sInstance->getCounterOrFlag(681);
}

bool DowsingTarget::hasPartyWheelDowsing() {
return StoryFlagManager::sInstance->getCounterOrFlag(682);
return StoryflagManager::sInstance->getCounterOrFlag(682);
}

bool DowsingTarget::hasDowsingInSlot(int slot) {
Expand All @@ -131,7 +131,7 @@ bool DowsingTarget::hasDowsingInSlot(int slot) {
} else if (slot == 2) {
return hasCrystalBallDowsing() || hasPumpkinDowsing() || hasNewPlantSpeciesDowsing() || hasKikwiDowsing() ||
hasKeyPieceDowsing() || hasDesertNodeDowsing() || hasPartyWheelDowsing();
} else if (StoryFlagManager::sInstance->getCounterOrFlag(DOWSING_TARGET_STORY_FLAGS[slot])) {
} else if (StoryflagManager::sInstance->getCounterOrFlag(DOWSING_TARGET_STORY_FLAGS[slot])) {
// TODO small instruction shuffle
return true;
}
Expand Down

0 comments on commit 22a5cad

Please sign in to comment.