From 93c148ff88ba2c8266b44c336ba7ddd948010de7 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 3 May 2014 14:04:14 +0300 Subject: [PATCH] Things with different gauges don't go together --- source/libr2c2/track.cpp | 4 ++++ source/libr2c2/vehicle.cpp | 3 +++ 2 files changed, 7 insertions(+) diff --git a/source/libr2c2/track.cpp b/source/libr2c2/track.cpp index 7b6bef1..f1fdd99 100644 --- a/source/libr2c2/track.cpp +++ b/source/libr2c2/track.cpp @@ -320,6 +320,10 @@ bool Track::link_to(Object &other) if(!otrack) return false; + float gauge_ratio = otrack->get_type().get_gauge()/type.get_gauge(); + if(gauge_ratio<0.99 || gauge_ratio>1.01) + return false; + float limit = type.get_gauge(); if(!flex && !otrack->get_flex()) limit /= 10; diff --git a/source/libr2c2/vehicle.cpp b/source/libr2c2/vehicle.cpp index cb776f4..6615fb2 100644 --- a/source/libr2c2/vehicle.cpp +++ b/source/libr2c2/vehicle.cpp @@ -106,6 +106,9 @@ void Vehicle::place(const TrackOffsetIter &t, VehiclePlacement::Anchor a) { if(!t) throw invalid_argument("Vehicle::place"); + float gauge_ratio = t->get_type().get_gauge()/type.get_gauge(); + if(gauge_ratio<0.99 || gauge_ratio>1.01) + throw logic_error("Incompatible gauge"); placement.place(t, a); -- 2.45.2