mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 11:53:51 +00:00
more refactoring
This commit is contained in:
parent
63424ade56
commit
47cc945ef4
3 changed files with 18 additions and 8 deletions
|
@ -59,7 +59,7 @@ bool MWMechanics::AiTravel::execute (const MWWorld::Ptr& actor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!mPathFinder.mIsPathConstructed ||cellChange)
|
if(!mPathFinder.isPathConstructed() ||cellChange)
|
||||||
{
|
{
|
||||||
cellX = actor.getCell()->mCell->mData.mX;
|
cellX = actor.getCell()->mCell->mData.mX;
|
||||||
cellY = actor.getCell()->mCell->mData.mY;
|
cellY = actor.getCell()->mCell->mData.mY;
|
||||||
|
@ -81,7 +81,7 @@ bool MWMechanics::AiTravel::execute (const MWWorld::Ptr& actor)
|
||||||
dest.mY = pos.pos[1];
|
dest.mY = pos.pos[1];
|
||||||
dest.mZ = pos.pos[2];
|
dest.mZ = pos.pos[2];
|
||||||
|
|
||||||
mPathFinder.findPath(start,dest,pathgrid,xCell,yCell);
|
mPathFinder.buildPath(start,dest,pathgrid,xCell,yCell);
|
||||||
}
|
}
|
||||||
if(mPathFinder.checkIfNextPointReached(pos.pos[0],pos.pos[1],pos.pos[2]))
|
if(mPathFinder.checkIfNextPointReached(pos.pos[0],pos.pos[1],pos.pos[2]))
|
||||||
{
|
{
|
||||||
|
|
|
@ -118,7 +118,7 @@ namespace MWMechanics
|
||||||
return graph;
|
return graph;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<ESM::Pathgrid::Point> getPath(PointID start,PointID end,PathGridGraph graph){
|
std::list<ESM::Pathgrid::Point> findPath(PointID start,PointID end,PathGridGraph graph){
|
||||||
std::vector<PointID> p(boost::num_vertices(graph));
|
std::vector<PointID> p(boost::num_vertices(graph));
|
||||||
std::vector<float> d(boost::num_vertices(graph));
|
std::vector<float> d(boost::num_vertices(graph));
|
||||||
std::list<ESM::Pathgrid::Point> shortest_path;
|
std::list<ESM::Pathgrid::Point> shortest_path;
|
||||||
|
@ -149,7 +149,7 @@ namespace MWMechanics
|
||||||
mIsPathConstructed = false;
|
mIsPathConstructed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<ESM::Pathgrid::Point> PathFinder::findPath(ESM::Pathgrid::Point startPoint,ESM::Pathgrid::Point endPoint,
|
void PathFinder::buildPath(ESM::Pathgrid::Point startPoint,ESM::Pathgrid::Point endPoint,
|
||||||
const ESM::Pathgrid* pathGrid,float xCell,float yCell)
|
const ESM::Pathgrid* pathGrid,float xCell,float yCell)
|
||||||
{
|
{
|
||||||
int start = getClosestPoint(pathGrid,startPoint.mX - xCell,startPoint.mY - yCell,startPoint.mZ);
|
int start = getClosestPoint(pathGrid,startPoint.mX - xCell,startPoint.mY - yCell,startPoint.mZ);
|
||||||
|
@ -158,13 +158,11 @@ namespace MWMechanics
|
||||||
if(start != -1 && end != -1)
|
if(start != -1 && end != -1)
|
||||||
{
|
{
|
||||||
PathGridGraph graph = buildGraph(pathGrid,xCell,yCell);
|
PathGridGraph graph = buildGraph(pathGrid,xCell,yCell);
|
||||||
mPath = getPath(start,end,graph);
|
mPath = findPath(start,end,graph);
|
||||||
}
|
}
|
||||||
|
|
||||||
mPath.push_back(endPoint);
|
mPath.push_back(endPoint);
|
||||||
mIsPathConstructed = true;
|
mIsPathConstructed = true;
|
||||||
|
|
||||||
return mPath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float PathFinder::getZAngleToNext(float x,float y,float z)
|
float PathFinder::getZAngleToNext(float x,float y,float z)
|
||||||
|
@ -198,4 +196,13 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::list<ESM::Pathgrid::Point> PathFinder::getPath()
|
||||||
|
{
|
||||||
|
return mPath;
|
||||||
|
}
|
||||||
|
bool PathFinder::isPathConstructed()
|
||||||
|
{
|
||||||
|
return mIsPathConstructed;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -11,13 +11,16 @@ namespace MWMechanics
|
||||||
public:
|
public:
|
||||||
PathFinder();
|
PathFinder();
|
||||||
|
|
||||||
std::list<ESM::Pathgrid::Point> findPath(ESM::Pathgrid::Point startPoint,ESM::Pathgrid::Point endPoint,
|
void buildPath(ESM::Pathgrid::Point startPoint,ESM::Pathgrid::Point endPoint,
|
||||||
const ESM::Pathgrid* pathGrid,float xCell = 0,float yCell = 0);
|
const ESM::Pathgrid* pathGrid,float xCell = 0,float yCell = 0);
|
||||||
|
|
||||||
bool checkIfNextPointReached(float x,float y,float z);//returns true if the last point of the path has been reached.
|
bool checkIfNextPointReached(float x,float y,float z);//returns true if the last point of the path has been reached.
|
||||||
float getZAngleToNext(float x,float y,float z);
|
float getZAngleToNext(float x,float y,float z);
|
||||||
|
|
||||||
|
std::list<ESM::Pathgrid::Point> getPath();
|
||||||
|
bool isPathConstructed();
|
||||||
|
|
||||||
|
private:
|
||||||
std::list<ESM::Pathgrid::Point> mPath;
|
std::list<ESM::Pathgrid::Point> mPath;
|
||||||
bool mIsPathConstructed;
|
bool mIsPathConstructed;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue