Browse Source

Stabilization

Ivan Savenko 1 year ago
parent
commit
b42f073f0c

+ 4 - 13
lib/gameState/CGameState.cpp

@@ -526,15 +526,6 @@ void CGameState::randomizeMapObjects()
 
 		object->pickRandomObject(getRandomGenerator());
 
-		auto * hero = dynamic_cast<CGHeroInstance *>(object);
-		auto * town = dynamic_cast<CGTownInstance *>(object);
-
-		if (hero && hero->ID != Obj::PRISON)
-			map->heroesOnMap.emplace_back(hero);
-
-		if (town)
-			map->towns.emplace_back(town);
-
 		//handle Favouring Winds - mark tiles under it
 		if(object->ID == Obj::FAVORABLE_WINDS)
 		{
@@ -1825,10 +1816,10 @@ void CGameState::buildBonusSystemTree()
 	buildGlobalTeamPlayerTree();
 	attachArmedObjects();
 
-//	for(CGTownInstance *t : map->towns)
-//	{
-//		t->deserializationFix();
-//	}
+	for(CGTownInstance *t : map->towns)
+	{
+		t->deserializationFix();
+	}
 	// CStackInstance <-> CCreature, CStackInstance <-> CArmedInstance, CArtifactInstance <-> CArtifact
 	// are provided on initializing / deserializing
 

+ 3 - 1
lib/mapObjects/CGDwelling.cpp

@@ -128,7 +128,7 @@ void CGDwelling::pickRandomObject(CRandomGenerator & rand)
 		FactionID faction = randomizeFaction(rand);
 		int level = randomizeLevel(rand);
 		assert(faction != FactionID::NONE && faction != FactionID::NEUTRAL);
-		assert(level >= 1 && level <= 7);
+		assert(level >= 0 && level <= 6);
 		randomizationInfo.reset();
 
 		CreatureID cid = (*VLC->townh)[faction]->town->creatures[level][0];
@@ -163,6 +163,8 @@ void CGDwelling::pickRandomObject(CRandomGenerator & rand)
 			ID = Obj::CREATURE_GENERATOR4;
 			subID = *RandomGeneratorUtil::nextItem(VLC->objtypeh->knownSubObjects(Obj::CREATURE_GENERATOR1), rand);
 		}
+
+		setType(ID, subID);
 	}
 }
 

+ 2 - 2
lib/mapObjects/CGHeroInstance.cpp

@@ -1547,14 +1547,14 @@ void CGHeroInstance::afterAddToMap(CMap * map)
 		}
 	}
 
-	if(ID == Obj::HERO)
+	if(ID != Obj::PRISON)
 	{		
 		map->heroesOnMap.emplace_back(this);
 	}
 }
 void CGHeroInstance::afterRemoveFromMap(CMap* map)
 {
-	if (ID == Obj::HERO)
+	if (ID == Obj::PRISON)
 		vstd::erase_if_present(map->heroesOnMap, this);
 }
 

+ 2 - 4
lib/mapObjects/CGTownInstance.cpp

@@ -1100,14 +1100,12 @@ void CGTownInstance::onTownCaptured(const PlayerColor & winner) const
 
 void CGTownInstance::afterAddToMap(CMap * map)
 {
-	if(ID == Obj::TOWN)
-		map->towns.emplace_back(this);
+	map->towns.emplace_back(this);
 }
 
 void CGTownInstance::afterRemoveFromMap(CMap * map)
 {
-	if (ID == Obj::TOWN)
-		vstd::erase_if_present(map->towns, this);
+	vstd::erase_if_present(map->towns, this);
 }
 
 void CGTownInstance::reset()

+ 3 - 3
lib/mapping/MapFormatH3M.cpp

@@ -1326,14 +1326,14 @@ CGObjectInstance * CMapLoaderH3M::readDwellingRandom(const int3 & mapPosition, s
 
 	object->randomizationInfo = CGDwellingRandomizationInfo();
 
-	bool hasFactionInfo = objectTemplate->id == Obj::RANDOM_DWELLING || objectTemplate->id == Obj::RANDOM_DWELLING_FACTION;
-	bool hasLevelInfo = objectTemplate->id == Obj::RANDOM_DWELLING || objectTemplate->id == Obj::RANDOM_DWELLING_LVL;
+	bool hasFactionInfo = objectTemplate->id == Obj::RANDOM_DWELLING || objectTemplate->id == Obj::RANDOM_DWELLING_LVL;
+	bool hasLevelInfo = objectTemplate->id == Obj::RANDOM_DWELLING || objectTemplate->id == Obj::RANDOM_DWELLING_FACTION;
 
 	if (hasFactionInfo)
 	{
 		object->randomizationInfo->identifier = reader->readUInt32();
 
-		if(object->randomizationInfo->identifier != 0)
+		if(object->randomizationInfo->identifier == 0)
 			reader->readBitmaskFactions(object->randomizationInfo->allowedFactions, false);
 	}
 	else

+ 5 - 2
mapeditor/inspector/inspector.cpp

@@ -235,8 +235,11 @@ void Inspector::updateProperties(CGDwelling * o)
 	
 	addProperty("Owner", o->tempOwner, false);
 	
-	auto * delegate = new PickObjectDelegate(controller, PickObjectDelegate::typedFilter<CGTownInstance>);
-	addProperty("Same as town", PropertyEditorPlaceholder(), delegate, false);
+	if (o->ID == Obj::RANDOM_DWELLING || o->ID == Obj::RANDOM_DWELLING_LVL)
+	{
+		auto * delegate = new PickObjectDelegate(controller, PickObjectDelegate::typedFilter<CGTownInstance>);
+		addProperty("Same as town", PropertyEditorPlaceholder(), delegate, false);
+	}
 }
 
 void Inspector::updateProperties(CGLighthouse * o)