1 /*! 2 * \file Creature.h 3 * \brief Creature class 4 * 5 * Copyright (C) 2011-2016 OpenDungeons Team 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 3 of the License, or 10 * (at your option) 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 #ifndef CREATURE_H 22 #define CREATURE_H 23 24 #include "entities/MovableGameEntity.h" 25 26 #include <OgreVector2.h> 27 #include <OgreVector3.h> 28 #include <CEGUI/EventArgs.h> 29 30 #include <memory> 31 #include <string> 32 33 class Building; 34 class Creature; 35 class CreatureAction; 36 class CreatureEffect; 37 class CreatureDefinition; 38 class CreatureOverlayStatus; 39 class CreatureSkill; 40 class GameMap; 41 class ODPacket; 42 class Room; 43 class Weapon; 44 45 enum class CreatureActionType; 46 enum class CreatureMoodLevel; 47 enum class SkillType; 48 49 namespace CEGUI 50 { 51 class Window; 52 } 53 54 namespace Ogre 55 { 56 class ParticleSystem; 57 } 58 59 enum class CreatureSound 60 { 61 Pickup, 62 Drop, 63 Attack, 64 Die, 65 Slap, 66 Dig 67 }; 68 69 class CreatureSkillData 70 { 71 public: CreatureSkillData(const CreatureSkill * skill,uint32_t cooldown,uint32_t warmup)72 CreatureSkillData(const CreatureSkill* skill, uint32_t cooldown, uint32_t warmup) : 73 mSkill(skill), 74 mCooldown(cooldown), 75 mWarmup(warmup) 76 { 77 } 78 79 const CreatureSkill* mSkill; 80 uint32_t mCooldown; 81 uint32_t mWarmup; 82 }; 83 84 //! Class used on server side to link creature effects (spells, slap, ...) with particle effects 85 class CreatureParticuleEffect : public EntityParticleEffect 86 { 87 public: 88 CreatureParticuleEffect(Creature& creature, const std::string& name, const std::string& script, uint32_t nbTurnsEffect, 89 CreatureEffect* effect); 90 91 virtual ~CreatureParticuleEffect(); 92 getEntityParticleEffectType()93 virtual EntityParticleEffectType getEntityParticleEffectType() const override 94 { return EntityParticleEffectType::creature; } 95 96 CreatureEffect* mEffect; 97 Creature& mCreature; 98 }; 99 100 /*! \class Creature Creature.h 101 * \brief Position, status, and AI state for a single game creature. 102 * 103 * The creature class is the place where an individual creature's state is 104 * stored and manipulated. The creature class is also used to store creature 105 * class descriptions, since a class decription is really just a subset of the 106 * overall creature information. This is not really an optimal design and 107 * will probably be refined later but it works fine for now and the code 108 * affected by this change is relatively limited. 109 */ 110 class Creature: public MovableGameEntity 111 { 112 friend class ODClient; 113 public: 114 static const int32_t NB_TURNS_BEFORE_CHECKING_TASK; 115 116 //! \brief Constructor for creatures. It generates an unique name 117 Creature(GameMap* gameMap, const CreatureDefinition* definition, Seat* seat, Ogre::Vector3 position = Ogre::Vector3(0.0f,0.0f,0.0f)); 118 virtual ~Creature(); 119 120 static const uint32_t NB_OVERLAY_HEALTH_VALUES; 121 122 virtual GameEntityType getObjectType() const; 123 124 virtual void addToGameMap(); 125 virtual void removeFromGameMap() override; 126 canDisplayStatsWindow(Seat * seat)127 bool canDisplayStatsWindow(Seat* seat) override 128 { return true; } 129 void createStatsWindow(); 130 void destroyStatsWindow(); 131 bool CloseStatsWindow(const CEGUI::EventArgs& /*e*/); 132 void updateStatsWindow(const std::string& txt); 133 std::string getStatsText(); 134 135 //! \brief Get the level of the object getLevel()136 inline unsigned int getLevel() const 137 { return mLevel; } 138 getHP(Tile * tile)139 inline double getHP(Tile *tile) const override 140 { return mHp; } 141 142 bool isAlive() const; 143 144 //! \brief Gets the maximum HP the creature can have currently getMaxHp()145 inline double getMaxHp() const 146 { return mMaxHP; } 147 148 //! \brief Gets the maximum HP the creature can have currently getHP()149 inline double getHP() const 150 { return mHp; } 151 152 //! \brief Gets the current dig rate getDigRate()153 inline double getDigRate() const 154 { return mDigRate; } 155 156 //! \brief Gets the current claim rate getClaimRate()157 inline double getClaimRate() const 158 { return mClaimRate; } 159 160 //! \brief Gets pointer to the Weapon in left hand getWeaponL()161 inline const Weapon* getWeaponL() const 162 { return mWeaponL; } 163 164 //! \brief Gets pointer to the Weapon in right hand getWeaponR()165 inline const Weapon* getWeaponR() const 166 { return mWeaponR; } 167 168 //! \brief Pointer to the creatures home tile, where its bed is located getHomeTile()169 inline Tile* getHomeTile() const 170 { return mHomeTile; } 171 172 //! \brief Pointer to the creature type specification getDefinition()173 inline const CreatureDefinition* getDefinition() const 174 { return mDefinition; } 175 getMoodValue()176 inline CreatureMoodLevel getMoodValue() const 177 { return mMoodValue; } 178 getNbTurnFurious()179 inline int32_t getNbTurnFurious() const 180 { return mNbTurnFurious; } 181 182 void setPosition(const Ogre::Vector3& v) override; 183 184 //! \brief Gets the move speed on the current tile. 185 virtual double getMoveSpeed() const; 186 187 //! \brief Gets the move speed on the current tile. 188 double getMoveSpeed(Tile* tile) const; 189 190 //! \brief Gets the creature depending the terrain type. getMoveSpeedGround()191 inline double getMoveSpeedGround() const 192 { return mGroundSpeed; } getMoveSpeedWater()193 inline double getMoveSpeedWater() const 194 { return mWaterSpeed; } getMoveSpeedLava()195 inline double getMoveSpeedLava() const 196 { return mLavaSpeed; } 197 getKoTurnCounter()198 inline int32_t getKoTurnCounter() const 199 { return mKoTurnCounter; } 200 201 //! \brief Updates the entity path, movement, and direction, and creature attack time 202 //! \param timeSinceLastFrame the elapsed time since last displayed frame in seconds. 203 virtual void update(Ogre::Real timeSinceLastFrame); 204 205 bool setDestination(Tile* tile); 206 207 //! \brief Picks a destination far away in the visible tiles and goes there 208 //! Returns true if a valid Tile was found. The creature will go there 209 //! Returns false if no reachable Tile was found 210 bool wanderRandomly(const std::string& animationState); 211 212 void setHP(double nHP); 213 214 void heal(double hp); 215 setHomeTile(Tile * ht)216 inline void setHomeTile(Tile* ht) 217 { mHomeTile = ht; } 218 219 //! \brief Set the level of the creature 220 void setLevel(unsigned int level); 221 222 //! \brief Called when the creature dies or is KO to death. triggers death animation, stops 223 //! the creature job and drops what it is carrying 224 void dropCarriedEquipment(); 225 226 /*! \brief The main AI routine which decides what the creature will do and carries out that action. 227 * 228 * The doUpkeep routine is the heart of the Creature AI subsystem. The other, 229 * higher level, functions such as GameMap::doUpkeep() ultimately just call this 230 * function to make the creatures act. 231 * 232 * The function begins in a pre-cognition phase which prepares the creature's 233 * brain state for decision making. This involves generating lists of known 234 * about creatures, either through sight, hearing, keeper knowledge, etc, as 235 * well as some other bookkeeping stuff. 236 * 237 * Next the function enters the cognition phase where the creature's current 238 * state is examined and a decision is made about what to do. The state of the 239 * creature is in the form of a queue, which is really used more like a stack. 240 * If the queue is empty, the 'idle' action is used. It acts as a "last resort" 241 * for when the creature completely runs out of things to do. Other actions such 242 * as 'walkToTile' or 'job' can be pushed to determine the what the creature 243 * will do. Once the action is finished (because the creature is tired or there is 244 * nothing related to do), the action will be popped and the previous one will be 245 * used (if any - idle otherwise). This allows actions to be carried out recursively, 246 * i.e. if a creature is trying to dig a tile and it is not nearby it can begin 247 * walking toward the tile as a new action, and when it arrives at the tile it will 248 * revert to the 'digTile' action. 249 */ 250 void doUpkeep(); 251 252 //! \brief Computes the visible tiles and tags them to know which are visible 253 void computeVisibleTiles(); 254 255 virtual bool isAttackable(Tile* tile, Seat* seat) const; 256 257 double getPhysicalDefense() const; 258 double getMagicalDefense() const; 259 double getElementDefense() const; 260 261 //! \brief Check whether a creature has earned one level. If yes, handle leveling it up 262 void checkLevelUp(); 263 264 //! \brief Updates the lists of tiles within sight radius. 265 //! And the tiles the creature can "see" (removing the ones behind walls). 266 void updateTilesInSight(); 267 268 //! \brief Loops over the visibleTiles and adds all enemy creatures in each tile to a list which it returns. 269 std::vector<GameEntity*> getVisibleEnemyObjects(); 270 271 //! \brief Loops over objectsToCheck and returns a vector containing all the ones which can be reached via a valid path. 272 std::vector<GameEntity*> getReachableAttackableObjects(const std::vector<GameEntity*> &objectsToCheck); 273 274 //! \brief Loops over objectsToCheck and returns a vector containing all the creatures in the list. 275 std::vector<GameEntity*> getCreaturesFromList(const std::vector<GameEntity*> &objectsToCheck, bool workersOnly); 276 277 //! \brief Loops over the visibleTiles and adds all allied creatures in each tile to a list which it returns. 278 std::vector<GameEntity*> getVisibleAlliedObjects(); 279 280 //! \brief Loops over the visibleTiles and returns any creatures in those tiles 281 //! allied with the given seat (or if invert is true, does not allied) 282 std::vector<GameEntity*> getVisibleForce(Seat* seat, bool invert); 283 284 //! \brief Conform: GameEntity functions handling covered tiles 285 std::vector<Tile*> getCoveredTiles(); 286 Tile* getCoveredTile(int index); 287 uint32_t numCoveredTiles() const override; 288 289 //! \brief Conform: AttackableObject - Deducts a given amount of HP from this creature. 290 double takeDamage(GameEntity* attacker, double absoluteDamage, double physicalDamage, double magicalDamage, double elementDamage, 291 Tile *tileTakingDamage, bool ko) override; 292 293 //! \brief Conform: AttackableObject - Adds experience to this creature. 294 void receiveExp(double experience); 295 296 //! \brief performs the given attack on the given target 297 void useAttack(CreatureSkillData& skillData, GameEntity& entityAttack, 298 Tile& tileAttack, bool ko, bool notifyPlayerIfHit); 299 300 //! \brief Returns true if the given action is queued in the action list. False otherwise 301 bool isActionInList(CreatureActionType action) const; 302 303 //! \brief Clears the action queue, except for the Idle action at the end. 304 void clearActionQueue(); 305 306 //! \brief Computes the tiles visible for the creature and sends a message to the clients to mark those tiles. This function 307 //! should be called on server side only 308 void computeVisualDebugEntities(); 309 310 //! \brief Displays a mesh on all of the tiles in the list. This function should be called on client side only 311 void refreshVisualDebugEntities(const std::vector<Tile*>& tiles); 312 313 //! \brief Sends a message to the clients to stop displaying the tiles this creature sees 314 void stopComputeVisualDebugEntities(); 315 316 //! \brief Destroy the meshes created by createVisualDebuggingEntities(). This function should be called on client side only 317 void destroyVisualDebugEntities(); 318 319 //! \brief An accessor to return whether or not the creature has OGRE entities for its visual debugging entities. getHasVisualDebuggingEntities()320 inline bool getHasVisualDebuggingEntities() const 321 { return mHasVisualDebuggingEntities; } 322 getOverlayStatus()323 inline CreatureOverlayStatus* getOverlayStatus() const 324 { return mOverlayStatus; } 325 setOverlayStatus(CreatureOverlayStatus * overlayStatus)326 inline void setOverlayStatus(CreatureOverlayStatus* overlayStatus) 327 { mOverlayStatus = overlayStatus; } 328 329 //! \brief Get the text format of creatures in level files (already spawned at startup). 330 //! \returns A string describing the IO format the creatures need to have in file. 331 static std::string getCreatureStreamFormat(); 332 333 //! \brief Get a creature from a stream 334 static Creature* getCreatureFromStream(GameMap* gameMap, std::istream& is); 335 //! \brief Get a creature from a packet 336 static Creature* getCreatureFromPacket(GameMap* gameMap, ODPacket& is); 337 //! \brief Checks if the creature can be picked up. If yes, this function does the needed 338 //! to prepare for the pickup (removing creature from GameMap, changing states, ...). 339 //! Returns true if the creature can be picked up 340 bool tryPickup(Seat* seat) override; 341 void pickup() override; 342 bool tryDrop(Seat* seat, Tile* tile) override; 343 void drop(const Ogre::Vector3& v) override; 344 bool resizeMeshAfterDrop() override; 345 346 //! \brief sets the speed modifier (coef) 347 void setMoveSpeedModifier(double modifier); 348 void clearMoveSpeedModifier(); 349 350 //! \brief sets the defense modifier 351 void setDefenseModifier(double phy, double mag, double ele); 352 void clearDefenseModifier(); 353 354 //! \brief sets the strength modifier (coef) 355 void setStrengthModifier(double modifier); 356 void clearStrengthModifier(); 357 getAnimationSpeedFactor()358 virtual double getAnimationSpeedFactor() const override 359 { return mSpeedModifier; } 360 jobDone(double val)361 inline void jobDone(double val) 362 { 363 mWakefulness -= val; 364 if(mWakefulness < 0.0) 365 mWakefulness = 0.0; 366 } decreaseJobCooldown()367 inline bool decreaseJobCooldown() 368 { 369 if(mJobCooldown <= 0) 370 return true; 371 372 --mJobCooldown; 373 return false; 374 } 375 void setJobCooldown(int val); 376 foodEaten(double val)377 inline void foodEaten(double val) 378 { 379 mHunger -= val; 380 if(mHunger < 0.0) 381 mHunger = 0.0; 382 } 383 384 //! \brief Tells whether the creature can go through the given tile. 385 bool canGoThroughTile(Tile* tile) const; 386 387 virtual EntityCarryType getEntityCarryType(Creature* carrier); 388 virtual void notifyEntityCarryOn(Creature* carrier); 389 virtual void notifyEntityCarryOff(const Ogre::Vector3& position); 390 391 bool canSlap(Seat* seat); 392 void slap(); 393 394 void fireCreatureSound(CreatureSound sound); 395 396 void itsPayDay(); 397 getVisibleTiles()398 inline const std::vector<Tile*>& getVisibleTiles() const 399 { return mVisibleTiles; } 400 getTilesWithinSightRadius()401 inline const std::vector<Tile*>& getTilesWithinSightRadius() const 402 { return mTilesWithinSightRadius; } 403 getVisibleEnemyObjects()404 inline const std::vector<GameEntity*>& getVisibleEnemyObjects() const 405 { return mVisibleEnemyObjects; } 406 getVisibleAlliedObjects()407 inline const std::vector<GameEntity*>& getVisibleAlliedObjects() const 408 { return mVisibleAlliedObjects; } 409 getReachableAlliedObjects()410 inline const std::vector<GameEntity*>& getReachableAlliedObjects() const 411 { return mReachableAlliedObjects; } 412 getActions()413 inline const std::vector<std::unique_ptr<CreatureAction>>& getActions() const 414 { return mActions; } 415 getWakefulness()416 inline double getWakefulness() const 417 { return mWakefulness; } 418 increaseWakefulness(double value)419 inline void increaseWakefulness(double value) 420 { 421 mWakefulness += value; 422 if(mWakefulness > 100.0) 423 mWakefulness = 100.0; 424 } 425 426 void decreaseWakefulness(double value); 427 getHunger()428 inline double getHunger() const 429 { return mHunger; } 430 getGoldFee()431 inline int32_t getGoldFee() const 432 { return mGoldFee; } 433 decreaseGoldFee(int32_t value)434 void decreaseGoldFee(int32_t value) 435 { 436 mGoldFee -= value; 437 if(mGoldFee < 0) 438 mGoldFee = 0; 439 } 440 getGoldCarried()441 inline int32_t getGoldCarried() const 442 { return mGoldCarried; } 443 resetGoldCarried()444 inline void resetGoldCarried() 445 { mGoldCarried = 0; } 446 addGoldCarried(int32_t gold)447 inline void addGoldCarried(int32_t gold) 448 { mGoldCarried += gold; } 449 getOverlayHealthValue()450 inline uint32_t getOverlayHealthValue() const 451 { return mOverlayHealthValue; } 452 getOverlayMoodValue()453 inline uint32_t getOverlayMoodValue() const 454 { return mOverlayMoodValue; } 455 getNbTurnsWithoutBattle()456 inline int32_t getNbTurnsWithoutBattle() const 457 { return mNbTurnsWithoutBattle; } 458 setNbTurnsWithoutBattle(int32_t nbTurnsWithoutBattle)459 inline void setNbTurnsWithoutBattle(int32_t nbTurnsWithoutBattle) 460 { mNbTurnsWithoutBattle = nbTurnsWithoutBattle; } 461 getCarriedEntity()462 inline GameEntity* getCarriedEntity() const 463 { return mCarriedEntity; } 464 465 void carryEntity(GameEntity* carriedEntity); 466 467 void releaseCarriedEntity(); 468 469 bool hasActionBeenTried(CreatureActionType actionType) const; 470 471 void pushAction(std::unique_ptr<CreatureAction>&& action); 472 void popAction(); 473 474 void fireCreatureRefreshIfNeeded(); 475 476 void fireChatMsgTookFee(int goldTaken); 477 void fireChatMsgLeftDungeon(); 478 void fireChatMsgLeavingDungeon(); 479 void fireChatMsgBecameRogue(); 480 void fireChatMsgUnhappy(); 481 void fireChatMsgFurious(); 482 483 //! \brief Load creature definition according to @mDefinitionString 484 //! This should be called before createMesh. This was formerly in CreateMesh 485 //! but is now split out since this is needed on the server, while the mesh isn't. 486 //! This is normally called by the constructor, but creatures loaded from the map files 487 //! use a different constructor, and this is then called by the gameMap when other details have been loaded. 488 void setupDefinition(GameMap& gameMap, const CreatureDefinition& defaultWorkerCreatureDefinition); 489 490 //! Called on server side to add an effect (spell, slap, ...) to this creature 491 void addCreatureEffect(CreatureEffect* effect); 492 493 //!\brief Returns true if the creature has an active slap effect hasSlapEffect()494 bool hasSlapEffect() const 495 { return mActiveSlapsCount > 0; } 496 addActiveSlapCount()497 void addActiveSlapCount() 498 { ++mActiveSlapsCount; } 499 removeActiveSlapCount()500 void removeActiveSlapCount() 501 { --mActiveSlapsCount; } 502 503 virtual void correctEntityMovePosition(Ogre::Vector3& position) override; 504 505 //! \brief Called on client side and server side. true if the creature is hurt and false 506 //! if at max HP or above 507 bool isHurt() const; 508 509 //! \brief Called on client side and server side. true if the creature is ko and false if not 510 bool isKo() const; 511 bool isKoDeath() const; 512 bool isKoTemp() const; 513 514 //! \brief Called on client side and server side. true if the creature is in prison and false if not 515 bool isInPrison() const; 516 517 //! Checks if the creature current walk path is still valid. This will be called if tiles passability changes (for 518 //! example if a door is closed) 519 void checkWalkPathValid(); 520 521 bool isTired() const; 522 523 bool isHungry() const; 524 525 void resetKoTurns(); 526 527 //! \brief Called when the creature is set in jail by dropping or brought by 528 //! a worker. if prison is nullptr, the creature is freed 529 void setInJail(Room* prison); 530 getSeatPrison()531 inline Seat* getSeatPrison() const 532 { return mSeatPrison; } 533 isInContainment()534 inline bool isInContainment() const 535 { return (mSeatPrison != nullptr); } 536 getNbTurnsTorture()537 inline int32_t getNbTurnsTorture() const 538 { return mNbTurnsTorture; } 539 increaseTurnsTorture()540 inline void increaseTurnsTorture() 541 { ++mNbTurnsTorture; } 542 getNbTurnsPrison()543 inline int32_t getNbTurnsPrison() const 544 { return mNbTurnsPrison; } 545 increaseTurnsPrison()546 inline void increaseTurnsPrison() 547 { ++mNbTurnsPrison; } 548 549 virtual bool isDangerous(const Creature* creature, int distance) const override; 550 551 virtual void clientUpkeep() override; 552 553 virtual void exportToPacketForUpdate(ODPacket& os, const Seat* seat) const override; 554 virtual void updateFromPacket(ODPacket& is) override; 555 556 //! \brief Called when an angry creature wants to attack a natural enemy 557 void engageAlliedNaturalEnemy(Creature& attacker); 558 getModifierStrength()559 inline double getModifierStrength() const 560 { return mModifierStrength; } 561 562 void fight(); 563 564 void fightCreature(Creature& creature, bool ko, bool notifyPlayerIfHit); 565 566 void flee(); 567 568 void sleep(); 569 570 void leaveDungeon(); 571 572 bool isWarmup() const; 573 574 void computeCreatureOverlayHealthValue(); 575 576 //! \brief Search within listObjects the closest attackable one. 577 //! If a target is found and can be attacked, returns true and 578 //! attackedEntity, attackedTile will be set to the target closest tile and positionTile will 579 //! be set to the best spot. 580 //! If the creature should flee (ranged units attacked by melee), true is returned, positionTile is 581 //! set to the tile where it should flee and attackedEntity = nullptr and attackedTile = nullptr 582 //! If tilesFilter is empty, the creature will consider moving on visible tiles. If not, it will consider 583 //! moving on the given tiles only 584 //! If no suitable target is found, returns false 585 bool searchBestTargetInList(const std::vector<GameEntity*>& listObjects, const std::vector<Tile*>& tilesFilter, GameEntity*& attackedEntity, 586 Tile*& attackedTile, Tile*& positionTile, CreatureSkillData*& creatureSkillData); 587 588 //! \brief returns true if the creature needs to eat. forced should be true if 589 //! the creature is forced to eat (ie it has been dropped on a hatchery) and 590 //! false otherwise 591 bool needsToEat(bool forced) const; 592 593 //! \brief Called when the creature changes seat (for example when it becomes rogue or after torture) 594 void changeSeat(Seat* newSeat); 595 596 protected: 597 virtual void exportToPacket(ODPacket& os, const Seat* seat) const override; 598 virtual void importFromPacket(ODPacket& is) override; 599 virtual void exportToStream(std::ostream& os) const override; 600 virtual bool importFromStream(std::istream& is) override; 601 602 virtual void createMeshLocal(); 603 virtual void destroyMeshLocal(); 604 virtual void fireAddEntity(Seat* seat, bool async); 605 virtual void fireRemoveEntity(Seat* seat); 606 private: 607 enum ForceAction 608 { 609 forcedActionNone, 610 forcedActionSearchAction, 611 forcedActionDigTile, 612 forcedActionClaimTile, 613 forcedActionClaimWallTile 614 }; 615 616 void createMeshWeapons(); 617 void destroyMeshWeapons(); 618 619 //! \brief Constructor for sending creatures through network. It should not be used in game. 620 Creature(GameMap* gameMap); 621 622 //! \brief Natural physical and magical attack and defense (without equipment) 623 double mPhysicalDefense; 624 double mMagicalDefense; 625 double mElementDefense; 626 627 //! \brief Strength modifiers (can be changed by effects like spells) 628 double mModifierStrength; 629 630 //! \brief The weapon the creature is holding in its left hand or nullptr if none. It will be set by a pointer 631 //! managed by the game map and thus, should not be deleted by the creature class 632 const Weapon* mWeaponL; 633 634 //! \brief The weapon the creature is holding in its right hand or nullptr if none. It will be set by a pointer 635 //! managed by the game map and thus, should not be deleted by the creature class 636 const Weapon* mWeaponR; 637 638 //! \brief The creatures home tile (where its bed is located) 639 Tile *mHomeTile; 640 641 //! Class name of the creature. The CreatureDefinition will be set from this name 642 //! when the creature will be initialized 643 std::string mDefinitionString; 644 //! \brief Pointer to the struct holding the general type of the creature with its values 645 const CreatureDefinition* mDefinition; 646 647 bool mHasVisualDebuggingEntities; 648 double mWakefulness; 649 double mHunger; 650 651 //! \brief The level of the creature 652 unsigned int mLevel; 653 654 //! \brief The creature stats 655 std::string mHpString; 656 double mHp; 657 double mMaxHP; 658 double mExp; 659 double mGroundSpeed; 660 double mWaterSpeed; 661 double mLavaSpeed; 662 663 //! \brief Workers only 664 double mDigRate; 665 double mClaimRate; 666 667 //! \brief Counter to let the creature stay some turns after its death 668 unsigned int mDeathCounter; 669 int mJobCooldown; 670 671 //! \brief At pay day, mGoldFee will be set to the creature fee and decreased when the creature gets gold 672 int32_t mGoldFee; 673 //! \brief Gold carried by the creature that will be dropped if it gets killed 674 int32_t mGoldCarried; 675 676 //! Skill type that will be dropped when the creature dies 677 SkillType mSkillTypeDropDeath; 678 679 //! Weapon that will be dropped when the creature dies 680 std::string mWeaponDropDeath; 681 682 CEGUI::Window* mStatsWindow; 683 int32_t mNbTurnsWithoutBattle; 684 685 //! \brief Every tiles within the creature sight radius, used for common actions. 686 std::vector<Tile*> mTilesWithinSightRadius; 687 688 //! \brief Only visible tiles, not hidden for other tiles, 689 //! used for actions linked to enemies. 690 std::vector<Tile*> mVisibleTiles; 691 692 std::vector<GameEntity*> mVisibleEnemyObjects; 693 std::vector<GameEntity*> mVisibleAlliedObjects; 694 std::vector<GameEntity*> mReachableAlliedObjects; 695 std::vector<std::unique_ptr<CreatureAction>> mActions; 696 std::vector<Tile*> mVisualDebugEntityTiles; 697 698 //! \brief Contains the actions that have already been tested to avoid trying several times same action 699 std::vector<CreatureActionType> mActionTry; 700 701 GameEntity* mCarriedEntity; 702 703 //! \brief The mood do not have to be computed at every turn. This cooldown will 704 //! count how many turns the creature should wait before computing it 705 int32_t mMoodCooldownTurns; 706 707 //! \brief Mood value. Depending on this value, the creature will be in bad mood and 708 //! might attack allied creatures or refuse to work or to go to combat 709 CreatureMoodLevel mMoodValue; 710 //! \brief Mood points. Computed by the creature MoodModifiers. It is promoted to class variable for debug purposes and 711 //! should not be used to check mood. If the mood is to be tested, mMoodValue should be used 712 int32_t mMoodPoints; 713 714 //! \brief Counts turns the creature is furious. If it stays like this for too long, it will become rogue 715 int32_t mNbTurnFurious; 716 717 //! \brief Represents the life value displayed on client side. We do not notify each HP change 718 //! to avoid too many communication. But when mOverlayHealthValue changes, we will 719 uint32_t mOverlayHealthValue; 720 721 //! \brief Represents the mood of the creature. It is a bit array 722 uint32_t mOverlayMoodValue; 723 724 //! Used by the renderer to save this entity's overlay. It is its responsibility 725 //! to allocate/delete this pointer 726 CreatureOverlayStatus* mOverlayStatus; 727 728 //! Used on server side to indicate if a change that needs to be notified to the clients happened (like changing 729 //! level or HP) 730 bool mNeedFireRefresh; 731 732 //! \brief Used on client side. When a creature is dropped, this cooldown will be set to a value > 0 733 //! and decreased at each turn. Until it is > 0, the creature cannot be slapped. That's to avoid 734 //! slapping creatures to death when dropping many. 735 //! Note that this is done on client side and not checked on server side because it is just to be 736 //! player friendly 737 uint32_t mDropCooldown; 738 739 //! \brief Speed modifier that will apply to both animation speed and move speed. If 740 //! 1.0, it will be default speed 741 double mSpeedModifier; 742 743 //! \brief Counter when the creature is KO. If = 0, the creature is not KO. 744 //! If > 0, the creature is temporary KO (after being drooped for example). Each 745 //! turn, the counter will decrease and the creature will wake up when the counter 746 //! reaches 0. 747 //! If < 0, the creature is KO to death. The counter will increase each turn and 748 //! if it reaches 0, the creature will die. 749 //! While KO to death, if a kobold carries the creature to its bed, the counter will 750 //! stop during the travel (and reset to 0 when the creature is dropped in its bed). 751 int32_t mKoTurnCounter; 752 753 //! \brief If nullptr, the creature is not in prison. If not, it is in the prison of 754 //! the given seat 755 Seat* mSeatPrison; 756 757 //! \brief allows to know how many turns a creature has been tortured 758 int32_t mNbTurnsTorture; 759 760 //! \brief allows to know how many turns a creature has been in prison 761 int32_t mNbTurnsPrison; 762 763 //! \brief Counts the number of active slaps affecting the creature 764 uint32_t mActiveSlapsCount; 765 766 //! \brief Skills the creature can use 767 std::vector<CreatureSkillData> mSkillData; 768 769 //! \brief A sub-function called by doTurn() 770 //! This one checks if there is something prioritary to do (like fighting). If it is the case, 771 //! it should empty the action list before adding what to do. 772 void decidePrioritaryAction(); 773 774 //! \brief A sub-function called by doTurn() 775 //! This functions will handle the creature idle action logic. 776 //! \return true when another action should handled after that one. 777 bool handleIdleAction(); 778 779 //! \brief Restores the creature's stats according to its current level 780 void buildStats(); 781 782 void increaseHunger(double value); 783 784 void computeMood(); 785 786 void computeCreatureOverlayMoodValue(); 787 }; 788 789 #endif // CREATURE_H 790