2010-08-03 15:24:44 +02:00
|
|
|
|
|
|
|
#include "potion.hpp"
|
|
|
|
|
|
|
|
#include <components/esm/loadalch.hpp>
|
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-07-03 12:30:50 +02:00
|
|
|
#include "../mwbase/world.hpp"
|
2012-08-12 18:11:09 +02:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2012-04-23 15:27:03 +02:00
|
|
|
|
2010-08-03 17:11:41 +02:00
|
|
|
#include "../mwworld/ptr.hpp"
|
2010-08-07 20:25:17 +02:00
|
|
|
#include "../mwworld/actiontake.hpp"
|
2012-07-13 13:09:22 +02:00
|
|
|
#include "../mwworld/actionapply.hpp"
|
2012-06-29 16:48:50 +02:00
|
|
|
#include "../mwworld/cellstore.hpp"
|
2012-07-03 13:15:20 +02:00
|
|
|
#include "../mwworld/physicssystem.hpp"
|
2012-07-13 15:51:57 +02:00
|
|
|
#include "../mwworld/player.hpp"
|
2012-04-16 22:58:16 +02:00
|
|
|
|
|
|
|
#include "../mwgui/tooltips.hpp"
|
2010-08-03 17:11:41 +02:00
|
|
|
|
2012-01-27 15:11:02 +01:00
|
|
|
#include "../mwrender/objects.hpp"
|
2012-07-03 13:15:20 +02:00
|
|
|
#include "../mwrender/renderinginterface.hpp"
|
2010-08-14 10:02:54 +02:00
|
|
|
|
2010-08-03 15:24:44 +02:00
|
|
|
namespace MWClass
|
|
|
|
{
|
2011-11-11 23:01:12 -05:00
|
|
|
void Potion::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
|
2010-08-14 10:02:54 +02:00
|
|
|
{
|
2012-07-24 20:22:11 +04:00
|
|
|
const std::string model = getModel(ptr);
|
|
|
|
if (!model.empty()) {
|
2011-11-19 01:01:19 -05:00
|
|
|
MWRender::Objects& objects = renderingInterface.getObjects();
|
2011-11-11 23:01:12 -05:00
|
|
|
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
|
2012-07-24 20:22:11 +04:00
|
|
|
objects.insertMesh(ptr, model);
|
2010-08-14 10:02:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
void Potion::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
|
2012-07-24 20:22:11 +04:00
|
|
|
{
|
|
|
|
const std::string model = getModel(ptr);
|
|
|
|
if(!model.empty()) {
|
|
|
|
physics.insertObjectPhysics(ptr, model);
|
|
|
|
}
|
|
|
|
}
|
2012-07-27 12:00:10 +02:00
|
|
|
|
2012-07-24 20:22:11 +04:00
|
|
|
std::string Potion::getModel(const MWWorld::Ptr &ptr) const
|
2011-11-11 23:01:12 -05:00
|
|
|
{
|
2012-06-29 18:54:23 +02:00
|
|
|
MWWorld::LiveCellRef<ESM::Potion> *ref =
|
2011-11-11 23:01:12 -05:00
|
|
|
ptr.get<ESM::Potion>();
|
2012-07-24 20:22:11 +04:00
|
|
|
assert(ref->base != NULL);
|
2011-11-11 23:01:12 -05:00
|
|
|
|
|
|
|
const std::string &model = ref->base->model;
|
2012-07-24 20:22:11 +04:00
|
|
|
if (!model.empty()) {
|
|
|
|
return "meshes\\" + model;
|
2011-11-11 23:01:12 -05:00
|
|
|
}
|
2012-07-24 20:22:11 +04:00
|
|
|
return "";
|
2011-11-11 23:01:12 -05:00
|
|
|
}
|
|
|
|
|
2010-08-03 17:11:41 +02:00
|
|
|
std::string Potion::getName (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 18:54:23 +02:00
|
|
|
MWWorld::LiveCellRef<ESM::Potion> *ref =
|
2010-08-03 17:11:41 +02:00
|
|
|
ptr.get<ESM::Potion>();
|
|
|
|
|
|
|
|
return ref->base->name;
|
|
|
|
}
|
|
|
|
|
2010-08-07 20:25:17 +02:00
|
|
|
boost::shared_ptr<MWWorld::Action> Potion::activate (const MWWorld::Ptr& ptr,
|
2012-04-23 15:27:03 +02:00
|
|
|
const MWWorld::Ptr& actor) const
|
2010-08-07 20:25:17 +02:00
|
|
|
{
|
2012-08-19 20:11:50 -03:00
|
|
|
boost::shared_ptr<MWWorld::Action> action(
|
|
|
|
new MWWorld::ActionTake (ptr));
|
2012-03-13 20:01:55 +02:00
|
|
|
|
2012-08-19 20:11:50 -03:00
|
|
|
action->setSound (getUpSoundId(ptr));
|
|
|
|
|
|
|
|
return action;
|
2010-08-07 20:25:17 +02:00
|
|
|
}
|
|
|
|
|
2010-08-05 15:40:03 +02:00
|
|
|
std::string Potion::getScript (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 18:54:23 +02:00
|
|
|
MWWorld::LiveCellRef<ESM::Potion> *ref =
|
2010-08-05 15:40:03 +02:00
|
|
|
ptr.get<ESM::Potion>();
|
|
|
|
|
|
|
|
return ref->base->script;
|
|
|
|
}
|
|
|
|
|
2012-04-07 19:53:49 +02:00
|
|
|
int Potion::getValue (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 18:54:23 +02:00
|
|
|
MWWorld::LiveCellRef<ESM::Potion> *ref =
|
2012-04-07 19:53:49 +02:00
|
|
|
ptr.get<ESM::Potion>();
|
|
|
|
|
|
|
|
return ref->base->data.value;
|
|
|
|
}
|
|
|
|
|
2010-08-03 15:24:44 +02:00
|
|
|
void Potion::registerSelf()
|
|
|
|
{
|
|
|
|
boost::shared_ptr<Class> instance (new Potion);
|
|
|
|
|
|
|
|
registerClass (typeid (ESM::Potion).name(), instance);
|
|
|
|
}
|
2012-03-13 20:01:55 +02:00
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
std::string Potion::getUpSoundId (const MWWorld::Ptr& ptr) const
|
2012-03-13 20:01:55 +02:00
|
|
|
{
|
|
|
|
return std::string("Item Potion Up");
|
|
|
|
}
|
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
std::string Potion::getDownSoundId (const MWWorld::Ptr& ptr) const
|
2012-03-13 20:01:55 +02:00
|
|
|
{
|
|
|
|
return std::string("Item Potion Down");
|
|
|
|
}
|
2012-04-15 17:52:39 +02:00
|
|
|
|
|
|
|
std::string Potion::getInventoryIcon (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 18:54:23 +02:00
|
|
|
MWWorld::LiveCellRef<ESM::Potion> *ref =
|
2012-04-15 17:52:39 +02:00
|
|
|
ptr.get<ESM::Potion>();
|
|
|
|
|
|
|
|
return ref->base->icon;
|
|
|
|
}
|
2012-05-11 10:40:40 +02:00
|
|
|
|
2012-04-16 22:58:16 +02:00
|
|
|
bool Potion::hasToolTip (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 18:54:23 +02:00
|
|
|
MWWorld::LiveCellRef<ESM::Potion> *ref =
|
2012-04-16 22:58:16 +02:00
|
|
|
ptr.get<ESM::Potion>();
|
|
|
|
|
|
|
|
return (ref->base->name != "");
|
|
|
|
}
|
|
|
|
|
2012-04-24 02:02:03 +02:00
|
|
|
MWGui::ToolTipInfo Potion::getToolTipInfo (const MWWorld::Ptr& ptr) const
|
2012-04-16 22:58:16 +02:00
|
|
|
{
|
2012-06-29 18:54:23 +02:00
|
|
|
MWWorld::LiveCellRef<ESM::Potion> *ref =
|
2012-04-16 22:58:16 +02:00
|
|
|
ptr.get<ESM::Potion>();
|
|
|
|
|
|
|
|
MWGui::ToolTipInfo info;
|
2012-05-12 13:46:03 +02:00
|
|
|
info.caption = ref->base->name + MWGui::ToolTips::getCountString(ptr.getRefData().getCount());
|
2012-04-16 22:58:16 +02:00
|
|
|
info.icon = ref->base->icon;
|
|
|
|
|
2012-04-24 02:02:03 +02:00
|
|
|
const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
|
|
|
|
|
2012-04-16 22:58:16 +02:00
|
|
|
std::string text;
|
|
|
|
|
2012-04-24 02:02:03 +02:00
|
|
|
text += "\n" + store.gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight);
|
|
|
|
text += MWGui::ToolTips::getValueString(ref->base->data.value, store.gameSettings.search("sValue")->str);
|
2012-04-16 22:58:16 +02:00
|
|
|
|
2012-05-24 14:47:57 +02:00
|
|
|
info.effects = MWGui::Widgets::MWEffectList::effectListFromESM(&ref->base->effects);
|
2012-04-30 01:08:10 +02:00
|
|
|
|
2012-04-24 02:02:03 +02:00
|
|
|
if (MWBase::Environment::get().getWindowManager()->getFullHelp()) {
|
2012-04-16 22:58:16 +02:00
|
|
|
text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner");
|
|
|
|
text += MWGui::ToolTips::getMiscString(ref->base->script, "Script");
|
|
|
|
}
|
|
|
|
|
|
|
|
info.text = text;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
2012-07-13 13:09:22 +02:00
|
|
|
|
|
|
|
boost::shared_ptr<MWWorld::Action> Potion::use (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
MWWorld::LiveCellRef<ESM::Potion> *ref =
|
|
|
|
ptr.get<ESM::Potion>();
|
|
|
|
|
|
|
|
ptr.getRefData().setCount (ptr.getRefData().getCount()-1);
|
|
|
|
|
2012-07-13 15:51:57 +02:00
|
|
|
MWWorld::Ptr actor = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
|
|
|
|
2012-07-27 12:27:22 +02:00
|
|
|
boost::shared_ptr<MWWorld::Action> action (
|
2012-07-27 12:00:10 +02:00
|
|
|
new MWWorld::ActionApply (actor, ref->base->mId));
|
2012-07-27 12:27:22 +02:00
|
|
|
|
|
|
|
action->setSound ("Drink");
|
|
|
|
|
|
|
|
return action;
|
2012-07-13 13:09:22 +02:00
|
|
|
}
|
2012-07-25 17:18:17 +04:00
|
|
|
|
|
|
|
MWWorld::Ptr
|
2012-07-26 16:14:11 +04:00
|
|
|
Potion::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
|
2012-07-25 17:18:17 +04:00
|
|
|
{
|
|
|
|
MWWorld::LiveCellRef<ESM::Potion> *ref =
|
|
|
|
ptr.get<ESM::Potion>();
|
|
|
|
|
|
|
|
return MWWorld::Ptr(&cell.potions.insert(*ref), &cell);
|
|
|
|
}
|
2010-08-03 15:24:44 +02:00
|
|
|
}
|