From 7f55cb51808d3140006a434eb49850e040a9b616 Mon Sep 17 00:00:00 2001 From: andreharv Date: Sun, 12 Apr 2020 09:06:51 -0400 Subject: [PATCH 1/4] Trim unneeded code/detours --- AssetsUpdater.cs | 74 +++++++-------- Detours/DepotAIDetour.cs | 109 ---------------------- Detours/MetroTrainAIDetour.cs | 78 ++++++++-------- Detours/PassengerTrainAIDetour.cs | 38 +------- InitializationSteps/CustomizationSteps.cs | 54 +---------- LoadingExtension.cs | 5 - MetroOverhaulMod.csproj | 1 - Options.cs | 4 - 8 files changed, 79 insertions(+), 284 deletions(-) diff --git a/AssetsUpdater.cs b/AssetsUpdater.cs index de681d5..2d819e5 100644 --- a/AssetsUpdater.cs +++ b/AssetsUpdater.cs @@ -688,43 +688,43 @@ private static void UpdateNoColPillars() } private static void UpdateMetroTrainEffects() { - var vanillaMetro = PrefabCollection.FindLoaded("Metro"); - var arriveEffect = ((MetroTrainAI)vanillaMetro.m_vehicleAI).m_arriveEffect; - for (uint i = 0; i < PrefabCollection.LoadedCount(); i++) - { - try - { - var info = PrefabCollection.GetLoaded(i); - var metroTrainAI = info?.m_vehicleAI as MetroTrainAI; - if (metroTrainAI == null) - { - continue; - } - if (info.m_effects == null || info.m_effects.Length == 0) - { - info.m_effects = vanillaMetro.m_effects; - } - else - { - for (var j = 0; j < info.m_effects.Length; j++) - { - if (info.m_effects[j].m_effect?.name == "Train Movement") - { - info.m_effects[j] = vanillaMetro.m_effects[0]; - } - } - } - var arriveEffectName = metroTrainAI.m_arriveEffect?.name; - if (arriveEffectName == null || arriveEffectName == "Transport Arrive") - { - metroTrainAI.m_arriveEffect = arriveEffect; - } - } - catch - { - //swallow - } - } + //var vanillaMetro = PrefabCollection.FindLoaded("Metro"); + //var arriveEffect = ((MetroTrainAI)vanillaMetro.m_vehicleAI).m_arriveEffect; + //for (uint i = 0; i < PrefabCollection.LoadedCount(); i++) + //{ + // try + // { + // var info = PrefabCollection.GetLoaded(i); + // var metroTrainAI = info?.m_vehicleAI as MetroTrainAI; + // if (metroTrainAI == null) + // { + // continue; + // } + // if (info.m_effects == null || info.m_effects.Length == 0) + // { + // info.m_effects = vanillaMetro.m_effects; + // } + // else + // { + // for (var j = 0; j < info.m_effects.Length; j++) + // { + // if (info.m_effects[j].m_effect?.name == "Train Movement") + // { + // info.m_effects[j] = vanillaMetro.m_effects[0]; + // } + // } + // } + // var arriveEffectName = metroTrainAI.m_arriveEffect?.name; + // if (arriveEffectName == null || arriveEffectName == "Transport Arrive") + // { + // metroTrainAI.m_arriveEffect = arriveEffect; + // } + // } + // catch + // { + // //swallow + // } + //} } } } \ No newline at end of file diff --git a/Detours/DepotAIDetour.cs b/Detours/DepotAIDetour.cs index 1cb2d4e..528ae44 100644 --- a/Detours/DepotAIDetour.cs +++ b/Detours/DepotAIDetour.cs @@ -65,114 +65,5 @@ public class DepotAIDetour : DepotAI } } } - [RedirectMethod] - public override string GetLocalizedStats(ushort buildingID, ref Building data) - { - string text = string.Empty; - if ((UnityEngine.Object)this.m_transportInfo != (UnityEngine.Object)null && this.m_maxVehicleCount != 0) - { - switch (this.m_transportInfo.m_transportType) - { - case TransportInfo.TransportType.Bus: - case TransportInfo.TransportType.TouristBus: - { - int vehicleCount = this.GetVehicleCount(buildingID, ref data); - int budget = Singleton.instance.GetBudget(this.m_info.m_class); - int productionRate = PlayerBuildingAI.GetProductionRate(100, budget); - int num = (productionRate * this.m_maxVehicleCount + 99) / 100; - text += LocaleFormatter.FormatGeneric("AIINFO_BUSDEPOT_BUSCOUNT", new object[] - { - vehicleCount, - num - }); - break; - } - case TransportInfo.TransportType.Ship: - if (this.m_transportInfo.m_vehicleType == VehicleInfo.VehicleType.Ferry) - { - int vehicleCount2 = this.GetVehicleCount(buildingID, ref data); - int budget2 = Singleton.instance.GetBudget(this.m_info.m_class); - int productionRate2 = PlayerBuildingAI.GetProductionRate(100, budget2); - int num2 = (productionRate2 * this.m_maxVehicleCount + 99) / 100; - text += LocaleFormatter.FormatGeneric("AIINFO_FERRYDEPOT_FERRYCOUNT", new object[] - { - vehicleCount2, - num2 - }); - } - break; - case TransportInfo.TransportType.Airplane: - if (this.m_transportInfo.m_vehicleType == VehicleInfo.VehicleType.Blimp) - { - int vehicleCount3 = this.GetVehicleCount(buildingID, ref data); - int budget3 = Singleton.instance.GetBudget(this.m_info.m_class); - int productionRate3 = PlayerBuildingAI.GetProductionRate(100, budget3); - int num3 = (productionRate3 * this.m_maxVehicleCount + 99) / 100; - text += LocaleFormatter.FormatGeneric("AIINFO_BLIMPDEPOT_BLIMPCOUNT", new object[] - { - vehicleCount3, - num3 - }); - } - break; - case TransportInfo.TransportType.Taxi: - { - int vehicleCount4 = this.GetVehicleCount(buildingID, ref data); - int budget4 = Singleton.instance.GetBudget(this.m_info.m_class); - int productionRate4 = PlayerBuildingAI.GetProductionRate(100, budget4); - int num4 = (productionRate4 * this.m_maxVehicleCount + 99) / 100; - text += LocaleFormatter.FormatGeneric("AIINFO_TAXIDEPOT_VEHICLES", new object[] - { - vehicleCount4, - num4 - }); - break; - } - case TransportInfo.TransportType.Tram: - { - int vehicleCount5 = this.GetVehicleCount(buildingID, ref data); - int budget5 = Singleton.instance.GetBudget(this.m_info.m_class); - int productionRate5 = PlayerBuildingAI.GetProductionRate(100, budget5); - int num5 = (productionRate5 * this.m_maxVehicleCount + 99) / 100; - text += LocaleFormatter.FormatGeneric("AIINFO_TRAMDEPOT_TRAMCOUNT", new object[] - { - vehicleCount5, - num5 - }); - break; - } - //begin mod - case TransportInfo.TransportType.Metro: - { - int vehicleCount6 = this.GetVehicleCount(buildingID, ref data); - int budget6 = Singleton.instance.GetBudget(this.m_info.m_class); - int productionRate6 = PlayerBuildingAI.GetProductionRate(100, budget6); - int num6 = (productionRate6 * this.m_maxVehicleCount + 99) / 100; - text += LocaleFormatter.FormatGeneric("AIINFO_TRAMDEPOT_TRAMCOUNT", new object[] - { - vehicleCount6, - num6 - }).Replace("Tram", "Metro"); - break; - } - - case TransportInfo.TransportType.Train: - { - int vehicleCount7 = this.GetVehicleCount(buildingID, ref data); - int budget7 = Singleton.instance.GetBudget(this.m_info.m_class); - int productionRate7 = PlayerBuildingAI.GetProductionRate(100, budget7); - int num7 = (productionRate7 * this.m_maxVehicleCount + 99) / 100; - text += LocaleFormatter.FormatGeneric("AIINFO_TRAMDEPOT_TRAMCOUNT", new object[] - { - vehicleCount7, - num7 - }).Replace("Tram", "Train"); - break; - //end mod - } - } - } - return text; - } } } \ No newline at end of file diff --git a/Detours/MetroTrainAIDetour.cs b/Detours/MetroTrainAIDetour.cs index 35ddbbe..44fa48e 100644 --- a/Detours/MetroTrainAIDetour.cs +++ b/Detours/MetroTrainAIDetour.cs @@ -22,45 +22,45 @@ public static void ChangeDeployState(bool state) } } - [RedirectMethod] - public override void CreateVehicle(ushort vehicleID, ref Vehicle data) - { - base.CreateVehicle(vehicleID, ref data); - //begin mod - if (vehicleID > 0) - { - var position = VehicleManager.instance.m_vehicles.m_buffer[vehicleID].m_frame0.m_position; - if (position.y < TerrainManager.instance.SampleDetailHeightSmooth(position.x, position.z)) - //how about sunken stations? - { - data.m_flags |= Vehicle.Flags.Underground; - } - else - { - data.m_flags &= ~Vehicle.Flags.Underground; - } - } - //end mod - } + //[RedirectMethod] + //public override void CreateVehicle(ushort vehicleID, ref Vehicle data) + //{ + // base.CreateVehicle(vehicleID, ref data); + // //begin mod + // if (vehicleID > 0) + // { + // var position = VehicleManager.instance.m_vehicles.m_buffer[vehicleID].m_frame0.m_position; + // if (position.y < TerrainManager.instance.SampleDetailHeightSmooth(position.x, position.z)) + // //how about sunken stations? + // { + // data.m_flags |= Vehicle.Flags.Underground; + // } + // else + // { + // data.m_flags &= ~Vehicle.Flags.Underground; + // } + // } + // //end mod + //} - [RedirectMethod] - public override void LoadVehicle(ushort vehicleID, ref Vehicle data) - { - base.LoadVehicle(vehicleID, ref data); - //begin mod - if (vehicleID > 0) - { - var position = VehicleManager.instance.m_vehicles.m_buffer[vehicleID].m_frame0.m_position; - if (position.y < TerrainManager.instance.SampleDetailHeightSmooth(position.x, position.z)) //how about sunken stations? - { - data.m_flags |= Vehicle.Flags.Underground; - } - else - { - data.m_flags &= ~Vehicle.Flags.Underground; - } - } - //end mod - } + //[RedirectMethod] + //public override void LoadVehicle(ushort vehicleID, ref Vehicle data) + //{ + // base.LoadVehicle(vehicleID, ref data); + // //begin mod + // if (vehicleID > 0) + // { + // var position = VehicleManager.instance.m_vehicles.m_buffer[vehicleID].m_frame0.m_position; + // if (position.y < TerrainManager.instance.SampleDetailHeightSmooth(position.x, position.z)) //how about sunken stations? + // { + // data.m_flags |= Vehicle.Flags.Underground; + // } + // else + // { + // data.m_flags &= ~Vehicle.Flags.Underground; + // } + // } + // //end mod + //} } } \ No newline at end of file diff --git a/Detours/PassengerTrainAIDetour.cs b/Detours/PassengerTrainAIDetour.cs index 44de578..32fd684 100644 --- a/Detours/PassengerTrainAIDetour.cs +++ b/Detours/PassengerTrainAIDetour.cs @@ -37,43 +37,7 @@ public static void ChangeDeployState(bool state) Redirector.Revert(); } } - [RedirectMethod] - protected override void ArrivingToDestination(ushort vehicleID, ref Vehicle vehicleData) - { - base.ArrivingToDestination(vehicleID, ref vehicleData); - if (this.m_arriveEffect == null) - return; - if ((vehicleData.m_flags & Vehicle.Flags.GoingBack) != ~(Vehicle.Flags.Created | Vehicle.Flags.Deleted | Vehicle.Flags.Spawned | Vehicle.Flags.Inverted | Vehicle.Flags.TransferToTarget | Vehicle.Flags.TransferToSource | Vehicle.Flags.Emergency1 | Vehicle.Flags.Emergency2 | Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped | Vehicle.Flags.Leaving | Vehicle.Flags.Arriving | Vehicle.Flags.Reversed | Vehicle.Flags.TakingOff | Vehicle.Flags.Flying | Vehicle.Flags.Landing | Vehicle.Flags.WaitingSpace | Vehicle.Flags.WaitingCargo | Vehicle.Flags.GoingBack | Vehicle.Flags.WaitingTarget | Vehicle.Flags.Importing | Vehicle.Flags.Exporting | Vehicle.Flags.Parking | Vehicle.Flags.CustomName | Vehicle.Flags.OnGravel | Vehicle.Flags.WaitingLoading | Vehicle.Flags.Congestion | Vehicle.Flags.DummyTraffic | Vehicle.Flags.Underground | Vehicle.Flags.Transition | Vehicle.Flags.InsideBuilding | Vehicle.Flags.LeftHandDrive)) - { - if ((int)vehicleData.m_sourceBuilding == 0) - return; - Vector3 position = Singleton.instance.m_buildings.m_buffer[(int)vehicleData.m_sourceBuilding].m_position; - InstanceID instance = new InstanceID(); - instance.Building = vehicleData.m_sourceBuilding; - EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(position, Vector3.up, 0.0f); - Singleton.instance.DispatchEffect(this.m_arriveEffect, instance, spawnArea, Vector3.zero, 0.0f, 1f, Singleton.instance.m_audioGroup); - } - else if ((vehicleData.m_flags & Vehicle.Flags.DummyTraffic) != ~(Vehicle.Flags.Created | Vehicle.Flags.Deleted | Vehicle.Flags.Spawned | Vehicle.Flags.Inverted | Vehicle.Flags.TransferToTarget | Vehicle.Flags.TransferToSource | Vehicle.Flags.Emergency1 | Vehicle.Flags.Emergency2 | Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped | Vehicle.Flags.Leaving | Vehicle.Flags.Arriving | Vehicle.Flags.Reversed | Vehicle.Flags.TakingOff | Vehicle.Flags.Flying | Vehicle.Flags.Landing | Vehicle.Flags.WaitingSpace | Vehicle.Flags.WaitingCargo | Vehicle.Flags.GoingBack | Vehicle.Flags.WaitingTarget | Vehicle.Flags.Importing | Vehicle.Flags.Exporting | Vehicle.Flags.Parking | Vehicle.Flags.CustomName | Vehicle.Flags.OnGravel | Vehicle.Flags.WaitingLoading | Vehicle.Flags.Congestion | Vehicle.Flags.DummyTraffic | Vehicle.Flags.Underground | Vehicle.Flags.Transition | Vehicle.Flags.InsideBuilding | Vehicle.Flags.LeftHandDrive)) - { - if ((int)vehicleData.m_targetBuilding == 0) - return; - Vector3 position = Singleton.instance.m_buildings.m_buffer[(int)vehicleData.m_targetBuilding].m_position; - InstanceID instance = new InstanceID(); - instance.Building = vehicleData.m_targetBuilding; - EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(position, Vector3.up, 0.0f); - Singleton.instance.DispatchEffect(this.m_arriveEffect, instance, spawnArea, Vector3.zero, 0.0f, 1f, Singleton.instance.m_audioGroup); - } - else - { - if ((int)vehicleData.m_targetBuilding == 0) - return; - Vector3 position = Singleton.instance.m_nodes.m_buffer[(int)vehicleData.m_targetBuilding].m_position; - InstanceID instance = new InstanceID(); - instance.NetNode = vehicleData.m_targetBuilding; - EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(position, Vector3.up, 0.0f); - Singleton.instance.DispatchEffect(this.m_arriveEffect, instance, spawnArea, Vector3.zero, 0.0f, 1f, Singleton.instance.m_audioGroup); - } - } + [RedirectMethod] protected override bool StartPathFind(ushort vehicleID, ref Vehicle vehicleData) { diff --git a/InitializationSteps/CustomizationSteps.cs b/InitializationSteps/CustomizationSteps.cs index 1d7d0c1..1d3dc64 100644 --- a/InitializationSteps/CustomizationSteps.cs +++ b/InitializationSteps/CustomizationSteps.cs @@ -187,24 +187,7 @@ public static void CommonSteelCustomization(NetInfo prefab, NetInfoVersion versi public static void CommonCustomization(NetInfo prefab, NetInfoVersion version) { - if (prefab.name.Contains("Station")) - { - prefab.m_connectGroup = NetInfo.ConnectGroup.MetroStation; - //prefab.m_nodeConnectGroups = (NetInfo.ConnectGroup)2048 | NetInfo.ConnectGroup.MonorailStation | NetInfo.ConnectGroup.DoubleMetro; - //if (version != NetInfoVersion.Tunnel) - //{ - // prefab.m_nodes[1].m_connectGroup = (NetInfo.ConnectGroup)2048 | NetInfo.ConnectGroup.MonorailStation; - //} - } - else - { - prefab.m_connectGroup = NetInfo.ConnectGroup.DoubleMetro; - //prefab.m_nodeConnectGroups = NetInfo.ConnectGroup.DoubleMetro; - //if (version != NetInfoVersion.Tunnel) - //{ - // prefab.m_nodes[1].m_connectGroup = NetInfo.ConnectGroup.DoubleMetro; - //} - } + prefab.m_connectGroup = prefab.name.Contains("Station") ? NetInfo.ConnectGroup.MetroStation : NetInfo.ConnectGroup.DoubleMetro; foreach (var lane in prefab.m_lanes) { if (lane.m_laneType == NetInfo.LaneType.Vehicle) @@ -217,12 +200,6 @@ public static void CommonCustomization(NetInfo prefab, NetInfoVersion version) public static void CommonCustomizationTwoLaneOneWay(NetInfo prefab, NetInfoVersion version) { prefab.m_connectGroup = NetInfo.ConnectGroup.MonorailStation; - //prefab.m_nodeConnectGroups = NetInfo.ConnectGroup.MonorailStation | (NetInfo.ConnectGroup)2048 | NetInfo.ConnectGroup.DoubleMetro | NetInfo.ConnectGroup.WideTram; - - //if (version != NetInfoVersion.Tunnel) - //{ - // prefab.m_nodes[1].m_connectGroup = NetInfo.ConnectGroup.MonorailStation; - //} foreach (var lane in prefab.m_lanes) { @@ -240,25 +217,7 @@ public static void CommonCustomizationTwoLaneOneWay(NetInfo prefab, NetInfoVersi public static void CommonCustomizationSmall(NetInfo prefab, NetInfoVersion version) { var isTwoWay = prefab.name.Contains("Two-Way") || prefab.name.Contains("Station"); - if (isTwoWay) - { - prefab.m_connectGroup = NetInfo.ConnectGroup.SingleMonorail; - //prefab.m_nodeConnectGroups = NetInfo.ConnectGroup.SingleMonorail | NetInfo.ConnectGroup.MonorailStation | (NetInfo.ConnectGroup)2048 | NetInfo.ConnectGroup.DoubleMetro | NetInfo.ConnectGroup.WideTram | NetInfo.ConnectGroup.SingleMetro; - //if (version != NetInfoVersion.Tunnel) - //{ - // prefab.m_nodes[1].m_connectGroup = NetInfo.ConnectGroup.SingleMonorail; - //} - } - else - { - prefab.m_connectGroup = NetInfo.ConnectGroup.SingleMetro; - //prefab.m_nodeConnectGroups = NetInfo.ConnectGroup.DoubleMetro | NetInfo.ConnectGroup.SingleMetro | (NetInfo.ConnectGroup)2048 | NetInfo.ConnectGroup.WideTram; - //if (version != NetInfoVersion.Tunnel) - //{ - // prefab.m_nodes[1].m_connectGroup = NetInfo.ConnectGroup.SingleMetro | NetInfo.ConnectGroup.Oneway; - //} - } - + prefab.m_connectGroup = (isTwoWay) ? NetInfo.ConnectGroup.SingleMonorail : NetInfo.ConnectGroup.SingleMetro; prefab.SetRoadLanes(version, new LanesConfiguration() { IsTwoWay = isTwoWay, @@ -330,11 +289,6 @@ public static void CommonCustomizationSmall(NetInfo prefab, NetInfoVersion versi public static void CommonIslandCustomization(NetInfo prefab, NetInfoVersion version) { prefab.m_connectGroup = NetInfo.ConnectGroup.None; - //prefab.m_nodeConnectGroups = NetInfo.ConnectGroup.WideTram | NetInfo.ConnectGroup.DoubleMetro; - //if (version != NetInfoVersion.Tunnel) - //{ - // prefab.m_nodes[1].m_connectGroup = NetInfo.ConnectGroup.DoubleMetro | NetInfo.ConnectGroup.MonorailStation; - //} var theLanes = prefab.m_lanes.ToList(); for (var i = 0; i < theLanes.Count; i++) @@ -377,10 +331,6 @@ public static void CommonCustomizationLarge(NetInfo prefab, NetInfoVersion versi { prefab.m_connectGroup = NetInfo.ConnectGroup.WideTram; prefab.m_nodeConnectGroups = NetInfo.ConnectGroup.WideTram | NetInfo.ConnectGroup.DoubleMetro | NetInfo.ConnectGroup.SingleMonorail; - //if (version != NetInfoVersion.Tunnel) - //{ - // prefab.m_nodes[1].m_connectGroup = NetInfo.ConnectGroup.WideTram; - //} } prefab.SetRoadLanes(version, new LanesConfiguration() diff --git a/LoadingExtension.cs b/LoadingExtension.cs index 531898f..751077e 100644 --- a/LoadingExtension.cs +++ b/LoadingExtension.cs @@ -58,10 +58,6 @@ public override void OnCreated(ILoading loading) if (loading.currentMode == AppMode.Game) { Redirector.Deploy(); - if (OptionsWrapper.Options.improvedMetroTrainAi) - { - Redirector.Deploy(); - } if (OptionsWrapper.Options.improvedPassengerTrainAi) { Redirector.Deploy(); @@ -196,7 +192,6 @@ public override void OnReleased() Container = null; Redirector.Revert(); Redirector.Revert(); - Redirector.Revert(); Redirector.Revert(); } } diff --git a/MetroOverhaulMod.csproj b/MetroOverhaulMod.csproj index 8b25ab2..01b6838 100644 --- a/MetroOverhaulMod.csproj +++ b/MetroOverhaulMod.csproj @@ -44,7 +44,6 @@ - diff --git a/Options.cs b/Options.cs index 53dee31..8a40307 100644 --- a/Options.cs +++ b/Options.cs @@ -16,7 +16,6 @@ public Options() { ingameTrainMetroConverter = true; improvedPassengerTrainAi = true; - improvedMetroTrainAi = true; metroUi = true; ghostMode = false; depotsNotRequiredMode = false; @@ -36,9 +35,6 @@ public Options() [Checkbox("Improved PassengerTrainAI (Allows trains to return to depots)", GENERAL, typeof(PassengerTrainAIDetour), nameof(PassengerTrainAIDetour.ChangeDeployState))] public bool improvedPassengerTrainAi { set; get; } - [Checkbox("Improved MetroTrainAI (Allows trains to properly spawn at surface)", GENERAL, typeof(MetroTrainAIDetour), nameof(MetroTrainAIDetour.ChangeDeployState))] - public bool improvedMetroTrainAi { set; get; } - [Checkbox("GHOST MODE (Load your MOM city with this ON and save before unsubscribing)", UNSUBPREP)] public bool ghostMode { set; get; } } From f64a4831afdc80d1472274e8f0cf51a76a325348 Mon Sep 17 00:00:00 2001 From: andreharv Date: Mon, 11 May 2020 02:09:51 -0400 Subject: [PATCH 2/4] Cleanup --- InitializationSteps/CustomizationSteps.cs | 6 +++++- NEXT/Extensions/PrefabInfoExtensions.cs | 24 ++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/InitializationSteps/CustomizationSteps.cs b/InitializationSteps/CustomizationSteps.cs index 1d3dc64..d1e4204 100644 --- a/InitializationSteps/CustomizationSteps.cs +++ b/InitializationSteps/CustomizationSteps.cs @@ -88,8 +88,8 @@ private static void AddBasicProp(this List propList, PropInfo theProp.m_prop = thePropInfo; theProp.m_finalProp = thePropInfo; theProp.m_position = position; - theProp.m_repeatDistance = repeatDistance; theProp.m_angle = angle; + theProp.m_repeatDistance = repeatDistance; propList.Add(theProp); } public static void CommonVanillaCustomization(NetInfo prefab, NetInfoVersion version) @@ -194,6 +194,10 @@ public static void CommonCustomization(NetInfo prefab, NetInfoVersion version) { lane.m_verticalOffset = 0.35f; } + else if(lane.m_laneType == NetInfo.LaneType.Pedestrian) + { + lane.m_verticalOffset = 1; + } } } diff --git a/NEXT/Extensions/PrefabInfoExtensions.cs b/NEXT/Extensions/PrefabInfoExtensions.cs index 27f54ad..ee7b521 100644 --- a/NEXT/Extensions/PrefabInfoExtensions.cs +++ b/NEXT/Extensions/PrefabInfoExtensions.cs @@ -1,4 +1,8 @@ -using System.Reflection; +using ColossalFramework; +using ColossalFramework.Globalization; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; using UnityEngine; namespace MetroOverhaul.NEXT.Extensions @@ -22,5 +26,23 @@ public static void SetUICategory(this PrefabInfo info, string category) { typeof(PrefabInfo).GetField("m_UICategory", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(info, category); } + + public static void ModifyTitle(this PrefabInfo info, string newTitle) + { + var localizedStringsField = typeof(Locale).GetFieldByName("m_LocalizedStrings"); + var locale = SingletonLite.instance.GetLocale(); + var localizedStrings = (Dictionary)localizedStringsField.GetValue(locale); + + var kvp = + localizedStrings + .FirstOrDefault(kvpInternal => + kvpInternal.Key.m_Identifier == "NET_TITLE" && + kvpInternal.Key.m_Key == info.name); + + if (!Equals(kvp, default(KeyValuePair))) + { + localizedStrings[kvp.Key] = newTitle; + } + } } } From a052c99f3e71f4efa193842918305fc5fd7fd9a2 Mon Sep 17 00:00:00 2001 From: andreharv Date: Sat, 23 May 2020 10:26:50 -0400 Subject: [PATCH 3/4] Fixed major errors with bending tracks and modifying hub station layouts --- Extensions/BuildingInfoExtensions.cs | 16 +- Extensions/NetInfoExtensions.cs | 2 +- ParentStationMetaData.cs | 2 +- SetStationCustomizations.cs | 730 +++++++++++---------------- 4 files changed, 302 insertions(+), 448 deletions(-) diff --git a/Extensions/BuildingInfoExtensions.cs b/Extensions/BuildingInfoExtensions.cs index 943cb5e..b0648e2 100644 --- a/Extensions/BuildingInfoExtensions.cs +++ b/Extensions/BuildingInfoExtensions.cs @@ -630,19 +630,6 @@ public static List LinkedPaths(this BuildingInfo info, int inx, List i return retval; } - public static List LowestHighPaths(this BuildingInfo info) - { - var retval = new List(); - retval = info.m_paths.Where(p => p.IsPedestrianPath() && p.m_nodes.Any(n => n.y > -4) && p.m_nodes.Any(nd => nd.y <= -4)).ToList(); - if (retval.Count == 0) - { - retval.Add(info.m_paths.Where(p => IsPedestrianPath(p)) - .OrderByDescending(p => p.m_nodes[0].y) - .FirstOrDefault()); - } - return retval; - } - public static Vector3 FindAverageNode(this BuildingInfo info, bool isDeep) { var center = Vector3.zero; @@ -667,7 +654,7 @@ public static Vector3 FindAverageNode(this BuildingInfo info, bool isDeep) { for (int k = 0; k < path.m_nodes.Length; k++) { - nodeList.Add(SetStationCustomizations.AdjustNodeForParent(path.m_nodes[k], parentMetaData)); + nodeList.Add(SetStationCustomizations.AdjustNodeFromParentToChild(path.m_nodes[k], parentMetaData)); } } } @@ -683,6 +670,7 @@ public static Vector3 FindAverageNode(this BuildingInfo info, bool isDeep) center /= nodeList.Count(); return center; } + public static void StoreBuildingDefault(this BuildingInfo info) { if (StationBuildingCustomization.StoredStationPaths == null) diff --git a/Extensions/NetInfoExtensions.cs b/Extensions/NetInfoExtensions.cs index 6d735f8..9d11495 100644 --- a/Extensions/NetInfoExtensions.cs +++ b/Extensions/NetInfoExtensions.cs @@ -369,7 +369,7 @@ public static bool IsTrainSingleTrack(this NetInfo netInfo) } public static bool IsPedestrianNetwork(this NetInfo info) { - return info != null && (info.name == "Pedestrian Connection Surface" || info.name == "Pedestrian Connection Inside" || info.name == "Pedestrian Connection Underground"); + return info != null && info.name.StartsWith("Pedestrian Connection"); } public static bool IsTrainTrackAI(this NetInfo info) { diff --git a/ParentStationMetaData.cs b/ParentStationMetaData.cs index 27f5404..9622a30 100644 --- a/ParentStationMetaData.cs +++ b/ParentStationMetaData.cs @@ -8,7 +8,7 @@ namespace MetroOverhaul public class ParentStationMetaData { public BuildingInfo Info { get; set; } - public List LowestHighestPaths { get; set; } + public List AnchorPoints { get; set; } public float Angle { get; set; } public UnityEngine.Vector3 Position { get; set; } } diff --git a/SetStationCustomizations.cs b/SetStationCustomizations.cs index dce6969..247462d 100644 --- a/SetStationCustomizations.cs +++ b/SetStationCustomizations.cs @@ -35,10 +35,10 @@ public static class SetStationCustomizations public static Dictionary> StationBuildingCustomizations; private static StationTrackCustomizations m_PathCustomization; private static Stack m_BuildingStack = new Stack(); - private static Stack> m_StationPathStack = new Stack>(); - private static BuildingInfo m_Info; private static Stack m_ParentMetaDataStack = new Stack(); + private static BuildingInfo m_Info; private static ParentStationMetaData m_ParentMetaData; + private static bool m_ResetMainRotation = false; private static float StairCoeff { get { return 0.2f; } }// (11f / 64f); } } private static List m_connectorNode = null; @@ -107,44 +107,79 @@ private static void FillInPathCustomizations() PathCustomizationDict.Add(new BuildingInfo.PathInfo(), PathCustomization); } } - public static List m_LowestHighPaths = null; - public static List LowestHighPaths { + public static List m_AnchorPoints = null; + public static List AnchorPoints { get { - if (m_LowestHighPaths == null) - m_LowestHighPaths = m_Info.LowestHighPaths(); - return m_LowestHighPaths; + if (m_AnchorPoints == null) + { + m_AnchorPoints = new List(); + Debug.Log("Setting up AnchorPoints for " + m_Info); + if (m_ParentMetaData != null) + { + Debug.Log("SubBuilding " + m_Info.name + " is being checked for AnchorPoints"); + var anchorPoints = m_Info.m_paths.Where(p => p.IsPedestrianPath() && p.m_nodes.Any(n => n.y < 0) && p.m_nodes.Any(n => n.y >= 0)).SelectMany(p => p.m_nodes).Where(n => n.y < 0); + if (anchorPoints != null && anchorPoints.Count() > 0) + { + m_AnchorPoints.AddRange(anchorPoints); + } + else + { + anchorPoints = m_ParentMetaData.Info.m_paths.Where(p => p.IsPedestrianPath() && p.m_nodes.Any(n => n.y == 0)).SelectMany(p => p.m_nodes).Where(n => n.y == 0).ToList(); + m_AnchorPoints.AddRange(anchorPoints.Select(n => AdjustNodeFromParentToChild(n))); + } + } + else + { + Debug.Log("Building " + m_Info.name + " is being checked for AnchorPoints"); + var anchorPaths = m_Info.m_paths.Where(p => p.IsPedestrianPath() && p.m_nodes.Any(n => n.y == 0)).ToList(); + if (anchorPaths != null) + { + for (int i = 0; i < anchorPaths.Count(); i++) + { + var anchorNode = anchorPaths[i].m_nodes.OrderBy(p => p.y).FirstOrDefault(); + m_AnchorPoints.Add(anchorNode); + if (anchorNode == default) + { + Debug.Log("No suitable anchorNodes found on building."); + foreach (var node in anchorPaths[i].m_nodes) + { + Debug.Log(node.ToString() + ", parent: " + AdjustNodeFromChildToParent(node).ToString()); + } + } + Debug.Log("Anchorpoint " + anchorNode.ToString() + " found on building" + m_Info.name); + } + } + else + { + Debug.Log("No nodes in Building " + m_Info.name + " that satisfies the outline criteria."); + } + } + } + return m_AnchorPoints; } } + private static double m_AngleDelta = 0; public static void ModifyStation(BuildingInfo info, StationTrackCustomizations pathCustomization, ParentStationMetaData parentMetaData = null) { - Debug.Log("XXXXX STARTING " + info.name + " XXXXXXX"); m_BuildingStack.Push(info); m_Info = info; m_ParentMetaDataStack.Push(parentMetaData); m_ParentMetaData = parentMetaData; m_StationPaths = info.UndergroundStationPaths(false); + if (pathCustomization.Path.m_nodes == null && m_ResetMainRotation) + { + m_ResetMainRotation = false; + m_PrevAngle = 0; + } var hasPaths = m_StationPaths.Count() > 0; PathCustomization = pathCustomization; - + ClearAnchorPoints(); if (PathCustomization.AlterType == MetroStationTrackAlterType.None) PathCustomization.AlterType = MetroStationTrackAlterType.All; - //if (PathCustomization.Path?.m_nodes == null) - //{ - // FillInPathCustomizations(); - //} - //else if (PathCustomizationDict.ContainsKey(PathCustomization.Path)) - //{ - // PathCustomizationDict[PathCustomization.Path] = PathCustomization; - //} - //else - //{ - // PathCustomizationDict.Add(PathCustomization.Path, PathCustomization); - //} - m_ParentMetaData = parentMetaData; if (PathCustomization.Depth <= 0 || PathCustomization.Length <= 0 || (!info.HasUndergroundMetroStationTracks() && (info?.m_subBuildings == null || info?.m_subBuildings.Count() == 0))) { @@ -170,11 +205,12 @@ public static void ModifyStation(BuildingInfo info, StationTrackCustomizations p HandleSubBuildings(); if (hasPaths) { + ClearAnchorPoints(); Debug.Log("info " + m_Info.name + " has " + m_StationPaths.Count() + " station paths"); if (m_Info.HasUndergroundMetroStationTracks(false)) - RemovePedPaths(); - if (IsAlterOfType(MetroStationTrackAlterType.Length)) - ResizeUndergroundStationTracks(); + //RemovePedPaths(); + if (IsAlterOfType(MetroStationTrackAlterType.Length)) + ResizeUndergroundStationTracks(); ChangeStationDepthAndRotation(); if (IsAlterOfType(MetroStationTrackAlterType.Vertical | MetroStationTrackAlterType.Horizontal) && !IsAlterOfType(MetroStationTrackAlterType.Rotation)) ChangeStationPlanarPosition(); @@ -192,9 +228,17 @@ public static void ModifyStation(BuildingInfo info, StationTrackCustomizations p m_StationPaths = originalInfo.UndergroundStationPaths(false); } m_ParentMetaData = m_ParentMetaDataStack.Pop(); - m_LowestHighPaths = null; + } + private static void ClearAnchorPoints() + { + if (m_AnchorPoints != null) + { + m_AnchorPoints.Clear(); + m_AnchorPoints = null; + } + } private static NetInfo m_SpecialNetInfo = null; private static NetInfo SpecialNetInfo { get @@ -220,6 +264,25 @@ private static NetInfo SpecialNetInfo { private static float zCoeff { get; set; } private static float StairsLengthX { get; set; } private static float StairsLengthZ { get; set; } + private static List m_NodeList = new List(); + private static List NodeList { + get + { + if (m_NodeList == null) + { + m_NodeList = new List(); + } + return m_NodeList; + } + } + private static void ClearNodeList() + { + if (m_NodeList != null) + { + m_NodeList.Clear(); + m_NodeList = null; + } + } private static List SetStationPaths(params float[] connectorHalfWidths) { var retval = new List(); @@ -231,7 +294,7 @@ private static NetInfo SpecialNetInfo { connectorHalfWidthList.Sort(); var offset = connectorHalfWidthList[0]; var forbiddenList = new List(); - + var midPoint = Vector3.zero; for (int i = 0; i < connectorHalfWidthList.Count(); i++) { if (i == 0) @@ -255,16 +318,6 @@ private static NetInfo SpecialNetInfo { }); offset = connectorHalfWidthList[i]; } - forbiddenList.Add(true); - - } - - if (!ConnectDict.ContainsKey(TrackPath)) - { - var connectBounds = new Vector3[2]; - connectBounds[0] = newNodes.First(); - connectBounds[1] = newNodes.Last(); - ConnectDict.Add(TrackPath, connectBounds); } var stairNodes = new List(); @@ -279,14 +332,23 @@ private static NetInfo SpecialNetInfo { }); } - NewPath.m_nodes = newNodes.ToArray(); - NewPath.m_forbidLaneConnection = forbiddenList.ToArray(); - - retval.Add(NewPath); - if (!StairDict.ContainsKey(TrackPath)) StairDict.Add(TrackPath, new List()); + if (connectorHalfWidths.Count() > 1) + { + var newNodesCount = newNodes.Count() - 1; + for (int i = 0; i < newNodesCount; i++) + { + if (Vector3.Distance(newNodes[i], newNodes[i + 1]) <= 4) + { + var averageNode = AverageNode(newNodes[i], newNodes[i + 1]); + newNodes[i] = averageNode; + newNodes[i + 1] = averageNode; + } + } + } + for (var i = 0; i < stairNodes.Count(); i++) { var branchPathStair = CreatePath(NewPath, newNodes[i], stairNodes[i]); @@ -295,6 +357,8 @@ private static NetInfo SpecialNetInfo { StairDict[TrackPath].Add(branchPathStair); retval.Add(branchPathStair); } + + NodeList.AddRange(newNodes); } return retval; } @@ -311,19 +375,7 @@ private static NetInfo SpecialNetInfo { m_StairDict = value; } } - private static Dictionary m_ConnectDict = null; - private static Dictionary ConnectDict { - get - { - if (m_ConnectDict == null) - m_ConnectDict = new Dictionary(); - return m_ConnectDict; - } - set - { - m_ConnectDict = value; - } - } + private static bool IsATargetPath(BuildingInfo.PathInfo path) { return (m_PathCustomization.Path?.m_nodes == null || m_PathCustomization.Path == path); @@ -338,17 +390,12 @@ private static void ReconfigureStationAccess() aPath = new BuildingInfo.PathInfo(); } Debug.Log(m_Info.name + " has " + pathList.Count() + " paths with " + pathList.Where(p => p?.m_netInfo != null && p.m_netInfo.IsUndergroundDualIslandPlatformMetroStationTrack())); - if (m_ConnectDict != null) - { - m_ConnectDict.Clear(); - m_ConnectDict = null; - } if (m_StairDict != null) { m_StairDict.Clear(); m_StairDict = null; } - + ClearNodeList(); for (int i = 0; i < pathList.Count; i++) { if (pathList[i]?.m_netInfo != null && pathList[i].m_netInfo.IsUndergroundMetroStationTrack()) @@ -408,310 +455,229 @@ private static void ReconfigureStationAccess() { CheckPedestrianConnections(); } - m_Info.m_paths = CleanPaths(pathList).ToArray(); + m_Info.m_paths = pathList.ToArray(); + CleanPaths(); + + } + private static List m_TrackPool; + private static List TrackPool { + get + { + if (m_TrackPool == null) + { + m_TrackPool = new List(); + m_TrackPool.AddRange(m_StationPaths); + } + return m_TrackPool; + } + } + private static void ClearTrackPool() + { + if (m_TrackPool != null) + { + m_TrackPool.Clear(); + m_TrackPool = null; + } + } + private static Vector2 ConvertToPlanar(Vector3 vector) + { + return new Vector2(vector.x, vector.z); + } + private static float GetPlanarDistance(Vector3 a, Vector3 b) + { + return Vector2.Distance(ConvertToPlanar(a), ConvertToPlanar(b)); } - private static List TrackPool; + private static void ConnectStations() { if (m_StationPaths.Count > 0) { - Debug.Log("info is null for some reason " + (m_Info?.m_paths == null)); - Debug.Log("Connecting up " + m_Info.name); var pathList = m_Info.m_paths.ToList(); - var connectPoints = new List(); - //if (m_ParentMetaData?.LowestHighestPaths != null && m_ParentMetaData?.LowestHighestPaths.Count() > 0) - //{ - // Debug.Log("Building " + m_Info.name + " has a parent"); - // Vector3 subVector = Vector3.zero; - // Vector3 parentVector = Vector3.zero; - // float distance = 0; - // for (int i = 0; i < LowestHighPaths.Count(); i++) - // { - // var subLowestHighPath = LowestHighPaths[i]; - // if (subLowestHighPath?.m_nodes != null) - // { - // var subMidpoint = Vector3.Lerp(subLowestHighPath.m_nodes.First(), subLowestHighPath.m_nodes.Last(), 0.5f); - // for (int j = 0; j < m_ParentMetaData.LowestHighestPaths.Count(); j++) - // { - // var subLowestHighestPath = m_ParentMetaData?.LowestHighestPaths[j]; - // if (subLowestHighestPath?.m_nodes != null) - // { - // var adjustedNodeList = new List(); - // foreach (var subNode in subLowestHighestPath.m_nodes) - // { - // adjustedNodeList.Add(AdjustNodeForParent(subNode)); - // } - // var parentMidpoint = Vector3.Lerp(adjustedNodeList.First(), adjustedNodeList.Last(), 0.5f); - // var newDistance = Vector3.Distance(parentMidpoint, subMidpoint); - // if (distance == 0 || newDistance < distance) - // { - // distance = newDistance; - // subVector = subLowestHighPath.m_nodes.OrderBy(n => Vector3.Distance(n, parentMidpoint)).FirstOrDefault(); - // Debug.Log("subVector is " + subVector.ToString()); - // var planarSubVector = new Vector2(subVector.x, subVector.z); - // parentVector = adjustedNodeList.Where(n => Vector2.Distance(new Vector2(n.x, n.z), planarSubVector) >= 4).OrderBy(n => Vector3.Distance(n, subMidpoint)).FirstOrDefault(); - // Debug.Log("parentVector is " + parentVector.ToString()); - // } - // } - // } - // } - // } - // Debug.Log("final subVector is " + subVector.ToString()); - // Debug.Log("final parentVector is " + parentVector.ToString()); - // if (distance > 0) - // { - // Debug.Log("pathlist has " + pathList.Count()); - // pathList.Add(CreatePath(NewPath, subVector, parentVector)); - // Debug.Log("pathlist has " + pathList.Count()); - // } + var nodePool = new List(); + var pathNodeList = new List(); + var connectorPath = NewPath.ShallowClone(); + var averageAnchorNode = Vector3.zero; + foreach (var node in AnchorPoints) + { + averageAnchorNode += node; + } + averageAnchorNode /= AnchorPoints.Count(); + m_NodeList = m_NodeList.OrderByDescending(n => Vector3.Distance(n, averageAnchorNode)).ToList(); + nodePool.AddRange(m_NodeList); + nodePool.AddRange(AnchorPoints); + for (int i = 0; i < nodePool.Count(); i++) + { + Debug.Log("NodePool contains " + nodePool[i].ToString()); + } - //} - //else - //{ - if (LowestHighPaths != null && LowestHighPaths.Count > 0) + Debug.Log("NodeList count is " + NodeList.Count()); + for (int i = 0; i < NodeList.Count(); i++) { - TrackPool = new List(); - TrackPool.AddRange(m_StationPaths); - var originVectors = new List(); - Vector3 nearestReasonableNode; - if (m_ParentMetaData?.LowestHighestPaths != null) - { - var reasonableNodes = m_ParentMetaData.Info.m_paths.Where(p => p.IsPedestrianPath() && !p.IsPathGenerated()).SelectMany(p => p.m_nodes).Where(n => n.y <= 0).ToList(); - var nearestTrackToCenter = TrackPool.OrderBy(p => Vector3.Magnitude(Vector3.Lerp(AdjustNodeForParent(p.m_nodes.First()), AdjustNodeForParent(p.m_nodes.Last()), 0.5f))).FirstOrDefault(); - var nearestConnectNodes = ConnectDict[nearestTrackToCenter]; - var nearestConnectNodesMidpoint = Vector3.Lerp(nearestConnectNodes.First(), nearestConnectNodes.Last(), 0.5f); - nearestReasonableNode = AdjustNodeForParent(reasonableNodes.Where(n => Vector3.Distance(AdjustNodeForParent(n), nearestConnectNodesMidpoint) >= 4).OrderBy(n => Vector3.Distance(AdjustNodeForParent(n), nearestConnectNodesMidpoint)).FirstOrDefault()); - var nearestConnectNodeOrder = nearestConnectNodes.OrderBy(n => Vector3.Distance(nearestReasonableNode, n)); - pathList.Add(CreatePath(StairDict[nearestTrackToCenter].First(), nearestReasonableNode, nearestConnectNodeOrder.First())); - TrackPool.Remove(nearestTrackToCenter); - nearestReasonableNode = nearestConnectNodeOrder.Last(); - } - else + var node = NodeList[i]; + nodePool.Remove(node); + Debug.Log("Inspecting NodeList[" + i + "] " + node.ToString()); + Debug.Log("NodePool has the following remaining"); + for (int j = 0; j < nodePool.Count(); j++) { - var reasonableNodes = m_Info.m_paths.Where(p => p.IsPedestrianPath() && !p.IsPathGenerated()).SelectMany(p => p.m_nodes).Where(n => n.y <= 0).ToList(); - var nearestTrackToCenter = TrackPool.OrderBy(p => Vector3.Magnitude(Vector3.Lerp(p.m_nodes.First(), p.m_nodes.Last(), 0.5f))).FirstOrDefault(); - var nearestConnectNodes = ConnectDict[nearestTrackToCenter]; - var nearestConnectNodesMidpoint = Vector3.Lerp(nearestConnectNodes.First(), nearestConnectNodes.Last(), 0.5f); - nearestReasonableNode = reasonableNodes.Where(n => Vector3.Distance(n, nearestConnectNodesMidpoint) >= 4).OrderBy(n => Vector3.Distance(n, nearestConnectNodesMidpoint)).FirstOrDefault(); + Debug.Log(nodePool[j].ToString()); } - var trackPathCount = TrackPool.Count(); - if (trackPathCount > 0) + var closestNode = nodePool.Where(n => GetPlanarDistance(n, node) >= 4).OrderBy(n => Vector3.Distance(n, node)).FirstOrDefault(); + Debug.Log("Starting Node " + node.ToString()); + if (!pathNodeList.Contains(node)) + pathNodeList.Add(node); + if (!pathNodeList.Contains(closestNode)) + pathNodeList.Add(closestNode); + Debug.Log("Node " + closestNode.ToString() + " added"); + if (AnchorPoints.Contains(closestNode)) { - for (int i = 0; i < trackPathCount; i++) + Debug.Log("Path done"); + connectorPath.m_nodes = pathNodeList.ToArray(); + var forbidLaneConnectionList = new List(); + for (int j = 0; j < pathNodeList.Count() - 1; j++) { - var closestTrack = TrackPool.OrderBy(p => Vector3.Distance(nearestReasonableNode, Vector3.Lerp(p.m_nodes.First(), p.m_nodes.Last(), 0.5f))).FirstOrDefault(); - if (closestTrack != null && ConnectDict.ContainsKey(closestTrack)) - { - Debug.Log("Closest track exists and connectdict contains closest track"); - var closestConnectVectors = ConnectDict[closestTrack].OrderBy(n => Vector3.Distance(nearestReasonableNode, n)); - if (closestConnectVectors != null) - { - pathList.Add(CreatePath(StairDict[closestTrack].First(), nearestReasonableNode, closestConnectVectors.First())); - nearestReasonableNode = closestConnectVectors.Last(); - } - TrackPool.Remove(closestTrack); - } - else - { - break; - } + + forbidLaneConnectionList.Add(true); } + forbidLaneConnectionList.Add(false); + connectorPath.m_forbidLaneConnection = forbidLaneConnectionList.ToArray(); + connectorPath.MarkPathGenerated(); + //connectorPath.SetCurveTargets(); + pathList.Add(connectorPath); + pathNodeList.Clear(); + connectorPath = connectorPath.ShallowClone(); } - //for(var i = 0; i < TrackPath.cou) - //while (TrackPool.Count > 0) //Do away with this!!!! - //{ - // var newOriginVectors = new List(); - //var aLowNode = originVectors[0]; - // //foreach (var lowNode in originVectors) - // //{ - // Debug.Log("lownode is " + aLowNode.ToString()); - // var closestTrack = TrackPool.OrderBy(p => Vector3.Distance(aLowNode, Vector3.Lerp(p.m_nodes.First(), p.m_nodes.Last(), 0.5f))).FirstOrDefault(); - // if (closestTrack != null && ConnectDict.ContainsKey(closestTrack)) - // { - // Debug.Log("Closest track exists and connectdict contains closest track"); - // var closestConnectVectors = ConnectDict[closestTrack].OrderBy(n => Vector3.Distance(aLowNode, n)); - // if (closestConnectVectors != null) - // { - // Debug.Log("Path created between " + aLowNode.ToString() + " and " + closestConnectVectors.First().ToString()); - // pathList.Add(CreatePath(StairDict[closestTrack].First(), aLowNode, closestConnectVectors.First())); - // TrackPool.Remove(closestTrack); - // newOriginVectors.Add(closestConnectVectors.Last()); - // //if (TrackPool.Count == 0) - // //break; - // } - // } - // else - // { - // if (closestTrack == null) - // { - // Debug.Log("There is no closest track...huh?"); - // } - // else - // { - // Debug.Log("ConnectDict does not contain the specified closest track. There are " + ConnectDict.Count() + " tracks in ConnectDict."); - // } - // } - // //} - // originVectors = newOriginVectors; - //} } - //if (m_ParentMetaData?.LowestHighestPaths != null && m_ParentMetaData?.LowestHighestPaths.Count() > 0) - //{ - // var parentLowestHighNodes = m_ParentMetaData.LowestHighestPaths.SelectMany(p => AdjustNodeForParent(p.m_nodes)); - // var averageNode = Vector3.zero; - // foreach (var node in parentLowestHighNodes) - // { - // averageNode += node; - // } - // averageNode /= parentLowestHighNodes.Count(); - // var closestTrack = ConnectDict.Keys.OrderBy(p => Vector3.Distance(Vector3.Lerp(p.m_nodes.First(), p.m_nodes.Last(), 0.5f), averageNode)).FirstOrDefault(); - // var closestNode = parentLowestHighNodes.OrderBy(n => Vector3.Distance(n, Vector3.Lerp(closestTrack.m_nodes.First(), closestTrack.m_nodes.Last(), 0.5f))).FirstOrDefault(); - // var closestConnectVector = ConnectDict.Values.SelectMany(n => n).OrderBy(n2 => Vector3.Distance(n2, closestNode)).FirstOrDefault(); - // pathList.Add(CreatePath(StairDict[closestTrack].First(), closestNode, closestConnectVector)); - - //} - m_Info.m_paths = CleanPaths(pathList).ToArray(); - //if (LowestHighPaths != null && LowestHighPaths.Count > 0) - //{ - // foreach (BuildingInfo.PathInfo p in LowestHighPaths) - // { - // if (p?.m_nodes != null && p.m_nodes.Count() > 0) - // { - // connectPoints.Add(p.m_nodes.OrderByDescending(n => n.y).ThenBy(n => n.z).LastOrDefault()); - // } - - // } - //} - //var currentVector = connectPoints.FirstOrDefault(); - //var stationPath = m_Info.m_paths.FirstOrDefault(p => p.m_netInfo.IsUndergroundMetroStationTrack()); - //if (m_Info.m_paths.Any(p => p.m_netInfo != null && p.m_netInfo.IsUndergroundMetroStationTrack())) - //{ - // if (connectPoints != null && connectPoints.Count > 0) - // { - // var pool = new List(); - // var pivotPath = pathList.FirstOrDefault(p => p.m_nodes.Any(n => n == connectPoints.FirstOrDefault())); - // pool.AddRange(connectList); - // for (var i = 0; i < connectList.Count; i++) - // { - // var closestVector = pool.SelectMany(n => n).OrderBy(n => (currentVector.x - n.x) + (100 * (connectPoints.FirstOrDefault().y - n.y)) + (currentVector.z - n.z)).LastOrDefault(); - // var closestPath = pathList.FirstOrDefault(p => p.m_nodes.Any(n => n == closestVector)); - // BuildingInfo.PathInfo branch = null; - // if (currentVector == connectPoints.FirstOrDefault()) - // { - // branch = ChainPath(pivotPath, closestVector, Array.IndexOf(pivotPath.m_nodes, connectPoints.FirstOrDefault())); - // } - // else - // { - // branch = ChainPath(closestPath, currentVector, Array.IndexOf(closestPath.m_nodes, closestVector)); - // } - // branch.AssignNetInfo(SpecialNetInfo); - // branch.m_forbidLaneConnection = new[] { true, true }; - // pathList.Add(branch); - // var nodeArrayToLose = pool.FirstOrDefault(na => na.Any(n => n == closestVector)); - // if (nodeArrayToLose != null) - // { - // currentVector = nodeArrayToLose.OrderBy(n => Vector3.Distance(closestVector, n)).LastOrDefault(); - // pool.Remove(nodeArrayToLose); - // } - // } - // if (connectPoints.Count > 1) - // { - // for (var i = 1; i < connectPoints.Count(); i++) - // { - // Vector3 node = connectPoints[i]; - // Vector3 closestVector = connectList.SelectMany(n => n).OrderBy(n => (node.x - n.x) + (100 * (node.y - n.y)) + (node.z - n.z)).FirstOrDefault(); - // var closestPath = pathList.FirstOrDefault(p => p != null && p.m_nodes.Any(n => n == closestVector)); - // var branch = ChainPath(closestPath, node, Array.IndexOf(closestPath.m_nodes, closestVector)); - // branch.AssignNetInfo(SpecialNetInfo); - // branch.m_forbidLaneConnection = new[] { true, true }; - // pathList.Add(branch); - // } - // } - // } - //} - //m_Info.m_paths = CleanPaths(pathList).ToArray(); + m_Info.m_paths = pathList.ToArray(); + //CleanPaths(); } } - public static List AdjustNodeForParent(Vector3[] nodes, ParentStationMetaData parentmetadata = null) + + public static List AdjustNodeFromParentToChild(Vector3[] nodes, ParentStationMetaData parentmetadata = null) { List retList = new List(); foreach (var node in nodes) { - retList.Add(AdjustNodeForParent(node, parentmetadata)); + retList.Add(AdjustNodeFromParentToChild(node, parentmetadata)); } return retList; } - public static Vector3 AdjustNodeForParent(Vector3 node, ParentStationMetaData parentMetaData = null) + + public static Vector3 AdjustNodeFromParentToChild(Vector3 node, ParentStationMetaData parentMetaData = null) { if (parentMetaData == null) parentMetaData = m_ParentMetaData; var retNode = node; - if (parentMetaData != null) + if (m_ParentMetaData != null) { var angle = (parentMetaData.Angle * Math.PI) / 180; retNode = new Vector3 { - x = (float)Math.Round(((node.x - parentMetaData.Position.x) * Math.Cos(angle)) - ((node.z + parentMetaData.Position.z) * Math.Sin(angle))), + x = (float)(((node.x - parentMetaData.Position.x) * Math.Cos(angle)) - ((node.z + parentMetaData.Position.z) * Math.Sin(angle))), y = node.y, - z = (float)Math.Round(((node.x - parentMetaData.Position.x) * Math.Sin(angle)) + ((node.z + parentMetaData.Position.z) * Math.Cos(angle))) + z = (float)(((node.x - parentMetaData.Position.x) * Math.Sin(angle)) + ((node.z + parentMetaData.Position.z) * Math.Cos(angle))) }; } return retNode; } - private static List CleanPaths(List pathList) + public static Vector3 AdjustNodeFromChildToParent(Vector3 node) { - var tinyPaths = pathList.Where(p => Vector3.Distance(p.m_nodes.First(), p.m_nodes.Last()) <= 4).ToList(); - var mergePathDict = new Dictionary(); - if (tinyPaths.Count > 0) + var retNode = node; + if (m_ParentMetaData != null) { - foreach (var path in tinyPaths) + var angle = (m_ParentMetaData.Angle * Math.PI) / 180; + retNode = new Vector3 { - var average = (path.m_nodes.First() + path.m_nodes.Last()) / 2; + x = (float)(node.x * Math.Cos(angle) + node.z * Math.Sin(angle) + m_ParentMetaData.Position.x), + y = node.y, + z = (float)(node.z * Math.Cos(angle) - node.x * Math.Sin(angle) - m_ParentMetaData.Position.z) + }; + } + return retNode; + } + private static Vector3 AverageNode(params Vector3[] nodes) + { + var center = Vector3.zero; + foreach (var node in nodes) + { + center += node; + } + return center / nodes.Count(); + } - if (!(mergePathDict.ContainsKey(path.m_nodes.First()))) - { - mergePathDict.Add(path.m_nodes.First(), average); - } - else if (!mergePathDict.ContainsKey(path.m_nodes.Last())) - { - mergePathDict.Add(path.m_nodes.Last(), mergePathDict[path.m_nodes.First()]); - } - if (!(mergePathDict.ContainsKey(path.m_nodes.Last()))) - { - mergePathDict.Add(path.m_nodes.Last(), average); - } - else if (!mergePathDict.ContainsKey(path.m_nodes.First())) - { - mergePathDict.Add(path.m_nodes.First(), mergePathDict[path.m_nodes.Last()]); - } + private static Dictionary m_MergePathDict = null; + private static Dictionary MergePathDict { + get + { + if (m_MergePathDict == null) + { + m_MergePathDict = new Dictionary(); } + return m_MergePathDict; } - - var finalPathList = new List(); - for (var i = 0; i < pathList.Count(); i++) + } + private static void ClearMergePathDict() + { + if (m_MergePathDict != null) + { + m_MergePathDict.Clear(); + m_MergePathDict = null; + } + } + private static void CleanPaths() + { + var pathList = m_Info.m_paths; + List parentBuildingInfo = null; + ClearMergePathDict(); + for (int i = 0; i < pathList.Count(); i++) { var path = pathList[i]; - if (tinyPaths.Contains(path)) + for (int j = 0; j < path.m_nodes.Count() - 1; j++) { - continue; + var node = path.m_nodes[j]; + var nextNode = path.m_nodes[j + 1]; + if (!MergePathDict.ContainsKey(node) && Vector3.Distance(node, nextNode) <= 4) + { + var average = AverageNode(node, nextNode); + MergePathDict.Add(node, average); + } } - var nodeList = new List(); - for (var j = 0; j < path.m_nodes.Count(); j++) + } + ConsolidatePaths(false); + if (m_ParentMetaData != null) + ConsolidatePaths(true); + } + private static void ConsolidatePaths(bool consolidateParentNodes) + { + var pathList = consolidateParentNodes ? m_ParentMetaData.Info.m_paths : m_Info.m_paths; + for (int i = 0; i < pathList.Count(); i++) + { + var path = pathList[i]; + List nodeList = path.m_nodes.Any(n => MergePathDict.ContainsKey(n)) ? new List() : null; + if (nodeList != null) { - var newNode = path.m_nodes[j]; - if (mergePathDict.ContainsKey(path.m_nodes[j])) + for (int j = 0; j < pathList[i].m_nodes.Count(); j++) { - newNode = mergePathDict[path.m_nodes[j]]; + var node = path.m_nodes[j]; + for (int k = 0; k < MergePathDict.Count(); k++) + { + var kvp = MergePathDict.ElementAt(k); + var nodeToMove = consolidateParentNodes ? AdjustNodeFromChildToParent(kvp.Key) : kvp.Key; + var moveNodeTo = consolidateParentNodes ? AdjustNodeFromChildToParent(kvp.Value) : kvp.Value; + if (node == nodeToMove) + if (!nodeList.Contains(moveNodeTo)) + nodeList.Add(moveNodeTo); + else + if (!nodeList.Contains(node)) + nodeList.Add(node); + } } - nodeList.Add(newNode); + pathList[i].m_nodes = nodeList.ToArray(); + pathList[i].SetCurveTargets(); } - path.m_nodes = nodeList.ToArray(); - path.SetCurveTargets(); - finalPathList.Add(path); } - return finalPathList; } + private static NetInfo FindNetInfo(string prefabName) { return PrefabCollection.FindLoaded(prefabName); @@ -747,10 +713,9 @@ private static BuildingInfo.PathInfo CreatePath(BuildingInfo.PathInfo templatePa newPath.m_nodes = nodeList.ToArray(); newPath.MarkPathGenerated(); newPath.AssignNetInfo(SpecialNetInfo); - NewPath.SetCurveTargets(); + newPath.SetCurveTargets(); return newPath; } - private static void CurveStationTrack() { for (var i = 0; i < m_StationPaths.Count(); i++) @@ -803,7 +768,10 @@ private static void CleanUpPaths(BuildingInfo info) private static void CleanUpPaths() { - m_Info.m_paths = m_Info.m_paths.Where(p => !p.IsPathGenerated()).ToArray(); + if (m_ParentMetaData != null) + m_Info.m_paths = m_Info.m_paths.Where(p => !p.IsPedestrianPath() || p.m_nodes.Any(n => n.y == 0)).ToArray(); + else + m_Info.m_paths = m_Info.m_paths.Where(p => !p.IsPathGenerated()).ToArray(); } private static void RecalculateSpawnPoints() @@ -867,12 +835,11 @@ public static void HandleSubBuildings() var metaData = new ParentStationMetaData() { Info = m_Info, - LowestHighestPaths = LowestHighPaths, + AnchorPoints = AnchorPoints, Angle = subBuilding.m_angle, Position = subBuilding.m_position }; var modifiedPathCustomization = PathCustomization; - modifiedPathCustomization.Curve *= 90; ModifyStation(subBuilding.m_buildingInfo, modifiedPathCustomization, metaData); } } @@ -888,13 +855,8 @@ private static void RemovePedPaths() var pathList = new List(); foreach (var path in m_Info.m_paths) { - if (path.m_netInfo.IsPedestrianNetwork()) - { - if (path.m_nodes.All(n => n.y <= -8) && !LowestHighPaths.Contains(path)) - { - continue; - } - } + if (path.m_netInfo.IsPedestrianNetwork() && !path.IsPathGenerated() && path.m_nodes.All(n => n.y <= -8)) + continue; pathList.Add(path); } m_Info.m_paths = pathList.ToArray(); @@ -980,7 +942,7 @@ private static void ChangeStationDepthAndRotation() var offsetDepthDist = PathCustomization.Depth + highestStation; - if (LowestHighPaths.Count > 0) + if (AnchorPoints.Count > 0) { m_AngleDelta = CalculateAngleDelta(); for (var i = 0; i < m_Info.m_paths.Count(); i++) @@ -989,23 +951,15 @@ private static void ChangeStationDepthAndRotation() var path = m_Info.m_paths[i]; if (AllNodesUnderGround(path)) { - if (LowestHighPaths.Contains(path)) - { - path.AssignNetInfo("Pedestrian Connection Underground"); - path.m_forbidLaneConnection = new[] { false, true }; - } - else + if (path.IsPedestrianPath()) { - if (path.IsPedestrianPath()) - { - pathList.Add(path); - continue; - } - if (IsAlterOfType(MetroStationTrackAlterType.Rotation)) - ChangePathRotation(path, m_AngleDelta); - if (IsAlterOfType(MetroStationTrackAlterType.Depth) && IsATargetPath(path)) - DipPath(path, offsetDepthDist); + pathList.Add(path); + continue; } + if (IsAlterOfType(MetroStationTrackAlterType.Rotation)) + ChangePathRotation(path, m_AngleDelta); + if (IsAlterOfType(MetroStationTrackAlterType.Depth) && IsATargetPath(path)) + DipPath(path, offsetDepthDist); } pathList.Add(path); } @@ -1013,25 +967,6 @@ private static void ChangeStationDepthAndRotation() } } - private static Vector3 GetMeanVector(List vectorList) - { - if (vectorList.Count > 0) - { - float x = 0f; - float y = 0f; - float z = 0f; - foreach (Vector3 v in vectorList) - { - x += v.x; - y += v.y; - z += v.z; - } - return new Vector3(x / vectorList.Count, y / vectorList.Count, z / vectorList.Count); - } - return Vector3.zero; - - - } private static void DipPath(BuildingInfo.PathInfo path, float depthOffsetDist) { ShiftPath(path, new Vector3(0, -depthOffsetDist, 0)); @@ -1049,80 +984,6 @@ private static void ShiftPath(BuildingInfo.PathInfo path, Vector3 offset) } } - //private static IEnumerable GenerateSteps(BuildingInfo.PathInfo path, float depth, double angle, bool isBound = true) - //{ - // var newPath = path.ShallowClone(); - // var pathList = new List(); - // Vector3 lastCoords; - // Vector3 currCoords; - // if (AllNodesUnderGround(newPath)) - // { - // lastCoords = newPath.m_nodes.OrderBy(n => n.z).FirstOrDefault(); - // currCoords = newPath.m_nodes.OrderBy(n => n.z).LastOrDefault(); - // } - // else - // { - // lastCoords = newPath.m_nodes.OrderBy(n => n.y).LastOrDefault(); - // currCoords = newPath.m_nodes.OrderBy(n => n.y).FirstOrDefault(); - // } - // var dir = new Vector3(); - - // MarkPathGenerated(newPath); - // newPath.AssignNetInfo("Pedestrian Connection Underground"); - // var steps = (float)Math.Floor((depth + 4) / 12) * 4; - // if (steps == 0) - // { - // currCoords.y -= depth; - // newPath.m_nodes = new[] { lastCoords, currCoords }; - // SetCurveTargets(newPath); - // ChangePathRotation(newPath, angle); - // pathList.Add(newPath); - // } - // else - // { - // float binder = 8; - // float stepDepth = binder / 2; - // var depthLeft = depth; - // if (isBound) - // { - // dir.x = Math.Min(currCoords.x - lastCoords.x, binder); - // dir.z = Math.Min(currCoords.z - lastCoords.z, binder); - // } - // else - // { - // dir.x = currCoords.x - lastCoords.x; - // dir.z = currCoords.z - lastCoords.z; - // } - // dir.y = currCoords.y - lastCoords.y; - // for (var j = 0; j < steps; j++) - // { - // var newZ = currCoords.z + dir.x; - // var newX = currCoords.x - dir.z; - // lastCoords = currCoords; - // currCoords = new Vector3() { x = newX, y = currCoords.y - Math.Max(0, Math.Min(stepDepth, depthLeft)), z = newZ }; - // depthLeft -= stepDepth; - // var newNodes = new[] { lastCoords, currCoords }; - // newPath = newPath.ShallowClone(); - // newPath.m_nodes = newNodes; - // SetCurveTargets(newPath); - // ChangePathRotation(newPath, angle); - // pathList.Add(newPath); - // if (isBound) - // { - // dir.x = Math.Min(currCoords.x - lastCoords.x, binder); - // dir.z = Math.Min(currCoords.z - lastCoords.z, binder); - // } - // else - // { - // dir.x = currCoords.x - lastCoords.x; - // dir.z = currCoords.z - lastCoords.z; - // } - // dir.y = currCoords.y - lastCoords.y; - // } - // } - // return pathList; - //} - private static void ChangeStationTrackLength(int pathIndex, ICollection processedConnectedPaths) { var path = m_StationPaths[pathIndex]; @@ -1204,6 +1065,11 @@ private static void ChangePathRotation(BuildingInfo.PathInfo path, double angle) if (PathCustomization.Path == path) { offset = Vector3.Lerp(path.m_nodes.First(), path.m_nodes.Last(), 0.5f); + if (angle != 0 && !m_ResetMainRotation && PathCustomizationDict.Count > 1) + { + PathCustomizationDict.FirstOrDefault(p => p.Key.m_nodes == null).Value.Rotation = 0; + m_ResetMainRotation = true; + } } else { From 4ab04e193d3c60cf600b84ceef052c30f1e4ec1b Mon Sep 17 00:00:00 2001 From: andreharv Date: Thu, 28 May 2020 01:56:07 -0400 Subject: [PATCH 4/4] Fix ped clipping. Pathfinding fix for non sub stations --- InitializationSteps/CustomizationSteps.cs | 12 ++-- Initializer.cs | 87 ++++++++++++++--------- SetStationCustomizations.cs | 65 ++++++++++------- 3 files changed, 95 insertions(+), 69 deletions(-) diff --git a/InitializationSteps/CustomizationSteps.cs b/InitializationSteps/CustomizationSteps.cs index d1e4204..086eef3 100644 --- a/InitializationSteps/CustomizationSteps.cs +++ b/InitializationSteps/CustomizationSteps.cs @@ -187,7 +187,6 @@ public static void CommonSteelCustomization(NetInfo prefab, NetInfoVersion versi public static void CommonCustomization(NetInfo prefab, NetInfoVersion version) { - prefab.m_connectGroup = prefab.name.Contains("Station") ? NetInfo.ConnectGroup.MetroStation : NetInfo.ConnectGroup.DoubleMetro; foreach (var lane in prefab.m_lanes) { if (lane.m_laneType == NetInfo.LaneType.Vehicle) @@ -201,6 +200,11 @@ public static void CommonCustomization(NetInfo prefab, NetInfoVersion version) } } + public static void CommonCustomizationTwoLaneTwoWay(NetInfo prefab, NetInfoVersion version) + { + prefab.m_connectGroup = prefab.name.Contains("Station") ? NetInfo.ConnectGroup.MetroStation : NetInfo.ConnectGroup.DoubleMetro; + } + public static void CommonCustomizationTwoLaneOneWay(NetInfo prefab, NetInfoVersion version) { prefab.m_connectGroup = NetInfo.ConnectGroup.MonorailStation; @@ -209,7 +213,6 @@ public static void CommonCustomizationTwoLaneOneWay(NetInfo prefab, NetInfoVersi { if (lane.m_laneType == NetInfo.LaneType.Vehicle) { - lane.m_verticalOffset = 0.35f; if (lane.m_direction == NetInfo.Direction.Backward) { lane.m_direction = NetInfo.Direction.Forward; @@ -284,7 +287,6 @@ public static void CommonCustomizationSmall(NetInfo prefab, NetInfoVersion versi theLanes[i].m_direction = NetInfo.Direction.AvoidBackward; } } - theLanes[i].m_verticalOffset = 0.35f; } } prefab.m_lanes = theLanes.Except(removedLanes).ToArray(); @@ -319,7 +321,6 @@ public static void CommonIslandCustomization(NetInfo prefab, NetInfoVersion vers { theLanes[i].m_position += -4.5f; } - theLanes[i].m_verticalOffset = 0.35f; } } prefab.m_lanes = theLanes.ToArray(); @@ -375,7 +376,6 @@ public static void CommonCustomizationLarge(NetInfo prefab, NetInfoVersion versi break; } count++; - theLanes[i].m_verticalOffset = 0.35f; } else if (theLanes[i].m_laneType == NetInfo.LaneType.Pedestrian) { @@ -452,7 +452,6 @@ public static void CommonLargeSideIslandCustomization(NetInfo prefab, NetInfoVer break; } vehicleCount++; - theLane.m_verticalOffset = 0.35f; } } prefab.m_lanes = theLanes.ToArray(); @@ -523,7 +522,6 @@ public static void CommonLargeDualIslandCustomization(NetInfo prefab, NetInfoVer break; } vehicleLaneCount++; - theLanes[i].m_verticalOffset = 0.35f; } } prefab.m_lanes = theLanes.ToArray(); diff --git a/Initializer.cs b/Initializer.cs index 5c48362..d91d015 100644 --- a/Initializer.cs +++ b/Initializer.cs @@ -10,8 +10,10 @@ using Debug = UnityEngine.Debug; using MetroOverhaul.Extensions; -namespace MetroOverhaul { - public class Initializer: AbstractInitializer { +namespace MetroOverhaul +{ + public class Initializer : AbstractInitializer + { public AppMode AppMode { get; set; } protected override void InitializeNetInfoImpl() @@ -41,9 +43,9 @@ private void CreateConcreteTracks() var replacements = new Dictionary { { NetInfoVersion.Tunnel, Util.GetMetroTrackName(NetInfoVersion.Tunnel, TrackStyle.Modern) } }; CreateFullPrefab( ActionExtensions.BeginChain(). -// Chain(CustomizationSteps.SetupTrackProps). Chain(CustomizationSteps.SetStandardTrackWidths). Chain(CustomizationSteps.CommonCustomization). + Chain(CustomizationSteps.CommonCustomizationTwoLaneTwoWay). Chain(CustomizationSteps.CommonConcreteCustomization). Chain(CustomizationSteps.ReplaceTrackIcon). Chain(SetupMesh.Setup10mMesh, elevatedInfo, metroInfo). @@ -67,8 +69,8 @@ private void CreateConcreteTracks() { CreateFullPrefab( ActionExtensions.BeginChain(). -// Chain(CustomizationSteps.SetupTrackProps). Chain(CustomizationSteps.CommonCustomization). + Chain(CustomizationSteps.CommonCustomizationTwoLaneTwoWay). Chain(CustomizationSteps.CommonConcreteCustomization). Chain(CustomizationSteps.SetStandardTrackWidths). Chain(SetupMesh.Setup10mMesh, elevatedInfo, metroInfo). @@ -95,7 +97,7 @@ private void CreateConcreteTracks() { CreateFullPrefab( ActionExtensions.BeginChain(). -// Chain(CustomizationSteps.SetupTrackProps). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonCustomizationTwoLaneOneWay). Chain(CustomizationSteps.CommonConcreteCustomization). Chain(CustomizationSteps.SetStandardTrackWidths). @@ -124,7 +126,7 @@ private void CreateConcreteTracks() { CreateFullPrefab( ActionExtensions.BeginChain(). -// Chain(CustomizationSteps.SetupTrackProps). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonCustomizationTwoLaneOneWay). Chain(CustomizationSteps.CommonConcreteCustomization). Chain(CustomizationSteps.SetStandardTrackWidths). @@ -151,7 +153,7 @@ private void CreateConcreteTracks() { CreateFullPrefab( ActionExtensions.BeginChain(). -// Chain(CustomizationSteps.SetupTrackProps). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonCustomizationLarge). Chain(CustomizationSteps.CommonConcreteCustomization). Chain(CustomizationSteps.ReplaceTrackIcon). @@ -181,7 +183,7 @@ private void CreateConcreteTracks() { CreateFullPrefab( ActionExtensions.BeginChain(). -// Chain(CustomizationSteps.SetupTrackProps). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonCustomizationLarge). Chain(CustomizationSteps.CommonConcreteCustomization). Chain(CustomizationSteps.SetLargeTrackWidths). @@ -208,7 +210,7 @@ private void CreateConcreteTracks() { CreateFullPrefab( ActionExtensions.BeginChain(). -// Chain(CustomizationSteps.SetupTrackProps). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonCustomizationSmall). Chain(CustomizationSteps.CommonConcreteCustomization). Chain(CustomizationSteps.ReplaceTrackIcon). @@ -238,7 +240,7 @@ private void CreateConcreteTracks() { CreateFullPrefab( ActionExtensions.BeginChain(). -// Chain(CustomizationSteps.SetupTrackProps). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonCustomizationSmall). Chain(CustomizationSteps.CommonConcreteCustomization). Chain(CustomizationSteps.SetSmallTrackWidths). @@ -266,7 +268,7 @@ private void CreateConcreteTracks() { CreateFullPrefab( ActionExtensions.BeginChain(). -// Chain(CustomizationSteps.SetupTrackProps). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonCustomizationSmall). Chain(CustomizationSteps.CommonConcreteCustomization). Chain(CustomizationSteps.SetSmallTrackWidths). @@ -295,7 +297,7 @@ private void CreateConcreteTracks() { CreateFullPrefab( ActionExtensions.BeginChain(). -// Chain(CustomizationSteps.SetupTrackProps). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonCustomizationSmall). Chain(CustomizationSteps.CommonConcreteCustomization). Chain(CustomizationSteps.SetSmallTrackWidths). @@ -324,8 +326,8 @@ private void CreateConcreteTracks() var replacements = new Dictionary { { NetInfoVersion.Tunnel, "Metro Station Track" } }; CreateFullStationPrefab( ActionExtensions.BeginChain(). - //Chain(CustomizationSteps.SetupStationProps). - Chain(CustomizationSteps.CommonCustomization). + Chain(CustomizationSteps.CommonCustomization). + Chain(CustomizationSteps.CommonCustomizationTwoLaneTwoWay). Chain(CustomizationSteps.SetStandardStationTrackWidths). Chain(CustomizationSteps.CommonConcreteCustomization). Chain(SetupMesh.Setup10mStationMesh, elevatedInfo, metroStationInfo). @@ -351,8 +353,8 @@ private void CreateConcreteTracks() { CreateFullStationPrefab( ActionExtensions.BeginChain(). - //Chain(CustomizationSteps.SetupStationProps). Chain(CustomizationSteps.CommonCustomization). + Chain(CustomizationSteps.CommonCustomizationTwoLaneTwoWay). Chain(CustomizationSteps.SetStandardStationTrackWidths). Chain(CustomizationSteps.CommonConcreteCustomization). Chain(SetupMesh.Setup10mStationMesh, elevatedInfo, metroStationInfo). @@ -379,7 +381,7 @@ private void CreateConcreteTracks() { CreateFullStationPrefab( ActionExtensions.BeginChain(). - //Chain(CustomizationSteps.SetupStationProps). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonIslandCustomization). Chain(CustomizationSteps.SetIslandTrackWidths). Chain(CustomizationSteps.CommonConcreteCustomization). @@ -434,7 +436,7 @@ private void CreateConcreteTracks() { CreateFullStationPrefab( ActionExtensions.BeginChain(). - //Chain(CustomizationSteps.SetupStationProps). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonLargeDualIslandCustomization). Chain(CustomizationSteps.SetLargeIslandTrackWidths). Chain(CustomizationSteps.CommonConcreteCustomization). @@ -461,7 +463,7 @@ private void CreateConcreteTracks() { CreateFullStationPrefab( ActionExtensions.BeginChain(). - //Chain(CustomizationSteps.SetupStationProps). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonCustomizationSmall). Chain(CustomizationSteps.CommonConcreteCustomization). Chain(CustomizationSteps.SetSmallStationTrackWidths). @@ -489,7 +491,7 @@ private void CreateConcreteTracks() { CreateFullStationPrefab( ActionExtensions.BeginChain(). - //Chain(CustomizationSteps.SetupStationProps). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonCustomizationLarge). Chain(CustomizationSteps.SetLargeStationTrackWidths). Chain(CustomizationSteps.CommonConcreteCustomization). @@ -527,9 +529,10 @@ private void CreateSteelTracks() { CreateFullPrefab( ActionExtensions.BeginChain(). -// Chain(CustomizationSteps.SetupTrackProps). + // Chain(CustomizationSteps.SetupTrackProps). Chain(CustomizationSteps.SetStandardTrackWidths). Chain(CustomizationSteps.CommonCustomization). + Chain(CustomizationSteps.CommonCustomizationTwoLaneTwoWay). Chain(CustomizationSteps.CommonSteelCustomization). Chain(SetupSteelMesh.Setup10mSteelMesh, elevatedInfo). Chain(SetupSteelMesh.Setup10mSteelBarMesh, elevatedInfo). @@ -558,8 +561,9 @@ private void CreateSteelTracks() { CreateFullPrefab( ActionExtensions.BeginChain(). -// Chain(CustomizationSteps.SetupTrackProps). + // Chain(CustomizationSteps.SetupTrackProps). Chain(CustomizationSteps.CommonCustomizationLarge). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonSteelCustomization). Chain(CustomizationSteps.SetLargeTrackWidths). Chain(SetupSteelMesh.Setup10mSteelMesh, elevatedInfo). @@ -589,8 +593,9 @@ private void CreateSteelTracks() { CreateFullPrefab( ActionExtensions.BeginChain(). -// Chain(CustomizationSteps.SetupTrackProps). + // Chain(CustomizationSteps.SetupTrackProps). Chain(CustomizationSteps.CommonCustomizationLarge). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonSteelCustomization). Chain(CustomizationSteps.SetLargeTrackWidths). Chain(SetupSteelMesh.Setup10mSteelMesh, elevatedInfo). @@ -621,8 +626,9 @@ private void CreateSteelTracks() CreateFullPrefab( ActionExtensions.BeginChain(). Chain(CustomizationSteps.CommonCustomization). + Chain(CustomizationSteps.CommonCustomizationTwoLaneTwoWay). Chain(CustomizationSteps.CommonSteelCustomization). -// Chain(CustomizationSteps.SetupTrackProps). + // Chain(CustomizationSteps.SetupTrackProps). Chain(CustomizationSteps.SetStandardTrackWidths). Chain(SetupSteelMesh.Setup10mSteelMesh, elevatedInfo). Chain(SetupSteelMesh.Setup10mSteelNoBarMesh, elevatedInfo, metroInfo). @@ -652,8 +658,9 @@ private void CreateSteelTracks() { CreateFullPrefab( ActionExtensions.BeginChain(). -// Chain(CustomizationSteps.SetupTrackProps). + // Chain(CustomizationSteps.SetupTrackProps). Chain(CustomizationSteps.CommonCustomizationTwoLaneOneWay). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonSteelCustomization). Chain(CustomizationSteps.SetStandardTrackWidths). Chain(SetupSteelMesh.Setup10mSteelMesh, elevatedInfo). @@ -684,8 +691,9 @@ private void CreateSteelTracks() { CreateFullPrefab( ActionExtensions.BeginChain(). -// Chain(CustomizationSteps.SetupTrackProps). + // Chain(CustomizationSteps.SetupTrackProps). Chain(CustomizationSteps.CommonCustomizationTwoLaneOneWay). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonSteelCustomization). Chain(CustomizationSteps.SetStandardTrackWidths). Chain(SetupSteelMesh.Setup10mSteelMesh, elevatedInfo). @@ -716,8 +724,9 @@ private void CreateSteelTracks() { CreateFullPrefab( ActionExtensions.BeginChain(). -// Chain(CustomizationSteps.SetupTrackProps). + // Chain(CustomizationSteps.SetupTrackProps). Chain(CustomizationSteps.CommonCustomizationSmall). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonSteelCustomization). Chain(CustomizationSteps.SetSmallTrackWidths). Chain(SetupSteelMesh.Setup6mSteelMesh, elevatedInfo). @@ -748,8 +757,9 @@ private void CreateSteelTracks() { CreateFullPrefab( ActionExtensions.BeginChain(). -// Chain(CustomizationSteps.SetupTrackProps). + // Chain(CustomizationSteps.SetupTrackProps). Chain(CustomizationSteps.CommonCustomizationSmall). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonSteelCustomization). Chain(CustomizationSteps.SetSmallTrackWidths). Chain(SetupSteelMesh.Setup6mSteelMesh, elevatedInfo). @@ -779,8 +789,9 @@ private void CreateSteelTracks() { CreateFullPrefab( ActionExtensions.BeginChain(). -// Chain(CustomizationSteps.SetupTrackProps). + // Chain(CustomizationSteps.SetupTrackProps). Chain(CustomizationSteps.CommonCustomizationSmall). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonSteelCustomization). Chain(CustomizationSteps.SetSmallTrackWidths). Chain(SetupSteelMesh.Setup6mSteelMesh, elevatedInfo). @@ -811,8 +822,9 @@ private void CreateSteelTracks() { CreateFullPrefab( ActionExtensions.BeginChain(). -// Chain(CustomizationSteps.SetupTrackProps). + // Chain(CustomizationSteps.SetupTrackProps). Chain(CustomizationSteps.CommonCustomizationSmall). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonSteelCustomization). Chain(CustomizationSteps.SetSmallTrackWidths). Chain(SetupSteelMesh.Setup6mSteelMesh, elevatedInfo). @@ -846,6 +858,7 @@ private void CreateSteelTracks() ActionExtensions.BeginChain(). //Chain(CustomizationSteps.SetupStationProps). Chain(CustomizationSteps.CommonCustomization). + Chain(CustomizationSteps.CommonCustomizationTwoLaneTwoWay). Chain(CustomizationSteps.CommonSteelCustomization). Chain(SetupSteelMesh.Setup10mStationSteelMesh, elevatedInfo). Chain(SetupSteelTexture.Setup10mSteelTexture) @@ -895,6 +908,7 @@ private void CreateSteelTracks() //Chain(CustomizationSteps.SetupStationProps). Chain(CustomizationSteps.CommonLargeDualIslandCustomization). Chain(CustomizationSteps.SetLargeIslandTrackWidths). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonSteelCustomization). Chain(SetupSteelMesh.Setup19mSteelStationMesh, elevatedInfo, metroStationInfo). Chain(SetupSteelTexture.Setup19mSteelTexture). @@ -921,6 +935,7 @@ private void CreateSteelTracks() ActionExtensions.BeginChain(). //Chain(CustomizationSteps.SetupStationProps). Chain(CustomizationSteps.CommonIslandCustomization). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonSteelCustomization). Chain(CustomizationSteps.SetIslandTrackWidths). Chain(SetupSteelMesh.Setup19mSteelStationMesh, elevatedInfo, metroStationInfo). @@ -944,6 +959,7 @@ private void CreateSteelTracks() ActionExtensions.BeginChain(). //Chain(CustomizationSteps.SetupStationProps). Chain(CustomizationSteps.CommonCustomizationSmall). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonSteelCustomization). Chain(CustomizationSteps.SetSmallTrackWidths). Chain(SetupSteelMesh.Setup6mStationSteelMesh, elevatedInfo, metroStationInfo). @@ -965,7 +981,8 @@ private void CreateSteelTracks() { CreateFullStationPrefab( ActionExtensions.BeginChain(). - //Chain(CustomizationSteps.SetupStationProps). +//Chain(CustomizationSteps.SetupStationProps). + Chain(CustomizationSteps.CommonCustomization). Chain(CustomizationSteps.CommonSteelCustomization). Chain(CustomizationSteps.CommonCustomizationLarge). Chain(CustomizationSteps.SetLargeStationTrackWidths). @@ -1002,7 +1019,7 @@ private void CreateCloneBuilding(BuildingInfo info) sw.Start(); CreateFullStationClone(info, ActionExtensions.BeginChain(). Chain(CustomizationSteps.CommonClonedStationCustomization)); - //Chain(CustomizationSteps.ReplaceBuildingIcon)); + //Chain(CustomizationSteps.ReplaceBuildingIcon)); sw.Stop(); UnityEngine.Debug.Log("Items took " + sw.ElapsedMilliseconds + "ms"); } @@ -1019,7 +1036,7 @@ private void CreateCloneBuilding(BuildingInfo info) private void ModifyVanillaTrackPrefabs() { var groundVersion = Prefabs.Find(Util.GetMetroTrackName(NetInfoVersion.Ground, TrackStyle.Vanilla)); - foreach (var version in new[] { NetInfoVersion.Ground, NetInfoVersion.Elevated, NetInfoVersion.Bridge, NetInfoVersion.Slope, NetInfoVersion.Tunnel }) + foreach (var version in new[] { NetInfoVersion.Ground, NetInfoVersion.Elevated, NetInfoVersion.Bridge, NetInfoVersion.Slope, NetInfoVersion.Tunnel }) { var info = Prefabs.Find(Util.GetMetroTrackName(version, TrackStyle.Vanilla)); ReplaceAI(info, version); @@ -1212,8 +1229,8 @@ private static void ReplaceBuildingAI(BuildingInfo prefab) { var clonedTtsaAi = ttsaAI.CloneBuildingAI(ttsaAI.name); var metroEntrance = PrefabCollection.FindLoaded("Metro Entrance"); - clonedTtsaAi.m_transportLineInfo =PrefabCollection.FindLoaded("Metro Line"); - clonedTtsaAi.m_transportInfo =PrefabCollection.FindLoaded("Metro"); + clonedTtsaAi.m_transportLineInfo = PrefabCollection.FindLoaded("Metro Line"); + clonedTtsaAi.m_transportInfo = PrefabCollection.FindLoaded("Metro"); clonedTtsaAi.m_maxVehicleCount = 0; //clonedTtsaAi.m_createPassMilestone = metroEntrance.GetComponent().m_createPassMilestone; clonedTtsaAi.m_info = trainStationAnalog; @@ -1449,7 +1466,7 @@ public static void SetCosts(PrefabInfo newPrefab, NetInfoVersion version) { metroTrackInfo = FindOriginalNetInfo(Util.GetMetroTrackName(version, TrackStyle.Vanilla)); } - + var baseConstructionCost = metroTrackInfo.GetComponent().m_constructionCost; var baseMaintenanceCost = metroTrackInfo.GetComponent().m_maintenanceCost; var newAi = newPrefab.GetComponent(); diff --git a/SetStationCustomizations.cs b/SetStationCustomizations.cs index 247462d..770e585 100644 --- a/SetStationCustomizations.cs +++ b/SetStationCustomizations.cs @@ -132,27 +132,25 @@ public static List AnchorPoints { else { Debug.Log("Building " + m_Info.name + " is being checked for AnchorPoints"); - var anchorPaths = m_Info.m_paths.Where(p => p.IsPedestrianPath() && p.m_nodes.Any(n => n.y == 0)).ToList(); - if (anchorPaths != null) + var pedPaths = m_Info.m_paths.Where(p => p.IsPedestrianPath()); + var anchorPaths = pedPaths.Where(p => p.m_nodes.Any(n => n.y < 0) && p.m_nodes.Any(n => n.y >= 0)).ToList(); + if (anchorPaths == null || anchorPaths.Count() == 0) { - for (int i = 0; i < anchorPaths.Count(); i++) + anchorPaths = pedPaths.OrderBy(p => p.m_nodes.Min(n => n.z)).ToList(); + } + for (int i = 0; i < anchorPaths.Count(); i++) + { + var anchorNode = anchorPaths[i].m_nodes.OrderBy(p => p.y).FirstOrDefault(); + m_AnchorPoints.Add(anchorNode); + if (anchorNode == default) { - var anchorNode = anchorPaths[i].m_nodes.OrderBy(p => p.y).FirstOrDefault(); - m_AnchorPoints.Add(anchorNode); - if (anchorNode == default) + Debug.Log("No suitable anchorNodes found on building."); + foreach (var node in anchorPaths[i].m_nodes) { - Debug.Log("No suitable anchorNodes found on building."); - foreach (var node in anchorPaths[i].m_nodes) - { - Debug.Log(node.ToString() + ", parent: " + AdjustNodeFromChildToParent(node).ToString()); - } + Debug.Log(node.ToString() + ", parent: " + AdjustNodeFromChildToParent(node).ToString()); } - Debug.Log("Anchorpoint " + anchorNode.ToString() + " found on building" + m_Info.name); } - } - else - { - Debug.Log("No nodes in Building " + m_Info.name + " that satisfies the outline criteria."); + Debug.Log("Anchorpoint " + anchorNode.ToString() + " found on building" + m_Info.name); } } } @@ -418,7 +416,7 @@ private static void ReconfigureStationAccess() var stationLength = Vector3.Distance(TrackPath.m_nodes[0], TrackPath.m_nodes.Last()); StairsLengthX = ((0.12f * curve) + 1) * (stationLength * StairCoeff) * -xCoeff; StairsLengthZ = ((0.12f * curve) + 1) * (stationLength * StairCoeff) * zCoeff; - var interpolant = 0.6f; + var interpolant = 1; Crossing = Vector3.Lerp(TrackPath.m_nodes.First(), TrackPath.m_nodes.Last(), interpolant); if (TrackPath.m_netInfo.IsUndergroundIslandPlatformStationTrack()) { @@ -542,7 +540,7 @@ private static void ConnectStations() forbidLaneConnectionList.Add(false); connectorPath.m_forbidLaneConnection = forbidLaneConnectionList.ToArray(); connectorPath.MarkPathGenerated(); - //connectorPath.SetCurveTargets(); + connectorPath.m_curveTargets = null; pathList.Add(connectorPath); pathNodeList.Clear(); connectorPath = connectorPath.ShallowClone(); @@ -632,14 +630,17 @@ private static void CleanPaths() for (int i = 0; i < pathList.Count(); i++) { var path = pathList[i]; - for (int j = 0; j < path.m_nodes.Count() - 1; j++) + if (path.IsPathGenerated()) { - var node = path.m_nodes[j]; - var nextNode = path.m_nodes[j + 1]; - if (!MergePathDict.ContainsKey(node) && Vector3.Distance(node, nextNode) <= 4) + for (int j = 0; j < path.m_nodes.Count() - 1; j++) { - var average = AverageNode(node, nextNode); - MergePathDict.Add(node, average); + var node = path.m_nodes[j]; + var nextNode = path.m_nodes[j + 1]; + if (!MergePathDict.ContainsKey(node) && Vector3.Distance(node, nextNode) <= 4) + { + var average = AverageNode(node, nextNode); + MergePathDict.Add(node, average); + } } } } @@ -768,10 +769,20 @@ private static void CleanUpPaths(BuildingInfo info) private static void CleanUpPaths() { - if (m_ParentMetaData != null) - m_Info.m_paths = m_Info.m_paths.Where(p => !p.IsPedestrianPath() || p.m_nodes.Any(n => n.y == 0)).ToArray(); - else + if (m_ParentMetaData == null && m_Info.m_paths.SelectMany(p => p.m_nodes).All(n => n.y < 0)) + { m_Info.m_paths = m_Info.m_paths.Where(p => !p.IsPathGenerated()).ToArray(); + } + else + { + var pathsToKeep = m_Info.m_paths.Where(p => !p.IsPathGenerated() && (!p.IsPedestrianPath() || p.m_nodes.Any(n => n.y >= 0))); + if (pathsToKeep == null || pathsToKeep.Count() == 0) + pathsToKeep = m_Info.m_paths.OrderBy(p => p.m_nodes.Min(n => n.z)).Take(1); + m_Info.m_paths = pathsToKeep.ToArray(); + } + + //else + //m_Info.m_paths = m_Info.m_paths.Where(p => !p.IsPathGenerated()).ToArray(); } private static void RecalculateSpawnPoints()