nice
This commit is contained in:
137
include/td/game/World.h
Normal file
137
include/td/game/World.h
Normal file
@@ -0,0 +1,137 @@
|
||||
#pragma once
|
||||
|
||||
#include <td/game/WorldTypes.h>
|
||||
#include <td/protocol/packet/Packets.h>
|
||||
|
||||
namespace td {
|
||||
namespace game {
|
||||
|
||||
class World {
|
||||
protected:
|
||||
TowerTileColorPalette m_TowerPlacePalette;
|
||||
Color m_WalkablePalette;
|
||||
std::vector<Color> m_DecorationPalette;
|
||||
Color m_Background;
|
||||
|
||||
std::unordered_map<ChunkCoord, ChunkPtr> m_Chunks;
|
||||
|
||||
SpawnColorPalette m_SpawnColorPalette;
|
||||
|
||||
TilePalette m_TilePalette;
|
||||
|
||||
MobList m_Mobs;
|
||||
|
||||
TowerList m_Towers;
|
||||
|
||||
TeamList m_Teams;
|
||||
|
||||
public:
|
||||
World();
|
||||
|
||||
bool LoadMap(const protocol::pdata::WorldHeader& worldHeader);
|
||||
bool LoadMap(const protocol::pdata::WorldData& worldData);
|
||||
|
||||
bool LoadMapFromFile(const std::string& fileName);
|
||||
bool SaveMap(const std::string& fileName) const;
|
||||
|
||||
void Tick(std::uint64_t delta);
|
||||
|
||||
void SpawnMobAt(MobID id, MobType type, std::uint8_t level, PlayerID sender, float x, float y, Direction dir);
|
||||
|
||||
TowerPtr PlaceTowerAt(TowerID id, TowerType type, std::int32_t x, std::int32_t y, PlayerID builder);
|
||||
TowerPtr RemoveTower(TowerID id);
|
||||
|
||||
TilePtr GetTile(std::int32_t x, std::int32_t y) const;
|
||||
|
||||
const TowerTileColorPalette& GetTowerTileColorPalette() const {
|
||||
return m_TowerPlacePalette;
|
||||
}
|
||||
const Color& GetWalkableTileColor() const {
|
||||
return m_WalkablePalette;
|
||||
}
|
||||
const std::vector<Color>& GetDecorationPalette() const {
|
||||
return m_DecorationPalette;
|
||||
}
|
||||
const Color& GetBackgroundColor() const {
|
||||
return m_Background;
|
||||
}
|
||||
|
||||
const TilePalette& GetTilePalette() const {
|
||||
return m_TilePalette;
|
||||
}
|
||||
|
||||
TilePtr GetTilePtr(TileIndex index) const {
|
||||
if (index == 0)
|
||||
return nullptr;
|
||||
return m_TilePalette.at(index - 1);
|
||||
}
|
||||
|
||||
bool CanPlaceLittleTower(const Vec2f& worldPos, PlayerID player) const;
|
||||
bool CanPlaceBigTower(const Vec2f& worldPos, PlayerID player) const;
|
||||
|
||||
TowerPtr GetTower(const Vec2f& position) const; // returns null if no tower is here
|
||||
|
||||
const std::unordered_map<ChunkCoord, ChunkPtr>& GetChunks() const {
|
||||
return m_Chunks;
|
||||
}
|
||||
|
||||
const Color& GetSpawnColor(TeamColor color) const {
|
||||
return m_SpawnColorPalette[static_cast<std::size_t>(color)];
|
||||
}
|
||||
const SpawnColorPalette& GetSpawnColors() const {
|
||||
return m_SpawnColorPalette;
|
||||
}
|
||||
|
||||
const MobList& GetMobList() const {
|
||||
return m_Mobs;
|
||||
}
|
||||
MobList& GetMobList() {
|
||||
return m_Mobs;
|
||||
}
|
||||
|
||||
const Color* GetTileColor(TilePtr tile) const;
|
||||
|
||||
Team& GetRedTeam() {
|
||||
return m_Teams[static_cast<std::uint8_t>(TeamColor::Red)];
|
||||
}
|
||||
const Team& GetRedTeam() const {
|
||||
return m_Teams[static_cast<std::uint8_t>(TeamColor::Red)];
|
||||
}
|
||||
|
||||
Team& GetBlueTeam() {
|
||||
return m_Teams[static_cast<std::uint8_t>(TeamColor::Blue)];
|
||||
}
|
||||
const Team& GetBlueTeam() const {
|
||||
return m_Teams[static_cast<std::uint8_t>(TeamColor::Red)];
|
||||
}
|
||||
|
||||
Team& GetTeam(TeamColor team) {
|
||||
return m_Teams[static_cast<std::uint8_t>(team)];
|
||||
}
|
||||
const Team& GetTeam(TeamColor team) const {
|
||||
return m_Teams[static_cast<std::uint8_t>(team)];
|
||||
}
|
||||
|
||||
const TeamList& GetTeams() const {
|
||||
return m_Teams;
|
||||
}
|
||||
|
||||
const TowerList& GetTowers() const {
|
||||
return m_Towers;
|
||||
}
|
||||
|
||||
TowerPtr GetTowerById(TowerID tower);
|
||||
|
||||
const Player* GetPlayerById(PlayerID id) const;
|
||||
|
||||
private:
|
||||
void TickMobs(std::uint64_t delta);
|
||||
void CleanDeadMobs();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace game
|
||||
} // namespace td
|
||||
Reference in New Issue
Block a user