diff --git a/include/d/a/d_a_base.h b/include/d/a/d_a_base.h index b705940e..2a6ca355 100644 --- a/include/d/a/d_a_base.h +++ b/include/d/a/d_a_base.h @@ -93,13 +93,13 @@ protected: public: /* 8002c3b0 */ dAcBase_c(); - void setPostion(mVec3_c &r) { + void setPostion(const mVec3_c &r) { position = r; } - void SetScale(mVec3_c &r) { + void SetScale(const mVec3_c &r) { scale = r; } - void SetRotation(mAng3_c &r) { + void SetRotation(const mAng3_c &r) { rotation = r; } @@ -113,8 +113,17 @@ public: void copyRotation() { rot_copy = rotation; } - mVec3_c GetPostionDifference(const dAcBase_c *other) { - return position - other->position; + mVec3_c GetPostionDifference(const dAcBase_c &other) { + return position - other.position; + } + + f32 getSquareDistanceTo(const mVec3_c &point) { + mVec3_c diff = position - point; + return diff.x * diff.x + diff.z * diff.z; + } + + bool IsOutOfRange(const mVec3_c &point, f32 radius) { + return getSquareDistanceTo(point) > radius; } public: diff --git a/include/d/a/obj/d_a_obj_base.h b/include/d/a/obj/d_a_obj_base.h index 6346bda8..a30ed79a 100644 --- a/include/d/a/obj/d_a_obj_base.h +++ b/include/d/a/obj/d_a_obj_base.h @@ -2,8 +2,9 @@ #define D_A_OBJ_BASE_H #include "d/a/d_a_base.h" -#include "m/types_m.h" #include "m/m_mtx.h" +#include "m/types_m.h" + // Ghidra: ActorObjectBase // size: 0x330 diff --git a/src/REL/d/a/d_a_t_wood_area.cpp b/src/REL/d/a/d_a_t_wood_area.cpp index 2af6e24b..32caa365 100644 --- a/src/REL/d/a/d_a_t_wood_area.cpp +++ b/src/REL/d/a/d_a_t_wood_area.cpp @@ -24,19 +24,32 @@ public: void dropItems(); bool attachObject(dAcObjBase_c *obj); - inline f32 getAttachRadius() { - return scale.x * 100.0f; + f32 getAttachRadius() { + return scale.x * scaleX; + } + f32 getAttachRadiusSquare() { + return getAttachRadius() * getAttachRadius(); + } + + f32 getAttachHeight() { + return scale.y * scaleY; } STATE_FUNC_DECLARE(dAcTWoodArea_c, Init); STATE_FUNC_DECLARE(dAcTWoodArea_c, Wait); + static const f32 scaleX; + static const f32 scaleY; + private: STATE_MGR_DECLARE(dAcTWoodArea_c); fLiNdBa_Wood_c mRefs[8]; }; +const f32 dAcTWoodArea_c::scaleX = 100.0f; +const f32 dAcTWoodArea_c::scaleY = 100.0f; + SPECIAL_ACTOR_PROFILE(TAG_WOOD_AREA, dAcTWoodArea_c, fProfile::WOODAREA_TAG, 0x166, 0, 2); STATE_DEFINE(dAcTWoodArea_c, Init); @@ -45,13 +58,8 @@ STATE_DEFINE(dAcTWoodArea_c, Wait); int dAcTWoodArea_c::actorCreate() { mStateMgr.changeState(StateID_Init); PSMTXTrans(worldMatrix.m, position.x, position.y, position.z); - boundingBox.min.x = -0.0f; - boundingBox.min.y = -0.0f; - boundingBox.min.z = -0.0f; - boundingBox.max.x = 0.0f; - boundingBox.max.y = 0.0f; - boundingBox.max.z = 0.0f; - // Fun dead stores to stack here + boundingBox.min = mVec3_c(-0.0f, -0.0f, -0.0f); + boundingBox.max = mVec3_c(0.0f, 0.0f, 0.0f); return 1; } @@ -103,7 +111,7 @@ void dAcTWoodArea_c::executeState_Wait() { bool someEffectThing = subtype != 1 ? (params & 0xF) != 0 ? false : true : true; if (someEffectThing) { fn_800298B0(PARTICLE_RESOURCE_ID_MAPPING[8], - &mVec3_c(position.x, position.y + scale.y * 100.0f, position.z), nullptr, 0, 0, 0, 0, 0); + &mVec3_c(position.x, position.y + getAttachHeight(), position.z), nullptr, 0, 0, 0, 0, 0); } dropItems(); } @@ -112,10 +120,8 @@ void dAcTWoodArea_c::executeState_Wait() { void dAcTWoodArea_c::finalizeState_Wait() {} void dAcTWoodArea_c::attachCloseObjects(ProfileName profID) { - // TODO FPR regshuffle - f32 dist = getAttachRadius(); - dist = dist * dist; fBase_c *base = nullptr; + f32 attachRadius = getAttachRadius() * getAttachRadius(); while (true) { base = fManager_c::searchBaseByProfName(profID, base); if (base == nullptr) { @@ -123,14 +129,11 @@ void dAcTWoodArea_c::attachCloseObjects(ProfileName profID) { } dAcObjBase_c *obj = static_cast(base); - if (!obj->canBeLinkedToWoodTag()) { - continue; - } - - mVec3_c diff = obj->position - position; - if (!(diff.x * diff.x + diff.z * diff.z > dist)) { - if (!attachObject(obj)) { - return; + if (obj->canBeLinkedToWoodTag()) { + if (!(obj->getSquareDistanceTo(position) > attachRadius)) { + if (!attachObject(obj)) { + return; + } } } } diff --git a/src/d/a/d_a_base.cpp b/src/d/a/d_a_base.cpp index 770ce347..ddcf28f7 100644 --- a/src/d/a/d_a_base.cpp +++ b/src/d/a/d_a_base.cpp @@ -393,8 +393,8 @@ bool dAcBase_c::getDistanceAndAngleToActor(dAcBase_c *actor, f32 distThresh, s16 // 8002d3e0 bool dAcBase_c::isWithinPlayerRadius(f32 radius) { - mVec3_c dist_diff = GetPostionDifference(dPlayer::LINK); - return dist_diff.x * dist_diff.x + dist_diff.z * dist_diff.z < radius * radius; + f32 dist_diff = getSquareDistanceTo(dPlayer::LINK->position); + return dist_diff < radius * radius; } // 8002d440