ManaPlus
Functions
BeingCommon Namespace Reference

Functions

void readBasicAttributes (BeingInfo *const info, xmlNode *const node, const std::string &hoverCursor)
 
void readWalkingAttributes (BeingInfo *const info, xmlNode *const node, const int moreBlockFlags)
 
void readAiAttributes (BeingInfo *const info, xmlNode *const node)
 
void getIncludeFiles (const std::string &dir, StringVect &list, const std::string &ext)
 
bool readObjectNodes (xmlNode *const &spriteNode, SpriteDisplay &display, BeingInfo *const currentInfo, const std::string &dbName)
 

Function Documentation

◆ getIncludeFiles()

void BeingCommon::getIncludeFiles ( const std::string &  dir,
StringVect list,
const std::string &  ext 
)

◆ readAiAttributes()

void BeingCommon::readAiAttributes ( BeingInfo *const  info,
xmlNode *const  node 
)

Definition at line 96 of file beingcommon.cpp.

98 {
99  info->setStartFollowDist(XML::getProperty(node,
100  "startFollowDistance", 3));
101  info->setFollowDist(XML::getProperty(node,
102  "followDistance", 0));
103  info->setWarpDist(XML::getProperty(node,
104  "warpDistance", 11));
105 
106  info->setTargetOffsetX(XML::getProperty(node,
107  "offsetX", 0));
108  info->setTargetOffsetY(XML::getProperty(node,
109  "offsetY", 1));
110  info->setSitOffsetX(XML::getProperty(node,
111  "sitOffsetX", 0));
112  info->setSitOffsetY(XML::getProperty(node,
113  "sitOffsetY", 1));
114  info->setMoveOffsetX(XML::getProperty(node,
115  "moveOffsetX", 0));
116  info->setMoveOffsetY(XML::getProperty(node,
117  "moveOffsetY", 1));
118  info->setDeadOffsetX(XML::getProperty(node,
119  "deadOffsetX", 0));
120  info->setDeadOffsetY(XML::getProperty(node,
121  "deadOffsetY", 1));
122  info->setAttackOffsetX(XML::getProperty(node,
123  "attackOffsetX", info->getTargetOffsetX()));
124  info->setAttackOffsetY(XML::getProperty(node,
125  "attackOffsetY", info->getTargetOffsetY()));
126 
127  info->setThinkTime(XML::getProperty(node,
128  "thinkTime", 500) / 10);
129 
130  info->setDirectionType(XML::getProperty(node,
131  "directionType", 1));
132  info->setSitDirectionType(XML::getProperty(node,
133  "sitDirectionType", 1));
134  info->setDeadDirectionType(XML::getProperty(node,
135  "deadDirectionType", 1));
136  info->setAttackDirectionType(XML::getProperty(node,
137  "attackDirectionType", 4));
138 }
bool info(InputEvent &event)
Definition: commands.cpp:57
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174

References XML::getProperty(), and Actions::info().

Referenced by HomunculusDB::loadXmlFile(), and MercenaryDB::loadXmlFile().

◆ readBasicAttributes()

void BeingCommon::readBasicAttributes ( BeingInfo *const  info,
xmlNode *const  node,
const std::string &  hoverCursor 
)

Definition at line 37 of file beingcommon.cpp.

40 {
41  info->setTargetCursorSize(XML::getProperty(node,
42  "targetCursor", "medium"));
43 
44  info->setHoverCursor(XML::getProperty(node, "hoverCursor", hoverCursor));
45 
46  info->setTargetOffsetX(XML::getProperty(node, "targetOffsetX", 0));
47  info->setTargetOffsetY(XML::getProperty(node, "targetOffsetY", 0));
48 
49  info->setNameOffsetX(XML::getProperty(node, "nameOffsetX", 0));
50  info->setNameOffsetY(XML::getProperty(node, "nameOffsetY", 0));
51  info->setSortOffsetY(XML::getProperty(node, "sortOffsetY", 0));
52 
53  info->setHpBarOffsetX(XML::getProperty(node, "hpBarOffsetX", 0));
54  info->setHpBarOffsetY(XML::getProperty(node, "hpBarOffsetY", 0));
55 
56  info->setQuickActionEffectId(XML::getProperty(node,
57  "quickActionEffect", -1));
58 }

References XML::getProperty(), and Actions::info().

Referenced by ElementalDb::loadXmlFile(), HomunculusDB::loadXmlFile(), MercenaryDB::loadXmlFile(), MonsterDB::loadXmlFile(), NPCDB::loadXmlFile(), PETDB::loadXmlFile(), and SkillUnitDb::loadXmlFile().

◆ readObjectNodes()

bool BeingCommon::readObjectNodes ( xmlNode *const &  spriteNode,
SpriteDisplay display,
BeingInfo *const  currentInfo,
const std::string &  dbName 
)

Definition at line 140 of file beingcommon.cpp.

144 {
145  if (xmlNameEqual(spriteNode, "sprite"))
146  {
147  if (!XmlHaveChildContent(spriteNode))
148  return true;
149 
150  SpriteReference *const currentSprite = new SpriteReference;
151  currentSprite->sprite = XmlChildContent(spriteNode);
152 
153  currentSprite->variant = XML::getProperty(
154  spriteNode, "variant", 0);
155  display.sprites.push_back(currentSprite);
156  return true;
157  }
158  else if (xmlNameEqual(spriteNode, "sound"))
159  {
160  if (!XmlHaveChildContent(spriteNode))
161  return true;
162 
163  const std::string event = XML::getProperty(
164  spriteNode, "event", "");
165  const int delay = XML::getProperty(
166  spriteNode, "delay", 0);
167  const char *const filename = XmlChildContent(spriteNode);
168 
169  if (event == "hit")
170  {
171  currentInfo->addSound(ItemSoundEvent::HIT, filename, delay);
172  }
173  else if (event == "miss")
174  {
175  currentInfo->addSound(ItemSoundEvent::MISS, filename, delay);
176  }
177  else if (event == "hurt")
178  {
179  currentInfo->addSound(ItemSoundEvent::HURT, filename, delay);
180  }
181  else if (event == "die")
182  {
183  currentInfo->addSound(ItemSoundEvent::DIE, filename, delay);
184  }
185  else if (event == "move")
186  {
187  currentInfo->addSound(ItemSoundEvent::MOVE, filename, delay);
188  }
189  else if (event == "sit")
190  {
191  currentInfo->addSound(ItemSoundEvent::SIT, filename, delay);
192  }
193  else if (event == "sittop")
194  {
195  currentInfo->addSound(ItemSoundEvent::SITTOP, filename, delay);
196  }
197  else if (event == "spawn")
198  {
199  currentInfo->addSound(ItemSoundEvent::SPAWN, filename, delay);
200  }
201  else
202  {
203  logger->log((dbName + ": Warning, sound effect %s for "
204  "unknown event %s of monster %s").c_str(),
205  filename, event.c_str(),
206  currentInfo->getName().c_str());
207  }
208  return true;
209  }
210  else if (xmlNameEqual(spriteNode, "attack"))
211  {
212  const int attackId = XML::getProperty(spriteNode, "id", 0);
213  const int effectId = XML::getProperty(spriteNode, "effect-id",
214  paths.getIntValue("effectId"));
215  const int hitEffectId = XML::getProperty(spriteNode, "hit-effect-id",
216  paths.getIntValue("hitEffectId"));
217  const int criticalHitEffectId = XML::getProperty(spriteNode,
218  "critical-hit-effect-id",
219  paths.getIntValue("criticalHitEffectId"));
220  const int missEffectId = XML::getProperty(spriteNode, "miss-effect-id",
221  paths.getIntValue("missEffectId"));
222 
223  const std::string spriteAction = XML::getProperty(spriteNode, "action",
224  "attack");
225  const std::string skySpriteAction = XML::getProperty(spriteNode,
226  "skyaction", "skyattack");
227  const std::string waterSpriteAction = XML::getProperty(spriteNode,
228  "wateraction", "waterattack");
229  const std::string rideSpriteAction = XML::getProperty(spriteNode,
230  "rideaction", "rideattack");
231 
232  const std::string missileParticle = XML::getProperty(spriteNode,
233  "missile-particle", "");
234 
235  const float missileZ = XML::getFloatProperty(
236  spriteNode, "missile-z", 32.0F);
237  const int missileLifeTime = XML::getProperty(
238  spriteNode, "missile-lifetime", 500);
239  const float missileSpeed = XML::getFloatProperty(
240  spriteNode, "missile-speed", 7.0F);
241  const float missileDieDistance = XML::getFloatProperty(
242  spriteNode, "missile-diedistance", 8.0F);
243 
244  currentInfo->addAttack(attackId,
245  spriteAction,
246  skySpriteAction,
247  waterSpriteAction,
248  rideSpriteAction,
249  effectId,
250  hitEffectId,
251  criticalHitEffectId,
252  missEffectId,
253  missileParticle,
254  missileZ,
255  missileSpeed,
256  missileDieDistance,
257  missileLifeTime);
258  return true;
259  }
260  else if (xmlNameEqual(spriteNode, "particlefx"))
261  {
262  if (!XmlHaveChildContent(spriteNode))
263  return true;
264 
265  display.particles.push_back(XmlChildContent(spriteNode));
266  return true;
267  }
268  return false;
269 }
void addSound(const ItemSoundEvent::Type event, const std::string &filename, const int delay)
Definition: beinginfo.cpp:154
void addAttack(const int id, const std::string &action, const std::string &skyAttack, const std::string &waterAttack, const std::string &rideAttack, const int effectId, const int hitEffectId, const int criticalHitEffectId, const int missEffectId, const std::string &missileParticle, const float missileZ, const float missileSpeed, const float missileDieDistance, const int missileLifeTime)
Definition: beinginfo.cpp:186
const std::string & getName() const
Definition: beinginfo.h:68
int getIntValue(const std::string &key) const
void log(const char *const log_text,...)
Definition: logger.cpp:269
Configuration paths
Logger * logger
Definition: logger.cpp:89
float getFloatProperty(const xmlNodePtr node, const char *const name, float def)
Definition: libxml.cpp:211
StringVect particles
Definition: spritedisplay.h:48
std::vector< SpriteReference * > sprites
Definition: spritedisplay.h:47
std::string sprite

References BeingInfo::addAttack(), BeingInfo::addSound(), ItemSoundEvent::DIE, XML::getFloatProperty(), Configuration::getIntValue(), BeingInfo::getName(), XML::getProperty(), ItemSoundEvent::HIT, ItemSoundEvent::HURT, Logger::log(), logger, ItemSoundEvent::MISS, ItemSoundEvent::MOVE, SpriteDisplay::particles, paths, ItemSoundEvent::SIT, ItemSoundEvent::SITTOP, ItemSoundEvent::SPAWN, SpriteReference::sprite, SpriteDisplay::sprites, and SpriteReference::variant.

Referenced by ElementalDb::loadXmlFile(), HomunculusDB::loadXmlFile(), MercenaryDB::loadXmlFile(), and MonsterDB::loadXmlFile().

◆ readWalkingAttributes()

void BeingCommon::readWalkingAttributes ( BeingInfo *const  info,
xmlNode *const  node,
const int  moreBlockFlags 
)

Definition at line 60 of file beingcommon.cpp.

63 {
64  uint8_t block = 0;
65  std::string walkStr = XML::getProperty(
66  node, "walkType", "walk");
67 
68  const uint8_t allFlags = CAST_U8(
73  moreBlockFlags);
74  StringVect tokens;
75  splitToStringVector(tokens, walkStr, ',');
76  FOR_EACH (StringVectCIter, it, tokens)
77  {
78  if (walkStr == "walk" || walkStr == "ground")
79  block |= BlockMask::GROUND;
80  else if (walkStr == "fly" || walkStr == "air")
82  else if (walkStr == "all")
83  block |= allFlags;
84  else if (walkStr == "wall")
85  block |= BlockMask::WALL;
86  else if (walkStr == "monsterwall")
87  block |= BlockMask::MONSTERWALL;
88  else if (walkStr == "swim" || walkStr == "water")
89  block |= BlockMask::WATER;
90  else if (walkStr == "walkswim" || walkStr == "swimwalk") // legacy
92  }
93  info->setBlockWalkMask(CAST_U8(block ^ allFlags));
94 }
#define CAST_U8
Definition: cast.h:27
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
@ MONSTERWALL
Definition: blockmask.h:37
void splitToStringVector(StringVect &tokens, const std::string &text, const char separator)
StringVect::const_iterator StringVectCIter
Definition: stringvector.h:31
std::vector< std::string > StringVect
Definition: stringvector.h:29

References BlockMask::AIR, CAST_U8, FOR_EACH, XML::getProperty(), BlockMask::GROUND, Actions::info(), BlockMask::MONSTERWALL, splitToStringVector(), BlockMask::WALL, and BlockMask::WATER.

Referenced by ElementalDb::loadXmlFile(), HomunculusDB::loadXmlFile(), MercenaryDB::loadXmlFile(), MonsterDB::loadXmlFile(), NPCDB::loadXmlFile(), PETDB::loadXmlFile(), and SkillUnitDb::loadXmlFile().