R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
ecs::Weapon Class Reference

Component for entities capable of shooting projectiles. More...

#include <Weapon.hpp>

Inheritance diagram for ecs::Weapon:
Inheritance graph
Collaboration diagram for ecs::Weapon:
Collaboration graph

Public Member Functions

 Weapon (float fireRate, float cooldown, int projectileType, int damage)
 Constructor with weapon parameters.
 
 ~Weapon () override=default
 
float getFireRate () const
 Get fire rate.
 
float getCooldown () const
 Get current cooldown.
 
int getProjectileType () const
 Get projectile type.
 
float getDamage () const
 Get damage value.
 
bool shouldShoot () const
 Check if the weapon should shoot.
 
float getBaseFireRate () const
 Get base fire rate (before buffs).
 
int getBaseDamage () const
 Get base damage (before buffs).
 
void setFireRate (float fireRate)
 Set fire rate.
 
void setCooldown (float cooldown)
 Set cooldown timer.
 
void setProjectileType (int projectileType)
 Set projectile type.
 
void setDamage (float damage)
 Set damage value.
 
void setShouldShoot (bool shouldShoot)
 Set whether the weapon should shoot.
 
bool isCharging () const
 Check if weapon is currently charging.
 
void setCharging (bool charging)
 Set charging state.
 
float getChargeLevel () const
 Get current charge level.
 
void setChargeLevel (float level)
 Set charge level.
 
float getChargeRate () const
 Get charge rate (how fast the weapon charges).
 
void setChargeRate (float rate)
 Set charge rate.
 
ComponentType getType () const override
 Get the component type ID.
 
- Public Member Functions inherited from ecs::IComponent
virtual ~IComponent ()=default
 Virtual destructor.
 

Private Attributes

float _fireRate
 Shots per second.
 
float _cooldown
 Current cooldown timer in seconds.
 
int _projectileType
 Type of projectile spawned.
 
float _damage
 Base damage dealt.
 
bool _shouldShoot = false
 Whether the weapon is currently set to shoot.
 
float _baseFireRate
 Base fire rate (before buffs)
 
int _baseDamage
 Base damage (before buffs)
 
bool _isCharging = false
 Whether the weapon is currently charging.
 
float _chargeLevel = 0.0F
 Current charge level (0.0 to 1.0)
 
float _chargeRate = 1.0F
 How fast the weapon charges per second.
 

Detailed Description

Component for entities capable of shooting projectiles.

Manages weapon characteristics including fire rate, cooldown timer, projectile type spawned, base damage dealt, and charged shot mechanics.

Charged Shots

Weapons support a charging mechanic where holding the fire button accumulates charge over time. When released:

  • If charge >= 50%: Fires a charged shot with increased damage (up to 2.5x) and speed (up to 1.5x)
  • If charge < 50%: Fires a normal shot

Charge accumulation is controlled by the chargeRate field (default: 1.0 = full charge in 1 second).

Definition at line 28 of file Weapon.hpp.

Constructor & Destructor Documentation

◆ Weapon()

ecs::Weapon::Weapon ( float  fireRate,
float  cooldown,
int  projectileType,
int  damage 
)
inline

Constructor with weapon parameters.

Parameters
fireRateShots per second (higher = faster)
cooldownCurrent cooldown timer (in seconds)
projectileTypeType of projectile spawned
damageBase damage dealt by this weapon

Definition at line 37 of file Weapon.hpp.

◆ ~Weapon()

ecs::Weapon::~Weapon ( )
overridedefault

Member Function Documentation

◆ getBaseDamage()

int ecs::Weapon::getBaseDamage ( ) const
inline

Get base damage (before buffs).

Returns
int Base damage value

Definition at line 86 of file Weapon.hpp.

References _baseDamage.

Referenced by ecs::BuffSystem::_applyDamageBoost().

◆ getBaseFireRate()

float ecs::Weapon::getBaseFireRate ( ) const
inline

Get base fire rate (before buffs).

Returns
float Base shots per second

Definition at line 80 of file Weapon.hpp.

References _baseFireRate.

Referenced by ecs::BuffSystem::_applyFireRateBoost().

◆ getChargeLevel()

float ecs::Weapon::getChargeLevel ( ) const
inline

Get current charge level.

Returns
float Charge level from 0.0 (empty) to 1.0 (full)

Definition at line 134 of file Weapon.hpp.

References _chargeLevel.

◆ getChargeRate()

float ecs::Weapon::getChargeRate ( ) const
inline

Get charge rate (how fast the weapon charges).

Returns
float Charge rate (0.0 to 1.0 per second)

Definition at line 148 of file Weapon.hpp.

References _chargeRate.

◆ getCooldown()

float ecs::Weapon::getCooldown ( ) const
inline

Get current cooldown.

Returns
float Remaining cooldown in seconds.

Definition at line 56 of file Weapon.hpp.

References _cooldown.

◆ getDamage()

float ecs::Weapon::getDamage ( ) const
inline

Get damage value.

Returns
float Base damage dealt.

Definition at line 68 of file Weapon.hpp.

References _damage.

Referenced by ecs::WeaponSystem::fireChargedShot(), and ecs::WeaponSystem::fireWeapon().

◆ getFireRate()

float ecs::Weapon::getFireRate ( ) const
inline

Get fire rate.

Returns
float Shots per second.

Definition at line 50 of file Weapon.hpp.

References _fireRate.

Referenced by ecs::WeaponSystem::createProjectile().

◆ getProjectileType()

int ecs::Weapon::getProjectileType ( ) const
inline

Get projectile type.

Returns
int Type of projectile spawned.

Definition at line 62 of file Weapon.hpp.

References _projectileType.

◆ getType()

ComponentType ecs::Weapon::getType ( ) const
inlineoverridevirtual

Get the component type ID.

Returns
ComponentType Unique ID for Weapon component.

Implements ecs::IComponent.

Definition at line 160 of file Weapon.hpp.

◆ isCharging()

bool ecs::Weapon::isCharging ( ) const
inline

Check if weapon is currently charging.

Returns
bool True if charging, false otherwise

Definition at line 122 of file Weapon.hpp.

References _isCharging.

◆ setChargeLevel()

void ecs::Weapon::setChargeLevel ( float  level)
inline

Set charge level.

Parameters
levelCharge level (clamped to 0.0-1.0)

Definition at line 140 of file Weapon.hpp.

References _chargeLevel.

◆ setChargeRate()

void ecs::Weapon::setChargeRate ( float  rate)
inline

Set charge rate.

Parameters
rateCharge rate per second

Definition at line 154 of file Weapon.hpp.

References _chargeRate.

◆ setCharging()

void ecs::Weapon::setCharging ( bool  charging)
inline

Set charging state.

Parameters
chargingTrue to start charging, false to stop

Definition at line 128 of file Weapon.hpp.

References _isCharging.

◆ setCooldown()

void ecs::Weapon::setCooldown ( float  cooldown)
inline

Set cooldown timer.

Parameters
cooldownNew cooldown value in seconds

Definition at line 98 of file Weapon.hpp.

References _cooldown.

Referenced by ecs::WeaponSystem::update().

◆ setDamage()

void ecs::Weapon::setDamage ( float  damage)
inline

Set damage value.

Parameters
damageNew damage value

Definition at line 110 of file Weapon.hpp.

References _damage.

Referenced by ecs::BuffSystem::_applyDamageBoost().

◆ setFireRate()

void ecs::Weapon::setFireRate ( float  fireRate)
inline

Set fire rate.

Parameters
fireRateNew shots per second

Definition at line 92 of file Weapon.hpp.

References _fireRate.

Referenced by ecs::BuffSystem::_applyFireRateBoost().

◆ setProjectileType()

void ecs::Weapon::setProjectileType ( int  projectileType)
inline

Set projectile type.

Parameters
projectileTypeNew projectile type

Definition at line 104 of file Weapon.hpp.

References _projectileType.

◆ setShouldShoot()

void ecs::Weapon::setShouldShoot ( bool  shouldShoot)
inline

Set whether the weapon should shoot.

Parameters
shouldShootTrue to enable shooting, false to disable

Definition at line 116 of file Weapon.hpp.

References _shouldShoot, and shouldShoot().

Referenced by server::GameLogic::_applyPlayerInput(), and ecs::AISystem::update().

Here is the call graph for this function:

◆ shouldShoot()

bool ecs::Weapon::shouldShoot ( ) const
inline

Check if the weapon should shoot.

Returns
bool True if the weapon is set to shoot, false otherwise.

Definition at line 74 of file Weapon.hpp.

References _shouldShoot.

Referenced by setShouldShoot().

Member Data Documentation

◆ _baseDamage

int ecs::Weapon::_baseDamage
private

Base damage (before buffs)

Definition at line 169 of file Weapon.hpp.

Referenced by getBaseDamage().

◆ _baseFireRate

float ecs::Weapon::_baseFireRate
private

Base fire rate (before buffs)

Definition at line 168 of file Weapon.hpp.

Referenced by getBaseFireRate().

◆ _chargeLevel

float ecs::Weapon::_chargeLevel = 0.0F
private

Current charge level (0.0 to 1.0)

Definition at line 173 of file Weapon.hpp.

Referenced by getChargeLevel(), and setChargeLevel().

◆ _chargeRate

float ecs::Weapon::_chargeRate = 1.0F
private

How fast the weapon charges per second.

Definition at line 174 of file Weapon.hpp.

Referenced by getChargeRate(), and setChargeRate().

◆ _cooldown

float ecs::Weapon::_cooldown
private

Current cooldown timer in seconds.

Definition at line 164 of file Weapon.hpp.

Referenced by getCooldown(), and setCooldown().

◆ _damage

float ecs::Weapon::_damage
private

Base damage dealt.

Definition at line 166 of file Weapon.hpp.

Referenced by getDamage(), and setDamage().

◆ _fireRate

float ecs::Weapon::_fireRate
private

Shots per second.

Definition at line 163 of file Weapon.hpp.

Referenced by getFireRate(), and setFireRate().

◆ _isCharging

bool ecs::Weapon::_isCharging = false
private

Whether the weapon is currently charging.

Definition at line 172 of file Weapon.hpp.

Referenced by isCharging(), and setCharging().

◆ _projectileType

int ecs::Weapon::_projectileType
private

Type of projectile spawned.

Definition at line 165 of file Weapon.hpp.

Referenced by getProjectileType(), and setProjectileType().

◆ _shouldShoot

bool ecs::Weapon::_shouldShoot = false
private

Whether the weapon is currently set to shoot.

Definition at line 167 of file Weapon.hpp.

Referenced by setShouldShoot(), and shouldShoot().


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