diff --git a/include/GameObjectID.hpp b/include/GameObjectID.hpp index 87ac3b20..d3093954 100644 --- a/include/GameObjectID.hpp +++ b/include/GameObjectID.hpp @@ -41,6 +41,9 @@ class GameObjectID { GameObjectID() : m_unitType(unitType::null), number(0) {} + GameObjectID(unitType type) + : m_unitType(type), + number(OccupiedID::getNewestID(type)) {} ~GameObjectID() {} void generateID(unitType type) { m_unitType = type; } diff --git a/include/Structure/AdvencePowerPlants.hpp b/include/Structure/AdvencePowerPlants.hpp index fd74bd00..598c160f 100644 --- a/include/Structure/AdvencePowerPlants.hpp +++ b/include/Structure/AdvencePowerPlants.hpp @@ -1,14 +1,16 @@ #ifndef PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_ADVPowerPlants_HPP #define PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_ADVPowerPlants_HPP - #include "Structure.hpp" -class ADVPowerPlants:public Structure{ +class ADVPowerPlants : public Structure { public: - ADVPowerPlants(float electricPower=200.F,float buildingTime=25.F, - float buildingCost=500.F,float buildingHp=700.F): Structure(electricPower, buildingTime, buildingCost, buildingHp){ - SetDrawable(std::make_unique("../assets/sprites/PowerPlants.png")); - }; + ADVPowerPlants(float electricPower = 200.F, float buildingTime = 25.F, + float buildingCost = 500.F, float buildingHp = 700.F) + : Structure(electricPower, buildingTime, buildingCost, buildingHp, + unitType::ADV_POWER_PLANT) { + SetDrawable( + std::make_unique("../assets/sprites/PowerPlants.png")); + }; }; #endif diff --git a/include/Structure/Barracks.hpp b/include/Structure/Barracks.hpp index 2734f199..1d068549 100644 --- a/include/Structure/Barracks.hpp +++ b/include/Structure/Barracks.hpp @@ -1,35 +1,37 @@ #ifndef PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_BARRACKS_HPP #define PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_BARRACKS_HPP +#include "Grid.hpp" +#include "HighLight.h" +#include "Line.hpp" #include "Structure/IWayPointStructure.hpp" #include "Structure/MousOverlapTool.h" #include "Structure/Structure.hpp" #include "Util/Image.hpp" -#include "Util/Keycode.hpp" #include "Util/Input.hpp" +#include "Util/Keycode.hpp" #include "WayPoint.hpp" -#include "HighLight.h" -#include "Line.hpp" -#include "Grid.hpp" -class Barracks : public Structure,public IWayPointStructure{ +class Barracks : public Structure, public IWayPointStructure { private: std::shared_ptr m_wayPoint = std::make_shared(); HighLight m_HighLight; Grid m_Grid; Line m_Line; std::vector m_lineVector; + public: - Barracks(float electricPower=-20.F,float buildingTime= 15.F, - float buildingCost=300.F,float buildingHp=800.F): - Structure(electricPower, buildingTime, buildingCost, buildingHp){}; - void Start()override; + Barracks(float electricPower = -20.F, float buildingTime = 15.F, + float buildingCost = 300.F, float buildingHp = 800.F) + : Structure(electricPower, buildingTime, buildingCost, buildingHp, + unitType::BARRACKS){}; + void Start() override; - virtual void onSelected(bool selected)override; - virtual void SetAttachVisible(bool visible)override; + virtual void onSelected(bool selected) override; + virtual void SetAttachVisible(bool visible) override; - virtual void updateMoveable()override; - virtual void attachmentUpdate()override; + virtual void updateMoveable() override; + virtual void attachmentUpdate() override; }; #endif diff --git a/include/Structure/OreRefinery.hpp b/include/Structure/OreRefinery.hpp index e2034e04..a2d89f1d 100644 --- a/include/Structure/OreRefinery.hpp +++ b/include/Structure/OreRefinery.hpp @@ -1,34 +1,36 @@ #ifndef PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_OreRefinery_HPP #define PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_OreRefinery_HPP +#include "Grid.hpp" +#include "HighLight.h" +#include "Line.hpp" #include "Structure/IWayPointStructure.hpp" #include "Structure/Structure.hpp" #include "Util/Image.hpp" -#include "Util/Keycode.hpp" #include "Util/Input.hpp" +#include "Util/Keycode.hpp" #include "WayPoint.hpp" -#include "HighLight.h" -#include "Line.hpp" -#include "Grid.hpp" -class OreRefinery:public Structure,public IWayPointStructure{ +class OreRefinery : public Structure, public IWayPointStructure { private: std::shared_ptr m_wayPoint = std::make_shared(); HighLight m_HighLight; - bool b_select= true; + bool b_select = true; Grid m_Grid; Line m_Line; std::vector m_lineVector; + public: - OreRefinery(float electricPower=-30.F,float buildingTime=100.F, - float buildingCost=2000.F,float buildingHp=900.F): - Structure(electricPower, buildingTime, buildingCost, buildingHp){}; + OreRefinery(float electricPower = -30.F, float buildingTime = 100.F, + float buildingCost = 2000.F, float buildingHp = 900.F) + : Structure(electricPower, buildingTime, buildingCost, buildingHp, + unitType::ORE_REF){}; void Start() override; - virtual void onSelected(bool selected)override; - virtual void SetAttachVisible(bool visible)override; + virtual void onSelected(bool selected) override; + virtual void SetAttachVisible(bool visible) override; - virtual void updateMoveable()override; - virtual void attachmentUpdate()override; + virtual void updateMoveable() override; + virtual void attachmentUpdate() override; }; #endif diff --git a/include/Structure/PowerPlants.hpp b/include/Structure/PowerPlants.hpp index ef7a717f..3539fed5 100644 --- a/include/Structure/PowerPlants.hpp +++ b/include/Structure/PowerPlants.hpp @@ -1,14 +1,16 @@ #ifndef PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_PowerPlants_HPP #define PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_PowerPlants_HPP - #include "Structure.hpp" -class PowerPlants:public Structure{ +class PowerPlants : public Structure { public: - PowerPlants(float electricPower=100.F,float buildingTime=15.F, - float buildingCost=300.F,float buildingHp=400.F): Structure(electricPower, buildingTime, buildingCost, buildingHp){ - SetDrawable(std::make_unique("../assets/sprites/PowerPlants.png")); - }; + PowerPlants(float electricPower = 100.F, float buildingTime = 15.F, + float buildingCost = 300.F, float buildingHp = 400.F) + : Structure(electricPower, buildingTime, buildingCost, buildingHp, + unitType::POWER_PLANT) { + SetDrawable( + std::make_unique("../assets/sprites/PowerPlants.png")); + }; }; #endif diff --git a/include/Structure/Structure.hpp b/include/Structure/Structure.hpp index 54bbc51e..26fbaf9a 100644 --- a/include/Structure/Structure.hpp +++ b/include/Structure/Structure.hpp @@ -4,6 +4,7 @@ #ifndef PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_HPP #define PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_HPP +#include "GameObjectID.hpp" #include "HighLight.h" #include "Map.hpp" #include "Structure/MousOverlapTool.h" @@ -28,11 +29,12 @@ class Structure : public Util::GameObject { }; Structure(float electricPower, float buildingTime, float buildingCost, - float buildingHp) + float buildingHp, GameObjectID id) : electricPower(electricPower), buildingTime(buildingTime), buildingCost(buildingCost), - buildingHp(buildingHp) { + buildingHp(buildingHp), + m_ID(id) { m_Transform.scale = {1, 1}; // this->SetZIndex(DEFAULT_ZINDEX); }; @@ -84,6 +86,7 @@ class Structure : public Util::GameObject { float buildingCost; float buildingHp; HighLight m_HighLight; + GameObjectID m_ID; protected: bool b_selected = false; diff --git a/include/Structure/WarFactory.hpp b/include/Structure/WarFactory.hpp index a6046fe9..b68746dd 100644 --- a/include/Structure/WarFactory.hpp +++ b/include/Structure/WarFactory.hpp @@ -1,6 +1,7 @@ #ifndef PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_WarFactory_HPP #define PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_WarFactory_HPP +#include "GameObjectID.hpp" #include "Grid.hpp" #include "HighLight.h" #include "Line.hpp" @@ -18,17 +19,19 @@ class WarFactory : public Structure, public IWayPointStructure { Grid m_Grid; Line m_Line; std::vector m_lineVector; + public: WarFactory(float electricPower = -30.F, float buildingTime = 100.F, float buildingCost = 2000.F, float buildingHp = 1000.F) - : Structure(electricPower, buildingTime, buildingCost, buildingHp){}; + : Structure(electricPower, buildingTime, buildingCost, buildingHp, + unitType::WAR_FACT){}; void Start() override; - virtual void onSelected(bool selected)override; - virtual void SetAttachVisible(bool visible)override; + virtual void onSelected(bool selected) override; + virtual void SetAttachVisible(bool visible) override; - virtual void updateMoveable()override; - virtual void attachmentUpdate()override; + virtual void updateMoveable() override; + virtual void attachmentUpdate() override; }; #endif diff --git a/src/GameObjectID.cpp b/src/GameObjectID.cpp index 9f3046fc..0b90ba21 100644 --- a/src/GameObjectID.cpp +++ b/src/GameObjectID.cpp @@ -3,6 +3,7 @@ // #include "GameObjectID.hpp" std::unordered_map OccupiedID::m_OccupiedID; + void OccupiedID::InitID() { OccupiedID::m_OccupiedID[unitType::INFANTRY] = 0; OccupiedID::m_OccupiedID[unitType::POWER_PLANT] = 0; @@ -23,6 +24,5 @@ void OccupiedID::InitID() { } int OccupiedID::getNewestID(unitType type) { - OccupiedID::m_OccupiedID[type] += 1; - return OccupiedID::m_OccupiedID[type]; + return OccupiedID::m_OccupiedID[type]++; }