From 1807a8a53682836d309f50d5135be47581428429 Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Wed, 26 Dec 2012 09:46:09 +0000 Subject: [PATCH] - Bonus subtype will now be resolved using string identifiers. - Registered secondary skills and resource names in identifier pool --- config/artifacts.json | 92 +++++++++++++++++++++---------------------- lib/CHeroHandler.cpp | 7 +++- lib/CModHandler.cpp | 6 +++ lib/JsonNode.cpp | 32 +++++++++++++-- lib/JsonNode.h | 1 + 5 files changed, 88 insertions(+), 50 deletions(-) diff --git a/config/artifacts.json b/config/artifacts.json index 4b8111363..4fac463ae 100644 --- a/config/artifacts.json +++ b/config/artifacts.json @@ -910,7 +910,7 @@ { "bonuses" : [ { - "subtype" : 1, + "subtype" : "skill.archery", "type" : "SECONDARY_SKILL_PREMY", "val" : 5, "valueType" : "ADDITIVE_VALUE" @@ -923,7 +923,7 @@ { "bonuses" : [ { - "subtype" : 1, + "subtype" : "skill.archery", "type" : "SECONDARY_SKILL_PREMY", "val" : 10, "valueType" : "ADDITIVE_VALUE" @@ -936,7 +936,7 @@ { "bonuses" : [ { - "subtype" : 1, + "subtype" : "skill.archery", "type" : "SECONDARY_SKILL_PREMY", "val" : 15, "valueType" : "ADDITIVE_VALUE" @@ -949,7 +949,7 @@ { "bonuses" : [ { - "subtype" : 11, + "subtype" : "skill.eagleEye", "type" : "SECONDARY_SKILL_PREMY", "val" : 5, "valueType" : "ADDITIVE_VALUE" @@ -962,7 +962,7 @@ { "bonuses" : [ { - "subtype" : 11, + "subtype" : "skill.eagleEye", "type" : "SECONDARY_SKILL_PREMY", "val" : 10, "valueType" : "ADDITIVE_VALUE" @@ -975,7 +975,7 @@ { "bonuses" : [ { - "subtype" : 11, + "subtype" : "skill.eagleEye", "type" : "SECONDARY_SKILL_PREMY", "val" : 15, "valueType" : "ADDITIVE_VALUE" @@ -1401,7 +1401,7 @@ { "bonuses" : [ { - "subtype" : 59, + "subtype" : "spell.berserk", "type" : "SPELL_IMMUNITY", "val" : 0, "valueType" : "BASE_NUMBER" @@ -1414,7 +1414,7 @@ { "bonuses" : [ { - "subtype" : 62, + "subtype" : "spell.blind", "type" : "SPELL_IMMUNITY", "val" : 0, "valueType" : "BASE_NUMBER" @@ -1427,7 +1427,7 @@ { "bonuses" : [ { - "subtype" : 42, + "subtype" : "spell.curse", "type" : "SPELL_IMMUNITY", "val" : 0, "valueType" : "BASE_NUMBER" @@ -1440,7 +1440,7 @@ { "bonuses" : [ { - "subtype" : 24, + "subtype" : "spell.deathRipple", "type" : "SPELL_IMMUNITY", "val" : 0, "valueType" : "BASE_NUMBER" @@ -1454,7 +1454,7 @@ "bonuses" : [ { "limiter" : "IS_UNDEAD", - "subtype" : 25, + "subtype" : "spell.destroyUndead", "type" : "SPELL_IMMUNITY", "val" : 0, "valueType" : "BASE_NUMBER" @@ -1467,7 +1467,7 @@ { "bonuses" : [ { - "subtype" : 60, + "subtype" : "spell.hypnotize", "type" : "SPELL_IMMUNITY", "val" : 0, "valueType" : "BASE_NUMBER" @@ -1480,13 +1480,13 @@ { "bonuses" : [ { - "subtype" : 17, + "subtype" : "spell.lightningBolt", "type" : "SPELL_IMMUNITY", "val" : 0, "valueType" : "BASE_NUMBER" }, { - "subtype" : 19, + "subtype" : "spell.chainLightning", "type" : "SPELL_IMMUNITY", "val" : 0, "valueType" : "BASE_NUMBER" @@ -1499,7 +1499,7 @@ { "bonuses" : [ { - "subtype" : 61, + "subtype" : "spell.forgetfulness", "type" : "SPELL_IMMUNITY", "val" : 0, "valueType" : "BASE_NUMBER" @@ -1529,7 +1529,7 @@ { "bonuses" : [ { - "subtype" : 4, + "subtype" : "resource.crystal", "type" : "GENERATE_RESOURCE", "val" : 1, "valueType" : "BASE_NUMBER" @@ -1542,7 +1542,7 @@ { "bonuses" : [ { - "subtype" : 5, + "subtype" : "resource.gems", "type" : "GENERATE_RESOURCE", "val" : 1, "valueType" : "BASE_NUMBER" @@ -1555,7 +1555,7 @@ { "bonuses" : [ { - "subtype" : 1, + "subtype" : "resource.mercury", "type" : "GENERATE_RESOURCE", "val" : 1, "valueType" : "BASE_NUMBER" @@ -1568,7 +1568,7 @@ { "bonuses" : [ { - "subtype" : 2, + "subtype" : "resource.ore", "type" : "GENERATE_RESOURCE", "val" : 1, "valueType" : "BASE_NUMBER" @@ -1581,7 +1581,7 @@ { "bonuses" : [ { - "subtype" : 3, + "subtype" : "resource.sulfur", "type" : "GENERATE_RESOURCE", "val" : 1, "valueType" : "BASE_NUMBER" @@ -1594,7 +1594,7 @@ { "bonuses" : [ { - "subtype" : 0, + "subtype" : "resource.wood", "type" : "GENERATE_RESOURCE", "val" : 1, "valueType" : "BASE_NUMBER" @@ -1607,7 +1607,7 @@ { "bonuses" : [ { - "subtype" : 6, + "subtype" : "resource.gold", "type" : "GENERATE_RESOURCE", "val" : 1000, "valueType" : "BASE_NUMBER" @@ -1620,7 +1620,7 @@ { "bonuses" : [ { - "subtype" : 6, + "subtype" : "resource.gold", "type" : "GENERATE_RESOURCE", "val" : 750, "valueType" : "BASE_NUMBER" @@ -1633,7 +1633,7 @@ { "bonuses" : [ { - "subtype" : 6, + "subtype" : "resource.gold", "type" : "GENERATE_RESOURCE", "val" : 500, "valueType" : "BASE_NUMBER" @@ -1681,13 +1681,13 @@ "valueType" : "BASE_NUMBER" }, { - "subtype" : 0, + "subtype" : "spell.summonBoat", "type" : "SPELL", "val" : 3, "valueType" : "INDEPENDENT_MAX" }, { - "subtype" : 1, + "subtype" : "spell.scuttleBoat", "type" : "SPELL", "val" : 3, "valueType" : "INDEPENDENT_MAX" @@ -1744,13 +1744,13 @@ { "bonuses" : [ { - "subtype" : 26, + "subtype" : "spell.armageddon", "type" : "SPELL", "val" : 3, "valueType" : "INDEPENDENT_MAX" }, { - "subtype" : 26, + "subtype" : "spell.armageddon", "type" : "SPELL_IMMUNITY", "val" : 0, "valueType" : "BASE_NUMBER" @@ -1792,7 +1792,7 @@ "valueType" : "BASE_NUMBER" }, { - "subtype" : 48, + "subtype" : "spell.prayer", "type" : "OPENING_BATTLE_SPELL", "val" : 10, "valueType" : "BASE_NUMBER" @@ -1855,25 +1855,25 @@ { "bonuses" : [ { - "subtype" : 54, + "subtype" : "spell.slow", "type" : "OPENING_BATTLE_SPELL", "val" : 50, "valueType" : "BASE_NUMBER" }, { - "subtype" : 47, + "subtype" : "spell.curse", "type" : "OPENING_BATTLE_SPELL", "val" : 50, "valueType" : "BASE_NUMBER" }, { - "subtype" : 45, + "subtype" : "spell.weakness", "type" : "OPENING_BATTLE_SPELL", "val" : 50, "valueType" : "BASE_NUMBER" }, { - "subtype" : 52, + "subtype" : "spell.misfortune", "type" : "OPENING_BATTLE_SPELL", "val" : 50, "valueType" : "BASE_NUMBER" @@ -1930,7 +1930,7 @@ { "bonuses" : [ { - "subtype" : 57, + "subtype" : "spell.titanBolt", "type" : "SPELL", "val" : 3, "valueType" : "BASE_NUMBER" @@ -2037,25 +2037,25 @@ { "bonuses" : [ { - "subtype" : 1, + "subtype" : "resource.crystal", "type" : "GENERATE_RESOURCE", "val" : 4, "valueType" : "BASE_NUMBER" }, { - "subtype" : 3, + "subtype" : "resource.gems", "type" : "GENERATE_RESOURCE", "val" : 4, "valueType" : "BASE_NUMBER" }, { - "subtype" : 4, + "subtype" : "resource.mercury", "type" : "GENERATE_RESOURCE", "val" : 4, "valueType" : "BASE_NUMBER" }, { - "subtype" : 5, + "subtype" : "resource.sulfur", "type" : "GENERATE_RESOURCE", "val" : 4, "valueType" : "BASE_NUMBER" @@ -2080,13 +2080,13 @@ "valueType" : "BASE_NUMBER" }, { - "subtype" : 18, + "subtype" : "spell.implosion", "type" : "SPELLCASTER", "val" : 0, "valueType" : "BASE_NUMBER" }, { - "subtype" : 21, + "subtype" : "spell.fireball", "type" : "SPELLCASTER", "val" : 0, "valueType" : "BASE_NUMBER" @@ -2097,14 +2097,14 @@ "valueType" : "BASE_NUMBER" }, { - "subtype" : 63, + "subtype" : "creature.vampireLord", "type" : "DAEMON_SUMMONING", "val" : 10, "valueType" : "BASE_NUMBER" }, { "additionalInfo" : 2, - "subtype" : 17, + "subtype" : "spell.lightningBolt", "type" : "ENCHANTER", "val" : 0, "valueType" : "BASE_NUMBER" @@ -2166,28 +2166,28 @@ }, { "additionalInfo" : 1, - "subtype" : 75, + "subtype" : "spell.age", "type" : "SPELL_BEFORE_ATTACK", "val" : 50, "valueType" : "BASE_NUMBER" }, { "additionalInfo" : 1, - "subtype" : 59, + "subtype" : "spell.berserk", "type" : "SPELL_AFTER_ATTACK", "val" : 50, "valueType" : "BASE_NUMBER" }, { "additionalInfo" : 1, - "subtype" : 71, + "subtype" : "spell.poison", "type" : "SPELL_AFTER_ATTACK", "val" : 50, "valueType" : "BASE_NUMBER" }, { "additionalInfo" : 1, - "subtype" : 47, + "subtype" : "spell.disruptingRay", "type" : "SPELL_AFTER_ATTACK", "val" : 50, "valueType" : "BASE_NUMBER" diff --git a/lib/CHeroHandler.cpp b/lib/CHeroHandler.cpp index 9a7d87383..4f8da6332 100644 --- a/lib/CHeroHandler.cpp +++ b/lib/CHeroHandler.cpp @@ -205,7 +205,12 @@ CHeroHandler::~CHeroHandler() } CHeroHandler::CHeroHandler() -{} +{ + for (int i = 0; i < GameConstants::SKILL_QUANTITY; ++i) + { + VLC->modh->identifiers.registerObject("skill." + SecondarySkill::names[i], i); + } +} void CHeroHandler::load(const JsonNode & input) { diff --git a/lib/CModHandler.cpp b/lib/CModHandler.cpp index 01e3b0280..5d55108d0 100644 --- a/lib/CModHandler.cpp +++ b/lib/CModHandler.cpp @@ -10,6 +10,7 @@ #include "CTownHandler.h" #include "CHeroHandler.h" #include "CObjectHandler.h" +#include "StringConstants.h" /* * CModHandler.h, part of VCMI engine @@ -89,6 +90,11 @@ CModHandler::CModHandler() { VLC->modh = this; + for (int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i) + { + identifiers.registerObject("resource." + GameConstants::RESOURCE_NAMES[i], i); + } + loadConfigFromFile ("defaultMods"); } diff --git a/lib/JsonNode.cpp b/lib/JsonNode.cpp index e0e068aba..ab0778dfb 100644 --- a/lib/JsonNode.cpp +++ b/lib/JsonNode.cpp @@ -13,9 +13,14 @@ #include "HeroBonus.h" #include "Filesystem/CResourceLoader.h" +#include "VCMI_Lib.h" //for identifier resolution +#include "CModHandler.h" using namespace JsonDetail; +class LibClasses; +class CModHandler; + static const JsonNode nullNode; JsonNode::JsonNode(JsonType Type): @@ -920,6 +925,29 @@ const T & parseByMap(const std::map & map, const JsonNode * val, return defaultValue; }; +void JsonUtils::resolveIdentifier (si32 &var, const JsonNode &node, std::string name) +{ + const JsonNode *value; + value = &node[name]; + if (!value->isNull()) + { + switch (value->getType()) + { + case JsonNode::DATA_FLOAT: + var = value->Float(); + break; + case JsonNode::DATA_STRING: + VLC->modh->identifiers.requestIdentifier (value->String(), [&](si32 identifier) + { + var = identifier; + }); + break; + default: + tlog2 << "Error! Wrong indentifier used for value of " << name; + } + } +} + Bonus * JsonUtils::parseBonus (const JsonNode &ability) { @@ -935,9 +963,7 @@ Bonus * JsonUtils::parseBonus (const JsonNode &ability) } b->type = it->second; - value = &ability["subtype"]; - if (!value->isNull()) - b->subtype = value->Float(); + resolveIdentifier (b->subtype, ability, "subtype"); value = &ability["val"]; if (!value->isNull()) diff --git a/lib/JsonNode.h b/lib/JsonNode.h index dbfc0a56a..2edd90d97 100644 --- a/lib/JsonNode.h +++ b/lib/JsonNode.h @@ -117,6 +117,7 @@ namespace JsonUtils DLL_LINKAGE Bonus * parseBonus (const JsonVector &ability_vec); DLL_LINKAGE Bonus * parseBonus (const JsonNode &bonus); DLL_LINKAGE void unparseBonus (JsonNode &node, const Bonus * bonus); + DLL_LINKAGE void resolveIdentifier (si32 &var, const JsonNode &node, std::string name); /// recursivly merges source into dest, replacing identical fields /// struct : recursively calls this function