diff --git a/include/AI/AIGroupCommander.hpp b/include/AI/AIGroupCommander.hpp index c77b3538..5e96a332 100644 --- a/include/AI/AIGroupCommander.hpp +++ b/include/AI/AIGroupCommander.hpp @@ -74,17 +74,19 @@ class AIGroupCommander { for (int j = 0; j < static_cast(i.size()); j++) { if (i[j]->getHealth()->ifDead()) { i.erase(i.begin() + j); + j--; } } } updateOffensiveTroopAttackTarget(); } void updateDefensiveGroup() { - for (int i = static_cast(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(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> temp = diff --git a/src/Map/Map.cpp b/src/Map/Map.cpp index 5a83d57b..8b618522 100644 --- a/src/Map/Map.cpp +++ b/src/Map/Map.cpp @@ -67,15 +67,17 @@ void MapClass::Init(std::vector>> 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(i, m_MapHeight - j)}); + m_Tiles[m_Map[j][i]->getTileImagePath()] = + std::vector({glm::vec2(j, m_MapHeight - i)}); } } } diff --git a/src/Map/MapBinReader.cpp b/src/Map/MapBinReader.cpp index 6c41ecf9..ebeeb3f1 100644 --- a/src/Map/MapBinReader.cpp +++ b/src/Map/MapBinReader.cpp @@ -67,7 +67,6 @@ MapBinReader::readBin(const std::string filepath, int width, int hieght) { // Close the file file.close(); - return fullmap; } diff --git a/src/Map/TerrainConfig.cpp b/src/Map/TerrainConfig.cpp index 97a2e275..50af40d5 100644 --- a/src/Map/TerrainConfig.cpp +++ b/src/Map/TerrainConfig.cpp @@ -9,9 +9,9 @@ std::unordered_map> {"Clear", std::make_shared(UnitType::TILE_CLEAR, 1, 1, 1)}, {"Gems", std::make_shared(UnitType::OVERLAY_GEMS, 0, 1, 1)}, {"Ore", std::make_shared(UnitType::OVERLAY_ORE, 0, 1, 1)}, - {"River", std::make_shared(UnitType::TILE_RIVER, 0, 0, 1)}, + {"River", std::make_shared(UnitType::TILE_RIVER, 0, 0, 0)}, {"Road", std::make_shared(UnitType::TILE_ROAD, 1, 1, 1)}, {"Rock", std::make_shared(UnitType::TILE_ROCK, 0, 0, 1)}, {"Rough", std::make_shared(UnitType::TILE_ROUGH, 0, 1, 1)}, - {"Tree", std::make_shared(UnitType::TILE_TREE, 0, 0, 1)}, - {"Water", std::make_shared(UnitType::TILE_WATER, 0, 0, 1)}}; + {"Tree", std::make_shared(UnitType::TILE_TREE, 0, 1, 1)}, + {"Water", std::make_shared(UnitType::TILE_WATER, 0, 0, 0)}}; diff --git a/src/Map/YAMLReader.cpp b/src/Map/YAMLReader.cpp index 47867a6b..aa2ff4a8 100644 --- a/src/Map/YAMLReader.cpp +++ b/src/Map/YAMLReader.cpp @@ -1,9 +1,9 @@ // // Created by 盧威任 on 3/18/24. // -#include #include "Map/YAMLReader.hpp" #include "Map/Tile.hpp" +#include std::string YAMLReader::convertYAMLTileToImagePath(int id, int index) { std::string indexStr = std::to_string(index); // Example string @@ -58,6 +58,9 @@ std::shared_ptr YAMLReader::convertYAMLTileToTileClass(int id, std::shared_ptr tile = std::move(TerrainConfig::GetConfig(terrainName)); tile->setTileImage(convertYAMLTileToImagePath(id, index)); + if (terrainName == "River") { + return tile; + } // tile->setTileImage(image); return tile;