mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Fixing bug for merchant
This commit is contained in:
parent
46e07e4b19
commit
a662a00c62
@ -442,9 +442,11 @@ void MWWorld::ContainerStore::addInitialItem (const std::string& id, const std::
|
|||||||
// For a restocking levelled item, remember what we spawned so we can delete it later when the merchant restocks
|
// For a restocking levelled item, remember what we spawned so we can delete it later when the merchant restocks
|
||||||
if (!levItem.empty() && count < 0)
|
if (!levItem.empty() && count < 0)
|
||||||
{
|
{
|
||||||
if (mLevelledItemMap.find(id) == mLevelledItemMap.end())
|
//If there is no item in map, insert it
|
||||||
mLevelledItemMap[id] = 0;
|
std::map<std::string, std::pair<int, std::string> >::iterator itemInMap =
|
||||||
mLevelledItemMap[id] += std::abs(count);
|
mLevelledItemMap.insert(std::make_pair(id, std::make_pair(0, levItem))).first;
|
||||||
|
//Update spawned count
|
||||||
|
itemInMap->second.first += std::abs(count);
|
||||||
}
|
}
|
||||||
count = std::abs(count);
|
count = std::abs(count);
|
||||||
|
|
||||||
@ -461,30 +463,56 @@ void MWWorld::ContainerStore::addInitialItem (const std::string& id, const std::
|
|||||||
|
|
||||||
void MWWorld::ContainerStore::restock (const ESM::InventoryList& items, const MWWorld::Ptr& ptr, const std::string& owner)
|
void MWWorld::ContainerStore::restock (const ESM::InventoryList& items, const MWWorld::Ptr& ptr, const std::string& owner)
|
||||||
{
|
{
|
||||||
// Remove the items already spawned by levelled items that will restock
|
//allowedForReplace - Holds information about how many items from the list were sold;
|
||||||
for (std::map<std::string, int>::iterator it = mLevelledItemMap.begin(); it != mLevelledItemMap.end(); ++it)
|
// Hence, tells us how many items we need to restock.
|
||||||
{
|
//allowedForReplace[list] <- How many items we should generate(how many of these were sold)
|
||||||
if (count(it->first) >= it->second)
|
std::map<std::string, int> allowedForReplace;
|
||||||
remove(it->first, it->second, ptr);
|
|
||||||
}
|
|
||||||
mLevelledItemMap.clear();
|
|
||||||
|
|
||||||
|
//Check which lists need restocking:
|
||||||
|
for (std::map<std::string, std::pair<int, std::string> >::iterator it = mLevelledItemMap.begin(); it != mLevelledItemMap.end(); ++it)
|
||||||
|
{
|
||||||
|
int spawnedCount = it->second.first; //How many items should be in shop originally
|
||||||
|
int itemCount = count(it->first); //How many items are there in shop now
|
||||||
|
//If anything was sold
|
||||||
|
if(itemCount < spawnedCount)
|
||||||
|
{
|
||||||
|
//Create entry if it does not exist yet
|
||||||
|
std::map<std::string, int>::iterator listInMap = allowedForReplace.insert(
|
||||||
|
std::make_pair(it->second.second, 0)).first;
|
||||||
|
//And signal that we need to restock item from this list
|
||||||
|
listInMap->second += std::abs(spawnedCount - itemCount);
|
||||||
|
//Also, remove the record if item no longer figures in the shop
|
||||||
|
if(!itemCount)
|
||||||
|
mLevelledItemMap.erase(it->first);
|
||||||
|
//If there's still item in the shop, change its spawnedCount to current count.
|
||||||
|
else
|
||||||
|
it->second.first -= itemCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Restock:
|
||||||
|
//For every item that NPC could have
|
||||||
for (std::vector<ESM::ContItem>::const_iterator it = items.mList.begin(); it != items.mList.end(); ++it)
|
for (std::vector<ESM::ContItem>::const_iterator it = items.mList.begin(); it != items.mList.end(); ++it)
|
||||||
{
|
{
|
||||||
|
//If he shouldn't have it restocked, don't restock it.
|
||||||
if (it->mCount >= 0)
|
if (it->mCount >= 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
std::string item = Misc::StringUtils::lowerCase(it->mItem.toString());
|
std::string itemOrList = Misc::StringUtils::lowerCase(it->mItem.toString());
|
||||||
|
|
||||||
|
//If it's levelled list, restock if there's need to do so.
|
||||||
if (MWBase::Environment::get().getWorld()->getStore().get<ESM::ItemLevList>().search(it->mItem.toString()))
|
if (MWBase::Environment::get().getWorld()->getStore().get<ESM::ItemLevList>().search(it->mItem.toString()))
|
||||||
{
|
{
|
||||||
addInitialItem(item, owner, it->mCount, true);
|
std::map<std::string, int>::iterator listInMap = allowedForReplace.find(itemOrList);
|
||||||
|
if(listInMap != allowedForReplace.end())
|
||||||
|
addInitialItem(itemOrList, owner, listInMap->second, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int currentCount = count(item);
|
//Restocking static item - just restock to the max count
|
||||||
|
int currentCount = count(itemOrList);
|
||||||
if (currentCount < std::abs(it->mCount))
|
if (currentCount < std::abs(it->mCount))
|
||||||
addInitialItem(item, owner, std::abs(it->mCount) - currentCount, true);
|
addInitialItem(itemOrList, owner, std::abs(it->mCount) - currentCount, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
flagAsModified();
|
flagAsModified();
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include <components/esm/loadalch.hpp>
|
#include <components/esm/loadalch.hpp>
|
||||||
#include <components/esm/loadappa.hpp>
|
#include <components/esm/loadappa.hpp>
|
||||||
@ -68,9 +69,9 @@ namespace MWWorld
|
|||||||
MWWorld::CellRefList<ESM::Repair> repairs;
|
MWWorld::CellRefList<ESM::Repair> repairs;
|
||||||
MWWorld::CellRefList<ESM::Weapon> weapons;
|
MWWorld::CellRefList<ESM::Weapon> weapons;
|
||||||
|
|
||||||
std::map<std::string, int> mLevelledItemMap;
|
std::map<std::string, std::pair<int, std::string> > mLevelledItemMap;
|
||||||
///< Stores result of levelled item spawns. <refId, count>
|
///< Stores result of levelled item spawns. <refId, pair(count, spawningGroup)>
|
||||||
/// This is used to remove the spawned item(s) if the levelled item is restocked.
|
/// This is used to restock levelled items(s) if the old item was sold.
|
||||||
|
|
||||||
mutable float mCachedWeight;
|
mutable float mCachedWeight;
|
||||||
mutable bool mWeightUpToDate;
|
mutable bool mWeightUpToDate;
|
||||||
|
@ -36,6 +36,10 @@ void ESM::InventoryState::load (ESMReader &esm)
|
|||||||
{
|
{
|
||||||
std::string id = esm.getHString();
|
std::string id = esm.getHString();
|
||||||
int count;
|
int count;
|
||||||
|
std::string parentList;
|
||||||
|
//TODO: How should I handle old saves?
|
||||||
|
if(esm.isNextSub("LLST"))
|
||||||
|
std::string parentList = esm.getHString();
|
||||||
esm.getHNT (count, "COUN");
|
esm.getHNT (count, "COUN");
|
||||||
mLevelledItemMap[id] = count;
|
mLevelledItemMap[id] = count;
|
||||||
}
|
}
|
||||||
@ -79,10 +83,11 @@ void ESM::InventoryState::save (ESMWriter &esm) const
|
|||||||
iter->save (esm, true);
|
iter->save (esm, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::map<std::string, int>::const_iterator it = mLevelledItemMap.begin(); it != mLevelledItemMap.end(); ++it)
|
for (std::map<std::string, std::pair<int, std::string> >::const_iterator it = mLevelledItemMap.begin(); it != mLevelledItemMap.end(); ++it)
|
||||||
{
|
{
|
||||||
esm.writeHNString ("LEVM", it->first);
|
esm.writeHNString ("LEVM", it->first);
|
||||||
esm.writeHNT ("COUN", it->second);
|
esm.writeHNT ("COUN", it->second.first);
|
||||||
|
esm.writeHNString("LLST", it->second.second)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (TEffectMagnitudes::const_iterator it = mPermanentMagicEffectMagnitudes.begin(); it != mPermanentMagicEffectMagnitudes.end(); ++it)
|
for (TEffectMagnitudes::const_iterator it = mPermanentMagicEffectMagnitudes.begin(); it != mPermanentMagicEffectMagnitudes.end(); ++it)
|
||||||
|
@ -20,7 +20,7 @@ namespace ESM
|
|||||||
// <Index in mItems, equipment slot>
|
// <Index in mItems, equipment slot>
|
||||||
std::map<int, int> mEquipmentSlots;
|
std::map<int, int> mEquipmentSlots;
|
||||||
|
|
||||||
std::map<std::string, int> mLevelledItemMap;
|
std::map<std::string, std::pair<int, std::string> > mLevelledItemMap;
|
||||||
|
|
||||||
typedef std::map<std::string, std::vector<std::pair<float, float> > > TEffectMagnitudes;
|
typedef std::map<std::string, std::vector<std::pair<float, float> > > TEffectMagnitudes;
|
||||||
TEffectMagnitudes mPermanentMagicEffectMagnitudes;
|
TEffectMagnitudes mPermanentMagicEffectMagnitudes;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user