ManaPlus
Functions
QuestDb Namespace Reference

Functions

void load ()
 
void loadXmlFile (const std::string &fileName, const SkipError skipError)
 
void unload ()
 
NpcQuestVarMapgetVars ()
 
std::map< int, std::vector< QuestItem * > > * getQuests ()
 
std::vector< QuestEffect * > * getAllEffects ()
 
std::string getName (const int id)
 

Function Documentation

◆ getAllEffects()

std::vector< QuestEffect * > * QuestDb::getAllEffects ( )

Definition at line 244 of file questdb.cpp.

245 {
246  return &mAllEffects;
247 }
std::vector< QuestEffect * > mAllEffects
Definition: questdb.cpp:44

References anonymous_namespace{questdb.cpp}::mAllEffects.

Referenced by QuestsWindow::QuestsWindow().

◆ getName()

std::string QuestDb::getName ( const int  id)

Definition at line 249 of file questdb.cpp.

250 {
251  std::map<int, STD_VECTOR<QuestItem*> >::const_iterator it =
252  mQuests.find(id);
253  if (it == mQuests.end())
254  {
255  // TRANSLATORS: quests window quest name
256  return _("unknown");
257  }
258  const STD_VECTOR<QuestItem*> &items = (*it).second;
259  if (items.empty())
260  {
261  // TRANSLATORS: quests window quest name
262  return _("unknown");
263  }
264  return items[0]->name;
265 }
#define _(s)
Definition: gettext.h:35
std::map< int, std::vector< QuestItem * > > mQuests
Definition: questdb.cpp:43

References _, and anonymous_namespace{questdb.cpp}::mQuests.

Referenced by BrowserBoxTools::replaceLinkCommands().

◆ getQuests()

std::map< int, std::vector< QuestItem * > > * QuestDb::getQuests ( )

Definition at line 239 of file questdb.cpp.

240 {
241  return &mQuests;
242 }

References anonymous_namespace{questdb.cpp}::mQuests.

Referenced by QuestsWindow::QuestsWindow().

◆ getVars()

NpcQuestVarMap * QuestDb::getVars ( )

Definition at line 234 of file questdb.cpp.

235 {
236  return &mVars;
237 }

References anonymous_namespace{questdb.cpp}::mVars.

Referenced by QuestsWindow::QuestsWindow().

◆ load()

void QuestDb::load ( )

Definition at line 47 of file questdb.cpp.

48 {
49  unload();
50  logger->log1("Initializing quest database...");
52  loadXmlFile(paths.getStringValue("questsPatchFile"), SkipError_true);
53  loadXmlDir("questsPatchDir", loadXmlFile)
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, paths, SkipError_false, SkipError_true, and Net::unload().

Referenced by QuestsWindow::QuestsWindow().

◆ loadXmlFile()

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

Definition at line 179 of file questdb.cpp.

181 {
184  skipError);
185  XmlNodeConstPtrConst root = doc.rootNode();
186  if (root == nullptr)
187  return;
188 
189  for_each_xml_child_node(varNode, root)
190  {
191  if (xmlNameEqual(varNode, "include"))
192  {
193  const std::string name = XML::getProperty(varNode, "name", "");
194  if (!name.empty())
195  loadXmlFile(name, skipError);
196  continue;
197  }
198  else if (xmlNameEqual(varNode, "var"))
199  {
200  const int id = XML::getProperty(varNode, "id", 0);
201  if (id < 0)
202  continue;
203  mVars[id] = QuestVar();
204  for_each_xml_child_node(questNode, varNode)
205  {
206  if (xmlNameEqual(questNode, "quest"))
207  loadQuest(id, questNode);
208  else if (xmlNameEqual(questNode, "effect"))
209  loadEffect(id, questNode);
210  }
211  }
212  }
213 }
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
static void loadQuest(const int var, const xmlNodePtr node)
Definition: questdb.cpp:56
static void loadEffect(const int var, const xmlNodePtr node)
Definition: questdb.cpp:159
std::string fileName
Definition: testmain.cpp:39
const bool UseVirtFs_true
Definition: usevirtfs.h:30

References fileName, for_each_xml_child_node, XML::getProperty(), loadEffect(), loadQuest(), loadXmlFile(), anonymous_namespace{questdb.cpp}::mVars, XML::Document::rootNode(), and UseVirtFs_true.

◆ unload()

void QuestDb::unload ( )

Definition at line 216 of file questdb.cpp.

217 {
218  logger->log1("Unloading quest database...");
219  for (std::map<int, STD_VECTOR<QuestItem*> >::iterator it
220  = mQuests.begin(), it_end = mQuests.end(); it != it_end; ++ it)
221  {
222  STD_VECTOR<QuestItem*> &quests = (*it).second;
223  for (STD_VECTOR<QuestItem*>::iterator it2 = quests.begin(),
224  it2_end = quests.end(); it2 != it2_end; ++ it2)
225  {
226  delete *it2;
227  }
228  }
230  mAllEffects.clear();
231  mQuests.clear();
232 }
void delete_all(Container &c)
Definition: dtor.h:56

References delete_all(), Logger::log1(), logger, anonymous_namespace{questdb.cpp}::mAllEffects, and anonymous_namespace{questdb.cpp}::mQuests.

Referenced by QuestsWindow::~QuestsWindow().