mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-31 15:45:35 +00:00
Use string_view in modifyBaseInventory
This commit is contained in:
parent
1f5277349c
commit
262b29ed40
11 changed files with 15 additions and 15 deletions
|
@ -288,7 +288,7 @@ namespace MWClass
|
|||
return !(ref->mBase->mFlags & ESM::Container::Organic);
|
||||
}
|
||||
|
||||
void Container::modifyBaseInventory(const std::string& containerId, const std::string& itemId, int amount) const
|
||||
void Container::modifyBaseInventory(std::string_view containerId, std::string_view itemId, int amount) const
|
||||
{
|
||||
MWMechanics::modifyBaseInventory<ESM::Container>(containerId, itemId, amount);
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ namespace MWClass
|
|||
|
||||
bool useAnim() const override;
|
||||
|
||||
void modifyBaseInventory(const std::string& containerId, const std::string& itemId, int amount) const override;
|
||||
void modifyBaseInventory(std::string_view containerId, std::string_view itemId, int amount) const override;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -898,7 +898,7 @@ namespace MWClass
|
|||
MWMechanics::setBaseAISetting<ESM::Creature>(id, setting, value);
|
||||
}
|
||||
|
||||
void Creature::modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount) const
|
||||
void Creature::modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount) const
|
||||
{
|
||||
MWMechanics::modifyBaseInventory<ESM::Creature>(actorId, itemId, amount);
|
||||
}
|
||||
|
|
|
@ -138,7 +138,7 @@ namespace MWClass
|
|||
|
||||
void setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) const override;
|
||||
|
||||
void modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount) const override;
|
||||
void modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount) const override;
|
||||
|
||||
float getWalkSpeed(const MWWorld::Ptr& ptr) const override;
|
||||
|
||||
|
|
|
@ -1495,7 +1495,7 @@ namespace MWClass
|
|||
MWMechanics::setBaseAISetting<ESM::NPC>(id, setting, value);
|
||||
}
|
||||
|
||||
void Npc::modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount) const
|
||||
void Npc::modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount) const
|
||||
{
|
||||
MWMechanics::modifyBaseInventory<ESM::NPC>(actorId, itemId, amount);
|
||||
}
|
||||
|
|
|
@ -166,7 +166,7 @@ namespace MWClass
|
|||
|
||||
void setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) const override;
|
||||
|
||||
void modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount) const override;
|
||||
void modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount) const override;
|
||||
|
||||
float getWalkSpeed(const MWWorld::Ptr& ptr) const override;
|
||||
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
#include <components/esm3/loadcont.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
template <class T>
|
||||
void modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount)
|
||||
void modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount)
|
||||
{
|
||||
T copy = *MWBase::Environment::get().getWorld()->getStore().get<T>().find(actorId);
|
||||
for (auto& it : copy.mInventory.mList)
|
||||
|
|
|
@ -118,7 +118,7 @@ namespace MWScript
|
|||
// Explicit calls to non-unique actors affect the base record
|
||||
if(!R::implicit && ptr.getClass().isActor() && MWBase::Environment::get().getWorld()->getStore().getRefCount(ptr.getCellRef().getRefId()) > 1)
|
||||
{
|
||||
ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), std::string{item}, count);
|
||||
ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), item, count);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,7 @@ namespace MWScript
|
|||
if(ptr.getClass().getType() == ESM::Container::sRecordId && (!ptr.getRefData().getCustomData() ||
|
||||
!ptr.getClass().getContainerStore(ptr).isResolved()))
|
||||
{
|
||||
ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), std::string{item}, count);
|
||||
ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), item, count);
|
||||
const ESM::Container* baseRecord = MWBase::Environment::get().getWorld()->getStore().get<ESM::Container>().find(ptr.getCellRef().getRefId());
|
||||
const auto& ptrs = MWBase::Environment::get().getWorld()->getAll(ptr.getCellRef().getRefId());
|
||||
for(const auto& container : ptrs)
|
||||
|
@ -231,14 +231,14 @@ namespace MWScript
|
|||
// Explicit calls to non-unique actors affect the base record
|
||||
if(!R::implicit && ptr.getClass().isActor() && MWBase::Environment::get().getWorld()->getStore().getRefCount(ptr.getCellRef().getRefId()) > 1)
|
||||
{
|
||||
ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), std::string{item}, -count);
|
||||
ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), item, -count);
|
||||
return;
|
||||
}
|
||||
// Calls to unresolved containers affect the base record instead
|
||||
else if(ptr.getClass().getType() == ESM::Container::sRecordId &&
|
||||
(!ptr.getRefData().getCustomData() || !ptr.getClass().getContainerStore(ptr).isResolved()))
|
||||
{
|
||||
ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), std::string{item}, -count);
|
||||
ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), item, -count);
|
||||
const ESM::Container* baseRecord = MWBase::Environment::get().getWorld()->getStore().get<ESM::Container>().find(ptr.getCellRef().getRefId());
|
||||
const auto& ptrs = MWBase::Environment::get().getWorld()->getAll(ptr.getCellRef().getRefId());
|
||||
for(const auto& container : ptrs)
|
||||
|
|
|
@ -64,7 +64,7 @@ namespace
|
|||
}
|
||||
|
||||
ESM::LevelledListBase::LevelItem item;
|
||||
item.mId = std::string{itemId};
|
||||
item.mId = itemId;
|
||||
item.mLevel = level;
|
||||
list->mList.push_back(item);
|
||||
}
|
||||
|
|
|
@ -531,7 +531,7 @@ namespace MWWorld
|
|||
throw std::runtime_error ("class does not have creature stats");
|
||||
}
|
||||
|
||||
void Class::modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount) const
|
||||
void Class::modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount) const
|
||||
{
|
||||
throw std::runtime_error ("class does not have an inventory store");
|
||||
}
|
||||
|
|
|
@ -368,7 +368,7 @@ namespace MWWorld
|
|||
|
||||
virtual void setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) const;
|
||||
|
||||
virtual void modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount) const;
|
||||
virtual void modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount) const;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue