2011-12-14 00:23:17 +03:00
# pragma once
2009-04-16 14:14:13 +03:00
2011-12-17 21:59:59 +03:00
# include "../CDefHandler.h"
# include "../../client/CBitmapHandler.h"
# include "../CAnimation.h"
2009-04-16 14:14:13 +03:00
2009-04-15 17:03:31 +03:00
/*
* CCreatureAnimation . h , part of VCMI engine
*
* Authors : listed in file AUTHORS in main folder
*
* License : GNU General Public License v2 .0 or later
* Full text of license available in license . txt file , in main folder
*
2009-04-16 14:14:13 +03:00
*/
2010-08-17 17:58:13 +03:00
struct BMPPalette ;
2011-12-17 21:59:59 +03:00
class CIntObject ;
2010-08-17 17:58:13 +03:00
2011-02-22 13:52:36 +02:00
/// Class which manages animations of creatures/units inside battles
2009-04-16 14:14:13 +03:00
class CCreatureAnimation : public CIntObject
{
private :
int totalEntries , DEFType , totalBlocks ;
BMPPalette palette [ 256 ] ;
struct SEntry
{
int offset ;
int group ;
} ;
std : : vector < SEntry > SEntries ;
std : : string defName , curDir ;
2010-02-12 17:04:01 +02:00
2010-08-12 08:22:48 +03:00
template < int bpp >
2009-04-16 14:14:13 +03:00
void putPixel (
SDL_Surface * dest ,
2011-02-06 19:26:27 +02:00
const int & ftcpX ,
const int & ftcpY ,
2009-04-16 14:14:13 +03:00
const BMPPalette & color ,
2011-12-14 00:23:17 +03:00
const ui8 & palc ,
2009-04-16 14:14:13 +03:00
const bool & yellowBorder ,
const bool & blueBorder ,
2011-12-14 00:23:17 +03:00
const ui8 & animCount
2009-04-16 14:14:13 +03:00
) const ;
////////////
2011-12-14 00:23:17 +03:00
ui8 * FDef ; //animation raw data
2009-04-16 14:14:13 +03:00
int curFrame , internalFrame ; //number of currently displayed frame
2011-12-14 00:23:17 +03:00
ui32 frames ; //number of frames
2011-02-09 15:56:30 +02:00
CCreatureAnim : : EAnimType type ; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1])
2011-03-22 15:19:07 +02:00
template < int bpp >
2011-12-14 00:23:17 +03:00
int nextFrameT ( SDL_Surface * dest , int x , int y , bool attacker , ui8 animCount , bool incrementFrame = true , bool yellowBorder = false , bool blueBorder = false , SDL_Rect * destRect = NULL ) ; //0 - success, any other - error //print next
int nextFrameMiddle ( SDL_Surface * dest , int x , int y , bool attacker , ui8 animCount , bool IncrementFrame = true , bool yellowBorder = false , bool blueBorder = false , SDL_Rect * destRect = NULL ) ; //0 - success, any other - error //print next
2011-03-22 15:19:07 +02:00
2009-04-16 14:14:13 +03:00
std : : map < int , std : : vector < int > > frameGroups ; //groups of frames; [groupID] -> vector of frame IDs in group
2011-03-22 15:19:07 +02:00
bool once ;
public :
2009-04-16 14:14:13 +03:00
int fullWidth , fullHeight ; //read-only, please!
CCreatureAnimation ( std : : string name ) ; //c-tor
~ CCreatureAnimation ( ) ; //d-tor
2011-02-09 15:56:30 +02:00
void setType ( CCreatureAnim : : EAnimType type ) ; //sets type of animation and cleares framecount
CCreatureAnim : : EAnimType getType ( ) const ; //returns type of animation
2009-04-16 14:14:13 +03:00
2011-12-14 00:23:17 +03:00
int nextFrame ( SDL_Surface * dest , int x , int y , bool attacker , ui8 animCount , bool incrementFrame = true , bool yellowBorder = false , bool blueBorder = false , SDL_Rect * destRect = NULL ) ; //0 - success, any other - error //print next
2009-04-16 14:14:13 +03:00
void incrementFrame ( ) ;
2011-05-26 17:47:45 +03:00
int getFrame ( ) const ; // Gets the current frame ID relative to DEF file.
int getAnimationFrame ( ) const ; // Gets the current frame ID relative to frame group.
2009-10-13 05:01:29 +03:00
bool onFirstFrameInGroup ( ) ;
2009-04-16 14:14:13 +03:00
bool onLastFrameInGroup ( ) ;
2011-02-09 15:56:30 +02:00
void playOnce ( CCreatureAnim : : EAnimType type ) ; //plays once given stage of animation, then resets to 2
2009-04-16 14:14:13 +03:00
2011-02-09 15:56:30 +02:00
int framesInGroup ( CCreatureAnim : : EAnimType group ) const ; //retirns number of fromes in given group
2009-04-16 14:14:13 +03:00
} ;