ManaPlus
Namespaces | Functions | Variables
questdb.cpp File Reference

(986a3bf)

#include "resources/db/questdb.h"
#include "configuration.h"
#include "logger.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
#include "utils/translation/podict.h"
#include "resources/beingcommon.h"
#include "resources/questeffect.h"
#include "resources/questitem.h"
#include "debug.h"

Go to the source code of this file.

Namespaces

 anonymous_namespace{questdb.cpp}
 

Functions

static void loadQuest (const int var, const xmlNodePtr node)
 
static void loadEffect (const int var, const xmlNodePtr node)
 

Variables

NpcQuestVarMap anonymous_namespace{questdb.cpp}::mVars
 
std::map< int, std::vector< QuestItem * > > anonymous_namespace{questdb.cpp}::mQuests
 
std::vector< QuestEffect * > anonymous_namespace{questdb.cpp}::mAllEffects
 

Function Documentation

◆ loadEffect()

static void loadEffect ( const int  var,
const xmlNodePtr  node 
)
static

Definition at line 159 of file questdb.cpp.

161 {
162  QuestEffect *const effect = new QuestEffect;
163  effect->map = XML::getProperty(node, "map", "");
164  effect->id = fromInt(XML::getProperty(node, "npc", -1), BeingTypeId);
165  effect->effectId = XML::getProperty(node, "effect", -1);
166  const std::string values = XML::getProperty(node, "value", "");
167  splitToIntSet(effect->values, values, ',');
168 
169  if (effect->map.empty() || effect->id == BeingTypeId_negOne
170  || effect->effectId == -1 || values.empty())
171  {
172  delete effect;
173  return;
174  }
175  effect->var = var;
176  mAllEffects.push_back(effect);
177 }
int BeingTypeId
Definition: beingtypeid.h:30
const BeingTypeId BeingTypeId_negOne
Definition: beingtypeid.h:31
#define fromInt(val, name)
Definition: intdefines.h:46
CompositeGenerator< T > values(T val1, T val2)
Definition: catch.hpp:2472
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
std::vector< QuestEffect * > mAllEffects
Definition: questdb.cpp:44
void splitToIntSet(std::set< int > &tokens, const std::string &text, const char separator)
std::string map
Definition: questeffect.h:45
BeingTypeId id
Definition: questeffect.h:47
std::set< int > values
Definition: questeffect.h:49

References BeingTypeId_negOne, QuestEffect::effectId, fromInt, XML::getProperty(), QuestEffect::id, anonymous_namespace{questdb.cpp}::mAllEffects, QuestEffect::map, splitToIntSet(), QuestEffect::values, Catch::Generators::values(), and QuestEffect::var.

Referenced by QuestDb::loadXmlFile().

◆ loadQuest()

static void loadQuest ( const int  var,
const xmlNodePtr  node 
)
static

Definition at line 56 of file questdb.cpp.

58 {
59  if (node == nullptr)
60  return;
61  QuestItem *const quest = new QuestItem;
62  // TRANSLATORS: quests window quest name
63  quest->name = XML::langProperty(node, "name", _("unknown"));
64  quest->group = XML::getProperty(node, "group", "");
65  std::string incompleteStr = XML::getProperty(node, "incomplete", "");
66  std::string completeStr = XML::getProperty(node, "complete", "");
67  if (incompleteStr.empty() && completeStr.empty())
68  {
69  logger->log("complete flags incorrect");
70  delete quest;
71  return;
72  }
73  splitToIntSet(quest->incomplete, incompleteStr, ',');
74  splitToIntSet(quest->complete, completeStr, ',');
75  if (quest->incomplete.empty() && quest->complete.empty())
76  {
77  logger->log("complete flags incorrect");
78  delete quest;
79  return;
80  }
81  if (quest->incomplete.empty() || quest->complete.empty())
82  quest->broken = true;
83 
84  for_each_xml_child_node(dataNode, node)
85  {
86  if (!xmlTypeEqual(dataNode, XML_ELEMENT_NODE))
87  continue;
88  XmlChar *const data = reinterpret_cast<XmlChar*>(
89  XmlNodeGetContent(dataNode));
90  if (data == nullptr)
91  continue;
92  std::string str = translator->getStr(data);
93  XmlFree(data);
94 
95  for (int f = 1; f < 100; f ++)
96  {
97  const std::string key = strprintf("text%d", f);
98  const std::string val = XML::getProperty(dataNode,
99  key.c_str(),
100  "");
101  if (val.empty())
102  break;
103  const std::string param = strprintf("{@@%d}", f);
104  replaceAll(str, param, val);
105  }
106  replaceItemLinks(str);
107  if (xmlNameEqual(dataNode, "text"))
108  {
109  quest->texts.push_back(QuestItemText(str,
111  std::string(),
112  std::string()));
113  }
114  else if (xmlNameEqual(dataNode, "name"))
115  {
116  quest->texts.push_back(QuestItemText(str,
118  std::string(),
119  std::string()));
120  }
121  else if (xmlNameEqual(dataNode, "reward"))
122  {
123  quest->texts.push_back(QuestItemText(str,
125  std::string(),
126  std::string()));
127  }
128  else if (xmlNameEqual(dataNode, "questgiver") ||
129  xmlNameEqual(dataNode, "giver"))
130  {
131  quest->texts.push_back(QuestItemText(str,
133  std::string(),
134  std::string()));
135  }
136  else if (xmlNameEqual(dataNode, "coordinates"))
137  {
138  const std::string str1 = toString(XML::getIntProperty(
139  dataNode, "x", 0, 1, 1000));
140  const std::string str2 = toString(XML::getIntProperty(
141  dataNode, "y", 0, 1, 1000));
142  quest->texts.push_back(QuestItemText(str,
144  str1,
145  str2));
146  }
147  else if (xmlNameEqual(dataNode, "npc"))
148  {
149  quest->texts.push_back(QuestItemText(str,
151  std::string(),
152  std::string()));
153  }
154  }
155  quest->var = var;
156  mQuests[var].push_back(quest);
157 }
void log(const char *const log_text,...)
Definition: logger.cpp:269
const std::string getStr(const std::string &str)
Definition: podict.cpp:45
#define _(s)
Definition: gettext.h:35
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
Logger * logger
Definition: logger.cpp:89
uint32_t data
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
@ COORDINATES
Definition: questtype.h:33
std::string langProperty(const xmlNodePtr node, const char *const name, const std::string &def)
Definition: libxml.cpp:258
int getIntProperty(const xmlNodePtr node, const char *const name, int def, const int min, const int max)
Definition: libxml.cpp:190
std::map< int, std::vector< QuestItem * > > mQuests
Definition: questdb.cpp:43
PoDict * translator
Definition: podict.cpp:28
std::string & replaceAll(std::string &context, const std::string &from, const std::string &to)
std::string strprintf(const char *const format,...)
void replaceItemLinks(std::string &msg)
std::vector< QuestItemText > texts
Definition: questitem.h:54
std::string group
Definition: questitem.h:51
int var
Definition: questitem.h:49
bool broken
Definition: questitem.h:56
std::set< int > complete
Definition: questitem.h:53
std::string name
Definition: questitem.h:50
std::set< int > incomplete
Definition: questitem.h:52

References _, QuestItem::broken, QuestItem::complete, QuestType::COORDINATES, data, for_each_xml_child_node, XML::getIntProperty(), XML::getProperty(), PoDict::getStr(), QuestType::GIVER, QuestItem::group, QuestItem::incomplete, XML::langProperty(), Logger::log(), logger, anonymous_namespace{questdb.cpp}::mQuests, QuestType::NAME, QuestItem::name, QuestType::NPC, replaceAll(), replaceItemLinks(), QuestType::REWARD, splitToIntSet(), strprintf(), QuestType::TEXT, QuestItem::texts, Catch::toString(), translator, and QuestItem::var.

Referenced by QuestDb::loadXmlFile().