Added Gameplay.AutoReload bool to config
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "Input/EInputCommand.h"
|
||||
#include "Systems/SpawnerSystem.h"
|
||||
#include "Rendering/ESetCamera.h"
|
||||
#include "Core/ConfigFile.h"
|
||||
|
||||
template <typename ETYPE>
|
||||
class WeaponBehaviour : public PureSystem
|
||||
@@ -21,8 +22,10 @@ public:
|
||||
, m_Renderer(renderer)
|
||||
, m_CollisionOctree(collisionOctree)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &WeaponBehaviour::_OnInputCommand)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &WeaponBehaviour::_OnSetCamera)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &WeaponBehaviour::_OnInputCommand);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &WeaponBehaviour::_OnSetCamera);
|
||||
auto config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
m_ConfigAutoReload = config->Get<bool>("Gameplay.AutoReload", true);
|
||||
}
|
||||
virtual ~WeaponBehaviour() = default;
|
||||
|
||||
@@ -49,6 +52,7 @@ protected:
|
||||
EntityWrapper m_CurrentCamera;
|
||||
Octree<EntityAABB>* m_CollisionOctree;
|
||||
std::unordered_map<EntityWrapper, WeaponInfo> m_ActiveWeapons;
|
||||
bool m_ConfigAutoReload;
|
||||
|
||||
virtual void UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) { }
|
||||
virtual void OnPrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) { }
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
[Gameplay]
|
||||
AutoReload=true
|
||||
|
||||
[Debug]
|
||||
LogLevel=1
|
||||
LoadMap=
|
||||
|
||||
@@ -14,11 +14,16 @@ void DefenderWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo&
|
||||
double& reloadTimer = cWeapon["ReloadTimer"];
|
||||
reloadTimer = glm::max(0.0, reloadTimer - dt);
|
||||
|
||||
// Start reloading automatically if at 0 mag ammo
|
||||
int& magAmmo = cWeapon["MagazineAmmo"];
|
||||
if (m_ConfigAutoReload && magAmmo <= 0) {
|
||||
OnReload(cWeapon, wi);
|
||||
}
|
||||
|
||||
// Handle reloading
|
||||
double reloadTime = cWeapon["ReloadTime"];
|
||||
bool& isReloading = cWeapon["IsReloading"];
|
||||
if (isReloading && reloadTimer <= 0.0) {
|
||||
int& magAmmo = cWeapon["MagazineAmmo"];
|
||||
double reloadTime = cWeapon["ReloadTime"];
|
||||
int& magSize = cWeapon["MagazineSize"];
|
||||
int& ammo = cWeapon["Ammo"];
|
||||
if (magAmmo < magSize && ammo > 0) {
|
||||
@@ -130,7 +135,6 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
|
||||
// Ammo
|
||||
int& magAmmo = cWeapon["MagazineAmmo"];
|
||||
if (magAmmo <= 0) {
|
||||
OnReload(cWeapon, wi);
|
||||
return;
|
||||
} else {
|
||||
magAmmo -= 1;
|
||||
|
||||
Reference in New Issue
Block a user