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

138 lines
4 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"
#include "../mwworld/esmstore.hpp"
2010-08-03 15:11:41 +00:00
#include "../mwworld/ptr.hpp"
2013-08-28 18:36:22 +00:00
#include "../mwworld/action.hpp"
#include "../mwworld/failedaction.hpp"
#include "../mwworld/nullaction.hpp"
#include "../mwphysics/physicssystem.hpp"
#include "../mwrender/objects.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
{
void Activator::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
2012-07-24 16:22:11 +00:00
if (!model.empty()) {
renderingInterface.getObjects().insertModel(ptr, model, true);
}
}
void Activator::insertObject(const MWWorld::Ptr& ptr, const std::string& model, MWPhysics::PhysicsSystem& physics) const
2012-07-24 16:22:11 +00:00
{
if(!model.empty())
physics.addObject(ptr, model);
2012-07-24 16:22:11 +00:00
}
2015-12-18 14:51:05 +00:00
std::string Activator::getModel(const MWWorld::ConstPtr &ptr) const
2011-11-12 04:01:12 +00:00
{
2015-12-18 14:51:05 +00:00
const MWWorld::LiveCellRef<ESM::Activator> *ref = ptr.get<ESM::Activator>();
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
}
bool Activator::isActivator() const
{
return true;
}
bool Activator::useAnim() const
{
return true;
}
std::string Activator::getName (const MWWorld::ConstPtr& ptr) const
2010-08-03 15:11:41 +00:00
{
const MWWorld::LiveCellRef<ESM::Activator> *ref = ptr.get<ESM::Activator>();
2010-08-03 15:11:41 +00:00
2012-11-05 12:07:59 +00:00
return ref->mBase->mName;
2010-08-03 15:11:41 +00:00
}
2015-12-17 23:12:03 +00:00
std::string Activator::getScript (const MWWorld::ConstPtr& ptr) const
{
2015-12-17 23:12:03 +00:00
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()
{
std::shared_ptr<Class> instance (new Activator);
2010-08-03 11:03:08 +00:00
registerClass (typeid (ESM::Activator).name(), instance);
}
2015-12-19 15:13:00 +00:00
bool Activator::hasToolTip (const MWWorld::ConstPtr& ptr) const
{
2015-12-19 15:13:00 +00:00
const MWWorld::LiveCellRef<ESM::Activator> *ref = ptr.get<ESM::Activator>();
2012-11-05 12:07:59 +00:00
return (ref->mBase->mName != "");
}
bool Activator::allowTelekinesis(const MWWorld::ConstPtr &ptr) const {
return false;
}
2015-12-19 15:29:07 +00:00
MWGui::ToolTipInfo Activator::getToolTipInfo (const MWWorld::ConstPtr& ptr, int count) const
{
const MWWorld::LiveCellRef<ESM::Activator> *ref = ptr.get<ESM::Activator>();
MWGui::ToolTipInfo info;
2015-12-19 15:29:07 +00:00
info.caption = ref->mBase->mName + MWGui::ToolTips::getCountString(count);
std::string text;
if (MWBase::Environment::get().getWindowManager()->getFullHelp())
2014-01-07 19:24:01 +00:00
{
text += MWGui::ToolTips::getCellRefString(ptr.getCellRef());
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
std::shared_ptr<MWWorld::Action> Activator::activate(const MWWorld::Ptr &ptr, const MWWorld::Ptr &actor) const
2013-08-28 18:36:22 +00:00
{
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");
std::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction("#{sWerewolfRefusal}"));
2013-08-28 18:36:22 +00:00
if(sound) action->setSound(sound->mId);
return action;
}
return std::shared_ptr<MWWorld::Action>(new MWWorld::NullAction);
2013-08-28 18:36:22 +00:00
}
2015-12-18 15:24:24 +00:00
MWWorld::Ptr Activator::copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const
{
2015-12-18 15:24:24 +00:00
const MWWorld::LiveCellRef<ESM::Activator> *ref = ptr.get<ESM::Activator>();
return MWWorld::Ptr(cell.insert(ref), &cell);
}
2010-08-03 11:03:08 +00:00
}