PGE API 0.4
PR00F's Game Engine full documentation
|
PR00F's Game Engine Weapon Manager. More...
PR00F's Game Engine Weapon Manager.
The idea is that Weapon instances are created and stored by this manager. Each player has a different instance of Weapon Manager. Thus, for each player, Weapon instances also need to be created. This way, each player can utilize convenient manager functions, such as:
Definition at line 550 of file WeaponManager.h.
#include <WeaponManager.h>
Public Types | |
typedef std::map< unsigned char, std::string > | KeypressToWeaponMap |
Public Member Functions | |
WeaponManager (pge_audio::PgeAudio &audio, PGEcfgProfiles &cfgProfiles, PR00FsUltimateRenderingEngine &gfx, PgeObjectPool< PooledBullet > &bullets) | |
virtual | ~WeaponManager () |
CConsole & | getConsole () const |
Returns access to console preset with logger module name as this class. | |
Weapon * | load (const char *fname, pge_network::PgeNetworkConnectionHandle connHandle) |
Loads the given weapon file and returns the created Weapon instance. | |
const std::vector< Weapon * > & | getWeapons () const |
Weapon * | getWeaponById (const WeaponId &id) |
const Weapon * | getWeaponById (const WeaponId &id) const |
Weapon * | getWeaponByFilename (const std::string &wpnName) |
const Weapon * | getWeaponByFilename (const std::string &wpnName) const |
const std::string & | getDefaultAvailableWeaponFilename () const |
bool | setDefaultAvailableWeaponByFilename (const std::string &sFilename) |
Sets default available weapon that should be by default available for any new/respawning player. | |
const Weapon * | getCurrentWeapon () const |
Gets the current weapon. | |
Weapon * | getCurrentWeapon () |
Gets the current weapon. | |
bool | setCurrentWeapon (Weapon *wpn, bool bRecordSwitchTime, bool bServer) |
Sets the current weapon. | |
Weapon * | getPrevAvailableWeapon (unsigned char &cTargetWeapon) |
Gets the previous available weapon. | |
const Weapon * | getPrevAvailableWeapon (unsigned char &cTargetWeapon) const |
Gets the previous available weapon. | |
Weapon * | getNextAvailableWeapon (unsigned char &cTargetWeapon) |
Gets the next available weapon. | |
const Weapon * | getNextAvailableWeapon (unsigned char &cTargetWeapon) const |
Gets the next available weapon. | |
Weapon * | getNextBestAvailableWeapon (unsigned char &cTargetWeapon, bool bMustHaveMagBullet) |
Gets the next best available weapon. | |
const Weapon * | getNextBestAvailableWeapon (unsigned char &cTargetWeapon, bool bMustHaveMagBullet) const |
Gets the next best available weapon. | |
const std::chrono::time_point< std::chrono::steady_clock > & | getTimeLastWeaponSwitch () const |
void | Clear () |
Deletes all loaded weapons, sets current weapon to null and clears default available weapon and last weapon switch timestamp. | |
PgeObjectPool< PooledBullet > & | getBullets () |
Static Public Member Functions | |
static const char * | getLoggerModuleName () |
Returns the logger module name of this class. | |
static KeypressToWeaponMap & | getKeypressToWeaponMap () |
Returns the only instance of KeypressToWeaponMap. | |
Protected Member Functions | |
WeaponManager (const WeaponManager &) | |
WeaponManager & | operator= (const WeaponManager &) |
Private Member Functions | |
WeaponManager () | |
Private Attributes | |
pge_audio::PgeAudio & | m_audio |
PGEcfgProfiles & | m_cfgProfiles |
PR00FsUltimateRenderingEngine & | m_gfx |
std::vector< Weapon * > | m_weapons |
Weapon * | m_pCurrentWpn |
std::chrono::time_point< std::chrono::steady_clock > | m_timeLastWeaponSwitch |
PgeObjectPool< PooledBullet > & | m_bullets |
std::string | m_sDefaultAvailableWeapon |
Static Private Attributes | |
static KeypressToWeaponMap | m_mapKeypressToWeapon |
std::map<unsigned char, std::string> WeaponManager::KeypressToWeaponMap |
Definition at line 557 of file WeaponManager.h.
WeaponManager::WeaponManager | ( | pge_audio::PgeAudio & | audio, |
PGEcfgProfiles & | cfgProfiles, | ||
PR00FsUltimateRenderingEngine & | gfx, | ||
PgeObjectPool< PooledBullet > & | bullets ) |
bullets | A bullet pool for storing the bullets that are fired by Weapon instances created by this WeaponManager instance. |
Definition at line 1718 of file WeaponManager.cpp.
|
virtual |
Definition at line 1732 of file WeaponManager.cpp.
|
inlineprotected |
Definition at line 606 of file WeaponManager.h.
|
private |
void WeaponManager::Clear | ( | ) |
Deletes all loaded weapons, sets current weapon to null and clears default available weapon and last weapon switch timestamp.
Definition at line 2235 of file WeaponManager.cpp.
PgeObjectPool< PooledBullet > & WeaponManager::getBullets | ( | ) |
Definition at line 2250 of file WeaponManager.cpp.
CConsole & WeaponManager::getConsole | ( | ) | const |
Returns access to console preset with logger module name as this class.
Definition at line 1737 of file WeaponManager.cpp.
Weapon * WeaponManager::getCurrentWeapon | ( | ) |
Gets the current weapon.
Useful for a player object for tracking player's current weapon. Note that WeaponManager doesn't know about any player entity, you need to connect this logic with your player entity.
Definition at line 1886 of file WeaponManager.cpp.
const Weapon * WeaponManager::getCurrentWeapon | ( | ) | const |
Gets the current weapon.
Useful for a player object for tracking player's current weapon. Note that WeaponManager doesn't know about any player entity, you need to connect this logic with your player entity.
Definition at line 1874 of file WeaponManager.cpp.
const std::string & WeaponManager::getDefaultAvailableWeaponFilename | ( | ) | const |
Definition at line 1846 of file WeaponManager.cpp.
|
static |
Returns the only instance of KeypressToWeaponMap.
This map allows the user to define keyboard key mapping to weapons. Currently it is still the user's responsibility to handle these keypresses in game code, however this map is also used by WeaponManager's getPrev/NextWeapon() functions since this map defines the desired logical order of the weapons. Note that this logical order is independent from the power order which is based on the DPFR value of weapons.
Definition at line 1755 of file WeaponManager.cpp.
|
static |
Returns the logger module name of this class.
Definition at line 1742 of file WeaponManager.cpp.
Weapon * WeaponManager::getNextAvailableWeapon | ( | unsigned char & | cTargetWeapon | ) |
Gets the next available weapon.
Typically you need this function when the user is browsing their weapons forward e.g. scrolling mousewheel forward.
cTargetWeapon | Output argument, the key associated to the next available weapon in KeypressToWeaponMap will be set in this output argument. Will be set to '\0' (null-char) if no current weapon is set or the file name of the current weapon is not present in KeypressToWeaponMap. Will be set to the key of the current weapon if we could not find another available weapon. |
Definition at line 2051 of file WeaponManager.cpp.
const Weapon * WeaponManager::getNextAvailableWeapon | ( | unsigned char & | cTargetWeapon | ) | const |
Gets the next available weapon.
Typically you need this function when the user is browsing their weapons forward e.g. scrolling mousewheel forward.
cTargetWeapon | Output argument, the key associated to the next available weapon in KeypressToWeaponMap will be set in this output argument. Will be set to '\0' (null-char) if no current weapon is set or the file name of the current weapon is not present in KeypressToWeaponMap. Will be set to the key of the current weapon if we could not find another available weapon. |
Definition at line 2070 of file WeaponManager.cpp.
Weapon * WeaponManager::getNextBestAvailableWeapon | ( | unsigned char & | cTargetWeapon, |
bool | bMustHaveMagBullet ) |
Gets the next best available weapon.
Typically you need this when you run out of ammo of your current weapon and want to switch to another most useful weapon. Unlike the getPrev/NextAvailableWeapon() functions, here we follow the power order of available weapons defined by their DPSR value, and we don't consider weapons for which we don't have any kind (mag and unmag) ammo.
cTargetWeapon | Output-only argument, the key associated to the next best available weapon. Set to '\0' in case of error. Set to key associated to current weapon if we could not find a best next available weapon. Set to key associated to the found next best available weapon if we found one. |
bMustHaveMagBullet | If true, only weapons with non-zero mag bullet count will be considered. |
Definition at line 2146 of file WeaponManager.cpp.
const Weapon * WeaponManager::getNextBestAvailableWeapon | ( | unsigned char & | cTargetWeapon, |
bool | bMustHaveMagBullet ) const |
Gets the next best available weapon.
Typically you need this when you run out of ammo of your current weapon and want to switch to another most useful weapon. Unlike the getPrev/NextAvailableWeapon() functions, here we follow the power order of available weapons defined by their DPSR value, and we don't consider weapons for which we don't have any kind (mag and unmag) ammo.
cTargetWeapon | Output-only argument, the key associated to the next best available weapon. Set to '\0' in case of error. Set to key associated to current weapon if we could not find a best next available weapon. Set to key associated to the found next best available weapon if we found one. |
bMustHaveMagBullet | If true, only weapons with non-zero mag bullet count will be considered. |
Definition at line 2169 of file WeaponManager.cpp.
Weapon * WeaponManager::getPrevAvailableWeapon | ( | unsigned char & | cTargetWeapon | ) |
Gets the previous available weapon.
Typically you need this function when the user is browsing their weapons backwards e.g. scrolling mousewheel backward.
cTargetWeapon | Output argument, the key associated to the previous available weapon in KeypressToWeaponMap will be set in this output argument. Will be set to '\0' (null-char) if no current weapon is set or the file name of the current weapon is not present in KeypressToWeaponMap. Will be set to the key of the current weapon if we could not find another available weapon. |
Definition at line 1957 of file WeaponManager.cpp.
const Weapon * WeaponManager::getPrevAvailableWeapon | ( | unsigned char & | cTargetWeapon | ) | const |
Gets the previous available weapon.
Typically you need this function when the user is browsing their weapons backwards e.g. scrolling mousewheel backward.
cTargetWeapon | Output argument, the key associated to the previous available weapon in KeypressToWeaponMap will be set in this output argument. Will be set to '\0' (null-char) if no current weapon is set or the file name of the current weapon is not present in KeypressToWeaponMap. Will be set to the key of the current weapon if we could not find another available weapon. |
Definition at line 1976 of file WeaponManager.cpp.
const std::chrono::time_point< std::chrono::steady_clock > & WeaponManager::getTimeLastWeaponSwitch | ( | ) | const |
Definition at line 2227 of file WeaponManager.cpp.
Weapon * WeaponManager::getWeaponByFilename | ( | const std::string & | wpnName | ) |
Definition at line 1827 of file WeaponManager.cpp.
const Weapon * WeaponManager::getWeaponByFilename | ( | const std::string & | wpnName | ) | const |
Definition at line 1832 of file WeaponManager.cpp.
Definition at line 1811 of file WeaponManager.cpp.
Definition at line 1816 of file WeaponManager.cpp.
const std::vector< Weapon * > & WeaponManager::getWeapons | ( | ) | const |
Definition at line 1806 of file WeaponManager.cpp.
Weapon * WeaponManager::load | ( | const char * | fname, |
pge_network::PgeNetworkConnectionHandle | connHandleServerSide ) |
Loads the given weapon file and returns the created Weapon instance.
fname | Weapon file name. |
connHandleServerSide | The server-side connection handle of the owner of the loaded weapon. Basically this connects the weapon to the user of the weapon. |
Definition at line 1768 of file WeaponManager.cpp.
|
inlineprotected |
Definition at line 614 of file WeaponManager.h.
bool WeaponManager::setCurrentWeapon | ( | Weapon * | wpn, |
bool | bRecordSwitchTime, | ||
bool | bServer ) |
Sets the current weapon.
Useful for a player object for tracking player's current weapon. Note that WeaponManager doesn't know about any player entity, you need to connect this logic with your player entity.
wpn | The weapon you want to set to be current. Cannot be null. |
bRecordSwitchTime | Set it to true if you want the timestamp of this change to be saved for later query by getTimeLastWeaponSwitch(). Ignored if this is the very first time you invoke this function, since that won't be a real switch at all. |
bServer | Set it to true if we are server instance, false if we are client. Only server does availability check because clients might not be up-to-date about weapon availability. |
Definition at line 1904 of file WeaponManager.cpp.
bool WeaponManager::setDefaultAvailableWeaponByFilename | ( | const std::string & | sFilename | ) |
Sets default available weapon that should be by default available for any new/respawning player.
Note that WeaponManager doesn't know about any player entity, you need to connect this logic with your player entity.
Definition at line 1855 of file WeaponManager.cpp.
|
private |
Definition at line 622 of file WeaponManager.h.
|
private |
Definition at line 628 of file WeaponManager.h.
|
private |
Definition at line 623 of file WeaponManager.h.
|
private |
Definition at line 624 of file WeaponManager.h.
|
staticprivate |
Definition at line 620 of file WeaponManager.h.
|
private |
Definition at line 626 of file WeaponManager.h.
|
private |
Definition at line 629 of file WeaponManager.h.
|
private |
Definition at line 627 of file WeaponManager.h.
|
private |
Definition at line 625 of file WeaponManager.h.