2009-04-16 14:14:13 +03:00
|
|
|
#ifndef __CCREATUREHANDLER_H__
|
|
|
|
#define __CCREATUREHANDLER_H__
|
|
|
|
#include "../global.h"
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
|
2010-05-02 21:20:26 +03:00
|
|
|
#include "../lib/HeroBonus.h"
|
2010-08-24 17:26:57 +03:00
|
|
|
#include "../lib/CGameState.h"
|
2010-08-30 02:12:34 +03:00
|
|
|
#include "../lib/CCreatureSet.h"
|
2010-12-17 20:47:07 +02:00
|
|
|
#include "../lib/ConstTransitivePtr.h"
|
2009-04-26 02:31:39 +03:00
|
|
|
|
2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* CCreatureHandler.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
|
|
|
|
*
|
2009-04-16 14:14:13 +03:00
|
|
|
*/
|
2010-08-29 10:49:04 +03:00
|
|
|
#define ALLCREATURESGETDOUBLEMONTHS false
|
2009-04-16 14:14:13 +03:00
|
|
|
|
|
|
|
class CLodHandler;
|
2010-05-02 21:20:26 +03:00
|
|
|
class CCreatureHandler;
|
2010-08-24 17:26:57 +03:00
|
|
|
class CCreature;
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2010-05-02 21:20:26 +03:00
|
|
|
class DLL_EXPORT CCreature : public CBonusSystemNode
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string namePl, nameSing, nameRef; //name in singular and plural form; and reference name
|
|
|
|
std::vector<ui32> cost; //cost[res_id] - amount of that resource
|
|
|
|
std::set<ui32> upgrades; // IDs of creatures to which this creature can be upgraded
|
2010-05-12 05:32:56 +03:00
|
|
|
ui32 hitPoints, speed, attack, defence;
|
2010-05-02 21:20:26 +03:00
|
|
|
ui32 fightValue, AIValue, growth, hordeGrowth, shots, spells;
|
2009-04-16 14:14:13 +03:00
|
|
|
ui32 damageMin, damageMax;
|
|
|
|
ui32 ammMin, ammMax;
|
|
|
|
ui8 level; // 0 - unknown
|
|
|
|
std::string abilityText; //description of abilities
|
|
|
|
std::string abilityRefs; //references to abilities, in textformat
|
|
|
|
std::string animDefName;
|
2010-06-26 19:02:10 +03:00
|
|
|
si32 idNumber;
|
2009-04-16 14:14:13 +03:00
|
|
|
si8 faction; //-1 = neutral
|
2010-05-02 21:20:26 +03:00
|
|
|
ui8 doubleWide;
|
2009-04-16 14:14:13 +03:00
|
|
|
|
|
|
|
///animation info
|
|
|
|
float timeBetweenFidgets, walkAnimationTime, attackAnimationTime, flightAnimationDistance;
|
|
|
|
int upperRightMissleOffsetX, rightMissleOffsetX, lowerRightMissleOffsetX, upperRightMissleOffsetY, rightMissleOffsetY, lowerRightMissleOffsetY;
|
|
|
|
float missleFrameAngles[12];
|
|
|
|
int troopCountLocationOffset, attackClimaxFrame;
|
|
|
|
///end of anim info
|
|
|
|
|
|
|
|
bool isDoubleWide() const; //returns true if unit is double wide on battlefield
|
|
|
|
bool isFlying() const; //returns true if it is a flying unit
|
|
|
|
bool isShooting() const; //returns true if unit can shoot
|
2009-04-16 17:01:27 +03:00
|
|
|
bool isUndead() const; //returns true if unit is undead
|
2009-08-24 20:40:20 +03:00
|
|
|
bool isGood () const;
|
|
|
|
bool isEvil () const;
|
2009-04-16 14:14:13 +03:00
|
|
|
si32 maxAmount(const std::vector<si32> &res) const; //how many creatures can be bought
|
|
|
|
static int getQuantityID(const int & quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion
|
2010-07-12 13:20:25 +03:00
|
|
|
bool isMyUpgrade(const CCreature *anotherCre) const;
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2010-11-27 22:17:28 +02:00
|
|
|
bool valid() const;
|
|
|
|
|
2010-05-02 21:20:26 +03:00
|
|
|
void addBonus(int val, int type, int subtype = -1);
|
2010-12-29 23:04:22 +02:00
|
|
|
std::string nodeName() const OVERRIDE;
|
2010-11-13 22:26:15 +02:00
|
|
|
//void getParents(TCNodes &out, const CBonusSystemNode *root /*= NULL*/) const;
|
2010-07-12 13:20:25 +03:00
|
|
|
|
2009-07-09 22:15:22 +03:00
|
|
|
template<typename RanGen>
|
|
|
|
int getRandomAmount(RanGen &ranGen)
|
|
|
|
{
|
|
|
|
if(ammMax == ammMin)
|
|
|
|
return ammMax;
|
|
|
|
else
|
|
|
|
return ammMin + (ranGen() % (ammMax - ammMin));
|
|
|
|
}
|
|
|
|
|
2009-04-16 14:14:13 +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);
|
2009-04-16 14:14:13 +03:00
|
|
|
h & namePl & nameSing & nameRef
|
|
|
|
& cost & upgrades
|
|
|
|
& fightValue & AIValue & growth & hordeGrowth & hitPoints & speed & attack & defence & shots & spells
|
|
|
|
& damageMin & damageMax & ammMin & ammMax & level
|
|
|
|
& abilityText & abilityRefs & animDefName
|
2010-05-02 21:20:26 +03:00
|
|
|
& idNumber & faction
|
2009-04-16 14:14:13 +03:00
|
|
|
|
|
|
|
& timeBetweenFidgets & walkAnimationTime & attackAnimationTime & flightAnimationDistance
|
|
|
|
& upperRightMissleOffsetX & rightMissleOffsetX & lowerRightMissleOffsetX & upperRightMissleOffsetY & rightMissleOffsetY & lowerRightMissleOffsetY
|
|
|
|
& missleFrameAngles & troopCountLocationOffset & attackClimaxFrame;
|
2009-11-13 21:04:36 +02:00
|
|
|
|
2010-06-01 22:02:40 +03:00
|
|
|
h & doubleWide;
|
2009-04-16 14:14:13 +03:00
|
|
|
}
|
2010-05-02 21:20:26 +03:00
|
|
|
|
|
|
|
|
|
|
|
CCreature();
|
2010-05-12 05:32:56 +03:00
|
|
|
friend class CCreatureHandler;
|
2009-04-16 14:14:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_EXPORT CCreatureHandler
|
2010-08-24 17:26:57 +03:00
|
|
|
{
|
2011-02-10 15:12:53 +02:00
|
|
|
CBonusSystemNode allCreatures, creaturesOfLevel[CREATURES_PER_TOWN + 1];//index 0 is used for creatures of unknown tier or outside <1-7> range
|
2009-04-16 14:14:13 +03:00
|
|
|
public:
|
|
|
|
std::set<int> notUsedMonsters;
|
2010-08-29 10:49:04 +03:00
|
|
|
std::set<TCreature> doubledCreatures; //they get double week
|
2010-12-17 20:47:07 +02:00
|
|
|
std::vector<ConstTransitivePtr<CCreature> > creatures; //creature ID -> creature info
|
|
|
|
bmap<std::string,int> nameToID;
|
|
|
|
bmap<int,std::string> idToProjectile;
|
|
|
|
bmap<int,bool> idToProjectileSpin; //if true, appropriate projectile is spinning during flight
|
2009-09-05 17:10:26 +03:00
|
|
|
std::vector<si8> factionAlignments; //1 for good, 0 for neutral and -1 for evil with faction ID as index
|
|
|
|
int factionToTurretCreature[F_NUMBER]; //which creature's animation should be used to dispaly creature in turret while siege
|
2009-08-24 20:40:20 +03:00
|
|
|
|
2011-02-06 10:32:05 +02:00
|
|
|
std::map<TBonusType, std::pair<std::string, std::string> > stackBonuses; // bonus => name, description
|
2011-02-03 14:58:46 +02:00
|
|
|
std::vector<BonusList> commonBonuses; // levels 1-8 from CREXPBON.txt
|
2011-02-02 20:49:48 +02:00
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
void loadCreatures();
|
|
|
|
void loadAnimationInfo();
|
|
|
|
void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i);
|
2011-02-03 14:58:46 +02:00
|
|
|
void loadStackExp(stackExperience & b, std::string & src, int & it);
|
2011-02-08 13:34:34 +02:00
|
|
|
void loadMindImmunity(stackExperience & b, std::string & src, int & it); //multiple bonuses at once
|
2011-02-09 16:58:15 +02:00
|
|
|
int stringToNumber(std::string & s);//help function for parsing CREXPBON.txt
|
2009-08-24 20:40:20 +03:00
|
|
|
|
|
|
|
bool isGood (si8 faction) const;
|
|
|
|
bool isEvil (si8 faction) const;
|
|
|
|
|
2011-02-10 15:12:53 +02:00
|
|
|
int pickRandomMonster(const boost::function<int()> &randGen = 0, int tier = -1) const; //tier <1 - CREATURES_PER_TOWN> or -1 for any
|
|
|
|
void addBonusForTier(int tier, Bonus *b); //tier must be <1-7>
|
|
|
|
void addBonusForAllCreatures(Bonus *b);
|
2010-07-24 00:05:49 +03:00
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
CCreatureHandler();
|
|
|
|
~CCreatureHandler();
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
//TODO: should be optimized, not all these informations needs to be serialized (same for ccreature)
|
2009-09-05 17:10:26 +03:00
|
|
|
h & notUsedMonsters & creatures & nameToID & idToProjectile & idToProjectileSpin & factionToTurretCreature;
|
2011-02-10 15:12:53 +02:00
|
|
|
h & allCreatures;
|
|
|
|
h & creaturesOfLevel;
|
2009-04-16 14:14:13 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __CCREATUREHANDLER_H__
|