Otclient  14/8/2020
creature.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #ifndef CREATURE_H
24 #define CREATURE_H
25 
26 #include "thing.h"
27 #include "outfit.h"
28 #include "tile.h"
29 #include "mapview.h"
32 #include <framework/core/timer.h>
35 
36 // @bindclass
37 class Creature : public Thing
38 {
39 public:
40  enum {
43  };
44 
45  Creature();
46 
47  virtual void draw(const Point& dest, float scaleFactor, bool animate, LightView *lightView = nullptr);
48 
49  void internalDrawOutfit(Point dest, float scaleFactor, bool animateWalk, bool animateIdle, Otc::Direction direction, LightView *lightView = nullptr);
50  void drawOutfit(const Rect& destRect, bool resize);
51  void drawInformation(const Point& point, bool useGray, const Rect& parentRect, int drawFlags);
52 
53  void setId(uint32 id) { m_id = id; }
54  void setName(const std::string& name);
55  void setHealthPercent(uint8 healthPercent);
56  void setDirection(Otc::Direction direction);
57  void setOutfit(const Outfit& outfit);
58  void setOutfitColor(const Color& color, int duration);
59  void setLight(const Light& light) { m_light = light; }
60  void setSpeed(uint16 speed);
61  void setBaseSpeed(double baseSpeed);
62  void setSkull(uint8 skull);
63  void setShield(uint8 shield);
64  void setEmblem(uint8 emblem);
65  void setType(uint8 type);
66  void setIcon(uint8 icon);
67  void setSkullTexture(const std::string& filename);
68  void setShieldTexture(const std::string& filename, bool blink);
69  void setEmblemTexture(const std::string& filename);
70  void setTypeTexture(const std::string& filename);
71  void setIconTexture(const std::string& filename);
72  void setPassable(bool passable) { m_passable = passable; }
73  void setSpeedFormula(double speedA, double speedB, double speedC);
74 
75  void addTimedSquare(uint8 color);
77 
78  void showStaticSquare(const Color& color) { m_showStaticSquare = true; m_staticSquareColor = color; }
80 
81  uint32 getId() { return m_id; }
82  std::string getName() { return m_name; }
85  Outfit getOutfit() { return m_outfit; }
86  Light getLight() { return m_light; }
87  uint16 getSpeed() { return m_speed; }
88  double getBaseSpeed() { return m_baseSpeed; }
89  uint8 getSkull() { return m_skull; }
90  uint8 getShield() { return m_shield; }
91  uint8 getEmblem() { return m_emblem; }
92  uint8 getType() { return m_type; }
93  uint8 getIcon() { return m_icon; }
94  bool isPassable() { return m_passable; }
96  int getStepDuration(bool ignoreDiagonal = false, Otc::Direction dir = Otc::InvalidDirection);
103  double getSpeedFormula(Otc::SpeedFormula formula) { return m_speedFormula[formula]; }
104  bool hasSpeedFormula();
105  std::array<double, Otc::LastSpeedFormula> getSpeedFormulaArray() { return m_speedFormula; }
106  virtual Point getDisplacement();
107  virtual int getDisplacementX();
108  virtual int getDisplacementY();
109  virtual int getExactSize(int layer = 0, int xPattern = 0, int yPattern = 0, int zPattern = 0, int animationPhase = 0);
111 
112  void updateShield();
113 
114  // walk related
115  void turn(Otc::Direction direction);
116  void jump(int height, int duration);
117  virtual void walk(const Position& oldPos, const Position& newPos);
118  virtual void stopWalk();
120 
121  bool isWalking() { return m_walking; }
122  bool isRemoved() { return m_removed; }
124  bool isDead() { return m_healthPercent <= 0; }
125  bool canBeSeen() { return !isInvisible() || isPlayer(); }
126 
127  bool isCreature() { return true; }
128 
129  const ThingTypePtr& getThingType();
131 
132  virtual void onPositionChange(const Position& newPos, const Position& oldPos);
133  virtual void onAppear();
134  virtual void onDisappear();
135  virtual void onDeath();
136 
137 protected:
138  virtual void updateWalkAnimation(int totalPixelsWalked);
139  virtual void updateWalkOffset(int totalPixelsWalked);
140  void updateWalkingTile();
141  virtual void nextWalkUpdate();
142  virtual void updateWalk();
143  virtual void terminateWalk();
144 
145  void updateOutfitColor(Color color, Color finalColor, Color delta, int duration);
146  void updateJump();
147 
149  std::string m_name;
154  int m_speed;
155  double m_baseSpeed;
179 
180  std::array<double, Otc::LastSpeedFormula> m_speedFormula;
181 
182  // walk related
201 
202  // jump related
207 };
208 
209 // @bindclass
210 class Npc : public Creature
211 {
212 public:
213  bool isNpc() { return true; }
214 };
215 
216 // @bindclass
217 class Monster : public Creature
218 {
219 public:
220  bool isMonster() { return true; }
221 };
222 
223 #endif
Creature::m_outfit
Outfit m_outfit
Definition: creature.h:152
Otc::InvalidDirection
@ InvalidDirection
Definition: const.h:170
Creature::m_footStepDrawn
stdext::boolean< false > m_footStepDrawn
Definition: creature.h:191
Creature::isInvisible
bool isInvisible()
Definition: creature.h:123
Creature::getShield
uint8 getShield()
Definition: creature.h:90
Creature::turn
void turn(Otc::Direction direction)
Definition: creature.cpp:325
Creature::terminateWalk
virtual void terminateWalk()
Definition: creature.cpp:604
Creature::setShield
void setShield(uint8 shield)
Definition: creature.cpp:742
Creature::m_jumpHeight
float m_jumpHeight
Definition: creature.h:203
Creature::m_lastStepFromPosition
Position m_lastStepFromPosition
Definition: creature.h:198
Creature::getDrawOffset
Point getDrawOffset()
Definition: creature.cpp:840
Creature::drawOutfit
void drawOutfit(const Rect &destRect, bool resize)
Definition: creature.cpp:196
Creature::getId
uint32 getId()
Definition: creature.h:81
Creature::setEmblemTexture
void setEmblemTexture(const std::string &filename)
Definition: creature.cpp:786
Color
Definition: color.h:32
Creature::m_shield
uint8 m_shield
Definition: creature.h:157
Creature::m_jumpOffset
PointF m_jumpOffset
Definition: creature.h:205
Creature::setId
void setId(uint32 id)
Definition: creature.h:53
Timer::ticksElapsed
ticks_t ticksElapsed()
Definition: timer.cpp:33
Creature::m_disappearEvent
EventPtr m_disappearEvent
Definition: creature.h:194
TRect< int >
Creature::m_timedSquareColor
Color m_timedSquareColor
Definition: creature.h:169
Creature::getEmblem
uint8 getEmblem()
Definition: creature.h:91
Creature::onAppear
virtual void onAppear()
Definition: creature.cpp:431
Creature::getDisplacement
virtual Point getDisplacement()
Definition: creature.cpp:912
Creature::getLight
Light getLight()
Definition: creature.h:86
Monster::isMonster
bool isMonster()
Definition: creature.h:220
uint32
uint32_t uint32
Definition: types.h:35
Creature::setSkullTexture
void setSkullTexture(const std::string &filename)
Definition: creature.cpp:766
Creature::setDirection
void setDirection(Otc::Direction direction)
Definition: creature.cpp:659
Creature::isWalking
bool isWalking()
Definition: creature.h:121
Creature
Definition: creature.h:37
Creature::onDeath
virtual void onDeath()
Definition: creature.cpp:481
CachedText
Definition: cachedtext.h:29
Creature::setIconTexture
void setIconTexture(const std::string &filename)
Definition: creature.cpp:796
Creature::hasSpeedFormula
bool hasSpeedFormula()
Definition: creature.cpp:808
Creature::onPositionChange
virtual void onPositionChange(const Position &newPos, const Position &oldPos)
Definition: creature.cpp:426
Creature::updateWalkingTile
void updateWalkingTile()
Definition: creature.cpp:535
ticks_t
int64 ticks_t
Definition: types.h:43
Creature::m_staticSquareColor
Color m_staticSquareColor
Definition: creature.h:170
Creature::canBeSeen
bool canBeSeen()
Definition: creature.h:125
Creature::m_emblem
uint8 m_emblem
Definition: creature.h:158
Creature::addTimedSquare
void addTimedSquare(uint8 color)
Definition: creature.cpp:814
Creature::getDisplacementX
virtual int getDisplacementX()
Definition: creature.cpp:921
Creature::setLight
void setLight(const Light &light)
Definition: creature.h:59
Creature::m_outfitColorUpdateEvent
ScheduledEventPtr m_outfitColorUpdateEvent
Definition: creature.h:177
Creature::getLastStepToPosition
Position getLastStepToPosition()
Definition: creature.h:99
Creature::m_type
uint8 m_type
Definition: creature.h:159
Creature::getExactSize
virtual int getExactSize(int layer=0, int xPattern=0, int yPattern=0, int zPattern=0, int animationPhase=0)
Definition: creature.cpp:951
Thing::isPlayer
virtual bool isPlayer()
Definition: thing.h:57
Creature::m_footStep
uint m_footStep
Definition: creature.h:185
Creature::onDisappear
virtual void onDisappear()
Definition: creature.cpp:457
ThingCategoryEffect
@ ThingCategoryEffect
Definition: thingtype.h:45
cachedtext.h
Creature::m_baseSpeed
double m_baseSpeed
Definition: creature.h:155
stdext::boolean< true >
Creature::getDisplacementY
virtual int getDisplacementY()
Definition: creature.cpp:936
Creature::setType
void setType(uint8 type)
Definition: creature.cpp:754
Thing
Definition: thing.h:33
Creature::m_skull
uint8 m_skull
Definition: creature.h:156
Creature::m_informationColor
Color m_informationColor
Definition: creature.h:175
Creature::m_nameCache
CachedText m_nameCache
Definition: creature.h:174
LightView
Definition: lightview.h:37
Creature::setSkull
void setSkull(uint8 skull)
Definition: creature.cpp:736
Creature::getType
uint8 getType()
Definition: creature.h:92
Creature::drawInformation
void drawInformation(const Point &point, bool useGray, const Rect &parentRect, int drawFlags)
Definition: creature.cpp:226
Creature::updateWalk
virtual void updateWalk()
Definition: creature.cpp:586
uint16
uint16_t uint16
Definition: types.h:36
Creature::SHIELD_BLINK_TICKS
@ SHIELD_BLINK_TICKS
Definition: creature.h:41
Creature::m_emblemTexture
TexturePtr m_emblemTexture
Definition: creature.h:163
Otc::SpeedFormula
SpeedFormula
Definition: const.h:468
Creature::getJumpOffset
PointF getJumpOffset()
Definition: creature.h:110
Creature::m_walkAnimationPhase
int m_walkAnimationPhase
Definition: creature.h:183
Otc::Direction
Direction
Definition: const.h:161
Creature::m_oldPosition
Position m_oldPosition
Definition: creature.h:200
Creature::m_lastStepToPosition
Position m_lastStepToPosition
Definition: creature.h:199
Outfit
Definition: outfit.h:29
Creature::setOutfitColor
void setOutfitColor(const Color &color, int duration)
Definition: creature.cpp:683
Monster
Definition: creature.h:217
Creature::m_passable
stdext::boolean< false > m_passable
Definition: creature.h:168
declarations.h
uint
unsigned int uint
Definition: types.h:31
Creature::getName
std::string getName()
Definition: creature.h:82
Creature::nextWalkUpdate
virtual void nextWalkUpdate()
Definition: creature.cpp:567
Creature::updateJump
void updateJump()
Definition: creature.cpp:386
Creature::m_jumpDuration
float m_jumpDuration
Definition: creature.h:204
Creature::getIcon
uint8 getIcon()
Definition: creature.h:93
Creature::getBaseSpeed
double getBaseSpeed()
Definition: creature.h:88
mapview.h
Creature::m_allowAppearWalk
stdext::boolean< false > m_allowAppearWalk
Definition: creature.h:190
Creature::setTypeTexture
void setTypeTexture(const std::string &filename)
Definition: creature.cpp:791
Creature::internalDrawOutfit
void internalDrawOutfit(Point dest, float scaleFactor, bool animateWalk, bool animateIdle, Otc::Direction direction, LightView *lightView=nullptr)
Definition: creature.cpp:105
timer.h
Npc
Definition: creature.h:210
Creature::setIcon
void setIcon(uint8 icon)
Definition: creature.cpp:760
Creature::m_skullTexture
TexturePtr m_skullTexture
Definition: creature.h:161
Creature::m_light
Light m_light
Definition: creature.h:153
Creature::m_walkUpdateEvent
ScheduledEventPtr m_walkUpdateEvent
Definition: creature.h:192
Creature::walk
virtual void walk(const Position &oldPos, const Position &newPos)
Definition: creature.cpp:335
Position
Definition: position.h:33
Creature::setName
void setName(const std::string &name)
Definition: creature.cpp:631
Creature::m_walkOffset
Point m_walkOffset
Definition: creature.h:195
Creature::setSpeed
void setSpeed(uint16 speed)
Definition: creature.cpp:714
Creature::jump
void jump(int height, int duration)
Definition: creature.cpp:374
Creature::m_speedFormula
std::array< double, Otc::LastSpeedFormula > m_speedFormula
Definition: creature.h:180
Creature::removeTimedSquare
void removeTimedSquare()
Definition: creature.h:76
Creature::getSpeed
uint16 getSpeed()
Definition: creature.h:87
Creature::updateOutfitColor
void updateOutfitColor(Color color, Color finalColor, Color delta, int duration)
Definition: creature.cpp:699
Creature::m_iconTexture
TexturePtr m_iconTexture
Definition: creature.h:165
Creature::m_shieldTexture
TexturePtr m_shieldTexture
Definition: creature.h:162
Creature::getSkull
uint8 getSkull()
Definition: creature.h:89
Creature::m_icon
uint8 m_icon
Definition: creature.h:160
Creature::updateWalkOffset
virtual void updateWalkOffset(int totalPixelsWalked)
Definition: creature.cpp:521
Creature::getOutfit
Outfit getOutfit()
Definition: creature.h:85
Creature::setPassable
void setPassable(bool passable)
Definition: creature.h:72
Creature::m_showTimedSquare
stdext::boolean< false > m_showTimedSquare
Definition: creature.h:171
Creature::m_outfitColorTimer
Timer m_outfitColorTimer
Definition: creature.h:178
Creature::setShieldTexture
void setShieldTexture(const std::string &filename, bool blink)
Definition: creature.cpp:771
Creature::m_footTimer
Timer m_footTimer
Definition: creature.h:187
Creature::m_walkTimer
Timer m_walkTimer
Definition: creature.h:186
Creature::getWalkOffset
Point getWalkOffset()
Definition: creature.h:97
ThingType
Definition: thingtype.h:123
Creature::getDirection
Otc::Direction getDirection()
Definition: creature.h:84
Creature::getWalkTicksElapsed
ticks_t getWalkTicksElapsed()
Definition: creature.h:102
Creature::m_removed
stdext::boolean< true > m_removed
Definition: creature.h:173
Creature::getSpeedFormulaArray
std::array< double, Otc::LastSpeedFormula > getSpeedFormulaArray()
Definition: creature.h:105
Creature::m_walkFinishAnimEvent
ScheduledEventPtr m_walkFinishAnimEvent
Definition: creature.h:193
Creature::m_direction
Otc::Direction m_direction
Definition: creature.h:151
Creature::showStaticSquare
void showStaticSquare(const Color &color)
Definition: creature.h:78
outfit.h
Creature::updateWalkAnimation
virtual void updateWalkAnimation(int totalPixelsWalked)
Definition: creature.cpp:486
fontmanager.h
Creature::setSpeedFormula
void setSpeedFormula(double speedA, double speedB, double speedC)
Definition: creature.cpp:801
Creature::m_healthPercent
uint8 m_healthPercent
Definition: creature.h:150
Creature::getSpeedFormula
double getSpeedFormula(Otc::SpeedFormula formula)
Definition: creature.h:103
Npc::isNpc
bool isNpc()
Definition: creature.h:213
Creature::getHealthPercent
uint8 getHealthPercent()
Definition: creature.h:83
Creature::VOLATILE_SQUARE_DURATION
@ VOLATILE_SQUARE_DURATION
Definition: creature.h:42
Creature::m_walkedPixels
int m_walkedPixels
Definition: creature.h:184
Creature::draw
virtual void draw(const Point &dest, float scaleFactor, bool animate, LightView *lightView=nullptr)
Definition: creature.cpp:66
Creature::isDead
bool isDead()
Definition: creature.h:124
Outfit::getAuxId
int getAuxId() const
Definition: outfit.h:54
stdext::shared_object_ptr< ThingType >
Creature::isRemoved
bool isRemoved()
Definition: creature.h:122
Creature::m_walking
stdext::boolean< false > m_walking
Definition: creature.h:189
Creature::stopWalk
virtual void stopWalk()
Definition: creature.cpp:365
Outfit::getCategory
ThingCategory getCategory() const
Definition: outfit.h:61
Light
Definition: thingtype.h:117
Creature::getStepDuration
int getStepDuration(bool ignoreDiagonal=false, Otc::Direction dir=Otc::InvalidDirection)
Definition: creature.cpp:855
Creature::m_lastStepDirection
Otc::Direction m_lastStepDirection
Definition: creature.h:197
Creature::updateShield
void updateShield()
Definition: creature.cpp:826
scheduledevent.h
Timer
Definition: timer.h:28
Creature::m_name
std::string m_name
Definition: creature.h:149
Creature::m_walkTurnDirection
Otc::Direction m_walkTurnDirection
Definition: creature.h:196
Creature::m_walkingTile
TilePtr m_walkingTile
Definition: creature.h:188
Creature::m_outfitColor
Color m_outfitColor
Definition: creature.h:176
Creature::m_showStaticSquare
stdext::boolean< false > m_showStaticSquare
Definition: creature.h:172
Creature::m_typeTexture
TexturePtr m_typeTexture
Definition: creature.h:164
Creature::m_jumpTimer
Timer m_jumpTimer
Definition: creature.h:206
Creature::isPassable
bool isPassable()
Definition: creature.h:94
thing.h
Creature::hideStaticSquare
void hideStaticSquare()
Definition: creature.h:79
Creature::getLastStepFromPosition
Position getLastStepFromPosition()
Definition: creature.h:98
TPoint< int >
Creature::setHealthPercent
void setHealthPercent(uint8 healthPercent)
Definition: creature.cpp:637
Creature::allowAppearWalk
void allowAppearWalk()
Definition: creature.h:119
tile.h
Creature::setBaseSpeed
void setBaseSpeed(double baseSpeed)
Definition: creature.cpp:726
Creature::setOutfit
void setOutfit(const Outfit &outfit)
Definition: creature.cpp:665
Creature::getStepTicksLeft
float getStepTicksLeft()
Definition: creature.h:101
Creature::m_shieldBlink
stdext::boolean< false > m_shieldBlink
Definition: creature.h:167
Creature::Creature
Creature()
Definition: creature.cpp:44
Creature::isCreature
bool isCreature()
Definition: creature.h:127
Creature::setEmblem
void setEmblem(uint8 emblem)
Definition: creature.cpp:748
Creature::rawGetThingType
ThingType * rawGetThingType()
Definition: creature.cpp:978
Creature::getStepProgress
float getStepProgress()
Definition: creature.h:100
Creature::m_speed
int m_speed
Definition: creature.h:154
Creature::m_showShieldTexture
stdext::boolean< true > m_showShieldTexture
Definition: creature.h:166
uint8
uint8_t uint8
Definition: types.h:37
Creature::getThingType
const ThingTypePtr & getThingType()
Definition: creature.cpp:973
Creature::m_id
uint32 m_id
Definition: creature.h:148