From 709dd833d5344a6dec5a790d42e728c1fc648b35 Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Sun, 14 Feb 2016 11:25:01 +0300 Subject: [PATCH] Added hacks for hero identification. --- lib/mapObjects/CGHeroInstance.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/mapObjects/CGHeroInstance.cpp b/lib/mapObjects/CGHeroInstance.cpp index bd055ff90..215d73460 100644 --- a/lib/mapObjects/CGHeroInstance.cpp +++ b/lib/mapObjects/CGHeroInstance.cpp @@ -1472,13 +1472,35 @@ bool CGHeroInstance::hasVisions(const CGObjectInstance * target, const int subty void CGHeroInstance::writeJsonOptions(JsonNode& json) const { + if(type) + { + json["type"].String() = type->identifier; + } + else + { + json["type"].String() = VLC->heroh->heroes[subID]->identifier; + } + CCreatureSet::writeJson(json["army"]); CGObjectInstance::writeOwner(json); CArtifactSet::writeJson(json["artifacts"]); + } void CGHeroInstance::readJsonOptions(const JsonNode& json) { + if(ID == Obj::HERO || ID == Obj::PRISON) + { + auto typeName = json["type"].String(); + + auto rawId = VLC->modh->identifiers.getIdentifier("core", "hero", typeName); + + if(rawId) + subID = rawId.get(); + else + subID = 0; //fallback to Orrin, throw error instead? + } + CCreatureSet::readJson(json["army"]); CGObjectInstance::readOwner(json); CArtifactSet::readJson(json["artifacts"]);