示例#1
0
 private static CatenaryType GetCatenaryType(ICollection <PropInfo> defaultCatenaries)
 {
     foreach (var prop in defaultCatenaries)
     {
         if (CatenaryUtils.IsQuadRailNormalCatenaryProp(prop))
         {
             return(CatenaryType.TrainQuad);
         }
         else if (CatenaryUtils.IsDoubleRailNormalCatenaryProp(prop))
         {
             return(CatenaryType.TrainDouble);
         }
         else if (CatenaryUtils.IsSingleRailNormalCatenaryProp(prop))
         {
             return(CatenaryType.TrainSingle);
         }
         else if (CatenaryUtils.IsTramPoleSideProp(prop))
         {
             return(CatenaryType.TramPoleSide);
         }
         else if (CatenaryUtils.IsTramPoleCenterProp(prop))
         {
             return(CatenaryType.TramPoleCenter);
         }
     }
     return(CatenaryType.TrainDouble);
 }
示例#2
0
 private void ReplaceWithTunnelCatenary(NetworkSkin skin, int l, int p)
 {
     skin.UpdateLaneProp(l, p, laneProp2 =>
     {
         laneProp2.m_prop      = _tunnelCatenary;
         laneProp2.m_finalProp = _tunnelCatenary;
         CatenaryUtils.CorrectCatenaryPropAngleAndPosition(laneProp2);
     });
 }
示例#3
0
        private static void RemoveWireSegments(NetworkSkin skin)
        {
            if (skin.m_segments == null)
            {
                return;
            }

            for (var s = skin.m_segments.Length - 1; s >= 0; s--)
            {
                var segment = skin.m_segments[s];
                if (CatenaryUtils.IsWireSegment(segment))
                {
                    skin.RemoveSegment(s);
                }
            }
        }
        private Dictionary <NetInfo, PropInfo> GetDefaultCatenaries()
        {
            var defaultCatenaries = new Dictionary <NetInfo, PropInfo>();

            var groundCatenary = CatenaryUtils.GetDefaultNormalCatenary(Prefab);

            if (groundCatenary != null)
            {
                defaultCatenaries[Prefab] = groundCatenary;
            }

            var slopePrefab = NetUtils.GetSlopePrefab(Prefab);

            if (slopePrefab != null)
            {
                var slopeCatenary = CatenaryUtils.GetDefaultNormalCatenary(slopePrefab);
                if (slopeCatenary != null)
                {
                    defaultCatenaries[slopePrefab] = slopeCatenary;
                }
            }

            var elevatedPrefab = NetUtils.GetElevatedPrefab(Prefab);

            if (elevatedPrefab != null)
            {
                var elevatedCatenary = CatenaryUtils.GetDefaultNormalCatenary(elevatedPrefab);
                if (elevatedCatenary != null)
                {
                    defaultCatenaries[elevatedPrefab] = elevatedCatenary;
                }
            }

            var bridgePrefab = NetUtils.GetBridgePrefab(Prefab);

            if (bridgePrefab != null)
            {
                var bridgeCatenary = CatenaryUtils.GetDefaultNormalCatenary(bridgePrefab);
                if (bridgeCatenary != null)
                {
                    defaultCatenaries[bridgePrefab] = bridgeCatenary;
                }
            }

            return(defaultCatenaries);
        }
        private bool IsCatenaryProp(PropInfo prefab, CatenaryType type)
        {
            switch (type)
            {
            case CatenaryType.TrainDouble:
                return(CatenaryUtils.IsDoubleRailNormalCatenaryProp(prefab));

            case CatenaryType.TrainSingle:
                return(CatenaryUtils.IsSingleRailNormalCatenaryProp(prefab));

            case CatenaryType.TramPoleSide:
                return(CatenaryUtils.IsTramPoleSideProp(prefab));

            case CatenaryType.TramPoleCenter:
                return(CatenaryUtils.IsTramPoleCenterProp(prefab));

            default:
                return(false);
            }
        }
        private List <PropInfo> GetAvailableCatenaries(CatenaryType type)
        {
            var catenaries = new List <PropInfo>();

            var prefabCount = PrefabCollection <PropInfo> .LoadedCount();

            for (uint prefabIndex = 0; prefabIndex < prefabCount; prefabIndex++)
            {
                var prefab = PrefabCollection <PropInfo> .GetLoaded(prefabIndex);

                if (IsCatenaryProp(prefab, type) && CatenaryUtils.IsCatenaryPropVisibeInUI(prefab))
                {
                    catenaries.Add(prefab);
                }
            }

            catenaries.Sort((a, b) => string.Compare(a.GetUncheckedLocalizedTitle(), b.GetUncheckedLocalizedTitle(), StringComparison.Ordinal));

            return(catenaries);
        }
示例#7
0
        private static void RemoveCatenaries(NetworkSkin skin)
        {
            if (skin.m_lanes == null)
            {
                return;
            }

            for (var l = 0; l < skin.m_lanes.Length; l++)
            {
                if (skin.m_lanes[l]?.m_laneProps?.m_props == null)
                {
                    continue;
                }

                for (var p = skin.m_lanes[l].m_laneProps.m_props.Length - 1; p >= 0; p--)
                {
                    var finalProp = skin.m_lanes[l].m_laneProps.m_props[p]?.m_finalProp;
                    if (CatenaryUtils.IsNormalCatenaryProp(finalProp) || CatenaryUtils.IsEndCatenaryProp(finalProp) || CatenaryUtils.IsTunnelCatenaryProp(finalProp))
                    {
                        skin.RemoveLaneProp(l, p);
                    }
                }
            }
        }
示例#8
0
        private void UpdateCatenaries(NetworkSkin skin)
        {
            if (skin.m_lanes == null)
            {
                return;
            }

            // TODO implement tunnel cats
            //var tunnelCatenary = CatenaryUtils.GetEndCatenary(Catenary);

            for (var l = 0; l < skin.m_lanes.Length; l++)
            {
                if (skin.m_lanes[l]?.m_laneProps?.m_props == null)
                {
                    continue;
                }

                for (var p = skin.m_lanes[l].m_laneProps.m_props.Length - 1; p >= 0; p--)
                {
                    var laneProp = skin.m_lanes[l].m_laneProps.m_props[p];
                    if (laneProp?.m_finalProp == null)
                    {
                        continue;
                    }

                    if (CatenaryUtils.IsNormalCatenaryProp(laneProp.m_finalProp) || CatenaryUtils.IsEndCatenaryProp(laneProp.m_finalProp))
                    {
                        if (Catenary == _endCatenary)
                        {
                            ReplaceWithNormalCatenary(skin, l, p);
                        }
                        else
                        {
                            // Start node catenary
                            if (laneProp.m_segmentOffset == -1f)
                            {
                                // Start-of-track node
                                if ((laneProp.m_startFlagsRequired & NetNode.Flags.End) != 0)
                                {
                                    ReplaceWithEndCatenary(skin, l, p);
                                }
                                // Mid-track node
                                else if ((laneProp.m_startFlagsForbidden & NetNode.Flags.End) != 0)
                                {
                                    ReplaceWithNormalCatenary(skin, l, p);
                                }
                                // Vanilla rail: Create separate lane prop for start-of-track
                                else
                                {
                                    skin.CopyAndUpdateLaneProp(l, p, laneProp2 =>
                                    {
                                        laneProp2.m_prop                = _endCatenary;
                                        laneProp2.m_finalProp           = _endCatenary;
                                        laneProp2.m_startFlagsRequired |= NetNode.Flags.End;
                                        CatenaryUtils.CorrectCatenaryPropAngleAndPosition(laneProp2);
                                    });
                                    skin.UpdateLaneProp(l, p, laneProp2 =>
                                    {
                                        laneProp2.m_prop                 = Catenary;
                                        laneProp2.m_finalProp            = Catenary;
                                        laneProp2.m_startFlagsForbidden |= NetNode.Flags.End;
                                        CatenaryUtils.CorrectCatenaryPropAngleAndPosition(laneProp2);
                                    });
                                }
                            }

                            // End node catenary
                            else if (laneProp.m_segmentOffset == 1f)
                            {
                                // End-of-track node
                                if ((laneProp.m_endFlagsRequired & NetNode.Flags.End) != 0)
                                {
                                    ReplaceWithEndCatenary(skin, l, p);
                                }
                                // Mid-track node
                                else if ((laneProp.m_endFlagsForbidden & NetNode.Flags.End) != 0)
                                {
                                    ReplaceWithNormalCatenary(skin, l, p);
                                }
                                // Vanilla rail: Create separate lane prop for end-of-track
                                else
                                {
                                    skin.CopyAndUpdateLaneProp(l, p, laneProp2 =>
                                    {
                                        laneProp2.m_prop              = _endCatenary;
                                        laneProp2.m_finalProp         = _endCatenary;
                                        laneProp2.m_endFlagsRequired |= NetNode.Flags.End;
                                        CatenaryUtils.CorrectCatenaryPropAngleAndPosition(laneProp2);
                                    });
                                    skin.UpdateLaneProp(l, p, laneProp2 =>
                                    {
                                        laneProp2.m_prop               = Catenary;
                                        laneProp2.m_finalProp          = Catenary;
                                        laneProp2.m_endFlagsForbidden |= NetNode.Flags.End;
                                        CatenaryUtils.CorrectCatenaryPropAngleAndPosition(laneProp2);
                                    });
                                }
                            }

                            // Mid-segment catenary
                            else
                            {
                                ReplaceWithNormalCatenary(skin, l, p);
                            }
                        }
                    }
                    else if (CatenaryUtils.IsTunnelCatenaryProp(laneProp.m_finalProp))
                    {
                        if (_tunnelCatenary != null)
                        {
                            ReplaceWithTunnelCatenary(skin, l, p);
                        }
                    }
                }
            }
        }
示例#9
0
 public CatenaryModifier(PropInfo catenary) : base(NetworkSkinModifierType.Catenary)
 {
     Catenary        = catenary;
     _endCatenary    = CatenaryUtils.GetEndCatenary(catenary);
     _tunnelCatenary = CatenaryUtils.GetTunnelCatenary(catenary);
 }