1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 15:35:23 +00:00

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

267 lines
9.2 KiB
C++
Raw Normal View History

2010-08-03 15:24:44 +02:00
#include "misc.hpp"
#include <MyGUI_TextIterator.h>
2022-09-08 21:08:59 +02:00
#include <components/esm3/loadcrea.hpp>
#include <components/esm3/loadmisc.hpp>
2022-09-08 21:08:59 +02:00
#include <components/esm3/loadnpc.hpp>
2023-06-27 23:41:06 +02:00
#include <components/settings/values.hpp>
2010-08-03 15:24:44 +02:00
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwworld/actionsoulgem.hpp"
#include "../mwworld/cellstore.hpp"
2015-02-09 15:01:49 +01:00
#include "../mwworld/esmstore.hpp"
#include "../mwworld/manualref.hpp"
#include "../mwworld/nullaction.hpp"
#include "../mwworld/worldmodel.hpp"
2010-08-03 17:11:41 +02:00
#include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
2010-08-03 17:11:41 +02:00
2012-01-27 15:11:02 +01:00
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp"
2012-01-27 15:11:02 +01: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)
{
}
bool Miscellaneous::isGold(const MWWorld::ConstPtr& ptr) const
2015-07-20 08:05:52 +09:00
{
return ptr.getCellRef().getRefId() == "gold_001" || ptr.getCellRef().getRefId() == "gold_005"
|| ptr.getCellRef().getRefId() == "gold_010" || ptr.getCellRef().getRefId() == "gold_025"
|| ptr.getCellRef().getRefId() == "gold_100";
2015-07-20 08:05:52 +09:00
}
void Miscellaneous::insertObjectRendering(
const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
2012-07-24 20:22:11 +04:00
if (!model.empty())
{
2013-08-07 03:51:57 -07:00
renderingInterface.getObjects().insertModel(ptr, model);
}
}
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
{
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
{
const MWWorld::LiveCellRef<ESM::Miscellaneous>* ref = ptr.get<ESM::Miscellaneous>();
const std::string& name = ref->mBase->mName;
2010-08-03 17:11:41 +02:00
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID Slowly going through all the changes to make, still hundreds of errors a lot of functions/structures use std::string or stringview to designate an ID. So it takes time Continues slowly replacing ids. There are technically more and more compilation errors I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type Continue moving forward, changes to the stores slowly moving along Starting to see the fruit of those changes. still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type. More replacements. Things are starting to get easier I can see more and more often the issue is that the function is awaiting a RefId, but is given a string there is less need to go down functions and to fix a long list of them. Still moving forward, and for the first time error count is going down! Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably Cells are back to using string for the name, haven't fixed everything yet. Many other changes Under the bar of 400 compilation errors. more good progress <100 compile errors! More progress Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string some more progress on other fronts Mostly game settings clean one error opened a lot of other errors. Down to 18, but more will prbably appear only link errors left?? Fixed link errors OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
2010-08-03 17:11:41 +02:00
}
std::unique_ptr<MWWorld::Action> Miscellaneous::activate(const MWWorld::Ptr& ptr, 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
}
ESM::RefId Miscellaneous::getScript(const MWWorld::ConstPtr& ptr) const
{
2015-12-18 00:12:03 +01:00
const MWWorld::LiveCellRef<ESM::Miscellaneous>* ref = ptr.get<ESM::Miscellaneous>();
2012-11-05 16:07:59 +04:00
return ref->mBase->mScript;
}
int Miscellaneous::getValue(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Miscellaneous>* ref = ptr.get<ESM::Miscellaneous>();
2014-01-09 01:34:10 +01:00
int value = ref->mBase->mData.mValue;
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())
{
const ESM::Creature* creature
2023-04-20 21:07:53 +02:00
= MWBase::Environment::get().getESMStore()->get<ESM::Creature>().search(ref->mRef.getSoul());
if (creature)
{
int soul = creature->mData.mSoul;
2023-06-27 23:41:06 +02:00
if (Settings::game().mRebalanceSoulGemValues)
{
2018-05-21 22:14:23 +01:00
// use the 'soul gem value rebalance' formula from the Morrowind Code Patch
float soulValue = 0.0001 * pow(soul, 3) + 2 * soul;
2022-09-22 21:26:05 +03:00
// for Azura's star add the unfilled value
if (ptr.getCellRef().getRefId() == "Misc_SoulGem_Azura")
value += soulValue;
else
value = soulValue;
}
else
value *= soul;
}
}
2013-03-27 17:27:43 +01:00
return value;
}
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID Slowly going through all the changes to make, still hundreds of errors a lot of functions/structures use std::string or stringview to designate an ID. So it takes time Continues slowly replacing ids. There are technically more and more compilation errors I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type Continue moving forward, changes to the stores slowly moving along Starting to see the fruit of those changes. still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type. More replacements. Things are starting to get easier I can see more and more often the issue is that the function is awaiting a RefId, but is given a string there is less need to go down functions and to fix a long list of them. Still moving forward, and for the first time error count is going down! Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably Cells are back to using string for the name, haven't fixed everything yet. Many other changes Under the bar of 400 compilation errors. more good progress <100 compile errors! More progress Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string some more progress on other fronts Mostly game settings clean one error opened a lot of other errors. Down to 18, but more will prbably appear only link errors left?? Fixed link errors OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
const ESM::RefId& Miscellaneous::getUpSoundId(const MWWorld::ConstPtr& ptr) const
{
static const ESM::RefId soundGold = ESM::RefId::stringRefId("Item Gold Up");
static const ESM::RefId soundMisc = ESM::RefId::stringRefId("Item Misc Up");
if (isGold(ptr))
return soundGold;
return soundMisc;
}
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID Slowly going through all the changes to make, still hundreds of errors a lot of functions/structures use std::string or stringview to designate an ID. So it takes time Continues slowly replacing ids. There are technically more and more compilation errors I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type Continue moving forward, changes to the stores slowly moving along Starting to see the fruit of those changes. still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type. More replacements. Things are starting to get easier I can see more and more often the issue is that the function is awaiting a RefId, but is given a string there is less need to go down functions and to fix a long list of them. Still moving forward, and for the first time error count is going down! Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably Cells are back to using string for the name, haven't fixed everything yet. Many other changes Under the bar of 400 compilation errors. more good progress <100 compile errors! More progress Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string some more progress on other fronts Mostly game settings clean one error opened a lot of other errors. Down to 18, but more will prbably appear only link errors left?? Fixed link errors OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
const ESM::RefId& Miscellaneous::getDownSoundId(const MWWorld::ConstPtr& ptr) const
{
static const ESM::RefId soundGold = ESM::RefId::stringRefId("Item Gold Down");
static const ESM::RefId soundMisc = ESM::RefId::stringRefId("Item Misc Down");
if (isGold(ptr))
return soundGold;
return soundMisc;
}
2012-04-15 17:52:39 +02:00
2022-08-22 16:55:53 +02:00
const 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
}
2015-12-19 16:29:07 +01:00
MWGui::ToolTipInfo Miscellaneous::getToolTipInfo(const MWWorld::ConstPtr& ptr, int count) const
{
const MWWorld::LiveCellRef<ESM::Miscellaneous>* ref = ptr.get<ESM::Miscellaneous>();
MWGui::ToolTipInfo info;
bool gold = isGold(ptr);
if (gold)
count *= getValue(ptr);
2012-05-16 17:22:25 +02:00
std::string countString;
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);
2022-08-25 21:37:20 +02:00
info.caption = MyGUI::TextIterator::toTagsString(MWGui::toUString(name))
+ MWGui::ToolTips::getCountString(count) + MWGui::ToolTips::getSoulString(ptr.getCellRef());
2012-11-05 16:07:59 +04:00
info.icon = ref->mBase->mIcon;
2012-05-12 14:29:49 +02:00
std::string text;
text += MWGui::ToolTips::getWeightString(ref->mBase->mData.mWeight, "#{sWeight}");
2022-09-30 12:16:45 +02:00
if (!gold && !(ref->mBase->mData.mFlags & ESM::Miscellaneous::Key))
text += MWGui::ToolTips::getValueString(getValue(ptr), "#{sValue}");
if (MWBase::Environment::get().getWindowManager()->getFullHelp())
{
text += MWGui::ToolTips::getCellRefString(ptr.getCellRef());
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID Slowly going through all the changes to make, still hundreds of errors a lot of functions/structures use std::string or stringview to designate an ID. So it takes time Continues slowly replacing ids. There are technically more and more compilation errors I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type Continue moving forward, changes to the stores slowly moving along Starting to see the fruit of those changes. still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type. More replacements. Things are starting to get easier I can see more and more often the issue is that the function is awaiting a RefId, but is given a string there is less need to go down functions and to fix a long list of them. Still moving forward, and for the first time error count is going down! Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably Cells are back to using string for the name, haven't fixed everything yet. Many other changes Under the bar of 400 compilation errors. more good progress <100 compile errors! More progress Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string some more progress on other fronts Mostly game settings clean one error opened a lot of other errors. Down to 18, but more will prbably appear only link errors left?? Fixed link errors OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
text += MWGui::ToolTips::getMiscString(ref->mBase->mScript.getRefIdString(), "Script");
}
info.text = text;
return info;
}
static MWWorld::Ptr createGold(MWWorld::CellStore& cell, int goldAmount)
{
std::string_view base = "gold_001";
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";
2023-04-20 21:07:53 +02:00
const MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore();
MWWorld::ManualRef newRef(store, ESM::RefId::stringRefId(base));
const MWWorld::LiveCellRef<ESM::Miscellaneous>* ref = newRef.getPtr().get<ESM::Miscellaneous>();
MWWorld::Ptr ptr(cell.insert(ref), &cell);
ptr.getCellRef().setGoldValue(goldAmount);
ptr.getRefData().setCount(1);
return ptr;
}
MWWorld::Ptr Miscellaneous::copyToCell(const MWWorld::ConstPtr& ptr, MWWorld::CellStore& cell, int count) const
{
MWWorld::Ptr newPtr;
if (isGold(ptr))
newPtr = createGold(cell, getValue(ptr) * count);
else
{
const MWWorld::LiveCellRef<ESM::Miscellaneous>* ref = ptr.get<ESM::Miscellaneous>();
newPtr = MWWorld::Ptr(cell.insert(ref), &cell);
newPtr.getRefData().setCount(count);
}
newPtr.getCellRef().unsetRefNum();
newPtr.getRefData().setLuaScripts(nullptr);
MWBase::Environment::get().getWorldModel()->registerPtr(newPtr);
return newPtr;
}
MWWorld::Ptr Miscellaneous::moveToCell(const MWWorld::Ptr& ptr, MWWorld::CellStore& cell) const
{
MWWorld::Ptr newPtr;
if (isGold(ptr))
{
newPtr = createGold(cell, getValue(ptr) * ptr.getRefData().getCount());
newPtr.getRefData() = ptr.getRefData();
newPtr.getCellRef().setRefNum(ptr.getCellRef().getRefNum());
newPtr.getRefData().setCount(1);
}
else
{
2015-12-18 16:24:24 +01:00
const MWWorld::LiveCellRef<ESM::Miscellaneous>* ref = ptr.get<ESM::Miscellaneous>();
newPtr = MWWorld::Ptr(cell.insert(ref), &cell);
}
ptr.getRefData().setLuaScripts(nullptr);
MWBase::Environment::get().getWorldModel()->registerPtr(newPtr);
return newPtr;
}
std::unique_ptr<MWWorld::Action> Miscellaneous::use(const MWWorld::Ptr& ptr, bool force) const
{
2022-08-25 21:37:20 +02:00
if (isSoulGem(ptr))
return std::make_unique<MWWorld::ActionSoulgem>(ptr);
return std::make_unique<MWWorld::NullAction>();
}
2015-12-18 15:58:23 +01:00
bool Miscellaneous::canSell(const MWWorld::ConstPtr& item, int npcServices) const
{
2015-12-18 15:58:23 +01:00
const MWWorld::LiveCellRef<ESM::Miscellaneous>* ref = item.get<ESM::Miscellaneous>();
2022-09-30 12:16:45 +02:00
return !(ref->mBase->mData.mFlags & ESM::Miscellaneous::Key) && (npcServices & ESM::NPC::Misc) && !isGold(item);
}
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;
}
bool Miscellaneous::isKey(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Miscellaneous>* ref = ptr.get<ESM::Miscellaneous>();
2022-09-30 12:16:45 +02:00
return ref->mBase->mData.mFlags & ESM::Miscellaneous::Key;
}
2022-08-25 21:37:20 +02:00
bool Miscellaneous::isSoulGem(const MWWorld::ConstPtr& ptr) const
{
return ptr.getCellRef().getRefId().startsWith("misc_soulgem");
2022-08-25 21:37:20 +02:00
}
2010-08-03 15:24:44 +02:00
}