mirror of
https://github.com/ApfelTeeSaft/PlanetFleet.git
synced 2026-08-26 19:33:38 +00:00
Merge pull request #160 from devZoGok/imp-153-test-maps
Imp 153 test maps
This commit is contained in:
Vendored
+1
-1
Submodule external/vb01 updated: 6077cf9cde...54b4d55f8d
@@ -142,8 +142,8 @@ namespace battleship{
|
||||
void Map::loadSpawnPoints(){
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
string spawnPointInd = "spawnPoints";
|
||||
SOL_LUA_VIEW.script("numSpawnPoints = #" + mapTable + "." + spawnPointInd);
|
||||
int numSpawnPoints = SOL_LUA_VIEW["numSpawnPoints"];
|
||||
sol::table spawnPointsTbl = SOL_LUA_VIEW[mapTable][spawnPointInd];
|
||||
int numSpawnPoints = spawnPointsTbl.size();
|
||||
|
||||
for(int i = 0; i < numSpawnPoints; i++){
|
||||
sol::table posTable = SOL_LUA_VIEW[mapTable][spawnPointInd][i + 1];
|
||||
|
||||
@@ -56,6 +56,7 @@ namespace battleship{
|
||||
inline vb01::Vector3 getCellSize(){return CELL_SIZE;}
|
||||
inline int getNumSpawnPoints(){return spawnPoints.size();}
|
||||
inline vb01::Vector3 getSpawnPoint(int i){return spawnPoints[i];}
|
||||
inline vb01::Vector3 getMapSize(){return mapSize;}
|
||||
inline void addSpawnPoint(vb01::Vector3 sp){spawnPoints.push_back(sp);}
|
||||
inline std::vector<Map::Cell>& getCells(){return cells;}
|
||||
private:
|
||||
|
||||
+26
-21
@@ -6,8 +6,8 @@
|
||||
#include "gameObjectFactory.h"
|
||||
#include "gameObjectFrameController.h"
|
||||
#include "player.h"
|
||||
#include "game.h"
|
||||
#include "map.h"
|
||||
#include "mesh.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <box.h>
|
||||
@@ -39,7 +39,6 @@ namespace battleship{
|
||||
|
||||
MapEditorAppState::MapEditor::MapEditor(string name, Vector2 size, bool newMap){
|
||||
this->newMap = newMap;
|
||||
this->mapSize = size;
|
||||
|
||||
string basePath = GameManager::getSingleton()->getPath();
|
||||
prepareTextures(basePath + "Textures/Skyboxes/", true, skyTextures);
|
||||
@@ -53,9 +52,10 @@ namespace battleship{
|
||||
|
||||
map = Map::getSingleton();
|
||||
map->load(name, newMap);
|
||||
Game *game = Game::getSingleton();
|
||||
|
||||
if(newMap){
|
||||
addPlayer(new Player(0, 0, 0, Vector3(1, 1, 1)));
|
||||
game->addPlayer(new Player(0, 0, 0, Vector3(1, 1, 1)));
|
||||
map->addSpawnPoint(Vector3::VEC_ZERO);
|
||||
generatePlane(size);
|
||||
}
|
||||
@@ -63,7 +63,7 @@ namespace battleship{
|
||||
int numPlayers = map->getNumSpawnPoints();
|
||||
|
||||
for(int i = 0; i < numPlayers; i++)
|
||||
addPlayer(new Player(0, 0, 0, Vector3(1, 1, 1)));
|
||||
game->addPlayer(new Player(0, 0, 0, Vector3(1, 1, 1)));
|
||||
|
||||
map->loadPlayerGameObjects();
|
||||
}
|
||||
@@ -305,10 +305,12 @@ namespace battleship{
|
||||
doc->SaveFile(name.c_str());
|
||||
}
|
||||
|
||||
//TODO add diagnally adjacent edges to underwater cells
|
||||
vector<Map::Cell> MapEditorAppState::MapEditor::generateMapCells(){
|
||||
Vector3 startPos = -.49 * Vector3(mapSize.x, 0, mapSize.y), cellSize = map->getCellSize();
|
||||
Vector3 mapSize = map->getMapSize();
|
||||
Vector3 startPos = -.49 * Vector3(mapSize.x, 0, mapSize.z), cellSize = map->getCellSize();
|
||||
int numHorCells = int(mapSize.x / cellSize.x);
|
||||
int numVertCells = int(mapSize.y / cellSize.z);
|
||||
int numVertCells = int(mapSize.z / cellSize.z);
|
||||
vector<Map::Cell> cells;
|
||||
vector<pair<int, float>> waterBodyBedPoints;
|
||||
Node *terrainNode = map->getNodeParent();
|
||||
@@ -343,7 +345,7 @@ namespace battleship{
|
||||
cells.push_back(Map::Cell(pos, type, edges));
|
||||
}
|
||||
|
||||
vector<Map::Cell> waterCells;
|
||||
vector<Map::Cell> surfaceWaterCells;
|
||||
int currUnderWaterCellId = cells.size();
|
||||
int weight = 20;
|
||||
|
||||
@@ -356,27 +358,27 @@ namespace battleship{
|
||||
for(int i = 0; i < numUnderWaterCells; i++, currUnderWaterCellId++)
|
||||
cells[p.first].underWaterCellIds.push_back(currUnderWaterCellId);
|
||||
|
||||
waterCells.push_back(cells[p.first]);
|
||||
surfaceWaterCells.push_back(cells[p.first]);
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < waterCells.size(); i++){
|
||||
for(int j = 0; j < waterCells[i].underWaterCellIds.size(); j++){
|
||||
int aboveCellId = (j == 0 ? waterCells[i].edges[0].srcCellId : j - 1);
|
||||
vector<Map::Edge> edges = vector<Map::Edge>{Map::Edge(weight, waterCells[i].underWaterCellIds[j], aboveCellId)};
|
||||
for(int i = 0; i < surfaceWaterCells.size(); i++){
|
||||
for(int j = 0; j < surfaceWaterCells[i].underWaterCellIds.size(); j++){
|
||||
int aboveCellId = (j == 0 ? surfaceWaterCells[i].edges[0].srcCellId : j - 1);
|
||||
vector<Map::Edge> edges = vector<Map::Edge>{Map::Edge(weight, surfaceWaterCells[i].underWaterCellIds[j], aboveCellId)};
|
||||
|
||||
if(waterCells[i].underWaterCellIds.size() > j + 1)
|
||||
edges.push_back(Map::Edge(weight, waterCells[i].underWaterCellIds[j], waterCells[i].underWaterCellIds[j + 1]));
|
||||
if(surfaceWaterCells[i].underWaterCellIds.size() > j + 1)
|
||||
edges.push_back(Map::Edge(weight, surfaceWaterCells[i].underWaterCellIds[j], surfaceWaterCells[i].underWaterCellIds[j + 1]));
|
||||
|
||||
for(int k = 0; k < waterCells[i].edges.size(); k++){
|
||||
Map::Cell adjacentUnderwaterCell = cells[waterCells[i].edges[k].destCellId];
|
||||
for(int k = 0; k < surfaceWaterCells[i].edges.size() - 1; k++){
|
||||
Map::Cell adjacentUnderwaterCell = cells[surfaceWaterCells[i].edges[k].destCellId];
|
||||
|
||||
if(adjacentUnderwaterCell.underWaterCellIds.size() >= j + 1){
|
||||
edges.push_back(Map::Edge(weight, waterCells[i].underWaterCellIds[j], adjacentUnderwaterCell.underWaterCellIds[j]));
|
||||
edges.push_back(Map::Edge(weight, surfaceWaterCells[i].underWaterCellIds[j], adjacentUnderwaterCell.underWaterCellIds[j]));
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 cellPos = waterCells[i].pos - Vector3::VEC_J * cellSize.y * (j + 1);
|
||||
Vector3 cellPos = surfaceWaterCells[i].pos - Vector3::VEC_J * cellSize.y * (j + 1);
|
||||
cells.push_back(Map::Cell(cellPos, Map::Cell::Type::WATER, edges));
|
||||
}
|
||||
}
|
||||
@@ -386,8 +388,11 @@ namespace battleship{
|
||||
|
||||
void MapEditorAppState::MapEditor::generateMapScript(){
|
||||
int numWaterBodies = map->getNodeParent()->getNumChildren() - 1;
|
||||
vector<Player*> players = Game::getSingleton()->getPlayers();
|
||||
|
||||
Vector3 mapSize = map->getMapSize();
|
||||
string mapScript = "map = {\nnumWaterBodies = " + to_string(numWaterBodies) + ",\n";
|
||||
mapScript += "size = {x = " + to_string(mapSize.x) + ", y = 100, z = " + to_string(mapSize.y) + "},\n";
|
||||
mapScript += "size = {x = " + to_string(mapSize.x) + ", y = 100, z = " + to_string(mapSize.z) + "},\n";
|
||||
mapScript += "impassibleNodeValue = " + to_string(IMPASS_NODE_VAL) + ",\n";
|
||||
mapScript += "numPlayers = " + to_string(players.size()) + ",\n";
|
||||
|
||||
@@ -432,7 +437,7 @@ namespace battleship{
|
||||
mapScript += "units = {\n";
|
||||
|
||||
for(int j = 0; j < numUnits; j++){
|
||||
Unit *unit = getPlayer(i)->getUnit(j);
|
||||
Unit *unit = Game::getSingleton()->getPlayer(i)->getUnit(j);
|
||||
|
||||
string idStr = "id = " + to_string(unit->getId());
|
||||
|
||||
@@ -593,7 +598,7 @@ namespace battleship{
|
||||
switch((Bind)bind){
|
||||
case Bind::LOOK_AROUND:
|
||||
if(ufCtr->isPlacingFrames()){
|
||||
Player *player = mapEditor->getPlayer(0);
|
||||
Player *player = Game::getSingleton()->getPlayer(0);
|
||||
GameObjectFrame &frame = ufCtr->getGameObjectFrame(0);
|
||||
Model *model = frame.getModel();
|
||||
Vector3 pos = model->getPosition();
|
||||
|
||||
@@ -40,8 +40,6 @@ namespace battleship{
|
||||
void exportMap();
|
||||
void prepareTerrainObjects(int = 0, int = -1);
|
||||
void togglePush(bool);
|
||||
inline void addPlayer(Player *pl){players.push_back(pl);}
|
||||
inline Player* getPlayer(int id){return players[id];}
|
||||
inline vb01::Node* getSelectedNode(){return selectedTerrainNode;}
|
||||
inline float getGuiThreshold(){return guiThreshold;}
|
||||
inline float getCircleRadius(){return circleRadius;}
|
||||
@@ -66,7 +64,6 @@ namespace battleship{
|
||||
void prepareTerrainObject(vb01::u32**, Map::Cell*, int[3], float, bool);
|
||||
|
||||
Map *map;
|
||||
std::vector<Player*> players;
|
||||
vb01::Node *selectedTerrainNode = nullptr;
|
||||
TransformAxis transformAxis = X_AXIS;
|
||||
vb01Gui::Listbox *skyListbox = nullptr;
|
||||
@@ -76,7 +73,6 @@ namespace battleship{
|
||||
const int NUM_SUBDIVS = 100;
|
||||
float circleRadius = MIN_RADIUS, guiThreshold = 200;
|
||||
vb01::Vector3 pushPos = vb01::Vector3::VEC_ZERO;
|
||||
vb01::Vector2 mapSize;
|
||||
std::vector<vb01::Texture*> skyTextures, landmassTextures, waterTextures;
|
||||
};
|
||||
|
||||
|
||||
@@ -288,10 +288,10 @@ namespace battleship{
|
||||
}
|
||||
|
||||
Camera *cam = Root::getSingleton()->getCamera();
|
||||
float near = cam->getNearPlane();
|
||||
float camNorm = cam->getNearPlane();
|
||||
float tg = tan(radians(cam->getFov()) / 2), ar = midWidth / midHeight;
|
||||
float camHeight = near * tg, camWidth = camHeight * ar;
|
||||
Vector3 posOffset = (cam->getLeft() * camWidth * horOffset + cam->getUp() * camHeight * vertOffset + cam->getDirection() * near);
|
||||
float camHeight = camNorm * tg, camWidth = camHeight * ar;
|
||||
Vector3 posOffset = (cam->getLeft() * camWidth * horOffset + cam->getUp() * camHeight * vertOffset + cam->getDirection() * camNorm);
|
||||
|
||||
return cam->getPosition() + posOffset;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user