mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
87 lines
2.5 KiB
C++
Executable File
87 lines
2.5 KiB
C++
Executable File
#pragma once
|
|
#ifndef MAP_H
|
|
#define MAP_H
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <vector.h>
|
|
#include <util.h>
|
|
|
|
namespace vb01{
|
|
class Model;
|
|
class Material;
|
|
class Node;
|
|
}
|
|
|
|
namespace battleship{
|
|
class Player;
|
|
class GameObject;
|
|
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<Edge> edges;
|
|
std::vector<int> underWaterCellIds;
|
|
|
|
Cell(){}
|
|
Cell(vb01::Vector3 p, Type t, std::vector<Edge> e = std::vector<Edge>{}, std::vector<int> uc = std::vector<int>{}): pos(p), type(t), edges(e), underWaterCellIds(uc){}
|
|
int getEdgeWeight(int);
|
|
};
|
|
|
|
static Map* getSingleton();
|
|
~Map(){}
|
|
void update();
|
|
void load(std::string, bool = false);
|
|
void unload();
|
|
int getCellId(vb01::Vector3);
|
|
bool isPointWithinTerrainObject(vb01::Vector3, int);
|
|
inline std::string getMapName(){return mapName;}
|
|
inline vb01::Node* getNodeParent(){return terrainNode;}
|
|
inline vb01::Vector3 getCellSize(){return CELL_SIZE;}
|
|
inline std::vector<Player*> getPlayers() {return players;}
|
|
inline Player* getPlayer(int i){return players[i];}
|
|
inline void addPlayer(Player *p){players.push_back(p);}
|
|
inline int getNumPlayers(){return players.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<Map::Cell>& getCells(){return cells;}
|
|
inline void addNpcGameObject(GameObject *obj){npcGameObjects.push_back(obj);}
|
|
inline std::vector<GameObject*> getNpcGameObjects(){return npcGameObjects;}
|
|
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<vb01::Vector3> spawnPoints;
|
|
std::vector<Player*> players;
|
|
std::vector<Cell> cells;
|
|
std::vector<GameObject*> npcGameObjects;
|
|
|
|
Map(){}
|
|
void preprareScene();
|
|
void loadSpawnPoints();
|
|
void loadPlayers();
|
|
void loadSkybox();
|
|
void loadCells();
|
|
void loadTerrainObject(int);
|
|
template<typename T> int bsearch(std::vector<T>, T, float);
|
|
};
|
|
}
|
|
|
|
#endif
|