CCreatureHandler.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #ifndef CCREATUREHANDLER_H
  2. #define CCREATUREHANDLER_H
  3. #include "../CPlayerInterface.h"
  4. #include <string>
  5. #include <vector>
  6. #include <map>
  7. #include "CDefHandler.h"
  8. class CDefHandler;
  9. struct SDL_Surface;
  10. class CCreature
  11. {
  12. public:
  13. std::string namePl, nameSing, nameRef; //name in singular and plural form; and reference name
  14. std::vector<int> cost; //cost[res_id] - amount of that resource
  15. std::set<int> upgrades; // IDs of creatures to which this creature can be upgraded
  16. int fightValue, AIValue, growth, hordeGrowth, hitPoints, speed, attack, defence, shots, spells;
  17. int damageMin, damageMax;
  18. int ammMin, ammMax;
  19. int level; // 0 - unknown
  20. std::string abilityText; //description of abilities
  21. std::string abilityRefs; //references to abilities, in textformat
  22. std::string animDefName;
  23. int idNumber;
  24. int faction; //-1 = neutral
  25. ///animation info
  26. float timeBetweenFidgets, walkAnimationTime, attackAnimationTime, flightAnimationDistance;
  27. int upperRightMissleOffsetX, rightMissleOffsetX, lowerRightMissleOffsetX, upperRightMissleOffsetY, rightMissleOffsetY, lowerRightMissleOffsetY;
  28. float missleFrameAngles[12];
  29. int troopCountLocationOffset, attackClimaxFrame;
  30. ///end of anim info
  31. //for some types of towns
  32. bool isDefinite; //if the creature type is wotn dependent, it should be true
  33. int indefLevel; //only if indefinite
  34. bool indefUpgraded; //onlu if inddefinite
  35. //end
  36. //CDefHandler * battleAnimation;
  37. //TODO - zdolnoœci - na typie wyliczeniowym czy czymœ
  38. static int getQuantityID(int quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion
  39. bool isDoubleWide(); //returns true if unit is double wide on battlefield
  40. bool isFlying(); //returns true if it is a flying unit
  41. bool isShooting(); //returns true if unit can shoot
  42. int maxAmount(const std::vector<int> &res) const; //how many creatures can be bought
  43. };
  44. class CCreatureSet //seven combined creatures
  45. {
  46. public:
  47. std::map<int,std::pair<CCreature*,int> > slots;
  48. //CCreature * slot1, * slot2, * slot3, * slot4, * slot5, * slot6, * slot7; //types of creatures on each slot
  49. //unsigned int s1, s2, s3, s4, s5, s6, s7; //amounts of units in slots
  50. bool formation; //false - wide, true - tight
  51. };
  52. class CCreatureHandler
  53. {
  54. public:
  55. std::map<int,SDL_Surface*> smallImgs; //creature ID -> small 32x32 img of creature; //ID=-2 is for blank (black) img; -1 for the border
  56. std::map<int,SDL_Surface*> bigImgs; //creature ID -> big 58x64 img of creature; //ID=-2 is for blank (black) img; -1 for the border
  57. std::map<int,SDL_Surface*> backgrounds; //castle ID -> 100x130 background creature image // -1 is for neutral
  58. std::vector<CCreature> creatures; //creature ID -> creature info
  59. std::map<int,std::vector<CCreature*> > levelCreatures; //level -> list of creatures
  60. std::map<std::string,int> nameToID;
  61. std::map<int,std::string> idToProjectile;
  62. std::map<int,bool> idToProjectileSpin; //if true, appropriate projectile is spinning during flight
  63. void loadCreatures();
  64. void loadAnimationInfo();
  65. void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i);
  66. void loadUnitAnimations();
  67. };
  68. class CCreatureAnimation : public CIntObject
  69. {
  70. private:
  71. int totalEntries, DEFType, totalBlocks;
  72. bool allowRepaint;
  73. int length;
  74. BMPPalette palette[256];
  75. unsigned int * RWEntries;
  76. int * RLEntries;
  77. struct SEntry
  78. {
  79. std::string name;
  80. int offset;
  81. int group;
  82. } ;
  83. std::vector<SEntry> SEntries ;
  84. char id[2];
  85. std::string defName, curDir;
  86. int readNormalNr (int pos, int bytCon, unsigned char * str=NULL, bool cyclic=false);
  87. void putPixel(SDL_Surface * dest, const int & ftcp, const BMPPalette & color, const unsigned char & palc, const bool & yellowBorder) const;
  88. ////////////
  89. unsigned char * FDef; //animation raw data
  90. unsigned int curFrame; //number of currently displayed frame
  91. unsigned int frames; //number of frames
  92. int type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1])
  93. public:
  94. int fullWidth, fullHeight; //read-only, please!
  95. CCreatureAnimation(std::string name); //c-tor
  96. ~CCreatureAnimation(); //d-tor
  97. void setType(int type); //sets type of animation and cleares framecount
  98. int getType() const; //returns type of animation
  99. int nextFrame(SDL_Surface * dest, int x, int y, bool attacker, bool incrementFrame = true, bool yellowBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next
  100. int nextFrameMiddle(SDL_Surface * dest, int x, int y, bool attacker, bool incrementFrame = true, bool yellowBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next
  101. int framesInGroup(int group) const; //retirns number of fromes in given group
  102. };
  103. #endif //CCREATUREHANDLER_H