mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-13 12:40:04 +00:00
Load repeat flag and use reset argument
This commit is contained in:
parent
c5de69f9c6
commit
231da19aa4
@ -13,8 +13,8 @@
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
AiActivate::AiActivate(const std::string &objectId)
|
||||
: mObjectId(objectId)
|
||||
AiActivate::AiActivate(const std::string &objectId, bool repeat)
|
||||
: TypedAiPackage<AiActivate>(repeat), mObjectId(objectId)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ namespace MWMechanics
|
||||
public:
|
||||
/// Constructor
|
||||
/** \param objectId Reference to object to activate **/
|
||||
explicit AiActivate(const std::string &objectId);
|
||||
explicit AiActivate(const std::string &objectId, bool repeat);
|
||||
|
||||
explicit AiActivate(const ESM::AiSequence::AiActivate* activate);
|
||||
|
||||
|
@ -20,16 +20,16 @@
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
AiEscort::AiEscort(const std::string &actorId, int duration, float x, float y, float z)
|
||||
: mX(x), mY(y), mZ(z), mDuration(duration), mRemainingDuration(static_cast<float>(duration))
|
||||
AiEscort::AiEscort(const std::string &actorId, int duration, float x, float y, float z, bool repeat)
|
||||
: TypedAiPackage<AiEscort>(repeat), mX(x), mY(y), mZ(z), mDuration(duration), mRemainingDuration(static_cast<float>(duration))
|
||||
, mCellX(std::numeric_limits<int>::max())
|
||||
, mCellY(std::numeric_limits<int>::max())
|
||||
{
|
||||
mTargetActorRefId = actorId;
|
||||
}
|
||||
|
||||
AiEscort::AiEscort(const std::string &actorId, const std::string &cellId, int duration, float x, float y, float z)
|
||||
: mCellId(cellId), mX(x), mY(y), mZ(z), mDuration(duration), mRemainingDuration(static_cast<float>(duration))
|
||||
AiEscort::AiEscort(const std::string &actorId, const std::string &cellId, int duration, float x, float y, float z, bool repeat)
|
||||
: TypedAiPackage<AiEscort>(repeat), mCellId(cellId), mX(x), mY(y), mZ(z), mDuration(duration), mRemainingDuration(static_cast<float>(duration))
|
||||
, mCellX(std::numeric_limits<int>::max())
|
||||
, mCellY(std::numeric_limits<int>::max())
|
||||
{
|
||||
|
@ -22,11 +22,11 @@ namespace MWMechanics
|
||||
/// Implementation of AiEscort
|
||||
/** The Actor will escort the specified actor to the world position x, y, z until they reach their position, or they run out of time
|
||||
\implement AiEscort **/
|
||||
AiEscort(const std::string &actorId, int duration, float x, float y, float z);
|
||||
AiEscort(const std::string &actorId, int duration, float x, float y, float z, bool repeat);
|
||||
/// Implementation of AiEscortCell
|
||||
/** The Actor will escort the specified actor to the cell position x, y, z until they reach their position, or they run out of time
|
||||
\implement AiEscortCell **/
|
||||
AiEscort(const std::string &actorId, const std::string &cellId, int duration, float x, float y, float z);
|
||||
AiEscort(const std::string &actorId, const std::string &cellId, int duration, float x, float y, float z, bool repeat);
|
||||
|
||||
AiEscort(const ESM::AiSequence::AiEscort* escort);
|
||||
|
||||
|
@ -28,36 +28,20 @@ namespace MWMechanics
|
||||
{
|
||||
int AiFollow::mFollowIndexCounter = 0;
|
||||
|
||||
AiFollow::AiFollow(const std::string &actorId, float duration, float x, float y, float z)
|
||||
: mAlwaysFollow(false), mDuration(duration), mRemainingDuration(duration), mX(x), mY(y), mZ(z)
|
||||
AiFollow::AiFollow(const std::string &actorId, float duration, float x, float y, float z, bool repeat)
|
||||
: TypedAiPackage<AiFollow>(repeat), mAlwaysFollow(false), mDuration(duration), mRemainingDuration(duration), mX(x), mY(y), mZ(z)
|
||||
, mCellId(""), mActive(false), mFollowIndex(mFollowIndexCounter++)
|
||||
{
|
||||
mTargetActorRefId = actorId;
|
||||
}
|
||||
|
||||
AiFollow::AiFollow(const std::string &actorId, const std::string &cellId, float duration, float x, float y, float z)
|
||||
: mAlwaysFollow(false), mDuration(duration), mRemainingDuration(duration), mX(x), mY(y), mZ(z)
|
||||
AiFollow::AiFollow(const std::string &actorId, const std::string &cellId, float duration, float x, float y, float z, bool repeat)
|
||||
: TypedAiPackage<AiFollow>(repeat), mAlwaysFollow(false), mDuration(duration), mRemainingDuration(duration), mX(x), mY(y), mZ(z)
|
||||
, mCellId(cellId), mActive(false), mFollowIndex(mFollowIndexCounter++)
|
||||
{
|
||||
mTargetActorRefId = actorId;
|
||||
}
|
||||
|
||||
AiFollow::AiFollow(const MWWorld::Ptr& actor, float duration, float x, float y, float z)
|
||||
: mAlwaysFollow(false), mDuration(duration), mRemainingDuration(duration), mX(x), mY(y), mZ(z)
|
||||
, mCellId(""), mActive(false), mFollowIndex(mFollowIndexCounter++)
|
||||
{
|
||||
mTargetActorRefId = actor.getCellRef().getRefId();
|
||||
mTargetActorId = actor.getClass().getCreatureStats(actor).getActorId();
|
||||
}
|
||||
|
||||
AiFollow::AiFollow(const MWWorld::Ptr& actor, const std::string &cellId, float duration, float x, float y, float z)
|
||||
: mAlwaysFollow(false), mDuration(duration), mRemainingDuration(duration), mX(x), mY(y), mZ(z)
|
||||
, mCellId(cellId), mActive(false), mFollowIndex(mFollowIndexCounter++)
|
||||
{
|
||||
mTargetActorRefId = actor.getCellRef().getRefId();
|
||||
mTargetActorId = actor.getClass().getCreatureStats(actor).getActorId();
|
||||
}
|
||||
|
||||
AiFollow::AiFollow(const MWWorld::Ptr& actor, bool commanded)
|
||||
: TypedAiPackage<AiFollow>(makeDefaultOptions().withShouldCancelPreviousAi(!commanded))
|
||||
, mAlwaysFollow(true), mDuration(0), mRemainingDuration(0), mX(0), mY(0), mZ(0)
|
||||
|
@ -40,12 +40,10 @@ namespace MWMechanics
|
||||
class AiFollow final : public TypedAiPackage<AiFollow>
|
||||
{
|
||||
public:
|
||||
AiFollow(const std::string &actorId, float duration, float x, float y, float z);
|
||||
AiFollow(const std::string &actorId, const std::string &CellId, float duration, float x, float y, float z);
|
||||
/// Follow Actor for duration or until you arrive at a world position
|
||||
AiFollow(const MWWorld::Ptr& actor, float duration, float X, float Y, float Z);
|
||||
AiFollow(const std::string &actorId, float duration, float x, float y, float z, bool repeat);
|
||||
/// Follow Actor for duration or until you arrive at a position in a cell
|
||||
AiFollow(const MWWorld::Ptr& actor, const std::string &CellId, float duration, float X, float Y, float Z);
|
||||
AiFollow(const std::string &actorId, const std::string &CellId, float duration, float x, float y, float z, bool repeat);
|
||||
/// Follow Actor indefinitively
|
||||
AiFollow(const MWWorld::Ptr& actor, bool commanded=false);
|
||||
|
||||
|
@ -108,7 +108,7 @@ namespace MWMechanics
|
||||
/// Upon adding this Ai package, should the Ai Sequence attempt to cancel previous Ai packages (default true)?
|
||||
bool shouldCancelPreviousAi() const { return mOptions.mShouldCancelPreviousAi; }
|
||||
|
||||
/// Return true if this package should repeat. Currently only used for Wander packages.
|
||||
/// Return true if this package should repeat.
|
||||
bool getRepeat() const { return mOptions.mRepeat; }
|
||||
|
||||
virtual osg::Vec3f getDestination() const { return osg::Vec3f(0, 0, 0); }
|
||||
|
@ -31,14 +31,13 @@ void AiSequence::copy (const AiSequence& sequence)
|
||||
sequence.mAiState.copy<AiWanderStorage>(mAiState);
|
||||
}
|
||||
|
||||
AiSequence::AiSequence() : mDone (false), mRepeat(false), mLastAiPackage(AiPackageTypeId::None) {}
|
||||
AiSequence::AiSequence() : mDone (false), mLastAiPackage(AiPackageTypeId::None) {}
|
||||
|
||||
AiSequence::AiSequence (const AiSequence& sequence)
|
||||
{
|
||||
copy (sequence);
|
||||
mDone = sequence.mDone;
|
||||
mLastAiPackage = sequence.mLastAiPackage;
|
||||
mRepeat = sequence.mRepeat;
|
||||
}
|
||||
|
||||
AiSequence& AiSequence::operator= (const AiSequence& sequence)
|
||||
@ -281,7 +280,7 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac
|
||||
if (package->execute(actor, characterController, mAiState, duration))
|
||||
{
|
||||
// Put repeating noncombat AI packages on the end of the stack so they can be used again
|
||||
if (isActualAiPackage(packageTypeId) && (mRepeat || package->getRepeat()))
|
||||
if (isActualAiPackage(packageTypeId) && package->getRepeat())
|
||||
{
|
||||
package->reset();
|
||||
mPackages.push_back(package->clone());
|
||||
@ -355,7 +354,6 @@ void AiSequence::stack (const AiPackage& package, const MWWorld::Ptr& actor, boo
|
||||
else
|
||||
++it;
|
||||
}
|
||||
mRepeat=false;
|
||||
}
|
||||
|
||||
// insert new package in correct place depending on priority
|
||||
@ -401,10 +399,6 @@ const AiPackage& MWMechanics::AiSequence::getActivePackage()
|
||||
|
||||
void AiSequence::fill(const ESM::AIPackageList &list)
|
||||
{
|
||||
// If there is more than one package in the list, enable repeating
|
||||
if (list.mList.size() >= 2)
|
||||
mRepeat = true;
|
||||
|
||||
for (const auto& esmPackage : list.mList)
|
||||
{
|
||||
std::unique_ptr<MWMechanics::AiPackage> package;
|
||||
@ -420,22 +414,22 @@ void AiSequence::fill(const ESM::AIPackageList &list)
|
||||
else if (esmPackage.mType == ESM::AI_Escort)
|
||||
{
|
||||
ESM::AITarget data = esmPackage.mTarget;
|
||||
package = std::make_unique<MWMechanics::AiEscort>(data.mId.toString(), data.mDuration, data.mX, data.mY, data.mZ);
|
||||
package = std::make_unique<MWMechanics::AiEscort>(data.mId.toString(), data.mDuration, data.mX, data.mY, data.mZ, data.mShouldRepeat != 0);
|
||||
}
|
||||
else if (esmPackage.mType == ESM::AI_Travel)
|
||||
{
|
||||
ESM::AITravel data = esmPackage.mTravel;
|
||||
package = std::make_unique<MWMechanics::AiTravel>(data.mX, data.mY, data.mZ);
|
||||
package = std::make_unique<MWMechanics::AiTravel>(data.mX, data.mY, data.mZ, data.mShouldRepeat != 0);
|
||||
}
|
||||
else if (esmPackage.mType == ESM::AI_Activate)
|
||||
{
|
||||
ESM::AIActivate data = esmPackage.mActivate;
|
||||
package = std::make_unique<MWMechanics::AiActivate>(data.mName.toString());
|
||||
package = std::make_unique<MWMechanics::AiActivate>(data.mName.toString(), data.mShouldRepeat != 0);
|
||||
}
|
||||
else //if (esmPackage.mType == ESM::AI_Follow)
|
||||
{
|
||||
ESM::AITarget data = esmPackage.mTarget;
|
||||
package = std::make_unique<MWMechanics::AiFollow>(data.mId.toString(), data.mDuration, data.mX, data.mY, data.mZ);
|
||||
package = std::make_unique<MWMechanics::AiFollow>(data.mId.toString(), data.mDuration, data.mX, data.mY, data.mZ, data.mShouldRepeat != 0);
|
||||
}
|
||||
mPackages.push_back(std::move(package));
|
||||
}
|
||||
@ -454,24 +448,6 @@ void AiSequence::readState(const ESM::AiSequence::AiSequence &sequence)
|
||||
if (!sequence.mPackages.empty())
|
||||
clear();
|
||||
|
||||
// If there is more than one non-combat, non-pursue package in the list, enable repeating.
|
||||
int count = 0;
|
||||
for (auto& container : sequence.mPackages)
|
||||
{
|
||||
switch (container.mType)
|
||||
{
|
||||
case ESM::AiSequence::Ai_Wander:
|
||||
case ESM::AiSequence::Ai_Travel:
|
||||
case ESM::AiSequence::Ai_Escort:
|
||||
case ESM::AiSequence::Ai_Follow:
|
||||
case ESM::AiSequence::Ai_Activate:
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
if (count > 1)
|
||||
mRepeat = true;
|
||||
|
||||
// Load packages
|
||||
for (auto& container : sequence.mPackages)
|
||||
{
|
||||
|
@ -43,9 +43,6 @@ namespace MWMechanics
|
||||
///Finished with top AIPackage, set for one frame
|
||||
bool mDone;
|
||||
|
||||
///Does this AI sequence repeat (repeating of Wander packages handled separately)
|
||||
bool mRepeat;
|
||||
|
||||
///Copy AiSequence
|
||||
void copy (const AiSequence& sequence);
|
||||
|
||||
|
@ -34,8 +34,8 @@ bool isWithinMaxRange(const osg::Vec3f& pos1, const osg::Vec3f& pos2)
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
AiTravel::AiTravel(float x, float y, float z, AiTravel*)
|
||||
: mX(x), mY(y), mZ(z), mHidden(false)
|
||||
AiTravel::AiTravel(float x, float y, float z, bool repeat, AiTravel*)
|
||||
: TypedAiPackage<AiTravel>(repeat), mX(x), mY(y), mZ(z), mHidden(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -44,8 +44,8 @@ namespace MWMechanics
|
||||
{
|
||||
}
|
||||
|
||||
AiTravel::AiTravel(float x, float y, float z)
|
||||
: AiTravel(x, y, z, this)
|
||||
AiTravel::AiTravel(float x, float y, float z, bool repeat)
|
||||
: AiTravel(x, y, z, repeat, this)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -19,11 +19,11 @@ namespace MWMechanics
|
||||
class AiTravel : public TypedAiPackage<AiTravel>
|
||||
{
|
||||
public:
|
||||
AiTravel(float x, float y, float z, AiTravel* derived);
|
||||
AiTravel(float x, float y, float z, bool repeat, AiTravel* derived);
|
||||
|
||||
AiTravel(float x, float y, float z, AiInternalTravel* derived);
|
||||
|
||||
AiTravel(float x, float y, float z);
|
||||
AiTravel(float x, float y, float z, bool repeat);
|
||||
|
||||
explicit AiTravel(const ESM::AiSequence::AiTravel* travel);
|
||||
|
||||
|
@ -105,7 +105,7 @@ namespace MWMechanics
|
||||
}
|
||||
|
||||
AiWander::AiWander(int distance, int duration, int timeOfDay, const std::vector<unsigned char>& idle, bool repeat):
|
||||
TypedAiPackage<AiWander>(makeDefaultOptions().withRepeat(repeat)),
|
||||
TypedAiPackage<AiWander>(repeat),
|
||||
mDistance(std::max(0, distance)),
|
||||
mDuration(std::max(0, duration)),
|
||||
mRemainingDuration(duration), mTimeOfDay(timeOfDay),
|
||||
|
@ -11,6 +11,9 @@ namespace MWMechanics
|
||||
TypedAiPackage() :
|
||||
AiPackage(T::getTypeId(), T::makeDefaultOptions()) {}
|
||||
|
||||
TypedAiPackage(bool repeat) :
|
||||
AiPackage(T::getTypeId(), T::makeDefaultOptions().withRepeat(repeat)) {}
|
||||
|
||||
TypedAiPackage(const Options& options) :
|
||||
AiPackage(T::getTypeId(), options) {}
|
||||
|
||||
|
@ -48,13 +48,14 @@ namespace MWScript
|
||||
std::string objectID = runtime.getStringLiteral (runtime[0].mInteger);
|
||||
runtime.pop();
|
||||
|
||||
// discard additional arguments (reset), because we have no idea what they mean.
|
||||
// The value of the reset argument doesn't actually matter
|
||||
bool repeat = arg0;
|
||||
for (unsigned int i=0; i<arg0; ++i) runtime.pop();
|
||||
|
||||
if (!ptr.getClass().isActor() || ptr == MWMechanics::getPlayer())
|
||||
return;
|
||||
|
||||
MWMechanics::AiActivate activatePackage(objectID);
|
||||
MWMechanics::AiActivate activatePackage(objectID, repeat);
|
||||
ptr.getClass().getCreatureStats (ptr).getAiSequence().stack(activatePackage, ptr);
|
||||
Log(Debug::Info) << "AiActivate";
|
||||
}
|
||||
@ -78,13 +79,14 @@ namespace MWScript
|
||||
Interpreter::Type_Float z = runtime[0].mFloat;
|
||||
runtime.pop();
|
||||
|
||||
// discard additional arguments (reset), because we have no idea what they mean.
|
||||
// The value of the reset argument doesn't actually matter
|
||||
bool repeat = arg0;
|
||||
for (unsigned int i=0; i<arg0; ++i) runtime.pop();
|
||||
|
||||
if (!ptr.getClass().isActor() || ptr == MWMechanics::getPlayer())
|
||||
return;
|
||||
|
||||
MWMechanics::AiTravel travelPackage(x, y, z);
|
||||
MWMechanics::AiTravel travelPackage(x, y, z, repeat);
|
||||
ptr.getClass().getCreatureStats (ptr).getAiSequence().stack(travelPackage, ptr);
|
||||
|
||||
Log(Debug::Info) << "AiTravel: " << x << ", " << y << ", " << z;
|
||||
@ -115,13 +117,14 @@ namespace MWScript
|
||||
Interpreter::Type_Float z = runtime[0].mFloat;
|
||||
runtime.pop();
|
||||
|
||||
// discard additional arguments (reset), because we have no idea what they mean.
|
||||
// The value of the reset argument doesn't actually matter
|
||||
bool repeat = arg0;
|
||||
for (unsigned int i=0; i<arg0; ++i) runtime.pop();
|
||||
|
||||
if (!ptr.getClass().isActor() || ptr == MWMechanics::getPlayer())
|
||||
return;
|
||||
|
||||
MWMechanics::AiEscort escortPackage(actorID, static_cast<int>(duration), x, y, z);
|
||||
MWMechanics::AiEscort escortPackage(actorID, static_cast<int>(duration), x, y, z, repeat);
|
||||
ptr.getClass().getCreatureStats (ptr).getAiSequence().stack(escortPackage, ptr);
|
||||
|
||||
Log(Debug::Info) << "AiEscort: " << x << ", " << y << ", " << z << ", " << duration;
|
||||
@ -155,7 +158,8 @@ namespace MWScript
|
||||
Interpreter::Type_Float z = runtime[0].mFloat;
|
||||
runtime.pop();
|
||||
|
||||
// discard additional arguments (reset), because we have no idea what they mean.
|
||||
// The value of the reset argument doesn't actually matter
|
||||
bool repeat = arg0;
|
||||
for (unsigned int i=0; i<arg0; ++i) runtime.pop();
|
||||
|
||||
if (!ptr.getClass().isActor() || ptr == MWMechanics::getPlayer())
|
||||
@ -167,7 +171,7 @@ namespace MWScript
|
||||
if (!MWBase::Environment::get().getWorld()->getStore().get<ESM::Cell>().search(cellID))
|
||||
return;
|
||||
|
||||
MWMechanics::AiEscort escortPackage(actorID, cellID, static_cast<int>(duration), x, y, z);
|
||||
MWMechanics::AiEscort escortPackage(actorID, cellID, static_cast<int>(duration), x, y, z, repeat);
|
||||
ptr.getClass().getCreatureStats (ptr).getAiSequence().stack(escortPackage, ptr);
|
||||
|
||||
Log(Debug::Info) << "AiEscort: " << x << ", " << y << ", " << z << ", " << duration;
|
||||
@ -237,7 +241,7 @@ namespace MWScript
|
||||
--arg0;
|
||||
}
|
||||
|
||||
// discard additional arguments (reset), because we have no idea what they mean.
|
||||
// discard additional arguments, because we have no idea what they mean.
|
||||
for (unsigned int i=0; i<arg0; ++i) runtime.pop();
|
||||
|
||||
if (!ptr.getClass().isActor() || ptr == MWMechanics::getPlayer())
|
||||
@ -331,13 +335,14 @@ namespace MWScript
|
||||
Interpreter::Type_Float z = runtime[0].mFloat;
|
||||
runtime.pop();
|
||||
|
||||
// discard additional arguments (reset), because we have no idea what they mean.
|
||||
// The value of the reset argument doesn't actually matter
|
||||
bool repeat = arg0;
|
||||
for (unsigned int i=0; i<arg0; ++i) runtime.pop();
|
||||
|
||||
if (!ptr.getClass().isActor() || ptr == MWMechanics::getPlayer())
|
||||
return;
|
||||
|
||||
MWMechanics::AiFollow followPackage(actorID, duration, x, y ,z);
|
||||
MWMechanics::AiFollow followPackage(actorID, duration, x, y, z, repeat);
|
||||
ptr.getClass().getCreatureStats (ptr).getAiSequence().stack(followPackage, ptr);
|
||||
|
||||
Log(Debug::Info) << "AiFollow: " << actorID << ", " << x << ", " << y << ", " << z << ", " << duration;
|
||||
@ -371,13 +376,14 @@ namespace MWScript
|
||||
Interpreter::Type_Float z = runtime[0].mFloat;
|
||||
runtime.pop();
|
||||
|
||||
// discard additional arguments (reset), because we have no idea what they mean.
|
||||
// The value of the reset argument doesn't actually matter
|
||||
bool repeat = arg0;
|
||||
for (unsigned int i=0; i<arg0; ++i) runtime.pop();
|
||||
|
||||
if (!ptr.getClass().isActor() || ptr == MWMechanics::getPlayer())
|
||||
return;
|
||||
|
||||
MWMechanics::AiFollow followPackage(actorID, cellID, duration, x, y ,z);
|
||||
MWMechanics::AiFollow followPackage(actorID, cellID, duration, x, y, z, repeat);
|
||||
ptr.getClass().getCreatureStats (ptr).getAiSequence().stack(followPackage, ptr);
|
||||
Log(Debug::Info) << "AiFollow: " << actorID << ", " << x << ", " << y << ", " << z << ", " << duration;
|
||||
}
|
||||
|
@ -37,7 +37,8 @@ namespace ESM
|
||||
struct AITravel
|
||||
{
|
||||
float mX, mY, mZ;
|
||||
int mUnk;
|
||||
unsigned char mShouldRepeat;
|
||||
unsigned char mPadding[3];
|
||||
};
|
||||
|
||||
struct AITarget
|
||||
@ -45,13 +46,14 @@ namespace ESM
|
||||
float mX, mY, mZ;
|
||||
short mDuration;
|
||||
NAME32 mId;
|
||||
short mUnk;
|
||||
unsigned char mShouldRepeat;
|
||||
unsigned char mPadding;
|
||||
};
|
||||
|
||||
struct AIActivate
|
||||
{
|
||||
NAME32 mName;
|
||||
unsigned char mUnk;
|
||||
unsigned char mShouldRepeat;
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
Loading…
x
Reference in New Issue
Block a user