Merge pull request #158 from devZoGok/bf-154-vessel-pathfinding

Bf 154 vessel pathfinding
This commit is contained in:
devZoGok
2024-07-28 11:51:27 +00:00
committed by GitHub
12 changed files with 41807 additions and 26967 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

File diff suppressed because it is too large Load Diff
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

File diff suppressed because it is too large Load Diff
+4 -11
View File
@@ -6,7 +6,6 @@
#include <quad.h>
#include <box.h>
#include <text.h>
#include <rayCaster.h>
#include <stateManager.h>
#include <solUtil.h>
@@ -403,18 +402,18 @@ namespace battleship{
Vector3 endPos = screenToSpace(getCursorPos());
Vector3 rayDir = (endPos - camPos).norm();
vector<RayCaster::CollisionResult> results = RayCaster::cast(camPos, rayDir, Map::getSingleton()->getNodeParent(), 0, configData::DIST_FROM_RAY);
Map *map = Map::getSingleton();
vector<RayCaster::CollisionResult> results = map->raycastTerrain(camPos, rayDir, true);
if(!results.empty()){
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
Map *map = Map::getSingleton();
for(Unit *u : mainPlayer->getSelectedUnits()){
Vector3 pos = u->getPos();
Node *nodeParent = map->getNodeParent();
if(u->getType() == UnitType::UNDERWATER && nodeParent->getNumChildren() > 0){
vector<RayCaster::CollisionResult> res = RayCaster::cast(Vector3(pos.x, 100, pos.z), Vector3(0, -1, 0), nodeParent->getChild(0), 0, configData::DIST_FROM_RAY);
vector<RayCaster::CollisionResult> res = map->raycastTerrain(Vector3(pos.x, 100, pos.z), Vector3(0, -1, 0), false);
Vector3 waterBodyPos = Vector3::VEC_ZERO;
Vector3 cellSize = map->getCellSize();
@@ -626,13 +625,7 @@ namespace battleship{
depth += 0.05;
Vector3 startPos = Root::getSingleton()->getCamera()->getPosition();
vector<RayCaster::CollisionResult> results = RayCaster::cast(
startPos,
(screenToSpace(getCursorPos()) - startPos).norm(),
Map::getSingleton()->getNodeParent()->getChild(0),
0,
configData::DIST_FROM_RAY
);
vector<RayCaster::CollisionResult> results = Map::getSingleton()->raycastTerrain(startPos, (screenToSpace(getCursorPos()) - startPos).norm(), true);
if(!results.empty())
ufCtr->setPaintSelectRowStart(results[0].pos);
+3 -3
View File
@@ -332,19 +332,19 @@ namespace battleship{
case RESOURCE_DEPOSITS:{
bool resources = (listboxType == RESOURCE_DEPOSITS);
sol::table gameObjTable = SOL_LUA_STATE[resources ? "resources" : "units"];
int numGameObjs = gameObjTable["num"];
int numGameObjs = gameObjTable.size();
for(int i = 0; i < numGameObjs; i++){
bool canAdd = true;
if(!resources){
bool vehicles = (listboxType == VEHICLES);
bool v = gameObjTable["isVehicle"][i + 1];
bool v = gameObjTable[i + 1]["isVehicle"];
canAdd = (v == vehicles);
}
if(canAdd)
lines.push_back(gameObjTable["name"][i + 1]);
lines.push_back(gameObjTable[i + 1]["name"]);
}
numLines = lines.size();
+1 -8
View File
@@ -14,7 +14,6 @@
#include <mesh.h>
#include <model.h>
#include <root.h>
#include <rayCaster.h>
#include <string>
@@ -119,13 +118,7 @@ namespace battleship{
frame.update();
Vector3 startPos = Root::getSingleton()->getCamera()->getPosition();
vector<RayCaster::CollisionResult> results = RayCaster::cast(
startPos,
(screenToSpace(getCursorPos()) - startPos).norm(),
Map::getSingleton()->getNodeParent()->getChild(0),
0,
configData::DIST_FROM_RAY
);
vector<RayCaster::CollisionResult> results = Map::getSingleton()->raycastTerrain(startPos, (screenToSpace(getCursorPos()) - startPos).norm(), true);
if(results.empty()) return;
+24 -6
View File
@@ -48,16 +48,16 @@ namespace battleship{
edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * (i + 1) + j));
if(up && left)
edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * (i - 1) + j - 1));
edges.push_back(Map::Edge(int(sqrt(2 * weight * weight)), numVertCells * i + j, numVertCells * (i - 1) + j - 1));
if(up && right)
edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * (i - 1) + j + 1));
edges.push_back(Map::Edge((sqrt(2 * weight * weight)), numVertCells * i + j, numVertCells * (i - 1) + j + 1));
if(down && left)
edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * (i + 1) + j - 1));
edges.push_back(Map::Edge((sqrt(2 * weight * weight)), numVertCells * i + j, numVertCells * (i + 1) + j - 1));
if(down && right)
edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * (i + 1) + j + 1));
edges.push_back(Map::Edge((sqrt(2 * weight * weight)), numVertCells * i + j, numVertCells * (i + 1) + j + 1));
return edges;
}
@@ -133,8 +133,10 @@ namespace battleship{
if(id == -1)
((Model*)node)->setMaterial(mat);
else
else{
mat->setTransparent(true);
quad->setMaterial(mat);
}
}
void Map::loadSpawnPoints(){
@@ -225,7 +227,7 @@ namespace battleship{
waterCellMat->addVec4Uniform("diffuseColor", Vector4(0, 0, 1, 1));
Camera *cam = root->getCamera();
cam->setFarPlane(300);
cam->setFarPlane(600);
cam->setPosition(Vector3(1, 1, 1) * configData::CAMERA_DISTANCE);
cam->lookAt(Vector3(-1, -1, -1).norm(), Vector3(-1, 1, -1).norm());
}
@@ -350,6 +352,22 @@ namespace battleship{
destroyScene();
}
vector<RayCaster::CollisionResult> Map::raycastTerrain(Vector3 rayPos, Vector3 rayDir, bool bothTerrTypes){
vector<RayCaster::CollisionResult> allResults = RayCaster::cast(rayPos, rayDir, terrainNode->getChild(0), 0, configData::DIST_FROM_RAY);
if(bothTerrTypes){
vector<Node*> waterNodes = terrainNode->getChildren();
waterNodes.erase(waterNodes.begin());
vector<RayCaster::CollisionResult> waterResults = RayCaster::cast(rayPos, rayDir, waterNodes);
allResults.insert(allResults.end(), waterResults.begin(), waterResults.end());
RayCaster::sortResults(allResults);
}
return allResults;
}
template<typename T> int Map::bsearch(vector<T> haystack, T needle, float eps){
T haystackMidVal;
bool sizeHaystackEven = (haystack.size() % 2 == 0);
+2
View File
@@ -4,6 +4,7 @@
#include <string>
#include <vector>
#include <rayCaster.h>
#include <vector.h>
#include <util.h>
@@ -46,6 +47,7 @@ namespace battleship{
void update();
void load(std::string, bool = false);
void unload();
std::vector<vb01::RayCaster::CollisionResult> raycastTerrain(vb01::Vector3, vb01::Vector3, bool);
int getCellId(vb01::Vector3, bool = true);
bool isPointWithinTerrainObject(vb01::Vector3, int);
void loadPlayerGameObjects();
+3 -4
View File
@@ -10,7 +10,6 @@
#include "mesh.h"
#include "util.h"
#include <rayCaster.h>
#include <box.h>
#include <text.h>
#include <node.h>
@@ -340,13 +339,13 @@ namespace battleship{
}
}
vector<Map::Edge> edges = Map::generateAdjacentNodeEdges(numVertCells, i, numHorCells, j, 1);
vector<Map::Edge> edges = Map::generateAdjacentNodeEdges(numVertCells, i, numHorCells, j, 10);
cells.push_back(Map::Cell(pos, type, edges));
}
vector<Map::Cell> waterCells;
int currUnderWaterCellId = cells.size();
int weight = 2;
int weight = 20;
for(pair<int, float> p : waterBodyBedPoints){
int numUnderWaterCells = (int)((cells[p.first].pos.y - p.second) / cellSize.y);
@@ -503,7 +502,7 @@ namespace battleship{
Vector3 size = ((Quad*)waterNode->getMesh(0))->getSize();
mapScript +=
"{pos = {x = " + to_string(pos.x) + ", y = " + to_string(pos.y) + ", z = " + to_string(pos.z) + "},\
size = {x = " + to_string(size.x) + ", y = " + to_string(size.y) + "}, albedo = \"water.jpg\"},";
size = {x = " + to_string(size.x) + ", y = " + to_string(size.y) + "}, albedo = \"water.png\"},";
}
mapScript += "}\n}";
-1
View File
@@ -1,7 +1,6 @@
#include <node.h>
#include <model.h>
#include <material.h>
#include <rayCaster.h>
#include <quaternion.h>
#include <particleEmitter.h>
-1
View File
@@ -3,7 +3,6 @@
#include <solUtil.h>
#include <util.h>
#include <rayCaster.h>
#include <box.h>
#include <model.h>
#include <quaternion.h>