CCreatureAnimation.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef __CCREATUREANIMATION_H__
  2. #define __CCREATUREANIMATION_H__
  3. #include "../global.h"
  4. #include "CDefHandler.h"
  5. #include "GUIBase.h"
  6. #include "../client/CBitmapHandler.h"
  7. #include "CAnimation.h"
  8. /*
  9. * CCreatureAnimation.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. struct BMPPalette;
  18. /// Class which manages animations of creatures/units inside battles
  19. class CCreatureAnimation : public CIntObject
  20. {
  21. private:
  22. int totalEntries, DEFType, totalBlocks;
  23. int length;
  24. BMPPalette palette[256];
  25. struct SEntry
  26. {
  27. int offset;
  28. int group;
  29. } ;
  30. std::vector<SEntry> SEntries ;
  31. std::string defName, curDir;
  32. template< int bytCon > static int readNormalNr (int pos, unsigned char * str)
  33. {
  34. int ret=0;
  35. int amp=1;
  36. for (int i=0; i<bytCon; i++)
  37. {
  38. ret+=str[pos+i]*amp;
  39. amp<<=8; //amp*=256;
  40. }
  41. return ret;
  42. }
  43. template<int bpp>
  44. void putPixel(
  45. SDL_Surface * dest,
  46. const int & ftcpX,
  47. const int & ftcpY,
  48. const BMPPalette & color,
  49. const unsigned char & palc,
  50. const bool & yellowBorder,
  51. const bool & blueBorder,
  52. const unsigned char & animCount
  53. ) const;
  54. ////////////
  55. unsigned char * FDef; //animation raw data
  56. int curFrame, internalFrame; //number of currently displayed frame
  57. unsigned int frames; //number of frames
  58. CCreatureAnim::EAnimType type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1])
  59. template<int bpp>
  60. int nextFrameT(SDL_Surface * dest, int x, int y, bool attacker, unsigned char animCount, bool incrementFrame = true, bool yellowBorder = false, bool blueBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next
  61. int nextFrameMiddle(SDL_Surface * dest, int x, int y, bool attacker, unsigned char animCount, bool IncrementFrame = true, bool yellowBorder = false, bool blueBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next
  62. std::map<int, std::vector<int> > frameGroups; //groups of frames; [groupID] -> vector of frame IDs in group
  63. bool once;
  64. public:
  65. int fullWidth, fullHeight; //read-only, please!
  66. CCreatureAnimation(std::string name); //c-tor
  67. ~CCreatureAnimation(); //d-tor
  68. void setType(CCreatureAnim::EAnimType type); //sets type of animation and cleares framecount
  69. CCreatureAnim::EAnimType getType() const; //returns type of animation
  70. int nextFrame(SDL_Surface * dest, int x, int y, bool attacker, unsigned char animCount, bool incrementFrame = true, bool yellowBorder = false, bool blueBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next
  71. void incrementFrame();
  72. int getFrame() const; // Gets the current frame ID relative to DEF file.
  73. int getAnimationFrame() const; // Gets the current frame ID relative to frame group.
  74. bool onFirstFrameInGroup();
  75. bool onLastFrameInGroup();
  76. void playOnce(CCreatureAnim::EAnimType type); //plays once given stage of animation, then resets to 2
  77. int framesInGroup(CCreatureAnim::EAnimType group) const; //retirns number of fromes in given group
  78. };
  79. #endif // __CCREATUREANIMATION_H__