2024-10-11 18:30:16 +02:00
/*
* CHeroClass . cpp , 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
*
*/
# include "StdInc.h"
# include "CHeroClass.h"
# include "../faction/CFaction.h"
# include "../../VCMI_Lib.h"
# include "../../texts/CGeneralTextHandler.h"
# include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN
SecondarySkill CHeroClass : : chooseSecSkill ( const std : : set < SecondarySkill > & possibles , vstd : : RNG & rand ) const //picks secondary skill out from given possibilities
{
assert ( ! possibles . empty ( ) ) ;
2024-11-17 19:55:09 +02:00
std : : vector < int > weights ;
std : : vector < SecondarySkill > skills ;
2024-10-11 18:30:16 +02:00
for ( const auto & possible : possibles )
{
2024-11-17 19:55:09 +02:00
skills . push_back ( possible ) ;
2024-10-11 18:30:16 +02:00
if ( secSkillProbability . count ( possible ) ! = 0 )
2024-11-19 16:39:40 +02:00
{
int weight = secSkillProbability . at ( possible ) ;
weights . push_back ( std : : max ( 1 , weight ) ) ;
}
2024-11-17 19:55:09 +02:00
else
weights . push_back ( 1 ) ; // H3 behavior - banned skills have minimal (1) chance to be picked
2024-10-11 18:30:16 +02:00
}
2024-11-17 19:55:09 +02:00
int selectedIndex = RandomGeneratorUtil : : nextItemWeighted ( weights , rand ) ;
return skills . at ( selectedIndex ) ;
2024-10-11 18:30:16 +02:00
}
bool CHeroClass : : isMagicHero ( ) const
{
return affinity = = MAGIC ;
}
int CHeroClass : : tavernProbability ( FactionID targetFaction ) const
{
auto it = selectionProbability . find ( targetFaction ) ;
if ( it ! = selectionProbability . end ( ) )
return it - > second ;
return 0 ;
}
EAlignment CHeroClass : : getAlignment ( ) const
{
return faction . toEntity ( VLC ) - > getAlignment ( ) ;
}
int32_t CHeroClass : : getIndex ( ) const
{
return id . getNum ( ) ;
}
int32_t CHeroClass : : getIconIndex ( ) const
{
return getIndex ( ) ;
}
std : : string CHeroClass : : getJsonKey ( ) const
{
return modScope + ' : ' + identifier ;
}
std : : string CHeroClass : : getModScope ( ) const
{
return modScope ;
}
HeroClassID CHeroClass : : getId ( ) const
{
return id ;
}
void CHeroClass : : registerIcons ( const IconRegistar & cb ) const
{
}
std : : string CHeroClass : : getNameTranslated ( ) const
{
return VLC - > generaltexth - > translate ( getNameTextID ( ) ) ;
}
std : : string CHeroClass : : getNameTextID ( ) const
{
return TextIdentifier ( " heroClass " , modScope , identifier , " name " ) . get ( ) ;
}
void CHeroClass : : updateFrom ( const JsonNode & data )
{
//TODO: CHeroClass::updateFrom
}
void CHeroClass : : serializeJson ( JsonSerializeFormat & handler )
{
}
CHeroClass : : CHeroClass ( ) :
faction ( 0 ) ,
affinity ( 0 ) ,
defaultTavernChance ( 0 )
{
}
VCMI_LIB_NAMESPACE_END