Merge pull request #411 from OpenMW/master

Add OpenMW commits up to 19 Apr 2018
0.6.3
David Cernat 7 years ago committed by GitHub
commit 02eef933fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -404,7 +404,12 @@ namespace MWGui
MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player);
MWMechanics::Spells& spells = stats.getSpells(); MWMechanics::Spells& spells = stats.getSpells();
if (!spells.hasSpell(spellId)) if (!spells.hasSpell(spellId))
{
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find(spellId);
MWBase::Environment::get().getWindowManager()->messageBox (
"#{sQuickMenu5} " + spell->mName);
return; return;
}
store.setSelectedEnchantItem(store.end()); store.setSelectedEnchantItem(store.end());
MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, int(MWMechanics::getSpellSuccessChance(spellId, player))); MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, int(MWMechanics::getSpellSuccessChance(spellId, player)));
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Spell); MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Spell);

@ -63,28 +63,16 @@ std::string Misc::ResourceHelpers::correctResourcePath(const std::string &topLev
std::string origExt = correctedPath; std::string origExt = correctedPath;
// since we know all (GOTY edition or less) textures end if (vfs->exists(origExt)
// in .dds, we change the extension || (changeExtensionToDds(correctedPath) && vfs->exists(correctedPath)))
bool changedToDds = changeExtensionToDds(correctedPath);
if (vfs->exists(correctedPath))
return correctedPath; return correctedPath;
// if it turns out that the above wasn't true in all cases (not for vanilla, but maybe mods)
// verify, and revert if false (this call succeeds quickly, but fails slowly)
if (changedToDds && vfs->exists(origExt))
return origExt;
// fall back to a resource in the top level directory if it exists // fall back to a resource in the top level directory if it exists
std::string fallback = topLevelDirectory + "\\" + getBasename(correctedPath); std::string fallback = topLevelDirectory + "\\" + getBasename(origExt);
if (vfs->exists(fallback)) if (vfs->exists(fallback)
|| (changeExtensionToDds(fallback) && vfs->exists(fallback)))
return fallback; return fallback;
if (changedToDds)
{
fallback = topLevelDirectory + "\\" + getBasename(origExt);
if (vfs->exists(fallback))
return fallback;
}
return correctedPath; return correctedPath;
} }

@ -1,28 +1,31 @@
#include "rng.hpp" #include "rng.hpp"
#include <cstdlib>
#include <ctime> #include <chrono>
#include <random>
namespace Misc namespace Misc
{ {
std::mt19937 Rng::generator = std::mt19937();
void Rng::init() void Rng::init()
{ {
std::srand(static_cast<unsigned int>(std::time(NULL))); generator.seed(static_cast<unsigned int>(std::chrono::high_resolution_clock::now().time_since_epoch().count()));
} }
float Rng::rollProbability() float Rng::rollProbability()
{ {
return static_cast<float>(std::rand() / (static_cast<double>(RAND_MAX)+1.0)); return std::uniform_real_distribution<float>(0, 1 - std::numeric_limits<float>::epsilon())(generator);
} }
float Rng::rollClosedProbability() float Rng::rollClosedProbability()
{ {
return static_cast<float>(std::rand() / static_cast<double>(RAND_MAX)); return std::uniform_real_distribution<float>(0, 1)(generator);
} }
int Rng::rollDice(int max) int Rng::rollDice(int max)
{ {
return static_cast<int>((std::rand() / (static_cast<double>(RAND_MAX)+1.0)) * (max)); return std::uniform_int_distribution<int>(0, max - 1)(generator);
} }
} }

@ -2,6 +2,7 @@
#define OPENMW_COMPONENTS_MISC_RNG_H #define OPENMW_COMPONENTS_MISC_RNG_H
#include <cassert> #include <cassert>
#include <random>
namespace Misc namespace Misc
{ {
@ -13,6 +14,9 @@ class Rng
{ {
public: public:
/// create a RNG
static std::mt19937 generator;
/// seed the RNG /// seed the RNG
static void init(); static void init();

Loading…
Cancel
Save