Skip to content

Commit

Permalink
id
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 committed Mar 13, 2024
1 parent 6dc7cda commit ae4f10e
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 47 deletions.
3 changes: 3 additions & 0 deletions include/GameObjectID.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
14 changes: 8 additions & 6 deletions include/Structure/AdvencePowerPlants.hpp
Original file line number Diff line number Diff line change
@@ -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<Util::Image>("../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<Util::Image>("../assets/sprites/PowerPlants.png"));
};
};

#endif
28 changes: 15 additions & 13 deletions include/Structure/Barracks.hpp
Original file line number Diff line number Diff line change
@@ -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<WayPoint> m_wayPoint = std::make_shared<WayPoint>();
HighLight m_HighLight;
Grid m_Grid;
Line m_Line;
std::vector<Line> 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
28 changes: 15 additions & 13 deletions include/Structure/OreRefinery.hpp
Original file line number Diff line number Diff line change
@@ -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<WayPoint> m_wayPoint = std::make_shared<WayPoint>();
HighLight m_HighLight;
bool b_select= true;
bool b_select = true;
Grid m_Grid;
Line m_Line;
std::vector<Line> 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
14 changes: 8 additions & 6 deletions include/Structure/PowerPlants.hpp
Original file line number Diff line number Diff line change
@@ -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<Util::Image>("../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<Util::Image>("../assets/sprites/PowerPlants.png"));
};
};

#endif
7 changes: 5 additions & 2 deletions include/Structure/Structure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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);
};
Expand Down Expand Up @@ -84,6 +86,7 @@ class Structure : public Util::GameObject {
float buildingCost;
float buildingHp;
HighLight m_HighLight;
GameObjectID m_ID;

protected:
bool b_selected = false;
Expand Down
13 changes: 8 additions & 5 deletions include/Structure/WarFactory.hpp
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -18,17 +19,19 @@ class WarFactory : public Structure, public IWayPointStructure {
Grid m_Grid;
Line m_Line;
std::vector<Line> 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
4 changes: 2 additions & 2 deletions src/GameObjectID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//
#include "GameObjectID.hpp"
std::unordered_map<unitType, unsigned int> OccupiedID::m_OccupiedID;

void OccupiedID::InitID() {
OccupiedID::m_OccupiedID[unitType::INFANTRY] = 0;
OccupiedID::m_OccupiedID[unitType::POWER_PLANT] = 0;
Expand All @@ -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]++;
}

0 comments on commit ae4f10e

Please sign in to comment.