diff options
| author | savage13 <savage13@gmail.com> | 2022-02-20 17:50:28 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-20 23:50:28 +0100 |
| commit | c804527d7a247aca80b88de56191bb13938de38a (patch) | |
| tree | 8e9a7e4492ca1f1433e2f00deefa795b1021f25e /src/KingSystem/Map/mapPlacementMap.cpp | |
| parent | 4e21ee7613e08cf59e7504844568f7eea067dde8 (diff) | |
PlacementMap: Add x_0, x_4(); change u16 mStaticCompoundId to s16 mStaticCompundActorId (#85)
Diffstat (limited to 'src/KingSystem/Map/mapPlacementMap.cpp')
| -rw-r--r-- | src/KingSystem/Map/mapPlacementMap.cpp | 90 |
1 files changed, 84 insertions, 6 deletions
diff --git a/src/KingSystem/Map/mapPlacementMap.cpp b/src/KingSystem/Map/mapPlacementMap.cpp index 8bc0988b..ad4cfeef 100644 --- a/src/KingSystem/Map/mapPlacementMap.cpp +++ b/src/KingSystem/Map/mapPlacementMap.cpp @@ -40,6 +40,73 @@ PlacementMap::~PlacementMap() { r.cleanup(); } } +bool PlacementMap::clearStaticCompoundActorId(int idx) { + const auto lock = sead::makeScopedLock(mCs); + const auto& resource = mRes[idx].mRes.getResource(); + if (auto* sc = sead::DynamicCast<phys::StaticCompound>(resource)) { + if (sc->calledFromMapDtor()) { + return false; + } + mRes[idx].mRes.requestUnload(); + } + + for (int i = mParsedNumStaticObjs; i <= mNumStaticObjs; i++) { + auto* obj = mPa->getStaticObj_2(i); + if (getStaticCompoundIdFromPosition(*obj) == idx) { + obj->setStaticCompoundActorId(-1); + } + } + + int gid = mDynamicGroupIdx; + if (gid >= 0) { + int num_objs = mPa->getNumObjs(gid); + for (int i = 0; i < num_objs; i++) { + auto* obj = mPa->getObj(gid, i); + if (getStaticCompoundIdFromPosition(*obj) == idx) { + obj->setStaticCompoundActorId(-1); + } + } + } + return true; +} + +void PlacementMap::updateObjectCollisionAndId(int index, Object* obj) { + if (PlacementMgr::instance()->auto17(obj)) { + return; + } + if (getStaticCompoundIdFromPosition(*obj) != index) { + return; + } + auto& rsrc = mRes[index]; + obj->setStaticCompoundActorId(-1); + + const auto lock = sead::makeScopedLock(mCs); + + auto* sc = sead::DynamicCast<phys::StaticCompound>(rsrc.mRes.getResource()); + if (!sc) { + return; + } + u32 hash_id = obj->getHashId(); + int srt_hash = 0; + obj->getMubinIter().tryGetParamIntByKey(&srt_hash, "SRTHash"); + int idx = sc->setMapObject(hash_id, static_cast<u32>(srt_hash), obj); + obj->setStaticCompoundActorId(idx); + if (obj->getStaticCompoundActorId() < 0) { + return; + } + bool disable = false; + if (obj->shouldSkipSpawn() || + (obj->checkActorDataFlag(mPa, map::ActorData::Flag::MapConstPassive) && + obj->getFlags0().isOn(Object::Flag0::_800))) { + obj->resetFlags0(Object::Flag0::_200000); + disable = false; + } else { + obj->setFlags0(Object::Flag0::_200000); + disable = true; + } + sc->disableCollision(idx, disable); +} + bool PlacementMap::parseStaticMap_(sead::Heap* heap, u8* data) { if (!mMubinPath.isEmpty()) { if (!mSkipLoadStaticMap) { @@ -52,14 +119,25 @@ bool PlacementMap::parseStaticMap_(sead::Heap* heap, u8* data) { mStaticMapLoaded = true; return false; } - +int PlacementMap::getStaticCompoundIdFromPosition(const Object& object) const { + if (mMgr->isShrineOrDivineBeast()) { + return 0; + } + return getStaticCompoundIdFromPosition(object.getTranslate().x, object.getTranslate().z); +} +int PlacementMap::getStaticCompoundIdFromPosition(float x, float z) const { + if (mMgr->isShrineOrDivineBeast()) { + return 0; + } + return getStaticCompoundIdFromPosition(sead::Vector3f(x, 0, z)); +} int PlacementMap::getStaticCompoundIdFromPosition(const sead::Vector3f& pos) const { if (mMgr->isShrineOrDivineBeast()) { return 0; } float dx = (pos.x - (1000 * mCol - 5000)); float dz = (pos.z - (1000 * mRow - 4000)); - return (2 * (dz > 500.0)) + (dx > 500.0); + return (2 * (dz > 500.0f)) + (dx > 500.0f); } bool PlacementMap::isDynamicLoaded(const sead::Vector3f& pos) { @@ -144,20 +222,20 @@ PlacementMap::MapObjStatus PlacementMap::x_2(int hksc_idx) { sc->sub_7100FCAD0C(mMat); for (int i = mParsedNumStaticObjs; i <= mNumStaticObjs; i++) { - x_0(hksc_idx, mPa->getStaticObj_0(i)); + updateObjectCollisionAndId(hksc_idx, mPa->getStaticObj_0(i)); } const int gid = mDynamicGroupIdx; if (gid >= 0) { int n = mPa->getNumObjs(gid); for (int i = 0; i < n; i++) { - x_0(hksc_idx, mPa->getObj(gid, i)); + updateObjectCollisionAndId(hksc_idx, mPa->getObj(gid, i)); } } return MapObjStatus::Loading; } void PlacementMap::doDisableObjStaticCompound(Object* obj, bool disable) { - if ((s16)obj->getStaticCompoundId() < 0) { + if ((s16)obj->getStaticCompoundActorId() < 0) { return; } const auto lock = sead::makeScopedLock(mCs); @@ -175,7 +253,7 @@ void PlacementMap::doDisableObjStaticCompound(Object* obj, bool disable) { int idx = getStaticCompoundIdFromPosition(obj->getTranslate()); auto* resource = mRes[idx].mRes.getResource(); if (auto* sc = sead::DynamicCast<ksys::phys::StaticCompound>(resource)) { - s16 sc_id = obj->getStaticCompoundId(); + s16 sc_id = obj->getStaticCompoundActorId(); sc->disableCollision(sc_id, disable); } } |
