2010-04-02 05:23:22 +03:00
# ifndef __CCREATURESET_H__
# define __CCREATURESET_H__
# include "../global.h"
# include <map>
2010-05-02 21:20:26 +03:00
# include "HeroBonus.h"
2010-04-02 05:23:22 +03:00
class CCreature ;
class CGHeroInstance ;
2010-05-02 21:20:26 +03:00
class CArmedInstance ;
2010-04-02 05:23:22 +03:00
//a few typedefs for CCreatureSet
typedef si32 TSlot ;
typedef si32 TQuantity ;
typedef ui32 TCreature ; //creature id
2010-05-02 21:20:26 +03:00
const int ARMY_SIZE = 7 ;
2010-04-02 05:23:22 +03:00
2010-05-02 21:20:26 +03:00
class DLL_EXPORT CStackInstance : public CBonusSystemNode
2010-04-02 05:23:22 +03:00
{
public :
int idRand ; //hlp variable used during loading game -> "id" placeholder for randomization
2010-05-02 21:20:26 +03:00
const CArmedInstance * armyObj ; //stack must be part of some army, army must be part of some object
2010-04-02 05:23:22 +03:00
const CCreature * type ;
TQuantity count ;
2010-07-16 09:18:41 +03:00
ui32 getMinDamage ( ) const ;
ui32 getMaxDamage ( ) const ;
2010-04-02 05:23:22 +03:00
ui32 experience ; //TODO: handle
//TODO: stack artifacts
template < typename Handler > void serialize ( Handler & h , const int version )
{
2010-05-02 21:20:26 +03:00
h & static_cast < CBonusSystemNode & > ( * this ) ;
h & armyObj & type & count & experience ;
2010-04-02 05:23:22 +03:00
}
2010-05-02 21:20:26 +03:00
//overrides CBonusSystemNode
void getParents ( TCNodes & out , const CBonusSystemNode * source = NULL ) const ; //retrieves list of parent nodes (nodes to inherit bonuses from), source is the prinary asker
2010-04-02 05:23:22 +03:00
int getQuantityID ( ) const ;
2010-07-31 03:26:34 +03:00
std : : string getQuantityTXT ( bool capitalized = true ) const ;
2010-04-02 05:23:22 +03:00
void init ( ) ;
CStackInstance ( ) ;
2010-05-02 21:20:26 +03:00
CStackInstance ( TCreature id , TQuantity count , const CArmedInstance * ArmyObj = NULL ) ;
2010-04-02 05:23:22 +03:00
CStackInstance ( const CCreature * cre , TQuantity count ) ;
void setType ( int creID ) ;
} ;
typedef std : : map < TSlot , CStackInstance > TSlots ;
2010-05-02 21:20:26 +03:00
2010-04-02 05:23:22 +03:00
class DLL_EXPORT CCreatureSet //seven combined creatures
{
public :
TSlots slots ; //slots[slot_id]=> pair(creature_id,creature_quantity)
ui8 formation ; //false - wide, true - tight
const CStackInstance operator [ ] ( TSlot slot ) const ;
2010-05-02 21:20:26 +03:00
const TSlots & Slots ( ) const { return slots ; }
2010-04-02 05:23:22 +03:00
2010-05-02 21:20:26 +03:00
void addToSlot ( TSlot slot , TCreature cre , TQuantity count , bool allowMerging = true ) ; //Adds stack to slot. Slot must be empty or with same type creature
void addToSlot ( TSlot slot , const CStackInstance & stack , bool allowMerging = true ) ; //Adds stack to slot. Slot must be empty or with same type creature
void addStack ( TSlot slot , const CStackInstance & stack ) ; //adds new stack to the army, slot must be empty
bool setCreature ( TSlot slot , TCreature type , TQuantity quantity ) ; //slots 0 to 6, if quantity=0, erases stack
void clear ( ) ;
void setFormation ( bool tight ) ;
void setStackCount ( TSlot slot , TQuantity count ) ; //stack must exist!
void eraseStack ( TSlot slot ) ;
const CStackInstance & getStack ( TSlot slot ) const ;
2010-04-02 05:23:22 +03:00
const CCreature * getCreature ( TSlot slot ) const ; //workaround of map issue;
int getAmount ( TSlot slot ) const ;
2010-05-02 21:20:26 +03:00
TSlot getSlotFor ( TCreature creature , ui32 slotsAmount = ARMY_SIZE ) const ; //returns -1 if no slot available
bool mergableStacks ( std : : pair < TSlot , TSlot > & out , TSlot preferable = - 1 ) const ; //looks for two same stacks, returns slot positions;
2010-04-02 05:23:22 +03:00
bool validTypes ( bool allowUnrandomized = false ) const ; //checks if all types of creatures are set properly
2010-05-02 21:20:26 +03:00
bool slotEmpty ( TSlot slot ) const ;
int stacksCount ( ) const ;
virtual bool needsLastStack ( ) const ; //true if last stack cannot be taken
int getArmyStrength ( ) const ; //sum of AI values of creatures
ui64 getPower ( TSlot slot ) const ; //value of specific stack
2010-05-26 12:47:53 +03:00
std : : string getRoughAmount ( TSlot slot ) const ; //rough size of specific stack
2010-05-02 21:20:26 +03:00
bool contains ( const CStackInstance * stack ) const ;
2010-04-02 05:23:22 +03:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
h & slots & formation ;
}
operator bool ( ) const
{
return slots . size ( ) > 0 ;
}
void sweep ( ) ;
} ;
# endif // __CCREATURESET_H__