refactor: move tower place detection to World.cpp
This commit is contained in:
@@ -20,7 +20,7 @@ World::World(Game* game) : m_Game(game) {
|
||||
#endif
|
||||
}
|
||||
|
||||
TilePtr World::getTile(std::int32_t x, std::int32_t y) {
|
||||
TilePtr World::getTile(std::int32_t x, std::int32_t y) const {
|
||||
std::int16_t chunkX = x / Chunk::ChunkWidth;
|
||||
std::int16_t chunkY = y / Chunk::ChunkHeight;
|
||||
|
||||
@@ -389,6 +389,50 @@ const Color* World::getTileColor(TilePtr tile) const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool World::CanPlaceLittleTower(const glm::vec2& worldPos) const {
|
||||
TilePtr tile = getTile(worldPos.x, worldPos.y);
|
||||
|
||||
if (tile == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tile->getType() == game::TileType::Tower) {
|
||||
for (int x = -1; x < 2; x++) {
|
||||
for (int y = -1; y < 2; y++) {
|
||||
game::TilePtr adjacentTile = getTile(worldPos.x + x, worldPos.y + y);
|
||||
if (adjacentTile == nullptr || adjacentTile->getType() != game::TileType::Tower) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool World::CanPlaceBigTower(const glm::vec2& worldPos) const {
|
||||
TilePtr tile = getTile(worldPos.x, worldPos.y);
|
||||
|
||||
if (tile == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tile->getType() == game::TileType::Tower) {
|
||||
for (int x = -2; x < 3; x++) {
|
||||
for (int y = -2; y < 3; y++) {
|
||||
game::TilePtr adjacentTile = getTile(worldPos.x + x, worldPos.y + y);
|
||||
if (adjacentTile == nullptr || adjacentTile->getType() != game::TileType::Tower) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Team& World::getRedTeam() {
|
||||
return m_Game->getRedTeam();
|
||||
}
|
||||
|
||||
@@ -116,49 +116,5 @@ void ClientGame::PlaceTower(game::TowerType type, const glm::vec2& position) {
|
||||
m_Client->getConnexion().sendPacket(&packet);
|
||||
}
|
||||
|
||||
bool ClientGame::CanPlaceLittleTower(const glm::vec2& worldPos) {
|
||||
game::TilePtr tile = m_WorldClient.getTile(worldPos.x, worldPos.y);
|
||||
|
||||
if (tile == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tile->getType() == game::TileType::Tower) {
|
||||
for (int x = -1; x < 2; x++) {
|
||||
for (int y = -1; y < 2; y++) {
|
||||
game::TilePtr adjacentTile = m_WorldClient.getTile(worldPos.x + x, worldPos.y + y);
|
||||
if (adjacentTile == nullptr || adjacentTile->getType() != game::TileType::Tower) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ClientGame::CanPlaceBigTower(const glm::vec2& worldPos) {
|
||||
game::TilePtr tile = m_WorldClient.getTile(worldPos.x, worldPos.y);
|
||||
|
||||
if (tile == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tile->getType() == game::TileType::Tower) {
|
||||
for (int x = -2; x < 3; x++) {
|
||||
for (int y = -2; y < 3; y++) {
|
||||
game::TilePtr adjacentTile = m_WorldClient.getTile(worldPos.x + x, worldPos.y + y);
|
||||
if (adjacentTile == nullptr || adjacentTile->getType() != game::TileType::Tower) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace client
|
||||
} // namespace td
|
||||
|
||||
Reference in New Issue
Block a user