Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Task_ChangeState.cpp
Go to the documentation of this file.
1/**
2 * @file Task_ChangeState.cpp
3 * @brief Atomic task: change the AI state in the LocalBlackboard.
4 * @author Olympe Engine
5 * @date 2026-03-08
6 *
7 * C++14 compliant - no C++17/20 features.
8 */
9
10#include "Task_ChangeState.h"
11#include "../../AtomicTaskRegistry.h"
12#include "../../LocalBlackboard.h"
13#include "../../../system/system_utils.h"
14
15namespace Olympe {
16
18
20{
21 SYSTEM_LOG << "[Task_ChangeState] Abort()\n";
22}
23
24TaskStatus Task_ChangeState::Execute(const ParameterMap& /*params*/)
25{
26 return TaskStatus::Failure; // requires context; use ExecuteWithContext
27}
28
30 const ParameterMap& params)
31{
32 if (!ctx.LocalBB)
33 {
34 SYSTEM_LOG << "[Task_ChangeState] No LocalBlackboard in context\n";
36 }
37
38 // --- Resolve NewState parameter ---
39 std::string newState;
40 {
41 auto it = params.find("NewState");
42 if (it == params.end() || it->second.GetType() != VariableType::String)
43 {
44 SYSTEM_LOG << "[Task_ChangeState] Missing or invalid 'NewState' parameter\n";
46 }
47 newState = it->second.AsString();
48 }
49
50 // --- Log the current state for diagnostics ---
51 const TaskValue currentVal = ctx.LocalBB->GetValueScoped("local:CurrentState");
52 if (currentVal.GetType() == VariableType::String)
53 {
54 SYSTEM_LOG << "[Task_ChangeState] Entity " << ctx.Entity
55 << " state: '" << currentVal.AsString()
56 << "' -> '" << newState << "'\n";
57 }
58 else
59 {
60 SYSTEM_LOG << "[Task_ChangeState] Entity " << ctx.Entity
61 << " setting state to '" << newState << "'\n";
62 }
63
64 // --- Write new state to LocalBlackboard ---
65 ctx.LocalBB->SetValueScoped("local:CurrentState", TaskValue(newState));
66
68}
69
70REGISTER_ATOMIC_TASK(Task_ChangeState, "Task_ChangeState")
71
72} // namespace Olympe
#define REGISTER_ATOMIC_TASK(ClassName, Id)
Registers a factory for ClassName under Id at static init time.
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Atomic task that changes the AI state stored in the LocalBlackboard.
TaskStatus Execute(const ParameterMap &params) override
Executes the atomic task for one frame.
TaskStatus ExecuteWithContext(const AtomicTaskContext &ctx, const ParameterMap &params) override
Executes the atomic task for one frame with full runtime context.
void Abort() override
Aborts the task, releasing any in-progress state.
< Provides AssetID and INVALID_ASSET_ID
@ String
std::string
TaskStatus
Result code returned by IAtomicTask::Execute().
Definition IAtomicTask.h:38
@ Success
Task completed successfully.
@ Failure
Task failed.
#define SYSTEM_LOG