Skip to content

Instantly share code, notes, and snippets.

@Wolfolo
Created December 11, 2016 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wolfolo/c9c5189b98b44e13e1f97fa198293829 to your computer and use it in GitHub Desktop.
Save Wolfolo/c9c5189b98b44e13e1f97fa198293829 to your computer and use it in GitHub Desktop.
diff --git a/src/road.h b/src/road.h
index 0defe74..3bde774 100644
--- a/src/road.h
+++ b/src/road.h
@@ -25,9 +25,11 @@
/** Roadtype flags. Starts with RO instead of R because R is used for rails */
enum RoadTypeFlags {
ROTF_CATENARY = 0, ///< Bit number for adding catenary
+ ROTF_DISALLOW_JUNCTIONS = 1, ///< Bit number for disallowing junctions (only build straight line or curve)
ROTFB_NONE = 0, ///< All flags cleared.
ROTFB_CATENARY = 1 << ROTF_CATENARY, ///< Value for drawing a catenary.
+ ROTFB_DISALLOW_JUNCTIONS = 1 << ROTF_DISALLOW_JUNCTIONS, ///< Value for disallowing junctions.
};
DECLARE_ENUM_AS_BIT_SET(RoadTypeFlags)
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index 6687aa4..bf232e0 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -626,6 +626,7 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
RoadBits existing = ROAD_NONE;
RoadBits other_bits = ROAD_NONE;
+ RoadTypeIdentifiers existing_rtids;
/* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero
* if a non-company is building the road */
@@ -666,8 +667,15 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
other_bits = GetOtherRoadBits(tile, rtid.basetype);
if (!HasTileRoadType(tile, rtid.basetype)) break;
-
+
+ existing_rtids = RoadTypeIdentifiers::FromTile(tile);
existing = GetRoadBits(tile, rtid.basetype);
+ bool disallow_junctions = HasBit(GetRoadTypeInfo(rtid)->flags, ROTF_DISALLOW_JUNCTIONS)
+ || HasBit(GetRoadTypeInfo(existing_rtids.GetType(rtid.basetype))->flags, ROTF_DISALLOW_JUNCTIONS);
+ if (rtid.IsRoad() && IsRoadJunction(existing | pieces) && disallow_junctions) {
+ /* Some roads disallow junctions */
+ return_cmd_error(STR_ERROR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION); // TODO
+ }
bool crossing = !IsStraightRoad(existing | pieces);
if (rtid.IsRoad() && (GetDisallowedRoadDirections(tile) != DRD_NONE || toggle_drd != DRD_NONE) && crossing) {
/* Junctions cannot be one-way */
diff --git a/src/road_func.h b/src/road_func.h
index d4828cb..a611fb0 100644
--- a/src/road_func.h
+++ b/src/road_func.h
@@ -123,6 +123,12 @@ static inline bool IsStraightRoad(RoadBits r)
return (r == ROAD_X || r == ROAD_Y);
}
+static inline bool IsRoadJunction(RoadBits r)
+{
+ assert(IsValidRoadBits(r));
+ return (CountBits(r) > 2);
+}
+
/**
* Create the road-part which belongs to the given DiagDirection
*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment