VR-Engage  2.2
Loading...
Searching...
No Matches
makVre::DtWeaponsStatusController Class Reference

Detailed Description

DtWeaponsStatusController monitors and updates weapon systems status information for an entity. It manages the SelectedWeapon and WeaponsStatus state properties, and handles "CycleWeapon" commands to change the currently selected weapon system. The controller maintains a map of weapon configurations, tracks ammunition levels, and publishes this information for use by the VR-Engage interface.

This component is responsible for determining valid weapon selections based on the availability of ammunition and updating state properties to reflect current weapon status for the entity.

Uses Descriptor Type: DtWeaponsStatusControllerDescriptor

#include <weaponsStatusController.h>

Inheritance diagram for makVre::DtWeaponsStatusController:
[legend]

Public Member Functions

 DtWeaponsStatusController (const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
 
virtual ~DtWeaponsStatusController () override
 
virtual void preFirstTickInit () override
 
virtual bool init () override
 
virtual void tick () override
 
virtual const char * type () const override
 
virtual void calcAndSetPortValues (const DtString &functionGroup, const DtString &function, double value, bool repeat) override
 
virtual int munitionResourceCount (const DtEntityType &munitionName) const
 
- Public Member Functions inherited from makVre::DtVreSimComponent< DtSimComponent >
 DtVreSimComponent (const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
 
virtual ~DtVreSimComponent ()
 
bool isPlayerControlled (const std::string &role="") const
 
DtString entitySystemName () const
 

Static Public Member Functions

static DtSimComponent * creator (const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
 

Protected Member Functions

virtual void initWeaponConfigs ()
 
virtual void addWeaponConfig (DtComponentSystem *system, const std::string &postfix)
 
virtual void updateAmmo ()
 
virtual void sendWeaponConfig ()
 
virtual void sendAmmoUpdate (const std::string &weapon, const DtEntityType &munition, int count)
 
virtual DtVreMessageResult handleWeaponConfigRequestMessage (DtVreMessage *msg)
 
virtual DtVreMessageResult handleWeaponConfigSelectWeapon (DtVreMessage *msg)
 
virtual void processSetRestore (DtSimMessage *msg)
 
virtual bool selectNextWeapon ()
 
virtual bool selectWeapon (const DtString &selection)
 
virtual void updateRangeItems ()
 
virtual void joystickConnected () override
 
virtual void joystickDisconnected () override
 
DtRwPropertiesMap & getWeaponsStatusMap ()
 
DtRwPropertyString & getCurrentWeapon ()
 
virtual void replenishFuelAndAmmo ()
 

Static Protected Member Functions

static void setRestoreCallback (DtSimMessage *msg, void *usrData)
 

Protected Attributes

bool myWasPlayerControlled
 
bool myHasWeaponSystems
 
std::vector< std::string > myWeaponCycleOrder
 
std::vector< WeaponConfigResponseMessage::WeaponConfigmyWeaponConfigCache
 
std::map< DtEntityType, unsigned int > myAmmoCache
 

Private Member Functions

 DtWeaponsStatusController ()
 
 DtWeaponsStatusController (const DtWeaponsStatusController &orig)
 
const DtWeaponsStatusControlleroperator= (const DtWeaponsStatusController &orig)
 

Constructor & Destructor Documentation

◆ DtWeaponsStatusController() [1/3]

makVre::DtWeaponsStatusController::DtWeaponsStatusController ( const DtString & name,
DtLocalObject * owner,
DtSimulationServices * simManager,
DtComponentDescriptor * desc = 0,
DtReaderWriterRegistry * parentRegistry = 0 )

Constructor.

Parameters
nameThe name of this component
ownerThe local object that owns this component
simManagerThe simulation services manager
descComponent descriptor with configuration parameters
parentRegistryOptional parent registry for reader/writer functionality

Creates a new weapon status controller component with the specified parameters. Initializes the weapon status tracking system.

Referenced by DtWeaponsStatusController(), and operator=().

◆ ~DtWeaponsStatusController()

virtual makVre::DtWeaponsStatusController::~DtWeaponsStatusController ( )
overridevirtual

Virtual destructor.

Cleans up resources used by the weapon status controller component.

◆ DtWeaponsStatusController() [2/3]

makVre::DtWeaponsStatusController::DtWeaponsStatusController ( )
private

Default constructor (not implemented)

Default constructor is private and not implemented to prevent creation of instances without proper initialization.

◆ DtWeaponsStatusController() [3/3]

makVre::DtWeaponsStatusController::DtWeaponsStatusController ( const DtWeaponsStatusController & orig)
private

Copy constructor (not implemented)

Copy constructor is private and not implemented to prevent copy construction.

References DtWeaponsStatusController().

Member Function Documentation

◆ preFirstTickInit()

virtual void makVre::DtWeaponsStatusController::preFirstTickInit ( )
overridevirtual

Initializes the controller before the first tick.

Returns
None

Sets up state properties for weapon status tracking. This initialization relies on other systems already being initialized, so it can't be done in the init() method itself. Initializes weapon configurations and establishes initial weapon selection state.

◆ init()

virtual bool makVre::DtWeaponsStatusController::init ( )
overridevirtual

Initializes the controller.

Returns
True if initialization was successful, false otherwise

Initializes the weapon status controller, adding a setRestore callback for reinitializing state properties when the entity is restored. Also registers message handlers for weapon configuration requests.

◆ tick()

virtual void makVre::DtWeaponsStatusController::tick ( )
overridevirtual

Updates the controller state each simulation frame.

Updates weapon status properties each frame, tracking ammunition levels and selected weapon state. Handles both player-controlled and non-player controlled states, with different update behaviors for each.

◆ type()

virtual const char * makVre::DtWeaponsStatusController::type ( ) const
overridevirtual

Gets the type identifier for this component.

Returns
String identifying the component type (DtWeaponStatusControllerType)

Implements the DtSimComponent::type() method to return the type identifier for this component.

◆ creator()

static DtSimComponent * makVre::DtWeaponsStatusController::creator ( const DtString & name,
DtLocalObject * owner,
DtSimulationServices * simManager,
DtComponentDescriptor * desc = 0,
DtReaderWriterRegistry * parentRegistry = 0 )
static

Factory method to create a new instance of this component.

Parameters
nameThe name for the new component
ownerThe local object that will own this component
simManagerThe simulation services manager
descOptional component descriptor
parentRegistryOptional parent registry for reader/writer functionality
Returns
Pointer to the newly created component

Static factory method used by the component creation system to instantiate new instances of this component type.

◆ calcAndSetPortValues()

virtual void makVre::DtWeaponsStatusController::calcAndSetPortValues ( const DtString & functionGroup,
const DtString & function,
double value,
bool repeat )
overridevirtual

Processes joystick input for weapon cycling.

Parameters
functionGroupThe function group identifier for the input
functionThe specific function name for the input
valueThe input value (typically in range [-1.0, 1.0])
repeatFlag indicating whether the function should repeat

Handles the "CycleWeapon" joystick function by selecting the next weapon that has ammunition, or "None" if no weapons with ammunition are available. This allows players to quickly cycle through available weapons using joystick inputs.

◆ munitionResourceCount()

virtual int makVre::DtWeaponsStatusController::munitionResourceCount ( const DtEntityType & munitionName) const
virtual

Gets the count of a specific munition resource.

Parameters
munitionNameThe name of the munition resource to count
Returns
The number of units of the specified munition available

Retrieves the current count of a specific munition resource by name. Returns 0 if the resource is not found or depleted.

◆ initWeaponConfigs()

virtual void makVre::DtWeaponsStatusController::initWeaponConfigs ( )
protectedvirtual

Initializes weapon configurations from entity's weapon systems.

Returns
True if weapon configurations were successfully initialized, false otherwise

Sets up the weapon configuration map from the entity's weapon systems. Identifies and catalogs all weapon systems on the entity, setting up the data structures needed to track their status.

◆ addWeaponConfig()

virtual void makVre::DtWeaponsStatusController::addWeaponConfig ( DtComponentSystem * system,
const std::string & postfix )
protectedvirtual

Adds a weapon configuration for a specific weapon system.

Parameters
systemThe component system representing a weapon system
postfixThe suffix to add to the weapon category name

Adds a weapon configuration for the specified weapon system to the weapon configuration map. The postfix parameter is used to distinguish between multiple weapon systems of the same category.

◆ updateAmmo()

virtual void makVre::DtWeaponsStatusController::updateAmmo ( )
protectedvirtual

◆ sendWeaponConfig()

virtual void makVre::DtWeaponsStatusController::sendWeaponConfig ( )
protectedvirtual

Sends a weapon configuration response message.

Constructs and sends a response message containing detailed information about all weapon configurations on the entity. This includes weapon categories, ammunition types, ranges, and other properties.

◆ sendAmmoUpdate()

virtual void makVre::DtWeaponsStatusController::sendAmmoUpdate ( const std::string & weapon,
const DtEntityType & munition,
int count )
protectedvirtual

◆ handleWeaponConfigRequestMessage()

virtual DtVreMessageResult makVre::DtWeaponsStatusController::handleWeaponConfigRequestMessage ( DtVreMessage * msg)
protectedvirtual

Handles weapon configuration request messages.

Parameters
msgThe message containing the weapon configuration request
Returns
Message processing result indicating success or failure

Processes messages requesting information about the entity's weapon configurations. Triggers the sending of a weapon configuration response.

◆ handleWeaponConfigSelectWeapon()

virtual DtVreMessageResult makVre::DtWeaponsStatusController::handleWeaponConfigSelectWeapon ( DtVreMessage * msg)
protectedvirtual

Handles weapon selection messages.

Parameters
msgThe message containing the weapon selection request
Returns
Message processing result indicating success or failure

Processes messages requesting the selection of a specific weapon category. Updates the selected weapon state property and related weapon status information.

◆ setRestoreCallback()

static void makVre::DtWeaponsStatusController::setRestoreCallback ( DtSimMessage * msg,
void * usrData )
staticprotected

Static callback function for set restore messages.

Parameters
msgThe simulation message containing restore information
usrDataUser data pointer, typically pointing to an instance of this class

Static function registered as a callback to handle set restore messages. Forwards the message to the appropriate instance's processSetRestore method.

◆ processSetRestore()

virtual void makVre::DtWeaponsStatusController::processSetRestore ( DtSimMessage * msg)
protectedvirtual

Reinitializes state properties during entity restoration.

Parameters
msgThe simulation message containing restore information

Reinitializes weapon status state properties when a set restore operation is executed. Ensures that weapon configurations and status information are properly restored after entity restoration.

◆ selectNextWeapon()

virtual bool makVre::DtWeaponsStatusController::selectNextWeapon ( )
protectedvirtual

Finds the next weapon system category to select.

Returns
String containing the category name of the next weapon system

Finds the category for the next weapon system to select, using the order defined in the descriptor if it exists, or falling back on the order of elements in the state property. Only considers weapon systems that have ammunition available.

◆ selectWeapon()

virtual bool makVre::DtWeaponsStatusController::selectWeapon ( const DtString & selection)
protectedvirtual

◆ updateRangeItems()

virtual void makVre::DtWeaponsStatusController::updateRangeItems ( )
protectedvirtual

Updates range information for the selected weapon system.

Clears the existing range items in state properties, then adds minimum, optimal, and maximum range values for the selected weapon system. This information is used by the UI to display weapon range indicators.

◆ joystickConnected()

virtual void makVre::DtWeaponsStatusController::joystickConnected ( )
overrideprotectedvirtual

Handles joystick connection events.

Required by the DtJoystickControllerInterface but implemented as a no-op since no special handling is needed when a joystick is connected.

◆ joystickDisconnected()

virtual void makVre::DtWeaponsStatusController::joystickDisconnected ( )
overrideprotectedvirtual

Handles joystick disconnection events.

Required by the DtJoystickControllerInterface but implemented as a no-op since no special handling is needed when a joystick is disconnected.

◆ getWeaponsStatusMap()

DtRwPropertiesMap & makVre::DtWeaponsStatusController::getWeaponsStatusMap ( )
protected

◆ getCurrentWeapon()

DtRwPropertyString & makVre::DtWeaponsStatusController::getCurrentWeapon ( )
protected

◆ replenishFuelAndAmmo()

virtual void makVre::DtWeaponsStatusController::replenishFuelAndAmmo ( )
protectedvirtual

Replenishes fuel and ammunition resources.

Restores all fuel and ammunition resources to their maximum levels. Used during entity restoration or for gameplay mechanics that provide resource replenishment.

◆ operator=()

const DtWeaponsStatusController & makVre::DtWeaponsStatusController::operator= ( const DtWeaponsStatusController & orig)
private

Assignment operator (not implemented)

Returns
Reference to this object

Assignment operator is private and not implemented to prevent assignment.

References DtWeaponsStatusController().

Member Data Documentation

◆ myWasPlayerControlled

bool makVre::DtWeaponsStatusController::myWasPlayerControlled
protected

Flag tracking player control state.

Used to track when a player first takes control of the entity, in order to trigger a full update of weapon status property values. Helps ensure that the interface shows current values when a player first engages control.

◆ myHasWeaponSystems

bool makVre::DtWeaponsStatusController::myHasWeaponSystems
protected

Flag indicating if entity has weapon systems.

True if the ownship entity has weapon systems that need to be updated. Used to optimize performance by skipping weapon updates for entities that don't have weapons.

◆ myWeaponCycleOrder

std::vector<std::string> makVre::DtWeaponsStatusController::myWeaponCycleOrder
protected

Ordered list of weapon categories for cycling.

Defines the order to cycle through weapon categories. Either specified in the descriptor or determined by the order the weapon systems are defined in the entity file. Used when cycling through weapons with joystick inputs.

◆ myWeaponConfigCache

std::vector<WeaponConfigResponseMessage::WeaponConfig> makVre::DtWeaponsStatusController::myWeaponConfigCache
protected

◆ myAmmoCache

std::map<DtEntityType, unsigned int> makVre::DtWeaponsStatusController::myAmmoCache
protected

The documentation for this class was generated from the following file: