ManaPlus
beingcommon.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2013-2019 The ManaPlus Developers
4  *
5  * This file is part of The ManaPlus Client.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "resources/beingcommon.h"
22 
23 #include "configuration.h"
24 #include "logger.h"
25 
27 
28 #include "utils/cast.h"
29 
30 #include "resources/beinginfo.h"
31 
33 
34 #include "debug.h"
35 
37  XmlNodePtrConst node,
38  const std::string &hoverCursor)
39 {
40  info->setTargetCursorSize(XML::getProperty(node,
41  "targetCursor", "medium"));
42 
43  info->setHoverCursor(XML::getProperty(node, "hoverCursor", hoverCursor));
44 
45  info->setTargetOffsetX(XML::getProperty(node, "targetOffsetX", 0));
46  info->setTargetOffsetY(XML::getProperty(node, "targetOffsetY", 0));
47 
48  info->setNameOffsetX(XML::getProperty(node, "nameOffsetX", 0));
49  info->setNameOffsetY(XML::getProperty(node, "nameOffsetY", 0));
50  info->setSortOffsetY(XML::getProperty(node, "sortOffsetY", 0));
51 
52  info->setHpBarOffsetX(XML::getProperty(node, "hpBarOffsetX", 0));
53  info->setHpBarOffsetY(XML::getProperty(node, "hpBarOffsetY", 0));
54 
55  info->setQuickActionEffectId(XML::getProperty(node,
56  "quickActionEffect", -1));
57 }
58 
60  XmlNodePtrConst node,
61  const int moreBlockFlags)
62 {
63  uint8_t block = 0;
64  std::string walkStr = XML::getProperty(
65  node, "walkType", "walk");
66 
67  const uint8_t allFlags = CAST_U8(
72  moreBlockFlags);
73  StringVect tokens;
74  splitToStringVector(tokens, walkStr, ',');
75  FOR_EACH (StringVectCIter, it, tokens)
76  {
77  if (walkStr == "walk" || walkStr == "ground")
78  block |= BlockMask::GROUND;
79  else if (walkStr == "fly" || walkStr == "air")
81  else if (walkStr == "all")
82  block |= allFlags;
83  else if (walkStr == "wall")
84  block |= BlockMask::WALL;
85  else if (walkStr == "monsterwall")
86  block |= BlockMask::MONSTERWALL;
87  else if (walkStr == "swim" || walkStr == "water")
88  block |= BlockMask::WATER;
89  else if (walkStr == "walkswim" || walkStr == "swimwalk") // legacy
91  }
92  info->setBlockWalkMask(CAST_U8(block ^ allFlags));
93 }
94 
96  XmlNodePtrConst node)
97 {
98  info->setStartFollowDist(XML::getProperty(node,
99  "startFollowDistance", 3));
100  info->setFollowDist(XML::getProperty(node,
101  "followDistance", 0));
102  info->setWarpDist(XML::getProperty(node,
103  "warpDistance", 11));
104 
105  info->setTargetOffsetX(XML::getProperty(node,
106  "offsetX", 0));
107  info->setTargetOffsetY(XML::getProperty(node,
108  "offsetY", 1));
109  info->setSitOffsetX(XML::getProperty(node,
110  "sitOffsetX", 0));
111  info->setSitOffsetY(XML::getProperty(node,
112  "sitOffsetY", 1));
113  info->setMoveOffsetX(XML::getProperty(node,
114  "moveOffsetX", 0));
115  info->setMoveOffsetY(XML::getProperty(node,
116  "moveOffsetY", 1));
117  info->setDeadOffsetX(XML::getProperty(node,
118  "deadOffsetX", 0));
119  info->setDeadOffsetY(XML::getProperty(node,
120  "deadOffsetY", 1));
121  info->setAttackOffsetX(XML::getProperty(node,
122  "attackOffsetX", info->getTargetOffsetX()));
123  info->setAttackOffsetY(XML::getProperty(node,
124  "attackOffsetY", info->getTargetOffsetY()));
125 
126  info->setThinkTime(XML::getProperty(node,
127  "thinkTime", 500) / 10);
128 
129  info->setDirectionType(XML::getProperty(node,
130  "directionType", 1));
131  info->setSitDirectionType(XML::getProperty(node,
132  "sitDirectionType", 1));
133  info->setDeadDirectionType(XML::getProperty(node,
134  "deadDirectionType", 1));
135  info->setAttackDirectionType(XML::getProperty(node,
136  "attackDirectionType", 4));
137 }
138 
139 bool BeingCommon::readObjectNodes(XmlNodePtrConst &spriteNode,
140  SpriteDisplay &display,
141  BeingInfo *const currentInfo,
142  const std::string &dbName)
143 {
144  if (xmlNameEqual(spriteNode, "sprite"))
145  {
146  if (!XmlHaveChildContent(spriteNode))
147  return true;
148 
149  SpriteReference *const currentSprite = new SpriteReference;
150  currentSprite->sprite = XmlChildContent(spriteNode);
151 
152  currentSprite->variant = XML::getProperty(
153  spriteNode, "variant", 0);
154  display.sprites.push_back(currentSprite);
155  return true;
156  }
157  else if (xmlNameEqual(spriteNode, "sound"))
158  {
159  if (!XmlHaveChildContent(spriteNode))
160  return true;
161 
162  const std::string event = XML::getProperty(
163  spriteNode, "event", "");
164  const int delay = XML::getProperty(
165  spriteNode, "delay", 0);
166  const char *const filename = XmlChildContent(spriteNode);
167 
168  if (event == "hit")
169  {
170  currentInfo->addSound(ItemSoundEvent::HIT, filename, delay);
171  }
172  else if (event == "miss")
173  {
174  currentInfo->addSound(ItemSoundEvent::MISS, filename, delay);
175  }
176  else if (event == "hurt")
177  {
178  currentInfo->addSound(ItemSoundEvent::HURT, filename, delay);
179  }
180  else if (event == "die")
181  {
182  currentInfo->addSound(ItemSoundEvent::DIE, filename, delay);
183  }
184  else if (event == "move")
185  {
186  currentInfo->addSound(ItemSoundEvent::MOVE, filename, delay);
187  }
188  else if (event == "sit")
189  {
190  currentInfo->addSound(ItemSoundEvent::SIT, filename, delay);
191  }
192  else if (event == "sittop")
193  {
194  currentInfo->addSound(ItemSoundEvent::SITTOP, filename, delay);
195  }
196  else if (event == "spawn")
197  {
198  currentInfo->addSound(ItemSoundEvent::SPAWN, filename, delay);
199  }
200  else
201  {
202  logger->log((dbName + ": Warning, sound effect %s for "
203  "unknown event %s of monster %s").c_str(),
204  filename, event.c_str(),
205  currentInfo->getName().c_str());
206  }
207  return true;
208  }
209  else if (xmlNameEqual(spriteNode, "attack"))
210  {
211  const int attackId = XML::getProperty(spriteNode, "id", 0);
212  const int effectId = XML::getProperty(spriteNode, "effect-id",
213  paths.getIntValue("effectId"));
214  const int hitEffectId = XML::getProperty(spriteNode, "hit-effect-id",
215  paths.getIntValue("hitEffectId"));
216  const int criticalHitEffectId = XML::getProperty(spriteNode,
217  "critical-hit-effect-id",
218  paths.getIntValue("criticalHitEffectId"));
219  const int missEffectId = XML::getProperty(spriteNode, "miss-effect-id",
220  paths.getIntValue("missEffectId"));
221 
222  const std::string spriteAction = XML::getProperty(spriteNode, "action",
223  "attack");
224  const std::string skySpriteAction = XML::getProperty(spriteNode,
225  "skyaction", "skyattack");
226  const std::string waterSpriteAction = XML::getProperty(spriteNode,
227  "wateraction", "waterattack");
228  const std::string rideSpriteAction = XML::getProperty(spriteNode,
229  "rideaction", "rideattack");
230 
231  const std::string missileParticle = XML::getProperty(spriteNode,
232  "missile-particle", "");
233 
234  const float missileZ = XML::getFloatProperty(
235  spriteNode, "missile-z", 32.0F);
236  const int missileLifeTime = XML::getProperty(
237  spriteNode, "missile-lifetime", 500);
238  const float missileSpeed = XML::getFloatProperty(
239  spriteNode, "missile-speed", 7.0F);
240  const float missileDieDistance = XML::getFloatProperty(
241  spriteNode, "missile-diedistance", 8.0F);
242 
243  currentInfo->addAttack(attackId,
244  spriteAction,
245  skySpriteAction,
246  waterSpriteAction,
247  rideSpriteAction,
248  effectId,
249  hitEffectId,
250  criticalHitEffectId,
251  missEffectId,
252  missileParticle,
253  missileZ,
254  missileSpeed,
255  missileDieDistance,
256  missileLifeTime);
257  return true;
258  }
259  else if (xmlNameEqual(spriteNode, "particlefx"))
260  {
261  if (!XmlHaveChildContent(spriteNode))
262  return true;
263 
264  display.particles.push_back(XmlChildContent(spriteNode));
265  return true;
266  }
267  return false;
268 }
cast.h
ItemSoundEvent::HURT
@ HURT
Definition: itemsoundevent.h:30
XML::getFloatProperty
float getFloatProperty(const xmlNodePtr node, const char *const name, float def)
Definition: libxml.cpp:210
logger.h
BeingInfo
Definition: beinginfo.h:52
ItemSoundEvent::DIE
@ DIE
Definition: itemsoundevent.h:31
BeingCommon::readAiAttributes
void readAiAttributes(BeingInfo *const info, xmlNode *const node)
Definition: beingcommon.cpp:95
SpriteDisplay::sprites
std::vector< SpriteReference * > sprites
Definition: spritedisplay.h:46
paths
Configuration paths
Definition: configuration.cpp:55
splitToStringVector
void splitToStringVector(StringVect &tokens, const std::string &text, const char separator)
Definition: stringutils.cpp:484
StringVect
std::vector< std::string > StringVect
Definition: stringvector.h:28
BlockMask::WATER
@ WATER
Definition: blockmask.h:32
blockmask.h
ItemSoundEvent::SIT
@ SIT
Definition: itemsoundevent.h:33
XML::getProperty
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:173
ItemSoundEvent::HIT
@ HIT
Definition: itemsoundevent.h:28
logger
Logger * logger
Definition: logger.cpp:88
BlockMask::GROUND
@ GROUND
Definition: blockmask.h:33
Actions::info
bool info(InputEvent &event)
Definition: commands.cpp:56
CAST_U8
#define CAST_U8
Definition: cast.h:26
SpriteReference
Definition: spritereference.h:30
BlockMask::MONSTERWALL
@ MONSTERWALL
Definition: blockmask.h:36
beingcommon.h
BeingInfo::getName
const std::string & getName() const
Definition: beinginfo.h:67
BlockMask::WALL
@ WALL
Definition: blockmask.h:30
ItemSoundEvent::SITTOP
@ SITTOP
Definition: itemsoundevent.h:34
spritereference.h
SpriteDisplay
Definition: spritedisplay.h:32
BeingCommon::readBasicAttributes
void readBasicAttributes(BeingInfo *const info, xmlNode *const node, const std::string &hoverCursor)
Definition: beingcommon.cpp:36
Configuration::getIntValue
int getIntValue(const std::string &key) const
Definition: configuration.cpp:403
SpriteDisplay::particles
StringVect particles
Definition: spritedisplay.h:47
BlockMask::AIR
@ AIR
Definition: blockmask.h:31
BeingInfo::addSound
void addSound(const ItemSoundEvent::Type event, const std::string &filename, const int delay)
Definition: beinginfo.cpp:153
BeingInfo::addAttack
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:185
beinginfo.h
configuration.h
SpriteReference::variant
int variant
Definition: spritereference.h:48
BeingCommon::readObjectNodes
bool readObjectNodes(xmlNode *const &spriteNode, SpriteDisplay &display, BeingInfo *const currentInfo, const std::string &dbName)
Definition: beingcommon.cpp:139
StringVectCIter
StringVect::const_iterator StringVectCIter
Definition: stringvector.h:30
BeingCommon::readWalkingAttributes
void readWalkingAttributes(BeingInfo *const info, xmlNode *const node, const int moreBlockFlags)
Definition: beingcommon.cpp:59
ItemSoundEvent::MOVE
@ MOVE
Definition: itemsoundevent.h:32
SpriteReference::sprite
std::string sprite
Definition: spritereference.h:47
ItemSoundEvent::SPAWN
@ SPAWN
Definition: itemsoundevent.h:35
ItemSoundEvent::MISS
@ MISS
Definition: itemsoundevent.h:29
Logger::log
void log(const char *const log_text,...)
Definition: logger.cpp:268
FOR_EACH
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
debug.h