VR-Engage  2.2
Loading...
Searching...
No Matches
echelonLogic.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file echelonLogic.h
7//! \brief Defines the DtEchelonLogic component for tracking hierarchical relationships between entities.
8//!
9//! This component handles military-style echelon relationships, determining superiors and subordinates
10//! in the command structure and making this information available via state attributes.
11//!
12//! \ingroup vreCommonComponents
13
14#pragma once
15
17
19#include <vrvCore/DtUniqueID.h>
20#include <vrvCore/DtElementIDHierarchyState.h>
21
22namespace makVre
23{
24//! \brief Type identifier for DtEchelonLogic component
25constexpr const char* DtEchelonLogicType = "DtEchelonLogic";
26
27//! \brief Component for handling command hierarchy relationships between entities
28//!
29//! The DtEchelonLogic tracks hierarchical relationships between entities in a command structure.
30//! It queries the DtElementIDHierarchyState to determine an entity's superior (commanding entity)
31//! and its peer subordinates (other entities sharing the same superior), then publishes this
32//! information as state attributes for use by other components.
33//!
34//! The component maintains the following state attributes:
35//! - "Superior": The display name of the entity's commanding officer/unit
36//! - "subordinateList": A list of display names of peer entities (others reporting to the same superior)
37//! - "taskableEntities": Boolean flag indicating if there are any peer entities to potentially task
39{
40public:
41 //! \brief Constructor for DtEchelonLogic
42 //!
43 //! Initializes the component with the name "DtEchelonLogic".
45
46 //! \brief Virtual destructor for DtEchelonLogic
47 virtual ~DtEchelonLogic() override;
48
49 //! \brief Initializes the component with configuration from Lua
50 //!
51 //! Performs basic initialization using the parent class implementation.
52 //!
53 //! \param player Pointer to the player station this component belongs to
54 //! \param config Configuration table containing initialization parameters
55 //! \return True if initialization succeeds, false otherwise
56 virtual bool initialize(DtPlayerStation* player, DtInitTable& config) override;
57
58 //! \brief Updates the component state
59 //!
60 //! Called each frame to update the command hierarchy information. This method:
61 //! - Looks up the entity's superior/commanding entity
62 //! - Finds all entities subordinate to that superior (peers of this entity)
63 //! - Updates the "Superior", "subordinateList", and "taskableEntities" state attributes
64 //!
65 //! \param dt Delta time in seconds since the last tick
66 virtual void tick(double dt) override;
67
68 //! \brief Shuts down the component
69 //!
70 //! Performs cleanup by calling the parent class shutdown method.
71 virtual void shutdown() override;
72
73 //! \brief Returns the component type identifier
74 //! \return The component type string
75 virtual const char* type() const override;
76
77protected:
78 //! \brief Initializes state attributes
79 //!
80 //! This method is reserved for initializing state attributes in the future.
81 //! Currently, it has an empty implementation with commented-out code.
82 virtual void initializeStateAttributes() override;
83
84 //! \brief Looks up the superior (commanding entity) for a given entity
85 //!
86 //! Queries the DtElementIDHierarchyState to find the parent entity ID
87 //! for the specified entity.
88 //!
89 //! \param de Reference to the dynamic environment
90 //! \param id Element ID of the entity to find the superior for
91 //! \return Element ID of the superior entity, or 0 if not found
92 virtual makVrv::DtElementID lookupSuperior(makVrv::DtDe& de, makVrv::DtElementID id) const;
93
94 //! \brief Looks up subordinate entities for a given entity
95 //!
96 //! Queries the DtElementIDHierarchyState to find all child entities
97 //! for the specified entity.
98 //!
99 //! \param de Reference to the dynamic environment
100 //! \param id Element ID of the entity to find subordinates for
101 //! \return Vector of element IDs of subordinate entities
102 virtual const makVrv::DtElementIDHierarchyState::ElementIDVector lookupSubordinates(
103 makVrv::DtDe& de, makVrv::DtElementID id) const;
104
105 //! \brief Finds the hierarchy state attribute for a given entity
106 //!
107 //! Locates the DtElementIDHierarchyStateAttribute for the specified entity
108 //! by looking it up in the data bank.
109 //!
110 //! \param de Reference to the dynamic environment
111 //! \param id Element ID of the entity to find the hierarchy item for
112 //! \return Pointer to the hierarchy state attribute, or nullptr if not found
113 virtual const makVrv::DtElementIDHierarchyStateAttribute* findHierarchyItem(
114 makVrv::DtDe& de, makVrv::DtElementID id) const;
115
116 // Commented out attributes for future use
117 //! \brief Pointer to the superior entity attribute (commented out)
118 // DtAttribute<std::string>* mySuperiorAttr;
119
120 //! \brief Pointer to the subordinate list attribute (commented out)
121 // DtAttribute<std::vector<std::string>>* mySubordinateListAttr;
122
123 //! \brief Pointer to the taskable entities flag attribute (commented out)
124 // DtAttribute<bool>* myTaskableEntitiesAttr;
125};
126
127} // namespace makVre
virtual void tick(double dt) override
Updates the component state.
virtual makVrv::DtElementID lookupSuperior(makVrv::DtDe &de, makVrv::DtElementID id) const
Looks up the superior (commanding entity) for a given entity.
virtual const makVrv::DtElementIDHierarchyStateAttribute * findHierarchyItem(makVrv::DtDe &de, makVrv::DtElementID id) const
Finds the hierarchy state attribute for a given entity.
virtual void initializeStateAttributes() override
Initializes state attributes.
virtual const char * type() const override
Returns the component type identifier.
virtual bool initialize(DtPlayerStation *player, DtInitTable &config) override
Initializes the component with configuration from Lua.
DtEchelonLogic()
Constructor for DtEchelonLogic.
virtual void shutdown() override
Shuts down the component.
virtual const makVrv::DtElementIDHierarchyState::ElementIDVector lookupSubordinates(makVrv::DtDe &de, makVrv::DtElementID id) const
Looks up subordinate entities for a given entity.
virtual ~DtEchelonLogic() override
Virtual destructor for DtEchelonLogic.
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Base class for all role components in VR-Engage.
Definition playerComponent.h:78
virtual DtPlayerStation & player()
Gets the player station.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
constexpr const char * DtEchelonLogicType
Type identifier for DtEchelonLogic component.
Definition echelonLogic.h:25
Defines the DtPlayerComponent base class for VR-Engage role components.
makVrv::DtDe * de()
Gets the display element pointer used by the plugin.