2010-04-02 02:23:22 +00:00
# ifndef __CCREATURESET_H__
# define __CCREATURESET_H__
# include "../global.h"
# include <map>
2010-05-02 18:20:26 +00:00
# include "HeroBonus.h"
2010-04-02 02:23:22 +00:00
class CCreature ;
class CGHeroInstance ;
2010-05-02 18:20:26 +00:00
class CArmedInstance ;
2010-04-02 02:23:22 +00:00
2010-11-22 00:34:46 +00:00
class DLL_EXPORT CStackBasicDescriptor
{
public :
const CCreature * type ;
TQuantity count ;
2010-05-02 18:20:26 +00:00
2010-11-22 00:34:46 +00:00
CStackBasicDescriptor ( ) ;
CStackBasicDescriptor ( TCreature id , TQuantity Count ) ;
2010-12-05 23:10:02 +00:00
CStackBasicDescriptor ( const CCreature * c , TQuantity Count ) ;
2010-11-22 00:34:46 +00:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
h & type & count ;
}
} ;
class DLL_EXPORT CStackInstance : public CBonusSystemNode , public CStackBasicDescriptor
2010-04-02 02:23:22 +00:00
{
2010-11-27 01:46:19 +00:00
const CArmedInstance * _armyObj ; //stack must be part of some army, army must be part of some object
2010-04-02 02:23:22 +00:00
public :
int idRand ; //hlp variable used during loading game -> "id" placeholder for randomization
2010-05-02 18:20:26 +00:00
2010-11-27 01:46:19 +00:00
const CArmedInstance * const & armyObj ; //stack must be part of some army, army must be part of some object
2010-04-02 02:23:22 +00:00
ui32 experience ; //TODO: handle
//TODO: stack artifacts
template < typename Handler > void serialize ( Handler & h , const int version )
{
2010-05-02 18:20:26 +00:00
h & static_cast < CBonusSystemNode & > ( * this ) ;
2010-11-22 00:34:46 +00:00
h & static_cast < CStackBasicDescriptor & > ( * this ) ;
2010-11-27 01:46:19 +00:00
h & _armyObj & experience ;
2011-02-22 09:47:25 +00:00
BONUS_TREE_DESERIALIZATION_FIX
2010-04-02 02:23:22 +00:00
}
2010-05-02 18:20:26 +00:00
//overrides CBonusSystemNode
2010-11-13 20:26:15 +00:00
//void getParents(TCNodes &out, const CBonusSystemNode *source = NULL) const; //retrieves list of parent nodes (nodes to inherit bonuses from), source is the prinary asker
2011-02-01 18:10:43 +00:00
std : : string bonusToString ( Bonus * bonus , bool description ) const ; // how would bonus description look for this particular type of node
2011-03-20 08:45:05 +00:00
std : : string bonusToGraphics ( Bonus * bonus ) const ; //file name of graphics from StackSkills , in future possibly others
2010-05-02 18:20:26 +00:00
2010-04-02 02:23:22 +00:00
int getQuantityID ( ) const ;
2010-07-31 00:26:34 +00:00
std : : string getQuantityTXT ( bool capitalized = true ) const ;
2011-02-11 08:20:26 +00:00
int getExpRank ( ) const ;
2010-04-02 02:23:22 +00:00
void init ( ) ;
CStackInstance ( ) ;
2010-11-27 01:46:19 +00:00
CStackInstance ( TCreature id , TQuantity count ) ;
2010-04-02 02:23:22 +00:00
CStackInstance ( const CCreature * cre , TQuantity count ) ;
2010-12-05 23:10:02 +00:00
~ CStackInstance ( ) ;
2010-04-02 02:23:22 +00:00
void setType ( int creID ) ;
2010-11-27 01:46:19 +00:00
void setType ( const CCreature * c ) ;
2010-11-22 00:34:46 +00:00
void setArmyObj ( const CArmedInstance * ArmyObj ) ;
2011-02-12 18:48:11 +00:00
void giveStackExp ( expType exp ) ;
2010-11-27 01:46:19 +00:00
bool valid ( bool allowUnrandomized ) const ;
2010-12-11 23:11:26 +00:00
virtual std : : string nodeName ( ) const OVERRIDE ;
2011-02-04 14:58:14 +00:00
void deserializationFix ( ) ;
2010-04-02 02:23:22 +00:00
} ;
2010-11-27 01:46:19 +00:00
DLL_EXPORT std : : ostream & operator < < ( std : : ostream & str , const CStackInstance & sth ) ;
2010-04-02 02:23:22 +00:00
2010-11-22 00:34:46 +00:00
typedef std : : map < TSlot , CStackInstance * > TSlots ;
2011-01-28 02:11:58 +00:00
typedef std : : map < TSlot , CStackBasicDescriptor > TSimpleSlots ;
2010-04-02 02:23:22 +00:00
2011-01-28 02:11:58 +00:00
class IArmyDescriptor
{
public :
virtual void clear ( ) = 0 ;
virtual bool setCreature ( TSlot slot , TCreature cre , TQuantity count ) = 0 ;
} ;
//simplified version of CCreatureSet
class DLL_EXPORT CSimpleArmy : public IArmyDescriptor
{
public :
TSimpleSlots army ;
void clear ( ) OVERRIDE ;
bool setCreature ( TSlot slot , TCreature cre , TQuantity count ) OVERRIDE ;
operator bool ( ) const ;
2010-05-02 18:20:26 +00:00
2011-01-28 02:11:58 +00:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
h & army ;
}
} ;
2010-05-02 18:20:26 +00:00
2011-01-28 02:11:58 +00:00
class DLL_EXPORT CCreatureSet : public IArmyDescriptor //seven combined creatures
2010-04-02 02:23:22 +00:00
{
2010-12-05 23:10:02 +00:00
CCreatureSet ( const CCreatureSet & ) ; ;
CCreatureSet & operator = ( const CCreatureSet & ) ;
2010-04-02 02:23:22 +00:00
public :
2011-01-21 02:36:30 +00:00
TSlots stacks ; //slots[slot_id]->> pair(creature_id,creature_quantity)
2010-04-02 02:23:22 +00:00
ui8 formation ; //false - wide, true - tight
2010-11-27 01:46:19 +00:00
CCreatureSet ( ) ;
virtual ~ CCreatureSet ( ) ;
2011-02-04 14:58:14 +00:00
virtual void armyChanged ( ) ;
2010-11-27 01:46:19 +00:00
2010-11-22 00:34:46 +00:00
const CStackInstance & operator [ ] ( TSlot slot ) const ;
2010-04-02 02:23:22 +00:00
2011-01-21 02:36:30 +00:00
const TSlots & Slots ( ) const { return stacks ; }
2010-04-02 02:23:22 +00:00
2010-05-02 18:20:26 +00: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
2010-11-22 00:34:46 +00:00
void addToSlot ( TSlot slot , CStackInstance * stack , bool allowMerging = true ) ; //Adds stack to slot. Slot must be empty or with same type creature
2011-01-28 02:11:58 +00:00
void clear ( ) OVERRIDE ;
2010-05-02 18:20:26 +00:00
void setFormation ( bool tight ) ;
2010-11-27 01:46:19 +00:00
CArmedInstance * castToArmyObj ( ) ;
//basic operations
void putStack ( TSlot slot , CStackInstance * stack ) ; //adds new stack to the army, slot must be empty
2010-05-02 18:20:26 +00:00
void setStackCount ( TSlot slot , TQuantity count ) ; //stack must exist!
2011-02-04 14:58:14 +00:00
CStackInstance * detachStack ( TSlot slot ) ; //removes stack from army but doesn't destroy it (so it can be moved somewhere else or safely deleted)
2010-11-27 01:46:19 +00:00
void setStackType ( TSlot slot , const CCreature * type ) ;
2011-02-12 18:48:11 +00:00
void giveStackExp ( expType exp ) ;
2011-03-27 09:31:14 +00:00
void setStackExp ( TSlot slot , expType exp ) ;
2010-11-27 01:46:19 +00:00
//derivative
2011-02-04 14:58:14 +00:00
void eraseStack ( TSlot slot ) ; //slot must be occupied
void joinStack ( TSlot slot , CStackInstance * stack ) ; //adds new stack to the existing stack of the same type
2010-11-27 01:46:19 +00:00
void changeStackCount ( TSlot slot , TQuantity toAdd ) ; //stack must exist!
2011-01-28 02:11:58 +00:00
bool setCreature ( TSlot slot , TCreature type , TQuantity quantity ) OVERRIDE ; //replaces creature in stack; slots 0 to 6, if quantity=0 erases stack
void setToArmy ( CSimpleArmy & src ) ; //erases all our army and moves stacks from src to us; src MUST NOT be an armed object! WARNING: use it wisely. Or better do not use at all.
2010-05-02 18:20:26 +00:00
const CStackInstance & getStack ( TSlot slot ) const ;
2010-04-02 02:23:22 +00:00
const CCreature * getCreature ( TSlot slot ) const ; //workaround of map issue;
2010-11-27 01:46:19 +00:00
int getStackCount ( TSlot slot ) const ;
2011-03-27 09:31:14 +00:00
expType getStackExperience ( TSlot slot ) const ;
2010-11-20 17:36:02 +00:00
TSlot findStack ( const CStackInstance * stack ) const ; //-1 if none
2010-05-02 18:20:26 +00:00
TSlot getSlotFor ( TCreature creature , ui32 slotsAmount = ARMY_SIZE ) const ; //returns -1 if no slot available
2010-11-27 20:17:28 +00:00
TSlot getSlotFor ( const CCreature * c , ui32 slotsAmount = ARMY_SIZE ) const ; //returns -1 if no slot available
2011-04-10 08:33:53 +00:00
TSlot getFreeSlot ( ui32 slotsAmount = ARMY_SIZE ) const ;
2010-05-02 18:20:26 +00:00
bool mergableStacks ( std : : pair < TSlot , TSlot > & out , TSlot preferable = - 1 ) const ; //looks for two same stacks, returns slot positions;
2010-04-02 02:23:22 +00:00
bool validTypes ( bool allowUnrandomized = false ) const ; //checks if all types of creatures are set properly
2010-05-02 18:20:26 +00: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 09:47:53 +00:00
std : : string getRoughAmount ( TSlot slot ) const ; //rough size of specific stack
2010-12-25 19:23:30 +00:00
bool hasStackAtSlot ( TSlot slot ) const ;
2010-05-02 18:20:26 +00:00
bool contains ( const CStackInstance * stack ) const ;
2010-12-12 23:44:16 +00:00
bool canBeMergedWith ( const CCreatureSet & cs , bool allowMergingStacks = true ) const ;
2010-11-22 00:34:46 +00:00
2010-04-02 02:23:22 +00:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2011-01-21 02:36:30 +00:00
h & stacks & formation ;
2010-04-02 02:23:22 +00:00
}
operator bool ( ) const
{
2011-01-21 02:36:30 +00:00
return stacks . size ( ) > 0 ;
2010-04-02 02:23:22 +00:00
}
void sweep ( ) ;
} ;
# endif // __CCREATURESET_H__