ManaPlus
Functions
SkillUnitDb Namespace Reference

Functions

void load ()
 
void loadXmlFile (const std::string &fileName, const SkipError skipError)
 
void unload ()
 
BeingInfoget (const BeingTypeId id)
 

Function Documentation

◆ get()

BeingInfo * SkillUnitDb::get ( const BeingTypeId  id)

Definition at line 150 of file skillunitdb.cpp.

151 {
152  const BeingInfoIterator i = mSkillUnitInfos.find(id);
153 
154  if (i == mSkillUnitInfos.end())
155  {
156  reportAlways("SkillUnitDb: Warning, unknown skill unit id "
157  "%d requested",
158  toInt(id, int))
159  return BeingInfo::unknown;
160  }
161  return i->second;
162 }
BeingInfos::iterator BeingInfoIterator
Definition: beinginfo.h:410
#define reportAlways(...)
Definition: checkutils.h:253
static BeingInfo * unknown
Definition: beinginfo.h:56
#define toInt(val, name)
Definition: intdefines.h:47

References anonymous_namespace{skillunitdb.cpp}::mSkillUnitInfos, reportAlways, toInt, and BeingInfo::unknown.

Referenced by Being::setSubtype().

◆ load()

void SkillUnitDb::load ( )

Definition at line 45 of file skillunitdb.cpp.

46 {
47  if (mLoaded)
48  unload();
49 
50  logger->log1("Initializing skill unit database...");
51  loadXmlFile(paths.getStringValue("skillUnitsFile"), SkipError_false);
52  loadXmlFile(paths.getStringValue("skillUnitsPatchFile"), SkipError_true);
53  loadXmlDir("skillUnitsPatchDir", loadXmlFile)
54  mLoaded = true;
55 }
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{skillunitdb.cpp}::mLoaded, paths, SkipError_false, SkipError_true, and Net::unload().

Referenced by DbManager::loadDb().

◆ loadXmlFile()

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

Definition at line 57 of file skillunitdb.cpp.

59 {
60  XML::Document doc(fileName, UseVirtFs_true, skipError);
61  XmlNodeConstPtrConst rootNode = doc.rootNode();
62 
63  if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "skillunits"))
64  {
65  logger->log("SkillUnitDb: Error while loading %s!",
66  fileName.c_str());
67  return;
68  }
69 
70  // iterate <skillunit>s
71  for_each_xml_child_node(skillUnitNode, rootNode)
72  {
73  if (xmlNameEqual(skillUnitNode, "include"))
74  {
75  const std::string name = XML::getProperty(skillUnitNode,
76  "name", "");
77  if (!name.empty())
78  loadXmlFile(name, skipError);
79  continue;
80  }
81  else if (!xmlNameEqual(skillUnitNode, "skillunit"))
82  {
83  continue;
84  }
85 
87  skillUnitNode, "id", -1), BeingTypeId);
88  if (id == BeingTypeId_negOne)
89  {
90  reportAlways("SkillUnitDb: skill unit with missing ID in %s!",
91  paths.getStringValue("skillUnitsFile").c_str())
92  continue;
93  }
94 
95  BeingInfo *currentInfo = nullptr;
96  if (mSkillUnitInfos.find(id) != mSkillUnitInfos.end())
97  currentInfo = mSkillUnitInfos[id];
98  if (currentInfo == nullptr)
99  currentInfo = new BeingInfo;
100 
101  currentInfo->setName(XML::langProperty(skillUnitNode,
102  // TRANSLATORS: unknown info name
103  "name", _("skill")));
104 
105  currentInfo->setTargetSelection(XML::getBoolProperty(skillUnitNode,
106  "targetSelection", true));
107 
108  BeingCommon::readBasicAttributes(currentInfo, skillUnitNode, "attack");
109  BeingCommon::readWalkingAttributes(currentInfo, skillUnitNode, 0);
110 
111  currentInfo->setDeadSortOffsetY(XML::getProperty(skillUnitNode,
112  "deadSortOffsetY", 31));
113 
114  SpriteDisplay display;
115  for_each_xml_child_node(spriteNode, skillUnitNode)
116  {
117  if (!XmlHaveChildContent(spriteNode))
118  continue;
119 
120  if (xmlNameEqual(spriteNode, "sprite"))
121  {
122  SpriteReference *const currentSprite = new SpriteReference;
123  currentSprite->sprite = XmlChildContent(spriteNode);
124  currentSprite->variant =
125  XML::getProperty(spriteNode, "variant", 0);
126  display.sprites.push_back(currentSprite);
127  }
128  else if (xmlNameEqual(spriteNode, "particlefx"))
129  {
130  std::string particlefx = XmlChildContent(spriteNode);
131  display.particles.push_back(particlefx);
132  }
133  }
134 
135  currentInfo->setDisplay(display);
136 
137  mSkillUnitInfos[id] = currentInfo;
138  }
139 }
int BeingTypeId
Definition: beingtypeid.h:30
const BeingTypeId BeingTypeId_negOne
Definition: beingtypeid.h:31
void log(const char *const log_text,...)
Definition: logger.cpp:269
#define new
Definition: debug_new.h:147
#define _(s)
Definition: gettext.h:35
if(!vert) return
#define fromInt(val, name)
Definition: intdefines.h:46
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
bool attack(InputEvent &event)
Definition: actions.cpp:58
bool skill(InputEvent &event)
Definition: commands.cpp:97
bool find(const std::string &key)
void readBasicAttributes(BeingInfo *const info, xmlNode *const node, const std::string &hoverCursor)
Definition: beingcommon.cpp:37
void readWalkingAttributes(BeingInfo *const info, xmlNode *const node, const int moreBlockFlags)
Definition: beingcommon.cpp:60
Definition: libxml.cpp:86
std::string langProperty(const xmlNodePtr node, const char *const name, const std::string &def)
Definition: libxml.cpp:258
bool getBoolProperty(const xmlNodePtr node, const char *const name, const bool def)
Definition: libxml.cpp:269
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
StringVect particles
Definition: spritedisplay.h:48
std::vector< SpriteReference * > sprites
Definition: spritedisplay.h:47
std::string sprite
std::string fileName
Definition: testmain.cpp:39
const bool UseVirtFs_true
Definition: usevirtfs.h:30

References _, BeingTypeId_negOne, fileName, for_each_xml_child_node, fromInt, XML::getBoolProperty(), XML::getProperty(), Configuration::getStringValue(), XML::langProperty(), loadXmlFile(), Logger::log(), logger, anonymous_namespace{skillunitdb.cpp}::mSkillUnitInfos, SpriteDisplay::particles, paths, BeingCommon::readBasicAttributes(), BeingCommon::readWalkingAttributes(), reportAlways, XML::Document::rootNode(), BeingInfo::setDeadSortOffsetY(), BeingInfo::setDisplay(), BeingInfo::setName(), BeingInfo::setTargetSelection(), SpriteReference::sprite, SpriteDisplay::sprites, UseVirtFs_true, and SpriteReference::variant.

◆ unload()

void SkillUnitDb::unload ( )

Definition at line 141 of file skillunitdb.cpp.

142 {
143  logger->log1("Unloading skill unit database...");
145  mSkillUnitInfos.clear();
146 
147  mLoaded = false;
148 }
void delete_all(Container &c)
Definition: dtor.h:56

References delete_all(), Logger::log1(), logger, anonymous_namespace{skillunitdb.cpp}::mLoaded, and anonymous_namespace{skillunitdb.cpp}::mSkillUnitInfos.

Referenced by DbManager::unloadDb().