Commit 89c7f5bc authored by Chris Robinson's avatar Chris Robinson

Handle object activation as a werewolf

parent 6110a0ee
......@@ -60,15 +60,7 @@ namespace MWClass
boost::shared_ptr<MWWorld::Action> Apparatus::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor) const
{
if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction ());
boost::shared_ptr<MWWorld::Action> action(
new MWWorld::ActionTake (ptr));
action->setSound(getUpSoundId(ptr));
return action;
return defaultItemActivate(ptr, actor);
}
std::string Apparatus::getScript (const MWWorld::Ptr& ptr) const
......
......@@ -65,14 +65,7 @@ namespace MWClass
boost::shared_ptr<MWWorld::Action> Armor::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor) const
{
if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction ());
boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTake (ptr));
action->setSound(getUpSoundId(ptr));
return action;
return defaultItemActivate(ptr, actor);
}
bool Armor::hasItemHealth (const MWWorld::Ptr& ptr) const
......
......@@ -9,6 +9,7 @@
#include "../mwworld/ptr.hpp"
#include "../mwworld/actionread.hpp"
#include "../mwworld/failedaction.hpp"
#include "../mwworld/cellstore.hpp"
#include "../mwworld/physicssystem.hpp"
......@@ -17,6 +18,8 @@
#include "../mwgui/tooltips.hpp"
#include "../mwmechanics/npcstats.hpp"
namespace MWClass
{
void Book::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
......@@ -58,8 +61,15 @@ namespace MWClass
boost::shared_ptr<MWWorld::Action> Book::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor) const
{
return boost::shared_ptr<MWWorld::Action> (
new MWWorld::ActionRead (ptr));
if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf())
{
boost::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction("#{sWerewolfRefusal}"));
// FIXME: Randomize using all WolfItem* sound records
action->setSound("WolfItem1");
return action;
}
return boost::shared_ptr<MWWorld::Action>(new MWWorld::ActionRead(ptr));
}
std::string Book::getScript (const MWWorld::Ptr& ptr) const
......
......@@ -60,16 +60,9 @@ namespace MWClass
}
boost::shared_ptr<MWWorld::Action> Clothing::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor) const
const MWWorld::Ptr& actor) const
{
if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction ());
boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTake (ptr));
action->setSound(getUpSoundId(ptr));
return action;
return defaultItemActivate(ptr, actor);
}
std::string Clothing::getScript (const MWWorld::Ptr& ptr) const
......
......@@ -23,6 +23,8 @@
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp"
#include "../mwmechanics/npcstats.hpp"
namespace
{
struct CustomData : public MWWorld::CustomData
......@@ -91,6 +93,14 @@ namespace MWClass
if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction ());
if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf())
{
boost::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction("#{sWerewolfRefusal}"));
// FIXME: Randomize using all WolfContainer* sound records
action->setSound("WolfContainer1");
return action;
}
const std::string lockedSound = "LockedChest";
const std::string trapActivationSound = "Disarm Trap Fail";
......
......@@ -16,6 +16,7 @@
#include "../mwworld/ptr.hpp"
#include "../mwworld/actiontalk.hpp"
#include "../mwworld/actionopen.hpp"
#include "../mwworld/failedaction.hpp"
#include "../mwworld/customdata.hpp"
#include "../mwworld/containerstore.hpp"
#include "../mwworld/physicssystem.hpp"
......@@ -25,6 +26,8 @@
#include "../mwgui/tooltips.hpp"
#include "../mwmechanics/npcstats.hpp"
namespace
{
struct CustomData : public MWWorld::CustomData
......@@ -222,10 +225,17 @@ namespace MWClass
boost::shared_ptr<MWWorld::Action> Creature::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor) const
{
if (MWWorld::Class::get (ptr).getCreatureStats (ptr).isDead())
return boost::shared_ptr<MWWorld::Action> (new MWWorld::ActionOpen(ptr, true));
else
return boost::shared_ptr<MWWorld::Action> (new MWWorld::ActionTalk (ptr));
if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf())
{
boost::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction("#{sWerewolfRefusal}"));
// FIXME: Randomize using all WolfCreature* sound records
action->setSound("WolfCreature1");
return action;
}
if(getCreatureStats(ptr).isDead())
return boost::shared_ptr<MWWorld::Action>(new MWWorld::ActionOpen(ptr, true));
return boost::shared_ptr<MWWorld::Action>(new MWWorld::ActionTalk(ptr));
}
MWWorld::ContainerStore& Creature::getContainerStore (const MWWorld::Ptr& ptr)
......
......@@ -71,14 +71,7 @@ namespace MWClass
boost::shared_ptr<MWWorld::Action> Ingredient::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor) const
{
if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction ());
boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTake (ptr));
action->setSound(getUpSoundId(ptr));
return action;
return defaultItemActivate(ptr, actor);
}
std::string Ingredient::getScript (const MWWorld::Ptr& ptr) const
......
......@@ -76,20 +76,14 @@ namespace MWClass
boost::shared_ptr<MWWorld::Action> Light::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor) const
{
if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction ());
if(!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
return boost::shared_ptr<MWWorld::Action>(new MWWorld::NullAction());
MWWorld::LiveCellRef<ESM::Light> *ref =
ptr.get<ESM::Light>();
if (!(ref->mBase->mData.mFlags & ESM::Light::Carry))
return boost::shared_ptr<MWWorld::Action> (new MWWorld::FailedAction);
boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTake (ptr));
MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
if(!(ref->mBase->mData.mFlags&ESM::Light::Carry))
return boost::shared_ptr<MWWorld::Action>(new MWWorld::FailedAction());
action->setSound(getUpSoundId(ptr));
return action;
return defaultItemActivate(ptr, actor);
}
std::string Light::getScript (const MWWorld::Ptr& ptr) const
......
......@@ -61,14 +61,7 @@ namespace MWClass
boost::shared_ptr<MWWorld::Action> Lockpick::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor) const
{
if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction ());
boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTake (ptr));
action->setSound(getUpSoundId(ptr));
return action;
return defaultItemActivate(ptr, actor);
}
std::string Lockpick::getScript (const MWWorld::Ptr& ptr) const
......
......@@ -77,14 +77,7 @@ namespace MWClass
boost::shared_ptr<MWWorld::Action> Miscellaneous::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor) const
{
if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction ());
boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTake (ptr));
action->setSound(getUpSoundId(ptr));
return action;
return defaultItemActivate(ptr, actor);
}
std::string Miscellaneous::getScript (const MWWorld::Ptr& ptr) const
......
......@@ -23,6 +23,7 @@
#include "../mwworld/ptr.hpp"
#include "../mwworld/actiontalk.hpp"
#include "../mwworld/actionopen.hpp"
#include "../mwworld/failedaction.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwworld/customdata.hpp"
#include "../mwworld/physicssystem.hpp"
......@@ -562,12 +563,18 @@ namespace MWClass
boost::shared_ptr<MWWorld::Action> Npc::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor) const
{
if (MWWorld::Class::get (ptr).getCreatureStats (ptr).isDead())
return boost::shared_ptr<MWWorld::Action> (new MWWorld::ActionOpen(ptr, true));
else if (MWWorld::Class::get(actor).getStance(actor, MWWorld::Class::Sneak))
return boost::shared_ptr<MWWorld::Action> (new MWWorld::ActionOpen(ptr)); // stealing
else
return boost::shared_ptr<MWWorld::Action> (new MWWorld::ActionTalk (ptr));
if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf())
{
boost::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction("#{sWerewolfRefusal}"));
// FIXME: Randomize using all WolfNPC* sound records
action->setSound("WolfNPC1");
return action;
}
if(getCreatureStats(ptr).isDead())
return boost::shared_ptr<MWWorld::Action>(new MWWorld::ActionOpen(ptr, true));
if(get(actor).getStance(actor, MWWorld::Class::Sneak))
return boost::shared_ptr<MWWorld::Action>(new MWWorld::ActionOpen(ptr)); // stealing
return boost::shared_ptr<MWWorld::Action>(new MWWorld::ActionTalk(ptr));
}
MWWorld::ContainerStore& Npc::getContainerStore (const MWWorld::Ptr& ptr)
......
......@@ -144,8 +144,11 @@ namespace MWClass
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
virtual bool
isActor() const {
virtual bool isActor() const {
return true;
}
virtual bool isNpc() const {
return true;
}
};
......
......@@ -63,15 +63,7 @@ namespace MWClass
boost::shared_ptr<MWWorld::Action> Potion::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor) const
{
if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction ());
boost::shared_ptr<MWWorld::Action> action(
new MWWorld::ActionTake (ptr));
action->setSound (getUpSoundId(ptr));
return action;
return defaultItemActivate(ptr, actor);
}
std::string Potion::getScript (const MWWorld::Ptr& ptr) const
......
......@@ -60,14 +60,7 @@ namespace MWClass
boost::shared_ptr<MWWorld::Action> Probe::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor) const
{
if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction ());
boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTake (ptr));
action->setSound(getUpSoundId(ptr));
return action;
return defaultItemActivate(ptr, actor);
}
std::string Probe::getScript (const MWWorld::Ptr& ptr) const
......
......@@ -60,14 +60,7 @@ namespace MWClass
boost::shared_ptr<MWWorld::Action> Repair::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor) const
{
if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction ());
boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTake (ptr));
action->setSound(getUpSoundId(ptr));
return action;
return defaultItemActivate(ptr, actor);
}
std::string Repair::getScript (const MWWorld::Ptr& ptr) const
......
......@@ -68,14 +68,7 @@ namespace MWClass
boost::shared_ptr<MWWorld::Action> Weapon::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor) const
{
if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction ());
boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTake (ptr));
action->setSound(getUpSoundId(ptr));
return action;
return defaultItemActivate(ptr, actor);
}
bool Weapon::hasItemHealth (const MWWorld::Ptr& ptr) const
......
......@@ -7,13 +7,20 @@
#include <components/esm/defs.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
#include "ptr.hpp"
#include "refdata.hpp"
#include "nullaction.hpp"
#include "failedaction.hpp"
#include "actiontake.hpp"
#include "containerstore.hpp"
#include "../mwgui/tooltips.hpp"
#include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/magiceffects.hpp"
namespace MWWorld
......@@ -304,6 +311,25 @@ namespace MWWorld
{
}
boost::shared_ptr<Action> Class::defaultItemActivate(const Ptr &ptr, const Ptr &actor) const
{
if(!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
return boost::shared_ptr<Action>(new NullAction());
if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf())
{
boost::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction("#{sWerewolfRefusal}"));
// FIXME: Randomize using all WolfItem* sound records
action->setSound("WolfItem1");
return action;
}
boost::shared_ptr<MWWorld::Action> action(new ActionTake(ptr));
action->setSound(getUpSoundId(ptr));
return action;
}
MWWorld::Ptr
Class::copyToCellImpl(const Ptr &ptr, CellStore &cell) const
{
......
......@@ -57,6 +57,9 @@ namespace MWWorld
Class();
boost::shared_ptr<Action> defaultItemActivate(const Ptr &ptr, const Ptr &actor) const;
///< Generate default action for activating inventory items
virtual Ptr copyToCellImpl(const Ptr &ptr, CellStore &cell) const;
public:
......@@ -285,9 +288,12 @@ namespace MWWorld
virtual Ptr
copyToCell(const Ptr &ptr, CellStore &cell, const ESM::Position &pos) const;
virtual bool
isActor() const {
virtual bool isActor() const {
return false;
}
virtual bool isNpc() const {
return false;
}
};
......
......@@ -7,15 +7,13 @@
namespace MWWorld
{
FailedAction::FailedAction (const std::string& msg) : Action (false), message(msg)
FailedAction::FailedAction(const std::string &msg)
: Action(false), mMessage(msg)
{ }
void FailedAction::executeImp (const Ptr& actor)
void FailedAction::executeImp(const Ptr &actor)
{
if ( actor.getRefData().getHandle()=="player" && !(message.empty()))
{
MWBase::Environment::get().getWindowManager() ->messageBox(message);
}
if(actor.getRefData().getHandle() == "player" && !mMessage.empty())
MWBase::Environment::get().getWindowManager()->messageBox(mMessage);
}
}
......@@ -8,12 +8,12 @@ namespace MWWorld
{
class FailedAction : public Action
{
std::string message;
virtual void executeImp (const Ptr& actor);
std::string mMessage;
public:
FailedAction (const std::string& message = std::string());
virtual void executeImp(const Ptr &actor);
public:
FailedAction(const std::string &message = std::string());
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment