1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-22 03:40:49 +00:00

Merge branch 'actiontarget'

This commit is contained in:
Marc Zinnschlag 2012-09-04 20:56:40 +02:00
commit 0879abb948
16 changed files with 50 additions and 50 deletions

View File

@ -87,7 +87,6 @@ namespace MWClass
const std::string lockedSound = "LockedChest"; const std::string lockedSound = "LockedChest";
const std::string trapActivationSound = "Disarm Trap Fail"; const std::string trapActivationSound = "Disarm Trap Fail";
if (ptr.getCellRef().lockLevel>0) if (ptr.getCellRef().lockLevel>0)
{ {
// TODO check for key // TODO check for key
@ -98,12 +97,11 @@ namespace MWClass
} }
else else
{ {
std::cout << "Unlocked container" << std::endl;
if(ptr.getCellRef().trap.empty()) if(ptr.getCellRef().trap.empty())
{ {
// Not trapped, Inventory GUI goes here boost::shared_ptr<MWWorld::Action> action (new MWWorld::ActionOpen(ptr));
//return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction); action->setSound ("chest open");
return boost::shared_ptr<MWWorld::Action> (new MWWorld::ActionOpen(ptr)); return action;
} }
else else
{ {

View File

@ -6,7 +6,12 @@
#include "../mwbase/soundmanager.hpp" #include "../mwbase/soundmanager.hpp"
MWWorld::Action::Action (bool teleport) : mTeleport (teleport) const MWWorld::Ptr& MWWorld::Action::getTarget() const
{
return mTarget;
}
MWWorld::Action::Action (bool keepSound, const Ptr& target) : mKeepSound (keepSound), mTarget (target)
{} {}
MWWorld::Action::~Action() {} MWWorld::Action::~Action() {}
@ -15,16 +20,19 @@ void MWWorld::Action::execute (const Ptr& actor)
{ {
if (!mSoundId.empty()) if (!mSoundId.empty())
{ {
if (mTeleport == true) if (mKeepSound && actor.getRefData().getHandle()=="player")
{ {
//this is a teleport action, so we need to call playSound // sound moves with player when teleporting
MWBase::Environment::get().getSoundManager()->playSound(mSoundId, 1.0, 1.0, MWBase::Environment::get().getSoundManager()->playSound(mSoundId, 1.0, 1.0,
MWBase::SoundManager::Play_NoTrack); MWBase::SoundManager::Play_NoTrack);
} }
else else
{ {
MWBase::Environment::get().getSoundManager()->playSound3D (actor, mSoundId, 1.0, 1.0, bool local = mTarget.isEmpty() || !mTarget.isInCell(); // no usable target
MWBase::SoundManager::Play_NoTrack);
MWBase::Environment::get().getSoundManager()->playSound3D (local ? actor : mTarget,
mSoundId, 1.0, 1.0,
mKeepSound ? MWBase::SoundManager::Play_NoTrack : MWBase::SoundManager::Play_Normal);
} }
} }

View File

@ -3,15 +3,16 @@
#include <string> #include <string>
#include "ptr.hpp"
namespace MWWorld namespace MWWorld
{ {
class Ptr;
/// \brief Abstract base for actions /// \brief Abstract base for actions
class Action class Action
{ {
std::string mSoundId; std::string mSoundId;
bool mTeleport; bool mKeepSound;
Ptr mTarget;
// not implemented // not implemented
Action (const Action& action); Action (const Action& action);
@ -19,10 +20,14 @@ namespace MWWorld
virtual void executeImp (const Ptr& actor) = 0; virtual void executeImp (const Ptr& actor) = 0;
public: protected:
Action (bool teleport = false); const Ptr& getTarget() const;
///< \param teleport action will teleport the actor
public:
Action (bool keepSound = false, const Ptr& target = Ptr());
///< \param keepSound Keep playing the sound even if the object the sound is played on is removed.
virtual ~Action(); virtual ~Action();

View File

@ -6,23 +6,23 @@
namespace MWWorld namespace MWWorld
{ {
ActionApply::ActionApply (const Ptr& target, const std::string& id) ActionApply::ActionApply (const Ptr& target, const std::string& id)
: mTarget (target), mId (id) : Action (false, target), mId (id)
{} {}
void ActionApply::executeImp (const Ptr& actor) void ActionApply::executeImp (const Ptr& actor)
{ {
MWWorld::Class::get (mTarget).apply (mTarget, mId, actor); MWWorld::Class::get (getTarget()).apply (getTarget(), mId, actor);
} }
ActionApplyWithSkill::ActionApplyWithSkill (const Ptr& target, const std::string& id, ActionApplyWithSkill::ActionApplyWithSkill (const Ptr& target, const std::string& id,
int skillIndex, int usageType) int skillIndex, int usageType)
: mTarget (target), mId (id), mSkillIndex (skillIndex), mUsageType (usageType) : Action (false, target), mId (id), mSkillIndex (skillIndex), mUsageType (usageType)
{} {}
void ActionApplyWithSkill::executeImp (const Ptr& actor) void ActionApplyWithSkill::executeImp (const Ptr& actor)
{ {
if (MWWorld::Class::get (mTarget).apply (mTarget, mId, actor) && mUsageType!=-1) if (MWWorld::Class::get (getTarget()).apply (getTarget(), mId, actor) && mUsageType!=-1)
MWWorld::Class::get (mTarget).skillUsageSucceeded (actor, mSkillIndex, mUsageType); MWWorld::Class::get (getTarget()).skillUsageSucceeded (actor, mSkillIndex, mUsageType);
} }
} }

View File

@ -11,7 +11,6 @@ namespace MWWorld
{ {
class ActionApply : public Action class ActionApply : public Action
{ {
Ptr mTarget;
std::string mId; std::string mId;
virtual void executeImp (const Ptr& actor); virtual void executeImp (const Ptr& actor);
@ -23,7 +22,6 @@ namespace MWWorld
class ActionApplyWithSkill : public Action class ActionApplyWithSkill : public Action
{ {
Ptr mTarget;
std::string mId; std::string mId;
int mSkillIndex; int mSkillIndex;
int mUsageType; int mUsageType;

View File

@ -9,7 +9,7 @@
namespace MWWorld namespace MWWorld
{ {
ActionEquip::ActionEquip (const MWWorld::Ptr& object) : mObject (object) ActionEquip::ActionEquip (const MWWorld::Ptr& object) : Action (false, object)
{ {
} }
@ -19,13 +19,13 @@ namespace MWWorld
MWWorld::InventoryStore& invStore = MWWorld::Class::get(player).getInventoryStore(player); MWWorld::InventoryStore& invStore = MWWorld::Class::get(player).getInventoryStore(player);
// slots that this item can be equipped in // slots that this item can be equipped in
std::pair<std::vector<int>, bool> slots = MWWorld::Class::get(mObject).getEquipmentSlots(mObject); std::pair<std::vector<int>, bool> slots = MWWorld::Class::get(getTarget()).getEquipmentSlots(getTarget());
// retrieve ContainerStoreIterator to the item // retrieve ContainerStoreIterator to the item
MWWorld::ContainerStoreIterator it = invStore.begin(); MWWorld::ContainerStoreIterator it = invStore.begin();
for (; it != invStore.end(); ++it) for (; it != invStore.end(); ++it)
{ {
if (*it == mObject) if (*it == getTarget())
{ {
break; break;
} }

View File

@ -8,8 +8,6 @@ namespace MWWorld
{ {
class ActionEquip : public Action class ActionEquip : public Action
{ {
Ptr mObject;
virtual void executeImp (const Ptr& actor); virtual void executeImp (const Ptr& actor);
public: public:

View File

@ -10,8 +10,8 @@
namespace MWWorld namespace MWWorld
{ {
ActionOpen::ActionOpen (const MWWorld::Ptr& container) : mContainer (container) { ActionOpen::ActionOpen (const MWWorld::Ptr& container) : Action (false, container)
mContainer = container; {
} }
void ActionOpen::executeImp (const MWWorld::Ptr& actor) void ActionOpen::executeImp (const MWWorld::Ptr& actor)
@ -20,6 +20,6 @@ namespace MWWorld
return; return;
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Container); MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Container);
MWBase::Environment::get().getWindowManager()->getContainerWindow()->open(mContainer); MWBase::Environment::get().getWindowManager()->getContainerWindow()->open(getTarget());
} }
} }

View File

@ -10,8 +10,6 @@ namespace MWWorld
{ {
class ActionOpen : public Action class ActionOpen : public Action
{ {
Ptr mContainer;
virtual void executeImp (const MWWorld::Ptr& actor); virtual void executeImp (const MWWorld::Ptr& actor);
public: public:

View File

@ -8,23 +8,23 @@
namespace MWWorld namespace MWWorld
{ {
ActionRead::ActionRead (const MWWorld::Ptr& object) : mObject (object) ActionRead::ActionRead (const MWWorld::Ptr& object) : Action (false, object)
{ {
} }
void ActionRead::executeImp (const MWWorld::Ptr& actor) void ActionRead::executeImp (const MWWorld::Ptr& actor)
{ {
LiveCellRef<ESM::Book> *ref = mObject.get<ESM::Book>(); LiveCellRef<ESM::Book> *ref = getTarget().get<ESM::Book>();
if (ref->base->data.isScroll) if (ref->base->data.isScroll)
{ {
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Scroll); MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Scroll);
MWBase::Environment::get().getWindowManager()->getScrollWindow()->open(mObject); MWBase::Environment::get().getWindowManager()->getScrollWindow()->open(getTarget());
} }
else else
{ {
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Book); MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Book);
MWBase::Environment::get().getWindowManager()->getBookWindow()->open(mObject); MWBase::Environment::get().getWindowManager()->getBookWindow()->open(getTarget());
} }
} }
} }

View File

@ -8,8 +8,6 @@ namespace MWWorld
{ {
class ActionRead : public Action class ActionRead : public Action
{ {
Ptr mObject; // book or scroll to read
virtual void executeImp (const MWWorld::Ptr& actor); virtual void executeImp (const MWWorld::Ptr& actor);
public: public:

View File

@ -10,7 +10,7 @@
namespace MWWorld namespace MWWorld
{ {
ActionTake::ActionTake (const MWWorld::Ptr& object) : mObject (object) {} ActionTake::ActionTake (const MWWorld::Ptr& object) : Action (true, object) {}
void ActionTake::executeImp (const Ptr& actor) void ActionTake::executeImp (const Ptr& actor)
{ {
@ -20,10 +20,8 @@ namespace MWWorld
// insert into player's inventory // insert into player's inventory
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPtr ("player", true); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPtr ("player", true);
MWWorld::Class::get (player).getContainerStore (player).add (mObject); MWWorld::Class::get (player).getContainerStore (player).add (getTarget());
// remove from world, if the item is currently in the world (it could also be in a container) MWBase::Environment::get().getWorld()->deleteObject (getTarget());
if (mObject.isInCell())
MWBase::Environment::get().getWorld()->deleteObject (mObject);
} }
} }

View File

@ -8,8 +8,6 @@ namespace MWWorld
{ {
class ActionTake : public Action class ActionTake : public Action
{ {
MWWorld::Ptr mObject;
virtual void executeImp (const Ptr& actor); virtual void executeImp (const Ptr& actor);
public: public:

View File

@ -6,10 +6,10 @@
namespace MWWorld namespace MWWorld
{ {
ActionTalk::ActionTalk (const Ptr& actor) : mActor (actor) {} ActionTalk::ActionTalk (const Ptr& actor) : Action (false, actor) {}
void ActionTalk::executeImp (const Ptr& actor) void ActionTalk::executeImp (const Ptr& actor)
{ {
MWBase::Environment::get().getDialogueManager()->startDialogue (mActor); MWBase::Environment::get().getDialogueManager()->startDialogue (getTarget());
} }
} }

View File

@ -8,8 +8,6 @@ namespace MWWorld
{ {
class ActionTalk : public Action class ActionTalk : public Action
{ {
Ptr mActor;
virtual void executeImp (const Ptr& actor); virtual void executeImp (const Ptr& actor);
public: public:

View File

@ -75,6 +75,9 @@ namespace MWWorld
std::string RefData::getHandle() std::string RefData::getHandle()
{ {
if (!mBaseNode)
return "";
return mBaseNode->getName(); return mBaseNode->getName();
} }