From f4f416eb16f252b4118b367e5aaf5b3f2ff6885c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zieli=C5=84ski?= Date: Mon, 29 Jul 2024 20:36:23 +0200 Subject: [PATCH] Add RMG option "forcePortal" --- config/schemas/template.json | 2 +- docs/modders/Random_Map_Template.md | 2 +- lib/rmg/CRmgTemplate.cpp | 3 +- lib/rmg/CRmgTemplate.h | 3 +- lib/rmg/modificators/ConnectionsPlacer.cpp | 54 ++++++++++++++++------ lib/rmg/modificators/ConnectionsPlacer.h | 3 +- 6 files changed, 47 insertions(+), 20 deletions(-) diff --git a/config/schemas/template.json b/config/schemas/template.json index a1a353a6d..564210632 100644 --- a/config/schemas/template.json +++ b/config/schemas/template.json @@ -99,7 +99,7 @@ "type": { "type" : "string", - "enum" : ["wide", "fictive", "repulsive"] + "enum" : ["wide", "fictive", "repulsive", "forcePortal"] } } }, diff --git a/docs/modders/Random_Map_Template.md b/docs/modders/Random_Map_Template.md index c133b80d8..bf43cb106 100644 --- a/docs/modders/Random_Map_Template.md +++ b/docs/modders/Random_Map_Template.md @@ -38,7 +38,7 @@ { "a" : "zoneA", "b" : "zoneB", "guard" : 5000, "road" : "false" }, { "a" : "zoneA", "b" : "zoneC", "guard" : 5000, "road" : "random" }, { "a" : "zoneB", "b" : "zoneC", "type" : "wide" } - //"type" can be "guarded" (default), "wide", "fictive" or "repulsive" + //"type" can be "guarded" (default), "wide", "fictive", "repulsive" or "forcePortal" //"wide" connections have no border, or guard. "fictive" and "repulsive" connections are virtual - //they do not create actual path, but only attract or repulse zones, respectively ] diff --git a/lib/rmg/CRmgTemplate.cpp b/lib/rmg/CRmgTemplate.cpp index e5fb4836b..f678b47d3 100644 --- a/lib/rmg/CRmgTemplate.cpp +++ b/lib/rmg/CRmgTemplate.cpp @@ -463,7 +463,8 @@ void ZoneConnection::serializeJson(JsonSerializeFormat & handler) "guarded", "fictive", "repulsive", - "wide" + "wide", + "forcePortal" }; static const std::vector roadOptions = diff --git a/lib/rmg/CRmgTemplate.h b/lib/rmg/CRmgTemplate.h index 1d0382ad1..ba5e49f9b 100644 --- a/lib/rmg/CRmgTemplate.h +++ b/lib/rmg/CRmgTemplate.h @@ -75,7 +75,8 @@ enum class EConnectionType GUARDED = 0, //default FICTIVE, REPULSIVE, - WIDE + WIDE, + FORCE_PORTAL }; enum class ERoadOption diff --git a/lib/rmg/modificators/ConnectionsPlacer.cpp b/lib/rmg/modificators/ConnectionsPlacer.cpp index d6bc3c2c5..ab53acce0 100644 --- a/lib/rmg/modificators/ConnectionsPlacer.cpp +++ b/lib/rmg/modificators/ConnectionsPlacer.cpp @@ -74,6 +74,11 @@ void ConnectionsPlacer::process() } }; + diningPhilosophers([this](const rmg::ZoneConnection& c) + { + forcePortalConnection(c); + }); + diningPhilosophers([this](const rmg::ZoneConnection& c) { selfSideDirectConnection(c); @@ -115,6 +120,16 @@ void ConnectionsPlacer::otherSideConnection(const rmg::ZoneConnection & connecti dCompleted.push_back(connection); } +void ConnectionsPlacer::forcePortalConnection(const rmg::ZoneConnection & connection) +{ + // This should always succeed + if (connection.getConnectionType() == rmg::EConnectionType::FORCE_PORTAL) + { + placeMonolithConnection(connection); + dCompleted.push_back(connection); + } +} + void ConnectionsPlacer::selfSideDirectConnection(const rmg::ZoneConnection & connection) { bool success = false; @@ -410,23 +425,32 @@ void ConnectionsPlacer::selfSideIndirectConnection(const rmg::ZoneConnection & c //4. place monoliths/portals if(!success) { - auto factory = VLC->objtypeh->getHandlerFor(Obj::MONOLITH_TWO_WAY, generator.getNextMonlithIndex()); - auto * teleport1 = factory->create(map.mapInstance->cb, nullptr); - auto * teleport2 = factory->create(map.mapInstance->cb, nullptr); - - RequiredObjectInfo obj1(teleport1, connection.getGuardStrength(), allowRoad); - RequiredObjectInfo obj2(teleport2, connection.getGuardStrength(), allowRoad); - zone.getModificator()->addRequiredObject(obj1); - otherZone->getModificator()->addRequiredObject(obj2); - - assert(otherZone->getModificator()); - otherZone->getModificator()->otherSideConnection(connection); - - success = true; + placeMonolithConnection(connection); } - - if(success) + else + { dCompleted.push_back(connection); + } +} + +void ConnectionsPlacer::placeMonolithConnection(const rmg::ZoneConnection & connection) +{ + auto otherZoneId = (connection.getZoneA() == zone.getId() ? connection.getZoneB() : connection.getZoneA()); + auto & otherZone = map.getZones().at(otherZoneId); + + bool allowRoad = shouldGenerateRoad(connection); + + auto factory = VLC->objtypeh->getHandlerFor(Obj::MONOLITH_TWO_WAY, generator.getNextMonlithIndex()); + auto * teleport1 = factory->create(map.mapInstance->cb, nullptr); + auto * teleport2 = factory->create(map.mapInstance->cb, nullptr); + + RequiredObjectInfo obj1(teleport1, connection.getGuardStrength(), allowRoad); + RequiredObjectInfo obj2(teleport2, connection.getGuardStrength(), allowRoad); + zone.getModificator()->addRequiredObject(obj1); + otherZone->getModificator()->addRequiredObject(obj2); + + assert(otherZone->getModificator()); + otherZone->getModificator()->otherSideConnection(connection); } void ConnectionsPlacer::collectNeighbourZones() diff --git a/lib/rmg/modificators/ConnectionsPlacer.h b/lib/rmg/modificators/ConnectionsPlacer.h index 0350d6d92..ad31609b1 100644 --- a/lib/rmg/modificators/ConnectionsPlacer.h +++ b/lib/rmg/modificators/ConnectionsPlacer.h @@ -23,7 +23,8 @@ public: void init() override; void addConnection(const rmg::ZoneConnection& connection); - + void placeMonolithConnection(const rmg::ZoneConnection& connection); + void forcePortalConnection(const rmg::ZoneConnection & connection); void selfSideDirectConnection(const rmg::ZoneConnection & connection); void selfSideIndirectConnection(const rmg::ZoneConnection & connection); void otherSideConnection(const rmg::ZoneConnection & connection);