mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-12 21:39:26 +00:00
3f28634d1f
Note, I suspect Rng::rollClosedProbability() is not needed. The only difference between it and rollProbability() is that one time in 37k (on Windows), it will give an output of 1.0. On some versions of Linux, the value of 1.0 will occur about 1 time in 4 billion.
71 lines
3.1 KiB
C++
71 lines
3.1 KiB
C++
#ifndef OPENMW_MECHANICS_DISEASE_H
|
|
#define OPENMW_MECHANICS_DISEASE_H
|
|
|
|
#include <openengine/misc/rng.hpp>
|
|
|
|
#include "../mwbase/windowmanager.hpp"
|
|
#include "../mwbase/environment.hpp"
|
|
#include "../mwbase/world.hpp"
|
|
#include "../mwworld/ptr.hpp"
|
|
#include "../mwworld/class.hpp"
|
|
#include "../mwworld/esmstore.hpp"
|
|
#include "../mwmechanics/spells.hpp"
|
|
#include "../mwmechanics/creaturestats.hpp"
|
|
|
|
namespace MWMechanics
|
|
{
|
|
|
|
/// Call when \a actor has got in contact with \a carrier (e.g. hit by him, or loots him)
|
|
/// @param actor The actor that will potentially catch diseases. Currently only the player can catch diseases.
|
|
/// @param carrier The disease carrier.
|
|
inline void diseaseContact (MWWorld::Ptr actor, MWWorld::Ptr carrier)
|
|
{
|
|
if (!carrier.getClass().isActor() || actor != MWBase::Environment::get().getWorld()->getPlayerPtr())
|
|
return;
|
|
|
|
float fDiseaseXferChance =
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
|
|
"fDiseaseXferChance")->getFloat();
|
|
|
|
MagicEffects& actorEffects = actor.getClass().getCreatureStats(actor).getMagicEffects();
|
|
|
|
Spells& spells = carrier.getClass().getCreatureStats(carrier).getSpells();
|
|
for (Spells::TIterator it = spells.begin(); it != spells.end(); ++it)
|
|
{
|
|
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find(it->first);
|
|
|
|
if (actor.getClass().getCreatureStats(actor).getSpells().hasSpell(spell->mId))
|
|
continue;
|
|
|
|
float resist = 0.f;
|
|
if (spells.hasCorprusEffect(spell))
|
|
resist = 1.f - 0.01f * (actorEffects.get(ESM::MagicEffect::ResistCorprusDisease).getMagnitude()
|
|
- actorEffects.get(ESM::MagicEffect::WeaknessToCorprusDisease).getMagnitude());
|
|
else if (spell->mData.mType == ESM::Spell::ST_Disease)
|
|
resist = 1.f - 0.01f * (actorEffects.get(ESM::MagicEffect::ResistCommonDisease).getMagnitude()
|
|
- actorEffects.get(ESM::MagicEffect::WeaknessToCommonDisease).getMagnitude());
|
|
else if (spell->mData.mType == ESM::Spell::ST_Blight)
|
|
resist = 1.f - 0.01f * (actorEffects.get(ESM::MagicEffect::ResistBlightDisease).getMagnitude()
|
|
- actorEffects.get(ESM::MagicEffect::WeaknessToBlightDisease).getMagnitude());
|
|
else
|
|
continue;
|
|
|
|
int x = static_cast<int>(fDiseaseXferChance * 100 * resist);
|
|
if (OEngine::Misc::Rng::rollDice(10000) < x)
|
|
{
|
|
// Contracted disease!
|
|
actor.getClass().getCreatureStats(actor).getSpells().add(it->first);
|
|
|
|
std::string msg = "sMagicContractDisease";
|
|
msg = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(msg)->getString();
|
|
if (msg.find("%s") != std::string::npos)
|
|
msg.replace(msg.find("%s"), 2, spell->mName);
|
|
MWBase::Environment::get().getWindowManager()->messageBox(msg);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#endif
|