VR-Engage  2.2
Loading...
Searching...
No Matches
vreHumanDamageActuator.h
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2025 MAK Technologies
3 * All rights reserved.
4 ******************************************************************************/
5
6//! \file vreHumanDamageActuator.h
7//! \ingroup vreVrfmodel
8//! \brief Actuator for processing damage to human entities
9//!
10//! This file defines the DtVreHumanDamageActuator class which handles damage
11//! adjudication for human entities. It defines different areas of the human body
12//! and calculates the amount of damage received when hit in those areas based on
13//! posture, hit location, and weapon characteristics.
14
15#pragma once
16
17// Local Includes
18#include "vreVrfmodel/export.h"
20
21#include <vrfmodel/humanDamageActuator.h>
22
23// Class Forward Declarations
24
25namespace makVre
26{
27//! \brief Type identifier for the VRE human damage actuator component
28const char DtVreHumanDamageActuatorType[] = "vre-human-damage-actuator";
29
30//! \brief Actuator for processing damage to human entities
31//!
32//! DtVreHumanDamageActuator handles damage adjudication for human entities. It defines
33//! different areas of the human body and calculates the amount of damage received when
34//! hit in those areas based on posture, hit location, and weapon characteristics.
35//! The actuator maintains separate health values for overall health, mobility, and
36//! firepower, which can be affected differently depending on the hit location.
37class VREVRFMODEL_DLL DtVreHumanDamageActuator : public DtVreSimComponent<DtHumanDamageActuator>
38{
39public: // public typedefs and enumerations
40public: // public constructors and destructors
41 //! \brief Constructor
42 //! \param name The name of this component
43 //! \param owner The local object that owns this component
44 //! \param simManager The simulation services manager
45 //! \param desc Component descriptor with configuration parameters
46 //! \param parentRegistry Optional parent registry for reader/writer functionality
47 //!
48 //! Creates a new human damage actuator component with the specified parameters.
49 DtVreHumanDamageActuator(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
50 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
51
52 //! \brief Virtual destructor
53 //!
54 //! Cleans up resources used by the human damage actuator component.
55 virtual ~DtVreHumanDamageActuator() override;
56
57 //! \brief Gets the type identifier for this component
58 //! \return String identifying the component type (DtVreHumanDamageActuatorType)
59 //!
60 //! Implements the DtSimComponent::type() method to return the
61 //! type identifier for this component.
62 virtual const char* type() const override;
63
64 //! \brief Initializes the human damage actuator
65 //! \return True if initialization is successful, false otherwise
66 //!
67 //! Performs initial setup of the human damage actuator, including setting up
68 //! body zone damage maps and connecting to entity state variables. This method
69 //! is called during component initialization.
70 virtual bool init() override;
71
72 //! \brief Updates the actuator state each simulation frame
73 //!
74 //! Processes the human entity's damage state during each simulation frame.
75 //! This includes checking current health values and updating the entity's
76 //! state accordingly, such as changing posture when health drops below
77 //! certain thresholds.
78 virtual void tick() override;
79
80 //! \brief Processes direct damage from a detonation
81 //! \param detonationContext Information about the detonation that hit the entity
82 //! \return True if damage was applied, false otherwise
83 //!
84 //! Determines damage from a direct impact on the entity and decrements the
85 //! hit points on the entity if appropriate. The amount of damage depends on
86 //! the hit location, entity posture, and weapon characteristics.
87 virtual bool adjudicateDirectDamage(const DtDetonationContext& detonationContext) override;
88
89 //! \brief Processes collateral damage from a nearby detonation
90 //! \param detonationContext Information about the detonation that occurred near the entity
91 //! \return True if damage was applied, false otherwise
92 //!
93 //! Determines collateral damage from an impact near the entity, based on the
94 //! distance from the detonation, weapon type, and other factors. Applies
95 //! appropriate health reductions based on the blast effects.
96 virtual bool adjudicateCollateralDamage(const DtDetonationContext& detonationContext) override;
97
98 //! \brief Factory method to create a new instance of this component
99 //! \param name The name for the new component
100 //! \param owner The local object that will own this component
101 //! \param simManager The simulation services manager
102 //! \param desc Optional component descriptor
103 //! \param parentRegistry Optional parent registry for reader/writer functionality
104 //! \return Pointer to the newly created component
105 //!
106 //! Static factory method used by the component creation system to instantiate
107 //! new instances of this component type.
108 static DtSimComponent* creator(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
109 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
110
111protected:
112 //! \brief Updates the damage state of the entity
113 //! \param state The new damage state to apply to the entity
114 //!
115 //! Updates the entity's damage state and applies appropriate visual and
116 //! functional effects based on the new state. This may include changing
117 //! appearance, posture, or mobility capabilities.
118 virtual void updateState(DtDamageState state) override;
119 //! \brief Sets the entity to a destroyed state
120 //!
121 //! Sets the entity to a destroyed state when health reaches zero.
122 //! This includes updating visual appearance, disabling mobility,
123 //! and potentially triggering death animations.
124 virtual void setDestroyed() override;
125
126private:
127 //! \brief Copy constructor (not implemented)
128 //!
129 //! Copy constructor is private and not implemented to prevent
130 //! copy construction.
132 //! \brief Assignment operator (not implemented)
133 //! \return Reference to this object
134 //!
135 //! Assignment operator is private and not implemented to prevent assignment.
137
138public: // public methods
139public: // public static methods
140public: // public static data
141protected: // protected methods
142 //! \brief Restores an entity to a functional state
143 //!
144 //! Re-registers the entity to receive detonations since it is now restored.
145 //! This is called when an entity's health is reset or restored after
146 //! being damaged or destroyed.
147 //! \see registerForDetonations
148 virtual void setRestored() override;
149
150protected: // protected data
151 //! \brief Changes the entity's posture
152 //! \param post The new posture to set for the entity
153 //!
154 //! Changes the entity's posture, typically used to knock the entity to the
155 //! ground when significantly damaged. This sends the appropriate commands
156 //! to update the entity's visual representation and movement capabilities.
157 void sendSetPosture(DtLifeformState post);
158
159 //! \brief Initializes the posture-specific damage maps
160 //!
161 //! Sets up the damage maps for different postures, defining how much damage
162 //! is applied to different body zones in each posture. This is a temporary
163 //! implementation until damage maps can be read from configuration files.
165
166 //! \brief Information about a body zone and its damage characteristics
167 //!
168 //! Specifies amount of damage caused when a specific body zone is hit.
169 //! Each body zone can affect different health aspects differently.
171 {
172 std::string bodyZoneName; //!< Name of the body zone
173 DtVector bodyZoneCenter; //!< Point used to determine distance to the detonation
174 bool useSurfaceData; //!< If true, the surface name must match for a hit to count
175 //!< If set to true, the surface name specified in the surfaceName
176 //!< field must match the surface name that was hit by the detonation
177 //!< in order for a hit on this part to be true
178 std::string surfaceName; //!< Surface name to match when useSurfaceData is true
179 int overallHealthLoss; //!< Amount of overall health lost when this zone is hit
180 int overallHealthLossModifier; //!< Modifier to overall health loss (+/-)
181 int mobilityHealthLoss; //!< Amount of mobility health lost when this zone is hit
182 int mobilityHealthLossModifier; //!< Modifier to mobility health loss (+/-)
183 int firepowerHealthLoss; //!< Amount of firepower health lost when this zone is hit
184 int firepowerHealthLossModifier; //!< Modifier to firepower health loss (+/-)
185 };
186
187 //! \brief Damage map for body parts indexed by body zone name
188 //!
189 //! Maps body zone names to their corresponding damage information.
190 //! The key is the bodyZoneName string.
191 using DtDamageMap = std::map<std::string, DtDamageZoneInfo>;
192
193 //! \brief Map of damage maps for different postures
194 //!
195 //! Each posture (standing, prone, etc.) has its own damage map defining
196 //! how much damage is applied to different body zones in that posture.
197 std::map<DtLifeformState, DtDamageMap> myPostureDamageMap;
198
199 //! \brief Entity's overall health value
200 //!
201 //! State property defined in the Human OPE file, representing the
202 //! entity's overall health status.
204
205 //! \brief Entity's mobility health value
206 //!
207 //! State property defined in the Human OPE file, representing the
208 //! entity's ability to move effectively.
210
211 //! \brief Entity's firepower health value
212 //!
213 //! State property defined in the Human OPE file, representing the
214 //! entity's ability to use weapons effectively.
216
217 //! \brief Flag indicating if OPE access is valid
218 //!
219 //! Indicates whether the component was able to successfully access the
220 //! OPE (Object Property Editor) state variables.
222};
223} // namespace makVre
DtVreHumanDamageActuator(const DtVreHumanDamageActuator &other)
Copy constructor (not implemented)
std::map< DtLifeformState, DtDamageMap > myPostureDamageMap
Map of damage maps for different postures.
Definition vreHumanDamageActuator.h:197
DtRwInt * myFirepowerHealth
Entity's firepower health value.
Definition vreHumanDamageActuator.h:215
virtual bool init() override
Initializes the human damage actuator.
virtual void setRestored() override
Restores an entity to a functional state.
std::map< std::string, DtDamageZoneInfo > DtDamageMap
Damage map for body parts indexed by body zone name.
Definition vreHumanDamageActuator.h:191
DtVreHumanDamageActuator(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Constructor.
DtVreHumanDamageActuator & operator=(const DtVreHumanDamageActuator &other)
Assignment operator (not implemented)
bool myOpeOk
Flag indicating if OPE access is valid.
Definition vreHumanDamageActuator.h:221
static DtSimComponent * creator(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Factory method to create a new instance of this component.
virtual ~DtVreHumanDamageActuator() override
Virtual destructor.
virtual const char * type() const override
Gets the type identifier for this component.
virtual void tick() override
Updates the actuator state each simulation frame.
DtRwInt * myOverallHealth
Entity's overall health value.
Definition vreHumanDamageActuator.h:203
void initPostureDamageMaps()
Initializes the posture-specific damage maps.
virtual void setDestroyed() override
Sets the entity to a destroyed state.
void sendSetPosture(DtLifeformState post)
Changes the entity's posture.
virtual void updateState(DtDamageState state) override
Updates the damage state of the entity.
DtRwInt * myMobilityHealth
Entity's mobility health value.
Definition vreHumanDamageActuator.h:209
virtual bool adjudicateCollateralDamage(const DtDetonationContext &detonationContext) override
Processes collateral damage from a nearby detonation.
virtual bool adjudicateDirectDamage(const DtDetonationContext &detonationContext) override
Processes direct damage from a detonation.
struct DtDamageZoneInfo { std::string bodyZoneName; DtVector bodyZoneCenter; bool useSurfaceData; std::string surfaceName; int overallHealthLoss; int overallHealthLossModifier; int mobilityHealthLoss; int mobilityHealthLossModifier; int firepowerHealthLoss; int firepowerHealthLossModifier; } DtDamageZoneInfo
Information about a body zone and its damage characteristics.
Definition vreHumanDamageActuator.h:170
DtVreSimComponent(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Definition vreSimComponent.h:54
Defines export macros for the vreVrfmodel library.
#define VREVRFMODEL_DLL
Definition export.h:22
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
const char DtVreHumanDamageActuatorType[]
Type identifier for the VRE human damage actuator component.
Definition vreHumanDamageActuator.h:28
Base template class for VR-Engage simulation components.