mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
Merge pull request #4964 from vcmi/connections_rework
Connections rework
This commit is contained in:
commit
fcb4dfa985
@ -421,6 +421,7 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
|
||||
}
|
||||
|
||||
ZoneConnection::ZoneConnection():
|
||||
id(-1),
|
||||
zoneA(-1),
|
||||
zoneB(-1),
|
||||
guardStrength(0),
|
||||
@ -430,6 +431,16 @@ ZoneConnection::ZoneConnection():
|
||||
|
||||
}
|
||||
|
||||
int ZoneConnection::getId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
void ZoneConnection::setId(int id)
|
||||
{
|
||||
this->id = id;
|
||||
}
|
||||
|
||||
TRmgTemplateZoneId ZoneConnection::getZoneA() const
|
||||
{
|
||||
return zoneA;
|
||||
@ -473,7 +484,7 @@ rmg::ERoadOption ZoneConnection::getRoadOption() const
|
||||
|
||||
bool operator==(const ZoneConnection & l, const ZoneConnection & r)
|
||||
{
|
||||
return l.zoneA == r.zoneA && l.zoneB == r.zoneB && l.guardStrength == r.guardStrength;
|
||||
return l.id == r.id;
|
||||
}
|
||||
|
||||
void ZoneConnection::serializeJson(JsonSerializeFormat & handler)
|
||||
@ -592,7 +603,7 @@ const CRmgTemplate::Zones & CRmgTemplate::getZones() const
|
||||
|
||||
const std::vector<ZoneConnection> & CRmgTemplate::getConnectedZoneIds() const
|
||||
{
|
||||
return connectedZoneIds;
|
||||
return connections;
|
||||
}
|
||||
|
||||
void CRmgTemplate::validate() const
|
||||
@ -721,7 +732,14 @@ void CRmgTemplate::serializeJson(JsonSerializeFormat & handler)
|
||||
|
||||
{
|
||||
auto connectionsData = handler.enterArray("connections");
|
||||
connectionsData.serializeStruct(connectedZoneIds);
|
||||
connectionsData.serializeStruct(connections);
|
||||
if(!handler.saving)
|
||||
{
|
||||
for(size_t i = 0; i < connections.size(); ++i)
|
||||
{
|
||||
connections[i].setId(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
@ -843,7 +861,7 @@ void CRmgTemplate::afterLoad()
|
||||
}
|
||||
}
|
||||
|
||||
for(const auto & connection : connectedZoneIds)
|
||||
for(const auto & connection : connections)
|
||||
{
|
||||
auto id1 = connection.getZoneA();
|
||||
auto id2 = connection.getZoneB();
|
||||
|
@ -97,6 +97,8 @@ public:
|
||||
|
||||
ZoneConnection();
|
||||
|
||||
int getId() const;
|
||||
void setId(int id);
|
||||
TRmgTemplateZoneId getZoneA() const;
|
||||
TRmgTemplateZoneId getZoneB() const;
|
||||
TRmgTemplateZoneId getOtherZoneId(TRmgTemplateZoneId id) const;
|
||||
@ -108,6 +110,7 @@ public:
|
||||
|
||||
friend bool operator==(const ZoneConnection &, const ZoneConnection &);
|
||||
private:
|
||||
int id;
|
||||
TRmgTemplateZoneId zoneA;
|
||||
TRmgTemplateZoneId zoneB;
|
||||
int guardStrength;
|
||||
@ -294,7 +297,7 @@ private:
|
||||
CPlayerCountRange players;
|
||||
CPlayerCountRange humanPlayers;
|
||||
Zones zones;
|
||||
std::vector<rmg::ZoneConnection> connectedZoneIds;
|
||||
std::vector<rmg::ZoneConnection> connections;
|
||||
std::set<EWaterContent::EWaterContent> allowedWaterContent;
|
||||
std::unique_ptr<JsonNode> mapSettings;
|
||||
|
||||
|
@ -143,7 +143,7 @@ void ConnectionsPlacer::forcePortalConnection(const rmg::ZoneConnection & connec
|
||||
void ConnectionsPlacer::selfSideDirectConnection(const rmg::ZoneConnection & connection)
|
||||
{
|
||||
bool success = false;
|
||||
auto otherZoneId = (connection.getZoneA() == zone.getId() ? connection.getZoneB() : connection.getZoneA());
|
||||
auto otherZoneId = connection.getOtherZoneId(zone.getId());
|
||||
auto & otherZone = map.getZones().at(otherZoneId);
|
||||
bool createRoad = shouldGenerateRoad(connection);
|
||||
|
||||
@ -327,10 +327,9 @@ void ConnectionsPlacer::selfSideDirectConnection(const rmg::ZoneConnection & con
|
||||
|
||||
assert(otherZone->getModificator<RoadPlacer>());
|
||||
otherZone->getModificator<RoadPlacer>()->addRoadNode(roadNode);
|
||||
|
||||
assert(otherZone->getModificator<ConnectionsPlacer>());
|
||||
otherZone->getModificator<ConnectionsPlacer>()->otherSideConnection(connection);
|
||||
}
|
||||
assert(otherZone->getModificator<ConnectionsPlacer>());
|
||||
otherZone->getModificator<ConnectionsPlacer>()->otherSideConnection(connection);
|
||||
|
||||
success = true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user