forked from mirror/openmw-tes3mp
Implement Command creature/humanoid magic effects (Fixes #1120)
This commit is contained in:
parent
0f8a10f468
commit
22d7d8a466
7 changed files with 91 additions and 6 deletions
|
@ -89,6 +89,58 @@ bool disintegrateSlot (MWWorld::Ptr ptr, int slot, float disintegrate)
|
|||
return false;
|
||||
}
|
||||
|
||||
class CheckActorCommanded : public MWMechanics::EffectSourceVisitor
|
||||
{
|
||||
MWWorld::Ptr mActor;
|
||||
public:
|
||||
bool mCommanded;
|
||||
CheckActorCommanded(MWWorld::Ptr actor)
|
||||
: mActor(actor)
|
||||
, mCommanded(false){}
|
||||
|
||||
virtual void visit (MWMechanics::EffectKey key,
|
||||
const std::string& sourceName, int casterActorId,
|
||||
float magnitude, float remainingTime = -1)
|
||||
{
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||
if ( ((key.mId == ESM::MagicEffect::CommandHumanoid && mActor.getClass().isNpc())
|
||||
|| (key.mId == ESM::MagicEffect::CommandCreature && mActor.getTypeName() == typeid(ESM::Creature).name()))
|
||||
&& casterActorId == player.getClass().getCreatureStats(player).getActorId()
|
||||
&& magnitude >= mActor.getClass().getCreatureStats(mActor).getLevel())
|
||||
mCommanded = true;
|
||||
}
|
||||
};
|
||||
|
||||
void adjustCommandedActor (const MWWorld::Ptr& actor)
|
||||
{
|
||||
CheckActorCommanded check(actor);
|
||||
MWMechanics::CreatureStats& stats = actor.getClass().getCreatureStats(actor);
|
||||
stats.getActiveSpells().visitEffectSources(check);
|
||||
|
||||
bool hasCommandPackage = false;
|
||||
|
||||
std::list<MWMechanics::AiPackage*>::const_iterator it;
|
||||
for (it = stats.getAiSequence().begin(); it != stats.getAiSequence().end(); ++it)
|
||||
{
|
||||
if ((*it)->getTypeId() == MWMechanics::AiPackage::TypeIdFollow &&
|
||||
dynamic_cast<MWMechanics::AiFollow*>(*it)->isCommanded())
|
||||
{
|
||||
hasCommandPackage = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (check.mCommanded && !hasCommandPackage)
|
||||
{
|
||||
MWMechanics::AiFollow package("player", true);
|
||||
stats.getAiSequence().stack(package, actor);
|
||||
}
|
||||
else if (!check.mCommanded && hasCommandPackage)
|
||||
{
|
||||
stats.getAiSequence().erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void getRestorationPerHourOfSleep (const MWWorld::Ptr& ptr, float& health, float& magicka)
|
||||
{
|
||||
MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats (ptr);
|
||||
|
@ -1006,6 +1058,9 @@ namespace MWMechanics
|
|||
{
|
||||
if (timerUpdateAITargets == 0)
|
||||
{
|
||||
if (iter->first != player)
|
||||
adjustCommandedActor(iter->first);
|
||||
|
||||
for(PtrControllerMap::iterator it(mActors.begin()); it != mActors.end(); ++it)
|
||||
{
|
||||
if (it->first == iter->first || iter->first == player) // player is not AI-controlled
|
||||
|
|
|
@ -16,16 +16,16 @@
|
|||
#include "steering.hpp"
|
||||
|
||||
MWMechanics::AiFollow::AiFollow(const std::string &actorId,float duration, float x, float y, float z)
|
||||
: mAlwaysFollow(false), mRemainingDuration(duration), mX(x), mY(y), mZ(z), mActorId(actorId), mCellId("")
|
||||
: mAlwaysFollow(false), mCommanded(false), mRemainingDuration(duration), mX(x), mY(y), mZ(z), mActorId(actorId), mCellId("")
|
||||
{
|
||||
}
|
||||
MWMechanics::AiFollow::AiFollow(const std::string &actorId,const std::string &cellId,float duration, float x, float y, float z)
|
||||
: mAlwaysFollow(false), mRemainingDuration(duration), mX(x), mY(y), mZ(z), mActorId(actorId), mCellId(cellId)
|
||||
: mAlwaysFollow(false), mCommanded(false), mRemainingDuration(duration), mX(x), mY(y), mZ(z), mActorId(actorId), mCellId(cellId)
|
||||
{
|
||||
}
|
||||
|
||||
MWMechanics::AiFollow::AiFollow(const std::string &actorId)
|
||||
: mAlwaysFollow(true), mRemainingDuration(0), mX(0), mY(0), mZ(0), mActorId(actorId), mCellId("")
|
||||
MWMechanics::AiFollow::AiFollow(const std::string &actorId, bool commanded)
|
||||
: mAlwaysFollow(true), mCommanded(commanded), mRemainingDuration(0), mX(0), mY(0), mZ(0), mActorId(actorId), mCellId("")
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -99,6 +99,11 @@ int MWMechanics::AiFollow::getTypeId() const
|
|||
return TypeIdFollow;
|
||||
}
|
||||
|
||||
bool MWMechanics::AiFollow::isCommanded() const
|
||||
{
|
||||
return mCommanded;
|
||||
}
|
||||
|
||||
void MWMechanics::AiFollow::writeState(ESM::AiSequence::AiSequence &sequence) const
|
||||
{
|
||||
std::auto_ptr<ESM::AiSequence::AiFollow> follow(new ESM::AiSequence::AiFollow());
|
||||
|
@ -109,6 +114,7 @@ void MWMechanics::AiFollow::writeState(ESM::AiSequence::AiSequence &sequence) co
|
|||
follow->mRemainingDuration = mRemainingDuration;
|
||||
follow->mCellId = mCellId;
|
||||
follow->mAlwaysFollow = mAlwaysFollow;
|
||||
follow->mCommanded = mCommanded;
|
||||
|
||||
ESM::AiSequence::AiPackageContainer package;
|
||||
package.mType = ESM::AiSequence::Ai_Follow;
|
||||
|
@ -120,6 +126,7 @@ MWMechanics::AiFollow::AiFollow(const ESM::AiSequence::AiFollow *follow)
|
|||
: mAlwaysFollow(follow->mAlwaysFollow), mRemainingDuration(follow->mRemainingDuration)
|
||||
, mX(follow->mData.mX), mY(follow->mData.mY), mZ(follow->mData.mZ)
|
||||
, mActorId(follow->mTargetId), mCellId(follow->mCellId)
|
||||
, mCommanded(follow->mCommanded)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace MWMechanics
|
|||
/// Follow Actor for duration or until you arrive at a position in a cell
|
||||
AiFollow(const std::string &ActorId,const std::string &CellId,float duration, float X, float Y, float Z);
|
||||
/// Follow Actor indefinitively
|
||||
AiFollow(const std::string &ActorId);
|
||||
AiFollow(const std::string &ActorId, bool commanded=false);
|
||||
|
||||
AiFollow(const ESM::AiSequence::AiFollow* follow);
|
||||
|
||||
|
@ -44,10 +44,13 @@ namespace MWMechanics
|
|||
|
||||
virtual void writeState (ESM::AiSequence::AiSequence& sequence) const;
|
||||
|
||||
bool isCommanded() const;
|
||||
|
||||
private:
|
||||
/// This will make the actor always follow.
|
||||
/** Thus ignoring mDuration and mX,mY,mZ (used for summoned creatures). **/
|
||||
bool mAlwaysFollow;
|
||||
bool mCommanded;
|
||||
float mRemainingDuration; // Seconds
|
||||
float mX;
|
||||
float mY;
|
||||
|
|
|
@ -82,6 +82,20 @@ std::list<AiPackage*>::const_iterator AiSequence::end() const
|
|||
return mPackages.end();
|
||||
}
|
||||
|
||||
void AiSequence::erase(std::list<AiPackage*>::const_iterator package)
|
||||
{
|
||||
// Not sure if manually terminated packages should trigger mDone, probably not?
|
||||
for(std::list<AiPackage*>::iterator it = mPackages.begin(); it != mPackages.end(); ++it)
|
||||
{
|
||||
if (package == it)
|
||||
{
|
||||
mPackages.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw std::runtime_error("can't find package to erase");
|
||||
}
|
||||
|
||||
bool AiSequence::isInCombat() const
|
||||
{
|
||||
for(std::list<AiPackage*>::const_iterator it = mPackages.begin(); it != mPackages.end(); ++it)
|
||||
|
|
|
@ -54,6 +54,8 @@ namespace MWMechanics
|
|||
std::list<AiPackage*>::const_iterator begin() const;
|
||||
std::list<AiPackage*>::const_iterator end() const;
|
||||
|
||||
void erase (std::list<AiPackage*>::const_iterator package);
|
||||
|
||||
/// Returns currently executing AiPackage type
|
||||
/** \see enum AiPackage::TypeId **/
|
||||
int getTypeId() const;
|
||||
|
|
|
@ -58,6 +58,8 @@ namespace AiSequence
|
|||
esm.getHNT (mRemainingDuration, "DURA");
|
||||
mCellId = esm.getHNOString ("CELL");
|
||||
esm.getHNT (mAlwaysFollow, "ALWY");
|
||||
mCommanded = false;
|
||||
esm.getHNOT (mCommanded, "CMND");
|
||||
}
|
||||
|
||||
void AiFollow::save(ESMWriter &esm) const
|
||||
|
@ -68,6 +70,7 @@ namespace AiSequence
|
|||
if (!mCellId.empty())
|
||||
esm.writeHNString ("CELL", mCellId);
|
||||
esm.writeHNT ("ALWY", mAlwaysFollow);
|
||||
esm.writeHNT ("CMND", mCommanded);
|
||||
}
|
||||
|
||||
void AiActivate::load(ESMReader &esm)
|
||||
|
|
|
@ -96,6 +96,7 @@ namespace ESM
|
|||
float mRemainingDuration;
|
||||
|
||||
bool mAlwaysFollow;
|
||||
bool mCommanded;
|
||||
|
||||
void load(ESMReader &esm);
|
||||
void save(ESMWriter &esm) const;
|
||||
|
|
Loading…
Reference in a new issue