better timer

This commit is contained in:
gus 2013-10-30 20:42:50 +01:00
parent a6e7c6c104
commit 650a112e2e
16 changed files with 30 additions and 26 deletions

View file

@ -35,7 +35,7 @@ namespace MWMechanics
if(!MWBase::Environment::get().getWindowManager()->isGuiMode())
{
CreatureStats& creatureStats = MWWorld::Class::get (ptr).getCreatureStats (ptr);
creatureStats.getAiSequence().execute (ptr);
creatureStats.getAiSequence().execute (ptr,duration);
}
}

View file

@ -9,7 +9,7 @@ MWMechanics::AiActivate *MWMechanics::AiActivate::clone() const
{
return new AiActivate(*this);
}
bool MWMechanics::AiActivate::execute (const MWWorld::Ptr& actor)
bool MWMechanics::AiActivate::execute (const MWWorld::Ptr& actor,float duration)
{
std::cout << "AiActivate completed.\n";
return true;

View file

@ -12,7 +12,7 @@ namespace MWMechanics
public:
AiActivate(const std::string &objectId);
virtual AiActivate *clone() const;
virtual bool execute (const MWWorld::Ptr& actor);
virtual bool execute (const MWWorld::Ptr& actor,float duration);
///< \return Package completed?
virtual int getTypeId() const;

View file

@ -25,11 +25,11 @@ namespace MWMechanics
{
AiCombat::AiCombat(const std::string &targetId)
:mTargetId(targetId),mStartingSecond(0)
:mTargetId(targetId),mTimer(0)
{
}
bool AiCombat::execute (const MWWorld::Ptr& actor)
bool AiCombat::execute (const MWWorld::Ptr& actor,float duration)
{
const MWWorld::Ptr target = MWBase::Environment::get().getWorld()->getPtr(mTargetId, false);
@ -97,18 +97,22 @@ namespace MWMechanics
MWBase::Environment::get().getWorld()->rotateObject(actor, 0, 0, zAngle, false);
mPathFinder.clearPath();
MWWorld::TimeStamp time = MWBase::Environment::get().getWorld()->getTimeStamp();
if(mStartingSecond == 0)
if(mTimer == 0)
{
MWWorld::Class::get(actor).getCreatureStats(actor).setAttackingOrSpell(false);
mStartingSecond = ((time.getHour() - int(time.getHour())) * 100);
//mTimer = mTimer + duration;
}
else if( ((time.getHour() - int(time.getHour())) * 100) - mStartingSecond > 1)
if( mTimer > 1)
{
MWWorld::Class::get(actor).getCreatureStats(actor).setAttackingOrSpell(true);
mStartingSecond = 0;
mTimer = 0;
}
else
{
mTimer = mTimer + duration;
}
MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 0;
//MWWorld::Class::get(actor).getCreatureStats(actor).setAttackingOrSpell(!MWWorld::Class::get(actor).getCreatureStats(actor).getAttackingOrSpell());
}

View file

@ -24,7 +24,7 @@ namespace MWMechanics
virtual AiCombat *clone() const;
virtual bool execute (const MWWorld::Ptr& actor);
virtual bool execute (const MWWorld::Ptr& actor,float duration);
///< \return Package completed?
virtual int getTypeId() const;
@ -34,7 +34,7 @@ namespace MWMechanics
PathFinder mPathFinder;
PathFinder mPathFinder2;
unsigned int mStartingSecond;
float mTimer;
};
}

View file

@ -71,7 +71,7 @@ namespace MWMechanics
return new AiEscort(*this);
}
bool AiEscort::execute (const MWWorld::Ptr& actor)
bool AiEscort::execute (const MWWorld::Ptr& actor,float duration)
{
// If AiEscort has ran for as long or longer then the duration specified
// and the duration is not infinite, the package is complete.

View file

@ -18,7 +18,7 @@ namespace MWMechanics
virtual AiEscort *clone() const;
virtual bool execute (const MWWorld::Ptr& actor);
virtual bool execute (const MWWorld::Ptr& actor,float duration);
///< \return Package completed?
virtual int getTypeId() const;

View file

@ -15,7 +15,7 @@ MWMechanics::AiFollow *MWMechanics::AiFollow::clone() const
return new AiFollow(*this);
}
bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor)
bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration)
{
std::cout << "AiFollow completed.\n";
return true;

View file

@ -13,7 +13,7 @@ namespace MWMechanics
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);
virtual AiFollow *clone() const;
virtual bool execute (const MWWorld::Ptr& actor);
virtual bool execute (const MWWorld::Ptr& actor,float duration);
///< \return Package completed?
virtual int getTypeId() const;

View file

@ -17,7 +17,7 @@ namespace MWMechanics
virtual AiPackage *clone() const = 0;
virtual bool execute (const MWWorld::Ptr& actor) = 0;
virtual bool execute (const MWWorld::Ptr& actor,float duration) = 0;
///< \return Package completed?
virtual int getTypeId() const = 0;

View file

@ -65,13 +65,13 @@ bool MWMechanics::AiSequence::isPackageDone() const
return mDone;
}
void MWMechanics::AiSequence::execute (const MWWorld::Ptr& actor)
void MWMechanics::AiSequence::execute (const MWWorld::Ptr& actor,float duration)
{
if(actor != MWBase::Environment::get().getWorld()->getPlayer().getPlayer())
{
if(mCombat)
{
mCombatPackage->execute(actor);
mCombatPackage->execute(actor,duration);
}
else
{
@ -103,7 +103,7 @@ void MWMechanics::AiSequence::execute (const MWWorld::Ptr& actor)
}
if (!mPackages.empty())
{
if (mPackages.front()->execute (actor))
if (mPackages.front()->execute (actor,duration))
{
mPackages.erase (mPackages.begin());
mDone = true;

View file

@ -41,7 +41,7 @@ namespace MWMechanics
bool isPackageDone() const;
///< Has a package been completed during the last update?
void execute (const MWWorld::Ptr& actor);
void execute (const MWWorld::Ptr& actor,float duration);
///< Execute package.
void clear();

View file

@ -31,7 +31,7 @@ namespace MWMechanics
return new AiTravel(*this);
}
bool AiTravel::execute (const MWWorld::Ptr& actor)
bool AiTravel::execute (const MWWorld::Ptr& actor,float duration)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
ESM::Position pos = actor.getRefData().getPosition();

View file

@ -13,7 +13,7 @@ namespace MWMechanics
AiTravel(float x, float y, float z);
virtual AiTravel *clone() const;
virtual bool execute (const MWWorld::Ptr& actor);
virtual bool execute (const MWWorld::Ptr& actor,float duration);
///< \return Package completed?
virtual int getTypeId() const;

View file

@ -63,7 +63,7 @@ namespace MWMechanics
return new AiWander(*this);
}
bool AiWander::execute (const MWWorld::Ptr& actor)
bool AiWander::execute (const MWWorld::Ptr& actor,float duration)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
if(mDuration)

View file

@ -16,7 +16,7 @@ namespace MWMechanics
AiWander(int distance, int duration, int timeOfDay, const std::vector<int>& idle, bool repeat);
virtual AiPackage *clone() const;
virtual bool execute (const MWWorld::Ptr& actor);
virtual bool execute (const MWWorld::Ptr& actor,float duration);
///< \return Package completed?
virtual int getTypeId() const;
///< 0: Wander