mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-20 06:23:52 +00:00
Merge remote-tracking branch 'mrcheko/master'
This commit is contained in:
commit
df7c139e2f
4 changed files with 39 additions and 12 deletions
|
@ -1,4 +1,5 @@
|
||||||
#include "aicombat.hpp"
|
#include "aicombat.hpp"
|
||||||
|
#include "aifollow.hpp"
|
||||||
|
|
||||||
#include "movement.hpp"
|
#include "movement.hpp"
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ namespace MWMechanics
|
||||||
mTimerAttack(0),
|
mTimerAttack(0),
|
||||||
mTimerReact(0),
|
mTimerReact(0),
|
||||||
mTimerCombatMove(0),
|
mTimerCombatMove(0),
|
||||||
mCloseUp(false),
|
mFollowTarget(false),
|
||||||
mReadyToAttack(false),
|
mReadyToAttack(false),
|
||||||
mStrike(false),
|
mStrike(false),
|
||||||
mCombatMove(false),
|
mCombatMove(false),
|
||||||
|
@ -182,7 +183,7 @@ namespace MWMechanics
|
||||||
Ogre::Vector3 vDir = vDest - vStart;
|
Ogre::Vector3 vDir = vDest - vStart;
|
||||||
float distBetween = vDir.length();
|
float distBetween = vDir.length();
|
||||||
|
|
||||||
if(distBetween < rangeMelee || (distBetween <= rangeCloseUp && mCloseUp) )
|
if(distBetween < rangeMelee || (distBetween <= rangeCloseUp && mFollowTarget) )
|
||||||
{
|
{
|
||||||
//Melee and Close-up combat
|
//Melee and Close-up combat
|
||||||
vDir.z = 0;
|
vDir.z = 0;
|
||||||
|
@ -192,13 +193,10 @@ namespace MWMechanics
|
||||||
// TODO: use movement settings instead of rotating directly
|
// TODO: use movement settings instead of rotating directly
|
||||||
MWBase::Environment::get().getWorld()->rotateObject(actor, 0, 0, zAngle, false);
|
MWBase::Environment::get().getWorld()->rotateObject(actor, 0, 0, zAngle, false);
|
||||||
|
|
||||||
if(mPathFinder.isPathConstructed())
|
|
||||||
mPathFinder.clearPath();
|
|
||||||
|
|
||||||
//MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 0;
|
//MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 0;
|
||||||
|
|
||||||
//bool LOS = MWBase::Environment::get().getWorld()->getLOS(actor, mTarget);
|
//bool LOS = MWBase::Environment::get().getWorld()->getLOS(actor, mTarget);
|
||||||
if (mCloseUp && distBetween > rangeMelee)
|
if (mFollowTarget && distBetween > rangeMelee)
|
||||||
{
|
{
|
||||||
//Close-up combat: just run up on target
|
//Close-up combat: just run up on target
|
||||||
mMovement.mPosition[1] = 1;
|
mMovement.mPosition[1] = 1;
|
||||||
|
@ -214,7 +212,7 @@ namespace MWMechanics
|
||||||
mTimerCombatMove = 0.1f + 0.1f * static_cast<float>(rand())/RAND_MAX;
|
mTimerCombatMove = 0.1f + 0.1f * static_cast<float>(rand())/RAND_MAX;
|
||||||
mCombatMove = true;
|
mCombatMove = true;
|
||||||
}
|
}
|
||||||
else if(!distantCombat || (distantCombat && rangeMelee/5))
|
else if(actor.getClass().isNpc() && (!distantCombat || (distantCombat && rangeMelee/5)))
|
||||||
{
|
{
|
||||||
//apply sideway movement (kind of dodging) with some probability
|
//apply sideway movement (kind of dodging) with some probability
|
||||||
if(static_cast<float>(rand())/RAND_MAX < 0.25)
|
if(static_cast<float>(rand())/RAND_MAX < 0.25)
|
||||||
|
@ -232,13 +230,19 @@ namespace MWMechanics
|
||||||
|
|
||||||
mReadyToAttack = true;
|
mReadyToAttack = true;
|
||||||
//only once got in melee combat, actor is allowed to use close-up shortcutting
|
//only once got in melee combat, actor is allowed to use close-up shortcutting
|
||||||
mCloseUp = true;
|
mFollowTarget = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//target is at far distance: build & follow the path
|
//target is at far distance: build path to target OR follow target (if previously actor had reached it once)
|
||||||
mCloseUp = false;
|
|
||||||
|
/*
|
||||||
|
//apply when AIFOLLOW package implementation will be existent
|
||||||
|
if(mFollowTarget)
|
||||||
|
actor.getClass().getCreatureStats(actor).getAiSequence().stack(AiFollow(mTarget));*/
|
||||||
|
|
||||||
|
mFollowTarget = false;
|
||||||
|
|
||||||
buildNewPath(actor);
|
buildNewPath(actor);
|
||||||
|
|
||||||
|
@ -340,7 +344,8 @@ namespace MWMechanics
|
||||||
//maybe here is a mistake (?): PathFinder::getPathSize() returns number of grid points in the path,
|
//maybe here is a mistake (?): PathFinder::getPathSize() returns number of grid points in the path,
|
||||||
//not the actual path length. Here we should know if the new path is actually more effective.
|
//not the actual path length. Here we should know if the new path is actually more effective.
|
||||||
//if(pathFinder2.getPathSize() < mPathFinder.getPathSize())
|
//if(pathFinder2.getPathSize() < mPathFinder.getPathSize())
|
||||||
mPathFinder = newPathFinder;
|
newPathFinder.syncStart(mPathFinder.getPath());
|
||||||
|
mPathFinder = newPathFinder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ namespace MWMechanics
|
||||||
float mTimerCombatMove;
|
float mTimerCombatMove;
|
||||||
|
|
||||||
bool mReadyToAttack, mStrike;
|
bool mReadyToAttack, mStrike;
|
||||||
bool mCloseUp;
|
bool mFollowTarget;
|
||||||
bool mCombatMove;
|
bool mCombatMove;
|
||||||
|
|
||||||
MWMechanics::Movement mMovement;
|
MWMechanics::Movement mMovement;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
|
|
||||||
#include "OgreMath.h"
|
#include "OgreMath.h"
|
||||||
|
#include "OgreVector3.h"
|
||||||
|
|
||||||
#include <boost/graph/dijkstra_shortest_paths.hpp>
|
#include <boost/graph/dijkstra_shortest_paths.hpp>
|
||||||
#include <boost/graph/adjacency_list.hpp>
|
#include <boost/graph/adjacency_list.hpp>
|
||||||
|
@ -233,5 +234,21 @@ namespace MWMechanics
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PathFinder::syncStart(const std::list<ESM::Pathgrid::Point> &path)
|
||||||
|
{
|
||||||
|
std::list<ESM::Pathgrid::Point>::const_iterator oldStart = path.begin();
|
||||||
|
std::list<ESM::Pathgrid::Point>::iterator iter = ++mPath.begin();
|
||||||
|
|
||||||
|
if( (*iter).mX == oldStart->mX
|
||||||
|
&& (*iter).mY == oldStart->mY
|
||||||
|
&& (*iter).mZ == oldStart->mZ
|
||||||
|
&& (*iter).mAutogenerated == oldStart->mAutogenerated
|
||||||
|
&& (*iter).mConnectionNum == oldStart->mConnectionNum )
|
||||||
|
{
|
||||||
|
mPath.pop_front();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,11 @@ namespace MWMechanics
|
||||||
return mPath;
|
return mPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//When first point of newly created path is the nearest to actor point, then
|
||||||
|
//the cituation can occure when this point is undesirable (if the 2nd point of new path == the 1st point of old path)
|
||||||
|
//This functions deletes that point.
|
||||||
|
void syncStart(const std::list<ESM::Pathgrid::Point> &path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::list<ESM::Pathgrid::Point> mPath;
|
std::list<ESM::Pathgrid::Point> mPath;
|
||||||
bool mIsPathConstructed;
|
bool mIsPathConstructed;
|
||||||
|
|
Loading…
Reference in a new issue