1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-27 12:35:46 +00:00

Manually re-added AiCombat portion of actorid changes. This is the only one that really matters, and will not suffer from the infinite recursion because it's not included in AiSequence::fill.

This commit is contained in:
scrawl 2014-05-16 12:20:36 +02:00
parent 36d9ae17cc
commit 18852c09d0
2 changed files with 20 additions and 15 deletions

View File

@ -81,7 +81,7 @@ namespace MWMechanics
// NOTE: MIN_DIST_TO_DOOR_SQUARED is defined in obstacle.hpp // NOTE: MIN_DIST_TO_DOOR_SQUARED is defined in obstacle.hpp
AiCombat::AiCombat(const MWWorld::Ptr& actor) : AiCombat::AiCombat(const MWWorld::Ptr& actor) :
mTarget(actor), mTargetActorId(actor.getClass().getCreatureStats(actor).getActorId()),
mTimerAttack(0), mTimerAttack(0),
mTimerReact(0), mTimerReact(0),
mTimerCombatMove(0), mTimerCombatMove(0),
@ -153,7 +153,9 @@ namespace MWMechanics
|| actor.getClass().getCreatureStats(actor).getHealth().getCurrent() <= 0) || actor.getClass().getCreatureStats(actor).getHealth().getCurrent() <= 0)
return true; return true;
if(mTarget.getClass().getCreatureStats(mTarget).isDead()) MWWorld::Ptr target = MWBase::Environment::get().getWorld()->searchPtrViaActorId(mTargetActorId);
if(target.getClass().getCreatureStats(target).isDead())
return true; return true;
//Update every frame //Update every frame
@ -325,7 +327,7 @@ namespace MWMechanics
ESM::Position pos = actor.getRefData().getPosition(); ESM::Position pos = actor.getRefData().getPosition();
Ogre::Vector3 vActorPos(pos.pos); Ogre::Vector3 vActorPos(pos.pos);
Ogre::Vector3 vTargetPos(mTarget.getRefData().getPosition().pos); Ogre::Vector3 vTargetPos(target.getRefData().getPosition().pos);
Ogre::Vector3 vDirToTarget = vTargetPos - vActorPos; Ogre::Vector3 vDirToTarget = vTargetPos - vActorPos;
bool isStuck = false; bool isStuck = false;
@ -396,7 +398,7 @@ namespace MWMechanics
else // remote pathfinding else // remote pathfinding
{ {
bool preferShortcut = false; bool preferShortcut = false;
bool inLOS = MWBase::Environment::get().getWorld()->getLOS(actor, mTarget); bool inLOS = MWBase::Environment::get().getWorld()->getLOS(actor, target);
if(mReadyToAttack) isStuck = false; if(mReadyToAttack) isStuck = false;
@ -432,7 +434,7 @@ namespace MWMechanics
mFollowTarget = false; mFollowTarget = false;
buildNewPath(actor); //may fail to build a path, check before use buildNewPath(actor, target); //may fail to build a path, check before use
//delete visited path node //delete visited path node
mPathFinder.checkWaypoint(pos.pos[0],pos.pos[1],pos.pos[2]); mPathFinder.checkWaypoint(pos.pos[0],pos.pos[1],pos.pos[2]);
@ -476,9 +478,9 @@ namespace MWMechanics
//less than in time of playing weapon anim from 'start' to 'hit' tags (t_swing) //less than in time of playing weapon anim from 'start' to 'hit' tags (t_swing)
//then start attacking //then start attacking
float speed1 = actorCls.getSpeed(actor); float speed1 = actorCls.getSpeed(actor);
float speed2 = mTarget.getClass().getSpeed(mTarget); float speed2 = target.getClass().getSpeed(target);
if(mTarget.getClass().getMovementSettings(mTarget).mPosition[0] == 0 if(target.getClass().getMovementSettings(target).mPosition[0] == 0
&& mTarget.getClass().getMovementSettings(mTarget).mPosition[1] == 0) && target.getClass().getMovementSettings(target).mPosition[1] == 0)
speed2 = 0; speed2 = 0;
float s1 = distToTarget - weapRange; float s1 = distToTarget - weapRange;
@ -570,9 +572,9 @@ namespace MWMechanics
return false; return false;
} }
void AiCombat::buildNewPath(const MWWorld::Ptr& actor) void AiCombat::buildNewPath(const MWWorld::Ptr& actor, const MWWorld::Ptr& target)
{ {
Ogre::Vector3 newPathTarget = Ogre::Vector3(mTarget.getRefData().getPosition().pos); Ogre::Vector3 newPathTarget = Ogre::Vector3(target.getRefData().getPosition().pos);
float dist; float dist;
@ -627,9 +629,12 @@ namespace MWMechanics
return 1; return 1;
} }
const std::string &AiCombat::getTargetId() const std::string AiCombat::getTargetId() const
{ {
return mTarget.getRefData().getHandle(); MWWorld::Ptr target = MWBase::Environment::get().getWorld()->searchPtrViaActorId(mTargetActorId);
if (target.isEmpty())
return "";
return target.getRefData().getHandle();
} }

View File

@ -31,7 +31,7 @@ namespace MWMechanics
virtual unsigned int getPriority() const; virtual unsigned int getPriority() const;
///Returns target ID ///Returns target ID
const std::string &getTargetId() const; std::string getTargetId() const;
private: private:
PathFinder mPathFinder; PathFinder mPathFinder;
@ -53,7 +53,7 @@ namespace MWMechanics
ESM::Position mLastPos; ESM::Position mLastPos;
MWMechanics::Movement mMovement; MWMechanics::Movement mMovement;
MWWorld::Ptr mTarget; int mTargetActorId;
const MWWorld::CellStore* mCell; const MWWorld::CellStore* mCell;
ObstacleCheck mObstacleCheck; ObstacleCheck mObstacleCheck;
@ -63,7 +63,7 @@ namespace MWMechanics
MWWorld::CellRefList<ESM::Door>::List::iterator mDoorIter; MWWorld::CellRefList<ESM::Door>::List::iterator mDoorIter;
MWWorld::CellRefList<ESM::Door>& mDoors; MWWorld::CellRefList<ESM::Door>& mDoors;
void buildNewPath(const MWWorld::Ptr& actor); void buildNewPath(const MWWorld::Ptr& actor, const MWWorld::Ptr& target);
}; };
} }