mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-05-10 04:26:50 +03: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);
|
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);
|
MWMechanics::modifyBaseInventory<ESM::Container>(containerId, itemId, amount);
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ namespace MWClass
|
||||||
|
|
||||||
bool useAnim() const override;
|
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);
|
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);
|
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 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;
|
float getWalkSpeed(const MWWorld::Ptr& ptr) const override;
|
||||||
|
|
||||||
|
|
|
@ -1495,7 +1495,7 @@ namespace MWClass
|
||||||
MWMechanics::setBaseAISetting<ESM::NPC>(id, setting, value);
|
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);
|
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 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;
|
float getWalkSpeed(const MWWorld::Ptr& ptr) const override;
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,12 @@
|
||||||
#include <components/esm3/loadcont.hpp>
|
#include <components/esm3/loadcont.hpp>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string_view>
|
||||||
|
|
||||||
namespace MWMechanics
|
namespace MWMechanics
|
||||||
{
|
{
|
||||||
template <class T>
|
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);
|
T copy = *MWBase::Environment::get().getWorld()->getStore().get<T>().find(actorId);
|
||||||
for (auto& it : copy.mInventory.mList)
|
for (auto& it : copy.mInventory.mList)
|
||||||
|
|
|
@ -118,7 +118,7 @@ namespace MWScript
|
||||||
// Explicit calls to non-unique actors affect the base record
|
// 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)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ namespace MWScript
|
||||||
if(ptr.getClass().getType() == ESM::Container::sRecordId && (!ptr.getRefData().getCustomData() ||
|
if(ptr.getClass().getType() == ESM::Container::sRecordId && (!ptr.getRefData().getCustomData() ||
|
||||||
!ptr.getClass().getContainerStore(ptr).isResolved()))
|
!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 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());
|
const auto& ptrs = MWBase::Environment::get().getWorld()->getAll(ptr.getCellRef().getRefId());
|
||||||
for(const auto& container : ptrs)
|
for(const auto& container : ptrs)
|
||||||
|
@ -231,14 +231,14 @@ namespace MWScript
|
||||||
// Explicit calls to non-unique actors affect the base record
|
// 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)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
// Calls to unresolved containers affect the base record instead
|
// Calls to unresolved containers affect the base record instead
|
||||||
else if(ptr.getClass().getType() == ESM::Container::sRecordId &&
|
else if(ptr.getClass().getType() == ESM::Container::sRecordId &&
|
||||||
(!ptr.getRefData().getCustomData() || !ptr.getClass().getContainerStore(ptr).isResolved()))
|
(!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 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());
|
const auto& ptrs = MWBase::Environment::get().getWorld()->getAll(ptr.getCellRef().getRefId());
|
||||||
for(const auto& container : ptrs)
|
for(const auto& container : ptrs)
|
||||||
|
|
|
@ -64,7 +64,7 @@ namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
ESM::LevelledListBase::LevelItem item;
|
ESM::LevelledListBase::LevelItem item;
|
||||||
item.mId = std::string{itemId};
|
item.mId = itemId;
|
||||||
item.mLevel = level;
|
item.mLevel = level;
|
||||||
list->mList.push_back(item);
|
list->mList.push_back(item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -531,7 +531,7 @@ namespace MWWorld
|
||||||
throw std::runtime_error ("class does not have creature stats");
|
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");
|
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 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…
Add table
Add a link
Reference in a new issue