2012-09-04 11:25:53 +00:00
|
|
|
#ifndef GAME_MWMECHANICS_AISEQUENCE_H
|
|
|
|
#define GAME_MWMECHANICS_AISEQUENCE_H
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
2013-07-30 22:55:08 +00:00
|
|
|
#include <components/esm/loadnpc.hpp>
|
2014-10-08 08:58:52 +00:00
|
|
|
//#include "aistate.hpp"
|
2013-07-30 22:55:08 +00:00
|
|
|
|
2012-09-04 11:25:53 +00:00
|
|
|
namespace MWWorld
|
|
|
|
{
|
|
|
|
class Ptr;
|
|
|
|
}
|
|
|
|
|
2014-06-12 21:27:04 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
namespace AiSequence
|
|
|
|
{
|
|
|
|
class AiSequence;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-10 21:28:49 +00:00
|
|
|
|
2014-10-08 08:58:52 +00:00
|
|
|
|
2012-09-04 11:25:53 +00:00
|
|
|
namespace MWMechanics
|
|
|
|
{
|
|
|
|
class AiPackage;
|
2014-10-08 08:58:52 +00:00
|
|
|
|
2014-10-10 21:28:49 +00:00
|
|
|
template< class Base > class DerivedClassStorage;
|
2014-10-14 14:10:19 +00:00
|
|
|
struct AiTemporaryBase;
|
2014-10-08 08:58:52 +00:00
|
|
|
typedef DerivedClassStorage<AiTemporaryBase> AiState;
|
2014-04-30 03:40:59 +00:00
|
|
|
|
2012-09-04 11:25:53 +00:00
|
|
|
/// \brief Sequence of AI-packages for a single actor
|
2014-05-13 18:21:59 +00:00
|
|
|
/** The top-most AI package is run each frame. When completed, it is removed from the stack. **/
|
2012-09-04 11:25:53 +00:00
|
|
|
class AiSequence
|
|
|
|
{
|
2014-04-30 03:40:59 +00:00
|
|
|
///AiPackages to run though
|
2012-09-04 11:25:53 +00:00
|
|
|
std::list<AiPackage *> mPackages;
|
2013-09-25 16:01:36 +00:00
|
|
|
|
2014-05-13 18:21:59 +00:00
|
|
|
///Finished with top AIPackage, set for one frame
|
2012-09-04 11:25:53 +00:00
|
|
|
bool mDone;
|
|
|
|
|
2014-04-30 03:40:59 +00:00
|
|
|
///Copy AiSequence
|
2012-09-04 11:25:53 +00:00
|
|
|
void copy (const AiSequence& sequence);
|
|
|
|
|
2014-04-30 03:40:59 +00:00
|
|
|
/// The type of AI package that ran last
|
2014-01-28 19:57:37 +00:00
|
|
|
int mLastAiPackage;
|
|
|
|
|
2012-09-04 11:25:53 +00:00
|
|
|
public:
|
2014-04-30 03:40:59 +00:00
|
|
|
///Default constructor
|
2012-09-04 11:25:53 +00:00
|
|
|
AiSequence();
|
2014-04-30 03:40:59 +00:00
|
|
|
|
|
|
|
/// Copy Constructor
|
2012-09-04 11:25:53 +00:00
|
|
|
AiSequence (const AiSequence& sequence);
|
2014-04-30 03:40:59 +00:00
|
|
|
|
|
|
|
/// Assignment operator
|
2012-09-04 11:25:53 +00:00
|
|
|
AiSequence& operator= (const AiSequence& sequence);
|
2014-04-30 03:40:59 +00:00
|
|
|
|
2012-09-04 11:25:53 +00:00
|
|
|
virtual ~AiSequence();
|
|
|
|
|
2014-07-27 18:30:52 +00:00
|
|
|
/// Iterator may be invalidated by any function calls other than begin() or end().
|
|
|
|
std::list<AiPackage*>::const_iterator begin() const;
|
|
|
|
std::list<AiPackage*>::const_iterator end() const;
|
|
|
|
|
2014-12-14 18:35:34 +00:00
|
|
|
std::list<AiPackage*>::const_iterator erase (std::list<AiPackage*>::const_iterator package);
|
2014-08-06 19:16:14 +00:00
|
|
|
|
2014-04-30 03:40:59 +00:00
|
|
|
/// Returns currently executing AiPackage type
|
|
|
|
/** \see enum AiPackage::TypeId **/
|
2012-09-04 11:25:53 +00:00
|
|
|
int getTypeId() const;
|
2014-01-07 00:12:37 +00:00
|
|
|
|
2014-04-30 03:40:59 +00:00
|
|
|
/// Get the typeid of the Ai package that ran last
|
|
|
|
/** NOT the currently "active" Ai package that will be run in the next frame.
|
|
|
|
This difference is important when an Ai package has just finished and been removed.
|
|
|
|
\see enum AiPackage::TypeId **/
|
2014-01-28 19:57:37 +00:00
|
|
|
int getLastRunTypeId() const { return mLastAiPackage; }
|
|
|
|
|
2014-04-30 03:40:59 +00:00
|
|
|
/// Return true and assign target if combat package is currently active, return false otherwise
|
2014-05-18 16:13:46 +00:00
|
|
|
bool getCombatTarget (MWWorld::Ptr &targetActor) const;
|
2014-01-07 00:12:37 +00:00
|
|
|
|
2014-07-20 20:34:20 +00:00
|
|
|
/// Is there any combat package?
|
|
|
|
bool isInCombat () const;
|
|
|
|
|
|
|
|
/// Are we in combat with this particular actor?
|
|
|
|
bool isInCombat (const MWWorld::Ptr& actor) const;
|
|
|
|
|
2014-05-15 20:03:48 +00:00
|
|
|
bool canAddTarget(const ESM::Position& actorPos, float distToTarget) const;
|
|
|
|
///< Function assumes that actor can have only 1 target apart player
|
|
|
|
|
2014-04-30 03:40:59 +00:00
|
|
|
/// Removes all combat packages until first non-combat or stack empty.
|
2014-01-07 00:12:37 +00:00
|
|
|
void stopCombat();
|
2014-04-02 04:18:22 +00:00
|
|
|
|
2014-04-30 03:40:59 +00:00
|
|
|
/// Has a package been completed during the last update?
|
2012-09-04 11:25:53 +00:00
|
|
|
bool isPackageDone() const;
|
2014-04-30 03:40:59 +00:00
|
|
|
|
2014-05-04 06:06:43 +00:00
|
|
|
/// Removes all pursue packages until first non-pursue or stack empty.
|
|
|
|
void stopPursuit();
|
2014-05-12 18:49:08 +00:00
|
|
|
|
2014-04-30 03:40:59 +00:00
|
|
|
/// Execute current package, switching if needed.
|
2014-10-08 08:58:52 +00:00
|
|
|
void execute (const MWWorld::Ptr& actor, MWMechanics::AiState& state, float duration);
|
2014-04-30 03:40:59 +00:00
|
|
|
|
2014-12-31 17:41:57 +00:00
|
|
|
/// Simulate the passing of time using the currently active AI package
|
|
|
|
void fastForward(const MWWorld::Ptr &actor, AiState &state);
|
|
|
|
|
2014-04-30 03:40:59 +00:00
|
|
|
/// Remove all packages.
|
2012-09-04 11:25:53 +00:00
|
|
|
void clear();
|
2013-11-18 11:33:09 +00:00
|
|
|
|
2014-04-30 03:40:59 +00:00
|
|
|
///< Add \a package to the front of the sequence
|
2014-05-12 18:49:08 +00:00
|
|
|
/** Suspends current package
|
|
|
|
@param actor The actor that owns this AiSequence **/
|
2014-04-29 07:09:51 +00:00
|
|
|
void stack (const AiPackage& package, const MWWorld::Ptr& actor);
|
2014-04-30 03:40:59 +00:00
|
|
|
|
|
|
|
/// Return the current active package.
|
|
|
|
/** If there is no active package, it will throw an exception **/
|
2014-01-12 13:01:54 +00:00
|
|
|
AiPackage* getActivePackage();
|
|
|
|
|
2014-04-30 03:40:59 +00:00
|
|
|
/// Fills the AiSequence with packages
|
|
|
|
/** Typically used for loading from the ESM
|
|
|
|
\see ESM::AIPackageList **/
|
2013-07-30 22:55:08 +00:00
|
|
|
void fill (const ESM::AIPackageList& list);
|
2014-06-12 21:27:04 +00:00
|
|
|
|
|
|
|
void writeState (ESM::AiSequence::AiSequence& sequence) const;
|
|
|
|
void readState (const ESM::AiSequence::AiSequence& sequence);
|
2012-09-04 11:25:53 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|