mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 21:49:55 +00:00
Merge branch 'thelevelling' into 'master'
Allow adding levelled lists using AddItem Closes #2404 See merge request OpenMW/openmw!358
This commit is contained in:
commit
2972033a72
4 changed files with 40 additions and 12 deletions
|
@ -60,6 +60,7 @@
|
|||
Bug #5644: Summon effects running on the player during game initialization cause crashes
|
||||
Feature #390: 3rd person look "over the shoulder"
|
||||
Feature #2386: Distant Statics in the form of Object Paging
|
||||
Feature #2404: Levelled List can not be placed into a container
|
||||
Feature #4894: Consider actors as obstacles for pathfinding
|
||||
Feature #5043: Head Bobbing
|
||||
Feature #5297: Add a search function to the "Datafiles" tab of the OpenMW launcher
|
||||
|
|
|
@ -28,12 +28,13 @@
|
|||
#include "../mwworld/manualref.hpp"
|
||||
|
||||
#include "../mwmechanics/actorutil.hpp"
|
||||
#include "../mwmechanics/levelledlist.hpp"
|
||||
|
||||
#include "ref.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
void addToStore(MWWorld::Ptr& itemPtr, int count, MWWorld::Ptr& ptr, MWWorld::ContainerStore& store, bool resolve = true)
|
||||
void addToStore(const MWWorld::Ptr& itemPtr, int count, MWWorld::Ptr& ptr, MWWorld::ContainerStore& store, bool resolve = true)
|
||||
{
|
||||
if (itemPtr.getClass().getScript(itemPtr).empty())
|
||||
{
|
||||
|
@ -46,6 +47,30 @@ namespace
|
|||
store.add (itemPtr, 1, ptr, true, resolve);
|
||||
}
|
||||
}
|
||||
|
||||
void addRandomToStore(const MWWorld::Ptr& itemPtr, int count, MWWorld::Ptr& owner, MWWorld::ContainerStore& store, bool topLevel = true)
|
||||
{
|
||||
if(itemPtr.getTypeName() == typeid(ESM::ItemLevList).name())
|
||||
{
|
||||
const ESM::ItemLevList* levItemList = itemPtr.get<ESM::ItemLevList>()->mBase;
|
||||
|
||||
if(topLevel && count > 1 && levItemList->mFlags & ESM::ItemLevList::Each)
|
||||
{
|
||||
for(int i = 0; i < count; i++)
|
||||
addRandomToStore(itemPtr, 1, owner, store, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string itemId = MWMechanics::getLevelledItem(itemPtr.get<ESM::ItemLevList>()->mBase, false);
|
||||
if (itemId.empty())
|
||||
return;
|
||||
MWWorld::ManualRef manualRef(MWBase::Environment::get().getWorld()->getStore(), itemId, 1);
|
||||
addRandomToStore(manualRef.getPtr(), count, owner, store, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
addToStore(itemPtr, count, owner, store);
|
||||
}
|
||||
}
|
||||
|
||||
namespace MWScript
|
||||
|
@ -112,7 +137,7 @@ namespace MWScript
|
|||
{
|
||||
if(store.isResolved())
|
||||
{
|
||||
// TODO #2404
|
||||
addRandomToStore(itemPtr, count, ptr, store);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -122,8 +147,10 @@ namespace MWScript
|
|||
return;
|
||||
}
|
||||
MWWorld::ContainerStore& store = ptr.getClass().getContainerStore(ptr);
|
||||
// TODO #2404
|
||||
addToStore(itemPtr, count, ptr, store);
|
||||
if(isLevelledList)
|
||||
addRandomToStore(itemPtr, count, ptr, store);
|
||||
else
|
||||
addToStore(itemPtr, count, ptr, store);
|
||||
|
||||
// Spawn a messagebox (only for items added to player's inventory and if player is talking to someone)
|
||||
if (ptr == MWBase::Environment::get().getWorld ()->getPlayerPtr() )
|
||||
|
|
|
@ -550,7 +550,7 @@ void MWWorld::ContainerStore::fillNonRandom (const ESM::InventoryList& items, co
|
|||
}
|
||||
|
||||
void MWWorld::ContainerStore::addInitialItem (const std::string& id, const std::string& owner, int count,
|
||||
Misc::Rng::Seed* seed, bool topLevel, const std::string& levItem)
|
||||
Misc::Rng::Seed* seed, bool topLevel)
|
||||
{
|
||||
if (count == 0) return; //Don't restock with nothing.
|
||||
try
|
||||
|
@ -558,13 +558,13 @@ void MWWorld::ContainerStore::addInitialItem (const std::string& id, const std::
|
|||
ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), id, count);
|
||||
if (ref.getPtr().getClass().getScript(ref.getPtr()).empty())
|
||||
{
|
||||
addInitialItemImp(ref.getPtr(), owner, count, seed, topLevel, levItem);
|
||||
addInitialItemImp(ref.getPtr(), owner, count, seed, topLevel);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Adding just one item per time to make sure there isn't a stack of scripted items
|
||||
for (int i = 0; i < std::abs(count); i++)
|
||||
addInitialItemImp(ref.getPtr(), owner, count < 0 ? -1 : 1, seed, topLevel, levItem);
|
||||
addInitialItemImp(ref.getPtr(), owner, count < 0 ? -1 : 1, seed, topLevel);
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
|
@ -574,7 +574,7 @@ void MWWorld::ContainerStore::addInitialItem (const std::string& id, const std::
|
|||
}
|
||||
|
||||
void MWWorld::ContainerStore::addInitialItemImp(const MWWorld::Ptr& ptr, const std::string& owner, int count,
|
||||
Misc::Rng::Seed* seed, bool topLevel, const std::string& levItem)
|
||||
Misc::Rng::Seed* seed, bool topLevel)
|
||||
{
|
||||
if (ptr.getTypeName()==typeid (ESM::ItemLevList).name())
|
||||
{
|
||||
|
@ -585,7 +585,7 @@ void MWWorld::ContainerStore::addInitialItemImp(const MWWorld::Ptr& ptr, const s
|
|||
if (topLevel && std::abs(count) > 1 && levItemList->mFlags & ESM::ItemLevList::Each)
|
||||
{
|
||||
for (int i=0; i<std::abs(count); ++i)
|
||||
addInitialItem(ptr.getCellRef().getRefId(), owner, count > 0 ? 1 : -1, seed, true, levItemList->mId);
|
||||
addInitialItem(ptr.getCellRef().getRefId(), owner, count > 0 ? 1 : -1, seed, true);
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
@ -593,7 +593,7 @@ void MWWorld::ContainerStore::addInitialItemImp(const MWWorld::Ptr& ptr, const s
|
|||
std::string itemId = MWMechanics::getLevelledItem(ptr.get<ESM::ItemLevList>()->mBase, false, *seed);
|
||||
if (itemId.empty())
|
||||
return;
|
||||
addInitialItem(itemId, owner, count, seed, false, levItemList->mId);
|
||||
addInitialItem(itemId, owner, count, seed, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -126,8 +126,8 @@ namespace MWWorld
|
|||
std::weak_ptr<ResolutionListener> mResolutionListener;
|
||||
|
||||
ContainerStoreIterator addImp (const Ptr& ptr, int count, bool markModified = true);
|
||||
void addInitialItem (const std::string& id, const std::string& owner, int count, Misc::Rng::Seed* seed, bool topLevel=true, const std::string& levItem = "");
|
||||
void addInitialItemImp (const MWWorld::Ptr& ptr, const std::string& owner, int count, Misc::Rng::Seed* seed, bool topLevel=true, const std::string& levItem = "");
|
||||
void addInitialItem (const std::string& id, const std::string& owner, int count, Misc::Rng::Seed* seed, bool topLevel=true);
|
||||
void addInitialItemImp (const MWWorld::Ptr& ptr, const std::string& owner, int count, Misc::Rng::Seed* seed, bool topLevel=true);
|
||||
|
||||
int removeImp(const Ptr& item, int count, const Ptr& actor);
|
||||
|
||||
|
|
Loading…
Reference in a new issue