137 lines
3.3 KiB
C++
137 lines
3.3 KiB
C++
#pragma once
|
|
|
|
#include <td/simulation/WorldTicker.h>
|
|
#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;
|
|
|
|
ChunkList m_Chunks;
|
|
|
|
SpawnColorPalette m_SpawnColorPalette;
|
|
|
|
TilePalette m_TilePalette;
|
|
|
|
std::shared_ptr<sim::WorldSnapshot> m_CurrentState;
|
|
std::shared_ptr<sim::WorldSnapshot> m_NextState;
|
|
|
|
private:
|
|
sim::WorldTicker m_Ticker;
|
|
|
|
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 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 TilePtr(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 ChunkList& 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_CurrentState->m_Mobs;
|
|
}
|
|
MobList& GetMobList() {
|
|
return m_CurrentState->m_Mobs;
|
|
}
|
|
|
|
const Color* GetTileColor(const TilePtr& tile) const;
|
|
|
|
Team& GetRedTeam() {
|
|
return m_CurrentState->m_Teams[TeamColor::Red];
|
|
}
|
|
const Team& GetRedTeam() const {
|
|
return m_CurrentState->m_Teams[TeamColor::Red];
|
|
}
|
|
|
|
Team& GetBlueTeam() {
|
|
return m_CurrentState->m_Teams[TeamColor::Blue];
|
|
}
|
|
const Team& GetBlueTeam() const {
|
|
return m_CurrentState->m_Teams[TeamColor::Red];
|
|
}
|
|
|
|
Team& GetTeam(TeamColor team) {
|
|
return m_CurrentState->m_Teams[team];
|
|
}
|
|
const Team& GetTeam(TeamColor team) const {
|
|
return m_CurrentState->m_Teams[team];
|
|
}
|
|
|
|
const TeamList& GetTeams() const {
|
|
return m_CurrentState->m_Teams;
|
|
}
|
|
|
|
const TowerList& GetTowers() const {
|
|
return m_CurrentState->m_Towers;
|
|
}
|
|
|
|
TowerPtr GetTowerById(TowerID tower);
|
|
|
|
const Player* GetPlayerById(PlayerID id) const;
|
|
|
|
const std::shared_ptr<sim::WorldSnapshot>& Tick(const protocol::LockStep& a_LockStep, FpFloat a_Delta);
|
|
|
|
void ResetSnapshots(std::shared_ptr<sim::WorldSnapshot>& a_Current, std::shared_ptr<sim::WorldSnapshot>& a_Next);
|
|
|
|
private:
|
|
void TickMobs(std::uint64_t delta);
|
|
void CleanDeadMobs();
|
|
|
|
};
|
|
|
|
} // namespace game
|
|
} // namespace td
|