implemented simple pathfinding

This commit is contained in:
devZoGok
2023-09-03 10:39:42 +03:00
parent 02bf2cdd08
commit 63c0acf613
15 changed files with 55 additions and 143361 deletions
Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -5,7 +5,7 @@ gui = {
size = {x = 300, y = 20},
guiType = GuiType.LISTBOX,
listboxType = ListboxType.CONSOLE,
numMaxDisplay = 20,
numMaxDisplay = 10,
closable = false
},
{
+1 -1
View File
@@ -5,7 +5,7 @@ project(${GAME_NAME})
set(CMAKE_CXX_STANDART 17)
set(CMAKE_BUILD_TYPE Debug)
set(BUILD_TESTS OFF)
set(BUILD_TESTS ON)
cmake_policy(SET CMP0015 NEW)
set(OPTIONS_BUTTONS optionsButton.cpp tabButton.cpp okButton.cpp defaultsButton.cpp)
+1
View File
@@ -272,6 +272,7 @@ namespace battleship{
lines.push_back("");
closable = false;
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
listbox = new Listbox(pos, size, lines, maxDisplay, fontPath, closable);
}
+22 -2
View File
@@ -208,6 +208,7 @@ namespace battleship{
}
}
//TODO implement map size calculation when exporting maps
void Map::load(string mapName, bool empty) {
this->mapName = mapName;
@@ -218,7 +219,9 @@ namespace battleship{
preprareScene();
if(!empty){
SOL_LUA_STATE.script_file(GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/" + mapName + ".lua");
SOL_LUA_STATE.script_file(path + "Models/Maps/" + mapName + "/" + mapName + ".lua");
sol::table sizeTable = SOL_LUA_STATE[mapTable]["size"];
mapSize = Vector3(sizeTable["x"], sizeTable["y"], sizeTable["z"]);
int numWaterbodies = SOL_LUA_STATE[mapTable]["numWaterBodies"];
loadSpawnPoints();
@@ -266,8 +269,25 @@ namespace battleship{
}
}
//TODO replace search with binary search
//TODO implement search for underwater cells
int Map::getCellId(Vector3 pos){
int numHorCells = int(mapSize.x / CELL_SIZE.x), horId = -1;
return 0;
for(int i = 0; i < numHorCells; i++)
if(fabs(cells[i].pos.x - pos.x) < .5 * CELL_SIZE.x){
horId = i;
break;
}
int numVertCells = int(mapSize.z / CELL_SIZE.z), vertId = -1;
for(int i = 0; i < numVertCells; i++)
if(fabs(cells[i * numHorCells].pos.z - pos.z) < .5 * CELL_SIZE.z){
vertId = i;
break;
}
return vertId * numHorCells + horId;
}
}
+1
View File
@@ -2,6 +2,7 @@
#include "player.h"
#include "vehicle.h"
#include "engineer.h"
#include "defConfigs.h"
#include <solUtil.h>
+23 -1
View File
@@ -4,6 +4,7 @@
#include <util.h>
#include <ray.h>
#include <box.h>
#include <model.h>
#include <quaternion.h>
@@ -18,6 +19,11 @@ using namespace std;
namespace battleship{
Vehicle::Vehicle(Player *player, int id, Vector3 pos, Quaternion rot) : Unit(player, id, pos, rot){
initProperties();
debugMat = new Material(Root::getSingleton()->getLibPath() + "texture");
debugMat->addBoolUniform("lightingEnabled", false);
debugMat->addBoolUniform("texturingEnabled", false);
debugMat->addVec4Uniform("diffuseColor", Vector4::VEC_IJKL);
}
void Vehicle::halt(){
@@ -136,6 +142,7 @@ namespace battleship{
}
//TODO add hover unit type
//TODO cleanup debug pathpoint removal
void Vehicle::preparePathpoints(Order order){
Map *map = Map::getSingleton();
int source = map->getCellId(pos);
@@ -144,9 +151,24 @@ namespace battleship{
Pathfinder *pathfinder = Pathfinder::getSingleton();
vector<Map::Cell> &cells = map->getCells();
vector<int> path = pathfinder->findPath(cells, source, dest);
Node *rootNode = Root::getSingleton()->getRootNode();
for(Node *node : debugPathPoints)
rootNode->dettachChild(node);
debugPathPoints.clear();
pathPoints.clear();
for(int p : path)
for(int p : path){
pathPoints.push_back(cells[p].pos);
Box *b = new Box(Vector3::VEC_IJK);
b->setMaterial(debugMat);
Node *n = new Node(cells[p].pos);
n->attachMesh(b);
rootNode->attachChild(n);
debugPathPoints.push_back(n);
}
}
}
+6
View File
@@ -3,6 +3,10 @@
#include "unit.h"
namespace vb01{
class Material;
}
namespace battleship{
class Vehicle : public Unit{
public:
@@ -11,6 +15,8 @@ namespace battleship{
private:
int patrolPointId = 0;
float speed, maxTurnAngle, anglePrecision;
vb01::Material *debugMat = nullptr;
std::vector<vb01::Node*> debugPathPoints;
inline int getNextPatrolPointId(int numPoints) {return patrolPointId == numPoints - 1 ? 0 : patrolPointId + 1;}
void halt();