1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00
vcmi/lib/CCreatureSet.h

102 lines
3.5 KiB
C
Raw Normal View History

2010-04-02 05:23:22 +03:00
#ifndef __CCREATURESET_H__
#define __CCREATURESET_H__
#include "../global.h"
#include <map>
#include "HeroBonus.h"
2010-04-02 05:23:22 +03:00
class CCreature;
class CGHeroInstance;
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
const int ARMY_SIZE = 7;
2010-04-02 05:23:22 +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
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;
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)
{
h & static_cast<CBonusSystemNode&>(*this);
h & armyObj & type & count & experience;
2010-04-02 05:23:22 +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;
std::string getQuantityTXT(bool capitalized = true) const;
2010-04-02 05:23:22 +03:00
void init();
CStackInstance();
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-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;
const TSlots &Slots() const {return slots;}
2010-04-02 05:23:22 +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;
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
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
std::string getRoughAmount (TSlot slot) const; //rough size of specific stack
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__