#ifndef MAP_H #define MAP_H #include #include #include #include namespace vb01{ class Model; class Material; class Node; } namespace battleship{ class Player; class Unit; class ResourceDeposit; struct Cell; class Map { public: struct Cell; struct Edge{ Edge(vb01::s64 w, vb01::s64 src, vb01::s64 dest) : weight(w), srcCellId(src), destCellId(dest){} vb01::s64 weight, srcCellId, destCellId; }; struct Cell{ enum Type{LAND, WATER}; Type type; vb01::Vector3 pos; std::vector edges; std::vector underWaterCellIds; Cell(){} Cell(vb01::Vector3 p, Type t, std::vector e = std::vector{}, std::vector uc = std::vector{}): pos(p), type(t), edges(e), underWaterCellIds(uc){} }; static Map* getSingleton(); ~Map(){} static std::vector generateAdjacentNodeEdges(int, int, int, int, int); void update(); void load(std::string, bool = false); void unload(); int getCellId(vb01::Vector3, bool = true); bool isPointWithinTerrainObject(vb01::Vector3, int); void loadPlayerGameObjects(); inline std::string getMapName(){return mapName;} inline vb01::Node* getNodeParent(){return terrainNode;} inline vb01::Vector3 getCellSize(){return CELL_SIZE;} inline int getNumSpawnPoints(){return spawnPoints.size();} inline vb01::Vector3 getSpawnPoint(int i){return spawnPoints[i];} inline void addSpawnPoint(vb01::Vector3 sp){spawnPoints.push_back(sp);} inline std::vector& getCells(){return cells;} private: std::string mapTable = "map"; vb01::Node *terrainNode = nullptr, *cellNode = nullptr; vb01::Material *landCellMat = nullptr, *waterCellMat = nullptr; std::string mapName; vb01::Vector3 CELL_SIZE = vb01::Vector3(7, 7, 7), mapSize; std::vector spawnPoints; std::vector cells; Map(){} void preprareScene(); void loadSpawnPoints(); void loadSkybox(); void loadCells(); void loadTerrainObject(int); void unloadTerrainObjects(); void unloadCells(); void unloadSkybox(); void unloadPlayerObjects(); void destroyScene(); template int bsearch(std::vector, T, float); }; } #endif