1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Split CHeroHandler.cpp/.h into 1 file per class

All parts of CHeroHandler.cpp are now in lib/entities/hero
Adjusted includes to use new paths
No functionality changes
This commit is contained in:
Ivan Savenko 2024-10-11 16:30:16 +00:00
parent 7866179a01
commit 10ad0fc760
91 changed files with 867 additions and 730 deletions

View File

@ -17,7 +17,6 @@
#include "../../lib/mapObjects/ObjectTemplate.h"
#include "../../lib/mapObjects/CGHeroInstance.h"
#include "../../lib/CConfigHandler.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/IGameSettings.h"
#include "../../lib/gameState/CGameState.h"
#include "../../lib/serializer/CTypeList.h"

View File

@ -14,7 +14,6 @@
#include "../../lib/UnlockGuard.h"
#include "../../lib/CConfigHandler.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/mapObjects/MapObjects.h"
#include "../../lib/mapping/CMapDefines.h"
#include "../../lib/gameState/QuestInfo.h"

View File

@ -11,7 +11,6 @@
#include "../StdInc.h"
#include "../Engine/Nullkiller.h"
#include "../../../lib/mapObjects/MapObjects.h"
#include "../../../lib/CHeroHandler.h"
#include "../../../lib/IGameSettings.h"
namespace NKAI

View File

@ -15,7 +15,6 @@
#include "../../lib/UnlockGuard.h"
#include "../../lib/CConfigHandler.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/mapObjects/CGTownInstance.h"
#include "../../lib/mapObjects/CQuest.h"
#include "../../lib/mapping/CMapDefines.h"

View File

@ -12,7 +12,6 @@
#include "../../lib/GameConstants.h"
#include "../../lib/VCMI_Lib.h"
#include "../../lib/CCreatureHandler.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/mapObjects/CompoundMapObjectID.h"
#include "../../lib/mapObjectConstructors/AObjectTypeHandler.h"
#include "../../lib/mapObjects/CGHeroInstance.h"

View File

@ -20,7 +20,6 @@
#include "../../lib/mapObjects/MapObjects.h"
#include "../../lib/mapObjects/ObjectTemplate.h"
#include "../../lib/CConfigHandler.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/IGameSettings.h"
#include "../../lib/gameState/CGameState.h"
#include "../../lib/bonuses/Limiters.h"

View File

@ -18,7 +18,6 @@
#include "lib/mapObjects/CGHeroInstance.h"
#include "lib/mapObjects/CGTownInstance.h"
#include "lib/texts/CGeneralTextHandler.h"
#include "lib/CHeroHandler.h"
#include "lib/CArtHandler.h"
#include "lib/GameConstants.h"
#include "lib/CPlayerState.h"

View File

@ -67,7 +67,6 @@
#include "../lib/CConfigHandler.h"
#include "../lib/texts/CGeneralTextHandler.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CPlayerState.h"
#include "../lib/CRandomGenerator.h"
#include "../lib/CStack.h"

View File

@ -36,7 +36,6 @@
#include "../lib/modding/CModHandler.h"
#include "../lib/modding/ContentTypeHandler.h"
#include "../lib/modding/ModUtility.h"
#include "../lib/CHeroHandler.h"
#include "../lib/VCMIDirs.h"
#include "../lib/logging/VisualLogger.h"
#include "../lib/serializer/Connection.h"

View File

@ -32,7 +32,6 @@
#include "../lib/filesystem/FileInfo.h"
#include "../lib/serializer/Connection.h"
#include "../lib/texts/CGeneralTextHandler.h"
#include "../lib/CHeroHandler.h"
#include "../lib/VCMI_Lib.h"
#include "../lib/mapping/CMap.h"
#include "../lib/VCMIDirs.h"

View File

@ -29,7 +29,6 @@
#include "../render/Colors.h"
#include "../../lib/texts/CGeneralTextHandler.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/IGameSettings.h"
#include "../../lib/mapObjects/CGHeroInstance.h"
#include "../../lib/mapObjects/CGTownInstance.h"

View File

@ -39,7 +39,6 @@
#include "../../lib/CStack.h"
#include "../../lib/CConfigHandler.h"
#include "../../lib/texts/CGeneralTextHandler.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/gameState/InfoAboutArmy.h"
#include "../../lib/mapObjects/CGTownInstance.h"
#include "../../lib/networkPacks/PacksForClientBattle.h"

View File

@ -50,10 +50,11 @@
#include "../../lib/CStack.h"
#include "../../lib/CConfigHandler.h"
#include "../../lib/CCreatureHandler.h"
#include "../../lib/entities/hero/CHeroClass.h"
#include "../../lib/entities/hero/CHero.h"
#include "../../lib/gameState/InfoAboutArmy.h"
#include "../../lib/texts/CGeneralTextHandler.h"
#include "../../lib/texts/TextOperations.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/StartInfo.h"
#include "../../lib/mapObjects/CGTownInstance.h"
#include "../../lib/networkPacks/PacksForClientBattle.h"

View File

@ -41,7 +41,6 @@
#include "../../lib/CConfigHandler.h"
#include "../../lib/CCreatureHandler.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/CSkillHandler.h"
#include "../../lib/StartInfo.h"
#include "../../lib/entities/building/CBuilding.h"
@ -49,6 +48,7 @@
#include "../../lib/entities/faction/CFaction.h"
#include "../../lib/entities/faction/CTown.h"
#include "../../lib/entities/faction/CTownHandler.h"
#include "../../lib/entities/hero/CHeroHandler.h"
#include "../../lib/filesystem/Filesystem.h"
#include "../../lib/texts/CGeneralTextHandler.h"

View File

@ -43,7 +43,6 @@
#include "../render/IFont.h"
#include "../render/IRenderHandler.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/CRandomGenerator.h"
#include "../../lib/CThreadHelper.h"
#include "../../lib/filesystem/Filesystem.h"

View File

@ -39,12 +39,13 @@
#include "../../lib/entities/faction/CFaction.h"
#include "../../lib/entities/faction/CTown.h"
#include "../../lib/entities/faction/CTownHandler.h"
#include "../../lib/entities/hero/CHeroHandler.h"
#include "../../lib/entities/hero/CHeroClass.h"
#include "../../lib/filesystem/Filesystem.h"
#include "../../lib/networkPacks/PacksForLobby.h"
#include "../../lib/texts/CGeneralTextHandler.h"
#include "../../lib/CArtHandler.h"
#include "../../lib/CConfigHandler.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/mapping/CMapInfo.h"
#include "../../lib/mapping/CMapHeader.h"

View File

@ -37,7 +37,6 @@
#include "../../lib/spells/CSpellHandler.h"
#include "../../lib/CConfigHandler.h"
#include "../../lib/CSkillHandler.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/CCreatureHandler.h"
#include "../../lib/campaign/CampaignHandler.h"

View File

@ -28,7 +28,6 @@
#include "../lib/modding/CModHandler.h"
#include "../lib/modding/ModScope.h"
#include "../lib/VCMI_Lib.h"
#include "../lib/CHeroHandler.h"
#include <SDL_surface.h>

View File

@ -12,9 +12,6 @@
#include "Images.h"
#include <vcmi/spells/Service.h>
#include <vcmi/spells/Spell.h>
#include "../gui/CGuiHandler.h"
#include "../gui/CursorHandler.h"
#include "../gui/TextAlignment.h"
@ -29,7 +26,6 @@
#include "../CGameInfo.h"
#include "../../lib/ArtifactUtils.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/entities/building/CBuilding.h"
#include "../../lib/entities/faction/CFaction.h"
#include "../../lib/entities/faction/CTown.h"
@ -42,6 +38,11 @@
#include "../../lib/CArtHandler.h"
#include "../../lib/CArtifactInstance.h"
#include <vcmi/spells/Service.h>
#include <vcmi/spells/Spell.h>
#include <vcmi/HeroTypeService.h>
#include <vcmi/HeroType.h>
CComponent::CComponent(ComponentType Type, ComponentSubType Subtype, std::optional<int32_t> Val, ESize imageSize, EFonts font)
{
init(Type, Subtype, Val, imageSize, font, "");

View File

@ -23,9 +23,9 @@
#include "../../../CCallback.h"
#include "../../../lib/entities/hero/CHeroHandler.h"
#include "../../../lib/texts/CGeneralTextHandler.h"
#include "../../../lib/mapObjects/CGHeroInstance.h"
#include "../../../lib/CHeroHandler.h"
#include "../../../lib/mapObjects/CGMarket.h"
CMarketBase::CMarketBase(const IMarket * market, const CGHeroInstance * hero)

View File

@ -31,7 +31,7 @@
#include "../../lib/CStack.h"
#include "../../lib/CBonusTypeHandler.h"
#include "../../lib/IGameSettings.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/entities/hero/CHeroHandler.h"
#include "../../lib/gameState/CGameState.h"
#include "../../lib/networkPacks/ArtifactLocation.h"
#include "../../lib/texts/CGeneralTextHandler.h"

View File

@ -29,8 +29,8 @@
#include "../../CCallback.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CSkillHandler.h"
#include "../lib/entities/hero/CHeroHandler.h"
#include "../lib/filesystem/Filesystem.h"
#include "../lib/mapObjects/CGHeroInstance.h"
#include "../lib/texts/CGeneralTextHandler.h"

View File

@ -24,9 +24,10 @@
#include "../widgets/GraphicalPrimitiveCanvas.h"
#include "../../lib/IGameSettings.h"
#include "../../lib/entities/hero/CHeroHandler.h"
#include "../../lib/entities/hero/CHeroClass.h"
#include "../../lib/texts/CGeneralTextHandler.h"
#include "../../lib/CCreatureHandler.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/CSkillHandler.h"
#include "../../lib/spells/CSpellHandler.h"

View File

@ -35,11 +35,11 @@
#include "../lib/ArtifactUtils.h"
#include "../lib/CArtHandler.h"
#include "../lib/CConfigHandler.h"
#include "../lib/entities/hero/CHeroHandler.h"
#include "../lib/texts/CGeneralTextHandler.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CSkillHandler.h"
#include "../lib/mapObjects/CGHeroInstance.h"
#include "../../lib/networkPacks/ArtifactLocation.h"
#include "../lib/networkPacks/ArtifactLocation.h"
void CHeroSwitcher::clickPressed(const Point & cursorPosition)
{

View File

@ -33,8 +33,8 @@
#include "../../lib/CConfigHandler.h"
#include "../../lib/CCreatureHandler.h"
#include "../../lib/entities/hero/CHeroHandler.h"
#include "../../lib/texts/CGeneralTextHandler.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/IGameSettings.h"
#include "../../lib/CSkillHandler.h"
#include "../../lib/StartInfo.h"

View File

@ -44,6 +44,7 @@
#include "../lib/entities/building/CBuilding.h"
#include "../lib/entities/faction/CTownHandler.h"
#include "../lib/entities/hero/CHeroHandler.h"
#include "../lib/mapObjectConstructors/CObjectClassesHandler.h"
#include "../lib/mapObjectConstructors/CommonConstructors.h"
#include "../lib/mapObjects/CGHeroInstance.h"
@ -53,7 +54,6 @@
#include "../lib/gameState/SThievesGuildInfo.h"
#include "../lib/gameState/TavernHeroesPool.h"
#include "../lib/texts/CGeneralTextHandler.h"
#include "../lib/CHeroHandler.h"
#include "../lib/IGameSettings.h"
#include "ConditionalWait.h"
#include "../lib/CRandomGenerator.h"

View File

@ -15,12 +15,12 @@
#include "CCreatureHandler.h"
#include "VCMI_Lib.h"
#include "IGameSettings.h"
#include "entities/hero/CHeroHandler.h"
#include "mapObjects/CGHeroInstance.h"
#include "modding/ModScope.h"
#include "IGameCallback.h"
#include "texts/CGeneralTextHandler.h"
#include "spells/CSpellHandler.h"
#include "CHeroHandler.h"
#include "IBonusTypeHandler.h"
#include "serializer/JsonSerializeFormat.h"

View File

@ -1,221 +0,0 @@
/*
* 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
*
*/
#pragma once
#include <vcmi/HeroClass.h>
#include <vcmi/HeroClassService.h>
#include <vcmi/HeroType.h>
#include <vcmi/HeroTypeService.h>
#include "ConstTransitivePtr.h"
#include "GameConstants.h"
#include "bonuses/Bonus.h"
#include "bonuses/BonusList.h"
#include "IHandlerBase.h"
#include "filesystem/ResourcePath.h"
VCMI_LIB_NAMESPACE_BEGIN
namespace vstd
{
class RNG;
}
class CHeroClass;
class CGHeroInstance;
struct BattleHex;
class JsonNode;
class JsonSerializeFormat;
class BattleField;
enum class EHeroGender : int8_t
{
DEFAULT = -1, // from h3m, instance has same gender as hero type
MALE = 0,
FEMALE = 1,
};
class DLL_LINKAGE CHero : public HeroType
{
friend class CHeroHandler;
HeroTypeID ID;
std::string identifier;
std::string modScope;
public:
struct InitialArmyStack
{
ui32 minAmount;
ui32 maxAmount;
CreatureID creature;
};
si32 imageIndex = 0;
std::vector<InitialArmyStack> initialArmy;
const CHeroClass * heroClass = nullptr;
std::vector<std::pair<SecondarySkill, ui8> > secSkillsInit; //initial secondary skills; first - ID of skill, second - level of skill (1 - basic, 2 - adv., 3 - expert)
BonusList specialty;
std::set<SpellID> spells;
bool haveSpellBook = false;
bool special = false; // hero is special and won't be placed in game (unless preset on map), e.g. campaign heroes
bool onlyOnWaterMap; // hero will be placed only if the map contains water
bool onlyOnMapWithoutWater; // hero will be placed only if the map does not contain water
EHeroGender gender = EHeroGender::MALE; // default sex: 0=male, 1=female
/// Graphics
std::string iconSpecSmall;
std::string iconSpecLarge;
std::string portraitSmall;
std::string portraitLarge;
AnimationPath battleImage;
CHero();
virtual ~CHero();
int32_t getIndex() const override;
int32_t getIconIndex() const override;
std::string getJsonKey() const override;
std::string getModScope() const override;
HeroTypeID getId() const override;
void registerIcons(const IconRegistar & cb) const override;
std::string getNameTranslated() const override;
std::string getBiographyTranslated() const override;
std::string getSpecialtyNameTranslated() const override;
std::string getSpecialtyDescriptionTranslated() const override;
std::string getSpecialtyTooltipTranslated() const override;
std::string getNameTextID() const override;
std::string getBiographyTextID() const override;
std::string getSpecialtyNameTextID() const override;
std::string getSpecialtyDescriptionTextID() const override;
std::string getSpecialtyTooltipTextID() const override;
void updateFrom(const JsonNode & data);
void serializeJson(JsonSerializeFormat & handler);
};
class DLL_LINKAGE CHeroClass : public HeroClass
{
friend class CHeroClassHandler;
HeroClassID id; // use getId instead
std::string modScope;
std::string identifier; // use getJsonKey instead
public:
enum EClassAffinity
{
MIGHT,
MAGIC
};
//double aggression; // not used in vcmi.
FactionID faction;
ui8 affinity; // affinity, using EClassAffinity enum
// default chance for hero of specific class to appear in tavern, if field "tavern" was not set
// resulting chance = sqrt(town.chance * heroClass.chance)
ui32 defaultTavernChance;
CreatureID commander;
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::map<SecondarySkill, int> secSkillProbability; //probabilities of gaining secondary skills (out of 112), in id order
std::map<FactionID, int> selectionProbability; //probability of selection in towns
AnimationPath imageBattleMale;
AnimationPath imageBattleFemale;
std::string imageMapMale;
std::string imageMapFemale;
CHeroClass();
int32_t getIndex() const override;
int32_t getIconIndex() const override;
std::string getJsonKey() const override;
std::string getModScope() const override;
HeroClassID getId() const override;
void registerIcons(const IconRegistar & cb) const override;
std::string getNameTranslated() const override;
std::string getNameTextID() const override;
bool isMagicHero() const;
SecondarySkill chooseSecSkill(const std::set<SecondarySkill> & possibles, vstd::RNG & rand) const; //picks secondary skill out from given possibilities
void updateFrom(const JsonNode & data);
void serializeJson(JsonSerializeFormat & handler);
EAlignment getAlignment() const;
int tavernProbability(FactionID faction) const;
};
class DLL_LINKAGE CHeroClassHandler : public CHandlerBase<HeroClassID, HeroClass, CHeroClass, HeroClassService>
{
void fillPrimarySkillData(const JsonNode & node, CHeroClass * heroClass, PrimarySkill pSkill) const;
public:
std::vector<JsonNode> loadLegacyData() override;
void afterLoadFinalization() override;
~CHeroClassHandler();
protected:
const std::vector<std::string> & getTypeNames() const override;
std::shared_ptr<CHeroClass> loadFromJson(const std::string & scope, const JsonNode & node, const std::string & identifier, size_t index) override;
};
class DLL_LINKAGE CHeroHandler : public CHandlerBase<HeroTypeID, HeroType, CHero, HeroTypeService>
{
/// expPerLEvel[i] is amount of exp needed to reach level i;
/// consists of 196 values. Any higher levels require experience larger that TExpType can hold
std::vector<TExpType> expPerLevel;
/// helpers for loading to avoid huge load functions
void loadHeroArmy(CHero * hero, const JsonNode & node) const;
void loadHeroSkills(CHero * hero, const JsonNode & node) const;
void loadHeroSpecialty(CHero * hero, const JsonNode & node);
void loadExperience();
std::vector<std::function<void()>> callAfterLoadFinalization;
public:
ui32 level(TExpType experience) const; //calculates level corresponding to given experience amount
TExpType reqExp(ui32 level) const; //calculates experience required for given level
ui32 maxSupportedLevel() const;
std::vector<JsonNode> loadLegacyData() override;
void beforeValidate(JsonNode & object) override;
void loadObject(std::string scope, std::string name, const JsonNode & data) override;
void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
void afterLoadFinalization() override;
CHeroHandler();
~CHeroHandler();
std::set<HeroTypeID> getDefaultAllowed() const;
protected:
const std::vector<std::string> & getTypeNames() const override;
std::shared_ptr<CHero> loadFromJson(const std::string & scope, const JsonNode & node, const std::string & identifier, size_t index) override;
};
VCMI_LIB_NAMESPACE_END

View File

@ -87,6 +87,10 @@ set(lib_MAIN_SRCS
entities/faction/CFaction.cpp
entities/faction/CTown.cpp
entities/faction/CTownHandler.cpp
entities/hero/CHero.cpp
entities/hero/CHeroClass.cpp
entities/hero/CHeroClassHandler.cpp
entities/hero/CHeroHandler.cpp
events/ApplyDamage.cpp
events/GameResumed.cpp
@ -270,7 +274,6 @@ set(lib_MAIN_SRCS
CCreatureSet.cpp
CGameInfoCallback.cpp
CGameInterface.cpp
CHeroHandler.cpp
CPlayerState.cpp
CRandomGenerator.cpp
CScriptingModule.cpp
@ -458,6 +461,11 @@ set(lib_MAIN_HEADERS
entities/faction/CFaction.h
entities/faction/CTown.h
entities/faction/CTownHandler.h
entities/hero/CHero.h
entities/hero/CHeroClass.h
entities/hero/CHeroClassHandler.h
entities/hero/CHeroHandler.h
entities/hero/EHeroGender.h
events/ApplyDamage.h
events/GameResumed.h
@ -683,7 +691,6 @@ set(lib_MAIN_HEADERS
CCreatureSet.h
CGameInfoCallback.h
CGameInterface.h
CHeroHandler.h
ConstTransitivePtr.h
Color.h
CPlayerState.h

View File

@ -10,7 +10,6 @@
#include "StdInc.h"
#include "IGameCallback.h"
#include "CHeroHandler.h" // for CHeroHandler
#include "spells/CSpellHandler.h"// for CSpell
#include "CSkillHandler.h"// for CSkill
#include "CBonusTypeHandler.h"
@ -20,6 +19,7 @@
#include "bonuses/Propagators.h"
#include "bonuses/Updaters.h"
#include "entities/building/CBuilding.h"
#include "entities/hero/CHero.h"
#include "networkPacks/ArtifactLocation.h"
#include "serializer/CLoadFile.h"
#include "serializer/CSaveFile.h"

View File

@ -11,10 +11,10 @@
#include "StartInfo.h"
#include "texts/CGeneralTextHandler.h"
#include "CHeroHandler.h"
#include "VCMI_Lib.h"
#include "entities/faction/CFaction.h"
#include "entities/faction/CTownHandler.h"
#include "entities/hero/CHeroHandler.h"
#include "rmg/CMapGenOptions.h"
#include "mapping/CMapInfo.h"
#include "campaign/CampaignState.h"

View File

@ -14,7 +14,6 @@
#include "CArtHandler.h"
#include "CBonusTypeHandler.h"
#include "CCreatureHandler.h"
#include "CHeroHandler.h"
#include "CConfigHandler.h"
#include "RoadHandler.h"
#include "RiverHandler.h"
@ -23,6 +22,8 @@
#include "spells/effects/Registry.h"
#include "CSkillHandler.h"
#include "entities/faction/CTownHandler.h"
#include "entities/hero/CHeroClassHandler.h"
#include "entities/hero/CHeroHandler.h"
#include "texts/CGeneralTextHandler.h"
#include "modding/CModHandler.h"
#include "modding/CModInfo.h"

View File

@ -15,7 +15,6 @@
#include "bonuses/Limiters.h"
#include "bonuses/Updaters.h"
#include "../CStack.h"
#include "../CHeroHandler.h"
#include "../entities/building/TownFortifications.h"
#include "../filesystem/Filesystem.h"
#include "../mapObjects/CGTownInstance.h"

View File

@ -9,7 +9,6 @@
*/
#include "StdInc.h"
#include "CObstacleInstance.h"
#include "../CHeroHandler.h"
#include "../ObstacleHandler.h"
#include "../VCMI_Lib.h"

View File

@ -14,18 +14,18 @@
#include "Updaters.h"
#include "Propagators.h"
#include "../VCMI_Lib.h"
#include "../spells/CSpellHandler.h"
#include "../CArtHandler.h"
#include "../CCreatureHandler.h"
#include "../CCreatureSet.h"
#include "../CHeroHandler.h"
#include "../texts/CGeneralTextHandler.h"
#include "../CSkillHandler.h"
#include "../CArtHandler.h"
#include "../TerrainHandler.h"
#include "../constants/StringConstants.h"
#include "../VCMI_Lib.h"
#include "../battle/BattleInfo.h"
#include "../constants/StringConstants.h"
#include "../entities/hero/CHero.h"
#include "../modding/ModUtility.h"
#include "../spells/CSpellHandler.h"
#include "../texts/CGeneralTextHandler.h"
VCMI_LIB_NAMESPACE_BEGIN

View File

@ -17,7 +17,6 @@
#include "../spells/CSpellHandler.h"
#include "../CCreatureHandler.h"
#include "../CCreatureSet.h"
#include "../CHeroHandler.h"
#include "../texts/CGeneralTextHandler.h"
#include "../CSkillHandler.h"
#include "../CStack.h"

View File

@ -29,12 +29,13 @@
#include "modding/IdentifierStorage.h"
#include "modding/ModScope.h"
#include "VCMI_Lib.h"
#include "CHeroHandler.h"
#include "CArtHandler.h"//todo: remove
#include "CCreatureHandler.h"//todo: remove
#include "spells/CSpellHandler.h" //todo: remove
#include "CSkillHandler.h"//todo: remove
#include "entities/faction/CFaction.h"
#include "entities/hero/CHero.h"
#include "entities/hero/CHeroClass.h"
#include "mapObjectConstructors/AObjectTypeHandler.h"
#include "constants/StringConstants.h"
#include "texts/CGeneralTextHandler.h"

View File

@ -13,9 +13,9 @@
#include "CTown.h"
#include "CFaction.h"
#include "../building/CBuilding.h"
#include "../hero/CHeroClassHandler.h"
#include "../../CCreatureHandler.h"
#include "../../CHeroHandler.h"
#include "../../IGameSettings.h"
#include "../../TerrainHandler.h"
#include "../../VCMI_Lib.h"

114
lib/entities/hero/CHero.cpp Normal file
View File

@ -0,0 +1,114 @@
/*
* CHero.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 "CHero.h"
#include "../../VCMI_Lib.h"
#include "../../texts/CGeneralTextHandler.h"
VCMI_LIB_NAMESPACE_BEGIN
CHero::CHero() = default;
CHero::~CHero() = default;
int32_t CHero::getIndex() const
{
return ID.getNum();
}
int32_t CHero::getIconIndex() const
{
return imageIndex;
}
std::string CHero::getJsonKey() const
{
return modScope + ':' + identifier;
}
std::string CHero::getModScope() const
{
return modScope;
}
HeroTypeID CHero::getId() const
{
return ID;
}
std::string CHero::getNameTranslated() const
{
return VLC->generaltexth->translate(getNameTextID());
}
std::string CHero::getBiographyTranslated() const
{
return VLC->generaltexth->translate(getBiographyTextID());
}
std::string CHero::getSpecialtyNameTranslated() const
{
return VLC->generaltexth->translate(getSpecialtyNameTextID());
}
std::string CHero::getSpecialtyDescriptionTranslated() const
{
return VLC->generaltexth->translate(getSpecialtyDescriptionTextID());
}
std::string CHero::getSpecialtyTooltipTranslated() const
{
return VLC->generaltexth->translate(getSpecialtyTooltipTextID());
}
std::string CHero::getNameTextID() const
{
return TextIdentifier("hero", modScope, identifier, "name").get();
}
std::string CHero::getBiographyTextID() const
{
return TextIdentifier("hero", modScope, identifier, "biography").get();
}
std::string CHero::getSpecialtyNameTextID() const
{
return TextIdentifier("hero", modScope, identifier, "specialty", "name").get();
}
std::string CHero::getSpecialtyDescriptionTextID() const
{
return TextIdentifier("hero", modScope, identifier, "specialty", "description").get();
}
std::string CHero::getSpecialtyTooltipTextID() const
{
return TextIdentifier("hero", modScope, identifier, "specialty", "tooltip").get();
}
void CHero::registerIcons(const IconRegistar & cb) const
{
cb(getIconIndex(), 0, "UN32", iconSpecSmall);
cb(getIconIndex(), 0, "UN44", iconSpecLarge);
cb(getIconIndex(), 0, "PORTRAITSLARGE", portraitLarge);
cb(getIconIndex(), 0, "PORTRAITSSMALL", portraitSmall);
}
void CHero::updateFrom(const JsonNode & data)
{
//todo: CHero::updateFrom
}
void CHero::serializeJson(JsonSerializeFormat & handler)
{
}
VCMI_LIB_NAMESPACE_END

87
lib/entities/hero/CHero.h Normal file
View File

@ -0,0 +1,87 @@
/*
* CHero.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
*
*/
#pragma once
#include <vcmi/HeroType.h>
#include "EHeroGender.h"
#include "../../bonuses/BonusList.h"
#include "../../constants/EntityIdentifiers.h"
#include "../../filesystem/ResourcePath.h"
VCMI_LIB_NAMESPACE_BEGIN
class DLL_LINKAGE CHero : public HeroType
{
friend class CHeroHandler;
HeroTypeID ID;
std::string identifier;
std::string modScope;
public:
struct InitialArmyStack
{
ui32 minAmount;
ui32 maxAmount;
CreatureID creature;
};
si32 imageIndex = 0;
std::vector<InitialArmyStack> initialArmy;
const CHeroClass * heroClass = nullptr;
//initial secondary skills; first - ID of skill, second - level of skill (1 - basic, 2 - adv., 3 - expert)
std::vector<std::pair<SecondarySkill, ui8>> secSkillsInit;
BonusList specialty;
std::set<SpellID> spells;
bool haveSpellBook = false;
bool special = false; // hero is special and won't be placed in game (unless preset on map), e.g. campaign heroes
bool onlyOnWaterMap; // hero will be placed only if the map contains water
bool onlyOnMapWithoutWater; // hero will be placed only if the map does not contain water
EHeroGender gender = EHeroGender::MALE; // default sex: 0=male, 1=female
/// Graphics
std::string iconSpecSmall;
std::string iconSpecLarge;
std::string portraitSmall;
std::string portraitLarge;
AnimationPath battleImage;
CHero();
virtual ~CHero();
int32_t getIndex() const override;
int32_t getIconIndex() const override;
std::string getJsonKey() const override;
std::string getModScope() const override;
HeroTypeID getId() const override;
void registerIcons(const IconRegistar & cb) const override;
std::string getNameTranslated() const override;
std::string getBiographyTranslated() const override;
std::string getSpecialtyNameTranslated() const override;
std::string getSpecialtyDescriptionTranslated() const override;
std::string getSpecialtyTooltipTranslated() const override;
std::string getNameTextID() const override;
std::string getBiographyTextID() const override;
std::string getSpecialtyNameTextID() const override;
std::string getSpecialtyDescriptionTextID() const override;
std::string getSpecialtyTooltipTextID() const override;
void updateFrom(const JsonNode & data);
void serializeJson(JsonSerializeFormat & handler);
};
VCMI_LIB_NAMESPACE_END

View File

@ -0,0 +1,126 @@
/*
* 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());
if (possibles.size() == 1)
return *possibles.begin();
int totalProb = 0;
for(const auto & possible : possibles)
if (secSkillProbability.count(possible) != 0)
totalProb += secSkillProbability.at(possible);
if (totalProb == 0) // may trigger if set contains only banned skills (0 probability)
return *RandomGeneratorUtil::nextItem(possibles, rand);
auto ran = rand.nextInt(totalProb - 1);
for(const auto & possible : possibles)
{
if (secSkillProbability.count(possible) != 0)
ran -= secSkillProbability.at(possible);
if(ran < 0)
return possible;
}
assert(0); // should not be possible
return *possibles.begin();
}
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

View File

@ -0,0 +1,85 @@
/*
* CHeroClass.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
*
*/
#pragma once
#include <vcmi/HeroClass.h>
#include "../../constants/EntityIdentifiers.h"
#include "../../constants/Enumerations.h"
#include "../../filesystem/ResourcePath.h"
VCMI_LIB_NAMESPACE_BEGIN
namespace vstd
{
class RNG;
}
class DLL_LINKAGE CHeroClass : public HeroClass
{
friend class CHeroClassHandler;
HeroClassID id; // use getId instead
std::string modScope;
std::string identifier; // use getJsonKey instead
public:
enum EClassAffinity
{
MIGHT,
MAGIC
};
//double aggression; // not used in vcmi.
FactionID faction;
ui8 affinity; // affinity, using EClassAffinity enum
// default chance for hero of specific class to appear in tavern, if field "tavern" was not set
// resulting chance = sqrt(town.chance * heroClass.chance)
ui32 defaultTavernChance;
CreatureID commander;
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::map<SecondarySkill, int> secSkillProbability; //probabilities of gaining secondary skills (out of 112), in id order
std::map<FactionID, int> selectionProbability; //probability of selection in towns
AnimationPath imageBattleMale;
AnimationPath imageBattleFemale;
std::string imageMapMale;
std::string imageMapFemale;
CHeroClass();
int32_t getIndex() const override;
int32_t getIconIndex() const override;
std::string getJsonKey() const override;
std::string getModScope() const override;
HeroClassID getId() const override;
void registerIcons(const IconRegistar & cb) const override;
std::string getNameTranslated() const override;
std::string getNameTextID() const override;
bool isMagicHero() const;
SecondarySkill chooseSecSkill(const std::set<SecondarySkill> & possibles, vstd::RNG & rand) const; //picks secondary skill out from given possibilities
void updateFrom(const JsonNode & data);
void serializeJson(JsonSerializeFormat & handler);
EAlignment getAlignment() const;
int tavernProbability(FactionID faction) const;
};
VCMI_LIB_NAMESPACE_END

View File

@ -0,0 +1,226 @@
/*
* CHeroClassHandler.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 "CHeroClassHandler.h"
#include "CHeroClass.h"
#include "../faction/CTown.h"
#include "../faction/CTownHandler.h"
#include "../../CSkillHandler.h"
#include "../../IGameSettings.h"
#include "../../VCMI_Lib.h"
#include "../../constants/StringConstants.h"
#include "../../json/JsonNode.h"
#include "../../mapObjectConstructors/AObjectTypeHandler.h"
#include "../../mapObjectConstructors/CObjectClassesHandler.h"
#include "../../modding/IdentifierStorage.h"
#include "../../texts/CGeneralTextHandler.h"
#include "../../texts/CLegacyConfigParser.h"
VCMI_LIB_NAMESPACE_BEGIN
void CHeroClassHandler::fillPrimarySkillData(const JsonNode & node, CHeroClass * heroClass, PrimarySkill pSkill) const
{
const auto & skillName = NPrimarySkill::names[pSkill.getNum()];
auto currentPrimarySkillValue = static_cast<int>(node["primarySkills"][skillName].Integer());
int primarySkillLegalMinimum = VLC->engineSettings()->getVector(EGameSettings::HEROES_MINIMAL_PRIMARY_SKILLS)[pSkill.getNum()];
if(currentPrimarySkillValue < primarySkillLegalMinimum)
{
logMod->error("Hero class '%s' has incorrect initial value '%d' for skill '%s'. Value '%d' will be used instead.",
heroClass->getNameTranslated(), currentPrimarySkillValue, skillName, primarySkillLegalMinimum);
currentPrimarySkillValue = primarySkillLegalMinimum;
}
heroClass->primarySkillInitial.push_back(currentPrimarySkillValue);
heroClass->primarySkillLowLevel.push_back(static_cast<int>(node["lowLevelChance"][skillName].Float()));
heroClass->primarySkillHighLevel.push_back(static_cast<int>(node["highLevelChance"][skillName].Float()));
}
const std::vector<std::string> & CHeroClassHandler::getTypeNames() const
{
static const std::vector<std::string> typeNames = { "heroClass" };
return typeNames;
}
std::shared_ptr<CHeroClass> CHeroClassHandler::loadFromJson(const std::string & scope, const JsonNode & node, const std::string & identifier, size_t index)
{
assert(identifier.find(':') == std::string::npos);
assert(!scope.empty());
std::string affinityStr[2] = { "might", "magic" };
auto heroClass = std::make_shared<CHeroClass>();
heroClass->id = HeroClassID(index);
heroClass->identifier = identifier;
heroClass->modScope = scope;
heroClass->imageBattleFemale = AnimationPath::fromJson(node["animation"]["battle"]["female"]);
heroClass->imageBattleMale = AnimationPath::fromJson(node["animation"]["battle"]["male"]);
//MODS COMPATIBILITY FOR 0.96
heroClass->imageMapFemale = node["animation"]["map"]["female"].String();
heroClass->imageMapMale = node["animation"]["map"]["male"].String();
VLC->generaltexth->registerString(scope, heroClass->getNameTextID(), node["name"].String());
if (vstd::contains(affinityStr, node["affinity"].String()))
{
heroClass->affinity = vstd::find_pos(affinityStr, node["affinity"].String());
}
else
{
logGlobal->error("Mod '%s', hero class '%s': invalid affinity '%s'! Expected 'might' or 'magic'!", scope, identifier, node["affinity"].String());
heroClass->affinity = CHeroClass::MIGHT;
}
fillPrimarySkillData(node, heroClass.get(), PrimarySkill::ATTACK);
fillPrimarySkillData(node, heroClass.get(), PrimarySkill::DEFENSE);
fillPrimarySkillData(node, heroClass.get(), PrimarySkill::SPELL_POWER);
fillPrimarySkillData(node, heroClass.get(), PrimarySkill::KNOWLEDGE);
auto percentSumm = std::accumulate(heroClass->primarySkillLowLevel.begin(), heroClass->primarySkillLowLevel.end(), 0);
if(percentSumm <= 0)
logMod->error("Hero class %s has wrong lowLevelChance values: must be above zero!", heroClass->identifier, percentSumm);
percentSumm = std::accumulate(heroClass->primarySkillHighLevel.begin(), heroClass->primarySkillHighLevel.end(), 0);
if(percentSumm <= 0)
logMod->error("Hero class %s has wrong highLevelChance values: must be above zero!", heroClass->identifier, percentSumm);
for(auto skillPair : node["secondarySkills"].Struct())
{
int probability = static_cast<int>(skillPair.second.Integer());
VLC->identifiers()->requestIdentifier(skillPair.second.getModScope(), "skill", skillPair.first, [heroClass, probability](si32 skillID)
{
heroClass->secSkillProbability[skillID] = probability;
});
}
VLC->identifiers()->requestIdentifier ("creature", node["commander"],
[=](si32 commanderID)
{
heroClass->commander = CreatureID(commanderID);
});
heroClass->defaultTavernChance = static_cast<ui32>(node["defaultTavern"].Float());
for(const auto & tavern : node["tavern"].Struct())
{
int value = static_cast<int>(tavern.second.Float());
VLC->identifiers()->requestIdentifier(tavern.second.getModScope(), "faction", tavern.first,
[=](si32 factionID)
{
heroClass->selectionProbability[FactionID(factionID)] = value;
});
}
VLC->identifiers()->requestIdentifier("faction", node["faction"],
[=](si32 factionID)
{
heroClass->faction.setNum(factionID);
});
VLC->identifiers()->requestIdentifier(scope, "object", "hero", [=](si32 index)
{
JsonNode classConf = node["mapObject"];
classConf["heroClass"].String() = identifier;
if (!node["compatibilityIdentifiers"].isNull())
classConf["compatibilityIdentifiers"] = node["compatibilityIdentifiers"];
classConf.setModScope(scope);
VLC->objtypeh->loadSubObject(identifier, classConf, index, heroClass->getIndex());
});
return heroClass;
}
std::vector<JsonNode> CHeroClassHandler::loadLegacyData()
{
size_t dataSize = VLC->engineSettings()->getInteger(EGameSettings::TEXTS_HERO_CLASS);
objects.resize(dataSize);
std::vector<JsonNode> h3Data;
h3Data.reserve(dataSize);
CLegacyConfigParser parser(TextPath::builtin("DATA/HCTRAITS.TXT"));
parser.endLine(); // header
parser.endLine();
for (size_t i=0; i<dataSize; i++)
{
JsonNode entry;
entry["name"].String() = parser.readString();
parser.readNumber(); // unused aggression
for(const auto & name : NPrimarySkill::names)
entry["primarySkills"][name].Float() = parser.readNumber();
for(const auto & name : NPrimarySkill::names)
entry["lowLevelChance"][name].Float() = parser.readNumber();
for(const auto & name : NPrimarySkill::names)
entry["highLevelChance"][name].Float() = parser.readNumber();
for(const auto & name : NSecondarySkill::names)
entry["secondarySkills"][name].Float() = parser.readNumber();
for(const auto & name : NFaction::names)
entry["tavern"][name].Float() = parser.readNumber();
parser.endLine();
h3Data.push_back(entry);
}
return h3Data;
}
void CHeroClassHandler::afterLoadFinalization()
{
// for each pair <class, town> set selection probability if it was not set before in tavern entries
for(auto & heroClass : objects)
{
for(auto & faction : VLC->townh->objects)
{
if (!faction->town)
continue;
if (heroClass->selectionProbability.count(faction->getId()))
continue;
auto chance = static_cast<float>(heroClass->defaultTavernChance * faction->town->defaultTavernChance);
heroClass->selectionProbability[faction->getId()] = static_cast<int>(sqrt(chance) + 0.5); //FIXME: replace with std::round once MVS supports it
}
// set default probabilities for gaining secondary skills where not loaded previously
for(int skillID = 0; skillID < VLC->skillh->size(); skillID++)
{
if(heroClass->secSkillProbability.count(skillID) == 0)
{
const CSkill * skill = (*VLC->skillh)[SecondarySkill(skillID)];
logMod->trace("%s: no probability for %s, using default", heroClass->identifier, skill->getJsonKey());
heroClass->secSkillProbability[skillID] = skill->gainChance[heroClass->affinity];
}
}
}
for(const auto & hc : objects)
{
if(!hc->imageMapMale.empty())
{
JsonNode templ;
templ["animation"].String() = hc->imageMapMale;
VLC->objtypeh->getHandlerFor(Obj::HERO, hc->getIndex())->addTemplate(templ);
}
}
}
CHeroClassHandler::~CHeroClassHandler() = default;
VCMI_LIB_NAMESPACE_END

View File

@ -0,0 +1,37 @@
/*
* CHeroClassHandler.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
*
*/
#pragma once
#include <vcmi/HeroClassService.h>
#include "CHeroClass.h" // convenience include - users of handler generally also use its entity
#include "../../IHandlerBase.h"
#include "../../constants/EntityIdentifiers.h"
VCMI_LIB_NAMESPACE_BEGIN
class DLL_LINKAGE CHeroClassHandler : public CHandlerBase<HeroClassID, HeroClass, CHeroClass, HeroClassService>
{
void fillPrimarySkillData(const JsonNode & node, CHeroClass * heroClass, PrimarySkill pSkill) const;
public:
std::vector<JsonNode> loadLegacyData() override;
void afterLoadFinalization() override;
~CHeroClassHandler();
protected:
const std::vector<std::string> & getTypeNames() const override;
std::shared_ptr<CHeroClass> loadFromJson(const std::string & scope, const JsonNode & node, const std::string & identifier, size_t index) override;
};
VCMI_LIB_NAMESPACE_END

View File

@ -10,427 +10,22 @@
#include "StdInc.h"
#include "CHeroHandler.h"
#include "filesystem/Filesystem.h"
#include "VCMI_Lib.h"
#include "constants/StringConstants.h"
#include "battle/BattleHex.h"
#include "CCreatureHandler.h"
#include "IGameSettings.h"
#include "CSkillHandler.h"
#include "BattleFieldHandler.h"
#include "bonuses/Limiters.h"
#include "bonuses/Updaters.h"
#include "entities/faction/CFaction.h"
#include "entities/faction/CTown.h"
#include "entities/faction/CTownHandler.h"
#include "json/JsonBonus.h"
#include "json/JsonUtils.h"
#include "mapObjectConstructors/AObjectTypeHandler.h"
#include "mapObjectConstructors/CObjectClassesHandler.h"
#include "modding/IdentifierStorage.h"
#include "texts/CGeneralTextHandler.h"
#include "texts/CLegacyConfigParser.h"
#include "CHero.h"
#include <vstd/RNG.h>
#include "../../VCMI_Lib.h"
#include "../../constants/StringConstants.h"
#include "../../CCreatureHandler.h"
#include "../../IGameSettings.h"
#include "../../bonuses/Limiters.h"
#include "../../bonuses/Updaters.h"
#include "../../json/JsonBonus.h"
#include "../../json/JsonUtils.h"
#include "../../modding/IdentifierStorage.h"
#include "../../texts/CGeneralTextHandler.h"
#include "../../texts/CLegacyConfigParser.h"
VCMI_LIB_NAMESPACE_BEGIN
CHero::CHero() = default;
CHero::~CHero() = default;
int32_t CHero::getIndex() const
{
return ID.getNum();
}
int32_t CHero::getIconIndex() const
{
return imageIndex;
}
std::string CHero::getJsonKey() const
{
return modScope + ':' + identifier;
}
std::string CHero::getModScope() const
{
return modScope;
}
HeroTypeID CHero::getId() const
{
return ID;
}
std::string CHero::getNameTranslated() const
{
return VLC->generaltexth->translate(getNameTextID());
}
std::string CHero::getBiographyTranslated() const
{
return VLC->generaltexth->translate(getBiographyTextID());
}
std::string CHero::getSpecialtyNameTranslated() const
{
return VLC->generaltexth->translate(getSpecialtyNameTextID());
}
std::string CHero::getSpecialtyDescriptionTranslated() const
{
return VLC->generaltexth->translate(getSpecialtyDescriptionTextID());
}
std::string CHero::getSpecialtyTooltipTranslated() const
{
return VLC->generaltexth->translate(getSpecialtyTooltipTextID());
}
std::string CHero::getNameTextID() const
{
return TextIdentifier("hero", modScope, identifier, "name").get();
}
std::string CHero::getBiographyTextID() const
{
return TextIdentifier("hero", modScope, identifier, "biography").get();
}
std::string CHero::getSpecialtyNameTextID() const
{
return TextIdentifier("hero", modScope, identifier, "specialty", "name").get();
}
std::string CHero::getSpecialtyDescriptionTextID() const
{
return TextIdentifier("hero", modScope, identifier, "specialty", "description").get();
}
std::string CHero::getSpecialtyTooltipTextID() const
{
return TextIdentifier("hero", modScope, identifier, "specialty", "tooltip").get();
}
void CHero::registerIcons(const IconRegistar & cb) const
{
cb(getIconIndex(), 0, "UN32", iconSpecSmall);
cb(getIconIndex(), 0, "UN44", iconSpecLarge);
cb(getIconIndex(), 0, "PORTRAITSLARGE", portraitLarge);
cb(getIconIndex(), 0, "PORTRAITSSMALL", portraitSmall);
}
void CHero::updateFrom(const JsonNode & data)
{
//todo: CHero::updateFrom
}
void CHero::serializeJson(JsonSerializeFormat & handler)
{
}
SecondarySkill CHeroClass::chooseSecSkill(const std::set<SecondarySkill> & possibles, vstd::RNG & rand) const //picks secondary skill out from given possibilities
{
assert(!possibles.empty());
if (possibles.size() == 1)
return *possibles.begin();
int totalProb = 0;
for(const auto & possible : possibles)
if (secSkillProbability.count(possible) != 0)
totalProb += secSkillProbability.at(possible);
if (totalProb == 0) // may trigger if set contains only banned skills (0 probability)
return *RandomGeneratorUtil::nextItem(possibles, rand);
auto ran = rand.nextInt(totalProb - 1);
for(const auto & possible : possibles)
{
if (secSkillProbability.count(possible) != 0)
ran -= secSkillProbability.at(possible);
if(ran < 0)
return possible;
}
assert(0); // should not be possible
return *possibles.begin();
}
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 VLC->factions()->getById(faction)->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)
{
}
void CHeroClassHandler::fillPrimarySkillData(const JsonNode & node, CHeroClass * heroClass, PrimarySkill pSkill) const
{
const auto & skillName = NPrimarySkill::names[pSkill.getNum()];
auto currentPrimarySkillValue = static_cast<int>(node["primarySkills"][skillName].Integer());
int primarySkillLegalMinimum = VLC->engineSettings()->getVector(EGameSettings::HEROES_MINIMAL_PRIMARY_SKILLS)[pSkill.getNum()];
if(currentPrimarySkillValue < primarySkillLegalMinimum)
{
logMod->error("Hero class '%s' has incorrect initial value '%d' for skill '%s'. Value '%d' will be used instead.",
heroClass->getNameTranslated(), currentPrimarySkillValue, skillName, primarySkillLegalMinimum);
currentPrimarySkillValue = primarySkillLegalMinimum;
}
heroClass->primarySkillInitial.push_back(currentPrimarySkillValue);
heroClass->primarySkillLowLevel.push_back(static_cast<int>(node["lowLevelChance"][skillName].Float()));
heroClass->primarySkillHighLevel.push_back(static_cast<int>(node["highLevelChance"][skillName].Float()));
}
const std::vector<std::string> & CHeroClassHandler::getTypeNames() const
{
static const std::vector<std::string> typeNames = { "heroClass" };
return typeNames;
}
std::shared_ptr<CHeroClass> CHeroClassHandler::loadFromJson(const std::string & scope, const JsonNode & node, const std::string & identifier, size_t index)
{
assert(identifier.find(':') == std::string::npos);
assert(!scope.empty());
std::string affinityStr[2] = { "might", "magic" };
auto heroClass = std::make_shared<CHeroClass>();
heroClass->id = HeroClassID(index);
heroClass->identifier = identifier;
heroClass->modScope = scope;
heroClass->imageBattleFemale = AnimationPath::fromJson(node["animation"]["battle"]["female"]);
heroClass->imageBattleMale = AnimationPath::fromJson(node["animation"]["battle"]["male"]);
//MODS COMPATIBILITY FOR 0.96
heroClass->imageMapFemale = node["animation"]["map"]["female"].String();
heroClass->imageMapMale = node["animation"]["map"]["male"].String();
VLC->generaltexth->registerString(scope, heroClass->getNameTextID(), node["name"].String());
if (vstd::contains(affinityStr, node["affinity"].String()))
{
heroClass->affinity = vstd::find_pos(affinityStr, node["affinity"].String());
}
else
{
logGlobal->error("Mod '%s', hero class '%s': invalid affinity '%s'! Expected 'might' or 'magic'!", scope, identifier, node["affinity"].String());
heroClass->affinity = CHeroClass::MIGHT;
}
fillPrimarySkillData(node, heroClass.get(), PrimarySkill::ATTACK);
fillPrimarySkillData(node, heroClass.get(), PrimarySkill::DEFENSE);
fillPrimarySkillData(node, heroClass.get(), PrimarySkill::SPELL_POWER);
fillPrimarySkillData(node, heroClass.get(), PrimarySkill::KNOWLEDGE);
auto percentSumm = std::accumulate(heroClass->primarySkillLowLevel.begin(), heroClass->primarySkillLowLevel.end(), 0);
if(percentSumm <= 0)
logMod->error("Hero class %s has wrong lowLevelChance values: must be above zero!", heroClass->identifier, percentSumm);
percentSumm = std::accumulate(heroClass->primarySkillHighLevel.begin(), heroClass->primarySkillHighLevel.end(), 0);
if(percentSumm <= 0)
logMod->error("Hero class %s has wrong highLevelChance values: must be above zero!", heroClass->identifier, percentSumm);
for(auto skillPair : node["secondarySkills"].Struct())
{
int probability = static_cast<int>(skillPair.second.Integer());
VLC->identifiers()->requestIdentifier(skillPair.second.getModScope(), "skill", skillPair.first, [heroClass, probability](si32 skillID)
{
heroClass->secSkillProbability[skillID] = probability;
});
}
VLC->identifiers()->requestIdentifier ("creature", node["commander"],
[=](si32 commanderID)
{
heroClass->commander = CreatureID(commanderID);
});
heroClass->defaultTavernChance = static_cast<ui32>(node["defaultTavern"].Float());
for(const auto & tavern : node["tavern"].Struct())
{
int value = static_cast<int>(tavern.second.Float());
VLC->identifiers()->requestIdentifier(tavern.second.getModScope(), "faction", tavern.first,
[=](si32 factionID)
{
heroClass->selectionProbability[FactionID(factionID)] = value;
});
}
VLC->identifiers()->requestIdentifier("faction", node["faction"],
[=](si32 factionID)
{
heroClass->faction.setNum(factionID);
});
VLC->identifiers()->requestIdentifier(scope, "object", "hero", [=](si32 index)
{
JsonNode classConf = node["mapObject"];
classConf["heroClass"].String() = identifier;
if (!node["compatibilityIdentifiers"].isNull())
classConf["compatibilityIdentifiers"] = node["compatibilityIdentifiers"];
classConf.setModScope(scope);
VLC->objtypeh->loadSubObject(identifier, classConf, index, heroClass->getIndex());
});
return heroClass;
}
std::vector<JsonNode> CHeroClassHandler::loadLegacyData()
{
size_t dataSize = VLC->engineSettings()->getInteger(EGameSettings::TEXTS_HERO_CLASS);
objects.resize(dataSize);
std::vector<JsonNode> h3Data;
h3Data.reserve(dataSize);
CLegacyConfigParser parser(TextPath::builtin("DATA/HCTRAITS.TXT"));
parser.endLine(); // header
parser.endLine();
for (size_t i=0; i<dataSize; i++)
{
JsonNode entry;
entry["name"].String() = parser.readString();
parser.readNumber(); // unused aggression
for(const auto & name : NPrimarySkill::names)
entry["primarySkills"][name].Float() = parser.readNumber();
for(const auto & name : NPrimarySkill::names)
entry["lowLevelChance"][name].Float() = parser.readNumber();
for(const auto & name : NPrimarySkill::names)
entry["highLevelChance"][name].Float() = parser.readNumber();
for(const auto & name : NSecondarySkill::names)
entry["secondarySkills"][name].Float() = parser.readNumber();
for(const auto & name : NFaction::names)
entry["tavern"][name].Float() = parser.readNumber();
parser.endLine();
h3Data.push_back(entry);
}
return h3Data;
}
void CHeroClassHandler::afterLoadFinalization()
{
// for each pair <class, town> set selection probability if it was not set before in tavern entries
for(auto & heroClass : objects)
{
for(auto & faction : VLC->townh->objects)
{
if (!faction->town)
continue;
if (heroClass->selectionProbability.count(faction->getId()))
continue;
auto chance = static_cast<float>(heroClass->defaultTavernChance * faction->town->defaultTavernChance);
heroClass->selectionProbability[faction->getId()] = static_cast<int>(sqrt(chance) + 0.5); //FIXME: replace with std::round once MVS supports it
}
// set default probabilities for gaining secondary skills where not loaded previously
for(int skillID = 0; skillID < VLC->skillh->size(); skillID++)
{
if(heroClass->secSkillProbability.count(skillID) == 0)
{
const CSkill * skill = (*VLC->skillh)[SecondarySkill(skillID)];
logMod->trace("%s: no probability for %s, using default", heroClass->identifier, skill->getJsonKey());
heroClass->secSkillProbability[skillID] = skill->gainChance[heroClass->affinity];
}
}
}
for(const auto & hc : objects)
{
if(!hc->imageMapMale.empty())
{
JsonNode templ;
templ["animation"].String() = hc->imageMapMale;
VLC->objtypeh->getHandlerFor(Obj::HERO, hc->getIndex())->addTemplate(templ);
}
}
}
CHeroClassHandler::~CHeroClassHandler() = default;
CHeroHandler::~CHeroHandler() = default;
CHeroHandler::CHeroHandler()

View File

@ -0,0 +1,59 @@
/*
* 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
*
*/
#pragma once
#include <vcmi/HeroTypeService.h>
#include "CHero.h" // convenience include - users of handler generally also use its entity
#include "../../GameConstants.h"
#include "../../IHandlerBase.h"
VCMI_LIB_NAMESPACE_BEGIN
class DLL_LINKAGE CHeroHandler : public CHandlerBase<HeroTypeID, HeroType, CHero, HeroTypeService>
{
/// expPerLEvel[i] is amount of exp needed to reach level i;
/// consists of 196 values. Any higher levels require experience larger that TExpType can hold
std::vector<TExpType> expPerLevel;
/// helpers for loading to avoid huge load functions
void loadHeroArmy(CHero * hero, const JsonNode & node) const;
void loadHeroSkills(CHero * hero, const JsonNode & node) const;
void loadHeroSpecialty(CHero * hero, const JsonNode & node);
void loadExperience();
std::vector<std::function<void()>> callAfterLoadFinalization;
public:
ui32 level(TExpType experience) const; //calculates level corresponding to given experience amount
TExpType reqExp(ui32 level) const; //calculates experience required for given level
ui32 maxSupportedLevel() const;
std::vector<JsonNode> loadLegacyData() override;
void beforeValidate(JsonNode & object) override;
void loadObject(std::string scope, std::string name, const JsonNode & data) override;
void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
void afterLoadFinalization() override;
CHeroHandler();
~CHeroHandler();
std::set<HeroTypeID> getDefaultAllowed() const;
protected:
const std::vector<std::string> & getTypeNames() const override;
std::shared_ptr<CHero> loadFromJson(const std::string & scope, const JsonNode & node, const std::string & identifier, size_t index) override;
};
VCMI_LIB_NAMESPACE_END

View File

@ -0,0 +1,21 @@
/*
* EHeroGender.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
*
*/
#pragma once
VCMI_LIB_NAMESPACE_BEGIN
enum class EHeroGender : int8_t
{
DEFAULT = -1, // from h3m, instance has same gender as hero type
MALE = 0,
FEMALE = 1,
};
VCMI_LIB_NAMESPACE_END

View File

@ -18,7 +18,6 @@
#include "../ArtifactUtils.h"
#include "../texts/CGeneralTextHandler.h"
#include "../CHeroHandler.h"
#include "../CPlayerState.h"
#include "../CStopWatch.h"
#include "../IGameSettings.h"
@ -30,6 +29,8 @@
#include "../campaign/CampaignState.h"
#include "../constants/StringConstants.h"
#include "../entities/faction/CTownHandler.h"
#include "../entities/hero/CHero.h"
#include "../entities/hero/CHeroClass.h"
#include "../filesystem/ResourcePath.h"
#include "../json/JsonBonus.h"
#include "../json/JsonUtils.h"

View File

@ -16,6 +16,8 @@
#include "../campaign/CampaignState.h"
#include "../entities/building/CBuilding.h"
#include "../entities/building/CBuildingHandler.h"
#include "../entities/hero/CHeroClass.h"
#include "../entities/hero/CHero.h"
#include "../mapping/CMapEditManager.h"
#include "../mapObjects/CGHeroInstance.h"
#include "../mapObjects/CGTownInstance.h"
@ -23,13 +25,13 @@
#include "../mapObjectConstructors/AObjectTypeHandler.h"
#include "../mapObjectConstructors/CObjectClassesHandler.h"
#include "../StartInfo.h"
#include "../CHeroHandler.h"
#include "../mapping/CMap.h"
#include "../ArtifactUtils.h"
#include "../CPlayerState.h"
#include "../serializer/CMemorySerializer.h"
#include <vstd/RNG.h>
#include <vcmi/HeroTypeService.h>
VCMI_LIB_NAMESPACE_BEGIN

View File

@ -14,7 +14,6 @@
#include "../VCMIDirs.h"
#include "CGameState.h"
#include "TerrainHandler.h"
#include "CHeroHandler.h"
#include "StartInfo.h"
#include "HighScore.h"
#include "../mapObjects/CGHeroInstance.h"

View File

@ -12,7 +12,9 @@
#include "../mapObjects/CGHeroInstance.h"
#include "../mapObjects/CGTownInstance.h"
#include "../CHeroHandler.h"
#include <vcmi/HeroTypeService.h>
#include <vcmi/HeroType.h>
VCMI_LIB_NAMESPACE_BEGIN

View File

@ -11,7 +11,6 @@
#include "TavernHeroesPool.h"
#include "../mapObjects/CGHeroInstance.h"
#include "../CHeroHandler.h"
VCMI_LIB_NAMESPACE_BEGIN

View File

@ -13,6 +13,8 @@
#include <vstd/StringUtils.h>
#include <vstd/RNG.h>
#include <vcmi/HeroClassService.h>
#include <vcmi/HeroTypeService.h>
#include "JsonBonus.h"
@ -23,8 +25,9 @@
#include "../CCreatureSet.h"
#include "../spells/CSpellHandler.h"
#include "../CSkillHandler.h"
#include "../CHeroHandler.h"
#include "../IGameCallback.h"
#include "../entities/hero/CHero.h"
#include "../entities/hero/CHeroClass.h"
#include "../gameState/CGameState.h"
#include "../mapObjects/IObjectInterface.h"
#include "../modding/IdentifierStorage.h"

View File

@ -11,7 +11,6 @@
#include "CommonConstructors.h"
#include "../texts/CGeneralTextHandler.h"
#include "../CHeroHandler.h"
#include "../IGameCallback.h"
#include "../json/JsonRandom.h"
#include "../constants/StringConstants.h"
@ -19,6 +18,7 @@
#include "../VCMI_Lib.h"
#include "../entities/faction/CTownHandler.h"
#include "../entities/hero/CHeroClass.h"
#include "../mapObjects/CGHeroInstance.h"
#include "../mapObjects/CGMarket.h"
#include "../mapObjects/CGTownInstance.h"

View File

@ -17,7 +17,6 @@
#include "../texts/CGeneralTextHandler.h"
#include "../ArtifactUtils.h"
#include "../CHeroHandler.h"
#include "../TerrainHandler.h"
#include "../RoadHandler.h"
#include "../IGameSettings.h"
@ -31,6 +30,8 @@
#include "../StartInfo.h"
#include "CGTownInstance.h"
#include "../entities/faction/CTownHandler.h"
#include "../entities/hero/CHeroHandler.h"
#include "../entities/hero/CHeroClass.h"
#include "../battle/CBattleInfoEssentials.h"
#include "../campaign/CampaignState.h"
#include "../json/JsonBonus.h"

View File

@ -14,6 +14,7 @@
#include "CArmedInstance.h"
#include "IOwnableObject.h"
#include "../entities/hero/EHeroGender.h"
#include "../CArtHandler.h" // For CArtifactSet
VCMI_LIB_NAMESPACE_BEGIN
@ -24,7 +25,6 @@ class CGTownInstance;
class CMap;
struct TerrainTile;
struct TurnInfo;
enum class EHeroGender : int8_t;
class DLL_LINKAGE CGHeroPlaceholder : public CGObjectInstance
{

View File

@ -16,9 +16,9 @@
#include "../ArtifactUtils.h"
#include "../CSoundBase.h"
#include "../texts/CGeneralTextHandler.h"
#include "../CHeroHandler.h"
#include "CGCreature.h"
#include "../IGameCallback.h"
#include "../entities/hero/CHeroHandler.h"
#include "../mapObjectConstructors/CObjectClassesHandler.h"
#include "../serializer/JsonSerializeFormat.h"
#include "../GameConstants.h"

View File

@ -13,11 +13,11 @@
#include "../CArtHandler.h"
#include "../VCMI_Lib.h"
#include "../CCreatureHandler.h"
#include "../CHeroHandler.h"
#include "../GameSettings.h"
#include "../RiverHandler.h"
#include "../RoadHandler.h"
#include "../TerrainHandler.h"
#include "../entities/hero/CHeroHandler.h"
#include "../mapObjects/CGHeroInstance.h"
#include "../mapObjects/CGTownInstance.h"
#include "../mapObjects/CQuest.h"

View File

@ -12,9 +12,9 @@
#include "MapFormat.h"
#include "../CHeroHandler.h"
#include "../VCMI_Lib.h"
#include "../entities/faction/CTownHandler.h"
#include "../entities/hero/CHeroHandler.h"
#include "../json/JsonUtils.h"
#include "../modding/CModHandler.h"
#include "../texts/CGeneralTextHandler.h"

View File

@ -25,7 +25,6 @@
#include "../texts/TextOperations.h"
#include "../CCreatureHandler.h"
#include "../IGameSettings.h"
#include "../CHeroHandler.h"
#include "../CConfigHandler.h"
VCMI_LIB_NAMESPACE_BEGIN

View File

@ -18,7 +18,6 @@
#include "../ArtifactUtils.h"
#include "../CCreatureHandler.h"
#include "../texts/CGeneralTextHandler.h"
#include "../CHeroHandler.h"
#include "../CSkillHandler.h"
#include "../CStopWatch.h"
#include "../IGameSettings.h"
@ -27,6 +26,7 @@
#include "../TerrainHandler.h"
#include "../VCMI_Lib.h"
#include "../constants/StringConstants.h"
#include "../entities/hero/CHeroHandler.h"
#include "../filesystem/CBinaryReader.h"
#include "../filesystem/Filesystem.h"
#include "../mapObjectConstructors/AObjectTypeHandler.h"

View File

@ -17,12 +17,12 @@
#include "CMap.h"
#include "MapFormat.h"
#include "../ArtifactUtils.h"
#include "../CHeroHandler.h"
#include "../VCMI_Lib.h"
#include "../RiverHandler.h"
#include "../RoadHandler.h"
#include "../TerrainHandler.h"
#include "../entities/faction/CTownHandler.h"
#include "../entities/hero/CHeroHandler.h"
#include "../mapObjectConstructors/AObjectTypeHandler.h"
#include "../mapObjectConstructors/CObjectClassesHandler.h"
#include "../mapObjects/ObjectTemplate.h"

View File

@ -12,7 +12,6 @@
#include "MapIdentifiersH3M.h"
#include "../VCMI_Lib.h"
#include "../CHeroHandler.h"
#include "../entities/faction/CFaction.h"
#include "../entities/faction/CTownHandler.h"
#include "../filesystem/Filesystem.h"

View File

@ -19,8 +19,9 @@
#include "../CCreatureHandler.h"
#include "../CConfigHandler.h"
#include "../entities/faction/CTownHandler.h"
#include "../entities/hero/CHeroClassHandler.h"
#include "../entities/hero/CHeroHandler.h"
#include "../texts/CGeneralTextHandler.h"
#include "../CHeroHandler.h"
#include "../CSkillHandler.h"
#include "../CStopWatch.h"
#include "../IGameSettings.h"

View File

@ -20,7 +20,6 @@
#include "NetPackVisitor.h"
#include "texts/CGeneralTextHandler.h"
#include "CArtHandler.h"
#include "CHeroHandler.h"
#include "VCMI_Lib.h"
#include "mapping/CMap.h"
#include "spells/CSpellHandler.h"

View File

@ -11,10 +11,10 @@
#include "StdInc.h"
#include "Interface.h"
#include "../CHeroHandler.h"
#include "../TerrainHandler.h"
#include "../CPlayerState.h"
#include "../CSoundBase.h"
#include "../entities/hero/CHeroHandler.h"
#include "../gameState/CGameState.h"
#include "../spells/CSpellHandler.h"
#include "../spells/ISpellMechanics.h"

View File

@ -17,7 +17,6 @@
#include "../networkPacks/Component.h"
#include "../serializer/JsonSerializeFormat.h"
#include "../constants/StringConstants.h"
#include "../CHeroHandler.h"
#include "../CSkillHandler.h"
#include "../ArtifactUtils.h"

View File

@ -17,11 +17,11 @@
#include "../CRandomGenerator.h"
#include "../entities/faction/CTownHandler.h"
#include "../entities/faction/CFaction.h"
#include "../entities/hero/CHero.h"
#include "../mapObjectConstructors/AObjectTypeHandler.h"
#include "../mapObjectConstructors/CObjectClassesHandler.h"
#include "../mapping/CMapEditManager.h"
#include "../CArtHandler.h"
#include "../CHeroHandler.h"
#include "../constants/StringConstants.h"
#include "../filesystem/Filesystem.h"
#include "CZonePlacer.h"
@ -35,6 +35,7 @@
#include "modificators/RoadPlacer.h"
#include <vstd/RNG.h>
#include <vcmi/HeroTypeService.h>
VCMI_LIB_NAMESPACE_BEGIN

View File

@ -10,9 +10,9 @@
#include "StdInc.h"
#include "CSerializer.h"
#include "../entities/hero/CHero.h"
#include "../gameState/CGameState.h"
#include "../mapping/CMap.h"
#include "../CHeroHandler.h"
#include "../mapObjects/CGHeroInstance.h"
#include "../mapObjects/CQuest.h"

View File

@ -9,7 +9,6 @@
*/
#pragma once
#include "../CHeroHandler.h"
#include "../CPlayerState.h"
#include "../CStack.h"
#include "../battle/BattleInfo.h"

View File

@ -19,6 +19,7 @@
#include "../RiverHandler.h"
#include "../RoadHandler.h"
#include "../TerrainHandler.h"
#include "../entities/hero/CHero.h"
#include "../mapObjects/ObjectTemplate.h"
#include "../mapping/CMapInfo.h"
#include "../rmg/CMapGenOptions.h"

View File

@ -12,12 +12,12 @@
#include "BonusCaster.h"
#include <vcmi/spells/Spell.h>
#include <vcmi/HeroType.h>
#include "../battle/Unit.h"
#include "../bonuses/Bonus.h"
#include "../VCMI_Lib.h"
#include "../CSkillHandler.h"
#include "../CHeroHandler.h"
VCMI_LIB_NAMESPACE_BEGIN

View File

@ -36,7 +36,6 @@
#include "CSpellHandler.h"
#include "../CHeroHandler.h"//todo: remove
#include "../IGameCallback.h"//todo: remove
#include "../BattleFieldHandler.h"

View File

@ -18,7 +18,6 @@
#include "../../battle/Unit.h"
#include "../../serializer/JsonSerializeFormat.h"
#include "../../CCreatureHandler.h"
#include "../../CHeroHandler.h"
#include "../../mapObjects/CGHeroInstance.h"
#include "../../networkPacks/PacksForClientBattle.h"

View File

@ -107,7 +107,7 @@ void TextLocalizationContainer::registerString(const std::string & identifierMod
assert(!identifierModContext.empty());
assert(!localizedStringModContext.empty());
assert(UID.get().find("..") == std::string::npos); // invalid identifier - there is section that was evaluated to empty string
assert(stringsLocalizations.count(UID.get()) == 0 || identifierModContext == "map"); // registering already registered string?
assert(stringsLocalizations.count(UID.get()) == 0 || boost::algorithm::starts_with(UID.get(), "map")); // registering already registered string?
if(stringsLocalizations.count(UID.get()) > 0)
{

View File

@ -29,11 +29,11 @@
#include "../lib/texts/CGeneralTextHandler.h"
#include "BitmapHandler.h"
#include "../lib/CStopWatch.h"
#include "../lib/entities/hero/CHeroClassHandler.h"
#include "../lib/mapObjectConstructors/AObjectTypeHandler.h"
#include "../lib/mapObjectConstructors/CObjectClassesHandler.h"
#include "../lib/mapObjects/CGObjectInstance.h"
#include "../lib/mapObjects/ObjectTemplate.h"
#include "../lib/CHeroHandler.h"
Graphics * graphics = nullptr;

View File

@ -11,8 +11,9 @@
#include "inspector.h"
#include "../lib/ArtifactUtils.h"
#include "../lib/CArtHandler.h"
#include "../lib/entities/hero/CHeroClass.h"
#include "../lib/entities/hero/CHeroHandler.h"
#include "../lib/spells/CSpellHandler.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CRandomGenerator.h"
#include "../lib/mapObjectConstructors/AObjectTypeHandler.h"
#include "../lib/mapObjectConstructors/CObjectClassesHandler.h"

View File

@ -10,8 +10,8 @@
#include "StdInc.h"
#include "portraitwidget.h"
#include "ui_portraitwidget.h"
#include "../../lib/CHeroHandler.h"
#include "../Animation.h"
#include "../lib/entities/hero/CHeroHandler.h"
PortraitWidget::PortraitWidget(CGHeroInstance & h, QWidget *parent):
QDialog(parent),

View File

@ -16,12 +16,16 @@
#include "../lib/spells/CSpellHandler.h"
#include "../lib/CArtHandler.h"
#include "../lib/CCreatureHandler.h"
#include "../lib/CHeroHandler.h"
#include "../lib/constants/StringConstants.h"
#include "../lib/mapping/CMap.h"
#include "../lib/mapObjects/CGHeroInstance.h"
#include "../lib/mapObjects/CGCreature.h"
#include <vcmi/HeroTypeService.h>
#include <vcmi/HeroType.h>
#include <vcmi/HeroClassService.h>
#include <vcmi/HeroClass.h>
QuestWidget::QuestWidget(MapController & _controller, CQuest & _sh, QWidget *parent) :
QDialog(parent),
controller(_controller),

View File

@ -13,7 +13,6 @@
#include "../lib/VCMI_Lib.h"
#include "../lib/CSkillHandler.h"
#include "../lib/spells/CSpellHandler.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CArtHandler.h"
#include "../lib/CCreatureHandler.h"
#include "../lib/constants/StringConstants.h"
@ -24,6 +23,11 @@
#include "../lib/mapObjects/CGPandoraBox.h"
#include "../lib/mapObjects/CQuest.h"
#include <vcmi/HeroTypeService.h>
#include <vcmi/HeroType.h>
#include <vcmi/HeroClassService.h>
#include <vcmi/HeroClass.h>
RewardsWidget::RewardsWidget(CMap & m, CRewardableObject & p, QWidget *parent) :
QDialog(parent),
map(m),

View File

@ -13,6 +13,8 @@
#include "../lib/ArtifactUtils.h"
#include "../lib/GameConstants.h"
#include "../lib/entities/hero/CHeroClass.h"
#include "../lib/entities/hero/CHeroHandler.h"
#include "../lib/mapObjectConstructors/AObjectTypeHandler.h"
#include "../lib/mapObjectConstructors/CObjectClassesHandler.h"
#include "../lib/mapObjects/ObjectTemplate.h"
@ -25,7 +27,6 @@
#include "../lib/TerrainHandler.h"
#include "../lib/CSkillHandler.h"
#include "../lib/spells/CSpellHandler.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CRandomGenerator.h"
#include "../lib/serializer/CMemorySerializer.h"
#include "mapview.h"

View File

@ -19,7 +19,6 @@
#include "../lib/mapObjects/CGHeroInstance.h"
#include "../lib/mapObjects/ObjectTemplate.h"
#include "../lib/mapObjects/MiscObjects.h"
#include "../lib/CHeroHandler.h"
#include "../lib/GameConstants.h"
const int tileSize = 32;

View File

@ -13,7 +13,6 @@
#include "../mapcontroller.h"
#include "../../lib/mapObjects/CGHeroInstance.h"
#include "../../lib/mapObjects/CGCreature.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/mapObjects/CGCreature.h"
//parses date for lose condition (1m 1w 1d)

View File

@ -13,10 +13,10 @@
#include "ui_mapsettings.h"
#include "mainwindow.h"
#include "../../lib/CSkillHandler.h"
#include "../../lib/spells/CSpellHandler.h"
#include "../../lib/CArtHandler.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/CSkillHandler.h"
#include "../../lib/entities/hero/CHeroHandler.h"
#include "../../lib/spells/CSpellHandler.h"
MapSettings::MapSettings(MapController & ctrl, QWidget *parent) :

View File

@ -12,12 +12,12 @@
#include "validator.h"
#include "mapcontroller.h"
#include "ui_validator.h"
#include "../lib/entities/hero/CHero.h"
#include "../lib/mapping/CMap.h"
#include "../lib/mapObjects/MapObjects.h"
#include "../lib/modding/CModHandler.h"
#include "../lib/modding/CModInfo.h"
#include "../lib/spells/CSpellHandler.h"
#include "../lib/CHeroHandler.h"
Validator::Validator(const CMap * map, QWidget *parent) :
QDialog(parent),

View File

@ -29,7 +29,6 @@
#include "../lib/CCreatureHandler.h"
#include "../lib/CCreatureSet.h"
#include "../lib/texts/CGeneralTextHandler.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CPlayerState.h"
#include "../lib/CRandomGenerator.h"
#include "../lib/CSoundBase.h"
@ -48,6 +47,7 @@
#include "../lib/entities/building/CBuilding.h"
#include "../lib/entities/faction/CTownHandler.h"
#include "../lib/entities/hero/CHeroHandler.h"
#include "../lib/filesystem/FileInfo.h"
#include "../lib/filesystem/Filesystem.h"

View File

@ -15,9 +15,10 @@
#include "LobbyNetPackVisitors.h"
#include "processors/PlayerMessageProcessor.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CPlayerState.h"
#include "../lib/campaign/CampaignState.h"
#include "../lib/entities/hero/CHeroHandler.h"
#include "../lib/entities/hero/CHeroClass.h"
#include "../lib/gameState/CGameState.h"
#include "../lib/mapping/CMapDefines.h"
#include "../lib/mapping/CMapInfo.h"

View File

@ -14,10 +14,11 @@
#include "../CGameHandler.h"
#include "../../lib/CRandomGenerator.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/CPlayerState.h"
#include "../../lib/IGameSettings.h"
#include "../../lib/StartInfo.h"
#include "../../lib/entities/hero/CHeroClass.h"
#include "../../lib/entities/hero/CHero.h"
#include "../../lib/mapObjects/CGTownInstance.h"
#include "../../lib/mapObjects/CGHeroInstance.h"
#include "../../lib/networkPacks/PacksForClient.h"

View File

@ -16,10 +16,10 @@
#include "../CVCMIServer.h"
#include "../TurnTimerHandler.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/CPlayerState.h"
#include "../../lib/StartInfo.h"
#include "../../lib/entities/building/CBuilding.h"
#include "../../lib/entities/hero/CHeroHandler.h"
#include "../../lib/gameState/CGameState.h"
#include "../../lib/mapObjects/CGTownInstance.h"
#include "../../lib/mapObjects/CGHeroInstance.h"

View File

@ -9,7 +9,7 @@
*/
#include "StdInc.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/entities/hero/CHeroClass.h"
namespace test
{

View File

@ -9,7 +9,7 @@
*/
#include "StdInc.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/entities/hero/CHero.h"
namespace test
{