From 081ddb2765689677a34a139f3fa526cdcecd6ccf Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 9 Oct 2022 15:41:30 +0300 Subject: [PATCH] cell size factored into the Map class fixed bug in Map::isPointWithinTerrainObject() --- map.cpp | 6 ++++-- map.h | 2 ++ unit.cpp | 7 ++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/map.cpp b/map.cpp index eca9da6..613dcf5 100755 --- a/map.cpp +++ b/map.cpp @@ -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{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 diff --git a/map.h b/map.h index 32ae35f..3f3ea00 100755 --- a/map.h +++ b/map.h @@ -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 terrainObjects; + vb01::Vector3 cellSize; Map(){} void loadSkybox(gameBase::LuaManager*); diff --git a/unit.cpp b/unit.cpp index b47a6c7..b2f30c5 100755 --- a/unit.cpp +++ b/unit.cpp @@ -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 path = pathfinder->findPath(weights, map->getTerrainObject(id).numCells, source, dest);