1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 18:35:20 +00:00

Use vector for mUsedPowers for deterministic order

This commit is contained in:
ζeh Matt 2022-03-25 20:42:01 +02:00
parent 6d55317d57
commit dcdba227f7
No known key found for this signature in database
GPG Key ID: 18CE582C71A225B0
2 changed files with 10 additions and 4 deletions

View File

@ -185,13 +185,19 @@ namespace MWMechanics
bool Spells::canUsePower(const ESM::Spell* spell) const
{
const auto it = mUsedPowers.find(spell);
const auto it = std::find_if(std::begin(mUsedPowers), std::end(mUsedPowers), [&](auto& pair) { return pair.first == spell; });
return it == mUsedPowers.end() || it->second + 24 <= MWBase::Environment::get().getWorld()->getTimeStamp();
}
void Spells::usePower(const ESM::Spell* spell)
{
mUsedPowers[spell] = MWBase::Environment::get().getWorld()->getTimeStamp();
// Updates or inserts a new entry with the current timestamp.
const auto it = std::find_if(std::begin(mUsedPowers), std::end(mUsedPowers), [&](auto& pair) { return pair.first == spell; });
const auto timestamp = MWBase::Environment::get().getWorld()->getTimeStamp();
if (it == mUsedPowers.end())
mUsedPowers.emplace_back(spell, timestamp);
else
it->second = timestamp;
}
void Spells::readState(const ESM::SpellState &state, CreatureStats* creatureStats)
@ -223,7 +229,7 @@ namespace MWMechanics
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search(it->first);
if (!spell)
continue;
mUsedPowers[spell] = MWWorld::TimeStamp(it->second);
mUsedPowers.emplace_back(spell, MWWorld::TimeStamp(it->second));
}
// Permanent effects are used only to keep the custom magnitude of corprus spells effects (after cure too), and only in old saves. Convert data to the new approach.

View File

@ -34,7 +34,7 @@ namespace MWMechanics
// Note: this is the spell that's about to be cast, *not* the spell selected in the GUI (which may be different)
std::string mSelectedSpell;
std::map<const ESM::Spell*, MWWorld::TimeStamp> mUsedPowers;
std::vector<std::pair<const ESM::Spell*, MWWorld::TimeStamp>> mUsedPowers;
bool hasDisease(const ESM::Spell::SpellType type) const;