Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 42 additions & 17 deletions Transit.Addon.RoadExtensions/Roads/Highways/Common/HighwayHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static NetInfo.Lane SetHighwayRightShoulder(this NetInfo hwInfo, NetInfo
return rightHwLane;
}

public static IEnumerable<NetInfo.Lane> SetHighwayVehicleLanes(this NetInfo hwInfo, int lanesToAdd = 0)
public static IEnumerable<NetInfo.Lane> SetHighwayVehicleLanes(this NetInfo hwInfo, int lanesToAdd = 0, bool isTwoWay = false)
{
if (lanesToAdd < 0)
{
Expand Down Expand Up @@ -145,7 +145,7 @@ public static NetInfo.Lane SetHighwayRightShoulder(this NetInfo hwInfo, NetInfo
var nbLanes = vehicleLanes.Count();
var positionStart = laneWidth * ((1f - nbLanes) / 2f);

for (var i = 0; i < vehicleLanes.Length; i++)
for (var i = 0; i < nbLanes; i++)
{
var l = vehicleLanes[i];
l.m_stopType = VehicleInfo.VehicleType.None;
Expand All @@ -159,6 +159,17 @@ public static NetInfo.Lane SetHighwayRightShoulder(this NetInfo hwInfo, NetInfo
{
prop.m_position = new Vector3(0, 0, 0);
}
if (isTwoWay)
{
if (l.m_position < 0.0f)
{
l.m_direction = NetInfo.Direction.Backward;
}
else
{
l.m_direction = NetInfo.Direction.Forward;
}
}
}

return vehicleLanes;
Expand Down Expand Up @@ -325,26 +336,30 @@ public static void SetHighwayRightLights(this ICollection<NetLaneProps.Prop> pro
public static void AddLeftWallLights(this ICollection<NetLaneProps.Prop> props, int xPos = 0)
{
var wallLightPropInfo = Prefabs.Find<PropInfo>("Wall Light Orange");
var wallLightProp = new NetLaneProps.Prop();
wallLightProp.m_prop = wallLightPropInfo.ShallowClone();
wallLightProp.m_probability = 100;
wallLightProp.m_repeatDistance = 20;
wallLightProp.m_segmentOffset = 0;
wallLightProp.m_angle = 270;
wallLightProp.m_position = new Vector3(xPos, 1.5f, 0);
var wallLightProp = new NetLaneProps.Prop
{
m_prop = wallLightPropInfo.ShallowClone(),
m_probability = 100,
m_repeatDistance = 20,
m_segmentOffset = 0,
m_angle = 270,
m_position = new Vector3(xPos, 1.5f, 0)
};
props.Add(wallLightProp);
}

public static void AddRightWallLights(this ICollection<NetLaneProps.Prop> props, int xPos = 0)
{
var wallLightPropInfo = Prefabs.Find<PropInfo>("Wall Light Orange");
var wallLightProp = new NetLaneProps.Prop();
wallLightProp.m_prop = wallLightPropInfo.ShallowClone();
wallLightProp.m_probability = 100;
wallLightProp.m_repeatDistance = 20;
wallLightProp.m_segmentOffset = 0;
wallLightProp.m_angle = 90;
wallLightProp.m_position = new Vector3(xPos, 1.5f, 0);
var wallLightProp = new NetLaneProps.Prop
{
m_prop = wallLightPropInfo.ShallowClone(),
m_probability = 100,
m_repeatDistance = 20,
m_segmentOffset = 0,
m_angle = 90,
m_position = new Vector3(xPos, 1.5f, 0)
};
props.Add(wallLightProp);
}

Expand All @@ -367,12 +382,14 @@ public static void SetHighwaySignsSlope(this ICollection<NetLaneProps.Prop> prop
}
}

public static void TrimNonHighwayProps(this NetInfo info, bool removeRightStreetLights = false, bool removeLeftStreetLights = true)
public static void TrimNonHighwayProps(this NetInfo info, bool removeRightStreetLights = false, bool removeLeftStreetLights = true, bool removeMotorwaySigns = false)
{
var randomProp = Prefabs.Find<PropInfo>("Random Street Prop", false);
var streetLight = Prefabs.Find<PropInfo>("New Street Light", false);
var streetLightHw = Prefabs.Find<PropInfo>("New Street Light Highway", false);
var manhole = Prefabs.Find<PropInfo>("Manhole", false);
var motorwaySign = Prefabs.Find<PropInfo>("Motorway Sign", false);
var motorwayOverroadSigns = Prefabs.Find<PropInfo>("Motorway Overroad Signs", false);

foreach (var laneProps in info.m_lanes.Select(l => l.m_laneProps).Where(lpi => lpi != null))
{
Expand Down Expand Up @@ -425,6 +442,14 @@ public static void TrimNonHighwayProps(this NetInfo info, bool removeRightStreet
}
}

if (removeMotorwaySigns)
{
if (prop.m_prop == motorwaySign || prop.m_prop == motorwayOverroadSigns)
{
continue;
}
}

remainingProp.Add(prop);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public partial class Highway2L2WBuilder : Activable, INetInfoBuilderPart

public string BasedPrefabName { get { return NetInfos.Vanilla.HIGHWAY_3L; } }
public string Name { get { return "Highway2L2W"; } }
public string DisplayName { get { return "Four-Lane National Highway"; } }
public string Description { get { return "A four-lane national highway accommodating medium traffic. Highway does not allow zoning next to it!"; } }
public string DisplayName { get { return "2+2 Lane Highway"; } }
public string Description { get { return "A two way two lane highway suitable for medium traffic."; } }
public string ShortDescription { get { return "No parking, not zoneable, medium traffic"; } }
public string UICategory { get { return "RoadsHighway"; } }

Expand All @@ -42,6 +42,7 @@ public void BuildUp(NetInfo info, NetInfoVersion version)
///////////////////////////
info.Setup24mMesh(version);


///////////////////////////
// Texturing //
///////////////////////////
Expand All @@ -61,50 +62,60 @@ public void BuildUp(NetInfo info, NetInfoVersion version)
info.m_hasPedestrianLanes = false;
info.m_UnlockMilestone = highwayInfo.m_UnlockMilestone;
info.m_halfWidth = (version == NetInfoVersion.Bridge || version == NetInfoVersion.Elevated) ? 11 : 12;
info.m_pavementWidth = 2f;
info.m_pavementWidth = 2;
info.m_maxBuildAngle = 90;
info.m_maxBuildAngleCos = 0;
if (version == NetInfoVersion.Tunnel)
{
info.m_setVehicleFlags = Vehicle.Flags.Transition | Vehicle.Flags.Underground;
info.m_class = highwayTunnelInfo.m_class.Clone(info.name + version.ToString() + "Class");
info.m_class = highwayTunnelInfo.m_class.Clone(NetInfoClasses.NEXT_HIGHWAY2L2W_TUNNEL);
}
else
{
info.m_class = highwayInfo.m_class.Clone(info.name + version.ToString() + "Class");
info.m_class = highwayInfo.m_class.Clone(NetInfoClasses.NEXT_HIGHWAY2L2W);
}


///////////////////////////
// Set up lanes //
///////////////////////////
info.SetRoadLanes(version, new LanesConfiguration
info.SetupHighwayLanes();
var leftHwLane = info.SetHighwayLeftShoulder(highwayInfo, version);
var rightHwLane = info.SetHighwayRightShoulder(highwayInfo, version);
var vehicleLanes = info.SetHighwayVehicleLanes(1, true);
foreach (var lane in vehicleLanes)
{
LanePositionOffst = (version == NetInfoVersion.Bridge || version == NetInfoVersion.Elevated) ? -1 : -2,
IsTwoWay = true,
LaneWidth = 4,
LanesToAdd = 1,
SpeedLimit = 1.8f
});
lane.m_speedLimit = 1.8f;
}


///////////////////////////
// Set up props //
///////////////////////////
var leftPedLane = info.GetLeftRoadShoulder();
var rightPedLane = info.GetRightRoadShoulder();
var leftHwLaneProps = leftHwLane.m_laneProps.m_props.ToList();
var rightHwLaneProps = rightHwLane.m_laneProps.m_props.ToList();

var leftRoadProps = leftPedLane?.m_laneProps.m_props.ToList();
var rightRoadProps = rightPedLane?.m_laneProps.m_props.ToList();
if (version == NetInfoVersion.Slope)
{
leftHwLaneProps.SetHighwaySignsSlope();
rightHwLaneProps.SetHighwaySignsSlope();
}

// Lightning
rightHwLaneProps.SetHighwayRightLights(version);
if (version == NetInfoVersion.Slope)
{
leftRoadProps?.AddLeftWallLights(info.m_pavementWidth);
rightRoadProps?.AddRightWallLights(info.m_pavementWidth);
leftHwLaneProps.AddLeftWallLights(1);
rightHwLaneProps.AddRightWallLights(-1);
}
if (leftPedLane != null && leftPedLane.m_laneProps != null)
leftPedLane.m_laneProps.m_props = leftRoadProps.ToArray();
if (rightPedLane != null && rightPedLane.m_laneProps != null)
rightPedLane.m_laneProps.m_props = rightRoadProps.ToArray();
info.TrimNonHighwayProps(version == NetInfoVersion.Ground);

leftHwLaneProps.RemoveProps("100 Speed Limit"); // Since we dont have the 90km/h limit prop
rightHwLaneProps.RemoveProps("100 Speed Limit"); // Since we dont have the 90km/h limit prop

leftHwLane.m_laneProps.m_props = leftHwLaneProps.ToArray();
rightHwLane.m_laneProps.m_props = rightHwLaneProps.ToArray();

info.TrimNonHighwayProps(false, false, true);

///////////////////////////
// AI //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public partial class HighwayL1R2Builder : Activable, INetInfoBuilderPart

public string BasedPrefabName { get { return NetInfos.Vanilla.HIGHWAY_3L; } }
public string Name { get { return "AsymHighwayL1R2"; } }
public string DisplayName { get { return "3 Lane Asymmetrical Highway: (1+2)"; } }
public string DisplayName { get { return "1+2 Lane Asymmetrical Highway"; } }
public string Description { get { return "An asymmetrical highway with one left lane and two right lanes. Note, dragging this highway backwards reverses its orientation."; } }
public string ShortDescription { get { return "No parking, not zoneable, medium to high traffic"; } }
public string UICategory { get { return "RoadsHighway"; } }
Expand All @@ -41,7 +41,7 @@ public void BuildUp(NetInfo info, NetInfoVersion version)
///////////////////////////
// 3DModeling //
///////////////////////////
info.Setup22mMesh(version, LanesLayoutStyle.AsymL1R2);
info.Setup22mMesh(version);


///////////////////////////
Expand All @@ -63,56 +63,60 @@ public void BuildUp(NetInfo info, NetInfoVersion version)
info.m_hasPedestrianLanes = false;
info.m_UnlockMilestone = highwayInfo.m_UnlockMilestone;
info.m_halfWidth = 11;
info.m_pavementWidth = 2f;
info.m_pavementWidth = 2;
info.m_maxBuildAngle = 90;
info.m_maxBuildAngleCos = 0;
if (version == NetInfoVersion.Tunnel)
{
info.m_setVehicleFlags = Vehicle.Flags.Transition | Vehicle.Flags.Underground;
info.m_class = highwayTunnelInfo.m_class.Clone(info.name + version.ToString() + "Class");
info.m_class = highwayTunnelInfo.m_class.Clone(NetInfoClasses.NEXT_HIGHWAYL1R2_TUNNEL);
}
else
{
info.m_class = highwayInfo.m_class.Clone(info.name + version.ToString() + "Class");
info.m_class = highwayInfo.m_class.Clone(NetInfoClasses.NEXT_HIGHWAYL1R2);
}
info.SetRoadLanes(version, new LanesConfiguration
{
LanePositionOffst = -3,
IsTwoWay = true,
LaneWidth = 4,
SpeedLimit = 1.8f
});


///////////////////////////
// Set up lanes //
///////////////////////////
// Setting up lanes
var vehicleLanes = info.m_lanes.Where(l => l.m_laneType == NetInfo.LaneType.Vehicle).ToList();
var leftLane = vehicleLanes.FirstOrDefault(l => l.m_position == vehicleLanes.Min(n => n.m_position));
leftLane.m_direction = NetInfo.Direction.Backward;
leftLane.m_finalDirection = NetInfo.Direction.Backward;
info.SetupHighwayLanes();
var leftHwLane = info.SetHighwayLeftShoulder(highwayInfo, version);
var rightHwLane = info.SetHighwayRightShoulder(highwayInfo, version);
var vehicleLanes = info.SetHighwayVehicleLanes(0, true);
foreach (var lane in vehicleLanes)
{
lane.m_speedLimit = 1.8f;
}



///////////////////////////
// Set up props //
///////////////////////////
var leftPedLane = info.GetLeftRoadShoulder();
var rightPedLane = info.GetRightRoadShoulder();
var leftHwLaneProps = leftHwLane.m_laneProps.m_props.ToList();
var rightHwLaneProps = rightHwLane.m_laneProps.m_props.ToList();

var leftRoadProps = leftPedLane?.m_laneProps.m_props.ToList();
var rightRoadProps = rightPedLane?.m_laneProps.m_props.ToList();
if (version == NetInfoVersion.Slope)
{
leftHwLaneProps.SetHighwaySignsSlope();
rightHwLaneProps.SetHighwaySignsSlope();
}

// Lightning
rightHwLaneProps.SetHighwayRightLights(version);
if (version == NetInfoVersion.Slope)
{
leftRoadProps?.AddLeftWallLights(info.m_pavementWidth);
rightRoadProps?.AddRightWallLights(info.m_pavementWidth);
leftHwLaneProps.AddLeftWallLights(1);
rightHwLaneProps.AddRightWallLights(-1);
}

if (leftPedLane != null && leftPedLane.m_laneProps != null)
leftPedLane.m_laneProps.m_props = leftRoadProps.ToArray();
if (rightPedLane != null && rightPedLane.m_laneProps != null)
rightPedLane.m_laneProps.m_props = rightRoadProps.ToArray();
leftHwLaneProps.RemoveProps("100 Speed Limit"); // Since we dont have the 90km/h limit prop
rightHwLaneProps.RemoveProps("100 Speed Limit"); // Since we dont have the 90km/h limit prop

leftHwLane.m_laneProps.m_props = leftHwLaneProps.ToArray();
rightHwLane.m_laneProps.m_props = rightHwLaneProps.ToArray();

info.TrimNonHighwayProps(version == NetInfoVersion.Ground);
info.TrimNonHighwayProps(false, false, true);

///////////////////////////
// AI //
Expand Down
4 changes: 4 additions & 0 deletions Transit.Framework/Network/NetInfoClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public static class NetInfoClasses
public const string NEXT_HIGHWAY1L_TUNNEL = "NExtHighwayTunnel1LTunnel";
public const string NEXT_HIGHWAY2L = "NExtHighway2L";
public const string NEXT_HIGHWAY2L_TUNNEL = "NExtHighwayTunnel2LTunnel";
public const string NEXT_HIGHWAY2L2W = "NExtHighway2L2W";
public const string NEXT_HIGHWAY2L2W_TUNNEL = "NExtHighwayTunnel2L2W";
public const string NEXT_HIGHWAYL1R2 = "NExtHighwayL1R2";
public const string NEXT_HIGHWAYL1R2_TUNNEL = "NExtHighwayTunnelL1R2";
public const string NEXT_HIGHWAY4L = "NExtHighway4L";
public const string NEXT_HIGHWAY4L_TUNNEL = "NExtHighwayTunnel4LTunnel";
public const string NEXT_HIGHWAY5L = "NExtHighway5L";
Expand Down