2010-07-29 20:00:34 +03:00
|
|
|
#ifndef __CARTHANDLER_H__
|
|
|
|
#define __CARTHANDLER_H__
|
|
|
|
#include "../global.h"
|
|
|
|
#include "../lib/HeroBonus.h"
|
|
|
|
#include <set>
|
|
|
|
#include <list>
|
2010-12-17 20:47:07 +02:00
|
|
|
|
|
|
|
#include "../lib/ConstTransitivePtr.h"
|
2010-07-29 20:00:34 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CArtHandler.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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class CDefHandler;
|
2010-11-10 02:06:25 +02:00
|
|
|
class CArtifact;
|
2010-07-29 20:00:34 +03:00
|
|
|
|
|
|
|
class DLL_EXPORT CArtifact : public CBonusSystemNode //container for artifacts
|
|
|
|
{
|
2010-11-10 02:06:25 +02:00
|
|
|
protected:
|
2010-07-29 20:00:34 +03:00
|
|
|
std::string name, description; //set if custom
|
|
|
|
public:
|
|
|
|
enum EartClass {ART_SPECIAL=1, ART_TREASURE=2, ART_MINOR=4, ART_MAJOR=8, ART_RELIC=16}; //artifact classes
|
|
|
|
const std::string &Name() const; //getter
|
|
|
|
const std::string &Description() const; //getter
|
|
|
|
bool isBig () const;
|
2010-11-10 02:06:25 +02:00
|
|
|
bool isModable () const;
|
2010-12-13 22:16:18 +02:00
|
|
|
bool fitsAt (const std::map<ui16, const CArtifact*> &artifWorn, ui16 slot) const;
|
|
|
|
bool canBeAssembledTo (const std::map<ui16, const CArtifact*> &artifWorn, ui32 artifactID) const;
|
2010-07-29 20:00:34 +03:00
|
|
|
void addBonusesTo (BonusList *otherBonuses) const;
|
|
|
|
void removeBonusesFrom (BonusList *otherBonuses) const;
|
2010-11-10 02:06:25 +02:00
|
|
|
virtual void SetProperty (int mod){};
|
|
|
|
virtual void Init(){};
|
2010-07-29 20:00:34 +03:00
|
|
|
int getArtClassSerial() const; //0 - treasure, 1 - minor, 2 - major, 3 - relic, 4 - spell scroll, 5 - other
|
2010-12-17 20:47:07 +02:00
|
|
|
std::string nodeName() const OVERRIDE;
|
2010-07-29 20:00:34 +03:00
|
|
|
|
|
|
|
ui32 price;
|
|
|
|
std::vector<ui16> possibleSlots; //ids of slots where artifact can be placed
|
|
|
|
std::vector<ui32> * constituents; // Artifacts IDs a combined artifact consists of, or NULL.
|
|
|
|
std::vector<ui32> * constituentOf; // Reverse map of constituents.
|
|
|
|
EartClass aClass;
|
|
|
|
si32 id;
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
h & static_cast<CBonusSystemNode&>(*this);;
|
|
|
|
h & name & description & price & possibleSlots & constituents & constituentOf & aClass & id;
|
|
|
|
}
|
|
|
|
|
|
|
|
CArtifact();
|
|
|
|
~CArtifact();
|
|
|
|
|
2010-07-26 18:37:58 +03:00
|
|
|
//override
|
2010-11-13 22:26:15 +02:00
|
|
|
//void getParents(TCNodes &out, const CBonusSystemNode *root = NULL) const;
|
2010-07-29 20:00:34 +03:00
|
|
|
};
|
|
|
|
|
2010-12-17 20:47:07 +02:00
|
|
|
class DLL_EXPORT CArtifactInstance : public CBonusSystemNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ConstTransitivePtr<CArtifact> art;
|
|
|
|
si32 id; //id of the instance
|
|
|
|
|
|
|
|
CArtifactInstance();
|
|
|
|
CArtifactInstance(CArtifact *Art);
|
|
|
|
|
|
|
|
void init();
|
|
|
|
std::string nodeName() const OVERRIDE;
|
|
|
|
void setType(CArtifact *Art);
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
h & static_cast<CBonusSystemNode&>(*this);
|
|
|
|
h & art & id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CArtifactInstance *createScroll(const CSpell *s);
|
|
|
|
};
|
|
|
|
|
2010-11-10 02:06:25 +02:00
|
|
|
class DLL_EXPORT IModableArt : public CArtifact //artifact which can have different properties, such as scroll or banner
|
|
|
|
{ //used only for dynamic cast :P
|
2010-10-01 19:54:12 +03:00
|
|
|
public:
|
2010-11-10 02:06:25 +02:00
|
|
|
si32 ID; //used for smart serialization
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
h & static_cast<CArtifact&>(*this);
|
|
|
|
h & ID;
|
|
|
|
}
|
2010-10-01 19:54:12 +03:00
|
|
|
};
|
|
|
|
|
2010-11-10 02:06:25 +02:00
|
|
|
class DLL_EXPORT CScroll : public IModableArt // Spell Scroll
|
2010-10-01 19:54:12 +03:00
|
|
|
{
|
|
|
|
public:
|
2010-11-10 02:06:25 +02:00
|
|
|
CScroll(){spellid=0;};
|
|
|
|
CScroll(spelltype sid){spellid = sid;};
|
2010-10-01 19:54:12 +03:00
|
|
|
spelltype spellid;
|
2010-11-10 02:06:25 +02:00
|
|
|
void Init();
|
|
|
|
void SetProperty (int mod){spellid = mod;};
|
2010-10-01 19:54:12 +03:00
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2010-11-10 02:06:25 +02:00
|
|
|
h & static_cast<IModableArt&>(*this);
|
2010-10-01 19:54:12 +03:00
|
|
|
h & spellid;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-11-10 02:06:25 +02:00
|
|
|
class DLL_EXPORT CCustomizableArt : public IModableArt // Warlord's Banner with multiple options
|
2010-10-01 19:54:12 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ui8 mode;
|
2010-11-10 02:06:25 +02:00
|
|
|
CCustomizableArt(){mode=0;};
|
2010-10-01 19:54:12 +03:00
|
|
|
void Init(){};
|
2010-11-10 02:06:25 +02:00
|
|
|
void SetProperty (int mod){};
|
2010-10-01 19:54:12 +03:00
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2010-11-10 02:06:25 +02:00
|
|
|
h & static_cast<IModableArt&>(*this);
|
2010-10-01 19:54:12 +03:00
|
|
|
h & mode;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-11-10 02:06:25 +02:00
|
|
|
class DLL_EXPORT CCommanderArt : public IModableArt // Growing with time
|
2010-10-01 19:54:12 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ui32 level;
|
2010-11-10 02:06:25 +02:00
|
|
|
CCommanderArt(){level = 0;};
|
2010-10-01 19:54:12 +03:00
|
|
|
void Init(){};
|
2010-11-10 02:06:25 +02:00
|
|
|
void SetProperty (int mod){level = mod;};
|
2010-10-01 19:54:12 +03:00
|
|
|
void Upgrade(){level++;};
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2010-11-10 02:06:25 +02:00
|
|
|
h & static_cast<IModableArt&>(*this);
|
2010-10-01 19:54:12 +03:00
|
|
|
h & level;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-29 20:00:34 +03:00
|
|
|
class DLL_EXPORT CArtHandler //handles artifacts
|
|
|
|
{
|
2010-08-06 13:46:40 +03:00
|
|
|
void giveArtBonus(int aid, Bonus::BonusType type, int val, int subtype = -1, int valType = Bonus::BASE_NUMBER, ILimiter * limiter = NULL);
|
2010-07-29 20:00:34 +03:00
|
|
|
public:
|
|
|
|
std::vector<CArtifact*> treasures, minors, majors, relics;
|
2010-12-17 20:47:07 +02:00
|
|
|
std::vector< ConstTransitivePtr<CArtifact> > artifacts;
|
2010-07-29 20:00:34 +03:00
|
|
|
std::vector<CArtifact *> allowedArtifacts;
|
|
|
|
std::set<ui32> bigArtifacts; // Artifacts that cannot be moved to backpack, e.g. war machines.
|
2010-11-10 02:06:25 +02:00
|
|
|
std::map<ui32, ui8> modableArtifacts; //1-scroll, 2-banner, 3-commander art with progressive bonus
|
2010-07-29 20:00:34 +03:00
|
|
|
|
|
|
|
void loadArtifacts(bool onlyTxt);
|
|
|
|
void sortArts();
|
|
|
|
void addBonuses();
|
|
|
|
void clear();
|
|
|
|
void clearHlpLists();
|
|
|
|
ui16 getRandomArt (int flags);
|
|
|
|
ui16 getArtSync (ui32 rand, int flags);
|
2010-12-17 20:47:07 +02:00
|
|
|
void getAllowedArts(std::vector<ConstTransitivePtr<CArtifact> > &out, std::vector<CArtifact*> *arts, int flag);
|
|
|
|
void getAllowed(std::vector<ConstTransitivePtr<CArtifact> > &out, int flags);
|
2010-07-29 20:00:34 +03:00
|
|
|
void erasePickedArt (si32 id);
|
2010-12-19 00:11:28 +02:00
|
|
|
bool isBigArtifact (ui32 artID) const {return bigArtifacts.find(artID) != bigArtifacts.end();}
|
|
|
|
void equipArtifact (std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID, const CArtifact* art) const;
|
|
|
|
void unequipArtifact (std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID) const;
|
2010-08-18 12:50:25 +03:00
|
|
|
void initAllowedArtifactsList(const std::vector<ui8> &allowed); //allowed[art_id] -> 0 if not allowed, 1 if allowed
|
2010-07-29 20:00:34 +03:00
|
|
|
static int convertMachineID(int id, bool creToArt);
|
|
|
|
CArtHandler();
|
|
|
|
~CArtHandler();
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
h & artifacts & allowedArtifacts & treasures & minors & majors & relics;
|
|
|
|
//if(!h.saving) sortArts();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // __CARTHANDLER_H__
|