1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-09 21:42:13 +00:00
OpenMW/apps/openmw/mwclass/probe.cpp

194 lines
5.6 KiB
C++
Raw Normal View History

2010-08-03 13:24:44 +00:00
#include "probe.hpp"
2013-03-22 04:50:54 +00:00
#include <components/esm/loadprob.hpp>
2010-08-03 13:24:44 +00:00
#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"
#include "../mwworld/actionequip.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwworld/cellstore.hpp"
#include "../mwworld/physicssystem.hpp"
#include "../mwworld/nullaction.hpp"
#include "../mwgui/tooltips.hpp"
2010-08-03 15:11:41 +00:00
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp"
2010-08-03 13:24:44 +00:00
namespace MWClass
{
2011-11-12 04:01:12 +00:00
void Probe::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()) {
2013-08-07 10:51:57 +00:00
renderingInterface.getObjects().insertModel(ptr, model);
}
}
void Probe::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-24 16:22:11 +00:00
std::string Probe::getModel(const MWWorld::Ptr &ptr) const
2010-08-03 15:11:41 +00:00
{
MWWorld::LiveCellRef<ESM::Probe> *ref =
2010-08-03 15:11:41 +00:00
ptr.get<ESM::Probe>();
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 "";
2010-08-03 15:11:41 +00:00
}
std::string Probe::getName (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Probe> *ref =
ptr.get<ESM::Probe>();
2012-11-05 12:07:59 +00:00
return ref->mBase->mName;
}
2010-08-07 18:25:17 +00:00
boost::shared_ptr<MWWorld::Action> Probe::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor) const
2010-08-07 18:25:17 +00:00
{
2013-08-09 05:34:53 +00:00
return defaultItemActivate(ptr, actor);
2010-08-07 18:25:17 +00:00
}
std::string Probe::getScript (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Probe> *ref =
ptr.get<ESM::Probe>();
2012-11-05 12:07:59 +00:00
return ref->mBase->mScript;
}
std::pair<std::vector<int>, bool> Probe::getEquipmentSlots (const MWWorld::Ptr& ptr) const
{
std::vector<int> slots_;
slots_.push_back (int (MWWorld::InventoryStore::Slot_CarriedRight));
return std::make_pair (slots_, false);
}
int Probe::getValue (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Probe> *ref =
ptr.get<ESM::Probe>();
if (ptr.getCellRef().mCharge == -1)
return ref->mBase->mData.mValue;
else
return ref->mBase->mData.mValue * (static_cast<float>(ptr.getCellRef().mCharge) / getItemMaxHealth(ptr));
}
2010-08-03 13:24:44 +00:00
void Probe::registerSelf()
{
boost::shared_ptr<Class> instance (new Probe);
registerClass (typeid (ESM::Probe).name(), instance);
}
std::string Probe::getUpSoundId (const MWWorld::Ptr& ptr) const
{
return std::string("Item Probe Up");
}
std::string Probe::getDownSoundId (const MWWorld::Ptr& ptr) const
{
return std::string("Item Probe Down");
}
2012-04-15 15:52:39 +00:00
std::string Probe::getInventoryIcon (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Probe> *ref =
2012-04-15 15:52:39 +00:00
ptr.get<ESM::Probe>();
2012-11-05 12:07:59 +00:00
return ref->mBase->mIcon;
2012-04-15 15:52:39 +00:00
}
bool Probe::hasToolTip (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Probe> *ref =
ptr.get<ESM::Probe>();
2012-11-05 12:07:59 +00:00
return (ref->mBase->mName != "");
}
MWGui::ToolTipInfo Probe::getToolTipInfo (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Probe> *ref =
ptr.get<ESM::Probe>();
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;
int remainingUses = (ptr.getCellRef().mCharge != -1) ? ptr.getCellRef().mCharge : ref->mBase->mData.mUses;
text += "\n#{sUses}: " + MWGui::ToolTips::toString(remainingUses);
2012-11-05 12:07:59 +00:00
text += "\n#{sQuality}: " + MWGui::ToolTips::toString(ref->mBase->mData.mQuality);
text += "\n#{sWeight}: " + MWGui::ToolTips::toString(ref->mBase->mData.mWeight);
text += MWGui::ToolTips::getValueString(getValue(ptr), "#{sValue}");
if (MWBase::Environment::get().getWindowManager()->getFullHelp()) {
2012-11-05 12:07:59 +00:00
text += MWGui::ToolTips::getMiscString(ref->mRef.mOwner, "Owner");
2014-01-07 19:24:01 +00:00
text += MWGui::ToolTips::getMiscString(ref->mRef.mFaction, "Faction");
2012-11-05 12:07:59 +00:00
text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script");
}
info.text = text;
return info;
}
boost::shared_ptr<MWWorld::Action> Probe::use (const MWWorld::Ptr& ptr) const
{
boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionEquip(ptr));
action->setSound(getUpSoundId(ptr));
return action;
}
MWWorld::Ptr
Probe::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::Probe> *ref =
ptr.get<ESM::Probe>();
2014-02-23 20:21:27 +00:00
return MWWorld::Ptr(&cell.get<ESM::Probe>().insert(*ref), &cell);
}
bool Probe::canSell (const MWWorld::Ptr& item, int npcServices) const
{
return npcServices & ESM::NPC::Probes;
}
int Probe::getItemMaxHealth (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Probe> *ref =
ptr.get<ESM::Probe>();
return ref->mBase->mData.mUses;
}
2013-05-11 16:38:27 +00:00
float Probe::getWeight(const MWWorld::Ptr &ptr) const
{
MWWorld::LiveCellRef<ESM::Probe> *ref =
ptr.get<ESM::Probe>();
return ref->mBase->mData.mWeight;
}
2010-08-03 13:24:44 +00:00
}