2010-08-03 15:24:44 +02:00
|
|
|
#include "misc.hpp"
|
|
|
|
|
2022-06-04 15:26:36 +02:00
|
|
|
#include <MyGUI_TextIterator.h>
|
|
|
|
|
2022-01-22 15:58:41 +01:00
|
|
|
#include <components/esm3/loadmisc.hpp>
|
2018-05-21 13:59:20 +01:00
|
|
|
#include <components/settings/settings.hpp>
|
2010-08-03 15:24:44 +02:00
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-07-03 12:30:50 +02:00
|
|
|
#include "../mwbase/world.hpp"
|
2012-08-12 18:11:09 +02:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2012-04-23 15:27:03 +02:00
|
|
|
|
2012-06-29 16:48:50 +02:00
|
|
|
#include "../mwworld/cellstore.hpp"
|
2015-02-09 15:01:49 +01:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
2012-07-25 17:18:17 +04:00
|
|
|
#include "../mwworld/manualref.hpp"
|
2013-02-17 15:56:22 +01:00
|
|
|
#include "../mwworld/nullaction.hpp"
|
2013-03-30 15:51:07 +01:00
|
|
|
#include "../mwworld/actionsoulgem.hpp"
|
2010-08-03 17:11:41 +02:00
|
|
|
|
2012-04-16 22:58:16 +02:00
|
|
|
#include "../mwgui/tooltips.hpp"
|
2010-08-03 17:11:41 +02:00
|
|
|
|
2012-01-27 15:11:02 +01:00
|
|
|
#include "../mwrender/objects.hpp"
|
2012-07-03 13:15:20 +02:00
|
|
|
#include "../mwrender/renderinginterface.hpp"
|
2012-01-27 15:11:02 +01:00
|
|
|
|
2022-06-29 00:32:11 +02:00
|
|
|
#include "classmodel.hpp"
|
|
|
|
|
2010-08-03 15:24:44 +02:00
|
|
|
namespace MWClass
|
|
|
|
{
|
2022-04-04 02:44:53 +02:00
|
|
|
Miscellaneous::Miscellaneous()
|
|
|
|
: MWWorld::RegisteredClass<Miscellaneous>(ESM::Miscellaneous::sRecordId)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-12-18 15:27:06 +01:00
|
|
|
bool Miscellaneous::isGold (const MWWorld::ConstPtr& ptr) const
|
2015-07-20 08:05:52 +09:00
|
|
|
{
|
|
|
|
return Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_001")
|
|
|
|
|| Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_005")
|
|
|
|
|| Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_010")
|
|
|
|
|| Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_025")
|
|
|
|
|| Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_100");
|
|
|
|
}
|
2014-07-18 09:56:58 +02:00
|
|
|
|
2015-01-12 11:29:56 +01:00
|
|
|
void Miscellaneous::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
|
2010-08-14 10:02:54 +02:00
|
|
|
{
|
2012-07-24 20:22:11 +04:00
|
|
|
if (!model.empty()) {
|
2013-08-07 03:51:57 -07:00
|
|
|
renderingInterface.getObjects().insertModel(ptr, model);
|
2010-08-14 10:02:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-18 15:51:05 +01:00
|
|
|
std::string Miscellaneous::getModel(const MWWorld::ConstPtr &ptr) const
|
2011-11-11 23:01:12 -05:00
|
|
|
{
|
2022-06-29 00:32:11 +02:00
|
|
|
return getClassModel<ESM::Miscellaneous>(ptr);
|
2011-11-11 23:01:12 -05:00
|
|
|
}
|
|
|
|
|
2022-08-16 21:15:03 +02:00
|
|
|
std::string_view Miscellaneous::getName(const MWWorld::ConstPtr& ptr) const
|
2010-08-03 17:11:41 +02:00
|
|
|
{
|
2015-12-18 15:27:06 +01:00
|
|
|
const MWWorld::LiveCellRef<ESM::Miscellaneous> *ref = ptr.get<ESM::Miscellaneous>();
|
2019-09-11 00:06:50 +03:00
|
|
|
const std::string& name = ref->mBase->mName;
|
2010-08-03 17:11:41 +02:00
|
|
|
|
2019-09-11 00:06:50 +03:00
|
|
|
return !name.empty() ? name : ref->mBase->mId;
|
2010-08-03 17:11:41 +02:00
|
|
|
}
|
|
|
|
|
2022-04-06 17:06:55 +02:00
|
|
|
std::unique_ptr<MWWorld::Action> Miscellaneous::activate (const MWWorld::Ptr& ptr,
|
2012-04-23 15:27:03 +02:00
|
|
|
const MWWorld::Ptr& actor) const
|
2010-08-07 20:25:17 +02:00
|
|
|
{
|
2013-08-08 22:34:53 -07:00
|
|
|
return defaultItemActivate(ptr, actor);
|
2010-08-07 20:25:17 +02:00
|
|
|
}
|
|
|
|
|
2022-08-11 22:51:55 +02:00
|
|
|
std::string_view Miscellaneous::getScript(const MWWorld::ConstPtr& ptr) const
|
2010-08-05 15:40:03 +02:00
|
|
|
{
|
2015-12-18 00:12:03 +01:00
|
|
|
const MWWorld::LiveCellRef<ESM::Miscellaneous> *ref = ptr.get<ESM::Miscellaneous>();
|
2010-08-05 15:40:03 +02:00
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
return ref->mBase->mScript;
|
2010-08-05 15:40:03 +02:00
|
|
|
}
|
|
|
|
|
2015-12-18 15:27:06 +01:00
|
|
|
int Miscellaneous::getValue (const MWWorld::ConstPtr& ptr) const
|
2012-04-07 19:53:49 +02:00
|
|
|
{
|
2015-12-18 15:27:06 +01:00
|
|
|
const MWWorld::LiveCellRef<ESM::Miscellaneous> *ref = ptr.get<ESM::Miscellaneous>();
|
2012-04-07 19:53:49 +02:00
|
|
|
|
2014-01-09 01:34:10 +01:00
|
|
|
int value = ref->mBase->mData.mValue;
|
2014-05-25 14:13:07 +02:00
|
|
|
if (ptr.getCellRef().getGoldValue() > 1 && ptr.getRefData().getCount() == 1)
|
|
|
|
value = ptr.getCellRef().getGoldValue();
|
2013-03-27 17:27:43 +01:00
|
|
|
|
2022-08-16 21:15:03 +02:00
|
|
|
if (!ptr.getCellRef().getSoul().empty())
|
2013-03-27 17:39:49 +01:00
|
|
|
{
|
2018-03-08 23:38:04 +00:00
|
|
|
const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get<ESM::Creature>().search(ref->mRef.getSoul());
|
2018-05-21 13:59:20 +01:00
|
|
|
if (creature)
|
|
|
|
{
|
2018-05-21 18:16:04 +01:00
|
|
|
int soul = creature->mData.mSoul;
|
2018-05-21 19:10:24 +01:00
|
|
|
if (Settings::Manager::getBool("rebalance soul gem values", "Game"))
|
2018-05-21 13:59:20 +01:00
|
|
|
{
|
2018-05-21 22:14:23 +01:00
|
|
|
// use the 'soul gem value rebalance' formula from the Morrowind Code Patch
|
2018-05-21 13:59:20 +01:00
|
|
|
float soulValue = 0.0001 * pow(soul, 3) + 2 * soul;
|
|
|
|
|
|
|
|
// for Azura's star add the unfilled value
|
|
|
|
if (Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "Misc_SoulGem_Azura"))
|
|
|
|
value += soulValue;
|
|
|
|
else
|
|
|
|
value = soulValue;
|
|
|
|
}
|
2018-05-20 17:06:26 +01:00
|
|
|
else
|
2018-05-21 18:16:04 +01:00
|
|
|
value *= soul;
|
2018-05-20 17:06:26 +01:00
|
|
|
}
|
2013-03-27 17:39:49 +01:00
|
|
|
}
|
|
|
|
|
2013-03-27 17:27:43 +01:00
|
|
|
return value;
|
2012-04-07 19:53:49 +02:00
|
|
|
}
|
|
|
|
|
2022-08-14 14:39:58 +02:00
|
|
|
std::string_view Miscellaneous::getUpSoundId(const MWWorld::ConstPtr& ptr) const
|
2012-03-13 18:50:32 +02:00
|
|
|
{
|
2013-03-30 18:29:21 +01:00
|
|
|
if (isGold(ptr))
|
2022-08-14 14:39:58 +02:00
|
|
|
return "Item Gold Up";
|
|
|
|
return "Item Misc Up";
|
2012-03-13 18:50:32 +02:00
|
|
|
}
|
|
|
|
|
2022-08-14 14:39:58 +02:00
|
|
|
std::string_view Miscellaneous::getDownSoundId(const MWWorld::ConstPtr& ptr) const
|
2012-03-13 18:50:32 +02:00
|
|
|
{
|
2013-03-30 18:29:21 +01:00
|
|
|
if (isGold(ptr))
|
2022-08-14 14:39:58 +02:00
|
|
|
return "Item Gold Down";
|
|
|
|
return "Item Misc Down";
|
2012-03-13 18:50:32 +02:00
|
|
|
}
|
2012-04-15 17:52:39 +02:00
|
|
|
|
2015-12-18 15:53:47 +01:00
|
|
|
std::string Miscellaneous::getInventoryIcon (const MWWorld::ConstPtr& ptr) const
|
2012-04-15 17:52:39 +02:00
|
|
|
{
|
2015-12-18 15:53:47 +01:00
|
|
|
const MWWorld::LiveCellRef<ESM::Miscellaneous> *ref = ptr.get<ESM::Miscellaneous>();
|
2012-04-15 17:52:39 +02:00
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
return ref->mBase->mIcon;
|
2012-04-15 17:52:39 +02:00
|
|
|
}
|
2012-05-11 10:40:40 +02:00
|
|
|
|
2015-12-19 16:29:07 +01:00
|
|
|
MWGui::ToolTipInfo Miscellaneous::getToolTipInfo (const MWWorld::ConstPtr& ptr, int count) const
|
2012-04-16 22:58:16 +02:00
|
|
|
{
|
2015-12-18 15:27:06 +01:00
|
|
|
const MWWorld::LiveCellRef<ESM::Miscellaneous> *ref = ptr.get<ESM::Miscellaneous>();
|
2012-04-16 22:58:16 +02:00
|
|
|
|
|
|
|
MWGui::ToolTipInfo info;
|
|
|
|
|
2013-03-30 18:29:21 +01:00
|
|
|
bool gold = isGold(ptr);
|
2014-01-29 15:22:07 +01:00
|
|
|
if (gold)
|
|
|
|
count *= getValue(ptr);
|
2012-05-16 17:22:25 +02:00
|
|
|
|
|
|
|
std::string countString;
|
2013-03-30 18:29:21 +01:00
|
|
|
if (!gold)
|
2012-05-16 17:22:25 +02:00
|
|
|
countString = MWGui::ToolTips::getCountString(count);
|
|
|
|
else // gold displays its count also if it's 1.
|
2017-05-06 23:05:13 +02:00
|
|
|
countString = " (" + std::to_string(count) + ")";
|
2012-05-12 14:29:49 +02:00
|
|
|
|
2022-08-16 21:15:03 +02:00
|
|
|
std::string_view name = getName(ptr);
|
|
|
|
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
|
2012-11-05 16:07:59 +04:00
|
|
|
info.icon = ref->mBase->mIcon;
|
2012-05-12 14:29:49 +02:00
|
|
|
|
2012-04-16 22:58:16 +02:00
|
|
|
std::string text;
|
|
|
|
|
2016-08-14 19:37:22 +09:00
|
|
|
text += MWGui::ToolTips::getWeightString(ref->mBase->mData.mWeight, "#{sWeight}");
|
2014-08-16 16:51:56 +02:00
|
|
|
if (!gold && !ref->mBase->mData.mIsKey)
|
2013-03-27 17:39:49 +01:00
|
|
|
text += MWGui::ToolTips::getValueString(getValue(ptr), "#{sValue}");
|
2012-04-16 22:58:16 +02:00
|
|
|
|
2012-04-24 02:02:03 +02:00
|
|
|
if (MWBase::Environment::get().getWindowManager()->getFullHelp()) {
|
2014-07-22 20:03:35 +02:00
|
|
|
text += MWGui::ToolTips::getCellRefString(ptr.getCellRef());
|
2012-11-05 16:07:59 +04:00
|
|
|
text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script");
|
2012-04-16 22:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
info.text = text;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
2012-07-25 17:18:17 +04:00
|
|
|
|
2015-12-19 16:47:55 +01:00
|
|
|
MWWorld::Ptr Miscellaneous::copyToCell(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell, int count) const
|
2012-07-25 17:18:17 +04:00
|
|
|
{
|
|
|
|
MWWorld::Ptr newPtr;
|
2012-08-09 14:33:21 +02:00
|
|
|
|
2012-10-01 19:17:04 +04:00
|
|
|
const MWWorld::ESMStore &store =
|
2012-07-25 17:18:17 +04:00
|
|
|
MWBase::Environment::get().getWorld()->getStore();
|
|
|
|
|
2013-03-30 18:29:21 +01:00
|
|
|
if (isGold(ptr)) {
|
2015-12-19 16:47:55 +01:00
|
|
|
int goldAmount = getValue(ptr) * count;
|
2012-07-25 17:18:17 +04:00
|
|
|
|
2022-08-16 21:15:03 +02:00
|
|
|
std::string_view base = "Gold_001";
|
2012-07-25 17:18:17 +04:00
|
|
|
if (goldAmount >= 100)
|
|
|
|
base = "Gold_100";
|
|
|
|
else if (goldAmount >= 25)
|
|
|
|
base = "Gold_025";
|
|
|
|
else if (goldAmount >= 10)
|
|
|
|
base = "Gold_010";
|
|
|
|
else if (goldAmount >= 5)
|
|
|
|
base = "Gold_005";
|
|
|
|
|
|
|
|
// Really, I have no idea why moving ref out of conditional
|
|
|
|
// scope causes list::push_back throwing std::bad_alloc
|
|
|
|
MWWorld::ManualRef newRef(store, base);
|
2015-12-18 16:24:24 +01:00
|
|
|
const MWWorld::LiveCellRef<ESM::Miscellaneous> *ref =
|
2012-07-25 17:18:17 +04:00
|
|
|
newRef.getPtr().get<ESM::Miscellaneous>();
|
2015-11-14 17:12:05 +01:00
|
|
|
|
|
|
|
newPtr = MWWorld::Ptr(cell.insert(ref), &cell);
|
2014-05-25 14:13:07 +02:00
|
|
|
newPtr.getCellRef().setGoldValue(goldAmount);
|
2014-01-29 15:22:07 +01:00
|
|
|
newPtr.getRefData().setCount(1);
|
2012-07-25 17:18:17 +04:00
|
|
|
} else {
|
2015-12-18 16:24:24 +01:00
|
|
|
const MWWorld::LiveCellRef<ESM::Miscellaneous> *ref =
|
2012-07-25 17:18:17 +04:00
|
|
|
ptr.get<ESM::Miscellaneous>();
|
2015-11-14 17:12:05 +01:00
|
|
|
newPtr = MWWorld::Ptr(cell.insert(ref), &cell);
|
2015-12-19 16:47:55 +01:00
|
|
|
newPtr.getRefData().setCount(count);
|
2012-07-25 17:18:17 +04:00
|
|
|
}
|
2015-12-19 16:47:55 +01:00
|
|
|
newPtr.getCellRef().unsetRefNum();
|
|
|
|
|
2012-07-25 17:18:17 +04:00
|
|
|
return newPtr;
|
|
|
|
}
|
2013-03-30 15:51:07 +01:00
|
|
|
|
2022-07-25 01:47:10 +03:00
|
|
|
std::unique_ptr<MWWorld::Action> Miscellaneous::use (const MWWorld::Ptr& ptr, bool force) const
|
2022-07-24 23:02:26 +03:00
|
|
|
{
|
2022-08-16 21:15:03 +02:00
|
|
|
const std::string_view soulgemPrefix = "misc_soulgem";
|
2022-07-24 23:02:26 +03:00
|
|
|
|
2022-07-25 02:56:25 +03:00
|
|
|
if (::Misc::StringUtils::ciCompareLen(ptr.getCellRef().getRefId(), soulgemPrefix, soulgemPrefix.length()) == 0)
|
2022-07-25 01:47:10 +03:00
|
|
|
return std::make_unique<MWWorld::ActionSoulgem>(ptr);
|
2022-07-24 23:02:26 +03:00
|
|
|
|
2022-07-25 01:47:10 +03:00
|
|
|
return std::make_unique<MWWorld::NullAction>();
|
2013-03-30 15:51:07 +01:00
|
|
|
}
|
|
|
|
|
2015-12-18 15:58:23 +01:00
|
|
|
bool Miscellaneous::canSell (const MWWorld::ConstPtr& item, int npcServices) const
|
2013-04-07 21:38:53 +02:00
|
|
|
{
|
2015-12-18 15:58:23 +01:00
|
|
|
const MWWorld::LiveCellRef<ESM::Miscellaneous> *ref = item.get<ESM::Miscellaneous>();
|
2013-04-07 21:38:53 +02:00
|
|
|
|
2014-05-25 14:13:07 +02:00
|
|
|
return !ref->mBase->mData.mIsKey && (npcServices & ESM::NPC::Misc) && !isGold(item);
|
2013-04-07 21:38:53 +02:00
|
|
|
}
|
|
|
|
|
2015-12-18 16:00:50 +01:00
|
|
|
float Miscellaneous::getWeight(const MWWorld::ConstPtr &ptr) const
|
2013-05-11 18:38:27 +02:00
|
|
|
{
|
2015-12-18 16:00:50 +01:00
|
|
|
const MWWorld::LiveCellRef<ESM::Miscellaneous> *ref = ptr.get<ESM::Miscellaneous>();
|
2013-05-11 18:38:27 +02:00
|
|
|
return ref->mBase->mData.mWeight;
|
|
|
|
}
|
|
|
|
|
2015-12-18 15:27:06 +01:00
|
|
|
bool Miscellaneous::isKey(const MWWorld::ConstPtr &ptr) const
|
2014-01-01 22:37:52 +01:00
|
|
|
{
|
2015-12-18 15:27:06 +01:00
|
|
|
const MWWorld::LiveCellRef<ESM::Miscellaneous> *ref = ptr.get<ESM::Miscellaneous>();
|
2015-03-06 23:19:57 +13:00
|
|
|
return ref->mBase->mData.mIsKey != 0;
|
2014-01-01 22:37:52 +01:00
|
|
|
}
|
|
|
|
|
2010-08-03 15:24:44 +02:00
|
|
|
}
|