#ifndef MAP_H #define MAP_H #include #include #include #include #include #include namespace vb01{ class Model; class Material; class Node; } namespace vb01Gui{ class Button; } 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; Unit *blockedBy = nullptr; 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){} }; class Minimap{ public: static Minimap* getSingleton(); ~Minimap(); void update(); void updateImage(); void load(); void unload(); inline vb01::u8* getOldMinimapImage(){return oldImageData;} private: Minimap(); vb01::Node* initIcon(vb01::Vector3, std::string); void updateCamFrame(vb01Gui::Button*); vb01::u8 *oldImageData = nullptr; vb01::Node *camFrame = nullptr; std::vector depositIcons; vb01::Node* camIcon = nullptr; }; static Map* getSingleton(); ~Map(){} static std::vector generateAdjacentNodeEdges(int, int, int, int, int); void update(); void load(std::string); void create(std::string, vb01::Vector3); void unload(); std::vector raycastTerrain(vb01::Vector3, vb01::Vector3, bool); int getCellId(vb01::Vector3, bool = true); bool isPointWithinTerrainObject(vb01::Vector3, int); void loadPlayersGameObjects(); int getNumMapSpawnPoints(std::string = ""); std::vector getSurroundingCells(vb01::Vector3, int); void blockCells(Unit*); void unblockCells(Unit*); inline std::pair>& getRegion(int i){return regions[i];} inline int getNumRegions(){return regions.size();} inline Map::Cell getCell(int i){return cells[i];} 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 setMapSize(vb01::Vector3 s){this->mapSize = s;} inline vb01::Vector3 getMapSize(){return mapSize;} inline void addSpawnPoint(vb01::Vector3 sp){spawnPoints.push_back(sp);} inline std::vector& getCells(){return cells;} inline vb01::Node* getLight(int i){return lights[i];} inline std::vector getLights(){return lights;} inline float getBaseHeight(){return baseHeight;} inline void setBaseHeight(float bh){this->baseHeight = bh;} private: std::string mapTable = "metadata"; 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; float baseHeight; std::vector lights; std::vector>> regions; Map(){} void preprareScene(bool); void loadSpawnPoints(); void loadLights(); void loadSkybox(); void loadCells(); void loadPlayerGameObjects(Player*, sol::table); void loadTerrainObject(int); void fillRegion(std::vector&, int); void calculateRegions(); void unloadTerrainObjects(); void unloadCells(); void unloadLights(); void unloadSkybox(); void unloadPlayerObjects(); void destroyScene(); template int bsearch(std::vector, T, float); }; } #endif