ManaPlus
Namespaces | Macros | Functions | Variables
horsedb.cpp File Reference

(986a3bf)

#include "resources/db/horsedb.h"
#include "configuration.h"
#include "enums/resources/spritedirection.h"
#include "resources/beingcommon.h"
#include "resources/horseinfo.h"
#include "utils/checkutils.h"
#include "utils/dtor.h"
#include "debug.h"

Go to the source code of this file.

Namespaces

 anonymous_namespace{horsedb.cpp}
 

Macros

#define loadSprite(name)
 

Functions

static void loadDownSprites (xmlNode *const parentNode, HorseInfo *const currentInfo)
 
static void loadUpSprites (xmlNode *const parentNode, HorseInfo *const currentInfo)
 
static int parseDirectionName (const std::string &name)
 
static void loadRiderOffset (xmlNode *const node, HorseInfo *const currentInfo)
 
static void loadOffset (xmlNode *const node, HorseInfo *const currentInfo, const bool isUp)
 

Variables

HorseInfos anonymous_namespace{horsedb.cpp}::mHorseInfos
 
HorseInfo anonymous_namespace{horsedb.cpp}::mUnknown
 
bool anonymous_namespace{horsedb.cpp}::mLoaded = false
 

Macro Definition Documentation

◆ loadSprite

#define loadSprite (   name)
Value:
{ \
SpriteReference *const currentSprite = new SpriteReference; \
currentSprite->sprite = pathJoin(paths.getStringValue("sprites"), \
XmlChildContent(spriteNode)); \
currentSprite->variant = XML::getProperty( \
spriteNode, "variant", 0); \
currentInfo->name.push_back(currentSprite); \
}
std::string getStringValue(const std::string &key) const
Configuration paths
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
std::string pathJoin(std::string str1, const std::string &str2)
std::string sprite

Definition at line 44 of file horsedb.cpp.

Function Documentation

◆ loadDownSprites()

static void loadDownSprites ( xmlNode *const  parentNode,
HorseInfo *const  currentInfo 
)
static

Definition at line 238 of file horsedb.cpp.

240 {
241  for_each_xml_child_node(spriteNode, parentNode)
242  {
243  if (xmlNameEqual(spriteNode, "offset"))
244  loadOffset(spriteNode, currentInfo, false);
245  if (!XmlHaveChildContent(spriteNode))
246  continue;
247  if (xmlNameEqual(spriteNode, "sprite"))
248  loadSprite(downSprites)
249  }
250 }
static void loadOffset(xmlNode *const node, HorseInfo *const currentInfo, const bool isUp)
Definition: horsedb.cpp:208
#define loadSprite(name)
Definition: horsedb.cpp:44
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161

References for_each_xml_child_node, loadOffset(), and loadSprite.

Referenced by HorseDB::loadXmlFile().

◆ loadOffset()

static void loadOffset ( xmlNode *const  node,
HorseInfo *const  currentInfo,
const bool  isUp 
)
static

Definition at line 208 of file horsedb.cpp.

211 {
212  const std::string dirName = XML::getProperty(node,
213  "direction", "");
214  const int dir = parseDirectionName(dirName);
215  if (dir == -1)
216  {
217  reportAlways("Wrong or missing horse direcion: %s",
218  dirName.c_str())
219  return;
220  }
221  HorseOffset &offset = currentInfo->offsets[dir];
222  if (isUp)
223  {
224  offset.upOffsetX = XML::getProperty(node,
225  "horseOffsetX", 0);
226  offset.upOffsetY = XML::getProperty(node,
227  "horseOffsetY", 0);
228  }
229  else
230  {
231  offset.downOffsetX = XML::getProperty(node,
232  "horseOffsetX", 0);
233  offset.downOffsetY = XML::getProperty(node,
234  "horseOffsetY", 0);
235  }
236 }
#define reportAlways(...)
Definition: checkutils.h:253
if(!vert) return
static int parseDirectionName(const std::string &name)
Definition: horsedb.cpp:86

References HorseOffset::downOffsetX, HorseOffset::downOffsetY, XML::getProperty(), HorseInfo::offsets, parseDirectionName(), reportAlways, HorseOffset::upOffsetX, and HorseOffset::upOffsetY.

Referenced by loadDownSprites(), and loadUpSprites().

◆ loadRiderOffset()

static void loadRiderOffset ( xmlNode *const  node,
HorseInfo *const  currentInfo 
)
static

Definition at line 130 of file horsedb.cpp.

132 {
133  const std::string dirName = XML::getProperty(node,
134  "direction", "");
135  const int dir = parseDirectionName(dirName);
136  if (dir == -1)
137  {
138  reportAlways("Wrong or missing horse rider direcion: %s",
139  dirName.c_str())
140  return;
141  }
142  HorseOffset &offset = currentInfo->offsets[dir];
143  offset.riderOffsetX = XML::getProperty(node,
144  "riderOffsetX", 0);
145  offset.riderOffsetY = XML::getProperty(node,
146  "riderOffsetY", 0);
147 }
Definition: libxml.cpp:86

References XML::getProperty(), HorseInfo::offsets, parseDirectionName(), reportAlways, HorseOffset::riderOffsetX, and HorseOffset::riderOffsetY.

Referenced by HorseDB::loadXmlFile().

◆ loadUpSprites()

static void loadUpSprites ( xmlNode *const  parentNode,
HorseInfo *const  currentInfo 
)
static

Definition at line 252 of file horsedb.cpp.

254 {
255  for_each_xml_child_node(spriteNode, parentNode)
256  {
257  if (xmlNameEqual(spriteNode, "offset"))
258  loadOffset(spriteNode, currentInfo, true);
259  if (!XmlHaveChildContent(spriteNode))
260  continue;
261  if (xmlNameEqual(spriteNode, "sprite"))
262  loadSprite(upSprites)
263  }
264 }

References for_each_xml_child_node, loadOffset(), and loadSprite.

Referenced by HorseDB::loadXmlFile().

◆ parseDirectionName()

static int parseDirectionName ( const std::string &  name)
static

Definition at line 86 of file horsedb.cpp.

87 {
88  int id = -1;
89  if (name == "down")
90  {
92  }
93  else if (name == "downleft" || name == "leftdown")
94  {
96  }
97  else if (name == "left")
98  {
100  }
101  else if (name == "upleft" || name == "leftup")
102  {
104  }
105  else if (name == "up")
106  {
107  id = SpriteDirection::UP;
108  }
109  else if (name == "upright" || name == "rightup")
110  {
112  }
113  else if (name == "right")
114  {
116  }
117  else if (name == "downright" || name == "rightdown")
118  {
120  }
121  // hack for died action.
122  else if (name == "died")
123  {
124  id = 9;
125  }
126 
127  return id;
128 }

References SpriteDirection::DOWN, SpriteDirection::DOWNLEFT, SpriteDirection::DOWNRIGHT, SpriteDirection::LEFT, SpriteDirection::RIGHT, SpriteDirection::UP, SpriteDirection::UPLEFT, and SpriteDirection::UPRIGHT.

Referenced by loadOffset(), and loadRiderOffset().