private static int ticketPriceForPrefix(ushort vehicleID, ref Vehicle vehicleData, int defaultPrice)
        {
            var def = TransportSystemDefinition.from(vehicleData.Info);

            if (def == default(TransportSystemDefinition))
            {
                if (TLMSingleton.instance != null && TLMSingleton.debugMode)
                {
                    TLMUtils.doLog("NULL TSysDef! {0}+{1}+{2}", vehicleData.Info.GetAI().GetType(), vehicleData.Info.m_class.m_subService, vehicleData.Info.m_vehicleType);
                }
                return(defaultPrice);
            }
            if (vehicleData.m_transportLine == 0)
            {
                var value = (int)def.GetTransportExtension().GetDefaultTicketPrice(0);
                return(value);
            }
            else
            {
                if (TLMTransportLineExtension.instance.GetUseCustomConfig(vehicleData.m_transportLine))
                {
                    return((int)TLMTransportLineExtension.instance.GetTicketPrice(vehicleData.m_transportLine));
                }
                else
                {
                    return((int)def.GetTransportExtension().GetTicketPrice(TLMLineUtils.getPrefix(vehicleData.m_transportLine)));
                }
            }
        }
Ejemplo n.º 2
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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public VehicleInfo GetAModel(ushort lineID)
        {
            var           prefix    = TLMLineUtils.getPrefix(lineID);
            VehicleInfo   info      = null;
            List <string> assetList = GetAssetList(prefix);

            while (info == null && assetList.Count > 0)
            {
                info = TLMUtils.GetRandomModel(assetList, out string modelName);
                if (info == null)
                {
                    RemoveAsset(prefix, modelName);
                    assetList = GetAssetList(prefix);
                }
            }
            return(info);
        }
        private static void GetColorFor(ushort vehicleID, ref Vehicle data, ref Color __result, InfoManager.InfoMode infoMode)
        {
            switch (infoMode)
            {
            case InfoManager.InfoMode.TrafficRoutes:
                return;

            case InfoManager.InfoMode.Underground:
            case InfoManager.InfoMode.ParkMaintenance:
IL_1D:
                if (infoMode != InfoManager.InfoMode.None)
                {
                    if (infoMode != InfoManager.InfoMode.Transport)
                    {
                        if (infoMode != InfoManager.InfoMode.EscapeRoutes)
                        {
                            return;
                        }
                        goto IL_1G;
                    }
                    else
                    {
                        return;
                        //goto IL_1G;
                    }
                }
IL_1G:
                ushort transportLine = data.m_transportLine;
                if (transportLine != 0)
                {
                    var tsd = TransportSystemDefinition.getDefinitionForLine(transportLine);
                    if (tsd.transportType == TransportInfo.TransportType.EvacuationBus)
                    {
                        return;
                    }

                    var ext    = tsd.GetTransportExtension();
                    var prefix = TLMLineUtils.getPrefix(transportLine);

                    if (ext.IsUsingColorForModel(prefix))
                    {
                        __result = ext.GetColor(prefix);
                    }
                    else
                    {
                        __result = Singleton <TransportManager> .instance.m_lines.m_buffer[(int)transportLine].GetColor();
                    }
                }
                return;

            case InfoManager.InfoMode.Tours:
                ushort transportLine2 = data.m_transportLine;
                var    tsd2           = TransportSystemDefinition.getDefinitionForLine(transportLine2);
                if (tsd2.transportType != TransportInfo.TransportType.TouristBus)
                {
                    return;
                }
                goto IL_1G;

            case InfoManager.InfoMode.Tourism:
                return;

            default:
                goto IL_1D;
            }
        }
        private static bool ticketPriceForPrefix(ushort vehicleID, ref Vehicle vehicleData, ref int __result)
        {
            var def = TransportSystemDefinition.from(vehicleData.Info);

            if (def == default(TransportSystemDefinition))
            {
                return(true);
            }

            DistrictManager instance = Singleton <DistrictManager> .instance;
            byte            district = instance.GetDistrict(vehicleData.m_targetPos3);

            DistrictPolicies.Services servicePolicies = instance.m_districts.m_buffer[(int)district].m_servicePolicies;
            DistrictPolicies.Event    @event          = instance.m_districts.m_buffer[(int)district].m_eventPolicies & Singleton <EventManager> .instance.GetEventPolicyMask();

            float multiplier;

            if (vehicleData.Info.m_class.m_subService == ItemClass.SubService.PublicTransportTours)
            {
                multiplier = 1;
            }
            else
            {
                if ((servicePolicies & DistrictPolicies.Services.FreeTransport) != DistrictPolicies.Services.None)
                {
                    __result = 0;
                    return(false);
                }
                if ((@event & DistrictPolicies.Event.ComeOneComeAll) != DistrictPolicies.Event.None)
                {
                    __result = 0;
                    return(false);
                }
                if ((servicePolicies & DistrictPolicies.Services.HighTicketPrices) != DistrictPolicies.Services.None)
                {
                    District[] expr_114_cp_0 = instance.m_districts.m_buffer;
                    byte       expr_114_cp_1 = district;
                    expr_114_cp_0[(int)expr_114_cp_1].m_servicePoliciesEffect = (expr_114_cp_0[(int)expr_114_cp_1].m_servicePoliciesEffect | DistrictPolicies.Services.HighTicketPrices);
                    multiplier = 5f / 4f;
                }
                else
                {
                    multiplier = 1;
                }
            }
            if (vehicleData.m_transportLine == 0)
            {
                __result = (int)(def.GetTransportExtension().GetDefaultTicketPrice(0) * multiplier);
                return(false);
            }
            else
            {
                if (TLMTransportLineExtension.instance.IsUsingCustomConfig(vehicleData.m_transportLine))
                {
                    __result = (int)(TLMTransportLineExtension.instance.GetTicketPrice(vehicleData.m_transportLine) * multiplier);
                }
                else
                {
                    __result = (int)(def.GetTransportExtension().GetTicketPrice(TLMLineUtils.getPrefix(vehicleData.m_transportLine)) * multiplier);
                }
                return(false);
            }
        }
        private void BindParentChanges()
        {
            m_lineInfo.EventOnLineChanged += (lineId) =>
            {
                TLMUtils.doLog("EventOnLineChanged");
                m_isLoading = true;
                bool isCustomLine             = TLMTransportLineExtension.instance.GetUseCustomConfig(lineId);
                TransportSystemDefinition tsd = TransportSystemDefinition.from(lineId);
                TLMUtils.doLog("tsd = {0}", tsd);
                if (m_lastDef != tsd)
                {
                    foreach (var i in m_checkboxes.Keys)
                    {
                        UnityEngine.Object.Destroy(m_checkboxes[i].gameObject);
                    }
                    m_defaultAssets = tsd.GetTransportExtension().GetAllBasicAssets(0);
                    m_checkboxes    = new Dictionary <string, UICheckBox>();

                    TLMUtils.doLog("m_defaultAssets Size = {0} ({1})", m_defaultAssets?.Count, string.Join(",", m_defaultAssets.Keys?.ToArray() ?? new string[0]));
                    foreach (var i in m_defaultAssets.Keys)
                    {
                        var checkbox = (UICheckBox)m_uiHelper.AddCheckbox(m_defaultAssets[i], false, (x) =>
                        {
                            ushort lineIdx = m_lineInfo.CurrentSelectedId;
                            if (m_isLoading)
                            {
                                return;
                            }
                            if (x)
                            {
                                if (TLMTransportLineExtension.instance.GetUseCustomConfig(lineIdx))
                                {
                                    TLMTransportLineExtension.instance.AddAsset(lineIdx, i);
                                }
                                else
                                {
                                    tsd.GetTransportExtension().AddAsset(TLMLineUtils.getPrefix(lineIdx), i);
                                }
                            }
                            else
                            {
                                if (TLMTransportLineExtension.instance.GetUseCustomConfig(lineIdx))
                                {
                                    TLMTransportLineExtension.instance.RemoveAsset(lineIdx, i);
                                }
                                else
                                {
                                    tsd.GetTransportExtension().RemoveAsset(TLMLineUtils.getPrefix(lineIdx), i);
                                }
                            }
                        });
                        CreateModelCheckBox(i, checkbox);
                        checkbox.label.tooltip              = checkbox.label.text;
                        checkbox.label.textScale            = 0.9f;
                        checkbox.label.transform.localScale = new Vector3(Math.Min((m_mainPanel.width - 50) / checkbox.label.width, 1), 1);
                        m_checkboxes[i] = checkbox;
                    }
                }
                m_lastDef = tsd;
                List <string> selectedAssets;
                if (isCustomLine)
                {
                    selectedAssets = TLMTransportLineExtension.instance.GetAssetList(lineId);
                }
                else
                {
                    selectedAssets = tsd.GetTransportExtension().GetAssetList(TLMLineUtils.getPrefix(lineId));
                }
                TLMUtils.doLog("selectedAssets Size = {0} ({1})", selectedAssets?.Count, string.Join(",", selectedAssets?.ToArray() ?? new string[0]));
                foreach (var i in m_checkboxes.Keys)
                {
                    m_checkboxes[i].isChecked = selectedAssets.Contains(i);
                }

                if (isCustomLine)
                {
                    m_title.text = string.Format(Locale.Get("TLM_ASSET_SELECT_WINDOW_TITLE"), TLMLineUtils.getLineStringId(lineId), TLMConfigWarehouse.getNameForTransportType(tsd.toConfigIndex()));
                }
                else
                {
                    TLMConfigWarehouse.ConfigIndex transportType = tsd.toConfigIndex();
                    ModoNomenclatura mnPrefixo = (ModoNomenclatura)TLMConfigWarehouse.getCurrentConfigInt(TLMConfigWarehouse.ConfigIndex.PREFIX | transportType);
                    var prefix = TLMLineUtils.getPrefix(lineId);
                    m_title.text = string.Format(Locale.Get("TLM_ASSET_SELECT_WINDOW_TITLE_PREFIX"), prefix > 0 ? TLMUtils.getStringFromNumber(TLMUtils.getStringOptionsForPrefix(mnPrefixo), (int)prefix + 1) : Locale.Get("TLM_UNPREFIXED"), TLMConfigWarehouse.getNameForTransportType(tsd.toConfigIndex()));
                }

                m_isLoading = false;
                m_previewPanel.isVisible = false;
            };
        }
Ejemplo n.º 7
0
        private void BindParentChanges()
        {
            TLMTabControllerPrefixList <T> .eventOnPrefixChange += (prefix) =>
            {
                TLMUtils.doLog("EventOnLineChanged");
                TransportSystemDefinition tsd = Singleton <T> .instance.GetTSD();

                if (!tsd.hasVehicles())
                {
                    m_mainPanel.isVisible = false;
                    return;
                }
                m_isLoading = true;
                TLMUtils.doLog("tsd = {0}", tsd);
                if (!loaded)
                {
                    foreach (var i in m_checkboxes.Keys)
                    {
                        UnityEngine.Object.Destroy(m_checkboxes[i].gameObject);
                    }
                    m_defaultAssets = tsd.GetTransportExtension().GetAllBasicAssets(0);
                    m_checkboxes    = new Dictionary <string, UICheckBox>();

                    TLMUtils.doLog("m_defaultAssets Size = {0} ({1})", m_defaultAssets?.Count, string.Join(",", m_defaultAssets.Keys?.ToArray() ?? new string[0]));
                    foreach (var i in m_defaultAssets.Keys)
                    {
                        var checkbox = (UICheckBox)m_uiHelper.AddCheckbox(m_defaultAssets[i], false, (x) =>
                        {
                            if (!m_isLoading)
                            {
                                ushort lineIdx = (ushort)m_parent.SelectedPrefix;
                                if (lineIdx > 100)
                                {
                                    return;
                                }
                                if (x)
                                {
                                    tsd.GetTransportExtension().AddAsset(TLMLineUtils.getPrefix(lineIdx), i);
                                }
                                else
                                {
                                    tsd.GetTransportExtension().RemoveAsset(TLMLineUtils.getPrefix(lineIdx), i);
                                }
                            }
                        });
                        CreateModelCheckBox(i, checkbox);
                        checkbox.label.tooltip              = checkbox.label.text;
                        checkbox.label.textScale            = 0.9f;
                        checkbox.label.transform.localScale = new Vector3(Math.Min((m_mainPanel.width - 50) / checkbox.label.width, 1), 1);
                        m_checkboxes[i] = checkbox;
                    }
                }
                loaded = true;
                List <string> selectedAssets;
                selectedAssets = tsd.GetTransportExtension().GetAssetList((uint)prefix);

                TLMUtils.doLog("selectedAssets Size = {0} ({1})", selectedAssets?.Count, string.Join(",", selectedAssets?.ToArray() ?? new string[0]));
                foreach (var i in m_checkboxes.Keys)
                {
                    m_checkboxes[i].isChecked = selectedAssets.Contains(i);
                }

                TLMConfigWarehouse.ConfigIndex transportType = tsd.toConfigIndex();
                ModoNomenclatura mnPrefixo = (ModoNomenclatura)TLMConfigWarehouse.getCurrentConfigInt(TLMConfigWarehouse.ConfigIndex.PREFIX | transportType);
                m_title.text = string.Format(Locale.Get("TLM_ASSET_SELECT_WINDOW_TITLE_PREFIX"), prefix > 0 ? TLMUtils.getStringFromNumber(TLMUtils.getStringOptionsForPrefix(mnPrefixo), (int)prefix + 1) : Locale.Get("TLM_UNPREFIXED"), TLMConfigWarehouse.getNameForTransportType(tsd.toConfigIndex()));

                m_isLoading = false;
            };
            TLMTabControllerPrefixList <T> .eventOnColorChange += (Color x) => m_lastColor = x;
        }
Ejemplo n.º 8
0
 public VehicleInfo GetAModel(ushort lineID)
 {
     return(TLMUtils.GetRandomModel(GetAssetList(TLMLineUtils.getPrefix(lineID))));
 }
Ejemplo n.º 9
0
        public void OnSetTarget(Type source)
        {
            if (source == GetType())
            {
                return;
            }

            TransportSystemDefinition tsd = TransportSystem;

            if (!tsd.HasVehicles())
            {
                MainPanel.isVisible = false;
                return;
            }
            m_isLoading = true;
            TLMUtils.doLog("tsd = {0}", tsd);
            IBasicExtension config = TLMLineUtils.GetEffectiveExtensionForLine(GetLineID());

            if (TransportSystem != m_lastSystem)
            {
                m_defaultAssets = tsd.GetTransportExtension().GetAllBasicAssetsForLine(0);
                UIPanel[] depotChecks = m_checkboxTemplateList.SetItemCount(m_defaultAssets.Count);

                TLMUtils.doLog("m_defaultAssets Size = {0} ({1})", m_defaultAssets?.Count, string.Join(",", m_defaultAssets.Keys?.ToArray() ?? new string[0]));
                for (int i = 0; i < m_defaultAssets.Count; i++)
                {
                    string     assetName = m_defaultAssets.Keys.ElementAt(i);
                    UICheckBox checkbox  = depotChecks[i].GetComponentInChildren <UICheckBox>();
                    checkbox.objectUserData = assetName;
                    UITextField capacityEditor = depotChecks[i].GetComponentInChildren <UITextField>();
                    capacityEditor.text = VehicleUtils.GetCapacity(PrefabCollection <VehicleInfo> .FindLoaded(assetName)).ToString("0");
                    if (checkbox.label.objectUserData == null)
                    {
                        checkbox.eventCheckChanged += (x, y) =>
                        {
                            if (m_isLoading)
                            {
                                return;
                            }

                            ushort          lineId    = GetLineID();
                            IBasicExtension extension = TLMLineUtils.GetEffectiveExtensionForLine(lineId);

                            TLMUtils.doErrorLog($"checkbox event: {x.objectUserData} => {y} at {extension}[{lineId}]");
                            if (y)
                            {
                                extension.AddAssetToLine(lineId, x.objectUserData.ToString());
                            }
                            else
                            {
                                extension.RemoveAssetFromLine(lineId, x.objectUserData.ToString());
                            }
                        };
                        CreateModelCheckBox(checkbox);
                        KlyteMonoUtils.LimitWidthAndBox(checkbox.label, 280);
                        capacityEditor.eventTextSubmitted += CapacityEditor_eventTextSubmitted;;

                        capacityEditor.eventMouseEnter += (x, y) =>
                        {
                            m_lastInfo = PrefabCollection <VehicleInfo> .FindLoaded(checkbox.objectUserData.ToString());

                            RedrawModel();
                        };
                        checkbox.label.objectUserData = true;
                    }
                    checkbox.text = m_defaultAssets[assetName];
                }
                m_lastSystem = TransportSystem;
            }
            else
            {
                List <string> allowedAssets = config.GetAssetListForLine(GetLineID());
                for (int i = 0; i < m_checkboxTemplateList.items.Count; i++)
                {
                    UICheckBox checkbox = m_checkboxTemplateList.items[i].GetComponentInChildren <UICheckBox>();
                    checkbox.isChecked = allowedAssets.Contains(checkbox.objectUserData.ToString());
                }
            }

            if (TransportLinesManagerMod.DebugMode)
            {
                List <string> allowedAssets = config.GetAssetListForLine(GetLineID());
                TLMUtils.doLog($"selectedAssets Size = {allowedAssets?.Count} ({ string.Join(",", allowedAssets?.ToArray() ?? new string[0])}) {config?.GetType()}");
            }

            if (config is TLMTransportLineConfiguration)
            {
                m_title.text = string.Format(Locale.Get("K45_TLM_ASSET_SELECT_WINDOW_TITLE"), TLMLineUtils.getLineStringId(GetLineID()));
            }
            else
            {
                int prefix = (int)TLMLineUtils.getPrefix(GetLineID());
                m_title.text = string.Format(Locale.Get("K45_TLM_ASSET_SELECT_WINDOW_TITLE_PREFIX"), prefix > 0 ? NumberingUtils.GetStringFromNumber(TLMUtils.GetStringOptionsForPrefix(tsd), prefix + 1) : Locale.Get("K45_TLM_UNPREFIXED"), TLMConfigWarehouse.getNameForTransportType(tsd.ToConfigIndex()));
            }

            m_isLoading = false;
        }
Ejemplo n.º 10
0
        public override void RefreshLines()
        {
            m_DayIcon.relativePosition      = new Vector3(655, 14);
            m_NightIcon.relativePosition    = new Vector3(682, 14);
            m_DayNightIcon.relativePosition = new Vector3(701, 14);
            m_visibilityToggle.area         = new Vector4(8, 5, 28, 28);

            var tsd = Singleton <T> .instance.GetTSD();

            bool hasPrefix = TLMLineUtils.hasPrefix(ref tsd);
            int  count     = 0;

            for (ushort lineID = 1; lineID < TransportManager.instance.m_lines.m_buffer.Length; lineID++)
            {
                TransportLine tl = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID];
                if (tl.Complete && Singleton <T> .instance.GetTSD().isFromSystem(tl) && (!hasPrefix || m_prefixFilter.selectedIndex == 0 || m_prefixFilter.selectedIndex - 1 == TLMLineUtils.getPrefix(lineID)))
                {
                    AddToList(lineID, ref count);
                }
            }
            RemoveExtraLines(count);

            switch (m_LastSortCriterionLines)
            {
            case LineSortCriterion.NAME: OnNameSort(); break;

            case LineSortCriterion.PASSENGER: OnPassengerSort(); break;

            case LineSortCriterion.STOP: OnStopSort(); break;

            case LineSortCriterion.VEHICLE: OnVehicleSort(); break;

            case LineSortCriterion.LINE_NUMBER:
            default: OnLineNumberSort(); break;
            }
            isUpdated = true;
        }
Ejemplo n.º 11
0
 public uint LineToIndex(ushort lineId) => TLMLineUtils.getPrefix(lineId);