2011-12-14 00:23:17 +03:00
# pragma once
2009-04-15 17:03:31 +03:00
2011-12-14 00:23:17 +03:00
2010-12-17 20:47:07 +02:00
# include "../lib/ConstTransitivePtr.h"
2011-12-14 00:23:17 +03:00
# include "GameConstants.h"
2010-12-17 20:47:07 +02:00
2009-04-15 17:03:31 +03:00
/*
* CHeroHandler . 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-02-09 16:50:32 +02:00
class CHeroClass ;
class CDefHandler ;
class CGameInfo ;
class CGHeroInstance ;
2012-04-23 22:56:37 +03:00
struct BattleHex ;
2010-08-17 17:58:13 +03:00
struct SSpecialtyInfo
2010-07-06 10:32:40 +03:00
{ si32 type ;
si32 val ;
si32 subtype ;
si32 additionalinfo ;
2010-12-25 21:23:30 +02:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
h & type & val & subtype & additionalinfo ;
}
2010-07-06 10:32:40 +03:00
} ;
2010-08-17 17:58:13 +03:00
2011-12-14 00:23:17 +03:00
class DLL_LINKAGE CHero
2009-02-09 16:50:32 +02:00
{
public :
2009-05-07 20:20:41 +03:00
enum EHeroClasses { KNIGHT , CLERIC , RANGER , DRUID , ALCHEMIST , WIZARD ,
DEMONIAC , HERETIC , DEATHKNIGHT , NECROMANCER , WARLOCK , OVERLORD ,
BARBARIAN , BATTLEMAGE , BEASTMASTER , WITCH , PLANESWALKER , ELEMENTALIST } ;
std : : string name ; //name of hero
2010-06-26 19:02:10 +03:00
si32 ID ;
2009-07-03 21:40:36 +03:00
ui32 lowStack [ 3 ] , highStack [ 3 ] ; //amount of units; described below
2009-02-09 16:50:32 +02:00
std : : string refTypeStack [ 3 ] ; //reference names of units appearing in hero's army if he is recruited in tavern
CHeroClass * heroClass ;
EHeroClasses heroType ; //hero class
std : : vector < std : : pair < ui8 , ui8 > > secSkillsInit ; //initial secondary skills; first - ID of skill, second - level of skill (1 - basic, 2 - adv., 3 - expert)
2010-08-17 17:58:13 +03:00
std : : vector < SSpecialtyInfo > spec ;
2009-07-03 21:40:36 +03:00
si32 startingSpell ; //-1 if none
2010-08-25 17:57:58 +03:00
ui8 sex ; // default sex: 0=male, 1=female
2009-02-09 16:50:32 +02:00
//bool operator<(CHero& drugi){if (ID < drugi.ID) return true; else return false;}
2009-07-03 21:40:36 +03:00
CHero ( ) ;
~ CHero ( ) ;
2009-02-09 16:50:32 +02:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2010-12-25 21:23:30 +02:00
h & name & ID & lowStack & highStack & refTypeStack & heroClass & heroType & secSkillsInit & spec & startingSpell & sex ;
2009-02-09 16:50:32 +02:00
}
} ;
2011-12-14 00:23:17 +03:00
class DLL_LINKAGE CHeroClass
2009-02-09 16:50:32 +02:00
{
public :
2010-07-20 09:05:45 +03:00
ui8 alignment ;
2009-02-09 16:50:32 +02:00
ui32 skillLimit ; //how many secondary skills can hero learn
std : : string name ;
2011-12-14 00:23:17 +03:00
double aggression ;
2012-09-23 21:01:04 +03:00
int initialPrimSkills [ GameConstants : : PRIMARY_SKILLS ] ; //initial values of primary skills, uses PrimarySkill enum
2009-02-09 16:50:32 +02:00
std : : vector < std : : pair < int , int > > primChance ; //primChance[PRIMARY_SKILL_ID] - first is for levels 2 - 9, second for 10+;;; probability (%) of getting point of primary skill when getting new level
std : : vector < int > proSec ; //probabilities of gaining secondary skills (out of 112), in id order
2012-10-06 11:47:13 +03:00
std : : map < TFaction , int > selectionProbability ; //probability of selection in towns
2009-02-09 16:50:32 +02:00
int chooseSecSkill ( const std : : set < int > & possibles ) const ; //picks secondary skill out from given possibilities
2009-05-07 20:20:41 +03:00
CHeroClass ( ) ; //c-tor
~ CHeroClass ( ) ; //d-tor
2009-02-09 16:50:32 +02:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2012-09-23 21:01:04 +03:00
h & skillLimit & name & aggression & initialPrimSkills & primChance
2012-09-05 15:49:23 +03:00
& proSec & selectionProbability & alignment ;
2009-02-09 16:50:32 +02:00
}
2012-09-23 21:01:04 +03:00
EAlignment : : EAlignment getAlignment ( ) const ;
2009-02-09 16:50:32 +02:00
} ;
2011-12-14 00:23:17 +03:00
struct DLL_LINKAGE CObstacleInfo
2009-02-09 16:50:32 +02:00
{
2012-04-23 22:56:37 +03:00
si32 ID ;
std : : string defName ;
std : : vector < ui8 > allowedTerrains ;
std : : vector < ui8 > allowedSpecialBfields ;
ui8 isAbsoluteObstacle ; //there may only one such obstacle in battle and its position is always the same
si32 width , height ; //how much space to the right and up is needed to place obstacle (affects only placement algorithm)
std : : vector < si16 > blockedTiles ; //offsets relative to obstacle position (that is its left bottom corner)
2011-12-22 16:05:19 +03:00
std : : vector < BattleHex > getBlocked ( BattleHex hex ) const ; //returns vector of hexes blocked by obstacle when it's placed on hex 'hex'
2012-04-23 22:56:37 +03:00
bool isAppropriate ( int terrainType , int specialBattlefield = - 1 ) const ;
2009-02-09 16:50:32 +02:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2012-04-23 22:56:37 +03:00
h & ID & defName & allowedTerrains & allowedSpecialBfields & isAbsoluteObstacle & width & height & blockedTiles ;
2009-02-09 16:50:32 +02:00
}
} ;
2011-12-14 00:23:17 +03:00
class DLL_LINKAGE CHeroHandler
2009-02-09 16:50:32 +02:00
{
public :
2010-12-17 20:47:07 +02:00
std : : vector < ConstTransitivePtr < CHero > > heroes ; //changed from nodrze
2009-02-09 16:50:32 +02:00
std : : vector < CHeroClass * > heroClasses ;
2009-08-17 13:02:29 +03:00
std : : vector < ui64 > expPerLevel ; //expPerLEvel[i] is amount of exp needed to reach level i; if it is not in this vector, multiplicate last value by 1,2 to get next value
2012-09-05 15:49:23 +03:00
//default costs of going through terrains: dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock; -1 means terrain is imapassable
std : : vector < int > terrCosts ;
2009-02-09 16:50:32 +02:00
struct SBallisticsLevelInfo
{
ui8 keep , tower , gate , wall ; //chance to hit in percent (eg. 87 is 87%)
ui8 shots ; //how many shots we have
ui8 noDmg , oneDmg , twoDmg ; //chances for shot dealing certain dmg in percent (eg. 87 is 87%); must sum to 100
ui8 sum ; //I don't know if it is useful for anything, but it's in config file
template < typename Handler > void serialize ( Handler & h , const int version )
{
h & keep & tower & gate & wall & shots & noDmg & oneDmg & twoDmg & sum ;
}
} ;
std : : vector < SBallisticsLevelInfo > ballistics ; //info about ballistics ability per level; [0] - none; [1] - basic; [2] - adv; [3] - expert
std : : map < int , CObstacleInfo > obstacles ; //info about obstacles that may be placed on battlefield
2012-04-23 22:56:37 +03:00
std : : map < int , CObstacleInfo > absoluteObstacles ; //info about obstacles that may be placed on battlefield
2012-05-18 23:50:16 +03:00
2009-05-07 20:20:41 +03:00
void loadObstacles ( ) ; //loads info about obstacles
2009-02-09 16:50:32 +02:00
2011-12-14 00:23:17 +03:00
ui32 level ( ui64 experience ) const ; //calculates level corresponding to given experience amount
ui64 reqExp ( ui32 level ) const ; //calculates experience required for given level
2009-02-09 16:50:32 +02:00
void loadHeroes ( ) ;
void loadHeroClasses ( ) ;
void initHeroClasses ( ) ;
2011-09-02 06:39:49 +03:00
void loadTerrains ( ) ;
2009-05-07 20:20:41 +03:00
CHeroHandler ( ) ; //c-tor
~ CHeroHandler ( ) ; //d-tor
2009-02-09 16:50:32 +02:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2012-09-21 00:28:18 +03:00
h & heroClasses & heroes & expPerLevel & ballistics & terrCosts ;
2012-05-18 23:50:16 +03:00
h & obstacles & absoluteObstacles ;
2009-02-09 16:50:32 +02:00
if ( ! h . saving )
{
//restore class pointers
for ( int i = 0 ; i < heroes . size ( ) ; i + + )
{
heroes [ i ] - > heroClass = heroClasses [ heroes [ i ] - > heroType ] ;
}
}
}
} ;