Ejemplo n.º 1
0
 private void changeLineTime(bool day, bool night)
 {
     m_LineOperation = Singleton <SimulationManager> .instance.AddAction(delegate
     {
         TLMLineUtils.setLineActive(ref Singleton <TransportManager> .instance.m_lines.m_buffer[(int)m_LineID], day, night);
     });
 }
Ejemplo n.º 2
0
 private void changeLineTime(int selection)
 {
     daytimeChange = Singleton <SimulationManager> .instance.AddAction(delegate
     {
         ushort lineID = m_lineIdSelecionado.TransportLine;
         TLMLineUtils.setLineActive(ref Singleton <TransportManager> .instance.m_lines.m_buffer[(int)lineID], ((selection & 0x2) == 0), ((selection & 0x1) == 0));
     });
 }
        public static bool SimulationStepPre(ushort lineID)
        {
            try
            {
                TransportLine t = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID];
                bool          activeDayNightManagedByTLM = TLMLineUtils.isPerHourBudget(lineID);
                if (t.m_lineNumber != 0 && t.m_stops != 0)
                {
                    Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_budget = (ushort)(TLMLineUtils.getBudgetMultiplierLine(lineID) * 100);
                }

                unchecked
                {
                    TLMLineUtils.getLineActive(ref Singleton <TransportManager> .instance.m_lines.m_buffer[lineID], out bool day, out bool night);
                    bool isNight = Singleton <SimulationManager> .instance.m_isNightTime;
                    bool zeroed  = false;
                    if ((activeDayNightManagedByTLM || (isNight && night) || (!isNight && day)) && Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_budget == 0)
                    {
                        Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags |= (TransportLine.Flags)TLMTransportLineFlags.ZERO_BUDGET_CURRENT;
                        zeroed = true;
                    }
                    else
                    {
                        Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags &= ~(TransportLine.Flags)TLMTransportLineFlags.ZERO_BUDGET_CURRENT;
                    }
                    TLMUtils.doLog("activeDayNightManagedByTLM = {0}; zeroed = {1}", activeDayNightManagedByTLM, zeroed);
                    if (activeDayNightManagedByTLM)
                    {
                        if (zeroed)
                        {
                            TLMLineUtils.setLineActive(ref Singleton <TransportManager> .instance.m_lines.m_buffer[lineID], false, false);
                        }
                        else
                        {
                            TLMLineUtils.setLineActive(ref Singleton <TransportManager> .instance.m_lines.m_buffer[lineID], true, true);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                TLMUtils.doErrorLog("Error processing budget for line: {0}\n{1}", lineID, e);
            }
            return(true);
        }
Ejemplo n.º 4
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();
            }
        }