2011-12-14 00:23:17 +03:00
# pragma once
2009-04-15 17:03:31 +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"
2013-01-19 20:38:37 +03:00
# include "HeroBonus.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
*
*/
2012-12-16 16:47:53 +03:00
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 ;
2012-12-14 18:32:53 +03:00
class JsonNode ;
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
2013-01-19 20:38:37 +03:00
struct SSpecialtyBonus
/// temporary hold
{
ui8 growsWithLevel ;
BonusList bonuses ;
template < typename Handler > void serialize ( Handler & h , const int version )
{
h & growsWithLevel & bonuses ;
}
} ;
2011-12-14 00:23:17 +03:00
class DLL_LINKAGE CHero
2009-02-09 16:50:32 +02:00
{
public :
2012-12-03 19:00:17 +03:00
struct InitialArmyStack
{
ui32 minAmount ;
ui32 maxAmount ;
2013-02-11 02:24:57 +03:00
CreatureID creature ;
2012-12-03 19:00:17 +03:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
h & minAmount & maxAmount & creature ;
}
} ;
2010-06-26 19:02:10 +03:00
si32 ID ;
2012-12-16 16:47:53 +03:00
si32 imageIndex ;
2012-12-03 19:00:17 +03:00
2012-12-16 16:47:53 +03:00
std : : vector < InitialArmyStack > initialArmy ;
2012-12-03 19:00:17 +03:00
2009-02-09 16:50:32 +02:00
CHeroClass * heroClass ;
2013-02-12 22:49:40 +03:00
std : : vector < std : : pair < SecondarySkill , 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 ;
2013-01-19 20:38:37 +03:00
std : : vector < SSpecialtyBonus > specialty ;
2013-02-11 02:24:57 +03:00
std : : set < SpellID > spells ;
2010-08-25 17:57:58 +03:00
ui8 sex ; // default sex: 0=male, 1=female
2012-12-17 15:55:29 +03:00
ui8 special ; // hero is special and won't be placed in game (unless preset on map), e.g. campaign heroes
2009-02-09 16:50:32 +02:00
2012-12-16 16:47:53 +03:00
/// Localized texts
std : : string name ; //name of hero
std : : string biography ;
std : : string specName ;
std : : string specDescr ;
std : : string specTooltip ;
/// Graphics
std : : string iconSpecSmall ;
std : : string iconSpecLarge ;
std : : string portraitSmall ;
std : : string portraitLarge ;
2009-07-03 21:40:36 +03:00
2009-02-09 16:50:32 +02:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2013-01-19 20:38:37 +03:00
h & ID & imageIndex & initialArmy & heroClass & secSkillsInit & spec & specialty & spells & sex ;
2012-12-16 16:47:53 +03:00
h & name & biography & specName & specDescr & specTooltip ;
h & iconSpecSmall & iconSpecLarge & portraitSmall & portraitLarge ;
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 :
2012-12-14 18:32:53 +03:00
std : : string identifier ;
std : : string name ; // translatable
2011-12-14 00:23:17 +03:00
double aggression ;
2012-12-14 18:32:53 +03:00
TFaction faction ;
ui8 id ;
std : : vector < int > primarySkillInitial ; // initial primary skills
std : : vector < int > primarySkillLowLevel ; // probability (%) of getting point of primary skill when getting level
std : : vector < int > primarySkillHighLevel ; // same for high levels (> 10)
std : : vector < int > secSkillProbability ; //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
2012-12-16 16:47:53 +03:00
std : : string imageBattleMale ;
std : : string imageBattleFemale ;
std : : string imageMapMale ;
std : : string imageMapFemale ;
2013-02-12 22:49:40 +03:00
SecondarySkill chooseSecSkill ( const std : : set < SecondarySkill > & possibles ) const ; //picks secondary skill out from given possibilities
2009-02-09 16:50:32 +02:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2012-12-14 18:32:53 +03:00
h & identifier & name & faction & aggression ;
h & primarySkillInitial & primarySkillLowLevel ;
h & primarySkillHighLevel & secSkillProbability ;
h & selectionProbability ;
2012-12-16 16:47:53 +03:00
h & imageBattleMale & imageBattleFemale & imageMapMale & imageMapFemale ;
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 ;
2013-02-13 01:24:48 +03:00
std : : vector < ETerrainType > allowedTerrains ;
std : : vector < BFieldType > allowedSpecialBfields ;
2012-04-23 22:56:37 +03:00
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
2013-02-13 01:24:48 +03:00
bool isAppropriate ( ETerrainType terrainType , int specialBattlefield = - 1 ) const ;
2012-04-23 22:56:37 +03:00
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
}
} ;
2012-12-14 18:32:53 +03:00
class DLL_LINKAGE CHeroClassHandler
{
public :
std : : vector < ConstTransitivePtr < CHeroClass > > heroClasses ;
/// load from H3 config
void load ( ) ;
/// load any number of classes from json
void load ( const JsonNode & classes ) ;
/// load one class from json
2012-12-16 16:47:53 +03:00
CHeroClass * loadClass ( const JsonNode & node ) ;
2012-12-14 18:32:53 +03:00
~ CHeroClassHandler ( ) ;
template < typename Handler > void serialize ( Handler & h , const int version )
{
h & heroClasses ;
}
} ;
2011-12-14 00:23:17 +03:00
class DLL_LINKAGE CHeroHandler
2009-02-09 16:50:32 +02:00
{
2012-12-15 16:40:22 +03:00
/// expPerLEvel[i] is amount of exp needed to reach level i;
/// consists of 201 values. Any higher levels require experience larger that ui64 can hold
std : : vector < ui64 > expPerLevel ;
2012-12-14 18:32:53 +03:00
2012-12-16 16:47:53 +03:00
/// common function for loading heroes from mods and from H3
void loadHeroJson ( CHero * hero , const JsonNode & node ) ;
2009-02-09 16:50:32 +02:00
public :
2012-12-14 18:32:53 +03:00
CHeroClassHandler classes ;
2012-12-15 11:47:02 +03:00
std : : vector < ConstTransitivePtr < CHero > > heroes ;
2012-09-05 15:49:23 +03:00
2012-12-15 11:47:02 +03:00
//default costs of going through terrains. -1 means terrain is impassable
2012-09-05 15:49:23 +03:00
std : : vector < int > terrCosts ;
2013-02-05 00:58:42 +03:00
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
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
2012-12-15 11:47:02 +03:00
/// Load multiple heroes from json
void load ( const JsonNode & heroes ) ;
/// Load single hero from json
2012-12-16 16:47:53 +03:00
CHero * loadHero ( const JsonNode & node ) ;
2012-12-15 11:47:02 +03:00
/// Load everything (calls functions below + classes.load())
2012-12-14 18:32:53 +03:00
void load ( ) ;
2012-12-15 11:47:02 +03:00
2009-02-09 16:50:32 +02:00
void loadHeroes ( ) ;
2012-12-16 16:47:53 +03:00
void loadHeroTexts ( ) ;
2012-12-15 11:47:02 +03:00
void loadExperience ( ) ;
void loadBallistics ( ) ;
2011-09-02 06:39:49 +03:00
void loadTerrains ( ) ;
2012-12-15 11:47:02 +03:00
void loadObstacles ( ) ;
2009-05-07 20:20:41 +03:00
CHeroHandler ( ) ; //c-tor
~ CHeroHandler ( ) ; //d-tor
2009-02-09 16:50:32 +02:00
2012-11-20 20:53:45 +03:00
/**
* Gets a list of default allowed heroes .
*
* TODO Proposal for hero modding : Replace hero id with a unique machine readable hero name and
* create a JSON config file or merge it with a existing config file which describes which heroes can be used for
* random map generation / map editor ( default map settings ) . ( Gelu , . . . should be excluded )
*
2013-01-06 22:30:12 +03:00
* @ return a list of allowed heroes , the index is the hero id and the value either 0 for not allowed or 1 for allowed
2012-11-20 20:53:45 +03:00
*/
2013-02-05 00:58:42 +03:00
std : : vector < bool > getDefaultAllowedHeroes ( ) const ;
2012-11-20 20:53:45 +03:00
2013-01-06 22:30:12 +03:00
/**
* Gets a list of default allowed abilities . OH3 abilities / skills are all allowed by default .
*
2013-02-05 00:58:42 +03:00
* @ return a list of allowed abilities , the index is the ability id
2013-01-06 22:30:12 +03:00
*/
2013-02-05 00:58:42 +03:00
std : : vector < bool > getDefaultAllowedAbilities ( ) const ;
2013-01-06 22:30:12 +03:00
2009-02-09 16:50:32 +02:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2012-12-14 18:32:53 +03:00
h & classes & heroes & expPerLevel & ballistics & terrCosts ;
2012-05-18 23:50:16 +03:00
h & obstacles & absoluteObstacles ;
2009-02-09 16:50:32 +02:00
}
} ;