2011-12-14 00:23:17 +03:00
# pragma once
2010-04-02 05:23:22 +03:00
2010-05-02 21:20:26 +03:00
# include "HeroBonus.h"
2011-12-14 00:23:17 +03:00
# include "GameConstants.h"
2012-01-30 19:07:52 +03:00
# include "CArtHandler.h"
2010-04-02 05:23:22 +03:00
class CCreature ;
class CGHeroInstance ;
2010-05-02 21:20:26 +03:00
class CArmedInstance ;
2012-01-30 19:07:52 +03:00
class CCreatureArtifactSet ;
2010-04-02 05:23:22 +03:00
2011-12-14 00:23:17 +03:00
class DLL_LINKAGE CStackBasicDescriptor
2010-11-22 02:34:46 +02:00
{
public :
const CCreature * type ;
TQuantity count ;
2010-05-02 21:20:26 +03:00
2010-11-22 02:34:46 +02:00
CStackBasicDescriptor ( ) ;
CStackBasicDescriptor ( TCreature id , TQuantity Count ) ;
2010-12-06 01:10:02 +02:00
CStackBasicDescriptor ( const CCreature * c , TQuantity Count ) ;
2010-11-22 02:34:46 +02:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
h & type & count ;
}
} ;
2012-04-14 05:20:22 +03:00
class DLL_LINKAGE CStackInstance : public CBonusSystemNode , public CStackBasicDescriptor , public CArtifactSet
2010-04-02 05:23:22 +03:00
{
2012-04-22 20:38:36 +03:00
protected :
2010-11-27 03:46:19 +02: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
public :
int idRand ; //hlp variable used during loading game -> "id" placeholder for randomization
2010-05-02 21:20:26 +03:00
2010-11-27 03:46:19 +02:00
const CArmedInstance * const & armyObj ; //stack must be part of some army, army must be part of some object
2012-05-18 22:44:15 +03:00
expType experience ; //commander needs same amount of exp as hero
2010-04-02 05:23:22 +03:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2010-05-02 21:20:26 +03:00
h & static_cast < CBonusSystemNode & > ( * this ) ;
2010-11-22 02:34:46 +02:00
h & static_cast < CStackBasicDescriptor & > ( * this ) ;
2012-04-14 05:20:22 +03:00
h & static_cast < CArtifactSet & > ( * this ) ;
2010-11-27 03:46:19 +02:00
h & _armyObj & experience ;
2011-02-22 11:47:25 +02:00
BONUS_TREE_DESERIALIZATION_FIX
2010-04-02 05:23:22 +03:00
}
2010-05-02 21:20:26 +03:00
//overrides CBonusSystemNode
2010-11-13 22:26:15 +02: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 20:10:43 +02:00
std : : string bonusToString ( Bonus * bonus , bool description ) const ; // how would bonus description look for this particular type of node
2011-03-20 10:45:05 +02:00
std : : string bonusToGraphics ( Bonus * bonus ) const ; //file name of graphics from StackSkills , in future possibly others
2010-05-02 21:20:26 +03:00
2012-04-04 20:41:55 +03:00
virtual ui64 getPower ( ) const ;
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 ;
2012-04-04 20:41:55 +03:00
virtual int getExpRank ( ) const ;
2011-05-29 21:28:50 +03:00
si32 magicResistance ( ) const ;
2011-06-20 14:41:04 +03:00
int getCreatureID ( ) const ; //-1 if not available
2011-10-22 10:05:57 +03:00
std : : string getName ( ) const ; //plural or singular
2012-04-22 20:38:36 +03:00
virtual void init ( ) ;
2010-04-02 05:23:22 +03:00
CStackInstance ( ) ;
2010-11-27 03:46:19 +02:00
CStackInstance ( TCreature id , TQuantity count ) ;
2010-04-02 05:23:22 +03:00
CStackInstance ( const CCreature * cre , TQuantity count ) ;
2010-12-06 01:10:02 +02:00
~ CStackInstance ( ) ;
2010-04-02 05:23:22 +03:00
void setType ( int creID ) ;
2010-11-27 03:46:19 +02:00
void setType ( const CCreature * c ) ;
2010-11-22 02:34:46 +02:00
void setArmyObj ( const CArmedInstance * ArmyObj ) ;
2012-04-22 20:38:36 +03:00
virtual void giveStackExp ( expType exp ) ;
2010-11-27 03:46:19 +02:00
bool valid ( bool allowUnrandomized ) const ;
2012-04-14 05:20:22 +03:00
ui8 bearerType ( ) const OVERRIDE ; //from CArtifactSet
virtual std : : string nodeName ( ) const OVERRIDE ; //from CBonusSystemnode
2011-02-04 16:58:14 +02:00
void deserializationFix ( ) ;
2010-04-02 05:23:22 +03:00
} ;
2012-04-04 20:41:55 +03:00
class DLL_LINKAGE CCommanderInstance : public CStackInstance
{
2012-04-22 20:38:36 +03:00
public :
2012-04-04 20:41:55 +03:00
//TODO: what if Commander is not a part of creature set?
//commander class is determined by its base creature
ui8 alive ;
2012-05-18 17:02:27 +03:00
ui8 level ; //required only to count callbacks
2012-04-04 20:41:55 +03:00
std : : string name ; // each Commander has different name
2012-05-18 17:02:27 +03:00
std : : vector < ui8 > secondarySkills ; //ID -> level
2012-05-18 22:44:15 +03:00
std : : set < ui8 > specialSKills ;
2012-04-04 20:41:55 +03:00
//std::vector <CArtifactInstance *> arts;
2012-04-28 14:41:20 +03:00
void init ( ) OVERRIDE ;
2012-04-22 20:38:36 +03:00
CCommanderInstance ( ) ;
CCommanderInstance ( TCreature id ) ;
~ CCommanderInstance ( ) ;
2012-05-01 11:52:22 +03:00
void setAlive ( bool alive ) ;
2012-05-07 15:54:22 +03:00
void giveStackExp ( expType exp ) ;
void levelUp ( ) ;
2012-04-04 20:41:55 +03:00
ui64 getPower ( ) const { return 0 ; } ;
2012-05-07 15:54:22 +03:00
int getExpRank ( ) const ;
2012-05-19 21:27:23 +03:00
ui8 bearerType ( ) const OVERRIDE ; //from CArtifactSet
2012-04-04 20:41:55 +03:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
h & static_cast < CStackInstance & > ( * this ) ;
2012-05-18 22:44:15 +03:00
h & alive & level & name & secondarySkills & specialSKills ;
2012-04-04 20:41:55 +03:00
}
} ;
2011-12-14 00:23:17 +03:00
DLL_LINKAGE std : : ostream & operator < < ( std : : ostream & str , const CStackInstance & sth ) ;
2010-04-02 05:23:22 +03:00
2010-11-22 02:34:46 +02:00
typedef std : : map < TSlot , CStackInstance * > TSlots ;
2011-01-28 04:11:58 +02:00
typedef std : : map < TSlot , CStackBasicDescriptor > TSimpleSlots ;
2010-04-02 05:23:22 +03:00
2011-01-28 04:11:58 +02:00
class IArmyDescriptor
{
public :
virtual void clear ( ) = 0 ;
virtual bool setCreature ( TSlot slot , TCreature cre , TQuantity count ) = 0 ;
} ;
//simplified version of CCreatureSet
2011-12-14 00:23:17 +03:00
class DLL_LINKAGE CSimpleArmy : public IArmyDescriptor
2011-01-28 04:11:58 +02:00
{
public :
TSimpleSlots army ;
void clear ( ) OVERRIDE ;
bool setCreature ( TSlot slot , TCreature cre , TQuantity count ) OVERRIDE ;
operator bool ( ) const ;
2010-05-02 21:20:26 +03:00
2011-01-28 04:11:58 +02:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
h & army ;
}
} ;
2010-05-02 21:20:26 +03:00
2011-12-14 00:23:17 +03:00
class DLL_LINKAGE CCreatureSet : public IArmyDescriptor //seven combined creatures
2010-04-02 05:23:22 +03:00
{
2012-09-15 22:16:16 +03:00
CCreatureSet ( const CCreatureSet & ) ;
2010-12-06 01:10:02 +02:00
CCreatureSet & operator = ( const CCreatureSet & ) ;
2010-04-02 05:23:22 +03:00
public :
2011-01-21 04:36:30 +02:00
TSlots stacks ; //slots[slot_id]->> pair(creature_id,creature_quantity)
2010-04-02 05:23:22 +03:00
ui8 formation ; //false - wide, true - tight
2010-11-27 03:46:19 +02:00
CCreatureSet ( ) ;
virtual ~ CCreatureSet ( ) ;
2011-02-04 16:58:14 +02:00
virtual void armyChanged ( ) ;
2010-11-27 03:46:19 +02:00
2012-09-15 22:16:16 +03:00
const CStackInstance & operator [ ] ( TSlot slot ) const ;
2010-04-02 05:23:22 +03:00
2011-01-21 04:36:30 +02:00
const TSlots & Slots ( ) const { return stacks ; }
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
2010-11-22 02:34:46 +02: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 04:11:58 +02:00
void clear ( ) OVERRIDE ;
2010-05-02 21:20:26 +03:00
void setFormation ( bool tight ) ;
2010-11-27 03:46:19 +02:00
CArmedInstance * castToArmyObj ( ) ;
//basic operations
void putStack ( TSlot slot , CStackInstance * stack ) ; //adds new stack to the army, slot must be empty
2010-05-02 21:20:26 +03:00
void setStackCount ( TSlot slot , TQuantity count ) ; //stack must exist!
2011-02-04 16:58:14 +02: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 03:46:19 +02:00
void setStackType ( TSlot slot , const CCreature * type ) ;
2011-02-12 20:48:11 +02:00
void giveStackExp ( expType exp ) ;
2011-03-27 12:31:14 +03:00
void setStackExp ( TSlot slot , expType exp ) ;
2010-11-27 03:46:19 +02:00
2012-09-15 22:16:16 +03:00
//derivative
2011-02-04 16:58:14 +02: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 03:46:19 +02:00
void changeStackCount ( TSlot slot , TQuantity toAdd ) ; //stack must exist!
2011-01-28 04:11:58 +02: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.
2012-09-15 22:16:16 +03:00
2011-06-20 14:41:04 +03:00
const CStackInstance & getStack ( TSlot slot ) const ; //stack must exist
const CStackInstance * getStackPtr ( TSlot slot ) const ; //if stack doesn't exist, returns NULL
2010-04-02 05:23:22 +03:00
const CCreature * getCreature ( TSlot slot ) const ; //workaround of map issue;
2010-11-27 03:46:19 +02:00
int getStackCount ( TSlot slot ) const ;
2011-03-27 12:31:14 +03:00
expType getStackExperience ( TSlot slot ) const ;
2010-11-20 19:36:02 +02:00
TSlot findStack ( const CStackInstance * stack ) const ; //-1 if none
2011-12-14 00:23:17 +03:00
TSlot getSlotFor ( TCreature creature , ui32 slotsAmount = GameConstants : : ARMY_SIZE ) const ; //returns -1 if no slot available
TSlot getSlotFor ( const CCreature * c , ui32 slotsAmount = GameConstants : : ARMY_SIZE ) const ; //returns -1 if no slot available
TSlot getFreeSlot ( ui32 slotsAmount = GameConstants : : ARMY_SIZE ) const ;
2010-05-02 21:20:26 +03:00
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
2011-06-21 12:31:08 +03:00
ui64 getArmyStrength ( ) const ; //sum of AI values of creatures
2010-05-02 21:20:26 +03:00
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-12-25 21:23:30 +02:00
bool hasStackAtSlot ( TSlot slot ) const ;
2012-09-15 22:16:16 +03:00
2010-05-02 21:20:26 +03:00
bool contains ( const CStackInstance * stack ) const ;
2010-12-13 01:44:16 +02:00
bool canBeMergedWith ( const CCreatureSet & cs , bool allowMergingStacks = true ) const ;
2010-11-22 02:34:46 +02:00
2010-04-02 05:23:22 +03:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2011-01-21 04:36:30 +02:00
h & stacks & formation ;
2010-04-02 05:23:22 +03:00
}
operator bool ( ) const
{
2011-01-21 04:36:30 +02:00
return stacks . size ( ) > 0 ;
2010-04-02 05:23:22 +03:00
}
void sweep ( ) ;
} ;