From 6f203fb7e296c6b857097c551aee51d30d83bbd1 Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Mon, 24 Aug 2015 11:55:45 +0300 Subject: [PATCH] Save string identifiers for all game objects --- lib/CArtHandler.cpp | 12 ++++++------ lib/CArtHandler.h | 9 +++++++-- lib/CCreatureHandler.cpp | 15 ++++++++------- lib/CCreatureHandler.h | 8 +++++++- lib/CHeroHandler.cpp | 16 ++++++++-------- lib/CHeroHandler.h | 10 +++++++--- lib/CTownHandler.cpp | 2 +- lib/CTownHandler.h | 2 +- lib/Connection.h | 2 +- lib/IHandlerBase.h | 6 +++--- lib/spells/CSpellHandler.cpp | 2 +- lib/spells/CSpellHandler.h | 4 ++-- 12 files changed, 52 insertions(+), 36 deletions(-) diff --git a/lib/CArtHandler.cpp b/lib/CArtHandler.cpp index ac4a310a9..4cc618023 100644 --- a/lib/CArtHandler.cpp +++ b/lib/CArtHandler.cpp @@ -201,28 +201,28 @@ std::vector CArtHandler::loadLegacyData(size_t dataSize) void CArtHandler::loadObject(std::string scope, std::string name, const JsonNode & data) { - auto object = loadFromJson(data); + auto object = loadFromJson(data, name); object->id = ArtifactID(artifacts.size()); object->iconIndex = object->id + 5; artifacts.push_back(object); - VLC->modh->identifiers.registerObject(scope, "artifact", name, object->id); + registerObject(scope, "artifact", object->identifier, object->id); } void CArtHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) { - auto object = loadFromJson(data); + auto object = loadFromJson(data, name); object->id = ArtifactID(index); object->iconIndex = object->id; assert(artifacts[index] == nullptr); // ensure that this id was not loaded before artifacts[index] = object; - VLC->modh->identifiers.registerObject(scope, "artifact", name, object->id); + registerObject(scope, "artifact", object->identifier, object->id); } -CArtifact * CArtHandler::loadFromJson(const JsonNode & node) +CArtifact * CArtHandler::loadFromJson(const JsonNode & node, const std::string & identifier) { CArtifact * art; @@ -234,7 +234,7 @@ CArtifact * CArtHandler::loadFromJson(const JsonNode & node) loadGrowingArt(growing, node); art = growing; } - + art->identifier = identifier; const JsonNode & text = node["text"]; art->name = text["name"].String(); art->description = text["description"].String(); diff --git a/lib/CArtHandler.h b/lib/CArtHandler.h index 5a6f4a841..f9d860a2c 100644 --- a/lib/CArtHandler.h +++ b/lib/CArtHandler.h @@ -48,7 +48,8 @@ protected: std::string eventText; //short story displayed upon picking public: enum EartClass {ART_SPECIAL=1, ART_TREASURE=2, ART_MINOR=4, ART_MAJOR=8, ART_RELIC=16}; //artifact classes - + + std::string identifier; std::string image; std::string large; // big image for cutom artifacts, used in drag & drop std::string advMapDef; //used for adventure map object @@ -79,6 +80,10 @@ public: h & static_cast(*this); h & name & description & eventText & image & large & advMapDef & iconIndex & price & possibleSlots & constituents & constituentOf & aClass & id; + if(version>=755) + { + h & identifier; + } } CArtifact(); @@ -244,7 +249,7 @@ public: } private: - CArtifact * loadFromJson(const JsonNode & node); + CArtifact * loadFromJson(const JsonNode & node, const std::string & identifier); void addSlot(CArtifact * art, const std::string & slotID); void loadSlots(CArtifact * art, const JsonNode & node); diff --git a/lib/CCreatureHandler.cpp b/lib/CCreatureHandler.cpp index 2f30d3c48..a536b5f18 100644 --- a/lib/CCreatureHandler.cpp +++ b/lib/CCreatureHandler.cpp @@ -357,23 +357,23 @@ std::vector CCreatureHandler::loadLegacyData(size_t dataSize) void CCreatureHandler::loadObject(std::string scope, std::string name, const JsonNode & data) { - auto object = loadFromJson(data); + auto object = loadFromJson(data, name); object->setId(CreatureID(creatures.size())); object->iconIndex = object->idNumber + 2; creatures.push_back(object); - VLC->modh->identifiers.registerObject(scope, "creature", name, object->idNumber); + registerObject(scope, "creature", name, object->idNumber); for(auto node : data["extraNames"].Vector()) { - VLC->modh->identifiers.registerObject(scope, "creature", node.String(), object->idNumber); + registerObject(scope, "creature", node.String(), object->idNumber); } } void CCreatureHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) { - auto object = loadFromJson(data); + auto object = loadFromJson(data, name); object->setId(CreatureID(index)); object->iconIndex = object->idNumber + 2; @@ -385,10 +385,10 @@ void CCreatureHandler::loadObject(std::string scope, std::string name, const Jso assert(creatures[index] == nullptr); // ensure that this id was not loaded before creatures[index] = object; - VLC->modh->identifiers.registerObject(scope, "creature", name, object->idNumber); + registerObject(scope, "creature", name, object->idNumber); for(auto & node : data["extraNames"].Vector()) { - VLC->modh->identifiers.registerObject(scope, "creature", node.String(), object->idNumber); + registerObject(scope, "creature", node.String(), object->idNumber); } } @@ -561,11 +561,12 @@ void CCreatureHandler::loadUnitAnimInfo(JsonNode & graphics, CLegacyConfigParser graphics.Struct().erase("missile"); } -CCreature * CCreatureHandler::loadFromJson(const JsonNode & node) +CCreature * CCreatureHandler::loadFromJson(const JsonNode & node, const std::string & identifier) { auto cre = new CCreature(); const JsonNode & name = node["name"]; + cre->identifier = identifier; cre->nameSing = name["singular"].String(); cre->namePl = name["plural"].String(); diff --git a/lib/CCreatureHandler.h b/lib/CCreatureHandler.h index 12ba7e146..b78753f5d 100644 --- a/lib/CCreatureHandler.h +++ b/lib/CCreatureHandler.h @@ -26,6 +26,8 @@ class CCreature; class DLL_LINKAGE CCreature : public CBonusSystemNode { public: + std::string identifier; + std::string nameRef; // reference name, stringID std::string nameSing;// singular name, e.g. Centaur std::string namePl; // plural name, e.g. Centaurs @@ -136,6 +138,10 @@ public: h & idNumber & faction & sounds & animation; h & doubleWide & special; + if(version>=755) + { + h & identifier; + } } CCreature(); @@ -148,7 +154,7 @@ private: CBonusSystemNode creaturesOfLevel[GameConstants::CREATURES_PER_TOWN + 1];//index 0 is used for creatures of unknown tier or outside <1-7> range /// load one creature from json config - CCreature * loadFromJson(const JsonNode & node); + CCreature * loadFromJson(const JsonNode & node, const std::string & identifier); void loadJsonAnimation(CCreature * creature, const JsonNode & graphics); void loadStackExperience(CCreature * creature, const JsonNode &input); diff --git a/lib/CHeroHandler.cpp b/lib/CHeroHandler.cpp index 25c43d4a4..5c5a73bf3 100644 --- a/lib/CHeroHandler.cpp +++ b/lib/CHeroHandler.cpp @@ -96,12 +96,12 @@ bool CObstacleInfo::isAppropriate(ETerrainType terrainType, int specialBattlefie return vstd::contains(allowedTerrains, terrainType); } -CHeroClass *CHeroClassHandler::loadFromJson(const JsonNode & node) +CHeroClass * CHeroClassHandler::loadFromJson(const JsonNode & node, const std::string & identifier) { std::string affinityStr[2] = { "might", "magic" }; auto heroClass = new CHeroClass(); - + heroClass->identifier = identifier; heroClass->imageBattleFemale = node["animation"]["battle"]["female"].String(); heroClass->imageBattleMale = node["animation"]["battle"]["male"].String(); //MODS COMPATIBILITY FOR 0.96 @@ -192,7 +192,7 @@ std::vector CHeroClassHandler::loadLegacyData(size_t dataSize) void CHeroClassHandler::loadObject(std::string scope, std::string name, const JsonNode & data) { - auto object = loadFromJson(data); + auto object = loadFromJson(data, name); object->id = heroClasses.size(); heroClasses.push_back(object); @@ -210,7 +210,7 @@ void CHeroClassHandler::loadObject(std::string scope, std::string name, const Js void CHeroClassHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) { - auto object = loadFromJson(data); + auto object = loadFromJson(data, name); object->id = index; assert(heroClasses[index] == nullptr); // ensure that this id was not loaded before @@ -288,10 +288,10 @@ CHeroHandler::CHeroHandler() loadExperience(); } -CHero * CHeroHandler::loadFromJson(const JsonNode & node) +CHero * CHeroHandler::loadFromJson(const JsonNode & node, const std::string & identifier) { auto hero = new CHero; - + hero->identifier = identifier; hero->sex = node["female"].Bool(); hero->special = node["special"].Bool(); @@ -536,7 +536,7 @@ std::vector CHeroHandler::loadLegacyData(size_t dataSize) void CHeroHandler::loadObject(std::string scope, std::string name, const JsonNode & data) { - auto object = loadFromJson(data); + auto object = loadFromJson(data, name); object->ID = HeroTypeID(heroes.size()); object->imageIndex = heroes.size() + 30; // 2 special frames + some extra portraits @@ -547,7 +547,7 @@ void CHeroHandler::loadObject(std::string scope, std::string name, const JsonNod void CHeroHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) { - auto object = loadFromJson(data); + auto object = loadFromJson(data, name); object->ID = HeroTypeID(index); object->imageIndex = index; diff --git a/lib/CHeroHandler.h b/lib/CHeroHandler.h index 6c87666d6..b0c22a4c6 100644 --- a/lib/CHeroHandler.h +++ b/lib/CHeroHandler.h @@ -59,7 +59,7 @@ public: h & minAmount & maxAmount & creature; } }; - + std::string identifier; HeroTypeID ID; si32 imageIndex; @@ -92,6 +92,10 @@ public: h & ID & imageIndex & initialArmy & heroClass & secSkillsInit & spec & specialty & spells & haveSpellBook & sex & special; h & name & biography & specName & specDescr & specTooltip; h & iconSpecSmall & iconSpecLarge & portraitSmall & portraitLarge; + if(version>=755) + { + h & identifier; + } } }; @@ -169,7 +173,7 @@ struct DLL_LINKAGE CObstacleInfo class DLL_LINKAGE CHeroClassHandler : public IHandlerBase { - CHeroClass *loadFromJson(const JsonNode & node); + CHeroClass *loadFromJson(const JsonNode & node, const std::string & identifier); public: std::vector< ConstTransitivePtr > heroClasses; @@ -207,7 +211,7 @@ class DLL_LINKAGE CHeroHandler : public IHandlerBase void loadObstacles(); /// Load single hero from json - CHero * loadFromJson(const JsonNode & node); + CHero * loadFromJson(const JsonNode & node, const std::string & identifier); public: CHeroClassHandler classes; diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index 340deab4c..cbcda27c2 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -633,7 +633,7 @@ void CTownHandler::loadPuzzle(CFaction &faction, const JsonNode &source) assert(faction.puzzleMap.size() == GameConstants::PUZZLE_MAP_PIECES); } -CFaction * CTownHandler::loadFromJson(const JsonNode &source, std::string identifier) +CFaction * CTownHandler::loadFromJson(const JsonNode &source, const std::string & identifier) { auto faction = new CFaction(); diff --git a/lib/CTownHandler.h b/lib/CTownHandler.h index 8997b6712..e0a289b0b 100644 --- a/lib/CTownHandler.h +++ b/lib/CTownHandler.h @@ -250,7 +250,7 @@ class DLL_LINKAGE CTownHandler : public IHandlerBase void loadPuzzle(CFaction & faction, const JsonNode & source); - CFaction * loadFromJson(const JsonNode & data, std::string identifier); + CFaction * loadFromJson(const JsonNode & data, const std::string & identifier); public: std::vector > factions; diff --git a/lib/Connection.h b/lib/Connection.h index 49acb9c14..07c724af1 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -27,7 +27,7 @@ #include "mapping/CCampaignHandler.h" //for CCampaignState #include "rmg/CMapGenerator.h" // for CMapGenOptions -const ui32 version = 754; +const ui32 version = 755; const ui32 minSupportedVersion = 753; class CISer; diff --git a/lib/IHandlerBase.h b/lib/IHandlerBase.h index c26b6f944..eb5e68482 100644 --- a/lib/IHandlerBase.h +++ b/lib/IHandlerBase.h @@ -65,7 +65,7 @@ public: void loadObject(std::string scope, std::string name, const JsonNode & data) override { auto type_name = getTypeName(); - auto object = loadFromJson(data); + auto object = loadFromJson(data, name); object->id = _ObjectID(objects.size()); objects.push_back(object); @@ -75,7 +75,7 @@ public: void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override { auto type_name = getTypeName(); - auto object = loadFromJson(data); + auto object = loadFromJson(data, name); object->id = _ObjectID(index); @@ -99,7 +99,7 @@ public: return objects[raw_id]; } protected: - virtual _Object * loadFromJson(const JsonNode & json) = 0; + virtual _Object * loadFromJson(const JsonNode & json, const std::string & identifier) = 0; virtual const std::string getTypeName() const = 0; public: //todo: make private std::vector> objects; diff --git a/lib/spells/CSpellHandler.cpp b/lib/spells/CSpellHandler.cpp index 1beaac6e3..284be7d34 100644 --- a/lib/spells/CSpellHandler.cpp +++ b/lib/spells/CSpellHandler.cpp @@ -799,7 +799,7 @@ const std::string CSpellHandler::getTypeName() const return "spell"; } -CSpell * CSpellHandler::loadFromJson(const JsonNode & json) +CSpell * CSpellHandler::loadFromJson(const JsonNode & json, const std::string & identifier) { using namespace SpellConfig; diff --git a/lib/spells/CSpellHandler.h b/lib/spells/CSpellHandler.h index 332b7396e..99fc28dda 100644 --- a/lib/spells/CSpellHandler.h +++ b/lib/spells/CSpellHandler.h @@ -172,7 +172,7 @@ public: }; SpellID id; - std::string identifier; //??? + std::string identifier; std::string name; si32 level; @@ -366,5 +366,5 @@ public: } protected: - CSpell * loadFromJson(const JsonNode & json) override; + CSpell * loadFromJson(const JsonNode & json, const std::string & identifier) override; };