OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
disease.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_MECHANICS_DISEASE_H
2 #define OPENMW_MECHANICS_DISEASE_H
3 
5 
6 #include "../mwbase/windowmanager.hpp"
7 #include "../mwbase/environment.hpp"
8 #include "../mwbase/world.hpp"
9 
10 #include "../mwworld/ptr.hpp"
11 #include "../mwworld/class.hpp"
12 #include "../mwworld/esmstore.hpp"
13 
14 #include "spells.hpp"
15 #include "creaturestats.hpp"
16 #include "actorutil.hpp"
17 
18 namespace MWMechanics
19 {
20 
24  inline void diseaseContact (MWWorld::Ptr actor, MWWorld::Ptr carrier)
25  {
26  if (!carrier.getClass().isActor() || actor != getPlayer())
27  return;
28 
29  float fDiseaseXferChance =
31  "fDiseaseXferChance")->getFloat();
32 
33  MagicEffects& actorEffects = actor.getClass().getCreatureStats(actor).getMagicEffects();
34 
35  Spells& spells = carrier.getClass().getCreatureStats(carrier).getSpells();
36  for (Spells::TIterator it = spells.begin(); it != spells.end(); ++it)
37  {
38  const ESM::Spell* spell = it->first;
39  if (actor.getClass().getCreatureStats(actor).getSpells().hasSpell(spell->mId))
40  continue;
41 
42  float resist = 0.f;
43  if (spells.hasCorprusEffect(spell))
44  resist = 1.f - 0.01f * (actorEffects.get(ESM::MagicEffect::ResistCorprusDisease).getMagnitude()
46  else if (spell->mData.mType == ESM::Spell::ST_Disease)
47  resist = 1.f - 0.01f * (actorEffects.get(ESM::MagicEffect::ResistCommonDisease).getMagnitude()
49  else if (spell->mData.mType == ESM::Spell::ST_Blight)
50  resist = 1.f - 0.01f * (actorEffects.get(ESM::MagicEffect::ResistBlightDisease).getMagnitude()
52  else
53  continue;
54 
55  int x = static_cast<int>(fDiseaseXferChance * 100 * resist);
56  if (Misc::Rng::rollDice(10000) < x)
57  {
58  // Contracted disease!
59  actor.getClass().getCreatureStats(actor).getSpells().add(it->first);
60 
61  std::string msg = "sMagicContractDisease";
63  if (msg.find("%s") != std::string::npos)
64  msg.replace(msg.find("%s"), 2, spell->mName);
66  }
67  }
68  }
69 }
70 
71 
72 #endif
bool hasSpell(const std::string &spell) const
Definition: spells.cpp:76
virtual MWMechanics::CreatureStats & getCreatureStats(const Ptr &ptr) const
Definition: class.cpp:63
World * getWorld() const
Definition: environment.cpp:82
const Class & getClass() const
Definition: ptr.hpp:40
Effects currently affecting a NPC or creature.
Definition: magiceffects.hpp:83
Definition: loadmgef.hpp:141
static const Environment & get()
Return instance of this class.
Definition: environment.cpp:171
Definition: loadspel.hpp:14
const MagicEffects & getMagicEffects() const
Definition: creaturestats.cpp:90
WindowManager * getWindowManager() const
Definition: environment.cpp:100
virtual const MWWorld::ESMStore & getStore() const =0
std::string mName
Definition: loadspel.hpp:45
void add(const std::string &spell)
Adding a spell that is already listed in *this is a no-op.
Definition: spells.cpp:119
Definition: loadgmst.hpp:19
float getMagnitude() const
Get the total magnitude including base and modifier.
Definition: magiceffects.cpp:43
float getFloat() const
Throws an exception if GMST is not of type int or float.
Definition: loadgmst.cpp:30
Definition: loadspel.hpp:24
SPDTstruct mData
Definition: loadspel.hpp:44
MWWorld::Ptr getPlayer()
Definition: actorutil.cpp:10
Definition: loadmgef.hpp:202
static int rollDice(int max)
return value in range [0, max) <- note open upper range.
Definition: rng.cpp:23
virtual void messageBox(const std::string &message, enum MWGui::ShowInDialogueMode showInDialogueMode=MWGui::ShowInDialogueMode_IfPossible)=0
Definition: loadmgef.hpp:139
void diseaseContact(MWWorld::Ptr actor, MWWorld::Ptr carrier)
Definition: disease.hpp:24
const Spells & getSpells() const
Definition: creaturestats.cpp:80
EffectParam get(const EffectKey &key) const
This function can safely be used for keys that are not present.
Definition: magiceffects.cpp:148
TIterator begin() const
Definition: spells.cpp:23
TContainer::const_iterator TIterator
Definition: spells.hpp:42
Definition: loadmgef.hpp:140
TIterator end() const
Definition: spells.cpp:28
Definition: loadmgef.hpp:201
const Store< T > & get() const
Definition: esmstore.hpp:164
virtual bool isActor() const
Definition: class.hpp:302
std::string mId
Definition: loadspel.hpp:45
Definition: loadmgef.hpp:203
Definition: loadspel.hpp:25
Spell list.
Definition: spells.hpp:31
Pointer to a LiveCellRef.
Definition: ptr.hpp:19
static bool hasCorprusEffect(const ESM::Spell *spell)
Definition: spells.cpp:326
std::string getString() const
Throwns an exception if GMST is not of type string.
Definition: loadgmst.cpp:35
int mType
Definition: loadspel.hpp:39