1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-24 03:47:18 +02:00

Limiters (at least creature type limiters) are printed as well

This commit is contained in:
Henning Koehler 2017-09-12 11:56:38 +12:00
parent 89b1ba7538
commit c79b776f3c
5 changed files with 84 additions and 14 deletions

View File

@ -404,6 +404,7 @@ std::vector<std::shared_ptr<Bonus>> SpecialtyInfoToBonuses(const SSpecialtyInfo
bonus = std::make_shared<Bonus>(*bonus);
bonus->type = Bonus::PRIMARY_SKILL;
bonus->val = 0;
int stepSize = specCreature.level ? specCreature.level : 5;
bonus->subtype = PrimarySkill::ATTACK;
@ -420,6 +421,7 @@ std::vector<std::shared_ptr<Bonus>> SpecialtyInfoToBonuses(const SSpecialtyInfo
bonus->type = Bonus::SECONDARY_SKILL_PREMY;
bonus->valType = Bonus::PERCENT_TO_BASE;
bonus->subtype = spec.subtype;
bonus->val = 0;
bonus->updater.reset(new ScalingUpdater(spec.val * 20));
result.push_back(bonus);
break;

View File

@ -1174,6 +1174,8 @@ JsonNode Bonus::toJsonNode() const
root["val"].Float() = val;
if(valType != ADDITIVE_VALUE)
root["valType"].Float() = valType;
if(limiter)
root["limiter"] = limiter->toJsonNode();
if(updater)
root["updater"] = updater->toJsonNode();
return root;
@ -1343,6 +1345,8 @@ DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const Bonus &bonus)
printField(effectRange);
#undef printField
if(bonus.limiter)
out << "\tLimiter: " << bonus.limiter->toString() << "\n";
if(bonus.updater)
out << "\tUpdater: " << bonus.updater->toString() << "\n";
@ -1381,6 +1385,18 @@ int ILimiter::limit(const BonusLimitationContext &context) const /*return true t
return false;
}
std::string ILimiter::toString() const
{
return typeid(*this).name();
}
JsonNode ILimiter::toJsonNode() const
{
JsonNode root(JsonNode::DATA_STRUCT);
root["type"].String() = toString();
return root;
}
int CCreatureTypeLimiter::limit(const BonusLimitationContext &context) const
{
const CCreature *c = retrieveCreature(&context.node);
@ -1406,6 +1422,26 @@ void CCreatureTypeLimiter::setCreature (CreatureID id)
creature = VLC->creh->creatures[id];
}
std::string CCreatureTypeLimiter::toString() const
{
char buf[100];
sprintf(buf, "CCreatureTypeLimiter(creature=%s, includeUpgrades=%s)",
creature->identifier.c_str(),
(includeUpgrades ? "true" : "false"));
return std::string(buf);
}
JsonNode CCreatureTypeLimiter::toJsonNode() const
{
JsonNode root(JsonNode::DATA_STRUCT);
root["type"].String() = "CREATURE_TYPE_LIMITER";
root["parameters"].Vector().push_back(JsonUtils::stringNode(creature->identifier));
root["parameters"].Vector().push_back(JsonUtils::boolNode(includeUpgrades));
return root;
}
HasAnotherBonusLimiter::HasAnotherBonusLimiter( Bonus::BonusType bonus )
: type(bonus), subtype(0), isSubtypeRelevant(false)
{
@ -1586,6 +1622,12 @@ void LimiterList::add( TLimiterPtr limiter )
// Updaters
std::shared_ptr<Bonus> Bonus::addUpdater(TUpdaterPtr Updater)
{
updater = Updater;
return this->shared_from_this();
}
IUpdater::~IUpdater()
{
}
@ -1630,23 +1672,11 @@ std::string ScalingUpdater::toString() const
JsonNode ScalingUpdater::toJsonNode() const
{
JsonNode root(JsonNode::DATA_STRUCT);
auto addParam = [&](int param)
{
JsonNode paramNode(JsonNode::DATA_INTEGER);
paramNode.Integer() = param;
root["parameters"].Vector().push_back(paramNode);
};
root["type"].String() = "GROWS_WITH_LEVEL";
addParam(valPer20);
root["parameters"].Vector().push_back(JsonUtils::intNode(valPer20));
if(stepSize > 1)
addParam(stepSize);
root["parameters"].Vector().push_back(JsonUtils::intNode(stepSize));
return root;
}
std::shared_ptr<Bonus> Bonus::addUpdater(TUpdaterPtr Updater)
{
updater = Updater;
return this->shared_from_this();
}

View File

@ -592,6 +592,8 @@ public:
virtual ~ILimiter();
virtual int limit(const BonusLimitationContext &context) const; //0 - accept bonus; 1 - drop bonus; 2 - delay (drops eventually)
virtual std::string toString() const;
virtual JsonNode toJsonNode() const;
template <typename Handler> void serialize(Handler &h, const int version)
{
@ -858,6 +860,8 @@ public:
void setCreature (CreatureID id);
int limit(const BonusLimitationContext &context) const override;
virtual std::string toString() const override;
virtual JsonNode toJsonNode() const override;
template <typename Handler> void serialize(Handler &h, const int version)
{

View File

@ -877,3 +877,31 @@ JsonNode JsonUtils::assembleFromFiles(std::string filename)
}
return result;
}
DLL_LINKAGE JsonNode JsonUtils::boolNode(bool value)
{
JsonNode node;
node.Bool() = value;
return node;
}
DLL_LINKAGE JsonNode JsonUtils::floatNode(double value)
{
JsonNode node;
node.Float() = value;
return node;
}
DLL_LINKAGE JsonNode JsonUtils::stringNode(std::string value)
{
JsonNode node;
node.String() = value;
return node;
}
DLL_LINKAGE JsonNode JsonUtils::intNode(si64 value)
{
JsonNode node;
node.Integer() = value;
return node;
}

View File

@ -220,6 +220,12 @@ namespace JsonUtils
/// get schema by json URI: vcmi:<name of file in schemas directory>#<entry in file, optional>
/// example: schema "vcmi:settings" is used to check user settings
DLL_LINKAGE const JsonNode & getSchema(std::string URI);
/// for easy construction of JsonNodes; helps with inserting primitives into vector node
DLL_LINKAGE JsonNode boolNode(bool value);
DLL_LINKAGE JsonNode floatNode(double value);
DLL_LINKAGE JsonNode stringNode(std::string value);
DLL_LINKAGE JsonNode intNode(si64 value);
}
namespace JsonDetail