From 8500298cd48e174538e44c485bd50145bfa3002b Mon Sep 17 00:00:00 2001 From: jonylu7 Date: Sun, 16 Jun 2024 13:46:18 +0800 Subject: [PATCH] un --- src/Mechanics/UnitManager.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/Mechanics/UnitManager.cpp b/src/Mechanics/UnitManager.cpp index f67b7698..78d16429 100644 --- a/src/Mechanics/UnitManager.cpp +++ b/src/Mechanics/UnitManager.cpp @@ -4,7 +4,9 @@ #include "Mechanics/UnitManager.hpp" void UnitManager::spawnToWayPoint(UnitType unit, HouseType house) { - + if (!m_StructureManager->getStructureArray()->ifBarrackBuilt()) { + return; + } switch (unit) { case UnitType::INFANTRY: { auto avatar = std::make_shared(house); @@ -41,42 +43,44 @@ void UnitManager::spawn(UnitType unit, HouseType house, glm::vec2 cellPos) { auto structure = std::make_shared(house); auto globalPos = MapUtil::CellCoordToGlobal(cellPos); structure->Start(globalPos); - m_StructureManager->getStructureArray()->buildNewStructure( - structure, true); - structure->setWaypointLocationByCellCoord({cellPos.x+2,cellPos.y+2}); + m_StructureManager->getStructureArray()->buildNewStructure(structure, + true); + structure->setWaypointLocationByCellCoord( + {cellPos.x + 2, cellPos.y + 2}); break; } case UnitType::ORE_REF: { auto structure = std::make_shared(house); auto globalPos = MapUtil::CellCoordToGlobal(cellPos); structure->Start(globalPos); - m_StructureManager->getStructureArray()->buildNewStructure( - structure, true); + m_StructureManager->getStructureArray()->buildNewStructure(structure, + true); break; } case UnitType::POWER_PLANT: { auto structure = std::make_shared(house); auto globalPos = MapUtil::CellCoordToGlobal(cellPos); structure->Start(globalPos); - m_StructureManager->getStructureArray()->buildNewStructure( - structure, true); + m_StructureManager->getStructureArray()->buildNewStructure(structure, + true); break; } case UnitType::WAR_FACT: { auto structure = std::make_shared(house); auto globalPos = MapUtil::CellCoordToGlobal(cellPos); structure->Start(globalPos); - structure->setWaypointLocationByCellCoord({cellPos.x+2,cellPos.y-2}); - m_StructureManager->getStructureArray()->buildNewStructure( - structure, true); + structure->setWaypointLocationByCellCoord( + {cellPos.x + 2, cellPos.y - 2}); + m_StructureManager->getStructureArray()->buildNewStructure(structure, + true); break; } case UnitType::ADV_POWER_PLANT: { auto structure = std::make_shared(house); auto globalPos = MapUtil::CellCoordToGlobal(cellPos); structure->Start(globalPos); - m_StructureManager->getStructureArray()->buildNewStructure( - structure, true); + m_StructureManager->getStructureArray()->buildNewStructure(structure, + true); break; } case UnitType::INFANTRY: { @@ -94,8 +98,8 @@ void UnitManager::spawn(UnitType unit, HouseType house, glm::vec2 cellPos) { break; } } - if(unit!=UnitType::NONE){ - addUnitConstructCount(unit,1); + if (unit != UnitType::NONE) { + addUnitConstructCount(unit, 1); } }