Files
PlanetFleet/map.h
T

78 lines
2.1 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 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;
Cell(){}
Cell(vb01::Vector3 p, Type t, std::vector<Edge> e = std::vector<Edge>{}): pos(p), type(t), edges(e){}
};
static Map* getSingleton();
~Map(){}
void update();
void load(std::string, bool = false);
void unload();
int getCellId(vb01::Vector3, int);
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);}
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);
std::vector<vb01::Vector3> spawnPoints;
std::vector<Player*> players;
std::vector<Cell> cells;
Map(){}
void preprareScene();
void loadSpawnPoints();
void loadPlayers();
void loadSkybox();
void loadCells();
void loadTerrainObject(int);
};
}
#endif