From 08844fb5da445344613971b66e7fdc9ff55290ac Mon Sep 17 00:00:00 2001 From: lepelog <25211966+lepelog@users.noreply.github.com> Date: Tue, 2 Dec 2025 17:44:48 +0100 Subject: start with d_t_insect --- src/REL/d/t/d_t_insect.cpp | 184 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 183 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/REL/d/t/d_t_insect.cpp b/src/REL/d/t/d_t_insect.cpp index 75e361de..718ff57b 100644 --- a/src/REL/d/t/d_t_insect.cpp +++ b/src/REL/d/t/d_t_insect.cpp @@ -1,4 +1,17 @@ #include "d/t/d_t_insect.h" +#include "c/c_lib.h" +#include "c/c_math.h" +#include "common.h" +#include "d/a/d_a_base.h" +#include "d/a/d_a_item.h" +#include "d/a/d_a_itembase.h" +#include "d/a/obj/d_a_obj_base.h" +#include "d/col/bg/d_bg_s_gnd_chk.h" +#include "d/flag/itemflag_manager.h" +#include "d/flag/sceneflag_manager.h" +#include "f/f_profile.h" +#include "f/f_profile_name.h" +#include "m/m_vec.h" SPECIAL_ACTOR_PROFILE(TAG_INSECT, dTgInsect_c, fProfile::TAG_INSECT, 0x167, 0, 0); @@ -10,7 +23,14 @@ STATE_DEFINE(dTgInsect_c, End); void dTgInsect_c::initializeState_Wait() {} void dTgInsect_c::executeState_Wait() {} void dTgInsect_c::finalizeState_Wait() {} -void dTgInsect_c::initializeState_WaitCreate() {} +void dTgInsect_c::initializeState_WaitCreate() { + if (getSpawnSubtype() != 2) { + unk24F = 1; + for (s32 i = 0; i < mInsectCount; i++) { + unk250[i] = shouldSpawn(); + } + } +} void dTgInsect_c::executeState_WaitCreate() {} void dTgInsect_c::finalizeState_WaitCreate() {} void dTgInsect_c::initializeState_WaitForceEscape() {} @@ -19,3 +39,165 @@ void dTgInsect_c::finalizeState_WaitForceEscape() {} void dTgInsect_c::initializeState_End() {} void dTgInsect_c::executeState_End() {} void dTgInsect_c::finalizeState_End() {} + +inline bool isButterfly3(int subtype, int spawnSubtype) { + if (subtype != 10) return false; + if (spawnSubtype != 3) return false; + return true; +} +inline bool isButterfly4(int subtype, int spawnSubtype) { + if (subtype != 10) return false; + if (spawnSubtype != 4) return false; + return true; +} +inline bool isButterfly5(int subtype, int spawnSubtype) { + if (subtype != 10) return false; + if (spawnSubtype != 5) return false; + return true; +} + +static const f32 FLOAT_ARRAY[] = { + 0.1f, + -0.4f, + 0.3f, + 0.7f, + -0.7f, +}; + +static const f32 WHATEVER[] = { + 100, + 150, + 0.5f +}; + +static const f32 different100[] = { 100 }; + + + +// regalloc (probably) +void dTgInsect_c::spawnInsect(s32 index) { + f32 scaledScale = 100 * mScale.y; + f32 scaled2 = mScale.x * WHATEVER[0] * 0.85f; + mAng3_c rot(0,0,0); + mVec3_c pos; + bool spawnFound = false; + s32 tries = 5; + do { + f32 scale = cM::rndF(scaled2); + s16 angle1 = cM::rndFX(65536.0f); + s16 angle2 = cM::rndFX(65536.0f); + rot.y = angle2; + mVec3_c v2 = mVec3_c::Ez * scale; + cLib::offsetPos(pos, mPosition, angle1, v2); + s32 subtype = mParams >> 4 & 0xF; + switch (subtype) { + case 3: + case 5: + case 6: + case 9: + pos = mPosition; + if (subtype == 6) { + mVec3_c tmp = mVec3_c::Ez; + tmp.rotY(mAng(mRotation.y + 0x4000)); + f32 arrayResult = FLOAT_ARRAY[index % 5]; + f32 scaledX = WHATEVER[0] * mScale.x; + tmp.multScalar(arrayResult * scaledX); + pos = mPosition + tmp; + f32 scaledScale = mScale.y * 100; + pos.y = mPosition.y + scaledScale * 0.3f; + pos.y += cM::rndF(scaledScale * 0.5f); + if (!someGroundCheck(pos, 0)) { + return; + } + } else { + pos.y += cM::rndF(scaledScale); + } + spawnFound = true; + break; + case 7: + case 8: + case 0xB: + case 0xC: + pos.y = different100[0] + mPosition.y; + if (dBgS_ObjGndChk::CheckPos(pos)) { + spawnFound = true; + } + break; + case 4: + case 0xA: + case 0xD: + spawnFound = true; + break; + } + } while (!spawnFound && --tries); + s32 subtype = mParams >> 4 & 0xF; + dAcBase_c* ref = nullptr; + if (subtype == 3) { + + } + switch (subtype) { + case 3: + ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_LADYBUG, 0, &pos, &rot, NULL, 0, 0x3f); + break; + case 4: + ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_DRAGONFLY, 0, &pos, &rot, NULL, 0, 0x3f); + break; + case 5: + ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_BEETLE, 0, &pos, &rot, NULL, 0, 0x3f); + break; + case 6: + ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_GRASSHOPPER, 0, &pos, &rot, NULL, 0, 0x3f); + break; + case 7: + ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_CICADA, 0, &pos, &rot, NULL, 0, 0x3f); + break; + case 8: + ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_ANT, 0, &pos, &rot, NULL, 0, 0x3f); + break; + case 9: + ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_BEETLE, 0x10000000, &pos, &rot, NULL, 0, 0x3f); + break; + case 0xA: + ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_BUTTERFLY, mViewClipIdx, &pos, &rot, NULL, 0, 0x3f); + break; + case 0xB: + ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_GRASSHOPPER, 0x10000000, &pos, &rot, NULL, 0, 0x3f); + break; + case 0xC: + ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_SCARAB, 0, &pos, &rot, NULL, 0, 0x3f); + break; + case 0xD: + ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_FIREFLY, 0, &pos, &rot, NULL, 0, 0x3f); + break; + } + if (ref != nullptr) { + mLinks[index].link(ref); + unk208[index] = -1; + } + return; +} + +bool dTgInsect_c::shouldSpawn() { + int spawnSubtype = mParams >> 8 & 0xF; + if (spawnSubtype == 2) { + return true; + } else if (spawnSubtype == 1) { + bool tmp = SceneflagManager::sInstance->checkFlag(mRoomID, 0x3a); + return !tmp; + } else { + int subtype = mParams >> 4 & 0xF; + if (isButterfly3(subtype, spawnSubtype)) { + return true; + } else if (isButterfly4(subtype, spawnSubtype) || isButterfly5(subtype, spawnSubtype)) { + return true; + } else if((subtype == 0xD) && !dAcItem_c::checkFlag(ITEM_STARRY_FIREFLY)) { + return true; + } else { + if (cM::rndF(1.0f) >= 0.5f) { + return false; + } else { + return true; + } + } + } +} -- cgit v1.2.3 From 413cfaa41f0811e209d16dea6a9aa79df757679d Mon Sep 17 00:00:00 2001 From: lepelog <25211966+lepelog@users.noreply.github.com> Date: Thu, 4 Dec 2025 13:42:58 +0100 Subject: insect tag progress --- src/REL/d/t/d_t_insect.cpp | 424 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 341 insertions(+), 83 deletions(-) (limited to 'src') diff --git a/src/REL/d/t/d_t_insect.cpp b/src/REL/d/t/d_t_insect.cpp index 718ff57b..827af1e9 100644 --- a/src/REL/d/t/d_t_insect.cpp +++ b/src/REL/d/t/d_t_insect.cpp @@ -1,17 +1,30 @@ #include "d/t/d_t_insect.h" + #include "c/c_lib.h" #include "c/c_math.h" #include "common.h" #include "d/a/d_a_base.h" +#include "d/a/d_a_insect_butterfly.h" #include "d/a/d_a_item.h" #include "d/a/d_a_itembase.h" #include "d/a/obj/d_a_obj_base.h" +#include "d/a/obj/d_a_obj_soil.h" +#include "d/a/obj/d_a_obj_warp.h" +#include "d/col/bg/d_bg_s.h" #include "d/col/bg/d_bg_s_gnd_chk.h" +#include "d/col/bg/d_bg_s_lin_chk.h" #include "d/flag/itemflag_manager.h" #include "d/flag/sceneflag_manager.h" +#include "d/flag/storyflag_manager.h" +#include "f/f_base.h" +#include "f/f_manager.h" #include "f/f_profile.h" #include "f/f_profile_name.h" +#include "m/m_angle.h" #include "m/m_vec.h" +#include "nw4r/math/math_geometry.h" +#include "nw4r/math/math_types.h" +#include "rvl/MTX/mtx.h" SPECIAL_ACTOR_PROFILE(TAG_INSECT, dTgInsect_c, fProfile::TAG_INSECT, 0x167, 0, 0); @@ -20,86 +33,309 @@ STATE_DEFINE(dTgInsect_c, WaitCreate); STATE_DEFINE(dTgInsect_c, WaitForceEscape); STATE_DEFINE(dTgInsect_c, End); +static const s32 unused[] = { + 0x001E0100, 0, 0, 0, 0, 0, 0, 0, +}; + +static const f32 different100[] = {100}; + +static const f32 WHATEVER[] = {100, 150, 0.5f}; + +const s32 *useUnused() { + return unused; +} + +// non matching +int dTgInsect_c::actorCreate() { + if (getSubtype() == 0) { + return FAILED; + } + if (getSubtype() == 1) { + return FAILED; + } + if (getSubtype() == 2) { + return FAILED; + } + mInsectCount = getInsectCount(); + if (mInsectCount > 0xF) { + mInsectCount = 0xF; + } else { + if (mInsectCount == 0xF) { + mInsectCount = 1; + } + } + mScale *= 0.01f; + unk24C = 0; + unk260 = mPosition; + // non matching: load of 0 in r0 + // that is already 0 + if (isTrialGateType() || isGossipStoneType() || isGoddessWallType() || isSpawnSubtype(SPAWN_BUG_MINIGAME)) { + unk24E = 1; + } + return SUCCEEDED; +} + +inline bool checkProfile(u16 prof, u32 target) { + return prof == target; +} + +// non matching: the inline vecs from the distance checks +// are in the wrong order on the stack +int dTgInsect_c::actorPostCreate() { + s32 subtype = (mParams >> 4 & 0xF); + // ??? doesn't match without the double comparison + if (subtype == 5 || subtype == 5 || subtype == 6 || subtype == 3 || subtype == 9) { + if (!someGroundCheck(mPosition, 1)) { + return FAILED; + } + } + dAcBase_c *obj = nullptr; + do { + obj = searchNextActor(obj); + if (obj == nullptr) { + break; + } + u16 prof = obj->mProfileName; + if (( + checkProfile(prof, fProfile::OBJ_TUBO) || checkProfile(prof, fProfile::OBJ_CARRY_STONE) || + checkProfile(prof, fProfile::OBJ_OCT_GRASS_LEAF) || checkProfile(prof, fProfile::OBJ_FRUIT) || + checkProfile(prof, fProfile::OBJ_BARREL) || checkProfile(prof, fProfile::OBJ_VSD) || + checkProfile(prof, fProfile::OBJ_SOIL) + // inline vec 1 + ) && + getSquareDistanceTo(obj->mPosition) < 25) { + if (subtype == 7 || subtype == 0xB || subtype == 8 || subtype == 0xC) { + if (prof == fProfile::OBJ_SOIL && static_cast(obj)->isStateHole()) { + return FAILED; + } + setActorRef(obj); + } + break; + } + } while (true); + if (mActorNode.isLinked()) { + mStateMgr.changeState(StateID_WaitCreate); + } else { + if (isSpawnSubtype(SPAWN_BUG_MINIGAME)) { + for (s32 i = 0; i < 16; i++) { + unk1F8[i] = 0; + } + mStateMgr.changeState(StateID_Wait); + } else if (isTrialGateType()) { + dAcOWarp_c *warp = static_cast(fManager_c::searchBaseByProfName(fProfile::OBJ_WARP)); + if (warp == nullptr) { + return FAILED; + } + if (!warp->checkThisHasSongItem() || warp->isTrialComplete()) { + return FAILED; + } + // inline vec 2 + if ((warp->checkInRadius(mPosition, 1000000))) { + unk26C.link(warp); + } else { + return FAILED; + } + mStateMgr.changeState(StateID_WaitForceEscape); + } else if (isGossipStoneType()) { + if (!ItemflagManager::sInstance->getFlagDirect(ITEM_BALLAD_OF_THE_GODDESS)) { + return FAILED; + } + if (!StoryflagManager::sInstance->getFlag(STORYFLAG_IMPRISONED_1_DEFEATED)) { + return FAILED; + } + bool flag = SceneflagManager::sInstance->checkFlag(mRoomID, mParams >> 0xC & 0xFF); + if (flag) { + return FAILED; + } + } else if (isGoddessWallType()) { + if (!ItemflagManager::sInstance->getFlagDirect(ITEM_BALLAD_OF_THE_GODDESS)) { + return FAILED; + } + if (!StoryflagManager::sInstance->getFlag(STORYFLAG_FARON_TRIAL_COMPLETE)) { + return FAILED; + } + mStateMgr.changeState(StateID_WaitForceEscape); + } else { + mStateMgr.changeState(StateID_End); + } + spawnAll(); + } + return SUCCEEDED; +} + void dTgInsect_c::initializeState_Wait() {} -void dTgInsect_c::executeState_Wait() {} + +void dTgInsect_c::executeState_Wait() { + if (isSpawnSubtype(SPAWN_BUG_MINIGAME)) { + s32 i = 0; + for (; i < mInsectCount; i++) { + if (!mLinks[i].isLinked()) { + if (unk208[i] > 0) { + unk208[i]--; + } else if (unk208[i] == 0) { + nw4r::math::MTX34 mtx; + PSMTXTrans(mtx, mPosition.x, mPosition.y, mPosition.z); + nw4r::math::MTX34 scale; + PSMTXScale(scale, mScale.x, mScale.y, mScale.x); + PSMTXConcat(mtx, scale, mtx); + nw4r::math::AABB aabb(-100, 0, -100, 100, 100, 100); + aabb.Set(&aabb, &mtx); + if (fn_801BB750(&aabb, 10000)) { + spawnInsect(i); + } + } else { + unk208[i] = 900; + } + } + } + } +} void dTgInsect_c::finalizeState_Wait() {} void dTgInsect_c::initializeState_WaitCreate() { - if (getSpawnSubtype() != 2) { + if (!isSpawnSubtype(SPAWN_BUG_MINIGAME)) { unk24F = 1; for (s32 i = 0; i < mInsectCount; i++) { unk250[i] = shouldSpawn(); } } } -void dTgInsect_c::executeState_WaitCreate() {} +#pragma opt_strength_reduction on +void dTgInsect_c::executeState_WaitCreate() { + if (mActorNode.isLinked()) { + if (mActorNode.get()->mProfileName == fProfile::OBJ_VSD || + mActorNode.get()->mProfileName == fProfile::OBJ_SOIL) { + if (unk24C == 0) { + return; + } + } else { + if (mPosition.squareDistanceToXZ(mActorNode.get()->mPosition) < 25) { + return; + } + } + } + mActorNode.unlink(); + for (s32 i = 0; i < mInsectCount; i++) { + if (!isSpawnSubtype(SPAWN_BUG_MINIGAME)) { + if (unk250[i] != 0) { + unk250[i] = 0; + } else { + continue; + } + } + dAcBase_c *insect = nullptr; + mVec3_c tmp1 = mPosition; + if (unk24C) { + tmp1 = unk260; + } + mAng3_c rot(0, cM::rndFX(65536), 0); + switch (getSubtype()) { + case SUBTYPE_LANAYRU_ANT: + insect = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_ANT, 1, &tmp1, &rot, nullptr, 0, 0x3f); + break; + case SUBTYPE_FARON_GRASSHOPPER: + insect = dAcObjBase_c::createInsectActor( + this, fProfile::INSECT_GRASSHOPPER, 1, &tmp1, &rot, nullptr, 0, 0x3f + ); + break; + case SUBTYPE_SKYLOFT_MANTIS: + insect = dAcObjBase_c::createInsectActor( + this, fProfile::INSECT_GRASSHOPPER, 0x10000001, &tmp1, &rot, nullptr, 0, 0x3f + ); + break; + case SUBTYPE_EDLIN_ROLLER: + insect = + dAcObjBase_c::createInsectActor(this, fProfile::INSECT_SCARAB, 1, &tmp1, &rot, nullptr, 0, 0x3f); + break; + } + if (insect != nullptr) { + mLinks[i].link(insect); + unk208[i] = -1; + } + } + if (isSpawnSubtype(SPAWN_BUG_MINIGAME)) { + mStateMgr.changeState(StateID_Wait); + } else { + mStateMgr.changeState(StateID_End); + } +} void dTgInsect_c::finalizeState_WaitCreate() {} -void dTgInsect_c::initializeState_WaitForceEscape() {} -void dTgInsect_c::executeState_WaitForceEscape() {} + +// non matching: regswap +void dTgInsect_c::initializeState_WaitForceEscape() { + for (s32 i = 0; i < mInsectCount; i++) { + if (mLinks[i].isLinked()) { + mLinks[i].get()->mActorProperties |= AC_PROP_0x4; + } + } +} + +void dTgInsect_c::executeState_WaitForceEscape() { + if (isTrialGateType()) { + if (unk26C.isLinked()) { + dAcOWarp_c *warp = static_cast(unk26C.get()); + if (warp->fn_0x90()) { + for (s32 i = 0; i < mInsectCount; i++) { + if (mLinks[i].isLinked()) { + static_cast(mLinks[i].get())->setKillSignal(); + mStateMgr.changeState(StateID_End); + } + } + } + } + } else if (isGoddessWallType() && unk24D) { + for (s32 i = 0; i < mInsectCount; i++) { + if (mLinks[i].isLinked()) { + static_cast(mLinks[i].get())->setKillSignal(); + mStateMgr.changeState(StateID_End); + } + } + } +} void dTgInsect_c::finalizeState_WaitForceEscape() {} void dTgInsect_c::initializeState_End() {} void dTgInsect_c::executeState_End() {} void dTgInsect_c::finalizeState_End() {} -inline bool isButterfly3(int subtype, int spawnSubtype) { - if (subtype != 10) return false; - if (spawnSubtype != 3) return false; - return true; -} -inline bool isButterfly4(int subtype, int spawnSubtype) { - if (subtype != 10) return false; - if (spawnSubtype != 4) return false; - return true; -} -inline bool isButterfly5(int subtype, int spawnSubtype) { - if (subtype != 10) return false; - if (spawnSubtype != 5) return false; - return true; -} - static const f32 FLOAT_ARRAY[] = { - 0.1f, - -0.4f, - 0.3f, - 0.7f, - -0.7f, -}; - -static const f32 WHATEVER[] = { - 100, - 150, - 0.5f + 0.1f, -0.4f, 0.3f, 0.7f, -0.7f, }; -static const f32 different100[] = { 100 }; - - +void dTgInsect_c::spawnAll() { + for (s32 i = 0; i < mInsectCount; i++) { + if (shouldSpawn()) { + spawnInsect(i); + } + } +} -// regalloc (probably) +// non matching: rodata is weird, using multiple different 100.0f instead of just one +// also the registers are wrong void dTgInsect_c::spawnInsect(s32 index) { + s32 tries; f32 scaledScale = 100 * mScale.y; f32 scaled2 = mScale.x * WHATEVER[0] * 0.85f; - mAng3_c rot(0,0,0); + bool spawnFound; mVec3_c pos; - bool spawnFound = false; - s32 tries = 5; + mVec3_c tmp; + mAng3_c rot(0, 0, 0); + spawnFound = false; + tries = 5; do { f32 scale = cM::rndF(scaled2); s16 angle1 = cM::rndFX(65536.0f); - s16 angle2 = cM::rndFX(65536.0f); - rot.y = angle2; + rot.y = cM::rndFX(65536.0f); mVec3_c v2 = mVec3_c::Ez * scale; cLib::offsetPos(pos, mPosition, angle1, v2); - s32 subtype = mParams >> 4 & 0xF; - switch (subtype) { - case 3: - case 5: - case 6: - case 9: + switch (getSubtype()) { + case SUBTYPE_VOLCANIC_LADYBUG: + case SUBTYPE_WOODLAND_RHINO_BEETLE: + case SUBTYPE_SAND_CICADA: + case SUBTYPE_SKY_STAG_BEETLE: pos = mPosition; - if (subtype == 6) { - mVec3_c tmp = mVec3_c::Ez; + if (getSubtype() == SUBTYPE_SAND_CICADA) { + tmp = mVec3_c::Ez; tmp.rotY(mAng(mRotation.y + 0x4000)); - f32 arrayResult = FLOAT_ARRAY[index % 5]; + f32 arrayResult = FLOAT_ARRAY[index % (s32)ARRAY_LENGTH(FLOAT_ARRAY)]; f32 scaledX = WHATEVER[0] * mScale.x; tmp.multScalar(arrayResult * scaledX); pos = mPosition + tmp; @@ -114,59 +350,59 @@ void dTgInsect_c::spawnInsect(s32 index) { } spawnFound = true; break; - case 7: - case 8: - case 0xB: - case 0xC: + case SUBTYPE_FARON_GRASSHOPPER: + case SUBTYPE_LANAYRU_ANT: + case SUBTYPE_SKYLOFT_MANTIS: + case SUBTYPE_EDLIN_ROLLER: pos.y = different100[0] + mPosition.y; if (dBgS_ObjGndChk::CheckPos(pos)) { spawnFound = true; } break; - case 4: - case 0xA: - case 0xD: + case SUBTYPE_GERUDO_DRAGONFLY: + case SUBTYPE_BUTTERFLY: + case SUBTYPE_STARRY_FIREFLY: spawnFound = true; break; } } while (!spawnFound && --tries); - s32 subtype = mParams >> 4 & 0xF; - dAcBase_c* ref = nullptr; - if (subtype == 3) { - - } - switch (subtype) { - case 3: + dAcBase_c *ref = nullptr; + switch (getSubtype()) { + case SUBTYPE_VOLCANIC_LADYBUG: ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_LADYBUG, 0, &pos, &rot, NULL, 0, 0x3f); break; - case 4: + case SUBTYPE_GERUDO_DRAGONFLY: ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_DRAGONFLY, 0, &pos, &rot, NULL, 0, 0x3f); break; - case 5: + case SUBTYPE_WOODLAND_RHINO_BEETLE: ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_BEETLE, 0, &pos, &rot, NULL, 0, 0x3f); break; - case 6: + case SUBTYPE_FARON_GRASSHOPPER: ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_GRASSHOPPER, 0, &pos, &rot, NULL, 0, 0x3f); break; - case 7: + case SUBTYPE_SAND_CICADA: ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_CICADA, 0, &pos, &rot, NULL, 0, 0x3f); break; - case 8: + case SUBTYPE_LANAYRU_ANT: ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_ANT, 0, &pos, &rot, NULL, 0, 0x3f); break; - case 9: + case SUBTYPE_SKY_STAG_BEETLE: ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_BEETLE, 0x10000000, &pos, &rot, NULL, 0, 0x3f); break; - case 0xA: - ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_BUTTERFLY, mViewClipIdx, &pos, &rot, NULL, 0, 0x3f); + case SUBTYPE_BUTTERFLY: + ref = dAcObjBase_c::createInsectActor( + this, fProfile::INSECT_BUTTERFLY, mViewClipIdx, &pos, &rot, NULL, 0, 0x3f + ); break; - case 0xB: - ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_GRASSHOPPER, 0x10000000, &pos, &rot, NULL, 0, 0x3f); + case SUBTYPE_SKYLOFT_MANTIS: + ref = dAcObjBase_c::createInsectActor( + this, fProfile::INSECT_GRASSHOPPER, 0x10000000, &pos, &rot, NULL, 0, 0x3f + ); break; - case 0xC: + case SUBTYPE_EDLIN_ROLLER: ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_SCARAB, 0, &pos, &rot, NULL, 0, 0x3f); break; - case 0xD: + case SUBTYPE_STARRY_FIREFLY: ref = dAcObjBase_c::createInsectActor(this, fProfile::INSECT_FIREFLY, 0, &pos, &rot, NULL, 0, 0x3f); break; } @@ -178,19 +414,17 @@ void dTgInsect_c::spawnInsect(s32 index) { } bool dTgInsect_c::shouldSpawn() { - int spawnSubtype = mParams >> 8 & 0xF; - if (spawnSubtype == 2) { + if (isSpawnSubtype(SPAWN_BUG_MINIGAME)) { return true; - } else if (spawnSubtype == 1) { + } else if (isSpawnSubtype(SPAWN_SKYLOFT_BUGKID_TREE)) { bool tmp = SceneflagManager::sInstance->checkFlag(mRoomID, 0x3a); return !tmp; } else { - int subtype = mParams >> 4 & 0xF; - if (isButterfly3(subtype, spawnSubtype)) { + if (isTrialGateType()) { return true; - } else if (isButterfly4(subtype, spawnSubtype) || isButterfly5(subtype, spawnSubtype)) { + } else if (isGossipStoneType() || isGoddessWallType()) { return true; - } else if((subtype == 0xD) && !dAcItem_c::checkFlag(ITEM_STARRY_FIREFLY)) { + } else if ((isSubtype(SUBTYPE_STARRY_FIREFLY)) && !dAcItem_c::checkFlag(ITEM_STARRY_FIREFLY)) { return true; } else { if (cM::rndF(1.0f) >= 0.5f) { @@ -201,3 +435,27 @@ bool dTgInsect_c::shouldSpawn() { } } } + +bool dTgInsect_c::someGroundCheck(const mVec3_c &pos, s32 updateRotation) { + mVec3_c tmp = mVec3_c::Ez * (mScale.x * 100); + tmp.rotY(mRotation.y); + tmp += pos; + dBgS_LinChk linChk; + linChk.mBackFlag = true; + linChk.mFrontFlag = false; + linChk.Set(&pos, &tmp, nullptr); + if (!dBgS::GetInstance()->LineCross(&linChk)) { + mAng yRot = mRotation.y + 0x7FFF; + if (updateRotation != 0) { + mRotation.y = yRot; + } + tmp = mVec3_c::Ez * (mScale.x * 100); + tmp.rotY(yRot); + tmp += pos; + linChk.Set(&pos, &tmp, nullptr); + if (!dBgS::GetInstance()->LineCross(&linChk)) { + return false; + } + } + return true; +} -- cgit v1.2.3 From 71b1bfa6d1cc8873d4d40d1226b878b0fc4aee3b Mon Sep 17 00:00:00 2001 From: lepelog <25211966+lepelog@users.noreply.github.com> Date: Thu, 4 Dec 2025 14:23:16 +0100 Subject: document d_t_insect --- src/REL/d/t/d_t_insect.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/REL/d/t/d_t_insect.cpp b/src/REL/d/t/d_t_insect.cpp index 827af1e9..5976220f 100644 --- a/src/REL/d/t/d_t_insect.cpp +++ b/src/REL/d/t/d_t_insect.cpp @@ -65,8 +65,8 @@ int dTgInsect_c::actorCreate() { } } mScale *= 0.01f; - unk24C = 0; - unk260 = mPosition; + mRevealed = 0; + mRevealedSpawnPos = mPosition; // non matching: load of 0 in r0 // that is already 0 if (isTrialGateType() || isGossipStoneType() || isGoddessWallType() || isSpawnSubtype(SPAWN_BUG_MINIGAME)) { @@ -131,7 +131,7 @@ int dTgInsect_c::actorPostCreate() { } // inline vec 2 if ((warp->checkInRadius(mPosition, 1000000))) { - unk26C.link(warp); + mWarpRef.link(warp); } else { return FAILED; } @@ -170,9 +170,9 @@ void dTgInsect_c::executeState_Wait() { s32 i = 0; for (; i < mInsectCount; i++) { if (!mLinks[i].isLinked()) { - if (unk208[i] > 0) { - unk208[i]--; - } else if (unk208[i] == 0) { + if (mInsectRespanwTimers[i] > 0) { + mInsectRespanwTimers[i]--; + } else if (mInsectRespanwTimers[i] == 0) { nw4r::math::MTX34 mtx; PSMTXTrans(mtx, mPosition.x, mPosition.y, mPosition.z); nw4r::math::MTX34 scale; @@ -184,7 +184,7 @@ void dTgInsect_c::executeState_Wait() { spawnInsect(i); } } else { - unk208[i] = 900; + mInsectRespanwTimers[i] = 900; } } } @@ -195,7 +195,7 @@ void dTgInsect_c::initializeState_WaitCreate() { if (!isSpawnSubtype(SPAWN_BUG_MINIGAME)) { unk24F = 1; for (s32 i = 0; i < mInsectCount; i++) { - unk250[i] = shouldSpawn(); + mShouldSpawn[i] = shouldSpawn(); } } } @@ -204,7 +204,7 @@ void dTgInsect_c::executeState_WaitCreate() { if (mActorNode.isLinked()) { if (mActorNode.get()->mProfileName == fProfile::OBJ_VSD || mActorNode.get()->mProfileName == fProfile::OBJ_SOIL) { - if (unk24C == 0) { + if (mRevealed == 0) { return; } } else { @@ -216,16 +216,16 @@ void dTgInsect_c::executeState_WaitCreate() { mActorNode.unlink(); for (s32 i = 0; i < mInsectCount; i++) { if (!isSpawnSubtype(SPAWN_BUG_MINIGAME)) { - if (unk250[i] != 0) { - unk250[i] = 0; + if (mShouldSpawn[i] != 0) { + mShouldSpawn[i] = 0; } else { continue; } } dAcBase_c *insect = nullptr; mVec3_c tmp1 = mPosition; - if (unk24C) { - tmp1 = unk260; + if (mRevealed) { + tmp1 = mRevealedSpawnPos; } mAng3_c rot(0, cM::rndFX(65536), 0); switch (getSubtype()) { @@ -249,7 +249,7 @@ void dTgInsect_c::executeState_WaitCreate() { } if (insect != nullptr) { mLinks[i].link(insect); - unk208[i] = -1; + mInsectRespanwTimers[i] = -1; } } if (isSpawnSubtype(SPAWN_BUG_MINIGAME)) { @@ -271,8 +271,8 @@ void dTgInsect_c::initializeState_WaitForceEscape() { void dTgInsect_c::executeState_WaitForceEscape() { if (isTrialGateType()) { - if (unk26C.isLinked()) { - dAcOWarp_c *warp = static_cast(unk26C.get()); + if (mWarpRef.isLinked()) { + dAcOWarp_c *warp = static_cast(mWarpRef.get()); if (warp->fn_0x90()) { for (s32 i = 0; i < mInsectCount; i++) { if (mLinks[i].isLinked()) { @@ -282,7 +282,7 @@ void dTgInsect_c::executeState_WaitForceEscape() { } } } - } else if (isGoddessWallType() && unk24D) { + } else if (isGoddessWallType() && mKillSignal) { for (s32 i = 0; i < mInsectCount; i++) { if (mLinks[i].isLinked()) { static_cast(mLinks[i].get())->setKillSignal(); @@ -408,7 +408,7 @@ void dTgInsect_c::spawnInsect(s32 index) { } if (ref != nullptr) { mLinks[index].link(ref); - unk208[index] = -1; + mInsectRespanwTimers[index] = -1; } return; } -- cgit v1.2.3 From e995c184e15a77313da0a94e17f7cf6550448004 Mon Sep 17 00:00:00 2001 From: lepelog <25211966+lepelog@users.noreply.github.com> Date: Thu, 4 Dec 2025 14:54:25 +0100 Subject: match actorCreate --- src/REL/d/t/d_t_insect.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'src') diff --git a/src/REL/d/t/d_t_insect.cpp b/src/REL/d/t/d_t_insect.cpp index 5976220f..9b29bd9e 100644 --- a/src/REL/d/t/d_t_insect.cpp +++ b/src/REL/d/t/d_t_insect.cpp @@ -45,7 +45,6 @@ const s32 *useUnused() { return unused; } -// non matching int dTgInsect_c::actorCreate() { if (getSubtype() == 0) { return FAILED; @@ -67,8 +66,6 @@ int dTgInsect_c::actorCreate() { mScale *= 0.01f; mRevealed = 0; mRevealedSpawnPos = mPosition; - // non matching: load of 0 in r0 - // that is already 0 if (isTrialGateType() || isGossipStoneType() || isGoddessWallType() || isSpawnSubtype(SPAWN_BUG_MINIGAME)) { unk24E = 1; } -- cgit v1.2.3 From f47cb1f1f7775fd5ec9bfb881e05707be9ffa0fb Mon Sep 17 00:00:00 2001 From: lepelog <25211966+lepelog@users.noreply.github.com> Date: Thu, 4 Dec 2025 15:02:01 +0100 Subject: match initializeState_WaitForceEscape --- src/REL/d/t/d_t_insect.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/REL/d/t/d_t_insect.cpp b/src/REL/d/t/d_t_insect.cpp index 9b29bd9e..ab9d569b 100644 --- a/src/REL/d/t/d_t_insect.cpp +++ b/src/REL/d/t/d_t_insect.cpp @@ -257,11 +257,11 @@ void dTgInsect_c::executeState_WaitCreate() { } void dTgInsect_c::finalizeState_WaitCreate() {} -// non matching: regswap void dTgInsect_c::initializeState_WaitForceEscape() { for (s32 i = 0; i < mInsectCount; i++) { - if (mLinks[i].isLinked()) { - mLinks[i].get()->mActorProperties |= AC_PROP_0x4; + dAcOInsect_c* tmp = static_cast(mLinks[i].get()); + if (tmp) { + tmp->setActorProperty(AC_PROP_0x4); } } } -- cgit v1.2.3 From 24d9396bee8680b4444c62303eb8b98f38bcbd1f Mon Sep 17 00:00:00 2001 From: lepelog <25211966+lepelog@users.noreply.github.com> Date: Thu, 4 Dec 2025 16:04:26 +0100 Subject: improve spawnInsect --- src/REL/d/t/d_t_insect.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/REL/d/t/d_t_insect.cpp b/src/REL/d/t/d_t_insect.cpp index ab9d569b..4d09bf9d 100644 --- a/src/REL/d/t/d_t_insect.cpp +++ b/src/REL/d/t/d_t_insect.cpp @@ -36,13 +36,13 @@ STATE_DEFINE(dTgInsect_c, End); static const s32 unused[] = { 0x001E0100, 0, 0, 0, 0, 0, 0, 0, }; +static const f32 SCALE_X = 100; +static const f32 SCALE_Y = 100; -static const f32 different100[] = {100}; - -static const f32 WHATEVER[] = {100, 150, 0.5f}; +static const f32 unused2[] = {150, 0.5f}; const s32 *useUnused() { - return unused; + return unused + (s32)unused2; } int dTgInsect_c::actorCreate() { @@ -308,17 +308,17 @@ void dTgInsect_c::spawnAll() { // non matching: rodata is weird, using multiple different 100.0f instead of just one // also the registers are wrong void dTgInsect_c::spawnInsect(s32 index) { - s32 tries; - f32 scaledScale = 100 * mScale.y; - f32 scaled2 = mScale.x * WHATEVER[0] * 0.85f; + f32 scaledScaleY = mScale.y * SCALE_Y; + f32 scaledScaleX = SCALE_X * mScale.x * 0.85f; bool spawnFound; mVec3_c pos; mVec3_c tmp; mAng3_c rot(0, 0, 0); spawnFound = false; + s32 tries; tries = 5; do { - f32 scale = cM::rndF(scaled2); + f32 scale = cM::rndF(scaledScaleX); s16 angle1 = cM::rndFX(65536.0f); rot.y = cM::rndFX(65536.0f); mVec3_c v2 = mVec3_c::Ez * scale; @@ -333,17 +333,17 @@ void dTgInsect_c::spawnInsect(s32 index) { tmp = mVec3_c::Ez; tmp.rotY(mAng(mRotation.y + 0x4000)); f32 arrayResult = FLOAT_ARRAY[index % (s32)ARRAY_LENGTH(FLOAT_ARRAY)]; - f32 scaledX = WHATEVER[0] * mScale.x; + f32 scaledX = SCALE_X * mScale.x; tmp.multScalar(arrayResult * scaledX); pos = mPosition + tmp; - f32 scaledScale = mScale.y * 100; + f32 scaledScale = SCALE_Y * mScale.y; pos.y = mPosition.y + scaledScale * 0.3f; pos.y += cM::rndF(scaledScale * 0.5f); if (!someGroundCheck(pos, 0)) { return; } } else { - pos.y += cM::rndF(scaledScale); + pos.y += cM::rndF(scaledScaleY); } spawnFound = true; break; @@ -351,7 +351,7 @@ void dTgInsect_c::spawnInsect(s32 index) { case SUBTYPE_LANAYRU_ANT: case SUBTYPE_SKYLOFT_MANTIS: case SUBTYPE_EDLIN_ROLLER: - pos.y = different100[0] + mPosition.y; + pos.y = 100 + mPosition.y; if (dBgS_ObjGndChk::CheckPos(pos)) { spawnFound = true; } @@ -388,7 +388,7 @@ void dTgInsect_c::spawnInsect(s32 index) { break; case SUBTYPE_BUTTERFLY: ref = dAcObjBase_c::createInsectActor( - this, fProfile::INSECT_BUTTERFLY, mViewClipIdx, &pos, &rot, NULL, 0, 0x3f + this, fProfile::INSECT_BUTTERFLY, (s16)mViewClipIdx, &pos, &rot, NULL, 0, 0x3f ); break; case SUBTYPE_SKYLOFT_MANTIS: -- cgit v1.2.3 From 44ec1a000301f7b48d38bc1a6ed8180fb3b9371e Mon Sep 17 00:00:00 2001 From: lepelog <25211966+lepelog@users.noreply.github.com> Date: Thu, 4 Dec 2025 16:28:44 +0100 Subject: tmp --- src/REL/d/t/d_t_insect.cpp | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/REL/d/t/d_t_insect.cpp b/src/REL/d/t/d_t_insect.cpp index 4d09bf9d..2a9f2343 100644 --- a/src/REL/d/t/d_t_insect.cpp +++ b/src/REL/d/t/d_t_insect.cpp @@ -76,8 +76,6 @@ inline bool checkProfile(u16 prof, u32 target) { return prof == target; } -// non matching: the inline vecs from the distance checks -// are in the wrong order on the stack int dTgInsect_c::actorPostCreate() { s32 subtype = (mParams >> 4 & 0xF); // ??? doesn't match without the double comparison @@ -98,7 +96,6 @@ int dTgInsect_c::actorPostCreate() { checkProfile(prof, fProfile::OBJ_OCT_GRASS_LEAF) || checkProfile(prof, fProfile::OBJ_FRUIT) || checkProfile(prof, fProfile::OBJ_BARREL) || checkProfile(prof, fProfile::OBJ_VSD) || checkProfile(prof, fProfile::OBJ_SOIL) - // inline vec 1 ) && getSquareDistanceTo(obj->mPosition) < 25) { if (subtype == 7 || subtype == 0xB || subtype == 8 || subtype == 0xC) { @@ -126,8 +123,7 @@ int dTgInsect_c::actorPostCreate() { if (!warp->checkThisHasSongItem() || warp->isTrialComplete()) { return FAILED; } - // inline vec 2 - if ((warp->checkInRadius(mPosition, 1000000))) { + if ((warp->mPosition - mPosition).squareMagXZ() < 1000000.f) { mWarpRef.link(warp); } else { return FAILED; @@ -308,18 +304,31 @@ void dTgInsect_c::spawnAll() { // non matching: rodata is weird, using multiple different 100.0f instead of just one // also the registers are wrong void dTgInsect_c::spawnInsect(s32 index) { - f32 scaledScaleY = mScale.y * SCALE_Y; - f32 scaledScaleX = SCALE_X * mScale.x * 0.85f; - bool spawnFound; + f32 scaleX; + f32 scaleY; + f32 scaleXExt; + f32 scaleYExt; + f32 scaledScaleY; + f32 scaledScaleX; + f32 mult; + f32 scaledTemp; + scaleY = mScale.y; + scaleYExt = SCALE_Y; + scaledScaleY = scaleY * scaleYExt; + mult = 0.85f; + scaleXExt = SCALE_X; + scaleX = mScale.x; + scaledTemp = scaleXExt * scaleX; + scaledScaleX = mult * scaledTemp; + s16 angle1; mVec3_c pos; mVec3_c tmp; mAng3_c rot(0, 0, 0); - spawnFound = false; - s32 tries; - tries = 5; + bool spawnFound = false; + s32 tries = 5; do { f32 scale = cM::rndF(scaledScaleX); - s16 angle1 = cM::rndFX(65536.0f); + angle1 = cM::rndFX(65536.0f); rot.y = cM::rndFX(65536.0f); mVec3_c v2 = mVec3_c::Ez * scale; cLib::offsetPos(pos, mPosition, angle1, v2); -- cgit v1.2.3 From 940238680d29136226c8712a215bdc0e2b54d6f9 Mon Sep 17 00:00:00 2001 From: lepelog <25211966+lepelog@users.noreply.github.com> Date: Thu, 4 Dec 2025 18:41:01 +0100 Subject: d_t_insect OK --- src/REL/d/t/d_t_insect.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/REL/d/t/d_t_insect.cpp b/src/REL/d/t/d_t_insect.cpp index 2a9f2343..17c5ebd5 100644 --- a/src/REL/d/t/d_t_insect.cpp +++ b/src/REL/d/t/d_t_insect.cpp @@ -36,8 +36,8 @@ STATE_DEFINE(dTgInsect_c, End); static const s32 unused[] = { 0x001E0100, 0, 0, 0, 0, 0, 0, 0, }; -static const f32 SCALE_X = 100; -static const f32 SCALE_Y = 100; +const f32 dTgInsect_c::SCALE_X = 100; +const f32 dTgInsect_c::SCALE_Y = 100; static const f32 unused2[] = {150, 0.5f}; @@ -156,8 +156,22 @@ int dTgInsect_c::actorPostCreate() { return SUCCEEDED; } +int dTgInsect_c::doDelete() { + return SUCCEEDED; +} + +int dTgInsect_c::actorExecute() { + mStateMgr.executeState(); + return SUCCEEDED; +} + +int dTgInsect_c::draw() { + return SUCCEEDED; +} + void dTgInsect_c::initializeState_Wait() {} +#pragma opt_strength_reduction off void dTgInsect_c::executeState_Wait() { if (isSpawnSubtype(SPAWN_BUG_MINIGAME)) { s32 i = 0; @@ -183,6 +197,7 @@ void dTgInsect_c::executeState_Wait() { } } } +#pragma opt_strength_reduction on void dTgInsect_c::finalizeState_Wait() {} void dTgInsect_c::initializeState_WaitCreate() { if (!isSpawnSubtype(SPAWN_BUG_MINIGAME)) { @@ -192,7 +207,6 @@ void dTgInsect_c::initializeState_WaitCreate() { } } } -#pragma opt_strength_reduction on void dTgInsect_c::executeState_WaitCreate() { if (mActorNode.isLinked()) { if (mActorNode.get()->mProfileName == fProfile::OBJ_VSD || @@ -443,7 +457,7 @@ bool dTgInsect_c::shouldSpawn() { } bool dTgInsect_c::someGroundCheck(const mVec3_c &pos, s32 updateRotation) { - mVec3_c tmp = mVec3_c::Ez * (mScale.x * 100); + mVec3_c tmp = mVec3_c::Ez * (SCALE_X * mScale.x); tmp.rotY(mRotation.y); tmp += pos; dBgS_LinChk linChk; @@ -455,7 +469,7 @@ bool dTgInsect_c::someGroundCheck(const mVec3_c &pos, s32 updateRotation) { if (updateRotation != 0) { mRotation.y = yRot; } - tmp = mVec3_c::Ez * (mScale.x * 100); + tmp = mVec3_c::Ez * (SCALE_X * mScale.x); tmp.rotY(yRot); tmp += pos; linChk.Set(&pos, &tmp, nullptr); @@ -465,3 +479,7 @@ bool dTgInsect_c::someGroundCheck(const mVec3_c &pos, s32 updateRotation) { } return true; } + +void moreUnused() { + static const s32 a = 0x3a; +} -- cgit v1.2.3 From 30b1ef36591e4bc1f8ad2bdf0e4ee989b64ca8df Mon Sep 17 00:00:00 2001 From: lepelog <25211966+lepelog@users.noreply.github.com> Date: Thu, 4 Dec 2025 23:19:05 +0100 Subject: review --- src/REL/d/t/d_t_insect.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/REL/d/t/d_t_insect.cpp b/src/REL/d/t/d_t_insect.cpp index 17c5ebd5..d430c313 100644 --- a/src/REL/d/t/d_t_insect.cpp +++ b/src/REL/d/t/d_t_insect.cpp @@ -77,9 +77,13 @@ inline bool checkProfile(u16 prof, u32 target) { } int dTgInsect_c::actorPostCreate() { - s32 subtype = (mParams >> 4 & 0xF); + s32 subtype = mParams >> 4 & 0xF; // ??? doesn't match without the double comparison - if (subtype == 5 || subtype == 5 || subtype == 6 || subtype == 3 || subtype == 9) { + if (subtype == SUBTYPE_WOODLAND_RHINO_BEETLE + || subtype == SUBTYPE_WOODLAND_RHINO_BEETLE + || subtype == SUBTYPE_SAND_CICADA + || subtype == SUBTYPE_VOLCANIC_LADYBUG + || subtype == SUBTYPE_SKY_STAG_BEETLE) { if (!someGroundCheck(mPosition, 1)) { return FAILED; } @@ -136,8 +140,7 @@ int dTgInsect_c::actorPostCreate() { if (!StoryflagManager::sInstance->getFlag(STORYFLAG_IMPRISONED_1_DEFEATED)) { return FAILED; } - bool flag = SceneflagManager::sInstance->checkFlag(mRoomID, mParams >> 0xC & 0xFF); - if (flag) { + if (SceneflagManager::sInstance->checkBoolFlag(mRoomID, mParams >> 0xC & 0xFF)) { return FAILED; } } else if (isGoddessWallType()) { @@ -315,8 +318,6 @@ void dTgInsect_c::spawnAll() { } } -// non matching: rodata is weird, using multiple different 100.0f instead of just one -// also the registers are wrong void dTgInsect_c::spawnInsect(s32 index) { f32 scaleX; f32 scaleY; @@ -437,8 +438,7 @@ bool dTgInsect_c::shouldSpawn() { if (isSpawnSubtype(SPAWN_BUG_MINIGAME)) { return true; } else if (isSpawnSubtype(SPAWN_SKYLOFT_BUGKID_TREE)) { - bool tmp = SceneflagManager::sInstance->checkFlag(mRoomID, 0x3a); - return !tmp; + return !SceneflagManager::sInstance->checkBoolFlag(mRoomID, 0x3a); } else { if (isTrialGateType()) { return true; -- cgit v1.2.3 From f0889aadb67d0b7295759e00f571ea221fffe204 Mon Sep 17 00:00:00 2001 From: lepelog <25211966+lepelog@users.noreply.github.com> Date: Thu, 4 Dec 2025 23:26:13 +0100 Subject: properly use subtype enum --- src/REL/d/t/d_t_insect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/REL/d/t/d_t_insect.cpp b/src/REL/d/t/d_t_insect.cpp index d430c313..19fd7333 100644 --- a/src/REL/d/t/d_t_insect.cpp +++ b/src/REL/d/t/d_t_insect.cpp @@ -77,7 +77,7 @@ inline bool checkProfile(u16 prof, u32 target) { } int dTgInsect_c::actorPostCreate() { - s32 subtype = mParams >> 4 & 0xF; + Subtype subtype = getSubtype(); // ??? doesn't match without the double comparison if (subtype == SUBTYPE_WOODLAND_RHINO_BEETLE || subtype == SUBTYPE_WOODLAND_RHINO_BEETLE -- cgit v1.2.3 From ad47fd3eb383679d9b502323cd8cbdc3434c10ba Mon Sep 17 00:00:00 2001 From: lepelog <25211966+lepelog@users.noreply.github.com> Date: Fri, 5 Dec 2025 10:49:39 +0100 Subject: review --- src/REL/d/t/d_t_insect.cpp | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/REL/d/t/d_t_insect.cpp b/src/REL/d/t/d_t_insect.cpp index 19fd7333..125387f8 100644 --- a/src/REL/d/t/d_t_insect.cpp +++ b/src/REL/d/t/d_t_insect.cpp @@ -46,13 +46,13 @@ const s32 *useUnused() { } int dTgInsect_c::actorCreate() { - if (getSubtype() == 0) { + if (getSubtype() == SUBTYPE_INVALID0) { return FAILED; } - if (getSubtype() == 1) { + if (getSubtype() == SUBTYPE_INVALID1) { return FAILED; } - if (getSubtype() == 2) { + if (getSubtype() == SUBTYPE_INVALID2) { return FAILED; } mInsectCount = getInsectCount(); @@ -67,7 +67,7 @@ int dTgInsect_c::actorCreate() { mRevealed = 0; mRevealedSpawnPos = mPosition; if (isTrialGateType() || isGossipStoneType() || isGoddessWallType() || isSpawnSubtype(SPAWN_BUG_MINIGAME)) { - unk24E = 1; + field_0x24e = 1; } return SUCCEEDED; } @@ -84,7 +84,7 @@ int dTgInsect_c::actorPostCreate() { || subtype == SUBTYPE_SAND_CICADA || subtype == SUBTYPE_VOLCANIC_LADYBUG || subtype == SUBTYPE_SKY_STAG_BEETLE) { - if (!someGroundCheck(mPosition, 1)) { + if (!checkValidSpawnLocation(mPosition, 1)) { return FAILED; } } @@ -102,7 +102,10 @@ int dTgInsect_c::actorPostCreate() { checkProfile(prof, fProfile::OBJ_SOIL) ) && getSquareDistanceTo(obj->mPosition) < 25) { - if (subtype == 7 || subtype == 0xB || subtype == 8 || subtype == 0xC) { + if (subtype == SUBTYPE_FARON_GRASSHOPPER + || subtype == SUBTYPE_SKYLOFT_MANTIS + || subtype == SUBTYPE_LANAYRU_ANT + || subtype == SUBTYPE_EDLIN_ROLLER) { if (prof == fProfile::OBJ_SOIL && static_cast(obj)->isStateHole()) { return FAILED; } @@ -115,8 +118,8 @@ int dTgInsect_c::actorPostCreate() { mStateMgr.changeState(StateID_WaitCreate); } else { if (isSpawnSubtype(SPAWN_BUG_MINIGAME)) { - for (s32 i = 0; i < 16; i++) { - unk1F8[i] = 0; + for (s32 i = 0; i < (s32)ARRAY_LENGTH(field_0x1f8); i++) { + field_0x1f8[i] = 0; } mStateMgr.changeState(StateID_Wait); } else if (isTrialGateType()) { @@ -180,9 +183,9 @@ void dTgInsect_c::executeState_Wait() { s32 i = 0; for (; i < mInsectCount; i++) { if (!mLinks[i].isLinked()) { - if (mInsectRespanwTimers[i] > 0) { - mInsectRespanwTimers[i]--; - } else if (mInsectRespanwTimers[i] == 0) { + if (mInsectRespawnTimers[i] > 0) { + mInsectRespawnTimers[i]--; + } else if (mInsectRespawnTimers[i] == 0) { nw4r::math::MTX34 mtx; PSMTXTrans(mtx, mPosition.x, mPosition.y, mPosition.z); nw4r::math::MTX34 scale; @@ -194,7 +197,7 @@ void dTgInsect_c::executeState_Wait() { spawnInsect(i); } } else { - mInsectRespanwTimers[i] = 900; + mInsectRespawnTimers[i] = 900; } } } @@ -204,7 +207,7 @@ void dTgInsect_c::executeState_Wait() { void dTgInsect_c::finalizeState_Wait() {} void dTgInsect_c::initializeState_WaitCreate() { if (!isSpawnSubtype(SPAWN_BUG_MINIGAME)) { - unk24F = 1; + field_0x24f = 1; for (s32 i = 0; i < mInsectCount; i++) { mShouldSpawn[i] = shouldSpawn(); } @@ -259,7 +262,7 @@ void dTgInsect_c::executeState_WaitCreate() { } if (insect != nullptr) { mLinks[i].link(insect); - mInsectRespanwTimers[i] = -1; + mInsectRespawnTimers[i] = -1; } } if (isSpawnSubtype(SPAWN_BUG_MINIGAME)) { @@ -363,7 +366,7 @@ void dTgInsect_c::spawnInsect(s32 index) { f32 scaledScale = SCALE_Y * mScale.y; pos.y = mPosition.y + scaledScale * 0.3f; pos.y += cM::rndF(scaledScale * 0.5f); - if (!someGroundCheck(pos, 0)) { + if (!checkValidSpawnLocation(pos, 0)) { return; } } else { @@ -429,7 +432,7 @@ void dTgInsect_c::spawnInsect(s32 index) { } if (ref != nullptr) { mLinks[index].link(ref); - mInsectRespanwTimers[index] = -1; + mInsectRespawnTimers[index] = -1; } return; } @@ -456,7 +459,7 @@ bool dTgInsect_c::shouldSpawn() { } } -bool dTgInsect_c::someGroundCheck(const mVec3_c &pos, s32 updateRotation) { +bool dTgInsect_c::checkValidSpawnLocation(const mVec3_c &pos, bool updateRotation) { mVec3_c tmp = mVec3_c::Ez * (SCALE_X * mScale.x); tmp.rotY(mRotation.y); tmp += pos; @@ -466,7 +469,7 @@ bool dTgInsect_c::someGroundCheck(const mVec3_c &pos, s32 updateRotation) { linChk.Set(&pos, &tmp, nullptr); if (!dBgS::GetInstance()->LineCross(&linChk)) { mAng yRot = mRotation.y + 0x7FFF; - if (updateRotation != 0) { + if (updateRotation) { mRotation.y = yRot; } tmp = mVec3_c::Ez * (SCALE_X * mScale.x); -- cgit v1.2.3