summaryrefslogtreecommitdiff
path: root/src/Game/Actor/AI/aiActorWaterDepthSelect.cpp
blob: 50d437cac861067a7df1dd4387f10e578b3f38ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "Game/Actor/AI/aiActorWaterDepthSelect.h"
#include "KingSystem/ActorSystem/actActor.h"

namespace uking::ai {

ActorWaterDepthSelect::ActorWaterDepthSelect(const InitArg& arg) : ksys::act::ai::Ai(arg) {}

ActorWaterDepthSelect::~ActorWaterDepthSelect() = default;

bool ActorWaterDepthSelect::isChangeable() const {
    return getCurrentChild()->isChangeable();
}

bool ActorWaterDepthSelect::isFailed() const {
    return getCurrentChild()->isFailed();
}

bool ActorWaterDepthSelect::isFinished() const {
    return getCurrentChild()->isFinished();
}

bool ActorWaterDepthSelect::init_(sead::Heap* heap) {
    return true;
}

void ActorWaterDepthSelect::enter_(ksys::act::ai::InlineParamPack* params) {
    if (isDeep() && isUnderwater()) {
        changeChild("深瀬", params);
    } else {
        changeChild("浅瀬", params);
    }
}

void ActorWaterDepthSelect::calc_() {
    if (*mOnEnterOnly_s)
        return;

    auto is_deep = isDeep() && isUnderwater();
    if (*mForceDeepChange_s && is_deep) {
        if (!isCurrentChild("深瀬")) {
            changeChild("深瀬");
            return;
        }
    }

    if (getCurrentChild()->isChangeable()) {
        if (is_deep && !isCurrentChild("深瀬"))
            changeChild("深瀬");
        else if (!is_deep && !isCurrentChild("浅瀬"))
            changeChild("浅瀬");
    }
}

void ActorWaterDepthSelect::leave_() {
    ksys::act::ai::Ai::leave_();
}

void ActorWaterDepthSelect::loadParams_() {
    getStaticParam(&mDeepDepth_s, "DeepDepth");
    getStaticParam(&mOnEnterOnly_s, "OnEnterOnly");
    getStaticParam(&mForceDeepChange_s, "ForceDeepChange");
}

bool ActorWaterDepthSelect::isDeep() const {
    return 0.0 < *mDeepDepth_s && mActor->get68f().load();
}

bool ActorWaterDepthSelect::isUnderwater() const {
    float y_w = mActor->getMtx().m[1][3];
    return mActor->get6f0() - y_w > *mDeepDepth_s;
}

}  // namespace uking::ai