Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Task_Attack.cpp
Go to the documentation of this file.
1/**
2 * @file Task_Attack.cpp
3 * @brief Atomic task: initiate a combat attack action.
4 * @author Olympe Engine
5 * @date 2026-03-08
6 *
7 * C++14 compliant - no C++17/20 features.
8 */
9
10#include "Task_Attack.h"
11#include "../../AtomicTaskRegistry.h"
12#include "../../LocalBlackboard.h"
13#include "../../../system/system_utils.h"
14
15namespace Olympe {
16
17static const float DEFAULT_DAMAGE = 10.0f;
18static const float DEFAULT_RANGE = 50.0f;
19
21
23{
24 SYSTEM_LOG << "[Task_Attack] Abort()\n";
25}
26
28{
29 return TaskStatus::Failure; // requires context; use ExecuteWithContext
30}
31
33 const ParameterMap& params)
34{
35 if (!ctx.LocalBB)
36 {
37 SYSTEM_LOG << "[Task_Attack] No LocalBlackboard in context\n";
39 }
40
41 // --- Resolve Damage parameter (optional) ---
42 float damage = DEFAULT_DAMAGE;
43 {
44 auto it = params.find("Damage");
45 if (it != params.end() && it->second.GetType() == VariableType::Float)
46 {
47 damage = it->second.AsFloat();
48 }
49 }
50
51 // --- Resolve Range parameter (optional) ---
52 float range = DEFAULT_RANGE;
53 {
54 auto it = params.find("Range");
55 if (it != params.end() && it->second.GetType() == VariableType::Float)
56 {
57 range = it->second.AsFloat();
58 }
59 }
60
61 // --- Read target from LocalBlackboard ---
63 {
64 const TaskValue targetVal = ctx.LocalBB->GetValueScoped("local:Target");
65 if (targetVal.GetType() == VariableType::EntityID)
66 {
67 target = targetVal.AsEntityID();
68 }
69 }
70
71 SYSTEM_LOG << "[Task_Attack] Entity " << ctx.Entity
72 << " attacks target=" << target
73 << " damage=" << damage
74 << " range=" << range << "\n";
75
77}
78
80
81} // 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
std::uint64_t EntityID
Definition ECS_Entity.h:21
const EntityID INVALID_ENTITY_ID
Definition ECS_Entity.h:23
Atomic task that performs a melee/ranged attack on a target entity.
std::unordered_map< std::string, TaskValue > ParameterMap
Convenience alias for the parameter map passed to Execute().
Definition IAtomicTask.h:67
C++14-compliant type-safe value container for task parameters.
EntityID AsEntityID() const
Returns the EntityID value.
Initiates an attack action on the current target entity.
Definition Task_Attack.h:34
TaskStatus Execute(const ParameterMap &params) override
Executes the atomic task for one frame.
void Abort() override
Aborts the task, releasing any in-progress state.
TaskStatus ExecuteWithContext(const AtomicTaskContext &ctx, const ParameterMap &params) override
Executes the atomic task for one frame with full runtime context.
< Provides AssetID and INVALID_ASSET_ID
@ Float
Single-precision float.
@ EntityID
Entity identifier (uint64_t)
TaskStatus
Result code returned by IAtomicTask::Execute().
Definition IAtomicTask.h:38
@ Success
Task completed successfully.
@ Failure
Task failed.
static const float DEFAULT_RANGE
static const float DEFAULT_DAMAGE
Lightweight context bundle passed to IAtomicTask::ExecuteWithContext().
#define SYSTEM_LOG