Browse Source

Added hacks for hero identification.

AlexVinS 9 years ago
parent
commit
709dd833d5
1 changed files with 22 additions and 0 deletions
  1. 22 0
      lib/mapObjects/CGHeroInstance.cpp

+ 22 - 0
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"]);