Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 committed Jun 14, 2024
1 parent c73b300 commit 56cb49f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
10 changes: 6 additions & 4 deletions include/AI/AIGroupCommander.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,19 @@ class AIGroupCommander {
for (int j = 0; j < static_cast<int>(i.size()); j++) {
if (i[j]->getHealth()->ifDead()) {
i.erase(i.begin() + j);
j--;
}
}
}
updateOffensiveTroopAttackTarget();
}
void updateDefensiveGroup() {
for (int i = static_cast<int>(m_defensiveGroup.size()); i > 0; --i) {
if (m_defensiveGroup[i - 1]->getHealth()->ifDead()) {
m_defensiveGroup.erase(m_defensiveGroup.begin() + i - 1);
for (int i = 0; i < static_cast<int>(m_defensiveGroup.size()); i++) {
if (m_defensiveGroup[i]->getHealth()->ifDead()) {
m_defensiveGroup.erase(m_defensiveGroup.begin() + i);
i--;
} else {
autoAttack(m_defensiveGroup[i - 1], AUTO_ATTACK_METHOD);
autoAttack(m_defensiveGroup[i], AUTO_ATTACK_METHOD);
};
}
std::vector<std::shared_ptr<Avatar>> temp =
Expand Down
12 changes: 7 additions & 5 deletions src/Map/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@ void MapClass::Init(std::vector<std::vector<std::shared_ptr<TileClass>>> map,
InitGrid();

for (int i = 0; i < m_Map.size(); i++) {
// y
for (int j = 0; j < m_Map[i].size(); j++) {
// x

auto findResult = m_Tiles.find(m_Map[i][j]->getTileImagePath());
auto findResult = m_Tiles.find(m_Map[j][i]->getTileImagePath());
if (findResult != m_Tiles.end()) {
m_Tiles[m_Map[i][j]->getTileImagePath()].push_back(
glm::vec2(i, m_MapHeight - j));
m_Tiles[m_Map[j][i]->getTileImagePath()].push_back(
glm::vec2(j, m_MapHeight - i));
} else {
m_Tiles[m_Map[i][j]->getTileImagePath()] =
std::vector<glm::vec2>({glm::vec2(i, m_MapHeight - j)});
m_Tiles[m_Map[j][i]->getTileImagePath()] =
std::vector<glm::vec2>({glm::vec2(j, m_MapHeight - i)});
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Map/MapBinReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ MapBinReader::readBin(const std::string filepath, int width, int hieght) {

// Close the file
file.close();

return fullmap;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Map/TerrainConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ std::unordered_map<std::string, std::shared_ptr<TileClass>>
{"Clear", std::make_shared<TileClass>(UnitType::TILE_CLEAR, 1, 1, 1)},
{"Gems", std::make_shared<TileClass>(UnitType::OVERLAY_GEMS, 0, 1, 1)},
{"Ore", std::make_shared<TileClass>(UnitType::OVERLAY_ORE, 0, 1, 1)},
{"River", std::make_shared<TileClass>(UnitType::TILE_RIVER, 0, 0, 1)},
{"River", std::make_shared<TileClass>(UnitType::TILE_RIVER, 0, 0, 0)},
{"Road", std::make_shared<TileClass>(UnitType::TILE_ROAD, 1, 1, 1)},
{"Rock", std::make_shared<TileClass>(UnitType::TILE_ROCK, 0, 0, 1)},
{"Rough", std::make_shared<TileClass>(UnitType::TILE_ROUGH, 0, 1, 1)},
{"Tree", std::make_shared<TileClass>(UnitType::TILE_TREE, 0, 0, 1)},
{"Water", std::make_shared<TileClass>(UnitType::TILE_WATER, 0, 0, 1)}};
{"Tree", std::make_shared<TileClass>(UnitType::TILE_TREE, 0, 1, 1)},
{"Water", std::make_shared<TileClass>(UnitType::TILE_WATER, 0, 0, 0)}};
5 changes: 4 additions & 1 deletion src/Map/YAMLReader.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// Created by 盧威任 on 3/18/24.
//
#include <iomanip>
#include "Map/YAMLReader.hpp"
#include "Map/Tile.hpp"
#include <iomanip>

std::string YAMLReader::convertYAMLTileToImagePath(int id, int index) {
std::string indexStr = std::to_string(index); // Example string
Expand Down Expand Up @@ -58,6 +58,9 @@ std::shared_ptr<TileClass> YAMLReader::convertYAMLTileToTileClass(int id,
std::shared_ptr<TileClass> tile =
std::move(TerrainConfig::GetConfig(terrainName));
tile->setTileImage(convertYAMLTileToImagePath(id, index));
if (terrainName == "River") {
return tile;
}
// tile->setTileImage(image);

return tile;
Expand Down

0 comments on commit 56cb49f

Please sign in to comment.