1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-12 03:36:32 +00:00
OpenMW/apps/openmw/mwclass/potion.cpp

210 lines
6.3 KiB
C++
Raw Normal View History

2010-08-03 13:24:44 +00:00
#include "potion.hpp"
#include <components/esm/loadalch.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/windowmanager.hpp"
2010-08-03 15:11:41 +00:00
#include "../mwworld/ptr.hpp"
2010-08-07 18:25:17 +00:00
#include "../mwworld/actiontake.hpp"
2012-07-13 11:09:22 +00:00
#include "../mwworld/actionapply.hpp"
#include "../mwworld/cellstore.hpp"
#include "../mwworld/physicssystem.hpp"
#include "../mwworld/player.hpp"
#include "../mwworld/nullaction.hpp"
#include "../mwgui/tooltips.hpp"
2010-08-03 15:11:41 +00:00
2012-01-27 14:11:02 +00:00
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp"
#include "../mwmechanics/npcstats.hpp"
2010-08-03 13:24:44 +00:00
namespace MWClass
{
2011-11-12 04:01:12 +00:00
void Potion::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
{
2012-07-24 16:22:11 +00:00
const std::string model = getModel(ptr);
if (!model.empty()) {
MWRender::Objects& objects = renderingInterface.getObjects();
2011-11-12 04:01:12 +00:00
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
2012-07-24 16:22:11 +00:00
objects.insertMesh(ptr, model);
}
}
void Potion::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
2012-07-24 16:22:11 +00:00
{
const std::string model = getModel(ptr);
if(!model.empty())
physics.addObject(ptr,true);
2012-07-24 16:22:11 +00:00
}
2012-07-27 10:00:10 +00:00
2012-07-24 16:22:11 +00:00
std::string Potion::getModel(const MWWorld::Ptr &ptr) const
2011-11-12 04:01:12 +00:00
{
MWWorld::LiveCellRef<ESM::Potion> *ref =
2011-11-12 04:01:12 +00:00
ptr.get<ESM::Potion>();
2012-11-05 12:07:59 +00:00
assert(ref->mBase != NULL);
2011-11-12 04:01:12 +00:00
2012-11-05 12:07:59 +00:00
const std::string &model = ref->mBase->mModel;
2012-07-24 16:22:11 +00:00
if (!model.empty()) {
return "meshes\\" + model;
2011-11-12 04:01:12 +00:00
}
2012-07-24 16:22:11 +00:00
return "";
2011-11-12 04:01:12 +00:00
}
2010-08-03 15:11:41 +00:00
std::string Potion::getName (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Potion> *ref =
2010-08-03 15:11:41 +00:00
ptr.get<ESM::Potion>();
2012-11-05 12:07:59 +00:00
return ref->mBase->mName;
2010-08-03 15:11:41 +00:00
}
2010-08-07 18:25:17 +00:00
boost::shared_ptr<MWWorld::Action> Potion::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor) const
2010-08-07 18:25:17 +00:00
{
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;
2010-08-07 18:25:17 +00:00
}
std::string Potion::getScript (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Potion> *ref =
ptr.get<ESM::Potion>();
2012-11-05 12:07:59 +00:00
return ref->mBase->mScript;
}
int Potion::getValue (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Potion> *ref =
ptr.get<ESM::Potion>();
2012-11-05 12:07:59 +00:00
return ref->mBase->mData.mValue;
}
2010-08-03 13:24:44 +00:00
void Potion::registerSelf()
{
boost::shared_ptr<Class> instance (new Potion);
registerClass (typeid (ESM::Potion).name(), instance);
}
std::string Potion::getUpSoundId (const MWWorld::Ptr& ptr) const
{
return std::string("Item Potion Up");
}
std::string Potion::getDownSoundId (const MWWorld::Ptr& ptr) const
{
return std::string("Item Potion Down");
}
2012-04-15 15:52:39 +00:00
std::string Potion::getInventoryIcon (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Potion> *ref =
2012-04-15 15:52:39 +00:00
ptr.get<ESM::Potion>();
2012-11-05 12:07:59 +00:00
return ref->mBase->mIcon;
2012-04-15 15:52:39 +00:00
}
bool Potion::hasToolTip (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Potion> *ref =
ptr.get<ESM::Potion>();
2012-11-05 12:07:59 +00:00
return (ref->mBase->mName != "");
}
MWGui::ToolTipInfo Potion::getToolTipInfo (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Potion> *ref =
ptr.get<ESM::Potion>();
MWGui::ToolTipInfo info;
2012-11-05 12:07:59 +00:00
info.caption = ref->mBase->mName + MWGui::ToolTips::getCountString(ptr.getRefData().getCount());
info.icon = ref->mBase->mIcon;
std::string text;
2012-11-05 12:07:59 +00:00
text += "\n#{sWeight}: " + MWGui::ToolTips::toString(ref->mBase->mData.mWeight);
text += MWGui::ToolTips::getValueString(ref->mBase->mData.mValue, "#{sValue}");
2012-11-05 12:07:59 +00:00
info.effects = MWGui::Widgets::MWEffectList::effectListFromESM(&ref->mBase->mEffects);
// hide effects the player doesnt know about
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayer ().getPlayer();
MWMechanics::NpcStats& npcStats = MWWorld::Class::get(player).getNpcStats (player);
int alchemySkill = npcStats.getSkill (ESM::Skill::Alchemy).getBase();
int i=0;
for (MWGui::Widgets::SpellEffectList::iterator it = info.effects.begin(); it != info.effects.end(); ++it)
{
/// \todo this code is duplicated from mwclass/ingredient, put it in a helper function
it->mKnown = ( (i == 0 && alchemySkill >= 15)
|| (i == 1 && alchemySkill >= 30)
|| (i == 2 && alchemySkill >= 45)
|| (i == 3 && alchemySkill >= 60));
++i;
}
info.isPotion = true;
if (MWBase::Environment::get().getWindowManager()->getFullHelp()) {
2012-11-05 12:07:59 +00:00
text += MWGui::ToolTips::getMiscString(ref->mRef.mOwner, "Owner");
text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script");
}
info.text = text;
return info;
}
2012-07-13 11:09:22 +00: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);
MWWorld::Ptr actor = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
boost::shared_ptr<MWWorld::Action> action (
2012-11-05 12:07:59 +00:00
new MWWorld::ActionApply (actor, ref->mBase->mId));
action->setSound ("Drink");
return action;
2012-07-13 11:09:22 +00:00
}
MWWorld::Ptr
Potion::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::Potion> *ref =
ptr.get<ESM::Potion>();
2012-11-05 12:07:59 +00:00
return MWWorld::Ptr(&cell.mPotions.insert(*ref), &cell);
}
bool Potion::canSell (const MWWorld::Ptr& item, int npcServices) const
{
return npcServices & ESM::NPC::Potions;
}
2013-05-11 16:38:27 +00:00
float Potion::getWeight(const MWWorld::Ptr &ptr) const
{
MWWorld::LiveCellRef<ESM::Potion> *ref =
ptr.get<ESM::Potion>();
return ref->mBase->mData.mWeight;
}
2010-08-03 13:24:44 +00:00
}