Browse Source

Merge pull request #4490 from godric3/fix-campaign-hero-placeholder

Fix campaign hero placeholder
Ivan Savenko 1 year ago
parent
commit
a58e209cbd

+ 1 - 1
lib/mapObjectConstructors/CObjectClassesHandler.cpp

@@ -346,7 +346,7 @@ TObjectTypeHandler CObjectClassesHandler::getHandlerFor(MapObjectID type, MapObj
 			return mapObjectTypes.front()->objectTypeHandlers.front();
 
 		auto subID = subtype.getNum();
-		if (type == Obj::PRISON)
+		if (type == Obj::PRISON || type == Obj::HERO_PLACEHOLDER)
 			subID = 0;
 		auto result = mapObjectTypes.at(type.getNum())->objectTypeHandlers.at(subID);
 

+ 2 - 0
lib/mapping/MapFormatJson.cpp

@@ -329,6 +329,8 @@ void CMapFormatJson::serializeHeader(JsonSerializeFormat & handler)
 
 	handler.serializeStruct("defeatMessage", mapHeader->defeatMessage);
 	handler.serializeInt("defeatIconIndex", mapHeader->defeatIconIndex);
+
+	handler.serializeIdArray("reservedCampaignHeroes", mapHeader->reservedCampaignHeroes);
 }
 
 void CMapFormatJson::serializePlayerInfo(JsonSerializeFormat & handler)

+ 1 - 1
mapeditor/inspector/inspector.cpp

@@ -475,7 +475,7 @@ void Inspector::updateProperties()
 	addProperty("TypeName", obj->typeName);
 	addProperty("SubTypeName", obj->subTypeName);
 	
-	if(!dynamic_cast<CGHeroInstance*>(obj))
+	if(obj->ID != Obj::HERO_PLACEHOLDER && !dynamic_cast<CGHeroInstance*>(obj))
 	{
 		auto factory = VLC->objtypeh->getHandlerFor(obj->ID, obj->subID);
 		addProperty("IsStatic", factory->isStaticObject());

+ 12 - 0
mapeditor/mainwindow.cpp

@@ -452,6 +452,18 @@ void MainWindow::saveMap()
 	
 	Translations::cleanupRemovedItems(*controller.map());
 
+	for(auto obj : controller.map()->objects)
+	{
+		if(obj->ID == Obj::HERO_PLACEHOLDER)
+		{
+			auto hero = dynamic_cast<CGHeroPlaceholder *>(obj.get());
+			if(hero->heroType.has_value())
+			{
+				controller.map()->reservedCampaignHeroes.insert(hero->heroType.value());
+			}
+		}
+	}
+
 	CMapService mapService;
 	try
 	{