From ea13bac74ad136aeb3dde81f07ccd62622be94ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Mon, 28 Sep 2026 03:39:31 +0200 Subject: 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) --- src/KingSystem/ActorSystem/aiRootAi.cpp | 157 ++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 src/KingSystem/ActorSystem/aiRootAi.cpp (limited to 'src/KingSystem/ActorSystem/aiRootAi.cpp') 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(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(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( + 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(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( + 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(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(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( + 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(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( + 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(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 -- cgit v1.2.3