From 39738233f87d0ca0d6783b4f89218433f1bad906 Mon Sep 17 00:00:00 2001 From: Naii-the-Baf Date: Wed, 15 Jan 2025 10:24:27 -0600 Subject: [PATCH 1/2] MapObj: Implement FurnitureStateWait --- data/odyssey_functions.csv | 16 ++--- src/MapObj/FurnitureStateWait.cpp | 99 +++++++++++++++++++++++++++++++ src/MapObj/FurnitureStateWait.h | 37 ++++++++++++ 3 files changed, 144 insertions(+), 8 deletions(-) create mode 100644 src/MapObj/FurnitureStateWait.cpp create mode 100644 src/MapObj/FurnitureStateWait.h diff --git a/data/odyssey_functions.csv b/data/odyssey_functions.csv index fb417229..92cdc26c 100644 --- a/data/odyssey_functions.csv +++ b/data/odyssey_functions.csv @@ -15983,14 +15983,14 @@ Address,Quality,Size,Name 0x000000710028b688,U,000072,_ZN26FukankunZoomTargetFunction35declareWatchFukankunZoomTargetActorEPK8Fukankuni 0x000000710028b6d0,U,000012,_ZNK21FukankunZoomObjHolder15getSceneObjNameEv 0x000000710028b6dc,U,000004,_ZN21FukankunZoomObjHolderD0Ev -0x000000710028b6e0,U,000120,_ZN18FurnitureStateWaitC1EPN2al9LiveActorE13FurnitureType -0x000000710028b758,U,000072,_ZN18FurnitureStateWait6appearEv -0x000000710028b7a0,U,000016,_ZNK18FurnitureStateWait19isEnableBindRequestEv -0x000000710028b7b0,U,000500,_ZN18FurnitureStateWait7exeWaitEv -0x000000710028b9a4,U,000124,_ZN18FurnitureStateWait14exeBindRequestEv -0x000000710028ba20,U,000036,_ZN18FurnitureStateWaitD0Ev -0x000000710028ba44,U,000008,_ZNK12_GLOBAL__N_125FurnitureStateWaitNrvWait7executeEPN2al11NerveKeeperE -0x000000710028ba4c,U,000124,_ZNK12_GLOBAL__N_132FurnitureStateWaitNrvBindRequest7executeEPN2al11NerveKeeperE +0x000000710028b6e0,O,000120,_ZN18FurnitureStateWaitC1EPN2al9LiveActorE13FurnitureType +0x000000710028b758,O,000072,_ZN18FurnitureStateWait6appearEv +0x000000710028b7a0,O,000016,_ZNK18FurnitureStateWait19isEnableBindRequestEv +0x000000710028b7b0,O,000500,_ZN18FurnitureStateWait7exeWaitEv +0x000000710028b9a4,O,000124,_ZN18FurnitureStateWait14exeBindRequestEv +0x000000710028ba20,O,000036,_ZN18FurnitureStateWaitD0Ev +0x000000710028ba44,O,000008,_ZNK12_GLOBAL__N_125FurnitureStateWaitNrvWait7executeEPN2al11NerveKeeperE +0x000000710028ba4c,O,000124,_ZNK12_GLOBAL__N_132FurnitureStateWaitNrvBindRequest7executeEPN2al11NerveKeeperE 0x000000710028bac8,U,000184,_ZN8GoalMarkC2EPKc 0x000000710028bb80,U,000196,_ZN8GoalMarkC1EPKc 0x000000710028bc44,U,000588,_ZN8GoalMark4initERKN2al13ActorInitInfoE diff --git a/src/MapObj/FurnitureStateWait.cpp b/src/MapObj/FurnitureStateWait.cpp new file mode 100644 index 00000000..65f8e3a2 --- /dev/null +++ b/src/MapObj/FurnitureStateWait.cpp @@ -0,0 +1,99 @@ +#include "MapObj/FurnitureStateWait.h" + +#include "Library/LiveActor/ActorPoseKeeper.h" +#include "Library/Math/MathAngleUtil.h" +#include "Library/Nerve/NerveSetupUtil.h" +#include "Library/Nerve/NerveUtil.h" + +#include "Util/PlayerCollisionUtil.h" +#include "Util/PlayerUtil.h" + +namespace { +NERVE_IMPL(FurnitureStateWait, Wait); +NERVE_IMPL(FurnitureStateWait, BindRequest); + +NERVES_MAKE_STRUCT(FurnitureStateWait, Wait, BindRequest); +} // namespace + +FurnitureStateWait::FurnitureStateWait(al::LiveActor* actor, FurnitureType furniture) + : al::ActorStateBase("待機", actor), mFurnitureType(furniture) { + initNerve(&NrvFurnitureStateWait.Wait, 0); +} + +void FurnitureStateWait::appear() { + setDead(false); + al::setNerve(this, &NrvFurnitureStateWait.Wait); + mIsPlayerNotOnGround = !rs::isPlayerOnGround(mActor); + mPlayerState = PlayerFurnitureState::Unbound; +} + +bool FurnitureStateWait::isEnableBindRequest() const { + return al::isNerve(this, &NrvFurnitureStateWait.BindRequest); +} + +void FurnitureStateWait::exeWait() { + al::LiveActor* actor = mActor; + + if (al::isFirstStep(this)) + mPlayerPos = rs::getPlayerPos(actor); + + bool isPlayerNoInput = rs::isPlayerNoInput(actor); + FurnitureType furniture = mFurnitureType; + bool isPlayerOnSomething = false; + + if (rs::isPlayerNoInput(actor)) { + if (furniture == FurnitureType::Chair) + isPlayerOnSomething = rs::isPlayerOnChairActor(actor); + if (furniture == FurnitureType::Bed) + isPlayerOnSomething = rs::isPlayerOnBedActor(actor); + } + + bool isPlayerOnGround = rs::isPlayerOnGround(actor); + const sead::Vector3f& newPlayerPos = rs::getPlayerPos(actor); + bool isPlayerStationary = al::isNearZero(mPlayerPos - newPlayerPos, 0.001f); + mPlayerPos = newPlayerPos; + + if (!isPlayerOnSomething || !isPlayerNoInput || !isPlayerStationary) { + mIsPlayerNotOnGround = !isPlayerOnGround; + al::setNerve(this, &NrvFurnitureStateWait.Wait); + return; + } + if (mIsPlayerNotOnGround) { + sead::Vector3f frontDir = sead::Vector3f::zero; + rs::calcPlayerFrontDir(&frontDir, actor); + sead::Vector3f plane = sead::Vector3f::zero; + al::calcFrontDir(&plane, actor); + f32 angle = al::calcAngleOnPlaneDegree(frontDir, plane, sead::Vector3f::ey); + + if (90.0f < sead::Mathf::abs(angle)) + mPlayerState = PlayerFurnitureState::AirNotFacing; + else + mPlayerState = PlayerFurnitureState::AirFacing; + mIsPlayerNotOnGround = false; + return; + } + + s32 waitTime = (mFurnitureType == FurnitureType::Chair) ? 30 : 120; + if (al::isGreaterEqualStep(this, waitTime)) { + mPlayerState = PlayerFurnitureState::Bound; + al::setNerve(this, &NrvFurnitureStateWait.BindRequest); + } +} + +void FurnitureStateWait::exeBindRequest() { + al::LiveActor* actor = mActor; + FurnitureType furniture = mFurnitureType; + + if (!rs::isPlayerNoInput(actor)) { + al::setNerve(this, &NrvFurnitureStateWait.Wait); + return; + } + + bool isPlayerOnSomething = false; + if (furniture == FurnitureType::Bed) + isPlayerOnSomething = rs::isPlayerOnBedActor(actor); + if (furniture == FurnitureType::Chair) + isPlayerOnSomething = rs::isPlayerOnChairActor(actor); + if (!isPlayerOnSomething) + al::setNerve(this, &NrvFurnitureStateWait.Wait); +} diff --git a/src/MapObj/FurnitureStateWait.h b/src/MapObj/FurnitureStateWait.h new file mode 100644 index 00000000..6ff100c1 --- /dev/null +++ b/src/MapObj/FurnitureStateWait.h @@ -0,0 +1,37 @@ +#pragma once + +#include +#include + +#include "Library/Nerve/NerveStateBase.h" + +namespace al { +class LiveActor; +} // namespace al + +enum class FurnitureType : u64 { + Chair = 0, + Bed = 1, +}; + +enum class PlayerFurnitureState : u32 { + AirFacing = 0, + AirNotFacing = 1, + Bound = 2, + Unbound = 3, +}; + +class FurnitureStateWait : public al::ActorStateBase { +public: + FurnitureStateWait(al::LiveActor* actor, FurnitureType furniture); + void appear() override; + bool isEnableBindRequest() const; + void exeWait(); + void exeBindRequest(); + +private: + FurnitureType mFurnitureType : 32; + PlayerFurnitureState mPlayerState = PlayerFurnitureState::Unbound; + bool mIsPlayerNotOnGround = false; + sead::Vector3f mPlayerPos = sead::Vector3f::zero; +}; From 044df8ae1d6b1321c0df6f463a00835e73435ce0 Mon Sep 17 00:00:00 2001 From: Naii-the-Baf Date: Mon, 20 Jan 2025 18:25:02 -0600 Subject: [PATCH 2/2] Tools: Fix linter --- tools/check-format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/check-format.py b/tools/check-format.py index 9e29efa7..aa28fa8d 100755 --- a/tools/check-format.py +++ b/tools/check-format.py @@ -376,7 +376,7 @@ def header_check_line(line, path, visibility, should_start_class): if newline.endswith("]"): newline = newline.split("[")[0].strip() - var_name = newline.split(" ")[-1] + var_name = newline.split(" : ")[0].split(" ")[-1] var_type = " ".join(newline.split(" ")[0:-1]) if var_type.startswith("enum"):