1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-16 07:10:08 +00:00
OpenMW/apps/openmw/mwclass/lockpick.cpp

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

173 lines
5.4 KiB
C++
Raw Normal View History

2010-08-03 13:24:44 +00:00
#include "lockpick.hpp"
#include <MyGUI_TextIterator.h>
2023-11-23 18:52:18 +00:00
#include <MyGUI_UString.h>
#include <components/esm3/loadlock.hpp>
2022-09-08 19:08:59 +00:00
#include <components/esm3/loadnpc.hpp>
2010-08-03 13:24:44 +00:00
#include "../mwbase/environment.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwworld/actionequip.hpp"
#include "../mwworld/cellstore.hpp"
#include "../mwworld/inventorystore.hpp"
2010-08-03 15:11:41 +00:00
#include "../mwworld/ptr.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
#include "classmodel.hpp"
#include "nameorid.hpp"
2010-08-03 13:24:44 +00:00
namespace MWClass
{
2022-04-04 00:44:53 +00:00
Lockpick::Lockpick()
: MWWorld::RegisteredClass<Lockpick>(ESM::Lockpick::sRecordId)
{
}
void Lockpick::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);
}
}
std::string_view Lockpick::getModel(const MWWorld::ConstPtr& ptr) const
{
return getClassModel<ESM::Lockpick>(ptr);
}
2022-08-16 19:15:03 +00:00
std::string_view Lockpick::getName(const MWWorld::ConstPtr& ptr) const
2010-08-03 15:11:41 +00:00
{
return getNameOrId<ESM::Lockpick>(ptr);
2010-08-03 15:11:41 +00:00
}
std::unique_ptr<MWWorld::Action> Lockpick::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
return defaultItemActivate(ptr, actor);
2010-08-07 18:25:17 +00:00
}
ESM::RefId Lockpick::getScript(const MWWorld::ConstPtr& ptr) const
{
2015-12-17 23:12:03 +00:00
const MWWorld::LiveCellRef<ESM::Lockpick>* ref = ptr.get<ESM::Lockpick>();
2012-11-05 12:07:59 +00:00
return ref->mBase->mScript;
}
std::pair<std::vector<int>, bool> Lockpick::getEquipmentSlots(const MWWorld::ConstPtr& ptr) const
{
std::vector<int> slots_;
slots_.push_back(int(MWWorld::InventoryStore::Slot_CarriedRight));
return std::make_pair(slots_, false);
}
int Lockpick::getValue(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Lockpick>* ref = ptr.get<ESM::Lockpick>();
return ref->mBase->mData.mValue;
}
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 11:17:09 +00:00
const ESM::RefId& Lockpick::getUpSoundId(const MWWorld::ConstPtr& ptr) const
{
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 11:17:09 +00:00
static ESM::RefId sound = ESM::RefId::stringRefId("Item Lockpick Up");
return sound;
}
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 11:17:09 +00:00
const ESM::RefId& Lockpick::getDownSoundId(const MWWorld::ConstPtr& ptr) const
{
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 11:17:09 +00:00
static ESM::RefId sound = ESM::RefId::stringRefId("Item Lockpick Down");
return sound;
}
2012-04-15 15:52:39 +00:00
2022-08-22 14:55:53 +00:00
const std::string& Lockpick::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::Lockpick>* ref = ptr.get<ESM::Lockpick>();
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:29:07 +00:00
MWGui::ToolTipInfo Lockpick::getToolTipInfo(const MWWorld::ConstPtr& ptr, int count) const
{
const MWWorld::LiveCellRef<ESM::Lockpick>* ref = ptr.get<ESM::Lockpick>();
MWGui::ToolTipInfo info;
2022-08-16 19:15:03 +00:00
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString(MyGUI::UString(name)) + MWGui::ToolTips::getCountString(count);
2012-11-05 12:07:59 +00:00
info.icon = ref->mBase->mIcon;
std::string text;
int remainingUses = getItemHealth(ptr);
text += "\n#{sUses}: " + MWGui::ToolTips::toString(remainingUses);
2012-11-05 12:07:59 +00:00
text += "\n#{sQuality}: " + MWGui::ToolTips::toString(ref->mBase->mData.mQuality);
text += MWGui::ToolTips::getWeightString(ref->mBase->mData.mWeight, "#{sWeight}");
text += MWGui::ToolTips::getValueString(ref->mBase->mData.mValue, "#{sValue}");
if (MWBase::Environment::get().getWindowManager()->getFullHelp())
{
info.extra += MWGui::ToolTips::getCellRefString(ptr.getCellRef());
info.extra += MWGui::ToolTips::getMiscString(ref->mBase->mScript.getRefIdString(), "Script");
}
2024-01-02 14:30:35 +00:00
info.text = std::move(text);
return info;
}
std::unique_ptr<MWWorld::Action> Lockpick::use(const MWWorld::Ptr& ptr, bool force) const
{
2022-05-29 11:24:48 +00:00
std::unique_ptr<MWWorld::Action> action = std::make_unique<MWWorld::ActionEquip>(ptr, force);
action->setSound(getUpSoundId(ptr));
return action;
}
2015-12-18 15:24:24 +00:00
MWWorld::Ptr Lockpick::copyToCellImpl(const MWWorld::ConstPtr& ptr, MWWorld::CellStore& cell) const
{
2015-12-18 15:24:24 +00:00
const MWWorld::LiveCellRef<ESM::Lockpick>* ref = ptr.get<ESM::Lockpick>();
return MWWorld::Ptr(cell.insert(ref), &cell);
}
std::pair<int, std::string_view> Lockpick::canBeEquipped(
const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const
{
// Do not allow equip tools from inventory during attack
if (MWBase::Environment::get().getMechanicsManager()->isAttackingOrSpell(npc)
&& MWBase::Environment::get().getWindowManager()->isGuiMode())
return { 0, "#{sCantEquipWeapWarning}" };
return { 1, {} };
}
2015-12-18 14:58:23 +00:00
bool Lockpick::canSell(const MWWorld::ConstPtr& item, int npcServices) const
{
return (npcServices & ESM::NPC::Picks) != 0;
}
int Lockpick::getItemMaxHealth(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Lockpick>* ref = ptr.get<ESM::Lockpick>();
return ref->mBase->mData.mUses;
}
2013-05-11 16:38:27 +00:00
2015-12-18 15:00:50 +00:00
float Lockpick::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::Lockpick>* ref = ptr.get<ESM::Lockpick>();
2013-05-11 16:38:27 +00:00
return ref->mBase->mData.mWeight;
}
2010-08-03 13:24:44 +00:00
}