VR-Engage  2.2
Loading...
Searching...
No Matches
gunnerControlLogic.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5//! \file gunnerControlLogic.h
6//! \brief Control logic for gunner roles in ground vehicles and weapon systems
7//! \ingroup vreCommonComponents
8
9
10#pragma once
11
14
16#include "vreUtil/initializer.h"
17
18#include <vrvCore/DtUniqueID.h>
19
20#include <string>
21
22namespace makVre
23{
24class DtVreMessage;
25
27
29{
30//! \ingroup RoleConfigParams
31//! \defgroup GunnerControlLogicRoleParams Gunner Control Logic Role Parameters
32//! \roleInherits{EntityControlLogicRoleParams}
33//! Configuration Options for gunner control logic role.
34//! @{
35
36//! \vreRoleParam{altRole,string,"",gunnerControlLogic,Alternate role name that can be switched to from the gunner role.}
37constexpr const char* altRole = "altRole";
38
39//! \vreRoleParam{armedProperty,string,"",gunnerControlLogic,Name of the property that controls the armed state for weapons requiring arming.}
40constexpr const char* armedProperty = "armedProperty";
41
42//! \vreRoleParam{azimuthStateAttribute,string,"mainGunAzimuth",gunnerControlLogic,State attribute name for storing the main gun azimuth angle.}
43constexpr const char* azimuthStateAttribute = "azimuthStateAttribute";
44
45//! \vreRoleParam{extendedWeaponSystems,table,"",gunnerControlLogic,Table of extended weapon system configurations for complex targeting scenarios.}
46constexpr const char* extendedWeaponSystems = "extendedWeaponSystems";
47
48//! \vreRoleParam{fireRequiresIntersection,bool,false,gunnerControlLogic,Determines whether firing requires a valid target intersection.}
49constexpr const char* fireRequiresIntersection = "fireRequiresIntersection";
50
51//! \vreRoleParam{forceResourceType,string,"",gunnerControlLogic,Forces the use of a specific resource type for weapon systems.}
52constexpr const char* forceResourceType = "forceResourceType";
53
54//! \vreRoleParam{isOverrideRole,bool,false,gunnerControlLogic,Indicates whether this gunner role operates in commander override mode.}
55constexpr const char* isOverrideRole = "isOverrideRole";
56
57//! \vreRoleParam{maxFireDegreesAzimuth,double,180.0,gunnerControlLogic,Maximum azimuth angle in degrees for weapon firing constraints.}
58constexpr const char* maxFireDegreesAzimuth = "maxFireDegreesAzimuth";
59
60//! \vreRoleParam{maxFireRange,double,10000.0,gunnerControlLogic,Maximum range in meters for weapon engagement.}
61constexpr const char* maxFireRange = "maxFireRange";
62
63//! \vreRoleParam{minFireDegreesAzimuth,double,-180.0,gunnerControlLogic,Minimum azimuth angle in degrees for weapon firing constraints.}
64constexpr const char* minFireDegreesAzimuth = "minFireDegreesAzimuth";
65
66//! \vreRoleParam{minFireRange,double,0.0,gunnerControlLogic,Minimum range in meters for weapon engagement.}
67constexpr const char* minFireRange = "minFireRange";
68
69//! \vreRoleParam{overrideSystem,string,"weapon",gunnerControlLogic,System name to use when operating in override mode.}
70constexpr const char* overrideSystem = "overrideSystem";
71
72//! \vreRoleParam{slewToCueTargetSystem,string,"",gunnerControlLogic,Target system name for slew-to-cue functionality.}
73constexpr const char* slewToCueTargetSystem = "slewToCueTargetSystem";
74
75//! \vreRoleParam{slewToCueUpdateDeltaThreshold,double,0.01,gunnerControlLogic,Threshold for slew-to-cue update sensitivity.}
76constexpr const char* slewToCueUpdateDeltaThreshold = "slewToCueUpdateDeltaThreshold";
77
78//! \vreRoleParam{slewToCueUpdateRate,double,10.0,gunnerControlLogic,Update rate in Hz for slew-to-cue operations.}
79constexpr const char* slewToCueUpdateRate = "slewToCueUpdateRate";
80
81//! \vreRoleParam{systemName,string,"weapon",gunnerControlLogic,Primary weapon system name for this gunner role.}
82constexpr const char* systemName = "systemName";
83
84//! \vreRoleParam{zoomLevels,table,"{1,2,4,8,16,32}",gunnerControlLogic,Array of available zoom magnification levels for the gunner sight system.}
85constexpr const char* zoomLevels = "zoomLevels";
86
87//! @}
88} // namespace GunnerControlLogicConfig
89
90//! \brief Type identifier for DtGunnerControlLogic component
91constexpr const char* DtGunnerControlLogicType = "DtGunnerControlLogic";
92
93//! \brief Control logic component that handles gunner role functionality for ground vehicles
94//!
95//! DtGunnerControlLogic provides input handling and simulation logic for gunner roles,
96//! including weapon control, turret movement, firing, aiming modes, and commander override
97//! capabilities. It manages weapon selection, zoom levels, sensor types, and slew-to-cue
98//! functionality for targeting systems.
100{
101public:
102 //! \brief Constructor for DtGunnerControlLogic
103 //!
104 //! Initializes component state and checks out required VRE_GROUND license
106
107 //! \brief Destructor for DtGunnerControlLogic
108 virtual ~DtGunnerControlLogic() override;
109
110 //! \brief Initializes the gunner control logic component
111 //! \param player Pointer to the player station this component belongs to
112 //! \param config Configuration table containing gunner settings
113 //! \return True if initialization succeeded, false otherwise
114 //!
115 //! Sets up joystick controls, input handlers, state attributes, zoom levels,
116 //! and configures extended weapon systems and slew-to-cue functionality
117 virtual bool initialize(DtPlayerStation* player, DtInitTable& config) override;
118 //! \brief Performs post-initialization after all components are initialized
119 //! \return True if post-initialization succeeded, false otherwise
120 //!
121 //! Locates and establishes connection with the DtWeaponResourceLogic component
122 virtual bool postInitialize() override;
123 //! \brief Called every frame to update gunner control logic
124 //! \param dt Delta time since the last frame in seconds
125 //!
126 //! Updates weapon system state, handles extended weapon system targeting,
127 //! manages slew-to-cue functionality, and sends firing position updates
128 virtual void tick(double dt) override;
129 //! \brief Shuts down the gunner control logic component
130 //!
131 //! Cleans up input handlers, message handlers, and disables commander override if active
132 virtual void shutdown() override;
133
134 //! \brief Returns the component type identifier
135 //! \return The component type string
136 virtual const char* type() const override;
137
138 //! \brief Input functions mapped to particular action strings in configuration
139 //!
140 //! \brief Handles weapon firing input
141 //! \param val Input value (1.0 = fire, 0.0 = stop firing)
142 virtual void fire(double val);
143 //! \brief Controls turret azimuth (horizontal rotation)
144 //! \param val Input value for azimuth rate (-1.0 to 1.0)
145 virtual void azimuth(double val);
146 //! \brief Controls turret elevation (vertical angle)
147 //! \param val Input value for elevation rate (-1.0 to 1.0)
148 virtual void elevation(double val);
149 //! \brief Controls weapon stabilization system
150 //! \param val Input value (1.0 = enable, 0.0 = disable)
151 virtual void stabilize(double val);
152 //! \brief Selects the next available weapon
153 //! \param val Input value (1.0 = select next weapon)
154 virtual void nextWeapon(double val);
155 //! \brief Selects the previous available weapon
156 //! \param val Input value (1.0 = select previous weapon)
157 virtual void previousWeapon(double val);
158 //! \brief Increases the sight magnification level
159 //! \param val Input value (1.0 = zoom in one level)
160 virtual void zoomIn(double val);
161 //! \brief Decreases the sight magnification level
162 //! \param val Input value (1.0 = zoom out one level)
163 virtual void zoomOut(double val);
164 //! \brief Cycles to the next available sensor type (visual, NVG, thermal)
165 //! \param val Input value (1.0 = select next sensor)
166 virtual void nextSensor(double val);
167 //! \brief Cycles between available aiming modes
168 virtual void cycleAimingMode();
169 //! \brief Activates or deactivates slew-to-cue functionality
170 //! \param onoff True to activate slew-to-cue, false to deactivate
171 virtual void slewToCue(bool onoff);
172 //! \brief Switches between gunner and alternate role (e.g., commander RWS)
173 virtual void switchToAltRole();
174
175 //! \brief Handles input for slew-to-cue activation
176 //! \param val Input value (1.0 = activate, 0.0 = deactivate)
177 virtual void handleSlewToCue(float val);
178 //! \brief Handles input for switching to alternate role
179 //! \param val Input value (1.0 = switch role)
180 virtual void handleSwitchToAltRole(float val);
181
182 //! \brief Moves turret upward (direct control)
183 //! \param val Input value (0.0 to 1.0 for speed)
184 virtual void turretUp(float val);
185
186 //! \brief Moves turret downward (direct control)
187 //! \param val Input value (0.0 to 1.0 for speed)
188 virtual void turretDown(float val);
189
190 //! \brief Moves turret to the right (direct control)
191 //! \param val Input value (0.0 to 1.0 for speed)
192 virtual void turretRight(float val);
193
194 //! \brief Moves turret to the left (direct control)
195 //! \param val Input value (0.0 to 1.0 for speed)
196 virtual void turretLeft(float val);
197 //! \brief Controls continuous zoom level directly
198 //! \param val Input value (-1.0 to 1.0) for zoom direction and speed
199 virtual void zoom(float val);
200
201 //! Set x and y inputs for manual missile aiming.
202 virtual void missileX(double val);
203 virtual void missileY(double val);
204
205 //! Toggles armed state for a weapon that requires arming (weapons don't by default).
206 virtual void toggleArmed();
207
208 //! \brief Handles action menu messages for the gunner role
209 //! \param msg The message to handle
210 //! \return Message handling result indicating if the message was handled
211 //!
212 //! Processes menu actions like cycling weapons, sensors, aiming modes, and role switching
214
215protected:
216 //! \brief Determines if aiming should use the observer's view
217 //! \return True if aiming should use the observer's view, false otherwise
218 virtual bool aimWithObserver() const;
219
220 //! \brief Sets the commander override active state
221 //! \param active True to activate commander override, false to deactivate
222 virtual void setCommanderOverrideActive(bool active) const;
223
224 //! \brief Sends a joystick message to the entity
225 //! \param func Function name to trigger on the entity
226 //! \param val Value to send with the function (typically -1.0 to 1.0)
227 void sendJoystickMessage(const std::string& func, const double val);
228
229 //! Update missile's target point based on the x and y input. Called any time x and y are
230 //! not 0.
231 virtual void aimMissile(double x, double y);
232
233 //! @brief Returns true if the weapon can fire. Checks for range, azimuth and isArmed.
234 virtual bool canFire();
235
236protected:
237 //! \brief Previously used munition name, used to detect changes
239
240 //! \brief Primary control group name for this gunner station
242
243 //! \brief Input logic that handles mapping of input actions to functions
245
246 //! \brief Name of the weapon system controlled by this gunner
247 std::string mySystemName;
248
249 //! \brief Pointer to the weapon resource logic component
251
252 //! \brief Available zoom magnification levels
253 std::vector<double> myZoomLevels;
254
255 //! \brief Current index into the zoom levels array
257
258 //! \brief Configuration table for extended weapon systems
260
261 //! \brief Configuration for the currently active extended weapon system
263
264 //! \brief Current target location for extended weapon systems
266
267 //! \brief Element ID of the current target
268 makVrv::DtElementID myTargetElement;
269
270 //! \brief Name of the target system for slew-to-cue functionality
272
273 //! \brief Flag indicating if slew-to-cue is currently active
275
276 //! \brief Rate at which to send slew-to-cue updates (seconds)
278
279 //! \brief Timer for tracking when to send the next slew-to-cue update
281
282 //! \brief Threshold for determining when to send updates based on angle change
284
285 //! \brief Last direction vector sent in a slew-to-cue message
287
288 //! \brief Name of the alternate role to switch to
289 std::string myAltRole;
290
291 //! \brief Flag indicating if this gunner is in override mode
293
294 //! \brief Name of the system to override
295 std::string myOverrideSystem;
296
297 //! \brief Flag indicating if a weapon cycle operation is in progress
299
300 //! \brief Timer for delaying weapon cycling operations
302
303 //! Allow the configuration to specify a resource name directly.
305
308
311
314
316
320
322};
323} // namespace makVre
Handle class for safe access to attributes.
Definition attributeHandle.h:30
DtEntityControlLogic()
Constructor.
virtual void cycleAimingMode()
Cycles between available aiming modes.
DtInputLogic myInputLogic
Input logic that handles mapping of input actions to functions.
Definition gunnerControlLogic.h:244
virtual makVre::DtVreMessageResult handleMenuMessage(makVre::DtVreMessage *msg)
Handles action menu messages for the gunner role.
virtual void shutdown() override
Shuts down the gunner control logic component.
std::string myMainControlGroup
Primary control group name for this gunner station.
Definition gunnerControlLogic.h:241
double myMinRange
Definition gunnerControlLogic.h:312
makVre::DtInitTable myExtendedWeaponSystems
Configuration table for extended weapon systems.
Definition gunnerControlLogic.h:259
double mySlewToCueUpdateRate
Rate at which to send slew-to-cue updates (seconds)
Definition gunnerControlLogic.h:277
std::string myAzimuthStateAttribute
Definition gunnerControlLogic.h:319
std::string mySlewToCueTargetSystem
Name of the target system for slew-to-cue functionality.
Definition gunnerControlLogic.h:271
virtual void zoomIn(double val)
Increases the sight magnification level.
virtual void stabilize(double val)
Controls weapon stabilization system.
virtual bool initialize(DtPlayerStation *player, DtInitTable &config) override
Initializes the gunner control logic component.
DtWeaponResourceLogic * myResourceLogic
Pointer to the weapon resource logic component.
Definition gunnerControlLogic.h:250
DtVector mySlewToCueLastSentVector
Last direction vector sent in a slew-to-cue message.
Definition gunnerControlLogic.h:286
double mySlewToCueTimer
Timer for tracking when to send the next slew-to-cue update.
Definition gunnerControlLogic.h:280
bool myIsOverrideRole
Flag indicating if this gunner is in override mode.
Definition gunnerControlLogic.h:292
virtual void previousWeapon(double val)
Selects the previous available weapon.
double myMinGunAzimuth
Definition gunnerControlLogic.h:317
std::string myForceResourceType
Allow the configuration to specify a resource name directly.
Definition gunnerControlLogic.h:304
virtual void azimuth(double val)
Controls turret azimuth (horizontal rotation)
double myMissileX
Definition gunnerControlLogic.h:309
virtual void fire(double val)
Input functions mapped to particular action strings in configuration.
virtual void missileY(double val)
virtual void turretDown(float val)
Moves turret downward (direct control)
std::string myAltRole
Name of the alternate role to switch to.
Definition gunnerControlLogic.h:289
virtual void switchToAltRole()
Switches between gunner and alternate role (e.g., commander RWS)
std::string myArmedStateProperty
Definition gunnerControlLogic.h:321
virtual void turretRight(float val)
Moves turret to the right (direct control)
DtAttributeHandle myResourceHandle
Definition gunnerControlLogic.h:306
std::vector< double > myZoomLevels
Available zoom magnification levels.
Definition gunnerControlLogic.h:253
double myMaxRange
Definition gunnerControlLogic.h:313
virtual ~DtGunnerControlLogic() override
Destructor for DtGunnerControlLogic.
makVrv::DtElementID myTargetElement
Element ID of the current target.
Definition gunnerControlLogic.h:268
virtual bool postInitialize() override
Performs post-initialization after all components are initialized.
virtual void turretUp(float val)
Moves turret upward (direct control)
bool myPreviousMissileInFlight
Definition gunnerControlLogic.h:315
double myMaxGunAzimuth
Definition gunnerControlLogic.h:318
virtual void toggleArmed()
Toggles armed state for a weapon that requires arming (weapons don't by default).
std::string myOverrideSystem
Name of the system to override.
Definition gunnerControlLogic.h:295
virtual void tick(double dt) override
Called every frame to update gunner control logic.
DtAttributeHandle myMunitionHandle
Definition gunnerControlLogic.h:307
virtual void aimMissile(double x, double y)
Update missile's target point based on the x and y input. Called any time x and y are not 0.
virtual void turretLeft(float val)
Moves turret to the left (direct control)
virtual void slewToCue(bool onoff)
Activates or deactivates slew-to-cue functionality.
virtual void nextSensor(double val)
Cycles to the next available sensor type (visual, NVG, thermal)
DtGunnerControlLogic()
Constructor for DtGunnerControlLogic.
virtual bool canFire()
Returns true if the weapon can fire. Checks for range, azimuth and isArmed.
virtual void missileX(double val)
Set x and y inputs for manual missile aiming.
std::string myPreviousMunitionType
Previously used munition name, used to detect changes.
Definition gunnerControlLogic.h:238
virtual bool aimWithObserver() const
Determines if aiming should use the observer's view.
virtual void setCommanderOverrideActive(bool active) const
Sets the commander override active state.
int myZoomIndex
Current index into the zoom levels array.
Definition gunnerControlLogic.h:256
DtVector myTargetLocation
Current target location for extended weapon systems.
Definition gunnerControlLogic.h:265
virtual void handleSlewToCue(float val)
Handles input for slew-to-cue activation.
virtual void handleSwitchToAltRole(float val)
Handles input for switching to alternate role.
std::string mySystemName
Name of the weapon system controlled by this gunner.
Definition gunnerControlLogic.h:247
virtual const char * type() const override
Returns the component type identifier.
void sendJoystickMessage(const std::string &func, const double val)
Sends a joystick message to the entity.
virtual void nextWeapon(double val)
Selects the next available weapon.
virtual void zoom(float val)
Controls continuous zoom level directly.
virtual void elevation(double val)
Controls turret elevation (vertical angle)
bool mySlewToCueActive
Flag indicating if slew-to-cue is currently active.
Definition gunnerControlLogic.h:274
double myDelayedCycleWeaponTimer
Timer for delaying weapon cycling operations.
Definition gunnerControlLogic.h:301
virtual void zoomOut(double val)
Decreases the sight magnification level.
double mySlewToCueUpdateDeltaThreshold
Threshold for determining when to send updates based on angle change.
Definition gunnerControlLogic.h:283
makVre::DtInitTable myCurrentExtendedSystem
Configuration for the currently active extended weapon system.
Definition gunnerControlLogic.h:262
bool myCycleWeaponFlag
Flag indicating if a weapon cycle operation is in progress.
Definition gunnerControlLogic.h:298
double myMissileY
Definition gunnerControlLogic.h:310
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Class for managing input configuration and handling in VR-Engage.
Definition inputLogic.h:35
virtual DtPlayerStation & player()
Gets the player station.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Component for managing weapon resources, equipment, and related state attributes.
Definition weaponResourceLogic.h:45
Defines the logic for controlling entities in VR-Engage.
constexpr const char * minFireRange
Definition gunnerControlLogic.h:67
constexpr const char * fireRequiresIntersection
Definition gunnerControlLogic.h:49
constexpr const char * azimuthStateAttribute
Definition gunnerControlLogic.h:43
constexpr const char * slewToCueUpdateRate
Definition gunnerControlLogic.h:79
constexpr const char * maxFireRange
Definition gunnerControlLogic.h:61
constexpr const char * armedProperty
Definition gunnerControlLogic.h:40
constexpr const char * extendedWeaponSystems
Definition gunnerControlLogic.h:46
constexpr const char * zoomLevels
\vreRoleParam{zoomLevels,table,"{1,2,4,8,16,32}",gunnerControlLogic,Array of available zoom magnifica...
Definition gunnerControlLogic.h:85
constexpr const char * maxFireDegreesAzimuth
Definition gunnerControlLogic.h:58
constexpr const char * altRole
Definition gunnerControlLogic.h:37
constexpr const char * isOverrideRole
Definition gunnerControlLogic.h:55
constexpr const char * systemName
Definition gunnerControlLogic.h:82
constexpr const char * minFireDegreesAzimuth
Definition gunnerControlLogic.h:64
constexpr const char * slewToCueTargetSystem
Definition gunnerControlLogic.h:73
constexpr const char * forceResourceType
Definition gunnerControlLogic.h:52
constexpr const char * slewToCueUpdateDeltaThreshold
Definition gunnerControlLogic.h:76
constexpr const char * overrideSystem
Definition gunnerControlLogic.h:70
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Provides configuration initialization for VREngage components.
Definition gunnerControlLogic.h:29
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
constexpr const char * DtGunnerControlLogicType
Type identifier for DtGunnerControlLogic component.
Definition gunnerControlLogic.h:91
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Defines the base class for all VREngage messages.