CCreatureHandler.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #ifndef __CCREATUREHANDLER_H__
  2. #define __CCREATUREHANDLER_H__
  3. #include "../global.h"
  4. #include <string>
  5. #include <vector>
  6. #include <map>
  7. #include <set>
  8. #include "../lib/HeroBonus.h"
  9. #include "../lib/CGameState.h"
  10. #include "../lib/CCreatureSet.h"
  11. #include "../lib/ConstTransitivePtr.h"
  12. /*
  13. * CCreatureHandler.h, part of VCMI engine
  14. *
  15. * Authors: listed in file AUTHORS in main folder
  16. *
  17. * License: GNU General Public License v2.0 or later
  18. * Full text of license available in license.txt file, in main folder
  19. *
  20. */
  21. #define ALLCREATURESGETDOUBLEMONTHS false
  22. class CLodHandler;
  23. class CCreatureHandler;
  24. class CCreature;
  25. class DLL_EXPORT CCreature : public CBonusSystemNode
  26. {
  27. public:
  28. std::string namePl, nameSing, nameRef; //name in singular and plural form; and reference name
  29. std::vector<ui32> cost; //cost[res_id] - amount of that resource
  30. std::set<ui32> upgrades; // IDs of creatures to which this creature can be upgraded
  31. ui32 hitPoints, speed, attack, defence;
  32. ui32 fightValue, AIValue, growth, hordeGrowth, shots, spells;
  33. ui32 damageMin, damageMax;
  34. ui32 ammMin, ammMax;
  35. ui8 level; // 0 - unknown
  36. std::string abilityText; //description of abilities
  37. std::string abilityRefs; //references to abilities, in textformat
  38. std::string animDefName;
  39. si32 idNumber;
  40. si8 faction; //-1 = neutral
  41. ui8 doubleWide;
  42. ///animation info
  43. float timeBetweenFidgets, walkAnimationTime, attackAnimationTime, flightAnimationDistance;
  44. int upperRightMissleOffsetX, rightMissleOffsetX, lowerRightMissleOffsetX, upperRightMissleOffsetY, rightMissleOffsetY, lowerRightMissleOffsetY;
  45. float missleFrameAngles[12];
  46. int troopCountLocationOffset, attackClimaxFrame;
  47. ///end of anim info
  48. bool isDoubleWide() const; //returns true if unit is double wide on battlefield
  49. bool isFlying() const; //returns true if it is a flying unit
  50. bool isShooting() const; //returns true if unit can shoot
  51. bool isUndead() const; //returns true if unit is undead
  52. bool isGood () const;
  53. bool isEvil () const;
  54. si32 maxAmount(const std::vector<si32> &res) const; //how many creatures can be bought
  55. static int getQuantityID(const int & quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion
  56. bool isMyUpgrade(const CCreature *anotherCre) const;
  57. bool valid() const;
  58. void addBonus(int val, int type, int subtype = -1);
  59. //void getParents(TCNodes &out, const CBonusSystemNode *root /*= NULL*/) const;
  60. template<typename RanGen>
  61. int getRandomAmount(RanGen &ranGen)
  62. {
  63. if(ammMax == ammMin)
  64. return ammMax;
  65. else
  66. return ammMin + (ranGen() % (ammMax - ammMin));
  67. }
  68. template <typename Handler> void serialize(Handler &h, const int version)
  69. {
  70. h & static_cast<CBonusSystemNode&>(*this);
  71. h & namePl & nameSing & nameRef
  72. & cost & upgrades
  73. & fightValue & AIValue & growth & hordeGrowth & hitPoints & speed & attack & defence & shots & spells
  74. & damageMin & damageMax & ammMin & ammMax & level
  75. & abilityText & abilityRefs & animDefName
  76. & idNumber & faction
  77. & timeBetweenFidgets & walkAnimationTime & attackAnimationTime & flightAnimationDistance
  78. & upperRightMissleOffsetX & rightMissleOffsetX & lowerRightMissleOffsetX & upperRightMissleOffsetY & rightMissleOffsetY & lowerRightMissleOffsetY
  79. & missleFrameAngles & troopCountLocationOffset & attackClimaxFrame;
  80. h & doubleWide;
  81. }
  82. CCreature();
  83. friend class CCreatureHandler;
  84. };
  85. class DLL_EXPORT CCreatureHandler
  86. {
  87. public:
  88. CBonusSystemNode *globalEffects;
  89. std::set<int> notUsedMonsters;
  90. std::set<TCreature> doubledCreatures; //they get double week
  91. std::vector<ConstTransitivePtr<CCreature> > creatures; //creature ID -> creature info
  92. bmap<int,std::vector<ConstTransitivePtr< CCreature> > > levelCreatures; //level -> list of creatures
  93. bmap<std::string,int> nameToID;
  94. bmap<int,std::string> idToProjectile;
  95. bmap<int,bool> idToProjectileSpin; //if true, appropriate projectile is spinning during flight
  96. std::vector<si8> factionAlignments; //1 for good, 0 for neutral and -1 for evil with faction ID as index
  97. int factionToTurretCreature[F_NUMBER]; //which creature's animation should be used to dispaly creature in turret while siege
  98. void loadCreatures();
  99. void loadAnimationInfo();
  100. void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i);
  101. bool isGood (si8 faction) const;
  102. bool isEvil (si8 faction) const;
  103. int pickRandomMonster(const boost::function<int()> &randGen = 0) const;
  104. CCreatureHandler();
  105. ~CCreatureHandler();
  106. template <typename Handler> void serialize(Handler &h, const int version)
  107. {
  108. //TODO: should be optimized, not all these informations needs to be serialized (same for ccreature)
  109. h & notUsedMonsters & creatures & nameToID & idToProjectile & idToProjectileSpin & factionToTurretCreature;
  110. h & levelCreatures & globalEffects;
  111. }
  112. };
  113. #endif // __CCREATUREHANDLER_H__