forked from teamnwah/openmw-tes3coop
AiFollow. Npc get stuck often (no stuck dtection yet)
This commit is contained in:
parent
f41f08c352
commit
2d66b2c4fa
3 changed files with 51 additions and 3 deletions
|
@ -3,7 +3,7 @@
|
||||||
#include "movement.hpp"
|
#include "movement.hpp"
|
||||||
|
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
#include "../mwworld/timestamp.hpp"
|
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwbase/mechanicsmanager.hpp"
|
#include "../mwbase/mechanicsmanager.hpp"
|
||||||
|
@ -87,6 +87,7 @@ namespace MWMechanics
|
||||||
mPathFinder = mPathFinder2;
|
mPathFinder = mPathFinder2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ESM::Pathgrid::Point lastPt = mPathFinder.getPath().back();
|
||||||
|
|
||||||
mPathFinder.checkPathCompleted(pos.pos[0],pos.pos[1],pos.pos[2]);
|
mPathFinder.checkPathCompleted(pos.pos[0],pos.pos[1],pos.pos[2]);
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
#include "aifollow.hpp"
|
#include "aifollow.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "../mwbase/world.hpp"
|
||||||
|
#include "../mwbase/environment.hpp"
|
||||||
|
#include "../mwworld/class.hpp"
|
||||||
|
#include "movement.hpp"
|
||||||
|
|
||||||
MWMechanics::AiFollow::AiFollow(const std::string &actorId,float duration, float x, float y, float z)
|
MWMechanics::AiFollow::AiFollow(const std::string &actorId,float duration, float x, float y, float z)
|
||||||
: mDuration(duration), mX(x), mY(y), mZ(z), mActorId(actorId)
|
: mDuration(duration), mX(x), mY(y), mZ(z), mActorId(actorId)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
MWMechanics::AiFollow::AiFollow(const std::string &actorId,const std::string &cellId,float duration, float x, float y, float z)
|
MWMechanics::AiFollow::AiFollow(const std::string &actorId,const std::string &cellId,float duration, float x, float y, float z)
|
||||||
: mDuration(duration), mX(x), mY(y), mZ(z), mActorId(actorId), mCellId(cellId)
|
: mDuration(duration), mX(x), mY(y), mZ(z), mActorId(actorId), mCellId(cellId), mTimer(0), mStuckTimer(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,8 +21,44 @@ MWMechanics::AiFollow *MWMechanics::AiFollow::clone() const
|
||||||
|
|
||||||
bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration)
|
bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration)
|
||||||
{
|
{
|
||||||
|
const MWWorld::Ptr target = MWBase::Environment::get().getWorld()->getPtr(mActorId, false);
|
||||||
|
|
||||||
|
mTimer = mTimer + duration;
|
||||||
|
mStuckTimer = mStuckTimer + duration;
|
||||||
|
mTotalTime = mTotalTime + duration;
|
||||||
|
|
||||||
|
if(mTotalTime > mDuration) return true;
|
||||||
|
|
||||||
|
ESM::Pathgrid::Point dest;
|
||||||
|
dest.mX = target.getRefData().getPosition().pos[0];
|
||||||
|
dest.mY = target.getRefData().getPosition().pos[1];
|
||||||
|
dest.mZ = target.getRefData().getPosition().pos[2];
|
||||||
|
|
||||||
|
if(mTimer > 0.25)
|
||||||
|
{
|
||||||
|
ESM::Pathgrid::Point lastPos = mPathFinder.getPath().back();
|
||||||
|
|
||||||
|
if((dest.mX - lastPos.mX)*(dest.mX - lastPos.mX)
|
||||||
|
+(dest.mY - lastPos.mY)*(dest.mY - lastPos.mY)
|
||||||
|
+(dest.mZ - lastPos.mZ)*(dest.mZ - lastPos.mZ)
|
||||||
|
> 100*100)
|
||||||
|
mPathFinder.getPath().push_back(dest);
|
||||||
|
|
||||||
|
mTimer = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ESM::Position pos = actor.getRefData().getPosition();
|
||||||
|
float zAngle = mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]);
|
||||||
|
MWBase::Environment::get().getWorld()->rotateObject(actor, 0, 0, zAngle, false);
|
||||||
|
|
||||||
|
if((dest.mX - pos.pos[0])*(dest.mX - pos.pos[0])+(dest.mY - pos.pos[1])*(dest.mY - pos.pos[1])+(dest.mZ - pos.pos[2])*(dest.mZ - pos.pos[2])
|
||||||
|
< 100*100)
|
||||||
|
MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 0;
|
||||||
|
else
|
||||||
|
MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 1;
|
||||||
|
|
||||||
std::cout << "AiFollow completed.\n";
|
std::cout << "AiFollow completed.\n";
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MWMechanics::AiFollow::getTypeId() const
|
int MWMechanics::AiFollow::getTypeId() const
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "aipackage.hpp"
|
#include "aipackage.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "pathfinding.hpp"
|
||||||
|
|
||||||
namespace MWMechanics
|
namespace MWMechanics
|
||||||
{
|
{
|
||||||
|
@ -24,6 +25,12 @@ namespace MWMechanics
|
||||||
float mZ;
|
float mZ;
|
||||||
std::string mActorId;
|
std::string mActorId;
|
||||||
std::string mCellId;
|
std::string mCellId;
|
||||||
|
|
||||||
|
float mTimer;
|
||||||
|
float mStuckTimer;
|
||||||
|
float mTotalTime;
|
||||||
|
|
||||||
|
PathFinder mPathFinder;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue