示例#1
0
    public void startNewLine()
    {
        GameObject line = Instantiate(m_transportLinePrefab, this.transform);

        line.name             = "Line " + line.GetComponent <TransportLine>().m_lineUid;
        m_activeTransportLine = line.GetComponent <TransportLine>();
    }
        static bool Prefix(out uint __state, VehicleInfo.VehicleType ___m_vehicleType, ushort nodeID, ref NetNode data)
        {
            __state = 0;
            if (nodeID == 0 || !___m_vehicleType.IsSharedStopTransport())
            {
                return(true);
            }
            ushort segment = Singleton <NetManager> .instance.m_lanes.m_buffer[data.m_lane].m_segment;

            ushort        lineID = Singleton <NetManager> .instance.m_nodes.m_buffer[nodeID].m_transportLine;
            TransportLine line   = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID];

            __state = data.m_lane;
            NetLane.Flags flags = (NetLane.Flags)Singleton <NetManager> .instance.m_lanes.m_buffer[data.m_lane].m_flags;
            if (!Singleton <SharedStopsTool> .instance.sharedStopSegments.Any(s => s.m_segment == segment))
            {
                return(true);
            }
            NetSegment segData = Singleton <NetManager> .instance.m_segments.m_buffer[segment];

            Log.Debug($"RemoveLaneConn on segment {segment}, {segData}");
            Singleton <SharedStopsTool> .instance.RemoveSharedStop(segment, lineID, data.m_lane);

            return(true);
        }
        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);
        }
        public static void RemoveRandomVehicle(ushort lineID, bool descreaseVehicleCount = true)
        {
            TransportLine transportLine = Singleton <TransportManager> .instance.m_lines.m_buffer[(int)lineID];
            int           index         = Singleton <SimulationManager> .instance.m_randomizer.Int32((uint)transportLine.CountVehicles(lineID));

            TransportLineMod.RemoveVehicle(lineID, transportLine.GetVehicle(index), descreaseVehicleCount);
        }
示例#5
0
        public static string GetLineSortString(ushort s, ref TransportLine tl)
        {
            var tsd = TransportSystemDefinition.GetDefinitionForLine(s);

            if (tsd == default)
            {
                return(null);
            }
            string transportTypeLetter =
                tsd == TransportSystemDefinition.PLANE ? "A"
            : tsd == TransportSystemDefinition.SHIP ? "B"
            : tsd == TransportSystemDefinition.BLIMP ? "C"
            : tsd == TransportSystemDefinition.HELICOPTER ? "D"
            : tsd == TransportSystemDefinition.TRAIN ? "E"
            : tsd == TransportSystemDefinition.FERRY ? "F"
            : tsd == TransportSystemDefinition.MONORAIL ? "G"
            : tsd == TransportSystemDefinition.METRO ? "H"
            : tsd == TransportSystemDefinition.CABLE_CAR ? "I"
            : tsd == TransportSystemDefinition.TROLLEY ? "J"
            : tsd == TransportSystemDefinition.TRAM ? "K"
            : tsd == TransportSystemDefinition.BUS ? "L"
            : tsd == TransportSystemDefinition.TOUR_BUS ? "M"
            : tsd == TransportSystemDefinition.TOUR_PED ? "N"
            : "";


            return(transportTypeLetter + tl.m_lineNumber.ToString().PadLeft(5, '0'));
        }
        public ushort GetStop(int index)
        {
            ushort stops = this.m_stops;
            ushort num   = stops;
            int    num2  = 0;

            while (num != 0)
            {
                if (index-- == 0)
                {
                    return(num);
                }
                num = TransportLine.GetNextStop(num);
                if (num == stops)
                {
                    break;
                }
                if (++num2 >= 32768)
                {
                    CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace);

                    break;
                }
            }
            return(0);
        }
        private static List<string> GetDistrictsForLine(TransportLine transportLine, NetManager theNetworkManager, DistrictManager theDistrictManager, out int stopCount)
        {
            var stop = TransportLine.GetPrevStop(transportLine.m_stops);
            var firstStop = stop;
            stopCount = 0;
            var districts = new List<string>();
            while (stop != 0)
            {
                stopCount++;
                var position = theNetworkManager.m_nodes.m_buffer[stop].m_position;
                var district = theDistrictManager.GetDistrict(position);
                if (district != 0)
                {
                    var districtName = theDistrictManager.GetDistrictName(district);
                    districtName = districtName.Trim();
                    if (districts.Contains(districtName) == false)
                        districts.Add(districtName);
                }
                else
                {
                    if (districts.Contains(string.Empty) == false)
                        districts.Add(string.Empty);
                }

                stop = TransportLine.GetNextStop(stop);
                if (stop == firstStop)
                    break;
            }
            return districts;
        }
示例#8
0
        public static int GetStopIndex(ushort lineID, ushort stopID)
        {
            ushort stop = Singleton <TransportManager> .instance.m_lines.m_buffer[(int)lineID].m_stops;
            int    num1 = 0;
            int    num2 = 0;

            while ((int)stop != 0)
            {
                if ((int)stopID == (int)stop)
                {
                    return(num1);
                }
                ++num1;
                stop = TransportLine.GetNextStop(stop);
                if (++num2 >= 32768)
                {
                    CODebugBase <LogChannel> .Error(LogChannel.Core,
                                                    "Invalid list detected!\n" + System.Environment.StackTrace);

                    break;
                }
            }

            return(0);
        }
示例#9
0
        public static void removeAllUnwantedVehicles()
        {
            for (ushort lineId = 1; lineId < Singleton <TransportManager> .instance.m_lines.m_size; lineId++)
            {
                if ((Singleton <TransportManager> .instance.m_lines.m_buffer[lineId].m_flags & TransportLine.Flags.Created) != TransportLine.Flags.None)
                {
                    if (TransportLinesManagerMod.instance != null && TransportLinesManagerMod.debugMode)
                    {
                        TLMUtils.doLog("removeAllUnwantedVehicles: line #{0}", lineId);
                    }
                    TransportLine tl     = Singleton <TransportManager> .instance.m_lines.m_buffer[lineId];
                    uint          prefix = 0;
                    if (TLMConfigWarehouse.getCurrentConfigInt(TLMConfigWarehouse.getConfigIndexForTransportInfo(tl.Info) | TLMConfigWarehouse.ConfigIndex.PREFIX) != (int)ModoNomenclatura.Nenhum)
                    {
                        prefix = tl.m_lineNumber / 1000u;
                    }
                    VehicleManager instance3 = Singleton <VehicleManager> .instance;
                    VehicleInfo    info      = instance3.m_vehicles.m_buffer[Singleton <TransportManager> .instance.m_lines.m_buffer[lineId].GetVehicle(0)].Info;
                    if (TransportLinesManagerMod.instance != null && TransportLinesManagerMod.debugMode)
                    {
                        TLMUtils.doLog("removeAllUnwantedVehicles: pre model list; type = {0}", info.GetAI());
                    }
                    var def = TransportSystemDefinition.from(info);
                    if (def == default(TransportSystemDefinition))
                    {
                        if (TransportLinesManagerMod.instance != null && TransportLinesManagerMod.debugMode)
                        {
                            TLMUtils.doLog("NULL TSysDef! {0}+{1}+{2}", info.GetAI().GetType(), info.m_class.m_subService, info.m_vehicleType);
                        }
                        continue;
                    }
                    var modelList = BasicTransportExtensionSingleton.instance(def).getAssetListForPrefix(prefix);
                    if (TransportLinesManagerMod.instance != null && TransportLinesManagerMod.debugMode)
                    {
                        TLMUtils.doLog("removeAllUnwantedVehicles: models found: {0}", modelList == null ? "?!?" : modelList.Count.ToString());
                    }
                    if (modelList.Count > 0)
                    {
                        Dictionary <ushort, VehicleInfo> vehiclesToRemove = new Dictionary <ushort, VehicleInfo>();
                        for (int i = 0; i < tl.CountVehicles(lineId); i++)
                        {
                            var vehicle = tl.GetVehicle(i);
                            if (vehicle != 0)
                            {
                                VehicleInfo info2 = instance3.m_vehicles.m_buffer[(int)vehicle].Info;
                                if (!modelList.Contains(info2.name))
                                {
                                    vehiclesToRemove[vehicle] = info2;
                                }
                            }
                        }

                        foreach (var item in vehiclesToRemove)
                        {
                            item.Value.m_vehicleAI.SetTransportLine(item.Key, ref instance3.m_vehicles.m_buffer[item.Key], 0);
                        }
                    }
                }
            }
        }
示例#10
0
 private void OnNextStopClick(UIComponent component, UIMouseEventParameter eventParam)
 {
     this.ChangeInstanceID(this.m_InstanceID, new InstanceID()
     {
         NetNode = TransportLine.GetNextStop(this.m_InstanceID.NetNode)
     });
 }
        // code from https://github.com/justacid/Skylines-ExtendedPublicTransport/blob/master/ExtendedPublicTransportUI/TransportUtil.cs
        private int GetTripsSaved(TransportLine line)
        {
            // formula lifted straight from decompiled source of PublicTransportWorldInfoPanel
            // just slightly deobfuscated
            var residents = line.m_passengers.m_residentPassengers.m_averageCount;
            var tourists = line.m_passengers.m_touristPassengers.m_averageCount;
            var teens = line.m_passengers.m_teenPassengers.m_averageCount;
            var young = line.m_passengers.m_youngPassengers.m_averageCount;
            var adult = line.m_passengers.m_adultPassengers.m_averageCount;
            var senior = line.m_passengers.m_seniorPassengers.m_averageCount;
            var carOwners = line.m_passengers.m_carOwningPassengers.m_averageCount;

            uint result = 0;
            if (residents + tourists != 0)
            {
                result = teens*5 +
                         young*((15*residents + 20*tourists + ((residents + tourists)/2))/(residents + tourists)) +
                         adult*((20*residents + 20*tourists + ((residents + tourists)/2))/(residents + tourists)) +
                         senior*((10*residents + 20*tourists + ((residents + tourists)/2))/(residents + tourists));
            }

            int tripsSaved = 0;
            if (result != 0)
            {
                var tmp = (carOwners*10000L + result/2) / result;
                tripsSaved = Mathf.Clamp((int)tmp, 0, 100);
            }

            return tripsSaved;
        }
        public Color AutoColor(ushort i, bool ignoreRandomIfSet = true, bool ignoreAnyIfSet = false)
        {
            TransportLine t = tm.m_lines.m_buffer[(int)i];

            try
            {
                var tsd = TransportSystemDefinition.getDefinitionForLine(i);
                if (tsd == default(TransportSystemDefinition) || (((t.m_flags & TransportLine.Flags.CustomColor) > 0) && ignoreAnyIfSet))
                {
                    return(Color.clear);
                }
                TLMCW.ConfigIndex transportType = tsd.toConfigIndex();
                Color             c             = TLMUtils.CalculateAutoColor(t.m_lineNumber, transportType, ((t.m_flags & TransportLine.Flags.CustomColor) > 0) && ignoreRandomIfSet, true);
                if (c.a == 1)
                {
                    TLMLineUtils.setLineColor(i, c);
                }
                //TLMUtils.doLog("Colocada a cor {0} na linha {1} ({3} {2})", c, i, t.m_lineNumber, t.Info.m_transportType);
                return(c);
            }
            catch (Exception e)
            {
                TLMUtils.doErrorLog("ERRO!!!!! " + e.Message);
                TLMCW.setCurrentConfigBool(TLMCW.ConfigIndex.AUTO_COLOR_ENABLED, false);
                return(Color.clear);
            }
        }
示例#13
0
        public void closeLineInfo(UIComponent component, UIMouseEventParameter eventParam)
        {
            TransportLine t = m_controller.tm.m_lines.m_buffer[(int)m_lineIdSelecionado.TransportLine];

            Hide();
            m_controller.defaultListingLinesPanel.Show();
            TLMPublicTransportDetailPanel.instance.SetActiveTab(Array.IndexOf(TLMPublicTransportDetailPanel.tabSystemOrder, TLMCW.getConfigIndexForTransportInfo(t.Info)));
        }
示例#14
0
 private static bool IsValid(ref TransportLine line)
 {
     if ((line.m_flags & TransportLine.Flags.Complete) != TransportLine.Flags.None)
     {
         return((line.m_flags & TransportLine.Flags.Temporary) == TransportLine.Flags.None);
     }
     return(false);
 }
示例#15
0
        //based off code in the SimulationStep of TransportLine
        public static int CountLineActiveVehicles(ushort lineID, out int allVehicles, Action <Int32> callback = null)
        {
            TransportLine thisLine       = TransportManager.instance.m_lines.m_buffer[lineID];
            int           activeVehicles = 0;

            allVehicles = 0;
            //this part is directly taken from beginning of vanilla SimulationStep method (except for marked part)

            if (thisLine.Complete)
            {
                int num2 = 0;
                int num3 = 0;
                if ((int)thisLine.m_vehicles != 0)
                {
                    VehicleManager instance3 = Singleton <VehicleManager> .instance;
                    ushort         num4      = thisLine.m_vehicles;
                    int            num5      = 0;
                    while ((int)num4 != 0)
                    {
                        ushort nextLineVehicle = instance3.m_vehicles.m_buffer[(int)num4].m_nextLineVehicle;
                        ++num2;
                        if ((instance3.m_vehicles.m_buffer[(int)num4].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))
                        {
                            //begin mod(+): callback
                            callback?.Invoke(num4);
                            //end mod
                            ++num3;
                        }

                        num4 = nextLineVehicle;
                        if (++num5 > CachedVehicleData.MaxVehicleCount)
                        {
                            CODebugBase <LogChannel> .Error(LogChannel.Core,
                                                            "Invalid list detected!\n" + System.Environment.StackTrace);

                            break;
                        }
                    }
                }

                //end of vanilla part
                activeVehicles = num3;
                allVehicles    = num2;
            }

            return(activeVehicles);
        }
示例#16
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);
        }
        private bool ArriveAtTarget(ushort vehicleID, ref Vehicle data)
        {
            if ((int)data.m_targetBuilding == 0 || (data.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))
            {
                Singleton <VehicleManager> .instance.ReleaseVehicle(vehicleID);

                return(true);
            }
            ushort targetBuilding = data.m_targetBuilding;
            ushort nextStop       = 0;

            if ((int)data.m_transportLine != 0)
            {
                nextStop = TransportLine.GetNextStop(data.m_targetBuilding);
            }
            else if ((data.m_flags & (Vehicle.Flags.Importing | Vehicle.Flags.Exporting)) != ~(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))
            {
                nextStop = TransportLine.GetNextStop(data.m_targetBuilding);
                Vector3 lastFramePosition = data.GetLastFramePosition();
                byte    max;
                if ((double)Mathf.Max(Mathf.Abs(lastFramePosition.x), Mathf.Abs(lastFramePosition.z)) > 4800.0 && PanelExtenderLine.CountWaitingPassengers(targetBuilding, nextStop, out max) == 0)
                {
                    nextStop = (ushort)0;
                }
            }
            ushort transferSize1 = data.m_transferSize;

            PassengerShipAIMod.UnloadPassengers(data.Info.m_vehicleAI as PassengerShipAI, vehicleID, ref data, targetBuilding, nextStop);
            ushort num1 = (ushort)((uint)transferSize1 - (uint)data.m_transferSize);

            VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].LastStopGonePassengers = (int)num1;
            VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].CurrentStop            = targetBuilding;
            NetManagerMod.m_cachedNodeData[(int)targetBuilding].PassengersOut           += (int)num1;
            if ((int)nextStop == 0)
            {
                data.m_waitCounter = (byte)0;
                data.m_flags      |= Vehicle.Flags.WaitingLoading;
            }
            else
            {
                data.m_targetBuilding = nextStop;
                if (!this.StartPathFind(vehicleID, ref data))
                {
                    return(true);
                }
                ushort transferSize2 = data.m_transferSize;
                PassengerShipAIMod.LoadPassengers(data.Info.m_vehicleAI as PassengerShipAI, vehicleID, ref data, targetBuilding, nextStop);
                ushort num2        = (ushort)((uint)data.m_transferSize - (uint)transferSize2);
                int    ticketPrice = data.Info.m_vehicleAI.GetTicketPrice(vehicleID, ref data);
                VehicleManagerMod.m_cachedVehicleData[(int)vehicleID].Add((int)num2, ticketPrice);
                NetManagerMod.m_cachedNodeData[(int)targetBuilding].PassengersIn += (int)num2;
                data.m_flags      &= 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.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;
                data.m_flags      |= Vehicle.Flags.Stopped;
                data.m_waitCounter = (byte)0;
            }
            return(false);
        }
 private void updateVehiclePosition(UILabel vehicleLabel)
 {
     try
     {
         DraggableVehicleInfo dvi = vehicleLabel.GetComponentInChildren <DraggableVehicleInfo>();
         if (dvi.isDragging)
         {
             return;
         }
         ushort vehicleId    = dvi.vehicleId;
         ushort stopId       = Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_targetBuilding;
         var    labelStation = residentCounters[Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_targetBuilding];
         float  destX        = stationOffsetX[stopId] - labelStation.width;
         if (Singleton <TransportManager> .instance.m_lines.m_buffer[Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_transportLine].GetStop(0) == stopId && (Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_flags & Vehicle.Flags.Stopped) != 0)
         {
             destX = stationOffsetX[TransportLine.GetPrevStop(stopId)];
         }
         float yOffset        = vehicleYbaseOffset;
         int   busesOnStation = vehiclesOnStation.ContainsKey(stopId) ? vehiclesOnStation[stopId] : 0;
         if ((Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_flags & Vehicle.Flags.Stopped) != 0)
         {
             ushort prevStop = TransportLine.GetPrevStop(stopId);
             destX         -= labelStation.width / 2;
             busesOnStation = Math.Max(busesOnStation, vehiclesOnStation.ContainsKey(prevStop) ? vehiclesOnStation[prevStop] : 0);
             vehiclesOnStation[prevStop] = busesOnStation + 1;
         }
         else if ((Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_flags & Vehicle.Flags.Arriving) != 0)
         {
             destX += labelStation.width / 4;
             ushort nextStop = TransportLine.GetNextStop(stopId);
             busesOnStation = Math.Max(busesOnStation, vehiclesOnStation.ContainsKey(nextStop) ? vehiclesOnStation[nextStop] : 0);
             vehiclesOnStation[nextStop] = busesOnStation + 1;
         }
         else if ((Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_flags & Vehicle.Flags.Leaving) != 0)
         {
             destX -= labelStation.width / 4;
             ushort prevStop = TransportLine.GetPrevStop(stopId);
             busesOnStation = Math.Max(busesOnStation, vehiclesOnStation.ContainsKey(prevStop) ? vehiclesOnStation[prevStop] : 0);
             vehiclesOnStation[prevStop] = busesOnStation + 1;
         }
         else
         {
             ushort prevStop = TransportLine.GetPrevStop(stopId);
             busesOnStation = Math.Max(busesOnStation, vehiclesOnStation.ContainsKey(prevStop) ? vehiclesOnStation[prevStop] : 0);
         }
         yOffset = vehicleYbaseOffset + busesOnStation * vehicleYoffsetIncrement;
         vehiclesOnStation[stopId] = busesOnStation + 1;
         vehicleLabel.position     = new Vector3(destX, yOffset);
     }
     catch (Exception e)
     {
         TLMUtils.doLog("ERROR UPDATING VEHICLE!!!");
         TLMUtils.doErrorLog(e.ToString());
         //redrawLine();
     }
 }
示例#19
0
        public static bool StartTransfer(DepotAI __instance, ushort buildingID, ref Building data, TransferManager.TransferReason reason, TransferManager.TransferOffer offer)
        {
            if (!managedReasons.Contains(reason) || offer.TransportLine == 0)
            {
                return(true);
            }

            TLMUtils.doLog("START TRANSFER!!!!!!!!");
            TransportInfo m_transportInfo = __instance.m_transportInfo;
            BuildingInfo  m_info          = __instance.m_info;

            if (TLMSingleton.instance != null && TLMSingleton.debugMode)
            {
                TLMUtils.doLog("m_info {0} | m_transportInfo {1} | Line: {2}", m_info.name, m_transportInfo.name, offer.TransportLine);
            }


            if (reason == m_transportInfo.m_vehicleReason || (__instance.m_secondaryTransportInfo != null && reason == __instance.m_secondaryTransportInfo.m_vehicleReason))
            {
                VehicleInfo randomVehicleInfo = null;
                var         tsd = TransportSystemDefinition.from(__instance.m_transportInfo);

                TransportLine tl = Singleton <TransportManager> .instance.m_lines.m_buffer[offer.TransportLine];
                TransportInfo.TransportType t = tl.Info.m_transportType;

                if (TLMLineUtils.hasPrefix(ref tl))
                {
                    setRandomBuildingByPrefix(tsd, tl.m_lineNumber / 1000u, ref buildingID);
                }
                else
                {
                    setRandomBuildingByPrefix(tsd, 0, ref buildingID);
                }

                TLMUtils.doLog("randomVehicleInfo");
                randomVehicleInfo = doModelDraw(offer.TransportLine);
                if (randomVehicleInfo == null)
                {
                    randomVehicleInfo = Singleton <VehicleManager> .instance.GetRandomVehicleInfo(ref Singleton <SimulationManager> .instance.m_randomizer, m_info.m_class.m_service, m_info.m_class.m_subService, m_info.m_class.m_level);
                }
                if (randomVehicleInfo != null)
                {
                    TLMUtils.doLog("randomVehicleInfo != null");
                    Array16 <Vehicle> vehicles = Singleton <VehicleManager> .instance.m_vehicles;
                    __instance.CalculateSpawnPosition(buildingID, ref Singleton <BuildingManager> .instance.m_buildings.m_buffer[buildingID], ref Singleton <SimulationManager> .instance.m_randomizer, randomVehicleInfo, out Vector3 position, out Vector3 vector);
                    if (Singleton <VehicleManager> .instance.CreateVehicle(out ushort vehicleID, ref Singleton <SimulationManager> .instance.m_randomizer, randomVehicleInfo, position, reason, false, true))
                    {
                        TLMUtils.doLog("CreatedVehicle!!!");
                        randomVehicleInfo.m_vehicleAI.SetSource(vehicleID, ref vehicles.m_buffer[(int)vehicleID], buildingID);
                        randomVehicleInfo.m_vehicleAI.StartTransfer(vehicleID, ref vehicles.m_buffer[(int)vehicleID], reason, offer);
                    }
                    return(false);
                }
            }
            return(true);
        }
        public IHttpActionResult GetTransportLine(string id)
        {
            TransportLine transportLine = unitOfWork.TransportLine.Get(id);

            if (transportLine == null)
            {
                return(NotFound());
            }

            return(Ok(transportLine));
        }
        private IEnumerable <KeyValuePair <ushort, int> > GetPositionPopularities()
        {
            ushort         nextStop         = TransportLine.GetNextStop(this.stopId);
            CitizenManager citizenManager   = Singleton <CitizenManager> .instance;
            NetManager     netManager       = Singleton <NetManager> .instance;
            float          num1             = 64f;
            Vector3        stopPosition     = netManager.m_nodes.m_buffer[this.stopId].m_position;
            Vector3        nextStopPosition = netManager.m_nodes.m_buffer[nextStop].m_position;
            int            num2             = Mathf.Max((int)(((double)stopPosition.x - (double)num1) / 8.0 + 1080.0), 0);
            int            num3             = Mathf.Max((int)(((double)stopPosition.z - (double)num1) / 8.0 + 1080.0), 0);
            int            num4             = Mathf.Min((int)(((double)stopPosition.x + (double)num1) / 8.0 + 1080.0), 2159);
            int            num5             = Mathf.Min((int)(((double)stopPosition.z + (double)num1) / 8.0 + 1080.0), 2159);

            Dictionary <ushort, int> popularities = new Dictionary <ushort, int>();

            for (int index1 = num3; index1 <= num5; ++index1)
            {
                for (int index2 = num2; index2 <= num4; ++index2)
                {
                    ushort citizenInstanceId = citizenManager.m_citizenGrid[index1 * 2160 + index2];
                    while (citizenInstanceId != (ushort)0)
                    {
                        CitizenInstance citizen = citizenManager.m_instances.m_buffer[(int)citizenInstanceId];

                        ushort nextGridInstance = citizen.m_nextGridInstance;

                        if (
                            (citizen.m_flags & CitizenInstance.Flags.WaitingTransport) != CitizenInstance.Flags.None &&
                            (double)Vector3.SqrMagnitude((Vector3)citizen.m_targetPos - stopPosition) < (double)num1 * (double)num1 &&
                            citizen.Info.m_citizenAI.TransportArriveAtSource(citizenInstanceId, ref citizen, stopPosition, nextStopPosition)
                            )
                        {
                            if (popularities.ContainsKey(citizen.m_targetBuilding))
                            {
                                int previous = popularities[citizen.m_targetBuilding];

                                popularities.Remove(citizen.m_targetBuilding);

                                popularities.Add(citizen.m_targetBuilding, previous + 1);
                            }
                            else
                            {
                                popularities.Add(citizen.m_targetBuilding, 1);
                            }
                        }

                        citizenInstanceId = nextGridInstance;
                    }
                }
            }

            return(popularities.OrderByDescending(key => key.Value));
        }
 public Color32 GetColor(TransportLine transportLine)
 {
     switch (transportLine.Info.m_transportType)
     {
         case TransportInfo.TransportType.Bus:
             return CategorisedColor.GetPaleColor(null);
         case TransportInfo.TransportType.Metro:
             return CategorisedColor.GetBrightColor(null);
         default:
             return CategorisedColor.GetDarkColor(null);
     }
 }
 public Color32 GetColor(TransportLine transportLine, System.Collections.Generic.List<Color32> usedColors)
 {
     switch (transportLine.Info.m_transportType)
     {
         case TransportInfo.TransportType.Bus:
             return CategorisedColor.GetPaleColor(usedColors);
         case TransportInfo.TransportType.Metro:
             return CategorisedColor.GetBrightColor(usedColors);
         default:
             return CategorisedColor.GetDarkColor(usedColors);
     }
 }
示例#24
0
        public static void RemoveAllUnwantedVehicles()
        {
            for (ushort lineId = 1; lineId < Singleton <TransportManager> .instance.m_lines.m_size; lineId++)
            {
                if ((Singleton <TransportManager> .instance.m_lines.m_buffer[lineId].m_flags & TransportLine.Flags.Created) != TransportLine.Flags.None)
                {
                    uint idx;
                    IAssetSelectorExtension extension;
                    if (TLMTransportLineExtension.instance.IsUsingCustomConfig(lineId))
                    {
                        idx       = lineId;
                        extension = TLMTransportLineExtension.instance;
                    }
                    else
                    {
                        idx = TLMLineUtils.getPrefix(lineId);
                        var def = TransportSystemDefinition.from(lineId);
                        extension = def.GetTransportExtension();
                    }

                    TransportLine  tl        = Singleton <TransportManager> .instance.m_lines.m_buffer[lineId];
                    var            modelList = extension.GetAssetList(idx);
                    VehicleManager vm        = Singleton <VehicleManager> .instance;
                    VehicleInfo    info      = vm.m_vehicles.m_buffer[Singleton <TransportManager> .instance.m_lines.m_buffer[lineId].GetVehicle(0)].Info;

                    if (TLMSingleton.instance != null && TLMSingleton.debugMode)
                    {
                        TLMUtils.doLog("removeAllUnwantedVehicles: models found: {0}", modelList == null ? "?!?" : modelList.Count.ToString());
                    }

                    if (modelList.Count > 0)
                    {
                        Dictionary <ushort, VehicleInfo> vehiclesToRemove = new Dictionary <ushort, VehicleInfo>();
                        for (int i = 0; i < tl.CountVehicles(lineId); i++)
                        {
                            var vehicle = tl.GetVehicle(i);
                            if (vehicle != 0)
                            {
                                VehicleInfo info2 = vm.m_vehicles.m_buffer[(int)vehicle].Info;
                                if (!modelList.Contains(info2.name))
                                {
                                    vehiclesToRemove[vehicle] = info2;
                                }
                            }
                        }
                        foreach (var item in vehiclesToRemove)
                        {
                            item.Value.m_vehicleAI.SetTransportLine(item.Key, ref vm.m_vehicles.m_buffer[item.Key], 0);
                        }
                    }
                }
            }
        }
        private IEnumerator RemoveStop(ushort lineId, int stopIndex, Action onSuccess)
        {
            TransportLine line    = TransportManager.instance.m_lines.m_buffer[lineId];
            bool          success = line.RemoveStop(lineId, stopIndex);

            if (success)
            {
                onSuccess();
            }

            yield return(null);
        }
 public string GetName(TransportLine transportLine)
 {
     switch (transportLine.Info.m_transportType)
     {
     case TransportInfo.TransportType.Bus:
         return GetBusLineName (transportLine);
     case TransportInfo.TransportType.Metro:
         return GetMetroLineName (transportLine);
     default:
         return GetTrainLineName (transportLine);
     }
 }
示例#27
0
        public static void AfterCreateLine(bool __result, ushort lineID, BuildingInfo info)
        {
            if (lineID == 0)
            {
                return;
            }
            TransportLine tl = TransportManager.instance.m_lines.m_buffer[lineID];

            if (__result && TLMBasicTabControllerLineList <V> .exists && (Singleton <V> .instance?.GetTSD().isFromSystem(tl) ?? false))
            {
                TLMBasicTabControllerLineList <V> .instance.isUpdated = false;
            }
        }
        public void run()
        {
            for (int i = 0; i < TransportManager.MAX_LINE_COUNT; ++i)
            {
                /*if (TransportManager.instance.m_lines.m_buffer[i].Info.m_transportType != TransportInfo.TransportType.Tram) {
                 *      continue;
                 * }*/
                //Log.Message("Transport line " + i + ":");
                if ((TransportManager.instance.m_lines.m_buffer[i].m_flags & TransportLine.Flags.Created) == TransportLine.Flags.None)
                {
                    //Log.Message("\tTransport line is not created.");
                }
                //Log.Message("\tFlags: " + TransportManager.instance.m_lines.m_buffer[i].m_flags + ", cat: " + TransportManager.instance.m_lines.m_buffer[i].Info.category + ", type: " + TransportManager.instance.m_lines.m_buffer[i].Info.m_transportType + ", name: " + TransportManager.instance.GetLineName((ushort)i));
                ushort  firstStopNodeId = TransportManager.instance.m_lines.m_buffer[i].m_stops;
                ushort  stopNodeId      = firstStopNodeId;
                Vector3 lastNodePos     = Vector3.zero;
                int     index           = 1;
                while (stopNodeId != 0)
                {
                    Vector3 pos = NetManager.instance.m_nodes.m_buffer[stopNodeId].m_position;
                    if (NetManager.instance.m_nodes.m_buffer[stopNodeId].m_problems != Notification.Problem.None)
                    {
                        Log.Message("\tStop node #" + index + " -- " + stopNodeId + ": Flags: " + NetManager.instance.m_nodes.m_buffer[stopNodeId].m_flags + ", Transport line: " + NetManager.instance.m_nodes.m_buffer[stopNodeId].m_transportLine + ", Problems: " + NetManager.instance.m_nodes.m_buffer[stopNodeId].m_problems + " Pos: " + pos + ", Dist. to lat pos: " + (lastNodePos - pos).magnitude);
                        Log.Message("\tFlags: " + TransportManager.instance.m_lines.m_buffer[i].m_flags + ", cat: " + TransportManager.instance.m_lines.m_buffer[i].Info.category + ", type: " + TransportManager.instance.m_lines.m_buffer[i].Info.m_transportType + ", name: " + TransportManager.instance.GetLineName((ushort)i));
                    }
                    lastNodePos = pos;

                    ushort nextSegment = TransportLine.GetNextSegment(stopNodeId);
                    if (nextSegment != 0)
                    {
                        stopNodeId = NetManager.instance.m_segments.m_buffer[(int)nextSegment].m_endNode;
                    }
                    else
                    {
                        break;
                    }
                    ++index;

                    if (stopNodeId == firstStopNodeId)
                    {
                        break;
                    }

                    if (index > 10000)
                    {
                        Log.Message("Too many iterations!");
                        break;
                    }
                }
            }
        }
示例#29
0
        private void updateVehiclePosition(ushort vehicleId, UILabel vehicleLabel)
        {
            try
            {
                ushort stopId       = Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_targetBuilding;
                var    labelStation = residentCounters[Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_targetBuilding];
                float  destX        = stationOffsetX[stopId] - labelStation.width / 4 * 3;
                if (Singleton <TransportManager> .instance.m_lines.m_buffer[Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_transportLine].GetStop(0) == stopId && (Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_flags & Vehicle.Flags.Stopped) != 0)
                {
                    destX = stationOffsetX[TransportLine.GetPrevStop(stopId)] + labelStation.width / 4;
                }
                float yOffset        = vehicleYbaseOffset;
                int   busesOnStation = vehiclesOnStation.ContainsKey(stopId) ? vehiclesOnStation[stopId] : 0;
                if ((Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_flags & Vehicle.Flags.Stopped) != 0)
                {
                    ushort prevStop = TransportLine.GetPrevStop(stopId);
                    destX          = stationOffsetX[prevStop] - labelStation.width / 4;
                    busesOnStation = Math.Max(busesOnStation, vehiclesOnStation.ContainsKey(prevStop) ? vehiclesOnStation[prevStop] : 0);
                    vehiclesOnStation[prevStop] = busesOnStation + 1;
                }
                else if ((Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_flags & Vehicle.Flags.Arriving) != 0)
                {
                    destX += labelStation.width / 4;
                    ushort nextStop = TransportLine.GetNextStop(stopId);
                    busesOnStation = Math.Max(busesOnStation, vehiclesOnStation.ContainsKey(nextStop) ? vehiclesOnStation[nextStop] : 0);
                    vehiclesOnStation[nextStop] = busesOnStation + 1;
                }
                else if ((Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_flags & Vehicle.Flags.Leaving) != 0)
                {
                    destX -= labelStation.width / 4;
                    ushort prevStop = TransportLine.GetPrevStop(stopId);
                    busesOnStation = Math.Max(busesOnStation, vehiclesOnStation.ContainsKey(prevStop) ? vehiclesOnStation[prevStop] : 0);
                    vehiclesOnStation[prevStop] = busesOnStation + 1;
                }
                else
                {
                    ushort prevStop = TransportLine.GetPrevStop(stopId);
                    busesOnStation = Math.Max(busesOnStation, vehiclesOnStation.ContainsKey(prevStop) ? vehiclesOnStation[prevStop] : 0);
                }
                yOffset = vehicleYbaseOffset + busesOnStation * vehicleYoffsetIncrement;
                vehiclesOnStation[stopId] = busesOnStation + 1;
                vehicleLabel.position     = new Vector3(destX, yOffset);
            }
#pragma warning disable CS0168 // Variable is declared but never used
            catch (Exception e)
#pragma warning restore CS0168 // Variable is declared but never used
            {
                TLMUtils.doLog("ERROR UPDATING VEHICLE!!!");
                redrawLine();
            }
        }
示例#30
0
        // if true, then this mod will intervene in handling instant departures etc.
        public static bool NowIsEligibleForInstantDeparture(ushort vehicleID, ref Vehicle vehicleData)
        {
            TransportManager instance        = Singleton <TransportManager> .instance;
            ushort           transportLineID = vehicleData.m_transportLine;
            // the semantics! they must be clear! dont try to cheat with "first is index=1 and current=next" again! it hurts devops!
            ushort firstStop   = instance.m_lines.m_buffer[transportLineID].GetStop(0);
            ushort currentStop = TransportLine.GetPrevStop(vehicleData.m_targetBuilding);

            // note:
            // if I somehow cannot determine where I am at or where the first stop is at, always unbunch.
            // this may be related to some random errors that I get about "vehicles not leaving stop",
            // where perhaps some vehicle states messed up.
            return(currentStop == 0 || firstStop == 0 || currentStop != firstStop);
        }
        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 Color32 GetColor(TransportLine transportLine, System.Collections.Generic.List<Color32> usedColors)
 {
     switch (transportLine.Info.m_transportType)
     {
         case TransportInfo.TransportType.Bus:
             return RandomColor.GetColor(ColorFamily.Blue, usedColors);
         case TransportInfo.TransportType.Metro:
             return RandomColor.GetColor(ColorFamily.Green, usedColors);
         case TransportInfo.TransportType.Train:
             return RandomColor.GetColor(ColorFamily.Orange, usedColors);
         default:
             return RandomColor.GetColor(ColorFamily.Any, usedColors);
     }
 }
示例#33
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);
        }
        public MapTransportLine(Color32 color, bool day, bool night, ushort lineId)
        {
            TransportLine t = Singleton <TransportManager> .instance.m_lines.m_buffer[lineId];

            this.lineName = Singleton <TransportManager> .instance.GetLineName(lineId);

            this.lineStringIdentifier = TLMLineUtils.getLineStringId(lineId);
            transportType             = t.Info.m_transportType;
            stations    = new List <Station>();
            lineColor   = color;
            activeDay   = day;
            activeNight = night;
            this.lineId = lineId;
        }
        private bool GetStopIndex(TransportLine line, int stopCount, ushort stopId, out int stopIndex)
        {
            for (int i = 0; i < stopCount; i++)
            {
                if (stopId == line.GetStop(i))
                {
                    stopIndex = i;
                    return(true);
                }
            }

            stopIndex = -1;
            return(false);
        }
 public Color32 GetColor(TransportLine transportLine)
 {
     switch (transportLine.Info.m_transportType)
     {
         case TransportInfo.TransportType.Bus:
             return RandomColor.GetColor(ColorFamily.Blue);
         case TransportInfo.TransportType.Metro:
             return RandomColor.GetColor(ColorFamily.Green);
         case TransportInfo.TransportType.Train:
             return RandomColor.GetColor(ColorFamily.Orange);
         default:
             return RandomColor.GetColor(ColorFamily.Any);
     }
 }
        private void RecalculateSharedStopSegments()
        {
            foreach (TransportLine line in Singleton <TransportManager> .instance.m_lines.m_buffer)
            {
                if (line.Info.m_class.m_subService != ItemClass.SubService.PublicTransportBus && line.Info.m_class.m_subService != ItemClass.SubService.PublicTransportTram &&
                    line.Info.m_class.m_subService != ItemClass.SubService.PublicTransportTrolleybus && line.Info.m_class.name != "Sightseeing Bus Line")
                {
                    continue;
                }

                ushort lineID = Singleton <NetManager> .instance.m_nodes.m_buffer[line.m_stops].m_transportLine;

                if (lineID == 0)
                {
                    continue;
                }
                ushort stops = line.m_stops;
                if (stops == 0)
                {
                    continue;
                }
                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)
                    {
                        Singleton <SharedStopsTool> .instance.AddSharedStop(segment, lineID, lane);

                        NetSegment segData = Singleton <NetManager> .instance.m_segments.m_buffer[segment];
                        if (segData.Info.m_netAI is RoadAI roadAI)
                        {
                            roadAI.UpdateSegmentFlags(segment, ref Singleton <NetManager> .instance.m_segments.m_buffer[segment]);
                        }
                        else if (segData.Info.m_netAI is RoadBridgeAI roadBridgeAI)
                        {
                            roadBridgeAI.UpdateSegmentStopFlags(segment, ref Singleton <NetManager> .instance.m_segments.m_buffer[segment]);
                        }
                    }
                    if (stops == line.m_stops)
                    {
                        break;
                    }
                }
                Log.Debug($"Stops found {sharedStopSegments.Count}");
            }
        }
 private List<Vehicle> GetLineVehicles(TransportLine line)
 {
     List<Vehicle> lineVehicles = new List<Vehicle>();
     if (line.m_vehicles != 0)
     {
         VehicleManager instance = Singleton<VehicleManager>.instance;
         ushort currentVehicle = line.m_vehicles;
         int index = 0;
         while (currentVehicle != 0)
         {
             lineVehicles.Add(instance.m_vehicles.m_buffer[(int)currentVehicle]);
             ushort nextLineVehicle = instance.m_vehicles.m_buffer[(int)currentVehicle].m_nextLineVehicle;
             currentVehicle = nextLineVehicle;
             if (++index > VehicleManager.MAX_VEHICLE_COUNT)
             {
                 break;
             }
         }
     }
     return lineVehicles;
 }
        /*
         * Bus line numbers are based on district:
         *
         * Given districts "Hamilton Park", "Ivy Square", "King District" in a city called "Springwood", bus line names look like:
         *
         * HP43 Local
         * 22 Hamilton Park
         * 345 Ivy to King Express
         * 9 Hamilton, Ivy and King
         * 6 Springwood Express
         */
        private string GetBusLineName(TransportLine transportLine)
        {
            var districtNames = new List<string>();
            bool nonDistrict;
            int districtCount;
            int stopCount;
            AnalyzeLine(transportLine, districtNames, out districtCount, out stopCount, out nonDistrict);
            string prefix = null;
            int number;
            string name = null;
            string suffix = null;
            var existingNames = GetExistingNames();
            var existingNumbers = GetNumbers(existingNames);

            // Work out the bus number (and prefix)
            if (!nonDistrict && districtCount == 1)
            {
                /* District Initials */
                prefix = GetInitials(districtNames[0]);
                number = 0;
                string prefixed_number;
                do
                {
                    number++;
                    prefixed_number = String.Format("{0}{1}", prefix, number);
                } while (existingNumbers.Contains(prefixed_number));
            }
            else
            {
                int step;
                if (stopCount < 15)
                {
                    number = Random.Range(100, 900);
                    step = Random.Range(7, 20);
                }
                else if (stopCount < 30)
                {
                    number = Random.Range(20, 100);
                    step = Random.Range(2, 10);
                }
                else
                {
                    number = Random.Range(1, 20);
                    step = Random.Range(1, 4);
                }
                while (existingNumbers.Contains(number.ToString()))
                {
                    number += step;
                }
            }

            // Work out the bus name
            if (districtCount == 1)
            {
                name = nonDistrict ? districtNames[0] : "Local";
            }

            if (districtCount == 2)
            {
                name = String.Format("{0} to {1}", FirstWord(districtNames[0]), FirstWord(districtNames[1]));
            }

            if (districtCount == 3)
            {
                name = String.Format("{0}, {1} and {2}",
                    FirstWord(districtNames[0]), FirstWord(districtNames[1]), FirstWord(districtNames[2]));
            }

            if (districtCount == 0 || districtCount > 3)
            {
                var theSimulationManager = Singleton<SimulationManager>.instance;
                name = theSimulationManager.m_metaData.m_CityName;
            }

            if (stopCount <= 4)
            {
                suffix = "Express";
            }

            string lineName = String.Format("{0}{1}", prefix ?? "", number);
            if (!String.IsNullOrEmpty(name))
            {
                lineName += " " + name;
            }
            if (!String.IsNullOrEmpty(suffix))
            {
                lineName += " " + suffix;
            }
            return lineName;
        }
        private void AnalyzeLine(TransportLine transportLine, List<string> districtNames, out int districtCount, out int stopCount, out bool nonDistrict)
        {
            var theNetManager = Singleton<NetManager>.instance;
            var theDistrictManager = Singleton<DistrictManager>.instance;
            var stop = transportLine.m_stops;
            var firstStop = stop;
            stopCount = 0;
            districtCount = 0;
            nonDistrict = false;
            do
            {
                var stopInfo = theNetManager.m_nodes.m_buffer[stop];
                var district = theDistrictManager.GetDistrict(stopInfo.m_position);

                if (district == 0)
                {
                    nonDistrict = true;
                }
                else
                {
                    var districtName = theDistrictManager.GetDistrictName(district).Trim();
                    if (!districtNames.Contains(districtName))
                    {
                        districtNames.Add(districtName);
                        districtCount++;
                    }
                }

                stop = TransportLine.GetNextStop (stop);
                stopCount++;
            } while (stopCount < 25 && stop != firstStop);
        }
        /*
         * Metro line names are based on district, with generic names from a list thrown in.
         *
         * Given districts "Manor Park", "Ivy Square", "Hickory District", metro line names look like:
         *
         * Manor Line
         * Ivy Loop Line
         * Hickory & Ivy Line
         * Hickory, Manor & Ivy Line
         * Foxtrot Line
         *
         * There's also some attempt to "Bakerlooify" line names.  No idea how well that will work.
         */
        private string GetMetroLineName(TransportLine transportLine)
        {
            var districtNames = new List<string>();
            bool nonDistrict;
            int districtCount;
            int stopCount;
            AnalyzeLine(transportLine, districtNames, out districtCount, out stopCount, out nonDistrict);
            string name = null;
            var districtFirstNames = districtNames.Select(FirstWord).ToList();
            var existingNames = GetExistingNames();
            int count = 0;

            if (districtCount == 1)
            {
                name = districtNames[0];
            }
            else if (districtCount == 2)
            {
                if (districtFirstNames[0].Equals(districtFirstNames[1]))
                {
                    name = districtFirstNames[0];
                }
                else
                {
                    name = TryBakerlooify(districtFirstNames[0], districtFirstNames[1]) ??
                        TryBakerlooify(districtFirstNames[1], districtFirstNames[0]) ??
                        String.Format("{0} & {1}", districtFirstNames[0], districtFirstNames[1]);
                }
            }
            else if (districtCount >= 3)
            {
                int totalLength = districtFirstNames.Sum(d => d.Length);
                if (totalLength < 20)
                {
                    var districtFirstNamesArray = districtFirstNames.ToArray();
                    name = String.Format("{0} & {1}",
                        String.Join(", ", districtFirstNamesArray, 0, districtFirstNamesArray.Length - 1),
                        districtFirstNamesArray[districtFirstNamesArray.Length - 1]);
                }
            }

            var lineName = name == null ? "Metro Line" : String.Format("{0} Line", name);
            while (name == null || existingNames.Contains(lineName))
            {
                name = GenericNames.GetGenericName(count / 2);
                lineName = String.Format("{0} Line", name);
                count++;
            }
            return lineName;
        }
 public Color32 GetColor(TransportLine transportLine)
 {
     return RandomColor.GetColor(ColorFamily.Any);
 }
 public Color32 GetColor(TransportLine transportLine, System.Collections.Generic.List<Color32> usedColors)
 {
     return RandomColor.GetColor(ColorFamily.Any, usedColors);
 }
示例#44
0
 public static bool UpdatePaths(ref TransportLine transportLine, ushort lineID)
 {
     bool flag = true;
     NetManager instance = Singleton<NetManager>.instance;
     ushort stops = transportLine.m_stops;
     ushort num = stops;
     int num2 = 0;
     while (num != 0)
     {
         ushort num3 = 0;
         for (int i = 0; i < 8; i++)
         {
             ushort segment = instance.m_nodes.m_buffer[(int)num].GetSegment(i);
             if (segment != 0 && instance.m_segments.m_buffer[(int)segment].m_startNode == num)
             {
                 TransportInfo info = transportLine.Info;
                 if (!BusTransportLineAI.UpdatePath(segment, ref instance.m_segments.m_buffer[(int)segment], info.m_netService, info.m_vehicleType, (transportLine.m_flags & TransportLine.Flags.Temporary) != TransportLine.Flags.None))
                 {
                     flag = false;
                 }
                 num3 = instance.m_segments.m_buffer[(int)segment].m_endNode;
                 break;
             }
         }
         num = num3;
         if (num == stops)
         {
             break;
         }
         if (!flag)
         {
             break;
         }
         if (++num2 >= 32768)
         {
             CODebugBase<LogChannel>.Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace);
             break;
         }
     }
     return flag;
 }
        /*
         * Train line names are based on the British designations, with some liberties taken.
         *
         * The format is AXNN Name:
         *
         * A is the number of districts the train stops at.
         * X is the first letter of the last district, or X if the train stops outside of a district.
         * NN are random digits.
         *
         * The name is based on the district names.
         */
        private string GetTrainLineName(TransportLine transportLine)
        {
            var districtNames = new List<string>();
            bool nonDistrict;
            int districtCount;
            int stopCount;
            AnalyzeLine(transportLine, districtNames, out districtCount, out stopCount, out nonDistrict);
            string ident = null;
            int number = Random.Range(1, 90);
            string name = null;
            var districtFirstNames = districtNames.Select(FirstWord).ToList();
            var existingNames = GetExistingNames();
            var existingNumbers = GetNumbers(existingNames);

            var lastDistrictName = districtNames.LastOrDefault();
            if (String.IsNullOrEmpty(lastDistrictName))
            {
                lastDistrictName = "Z";
            }

            ident = String.Format("{0}{1}", districtCount, nonDistrict ? "X" : lastDistrictName.Substring(0, 1));

            if (districtCount == 0)
            {
                var theSimulationManager = Singleton<SimulationManager>.instance;
                name = String.Format(_trains[Random.Range(0, _trains.Length)], theSimulationManager.m_metaData.m_CityName);
            }
            else if (districtCount == 1)
            {
                name = String.Format(_trains[Random.Range(0, _trains.Length)], districtNames[0]);
            }
            else if (districtCount == 2)
            {
                if (districtFirstNames[0].Equals(districtFirstNames[1]))
                {
                    name = districtFirstNames[0];
                }
                else if (stopCount == 2)
                {
                    name = String.Format("{0} {1} Shuttle", districtFirstNames[0], districtFirstNames[1]);
                }
                else if (!nonDistrict)
                {
                    name = String.Format("{0} {1} Express", districtFirstNames[0], districtFirstNames[1]);
                }
                else
                {
                    name = String.Format("{0} via {1}", districtFirstNames[0], districtFirstNames[1]);
                }
            }
            else
            {
                int totalLength = districtFirstNames.Sum(d => d.Length);
                if (totalLength < 15)
                {
                    var districtFirstNamesArray = districtFirstNames.ToArray();
                    name = String.Format("{0} and {1} via {2}",
                        String.Join(", ", districtFirstNamesArray, 0, districtFirstNamesArray.Length - 2),
                        districtFirstNamesArray[districtFirstNamesArray.Length - 1],
                        districtFirstNamesArray[districtFirstNamesArray.Length - 2]);
                }
                else
                {
                    name = String.Format(_trains[Random.Range(0, _trains.Length)], districtNames.First());
                }
            }

            var lineNumber = String.Format("{0}{1:00}", ident, number);
            while (existingNumbers.Contains(lineNumber))
            {
                number++;
                lineNumber = String.Format("{0}{1:00}", ident, number);
            }
            return String.Format("{0} {1}", lineNumber, name);
        }
 public string GetName(TransportLine transportLine)
 {
     return null;
 }
示例#47
0
        // from TransportLine
        public static bool UpdateMeshData(ref TransportLine transportLine, ushort lineID)
        {
            bool flag = true;
            int num = 0;
            int num2 = 0;
            int num3 = 0;
            float num4 = 0f;
            TransportManager instance = Singleton<TransportManager>.instance;
            NetManager instance2 = Singleton<NetManager>.instance;
            PathManager instance3 = Singleton<PathManager>.instance;
            ushort stops = transportLine.m_stops;
            ushort num5 = stops;
            int num6 = 0;
            while (num5 != 0)
            {
                ushort num7 = 0;
                for (int i = 0; i < 8; i++)
                {
                    ushort segment = instance2.m_nodes.m_buffer[(int)num5].GetSegment(i);
                    if (segment != 0 && instance2.m_segments.m_buffer[(int)segment].m_startNode == num5)
                    {
                        uint path = instance2.m_segments.m_buffer[(int)segment].m_path;
                        if (path != 0u)
                        {
                            byte pathFindFlags = instance3.m_pathUnits.m_buffer[(int)((UIntPtr)path)].m_pathFindFlags;
                            if ((pathFindFlags & 4) != 0)
                            {
                                if (!TransportLine.CalculatePathSegmentCount(path, ref num2, ref num3, ref num4))
                                {
                                    TransportInfo info = transportLine.Info;
                                    BusTransportLineAI.StartPathFind(segment, ref instance2.m_segments.m_buffer[(int)segment], info.m_netService, info.m_vehicleType, (transportLine.m_flags & TransportLine.Flags.Temporary) != TransportLine.Flags.None);
                                    flag = false;
                                }
                            }
                            else if ((pathFindFlags & 8) == 0)
                            {
                                flag = false;
                            }
                        }
                        num7 = instance2.m_segments.m_buffer[(int)segment].m_endNode;
                        break;
                    }
                }
                num++;
                num2++;
                num5 = num7;
                if (num5 == stops)
                {
                    break;
                }
                if (!flag)
                {
                    break;
                }
                if (++num6 >= 32768)
                {
                    CODebugBase<LogChannel>.Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace);
                    break;
                }
            }
            if (!flag)
            {
                return flag;
            }
            RenderGroup.MeshData meshData = new RenderGroup.MeshData();
            meshData.m_vertices = new Vector3[num2 * 8];
            meshData.m_normals = new Vector3[num2 * 8];
            meshData.m_tangents = new Vector4[num2 * 8];
            meshData.m_uvs = new Vector2[num2 * 8];
            meshData.m_uvs1 = new Vector2[num2 * 8];
            meshData.m_colors = new Color32[num2 * 8];
            meshData.m_triangles = new int[num2 * 30];
            TransportManager.LineSegment[] array = new TransportManager.LineSegment[num];
            Bezier3[] array2 = new Bezier3[num3];
            int num8 = 0;
            int num9 = 0;
            int num10 = 0;
            float lengthScale = Mathf.Ceil(num4 / 64f) / num4;
            float num11 = 0f;
            num5 = stops;
            Vector3 vector = new Vector3(100000f, 100000f, 100000f);
            Vector3 vector2 = new Vector3(-100000f, -100000f, -100000f);
            num6 = 0;
            while (num5 != 0)
            {
                ushort num12 = 0;
                for (int j = 0; j < 8; j++)
                {
                    ushort segment2 = instance2.m_nodes.m_buffer[(int)num5].GetSegment(j);
                    if (segment2 != 0 && instance2.m_segments.m_buffer[(int)segment2].m_startNode == num5)
                    {
                        uint path2 = instance2.m_segments.m_buffer[(int)segment2].m_path;
                        if (path2 != 0u && (instance3.m_pathUnits.m_buffer[(int)((UIntPtr)path2)].m_pathFindFlags & 4) != 0)
                        {
                            array[num8].m_curveStart = num10;
                            Vector3 vector3;
                            Vector3 vector4;
                            TransportLine.FillPathSegments(path2, meshData, array2, ref num9, ref num10, ref num11, lengthScale, out vector3, out vector4);
                            vector = Vector3.Min(vector, vector3);
                            vector2 = Vector3.Max(vector2, vector4);
                            array[num8].m_bounds.SetMinMax(vector3, vector4);
                            array[num8].m_curveEnd = num10;
                        }
                        num12 = instance2.m_segments.m_buffer[(int)segment2].m_endNode;
                        break;
                    }
                }
                TransportLine.FillPathNode(instance2.m_nodes.m_buffer[(int)num5].m_position, meshData, num9);
                num8++;
                num9++;
                num5 = num12;
                if (num5 == stops)
                {
                    break;
                }
                if (++num6 >= 32768)
                {
                    CODebugBase<LogChannel>.Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace);
                    break;
                }
            }
            while (!Monitor.TryEnter(instance.m_lineMeshData, SimulationManager.SYNCHRONIZE_TIMEOUT))
            {
            }
            try
            {
                instance.m_lineMeshData[(int)lineID] = meshData;
                instance.m_lineSegments[(int)lineID] = array;
                instance.m_lineCurves[(int)lineID] = array2;
                transportLine.m_bounds.SetMinMax(vector, vector2);
            }
            finally
            {
                Monitor.Exit(instance.m_lineMeshData);
            }

            return flag;
        }
示例#48
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;
        }
 public string GetName(TransportLine transportLine)
 {
     int stopCount;
     var districts = GetDistrictsForLine(transportLine, Singleton<NetManager>.instance, Singleton<DistrictManager>.instance, out stopCount);
     return BuildRandomName(transportLine.m_lineNumber, transportLine.Info.m_transportType, districts, stopCount);
 }