|
VR-Engage
2.2
|
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>
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::WeaponConfig > | myWeaponConfigCache |
| std::map< DtEntityType, unsigned int > | myAmmoCache |
Private Member Functions | |
| DtWeaponsStatusController () | |
| DtWeaponsStatusController (const DtWeaponsStatusController &orig) | |
| const DtWeaponsStatusController & | operator= (const DtWeaponsStatusController &orig) |
| makVre::DtWeaponsStatusController::DtWeaponsStatusController | ( | const DtString & | name, |
| DtLocalObject * | owner, | ||
| DtSimulationServices * | simManager, | ||
| DtComponentDescriptor * | desc = 0, | ||
| DtReaderWriterRegistry * | parentRegistry = 0 ) |
Constructor.
| name | The name of this component |
| owner | The local object that owns this component |
| simManager | The simulation services manager |
| desc | Component descriptor with configuration parameters |
| parentRegistry | Optional 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=().
|
overridevirtual |
Virtual destructor.
Cleans up resources used by the weapon status controller component.
|
private |
Default constructor (not implemented)
Default constructor is private and not implemented to prevent creation of instances without proper initialization.
|
private |
Copy constructor (not implemented)
Copy constructor is private and not implemented to prevent copy construction.
References DtWeaponsStatusController().
|
overridevirtual |
Initializes the controller before the first tick.
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.
|
overridevirtual |
Initializes the controller.
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.
|
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.
|
overridevirtual |
Gets the type identifier for this component.
Implements the DtSimComponent::type() method to return the type identifier for this component.
|
static |
Factory method to create a new instance of this component.
| name | The name for the new component |
| owner | The local object that will own this component |
| simManager | The simulation services manager |
| desc | Optional component descriptor |
| parentRegistry | Optional parent registry for reader/writer functionality |
Static factory method used by the component creation system to instantiate new instances of this component type.
|
overridevirtual |
Processes joystick input for weapon cycling.
| functionGroup | The function group identifier for the input |
| function | The specific function name for the input |
| value | The input value (typically in range [-1.0, 1.0]) |
| repeat | Flag 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.
|
virtual |
Gets the count of a specific munition resource.
| munitionName | The name of the munition resource to count |
Retrieves the current count of a specific munition resource by name. Returns 0 if the resource is not found or depleted.
|
protectedvirtual |
Initializes weapon configurations from entity's weapon systems.
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.
|
protectedvirtual |
Adds a weapon configuration for a specific weapon system.
| system | The component system representing a weapon system |
| postfix | The 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.
|
protectedvirtual |
|
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.
|
protectedvirtual |
|
protectedvirtual |
Handles weapon configuration request messages.
| msg | The message containing the weapon configuration request |
Processes messages requesting information about the entity's weapon configurations. Triggers the sending of a weapon configuration response.
|
protectedvirtual |
Handles weapon selection messages.
| msg | The message containing the weapon selection request |
Processes messages requesting the selection of a specific weapon category. Updates the selected weapon state property and related weapon status information.
|
staticprotected |
Static callback function for set restore messages.
| msg | The simulation message containing restore information |
| usrData | User 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.
|
protectedvirtual |
Reinitializes state properties during entity restoration.
| msg | The 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.
|
protectedvirtual |
Finds the next weapon system category to select.
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.
|
protectedvirtual |
|
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.
|
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.
|
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.
|
protected |
|
protected |
|
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.
|
private |
Assignment operator (not implemented)
Assignment operator is private and not implemented to prevent assignment.
References DtWeaponsStatusController().
|
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.
|
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.
|
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.
|
protected |
|
protected |