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

240 lines
7.9 KiB
C++
Raw Normal View History

2010-08-03 13:24:44 +00:00
#include "light.hpp"
#include <components/esm/loadligh.hpp>
#include <components/esm/objectstate.hpp>
#include <components/settings/settings.hpp>
2010-08-03 13:24:44 +00:00
#include "../mwbase/environment.hpp"
#include "../mwbase/soundmanager.hpp"
#include "../mwbase/windowmanager.hpp"
2010-08-03 15:11:41 +00:00
#include "../mwworld/ptr.hpp"
#include "../mwworld/actionequip.hpp"
2010-08-07 18:25:17 +00:00
#include "../mwworld/nullaction.hpp"
2012-11-17 17:17:08 +00:00
#include "../mwworld/failedaction.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwworld/cellstore.hpp"
#include "../mwphysics/physicssystem.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"
2012-01-27 14:11:02 +00:00
2010-08-03 13:24:44 +00:00
namespace MWClass
{
void Light::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
MWWorld::LiveCellRef<ESM::Light> *ref =
ptr.get<ESM::Light>();
// Insert even if model is empty, so that the light is added
renderingInterface.getObjects().insertModel(ptr, model, true, !(ref->mBase->mData.mFlags & ESM::Light::OffDefault));
2011-11-12 04:01:12 +00:00
}
void Light::insertObject(const MWWorld::Ptr& ptr, const std::string& model, MWPhysics::PhysicsSystem& physics) const
2011-11-12 04:01:12 +00:00
{
MWWorld::LiveCellRef<ESM::Light> *ref =
2011-11-12 04:01:12 +00:00
ptr.get<ESM::Light>();
2018-10-09 06:21:12 +00:00
assert (ref->mBase != nullptr);
2012-07-24 16:22:11 +00:00
// TODO: add option somewhere to enable collision for placeable objects
2015-05-12 14:50:31 +00:00
if (!model.empty() && (ref->mBase->mData.mFlags & ESM::Light::Carry) == 0)
physics.addObject(ptr, model);
if (!ref->mBase->mSound.empty() && !(ref->mBase->mData.mFlags & ESM::Light::OffDefault))
MWBase::Environment::get().getSoundManager()->playSound3D(ptr, ref->mBase->mSound, 1.0, 1.0,
MWSound::Type::Sfx,
MWSound::PlayMode::Loop);
}
bool Light::useAnim() const
{
return true;
2012-07-24 16:22:11 +00:00
}
2010-08-14 09:39:32 +00:00
2015-12-18 14:51:05 +00:00
std::string Light::getModel(const MWWorld::ConstPtr &ptr) const
2012-07-24 16:22:11 +00:00
{
2015-12-18 14:51:05 +00:00
const MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
2012-07-24 16:22:11 +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;
2010-08-14 09:39:32 +00:00
}
2012-07-24 16:22:11 +00:00
return "";
2010-08-14 09:39:32 +00:00
}
std::string Light::getName (const MWWorld::ConstPtr& ptr) const
2010-08-03 15:11:41 +00:00
{
const MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
2010-08-03 15:11:41 +00:00
2012-11-05 12:07:59 +00:00
if (ref->mBase->mModel.empty())
return std::string();
2010-08-03 15:11:41 +00:00
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId;
2010-08-03 15:11:41 +00:00
}
std::shared_ptr<MWWorld::Action> Light::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
if(!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
return std::shared_ptr<MWWorld::Action>(new MWWorld::NullAction());
2013-08-09 05:34:53 +00:00
MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
if(!(ref->mBase->mData.mFlags&ESM::Light::Carry))
return std::shared_ptr<MWWorld::Action>(new MWWorld::FailedAction());
2013-08-09 05:34:53 +00:00
return defaultItemActivate(ptr, actor);
2010-08-07 18:25:17 +00:00
}
2015-12-17 23:12:03 +00:00
std::string Light::getScript (const MWWorld::ConstPtr& ptr) const
{
2015-12-17 23:12:03 +00:00
const MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
2012-11-05 12:07:59 +00:00
return ref->mBase->mScript;
}
std::pair<std::vector<int>, bool> Light::getEquipmentSlots (const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
std::vector<int> slots_;
2012-11-05 12:07:59 +00:00
if (ref->mBase->mData.mFlags & ESM::Light::Carry)
slots_.push_back (int (MWWorld::InventoryStore::Slot_CarriedLeft));
return std::make_pair (slots_, false);
}
int Light::getValue (const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
2012-11-05 12:07:59 +00:00
return ref->mBase->mData.mValue;
}
2010-08-03 13:24:44 +00:00
void Light::registerSelf()
{
std::shared_ptr<Class> instance (new Light);
2010-08-03 13:24:44 +00:00
registerClass (typeid (ESM::Light).name(), instance);
}
2015-12-18 15:09:08 +00:00
std::string Light::getUpSoundId (const MWWorld::ConstPtr& ptr) const
{
return std::string("Item Misc Up");
}
2015-12-18 15:09:08 +00:00
std::string Light::getDownSoundId (const MWWorld::ConstPtr& ptr) const
{
return std::string("Item Misc Down");
}
2012-04-15 15:52:39 +00:00
2015-12-18 14:53:47 +00:00
std::string Light::getInventoryIcon (const MWWorld::ConstPtr& ptr) const
2012-04-15 15:52:39 +00:00
{
2015-12-18 14:53:47 +00:00
const MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
2012-04-15 15:52:39 +00:00
2012-11-05 12:07:59 +00:00
return ref->mBase->mIcon;
2012-04-15 15:52:39 +00:00
}
2015-12-19 15:13:00 +00:00
bool Light::hasToolTip (const MWWorld::ConstPtr& ptr) const
{
return showsInInventory(ptr);
}
2015-12-19 15:29:07 +00:00
MWGui::ToolTipInfo Light::getToolTipInfo (const MWWorld::ConstPtr& ptr, int count) const
{
const MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
MWGui::ToolTipInfo info;
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count);
2012-11-05 12:07:59 +00:00
info.icon = ref->mBase->mIcon;
std::string text;
// Don't show duration for infinite light sources.
if (Settings::Manager::getBool("show effect duration","Game") && ptr.getClass().getRemainingUsageTime(ptr) != -1)
text += MWGui::ToolTips::getDurationString(ptr.getClass().getRemainingUsageTime(ptr), "\n#{sDuration}");
text += MWGui::ToolTips::getWeightString(ref->mBase->mData.mWeight, "#{sWeight}");
text += MWGui::ToolTips::getValueString(ref->mBase->mData.mValue, "#{sValue}");
if (MWBase::Environment::get().getWindowManager()->getFullHelp()) {
text += MWGui::ToolTips::getCellRefString(ptr.getCellRef());
2012-11-05 12:07:59 +00:00
text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script");
}
info.text = text;
return info;
}
bool Light::showsInInventory (const MWWorld::ConstPtr& ptr) const
{
const ESM::Light* light = ptr.get<ESM::Light>()->mBase;
if (!(light->mData.mFlags & ESM::Light::Carry))
return false;
return Class::showsInInventory(ptr);
}
std::shared_ptr<MWWorld::Action> Light::use (const MWWorld::Ptr& ptr, bool force) const
{
std::shared_ptr<MWWorld::Action> action(new MWWorld::ActionEquip(ptr, force));
action->setSound(getUpSoundId(ptr));
return action;
}
void Light::setRemainingUsageTime (const MWWorld::Ptr& ptr, float duration) const
{
ptr.getCellRef().setChargeFloat(duration);
}
float Light::getRemainingUsageTime (const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
if (ptr.getCellRef().getCharge() == -1)
return static_cast<float>(ref->mBase->mData.mTime);
else
return ptr.getCellRef().getChargeFloat();
}
2015-12-18 15:24:24 +00:00
MWWorld::Ptr Light::copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const
{
2015-12-18 15:24:24 +00:00
const MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
return MWWorld::Ptr(cell.insert(ref), &cell);
}
2015-12-18 14:58:23 +00:00
bool Light::canSell (const MWWorld::ConstPtr& item, int npcServices) const
{
return (npcServices & ESM::NPC::Lights) != 0;
}
2013-05-11 16:38:27 +00:00
2015-12-18 15:00:50 +00:00
float Light::getWeight(const MWWorld::ConstPtr &ptr) const
2013-05-11 16:38:27 +00:00
{
2015-12-18 15:00:50 +00:00
const MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
2013-05-11 16:38:27 +00:00
return ref->mBase->mData.mWeight;
}
std::pair<int, std::string> Light::canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const
{
const MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
if (!(ref->mBase->mData.mFlags & ESM::Light::Carry))
return std::make_pair(0,"");
return std::make_pair(1,"");
}
2015-12-18 15:11:03 +00:00
std::string Light::getSound(const MWWorld::ConstPtr& ptr) const
{
return ptr.get<ESM::Light>()->mBase->mSound;
}
2010-08-03 13:24:44 +00:00
}