ManaPlus
Functions
StatusEffectDB Namespace Reference

Functions

StatusEffectgetStatusEffect (const int index, const Enable enabling)
 
void load ()
 
void loadXmlFile (const std::string &fileName, const SkipError skipError)
 
void unload ()
 
const OptionsMapgetOptionMap ()
 
const OptionsMapgetOpt1Map ()
 
const OptionsMapgetOpt2Map ()
 
const OptionsMapgetOpt3Map ()
 

Function Documentation

◆ getOpt1Map()

const OptionsMap & StatusEffectDB::getOpt1Map ( )

◆ getOpt2Map()

const OptionsMap & StatusEffectDB::getOpt2Map ( )

◆ getOpt3Map()

const OptionsMap & StatusEffectDB::getOpt3Map ( )

◆ getOptionMap()

const OptionsMap & StatusEffectDB::getOptionMap ( )

◆ getStatusEffect()

StatusEffect * StatusEffectDB::getStatusEffect ( const int  index,
const Enable  enabling 
)

Retrieves a status effect.

Parameters
indexIndex of the status effect.
enablingWhether to retrieve the activating effect (true) or the deactivating effect (false).

Definition at line 47 of file statuseffectdb.cpp.

49 {
50  std::map<int, StatusEffect *> &effects
51  = statusEffects[enabling == Enable_true];
52  const std::map<int, StatusEffect *>::iterator it = effects.find(index);
53  if (it != effects.end())
54  return (*it).second;
55  reportAlways("Missing status effect: %d",
56  index)
57  return nullptr;
58 }
#define reportAlways(...)
Definition: checkutils.h:253
const bool Enable_true
Definition: enable.h:30

References Enable_true, reportAlways, and anonymous_namespace{statuseffectdb.cpp}::statusEffects.

Referenced by ActorSprite::getStatusEffectsString(), ActorSprite::logic(), and ActorSprite::updateStatusEffect().

◆ load()

void StatusEffectDB::load ( )

Definition at line 60 of file statuseffectdb.cpp.

61 {
62  if (mLoaded)
63  unload();
64 
65  logger->log1("Initializing status effect database...");
66 
67  loadXmlFile(paths.getStringValue("statusEffectsFile"), SkipError_false);
68  loadXmlFile(paths.getStringValue("statusEffectsPatchFile"),
70  loadXmlDir("statusEffectsPatchDir", loadXmlFile)
71 
72  mLoaded = true;
73 }
static void loadXmlFile(const std::string &file, const std::string &name, BadgesInfos &arr, const SkipError skipError)
Definition: badgesdb.cpp:43
#define loadXmlDir(name, function)
Definition: beingcommon.h:39
std::string getStringValue(const std::string &key) const
void log1(const char *const log_text)
Definition: logger.cpp:238
Configuration paths
Logger * logger
Definition: logger.cpp:89
void unload()
Definition: net.cpp:180
const bool SkipError_false
Definition: skiperror.h:30
const bool SkipError_true
Definition: skiperror.h:30

References Configuration::getStringValue(), loadXmlDir, loadXmlFile(), Logger::log1(), logger, anonymous_namespace{statuseffectdb.cpp}::mLoaded, paths, SkipError_false, SkipError_true, and Net::unload().

Referenced by DbManager::loadDb().

◆ loadXmlFile()

void StatusEffectDB::loadXmlFile ( const std::string &  fileName,
const SkipError  skipError 
)

Definition at line 75 of file statuseffectdb.cpp.

77 {
78  XML::Document doc(fileName, UseVirtFs_true, skipError);
79  XmlNodeConstPtrConst rootNode = doc.rootNode();
80 
81  if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "status-effects"))
82  {
83  logger->log("Error loading status effects file: " + fileName);
84  return;
85  }
86 
87  for_each_xml_child_node(node, rootNode)
88  {
89  if (xmlNameEqual(node, "include"))
90  {
91  const std::string incName = XML::getProperty(node, "name", "");
92  if (!incName.empty())
93  loadXmlFile(incName, skipError);
94  continue;
95  }
96  else if (!xmlNameEqual(node, "status-effect"))
97  {
98  continue;
99  }
100 
101  int id = XML::getProperty(node, "id", -1);
102  if (id == -1)
103  {
104  id = fakeId;
105  fakeId ++;
106  }
107  const int option = XML::getProperty(node, "option", 0);
108  const int opt1 = XML::getProperty(node, "opt1", 0);
109  const int opt2 = XML::getProperty(node, "opt2", 0);
110  const int opt3 = XML::getProperty(node, "opt3", 0);
111  if (option != 0)
112  {
113  optionToIdMap[option] = id;
114  }
115  if (opt1 != 0)
116  {
117  opt1ToIdMap[opt1] = id;
118  }
119  if (opt2 != 0)
120  {
121  opt2ToIdMap[opt2] = id;
122  }
123  if (opt3 != 0)
124  {
125  opt3ToIdMap[opt3] = id;
126  }
127 
128  StatusEffect *startEffect = statusEffects[1][id];
129  StatusEffect *endEffect = statusEffects[0][id];
130  const std::string name = XML::getProperty(node, "name", "");
131  const std::string name2 = XML::langProperty(node, "name", "");
132  if (startEffect == nullptr)
133  startEffect = new StatusEffect;
134  if (endEffect == nullptr)
135  endEffect = new StatusEffect;
136 
137  startEffect->mName = name2;
138  startEffect->mIsPoison =
139  (name == paths.getStringValue("poisonEffectName"));
140  startEffect->mIsCart =
141  (name == paths.getStringValue("cartEffectName"));
142  startEffect->mIsRiding =
143  (name == paths.getStringValue("ridingEffectName"));
144  startEffect->mIsTrickDead =
145  (name == paths.getStringValue("trickDeadEffectName"));
146  startEffect->mIsPostDelay =
147  (name == paths.getStringValue("postDelayName"));
148  startEffect->mMessage = XML::getProperty(
149  node, "start-message", "");
150  startEffect->mSFXEffect = XML::getProperty(
151  node, "start-audio", "");
152  startEffect->mStartParticleEffect = XML::getProperty(
153  node, "start-particle", "");
154  startEffect->mParticleEffect = XML::getProperty(
155  node, "particle", "");
156 
157  startEffect->mIcon = XML::getProperty(node, "icon", "");
158  startEffect->mAction = XML::getProperty(node, "action", "");
159  startEffect->mIsPersistent = (XML::getProperty(
160  node, "persistent-particle-effect", "no")) != "no";
161 
162  endEffect->mName = startEffect->mName;
163  endEffect->mIsPoison = startEffect->mIsPoison;
164  endEffect->mIsCart = startEffect->mIsCart;
165  endEffect->mIsRiding = startEffect->mIsRiding;
166  endEffect->mIsTrickDead = startEffect->mIsTrickDead;
167  endEffect->mIsPostDelay = startEffect->mIsPostDelay;
168  endEffect->mMessage = XML::getProperty(node, "end-message", "");
169  endEffect->mSFXEffect = XML::getProperty(node, "end-audio", "");
171  node, "end-particle", "");
172 
173  statusEffects[1][id] = startEffect;
174  statusEffects[0][id] = endEffect;
175  }
176 }
void log(const char *const log_text,...)
Definition: logger.cpp:269
std::string mIcon
Definition: statuseffect.h:81
bool mIsPostDelay
Definition: statuseffect.h:89
std::string mSFXEffect
Definition: statuseffect.h:78
std::string mMessage
Definition: statuseffect.h:77
std::string mStartParticleEffect
Definition: statuseffect.h:79
bool mIsTrickDead
Definition: statuseffect.h:88
std::string mName
Definition: statuseffect.h:83
std::string mParticleEffect
Definition: statuseffect.h:80
bool mIsPersistent
Definition: statuseffect.h:84
std::string mAction
Definition: statuseffect.h:82
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
std::string langProperty(const xmlNodePtr node, const char *const name, const std::string &def)
Definition: libxml.cpp:258
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
std::string fileName
Definition: testmain.cpp:39
const bool UseVirtFs_true
Definition: usevirtfs.h:30

References anonymous_namespace{statuseffectdb.cpp}::fakeId, fileName, for_each_xml_child_node, XML::getProperty(), Configuration::getStringValue(), XML::langProperty(), loadXmlFile(), Logger::log(), logger, StatusEffect::mAction, StatusEffect::mIcon, StatusEffect::mIsCart, StatusEffect::mIsPersistent, StatusEffect::mIsPoison, StatusEffect::mIsPostDelay, StatusEffect::mIsRiding, StatusEffect::mIsTrickDead, StatusEffect::mMessage, StatusEffect::mName, StatusEffect::mParticleEffect, StatusEffect::mSFXEffect, StatusEffect::mStartParticleEffect, anonymous_namespace{statuseffectdb.cpp}::opt1ToIdMap, anonymous_namespace{statuseffectdb.cpp}::opt2ToIdMap, anonymous_namespace{statuseffectdb.cpp}::opt3ToIdMap, anonymous_namespace{statuseffectdb.cpp}::optionToIdMap, paths, XML::Document::rootNode(), anonymous_namespace{statuseffectdb.cpp}::statusEffects, and UseVirtFs_true.

◆ unload()

void StatusEffectDB::unload ( )

Definition at line 189 of file statuseffectdb.cpp.

190 {
191  if (!mLoaded)
192  return;
193 
194  logger->log1("Unloading status effect database...");
195 
196  fakeId = 10000;
199 
200  optionToIdMap.clear();
201  opt1ToIdMap.clear();
202  opt2ToIdMap.clear();
203  opt3ToIdMap.clear();
204 
205  mLoaded = false;
206 }
static void unloadMap(std::map< int, StatusEffect * > &map)

References anonymous_namespace{statuseffectdb.cpp}::fakeId, Logger::log1(), logger, anonymous_namespace{statuseffectdb.cpp}::mLoaded, anonymous_namespace{statuseffectdb.cpp}::opt1ToIdMap, anonymous_namespace{statuseffectdb.cpp}::opt2ToIdMap, anonymous_namespace{statuseffectdb.cpp}::opt3ToIdMap, anonymous_namespace{statuseffectdb.cpp}::optionToIdMap, anonymous_namespace{statuseffectdb.cpp}::statusEffects, and unloadMap().

Referenced by DbManager::unloadDb().