mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 22:15:32 +00:00
warning fix, vars renaming
This commit is contained in:
parent
82121e0401
commit
22cdb166f2
2 changed files with 42 additions and 49 deletions
|
@ -76,6 +76,7 @@ namespace
|
||||||
|
|
||||||
namespace MWMechanics
|
namespace MWMechanics
|
||||||
{
|
{
|
||||||
|
static const float MAX_ATTACK_DURATION = 0.35f;
|
||||||
static const float DOOR_CHECK_INTERVAL = 1.5f; // same as AiWander
|
static const float DOOR_CHECK_INTERVAL = 1.5f; // same as AiWander
|
||||||
// NOTE: MIN_DIST_TO_DOOR_SQUARED is defined in obstacle.hpp
|
// NOTE: MIN_DIST_TO_DOOR_SQUARED is defined in obstacle.hpp
|
||||||
|
|
||||||
|
@ -86,7 +87,7 @@ namespace MWMechanics
|
||||||
mTimerCombatMove(0),
|
mTimerCombatMove(0),
|
||||||
mFollowTarget(false),
|
mFollowTarget(false),
|
||||||
mReadyToAttack(false),
|
mReadyToAttack(false),
|
||||||
mStrike(false),
|
mAttack(false),
|
||||||
mCombatMove(false),
|
mCombatMove(false),
|
||||||
mMovement(),
|
mMovement(),
|
||||||
mForceNoShortcut(false),
|
mForceNoShortcut(false),
|
||||||
|
@ -182,7 +183,7 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
|
|
||||||
mTimerAttack -= duration;
|
mTimerAttack -= duration;
|
||||||
actor.getClass().getCreatureStats(actor).setAttackingOrSpell(mStrike);
|
actor.getClass().getCreatureStats(actor).setAttackingOrSpell(mAttack);
|
||||||
|
|
||||||
float tReaction = 0.25f;
|
float tReaction = 0.25f;
|
||||||
if(mTimerReact < tReaction)
|
if(mTimerReact < tReaction)
|
||||||
|
@ -203,16 +204,16 @@ namespace MWMechanics
|
||||||
|
|
||||||
//actual attacking logic
|
//actual attacking logic
|
||||||
//TODO: Some skills affect period of strikes.For berserk-like style period ~ 0.25f
|
//TODO: Some skills affect period of strikes.For berserk-like style period ~ 0.25f
|
||||||
float attackPeriod = 1.0f;
|
float attacksPeriod = 1.0f;
|
||||||
if(mReadyToAttack)
|
if(mReadyToAttack)
|
||||||
{
|
{
|
||||||
if(mTimerAttack <= -attackPeriod)
|
if(mTimerAttack <= -attacksPeriod)
|
||||||
{
|
{
|
||||||
//TODO: should depend on time between 'start' to 'min attack'
|
//TODO: should depend on time between 'start' to 'min attack'
|
||||||
//for better controlling of NPCs' attack strength.
|
//for better controlling of NPCs' attack strength.
|
||||||
//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 = MAX_ATTACK_DURATION * static_cast<float>(rand())/RAND_MAX;
|
||||||
mStrike = true;
|
mAttack = true;
|
||||||
|
|
||||||
//say a provoking combat phrase
|
//say a provoking combat phrase
|
||||||
if (actor.getClass().isNpc())
|
if (actor.getClass().isNpc())
|
||||||
|
@ -227,12 +228,12 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mTimerAttack <= 0)
|
else if (mTimerAttack <= 0)
|
||||||
mStrike = false;
|
mAttack = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mTimerAttack = -attackPeriod;
|
mTimerAttack = -attacksPeriod;
|
||||||
mStrike = false;
|
mAttack = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MWWorld::Class &actorCls = actor.getClass();
|
const MWWorld::Class &actorCls = actor.getClass();
|
||||||
|
@ -277,31 +278,23 @@ namespace MWMechanics
|
||||||
/*
|
/*
|
||||||
* Some notes on meanings of variables:
|
* Some notes on meanings of variables:
|
||||||
*
|
*
|
||||||
* rangeMelee:
|
* rangeAttack:
|
||||||
*
|
*
|
||||||
* - Distance where attack using the actor's weapon is possible
|
* - Distance where attack using the actor's weapon is possible:
|
||||||
* - longer for ranged weapons (obviously?) vs. melee weapons
|
* longer for ranged weapons (obviously?) vs. melee weapons
|
||||||
|
* - Determined by weapon's reach parameter; hardcoded value
|
||||||
|
* for ranged weapon and for creatures
|
||||||
* - Once within this distance mFollowTarget is triggered
|
* - Once within this distance mFollowTarget is triggered
|
||||||
* (TODO: check whether the follow logic still works for ranged
|
|
||||||
* weapons, since rangeCloseup is set to zero)
|
|
||||||
* - TODO: The variable name is confusing. It was ok when AiCombat only
|
|
||||||
* had melee weapons but now that ranged weapons are supported that is
|
|
||||||
* no longer the case. It should really be renamed to something
|
|
||||||
* like rangeStrike - alternatively, keep this name for melee
|
|
||||||
* weapons and use a different variable for tracking ranged weapon
|
|
||||||
* distance (rangeRanged maybe?)
|
|
||||||
*
|
*
|
||||||
* rangeCloseup:
|
* rangeFollow:
|
||||||
*
|
*
|
||||||
* - Applies to melee weapons or hand to hand only (or creatures without
|
* - Applies to melee weapons or hand to hand only (or creatures without
|
||||||
* weapons)
|
* weapons)
|
||||||
* - Distance a little further away from the actor's weapon strike
|
* - Distance a little further away than the actor's weapon reach
|
||||||
* i.e. rangeCloseup > rangeMelee for melee weapons
|
* i.e. rangeFollow > rangeAttack for melee weapons
|
||||||
* (the variable names make this simple concept counter-intuitive,
|
* - Hardcoded value (0 for ranged weapons)
|
||||||
* something like rangeMelee > rangeStrike may be better)
|
|
||||||
* - Once the target gets beyond this distance mFollowTarget is cleared
|
* - Once the target gets beyond this distance mFollowTarget is cleared
|
||||||
* and a path to the target needs to be found
|
* and a path to the target needs to be found
|
||||||
* - TODO: Possibly rename this variable to rangeMelee or even rangeFollow
|
|
||||||
*
|
*
|
||||||
* mFollowTarget:
|
* mFollowTarget:
|
||||||
*
|
*
|
||||||
|
@ -311,19 +304,19 @@ namespace MWMechanics
|
||||||
* target even if LOS is not achieved)
|
* target even if LOS is not achieved)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
float rangeMelee;
|
float rangeAttack;
|
||||||
float rangeCloseUp;
|
float rangeFollow;
|
||||||
bool distantCombat = false;
|
bool distantCombat = false;
|
||||||
if (weaptype == WeapType_BowAndArrow || weaptype == WeapType_Crossbow || weaptype == WeapType_Thrown)
|
if (weaptype == WeapType_BowAndArrow || weaptype == WeapType_Crossbow || weaptype == WeapType_Thrown)
|
||||||
{
|
{
|
||||||
rangeMelee = 1000; // TODO: should depend on archer skill
|
rangeAttack = 1000; // TODO: should depend on archer skill
|
||||||
rangeCloseUp = 0; // not needed in ranged combat
|
rangeFollow = 0; // not needed in ranged combat
|
||||||
distantCombat = true;
|
distantCombat = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rangeMelee = weapRange;
|
rangeAttack = weapRange;
|
||||||
rangeCloseUp = 300;
|
rangeFollow = 300;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESM::Position pos = actor.getRefData().getPosition();
|
ESM::Position pos = actor.getRefData().getPosition();
|
||||||
|
@ -339,42 +332,42 @@ namespace MWMechanics
|
||||||
|
|
||||||
mLastPos = pos;
|
mLastPos = pos;
|
||||||
|
|
||||||
// check if can move along z-axis
|
// check if actor can move along z-axis
|
||||||
bool canMoveByZ;
|
bool canMoveByZ = (actorCls.canSwim(actor) && MWBase::Environment::get().getWorld()->isSwimming(actor))
|
||||||
if(canMoveByZ = (actorCls.canSwim(actor) && MWBase::Environment::get().getWorld()->isSwimming(actor))
|
|| MWBase::Environment::get().getWorld()->isFlying(actor);
|
||||||
|| MWBase::Environment::get().getWorld()->isFlying(actor))
|
if(canMoveByZ)
|
||||||
{
|
{
|
||||||
// determine vertical angle to target
|
// determine vertical angle to target
|
||||||
mMovement.mRotation[0] = getXAngleToDir(vDirToTarget, distToTarget);
|
mMovement.mRotation[0] = getXAngleToDir(vDirToTarget, distToTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
// (within strike dist) || (not quite strike dist while following)
|
// (within strike dist) || (not quite strike dist while following)
|
||||||
if(distToTarget < rangeMelee || (distToTarget <= rangeCloseUp && mFollowTarget && !isStuck) )
|
if(distToTarget < rangeAttack || (distToTarget <= rangeFollow && mFollowTarget && !isStuck) )
|
||||||
{
|
{
|
||||||
//Melee and Close-up combat
|
//Melee and Close-up combat
|
||||||
vDirToTarget.z = 0;
|
vDirToTarget.z = 0;
|
||||||
mMovement.mRotation[2] = getZAngleToDir(vDirToTarget, distToTarget);
|
mMovement.mRotation[2] = getZAngleToDir(vDirToTarget, distToTarget);
|
||||||
|
|
||||||
// (not quite strike dist while following)
|
// (not quite strike dist while following)
|
||||||
if (mFollowTarget && distToTarget > rangeMelee)
|
if (mFollowTarget && distToTarget > rangeAttack)
|
||||||
{
|
{
|
||||||
//Close-up combat: just run up on target
|
//Close-up combat: just run up on target
|
||||||
mMovement.mPosition[1] = 1;
|
mMovement.mPosition[1] = 1;
|
||||||
}
|
}
|
||||||
else // (within strike dist)
|
else // (within strike dist)
|
||||||
{
|
{
|
||||||
//Melee: stop running and attack
|
|
||||||
mMovement.mPosition[1] = 0;
|
mMovement.mPosition[1] = 0;
|
||||||
|
|
||||||
// set slash/thrust/chop attack
|
// set slash/thrust/chop attack
|
||||||
if (mStrike && !distantCombat) chooseBestAttack(weapon, mMovement);
|
if (mAttack && !distantCombat) chooseBestAttack(weapon, mMovement);
|
||||||
|
|
||||||
if(mMovement.mPosition[0] || mMovement.mPosition[1])
|
if(mMovement.mPosition[0] || mMovement.mPosition[1])
|
||||||
{
|
{
|
||||||
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(actorCls.isNpc() && (!distantCombat || (distantCombat && distToTarget < rangeMelee/2)))
|
// only NPCs are smart enough to use dodge movements
|
||||||
|
else if(actorCls.isNpc() && (!distantCombat || (distantCombat && distToTarget < rangeAttack/2)))
|
||||||
{
|
{
|
||||||
//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)
|
||||||
|
@ -385,7 +378,7 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(distantCombat && distToTarget < rangeMelee/4)
|
if(distantCombat && distToTarget < rangeAttack/4)
|
||||||
{
|
{
|
||||||
mMovement.mPosition[1] = -1;
|
mMovement.mPosition[1] = -1;
|
||||||
}
|
}
|
||||||
|
@ -469,7 +462,7 @@ namespace MWMechanics
|
||||||
mReadyToAttack = false;
|
mReadyToAttack = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(distToTarget > rangeMelee && !distantCombat)
|
if(distToTarget > rangeAttack && !distantCombat)
|
||||||
{
|
{
|
||||||
//special run attack; it shouldn't affect melee combat tactics
|
//special run attack; it shouldn't affect melee combat tactics
|
||||||
if(actorCls.getMovementSettings(actor).mPosition[1] == 1)
|
if(actorCls.getMovementSettings(actor).mPosition[1] == 1)
|
||||||
|
@ -486,14 +479,14 @@ namespace MWMechanics
|
||||||
float s1 = distToTarget - weapRange;
|
float s1 = distToTarget - weapRange;
|
||||||
float t = s1/speed1;
|
float t = s1/speed1;
|
||||||
float s2 = speed2 * t;
|
float s2 = speed2 * t;
|
||||||
float t_swing = 0.17f/weapSpeed;//instead of 0.17 should be the time of playing weapon anim from 'start' to 'hit' tags
|
float t_swing = (MAX_ATTACK_DURATION/2) / weapSpeed;//instead of 0.17 should be the time of playing weapon anim from 'start' to 'hit' tags
|
||||||
if (t + s2/speed1 <= t_swing)
|
if (t + s2/speed1 <= t_swing)
|
||||||
{
|
{
|
||||||
mReadyToAttack = true;
|
mReadyToAttack = true;
|
||||||
if(mTimerAttack <= -attackPeriod)
|
if(mTimerAttack <= -attacksPeriod)
|
||||||
{
|
{
|
||||||
mTimerAttack = 0.3f*static_cast<float>(rand())/RAND_MAX;
|
mTimerAttack = MAX_ATTACK_DURATION * static_cast<float>(rand())/RAND_MAX;
|
||||||
mStrike = true;
|
mAttack = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -503,7 +496,7 @@ namespace MWMechanics
|
||||||
// coded at 250ms or 1/4 second
|
// coded at 250ms or 1/4 second
|
||||||
//
|
//
|
||||||
// TODO: Add a parameter to vary DURATION_SAME_SPOT?
|
// TODO: Add a parameter to vary DURATION_SAME_SPOT?
|
||||||
if((distToTarget > rangeMelee || mFollowTarget) &&
|
if((distToTarget > rangeAttack || mFollowTarget) &&
|
||||||
mObstacleCheck.check(actor, tReaction)) // check if evasive action needed
|
mObstacleCheck.check(actor, tReaction)) // check if evasive action needed
|
||||||
{
|
{
|
||||||
// first check if we're walking into a door
|
// first check if we're walking into a door
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace MWMechanics
|
||||||
float mTimerCombatMove;
|
float mTimerCombatMove;
|
||||||
|
|
||||||
// AiCombat states
|
// AiCombat states
|
||||||
bool mReadyToAttack, mStrike;
|
bool mReadyToAttack, mAttack;
|
||||||
bool mFollowTarget;
|
bool mFollowTarget;
|
||||||
bool mCombatMove;
|
bool mCombatMove;
|
||||||
bool mBackOffDoor;
|
bool mBackOffDoor;
|
||||||
|
|
Loading…
Reference in a new issue