ManaPlus
beinginfo.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include "resources/beinginfo.h"
24 
25 #include "configuration.h"
26 #include "logger.h"
27 
29 
31 
32 #include "resources/attack.h"
33 
35 
36 #include "resources/db/colordb.h"
37 
38 #include "utils/cast.h"
39 #include "utils/delete2.h"
40 #include "utils/dtor.h"
41 #include "utils/gettext.h"
42 
43 #include "debug.h"
44 
45 BeingInfo *BeingInfo::unknown = nullptr;
50  -1,
51  -1,
52  -1,
53  -1,
54  std::string(),
55  32.0F,
56  7.0F,
57  8.0F,
58  500);
59 
61  mDisplay(),
62  // TRANSLATORS: being info default name
63  mName(_("unnamed")),
64  mTargetCursorSize(TargetCursorSize::MEDIUM),
65  mHoverCursor(Cursor::CURSOR_POINTER),
66  mSounds(),
67  mAttacks(),
68  mMenu(),
69  mStrings(),
70  mCurrency(),
71  mBlockWalkMask(BlockMask::WALL |
72  BlockMask::AIR |
73  BlockMask::WATER |
75  mBlockType(BlockType::NONE),
77  mTargetOffsetX(0),
78  mTargetOffsetY(0),
79  mNameOffsetX(0),
80  mNameOffsetY(0),
81  mHpBarOffsetX(0),
82  mHpBarOffsetY(0),
83  mMaxHP(0),
84  mSortOffsetY(0),
85  mDeadSortOffsetY(31),
86  mAvatarId(BeingTypeId_zero),
87  mWidth(0),
88  mHeight(0),
89  mStartFollowDist(3),
90  mFollowDist(1),
91  mWarpDist(11),
92  mWalkSpeed(0),
93  mSitOffsetX(0),
94  mSitOffsetY(0),
95  mMoveOffsetX(0),
96  mMoveOffsetY(0),
97  mDeadOffsetX(0),
98  mDeadOffsetY(0),
99  mAttackOffsetX(0),
100  mAttackOffsetY(0),
101  mThinkTime(50),
102  mDirectionType(1),
103  mSitDirectionType(1),
104  mDeadDirectionType(1),
105  mAttackDirectionType(1),
106  mQuickActionEffectId(-1),
107  mStaticMaxHP(false),
108  mTargetSelection(true),
109  mAllowDelete(true),
110  mAllowEquipment(false)
111 {
112  SpriteDisplay display;
113  display.sprites.push_back(SpriteReference::Empty);
114 
115  setDisplay(display);
116 }
117 
119 {
122  mSounds.clear();
124 }
125 
127 {
128  mDisplay = display;
129 }
130 
131 void BeingInfo::setTargetCursorSize(const std::string &size)
132 {
133  if (size == "small")
134  {
136  }
137  else if (size == "medium")
138  {
140  }
141  else if (size == "large")
142  {
144  }
145  else
146  {
147  logger->log("Unknown target cursor type \"%s\" for %s - using medium "
148  "sized one", size.c_str(), getName().c_str());
150  }
151 }
152 
154  const std::string &filename,
155  const int delay)
156 {
157  if (mSounds.find(event) == mSounds.end())
158  mSounds[event] = new SoundInfoVect;
159 
160  if (mSounds[event] != nullptr)
161  mSounds[event]->push_back(SoundInfo(filename, delay));
162 }
163 
165 {
166  static SoundInfo emptySound("", 0);
167 
168  const ItemSoundEvents::const_iterator i = mSounds.find(event);
169 
170  if (i == mSounds.end())
171  return emptySound;
172 
173  const SoundInfoVect *const vect = i->second;
174  if (vect == nullptr || vect->empty())
175  return emptySound;
176  return vect->at(CAST_SIZE(rand()) % vect->size());
177 }
178 
179 const Attack *BeingInfo::getAttack(const int id) const
180 {
181  const Attacks::const_iterator i = mAttacks.find(id);
182  return (i == mAttacks.end()) ? empty : (*i).second;
183 }
184 
185 void BeingInfo::addAttack(const int id,
186  const std::string &action,
187  const std::string &skyAction,
188  const std::string &waterAction,
189  const std::string &rideAction,
190  const int effectId,
191  const int hitEffectId,
192  const int criticalHitEffectId,
193  const int missEffectId,
194  const std::string &missileParticle,
195  const float missileZ,
196  const float missileSpeed,
197  const float missileDieDistance,
198  const int missileLifeTime)
199 {
200  delete mAttacks[id];
201  mAttacks[id] = new Attack(action,
202  skyAction,
203  waterAction,
204  rideAction,
205  effectId,
206  hitEffectId,
207  criticalHitEffectId,
208  missEffectId,
209  missileParticle,
210  missileZ,
211  missileSpeed,
212  missileDieDistance,
213  missileLifeTime);
214 }
215 
217 {
219  delete2(empty)
220 }
221 
223 {
224  if (empty != nullptr)
225  {
226  empty->mEffectId = paths.getIntValue("effectId");
227  empty->mHitEffectId = paths.getIntValue("hitEffectId");
228  empty->mCriticalHitEffectId = paths.getIntValue("criticalHitEffectId");
229  empty->mMissEffectId = paths.getIntValue("missEffectId");
230  }
231 }
232 
233 void BeingInfo::setColorsList(const std::string &name)
234 {
235  if (name.empty())
236  mColors = nullptr;
237  else
239 }
240 
241 std::string BeingInfo::getColor(const ItemColor idx) const
242 {
243  if (mColors == nullptr)
244  return std::string();
245 
246  const std::map <ItemColor, ItemColorData>::const_iterator
247  it = mColors->find(idx);
248  if (it == mColors->end())
249  return std::string();
250  return it->second.color;
251 }
252 
253 void BeingInfo::addMenu(const std::string &name, const std::string &command)
254 {
255  mMenu.push_back(BeingMenuItem(name, command));
256 }
257 
258 const STD_VECTOR<BeingMenuItem> &BeingInfo::getMenu() const
259 {
260  return mMenu;
261 }
262 
263 std::string BeingInfo::getString(const int idx) const
264 {
265  const std::map<int, std::string>::const_iterator it = mStrings.find(idx);
266  if (it == mStrings.end())
267  return "";
268  return (*it).second;
269 }
BeingInfo::setDisplay
void setDisplay(const SpriteDisplay &display)
Definition: beinginfo.cpp:126
SpriteAction::ATTACKRIDE
static const std::string ATTACKRIDE("attackride")
Attack::mHitEffectId
int mHitEffectId
Definition: attack.h:35
TargetCursorSize::SMALL
@ SMALL
Definition: targetcursorsize.h:29
Attack::mCriticalHitEffectId
int mCriticalHitEffectId
Definition: attack.h:36
cast.h
CAST_SIZE
#define CAST_SIZE
Definition: cast.h:33
Cursor::CURSOR_POINTER
@ CURSOR_POINTER
Definition: cursor.h:28
logger.h
BeingInfo
Definition: beinginfo.h:52
BeingInfo::mColors
const std::map< ItemColor, ItemColorData > * mColors
Definition: beinginfo.h:371
BeingInfo::setTargetCursorSize
void setTargetCursorSize(const std::string &size)
Definition: beinginfo.cpp:131
BeingMenuItem
Definition: beingmenuitem.h:28
BeingInfo::getString
std::string getString(const int idx) const
Definition: beinginfo.cpp:263
SpriteAction::ATTACK
static const std::string ATTACK("attack")
BlockType
Definition: blocktype.h:28
SpriteDisplay::sprites
std::vector< SpriteReference * > sprites
Definition: spritedisplay.h:46
anonymous_namespace{palettedb.cpp}::mColors
std::map< std::string, DyeColor > mColors
Definition: palettedb.cpp:36
paths
Configuration paths
Definition: configuration.cpp:55
ItemSoundEvent::Type
Type
Definition: itemsoundevent.h:26
delete2.h
BeingInfo::init
static void init()
Definition: beinginfo.cpp:222
SoundInfoVect
std::vector< SoundInfo > SoundInfoVect
Definition: soundinfo.h:48
TargetCursorSize
Definition: targetcursorsize.h:27
BlockMask::WATER
@ WATER
Definition: blockmask.h:32
blockmask.h
Attack
Definition: attack.h:28
BeingInfo::mSounds
ItemSoundEvents mSounds
Definition: beinginfo.h:364
delete2
#define delete2(var)
Definition: delete2.h:24
SpriteAction::ATTACKSKY
static const std::string ATTACKSKY("attacksky")
BeingInfo::setColorsList
void setColorsList(const std::string &name)
Definition: beinginfo.cpp:233
attack.h
SkillType::Attack
@ Attack
Definition: skilltype.h:30
BeingInfo::mMenu
std::vector< BeingMenuItem > mMenu
Definition: beinginfo.h:366
logger
Logger * logger
Definition: logger.cpp:88
BeingInfo::empty
static Attack * empty
Definition: beinginfo.h:56
BeingInfo::~BeingInfo
~BeingInfo()
Definition: beinginfo.cpp:118
BeingInfo::clear
static void clear()
Definition: beinginfo.cpp:216
BlockMask::MONSTERWALL
@ MONSTERWALL
Definition: blockmask.h:36
nullptr
#define nullptr
Definition: localconsts.h:44
Attack::mEffectId
int mEffectId
Definition: attack.h:34
anonymous_namespace{sounddb.cpp}::mSounds
std::vector< std::string > mSounds
Definition: sounddb.cpp:36
BeingTypeId_zero
const BeingTypeId BeingTypeId_zero
Definition: beingtypeid.h:29
SpriteReference::Empty
static SpriteReference * Empty
Definition: spritereference.h:32
SoundInfo
Definition: soundinfo.h:33
colordb.h
TargetCursorType::NONE
@ NONE
Definition: targetcursortype.h:29
gettext.h
BeingInfo::getName
const std::string & getName() const
Definition: beinginfo.h:67
BeingInfo::BeingInfo
BeingInfo()
Definition: beinginfo.cpp:60
BlockMask::WALL
@ WALL
Definition: blockmask.h:30
spriteaction.h
BlockMask
Definition: blockmask.h:26
BeingInfo::mDisplay
SpriteDisplay mDisplay
Definition: beinginfo.h:360
BeingInfo::getMenu
const std::vector< BeingMenuItem > & getMenu() const A_CONST
Definition: beinginfo.cpp:258
ItemColor
uint16_t ItemColor
Definition: itemcolor.h:29
spritereference.h
SpriteDisplay
Definition: spritedisplay.h:32
Configuration::getIntValue
int getIntValue(const std::string &key) const
Definition: configuration.cpp:403
TargetCursorSize::LARGE
@ LARGE
Definition: targetcursorsize.h:31
BeingInfo::mAttacks
Attacks mAttacks
Definition: beinginfo.h:365
delete_all
void delete_all(Container &c)
Definition: dtor.h:55
BeingInfo::getAttack
const Attack * getAttack(const int id) const
Definition: beinginfo.cpp:179
EmoteDB::size
int size()
Definition: emotedb.cpp:305
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
TargetCursorSize::MEDIUM
@ MEDIUM
Definition: targetcursorsize.h:30
configuration.h
SpriteAction::ATTACKWATER
static const std::string ATTACKWATER("attackwater")
BeingInfo::addMenu
void addMenu(const std::string &name, const std::string &command)
Definition: beinginfo.cpp:253
BeingInfo::mStrings
std::map< int, std::string > mStrings
Definition: beinginfo.h:367
Attack::mMissEffectId
int mMissEffectId
Definition: attack.h:37
dtor.h
BeingInfo::unknown
static BeingInfo * unknown
Definition: beinginfo.h:55
_
#define _(s)
Definition: gettext.h:34
BeingInfo::getColor
std::string getColor(const ItemColor idx) const
Definition: beinginfo.cpp:241
ColorDB::getColorsList
const std::map< ItemColor, ItemColorData > * getColorsList(const std::string &name)
Definition: colordb.cpp:218
Logger::log
void log(const char *const log_text,...)
Definition: logger.cpp:268
debug.h
Cursor
Definition: cursor.h:26
BeingInfo::getSound
const SoundInfo & getSound(const ItemSoundEvent::Type event) const
Definition: beinginfo.cpp:164