summaryrefslogtreecommitdiff
path: root/src/KingSystem/ActorSystem/actBaseProcCreateTaskSelector.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2021-03-12 19:30:37 +0100
committerLéo Lam <leo@leolam.fr>2021-03-12 20:00:07 +0100
commitc23f86e6d5aaba7bd85790fc0f206f0db5e739cd (patch)
tree5586e9bed229d2b64b6ee934b3e9d9ab2b98eee9 /src/KingSystem/ActorSystem/actBaseProcCreateTaskSelector.cpp
parentd072fcf7da93fcd03a10a169ac3e10476191916e (diff)
ksys/act: Add BaseProcCreateTaskSelector
Diffstat (limited to 'src/KingSystem/ActorSystem/actBaseProcCreateTaskSelector.cpp')
-rw-r--r--src/KingSystem/ActorSystem/actBaseProcCreateTaskSelector.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/KingSystem/ActorSystem/actBaseProcCreateTaskSelector.cpp b/src/KingSystem/ActorSystem/actBaseProcCreateTaskSelector.cpp
new file mode 100644
index 00000000..5b98aac6
--- /dev/null
+++ b/src/KingSystem/ActorSystem/actBaseProcCreateTaskSelector.cpp
@@ -0,0 +1,45 @@
+#include "KingSystem/ActorSystem/actBaseProcCreateTaskSelector.h"
+#include <limits>
+#include "KingSystem/ActorSystem/actBaseProcCreateTask.h"
+#include "KingSystem/Map/mapObject.h"
+
+namespace ksys::act {
+
+SEAD_SINGLETON_DISPOSER_IMPL(BaseProcCreateTaskSelector)
+
+util::Task* BaseProcCreateTaskSelector::selectTask(const util::TaskSelectionContext& context) {
+ util::Task* min_task = nullptr;
+ util::Task* lane1_task = nullptr;
+ auto min = std::numeric_limits<float>::max();
+
+ for (auto& it : context) {
+ auto* task = sead::DynamicCast<BaseProcCreateTask>(&it);
+ if (!task)
+ return &it;
+
+ if (task->getLaneId() == 2)
+ return &it;
+
+ if (task->mMapObject && task->mMapObject->getFlags0().isOff(map::Object::Flag0::_4))
+ return &it;
+
+ if (task->mDistanceToLoadSphere >= 0.0 && min > task->mDistanceToLoadSphere)
+ min_task = &it;
+
+ if (task->mDistanceToLoadSphere >= 0.0 && min > task->mDistanceToLoadSphere)
+ min = task->mDistanceToLoadSphere;
+
+ if (task->getLaneId() == 1)
+ lane1_task = &it;
+ }
+
+ if (min_task)
+ return min_task;
+
+ if (lane1_task)
+ return lane1_task;
+
+ return std::addressof(*context.begin());
+}
+
+} // namespace ksys::act