Exemple #1
0
 public static void Postfix(ref BuildingInfo __instance)
 {
     if (OptionsWrapper <Options> .Options.ingameTrainMetroConverter)
     {
         try
         {
             var ai = __instance.GetComponent <TransportStationAI>();
             if (ai != null)
             {
                 if (__instance.m_class.m_subService == ItemClass.SubService.PublicTransportTrain || __instance.m_class.m_subService == ItemClass.SubService.PublicTransportMetro)
                 {
                     if (__instance.name.IndexOf(ModTrackNames.ANALOG_PREFIX) == -1)
                     {
                         if (__instance.HasAbovegroundTrainStationTracks() || __instance.HasAbovegroundMetroStationTracks())
                         {
                             m_Container.InitializeBuildingInfoImpl(__instance);
                         }
                     }
                 }
             }
         }
         catch (Exception e)
         {
             UnityEngine.Debug.LogError(e);
         }
     }
 }
        public static void CopyFields(this BuildingInfo oldInfo, string newName)
        {
            BuildingInfo newInfo = PrefabCollection <BuildingInfo> .FindLoaded(newName);

            if (newInfo == null)
            {
                return;
            }

            BuildingAI oldAI = newInfo.GetComponent <BuildingAI>();
            BuildingAI newAI = newInfo.gameObject.AddComponent <BuildingAI>().GetCopyOf(oldAI);

            Destroy(oldAI);

            newInfo.m_props = new BuildingInfo.Prop[oldInfo.m_props.Length];
            oldInfo.m_props.CopyTo(newInfo.m_props, 0);

            foreach (FieldInfo fieldInfo in newInfo.GetType().GetFields(Flags))
            {
                string fieldName = fieldInfo.Name;
                if (fieldName == "m_prefabDataIndex" || fieldName == "WidthCount" || fieldName == "LengthCount")
                {
                    continue;
                }
                object newValue = oldInfo.GetType().GetField(fieldName, Flags).GetValue(oldInfo);
                if (fieldName == "m_buildingAI")
                {
                    newValue = newAI;
                }
                newInfo.GetType().GetField(fieldName, Flags).SetValue(newInfo, newValue);
            }
        }
Exemple #3
0
        private static void RecalculateSpawnPoints()
        {
            var buildingAI = m_Info?.GetComponent <DepotAI>();
            var paths      = m_Info?.m_paths;

            if (buildingAI == null || paths == null)
            {
                return;
            }
            var spawnPoints = (from path in paths
                               where IsVehicleStop(path)
                               select GetMiddle(path, true)).Distinct().ToArray();

            switch (spawnPoints.Length)
            {
            case 0:
                buildingAI.m_spawnPosition = Vector3.zero;
                buildingAI.m_spawnTarget   = Vector3.zero;
                buildingAI.m_spawnPoints   = new DepotAI.SpawnPoint[] { };
                break;

            case 1:
                buildingAI.m_spawnPosition = spawnPoints[0];
                buildingAI.m_spawnTarget   = spawnPoints[0];
                buildingAI.m_spawnPoints   = new[]
                {
                    new DepotAI.SpawnPoint
                    {
                        m_position = spawnPoints[0],
                        m_target   = spawnPoints[0]
                    }
                };
                break;

            default:
                buildingAI.m_spawnPosition = Vector3.zero;
                buildingAI.m_spawnTarget   = Vector3.zero;
                var spawnPointList = new List <DepotAI.SpawnPoint>();
                foreach (var msp in buildingAI.m_spawnPoints)
                {
                    spawnPointList.Add(msp);
                }
                foreach (var sp in spawnPoints)
                {
                    spawnPointList.Add(new DepotAI.SpawnPoint()
                    {
                        m_position = sp, m_target = sp
                    });
                }
                buildingAI.m_spawnPoints = spawnPointList.ToArray();
                break;
            }
        }
        public static void PatchEveryBuildingAI()
        {
            prefabCount = PrefabCollection <BuildingInfo> .PrefabCount();

            for (int i = 0; i < prefabCount; ++i)
            {
                prefab = PrefabCollection <BuildingInfo> .GetPrefab((uint)i);

                if (prefab != null)
                {
                    component = prefab.GetComponent <BuildingAI>();

                    if (component != null)
                    {
                        Type currentAiType = component.GetType();
                        Type newAiType     = null;

                        if (currentAiType == typeof(ResidentialBuildingAI))
                        {
                            newAiType = typeof(MyResidentialBuildingAI);
                        }
                        else if (currentAiType == typeof(CommercialBuildingAI))
                        {
                            newAiType = typeof(MyCommercialBuildingAI);
                        }
                        else if (currentAiType == typeof(IndustrialBuildingAI))
                        {
                            newAiType = typeof(MyIndustrialBuildingAI);
                        }
                        else if (currentAiType == typeof(IndustrialExtractorAI))
                        {
                            newAiType = typeof(MyIndustrialExtractorAI);
                        }
                        else if (currentAiType == typeof(OfficeBuildingAI))
                        {
                            newAiType = typeof(MyOfficeBuildingAI);
                        }

                        if (newAiType != null)
                        {
                            BuildingAI buildingAI = (BuildingAI)prefab.gameObject.AddComponent(newAiType);

                            buildingAI.m_info   = prefab;
                            prefab.m_buildingAI = buildingAI;
                            buildingAI.InitializePrefab();
                        }
                    }
                }
            }
        }
Exemple #5
0
        public void ReplaceBuildingTextures(BuildingInfo prefab)
        {
            if (prefab == null)
            {
                return;
            }

            ReplaceBuildingTextures(prefab.GetComponent <Renderer>(), prefab.name, false);

            if (prefab.m_lodObject != null)
            {
                ReplaceBuildingTextures(prefab.m_lodObject.GetComponent <Renderer>(), prefab.name, true);
            }
        }
Exemple #6
0
 private static void RevertBuilding(ref BuildingInfo info)
 {
     if (m_CpmNetDict != null)
     {
         for (int j = 0; j < info.m_paths.Count(); j++)
         {
             NetInfo ninfo = info.m_paths[j].m_netInfo;
             if (m_CpmNetDict.ContainsKey(ninfo.name))
             {
                 if (ninfo.m_netAI != null)
                 {
                     PlayerNetAI pnai = ninfo.GetComponent <PlayerNetAI>();
                     if (pnai != null)
                     {
                         pnai.m_createPassMilestone = m_CpmNetDict[ninfo.name];
                     }
                 }
             }
         }
     }
     if (m_CpmBuildingDict != null)
     {
         if (m_CpmBuildingDict.ContainsKey(info.name))
         {
             PlayerBuildingAI pbai = info.GetComponent <PlayerBuildingAI>();
             if (pbai != null)
             {
                 pbai.m_createPassMilestone  = m_CpmBuildingDict[info.name][0];
                 pbai.m_createPassMilestone2 = m_CpmBuildingDict[info.name][1];
                 pbai.m_createPassMilestone3 = m_CpmBuildingDict[info.name][2];
                 info.m_buildingAI           = pbai;
                 if (info.m_subBuildings != null && info.m_subBuildings.Count() > 0)
                 {
                     foreach (BuildingInfo.SubInfo subBuilding in info.m_subBuildings)
                     {
                         if (subBuilding.m_buildingInfo != null)
                         {
                             RevertBuilding(ref subBuilding.m_buildingInfo);
                         }
                     }
                 }
             }
         }
     }
 }
            public void Apply(BuildingInfo prefab)
            {
                prefab.m_useColorVariations = UseColorVariations;
                prefab.m_color0             = Color0;
                prefab.m_color1             = Color1;
                prefab.m_color2             = Color2;
                prefab.m_color3             = Color3;

                var material = prefab.GetComponent <Renderer>()?.sharedMaterial;

                if (material != null)
                {
                    material.SetColor("_ColorV0", Color0);
                    material.SetColor("_ColorV1", Color1);
                    material.SetColor("_ColorV2", Color2);
                    material.SetColor("_ColorV3", Color3);
                }
            }
Exemple #8
0
        private static void RemoveCreatePassMileStone(ref BuildingInfo info)
        {
            PlayerBuildingAI pbai = info.GetComponent <PlayerBuildingAI>();

            if (pbai != null)
            {
                if (pbai.m_createPassMilestone != null)
                {
                    if (m_CpmBuildingDict == null)
                    {
                        m_CpmBuildingDict = new Dictionary <string, List <ManualMilestone> >();
                    }
                    if (m_CpmBuildingDict.ContainsKey(info.name) == false)
                    {
                        m_CpmBuildingDict.Add(info.name, new List <ManualMilestone>());
                    }
                    m_CpmBuildingDict[info.name].Add(pbai.m_createPassMilestone);
                    m_CpmBuildingDict[info.name].Add(pbai.m_createPassMilestone2);
                    m_CpmBuildingDict[info.name].Add(pbai.m_createPassMilestone3);
                    pbai.m_createPassMilestone  = null;
                    pbai.m_createPassMilestone2 = null;
                    pbai.m_createPassMilestone3 = null;
                    info.m_buildingAI           = pbai;
                }
                foreach (BuildingInfo.PathInfo path in info.m_paths)
                {
                    if (path.m_netInfo != null)
                    {
                        RemoveCreatePassMileStone(path.m_netInfo);
                    }
                }
                if (info.m_subBuildings != null)
                {
                    foreach (var subBuilding in info.m_subBuildings)
                    {
                        if (subBuilding.m_buildingInfo != null)
                        {
                            RemoveCreatePassMileStone(ref subBuilding.m_buildingInfo);
                        }
                    }
                }
            }
        }
Exemple #9
0
        public bool replaceBuildingAi <T>(BuildingInfo building, BuildingInfo medicalBuilding) where T : BuildingAI
        {
            Logger.logInfo(LOG_AI_REPLACEMENT, "AiReplacementHelper.replaceBuildingAi -- Checking Building: {0}", building);
            if (building == null)
            {
                Logger.logInfo(LOG_AI_REPLACEMENT, "AiReplacementHelper.replaceBuildingAi -- Null Building");
                return(false);
            }

            if (this.replacedAIs.ContainsKey(building.name))
            {
                Logger.logInfo(LOG_AI_REPLACEMENT, "AiReplacementHelper.replaceBuildingAi -- Did not replace AI for {0}, building AI has already been replaced", building.name);
                return(true);
            }


            if (building.m_buildingAI is DormitoryAi)
            {
                Logger.logInfo(LOG_AI_REPLACEMENT, "AiReplacementHelper.replaceBuildingAi -- Did not replace AI for {0}, building already running the DormitoryAi", building.name);
                return(false);
            }


            // Replace the AI
            BuildingAI originalAi = building.GetComponent <BuildingAI>();
            BuildingAI medicalAi  = medicalBuilding.GetComponent <BuildingAI>();
            T          to         = building.gameObject.AddComponent <T>();

            this.copyBuildingAIAttributes(originalAi, to, medicalAi);
            this.replacedAIs[building.name] = originalAi;
            building.m_buildingAI           = to;
            to.m_info = building;

            // Set the class as a medical building
            building.m_class = medicalBuilding.m_class;

            // Set the placement style as manual
            building.m_placementStyle = ItemClass.Placement.Manual;

            Logger.logInfo(LOG_AI_REPLACEMENT, "AiReplacementHelper.replaceBuildingAi -- Successfully replaced {0}'s AI", building.name);
            return(true);
        }
Exemple #10
0
        public static bool Convert(BuildingInfo info)
        {
            long id;

            if (!Util.TryGetWorkshopId(info, out id) || !Stations.GetConvertedIds(StationCategory.All).Contains(id))
            {
                return(false);
            }

            UnityEngine.Debug.Log("Metro Station Converter: Converting " + info.name);
            var metroEntrance = PrefabCollection <BuildingInfo> .FindLoaded("Metro Entrance");

            var ai = info.GetComponent <PlayerBuildingAI>();

            if (ai == null)
            {
                return(false);
            }

            var stationAi = ai as TransportStationAI;

            if (stationAi != null)
            {
                var item = Stations.GetItem(id);
                if (stationAi.m_transportInfo == PrefabCollection <TransportInfo> .FindLoaded("Metro"))
                {
                    UnityEngine.Debug.LogWarning("Metro Station Converter: " + id + ": already a metro station, no conversion applied.");
                    return(true); //already a metro station
                }

                if (item == null)
                {
                    UnityEngine.Debug.LogWarning("Metro Station Converter: Configuration for station " + id + " not found!");
                    return(false);
                }

                if (item.ToHub)
                {
                    if (stationAi.m_secondaryTransportInfo != null)
                    {
                        UnityEngine.Debug.LogWarning("Station " + id + " already has secondary transport info!");
                        return(false);
                    }

                    stationAi.m_secondaryTransportInfo = PrefabCollection <TransportInfo> .FindLoaded("Metro");

                    var spawnPoints = Util.CommaSeparatedStringToIntArray(item.PartialConversionSpawnPoints);
                    if (stationAi.m_spawnPoints != null)
                    {
                        var spawn1 = new ArrayList();
                        var spawn2 = new ArrayList();
                        for (var i = 0; i < stationAi.m_spawnPoints.Length; i++)
                        {
                            if (spawnPoints.Contains(i))
                            {
                                spawn2.Add(stationAi.m_spawnPoints[i]);
                            }
                            else
                            {
                                spawn1.Add(stationAi.m_spawnPoints[i]);
                            }
                        }

                        stationAi.m_spawnPoints  = (DepotAI.SpawnPoint[])spawn1.ToArray(typeof(DepotAI.SpawnPoint));
                        stationAi.m_spawnPoints2 = (DepotAI.SpawnPoint[])spawn2.ToArray(typeof(DepotAI.SpawnPoint));
                    }
                }
                else
                {
                    info.m_class                  = (ItemClass)ScriptableObject.CreateInstance(nameof(ItemClass));
                    info.m_class.name             = info.name;
                    info.m_class.m_subService     = ItemClass.SubService.PublicTransportMetro;
                    info.m_class.m_service        = ItemClass.Service.PublicTransport;
                    stationAi.m_transportLineInfo = PrefabCollection <NetInfo> .FindLoaded("Metro Line");

                    stationAi.m_transportInfo = PrefabCollection <TransportInfo> .FindLoaded("Metro");
                }
            }

            var item2 = Stations.GetItem(id);

            if (item2.ToDecoration)
            {
                GameObject.Destroy(ai);
                var newAi = info.gameObject.AddComponent <DecorationBuildingAI>();
                info.m_buildingAI    = newAi;
                newAi.m_info         = info;
                newAi.m_allowOverlap = true;
                info.m_placementMode = BuildingInfo.PlacementMode.OnGround;
            }
            else
            {
                ai.m_createPassMilestone = metroEntrance.GetComponent <PlayerBuildingAI>().m_createPassMilestone;
            }

            _uiCategoryfield.SetValue(info, metroEntrance.category);
            info.m_UnlockMilestone = metroEntrance.m_UnlockMilestone;


            if (info.m_paths == null)
            {
                return(true);
            }

            var metroTrack         = FindMetroTrack("Metro Track Ground 01");
            var metroTrackElevated = FindMetroTrack("Metro Track Elevated 01");
            var metroTrackSlope    = FindMetroTrack("Metro Track Slope 01");
            var metroTrackTunnel   = FindMetroTrack("Metro Track");

            var metroStationTrack         = FindMetroTrack("Metro Station Track Ground 01");
            var metroStationTrackElevated = FindMetroTrack("Metro Station Track Elevated 01");
            var metroStationTrackTunnel   = FindMetroTrack("Metro Station Track");

            var hubPathIndices = Util.CommaSeparatedStringToIntArray(item2.PartialConversion);

            for (var i = 0; i < info.m_paths.Length; i++)
            {
                var path = info.m_paths[i];
                if (path?.m_netInfo?.name == null ||
                    path.m_netInfo.m_class?.m_subService != ItemClass.SubService.PublicTransportTrain)
                {
                    continue;
                }

                if (item2.ToHub)
                {
                    if (!hubPathIndices.Contains(i))
                    {
                        continue;
                    }
                }

                if (path.m_netInfo.name.Contains("Train Track Tunnel"))
                {
                    path.m_netInfo = metroTrackTunnel;
                    continue;
                }

                if (path.m_netInfo.name.Contains("Train Track Elevated"))
                {
                    path.m_netInfo = metroTrackElevated;
                    continue;
                }

                if (path.m_netInfo.name.Contains("Train Track Slope"))
                {
                    path.m_netInfo = metroTrackSlope;
                    continue;
                }

                if (path.m_netInfo.name.Contains("Train Station Track Tunnel"))
                {
                    path.m_netInfo = metroStationTrackTunnel;
                    continue;
                }

                if (!path.m_netInfo.name.Contains("Metro") && path.m_netInfo.name.Contains("Station Track Eleva"))
                {
                    path.m_netInfo = metroStationTrackElevated;
                    continue;
                }

                if (path.m_netInfo.name.Contains("Train Station Track"))
                {
                    path.m_netInfo = metroStationTrack;
                    continue;
                }

                if (path.m_netInfo.name.Contains("Train Track"))
                {
                    path.m_netInfo = metroTrack;
                    continue;
                }

                //TODO(earalov): add more More Tracks and ETST tracks ?
            }

            return(true);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="buildinginfo"></param>
 /// <param name="componentRemap"></param>
 private void AdjustBuidingAI(BuildingInfo buildinginfo, Dictionary<Type, Type> componentRemap)
 {
     if (buildinginfo != null && buildinginfo.GetComponent<BuildingAI>() != null)
     {
         BuildingAI component = buildinginfo.GetComponent<BuildingAI>();
         Type originalAiType = component.GetType();
         Type newAIType;
         if (componentRemap.TryGetValue(originalAiType, out newAIType))
         {
             BuildingAI buildingAI = buildinginfo.gameObject.AddComponent(newAIType) as BuildingAI;
             buildingAI.m_info = buildinginfo;
             buildinginfo.m_buildingAI = buildingAI;
             buildingAI.InitializePrefab();
         }
     }
 }
        public static void RecalculateSpawnPoints(BuildingInfo info)
        {
            var buildingAI = info?.GetComponent <TransportStationAI>();
            var paths      = info?.m_paths;

            if (buildingAI == null || paths == null || buildingAI.m_transportLineInfo == null)
            {
                return;
            }
            var allSpawnPoints = (from path in paths
                                  where IsVehicleStop(path)
                                  select new KeyValuePair <Vector3, ItemClass>(GetMiddle(path), path.m_netInfo.m_class)).Distinct()
                                 .ToArray();

            Vector3[] primarySpawnPoints;
            Vector3[] secondarySpawnPoints;

            if (buildingAI.m_secondaryTransportInfo == null)
            {
                primarySpawnPoints   = allSpawnPoints.Select(kvp => kvp.Key).ToArray();
                secondarySpawnPoints = new Vector3[] { };
            }
            else
            {
                primarySpawnPoints = allSpawnPoints
                                     .Where(kvp => kvp.Value.m_subService == buildingAI.m_transportInfo.m_class.m_subService ||
                                            kvp.Value.m_subService == ItemClass.SubService.None &&
                                            kvp.Value.m_service == ItemClass.Service.Road &&
                                            buildingAI.m_transportInfo.m_class.m_subService ==
                                            ItemClass.SubService.PublicTransportBus)
                                     .Select(kvp => kvp.Key)
                                     .ToArray();
                secondarySpawnPoints = allSpawnPoints
                                       .Where(kvp => kvp.Value.m_subService == buildingAI.m_secondaryTransportInfo.m_class.m_subService ||
                                              kvp.Value.m_subService == ItemClass.SubService.None &&
                                              kvp.Value.m_service == ItemClass.Service.Road &&
                                              buildingAI.m_secondaryTransportInfo.m_class.m_subService ==
                                              ItemClass.SubService.PublicTransportBus)
                                       .Select(kvp => kvp.Key)
                                       .ToArray();
            }


            if (!(buildingAI.m_transportLineInfo.m_class.m_service == ItemClass.Service.PublicTransport &&
                  (buildingAI.m_transportLineInfo.m_class.m_subService == ItemClass.SubService.PublicTransportShip ||
                   buildingAI.m_transportLineInfo.m_class.m_subService == ItemClass.SubService.PublicTransportPlane) &&
                  buildingAI.m_transportLineInfo.m_class.m_level == ItemClass.Level.Level2))
            {
                switch (primarySpawnPoints.Length)
                {
                case 0:
                    buildingAI.m_spawnPosition = Vector3.zero;
                    buildingAI.m_spawnTarget   = Vector3.zero;
                    buildingAI.m_spawnPoints   = new DepotAI.SpawnPoint[] { };
                    break;

                case 1:
                    buildingAI.m_spawnPosition = primarySpawnPoints[0];
                    buildingAI.m_spawnTarget   = primarySpawnPoints[0];
                    buildingAI.m_spawnPoints   = new[]
                    {
                        new DepotAI.SpawnPoint
                        {
                            m_position = primarySpawnPoints[0],
                            m_target   = primarySpawnPoints[0]
                        }
                    };
                    break;

                default:
                    buildingAI.m_spawnPosition = Vector3.zero;
                    buildingAI.m_spawnTarget   = Vector3.zero;
                    buildingAI.m_spawnPoints   = primarySpawnPoints.Select(p => new DepotAI.SpawnPoint
                    {
                        m_position = p,
                        m_target   = p
                    })
                                                 .ToArray();
                    break;
                }
            }

            if (buildingAI.m_secondaryTransportInfo != null &&
                !(buildingAI.m_secondaryTransportInfo.m_class.m_service == ItemClass.Service.PublicTransport &&
                  (buildingAI.m_secondaryTransportInfo.m_class.m_subService == ItemClass.SubService.PublicTransportShip ||
                   buildingAI.m_secondaryTransportInfo.m_class.m_subService == ItemClass.SubService.PublicTransportPlane) &&
                  buildingAI.m_secondaryTransportInfo.m_class.m_level == ItemClass.Level.Level2))
            {
                switch (secondarySpawnPoints.Length)
                {
                case 0:
                    buildingAI.m_spawnPosition2 = Vector3.zero;
                    buildingAI.m_spawnTarget2   = Vector3.zero;
                    buildingAI.m_spawnPoints2   = new DepotAI.SpawnPoint[] { };
                    break;

                case 1:
                    buildingAI.m_spawnPosition2 = secondarySpawnPoints[0];
                    buildingAI.m_spawnTarget2   = secondarySpawnPoints[0];
                    buildingAI.m_spawnPoints2   = new[]
                    {
                        new DepotAI.SpawnPoint
                        {
                            m_position = secondarySpawnPoints[0],
                            m_target   = secondarySpawnPoints[0]
                        }
                    };
                    break;

                default:
                    buildingAI.m_spawnPosition2 = Vector3.zero;
                    buildingAI.m_spawnTarget2   = Vector3.zero;
                    buildingAI.m_spawnPoints2   = secondarySpawnPoints.Select(p => new DepotAI.SpawnPoint
                    {
                        m_position = p,
                        m_target   = p
                    })
                                                  .ToArray();
                    break;
                }
            }
        }
Exemple #13
0
        public static bool Convert(BuildingInfo info)
        {
            long id;

            if (!Util.TryGetWorkshopId(info, out id) || !Stations.GetConvertedIds(StationCategory.All).Contains(id))
            {
                return(false);
            }

            UnityEngine.Debug.Log("Converting " + info.name);
            var metroEntrance = PrefabCollection <BuildingInfo> .FindLoaded("Metro Entrance");

            var ai = info.GetComponent <PlayerBuildingAI>();

            if (ai == null)
            {
                return(false);
            }

            var stationAi = ai as TransportStationAI;

            if (stationAi != null)
            {
                var item = Stations.GetItem(id);
                if (stationAi.m_transportInfo == PrefabCollection <TransportInfo> .FindLoaded("Metro"))
                {
                    return(true); //already a metro station
                }

                if (item == null)
                {
                    UnityEngine.Debug.LogWarning("Configuration for station " + id + " not found!");
                    return(false);
                }

                if (item.ToHub)
                {
                    if (stationAi.m_secondaryTransportInfo != null)
                    {
                        UnityEngine.Debug.LogWarning("Station " + id + " already has secondary transport info!");
                        return(false);
                    }

                    stationAi.m_secondaryTransportInfo = PrefabCollection <TransportInfo> .FindLoaded("Metro");

                    stationAi.m_maxVehicleCount2 = 0;
                    var spawnPoints = Util.CommaSeparatedStringToIntArray(item.ParialConversionSpawnPoints);
                    if (stationAi.m_spawnPoints != null)
                    {
                        var spawn1 = new ArrayList();
                        var spawn2 = new ArrayList();
                        for (var i = 0; i < stationAi.m_spawnPoints.Length; i++)
                        {
                            if (spawnPoints.Contains(i))
                            {
                                spawn2.Add(stationAi.m_spawnPoints[i]);
                            }
                            else
                            {
                                spawn1.Add(stationAi.m_spawnPoints[i]);
                            }
                        }

                        stationAi.m_spawnPoints  = (DepotAI.SpawnPoint[])spawn1.ToArray(typeof(DepotAI.SpawnPoint));
                        stationAi.m_spawnPoints2 = (DepotAI.SpawnPoint[])spawn2.ToArray(typeof(DepotAI.SpawnPoint));
                    }
                }
                else
                {
                    info.m_class                  = (ItemClass)ScriptableObject.CreateInstance(nameof(ItemClass));
                    info.m_class.name             = info.name;
                    info.m_class.m_subService     = ItemClass.SubService.PublicTransportMetro;
                    info.m_class.m_service        = ItemClass.Service.PublicTransport;
                    stationAi.m_transportLineInfo = PrefabCollection <NetInfo> .FindLoaded("Metro Line");

                    stationAi.m_transportInfo = PrefabCollection <TransportInfo> .FindLoaded("Metro");

                    stationAi.m_maxVehicleCount = 0;
                }
            }

            var item2 = Stations.GetItem(id);

            if (item2.ToDecoration)
            {
                GameObject.Destroy(ai);
                var newAi = info.gameObject.AddComponent <DecorationBuildingAI>();
                info.m_buildingAI    = newAi;
                newAi.m_info         = info;
                newAi.m_allowOverlap = true;
                info.m_placementMode = BuildingInfo.PlacementMode.OnGround;
            }
            else
            {
                ai.m_createPassMilestone = metroEntrance.GetComponent <PlayerBuildingAI>().m_createPassMilestone;
            }

            _uiCategoryfield.SetValue(info, metroEntrance.category);
            info.m_UnlockMilestone = metroEntrance.m_UnlockMilestone;


            if (info.m_paths == null)
            {
                return(true);
            }

            var styleConverter = Stations.GetCategory(id) == StationCategory.Old
                ? new Func <string, string>(s => "Steel " + s)
                : (s => s);
            var nameConverter = item2.BarsType == BarsType.NoBar
                ? new Func <string, string>(s =>
                                            s.Contains("Station") || !s.Contains("Elevated") && !s.Contains("Ground") &&
                                            !s.Contains("Sunken") && !s.Contains("Bridge")
                        ? styleConverter.Invoke(s)
                        : styleConverter.Invoke(s) + " NoBar")
                : (s => styleConverter.Invoke(s));

            var metroTrack         = FindMetroTrackWithFallback(nameConverter, "Metro Track Ground");
            var metroTrackElevated = FindMetroTrackWithFallback(nameConverter, "Metro Track Elevated");
            var metroTrackSlope    = FindMetroTrackWithFallback(nameConverter, "Metro Track Slope");
            var metroTrackTunnel   = FindMetroTrackWithFallback(nameConverter, "Metro Track");

            var metroStationTrack        = FindMetroTrackWithFallback(nameConverter, "Metro Station Track Ground");
            var metroStationTracElevated = FindMetroTrackWithFallback(nameConverter, "Metro Station Track Elevated");
            var metroStationTracSunken   = FindMetroTrackWithFallback(nameConverter, "Metro Station Track Sunken");

            var metroTrackSmall         = FindMetroTrackWithFallback(nameConverter, "Metro Track Ground Small");
            var metroTrackElevatedSmall = FindMetroTrackWithFallback(nameConverter, "Metro Track Elevated Small");
            var metroTrackSlopeSmall    = FindMetroTrackWithFallback(nameConverter, "Metro Track Slope Small");
            var metroTrackTunnelSmall   = FindMetroTrackWithFallback(nameConverter, "Metro Track Small");

            var metroStationTrackSmall  = FindMetroTrackWithFallback(nameConverter, "Metro Station Track Ground Small");
            var metroStationTrackIsland =
                FindMetroTrackWithFallback(nameConverter, "Metro Station Track Ground Island");

            var hubPathIndices = Util.CommaSeparatedStringToIntArray(item2.ParialConversion);

            for (var i = 0; i < info.m_paths.Length; i++)
            {
                var path = info.m_paths[i];
                if (path?.m_netInfo?.name == null ||
                    path.m_netInfo.m_class?.m_subService != ItemClass.SubService.PublicTransportTrain)
                {
                    continue;
                }

                if (item2.ToHub)
                {
                    if (!hubPathIndices.Contains(i))
                    {
                        continue;
                    }
                }

                if (path.m_netInfo.name.Contains("Wide Train Station Track"))
                {
                    if (metroStationTrackIsland != null)
                    {
                        path.m_netInfo = metroStationTrackIsland;
                    }

                    continue;
                }


                if (path.m_netInfo.name.Contains("Rail1LStation"))
                {
                    if (metroStationTrackSmall != null)
                    {
                        path.m_netInfo = metroStationTrackSmall;
                    }

                    continue;
                }

                if (path.m_netInfo.name.Contains("Train Oneway Track Elevated"))
                {
                    if (metroTrackElevatedSmall != null)
                    {
                        path.m_netInfo = metroTrackElevatedSmall;
                    }

                    continue;
                }

                if (path.m_netInfo.name.Contains("Train Oneway Track Slope"))
                {
                    if (metroTrackSlopeSmall != null)
                    {
                        path.m_netInfo = metroTrackSlopeSmall;
                    }

                    continue;
                }

                if (path.m_netInfo.name.Contains("Train Oneway Track Tunnel"))
                {
                    if (metroTrackTunnelSmall != null)
                    {
                        path.m_netInfo = metroTrackTunnelSmall;
                    }

                    continue;
                }

                if (path.m_netInfo.name.Contains("Rail1L") || path.m_netInfo.name.Contains("Train Oneway Track"))
                {
                    if (metroTrackSmall != null)
                    {
                        path.m_netInfo = metroTrackSmall;
                    }

                    continue;
                }

                if (metroTrackTunnel != null)
                {
                    if (path.m_netInfo.name.Contains("Train Track Tunnel"))
                    {
                        path.m_netInfo = metroTrackTunnel;
                        continue;
                    }
                }

                if (metroTrackElevated != null)
                {
                    if (path.m_netInfo.name.Contains("Train Track Elevated"))
                    {
                        path.m_netInfo = metroTrackElevated;
                        continue;
                    }
                }

                if (metroTrackSlope != null)
                {
                    if (path.m_netInfo.name.Contains("Train Track Slope"))
                    {
                        path.m_netInfo = metroTrackSlope;
                        continue;
                    }
                }

                if (metroStationTracElevated != null)
                {
                    if (path.m_netInfo.name.Contains("Station Track Eleva"))
                    {
                        path.m_netInfo = metroStationTracElevated;
                        continue;
                    }
                }

                if (metroStationTracSunken != null)
                {
                    if (path.m_netInfo.name.Contains("Station Track Sunken"))
                    {
                        path.m_netInfo = metroStationTracSunken;
                        continue;
                    }
                }

                if (metroStationTrack != null)
                {
                    if (path.m_netInfo.name.Contains("Train Station Track"))
                    {
                        path.m_netInfo = metroStationTrack;
                        continue;
                    }
                }

                if (metroTrack != null)
                {
                    if (path.m_netInfo.name.Contains("Train Track"))
                    {
                        path.m_netInfo = metroTrack;
                        continue;
                    }
                }

                //TODO(earalov): add more More Tracks and ETST tracks ?
            }

            return(true);
        }
Exemple #14
0
        void RemoveSkippedFromBuilding(BuildingInfo info)
        {
            BuildingInfo.Prop[] props = info.m_props;

            if (props == null || props.Length == 0)
            {
                return;
            }

            try
            {
                //StreamWriter wp = new StreamWriter(Path.Combine(Util.GetSavePath(), "Building-props.txt"), true);
                //wp.WriteLine(info.name);
                List <BuildingInfo.Prop> keepThese = new List <BuildingInfo.Prop>(props.Length);
                bool skippedSome = false;

                for (int i = 0; i < props.Length; i++)
                {
                    BuildingInfo.Prop prop = props[i];

                    if (prop == null)
                    {
                        continue;
                    }
                    //if (prop.m_prop != null)
                    //    wp.WriteLine("  " + prop.m_prop.name);
                    if (prop.m_prop == null)
                    {
                        keepThese.Add(prop);
                    }
                    else if (Skip(prop.m_prop))
                    {
                        //Util.DebugPrint(prop.m_prop.name, "-> RemoveSkippedFromBuilding at", Profiling.Millis, "/", info.name);
                        prop.m_prop = prop.m_finalProp = null;
                        skippedSome = true;
                    }
                    else
                    {
                        keepThese.Add(prop);
                    }
                }

                if (skippedSome)
                {
                    info.m_props = keepThese.ToArray();

                    if (info.m_props.Length == 0)
                    {
                        // Less log clutter.
                        if (info.m_buildingAI is CommonBuildingAI cbai)
                        {
                            cbai.m_ignoreNoPropsWarning = true;
                        }
                        else if (info.GetComponent <BuildingAI>() is CommonBuildingAI cbai2)
                        {
                            cbai2.m_ignoreNoPropsWarning = true;
                        }
                    }
                }

                keepThese.Clear();
                //wp.Close();
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogException(e);
            }
        }