CCreatureHandler.h 3.7 KB

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