mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-05 15:45:33 +00:00
Merge branch 'autogoesbrr' into 'master'
Use range based for loops and auto See merge request OpenMW/openmw!400
This commit is contained in:
commit
c742c15f6d
2 changed files with 34 additions and 42 deletions
|
@ -48,9 +48,9 @@ namespace MWGui
|
||||||
const MWWorld::ESMStore &store =
|
const MWWorld::ESMStore &store =
|
||||||
MWBase::Environment::get().getWorld()->getStore();
|
MWBase::Environment::get().getWorld()->getStore();
|
||||||
|
|
||||||
for (unsigned int i = 0; i < effects.mList.size(); ++i)
|
for (const auto& effect : effects.mList)
|
||||||
{
|
{
|
||||||
short effectId = effects.mList[i].mEffectID;
|
short effectId = effect.mEffectID;
|
||||||
|
|
||||||
if (effectId != -1)
|
if (effectId != -1)
|
||||||
{
|
{
|
||||||
|
@ -59,14 +59,14 @@ namespace MWGui
|
||||||
std::string effectIDStr = ESM::MagicEffect::effectIdToString(effectId);
|
std::string effectIDStr = ESM::MagicEffect::effectIdToString(effectId);
|
||||||
std::string fullEffectName = wm->getGameSettingString(effectIDStr, "");
|
std::string fullEffectName = wm->getGameSettingString(effectIDStr, "");
|
||||||
|
|
||||||
if (magicEffect->mData.mFlags & ESM::MagicEffect::TargetSkill && effects.mList[i].mSkill != -1)
|
if (magicEffect->mData.mFlags & ESM::MagicEffect::TargetSkill && effect.mSkill != -1)
|
||||||
{
|
{
|
||||||
fullEffectName += " " + wm->getGameSettingString(ESM::Skill::sSkillNameIds[effects.mList[i].mSkill], "");
|
fullEffectName += " " + wm->getGameSettingString(ESM::Skill::sSkillNameIds[effect.mSkill], "");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (magicEffect->mData.mFlags & ESM::MagicEffect::TargetAttribute && effects.mList[i].mAttribute != -1)
|
if (magicEffect->mData.mFlags & ESM::MagicEffect::TargetAttribute && effect.mAttribute != -1)
|
||||||
{
|
{
|
||||||
fullEffectName += " " + wm->getGameSettingString(ESM::Attribute::sGmstAttributeIds[effects.mList[i].mAttribute], "");
|
fullEffectName += " " + wm->getGameSettingString(ESM::Attribute::sGmstAttributeIds[effect.mAttribute], "");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string convert = Misc::StringUtils::lowerCaseUtf8(fullEffectName);
|
std::string convert = Misc::StringUtils::lowerCaseUtf8(fullEffectName);
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace
|
||||||
void addScripts(MWWorld::ContainerStore& store, MWWorld::CellStore* cell)
|
void addScripts(MWWorld::ContainerStore& store, MWWorld::CellStore* cell)
|
||||||
{
|
{
|
||||||
auto& scripts = MWBase::Environment::get().getWorld()->getLocalScripts();
|
auto& scripts = MWBase::Environment::get().getWorld()->getLocalScripts();
|
||||||
for(const MWWorld::Ptr& ptr : store)
|
for(const auto&& ptr : store)
|
||||||
{
|
{
|
||||||
const std::string& script = ptr.getClass().getScript(ptr);
|
const std::string& script = ptr.getClass().getScript(ptr);
|
||||||
if(!script.empty())
|
if(!script.empty())
|
||||||
|
@ -43,13 +43,10 @@ namespace
|
||||||
{
|
{
|
||||||
float sum = 0;
|
float sum = 0;
|
||||||
|
|
||||||
for (typename MWWorld::CellRefList<T>::List::const_iterator iter (
|
for (const auto& iter : cellRefList.mList)
|
||||||
cellRefList.mList.begin());
|
|
||||||
iter!=cellRefList.mList.end();
|
|
||||||
++iter)
|
|
||||||
{
|
{
|
||||||
if (iter->mData.getCount()>0)
|
if (iter.mData.getCount()>0)
|
||||||
sum += iter->mData.getCount()*iter->mBase->mData.mWeight;
|
sum += iter.mData.getCount()*iter.mBase->mData.mWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sum;
|
return sum;
|
||||||
|
@ -62,12 +59,11 @@ namespace
|
||||||
store->resolve();
|
store->resolve();
|
||||||
std::string id2 = Misc::StringUtils::lowerCase (id);
|
std::string id2 = Misc::StringUtils::lowerCase (id);
|
||||||
|
|
||||||
for (typename MWWorld::CellRefList<T>::List::iterator iter (list.mList.begin());
|
for (auto& iter : list.mList)
|
||||||
iter!=list.mList.end(); ++iter)
|
|
||||||
{
|
{
|
||||||
if (Misc::StringUtils::ciEqual(iter->mBase->mId, id2) && iter->mData.getCount())
|
if (Misc::StringUtils::ciEqual(iter.mBase->mId, id2) && iter.mData.getCount())
|
||||||
{
|
{
|
||||||
MWWorld::Ptr ptr (&*iter, nullptr);
|
MWWorld::Ptr ptr (&iter, nullptr);
|
||||||
ptr.setContainerStore (store);
|
ptr.setContainerStore (store);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
@ -81,7 +77,7 @@ MWWorld::ResolutionListener::~ResolutionListener()
|
||||||
{
|
{
|
||||||
if(!mStore.mModified && mStore.mResolved && !mStore.mPtr.isEmpty())
|
if(!mStore.mModified && mStore.mResolved && !mStore.mPtr.isEmpty())
|
||||||
{
|
{
|
||||||
for(const MWWorld::Ptr& ptr : mStore)
|
for(const auto&& ptr : mStore)
|
||||||
ptr.getRefData().setCount(0);
|
ptr.getRefData().setCount(0);
|
||||||
mStore.fillNonRandom(mStore.mPtr.get<ESM::Container>()->mBase->mInventory, "", mStore.mSeed);
|
mStore.fillNonRandom(mStore.mPtr.get<ESM::Container>()->mBase->mInventory, "", mStore.mSeed);
|
||||||
addScripts(mStore, mStore.mPtr.mCell);
|
addScripts(mStore, mStore.mPtr.mCell);
|
||||||
|
@ -127,15 +123,14 @@ template<typename T>
|
||||||
void MWWorld::ContainerStore::storeStates (const CellRefList<T>& collection,
|
void MWWorld::ContainerStore::storeStates (const CellRefList<T>& collection,
|
||||||
ESM::InventoryState& inventory, int& index, bool equipable) const
|
ESM::InventoryState& inventory, int& index, bool equipable) const
|
||||||
{
|
{
|
||||||
for (typename CellRefList<T>::List::const_iterator iter (collection.mList.begin());
|
for (const auto& iter : collection.mList)
|
||||||
iter!=collection.mList.end(); ++iter)
|
|
||||||
{
|
{
|
||||||
if (iter->mData.getCount() == 0)
|
if (iter.mData.getCount() == 0)
|
||||||
continue;
|
continue;
|
||||||
ESM::ObjectState state;
|
ESM::ObjectState state;
|
||||||
storeState (*iter, state);
|
storeState (iter, state);
|
||||||
if (equipable)
|
if (equipable)
|
||||||
storeEquipmentState(*iter, index, inventory);
|
storeEquipmentState(iter, index, inventory);
|
||||||
inventory.mItems.push_back (state);
|
inventory.mItems.push_back (state);
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
|
@ -188,7 +183,7 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::end()
|
||||||
int MWWorld::ContainerStore::count(const std::string &id) const
|
int MWWorld::ContainerStore::count(const std::string &id) const
|
||||||
{
|
{
|
||||||
int total=0;
|
int total=0;
|
||||||
for (const auto& iter : *this)
|
for (const auto&& iter : *this)
|
||||||
if (Misc::StringUtils::ciEqual(iter.getCellRef().getRefId(), id))
|
if (Misc::StringUtils::ciEqual(iter.getCellRef().getRefId(), id))
|
||||||
total += iter.getRefData().getCount();
|
total += iter.getRefData().getCount();
|
||||||
return total;
|
return total;
|
||||||
|
@ -430,14 +425,14 @@ void MWWorld::ContainerStore::rechargeItems(float duration)
|
||||||
updateRechargingItems();
|
updateRechargingItems();
|
||||||
mRechargingItemsUpToDate = true;
|
mRechargingItemsUpToDate = true;
|
||||||
}
|
}
|
||||||
for (TRechargingItems::iterator it = mRechargingItems.begin(); it != mRechargingItems.end(); ++it)
|
for (auto& it : mRechargingItems)
|
||||||
{
|
{
|
||||||
if (!MWMechanics::rechargeItem(*it->first, it->second, duration))
|
if (!MWMechanics::rechargeItem(*it.first, it.second, duration))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// attempt to restack when fully recharged
|
// attempt to restack when fully recharged
|
||||||
if (it->first->getCellRef().getEnchantmentCharge() == it->second)
|
if (it.first->getCellRef().getEnchantmentCharge() == it.second)
|
||||||
it->first = restack(*it->first);
|
it.first = restack(*it.first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -481,9 +476,9 @@ int MWWorld::ContainerStore::remove(const std::string& itemId, int count, const
|
||||||
|
|
||||||
bool MWWorld::ContainerStore::hasVisibleItems() const
|
bool MWWorld::ContainerStore::hasVisibleItems() const
|
||||||
{
|
{
|
||||||
for (auto iter(begin()); iter != end(); ++iter)
|
for (const auto&& iter : *this)
|
||||||
{
|
{
|
||||||
if (iter->getClass().showsInInventory(*iter))
|
if (iter.getClass().showsInInventory(iter))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -601,8 +596,8 @@ void MWWorld::ContainerStore::addInitialItemImp(const MWWorld::Ptr& ptr, const s
|
||||||
|
|
||||||
void MWWorld::ContainerStore::clear()
|
void MWWorld::ContainerStore::clear()
|
||||||
{
|
{
|
||||||
for (ContainerStoreIterator iter (begin()); iter!=end(); ++iter)
|
for (auto&& iter : *this)
|
||||||
iter->getRefData().setCount (0);
|
iter.getRefData().setCount (0);
|
||||||
|
|
||||||
flagAsModified();
|
flagAsModified();
|
||||||
mModified = true;
|
mModified = true;
|
||||||
|
@ -623,7 +618,7 @@ void MWWorld::ContainerStore::resolve()
|
||||||
{
|
{
|
||||||
if(!mResolved && !mPtr.isEmpty())
|
if(!mResolved && !mPtr.isEmpty())
|
||||||
{
|
{
|
||||||
for(const MWWorld::Ptr& ptr : *this)
|
for(const auto&& ptr : *this)
|
||||||
ptr.getRefData().setCount(0);
|
ptr.getRefData().setCount(0);
|
||||||
Misc::Rng::Seed seed{mSeed};
|
Misc::Rng::Seed seed{mSeed};
|
||||||
fill(mPtr.get<ESM::Container>()->mBase->mInventory, "", seed);
|
fill(mPtr.get<ESM::Container>()->mBase->mInventory, "", seed);
|
||||||
|
@ -644,7 +639,7 @@ MWWorld::ResolutionHandle MWWorld::ContainerStore::resolveTemporarily()
|
||||||
}
|
}
|
||||||
if(!mResolved && !mPtr.isEmpty())
|
if(!mResolved && !mPtr.isEmpty())
|
||||||
{
|
{
|
||||||
for(const MWWorld::Ptr& ptr : *this)
|
for(const auto&& ptr : *this)
|
||||||
ptr.getRefData().setCount(0);
|
ptr.getRefData().setCount(0);
|
||||||
Misc::Rng::Seed seed{mSeed};
|
Misc::Rng::Seed seed{mSeed};
|
||||||
fill(mPtr.get<ESM::Container>()->mBase->mInventory, "", seed);
|
fill(mPtr.get<ESM::Container>()->mBase->mInventory, "", seed);
|
||||||
|
@ -727,10 +722,10 @@ MWWorld::Ptr MWWorld::ContainerStore::findReplacement(const std::string& id)
|
||||||
{
|
{
|
||||||
MWWorld::Ptr item;
|
MWWorld::Ptr item;
|
||||||
int itemHealth = 1;
|
int itemHealth = 1;
|
||||||
for (MWWorld::ContainerStoreIterator iter = begin(); iter != end(); ++iter)
|
for (auto&& iter : *this)
|
||||||
{
|
{
|
||||||
int iterHealth = iter->getClass().hasItemHealth(*iter) ? iter->getClass().getItemHealth(*iter) : 1;
|
int iterHealth = iter.getClass().hasItemHealth(iter) ? iter.getClass().getItemHealth(iter) : 1;
|
||||||
if (Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), id))
|
if (Misc::StringUtils::ciEqual(iter.getCellRef().getRefId(), id))
|
||||||
{
|
{
|
||||||
// Prefer the stack with the lowest remaining uses
|
// Prefer the stack with the lowest remaining uses
|
||||||
// Try to get item with zero durability only if there are no other items found
|
// Try to get item with zero durability only if there are no other items found
|
||||||
|
@ -738,7 +733,7 @@ MWWorld::Ptr MWWorld::ContainerStore::findReplacement(const std::string& id)
|
||||||
(iterHealth > 0 && iterHealth < itemHealth) ||
|
(iterHealth > 0 && iterHealth < itemHealth) ||
|
||||||
(itemHealth <= 0 && iterHealth > 0))
|
(itemHealth <= 0 && iterHealth > 0))
|
||||||
{
|
{
|
||||||
item = *iter;
|
item = iter;
|
||||||
itemHealth = iterHealth;
|
itemHealth = iterHealth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -867,11 +862,8 @@ void MWWorld::ContainerStore::readState (const ESM::InventoryState& inventory)
|
||||||
mResolved = true;
|
mResolved = true;
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (std::vector<ESM::ObjectState>::const_iterator
|
for (const ESM::ObjectState& state : inventory.mItems)
|
||||||
iter (inventory.mItems.begin()); iter!=inventory.mItems.end(); ++iter)
|
|
||||||
{
|
{
|
||||||
const ESM::ObjectState& state = *iter;
|
|
||||||
|
|
||||||
int type = MWBase::Environment::get().getWorld()->getStore().find(state.mRef.mRefID);
|
int type = MWBase::Environment::get().getWorld()->getStore().find(state.mRef.mRefID);
|
||||||
|
|
||||||
int thisIndex = index++;
|
int thisIndex = index++;
|
||||||
|
|
Loading…
Reference in a new issue