static bool Prefix(ushort lineID)
        {
            TransportLine line = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID];

            if (lineID == 0 || !line.Info.m_transportType.IsSharedStopTransport())
            {
                return(true);
            }

            Log.Debug($"remove line {lineID} with stops {line.m_stops}");
            ushort stops = line.m_stops;

            if (stops == 0)
            {
                return(true);
            }
            for (int i = 0; i < line.CountStops(lineID); i++)
            {
                stops = TransportLine.GetNextStop(stops);
                uint   lane    = Singleton <NetManager> .instance.m_nodes.m_buffer[stops].m_lane;
                ushort segment = Singleton <NetManager> .instance.m_lanes.m_buffer[lane].m_segment;
                if (lane != 0 && segment != 0)
                {
                    Log.Debug($"remove stop {stops} on lane {lane} on segment {segment}");
                    Singleton <SharedStopsTool> .instance.RemoveSharedStop(segment, lineID, lane);
                }
            }
            return(true);
        }
示例#2
0
        private List <OSMNode> CreateTransportLine(int index, TransportLine line)
        {
            List <OSMNode>   returnNodes      = new List <OSMNode>();
            TransportManager transportManager = Singleton <TransportManager> .instance;

            int numberOfStops = line.CountStops(line.m_stops);
            var transportType = line.Info.m_transportType;

            if (line.m_stops != 0 && numberOfStops > 0)
            {
                for (int stopIndex = 0; stopIndex < numberOfStops; ++stopIndex)
                {
                    ushort  stopId = line.GetStop(stopIndex);
                    NetNode stop = Singleton <NetManager> .instance.m_nodes.m_buffer[(int)stopId];
                    Vector3 position = stop.m_position;
                    ushort  transportLine = stop.m_transportLine;
                    string  transportLineName = transportLineName = transportManager.GetLineName(transportLine);;
                    decimal lon, lat;

                    Translations.VectorToLonLat(position, out lon, out lat);

                    List <OSMNodeTag> tags = new List <OSMNodeTag>();

                    if (transportType == TransportInfo.TransportType.Bus)
                    {
                        tags.Add(new OSMNodeTag {
                            k = "highway", v = "bus_stop"
                        });
                    }
                    else if (transportType == TransportInfo.TransportType.Train)
                    {
                        bool tramLine = transportLineName != null && (transportLineName.Contains("[t]") || transportLineName.ToLower().Contains("tram"));
                        tags.Add(new OSMNodeTag {
                            k = "public_transport", v = "platform"
                        });
                        tags.Add(new OSMNodeTag {
                            k = "railway", v = tramLine ? "tram_stop" : "station"
                        });
                    }
                    else if (transportType == TransportInfo.TransportType.Tram)
                    {
                        tags.Add(new OSMNodeTag {
                            k = "public_transport", v = "platform"
                        });
                        tags.Add(new OSMNodeTag {
                            k = "railway", v = "tram_stop"
                        });
                    }

                    returnNodes.Add(new OSMNode {
                        changeset = 50000000, id = (uint)unindexedNodeOffset++, version = 1, timestamp = DateTime.Now, user = "******", lon = lon, lat = lat, tag = tags.ToArray()
                    });
                }
            }

            return(returnNodes);
        }
示例#3
0
        public static string[] GetAllStopsFromLine(ushort lineID)
        {
            TransportLine t          = TransportManager.instance.m_lines.m_buffer[lineID];
            int           stopsCount = t.CountStops(lineID);

            string[]             result = new string[stopsCount];
            ItemClass.SubService ss     = TransportSystemDefinition.GetDefinitionForLine(lineID).SubService;
            for (int i = 0; i < stopsCount; i++)
            {
                ushort stationId = t.GetStop(i);
                result[i] = TLMStationUtils.GetFullStationName(stationId, lineID, ss);
            }
            return(result);
        }
        private void RemovePtStopClick(UIComponent component, UIMouseEventParameter eventparam)
        {
            if (_currentStop == 0 && _currentLine == 0)
            {
                return;
            }

            ShowConfirmDialog(
                "[BND] Remove Public Transport Stop",
                "Are you sure you want to remove that stop?",
                () => {
                TransportLine line = TransportManager.instance.m_lines.m_buffer[_currentLine];
                int stops          = line.CountStops(_currentLine);
                if (GetStopIndex(line, stops, _currentStop, out int stopIndex))
                {
                    Debug.Log("[BND] Removing stop [" + _currentStop + "] line: " + _currentLine + " index: " + stopIndex + " Line has " + stops + " stops");


                    //async task on simulation thread
                    AsyncTask a = Singleton <SimulationManager> .instance.AddAction("Remove PT stop", RemoveStop(_currentLine, stopIndex, () => {
                        _currentStop = 0;
                        if (stops == 1)
                        {
                            ModService.Instance.InvalidLines.Remove(_currentLine);
                            _currentLine = 0;
                            Debug.Log("[BND] Last Stop (" + _currentStop + ") removed successfully. Removing lane (" + _currentLine + ") from invalid PT lines");
                        }
                        else
                        {
                            ModService.Instance.InvalidLines[_currentLine].RefreshInvalidStops();
                            if (ModService.Instance.InvalidLines[_currentLine].Stops.Count == 0)
                            {
                                ModService.Instance.InvalidLines.Remove(_currentLine);
                                _currentLine = 0;
                                Debug.Log("[BND] No more disconnected PT stops. Removing lane (" + _currentLine + ") from invalid PT lines");
                            }
                        }

                        UpdatePtButtons();
                        UpdateLinePanel();
                    }));
                }
                else
                {
                    Debug.Log("[BND] Current PT stop (" + _currentStop + ") not found in line (" + _currentLine + ")!!!");
                    UpdatePtButtons();
                    UpdateLinePanel();
                }
            });
        }
        public static void BeforeRemoveStop(ref TransportLine __instance, int index, ushort lineID)
        {
            if ((__instance.m_flags & TransportLine.Flags.Temporary) != TransportLine.Flags.None || __instance.m_stops > NetManager.MAX_NODE_COUNT)
            {
                return;
            }
            ushort num;

            if (index == -1)
            {
                index += __instance.CountStops(lineID);
            }
            num = __instance.m_stops;
            for (int i = 0; i < index && num <= NetManager.MAX_NODE_COUNT; i++)
            {
                num = TransportLine.GetNextStop(num);
                if (num == __instance.m_stops)
                {
                    break;
                }
            }
            WTSBuildingDataCaches.PurgeStopCache(num);
        }
        private List<OSMNode> CreateTransportLine(int index, TransportLine line)
        {
            List<OSMNode> returnNodes = new List<OSMNode>();
            TransportManager transportManager = Singleton<TransportManager>.instance;

            int numberOfStops = line.CountStops(line.m_stops);
            var transportType = line.Info.m_transportType;

            if (line.m_stops != 0 && numberOfStops > 0)
            {
                for (int stopIndex = 0; stopIndex < numberOfStops; ++stopIndex)
                {
                    ushort stopId = line.GetStop(stopIndex);
                    NetNode stop = Singleton<NetManager>.instance.m_nodes.m_buffer[(int)stopId];
                    Vector3 position = stop.m_position;
                    ushort transportLine = stop.m_transportLine;
                    string transportLineName = transportLineName = transportManager.GetLineName(transportLine); ;
                    decimal lon, lat;

                    Translations.VectorToLonLat(position, out lon, out lat);

                    List<OSMNodeTag> tags = new List<OSMNodeTag>();

                    if (transportType == TransportInfo.TransportType.Bus)
                    {
                        tags.Add(new OSMNodeTag { k = "highway", v = "bus_stop" });
                    }
                    else if (transportType == TransportInfo.TransportType.Train)
                    {
                        bool tramLine = transportLineName != null && (transportLineName.Contains("[t]") || transportLineName.ToLower().Contains("tram"));
                        tags.Add(new OSMNodeTag { k = "public_transport", v = "platform" });
                        tags.Add(new OSMNodeTag { k = "railway", v = tramLine ? "tram_stop" : "station" });
                    }
                    else if (transportType == TransportInfo.TransportType.Tram)
                    {
                        tags.Add(new OSMNodeTag { k = "public_transport", v = "platform" });
                        tags.Add(new OSMNodeTag { k = "railway", v = "tram_stop" });
                    }

                    returnNodes.Add(new OSMNode { changeset = 50000000, id = (uint)unindexedNodeOffset++, version = 1, timestamp = DateTime.Now, user = "******", lon = lon, lat = lat, tag = tags.ToArray() });
                }
            }

            return returnNodes;
        }
        public static void drawCityMap()
        {
            TLMController controller = TLMController.instance;
            Dictionary <TransportInfo.TransportType, List <ushort> > linesByType = new Dictionary <TransportInfo.TransportType, List <ushort> >();

            foreach (var type in Enum.GetValues(typeof(TransportInfo.TransportType)))
            {
                linesByType[(TransportInfo.TransportType)type] = new List <ushort>();
            }

            //			List<int> usedX = new List<int> ();
            //			List<int> usedY = new List<int> ();
            int nextStationId = 1;

            for (ushort lineId = 0; lineId < controller.tm.m_lines.m_size; lineId++)
            {
                TransportLine t = controller.tm.m_lines.m_buffer[(int)lineId];
                if (t.m_lineNumber > 0 && (t.m_flags & TransportLine.Flags.Complete) != TransportLine.Flags.None)
                {
                    linesByType[t.Info.m_transportType].Add(lineId);
                }
            }

            CalculateCoords calc         = TLMUtils.gridPosition81Tiles;
            NetManager      nm           = NetManager.instance;
            float           invPrecision = 32;
            //Restart:
            Dictionary <int, List <int> > positions = new Dictionary <int, List <int> >();
            List <Station> stations = new List <Station>();
            Dictionary <ushort, MapTransportLine> transportLines = new Dictionary <ushort, MapTransportLine>();

            foreach (TransportInfo.TransportType tt in linesByType.Keys)
            {
                if (!linesByType.ContainsKey(tt))
                {
                    continue;
                }
                foreach (ushort lineId in linesByType[tt])
                {
                    TransportLine t     = controller.tm.m_lines.m_buffer[(int)lineId];
                    float         range = 75f;
                    switch (tt)
                    {
                    case TransportInfo.TransportType.Ship:
                        range = 150f;
                        break;

                    case TransportInfo.TransportType.Metro:
                    case TransportInfo.TransportType.Monorail:
                    case TransportInfo.TransportType.Train:
                    case TransportInfo.TransportType.CableCar:
                        range = 100f;
                        break;
                    }


                    int stopsCount = t.CountStops(lineId);
                    if (stopsCount == 0)
                    {
                        continue;
                    }
                    Color   color  = t.m_color;
                    Vector2 ultPos = Vector2.zero;
                    t.GetActive(out bool day, out bool night);
                    transportLines[lineId] = new MapTransportLine(color, day, night, lineId);
                    int startStop = 0;
                    int finalStop = stopsCount;

                    for (int j = startStop; j < finalStop; j++)
                    {
                        //						Debug.Log ("ULT POS:" + ultPos);
                        ushort nextStop = t.GetStop(j % stopsCount);
                        string name     = TLMLineUtils.getStationName(nextStop, lineId, t.Info.m_stationSubService, out ItemClass.Service service, out ItemClass.SubService nil2, out string prefix, out ushort buildingId, out NamingType namingType);

                        Vector3 worldPos = TLMLineUtils.getStationBuildingPosition(nextStop, t.Info.m_stationSubService);
                        Vector2 pos2D    = calc(worldPos, invPrecision);
                        Vector2 gridAdd  = Vector2.zero;


                        var idx = stations.FirstOrDefault(x => x.stopsWithWorldPos.ContainsKey(nextStop) || x.centralPos == pos2D);
                        if (idx != null)
                        {
                            transportLines[lineId].addStation(ref idx);
                        }
                        else
                        {
                            //if (positions.containskey((int)pos2d.x) && positions[(int)pos2d.x].contains((int)pos2d.y))
                            //{
                            //    float exp = (float)(math.log(invprecision) / math.log(2)) - 1;
                            //    invprecision = (float)math.pow(2, exp);
                            //    goto restart;
                            //}
                            Dictionary <ushort, Vector3> nearStops = new Dictionary <ushort, Vector3>();
                            TLMLineUtils.GetNearStopPoints(worldPos, range, ref nearStops, new ItemClass.SubService[] { ItemClass.SubService.PublicTransportShip, ItemClass.SubService.PublicTransportPlane }, 10);
                            TLMLineUtils.GetNearStopPoints(worldPos, range, ref nearStops, new ItemClass.SubService[] { ItemClass.SubService.PublicTransportTrain, ItemClass.SubService.PublicTransportMonorail, ItemClass.SubService.PublicTransportCableCar, ItemClass.SubService.PublicTransportMetro }, 10);
                            TLMLineUtils.GetNearStopPoints(worldPos, range, ref nearStops, new ItemClass.SubService[] { ItemClass.SubService.PublicTransportTram, ItemClass.SubService.PublicTransportBus }, 10);
                            TLMUtils.doLog("Station: ${0}; nearStops: ${1}", name, string.Join(",", nearStops.Select(x => x.ToString()).ToArray()));
                            Station thisStation = new Station(name, pos2D, worldPos, nearStops, nextStationId++, service, nextStop);
                            stations.Add(thisStation);
                            transportLines[lineId].addStation(ref thisStation);
                        }
                        if (!positions.ContainsKey((int)pos2D.x))
                        {
                            positions[(int)pos2D.x] = new List <int>();
                        }
                        positions[(int)pos2D.x].Add((int)pos2D.y);
                        //						Debug.Log ("POS:" + pos);
                        ultPos = pos2D;
                    }
                }
            }
            printToSVG(stations, transportLines, Singleton <SimulationManager> .instance.m_metaData.m_CityName + "_" + Singleton <SimulationManager> .instance.m_currentGameTime.ToString("yyyy.MM.dd"));
            printToJson(stations, transportLines, Singleton <SimulationManager> .instance.m_metaData.m_CityName + "_" + Singleton <SimulationManager> .instance.m_currentGameTime.ToString("yyyy.MM.dd"));
        }
示例#8
0
        public static void DrawCityMap()
        {
            TLMController controller  = TLMController.Instance;
            var           linesByType = new Dictionary <TransportInfo.TransportType, List <ushort> >();

            foreach (object type in Enum.GetValues(typeof(TransportInfo.TransportType)))
            {
                linesByType[(TransportInfo.TransportType)type] = new List <ushort>();
            }

            int nextStationId = 1;

            for (ushort lineId = 0; lineId < TransportManager.instance.m_lines.m_size; lineId++)
            {
                TransportLine t = TransportManager.instance.m_lines.m_buffer[lineId];

                if (t.m_lineNumber > 0 && allowedTypesToDraw.Contains(t.Info.m_transportType) && (t.m_flags & TransportLine.Flags.Complete) != TransportLine.Flags.None)
                {
                    linesByType[t.Info.m_transportType].Add(lineId);
                }
            }
            Func <Vector3, float, Vector2> calc = MapUtils.GridPosition81Tiles;
            NetManager nm           = NetManager.instance;
            float      invPrecision = 35;

            var stations       = new List <TLMMapStation>();
            var transportLines = new Dictionary <ushort, TLMMapTransportLine>();

            foreach (var tt in linesByType.OrderByDescending(x => GetRangeFromTransportType(x.Key)))
            {
                foreach (ushort lineId in tt.Value)
                {
                    ref TransportLine t     = ref TransportManager.instance.m_lines.m_buffer[lineId];
                    float             range = GetRangeFromTransportType(t.Info.m_transportType);

                    int stopsCount = t.CountStops(lineId);
                    if (stopsCount == 0)
                    {
                        continue;
                    }
                    Color color = t.m_color;
                    t.GetActive(out bool day, out bool night);
                    transportLines[lineId] = new TLMMapTransportLine(color, day, night, lineId);
                    ushort startStop = t.m_stops;
                    ushort nextStop  = startStop;
                    do
                    {
                        string name = TLMStationUtils.GetStationName(nextStop, lineId, t.Info.m_stationSubService, out ItemClass.Service service, out ItemClass.SubService nil2, out string prefix, out ushort buildingId, out NamingType namingType);

                        Vector3 worldPos = TLMStationUtils.GetStationBuildingPosition(nextStop, t.Info.m_stationSubService);
                        Vector2 pos2D    = calc(worldPos, invPrecision);
                        Vector2 gridAdd  = Vector2.zero;

                        TLMMapStation idx = stations.FirstOrDefault(x => x.stopsWithWorldPos.ContainsKey(nextStop));
                        if (idx != null)
                        {
                            transportLines[lineId].AddStation(ref idx);
                        }
                        else
                        {
                            var nearStops = new Dictionary <ushort, Vector3>();
                            TLMLineUtils.GetNearStopPoints(worldPos, range, ref nearStops, new ItemClass.SubService[] {
                                ItemClass.SubService.PublicTransportShip,
                                ItemClass.SubService.PublicTransportPlane,
                                ItemClass.SubService.PublicTransportTrain,
                                ItemClass.SubService.PublicTransportMonorail,
                                ItemClass.SubService.PublicTransportCableCar,
                                ItemClass.SubService.PublicTransportMetro,
                                ItemClass.SubService.PublicTransportTram,
                                ItemClass.SubService.PublicTransportBus,
                                ItemClass.SubService.PublicTransportTrolleybus
                            }, 15);
                            if (!nearStops.ContainsKey(nextStop))
                            {
                                nearStops[nextStop] = NetManager.instance.m_nodes.m_buffer[nextStop].m_position;
                            }
                            var thisStation = new TLMMapStation(name, pos2D, worldPos, nearStops, nextStationId++, service, nextStop);
                            stations.Add(thisStation);
                            transportLines[lineId].AddStation(ref thisStation);
                        }
                        nextStop = TransportLine.GetNextStop(nextStop);
                    } while (nextStop != startStop && nextStop != 0);
                }
            }
        public void redrawLine()
        {
            ushort        lineID       = parent.CurrentSelectedId;
            TransportLine t            = TLMController.instance.tm.m_lines.m_buffer[(int)lineID];
            int           stopsCount   = t.CountStops(lineID);
            int           vehicleCount = t.CountVehicles(lineID);
            Color         lineColor    = TLMController.instance.tm.GetLineColor(lineID);

            setLinearMapColor(lineColor);
            clearStations();
            updateSubIconLayer();
            setLineNumberCircle(lineID);
            if (lineID == 0)
            {
                var tsd = TransportSystemDefinition.from(parent.CurrentTransportInfo);
                if (tsd != default(TransportSystemDefinition))
                {
                    linearMapLineNumberFormat.backgroundSprite = TLMLineUtils.GetIconForIndex(tsd.toConfigIndex());
                }
                lineStationsPanel.width = 0;
                return;
            }

            ItemClass.SubService ss = TLMCW.getDefinitionForLine(lineID).subService;
            linearMapLineNumberFormat.backgroundSprite = TLMLineUtils.getIconForLine(lineID);
            m_autoName = TLMLineUtils.calculateAutoName(lineID, true);
            linearMapLineNumber.tooltip = m_autoName;
            string  stationName;
            Vector3 local;
            string  airport, taxi, harbor, regionalStation, cableCarStation;
            string  namePrefix;
            bool    isComplete = (Singleton <TransportManager> .instance.m_lines.m_buffer[TLMController.instance.CurrentSelectedId].m_flags & TransportLine.Flags.Complete) != TransportLine.Flags.None;
            bool    simmetric  = TLMLineUtils.CalculateSimmetry(ss, stopsCount, t, out int middle);
            float   addedWidth = 0;

            lineStationsPanel.width = 0;
            if (t.Info.m_transportType != TransportInfo.TransportType.Bus && t.Info.m_transportType != TransportInfo.TransportType.Tram && simmetric && !showExtraStopInfo)
            {
                int maxIt = middle + stopsCount / 2;
                for (int j = middle; j <= maxIt; j++)
                {
                    ushort stationId = t.GetStop(j);
                    local      = getStation(lineID, stationId, ss, out stationName, out List <ushort> intersections, out airport, out harbor, out taxi, out regionalStation, out cableCarStation, out namePrefix);
                    addedWidth = addStationToLinearMap(namePrefix, stationName, local, lineStationsPanel.width, intersections, airport, harbor, taxi, regionalStation, cableCarStation, stationId, ss, lineColor, false) + (j == middle + stopsCount / 2 ? 5 : 0);
                    lineStationsPanel.width += addedWidth;
                }
            }
            else
            {
                int minI = 0, maxI = stopsCount;
                if (simmetric)
                {
                    minI = middle + 1;
                    maxI = stopsCount + middle + 1;
                }
                if (showExtraStopInfo)
                {
                    int    j         = (minI - 1 + stopsCount) % stopsCount;
                    ushort stationId = t.GetStop(j);
                    local = getStation(lineID, stationId, ss, out stationName, out List <ushort> intersections, out airport, out harbor, out taxi, out regionalStation, out cableCarStation, out namePrefix);
                    lineStationsPanel.width += addStationToLinearMap(namePrefix, stationName, local, lineStationsPanel.width, intersections, airport, harbor, taxi, regionalStation, cableCarStation, stationId, ss, lineColor, true);
                }
                else if (TLMSingleton.showDistanceInLinearMap || parent.ForceShowStopsDistances)
                {
                    minI--;
                }
                for (int i = minI; i < maxI; i++)
                {
                    int    j         = (i + stopsCount) % stopsCount;
                    ushort stationId = t.GetStop(j);
                    local      = getStation(lineID, stationId, ss, out stationName, out List <ushort> intersections, out airport, out harbor, out taxi, out regionalStation, out cableCarStation, out namePrefix);
                    addedWidth = addStationToLinearMap(namePrefix, stationName, local, lineStationsPanel.width, intersections, airport, harbor, taxi, regionalStation, cableCarStation, stationId, ss, lineColor, false);
                    lineStationsPanel.width += addedWidth;
                }
            }
            lineStationsPanel.width -= addedWidth;
            if (showExtraStopInfo)
            {
                vehiclesOnStation.Clear();
                for (int v = 0; v < vehicleCount; v++)
                {
                    ushort vehicleId = t.GetVehicle(v);

                    AddVehicleToLinearMap(lineColor, vehicleId);
                }
            }
        }
示例#10
0
        public static void SimulationStep(ref TransportLine thisLine, ushort lineID)
        {
            //begin mod(+): change for initialization
            if (!TransportLineMod._init)
            {
                return;
            }
            //end mod

            TransportInfo info = thisLine.Info;

            if (thisLine.Complete)
            {
                //begin mod(*): moved this section to a separate method
                int num2 = CountLineActiveVehicles(lineID);
                //end mod
                bool flag1 = !Singleton <SimulationManager> .instance.m_isNightTime
                    ? (thisLine.m_flags & TransportLine.Flags.DisabledDay) == TransportLine.Flags.None
                    : (thisLine.m_flags & TransportLine.Flags.DisabledNight) == TransportLine.Flags.None;
                uint  range = 0;
                float num5  = 0.0f;
                int   num6  = 0;
                bool  flag2 = false;
                if ((int)thisLine.m_stops != 0)
                {
                    NetManager instance = Singleton <NetManager> .instance;
                    ushort     stops    = thisLine.m_stops;
                    ushort     num3     = stops;
                    int        num4     = 0;
                    while ((int)num3 != 0)
                    {
                        ushort num7 = 0;
                        if (flag1)
                        {
                            instance.m_nodes.m_buffer[(int)num3].m_flags &=
                                NetNode.Flags.OneWayOutTrafficLights | NetNode.Flags.UndergroundTransition |
                                NetNode.Flags.Created | NetNode.Flags.Deleted | NetNode.Flags.Original |
                                NetNode.Flags.End | NetNode.Flags.Middle | NetNode.Flags.Bend | NetNode.Flags.Junction |
                                NetNode.Flags.Moveable | NetNode.Flags.Untouchable | NetNode.Flags.Outside |
                                NetNode.Flags.Temporary | NetNode.Flags.Double | NetNode.Flags.Fixed |
                                NetNode.Flags.OnGround | NetNode.Flags.Ambiguous | NetNode.Flags.Water |
                                NetNode.Flags.Sewage | NetNode.Flags.ForbidLaneConnection |
                                NetNode.Flags.LevelCrossing | NetNode.Flags.OneWayIn | NetNode.Flags.Heating |
                                NetNode.Flags.Electricity | NetNode.Flags.Collapsed | NetNode.Flags.DisableOnlyMiddle |
                                NetNode.Flags.AsymForward | NetNode.Flags.AsymBackward |
                                NetNode.Flags.CustomTrafficLights;
                        }
                        else
                        {
                            instance.m_nodes.m_buffer[(int)num3].m_flags |= NetNode.Flags.Disabled;
                        }
                        for (int index = 0; index < 8; ++index)
                        {
                            ushort segment = instance.m_nodes.m_buffer[(int)num3].GetSegment(index);
                            if ((int)segment != 0 && (int)instance.m_segments.m_buffer[(int)segment].m_startNode ==
                                (int)num3)
                            {
                                num6 +=
                                    Mathf.Max((int)instance.m_segments.m_buffer[(int)segment].m_trafficLightState0,
                                              (int)instance.m_segments.m_buffer[(int)segment].m_trafficLightState1);
                                num5 += instance.m_segments.m_buffer[(int)segment].m_averageLength;
                                num7  = instance.m_segments.m_buffer[(int)segment].m_endNode;
                                if ((instance.m_segments.m_buffer[(int)segment].m_flags &
                                     NetSegment.Flags.PathLength) == NetSegment.Flags.None)
                                {
                                    flag2 = true;
                                    break;
                                }
                                break;
                            }
                        }
                        ++range;
                        num3 = num7;
                        if ((int)num3 != (int)stops)
                        {
                            if (++num4 >= 32768)
                            {
                                CODebugBase <LogChannel> .Error(LogChannel.Core,
                                                                "Invalid list detected!\n" + System.Environment.StackTrace);

                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                if (!flag2)
                {
                    thisLine.m_totalLength = num5;
                }
                if ((int)range != 0)
                {
                    thisLine.m_averageInterval = (byte)Mathf.Min((float)byte.MaxValue,
                                                                 (float)(((long)num6 + (long)(range >> 1)) / (long)range));
                }
                //begin mod(-): let's count maintenance once a week
                //end mod

                TransferManager.TransferReason vehicleReason = info.m_vehicleReason;
                if (vehicleReason != TransferManager.TransferReason.None)
                {
                    //begin mod: calculate target vehicle count or read saved value
                    int num3 = 0;
                    if (TransportLineMod._lineData[(int)lineID].BudgetControl || info.m_class.m_service == ItemClass.Service.Disaster)
                    {
                        num3 = !flag1 ? 0 : (!flag2 ? thisLine.CalculateTargetVehicleCount() : num2);
                        TransportLineMod._lineData[(int)lineID].TargetVehicleCount = num3;
                    }
                    else if (flag1)
                    {
                        num3 = TransportLineMod._lineData[(int)lineID].TargetVehicleCount;
                    }
                    //end mod
                    if (range != 0 && num2 < num3)
                    {
                        ushort stop = thisLine.GetStop(Singleton <SimulationManager> .instance.m_randomizer
                                                       .Int32((uint)thisLine.CountStops(lineID)));
                        if (info.m_vehicleReason != TransferManager.TransferReason.None && (int)stop != 0)
                        {
                            //begin mod(+): save offer as variable and directly invoke spawn if it's not evac line
                            TransferManager.TransferOffer offer =
                                new TransferManager.TransferOffer
                            {
                                Priority      = num3 - num2 + 1,
                                TransportLine = lineID,
                                Position      = Singleton <NetManager> .instance.m_nodes.m_buffer[(int)stop]
                                                .m_position,
                                Amount = 1,
                                Active = false
                            };
                            if (info.m_class.m_service == ItemClass.Service.Disaster)
                            {
                                Singleton <TransferManager> .instance.AddIncomingOffer(vehicleReason, offer);
                            }
                            else
                            {
                                HandleVehicleSpawn(lineID, info, num3, num2, offer);
                            }
                            //end mod
                        }
                    }
                    else if (num2 > num3)
                    {
                        //begin mod(*): encapsulate into method
                        TransportLineMod.RemoveActiveVehicle(lineID, false, num2);
                        //end mod
                    }
                }
            }
            if ((Singleton <SimulationManager> .instance.m_currentFrameIndex & 4095U) < 3840U)
            {
                return;
            }
            thisLine.m_passengers.Update();
            Singleton <TransportManager> .instance.m_passengers[(int)info.m_transportType].Add(ref thisLine.m_passengers);
            thisLine.m_passengers.Reset();


            //begin mod(+): update statistics + fetch maintenance costs
            if (thisLine.Complete)
            {
                ushort stops1 = thisLine.m_stops;
                ushort stop1  = stops1;
                do
                {
                    NetManagerMod.m_cachedNodeData[(int)stop1].StartNewWeek();
                    stop1 = TransportLine.GetNextStop(stop1);
                } while ((int)stops1 != (int)stop1 && (int)stop1 != 0);

                var          itemClass = info.m_class;
                PrefabData[] prefabs   = VehiclePrefabs.instance.GetPrefabs(itemClass.m_service, itemClass.m_subService, itemClass.m_level);
                int          amount    = 0;
                CountLineActiveVehicles(lineID, (num3) =>
                {
                    Vehicle vehicle       = VehicleManager.instance.m_vehicles.m_buffer[num3];
                    PrefabData prefabData = Array.Find(prefabs,
                                                       item => item.PrefabDataIndex == vehicle.Info.m_prefabDataIndex);
                    if (prefabData != null)
                    {
                        amount += prefabData.MaintenanceCost;
                        VehicleManagerMod.m_cachedVehicleData[num3].StartNewWeek(prefabData.MaintenanceCost);
                    }
                });
                if (amount != 0)
                {
                    Singleton <EconomyManager> .instance.FetchResource(EconomyManager.Resource.Maintenance, amount, info.m_class);
                }
                //end mod
            }
        }
        public static void SimulationStepImpl(ref TransportLine line, ushort lineID)
        {
            if (!line.Complete)
            {
                return;
            }
            TransportInfo     info      = line.Info;
            SimulationManager instance1 = Singleton <SimulationManager> .instance;
            bool isLineEnabled          = !instance1.m_isNightTime ? (line.m_flags & TransportLine.Flags.DisabledDay) == TransportLine.Flags.None : (line.m_flags & TransportLine.Flags.DisabledNight) == TransportLine.Flags.None;
            bool flag = TransportLineMod.SetLineStatus(lineID, isLineEnabled);
            int  num1 = line.CountVehicles(lineID);
            int  num2 = 0;

            if (TransportLineMod._lineData[(int)lineID].BudgetControl)
            {
                num2 = !isLineEnabled ? 0 : (!flag ? Mathf.CeilToInt((float)((double)TransportLineMod.GetBudget(lineID, instance1.m_isNightTime, info.m_class) * (double)TransportLineMod.GetLength(lineID) / ((double)info.m_defaultVehicleDistance * 100.0))) : num1);
                TransportLineMod._lineData[(int)lineID].TargetVehicleCount = num2;
            }
            else if (isLineEnabled)
            {
                num2 = TransportLineMod._lineData[(int)lineID].TargetVehicleCount;
            }
            if (num1 < num2)
            {
                if ((double)SimHelper.instance.SimulationTime >= (double)TransportLineMod._lineData[(int)lineID].NextSpawnTime)
                {
                    int    index1 = instance1.m_randomizer.Int32((uint)line.CountStops(lineID));
                    ushort stop   = line.GetStop(index1);
                    if (info.m_vehicleReason != TransferManager.TransferReason.None && (int)stop != 0)
                    {
                        TransferManager.TransferOffer offer = new TransferManager.TransferOffer();
                        offer.Priority      = num2 - num1 + 1;
                        offer.TransportLine = lineID;
                        offer.Position      = Singleton <NetManager> .instance.m_nodes.m_buffer[(int)stop].m_position;
                        offer.Amount        = 1;
                        offer.Active        = false;
                        ushort depot = TransportLineMod._lineData[(int)lineID].Depot;
                        if (TransportLineMod.IsLineDepotStillValid(lineID, ref depot))
                        {
                            BuildingManager instance2 = Singleton <BuildingManager> .instance;
                            if (TransportLineMod.CanAddVehicle(depot, ref instance2.m_buildings.m_buffer[(int)depot]))
                            {
                                string prefabName;
                                if (TransportLineMod.EnqueuedVehiclesCount(lineID) > 0)
                                {
                                    prefabName = TransportLineMod.Dequeue(lineID);
                                }
                                else
                                {
                                    int num3 = num2 - num1;
                                    for (int index2 = 0; index2 < num3; ++index2)
                                    {
                                        TransportLineMod.EnqueueVehicle(lineID, TransportLineMod.GetRandomPrefab(lineID), false);
                                    }
                                    prefabName = TransportLineMod.Dequeue(lineID);
                                }
                                if (prefabName != "")
                                {
                                    int num4 = (int)DepotAIMod.StartTransfer(depot, ref instance2.m_buildings.m_buffer[(int)depot], info.m_vehicleReason, offer, prefabName);
                                }
                                else
                                {
                                    instance2.m_buildings.m_buffer[(int)depot].Info.m_buildingAI.StartTransfer(depot, ref instance2.m_buildings.m_buffer[(int)depot], info.m_vehicleReason, offer);
                                }
                                TransportLineMod._lineData[(int)lineID].NextSpawnTime = SimHelper.instance.SimulationTime + (float)ImprovedPublicTransportMod.Settings.SpawnTimeInterval;
                            }
                            else
                            {
                                TransportLineMod.ClearEnqueuedVehicles(lineID);
                            }
                        }
                    }
                }
            }
            else if (num1 > num2)
            {
                TransportLineMod.RemoveRandomVehicle(lineID, false);
            }
            if ((instance1.m_currentFrameIndex & 4095U) < 3840U)
            {
                return;
            }
            line.m_passengers.Update();
            Singleton <TransportManager> .instance.m_passengers[(int)info.m_transportType].Add(ref line.m_passengers);
            line.m_passengers.Reset();
            ushort stops = line.m_stops;
            ushort stop1 = stops;

            do
            {
                NetManagerMod.m_cachedNodeData[(int)stop1].StartNewWeek();
                stop1 = TransportLine.GetNextStop(stop1);
            }while ((int)stops != (int)stop1 && (int)stop1 != 0);
            VehicleManager instance3 = Singleton <VehicleManager> .instance;

            PrefabData[] prefabs = VehiclePrefabs.instance.GetPrefabs(info.m_class.m_subService);
            int          amount  = 0;

            for (ushort index = line.m_vehicles; (int)index != 0; index = instance3.m_vehicles.m_buffer[(int)index].m_nextLineVehicle)
            {
                Vehicle    vehicle    = instance3.m_vehicles.m_buffer[(int)index];
                PrefabData prefabData = Array.Find <PrefabData>(prefabs, (Predicate <PrefabData>)(item => item.PrefabDataIndex == vehicle.Info.m_prefabDataIndex));
                if (prefabData != null)
                {
                    amount += prefabData.MaintenanceCost;
                    VehicleManagerMod.m_cachedVehicleData[(int)index].StartNewWeek(prefabData.MaintenanceCost);
                }
            }
            if (amount == 0)
            {
                return;
            }
            Singleton <EconomyManager> .instance.FetchResource(EconomyManager.Resource.Maintenance, amount, info.m_class);
        }
示例#12
0
        public void redrawLine()
        {
            ushort        lineID       = lineInfoPanel.lineIdSelecionado.TransportLine;
            TransportLine t            = lineInfoPanel.controller.tm.m_lines.m_buffer[(int)lineID];
            int           stopsCount   = t.CountStops(lineID);
            int           vehicleCount = t.CountVehicles(lineID);
            Color         lineColor    = lineInfoPanel.controller.tm.GetLineColor(lineID);

            setLinearMapColor(lineColor);
            clearStations();
            String bgSprite;

            ItemClass.SubService ss = TLMLineUtils.getLineNamingParameters(lineID, out prefix, out sep, out suffix, out nonPrefix, out zerosEsquerda, out invertPrefixSuffix, out bgSprite).subService;
            linearMapLineNumberFormat.backgroundSprite = bgSprite;


            bool day, night, zeroed;

            TLMLineUtils.getLineActive(ref t, out day, out night, out zeroed);
            if (zeroed)
            {
                linearMapLineTime.backgroundSprite = "NoBudgetIcon";
            }
            else
            {
                if (!day || !night)
                {
                    linearMapLineTime.backgroundSprite = day ? "DayIcon" : night ? "NightIcon" : "DisabledIcon";
                }
                else
                {
                    linearMapLineTime.backgroundSprite = "";
                }
            }

            setLineNumberCircle(t.m_lineNumber, prefix, sep, suffix, nonPrefix, zerosEsquerda, invertPrefixSuffix);

            m_autoName = TLMUtils.calculateAutoName(lineID);
            string  stationName = null;
            Vector3 local;
            string  airport, taxi, harbor, regionalStation;
            int     middle;
            string  namePrefix;
            bool    simmetric = TLMUtils.CalculateSimmetry(ss, stopsCount, t, out middle);

            if (t.Info.m_transportType != TransportInfo.TransportType.Bus && t.Info.m_transportType != TransportInfo.TransportType.Tram && simmetric && !showExtraStopInfo)
            {
                lineStationsPanel.width = 5;
                for (int j = middle; j <= middle + stopsCount / 2; j++)
                {
                    List <ushort> intersections;
                    ushort        stationId = t.GetStop(j);
                    local = getStation(lineID, stationId, ss, out stationName, out intersections, out airport, out harbor, out taxi, out regionalStation, out namePrefix);
                    lineStationsPanel.width += addStationToLinearMap(namePrefix, stationName, local, lineStationsPanel.width, intersections, airport, harbor, taxi, regionalStation, stationId, ss) + (j == middle + stopsCount / 2 ? 5 : 0);
                }
            }
            else
            {
                lineStationsPanel.width = 5;
                int minI = 0, maxI = stopsCount;
                if (simmetric)
                {
                    minI = middle + 1;
                    maxI = stopsCount + middle + 1;
                }
                if (showExtraStopInfo)
                {
                    int           j         = (minI - 1 + stopsCount) % stopsCount;
                    ushort        stationId = t.GetStop(j);
                    List <ushort> intersections;
                    local = getStation(lineID, stationId, ss, out stationName, out intersections, out airport, out harbor, out taxi, out regionalStation, out namePrefix);
                    lineStationsPanel.width += addStationToLinearMap(namePrefix, stationName, local, lineStationsPanel.width, intersections, airport, harbor, taxi, regionalStation, stationId, ss, true);
                }
                for (int i = minI; i < maxI; i++)
                {
                    int           j = i % stopsCount;
                    List <ushort> intersections;
                    ushort        stationId = t.GetStop(j);
                    local = getStation(lineID, stationId, ss, out stationName, out intersections, out airport, out harbor, out taxi, out regionalStation, out namePrefix);
                    lineStationsPanel.width += addStationToLinearMap(namePrefix, stationName, local, lineStationsPanel.width, intersections, airport, harbor, taxi, regionalStation, stationId, ss) + (j == stopsCount - (showExtraStopInfo ? 0 : 1) ? 5 : 0);
                }
            }
            if (showExtraStopInfo)
            {
                vehiclesOnStation.Clear();
                for (int v = 0; v < vehicleCount; v++)
                {
                    ushort vehicleId = t.GetVehicle(v);

                    AddVehicleToLinearMap(lineColor, vehicleId);
                }
            }
        }