Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MapObj: Implement FurnitureStateWait #280

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions data/odyssey_functions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
99 changes: 99 additions & 0 deletions src/MapObj/FurnitureStateWait.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
37 changes: 37 additions & 0 deletions src/MapObj/FurnitureStateWait.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <basis/seadTypes.h>
#include <math/seadVector.h>

#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;
};
2 changes: 1 addition & 1 deletion tools/check-format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
Loading