|
@@ -15,7 +15,9 @@
|
|
|
#include "../json/JsonRandom.h"
|
|
|
#include "../GameLibrary.h"
|
|
|
#include "../mapObjects/CGDwelling.h"
|
|
|
+#include "../mapObjects/ObjectTemplate.h"
|
|
|
#include "../modding/IdentifierStorage.h"
|
|
|
+#include "../CConfigHandler.h"
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
@@ -52,6 +54,30 @@ void DwellingInstanceConstructor::initTypeData(const JsonNode & input)
|
|
|
}
|
|
|
guards = input["guards"];
|
|
|
bannedForRandomDwelling = input["bannedForRandomDwelling"].Bool();
|
|
|
+
|
|
|
+ for (const auto & mapTemplate : getTemplates())
|
|
|
+ onTemplateAdded(mapTemplate);
|
|
|
+}
|
|
|
+
|
|
|
+void DwellingInstanceConstructor::onTemplateAdded(const std::shared_ptr<const ObjectTemplate> mapTemplate)
|
|
|
+{
|
|
|
+ if (bannedForRandomDwelling || settings["mods"]["validation"].String() == "off")
|
|
|
+ return;
|
|
|
+
|
|
|
+ bool invalidForRandomDwelling = false;
|
|
|
+ int3 corner = mapTemplate->getCornerOffset();
|
|
|
+
|
|
|
+ for (const auto & tile : mapTemplate->getBlockedOffsets())
|
|
|
+ invalidForRandomDwelling |= (tile.x != -corner.x && tile.x != -corner.x-1) || (tile.y != -corner.y && tile.y != -corner.y-1);
|
|
|
+
|
|
|
+ for (const auto & tile : {mapTemplate->getVisitableOffset()})
|
|
|
+ invalidForRandomDwelling |= (tile.x != corner.x && tile.x != corner.x+1) || tile.y != corner.y;
|
|
|
+
|
|
|
+ invalidForRandomDwelling |= !mapTemplate->isBlockedAt(corner.x+0, corner.y) && !mapTemplate->isVisibleAt(corner.x+0, corner.y);
|
|
|
+ invalidForRandomDwelling |= !mapTemplate->isBlockedAt(corner.x+1, corner.y) && !mapTemplate->isVisibleAt(corner.x+1, corner.y);
|
|
|
+
|
|
|
+ if (invalidForRandomDwelling)
|
|
|
+ logMod->warn("Dwelling %s has template %s which is not valid for a random dwelling! Dwellings must not block tiles outside 2x2 range and must be visitable in bottom row. Change dwelling mask or mark dwelling as 'bannedForRandomDwelling'", getJsonKey(), mapTemplate->animationFile.getOriginalName());
|
|
|
}
|
|
|
|
|
|
bool DwellingInstanceConstructor::isBannedForRandomDwelling() const
|
|
@@ -152,5 +178,4 @@ std::vector<const CCreature *> DwellingInstanceConstructor::getProducedCreatures
|
|
|
return creatures;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
VCMI_LIB_NAMESPACE_END
|