mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
cell size factored into the Map class
fixed bug in Map::isPointWithinTerrainObject()
This commit is contained in:
@@ -168,10 +168,12 @@ namespace battleship{
|
||||
else
|
||||
quad->setMaterial(mat);
|
||||
|
||||
terrainObjects.push_back(TerrainObject(pos, size, Vector3(14, (id == -1 ? 0 : 4), 14), type, node, numCells, cells, weights));
|
||||
terrainObjects.push_back(TerrainObject(pos, size, Vector3(cellSize.x, (id == -1 ? 0 : cellSize.y), cellSize.z), type, node, numCells, cells, weights));
|
||||
}
|
||||
|
||||
void Map::load(string mapName) {
|
||||
cellSize = Vector3(14, 6, 14);
|
||||
|
||||
this->mapName = mapName;
|
||||
LuaManager *luaManager = LuaManager::getSingleton();
|
||||
luaManager->buildScript(vector<string>{GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/" + mapName + ".lua"});
|
||||
@@ -217,7 +219,7 @@ namespace battleship{
|
||||
Vector3 pos = terrainObjects[id].pos, size = terrainObjects[id].size;
|
||||
|
||||
if(terrainObjects[id].type == TerrainObject::RECT_WATERBODY)
|
||||
within = (fabs(pos.x - p.x) < size.x && fabs(pos.z - p.z) < size.y);
|
||||
within = (fabs(pos.x - p.x) < 0.5 * size.x && fabs(pos.z - p.z) < 0.5 * size.z);
|
||||
else if(terrainObjects[id].type == TerrainObject::ROUND_WATERBODY)
|
||||
within = Vector2(pos.x, pos.z).getDistanceFrom(Vector2(p.x, p.z)) < size.x;
|
||||
else
|
||||
|
||||
@@ -58,11 +58,13 @@ namespace battleship{
|
||||
inline TerrainObject getTerrainObject(int i){return terrainObjects[i];}
|
||||
inline int getNumTerrainObjects(){return terrainObjects.size();}
|
||||
inline vb01::Node* getNodeParent(){return nodeParent;}
|
||||
inline vb01::Vector3 getCellSize(){return cellSize;}
|
||||
private:
|
||||
std::string mapTable = "map";
|
||||
vb01::Node *nodeParent = nullptr;
|
||||
std::string mapName;
|
||||
std::vector<TerrainObject> terrainObjects;
|
||||
vb01::Vector3 cellSize;
|
||||
|
||||
Map(){}
|
||||
void loadSkybox(gameBase::LuaManager*);
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace battleship{
|
||||
attack(order);
|
||||
break;
|
||||
case Order::TYPE::MOVE:
|
||||
move(order, UnitDataManager::getSingleton()->getDestinationOffset()[id]);
|
||||
move(order, 0.5 * Map::getSingleton()->getCellSize().x);
|
||||
break;
|
||||
case Order::TYPE::PATROL:
|
||||
patrol(order);
|
||||
@@ -284,6 +284,11 @@ namespace battleship{
|
||||
|
||||
int source = map->getCellId(pos, id);
|
||||
int dest = map->getCellId(order.targets[0].pos, id);
|
||||
int numCells = map->getTerrainObject(id).numCells;
|
||||
|
||||
if(source > numCells || dest > numCells)
|
||||
return;
|
||||
|
||||
Pathfinder *pathfinder = Pathfinder::getSingleton();
|
||||
u32 **weights = map->getTerrainObject(id).weights;
|
||||
vector<int> path = pathfinder->findPath(weights, map->getTerrainObject(id).numCells, source, dest);
|
||||
|
||||
Reference in New Issue
Block a user