1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 21:19:57 +00:00
openmw-tes3mp/apps/openmw/mwclass/activator.cpp

139 lines
4.2 KiB
C++
Raw Normal View History

2010-08-03 11:03:08 +00:00
#include "activator.hpp"
#include <components/esm/loadacti.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"
2013-08-28 18:36:22 +00:00
#include "../mwbase/world.hpp"
2010-08-03 15:11:41 +00:00
#include "../mwworld//cellstore.hpp"
2010-08-03 15:11:41 +00:00
#include "../mwworld/ptr.hpp"
#include "../mwworld/physicssystem.hpp"
2013-08-28 18:36:22 +00:00
#include "../mwworld/action.hpp"
#include "../mwworld/failedaction.hpp"
#include "../mwworld/nullaction.hpp"
#include "../mwrender/actors.hpp"
#include "../mwrender/renderinginterface.hpp"
#include "../mwgui/tooltips.hpp"
2013-08-28 18:36:22 +00:00
#include "../mwmechanics/npcstats.hpp"
namespace MWClass
2010-08-03 11:03:08 +00:00
{
std::string Activator::getId (const MWWorld::Ptr& ptr) const
{
return ptr.get<ESM::Activator>()->mBase->mId;
}
2013-08-28 18:36:22 +00:00
void Activator::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::Actors& actors = renderingInterface.getActors();
actors.insertActivator(ptr);
}
}
void Activator::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);
MWBase::Environment::get().getMechanicsManager()->add(ptr);
2012-07-24 16:22:11 +00:00
}
2012-07-24 16:22:11 +00:00
std::string Activator::getModel(const MWWorld::Ptr &ptr) const
2011-11-12 04:01:12 +00:00
{
MWWorld::LiveCellRef<ESM::Activator> *ref =
2011-11-12 04:01:12 +00:00
ptr.get<ESM::Activator>();
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 Activator::getName (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Activator> *ref =
2010-08-03 15:11:41 +00:00
ptr.get<ESM::Activator>();
2012-11-05 12:07:59 +00:00
return ref->mBase->mName;
2010-08-03 15:11:41 +00:00
}
std::string Activator::getScript (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Activator> *ref =
ptr.get<ESM::Activator>();
2012-11-05 12:07:59 +00:00
return ref->mBase->mScript;
}
2010-08-03 11:03:08 +00:00
void Activator::registerSelf()
{
boost::shared_ptr<Class> instance (new Activator);
registerClass (typeid (ESM::Activator).name(), instance);
}
bool Activator::hasToolTip (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Activator> *ref =
ptr.get<ESM::Activator>();
2012-11-05 12:07:59 +00:00
return (ref->mBase->mName != "");
}
MWGui::ToolTipInfo Activator::getToolTipInfo (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Activator> *ref =
ptr.get<ESM::Activator>();
MWGui::ToolTipInfo info;
2012-11-05 12:07:59 +00:00
info.caption = ref->mBase->mName + MWGui::ToolTips::getCountString(ptr.getRefData().getCount());
std::string text;
if (MWBase::Environment::get().getWindowManager()->getFullHelp())
2014-01-07 19:24:01 +00:00
{
text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getOwner(), "Owner");
text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getFaction(), "Faction");
2012-11-05 12:07:59 +00:00
text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script");
2014-01-07 19:24:01 +00:00
}
info.text = text;
return info;
}
2013-08-28 18:36:22 +00:00
boost::shared_ptr<MWWorld::Action> Activator::activate(const MWWorld::Ptr &ptr, const MWWorld::Ptr &actor) const
{
if(actor.getClass().isNpc() && actor.getClass().getNpcStats(actor).isWerewolf())
2013-08-28 18:36:22 +00:00
{
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
const ESM::Sound *sound = store.get<ESM::Sound>().searchRandom("WolfActivator");
boost::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction("#{sWerewolfRefusal}"));
if(sound) action->setSound(sound->mId);
return action;
}
return boost::shared_ptr<MWWorld::Action>(new MWWorld::NullAction);
}
MWWorld::Ptr
Activator::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::Activator> *ref =
ptr.get<ESM::Activator>();
2014-02-23 20:21:27 +00:00
return MWWorld::Ptr(&cell.get<ESM::Activator>().insert(*ref), &cell);
}
2010-08-03 11:03:08 +00:00
}