mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 20:26:43 +00:00 
			
		
		
		
	Issue #351: Refactoring Action class
This commit is contained in:
		
							parent
							
								
									281e15f58e
								
							
						
					
					
						commit
						78fe6fdce5
					
				
					 25 changed files with 71 additions and 56 deletions
				
			
		|  | @ -40,7 +40,7 @@ namespace MWClass | |||
|             physics.insertObjectPhysics(ptr, model); | ||||
|         } | ||||
|     } | ||||
|      | ||||
| 
 | ||||
|     std::string Door::getModel(const MWWorld::Ptr &ptr) const | ||||
|     { | ||||
|         MWWorld::LiveCellRef<ESM::Door> *ref = | ||||
|  | @ -97,18 +97,18 @@ namespace MWClass | |||
|         if (ref->ref.teleport) | ||||
|         { | ||||
|             // teleport door
 | ||||
|             /// \todo remove this if clause once ActionTeleport can also support other actors
 | ||||
|             if (MWBase::Environment::get().getWorld()->getPlayer().getPlayer()==actor) | ||||
|             { | ||||
|                 // the player is using the door
 | ||||
|                 // The reason this is not 3D is that it would get interrupted when you teleport
 | ||||
|                 MWBase::Environment::get().getSoundManager()->playSound(openSound, 1.0, 1.0); | ||||
|                 return boost::shared_ptr<MWWorld::Action> ( | ||||
|                     new MWWorld::ActionTeleportPlayer (ref->ref.destCell, ref->ref.doorDest)); | ||||
|                     new MWWorld::ActionTeleport (ref->ref.destCell, ref->ref.doorDest)); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 // another NPC or a creature is using the door
 | ||||
|                 // TODO return action for teleporting other NPC/creature
 | ||||
|                 return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction); | ||||
|             } | ||||
|         } | ||||
|  |  | |||
|  | @ -40,7 +40,7 @@ namespace MWClass | |||
|             physics.insertObjectPhysics(ptr, model); | ||||
|         } | ||||
|     } | ||||
|      | ||||
| 
 | ||||
|     std::string Potion::getModel(const MWWorld::Ptr &ptr) const | ||||
|     { | ||||
|         MWWorld::LiveCellRef<ESM::Potion> *ref = | ||||
|  | @ -158,7 +158,7 @@ namespace MWClass | |||
|         MWWorld::Ptr actor = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); | ||||
| 
 | ||||
|         return boost::shared_ptr<MWWorld::Action> ( | ||||
|             new MWWorld::ActionApply (actor, ref->base->mId, actor)); | ||||
|             new MWWorld::ActionApply (actor, ref->base->mId)); | ||||
|     } | ||||
| 
 | ||||
|     MWWorld::Ptr | ||||
|  | @ -170,4 +170,3 @@ namespace MWClass | |||
|         return MWWorld::Ptr(&cell.potions.insert(*ref), &cell); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -3,9 +3,11 @@ | |||
| #include <boost/lexical_cast.hpp> | ||||
| 
 | ||||
| #include "../mwbase/environment.hpp" | ||||
| #include "../mwbase/world.hpp" | ||||
| #include "../mwinput/inputmanager.hpp" | ||||
| #include "../mwsound/soundmanager.hpp" | ||||
| #include "../mwworld/actiontake.hpp" | ||||
| #include "../mwworld/player.hpp" | ||||
| 
 | ||||
| #include "formatting.hpp" | ||||
| #include "window_manager.hpp" | ||||
|  | @ -99,7 +101,7 @@ void BookWindow::onTakeButtonClicked (MyGUI::Widget* _sender) | |||
|     MWBase::Environment::get().getSoundManager()->playSound ("Item Book Up", 1.0, 1.0, MWSound::Play_NoTrack); | ||||
| 
 | ||||
|     MWWorld::ActionTake take(mBook); | ||||
|     take.execute(); | ||||
|     take.execute (MWBase::Environment::get().getWorld()->getPlayer().getPlayer()); | ||||
| 
 | ||||
|     mWindowManager.removeGuiMode(GM_Book); | ||||
| } | ||||
|  |  | |||
|  | @ -175,7 +175,7 @@ namespace MWGui | |||
| 
 | ||||
|             boost::shared_ptr<MWWorld::Action> action = MWWorld::Class::get(ptr).use(ptr); | ||||
| 
 | ||||
|             action->execute(); | ||||
|             action->execute (MWBase::Environment::get().getWorld()->getPlayer().getPlayer()); | ||||
| 
 | ||||
|             // this is necessary for books/scrolls: if they are already in the player's inventory,
 | ||||
|             // the "Take" button should not be visible.
 | ||||
|  |  | |||
|  | @ -1,8 +1,10 @@ | |||
| #include "scrollwindow.hpp" | ||||
| 
 | ||||
| #include "../mwbase/environment.hpp" | ||||
| #include "../mwbase/world.hpp" | ||||
| #include "../mwinput/inputmanager.hpp" | ||||
| #include "../mwworld/actiontake.hpp" | ||||
| #include "../mwworld/player.hpp" | ||||
| #include "../mwsound/soundmanager.hpp" | ||||
| 
 | ||||
| #include "formatting.hpp" | ||||
|  | @ -63,7 +65,7 @@ void ScrollWindow::onTakeButtonClicked (MyGUI::Widget* _sender) | |||
|     MWBase::Environment::get().getSoundManager()->playSound ("Item Book Up", 1.0, 1.0, MWSound::Play_NoTrack); | ||||
| 
 | ||||
|     MWWorld::ActionTake take(mScroll); | ||||
|     take.execute(); | ||||
|     take.execute (MWBase::Environment::get().getWorld()->getPlayer().getPlayer()); | ||||
| 
 | ||||
|     mWindowManager.removeGuiMode(GM_Scroll); | ||||
| } | ||||
|  |  | |||
|  | @ -10,6 +10,7 @@ | |||
| #include "../mwbase/world.hpp" | ||||
| 
 | ||||
| #include "../mwworld/class.hpp" | ||||
| #include "../mwworld/player.hpp" | ||||
| 
 | ||||
| #include "../mwgui/window_manager.hpp" | ||||
| 
 | ||||
|  | @ -236,7 +237,7 @@ namespace MWScript | |||
|         if (!mAction.get()) | ||||
|             throw std::runtime_error ("activation failed, because no action to perform"); | ||||
| 
 | ||||
|         mAction->execute(); | ||||
|         mAction->execute (MWBase::Environment::get().getWorld()->getPlayer().getPlayer()); | ||||
|         mActivationHandled = true; | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										11
									
								
								apps/openmw/mwworld/action.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								apps/openmw/mwworld/action.cpp
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | |||
| 
 | ||||
| #include "action.hpp" | ||||
| 
 | ||||
| MWWorld::Action::Action() {} | ||||
| 
 | ||||
| MWWorld::Action::~Action() {} | ||||
| 
 | ||||
| void MWWorld::Action::execute (const Ptr& actor) | ||||
| { | ||||
|     executeImp (actor); | ||||
| } | ||||
|  | @ -3,6 +3,8 @@ | |||
| 
 | ||||
| namespace MWWorld | ||||
| { | ||||
|     class Ptr; | ||||
| 
 | ||||
|     /// \brief Abstract base for actions
 | ||||
|     class Action | ||||
|     { | ||||
|  | @ -10,13 +12,15 @@ namespace MWWorld | |||
|             Action (const Action& action); | ||||
|             Action& operator= (const Action& action); | ||||
| 
 | ||||
|             virtual void executeImp (const Ptr& actor) = 0; | ||||
| 
 | ||||
|         public: | ||||
| 
 | ||||
|             Action() {} | ||||
|             Action(); | ||||
| 
 | ||||
|             virtual ~Action() {} | ||||
|             virtual ~Action(); | ||||
| 
 | ||||
|             virtual void execute() = 0; | ||||
|             void execute (const Ptr& actor); | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -5,7 +5,7 @@ | |||
| 
 | ||||
| namespace MWWorld | ||||
| { | ||||
|     void ActionAlchemy::execute() | ||||
|     void ActionAlchemy::executeImp (const Ptr& actor) | ||||
|     { | ||||
|         MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Alchemy); | ||||
|     } | ||||
|  |  | |||
|  | @ -7,8 +7,7 @@ namespace MWWorld | |||
| { | ||||
|     class ActionAlchemy : public Action | ||||
|     { | ||||
|         public: | ||||
|             virtual void execute (); | ||||
|             virtual void executeImp (const Ptr& actor); | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -5,24 +5,24 @@ | |||
| 
 | ||||
| namespace MWWorld | ||||
| { | ||||
|     ActionApply::ActionApply (const Ptr& target, const std::string& id, const Ptr& actor) | ||||
|     : mTarget (target), mId (id), mActor (actor) | ||||
|     ActionApply::ActionApply (const Ptr& target, const std::string& id) | ||||
|     : mTarget (target), mId (id) | ||||
|     {} | ||||
| 
 | ||||
|     void ActionApply::execute() | ||||
|     void ActionApply::executeImp (const Ptr& actor) | ||||
|     { | ||||
|         MWWorld::Class::get (mTarget).apply (mTarget, mId, mActor); | ||||
|         MWWorld::Class::get (mTarget).apply (mTarget, mId, actor); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     ActionApplyWithSkill::ActionApplyWithSkill (const Ptr& target, const std::string& id, | ||||
|         const Ptr& actor, int skillIndex, int usageType) | ||||
|     : mTarget (target), mId (id), mActor (actor), mSkillIndex (skillIndex), mUsageType (usageType) | ||||
|         int skillIndex, int usageType) | ||||
|     : mTarget (target), mId (id), mSkillIndex (skillIndex), mUsageType (usageType) | ||||
|     {} | ||||
| 
 | ||||
|     void ActionApplyWithSkill::execute() | ||||
|     void ActionApplyWithSkill::executeImp (const Ptr& actor) | ||||
|     { | ||||
|         if (MWWorld::Class::get (mTarget).apply (mTarget, mId, mActor) && mUsageType!=-1) | ||||
|             MWWorld::Class::get (mTarget).skillUsageSucceeded (mActor, mSkillIndex, mUsageType); | ||||
|         if (MWWorld::Class::get (mTarget).apply (mTarget, mId, actor) && mUsageType!=-1) | ||||
|             MWWorld::Class::get (mTarget).skillUsageSucceeded (actor, mSkillIndex, mUsageType); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -13,29 +13,27 @@ namespace MWWorld | |||
|     { | ||||
|             Ptr mTarget; | ||||
|             std::string mId; | ||||
|             Ptr mActor; | ||||
| 
 | ||||
|             virtual void executeImp (const Ptr& actor); | ||||
| 
 | ||||
|         public: | ||||
| 
 | ||||
|             ActionApply (const Ptr& target, const std::string& id, const Ptr& actor); | ||||
| 
 | ||||
|             virtual void execute(); | ||||
|             ActionApply (const Ptr& target, const std::string& id); | ||||
|     }; | ||||
| 
 | ||||
|     class ActionApplyWithSkill : public Action | ||||
|     { | ||||
|             Ptr mTarget; | ||||
|             std::string mId; | ||||
|             Ptr mActor; | ||||
|             int mSkillIndex; | ||||
|             int mUsageType; | ||||
| 
 | ||||
|             virtual void executeImp (const Ptr& actor); | ||||
| 
 | ||||
|         public: | ||||
| 
 | ||||
|             ActionApplyWithSkill (const Ptr& target, const std::string& id, const Ptr& actor, | ||||
|             ActionApplyWithSkill (const Ptr& target, const std::string& id, | ||||
|                 int skillIndex, int usageType); | ||||
| 
 | ||||
|             virtual void execute(); | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ namespace MWWorld | |||
|     { | ||||
|     } | ||||
| 
 | ||||
|     void ActionEquip::execute () | ||||
|     void ActionEquip::executeImp (const Ptr& actor) | ||||
|     { | ||||
|         MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); | ||||
|         MWWorld::InventoryStore& invStore = MWWorld::Class::get(player).getInventoryStore(player); | ||||
|  |  | |||
|  | @ -10,11 +10,11 @@ namespace MWWorld | |||
|     { | ||||
|             Ptr mObject; | ||||
| 
 | ||||
|             virtual void executeImp (const Ptr& actor); | ||||
| 
 | ||||
|         public: | ||||
|             /// @param item to equip
 | ||||
|             ActionEquip (const Ptr& object); | ||||
| 
 | ||||
|             virtual void execute (); | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -15,7 +15,7 @@ namespace MWWorld | |||
|         mContainer = container; | ||||
|     } | ||||
| 
 | ||||
|     void ActionOpen::execute () | ||||
|     void ActionOpen::executeImp (const MWWorld::Ptr& actor) | ||||
|     { | ||||
|         if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory)) | ||||
|             return; | ||||
|  |  | |||
|  | @ -12,10 +12,11 @@ namespace MWWorld | |||
|     { | ||||
|             Ptr mContainer; | ||||
| 
 | ||||
|             virtual void executeImp (const MWWorld::Ptr& actor); | ||||
| 
 | ||||
|         public: | ||||
|             ActionOpen (const Ptr& container); | ||||
|             ///< \param The Container the Player has activated.
 | ||||
|             virtual void execute (); | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -11,7 +11,7 @@ namespace MWWorld | |||
|     { | ||||
|     } | ||||
| 
 | ||||
|     void ActionRead::execute () | ||||
|     void ActionRead::executeImp (const MWWorld::Ptr& actor) | ||||
|     { | ||||
|         LiveCellRef<ESM::Book> *ref = mObject.get<ESM::Book>(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -10,11 +10,11 @@ namespace MWWorld | |||
|     { | ||||
|             Ptr mObject; // book or scroll to read
 | ||||
| 
 | ||||
|             virtual void executeImp (const MWWorld::Ptr& actor); | ||||
| 
 | ||||
|         public: | ||||
|             /// @param book or scroll to read
 | ||||
|             ActionRead (const Ptr& object); | ||||
| 
 | ||||
|             virtual void execute (); | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ namespace MWWorld | |||
| { | ||||
|     ActionTake::ActionTake (const MWWorld::Ptr& object) : mObject (object) {} | ||||
| 
 | ||||
|     void ActionTake::execute() | ||||
|     void ActionTake::executeImp (const Ptr& actor) | ||||
|     { | ||||
|         if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory)) | ||||
|             return; | ||||
|  |  | |||
|  | @ -10,11 +10,11 @@ namespace MWWorld | |||
|     { | ||||
|             MWWorld::Ptr mObject; | ||||
| 
 | ||||
|             virtual void executeImp (const Ptr& actor); | ||||
| 
 | ||||
|         public: | ||||
| 
 | ||||
|             ActionTake (const MWWorld::Ptr& object); | ||||
| 
 | ||||
|             virtual void execute(); | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -9,7 +9,7 @@ namespace MWWorld | |||
| { | ||||
|     ActionTalk::ActionTalk (const Ptr& actor) : mActor (actor) {} | ||||
| 
 | ||||
|     void ActionTalk::execute() | ||||
|     void ActionTalk::executeImp (const Ptr& actor) | ||||
|     { | ||||
|         MWBase::Environment::get().getDialogueManager()->startDialogue (mActor); | ||||
|     } | ||||
|  |  | |||
|  | @ -10,12 +10,12 @@ namespace MWWorld | |||
|     { | ||||
|             Ptr mActor; | ||||
| 
 | ||||
|             virtual void executeImp (const Ptr& actor); | ||||
| 
 | ||||
|         public: | ||||
| 
 | ||||
|             ActionTalk (const Ptr& actor); | ||||
|             ///< \param actor The actor the player is talking to
 | ||||
| 
 | ||||
|             virtual void execute(); | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -6,12 +6,12 @@ | |||
| 
 | ||||
| namespace MWWorld | ||||
| { | ||||
|     ActionTeleportPlayer::ActionTeleportPlayer (const std::string& cellName, | ||||
|     ActionTeleport::ActionTeleport (const std::string& cellName, | ||||
|         const ESM::Position& position) | ||||
|     : mCellName (cellName), mPosition (position) | ||||
|     {} | ||||
| 
 | ||||
|     void ActionTeleportPlayer::execute() | ||||
|     void ActionTeleport::executeImp (const Ptr& actor) | ||||
|     { | ||||
|         if (mCellName.empty()) | ||||
|             MWBase::Environment::get().getWorld()->changeToExteriorCell (mPosition); | ||||
|  |  | |||
|  | @ -9,17 +9,17 @@ | |||
| 
 | ||||
| namespace MWWorld | ||||
| { | ||||
|     class ActionTeleportPlayer : public Action | ||||
|     class ActionTeleport : public Action | ||||
|     { | ||||
|             std::string mCellName; | ||||
|             ESM::Position mPosition; | ||||
| 
 | ||||
|             virtual void executeImp (const Ptr& actor); | ||||
| 
 | ||||
|         public: | ||||
| 
 | ||||
|             ActionTeleportPlayer (const std::string& cellName, const ESM::Position& position); | ||||
|             ActionTeleport (const std::string& cellName, const ESM::Position& position); | ||||
|             ///< If cellName is empty, an exterior cell is asumed.
 | ||||
| 
 | ||||
|             virtual void execute(); | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -8,9 +8,7 @@ namespace MWWorld | |||
|     /// \brief Action: do nothing
 | ||||
|     class NullAction : public Action | ||||
|     { | ||||
|         public: | ||||
| 
 | ||||
|             virtual void execute() {} | ||||
|             virtual void executeImp (const Ptr& actor) {} | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue