Beispiel #1
0
        public void SimulationStep(ushort lineID)
        {
            if (!m_initialized)
            {
                m_initialized = true;
                for (int i = 0; i < Singleton <TransportManager> .instance.m_lines.m_buffer.Length; i++)
                {
                    m_flagsLastState[i] = Singleton <TransportManager> .instance.m_lines.m_buffer[i].m_flags;
                }
            }

            var flagsChanged = (m_flagsLastState[lineID] ^ Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags);

            m_flagsLastState[lineID] = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags;

            if ((flagsChanged & TransportLine.Flags.Complete) != TransportLine.Flags.None)
            {
                if (TLMConfigWarehouse.getCurrentConfigBool(TLMConfigWarehouse.ConfigIndex.AUTO_COLOR_ENABLED))
                {
                    TLMController.instance.AutoColor(lineID);
                }

                if (TLMConfigWarehouse.getCurrentConfigBool(TLMConfigWarehouse.ConfigIndex.AUTO_NAME_ENABLED))
                {
                    TLMUtils.setLineName(lineID, TLMUtils.calculateAutoName(lineID));
                }
            }

            if (TransportLinesManagerMod.instance != null && TransportLinesManagerMod.debugMode)
            {
                TLMUtils.doLog("LTLMTransportLine SimulationStep!");
            }
            TransportInfo info = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].Info;

            TLMCW.ConfigIndex lineType = TLMCW.getDefinitionForLine(lineID).toConfigIndex();

            float defaultCostPerPassengerCapacity = TLMCW.getCostPerPassengerCapacityLine(lineType);

            if (Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].Complete)
            {
                int vehicleCount      = 0;
                int installedCapacity = 0;
                if (Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_vehicles != 0)
                {
                    VehicleManager instance  = Singleton <VehicleManager> .instance;
                    ushort         nextId    = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_vehicles;
                    int            loopCount = 0;
                    while (nextId != 0)
                    {
                        ushort nextLineVehicle = instance.m_vehicles.m_buffer[(int)nextId].m_nextLineVehicle;
                        vehicleCount++;
                        installedCapacity += TLMLineUtils.getVehicleCapacity(nextId);
                        nextId             = nextLineVehicle;
                        if (++loopCount > 16384)
                        {
                            CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace);

                            break;
                        }
                    }
                }
                uint prefix = 0;
                if (TLMConfigWarehouse.getCurrentConfigInt(TLMConfigWarehouse.getConfigIndexForTransportInfo(info) | TLMConfigWarehouse.ConfigIndex.PREFIX) != (int)ModoNomenclatura.Nenhum)
                {
                    prefix = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_lineNumber / 1000u;
                }
                float budgetMultiplierPrefix = TLMUtils.getExtensionFromConfigIndex(TLMCW.getConfigIndexForTransportInfo(info)).getBudgetMultiplierForHour(prefix, (int)Singleton <SimulationManager> .instance.m_currentDayTimeHour) / 100f;

                var flagToCheck = (TransportLine.Flags.DisabledNight | TransportLine.Flags.DisabledDay);

                if (budgetMultiplierPrefix == 0 && (Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & flagToCheck) == TransportLine.Flags.None)
                {
                    int flagsToAdd = (int)(TransportLine.Flags.DisabledDay | TransportLine.Flags.DisabledNight) | (int)(TLMTransportLineFlags.ZERO_BUDGET_SETTED);
                    if ((Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & (TransportLine.Flags)TLMTransportLineFlags.ZERO_BUDGET_SETTED) == TransportLine.Flags.None)
                    {
                        if ((Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & TransportLine.Flags.DisabledDay) == TransportLine.Flags.None)
                        {
                            flagsToAdd |= (int)TLMTransportLineFlags.ZERO_BUDGET_DAY;
                        }
                        if ((Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & TransportLine.Flags.DisabledNight) == TransportLine.Flags.None)
                        {
                            flagsToAdd |= (int)TLMTransportLineFlags.ZERO_BUDGET_NIGHT;
                        }
                    }
                    Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags |= (TransportLine.Flags)flagsToAdd;
                }
                else if ((budgetMultiplierPrefix > 0 && (Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & (TransportLine.Flags)(TLMTransportLineFlags.ZERO_BUDGET_SETTED)) != TransportLine.Flags.None))
                {
                    bool actDay   = (Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & (TransportLine.Flags)TLMTransportLineFlags.ZERO_BUDGET_DAY) != TransportLine.Flags.None;
                    bool actNight = (Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & (TransportLine.Flags)TLMTransportLineFlags.ZERO_BUDGET_NIGHT) != TransportLine.Flags.None;
                    Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags &= (TransportLine.Flags) ~(TLMTransportLineFlags.ZERO_BUDGET_DAY | TLMTransportLineFlags.ZERO_BUDGET_NIGHT | TLMTransportLineFlags.ZERO_BUDGET_SETTED);
                    TLMLineUtils.setLineActive(ref Singleton <TransportManager> .instance.m_lines.m_buffer[lineID], actDay, actNight);
                }

                bool active;
                if (Singleton <SimulationManager> .instance.m_isNightTime)
                {
                    active = ((Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & TransportLine.Flags.DisabledNight) == TransportLine.Flags.None);
                }
                else
                {
                    active = ((Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & TransportLine.Flags.DisabledDay) == TransportLine.Flags.None);
                }
                uint  steps    = 0u;
                float distance = 0f;
                bool  broken   = false;
                if (Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_stops != 0)
                {
                    NetManager instance2 = Singleton <NetManager> .instance;
                    ushort     stops     = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_stops;
                    ushort     nextStop  = stops;
                    int        count     = 0;
                    while (nextStop != 0)
                    {
                        ushort num8 = 0;
                        if (active)
                        {
                            NetNode[] expr_10A_cp_0 = instance2.m_nodes.m_buffer;
                            ushort    expr_10A_cp_1 = nextStop;
                            expr_10A_cp_0[(int)expr_10A_cp_1].m_flags = (expr_10A_cp_0[(int)expr_10A_cp_1].m_flags & ~NetNode.Flags.Disabled);
                        }
                        else
                        {
                            NetNode[] expr_130_cp_0 = instance2.m_nodes.m_buffer;
                            ushort    expr_130_cp_1 = nextStop;
                            expr_130_cp_0[(int)expr_130_cp_1].m_flags = (expr_130_cp_0[(int)expr_130_cp_1].m_flags | NetNode.Flags.Disabled);
                        }
                        for (int i = 0; i < 8; i++)
                        {
                            ushort segment = instance2.m_nodes.m_buffer[(int)nextStop].GetSegment(i);
                            if (segment != 0 && instance2.m_segments.m_buffer[(int)segment].m_startNode == nextStop)
                            {
                                distance += instance2.m_segments.m_buffer[(int)segment].m_averageLength;
                                num8      = instance2.m_segments.m_buffer[(int)segment].m_endNode;
                                if ((instance2.m_segments.m_buffer[(int)segment].m_flags & NetSegment.Flags.PathLength) == NetSegment.Flags.None)
                                {
                                    broken = true;
                                }
                                break;
                            }
                        }
                        steps   += 1u;
                        nextStop = num8;
                        if (nextStop == stops)
                        {
                            break;
                        }
                        if (++count >= 32768)
                        {
                            CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace);

                            break;
                        }
                    }
                }
                float lineCost = vehicleCount * info.m_maintenanceCostPerVehicle / 100;// * defaultCostPerPassengerCapacity;
                if (lineCost != 0)
                {
                    Singleton <EconomyManager> .instance.FetchResource(EconomyManager.Resource.Maintenance, m_linesCost.m_buffer[lineID], info.m_class);
                }
                int budget = Singleton <EconomyManager> .instance.GetBudget(info.m_class);

                int necessaryVehicles;

                if (!active)
                {
                    necessaryVehicles = 0;
                }
                else
                {
                    necessaryVehicles = TLMVehiclesLineManager.instance[lineID];
                    if (necessaryVehicles == 0)
                    {
                        if (broken)
                        {
                            necessaryVehicles = vehicleCount;
                        }
                        else
                        {
                            necessaryVehicles = Mathf.CeilToInt(budget * budgetMultiplierPrefix * distance / (info.m_defaultVehicleDistance * 100f));
                        }
                    }
                }
                if (steps != 0u && vehicleCount < necessaryVehicles)
                {
                    TransferManager.TransferReason vehicleReason = info.m_vehicleReason;
                    int index = Singleton <SimulationManager> .instance.m_randomizer.Int32(steps);

                    ushort stop = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].GetStop(index);
                    if (vehicleReason != TransferManager.TransferReason.None && stop != 0)
                    {
                        TransferManager.TransferOffer offer = default(TransferManager.TransferOffer);
                        offer.Priority      = necessaryVehicles - vehicleCount + 1;
                        offer.TransportLine = lineID;
                        offer.Position      = Singleton <NetManager> .instance.m_nodes.m_buffer[stop].m_position;
                        offer.Amount        = 1;
                        offer.Active        = false;
                        Singleton <TransferManager> .instance.AddIncomingOffer(vehicleReason, offer);
                    }
                }
                else if (vehicleCount > necessaryVehicles)
                {
                    int index2 = Singleton <SimulationManager> .instance.m_randomizer.Int32((uint)vehicleCount);

                    ushort vehicle = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].GetVehicle(index2);
                    if (vehicle != 0)
                    {
                        VehicleManager instance3 = Singleton <VehicleManager> .instance;
                        VehicleInfo    info2     = instance3.m_vehicles.m_buffer[(int)vehicle].Info;
                        info2.m_vehicleAI.SetTransportLine(vehicle, ref instance3.m_vehicles.m_buffer[(int)vehicle], 0);
                    }
                }
            }
            if ((Singleton <SimulationManager> .instance.m_currentFrameIndex & 4095u) >= 3840u)
            {
                Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_passengers.Update();
                Singleton <TransportManager> .instance.m_passengers[(int)info.m_transportType].Add(ref Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_passengers);
                Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_passengers.Reset();
            }
        }
Beispiel #2
0
        private float addStationToLinearMap(string stationPrefix, string stationName, Vector3 location, float offsetX, List <ushort> intersections, string airport, string harbor, string taxi, string regionalTrainStation, ushort stationNodeId, ItemClass.SubService ss, bool simple = false)//, out float intersectionPanelHeight)
        {
            ushort           lineID = lineInfoPanel.lineIdSelecionado.TransportLine;
            TransportLine    t      = lineInfoPanel.controller.tm.m_lines.m_buffer[(int)lineID];
            TransportManager tm     = Singleton <TransportManager> .instance;

            UIButton stationButton = null;

            TLMUtils.createUIElement <UIButton>(ref stationButton, lineStationsPanel.transform);
            stationButton.relativePosition = new Vector3(offsetX, 15f);
            stationButton.width            = 20;
            stationButton.height           = 20;
            stationButton.name             = "Station [" + stationName + "]";
            TLMUtils.initButton(stationButton, true, "IconPolicyBaseCircle");

            UITextField stationLabel = null;

            TLMUtils.createUIElement <UITextField>(ref stationLabel, stationButton.transform);
            stationLabel.autoSize            = true;
            stationLabel.width               = 220;
            stationLabel.height              = 20;
            stationLabel.useOutline          = true;
            stationLabel.pivot               = UIPivotPoint.MiddleLeft;
            stationLabel.horizontalAlignment = UIHorizontalAlignment.Left;
            stationLabel.verticalAlignment   = UIVerticalAlignment.Middle;
            stationLabel.name             = "Station [" + stationName + "] Name";
            stationLabel.relativePosition = new Vector3(23f, -13f);
            stationLabel.text             = (!string.IsNullOrEmpty(stationPrefix) ? stationPrefix.Trim() + " " : "") + stationName.Trim();
            stationLabel.textScale        = Math.Max(0.5f, Math.Min(1, 24f / stationLabel.text.Length));

            TLMUtils.uiTextFieldDefaults(stationLabel);
            stationLabel.color           = new Color(0.3f, 0.3f, 0.3f, 1);
            stationLabel.textColor       = Color.white;
            stationLabel.cursorWidth     = 2;
            stationLabel.cursorBlinkTime = 100;
            stationLabel.eventGotFocus  += (x, y) =>
            {
                stationLabel.text = TLMUtils.getStationName(stationNodeId, lineID, ss);
            };
            stationLabel.eventTextSubmitted += (x, y) =>
            {
                TLMUtils.setStopName(y, stationNodeId, lineID, () =>
                {
                    stationLabel.text = TLMUtils.getFullStationName(stationNodeId, lineID, ss);
                    m_autoName        = TLMUtils.calculateAutoName(lineID);
                    lineInfoPanel.autoNameLabel.text = autoName;
                });
            };

            stationButton.gameObject.transform.localPosition    = new Vector3(0, 0, 0);
            stationButton.gameObject.transform.localEulerAngles = new Vector3(0, 0, 45);
            stationButton.eventClick += (component, eventParam) =>
            {
                lineInfoPanel.cameraController.SetTarget(lineInfoPanel.lineIdSelecionado, location, false);
                lineInfoPanel.cameraController.ClearTarget();
            };
            if (!simple)
            {
                stationOffsetX.Add(stationNodeId, offsetX);
                if (showIntersections)
                {
                    var otherLinesIntersections = TLMLineUtils.SortLines(intersections, t);

                    int intersectionCount = otherLinesIntersections.Count + (airport != string.Empty ? 1 : 0) + (taxi != string.Empty ? 1 : 0) + (harbor != string.Empty ? 1 : 0) + (regionalTrainStation != string.Empty ? 1 : 0);
                    if (intersectionCount > 0)
                    {
                        UIPanel intersectionsPanel = null;
                        TLMUtils.createUIElement <UIPanel>(ref intersectionsPanel, stationButton.transform);
                        intersectionsPanel.autoSize                  = false;
                        intersectionsPanel.autoLayout                = false;
                        intersectionsPanel.autoLayoutStart           = LayoutStart.TopLeft;
                        intersectionsPanel.autoLayoutDirection       = LayoutDirection.Horizontal;
                        intersectionsPanel.relativePosition          = new Vector3(-20, 10);
                        intersectionsPanel.wrapLayout                = false;
                        intersectionsPanel.autoFitChildrenVertically = true;

                        TLMLineUtils.PrintIntersections(airport, harbor, taxi, regionalTrainStation, intersectionsPanel, otherLinesIntersections);

                        intersectionsPanel.autoLayout = true;
                        intersectionsPanel.wrapLayout = true;
                        intersectionsPanel.width      = 55;
                        //
                        return(42f);
                    }
                    else
                    {
                        return(25f);
                    }
                }
                else if (showExtraStopInfo)
                {
                    float normalWidth = 42.5f;

                    NetNode stopNode = Singleton <NetManager> .instance.m_nodes.m_buffer[(int)stationNodeId];

                    int residents, tourists;
                    TLMLineUtils.GetQuantityPassengerWaiting(stationNodeId, out residents, out tourists);

                    UIPanel stationInfoStatsPanel = null;
                    TLMUtils.createUIElement <UIPanel>(ref stationInfoStatsPanel, stationButton.transform);
                    stationInfoStatsPanel.autoSize   = false;
                    stationInfoStatsPanel.autoLayout = false;
                    stationInfoStatsPanel.autoFitChildrenVertically = true;
                    stationInfoStatsPanel.autoLayoutStart           = LayoutStart.TopLeft;
                    stationInfoStatsPanel.autoLayoutDirection       = LayoutDirection.Horizontal;
                    stationInfoStatsPanel.relativePosition          = new Vector3(-20, 10);
                    stationInfoStatsPanel.autoLayout = true;
                    stationInfoStatsPanel.wrapLayout = true;
                    stationInfoStatsPanel.width      = normalWidth;

                    UILabel residentsWaiting = null;
                    TLMUtils.createUIElement <UILabel>(ref residentsWaiting, stationInfoStatsPanel.transform);
                    residentsWaiting.autoSize         = false;
                    residentsWaiting.useOutline       = true;
                    residentsWaiting.text             = residents.ToString();
                    residentsWaiting.tooltipLocaleID  = "TLM_RESIDENTS_WAITING";
                    residentsWaiting.backgroundSprite = "EmptySprite";
                    residentsWaiting.color            = new Color32(0x12, 0x68, 0x34, 255);
                    residentsWaiting.width            = normalWidth;
                    residentsWaiting.padding          = new RectOffset(0, 0, 4, 2);
                    residentsWaiting.height           = 20;
                    residentsWaiting.textScale        = 0.7f;
                    residentsWaiting.textAlignment    = UIHorizontalAlignment.Center;
                    residentCounters[stationNodeId]   = residentsWaiting;

                    UILabel touristsWaiting = null;
                    TLMUtils.createUIElement <UILabel>(ref touristsWaiting, stationInfoStatsPanel.transform);
                    touristsWaiting.autoSize         = false;
                    touristsWaiting.text             = tourists.ToString();
                    touristsWaiting.tooltipLocaleID  = "TLM_TOURISTS_WAITING";
                    touristsWaiting.useOutline       = true;
                    touristsWaiting.width            = normalWidth;
                    touristsWaiting.height           = 20;
                    touristsWaiting.padding          = new RectOffset(0, 0, 4, 2);
                    touristsWaiting.textScale        = 0.7f;
                    touristsWaiting.backgroundSprite = "EmptySprite";
                    touristsWaiting.color            = new Color32(0x1f, 0x25, 0x68, 255);
                    touristsWaiting.textAlignment    = UIHorizontalAlignment.Center;
                    touristCounters[stationNodeId]   = touristsWaiting;
                    //
                    return(normalWidth);
                }
                else
                {
                    return(25f);
                }
            }
            else
            {
                return(30f);
            }
        }
        public void DoAutoName()
        {
            string format = (TLMCW.getCurrentConfigBool(TLMConfigWarehouse.ConfigIndex.ADD_LINE_NUMBER_IN_AUTONAME)) ? "[{0}] {1}" : "{1}";

            TLMUtils.setLineName(m_LineID, string.Format(format, lineNumberFormatted, TLMUtils.calculateAutoName(m_LineID)));
        }
Beispiel #4
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);
                }
            }
        }