|
|
@ -34,9 +34,9 @@ namespace
|
|
|
|
namespace MWMechanics
|
|
|
|
namespace MWMechanics
|
|
|
|
{
|
|
|
|
{
|
|
|
|
AiCombat::AiCombat(const MWWorld::Ptr& actor) :
|
|
|
|
AiCombat::AiCombat(const MWWorld::Ptr& actor) :
|
|
|
|
mTarget(actor),
|
|
|
|
mTarget(actor),
|
|
|
|
mTimerAttack(0),
|
|
|
|
mTimerAttack(0),
|
|
|
|
mTimerReact(0),
|
|
|
|
mTimerReact(0),
|
|
|
|
mTimerCombatMove(0),
|
|
|
|
mTimerCombatMove(0),
|
|
|
|
mFollowTarget(false),
|
|
|
|
mFollowTarget(false),
|
|
|
|
mReadyToAttack(false),
|
|
|
|
mReadyToAttack(false),
|
|
|
@ -77,7 +77,7 @@ namespace MWMechanics
|
|
|
|
if (zTurn(actor, Ogre::Degree(mTargetAngle)))
|
|
|
|
if (zTurn(actor, Ogre::Degree(mTargetAngle)))
|
|
|
|
mRotate = false;
|
|
|
|
mRotate = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mTimerAttack -= duration;
|
|
|
|
mTimerAttack -= duration;
|
|
|
|
actor.getClass().getCreatureStats(actor).setAttackingOrSpell(mStrike);
|
|
|
|
actor.getClass().getCreatureStats(actor).setAttackingOrSpell(mStrike);
|
|
|
@ -105,7 +105,7 @@ namespace MWMechanics
|
|
|
|
//Also it seems that this time is different for slash/thrust/chop
|
|
|
|
//Also it seems that this time is different for slash/thrust/chop
|
|
|
|
mTimerAttack = 0.35f * static_cast<float>(rand())/RAND_MAX;
|
|
|
|
mTimerAttack = 0.35f * static_cast<float>(rand())/RAND_MAX;
|
|
|
|
mStrike = true;
|
|
|
|
mStrike = true;
|
|
|
|
|
|
|
|
|
|
|
|
//say a provoking combat phrase
|
|
|
|
//say a provoking combat phrase
|
|
|
|
if (actor.getClass().isNpc())
|
|
|
|
if (actor.getClass().isNpc())
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -126,7 +126,7 @@ namespace MWMechanics
|
|
|
|
mTimerAttack = -attackPeriod;
|
|
|
|
mTimerAttack = -attackPeriod;
|
|
|
|
mStrike = false;
|
|
|
|
mStrike = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const MWWorld::Class &cls = actor.getClass();
|
|
|
|
const MWWorld::Class &cls = actor.getClass();
|
|
|
|
const ESM::Weapon *weapon = NULL;
|
|
|
|
const ESM::Weapon *weapon = NULL;
|
|
|
|
MWMechanics::WeaponType weaptype;
|
|
|
|
MWMechanics::WeaponType weaptype;
|
|
|
@ -138,14 +138,14 @@ namespace MWMechanics
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MWMechanics::DrawState_ state = actor.getClass().getCreatureStats(actor).getDrawState();
|
|
|
|
MWMechanics::DrawState_ state = actor.getClass().getCreatureStats(actor).getDrawState();
|
|
|
|
if (state == MWMechanics::DrawState_Spell || state == MWMechanics::DrawState_Nothing)
|
|
|
|
if (state == MWMechanics::DrawState_Spell || state == MWMechanics::DrawState_Nothing)
|
|
|
|
actor.getClass().getNpcStats(actor).setDrawState(MWMechanics::DrawState_Weapon);
|
|
|
|
actor.getClass().getNpcStats(actor).setDrawState(MWMechanics::DrawState_Weapon);
|
|
|
|
|
|
|
|
|
|
|
|
//Get weapon speed and range
|
|
|
|
//Get weapon speed and range
|
|
|
|
MWWorld::ContainerStoreIterator weaponSlot =
|
|
|
|
MWWorld::ContainerStoreIterator weaponSlot =
|
|
|
|
MWMechanics::getActiveWeapon(cls.getNpcStats(actor), cls.getInventoryStore(actor), &weaptype);
|
|
|
|
MWMechanics::getActiveWeapon(cls.getNpcStats(actor), cls.getInventoryStore(actor), &weaptype);
|
|
|
|
if (weaptype == WeapType_HandToHand)
|
|
|
|
if (weaptype == WeapType_HandToHand)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const MWWorld::Store<ESM::GameSetting> &gmst =
|
|
|
|
const MWWorld::Store<ESM::GameSetting> &gmst =
|
|
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
|
|
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
|
|
|
|
weapRange = gmst.find("fHandToHandReach")->getFloat();
|
|
|
|
weapRange = gmst.find("fHandToHandReach")->getFloat();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -246,12 +246,12 @@ namespace MWMechanics
|
|
|
|
mPathFinder.checkPathCompleted(pos.pos[0],pos.pos[1],pos.pos[2]);
|
|
|
|
mPathFinder.checkPathCompleted(pos.pos[0],pos.pos[1],pos.pos[2]);
|
|
|
|
|
|
|
|
|
|
|
|
//try shortcut
|
|
|
|
//try shortcut
|
|
|
|
if(vDir.length() < mPathFinder.getDistToNext(pos.pos[0],pos.pos[1],pos.pos[2]) && MWBase::Environment::get().getWorld()->getLOS(actor, mTarget))
|
|
|
|
if(vDir.length() < mPathFinder.getDistToNext(pos.pos[0],pos.pos[1],pos.pos[2]) && MWBase::Environment::get().getWorld()->getLOS(actor, mTarget))
|
|
|
|
mTargetAngle = Ogre::Radian( Ogre::Math::ACos(vDir.y / vDir.length()) * sgn(Ogre::Math::ASin(vDir.x / vDir.length())) ).valueDegrees();
|
|
|
|
mTargetAngle = Ogre::Radian( Ogre::Math::ACos(vDir.y / vDir.length()) * sgn(Ogre::Math::ASin(vDir.x / vDir.length())) ).valueDegrees();
|
|
|
|
else
|
|
|
|
else
|
|
|
|
mTargetAngle = mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]);
|
|
|
|
mTargetAngle = mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]);
|
|
|
|
mRotate = true;
|
|
|
|
mRotate = true;
|
|
|
|
|
|
|
|
|
|
|
|
mMovement.mPosition[1] = 1;
|
|
|
|
mMovement.mPosition[1] = 1;
|
|
|
|
mReadyToAttack = false;
|
|
|
|
mReadyToAttack = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -305,13 +305,13 @@ namespace MWMechanics
|
|
|
|
float dist = Ogre::Math::Abs((newPathTarget - currPathTarget).length());
|
|
|
|
float dist = Ogre::Math::Abs((newPathTarget - currPathTarget).length());
|
|
|
|
|
|
|
|
|
|
|
|
float targetPosThreshold;
|
|
|
|
float targetPosThreshold;
|
|
|
|
bool isOutside = actor.getCell()->mCell->isExterior();
|
|
|
|
bool isOutside = actor.getCell()->getCell()->isExterior();
|
|
|
|
if (isOutside)
|
|
|
|
if (isOutside)
|
|
|
|
targetPosThreshold = 300;
|
|
|
|
targetPosThreshold = 300;
|
|
|
|
else
|
|
|
|
else
|
|
|
|
targetPosThreshold = 100;
|
|
|
|
targetPosThreshold = 100;
|
|
|
|
|
|
|
|
|
|
|
|
if(dist > targetPosThreshold)
|
|
|
|
if(dist > targetPosThreshold)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//construct new path only if target has moved away more than on <targetPosThreshold>
|
|
|
|
//construct new path only if target has moved away more than on <targetPosThreshold>
|
|
|
|
ESM::Position pos = actor.getRefData().getPosition();
|
|
|
|
ESM::Position pos = actor.getRefData().getPosition();
|
|
|
@ -328,7 +328,7 @@ namespace MWMechanics
|
|
|
|
PathFinder newPathFinder;
|
|
|
|
PathFinder newPathFinder;
|
|
|
|
newPathFinder.buildPath(start, dest, actor.getCell(), isOutside);
|
|
|
|
newPathFinder.buildPath(start, dest, actor.getCell(), isOutside);
|
|
|
|
|
|
|
|
|
|
|
|
//TO EXPLORE:
|
|
|
|
//TO EXPLORE:
|
|
|
|
//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())
|
|
|
@ -391,7 +391,7 @@ void chooseBestAttack(const ESM::Weapon* weapon, MWMechanics::Movement &movement
|
|
|
|
int thrust = (weapon->mData.mThrust[0] + weapon->mData.mThrust[1])/2;
|
|
|
|
int thrust = (weapon->mData.mThrust[0] + weapon->mData.mThrust[1])/2;
|
|
|
|
|
|
|
|
|
|
|
|
float total = slash + chop + thrust;
|
|
|
|
float total = slash + chop + thrust;
|
|
|
|
|
|
|
|
|
|
|
|
float roll = static_cast<float>(rand())/RAND_MAX;
|
|
|
|
float roll = static_cast<float>(rand())/RAND_MAX;
|
|
|
|
if(roll <= static_cast<float>(slash)/total)
|
|
|
|
if(roll <= static_cast<float>(slash)/total)
|
|
|
|
{
|
|
|
|
{
|
|
|
|