mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 18:19:55 +00:00
Allows the same item to have multiple ancestors
This commit is contained in:
parent
b0e6a52595
commit
3b254ad631
4 changed files with 25 additions and 25 deletions
|
@ -444,12 +444,12 @@ void MWWorld::ContainerStore::addInitialItem (const std::string& id, const std::
|
||||||
if (!levItem.empty() && count < 0)
|
if (!levItem.empty() && count < 0)
|
||||||
{
|
{
|
||||||
//If there is no item in map, insert it
|
//If there is no item in map, insert it
|
||||||
std::map<std::string, std::pair<int, std::string> >::iterator itemInMap =
|
std::map<std::pair<std::string, std::string>, int>::iterator itemInMap =
|
||||||
mLevelledItemMap.insert(std::make_pair(id, std::make_pair(0, levItem))).first;
|
mLevelledItemMap.insert(std::make_pair(std::make_pair(id, levItem), 0)).first;
|
||||||
//Update spawned count
|
//Update spawned count
|
||||||
itemInMap->second.first += std::abs(count);
|
itemInMap->second += std::abs(count);
|
||||||
}
|
}
|
||||||
count = std::abs(count);
|
count = std::abs(count);
|
||||||
|
|
||||||
ref.getPtr().getCellRef().setOwner(owner);
|
ref.getPtr().getCellRef().setOwner(owner);
|
||||||
addImp (ref.getPtr(), count);
|
addImp (ref.getPtr(), count);
|
||||||
|
@ -470,47 +470,48 @@ void MWWorld::ContainerStore::restock (const ESM::InventoryList& items, const MW
|
||||||
std::map<std::string, int> allowedForReplace;
|
std::map<std::string, int> allowedForReplace;
|
||||||
|
|
||||||
//Check which lists need restocking:
|
//Check which lists need restocking:
|
||||||
for (std::map<std::string, std::pair<int, std::string> >::iterator it = mLevelledItemMap.begin(); it != mLevelledItemMap.end(); ++it)
|
for (std::map<std::pair<std::string, std::string>, int>::iterator it = mLevelledItemMap.begin(); it != mLevelledItemMap.end();)
|
||||||
{
|
{
|
||||||
int spawnedCount = it->second.first; //How many items should be in shop originally
|
int spawnedCount = it->second; //How many items should be in shop originally
|
||||||
int itemCount = count(it->first); //How many items are there in shop now
|
int itemCount = count(it->first.first); //How many items are there in shop now
|
||||||
//If something was not sold
|
//If something was not sold
|
||||||
if(itemCount >= spawnedCount)
|
if(itemCount >= spawnedCount)
|
||||||
{
|
{
|
||||||
const std::string& parent = it->second.second;
|
const std::string& parent = it->first.second;
|
||||||
// Security check for old saves:
|
// Security check for old saves:
|
||||||
//If item is imported from old save(doesn't have an parent) and wasn't sold
|
//If item is imported from old save(doesn't have an parent) and wasn't sold
|
||||||
if(parent == "")
|
if(parent == "")
|
||||||
{
|
{
|
||||||
//Remove it, from shop,
|
//Remove it, from shop,
|
||||||
remove(it->first, itemCount, ptr);//ptr is the NPC
|
remove(it->first.first, itemCount, ptr);//ptr is the NPC
|
||||||
//And remove it from map, so that when we restock, the new item will have proper parent.
|
//And remove it from map, so that when we restock, the new item will have proper parent.
|
||||||
mLevelledItemMap.erase(it);
|
mLevelledItemMap.erase(it++);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
}
|
}
|
||||||
//Create the entry if it does not exist yet
|
//Create the entry if it does not exist yet
|
||||||
std::map<std::string, int>::iterator listInMap = allowedForReplace.insert(
|
std::map<std::string, int>::iterator listInMap = allowedForReplace.insert(
|
||||||
std::make_pair(it->second.second, 0)).first;
|
std::make_pair(it->first.second, 0)).first;
|
||||||
//And signal that we don't need to restock item from this list
|
//And signal that we don't need to restock item from this list
|
||||||
listInMap->second += std::abs(itemCount);
|
listInMap->second += std::abs(itemCount);
|
||||||
}
|
}
|
||||||
//If every of the item was sold
|
//If every of the item was sold
|
||||||
else if (itemCount == 0)
|
else if (itemCount == 0)
|
||||||
{
|
{
|
||||||
mLevelledItemMap.erase(it);
|
mLevelledItemMap.erase(it++);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
//If some was sold, but some remain
|
//If some was sold, but some remain
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Create entry if it does not exist yet
|
//Create entry if it does not exist yet
|
||||||
std::map<std::string, int>::iterator listInMap = allowedForReplace.insert(
|
std::map<std::string, int>::iterator listInMap = allowedForReplace.insert(
|
||||||
std::make_pair(it->second.second, 0)).first;
|
std::make_pair(it->first.second, 0)).first;
|
||||||
//And signal that we don't need to restock all items from this list
|
//And signal that we don't need to restock all items from this list
|
||||||
listInMap->second += std::abs(itemCount);
|
listInMap->second += std::abs(itemCount);
|
||||||
//And update itemCount so we don't mistake it next time.
|
//And update itemCount so we don't mistake it next time.
|
||||||
it->second.first = itemCount;
|
it->second = itemCount;
|
||||||
}
|
}
|
||||||
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Restock:
|
//Restock:
|
||||||
|
@ -528,13 +529,12 @@ void MWWorld::ContainerStore::restock (const ESM::InventoryList& items, const MW
|
||||||
{
|
{
|
||||||
std::map<std::string, int>::iterator listInMap = allowedForReplace.find(itemOrList);
|
std::map<std::string, int>::iterator listInMap = allowedForReplace.find(itemOrList);
|
||||||
|
|
||||||
int restockNum = it-> mCount;
|
int restockNum = it->mCount;
|
||||||
//If we know we must restock less, take it into account
|
//If we know we must restock less, take it into account
|
||||||
if(listInMap != allowedForReplace.end())
|
if(listInMap != allowedForReplace.end())
|
||||||
restockNum += listInMap->second;//We add, because list items have negative count
|
restockNum += listInMap->second;//We add, because list items have negative count
|
||||||
//restock
|
//restock
|
||||||
addInitialItem(itemOrList, owner, restockNum, true);
|
addInitialItem(itemOrList, owner, restockNum, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -69,8 +69,8 @@ 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, std::pair<int, std::string> > mLevelledItemMap;
|
std::map<std::pair<std::string, std::string>, int> mLevelledItemMap;
|
||||||
///< Stores result of levelled item spawns. <refId, pair(count, spawningGroup)>
|
///< Stores result of levelled item spawns. <(refId, spawningGroup), count>
|
||||||
/// This is used to restock levelled items(s) if the old item was sold.
|
/// This is used to restock levelled items(s) if the old item was sold.
|
||||||
|
|
||||||
mutable float mCachedWeight;
|
mutable float mCachedWeight;
|
||||||
|
|
|
@ -44,7 +44,7 @@ void ESM::InventoryState::load (ESMReader &esm)
|
||||||
if(esm.isNextSub("LGRP"))
|
if(esm.isNextSub("LGRP"))
|
||||||
//Newest saves contain parent group
|
//Newest saves contain parent group
|
||||||
parentGroup = esm.getHString();
|
parentGroup = esm.getHString();
|
||||||
mLevelledItemMap[id] = std::make_pair(count, parentGroup);
|
mLevelledItemMap[std::make_pair(id, parentGroup)] = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (esm.isNextSub("MAGI"))
|
while (esm.isNextSub("MAGI"))
|
||||||
|
@ -86,11 +86,11 @@ void ESM::InventoryState::save (ESMWriter &esm) const
|
||||||
iter->save (esm, true);
|
iter->save (esm, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::map<std::string, std::pair<int, std::string> >::const_iterator it = mLevelledItemMap.begin(); it != mLevelledItemMap.end(); ++it)
|
for (std::map<std::pair<std::string, std::string>, int>::const_iterator it = mLevelledItemMap.begin(); it != mLevelledItemMap.end(); ++it)
|
||||||
{
|
{
|
||||||
esm.writeHNString ("LEVM", it->first);
|
esm.writeHNString ("LEVM", it->first.first);
|
||||||
esm.writeHNT ("COUN", it->second.first);
|
esm.writeHNT ("COUN", it->second);
|
||||||
esm.writeHNString("LGRP", it->second.second);
|
esm.writeHNString("LGRP", it->first.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, std::pair<int, std::string> > mLevelledItemMap;
|
std::map<std::pair<std::string, std::string>, int> 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…
Reference in a new issue