CCreatureHandler.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 "CSoundBase.h"
  9. /*
  10. * CCreatureHandler.h, part of VCMI engine
  11. *
  12. * Authors: listed in file AUTHORS in main folder
  13. *
  14. * License: GNU General Public License v2.0 or later
  15. * Full text of license available in license.txt file, in main folder
  16. *
  17. */
  18. class CLodHandler;
  19. class DLL_EXPORT CCreature
  20. {
  21. public:
  22. std::string namePl, nameSing, nameRef; //name in singular and plural form; and reference name
  23. std::vector<ui32> cost; //cost[res_id] - amount of that resource
  24. std::set<ui32> upgrades; // IDs of creatures to which this creature can be upgraded
  25. ui32 fightValue, AIValue, growth, hordeGrowth, hitPoints, speed, attack, defence, shots, spells;
  26. ui32 damageMin, damageMax;
  27. ui32 ammMin, ammMax;
  28. ui8 level; // 0 - unknown
  29. std::string abilityText; //description of abilities
  30. std::string abilityRefs; //references to abilities, in textformat
  31. std::string animDefName;
  32. ui32 idNumber;
  33. std::set<EAbilities> abilities;
  34. si8 faction; //-1 = neutral
  35. ///animation info
  36. float timeBetweenFidgets, walkAnimationTime, attackAnimationTime, flightAnimationDistance;
  37. int upperRightMissleOffsetX, rightMissleOffsetX, lowerRightMissleOffsetX, upperRightMissleOffsetY, rightMissleOffsetY, lowerRightMissleOffsetY;
  38. float missleFrameAngles[12];
  39. int troopCountLocationOffset, attackClimaxFrame;
  40. ///end of anim info
  41. // Sound infos
  42. struct {
  43. soundBase::soundID attack;
  44. soundBase::soundID defend;
  45. soundBase::soundID killed; // was killed died
  46. soundBase::soundID move;
  47. soundBase::soundID shoot; // range attack
  48. soundBase::soundID wince; // attacked but did not die
  49. soundBase::soundID ext1; // creature specific extension
  50. soundBase::soundID ext2; // creature specific extension
  51. soundBase::soundID startMoving; // usually same as ext1
  52. soundBase::soundID endMoving; // usually same as ext2
  53. } sounds;
  54. bool isDoubleWide() const; //returns true if unit is double wide on battlefield
  55. bool isFlying() const; //returns true if it is a flying unit
  56. bool isShooting() const; //returns true if unit can shoot
  57. bool isUndead() const; //returns true if unit is undead
  58. si32 maxAmount(const std::vector<si32> &res) const; //how many creatures can be bought
  59. 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
  60. template <typename Handler> void serialize(Handler &h, const int version)
  61. {
  62. h & namePl & nameSing & nameRef
  63. & cost & upgrades
  64. & fightValue & AIValue & growth & hordeGrowth & hitPoints & speed & attack & defence & shots & spells
  65. & damageMin & damageMax & ammMin & ammMax & level
  66. & abilityText & abilityRefs & animDefName
  67. & idNumber & abilities & faction
  68. & timeBetweenFidgets & walkAnimationTime & attackAnimationTime & flightAnimationDistance
  69. & upperRightMissleOffsetX & rightMissleOffsetX & lowerRightMissleOffsetX & upperRightMissleOffsetY & rightMissleOffsetY & lowerRightMissleOffsetY
  70. & missleFrameAngles & troopCountLocationOffset & attackClimaxFrame;
  71. }
  72. };
  73. class DLL_EXPORT CCreatureHandler
  74. {
  75. public:
  76. std::set<int> notUsedMonsters;
  77. std::vector<CCreature> creatures; //creature ID -> creature info
  78. std::map<int,std::vector<CCreature*> > levelCreatures; //level -> list of creatures
  79. std::map<std::string,int> nameToID;
  80. std::map<int,std::string> idToProjectile;
  81. std::map<int,bool> idToProjectileSpin; //if true, appropriate projectile is spinning during flight
  82. void loadCreatures();
  83. void loadAnimationInfo();
  84. void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i);
  85. CCreatureHandler();
  86. ~CCreatureHandler();
  87. template <typename Handler> void serialize(Handler &h, const int version)
  88. {
  89. //TODO: should be optimized, not all these informations needs to be serialized (same for ccreature)
  90. h & notUsedMonsters & creatures & nameToID & idToProjectile & idToProjectileSpin;
  91. if(!h.saving)
  92. {
  93. for (int i=0; i<creatures.size(); i++) //recreate levelCreatures map
  94. {
  95. levelCreatures[creatures[i].level].push_back(&creatures[i]);
  96. }
  97. }
  98. }
  99. };
  100. #endif // __CCREATUREHANDLER_H__