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/clothing.cpp

281 lines
9.4 KiB
C++
Raw Normal View History

2010-08-03 13:24:44 +00:00
#include "clothing.hpp"
#include <components/esm/loadclot.hpp>
#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/esmstore.hpp"
#include "../mwphysics/physicssystem.hpp"
#include "../mwworld/nullaction.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"
2010-08-03 13:24:44 +00:00
namespace MWClass
{
void Clothing::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
2012-07-24 16:22:11 +00:00
if (!model.empty()) {
2013-08-07 10:51:57 +00:00
renderingInterface.getObjects().insertModel(ptr, model);
}
}
void Clothing::insertObject(const MWWorld::Ptr& ptr, const std::string& model, MWPhysics::PhysicsSystem& physics) const
2012-07-24 16:22:11 +00:00
{
// TODO: add option somewhere to enable collision for placeable objects
2012-07-24 16:22:11 +00:00
}
2015-12-18 14:51:05 +00:00
std::string Clothing::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::Clothing> *ref = ptr.get<ESM::Clothing>();
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
}
std::string Clothing::getName (const MWWorld::ConstPtr& ptr) const
2010-08-03 15:11:41 +00:00
{
const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();
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
}
std::shared_ptr<MWWorld::Action> Clothing::activate (const MWWorld::Ptr& ptr,
2013-08-09 05:34:53 +00:00
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
}
2015-12-17 23:12:03 +00:00
std::string Clothing::getScript (const MWWorld::ConstPtr& ptr) const
{
2015-12-17 23:12:03 +00:00
const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();
2012-11-05 12:07:59 +00:00
return ref->mBase->mScript;
}
std::pair<std::vector<int>, bool> Clothing::getEquipmentSlots (const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();
std::vector<int> slots_;
2012-11-05 12:07:59 +00:00
if (ref->mBase->mData.mType==ESM::Clothing::Ring)
{
slots_.push_back (int (MWWorld::InventoryStore::Slot_LeftRing));
slots_.push_back (int (MWWorld::InventoryStore::Slot_RightRing));
}
else
{
const int size = 9;
static const int sMapping[size][2] =
{
2012-04-14 20:44:46 +00:00
{ ESM::Clothing::Shirt, MWWorld::InventoryStore::Slot_Shirt },
{ ESM::Clothing::Belt, MWWorld::InventoryStore::Slot_Belt },
{ ESM::Clothing::Robe, MWWorld::InventoryStore::Slot_Robe },
{ ESM::Clothing::Pants, MWWorld::InventoryStore::Slot_Pants },
{ ESM::Clothing::Shoes, MWWorld::InventoryStore::Slot_Boots },
{ ESM::Clothing::LGlove, MWWorld::InventoryStore::Slot_LeftGauntlet },
{ ESM::Clothing::RGlove, MWWorld::InventoryStore::Slot_RightGauntlet },
{ ESM::Clothing::Skirt, MWWorld::InventoryStore::Slot_Skirt },
{ ESM::Clothing::Amulet, MWWorld::InventoryStore::Slot_Amulet }
};
for (int i=0; i<size; ++i)
2012-11-05 12:07:59 +00:00
if (sMapping[i][0]==ref->mBase->mData.mType)
{
slots_.push_back (int (sMapping[i][1]));
break;
}
}
return std::make_pair (slots_, false);
}
int Clothing::getEquipmentSkill (const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();
2012-11-05 12:07:59 +00:00
if (ref->mBase->mData.mType==ESM::Clothing::Shoes)
return ESM::Skill::Unarmored;
return -1;
}
int Clothing::getValue (const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();
2012-11-05 12:07:59 +00:00
return ref->mBase->mData.mValue;
}
2010-08-03 13:24:44 +00:00
void Clothing::registerSelf()
{
std::shared_ptr<Class> instance (new Clothing);
2010-08-03 13:24:44 +00:00
registerClass (typeid (ESM::Clothing).name(), instance);
}
2015-12-18 15:09:08 +00:00
std::string Clothing::getUpSoundId (const MWWorld::ConstPtr& ptr) const
{
2015-12-18 15:09:08 +00:00
const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();
2012-11-05 12:07:59 +00:00
if (ref->mBase->mData.mType == 8)
{
return std::string("Item Ring Up");
}
return std::string("Item Clothes Up");
}
2015-12-18 15:09:08 +00:00
std::string Clothing::getDownSoundId (const MWWorld::ConstPtr& ptr) const
{
2015-12-18 15:09:08 +00:00
const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();
2012-11-05 12:07:59 +00:00
if (ref->mBase->mData.mType == 8)
{
return std::string("Item Ring Down");
}
return std::string("Item Clothes Down");
}
2012-04-15 15:52:39 +00:00
2015-12-18 14:53:47 +00:00
std::string Clothing::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::Clothing> *ref = ptr.get<ESM::Clothing>();
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 Clothing::hasToolTip (const MWWorld::ConstPtr& ptr) const
{
2015-12-19 15:13:00 +00:00
const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();
2012-11-05 12:07:59 +00:00
return (ref->mBase->mName != "");
}
2015-12-19 15:29:07 +00:00
MWGui::ToolTipInfo Clothing::getToolTipInfo (const MWWorld::ConstPtr& ptr, int count) const
{
const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();
MWGui::ToolTipInfo info;
2015-12-19 15:29:07 +00:00
info.caption = ref->mBase->mName + MWGui::ToolTips::getCountString(count);
2012-11-05 12:07:59 +00:00
info.icon = ref->mBase->mIcon;
std::string text;
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");
}
2012-11-05 12:07:59 +00:00
info.enchant = ref->mBase->mEnchant;
if (!info.enchant.empty())
info.remainingEnchantCharge = static_cast<int>(ptr.getCellRef().getEnchantmentCharge());
info.text = text;
return info;
}
2012-05-12 14:17:03 +00:00
2015-12-18 14:56:45 +00:00
std::string Clothing::getEnchantment (const MWWorld::ConstPtr& ptr) const
2012-05-12 14:17:03 +00:00
{
2015-12-18 14:56:45 +00:00
const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();
2012-05-12 14:17:03 +00:00
2012-11-05 12:07:59 +00:00
return ref->mBase->mEnchant;
2012-05-12 14:17:03 +00:00
}
2015-12-18 15:43:11 +00:00
std::string Clothing::applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
2013-03-28 16:41:00 +00:00
{
2015-12-18 15:43:11 +00:00
const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();
2013-03-28 22:39:20 +00:00
ESM::Clothing newItem = *ref->mBase;
2013-03-28 16:41:00 +00:00
newItem.mId="";
newItem.mName=newName;
newItem.mData.mEnchant=enchCharge;
newItem.mEnchant=enchId;
const ESM::Clothing *record = MWBase::Environment::get().getWorld()->createRecord (newItem);
return record->mId;
2013-03-28 16:41:00 +00:00
}
std::pair<int, std::string> Clothing::canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const
2013-04-05 13:42:05 +00:00
{
// slots that this item can be equipped in
std::pair<std::vector<int>, bool> slots_ = ptr.getClass().getEquipmentSlots(ptr);
2013-04-05 13:42:05 +00:00
2013-12-30 18:04:35 +00:00
if (slots_.first.empty())
return std::make_pair(0, "");
if (npc.getClass().isNpc())
2013-04-05 13:42:05 +00:00
{
std::string npcRace = npc.get<ESM::NPC>()->mBase->mRace;
2013-04-05 13:42:05 +00:00
// Beast races cannot equip shoes / boots, or full helms (head part vs hair part)
const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get<ESM::Race>().find(npcRace);
if(race->mData.mFlags & ESM::Race::Beast)
2013-04-05 13:42:05 +00:00
{
std::vector<ESM::PartReference> parts = ptr.get<ESM::Clothing>()->mBase->mParts.mParts;
for(std::vector<ESM::PartReference>::iterator itr = parts.begin(); itr != parts.end(); ++itr)
{
if((*itr).mPart == ESM::PRT_Head)
return std::make_pair(0, "#{sNotifyMessage13}");
if((*itr).mPart == ESM::PRT_LFoot || (*itr).mPart == ESM::PRT_RFoot)
return std::make_pair(0, "#{sNotifyMessage15}");
}
2013-04-05 13:42:05 +00:00
}
}
2013-12-30 18:04:35 +00:00
return std::make_pair (1, "");
2013-04-05 13:42:05 +00:00
}
std::shared_ptr<MWWorld::Action> Clothing::use (const MWWorld::Ptr& ptr) const
{
std::shared_ptr<MWWorld::Action> action(new MWWorld::ActionEquip(ptr));
action->setSound(getUpSoundId(ptr));
return action;
}
2015-12-18 15:24:24 +00:00
MWWorld::Ptr Clothing::copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const
{
2015-12-18 15:24:24 +00:00
const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();
return MWWorld::Ptr(cell.insert(ref), &cell);
}
2013-03-16 18:00:14 +00:00
int Clothing::getEnchantmentPoints (const MWWorld::ConstPtr& ptr) const
2013-03-16 18:00:14 +00:00
{
const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();
2013-03-16 18:00:14 +00:00
2014-01-27 00:58:04 +00:00
return ref->mBase->mData.mEnchant;
2013-03-16 18:00:14 +00:00
}
2015-12-18 14:58:23 +00:00
bool Clothing::canSell (const MWWorld::ConstPtr& item, int npcServices) const
{
return (npcServices & ESM::NPC::Clothing)
|| ((npcServices & ESM::NPC::MagicItems) && !getEnchantment(item).empty());
}
2013-05-11 16:38:27 +00:00
2015-12-18 15:00:50 +00:00
float Clothing::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::Clothing> *ref = ptr.get<ESM::Clothing>();
2013-05-11 16:38:27 +00:00
return ref->mBase->mData.mWeight;
}
2010-08-03 13:24:44 +00:00
}