ManaPlus
Functions
MercenaryDB Namespace Reference

Functions

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

Detailed Description

Mercenary information database.

Function Documentation

◆ get()

BeingInfo * MercenaryDB::get ( const BeingTypeId  id)

Definition at line 142 of file mercenarydb.cpp.

143 {
144  BeingInfoIterator i = mMercenaryInfos.find(id);
145 
146  if (i == mMercenaryInfos.end())
147  {
148  i = mMercenaryInfos.find(id);
149  if (i == mMercenaryInfos.end())
150  {
151  reportAlways("MercenaryDB: Warning, unknown mercenary ID "
152  "%d requested",
153  toInt(id, int))
154  return BeingInfo::unknown;
155  }
156  }
157  return i->second;
158 }
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{mercenarydb.cpp}::mMercenaryInfos, reportAlways, toInt, and BeingInfo::unknown.

Referenced by BrowserBoxTools::replaceLinkCommands(), and Being::setSubtype().

◆ load()

void MercenaryDB::load ( )

Definition at line 43 of file mercenarydb.cpp.

44 {
45  if (mLoaded)
46  unload();
47 
48  logger->log1("Initializing mercenary database...");
49  loadXmlFile(paths.getStringValue("mercenariesFile"), SkipError_false);
50  loadXmlFile(paths.getStringValue("mercenariesPatchFile"), SkipError_true);
51  loadXmlDir("mercenariesPatchDir", loadXmlFile)
52 
53  mLoaded = true;
54 }
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{mercenarydb.cpp}::mLoaded, paths, SkipError_false, SkipError_true, and Net::unload().

Referenced by DbManager::loadDb().

◆ loadXmlFile()

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

Definition at line 56 of file mercenarydb.cpp.

58 {
61  skipError);
62  XmlNodeConstPtr rootNode = doc.rootNode();
63 
64  if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "mercenaries"))
65  {
66  logger->log("MercenaryDB: Error while loading %s!",
67  paths.getStringValue("mercenariesFile").c_str());
68  mLoaded = true;
69  return;
70  }
71 
72  const int offset = XML::getProperty(rootNode, "offset", 0);
73 
74  // iterate <mercenary>s
75  for_each_xml_child_node(mercenaryNode, rootNode)
76  {
77  if (xmlNameEqual(mercenaryNode, "include"))
78  {
79  const std::string name = XML::getProperty(
80  mercenaryNode, "name", "");
81  if (!name.empty())
82  loadXmlFile(name, skipError);
83  continue;
84  }
85  if (!xmlNameEqual(mercenaryNode, "mercenary"))
86  continue;
87 
88  const int id = XML::getProperty(mercenaryNode, "id", 0);
89  BeingInfo *currentInfo = nullptr;
90  if (mMercenaryInfos.find(fromInt(id + offset, BeingTypeId))
91  != mMercenaryInfos.end())
92  {
93  logger->log("MercenaryDB: Redefinition of mercenary ID %d", id);
94  currentInfo = mMercenaryInfos[fromInt(id + offset, BeingTypeId)];
95  }
96  if (currentInfo == nullptr)
97  currentInfo = new BeingInfo;
98 
99  currentInfo->setBlockType(BlockType::NONE);
100  currentInfo->setName(XML::langProperty(
101  // TRANSLATORS: unknown info name
102  mercenaryNode, "name", _("unnamed")));
103  BeingCommon::readBasicAttributes(currentInfo, mercenaryNode, "attack");
104  BeingCommon::readWalkingAttributes(currentInfo, mercenaryNode, 0);
105  BeingCommon::readAiAttributes(currentInfo, mercenaryNode);
106 
107  currentInfo->setMaxHP(XML::getProperty(mercenaryNode, "maxHP", 0));
108 
110  mercenaryNode, "deadSortOffsetY", 31));
111 
112  currentInfo->setColorsList(XML::getProperty(mercenaryNode,
113  "colors", ""));
114 
115  if (currentInfo->getMaxHP() != 0)
116  currentInfo->setStaticMaxHP(true);
117 
118  SpriteDisplay display;
119 
120  // iterate <sprite>s and <sound>s
121  for_each_xml_child_node(spriteNode, mercenaryNode)
122  {
123  BeingCommon::readObjectNodes(spriteNode, display,
124  currentInfo, "MonsterDB");
125  }
126  currentInfo->setDisplay(display);
127 
128  mMercenaryInfos[fromInt(id + offset, BeingTypeId)] = currentInfo;
129  }
130 }
int BeingTypeId
Definition: beingtypeid.h:30
void setBlockType(const BlockTypeT &blockType)
Definition: beinginfo.h:126
void setColorsList(const std::string &name)
Definition: beinginfo.cpp:234
void setName(const std::string &name)
Definition: beinginfo.h:65
void setDisplay(const SpriteDisplay &display)
Definition: beinginfo.cpp:127
void setDeadSortOffsetY(const int n)
Definition: beinginfo.h:195
void setStaticMaxHP(const bool n)
Definition: beinginfo.h:177
int getMaxHP() const
Definition: beinginfo.h:171
void setMaxHP(const int n)
Definition: beinginfo.h:168
void log(const char *const log_text,...)
Definition: logger.cpp:269
#define _(s)
Definition: gettext.h:35
#define fromInt(val, name)
Definition: intdefines.h:46
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
bool readObjectNodes(xmlNode *const &spriteNode, SpriteDisplay &display, BeingInfo *const currentInfo, const std::string &dbName)
void readAiAttributes(BeingInfo *const info, xmlNode *const node)
Definition: beingcommon.cpp:96
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
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 _, fileName, for_each_xml_child_node, fromInt, BeingInfo::getMaxHP(), XML::getProperty(), Configuration::getStringValue(), XML::langProperty(), loadXmlFile(), Logger::log(), logger, anonymous_namespace{mercenarydb.cpp}::mLoaded, anonymous_namespace{mercenarydb.cpp}::mMercenaryInfos, BlockType::NONE, paths, BeingCommon::readAiAttributes(), BeingCommon::readBasicAttributes(), BeingCommon::readObjectNodes(), BeingCommon::readWalkingAttributes(), XML::Document::rootNode(), BeingInfo::setBlockType(), BeingInfo::setColorsList(), BeingInfo::setDeadSortOffsetY(), BeingInfo::setDisplay(), BeingInfo::setMaxHP(), BeingInfo::setName(), BeingInfo::setStaticMaxHP(), and UseVirtFs_true.

◆ unload()

void MercenaryDB::unload ( )

Definition at line 132 of file mercenarydb.cpp.

133 {
134  logger->log1("Unloading mercenary database...");
136  mMercenaryInfos.clear();
137 
138  mLoaded = false;
139 }
void delete_all(Container &c)
Definition: dtor.h:56

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

Referenced by DbManager::unloadDb().