1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

Renamed new types for consistency with code style

This commit is contained in:
Ivan Savenko
2023-10-21 14:50:42 +03:00
parent 31cf3442af
commit ac925bb786
94 changed files with 564 additions and 566 deletions

View File

@@ -150,7 +150,7 @@ JsonNode Bonus::toJsonNode() const
JsonNode root(JsonNode::JsonType::DATA_STRUCT);
// only add values that might reasonably be found in config files
root["type"].String() = vstd::findKey(bonusNameMap, type);
if(subtype != TBonusSubtype())
if(subtype != BonusSubtypeID())
root["subtype"].String() = subtype.toString();
if(additionalInfo != CAddInfo::NONE)
root["addInfo"] = additionalInfoToJson(type, additionalInfo);
@@ -158,7 +158,7 @@ JsonNode Bonus::toJsonNode() const
root["sourceType"].String() = vstd::findKey(bonusSourceMap, source);
if(targetSourceType != BonusSource::OTHER)
root["targetSourceType"].String() = vstd::findKey(bonusSourceMap, targetSourceType);
if(sid != TBonusSourceID())
if(sid != BonusSourceID())
root["sourceID"].String() = sid.toString();
if(val != 0)
root["val"].Integer() = val;
@@ -183,19 +183,19 @@ JsonNode Bonus::toJsonNode() const
return root;
}
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, TBonusSourceID ID)
: Bonus(Duration, Type, Src, Val, ID, TBonusSubtype(), std::string())
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, BonusSourceID ID)
: Bonus(Duration, Type, Src, Val, ID, BonusSubtypeID(), std::string())
{}
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, TBonusSourceID ID, std::string Desc)
: Bonus(Duration, Type, Src, Val, ID, TBonusSubtype(), Desc)
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, BonusSourceID ID, std::string Desc)
: Bonus(Duration, Type, Src, Val, ID, BonusSubtypeID(), Desc)
{}
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, TBonusSourceID ID, TBonusSubtype Subtype)
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, BonusSourceID ID, BonusSubtypeID Subtype)
: Bonus(Duration, Type, Src, Val, ID, Subtype, std::string())
{}
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, TBonusSourceID ID, TBonusSubtype Subtype, std::string Desc):
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, BonusSourceID ID, BonusSubtypeID Subtype, std::string Desc):
duration(Duration),
type(Type),
subtype(Subtype),
@@ -208,7 +208,7 @@ Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32
targetSourceType = BonusSource::OTHER;
}
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, TBonusSourceID ID, TBonusSubtype Subtype, BonusValueType ValType):
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, BonusSourceID ID, BonusSubtypeID Subtype, BonusValueType ValType):
duration(Duration),
type(Type),
subtype(Subtype),

View File

@@ -10,7 +10,7 @@
#pragma once
#include "BonusEnum.h"
#include "BonusSubtypeID.h"
#include "BonusCustomTypes.h"
#include "../constants/VariantIdentifier.h"
#include "../constants/EntityIdentifiers.h"
@@ -25,8 +25,8 @@ class IUpdater;
class BonusList;
class CSelector;
using TBonusSubtype = VariantIdentifier<BonusSubtypeID, SpellID, CreatureID, PrimarySkill, TerrainId, GameResID, SpellSchool>;
using TBonusSourceID = VariantIdentifier<BonusSourceID, SpellID, CreatureID, ArtifactID, CampaignScenarioID, SecondarySkill, HeroTypeID, Obj, ObjectInstanceID, BuildingTypeUniqueID, BattleField>;
using BonusSubtypeID = VariantIdentifier<BonusCustomSubtype, SpellID, CreatureID, PrimarySkill, TerrainId, GameResID, SpellSchool>;
using BonusSourceID = VariantIdentifier<BonusCustomSource, SpellID, CreatureID, ArtifactID, CampaignScenarioID, SecondarySkill, HeroTypeID, Obj, ObjectInstanceID, BuildingTypeUniqueID, BattleField>;
using TBonusListPtr = std::shared_ptr<BonusList>;
using TConstBonusListPtr = std::shared_ptr<const BonusList>;
using TLimiterPtr = std::shared_ptr<ILimiter>;
@@ -60,12 +60,12 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this<Bonus>
si16 turnsRemain = 0; //used if duration is N_TURNS, N_DAYS or ONE_WEEK
BonusType type = BonusType::NONE; //uses BonusType values - says to what is this bonus - 1 byte
TBonusSubtype subtype;
BonusSubtypeID subtype;
BonusSource source = BonusSource::OTHER; //source type" uses BonusSource values - what gave that bonus
BonusSource targetSourceType;//Bonuses of what origin this amplifies, uses BonusSource values. Needed for PERCENT_TO_TARGET_TYPE.
si32 val = 0;
TBonusSourceID sid; //source id: id of object/artifact/spell
BonusSourceID sid; //source id: id of object/artifact/spell
BonusValueType valType = BonusValueType::ADDITIVE_VALUE;
std::string stacking; // bonuses with the same stacking value don't stack (e.g. Angel/Archangel morale bonus)
@@ -79,11 +79,11 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this<Bonus>
std::string description;
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, TBonusSourceID sourceID);
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, TBonusSourceID sourceID, std::string Desc);
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, TBonusSourceID sourceID, TBonusSubtype subtype);
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, TBonusSourceID sourceID, TBonusSubtype subtype, std::string Desc);
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, TBonusSourceID sourceID, TBonusSubtype subtype, BonusValueType ValType);
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, BonusSourceID sourceID);
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, BonusSourceID sourceID, std::string Desc);
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, BonusSourceID sourceID, BonusSubtypeID subtype);
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, BonusSourceID sourceID, BonusSubtypeID subtype, std::string Desc);
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, BonusSourceID sourceID, BonusSubtypeID subtype, BonusValueType ValType);
Bonus() = default;
template <typename Handler> void serialize(Handler &h, const int version)

View File

@@ -0,0 +1,74 @@
/*
* BonusCustomTypes.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 "BonusCustomTypes.h"
VCMI_LIB_NAMESPACE_BEGIN
const BonusCustomSubtype BonusCustomSubtype::creatureDamageBoth(0);
const BonusCustomSubtype BonusCustomSubtype::creatureDamageMin(1);
const BonusCustomSubtype BonusCustomSubtype::creatureDamageMax(2);
const BonusCustomSubtype BonusCustomSubtype::damageTypeAll(-1);
const BonusCustomSubtype BonusCustomSubtype::damageTypeMelee(0);
const BonusCustomSubtype BonusCustomSubtype::damageTypeRanged(1);
const BonusCustomSubtype BonusCustomSubtype::heroMovementLand(1);
const BonusCustomSubtype BonusCustomSubtype::heroMovementSea(0);
const BonusCustomSubtype BonusCustomSubtype::deathStareGorgon(0);
const BonusCustomSubtype BonusCustomSubtype::deathStareCommander(1);
const BonusCustomSubtype BonusCustomSubtype::rebirthRegular(0);
const BonusCustomSubtype BonusCustomSubtype::rebirthSpecial(1);
const BonusCustomSubtype BonusCustomSubtype::visionsMonsters(0);
const BonusCustomSubtype BonusCustomSubtype::visionsHeroes(1);
const BonusCustomSubtype BonusCustomSubtype::visionsTowns(2);
const BonusCustomSubtype BonusCustomSubtype::immunityBattleWide(0);
const BonusCustomSubtype BonusCustomSubtype::immunityEnemyHero(1);
const BonusCustomSubtype BonusCustomSubtype::transmutationPerHealth(0);
const BonusCustomSubtype BonusCustomSubtype::transmutationPerUnit(1);
const BonusCustomSubtype BonusCustomSubtype::destructionKillPercentage(0);
const BonusCustomSubtype BonusCustomSubtype::destructionKillAmount(1);
const BonusCustomSubtype BonusCustomSubtype::soulStealPermanent(0);
const BonusCustomSubtype BonusCustomSubtype::soulStealBattle(1);
const BonusCustomSubtype BonusCustomSubtype::movementFlying(0);
const BonusCustomSubtype BonusCustomSubtype::movementTeleporting(1);
const BonusCustomSource BonusCustomSource::undeadMoraleDebuff(-2);
BonusCustomSubtype BonusCustomSubtype::spellLevel(int level)
{
return BonusCustomSubtype(level);
}
BonusCustomSubtype BonusCustomSubtype::creatureLevel(int level)
{
return BonusCustomSubtype(level);
}
si32 BonusCustomSubtype::decode(const std::string & identifier)
{
return std::stoi(identifier);
}
std::string BonusCustomSubtype::encode(const si32 index)
{
return std::to_string(index);
}
si32 BonusCustomSource::decode(const std::string & identifier)
{
return std::stoi(identifier);
}
std::string BonusCustomSource::encode(const si32 index)
{
return std::to_string(index);
}
VCMI_LIB_NAMESPACE_END

View File

@@ -0,0 +1,75 @@
/*
* BonusCustomTypes.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 "../constants/EntityIdentifiers.h"
VCMI_LIB_NAMESPACE_BEGIN
class DLL_LINKAGE BonusCustomSource : public Identifier<BonusCustomSource>
{
public:
using Identifier<BonusCustomSource>::Identifier;
static std::string encode(int32_t index);
static si32 decode(const std::string & identifier);
static const BonusCustomSource undeadMoraleDebuff; // -2
};
class DLL_LINKAGE BonusCustomSubtype : public Identifier<BonusCustomSubtype>
{
public:
using Identifier<BonusCustomSubtype>::Identifier;
static std::string encode(int32_t index);
static si32 decode(const std::string & identifier);
static const BonusCustomSubtype creatureDamageBoth; // 0
static const BonusCustomSubtype creatureDamageMin; // 1
static const BonusCustomSubtype creatureDamageMax; // 2
static const BonusCustomSubtype damageTypeAll; // -1
static const BonusCustomSubtype damageTypeMelee; // 0
static const BonusCustomSubtype damageTypeRanged; // 1
static const BonusCustomSubtype heroMovementLand; // 1
static const BonusCustomSubtype heroMovementSea; // 0
static const BonusCustomSubtype deathStareGorgon; // 0
static const BonusCustomSubtype deathStareCommander;
static const BonusCustomSubtype rebirthRegular; // 0
static const BonusCustomSubtype rebirthSpecial; // 1
static const BonusCustomSubtype visionsMonsters; // 0
static const BonusCustomSubtype visionsHeroes; // 1
static const BonusCustomSubtype visionsTowns; // 2
static const BonusCustomSubtype immunityBattleWide; // 0
static const BonusCustomSubtype immunityEnemyHero; // 1
static const BonusCustomSubtype transmutationPerHealth; // 0
static const BonusCustomSubtype transmutationPerUnit; // 1
static const BonusCustomSubtype destructionKillPercentage; // 0
static const BonusCustomSubtype destructionKillAmount; // 1
static const BonusCustomSubtype soulStealPermanent; // 0
static const BonusCustomSubtype soulStealBattle; // 1
static const BonusCustomSubtype movementFlying; // 0
static const BonusCustomSubtype movementTeleporting; // 1
static BonusCustomSubtype spellLevel(int level);
static BonusCustomSubtype creatureLevel(int level);
};
VCMI_LIB_NAMESPACE_END

View File

@@ -84,66 +84,66 @@ BonusParams::BonusParams(std::string deprecatedTypeStr, std::string deprecatedSu
else if(deprecatedSubtype == SecondarySkill::SORCERY || deprecatedSubtypeStr == "skill.sorcery")
{
type = BonusType::SPELL_DAMAGE;
subtype = TBonusSubtype(SpellSchool::ANY);
subtype = BonusSubtypeID(SpellSchool::ANY);
}
else if(deprecatedSubtype == SecondarySkill::SCHOLAR || deprecatedSubtypeStr == "skill.scholar")
type = BonusType::LEARN_MEETING_SPELL_LIMIT;
else if(deprecatedSubtype == SecondarySkill::ARCHERY|| deprecatedSubtypeStr == "skill.archery")
{
subtype = BonusSubtypeID::damageTypeRanged;
subtype = BonusCustomSubtype::damageTypeRanged;
type = BonusType::PERCENTAGE_DAMAGE_BOOST;
}
else if(deprecatedSubtype == SecondarySkill::OFFENCE || deprecatedSubtypeStr == "skill.offence")
{
subtype = BonusSubtypeID::damageTypeMelee;
subtype = BonusCustomSubtype::damageTypeMelee;
type = BonusType::PERCENTAGE_DAMAGE_BOOST;
}
else if(deprecatedSubtype == SecondarySkill::ARMORER || deprecatedSubtypeStr == "skill.armorer")
{
subtype = BonusSubtypeID::damageTypeAll;
subtype = BonusCustomSubtype::damageTypeAll;
type = BonusType::GENERAL_DAMAGE_REDUCTION;
}
else if(deprecatedSubtype == SecondarySkill::NAVIGATION || deprecatedSubtypeStr == "skill.navigation")
{
subtype = BonusSubtypeID::heroMovementSea;
subtype = BonusCustomSubtype::heroMovementSea;
valueType = BonusValueType::PERCENT_TO_BASE;
type = BonusType::MOVEMENT;
}
else if(deprecatedSubtype == SecondarySkill::LOGISTICS || deprecatedSubtypeStr == "skill.logistics")
{
subtype = BonusSubtypeID::heroMovementLand;
subtype = BonusCustomSubtype::heroMovementLand;
valueType = BonusValueType::PERCENT_TO_BASE;
type = BonusType::MOVEMENT;
}
else if(deprecatedSubtype == SecondarySkill::ESTATES || deprecatedSubtypeStr == "skill.estates")
{
type = BonusType::GENERATE_RESOURCE;
subtype = TBonusSubtype(GameResID(EGameResID::GOLD));
subtype = BonusSubtypeID(GameResID(EGameResID::GOLD));
}
else if(deprecatedSubtype == SecondarySkill::AIR_MAGIC || deprecatedSubtypeStr == "skill.airMagic")
{
type = BonusType::MAGIC_SCHOOL_SKILL;
subtype = TBonusSubtype(SpellSchool::AIR);
subtype = BonusSubtypeID(SpellSchool::AIR);
}
else if(deprecatedSubtype == SecondarySkill::WATER_MAGIC || deprecatedSubtypeStr == "skill.waterMagic")
{
type = BonusType::MAGIC_SCHOOL_SKILL;
subtype = TBonusSubtype(SpellSchool::WATER);
subtype = BonusSubtypeID(SpellSchool::WATER);
}
else if(deprecatedSubtype == SecondarySkill::FIRE_MAGIC || deprecatedSubtypeStr == "skill.fireMagic")
{
type = BonusType::MAGIC_SCHOOL_SKILL;
subtype = TBonusSubtype(SpellSchool::FIRE);
subtype = BonusSubtypeID(SpellSchool::FIRE);
}
else if(deprecatedSubtype == SecondarySkill::EARTH_MAGIC || deprecatedSubtypeStr == "skill.earthMagic")
{
type = BonusType::MAGIC_SCHOOL_SKILL;
subtype = TBonusSubtype(SpellSchool::EARTH);
subtype = BonusSubtypeID(SpellSchool::EARTH);
}
else if (deprecatedSubtype == SecondarySkill::ARTILLERY || deprecatedSubtypeStr == "skill.artillery")
{
type = BonusType::BONUS_DAMAGE_CHANCE;
subtype = TBonusSubtype(CreatureID(CreatureID::BALLISTA));
subtype = BonusSubtypeID(CreatureID(CreatureID::BALLISTA));
}
else if (deprecatedSubtype == SecondarySkill::FIRST_AID || deprecatedSubtypeStr == "skill.firstAid")
{
@@ -165,20 +165,20 @@ BonusParams::BonusParams(std::string deprecatedTypeStr, std::string deprecatedSu
else if (deprecatedSubtype == SecondarySkill::ARTILLERY || deprecatedSubtypeStr == "skill.artillery")
{
type = BonusType::HERO_GRANTS_ATTACKS;
subtype = TBonusSubtype(CreatureID(CreatureID::BALLISTA));
subtype = BonusSubtypeID(CreatureID(CreatureID::BALLISTA));
}
else
isConverted = false;
}
else if (deprecatedTypeStr == "SEA_MOVEMENT")
{
subtype = BonusSubtypeID::heroMovementSea;
subtype = BonusCustomSubtype::heroMovementSea;
valueType = BonusValueType::ADDITIVE_VALUE;
type = BonusType::MOVEMENT;
}
else if (deprecatedTypeStr == "LAND_MOVEMENT")
{
subtype = BonusSubtypeID::heroMovementLand;
subtype = BonusCustomSubtype::heroMovementLand;
valueType = BonusValueType::ADDITIVE_VALUE;
type = BonusType::MOVEMENT;
}
@@ -226,52 +226,52 @@ BonusParams::BonusParams(std::string deprecatedTypeStr, std::string deprecatedSu
else if (deprecatedTypeStr == "DIRECT_DAMAGE_IMMUNITY")
{
type = BonusType::SPELL_DAMAGE_REDUCTION;
subtype = TBonusSubtype(SpellSchool::ANY);
subtype = BonusSubtypeID(SpellSchool::ANY);
val = 100;
}
else if (deprecatedTypeStr == "AIR_SPELL_DMG_PREMY")
{
type = BonusType::SPELL_DAMAGE;
subtype = TBonusSubtype(SpellSchool::AIR);
subtype = BonusSubtypeID(SpellSchool::AIR);
}
else if (deprecatedTypeStr == "FIRE_SPELL_DMG_PREMY")
{
type = BonusType::SPELL_DAMAGE;
subtype = TBonusSubtype(SpellSchool::FIRE);
subtype = BonusSubtypeID(SpellSchool::FIRE);
}
else if (deprecatedTypeStr == "WATER_SPELL_DMG_PREMY")
{
type = BonusType::SPELL_DAMAGE;
subtype = TBonusSubtype(SpellSchool::WATER);
subtype = BonusSubtypeID(SpellSchool::WATER);
}
else if (deprecatedTypeStr == "EARTH_SPELL_DMG_PREMY")
{
type = BonusType::SPELL_DAMAGE;
subtype = TBonusSubtype(SpellSchool::EARTH);
subtype = BonusSubtypeID(SpellSchool::EARTH);
}
else if (deprecatedTypeStr == "AIR_SPELLS")
{
type = BonusType::SPELLS_OF_SCHOOL;
subtype = TBonusSubtype(SpellSchool::AIR);
subtype = BonusSubtypeID(SpellSchool::AIR);
}
else if (deprecatedTypeStr == "FIRE_SPELLS")
{
type = BonusType::SPELLS_OF_SCHOOL;
subtype = TBonusSubtype(SpellSchool::FIRE);
subtype = BonusSubtypeID(SpellSchool::FIRE);
}
else if (deprecatedTypeStr == "WATER_SPELLS")
{
type = BonusType::SPELLS_OF_SCHOOL;
subtype = TBonusSubtype(SpellSchool::WATER);
subtype = BonusSubtypeID(SpellSchool::WATER);
}
else if (deprecatedTypeStr == "EARTH_SPELLS")
{
type = BonusType::SPELLS_OF_SCHOOL;
subtype = TBonusSubtype(SpellSchool::EARTH);
subtype = BonusSubtypeID(SpellSchool::EARTH);
}
else if (deprecatedTypeStr == "AIR_IMMUNITY")
{
subtype = TBonusSubtype(SpellSchool::AIR);
subtype = BonusSubtypeID(SpellSchool::AIR);
switch(deprecatedSubtype)
{
case 0:
@@ -287,7 +287,7 @@ BonusParams::BonusParams(std::string deprecatedTypeStr, std::string deprecatedSu
}
else if (deprecatedTypeStr == "FIRE_IMMUNITY")
{
subtype = TBonusSubtype(SpellSchool::FIRE);
subtype = BonusSubtypeID(SpellSchool::FIRE);
switch(deprecatedSubtype)
{
case 0:
@@ -303,7 +303,7 @@ BonusParams::BonusParams(std::string deprecatedTypeStr, std::string deprecatedSu
}
else if (deprecatedTypeStr == "WATER_IMMUNITY")
{
subtype = TBonusSubtype(SpellSchool::WATER);
subtype = BonusSubtypeID(SpellSchool::WATER);
switch(deprecatedSubtype)
{
case 0:
@@ -319,7 +319,7 @@ BonusParams::BonusParams(std::string deprecatedTypeStr, std::string deprecatedSu
}
else if (deprecatedTypeStr == "EARTH_IMMUNITY")
{
subtype = TBonusSubtype(SpellSchool::EARTH);
subtype = BonusSubtypeID(SpellSchool::EARTH);
switch(deprecatedSubtype)
{
case 0:

View File

@@ -19,7 +19,7 @@ VCMI_LIB_NAMESPACE_BEGIN
struct DLL_LINKAGE BonusParams {
bool isConverted;
BonusType type = BonusType::NONE;
std::optional<TBonusSubtype> subtype = std::nullopt;
std::optional<BonusSubtypeID> subtype = std::nullopt;
std::optional<BonusValueType> valueType = std::nullopt;
std::optional<si32> val = std::nullopt;
std::optional<BonusSource> targetType = std::nullopt;

View File

@@ -21,9 +21,9 @@ namespace Selector
return stype;
}
DLL_LINKAGE CSelectFieldEqual<TBonusSubtype> & subtype()
DLL_LINKAGE CSelectFieldEqual<BonusSubtypeID> & subtype()
{
static CSelectFieldEqual<TBonusSubtype> ssubtype(&Bonus::subtype);
static CSelectFieldEqual<BonusSubtypeID> ssubtype(&Bonus::subtype);
return ssubtype;
}
@@ -54,22 +54,22 @@ namespace Selector
DLL_LINKAGE CWillLastTurns turns;
DLL_LINKAGE CWillLastDays days;
CSelector DLL_LINKAGE typeSubtype(BonusType Type, TBonusSubtype Subtype)
CSelector DLL_LINKAGE typeSubtype(BonusType Type, BonusSubtypeID Subtype)
{
return type()(Type).And(subtype()(Subtype));
}
CSelector DLL_LINKAGE typeSubtypeInfo(BonusType type, TBonusSubtype subtype, const CAddInfo & info)
CSelector DLL_LINKAGE typeSubtypeInfo(BonusType type, BonusSubtypeID subtype, const CAddInfo & info)
{
return CSelectFieldEqual<BonusType>(&Bonus::type)(type)
.And(CSelectFieldEqual<TBonusSubtype>(&Bonus::subtype)(subtype))
.And(CSelectFieldEqual<BonusSubtypeID>(&Bonus::subtype)(subtype))
.And(CSelectFieldEqual<CAddInfo>(&Bonus::additionalInfo)(info));
}
CSelector DLL_LINKAGE source(BonusSource source, TBonusSourceID sourceID)
CSelector DLL_LINKAGE source(BonusSource source, BonusSourceID sourceID)
{
return CSelectFieldEqual<BonusSource>(&Bonus::source)(source)
.And(CSelectFieldEqual<TBonusSourceID>(&Bonus::sid)(sourceID));
.And(CSelectFieldEqual<BonusSourceID>(&Bonus::sid)(sourceID));
}
CSelector DLL_LINKAGE sourceTypeSel(BonusSource source)

View File

@@ -126,7 +126,7 @@ public:
namespace Selector
{
extern DLL_LINKAGE CSelectFieldEqual<BonusType> & type();
extern DLL_LINKAGE CSelectFieldEqual<TBonusSubtype> & subtype();
extern DLL_LINKAGE CSelectFieldEqual<BonusSubtypeID> & subtype();
extern DLL_LINKAGE CSelectFieldEqual<CAddInfo> & info();
extern DLL_LINKAGE CSelectFieldEqual<BonusSource> & sourceType();
extern DLL_LINKAGE CSelectFieldEqual<BonusSource> & targetSourceType();
@@ -134,9 +134,9 @@ namespace Selector
extern DLL_LINKAGE CWillLastTurns turns;
extern DLL_LINKAGE CWillLastDays days;
CSelector DLL_LINKAGE typeSubtype(BonusType Type, TBonusSubtype Subtype);
CSelector DLL_LINKAGE typeSubtypeInfo(BonusType type, TBonusSubtype subtype, const CAddInfo & info);
CSelector DLL_LINKAGE source(BonusSource source, TBonusSourceID sourceID);
CSelector DLL_LINKAGE typeSubtype(BonusType Type, BonusSubtypeID Subtype);
CSelector DLL_LINKAGE typeSubtypeInfo(BonusType type, BonusSubtypeID subtype, const CAddInfo & info);
CSelector DLL_LINKAGE source(BonusSource source, BonusSourceID sourceID);
CSelector DLL_LINKAGE sourceTypeSel(BonusSource source);
CSelector DLL_LINKAGE valueType(BonusValueType valType);

View File

@@ -1,74 +0,0 @@
/*
* Bonus.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 "BonusSubtypeID.h"
VCMI_LIB_NAMESPACE_BEGIN
const BonusSubtypeID BonusSubtypeID::creatureDamageBoth(0);
const BonusSubtypeID BonusSubtypeID::creatureDamageMin(1);
const BonusSubtypeID BonusSubtypeID::creatureDamageMax(2);
const BonusSubtypeID BonusSubtypeID::damageTypeAll(-1);
const BonusSubtypeID BonusSubtypeID::damageTypeMelee(0);
const BonusSubtypeID BonusSubtypeID::damageTypeRanged(1);
const BonusSubtypeID BonusSubtypeID::heroMovementLand(1);
const BonusSubtypeID BonusSubtypeID::heroMovementSea(0);
const BonusSubtypeID BonusSubtypeID::deathStareGorgon(0);
const BonusSubtypeID BonusSubtypeID::deathStareCommander(1);
const BonusSubtypeID BonusSubtypeID::rebirthRegular(0);
const BonusSubtypeID BonusSubtypeID::rebirthSpecial(1);
const BonusSubtypeID BonusSubtypeID::visionsMonsters(0);
const BonusSubtypeID BonusSubtypeID::visionsHeroes(1);
const BonusSubtypeID BonusSubtypeID::visionsTowns(2);
const BonusSubtypeID BonusSubtypeID::immunityBattleWide(0);
const BonusSubtypeID BonusSubtypeID::immunityEnemyHero(1);
const BonusSubtypeID BonusSubtypeID::transmutationPerHealth(0);
const BonusSubtypeID BonusSubtypeID::transmutationPerUnit(1);
const BonusSubtypeID BonusSubtypeID::destructionKillPercentage(0);
const BonusSubtypeID BonusSubtypeID::destructionKillAmount(1);
const BonusSubtypeID BonusSubtypeID::soulStealPermanent(0);
const BonusSubtypeID BonusSubtypeID::soulStealBattle(1);
const BonusSubtypeID BonusSubtypeID::movementFlying(0);
const BonusSubtypeID BonusSubtypeID::movementTeleporting(1);
const BonusSourceID BonusSourceID::undeadMoraleDebuff(-2);
BonusSubtypeID BonusSubtypeID::spellLevel(int level)
{
return BonusSubtypeID(level);
}
BonusSubtypeID BonusSubtypeID::creatureLevel(int level)
{
return BonusSubtypeID(level);
}
si32 BonusSubtypeID::decode(const std::string & identifier)
{
return std::stoi(identifier);
}
std::string BonusSubtypeID::encode(const si32 index)
{
return std::to_string(index);
}
si32 BonusSourceID::decode(const std::string & identifier)
{
return std::stoi(identifier);
}
std::string BonusSourceID::encode(const si32 index)
{
return std::to_string(index);
}
VCMI_LIB_NAMESPACE_END

View File

@@ -1,75 +0,0 @@
/*
* BonusSubtypeID.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 "../constants/EntityIdentifiers.h"
VCMI_LIB_NAMESPACE_BEGIN
class DLL_LINKAGE BonusSourceID : public Identifier<BonusSourceID>
{
public:
using Identifier<BonusSourceID>::Identifier;
static std::string encode(int32_t index);
static si32 decode(const std::string & identifier);
static const BonusSourceID undeadMoraleDebuff; // -2
};
class DLL_LINKAGE BonusSubtypeID : public Identifier<BonusSubtypeID>
{
public:
using Identifier<BonusSubtypeID>::Identifier;
static std::string encode(int32_t index);
static si32 decode(const std::string & identifier);
static const BonusSubtypeID creatureDamageBoth; // 0
static const BonusSubtypeID creatureDamageMin; // 1
static const BonusSubtypeID creatureDamageMax; // 2
static const BonusSubtypeID damageTypeAll; // -1
static const BonusSubtypeID damageTypeMelee; // 0
static const BonusSubtypeID damageTypeRanged; // 1
static const BonusSubtypeID heroMovementLand; // 1
static const BonusSubtypeID heroMovementSea; // 0
static const BonusSubtypeID deathStareGorgon; // 0
static const BonusSubtypeID deathStareCommander;
static const BonusSubtypeID rebirthRegular; // 0
static const BonusSubtypeID rebirthSpecial; // 1
static const BonusSubtypeID visionsMonsters; // 0
static const BonusSubtypeID visionsHeroes; // 1
static const BonusSubtypeID visionsTowns; // 2
static const BonusSubtypeID immunityBattleWide; // 0
static const BonusSubtypeID immunityEnemyHero; // 1
static const BonusSubtypeID transmutationPerHealth; // 0
static const BonusSubtypeID transmutationPerUnit; // 1
static const BonusSubtypeID destructionKillPercentage; // 0
static const BonusSubtypeID destructionKillAmount; // 1
static const BonusSubtypeID soulStealPermanent; // 0
static const BonusSubtypeID soulStealBattle; // 1
static const BonusSubtypeID movementFlying; // 0
static const BonusSubtypeID movementTeleporting; // 1
static BonusSubtypeID spellLevel(int level);
static BonusSubtypeID creatureLevel(int level);
};
VCMI_LIB_NAMESPACE_END

View File

@@ -62,7 +62,7 @@ bool IBonusBearer::hasBonusOfType(BonusType type) const
return hasBonus(s, cachingStr);
}
int IBonusBearer::valOfBonuses(BonusType type, TBonusSubtype subtype) const
int IBonusBearer::valOfBonuses(BonusType type, BonusSubtypeID subtype) const
{
//This part is performance-critical
std::string cachingStr = "type_" + std::to_string(static_cast<int>(type)) + "_" + subtype.toString();
@@ -72,7 +72,7 @@ int IBonusBearer::valOfBonuses(BonusType type, TBonusSubtype subtype) const
return valOfBonuses(s, cachingStr);
}
bool IBonusBearer::hasBonusOfType(BonusType type, TBonusSubtype subtype) const
bool IBonusBearer::hasBonusOfType(BonusType type, BonusSubtypeID subtype) const
{
//This part is performance-critical
std::string cachingStr = "type_" + std::to_string(static_cast<int>(type)) + "_" + subtype.toString();
@@ -82,7 +82,7 @@ bool IBonusBearer::hasBonusOfType(BonusType type, TBonusSubtype subtype) const
return hasBonus(s, cachingStr);
}
bool IBonusBearer::hasBonusFrom(BonusSource source, TBonusSourceID sourceID) const
bool IBonusBearer::hasBonusFrom(BonusSource source, BonusSourceID sourceID) const
{
boost::format fmt("source_%did_%s");
fmt % static_cast<int>(source) % sourceID.toString();

View File

@@ -35,9 +35,9 @@ public:
//Optimized interface (with auto-caching)
int valOfBonuses(BonusType type) const; //subtype -> subtype of bonus;
bool hasBonusOfType(BonusType type) const;//determines if hero has a bonus of given type (and optionally subtype)
int valOfBonuses(BonusType type, TBonusSubtype subtype) const; //subtype -> subtype of bonus;
bool hasBonusOfType(BonusType type, TBonusSubtype subtype) const;//determines if hero has a bonus of given type (and optionally subtype)
bool hasBonusFrom(BonusSource source, TBonusSourceID sourceID) const;
int valOfBonuses(BonusType type, BonusSubtypeID subtype) const; //subtype -> subtype of bonus;
bool hasBonusOfType(BonusType type, BonusSubtypeID subtype) const;//determines if hero has a bonus of given type (and optionally subtype)
bool hasBonusFrom(BonusSource source, BonusSourceID sourceID) const;
virtual int64_t getTreeVersion() const = 0;
};

View File

@@ -140,7 +140,7 @@ HasAnotherBonusLimiter::HasAnotherBonusLimiter( BonusType bonus )
{
}
HasAnotherBonusLimiter::HasAnotherBonusLimiter( BonusType bonus, TBonusSubtype _subtype )
HasAnotherBonusLimiter::HasAnotherBonusLimiter( BonusType bonus, BonusSubtypeID _subtype )
: type(bonus), subtype(_subtype), isSubtypeRelevant(true), isSourceRelevant(false), isSourceIDRelevant(false)
{
}
@@ -150,7 +150,7 @@ HasAnotherBonusLimiter::HasAnotherBonusLimiter(BonusType bonus, BonusSource src)
{
}
HasAnotherBonusLimiter::HasAnotherBonusLimiter(BonusType bonus, TBonusSubtype _subtype, BonusSource src)
HasAnotherBonusLimiter::HasAnotherBonusLimiter(BonusType bonus, BonusSubtypeID _subtype, BonusSource src)
: type(bonus), subtype(_subtype), isSubtypeRelevant(true), source(src), isSourceRelevant(true), isSourceIDRelevant(false)
{
}

View File

@@ -116,17 +116,17 @@ class DLL_LINKAGE HasAnotherBonusLimiter : public ILimiter //applies only to nod
{
public:
BonusType type;
TBonusSubtype subtype;
BonusSubtypeID subtype;
BonusSource source;
TBonusSourceID sid;
BonusSourceID sid;
bool isSubtypeRelevant; //check for subtype only if this is true
bool isSourceRelevant; //check for bonus source only if this is true
bool isSourceIDRelevant; //check for bonus source only if this is true
HasAnotherBonusLimiter(BonusType bonus = BonusType::NONE);
HasAnotherBonusLimiter(BonusType bonus, TBonusSubtype _subtype);
HasAnotherBonusLimiter(BonusType bonus, BonusSubtypeID _subtype);
HasAnotherBonusLimiter(BonusType bonus, BonusSource src);
HasAnotherBonusLimiter(BonusType bonus, TBonusSubtype _subtype, BonusSource src);
HasAnotherBonusLimiter(BonusType bonus, BonusSubtypeID _subtype, BonusSource src);
EDecision limit(const BonusLimitationContext &context) const override;
std::string toString() const override;