Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "interupt open fire command" #73

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/Avatar/AttackAndDamage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_ATTACKANDDAMAGE_HPP
#define PRACTICALTOOLSFORSIMPLEDESIGN_ATTACKANDDAMAGE_HPP
#include "Unit/Huntable.hpp"
#include "Unit/IHealthable.hpp"
#include "Util/Time.hpp"
#include "Weapon.hpp"

Expand All @@ -13,7 +13,7 @@ class AttackAndDamage {
AttackAndDamage() {}
virtual ~AttackAndDamage() {}

void damageTargetWithWeapon(std::shared_ptr<Huntable> target,
void damageTargetWithWeapon(std::shared_ptr<IHealthable> target,
std::shared_ptr<Weapon> weapon) {
auto targethealth = target->getHealth();
auto damage =
Expand All @@ -22,7 +22,7 @@ class AttackAndDamage {
targethealth->addHP(-1 * damage);
}

void openFireToTarget(std::shared_ptr<Huntable> target) {
void openFireToTarget(std::shared_ptr<IHealthable> target) {
// cd time
m_DeltaTime += m_Time.GetDeltaTime();
if (m_Weapon->getIntervalInS() <= m_DeltaTime) {
Expand Down
20 changes: 5 additions & 15 deletions include/Avatar/Avatar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
#include "Map/MapUtility.hpp"
#include "Mechanics/GameObjectID.hpp"
#include "Selectable.hpp"
#include "Unit/Huntable.hpp"
#include "Util/Image.hpp"

class Avatar : public Util::GameObject, public Selectable, public Huntable {
class Avatar : public Util::GameObject, public Selectable, public IHealthable {

public:
Avatar(){};
Expand Down Expand Up @@ -69,20 +68,11 @@ class Avatar : public Util::GameObject, public Selectable, public Huntable {
std::shared_ptr<Moving> getMoving() { return m_Moving; }
std::shared_ptr<AvatarOrder> getAvatarOrder() { return m_Order; }

void setHealth(std::shared_ptr<Health> health) { m_Health = health; }

public:
// huntable
std::shared_ptr<Health> getHealth() override { return m_Health; }
void setOrderNoOrder() override {
m_Order->setAvatarOrder(AvatarOrderType::NO_ORDER);
};
void setOrderTakenDamage() override {
m_Order->setAvatarOrder(AvatarOrderType::TAKEN_DAMAGE);
};
glm::vec2 getCurrentLocationInCell() override {
return getMoving()->getCurrentCell();
};

void setHealth(std::shared_ptr<Health> health) override {
m_Health = health;
}

protected:
std::shared_ptr<SpriteSheet> m_AvatarSpriteSheet =
Expand Down
9 changes: 2 additions & 7 deletions include/Avatar/Moving.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,8 @@ class Moving {
bool ifArrivedAtNextCell();

void setMovePath(std::deque<MoveDirection> movepath) {
if (movepath.empty()) {
m_MovePath = {MoveDirection::IDLE};
m_CurrentDir = MoveDirection::IDLE;
} else {
m_MovePath = movepath;
m_CurrentDir = m_MovePath.front();
}
m_MovePath = movepath;
m_CurrentDir = m_MovePath.front();
m_PrevCell = getCurrentCell();
}

Expand Down
2 changes: 1 addition & 1 deletion include/Map/Tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class TileClass {

std::vector<std::shared_ptr<Avatar>> getAvatars() { return m_Avatars; }
std::shared_ptr<Structure> getStructure() { return m_Structure; }
bool ifStructureExists() {
bool ifStrucutreExists() {
if (*m_Structure->getHealth()->getLivingStatus() ==
LivingStatus::NOT_BORN_YET) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions include/Mechanics/BuiltStructure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class BuiltStructure {
if (ifCanBuildStructureAtTile(newstruct) == true) {
m_BuiltStructure.push_back(newstruct);
m_Map->builtStructureByCellPosition(newstruct, coords);
newstruct->getStructureOrder()->setStructureOrder(
newstruct->getStructureOrder()->setStructOrder(
StructureOrderType::BUILT);
}
}
} else {
m_BuiltStructure.push_back(newstruct);
m_Map->builtStructureByCellPosition(newstruct, coords);
newstruct->getStructureOrder()->setStructureOrder(
newstruct->getStructureOrder()->setStructOrder(
StructureOrderType::BUILT);
}
}
Expand Down
19 changes: 11 additions & 8 deletions include/Mechanics/NemesisManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class NemesisManager {
NemesisManager() {}
~NemesisManager() {}
void addNemesis(std::shared_ptr<Avatar> avatar,
std::shared_ptr<Huntable> nemesis) {
std::shared_ptr<Avatar> nemesis) {
m_Nemesis[avatar] = nemesis;
}

Expand All @@ -34,7 +34,7 @@ class NemesisManager {
return false;
}
if (hunter->getDistance(
m_Nemesis[hunter]->getCurrentLocationInCell()) <=
m_Nemesis[hunter]->getMoving()->getCurrentCell()) <=
hunter->getAttackAndDamage()->getWeapon()->getFireRange() *
CELL_SIZE.x) // check with in range
{
Expand All @@ -52,16 +52,18 @@ class NemesisManager {
if (ifNemesisWithinWeaponRange(hunter)) {
hunter->getAvatarOrder()->setAvatarOrder(
AvatarOrderType::OPEN_FIRE);
prey->setOrderTakenDamage();
prey->getAvatarOrder()->setAvatarOrder(
AvatarOrderType::TAKEN_DAMAGE);
hunter->getAttackAndDamage()->openFireToTarget(prey);
}

if (pair.second->getHealth()->ifDead()) {
if (*pair.second->getHealth()->getLivingStatus() ==
LivingStatus::DEAD) {
removeNemesis(hunter);
hunter->getAvatarOrder()->setAvatarOrder(
AvatarOrderType::NO_ORDER);
prey->setOrderNoOrder();

prey->getAvatarOrder()->setAvatarOrder(
AvatarOrderType::NO_ORDER);
break;
}

Expand All @@ -70,14 +72,15 @@ class NemesisManager {
removeNemesis(hunter);
hunter->getAvatarOrder()->setAvatarOrder(
AvatarOrderType::NO_ORDER);
prey->setOrderNoOrder();
prey->getAvatarOrder()->setAvatarOrder(
AvatarOrderType::NO_ORDER);
break;
}
}
}

private:
std::unordered_map<std::shared_ptr<Avatar>, std::shared_ptr<Huntable>>
std::unordered_map<std::shared_ptr<Avatar>, std::shared_ptr<Avatar>>
m_Nemesis;
};
#endif // PRACTICALTOOLSFORSIMPLEDESIGN_NEMESISMANAGER_HPP
2 changes: 1 addition & 1 deletion include/Mechanics/StructureManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class StructureManager {
newstruct->Start();
m_StructSelectingConstructionSite = newstruct;

newstruct->getStructureOrder()->setStructureOrder(
newstruct->getStructureOrder()->setStructOrder(
StructureOrderType::SELECTING_SITE);
}

Expand Down
15 changes: 5 additions & 10 deletions include/Mechanics/UnitManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,40 +110,35 @@ class UnitManager : public Player {
switch (unit) {
case UnitType::BARRACKS: {
auto structure = std::make_shared<Barracks>(house);
auto globalPos = MapUtil::CellCoordToGlobal(cellPos);
structure->Start(globalPos);
structure->Start(cellPos);
m_StructureManager->getStructureArray()->buildNewStructure(
structure, true);
break;
}
case UnitType::ORE_REF: {
auto structure = std::make_shared<OreRefinery>(house);
auto globalPos = MapUtil::CellCoordToGlobal(cellPos);
structure->Start(globalPos);
structure->Start(cellPos);
m_StructureManager->getStructureArray()->buildNewStructure(
structure, true);
break;
}
case UnitType::POWER_PLANT: {
auto structure = std::make_shared<PowerPlants>(house);
auto globalPos = MapUtil::CellCoordToGlobal(cellPos);
structure->Start(globalPos);
structure->Start(cellPos);
m_StructureManager->getStructureArray()->buildNewStructure(
structure, true);
break;
}
case UnitType::WAR_FACT: {
auto structure = std::make_shared<WarFactory>(house);
auto globalPos = MapUtil::CellCoordToGlobal(cellPos);
structure->Start(globalPos);
structure->Start(cellPos);
m_StructureManager->getStructureArray()->buildNewStructure(
structure, true);
break;
}
case UnitType::ADV_POWER_PLANT: {
auto structure = std::make_shared<ADVPowerPlants>(house);
auto globalPos = MapUtil::CellCoordToGlobal(cellPos);
structure->Start(globalPos);
structure->Start(cellPos);
m_StructureManager->getStructureArray()->buildNewStructure(
structure, true);
break;
Expand Down
28 changes: 11 additions & 17 deletions include/Structure/Structure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@
#include "Selectable.hpp"
#include "Structure/StructureOrder.hpp"
#include "Unit/Health.hpp"
#include "Unit/Huntable.hpp"
#include "Util/GameObject.hpp"
#include "Unit/IHealthable.hpp"
#include "Util/Image.hpp"

#include "Util/GameObject.hpp"
#include "Util/Input.hpp"
#include "Util/TransformUtils.hpp"
#include "glm/glm.hpp"
#define DEFAULT_ZINDEX 15
#define CHEAT 0.01
#define INTERVAL 50

class Structure : public Util::GameObject, public Selectable, public Huntable {
class Structure : public Util::GameObject,
public Selectable,
public IHealthable {

public:
Structure()
Expand Down Expand Up @@ -94,25 +97,16 @@ class Structure : public Util::GameObject, public Selectable, public Huntable {

public:
GameObjectID getID() { return m_ID; }
void setHealth(std::shared_ptr<Health> health) { m_Health = health; }
std::shared_ptr<Health> getHealth() override { return m_Health; }
void setHealth(std::shared_ptr<Health> health) override {
m_Health = health;
}
std::shared_ptr<StructureOrder> getStructureOrder() { return m_Order; }

std::shared_ptr<AttackAndDamage> getAttackAndDamage() {
return m_AttackAndDamage;
}

public:
// huntable
std::shared_ptr<Health> getHealth() override { return m_Health; }
void setOrderNoOrder() override {
m_Order->setStructureOrder(StructureOrderType::NO_ORDER);
};
void setOrderTakenDamage() override {
m_Order->setStructureOrder(StructureOrderType::TAKEN_DAMAGE);
};
glm::vec2 getCurrentLocationInCell() override {
return getAbsoluteOccupiedArea()[0];
};

protected:
float m_ElectricPower;
float m_BuildingTime;
Expand Down
5 changes: 2 additions & 3 deletions include/Structure/StructureOrder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ enum class StructureOrderType {
CONSTRUCTED,
SELECTING_SITE,
BUILT,
NO_ORDER,
TAKEN_DAMAGE
NO_ORDER
};
class StructureOrder {
public:
Expand All @@ -19,7 +18,7 @@ class StructureOrder {

StructureOrderType getStructureOrderType() { return m_StructOrder; }

void setStructureOrder(StructureOrderType structorder) {
void setStructOrder(StructureOrderType structorder) {
m_StructOrder = structorder;
}

Expand Down
20 changes: 0 additions & 20 deletions include/Unit/Huntable.hpp

This file was deleted.

14 changes: 14 additions & 0 deletions include/Unit/IHealthable.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Created by 盧威任 on 5/5/24.
//

#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_IHEALTHABLE_HPP
#define PRACTICALTOOLSFORSIMPLEDESIGN_IHEALTHABLE_HPP
#include "Health.hpp"
#include <memory>
class IHealthable {
public:
virtual std::shared_ptr<Health> getHealth() = 0;
virtual void setHealth(std::shared_ptr<Health> health) = 0;
};
#endif // PRACTICALTOOLSFORSIMPLEDESIGN_IHEALTHABLE_HPP
22 changes: 4 additions & 18 deletions src/Mechanics/AvatarManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,13 @@ void AvatarManager::giveOrderToMyAvatar(std::shared_ptr<Avatar> unit) {
MapUtil::ScreenToGlobalCoord(dest)))
->ifEnemyAtTile()) {
unit->getAvatarOrder()->setAvatarOrder(AvatarOrderType::MOVE);
if (m_Map
m_NemesisManager->addNemesis(
unit,
m_Map
->getTileByCellPosition(MapUtil::GlobalCoordToCellCoord(
MapUtil::ScreenToGlobalCoord(dest)))
->ifStructureExists()) {
m_NemesisManager->addNemesis(
unit, m_Map
->getTileByCellPosition(
MapUtil::GlobalCoordToCellCoord(
MapUtil::ScreenToGlobalCoord(dest)))
->getStructure());
} else {
m_NemesisManager->addNemesis(
unit, m_Map
->getTileByCellPosition(
MapUtil::GlobalCoordToCellCoord(
MapUtil::ScreenToGlobalCoord(dest)))
->getAvatars()[0]);
}

->getAvatars()[0]);
} else {
m_NemesisManager->removeNemesis(unit);
unit->getAvatarOrder()->setAvatarOrder(AvatarOrderType::MOVE);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mechanics/CursorSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void CursorSelection::cursorSelect() {
for (int i = min_y_cell; i <= max_y_cell; i++) {
for (int j = min_x_cell; j <= max_x_cell; j++) {
auto tile = m_Map->getTileByCellPosition(glm::vec2(j, i));
if (tile->ifStructureExists()) {
if (tile->ifStrucutreExists()) {
auto structure = tile->getStructure();
Append(structure);

Expand Down
2 changes: 0 additions & 2 deletions src/Scene/TutorialScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ void TutorialScene::Start() {
// combat test
m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY,
{6, 6});
m_EnemyObjectManager->spawn(m_Map, UnitType::BARRACKS, HouseType::ENEMY,
{10, 10});

stageStart();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Structure/Barracks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void Barracks::Start() {
m_HighLight.SetHLScale(this->GetTransform().scale);
whenSelected();
// State
getStructureOrder()->setStructureOrder(StructureOrderType::CONSTRUCTED);
getStructureOrder()->setStructOrder(StructureOrderType::CONSTRUCTED);
// health
Structure::getHealth()->setLivingStatus(
std::make_shared<LivingStatus>(LivingStatus::ALIVE));
Expand All @@ -47,7 +47,7 @@ void Barracks::Start(glm::vec2 location) {
SetVisible(true);
m_SpriteSheetAnimation->initSpriteSheetAnimation(m_StructureSpriteSheet,
false, INTERVAL, false);
getStructureOrder()->setStructureOrder(StructureOrderType::BUILT);
getStructureOrder()->setStructOrder(StructureOrderType::BUILT);
Structure::getHealth()->setLivingStatus(
std::make_shared<LivingStatus>(LivingStatus::ALIVE));
}
Loading
Loading