Skip to content

Commit

Permalink
formal sandbox fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ntut-Tu committed Jun 14, 2024
1 parent 5085f15 commit 97df67b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/AI/AIScripts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AIScript {
std::shared_ptr<MapClass> m_Map;
std::shared_ptr<AIGroupCommander> m_AIGroupCommander;

glm::vec2 m_baseCell = {20, 20};
glm::vec2 m_baseCell = {20, 30};
int constructCountX = 0;
int constructCountY = 0;

Expand Down
9 changes: 9 additions & 0 deletions include/Mechanics/BuiltStructure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ class BuiltStructure {
}
}
}
void setBarrackWayPointByCell(glm::vec2 cell){
if(ifBarrackBuilt()){
for(auto i:m_BuiltStructure){
if(i->getID().getUnitType() == UnitType::BARRACKS){
std::dynamic_pointer_cast<Barracks>(i) ->setWaypointLocationByCellCoord(cell);
}
}
}
}

bool ifBarrackBuilt() {
for (auto i : m_BuiltStructure) {
Expand Down
4 changes: 4 additions & 0 deletions include/Mechanics/StructureManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class StructureManager {
return m_BuiltStructure;
}

void setBarrackWayPointByCell(glm::vec2 cell){
m_BuiltStructure->setBarrackWayPointByCell(cell);
}

protected:
std::shared_ptr<MapClass> m_Map = std::make_shared<MapClass>();
std::shared_ptr<BuiltStructure> m_BuiltStructure =
Expand Down
3 changes: 3 additions & 0 deletions include/Mechanics/UnitManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class UnitManager : public Player {
return m_cheat;
}

void setBarrackWayPointByCell(glm::vec2 cell){
m_StructureManager->setBarrackWayPointByCell(cell);
}

private:
std::unordered_map<UnitType,int> unitCount;
Expand Down
13 changes: 7 additions & 6 deletions src/AI/AIScripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,18 @@ void AIScript::buildBasic() {
setCDTime(15.f, SpawnMode::BUILDINGS);
setCost(300, SpawnMode::BUILDINGS);
m_selectedBuildingType = UnitType::POWER_PLANT;
} else if (m_EnemyObjectManager->getUnitConstructCount(UnitType::ORE_REF) <
1 &&
m_EnemyObjectManager->getTotalCurrency() > 2000) {
setCDTime(100.f, SpawnMode::BUILDINGS);
setCost(2000, SpawnMode::BUILDINGS);
m_selectedBuildingType = UnitType::ORE_REF;
} else if (m_EnemyObjectManager->getUnitConstructCount(UnitType::BARRACKS) <
1 &&
m_EnemyObjectManager->getTotalCurrency() > 300) {
setCDTime(15.f, SpawnMode::BUILDINGS);
setCost(300, SpawnMode::BUILDINGS);
m_selectedBuildingType = UnitType::BARRACKS;
} else if (m_EnemyObjectManager->getUnitConstructCount(UnitType::ORE_REF) <
1 &&
m_EnemyObjectManager->getTotalCurrency() > 2000) {
setCDTime(100.f, SpawnMode::BUILDINGS);
setCost(2000, SpawnMode::BUILDINGS);
m_selectedBuildingType = UnitType::ORE_REF;
}
}

Expand Down Expand Up @@ -210,6 +210,7 @@ void AIScript::UpdateSpawnScript(SpawnMode spawnMode) {
return;
}
if (m_selectedAvatarType == UnitType::INFANTRY) {
m_EnemyObjectManager->setBarrackWayPointByCell({m_baseCell.x-1+5*(m_EnemyObjectManager->getAvatarCount()%3),m_baseCell.y-1});
m_EnemyObjectManager->spawnToWayPoint(m_selectedAvatarType,
HouseType::ENEMY);
setCost(0, SpawnMode::AVATAR);
Expand Down
2 changes: 1 addition & 1 deletion src/Scene/SandBoxScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void SandBoxScene::stageStart() {
}
case Stages::FORMAL_START:{
m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {7, 9});
m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY, {18, 18});
m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY, {36, 36});
break;
}
}
Expand Down

0 comments on commit 97df67b

Please sign in to comment.