mirror of
https://github.com/zeldaret/botw
synced 2026-06-25 09:22:29 -04:00
ksys/act: Start adding Ai
This commit is contained in:
@@ -25,6 +25,8 @@ target_sources(uking PRIVATE
|
||||
actAiAction.h
|
||||
actAiActionBase.cpp
|
||||
actAiActionBase.h
|
||||
actAiAi.cpp
|
||||
actAiAi.h
|
||||
actAiClassDef.cpp
|
||||
actAiClassDef.h
|
||||
actAiParam.cpp
|
||||
|
||||
@@ -31,8 +31,8 @@ public:
|
||||
const char* getName() const;
|
||||
bool init(sead::Heap* heap, bool load_map_or_tree_params);
|
||||
|
||||
virtual bool isFinished() const;
|
||||
virtual bool isFailed() const;
|
||||
virtual bool isFinished() const;
|
||||
virtual bool isFlag4Set() const;
|
||||
|
||||
virtual bool m7() { return false; }
|
||||
@@ -52,13 +52,13 @@ public:
|
||||
virtual void getCurrentName(sead::BufferedSafeString* name, ActionBase* parent) const;
|
||||
virtual void* m22() { return nullptr; }
|
||||
virtual void getParams(ParamNameTypePairs* pairs, bool update_use_count) const;
|
||||
virtual s32 m24() { return 0; }
|
||||
virtual s32 getNumChildren() const { return 0; }
|
||||
virtual bool m25() { return true; }
|
||||
virtual ActionBase* getCurrentChild() const { return nullptr; }
|
||||
virtual bool isAction() const = 0;
|
||||
virtual bool reenter(ActionBase* other) { return reenter_(other, false); }
|
||||
virtual void postLeave() {}
|
||||
virtual ActionBase* getAction(s32 idx) const { return nullptr; }
|
||||
virtual ActionBase* getChild(s32 idx) const { return nullptr; }
|
||||
|
||||
protected:
|
||||
enum class Flag : u8 {
|
||||
@@ -83,8 +83,6 @@ protected:
|
||||
u16 mDefinitionIdx;
|
||||
u8 mRootIdx;
|
||||
sead::TypedBitFlag<Flag> mFlags;
|
||||
u16 mClassIdx;
|
||||
u16 mPrevClassIdx;
|
||||
};
|
||||
KSYS_CHECK_SIZE_NX150(ActionBase, 0x20);
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
#include "KingSystem/ActorSystem/actAiAi.h"
|
||||
|
||||
namespace ksys::act::ai {
|
||||
|
||||
Ai::Ai(const ActionBase::InitArg& arg) : ActionBase(arg) {}
|
||||
|
||||
Ai::~Ai() {
|
||||
mChildren.freeBuffer();
|
||||
}
|
||||
|
||||
void Ai::calc() {
|
||||
calc_();
|
||||
|
||||
auto* child = getCurrentChild();
|
||||
if (child)
|
||||
child->calc();
|
||||
|
||||
if (mPendingChildIdx != InvalidIdx && mChildIdx != mPendingChildIdx) {
|
||||
handlePendingChildChange_();
|
||||
auto* new_child = getCurrentChild();
|
||||
if (new_child)
|
||||
new_child->calc();
|
||||
}
|
||||
}
|
||||
|
||||
bool Ai::isFlag4Set() const {
|
||||
auto* child = getCurrentChild();
|
||||
if (child)
|
||||
return child->isFlag4Set();
|
||||
|
||||
return mFlags.isOn(Flag::_4);
|
||||
}
|
||||
|
||||
ActionBase* Ai::getCurrentChild() const {
|
||||
if (mChildIdx == InvalidIdx)
|
||||
return nullptr;
|
||||
return mChildren[mChildIdx];
|
||||
}
|
||||
|
||||
void Ai::updateChildIdx(u16 new_idx) {
|
||||
const auto prev_idx = mChildIdx;
|
||||
mChildIdx = new_idx;
|
||||
mPrevChildIdx = prev_idx;
|
||||
mPendingChildIdx = InvalidIdx;
|
||||
}
|
||||
|
||||
} // namespace ksys::act::ai
|
||||
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <container/seadBuffer.h>
|
||||
#include "KingSystem/ActorSystem/actAiActionBase.h"
|
||||
|
||||
namespace ksys::act::ai {
|
||||
|
||||
class Ai : public ActionBase {
|
||||
SEAD_RTTI_OVERRIDE(Ai, ActionBase)
|
||||
public:
|
||||
explicit Ai(const InitArg& arg);
|
||||
~Ai() override;
|
||||
|
||||
bool isFlag4Set() const override;
|
||||
bool reenter_(ActionBase* other, bool x) override;
|
||||
void calc() override;
|
||||
void* m22() override;
|
||||
void getParams(ParamNameTypePairs* pairs, bool update_use_count) const override;
|
||||
s32 getNumChildren() const override { return mChildren.size(); }
|
||||
bool m25() override;
|
||||
ActionBase* getCurrentChild() const override;
|
||||
bool isAction() const override { return false; }
|
||||
bool reenter(ActionBase* other) override;
|
||||
void postLeave() override { updateChildIdx(InvalidIdx); }
|
||||
ActionBase* getChild(s32 idx) const override { return mChildren[idx]; }
|
||||
virtual const char* getPreviousName();
|
||||
|
||||
protected:
|
||||
virtual void calc_() {}
|
||||
virtual void handlePendingChildChange_() { changeChildState(mPendingChildIdx); }
|
||||
void updateChildIdx(u16 new_idx);
|
||||
void changeChildState(u16 idx, InlineParamPack* params = nullptr);
|
||||
|
||||
static constexpr u16 InvalidIdx = 0xffff;
|
||||
|
||||
// TODO: give better names to these variables
|
||||
u16 mChildIdx = InvalidIdx;
|
||||
u16 mPrevChildIdx = InvalidIdx;
|
||||
u16 mPendingChildIdx = InvalidIdx;
|
||||
u16 mNewChildIdx = InvalidIdx;
|
||||
sead::Buffer<ActionBase*> mChildren;
|
||||
};
|
||||
KSYS_CHECK_SIZE_NX150(Ai, 0x38);
|
||||
|
||||
} // namespace ksys::act::ai
|
||||
Reference in New Issue
Block a user