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