1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-21 12:23:51 +00:00

Merge remote-tracking branch 'scrawl/item' into next

This commit is contained in:
Marc Zinnschlag 2013-04-25 10:21:14 +02:00
commit 71fc8f5830

View file

@ -193,59 +193,68 @@ void MWWorld::ContainerStore::addInitialItem (const std::string& id, const std::
{ {
count = std::abs(count); /// \todo implement item restocking (indicated by negative count) count = std::abs(count); /// \todo implement item restocking (indicated by negative count)
ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), id); try
if (ref.getPtr().getTypeName()==typeid (ESM::ItemLevList).name())
{ {
const ESM::ItemLevList* levItem = ref.getPtr().get<ESM::ItemLevList>()->mBase; ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), id);
const std::vector<ESM::LeveledListBase::LevelItem>& items = levItem->mList;
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); if (ref.getPtr().getTypeName()==typeid (ESM::ItemLevList).name())
int playerLevel = MWWorld::Class::get(player).getCreatureStats(player).getLevel();
failChance += levItem->mChanceNone;
if (topLevel && count > 1 && levItem->mFlags & ESM::ItemLevList::Each)
{ {
for (int i=0; i<count; ++i) const ESM::ItemLevList* levItem = ref.getPtr().get<ESM::ItemLevList>()->mBase;
addInitialItem(id, owner, 1, failChance, false); const std::vector<ESM::LeveledListBase::LevelItem>& items = levItem->mList;
return;
}
float random = static_cast<float> (std::rand()) / RAND_MAX; MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
if (random >= failChance/100.f) int playerLevel = MWWorld::Class::get(player).getCreatureStats(player).getLevel();
{
std::vector<std::string> candidates; failChance += levItem->mChanceNone;
int highestLevel = 0;
for (std::vector<ESM::LeveledListBase::LevelItem>::const_iterator it = items.begin(); it != items.end(); ++it) if (topLevel && count > 1 && levItem->mFlags & ESM::ItemLevList::Each)
{ {
if (it->mLevel > highestLevel) for (int i=0; i<count; ++i)
highestLevel = it->mLevel; addInitialItem(id, owner, 1, failChance, false);
return;
} }
std::pair<int, std::string> highest = std::make_pair(-1, ""); float random = static_cast<float> (std::rand()) / RAND_MAX;
for (std::vector<ESM::LeveledListBase::LevelItem>::const_iterator it = items.begin(); it != items.end(); ++it) if (random >= failChance/100.f)
{ {
if (playerLevel >= it->mLevel std::vector<std::string> candidates;
&& (levItem->mFlags & ESM::ItemLevList::AllLevels || it->mLevel == highestLevel)) int highestLevel = 0;
for (std::vector<ESM::LeveledListBase::LevelItem>::const_iterator it = items.begin(); it != items.end(); ++it)
{ {
candidates.push_back(it->mId); if (it->mLevel > highestLevel)
if (it->mLevel >= highest.first) highestLevel = it->mLevel;
highest = std::make_pair(it->mLevel, it->mId);
} }
std::pair<int, std::string> highest = std::make_pair(-1, "");
for (std::vector<ESM::LeveledListBase::LevelItem>::const_iterator it = items.begin(); it != items.end(); ++it)
{
if (playerLevel >= it->mLevel
&& (levItem->mFlags & ESM::ItemLevList::AllLevels || it->mLevel == highestLevel))
{
candidates.push_back(it->mId);
if (it->mLevel >= highest.first)
highest = std::make_pair(it->mLevel, it->mId);
}
}
if (!candidates.size())
return;
std::string item = candidates[std::rand()%candidates.size()];
addInitialItem(item, owner, count, failChance, false);
} }
if (!candidates.size()) }
return; else
std::string item = candidates[std::rand()%candidates.size()]; {
addInitialItem(item, owner, count, failChance, false); ref.getPtr().getRefData().setCount (count);
ref.getPtr().getCellRef().mOwner = owner;
addImp (ref.getPtr());
} }
} }
else catch (std::logic_error& e)
{ {
ref.getPtr().getRefData().setCount (count); // Vanilla doesn't fail on nonexistent items in levelled lists
ref.getPtr().getCellRef().mOwner = owner; std::cerr << "Warning: ignoring nonexistent item '" << id << "'" << std::endl;
addImp (ref.getPtr()); return;
} }
} }