diff options
| author | Léo Lam <leo@leolam.fr> | 2026-09-28 03:39:31 +0200 |
|---|---|---|
| committer | Léo Lam <leo@leolam.fr> | 2026-10-13 03:33:27 +0200 |
| commit | ea13bac74ad136aeb3dde81f07ccd62622be94ad (patch) | |
| tree | 6ce7dd47659a2513c0f25236d49aa7953e354e0f /src/KingSystem/ActorSystem/aiRootAi.cpp | |
| parent | e400fe702540b886b718b18e622be450008293a6 (diff) | |
ksys: move AS setting, RootAi and three others to match link order
Each file moves to where its code is linked, and namespaces follow the
new paths. ASSettingMgr is an unofficial name.
| Old | New |
|---|---|
| act::ASSetting (ActorSystem/actASSetting) | res::ASSettingMgr (Resource/Actor/resResourceASSettingMgr) |
| Resource/resResourceASSetting, Resource/Actor/resResourceASResourceExtension | Resource/Actor/resResourceASSetting |
| ksys::DebugFinder (System/DebugFinder) | ksys::act::DebugFinder (ActorSystem/actDebugFinder) |
| ActorSystem/LOD/actLodState | ActorSystem/actLodState |
| ActorSystem/actAiRoot | ActorSystem/aiRootAi |
| Map/mapStagePreActorCache | System/StagePreActorCache (ksys) |
(AI assisted using Claude Fable 5.1 and Claude Opus 5.5)
Diffstat (limited to 'src/KingSystem/ActorSystem/aiRootAi.cpp')
| -rw-r--r-- | src/KingSystem/ActorSystem/aiRootAi.cpp | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/src/KingSystem/ActorSystem/aiRootAi.cpp b/src/KingSystem/ActorSystem/aiRootAi.cpp new file mode 100644 index 00000000..2706a208 --- /dev/null +++ b/src/KingSystem/ActorSystem/aiRootAi.cpp @@ -0,0 +1,157 @@ +#include "KingSystem/ActorSystem/aiRootAi.h" +#include "KingSystem/ActorSystem/actActor.h" +#include "KingSystem/ActorSystem/actAiClassDef.h" +#include "KingSystem/Utils/InitTimeInfo.h" + +namespace ksys::act::ai { + +RootAi::RootAi(const InitArg& arg) : Ai(arg) { + mBehaviorsByStopAndCalcTiming[0].fill({}); + mBehaviorsByStopAndCalcTiming[1].fill({}); +} + +RootAi::~RootAi() { + mQueries.finalize(); + mBehaviors.finalize(); + mAis.finalize(); + mActions.finalize(); + if (_140) + delete _140; +} + +bool RootAi::loadMapUnitParams(const AIDef& def, sead::Heap* heap) { + return mMapUnitParams.load(*mActor, def, heap, AIDefInstParamKind::MapUnit); +} + +bool RootAi::loadAITreeParams(const AIDef& def, sead::Heap* heap) { + return mAiTreeParams.load(*mActor, def, heap, AIDefInstParamKind::AITree); +} + +bool RootAi::isActorDeletedOrDeleting() const { + return mActor->isDeletedOrDeleting(); +} + +bool RootAi::getMapUnitParam(sead::SafeString* value, const sead::SafeString& key) const { + sead::SafeString out; + if (mMapUnitParams.getString(&out, key)) { + *value = out.cstr(); + return true; + } + *value = sead::SafeString::cEmptyString; + return false; +} + +bool RootAi::getMapUnitParam(const s32** value, const sead::SafeString& key) const { + auto* ptr = + static_cast<int*>(mMapUnitParams.getAITreeVariablePointer(key, AIDefParamType::Int)); + static const s32 sDefault{}; + *value = ptr ? ptr : &sDefault; + return ptr != nullptr; +} + +bool RootAi::getMapUnitParam(const f32** value, const sead::SafeString& key) const { + auto* ptr = + static_cast<f32*>(mMapUnitParams.getAITreeVariablePointer(key, AIDefParamType::Float)); + static const f32 sDefault{}; + *value = ptr ? ptr : &sDefault; + return ptr != nullptr; +} + +bool RootAi::getMapUnitParam(const sead::Vector3f** value, const sead::SafeString& key) const { + auto* ptr = static_cast<sead::Vector3f*>( + mMapUnitParams.getAITreeVariablePointer(key, AIDefParamType::Vec3)); + *value = ptr ? ptr : &sead::Vector3f::zero; + return ptr != nullptr; +} + +bool RootAi::getMapUnitParam(const bool** value, const sead::SafeString& key) const { + auto* ptr = + static_cast<bool*>(mMapUnitParams.getAITreeVariablePointer(key, AIDefParamType::Bool)); + static const bool sDefault{}; + *value = ptr ? ptr : &sDefault; + return ptr != nullptr; +} + +namespace { +sead::FixedSafeString<64> sDefaultString; + +struct Vec3Wrapper { + util::InitTimeInfoEx init_time_info_ex; + sead::Vector3f sDefaultVec3{0, 0, 0}; +}; +Vec3Wrapper sDefaultAITreeVariables; +} // namespace + +bool RootAi::getAITreeVariable(sead::SafeString** value, const sead::SafeString& key) const { + auto* ptr = static_cast<sead::SafeString*>( + mAiTreeParams.getAITreeVariablePointer(key, AIDefParamType::String)); + *value = ptr ? ptr : &sDefaultString; + return ptr != nullptr; +} + +bool RootAi::getAITreeVariable(s32** value, const sead::SafeString& key) const { + auto* ptr = static_cast<s32*>(mAiTreeParams.getAITreeVariablePointer(key, AIDefParamType::Int)); + static s32 sDefault{}; + *value = ptr ? ptr : &sDefault; + return ptr != nullptr; +} + +bool RootAi::getAITreeVariable(f32** value, const sead::SafeString& key) const { + auto* ptr = + static_cast<f32*>(mAiTreeParams.getAITreeVariablePointer(key, AIDefParamType::Float)); + static f32 sDefault{}; + *value = ptr ? ptr : &sDefault; + return ptr != nullptr; +} + +bool RootAi::getAITreeVariable(sead::Vector3f** value, const sead::SafeString& key) const { + auto* ptr = static_cast<sead::Vector3f*>( + mAiTreeParams.getAITreeVariablePointer(key, AIDefParamType::Vec3)); + *value = ptr ? ptr : &sDefaultAITreeVariables.sDefaultVec3; + return ptr != nullptr; +} + +bool RootAi::getAITreeVariable(bool** value, const sead::SafeString& key) const { + auto* ptr = + static_cast<bool*>(mAiTreeParams.getAITreeVariablePointer(key, AIDefParamType::Bool)); + static bool sDefault{}; + *value = ptr ? ptr : &sDefault; + return ptr != nullptr; +} + +bool RootAi::getAITreeVariable(void** value, const sead::SafeString& key) const { + auto* ptr = static_cast<void**>( + mAiTreeParams.getAITreeVariablePointer(key, AIDefParamType::AITreeVariablePointer)); + static void* sDefault{}; + *value = ptr ? ptr : &sDefault; + return ptr != nullptr; +} + +bool RootAi::getAITreeVariable(u32** value, const sead::SafeString& key) const { + auto* ptr = + static_cast<u32*>(mAiTreeParams.getAITreeVariablePointer(key, AIDefParamType::UInt)); + static u32 sDefault{}; + *value = ptr ? ptr : &sDefault; + return ptr != nullptr; +} + +bool RootAi::getAITreeVariable2(sead::Vector3f** value, const sead::SafeString& key) const { + return getAITreeVariable(value, key); +} + +bool RootAi::getAITreeVariable2(bool** value, const sead::SafeString& key) const { + return getAITreeVariable(value, key); +} + +const char* getDefaultAiName(s32 root_idx) { + static constexpr const char* names[] = {"DemoRootAI", "Root"}; + if (root_idx >= 2) + return ""; + return names[root_idx]; +} + +const char* getDefaultActionName(s32) { + return ""; +} + +} // namespace ksys::act::ai |
