From 10a5bb946461ec6d48e184a36b76fbb7e8ef9652 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 29 Apr 2014 23:40:59 -0400 Subject: [PATCH] Made code a bit more standardized and added a good bit of documentation. --- apps/openmw/mwinput/inputmanagerimp.hpp | 6 +- apps/openmw/mwmechanics/aiactivate.hpp | 9 +-- apps/openmw/mwmechanics/aicombat.hpp | 5 +- apps/openmw/mwmechanics/aiescort.hpp | 10 ++- apps/openmw/mwmechanics/aifollow.hpp | 16 ++++- apps/openmw/mwmechanics/aipackage.hpp | 23 ++++--- apps/openmw/mwmechanics/aipersue.hpp | 6 +- apps/openmw/mwmechanics/aisequence.hpp | 62 ++++++++++------- apps/openmw/mwmechanics/aitravel.hpp | 7 +- apps/openmw/mwmechanics/aiwander.hpp | 23 ++++--- apps/openmw/mwmechanics/alchemy.hpp | 92 ++++++++++++------------- 11 files changed, 152 insertions(+), 107 deletions(-) diff --git a/apps/openmw/mwinput/inputmanagerimp.hpp b/apps/openmw/mwinput/inputmanagerimp.hpp index 3787a9c07..ace4cc6d0 100644 --- a/apps/openmw/mwinput/inputmanagerimp.hpp +++ b/apps/openmw/mwinput/inputmanagerimp.hpp @@ -46,10 +46,7 @@ namespace MyGUI namespace MWInput { - - /** - * @brief Class that handles all input and key bindings for OpenMW. - */ + /// \brief Class that handles all input and key bindings for OpenMW. class InputManager : public MWBase::InputManager, public SFO::KeyListener, @@ -68,6 +65,7 @@ namespace MWInput /// Clear all savegame-specific data virtual void clear(); + virtual void update(float dt, bool disableControls=false, bool disableEvents=false); void setPlayer (MWWorld::Player* player) { mPlayer = player; } diff --git a/apps/openmw/mwmechanics/aiactivate.hpp b/apps/openmw/mwmechanics/aiactivate.hpp index fd54869f6..b6ce9f85d 100644 --- a/apps/openmw/mwmechanics/aiactivate.hpp +++ b/apps/openmw/mwmechanics/aiactivate.hpp @@ -7,15 +7,16 @@ #include "pathfinding.hpp" namespace MWMechanics -{ - +{ + /// \brief Causes actor to walk to activatable object and activate it class AiActivate : public AiPackage { - public: + public: + /// Constructor + /** \param objectId Reference to object to activate **/ AiActivate(const std::string &objectId); virtual AiActivate *clone() const; virtual bool execute (const MWWorld::Ptr& actor,float duration); - ///< \return Package completed? virtual int getTypeId() const; private: diff --git a/apps/openmw/mwmechanics/aicombat.hpp b/apps/openmw/mwmechanics/aicombat.hpp index 30b72acd9..833b0063c 100644 --- a/apps/openmw/mwmechanics/aicombat.hpp +++ b/apps/openmw/mwmechanics/aicombat.hpp @@ -14,20 +14,23 @@ namespace MWMechanics { + /// \brief Causes the actor to fight another actor class AiCombat : public AiPackage { public: + ///Constructor + /** \param actor Actor to fight **/ AiCombat(const MWWorld::Ptr& actor); virtual AiCombat *clone() const; virtual bool execute (const MWWorld::Ptr& actor,float duration); - ///< \return Package completed? virtual int getTypeId() const; virtual unsigned int getPriority() const; + ///Returns target ID const std::string &getTargetId() const; private: diff --git a/apps/openmw/mwmechanics/aiescort.hpp b/apps/openmw/mwmechanics/aiescort.hpp index 53b57c058..3771417fa 100644 --- a/apps/openmw/mwmechanics/aiescort.hpp +++ b/apps/openmw/mwmechanics/aiescort.hpp @@ -8,18 +8,22 @@ namespace MWMechanics { + /// \brief AI Package to have an NPC lead the player to a specific point class AiEscort : public AiPackage { public: + /// 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); - ///< \implement AiEscort + /// 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); - ///< \implement AiEscortCell virtual AiEscort *clone() const; virtual bool execute (const MWWorld::Ptr& actor,float duration); - ///< \return Package completed? virtual int getTypeId() const; diff --git a/apps/openmw/mwmechanics/aifollow.hpp b/apps/openmw/mwmechanics/aifollow.hpp index 48a8eb4c2..4eb3e3757 100644 --- a/apps/openmw/mwmechanics/aifollow.hpp +++ b/apps/openmw/mwmechanics/aifollow.hpp @@ -8,22 +8,32 @@ namespace MWMechanics { - + /// \brief AiPackage for an actor to follow another actor/the PC + /** The AI will follow the target until a condition (time, or position) are set. Both can be disabled to cause the actor to follow the other indefinitely + **/ class AiFollow : public AiPackage { public: + /// Follow Actor for duration or until you arrive at a world position AiFollow(const std::string &ActorId,float duration, float X, float Y, float Z); + /// 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); + virtual AiFollow *clone() const; + virtual bool execute (const MWWorld::Ptr& actor,float duration); - ///< \return Package completed? + virtual int getTypeId() const; + /// Returns the actor being followed std::string getFollowedActor(); private: - bool mAlwaysFollow; //this will make the actor always follow, thus ignoring mDuration and mX,mY,mZ (used for summoned creatures). + /// This will make the actor always follow. + /** Thus ignoring mDuration and mX,mY,mZ (used for summoned creatures). **/ + bool mAlwaysFollow; float mDuration; float mX; float mY; diff --git a/apps/openmw/mwmechanics/aipackage.hpp b/apps/openmw/mwmechanics/aipackage.hpp index 8e015da15..30eab7f8b 100644 --- a/apps/openmw/mwmechanics/aipackage.hpp +++ b/apps/openmw/mwmechanics/aipackage.hpp @@ -12,6 +12,7 @@ namespace MWMechanics class AiPackage { public: + ///Enumerates the various AITypes availible. enum TypeId { TypeIdNone = -1, TypeIdWander = 0, @@ -23,18 +24,22 @@ namespace MWMechanics TypeIdPersue = 6 }; + ///Default Deconstructor virtual ~AiPackage(); - - virtual AiPackage *clone() const = 0; - - virtual bool execute (const MWWorld::Ptr& actor,float duration) = 0; - ///< \return Package completed? - - virtual int getTypeId() const = 0; - ///< @see enum TypeId + ///Clones the package + virtual AiPackage *clone() const = 0; + + /// Updates and runs the package (Should run every frame) + /// \return Package completed? + virtual bool execute (const MWWorld::Ptr& actor,float duration) = 0; + + /// Returns the TypeID of the AiPackage + /// \see enum TypeId + virtual int getTypeId() const = 0; + + /// Higher number is higher priority (0 beeing the lowest) virtual unsigned int getPriority() const {return 0;} - ///< higher number is higher priority (0 beeing the lowest) }; } diff --git a/apps/openmw/mwmechanics/aipersue.hpp b/apps/openmw/mwmechanics/aipersue.hpp index 3fd708ab3..bf5410676 100644 --- a/apps/openmw/mwmechanics/aipersue.hpp +++ b/apps/openmw/mwmechanics/aipersue.hpp @@ -8,14 +8,16 @@ namespace MWMechanics { - + /// \brief Makes the actor very closely follow the actor + /** Used for getting closer to fight, or to arrest (I think?) **/ class AiPersue : public AiPackage { public: + ///Constructor + /** \param objectId Actor to pursue **/ AiPersue(const std::string &objectId); virtual AiPersue *clone() const; virtual bool execute (const MWWorld::Ptr& actor,float duration); - ///< \return Package completed? virtual int getTypeId() const; private: diff --git a/apps/openmw/mwmechanics/aisequence.hpp b/apps/openmw/mwmechanics/aisequence.hpp index cb1b0de02..a751e0397 100644 --- a/apps/openmw/mwmechanics/aisequence.hpp +++ b/apps/openmw/mwmechanics/aisequence.hpp @@ -13,65 +13,79 @@ namespace MWWorld namespace MWMechanics { class AiPackage; - + /// \brief Sequence of AI-packages for a single actor + /** Each package will be run in succession for an actor until completed **/ class AiSequence { + ///AiPackages to run though std::list mPackages; + ///Finished with all AiPackages bool mDone; + ///Copy AiSequence void copy (const AiSequence& sequence); - // The type of AI package that ran last + /// The type of AI package that ran last int mLastAiPackage; public: - + ///Default constructor AiSequence(); - + + /// Copy Constructor AiSequence (const AiSequence& sequence); - + + /// Assignment operator AiSequence& operator= (const AiSequence& sequence); - + + /// Destructor virtual ~AiSequence(); + /// Returns currently executing AiPackage type + /** \see enum AiPackage::TypeId **/ int getTypeId() const; - ///< @see enum AiPackage::TypeId + /// 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 **/ int getLastRunTypeId() const { return mLastAiPackage; } - ///< 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. + /// Return true and assign target if combat package is currently active, return false otherwise bool getCombatTarget (std::string &targetActorId) const; - ///< Return true and assign target if combat package is currently - /// active, return false otherwise + /// Removes all combat packages until first non-combat or stack empty. void stopCombat(); - ///< Removes all combat packages until first non-combat or stack empty. + /// Removes all persue packages until first non-persue or stack empty. void stopPersue(); - ///< Removes all persue packages until first non-persue or stack empty. - + + /// Has a package been completed during the last update? bool isPackageDone() const; - ///< Has a package been completed during the last update? - + + /// Execute current package, switching if needed. void execute (const MWWorld::Ptr& actor,float duration); - ///< Execute package. - + + /// Remove all packages. void clear(); - ///< Remove all packages. + ///< Add \a package to the front of the sequence + /** Suspends current package **/ void stack (const AiPackage& package, const MWWorld::Ptr& actor); - ///< Add \a package to the front of the sequence (suspends current package) - + + /// Add \a package to the end of the sequence + /** Executed after all other packages have been completed **/ void queue (const AiPackage& package); - ///< Add \a package to the end of the sequence (executed after all other packages have been - /// completed) + /// Return the current active package. + /** If there is no active package, it will throw an exception **/ AiPackage* getActivePackage(); - ///< return the current active package. If there is no active package, throw an exeption + /// Fills the AiSequence with packages + /** Typically used for loading from the ESM + \see ESM::AIPackageList **/ void fill (const ESM::AIPackageList& list); }; } diff --git a/apps/openmw/mwmechanics/aitravel.hpp b/apps/openmw/mwmechanics/aitravel.hpp index 72f3e0298..ea7f1dc32 100644 --- a/apps/openmw/mwmechanics/aitravel.hpp +++ b/apps/openmw/mwmechanics/aitravel.hpp @@ -6,15 +6,16 @@ #include "pathfinding.hpp" namespace MWMechanics -{ +{ + /// \brief Causes the AI to travel to the specified point class AiTravel : public AiPackage { - public: + public: + /// Default constructor AiTravel(float x, float y, float z); virtual AiTravel *clone() const; virtual bool execute (const MWWorld::Ptr& actor,float duration); - ///< \return Package completed? virtual int getTypeId() const; diff --git a/apps/openmw/mwmechanics/aiwander.hpp b/apps/openmw/mwmechanics/aiwander.hpp index 2975c8315..6481b2a01 100644 --- a/apps/openmw/mwmechanics/aiwander.hpp +++ b/apps/openmw/mwmechanics/aiwander.hpp @@ -14,20 +14,27 @@ namespace MWMechanics { + /// \brief Causes the Actor to wander within a specified range class AiWander : public AiPackage { public: - + /// Constructor + /** \param distance Max distance the ACtor will wander + \param duration Time, in hours, that this package will be preformed + \param timeOfDay Start time of the package, if it has a duration. Currently unimplemented + \param idle Chances of each idle to play (9 in total) + \param repeat Repeat wander or not **/ AiWander(int distance, int duration, int timeOfDay, const std::vector& idle, bool repeat); - virtual AiPackage *clone() const; - virtual bool execute (const MWWorld::Ptr& actor,float duration); - ///< \return Package completed? - virtual int getTypeId() const; - ///< 0: Wander + virtual AiPackage *clone() const; + + virtual bool execute (const MWWorld::Ptr& actor,float duration); + + virtual int getTypeId() const; + + /// Set the position to return to for a stationary (non-wandering) actor + /** In case another AI package moved the actor elsewhere **/ void setReturnPosition (const Ogre::Vector3& position); - ///< Set the position to return to for a stationary (non-wandering) actor, in case - /// another AI package moved the actor elsewhere private: void stopWalking(const MWWorld::Ptr& actor); diff --git a/apps/openmw/mwmechanics/alchemy.hpp b/apps/openmw/mwmechanics/alchemy.hpp index 31cafa4dc..b2b0fe1ee 100644 --- a/apps/openmw/mwmechanics/alchemy.hpp +++ b/apps/openmw/mwmechanics/alchemy.hpp @@ -31,6 +31,8 @@ namespace MWMechanics typedef std::vector TEffectsContainer; typedef TEffectsContainer::const_iterator TEffectsIterator; + /// Result of potion creation + /** Only Result_Success results in success **/ enum Result { Result_Success, @@ -42,6 +44,46 @@ namespace MWMechanics Result_RandomFailure }; + /// Set alchemist and configure alchemy setup accordingly. + /** \a npc may be empty to indicate that there is no alchemist (alchemy session has ended). **/ + void setAlchemist (const MWWorld::Ptr& npc); + + /// \attention Iterates over tool slots, not over tools. Some of the slots may be empty. + TToolsIterator beginTools() const; + + TToolsIterator endTools() const; + + /// \attention Iterates over ingredient slots, not over ingredients. Some of the slots may be empty. + TIngredientsIterator beginIngredients() const; + + TIngredientsIterator endIngredients() const; + + /// Remove alchemist, tools and ingredients. + void clear(); + + /// Add ingredient into the next free slot. + /// + /// \return Slot index or -1, if adding failed because of no free slot or the ingredient type being + /// listed already. + int addIngredient (const MWWorld::Ptr& ingredient); + + /// Remove ingredient from slot (calling this function on an empty slot is a no-op). + void removeIngredient (int index); + + TEffectsIterator beginEffects() const; + + TEffectsIterator endEffects() const; + + /// Return the name of the potion that would be created when calling create (if a record for such + /// a potion already exists) or return an empty string. + std::string getPotionName() const; + + /// Try to create a potion from the ingredients, place it in the inventory of the alchemist and + /// adjust the skills of the alchemist accordingly. + /// \param name must not be an empty string, unless there is already a potion record ( + /// getPotionName() does not return an empty string). + Result create (const std::string& name); + private: MWWorld::Ptr mAlchemist; @@ -50,19 +92,19 @@ namespace MWMechanics TEffectsContainer mEffects; int mValue; + /// List all effects shared by at least two ingredients. std::set listEffects() const; - ///< List all effects shared by at least two ingredients. void applyTools (int flags, float& value) const; void updateEffects(); + /// Return existing recrod for created potion (may return 0) const ESM::Potion *getRecord() const; - ///< Return existing recrod for created potion (may return 0) - void removeIngredients(); - ///< Remove selected ingredients from alchemist's inventory, cleanup selected ingredients and + /// Remove selected ingredients from alchemist's inventory, cleanup selected ingredients and /// update effect list accordingly. + void removeIngredients(); void addPotion (const std::string& name); ///< Add a potion to the alchemist's inventory. @@ -74,48 +116,6 @@ namespace MWMechanics ///< Return chance of success. int countIngredients() const; - - public: - - void setAlchemist (const MWWorld::Ptr& npc); - ///< Set alchemist and configure alchemy setup accordingly. \a npc may be empty to indicate that - /// there is no alchemist (alchemy session has ended). - - TToolsIterator beginTools() const; - ///< \attention Iterates over tool slots, not over tools. Some of the slots may be empty. - - TToolsIterator endTools() const; - - TIngredientsIterator beginIngredients() const; - ///< \attention Iterates over ingredient slots, not over ingredients. Some of the slots may be empty. - - TIngredientsIterator endIngredients() const; - - void clear(); - ///< Remove alchemist, tools and ingredients. - - int addIngredient (const MWWorld::Ptr& ingredient); - ///< Add ingredient into the next free slot. - /// - /// \return Slot index or -1, if adding failed because of no free slot or the ingredient type being - /// listed already. - - void removeIngredient (int index); - ///< Remove ingredient from slot (calling this function on an empty slot is a no-op). - - TEffectsIterator beginEffects() const; - - TEffectsIterator endEffects() const; - - std::string getPotionName() const; - ///< Return the name of the potion that would be created when calling create (if a record for such - /// a potion already exists) or return an empty string. - - Result create (const std::string& name); - ///< Try to create a potion from the ingredients, place it in the inventory of the alchemist and - /// adjust the skills of the alchemist accordingly. - /// \param name must not be an empty string, unless there is already a potion record ( - /// getPotionName() does not return an empty string). }; }