//this method is supposed to be called from LoadingExtension
        public static void UpdateBuildingsMetroPaths(LoadMode mode, bool toVanilla = false)
        {
#if !DEBUG
            if (mode == LoadMode.NewAsset || mode == LoadMode.NewAsset)
            {
                return;
            }
#endif
            for (uint i = 0; i < PrefabCollection <BuildingInfo> .LoadedCount(); i++)
            {
                try
                {
                    var prefab = PrefabCollection <BuildingInfo> .GetPrefab(i);

                    if (prefab == null)
                    {
                        continue;
                    }
                    if (!toVanilla)
                    {
                        if (!OptionsWrapper <Options> .Options.metroUi)
                        {
                            SetStationCustomizations.ModifyStation(prefab, 12, 144, 0, 0);
                        }
                    }
                    SetupTunnelTracks(prefab, toVanilla);
                }
                catch (Exception e)
                {
                    UnityEngine.Debug.LogException(e);
                }
            }
        }
Beispiel #2
0
        private static void UpdateBuilding(ushort buildingID, BuildingInfo superInfo = null)
        {
            Building     building = BuildingFrom(buildingID);
            BuildingInfo info     = building.Info;

            PopulateDictionaries(buildingID);
            PrepareBuilding(ref info);
            if (!OptionsWrapper <Options> .Options.ghostMode && HasUndergroundMOMorVanilla(buildingID, false))
            {
                SetStationCustomizations.ModifyStation(info, SetStationCustomizations.DEF_DEPTH, SetStationCustomizations.MIN_LENGTH, (int)SetStationCustomizations.DEF_ANGLE, SetStationCustomizations.DEF_BEND_STRENGTH, superInfo);
            }
            info = BuildingFrom(buildingID).Info;
            binstance.UpdateBuildingInfo(buildingID, info);
            RevertBuilding(ref info);
            ReconsileOrphanedSegments(buildingID);
        }
Beispiel #3
0
        private static void UpdateBuilding(ushort buildingID)
        {
            Building     building = BuildingFrom(buildingID);
            BuildingInfo info     = building.Info.ShallowClone();

            PopulateDictionaries(buildingID);
            PrepareBuilding(ref info);
            if (!OptionsWrapper <Options> .Options.ghostMode && HasUndergroundMOMorVanilla(buildingID, true))
            {
                SetStationCustomizations.ModifyStation(info, SetStationCustomizations.DEF_DEPTH, SetStationCustomizations.MIN_LENGTH, (int)SetStationCustomizations.DEF_ANGLE, SetStationCustomizations.DEF_BEND_STRENGTH);
                binstance.UpdateBuildingInfo(buildingID, info);
            }

            RevertBuilding(ref info);
            ReconsileOrphanedSegments(buildingID);
            //binstance.RelocateBuilding(buildingID, building.m_position, building.m_angle);
        }
Beispiel #4
0
        public static void UpdateBuildingsMetroPaths(LoadMode mode, bool toVanilla = false)
        {
#if !DEBUG
            if (mode == LoadMode.NewAsset || mode == LoadMode.NewAsset)
            {
                return;
            }
#endif

            try
            {
                for (uint i = 0; i < PrefabCollection <BuildingInfo> .LoadedCount(); i++)
                {
                    var prefab = PrefabCollection <BuildingInfo> .GetPrefab(i);

                    if (prefab == null || !(prefab.m_buildingAI is DepotAI))
                    {
                        continue;
                    }
                    if (!toVanilla)
                    {
                        if (!OptionsWrapper <Options> .Options.metroUi)
                        {
                            SetStationCustomizations.ModifyStation(prefab, SetStationCustomizations.DEF_DEPTH, SetStationCustomizations.DEF_LENGTH, (int)SetStationCustomizations.DEF_ANGLE, SetStationCustomizations.DEF_BEND_STRENGTH);
                        }
                    }
                    else
                    {
                        SetupTunnelTracks(prefab, toVanilla);
                    }
                }
                var totalStations        = 0;
                var totalShallowStations = 0;
                for (ushort i = 0; i < binstance.m_buildings.m_buffer.Count(); i++)
                {
                    Building     b    = binstance.m_buildings.m_buffer[i];
                    BuildingInfo info = b.Info;
                    if (info == null || !(info.m_buildingAI is DepotAI))
                    {
                        continue;
                    }
                    List <ushort> stationNodes = GetStationNodes(b);
                    if (stationNodes != null)
                    {
                        totalStations++;
                        var highestStationNode = stationNodes.OrderBy(n => NodeFrom(n).m_position.y).LastOrDefault();
                        if (NodeFrom(highestStationNode).m_position.y == b.m_position.y - 4)
                        {
                            totalShallowStations++;
                        }
                        //stationNodes.Where(n => NodeFrom(n).m_position.y == b.m_position.y - 4).Count();
                    }
                }

                m_NeedsConvert = (float)totalShallowStations / totalStations >= 0.5f;
                for (ushort i = 0; i < Singleton <NetManager> .instance.m_nodes.m_buffer.Count(); i++)
                {
                    NetNode n    = Singleton <NetManager> .instance.m_nodes.m_buffer[i];
                    NetInfo info = n.Info;
                    if (info == null)
                    {
                        continue;
                    }
                    if (m_NeedsConvert && (info.IsUndergroundMetroTrack() || info.name == "Metro Track"))
                    {
                        m_NeedsConvert = true;
                        DipPath(i, n, toVanilla);
                    }
                    else if (toVanilla && info.IsUndergroundMetroTrack())
                    {
                        m_NeedsConvert = true;
                        DipPath(i, n, toVanilla);
                    }
                }
                if (m_NeedsConvert)
                {
                    for (ushort i = 0; i < binstance.m_buildings.m_buffer.Count(); i++)
                    {
                        Building     b    = BuildingFrom(i);
                        BuildingInfo info = b.Info;
                        if (b.m_parentBuilding == 0)
                        {
                            if (info != null && info.m_buildingAI is DepotAI)
                            {
                                connectList = null;
                                if (info.m_subBuildings != null && info.m_subBuildings.Any(sb => sb != null && sb.m_buildingInfo != null && HasStationTracks(sb.m_buildingInfo)))
                                {
                                    ushort subBuildingID = b.m_subBuilding;
                                    while (subBuildingID > 0)
                                    {
                                        if (HasStationTracks(BuildingFrom(subBuildingID).Info))
                                        {
                                            UpdateBuilding(subBuildingID);
                                        }
                                        subBuildingID = BuildingFrom(subBuildingID).m_subBuilding;
                                    }
                                }
                                if (HasUndergroundMOMorVanilla(i, false))
                                {
                                    UpdateBuilding(i);
                                }
                            }
                        }
                    }

                    if (toVanilla)
                    {
                        for (ushort i = 0; i < ninstance.m_nodes.m_buffer.Count(); i++)
                        {
                            NetNode node = NodeFrom(i);
                            if (node.Info.IsMetroTrack())
                            {
                                ninstance.m_nodes.m_buffer[i].Info = PrefabCollection <NetInfo> .FindLoaded("Metro Track");

                                ninstance.UpdateNode(i);
                            }
                            else if (node.Info.IsMetroStationTrack())
                            {
                                ninstance.m_nodes.m_buffer[i].Info = PrefabCollection <NetInfo> .FindLoaded("Metro Station Track");

                                ninstance.UpdateNode(i);
                            }
                        }
                        for (ushort i = 0; i < ninstance.m_segments.m_buffer.Count(); i++)
                        {
                            NetSegment segment = SegmentFrom(i);
                            if (segment.Info.IsMetroTrack())
                            {
                                ninstance.m_segments.m_buffer[i].Info = PrefabCollection <NetInfo> .FindLoaded("Metro Track");

                                ninstance.UpdateSegment(i);
                            }
                            else if (segment.Info.IsMetroStationTrack())
                            {
                                ninstance.m_segments.m_buffer[i].Info = PrefabCollection <NetInfo> .FindLoaded("Metro Station Track");

                                ninstance.UpdateSegment(i);
                            }
                        }
                    }
                }
                else
                {
                    for (uint i = 0; i < PrefabCollection <BuildingInfo> .LoadedCount(); i++)
                    {
                        var prefab = PrefabCollection <BuildingInfo> .GetPrefab(i);

                        if (prefab == null || !(prefab.m_buildingAI is DepotAI) || prefab.m_class?.m_service != ItemClass.Service.PublicTransport || prefab.m_class?.m_subService != ItemClass.SubService.PublicTransportMetro)
                        {
                            continue;
                        }
                        PrepareBuilding(ref prefab);
                    }
                }
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogException(e);
            }
        }