PGE API 0.4
PR00F's Game Engine full documentation
Loading...
Searching...
No Matches
Weapon Class Reference

Weapon class for PR00F's Game Engine Weapon Manager. More...

Detailed Description

Weapon class for PR00F's Game Engine Weapon Manager.

Definition at line 323 of file WeaponManager.h.

#include <WeaponManager.h>

+ Inheritance diagram for Weapon:

Public Types

enum  State { WPN_READY , WPN_RELOADING , WPN_SHOOTING }
 
enum  FiringMode { WPN_FM_SEMI , WPN_FM_BURST , WPN_FM_PROJ , WPN_FM_AUTO }
 
enum  Type { Ranged , Melee , Throwable }
 

Public Member Functions

 Weapon (const char *fname, PgeObjectPool< PooledBullet > &bullets, pge_audio::PgeAudio &audio, PR00FsUltimateRenderingEngine &gfx, pge_network::PgeNetworkConnectionHandle connHandle)
 
virtual ~Weapon ()
 
CConsole & getConsole () const
 Returns access to console preset with logger module name as this class.
 
const WeaponIdgetUniqueId () const
 
const TypegetType () const
 
PureObject3D & getObject3D ()
 Returns the graphical object entity associated to this weapon object.
 
const PureObject3D & getObject3D () const
 Returns the graphical object entity associated to this weapon object.
 
void UpdatePosition (const PureVector &playerPos, bool bStickToCenter)
 Updates the graphical object entity associated to this weapon object.
 
void UpdatePositions (const PureVector &playerPos, TPureFloat fAngleY, TPureFloat fAngleZ)
 Updates the graphical object entity associated to this weapon object.
 
void UpdatePositions (const PureVector &playerPos, const PureVector &targetPos2D)
 Updates the graphical object entity associated to this weapon object.
 
const FiringModegetCurrentFiringMode () const
 Returns the current firing mode of the weapon.
 
TPureUInt getUnmagBulletCount () const
 Returns the "unmag" bullet count of this weapon.
 
void SetUnmagBulletCount (TPureUInt count)
 Sets the "unmag" bullet count of this weapon.
 
TPureUInt getMagBulletCount () const
 Returns the "mag" bullet count of this weapon.
 
void SetMagBulletCount (TPureUInt count)
 Sets the "mag" bullet count of this weapon.
 
bool canIncBulletCount () const
 Returns if we can add more bullets for this weapon.
 
void IncBulletCount (TPureUInt count)
 Adds more bullets for this weapon.
 
const pge_network::PgeNetworkConnectionHandlegetOwner () const
 Returns the player associated with this weapon.
 
void SetOwner (const pge_network::PgeNetworkConnectionHandle &owner)
 Sets the player associated with this weapon.
 
bool update ()
 Updates the weapon based on the time elapsed since last call to this function.
 
const PgeOldNewValue< State > & getState () const
 Returns the current state of the weapon.
 
void clientReceiveStateFromServer (const State &state)
 
void updateOldValues ()
 
TPureBool reload ()
 Reloads the weapon i.e.
 
TPureBool pullTrigger (bool bMoving, bool bRun, bool bDuck)
 Pulls the trigger of the weapon, which might result in shooting the weapon.
 
void releaseTrigger ()
 Releases the trigger of the weapon.
 
bool isTriggerReleased () const
 Returns the state of the trigger.
 
void Reset ()
 Resets properties of the weapon to its initial values like when it was just loaded from file.
 
bool isAvailable () const
 Returns if this weapon is available for the player.
 
void SetAvailable (bool bAvail)
 Changes the availability of this weapon for the player.
 
float getDamagePerFireRating () const
 Returns a calculated rating of damage caused by a single shot fired.
 
float getFiringRate () const
 Returns a calculated firing rate per 1 second.
 
float getDamagePerSecondRating () const
 Returns a calculated rating of total damage per 1 second.
 
float getAccuracyByPose (bool bMoving, bool bRun, bool bDuck) const
 Returns a calculated accuracy based on player's pose.
 
float getLowestAccuracyByPose () const
 Returns the lowest possible accuracy of this weapon, based only on player's pose.
 
float getMomentaryRecoilMultiplier () const
 Returns the momentary recoil multiplier.
 
float getMaximumRecoilMultiplier () const
 Returns the weapon's maximum recoil multiplier.
 
float getMomentaryAccuracy (bool bMoving, bool bRun, bool bDuck) const
 Returns the calculated momentary accuracy based on all factors.
 
float getLowestAccuracyPossible () const
 Returns a positive relative bullet angle representing the lowest possible accuracy with this weapon.
 
float getRandomRelativeBulletAngle (bool bMoving, bool bRun, bool bDuck) const
 Returns a random relative angle for a bullet.
 
SoLoud::Wav & getFiringSound ()
 
SoLoud::Wav & getDryFiringSound ()
 
SoLoud::Wav & getReloadStartSound ()
 
SoLoud::Wav & getReloadEndSound ()
 
SoLoud::Wav & getPlayerHitSound ()
 
SoLoud::Wav & getWallHitSound ()
 
 Weapon (const Weapon &other)
 
Weaponoperator= (const Weapon &other)
 
- Public Member Functions inherited from PGEcfgFile
 PGEcfgFile (bool bRequireAllAcceptedVarsDefineRequirement, bool bCaseSensitiveVars)
 
virtual ~PGEcfgFile ()
 
CConsole & getConsole () const
 Returns access to console preset with logger module name as this class.
 
std::map< std::string, PGEcfgVariable > & getVars ()
 
const std::map< std::string, PGEcfgVariable > & getVars () const
 
bool load (const char *fname)
 Loads variables from the given config file.
 
bool save (const char *fname="") const
 Saves variables to the given config file.
 
const std::string & getFilename () const
 
const std::string & getPathToFile () const
 
bool getAllAcceptedVarsDefineRequirement () const
 
bool getCaseSensitiveVars () const
 
const std::set< std::string > & getAcceptedVars () const
 
bool setAcceptedVars (const std::set< std::string > &newAcceptedVars)
 
std::vector< std::string > & getTemplate ()
 Returns the lines of the template generated from the loaded config file.
 
const std::vector< std::string > & getTemplate () const
 Returns the lines of the template generated from the loaded config file.
 
 PGEcfgFile (const PGEcfgFile &other)
 
PGEcfgFileoperator= (const PGEcfgFile &other)
 

Static Public Member Functions

static const char * getLoggerModuleName ()
 Returns the logger module name of this class.
 
static std::string stateToString (const State &eState)
 
- Static Public Member Functions inherited from PGEcfgFile
static const char * getLoggerModuleName ()
 Returns the logger module name of this class.
 

Static Public Attributes

static constexpr TPureFloat WpnYBiasToPlayerCenter { 0.15f }
 

Private Types

typedef std::pair< FiringMode, std::string > FiringModeEnumToStringPair
 

Private Member Functions

 Weapon ()
 
void UpdateGraphics ()
 

Private Attributes

PgeObjectPool< PooledBullet > & m_bullets
 
pge_audio::PgeAudiom_audio
 
PR00FsUltimateRenderingEngine & m_gfx
 
pge_network::PgeNetworkConnectionHandle m_connHandle
 Owner (shooter) of this weapon.
 
PureObject3D * m_obj
 
WeaponId m_id {}
 Unique ID, filled by ctor.
 
Type m_type {}
 Type of weapon, filled by ctor.
 
PgeOldNewValue< Statem_state
 State as calculated and updated by PGE server instance.
 
FiringMode m_firingMode
 Current firing mode, something between getVars("firing_mode_def") and getVars("firing_mode_max").
 
TPureUInt m_nUnmagBulletCount
 Spare bullets not loaded into weapon.
 
TPureUInt m_nMagBulletCount
 Bullets loaded into weapon.
 
TPureUInt m_nBulletsToReload
 Only updated during reload() / Update().
 
PFL::timeval m_timeReloadStarted
 Only updated during reload() / Update().
 
PFL::timeval m_timeLastShot
 Only updated during pullTrigger() / Update().
 
bool m_bAvailable
 Flag for the game, e.g.
 
bool m_bTriggerReleased
 True if trigger is released, false when being pulled.
 
SoLoud::Wav m_sndShoot
 
SoLoud::Wav m_sndShootDry
 
SoLoud::Wav m_sndReloadStart
 
SoLoud::Wav m_sndReloadEnd
 
SoLoud::Wav m_sndDamageWall
 
SoLoud::Wav m_sndDamagePlayer
 

Static Private Attributes

static const std::vector< FiringModeEnumToStringPairm_vecOrderOfFiringModes
 
static std::set< std::string > m_WpnAcceptedVars
 

Additional Inherited Members

- Protected Member Functions inherited from PGEcfgFile
virtual bool validateOnLoad (std::ifstream &) const
 Validate the file being processed by load().
 
virtual bool validateOnSave (std::ofstream &) const
 Validate the file being processed by save().
 
- Static Protected Member Functions inherited from PGEcfgFile
static bool lineIsValueAssignment (const std::string &sTrimmedLine, bool bCaseSensitiveVars, std::string &sVar, std::string &sValue, bool &bParseError)
 
- Protected Attributes inherited from PGEcfgFile
std::set< std::string > m_acceptedVars
 
std::map< std::string, PGEcfgVariablem_vars
 

Member Typedef Documentation

◆ FiringModeEnumToStringPair

std::pair<FiringMode, std::string> Weapon::FiringModeEnumToStringPair
private

Definition at line 503 of file WeaponManager.h.

Member Enumeration Documentation

◆ FiringMode

Enumerator
WPN_FM_SEMI 

Semi-automatic: trigger needs to be pulled-and-released as many times as many bullets we want to fire.

WPN_FM_BURST 

Similar to semi, but 1 trigger pull shots some (limited amount) bullets after each other.

WPN_FM_PROJ 

Similar to burst, but 1 trigger pull shots some (limited amount) of projectiles AT ONCE, e.g.

shotguns.

WPN_FM_AUTO 

Trigger needs to be pulled only once to fire continuously until we have bullet.

Definition at line 337 of file WeaponManager.h.

◆ State

Enumerator
WPN_READY 
WPN_RELOADING 
WPN_SHOOTING 

Definition at line 330 of file WeaponManager.h.

◆ Type

Enumerator
Ranged 
Melee 
Throwable 

Definition at line 345 of file WeaponManager.h.

Constructor & Destructor Documentation

◆ Weapon() [1/3]

Weapon::Weapon ( const char * fname,
PgeObjectPool< PooledBullet > & bullets,
pge_audio::PgeAudio & audio,
PR00FsUltimateRenderingEngine & gfx,
pge_network::PgeNetworkConnectionHandle connHandle )
Parameters
fnamePath and filename of the Weapon file to be loaded.
bulletsA bullet pool for storing the bullets that are fired by Weapon instances created by this WeaponManager instance. Remember, the pool needs to be properly initialized with non-zero capacity, otherwise bullets cannot be fired.
audioThe engine's audio subsystem instance.
gfxThe engine's graphics subsystem instance.
connHandleConnection handle of the player owning this Weapon instance.

Definition at line 457 of file WeaponManager.cpp.

◆ ~Weapon()

Weapon::~Weapon ( )
virtual

Definition at line 844 of file WeaponManager.cpp.

◆ Weapon() [2/3]

Weapon::Weapon ( const Weapon & other)
inline

Definition at line 431 of file WeaponManager.h.

◆ Weapon() [3/3]

Weapon::Weapon ( )
private

Definition at line 1688 of file WeaponManager.cpp.

Member Function Documentation

◆ canIncBulletCount()

bool Weapon::canIncBulletCount ( ) const

Returns if we can add more bullets for this weapon.

Returns if we can add more bullets for this weapon, i.e.

if we can pick up more bullets for this weapon. Useful if we are touching bullet pack for this weapon and want to check if we can pick that up, or we are actually full. Basically this depends on the "unmag" or "mag" bullet count compared to getVars()["cap_max"], depending on if the weapon is reloadable or not.

Returns
True if we can still add more bullets for this weapon, false otherwise.

Definition at line 1091 of file WeaponManager.cpp.

◆ clientReceiveStateFromServer()

void Weapon::clientReceiveStateFromServer ( const State & state)

Definition at line 1226 of file WeaponManager.cpp.

◆ getAccuracyByPose()

float Weapon::getAccuracyByPose ( bool bMoving,
bool bRun,
bool bDuck ) const

Returns a calculated accuracy based on player's pose.

Returns a calculated accuracy (aim) based on player's pose.

This is basically the weapon's base accuracy (CVAR: acc_angle) multiplied by CVARS: acc_m_duck, acc_m_run, acc_m_walk.

Parameters
bMovingSet to true of player is moving (walk or run), or false if is still at the moment.
bRunUsed only if bMoving is true. If bRun is true, CVAR acc_m_run will be used, otherwise CVAR acc_m_walk will be used for calculation.
bDuckIf true, accuracy will be multiplied by CVAR acc_m_duck.
Returns
Calculated accuracy based on player's pose.

Definition at line 1508 of file WeaponManager.cpp.

◆ getConsole()

CConsole & Weapon::getConsole ( ) const

Returns access to console preset with logger module name as this class.

Definition at line 855 of file WeaponManager.cpp.

◆ getCurrentFiringMode()

const Weapon::FiringMode & Weapon::getCurrentFiringMode ( ) const

Returns the current firing mode of the weapon.

This is something between getVars("firing_mode_def") and getVars("firing_mode_max").

Returns
Current firing mode of the weapon.

Definition at line 1014 of file WeaponManager.cpp.

◆ getDamagePerFireRating()

float Weapon::getDamagePerFireRating ( ) const

Returns a calculated rating of damage caused by a single shot fired.

Returns a calculated rating of damage caused by a single shot fired: DPFR.

This is a positive number usually in range [0.01, 100], rarely even bigger.

Returns
DPFR (Damage per Fire Rating) caused by a single shot fired, calculated as: damage_hp * damage_ap / 100.f.

Definition at line 1450 of file WeaponManager.cpp.

◆ getDamagePerSecondRating()

float Weapon::getDamagePerSecondRating ( ) const

Returns a calculated rating of total damage per 1 second.

Returns a calculated rating of total damage per 1 second: DPSR.

This is used by WeaponManager to put Weapons into order based on their power. Always positive.

Returns
DPSR (Damage per Second Rating), calculated as: (1000.f/firing_cooldown * DPFR)^2.

Definition at line 1487 of file WeaponManager.cpp.

◆ getDryFiringSound()

SoLoud::Wav & Weapon::getDryFiringSound ( )

Definition at line 1645 of file WeaponManager.cpp.

◆ getFiringRate()

float Weapon::getFiringRate ( ) const

Returns a calculated firing rate per 1 second.

Currently it takes the firing cooldown into account, not considering magazine size and reload time. So this is perfect only for those weapons which cannot be emptied within 1 second with continuous firing. If a weapon can be emptied within 1 second and reload is needed to continue firing, this function returns imprecise value.

Also, this function does not consider weapon with different firing modes yet.

Returns
Firing rate per second i.e. how many bullets this weapon can fire within 1 second.

Definition at line 1473 of file WeaponManager.cpp.

◆ getFiringSound()

SoLoud::Wav & Weapon::getFiringSound ( )

Definition at line 1640 of file WeaponManager.cpp.

◆ getLoggerModuleName()

const char * Weapon::getLoggerModuleName ( )
static

Returns the logger module name of this class.

Definition at line 870 of file WeaponManager.cpp.

◆ getLowestAccuracyByPose()

float Weapon::getLowestAccuracyByPose ( ) const

Returns the lowest possible accuracy of this weapon, based only on player's pose.

Returns the lowest possible accuracy (aim) of this weapon, based only on player's pose.

Note: I use the term "weapon accuracy" interchangeably with "aim".

Returns
The lowest possible accuracy (aim) of this weapon, based only on player's pose

Definition at line 1526 of file WeaponManager.cpp.

◆ getLowestAccuracyPossible()

float Weapon::getLowestAccuracyPossible ( ) const

Returns a positive relative bullet angle representing the lowest possible accuracy with this weapon.

Returns a positive relative bullet angle representing the lowest possible accuracy (aim) with this weapon.

The higher is the absolute value of the relative bullet angle, the lower the accuracy (aim) is.

Note: I use the term "weapon accuracy" interchangeably with "aim".

Returns
A positive relative bullet angle representing the lowest possible accuracy (aim) with this weapon.

Definition at line 1613 of file WeaponManager.cpp.

◆ getMagBulletCount()

TPureUInt Weapon::getMagBulletCount ( ) const

Returns the "mag" bullet count of this weapon.

This is the number of bullets already loaded into the weapon. A weapon can be fired only if it has positive "mag" bullet count. "Mag" is short for "magazine", even though not all weapons have "magazines", we always refer to "mag" bullet count to know how many bullets are ready to be fired from the weapon without the need of reload. This also means that not reloadable weapons have all their bullets counted as "mag" bullet count.

Returns
"Mag" bullet count i.e. number of bullets already loaded into the weapon.

Definition at line 1056 of file WeaponManager.cpp.

◆ getMaximumRecoilMultiplier()

float Weapon::getMaximumRecoilMultiplier ( ) const

Returns the weapon's maximum recoil multiplier.

This is basically value of CVAR recoil_m. The minimum recoil multiplier is always 1.f for any weapon.

Returns
The maximum recoil multiplier for this weapon.

Definition at line 1581 of file WeaponManager.cpp.

◆ getMomentaryAccuracy()

float Weapon::getMomentaryAccuracy ( bool bMoving,
bool bRun,
bool bDuck ) const

Returns the calculated momentary accuracy based on all factors.

Returns the calculated momentary accuracy (aim) based on all factors.

The momentary accuracy depends on multiple factors:

Note: I use the term "weapon accuracy" interchangeably with "aim".

Parameters
bMovingSame as for getAccuracyByPose().
bRunSame as for getAccuracyByPose().
bDuckSame as for getAccuracyByPose().
Returns
The calculated momentary accuracy (aim) based on all factors.

Definition at line 1600 of file WeaponManager.cpp.

◆ getMomentaryRecoilMultiplier()

float Weapon::getMomentaryRecoilMultiplier ( ) const

Returns the momentary recoil multiplier.

The momentary recoil multiplier is always between 1.0 and CVAR recoil_m. When a shot is fired, the momentary recoil multiplier is set to CVAR recoil_m, and then is it linear decreased to 1.0 over the duration of CVAR recoil_cooldown. This causes rapid firing less accurate than moderate firing with the same weapon. Note that CVAR recoil_m set to 1.0 means no recoil i.e. weapon accuracy (aim) is not affected by recoil.

Returns
The momentary recoil multiplier.

Definition at line 1541 of file WeaponManager.cpp.

◆ getObject3D() [1/2]

PureObject3D & Weapon::getObject3D ( )

Returns the graphical object entity associated to this weapon object.

Definition at line 893 of file WeaponManager.cpp.

◆ getObject3D() [2/2]

const PureObject3D & Weapon::getObject3D ( ) const

Returns the graphical object entity associated to this weapon object.

Definition at line 901 of file WeaponManager.cpp.

◆ getOwner()

const pge_network::PgeNetworkConnectionHandle & Weapon::getOwner ( ) const

Returns the player associated with this weapon.

This is the player specified originally in the constructor of this Weapon object, or another player set using SetOwner(). Players are identified by their connection handle.

Returns
Connection handle of player associated with this Weapon object.

Definition at line 1129 of file WeaponManager.cpp.

◆ getPlayerHitSound()

SoLoud::Wav & Weapon::getPlayerHitSound ( )

Definition at line 1660 of file WeaponManager.cpp.

◆ getRandomRelativeBulletAngle()

float Weapon::getRandomRelativeBulletAngle ( bool bMoving,
bool bRun,
bool bDuck ) const

Returns a random relative angle for a bullet.

Returns a random relative Z angle for a newborn bullet.

This relative Z angle is the difference of the Z angles of the weapon and the newborn bullet. The relative Z angle can be positive or negative but its absolute maximum value is the momentary accuracy (aim) (getMomentaryAccuracy()).

Note: I use the term "weapon accuracy" interchangeably with "aim".

Parameters
bMovingSame as for getAccuracyByPose().
bRunSame as for getAccuracyByPose().
bDuckSame as for getAccuracyByPose().
Returns
A random relative Z angle for a newborn bullet, in the [-getMomentaryAccuracy(), getMomentaryAccuracy()] range.

Definition at line 1631 of file WeaponManager.cpp.

◆ getReloadEndSound()

SoLoud::Wav & Weapon::getReloadEndSound ( )

Definition at line 1655 of file WeaponManager.cpp.

◆ getReloadStartSound()

SoLoud::Wav & Weapon::getReloadStartSound ( )

Definition at line 1650 of file WeaponManager.cpp.

◆ getState()

const PgeOldNewValue< Weapon::State > & Weapon::getState ( ) const

Returns the current state of the weapon.

Weapon state can be updated by functions like pullTrigger(), reload(), update(), etc. Weapon state is totally independent of the state of trigger, see: isTriggerReleased().

Returns
Current state of the weapon.

Definition at line 1221 of file WeaponManager.cpp.

◆ getType()

const Weapon::Type & Weapon::getType ( ) const

Definition at line 865 of file WeaponManager.cpp.

◆ getUniqueId()

const WeaponId & Weapon::getUniqueId ( ) const

Definition at line 860 of file WeaponManager.cpp.

◆ getUnmagBulletCount()

TPureUInt Weapon::getUnmagBulletCount ( ) const

Returns the "unmag" bullet count of this weapon.

This is the number of bullets with the player not loaded into the weapon. To fire these bullets, they first need to be loaded into the weapon using reload(). Only reloadable weapons can have positive number of "unmag" bullets.

Returns
"Unmag" bullet count i.e. number of bullets with the player not loaded into the weapon.

Definition at line 1027 of file WeaponManager.cpp.

◆ getWallHitSound()

SoLoud::Wav & Weapon::getWallHitSound ( )

Definition at line 1665 of file WeaponManager.cpp.

◆ IncBulletCount()

void Weapon::IncBulletCount ( TPureUInt count)

Adds more bullets for this weapon.

Useful when we are picking up bullet pack for this weapon or same kind of weapon.

Parameters
countHow many bullets we want to add. The actual increase value might be less. See more details at canIncBulletCount().

Definition at line 1109 of file WeaponManager.cpp.

◆ isAvailable()

bool Weapon::isAvailable ( ) const

Returns if this weapon is available for the player.

The player is that client whose connection handle was specified in the constructor of this Weapon object.

Returns
True if this weapon is available for the player, false otherwise.

Definition at line 1431 of file WeaponManager.cpp.

◆ isTriggerReleased()

bool Weapon::isTriggerReleased ( ) const

Returns the state of the trigger.

Note that the trigger state is independent of the state of the weapon that can be queried by getState(). For example:

  • a pulled trigger may or may not transition the state to WPN_SHOOTING;
  • releasing the trigger while the weapon has WPN_SHOOTING state doesn't change the state to anything else.
Returns
True if the trigger is in released position, false if it is pulled.

Definition at line 1388 of file WeaponManager.cpp.

◆ operator=()

Weapon & Weapon::operator= ( const Weapon & other)
inline

Definition at line 464 of file WeaponManager.h.

◆ pullTrigger()

TPureBool Weapon::pullTrigger ( bool bMoving,
bool bRun,
bool bDuck )

Pulls the trigger of the weapon, which might result in shooting the weapon.

Firing an actual shot depends on different things like current state of the weapon, firing mode, etc. If a shot was actually fired, at least one new bullet is placed in 'bullets' specified in the constructor of this weapon.

Similar to ranged weapons, for melee type weapons as well, this is the attack function.

Parameters
bMovingSame as for getAccuracyByPose().
bRunSame as for getAccuracyByPose().
bDuckSame as for getAccuracyByPose().
Returns
True if a shot was actually triggered, false otherwise.

Definition at line 1301 of file WeaponManager.cpp.

◆ releaseTrigger()

void Weapon::releaseTrigger ( )

Releases the trigger of the weapon.

It is important to invoke this function whenever the player's input imply it. Some firing modes require repeated pull-and-release of the trigger, see FiringMode for details.

Definition at line 1374 of file WeaponManager.cpp.

◆ reload()

TPureBool Weapon::reload ( )

Reloads the weapon i.e.

moves some "unmag" bullets into "mag" bullet count.

moves some "unmag" bullets into "mag" bullet count. See the return value of the function if you are interested in if the reloading is actually triggered by this call. It can happen that the reloading process is not initiated by this call, e.g. reloading has been already initiated previously, or the magazine is already full, etc.

Returns
True if reload has been actually initiated by this call, false otherwise.

Definition at line 1247 of file WeaponManager.cpp.

◆ Reset()

void Weapon::Reset ( )

Resets properties of the weapon to its initial values like when it was just loaded from file.

Useful when the player respawns and we need to reset all of their weapons. The availability for the player is also being reset to false.

Definition at line 1398 of file WeaponManager.cpp.

◆ SetAvailable()

void Weapon::SetAvailable ( bool bAvail)

Changes the availability of this weapon for the player.

Definition at line 1439 of file WeaponManager.cpp.

◆ SetMagBulletCount()

void Weapon::SetMagBulletCount ( TPureUInt count)

Sets the "mag" bullet count of this weapon.

See getMagBulletCount() for better understanding "mag" bullet count.

Parameters
countThe "mag" bullet count to be set. For reloadable weapons, this cannot be greater than getVars()["reloadable"]. For non-reloadable weapons, this cannot be greater than getVars()["cap_max"].

Definition at line 1069 of file WeaponManager.cpp.

◆ SetOwner()

void Weapon::SetOwner ( const pge_network::PgeNetworkConnectionHandle & owner)

Sets the player associated with this weapon.

Players are identified by their connection handle.

Definition at line 1138 of file WeaponManager.cpp.

◆ SetUnmagBulletCount()

void Weapon::SetUnmagBulletCount ( TPureUInt count)

Sets the "unmag" bullet count of this weapon.

See getUnmagBulletCount() for better understanding "unmag" bullet count.

Parameters
countThe "unmag" bullet count to be set. This cannot be greater than getVars()["cap_max"].

Definition at line 1038 of file WeaponManager.cpp.

◆ stateToString()

std::string Weapon::stateToString ( const State & eState)
static

Definition at line 875 of file WeaponManager.cpp.

◆ update()

bool Weapon::update ( )

Updates the weapon based on the time elapsed since last call to this function.

This function is recommended to be invoked by the game as often as possible, since it is time-dependent. Calling this function takes care of the state transition and other property updates of the weapon, initiated by a trigger pull or reload.

Returns
True if the mag- or unmag bullet count changed, false otherwise.

Definition at line 1151 of file WeaponManager.cpp.

◆ UpdateGraphics()

void Weapon::UpdateGraphics ( )
private

Definition at line 1701 of file WeaponManager.cpp.

◆ updateOldValues()

void Weapon::updateOldValues ( )

Definition at line 1232 of file WeaponManager.cpp.

◆ UpdatePosition()

void Weapon::UpdatePosition ( const PureVector & playerPos,
bool bStickToCenter )

Updates the graphical object entity associated to this weapon object.

Only the position is updated.

Definition at line 910 of file WeaponManager.cpp.

◆ UpdatePositions() [1/2]

void Weapon::UpdatePositions ( const PureVector & playerPos,
const PureVector & targetPos2D )

Updates the graphical object entity associated to this weapon object.

The position and angles are updated. The angles are updated to point to the specified targetPos2D value. This function can be used to update our weapon on our side.

Definition at line 935 of file WeaponManager.cpp.

◆ UpdatePositions() [2/2]

void Weapon::UpdatePositions ( const PureVector & playerPos,
TPureFloat fAngleY,
TPureFloat fAngleZ )

Updates the graphical object entity associated to this weapon object.

The position and angles are updated to the specified values. This function can be used to update the weapon of other clients on our side.

Definition at line 923 of file WeaponManager.cpp.

Member Data Documentation

◆ m_audio

pge_audio::PgeAudio& Weapon::m_audio
private

Definition at line 510 of file WeaponManager.h.

◆ m_bAvailable

bool Weapon::m_bAvailable
private

Flag for the game, e.g.

if true then the player has this weapon.

Definition at line 523 of file WeaponManager.h.

◆ m_bTriggerReleased

bool Weapon::m_bTriggerReleased
private

True if trigger is released, false when being pulled.

True by default.

Definition at line 524 of file WeaponManager.h.

◆ m_bullets

PgeObjectPool<PooledBullet>& Weapon::m_bullets
private

Definition at line 509 of file WeaponManager.h.

◆ m_connHandle

pge_network::PgeNetworkConnectionHandle Weapon::m_connHandle
private

Owner (shooter) of this weapon.

Should be used by PGE server instance only.

Definition at line 512 of file WeaponManager.h.

◆ m_firingMode

FiringMode Weapon::m_firingMode
private

Current firing mode, something between getVars("firing_mode_def") and getVars("firing_mode_max").

Definition at line 517 of file WeaponManager.h.

◆ m_gfx

PR00FsUltimateRenderingEngine& Weapon::m_gfx
private

Definition at line 511 of file WeaponManager.h.

◆ m_id

WeaponId Weapon::m_id {}
private

Unique ID, filled by ctor.

Definition at line 514 of file WeaponManager.h.

◆ m_nBulletsToReload

TPureUInt Weapon::m_nBulletsToReload
private

Only updated during reload() / Update().

Should be managed by PGE server instance.

Definition at line 520 of file WeaponManager.h.

◆ m_nMagBulletCount

TPureUInt Weapon::m_nMagBulletCount
private

Bullets loaded into weapon.

Even if weapon is not reloadable. Should be managed by PGE server instance.

Definition at line 519 of file WeaponManager.h.

◆ m_nUnmagBulletCount

TPureUInt Weapon::m_nUnmagBulletCount
private

Spare bullets not loaded into weapon.

Should be managed by PGE server instance.

Definition at line 518 of file WeaponManager.h.

◆ m_obj

PureObject3D* Weapon::m_obj
private

Definition at line 513 of file WeaponManager.h.

◆ m_sndDamagePlayer

SoLoud::Wav Weapon::m_sndDamagePlayer
private

Definition at line 530 of file WeaponManager.h.

◆ m_sndDamageWall

SoLoud::Wav Weapon::m_sndDamageWall
private

Definition at line 529 of file WeaponManager.h.

◆ m_sndReloadEnd

SoLoud::Wav Weapon::m_sndReloadEnd
private

Definition at line 528 of file WeaponManager.h.

◆ m_sndReloadStart

SoLoud::Wav Weapon::m_sndReloadStart
private

Definition at line 527 of file WeaponManager.h.

◆ m_sndShoot

SoLoud::Wav Weapon::m_sndShoot
private

Definition at line 525 of file WeaponManager.h.

◆ m_sndShootDry

SoLoud::Wav Weapon::m_sndShootDry
private

Definition at line 526 of file WeaponManager.h.

◆ m_state

PgeOldNewValue<State> Weapon::m_state
private

State as calculated and updated by PGE server instance.

Definition at line 516 of file WeaponManager.h.

◆ m_timeLastShot

PFL::timeval Weapon::m_timeLastShot
private

Only updated during pullTrigger() / Update().

Should be managed by PGE server instance.

Definition at line 522 of file WeaponManager.h.

◆ m_timeReloadStarted

PFL::timeval Weapon::m_timeReloadStarted
private

Only updated during reload() / Update().

Should be managed by PGE server instance.

Definition at line 521 of file WeaponManager.h.

◆ m_type

Type Weapon::m_type {}
private

Type of weapon, filled by ctor.

Definition at line 515 of file WeaponManager.h.

◆ m_vecOrderOfFiringModes

const std::vector< Weapon::FiringModeEnumToStringPair > Weapon::m_vecOrderOfFiringModes
staticprivate
Initial value:
=
{
{WPN_FM_SEMI, "semi"},
{WPN_FM_BURST, "burst"},
{WPN_FM_PROJ, "proj"},
{WPN_FM_AUTO, "auto"}
}
@ WPN_FM_SEMI
Semi-automatic: trigger needs to be pulled-and-released as many times as many bullets we want to fire...
@ WPN_FM_BURST
Similar to semi, but 1 trigger pull shots some (limited amount) bullets after each other.
@ WPN_FM_PROJ
Similar to burst, but 1 trigger pull shots some (limited amount) of projectiles AT ONCE,...
@ WPN_FM_AUTO
Trigger needs to be pulled only once to fire continuously until we have bullet.

Definition at line 1677 of file WeaponManager.h.

◆ m_WpnAcceptedVars

std::set< std::string > Weapon::m_WpnAcceptedVars
staticprivate

Definition at line 507 of file WeaponManager.h.

◆ WpnYBiasToPlayerCenter

TPureFloat Weapon::WpnYBiasToPlayerCenter { 0.15f }
staticconstexpr

Definition at line 352 of file WeaponManager.h.


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