diff --git a/map.h b/map.h index bd8840d..122fc39 100755 --- a/map.h +++ b/map.h @@ -47,8 +47,8 @@ namespace battleship{ std::string mapName; std::vector waterBodies; //TODO replace hardcoded values - vb01::Vector3 size = vb01::Vector3(100, 20, 100); - float bottom = 13; + vb01::Vector3 size = vb01::Vector3(100, 30, 100); + float bottom = 30; Map(){} void loadSkybox(gameBase::LuaManager*); diff --git a/mapTest.cpp b/mapTest.cpp new file mode 100644 index 0000000..71387d8 --- /dev/null +++ b/mapTest.cpp @@ -0,0 +1,30 @@ +#include "mapTest.h" +#include "map.h" + +namespace battleship{ + using namespace vb01; + + void MapTest::setUp(){ + } + + void MapTest::tearDown(){ + } + + void MapTest::testGenerateWeights(){ + Map *map = Map::getSingleton(); + Vector3 mapSize = map->getSize(), cellSize = Vector3(6, 1, 6); + int cellsByDim[3] = { + int(mapSize.x / cellSize.x), + int(mapSize.y / cellSize.y), + int(mapSize.z / cellSize.z) + }; + int numCells = cellsByDim[0] * cellsByDim[1] * cellsByDim[2]; + + u32 **weights = new u32*[numCells]; + + for(int i = 0; i < numCells; i++) + weights[i] = new u32[numCells]; + + map->generateWeights(weights, cellSize, UnitType::UNDERWATER, Vector3::VEC_ZERO, 60000); + } +} diff --git a/mapTest.h b/mapTest.h new file mode 100644 index 0000000..302b8d1 --- /dev/null +++ b/mapTest.h @@ -0,0 +1,21 @@ +#ifndef MAP_TEST_H +#define MAP_TEST_H + +#include +#include + +namespace battleship{ + class MapTest : public CppUnit::TestFixture{ + CPPUNIT_TEST_SUITE(MapTest); + CPPUNIT_TEST(testGenerateWeights); + CPPUNIT_TEST_SUITE_END(); + + public: + MapTest(){} + void testGenerateWeights(); + void setUp(); + void tearDown(); + }; +} + +#endif diff --git a/unit.cpp b/unit.cpp index a45f885..dfd0271 100755 --- a/unit.cpp +++ b/unit.cpp @@ -302,6 +302,13 @@ namespace battleship{ else if(0 < xId && xId < cellsByDim[0] - 1 && abs(j - i) == 1) adjacent = true; + if(yId == 0 && j - i == cellsByDim[0] * cellsByDim[2]) + adjacent = true; + else if(0 < yId && yId < cellsByDim[1] - 1 && abs(j - i) == cellsByDim[0] * cellsByDim[2]) + adjacent = true; + else if(yId == cellsByDim[1] - 1 && j - i == -(cellsByDim[0] * cellsByDim[2])) + adjacent = true; + if(zId == 0 && j - i == cellsByDim[0]) adjacent = true; else if(zId == cellsByDim[2] - 1 && j - i == -cellsByDim[0]) @@ -346,11 +353,11 @@ namespace battleship{ Map *map = Map::getSingleton(); Vector3 mapSize = map->getSize(); - Vector3 cellSize = Vector3(eps, (type == UnitType::UNDERWATER ? int(mapSize.y / height) : 0), eps); + Vector3 cellSize = Vector3(eps, (type == UnitType::UNDERWATER ? (mapSize.y / height) : 0), eps); int cellsByDim[3] = { int(mapSize.x / cellSize.x), - (cellSize.y == 0 ? 1 : int(mapSize.y / cellSize.y)), + (cellSize.y == 0 ? 1 : cellSize.y), int(mapSize.z / cellSize.z) }; int numCells = cellsByDim[0] * cellsByDim[1] * cellsByDim[2];