CCreatureHandler.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. int fightValue, AIValue, growth, hordeGrowth, hitPoints, speed, attack, defence, shots, spells;
  16. int low1, low2, high1, high2; //TODO - co to w ogóle jest???
  17. int level; // 0 - unknown
  18. std::string abilityText; //description of abilities
  19. std::string abilityRefs; //references to abilities, in textformat
  20. std::string animDefName;
  21. int idNumber;
  22. int faction; //-1 = neutral
  23. ///animation info
  24. float timeBetweenFidgets, walkAnimationTime, attackAnimationTime, flightAnimationDistance;
  25. int upperRightMissleOffsetX, rightMissleOffsetX, lowerRightMissleOffsetX, upperRightMissleOffsetY, rightMissleOffsetY, lowerRightMissleOffsetY;
  26. float missleFrameAngles[12];
  27. int troopCountLocationOffset, attackClimaxFrame;
  28. ///end of anim info
  29. //for some types of towns
  30. bool isDefinite; //if the creature type is wotn dependent, it should be true
  31. int indefLevel; //only if indefinite
  32. bool indefUpgraded; //onlu if inddefinite
  33. //end
  34. CDefHandler * battleAnimation;
  35. //TODO - zdolnoœci - na typie wyliczeniowym czy czymœ
  36. static int getQuantityID(int quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion
  37. };
  38. class CCreatureSet //seven combined creatures
  39. {
  40. public:
  41. std::map<int,std::pair<CCreature*,int> > slots;
  42. //CCreature * slot1, * slot2, * slot3, * slot4, * slot5, * slot6, * slot7; //types of creatures on each slot
  43. //unsigned int s1, s2, s3, s4, s5, s6, s7; //amounts of units in slots
  44. bool formation; //false - wide, true - tight
  45. };
  46. class CCreatureHandler
  47. {
  48. public:
  49. std::map<int,SDL_Surface*> smallImgs; //creature ID -> small 32x32 img of creature; //ID=-2 is for blank (black) img; -1 for the border
  50. std::map<int,SDL_Surface*> bigImgs; //creature ID -> big 58x64 img of creature; //ID=-2 is for blank (black) img; -1 for the border
  51. std::map<int,SDL_Surface*> backgrounds; //castle ID -> 100x130 background creature image // -1 is for neutral
  52. std::vector<CCreature> creatures;
  53. std::map<int,std::vector<CCreature*> > levelCreatures; //level -> list of creatures
  54. std::map<std::string,int> nameToID;
  55. void loadCreatures();
  56. void loadAnimationInfo();
  57. void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i);
  58. void loadUnitAnimations();
  59. };
  60. class CCreatureAnimation : public CIntObject
  61. {
  62. private:
  63. int totalEntries, DEFType, totalBlocks;
  64. bool allowRepaint;
  65. int length;
  66. BMPPalette palette[256];
  67. unsigned int * RWEntries;
  68. int * RLEntries;
  69. struct SEntry
  70. {
  71. std::string name;
  72. int offset;
  73. int group;
  74. } ;
  75. std::vector<SEntry> SEntries ;
  76. char id[2];
  77. std::string defName, curDir;
  78. int readNormalNr (int pos, int bytCon, unsigned char * str=NULL, bool cyclic=false);
  79. void putPixel(SDL_Surface * dest, const int & ftcp, const BMPPalette & color, const unsigned char & palc, const bool & yellowBorder) const;
  80. ////////////
  81. unsigned char * FDef; //animation raw data
  82. unsigned int curFrame; //number of currently displayed frame
  83. unsigned int frames; //number of frames
  84. int type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1])
  85. public:
  86. int fullWidth, fullHeight; //read-only, please!
  87. CCreatureAnimation(std::string name); //c-tor
  88. ~CCreatureAnimation(); //d-tor //not necessery ATM
  89. void setType(int type); //sets type of animation and cleares framecount
  90. int getType() const; //returns type of animation
  91. int nextFrame(SDL_Surface * dest, int x, int y, bool attacker, bool incrementFrame = true, bool yellowBorder = false); //0 - success, any other - error //print next
  92. int nextFrameMiddle(SDL_Surface * dest, int x, int y, bool attacker, bool incrementFrame = true, bool yellowBorder = false); //0 - success, any other - error //print next
  93. };
  94. #endif //CCREATUREHANDLER_H