openmw-tes3coop/apps/openmw/mwclass/probe.cpp

147 lines
4.6 KiB
C++
Raw Normal View History

2010-08-03 13:24:44 +00:00
#include "probe.hpp"
#include <components/esm/loadlocks.hpp>
2010-08-03 15:11:41 +00:00
#include <components/esm_store/cell_store.hpp>
#include "../mwworld/ptr.hpp"
2010-08-07 18:25:17 +00:00
#include "../mwworld/actiontake.hpp"
#include "../mwworld/environment.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwworld/world.hpp"
#include "../mwgui/window_manager.hpp"
#include "../mwgui/tooltips.hpp"
2010-08-03 15:11:41 +00:00
#include "../mwrender/objects.hpp"
#include "../mwsound/soundmanager.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
{
ESMS::LiveCellRef<ESM::Probe, MWWorld::RefData> *ref =
ptr.get<ESM::Probe>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if (!model.empty())
{
MWRender::Objects& objects = renderingInterface.getObjects();
2011-11-12 04:01:12 +00:00
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
objects.insertMesh(ptr, "meshes\\" + model);
}
}
2011-11-12 04:01:12 +00:00
void Probe::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const
2010-08-03 15:11:41 +00:00
{
ESMS::LiveCellRef<ESM::Probe, MWWorld::RefData> *ref =
ptr.get<ESM::Probe>();
2011-11-12 04:01:12 +00:00
const std::string &model = ref->base->model;
assert (ref->base != NULL);
if(!model.empty()){
2011-11-18 00:38:52 +00:00
physics.insertObjectPhysics(ptr, "meshes\\" + model);
2011-11-12 04:01:12 +00:00
}
2010-08-03 15:11:41 +00:00
}
std::string Probe::getName (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Probe, MWWorld::RefData> *ref =
ptr.get<ESM::Probe>();
return ref->base->name;
}
2010-08-07 18:25:17 +00:00
boost::shared_ptr<MWWorld::Action> Probe::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const
{
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, MWSound::Play_NoTrack);
2010-08-07 18:25:17 +00:00
return boost::shared_ptr<MWWorld::Action> (
new MWWorld::ActionTake (ptr));
}
std::string Probe::getScript (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Probe, MWWorld::RefData> *ref =
ptr.get<ESM::Probe>();
return ref->base->script;
}
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
{
ESMS::LiveCellRef<ESM::Probe, MWWorld::RefData> *ref =
ptr.get<ESM::Probe>();
return ref->base->data.value;
}
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 MWWorld::Environment& environment) const
{
return std::string("Item Probe Up");
}
std::string Probe::getDownSoundId (const MWWorld::Ptr& ptr, const MWWorld::Environment& environment) const
{
return std::string("Item Probe Down");
}
bool Probe::hasToolTip (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Probe, MWWorld::RefData> *ref =
ptr.get<ESM::Probe>();
return (ref->base->name != "");
}
MWGui::ToolTipInfo Probe::getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const
{
ESMS::LiveCellRef<ESM::Probe, MWWorld::RefData> *ref =
ptr.get<ESM::Probe>();
MWGui::ToolTipInfo info;
info.caption = ref->base->name;
info.icon = ref->base->icon;
std::string text;
/// \todo store remaining uses somewhere
text += "\n" + environment.mWorld->getStore().gameSettings.search("sUses")->str + ": " + MWGui::ToolTips::toString(ref->base->data.uses);
text += "\n" + environment.mWorld->getStore().gameSettings.search("sQuality")->str + ": " + MWGui::ToolTips::toString(ref->base->data.quality);
text += "\n" + environment.mWorld->getStore().gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight);
text += MWGui::ToolTips::getValueString(ref->base->data.value, environment.mWorld->getStore().gameSettings.search("sValue")->str);
if (environment.mWindowManager->getFullHelp()) {
text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner");
text += MWGui::ToolTips::getMiscString(ref->base->script, "Script");
}
info.text = text;
return info;
}
2010-08-03 13:24:44 +00:00
}