ManaPlus
Functions
CharDB Namespace Reference

Functions

void load ()
 
void unload ()
 
void loadMinMax (const xmlNodePtr node, unsigned *const min, unsigned *const max)
 
unsigned getMinHairColor ()
 
unsigned getMaxHairColor ()
 
unsigned getMinHairStyle ()
 
unsigned getMaxHairStyle ()
 
unsigned getMinStat ()
 
unsigned getMaxStat ()
 
unsigned getSumStat ()
 
unsigned getMinLook ()
 
unsigned getMaxLook ()
 
unsigned getMinRace ()
 
unsigned getMaxRace ()
 
const std::vector< BeingSlot > & getDefaultItems ()
 

Detailed Description

Char information database.

Function Documentation

◆ getDefaultItems()

const std::vector< BeingSlot > & CharDB::getDefaultItems ( )

Definition at line 187 of file chardb.cpp.

188 {
189  return mDefaultItems;
190 }
std::vector< BeingSlot > mDefaultItems
Definition: chardb.cpp:44

References anonymous_namespace{chardb.cpp}::mDefaultItems.

Referenced by CharCreateDialog::CharCreateDialog().

◆ getMaxHairColor()

unsigned CharDB::getMaxHairColor ( )

Definition at line 137 of file chardb.cpp.

138 {
139  return mMaxHairColor;
140 }

References anonymous_namespace{chardb.cpp}::mMaxHairColor.

◆ getMaxHairStyle()

unsigned CharDB::getMaxHairStyle ( )

Definition at line 147 of file chardb.cpp.

148 {
149  return mMaxHairStyle;
150 }

References anonymous_namespace{chardb.cpp}::mMaxHairStyle.

◆ getMaxLook()

unsigned CharDB::getMaxLook ( )

Definition at line 172 of file chardb.cpp.

173 {
174  return mMaxLook;
175 }

References anonymous_namespace{chardb.cpp}::mMaxLook.

◆ getMaxRace()

unsigned CharDB::getMaxRace ( )

Definition at line 182 of file chardb.cpp.

183 {
184  return mMaxRace;
185 }

References anonymous_namespace{chardb.cpp}::mMaxRace.

◆ getMaxStat()

unsigned CharDB::getMaxStat ( )

Definition at line 157 of file chardb.cpp.

158 {
159  return mMaxStat;
160 }

References anonymous_namespace{chardb.cpp}::mMaxStat.

Referenced by TmwAthena::CharServerHandler::setCharCreateDialog().

◆ getMinHairColor()

unsigned CharDB::getMinHairColor ( )

Definition at line 132 of file chardb.cpp.

133 {
134  return mMinHairColor;
135 }

References anonymous_namespace{chardb.cpp}::mMinHairColor.

◆ getMinHairStyle()

unsigned CharDB::getMinHairStyle ( )

Definition at line 142 of file chardb.cpp.

143 {
144  return mMinHairStyle;
145 }

References anonymous_namespace{chardb.cpp}::mMinHairStyle.

◆ getMinLook()

unsigned CharDB::getMinLook ( )

Definition at line 167 of file chardb.cpp.

168 {
169  return mMinLook;
170 }

References anonymous_namespace{chardb.cpp}::mMinLook.

◆ getMinRace()

unsigned CharDB::getMinRace ( )

Definition at line 177 of file chardb.cpp.

178 {
179  return mMinRace;
180 }

References anonymous_namespace{chardb.cpp}::mMinRace.

◆ getMinStat()

unsigned CharDB::getMinStat ( )

Definition at line 152 of file chardb.cpp.

153 {
154  return mMinStat;
155 }

References anonymous_namespace{chardb.cpp}::mMinStat.

Referenced by TmwAthena::CharServerHandler::setCharCreateDialog().

◆ getSumStat()

unsigned CharDB::getSumStat ( )

Definition at line 162 of file chardb.cpp.

163 {
164  return mSumStat;
165 }

References anonymous_namespace{chardb.cpp}::mSumStat.

Referenced by TmwAthena::CharServerHandler::setCharCreateDialog().

◆ load()

void CharDB::load ( )

Loads the chars data.

Definition at line 47 of file chardb.cpp.

48 {
49  if (mLoaded)
50  unload();
51 
52  logger->log1("Initializing char database...");
53 
54  XML::Document *doc = new XML::Document(
55  paths.getStringValue("charCreationFile"),
58  XmlNodeConstPtrConst root = doc->rootNode();
59 
60  if ((root == nullptr) || !xmlNameEqual(root, "chars"))
61  {
62  logger->log("CharDB: Failed to parse %s.",
63  paths.getStringValue("charCreationFile").c_str());
64  delete doc;
65  return;
66  }
67 
68  for_each_xml_child_node(node, root)
69  {
70  if (xmlNameEqual(node, "haircolor"))
71  {
73  }
74  else if (xmlNameEqual(node, "hairstyle"))
75  {
77  }
78  else if (xmlNameEqual(node, "look"))
79  {
80  loadMinMax(node, &mMinLook, &mMaxLook);
81  }
82  else if (xmlNameEqual(node, "stat"))
83  {
84  loadMinMax(node, &mMinStat, &mMaxStat);
85  mSumStat = XML::getProperty(node, "sum", 0);
86  }
87  else if (xmlNameEqual(node, "item"))
88  {
89  const int id = XML::getProperty(node, "id", 0);
90  if (id > 0)
91  {
92  BeingSlot slot;
93  slot.spriteId = id;
94  for (int f = 0; f < maxCards; f ++)
95  {
96  const std::string cardName = strprintf("card%d", f + 1);
97  slot.cardsId.cards[f] = XML::getProperty(node,
98  cardName.c_str(),
99  0);
100  }
101  mDefaultItems.push_back(slot);
102  }
103  }
104  else if (xmlNameEqual(node, "race"))
105  {
106  loadMinMax(node, &mMinRace, &mMaxRace);
107  }
108  }
109 
110  delete doc;
111 
112  mLoaded = true;
113 }
#define maxCards
Definition: cards.h:25
std::string getStringValue(const std::string &key) const
void log(const char *const log_text,...)
Definition: logger.cpp:269
void log1(const char *const log_text)
Definition: logger.cpp:238
xmlNodePtr rootNode()
Definition: libxml.cpp:169
Configuration paths
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
Logger * logger
Definition: logger.cpp:89
void loadMinMax(const xmlNodePtr node, unsigned *const min, unsigned *const max)
Definition: chardb.cpp:115
void unload()
Definition: net.cpp:180
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
const bool SkipError_false
Definition: skiperror.h:30
std::string strprintf(const char *const format,...)
int spriteId
Definition: beingslot.h:45
CardsList cardsId
Definition: beingslot.h:46
int cards[4]
Definition: cardslist.h:68
const bool UseVirtFs_true
Definition: usevirtfs.h:30

References CardsList::cards, BeingSlot::cardsId, for_each_xml_child_node, XML::getProperty(), Configuration::getStringValue(), loadMinMax(), Logger::log(), Logger::log1(), logger, maxCards, anonymous_namespace{chardb.cpp}::mDefaultItems, anonymous_namespace{chardb.cpp}::mLoaded, anonymous_namespace{chardb.cpp}::mMaxHairColor, anonymous_namespace{chardb.cpp}::mMaxHairStyle, anonymous_namespace{chardb.cpp}::mMaxLook, anonymous_namespace{chardb.cpp}::mMaxRace, anonymous_namespace{chardb.cpp}::mMaxStat, anonymous_namespace{chardb.cpp}::mMinHairColor, anonymous_namespace{chardb.cpp}::mMinHairStyle, anonymous_namespace{chardb.cpp}::mMinLook, anonymous_namespace{chardb.cpp}::mMinRace, anonymous_namespace{chardb.cpp}::mMinStat, anonymous_namespace{chardb.cpp}::mSumStat, paths, XML::Document::rootNode(), SkipError_false, BeingSlot::spriteId, strprintf(), Net::unload(), and UseVirtFs_true.

Referenced by DbManager::loadDb().

◆ loadMinMax()

void CharDB::loadMinMax ( const xmlNodePtr  node,
unsigned *const  min,
unsigned *const  max 
)

Definition at line 115 of file chardb.cpp.

118 {
119  if (min != nullptr)
120  *min = XML::getProperty(node, "min", 1);
121  if (max != nullptr)
122  *max = XML::getProperty(node, "max", 10);
123 }

References XML::getProperty().

Referenced by load().

◆ unload()

void CharDB::unload ( )

Clear the chars data

Definition at line 125 of file chardb.cpp.

126 {
127  logger->log1("Unloading char database...");
128 
129  mLoaded = false;
130 }

References Logger::log1(), logger, and anonymous_namespace{chardb.cpp}::mLoaded.

Referenced by DbManager::unloadDb().