CCreatureHandler.h 3.4 KB

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