mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there. * Declared existing Entity APIs. * Added basic script context caching * Started Lua script module * Started Lua spell effect API * Started script state persistence * Started battle info callback binding * CommitPackage removed * Extracted spells::Caster to own header; Expanded Spell API. * implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C * !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented * Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key) * Re-enabled VERM macros. * !?GM0 added * !?TM implemented * Added !!MF:N * Started !?OB, !!BM, !!HE, !!OW, !!UN * Added basic support of w-variables * Added support for ERM indirect variables * Made !?FU regular trigger * !!re (ERA loop receiver) implemented * Fixed ERM receivers with zero args.
This commit is contained in:
@@ -9,6 +9,11 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <vcmi/HeroClass.h>
|
||||
#include <vcmi/HeroClassService.h>
|
||||
#include <vcmi/HeroType.h>
|
||||
#include <vcmi/HeroTypeService.h>
|
||||
|
||||
#include "../lib/ConstTransitivePtr.h"
|
||||
#include "GameConstants.h"
|
||||
#include "HeroBonus.h"
|
||||
@@ -20,6 +25,7 @@ class CGHeroInstance;
|
||||
struct BattleHex;
|
||||
class JsonNode;
|
||||
class CRandomGenerator;
|
||||
class JsonSerializeFormat;
|
||||
|
||||
struct SSpecialtyInfo
|
||||
{ si32 type;
|
||||
@@ -47,7 +53,7 @@ struct SSpecialtyBonus
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CHero
|
||||
class DLL_LINKAGE CHero : public HeroType
|
||||
{
|
||||
public:
|
||||
struct InitialArmyStack
|
||||
@@ -93,6 +99,19 @@ public:
|
||||
std::string portraitLarge;
|
||||
std::string battleImage;
|
||||
|
||||
CHero();
|
||||
virtual ~CHero();
|
||||
|
||||
int32_t getIndex() const override;
|
||||
int32_t getIconIndex() const override;
|
||||
const std::string & getName() const override;
|
||||
const std::string & getJsonKey() const override;
|
||||
HeroTypeID getId() const override;
|
||||
void registerIcons(const IconRegistar & cb) const override;
|
||||
|
||||
void updateFrom(const JsonNode & data);
|
||||
void serializeJson(JsonSerializeFormat & handler);
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & ID;
|
||||
@@ -137,7 +156,7 @@ public:
|
||||
std::vector<std::shared_ptr<Bonus>> SpecialtyInfoToBonuses(const SSpecialtyInfo & spec, int sid = 0);
|
||||
std::vector<std::shared_ptr<Bonus>> SpecialtyBonusToBonuses(const SSpecialtyBonus & spec, int sid = 0);
|
||||
|
||||
class DLL_LINKAGE CHeroClass
|
||||
class DLL_LINKAGE CHeroClass : public HeroClass
|
||||
{
|
||||
public:
|
||||
enum EClassAffinity
|
||||
@@ -150,8 +169,8 @@ public:
|
||||
std::string name; // translatable
|
||||
//double aggression; // not used in vcmi.
|
||||
TFaction faction;
|
||||
ui8 id;
|
||||
ui8 affinity; // affility, using EClassAffinity enum
|
||||
HeroClassID id;
|
||||
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)
|
||||
@@ -174,15 +193,34 @@ public:
|
||||
|
||||
CHeroClass();
|
||||
|
||||
int32_t getIndex() const override;
|
||||
int32_t getIconIndex() const override;
|
||||
const std::string & getName() const override;
|
||||
const std::string & getJsonKey() const override;
|
||||
HeroClassID getId() const override;
|
||||
void registerIcons(const IconRegistar & cb) const override;
|
||||
|
||||
bool isMagicHero() const;
|
||||
SecondarySkill chooseSecSkill(const std::set<SecondarySkill> & possibles, CRandomGenerator & rand) const; //picks secondary skill out from given possibilities
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
void updateFrom(const JsonNode & data);
|
||||
void serializeJson(JsonSerializeFormat & handler);
|
||||
|
||||
template <typename Handler> void serialize(Handler & h, const int version)
|
||||
{
|
||||
h & identifier;
|
||||
h & name;
|
||||
h & faction;
|
||||
h & id;
|
||||
if(version >= 800)
|
||||
{
|
||||
h & id;
|
||||
}
|
||||
else
|
||||
{
|
||||
ui8 old_id = 0;
|
||||
h & old_id;
|
||||
id = HeroClassID(old_id);
|
||||
}
|
||||
h & defaultTavernChance;
|
||||
h & primarySkillInitial;
|
||||
h & primarySkillLowLevel;
|
||||
@@ -201,7 +239,7 @@ public:
|
||||
for(auto i = 0; i < secSkillProbability.size(); i++)
|
||||
if(secSkillProbability[i] < 0)
|
||||
secSkillProbability[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
EAlignment::EAlignment getAlignment() const;
|
||||
};
|
||||
@@ -234,18 +272,12 @@ struct DLL_LINKAGE CObstacleInfo
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CHeroClassHandler : public IHandlerBase
|
||||
class DLL_LINKAGE CHeroClassHandler : public CHandlerBase<HeroClassID, HeroClass, CHeroClass, HeroClassService>
|
||||
{
|
||||
void fillPrimarySkillData(const JsonNode & node, CHeroClass * heroClass, PrimarySkill::PrimarySkill pSkill);
|
||||
CHeroClass *loadFromJson(const JsonNode & node, const std::string & identifier);
|
||||
public:
|
||||
std::vector< ConstTransitivePtr<CHeroClass> > heroClasses;
|
||||
|
||||
std::vector<JsonNode> loadLegacyData(size_t dataSize) 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;
|
||||
|
||||
std::vector<bool> getDefaultAllowed() const override;
|
||||
@@ -254,11 +286,16 @@ public:
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & heroClasses;
|
||||
h & objects;
|
||||
}
|
||||
|
||||
protected:
|
||||
const std::vector<std::string> & getTypeNames() const override;
|
||||
CHeroClass * loadFromJson(const std::string & scope, const JsonNode & node, const std::string & identifier, size_t index) override;
|
||||
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CHeroHandler : public IHandlerBase
|
||||
class DLL_LINKAGE CHeroHandler : public CHandlerBase<HeroTypeID, HeroType, CHero, HeroTypeService>
|
||||
{
|
||||
/// 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
|
||||
@@ -274,14 +311,9 @@ class DLL_LINKAGE CHeroHandler : public IHandlerBase
|
||||
void loadTerrains();
|
||||
void loadObstacles();
|
||||
|
||||
/// Load single hero from json
|
||||
CHero * loadFromJson(const JsonNode & node, const std::string & identifier);
|
||||
|
||||
public:
|
||||
CHeroClassHandler classes;
|
||||
|
||||
std::vector< ConstTransitivePtr<CHero> > heroes;
|
||||
|
||||
//default costs of going through terrains. -1 means terrain is impassable
|
||||
std::vector<int> terrCosts;
|
||||
|
||||
@@ -324,20 +356,18 @@ public:
|
||||
|
||||
std::vector<bool> getDefaultAllowed() const override;
|
||||
|
||||
///json serialization helper
|
||||
static si32 decodeHero(const std::string & identifier);
|
||||
|
||||
///json serialization helper
|
||||
static std::string encodeHero(const si32 index);
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & classes;
|
||||
h & heroes;
|
||||
h & objects;
|
||||
h & expPerLevel;
|
||||
h & ballistics;
|
||||
h & terrCosts;
|
||||
h & obstacles;
|
||||
h & absoluteObstacles;
|
||||
}
|
||||
|
||||
protected:
|
||||
const std::vector<std::string> & getTypeNames() const override;
|
||||
CHero * loadFromJson(const std::string & scope, const JsonNode & node, const std::string & identifier, size_t index) override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user