mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-23 13:23:52 +00:00
clean up + correct a bug
This commit is contained in:
parent
80804fac35
commit
9efb073617
1 changed files with 10 additions and 10 deletions
|
@ -40,8 +40,8 @@ float distance(ESM::Pathgrid::Point a,ESM::Pathgrid::Point b)
|
||||||
|
|
||||||
int getClosestPoint(const ESM::Pathgrid* grid,float x,float y,float z)
|
int getClosestPoint(const ESM::Pathgrid* grid,float x,float y,float z)
|
||||||
{
|
{
|
||||||
if(!grid) throw std::exception("NULL PathGrid!");
|
if(!grid) return -1;
|
||||||
if(grid->mPoints.empty()) throw std::exception("empty PathGrid!");
|
if(grid->mPoints.empty()) return -1;
|
||||||
|
|
||||||
float m = distance(grid->mPoints[0],x,y,z);
|
float m = distance(grid->mPoints[0],x,y,z);
|
||||||
int i0 = 0;
|
int i0 = 0;
|
||||||
|
@ -54,7 +54,6 @@ int getClosestPoint(const ESM::Pathgrid* grid,float x,float y,float z)
|
||||||
i0 = i;
|
i0 = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "distance:: " << m << "\n";
|
|
||||||
return i0;
|
return i0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +174,7 @@ bool MWMechanics::AiTravel::execute (const MWWorld::Ptr& actor)
|
||||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||||
if(actor.getCell()->mCell->mData.mX != player.getCell()->mCell->mData.mX)
|
if(actor.getCell()->mCell->mData.mX != player.getCell()->mCell->mData.mX)
|
||||||
{
|
{
|
||||||
int sideX = sgn(actor.getCell()->mCell->mData.mX != player.getCell()->mCell->mData.mX);
|
int sideX = sgn(actor.getCell()->mCell->mData.mX - player.getCell()->mCell->mData.mX);
|
||||||
//check if actor is near the border of an inactive cell. If so, disable aitravel.
|
//check if actor is near the border of an inactive cell. If so, disable aitravel.
|
||||||
if(sideX*(pos.pos[0] - actor.getCell()->mCell->mData.mX * ESM::Land::REAL_SIZE) > sideX*(ESM::Land::REAL_SIZE/2. - 2000))
|
if(sideX*(pos.pos[0] - actor.getCell()->mCell->mData.mX * ESM::Land::REAL_SIZE) > sideX*(ESM::Land::REAL_SIZE/2. - 2000))
|
||||||
{
|
{
|
||||||
|
@ -185,7 +184,7 @@ bool MWMechanics::AiTravel::execute (const MWWorld::Ptr& actor)
|
||||||
}
|
}
|
||||||
if(actor.getCell()->mCell->mData.mY != player.getCell()->mCell->mData.mY)
|
if(actor.getCell()->mCell->mData.mY != player.getCell()->mCell->mData.mY)
|
||||||
{
|
{
|
||||||
int sideY = sgn(actor.getCell()->mCell->mData.mY != player.getCell()->mCell->mData.mY);
|
int sideY = sgn(actor.getCell()->mCell->mData.mY - player.getCell()->mCell->mData.mY);
|
||||||
//check if actor is near the border of an inactive cell. If so, disable aitravel.
|
//check if actor is near the border of an inactive cell. If so, disable aitravel.
|
||||||
if(sideY*(pos.pos[1] - actor.getCell()->mCell->mData.mY * ESM::Land::REAL_SIZE) > sideY*(ESM::Land::REAL_SIZE/2. - 2000))
|
if(sideY*(pos.pos[1] - actor.getCell()->mCell->mData.mY * ESM::Land::REAL_SIZE) > sideY*(ESM::Land::REAL_SIZE/2. - 2000))
|
||||||
{
|
{
|
||||||
|
@ -193,10 +192,9 @@ bool MWMechanics::AiTravel::execute (const MWWorld::Ptr& actor)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//std::cout << "npcpos" << pos.pos[0] << pos.pos[1] <<pos.pos[2] <<"\n";
|
|
||||||
if(!isPathConstructed ||cellChange)
|
if(!isPathConstructed ||cellChange)
|
||||||
{
|
{
|
||||||
std::cout << "constructing path.... \n";
|
|
||||||
cellX = actor.getCell()->mCell->mData.mX;
|
cellX = actor.getCell()->mCell->mData.mX;
|
||||||
cellY = actor.getCell()->mCell->mData.mY;
|
cellY = actor.getCell()->mCell->mData.mY;
|
||||||
float xCell = 0;
|
float xCell = 0;
|
||||||
|
@ -210,9 +208,11 @@ bool MWMechanics::AiTravel::execute (const MWWorld::Ptr& actor)
|
||||||
int start = getClosestPoint(pathgrid,pos.pos[0] - xCell,pos.pos[1] - yCell,pos.pos[2]);
|
int start = getClosestPoint(pathgrid,pos.pos[0] - xCell,pos.pos[1] - yCell,pos.pos[2]);
|
||||||
int end = getClosestPoint(pathgrid,mX - xCell,mY - yCell,mZ);
|
int end = getClosestPoint(pathgrid,mX - xCell,mY - yCell,mZ);
|
||||||
|
|
||||||
PathGridGraph graph = buildGraph(pathgrid,xCell,yCell);
|
if(start != -1 && end != -1)
|
||||||
|
{
|
||||||
mPath = getPath(start,end,graph);
|
PathGridGraph graph = buildGraph(pathgrid,xCell,yCell);
|
||||||
|
mPath = getPath(start,end,graph);
|
||||||
|
}
|
||||||
|
|
||||||
ESM::Pathgrid::Point dest;
|
ESM::Pathgrid::Point dest;
|
||||||
dest.mX = mX;
|
dest.mX = mX;
|
||||||
|
|
Loading…
Reference in a new issue