Example #1
0
        /// <summary>
        /// Determine the trackItems and their location in the given tracknode.
        /// </summary>
        /// <param name="tn">The tracknode in which to search for track items</param>
        /// <returns>The list/set of track itemss together with their position information</returns>
        public IEnumerable <ChartableTrackItem> GetItemsInTracknode(TrackNode tn)
        {
            if (cachedItems.ContainsKey(tn))
            {
                return(cachedItems[tn]);
            }

            List <ChartableTrackItem> tracknodeItems = new List <ChartableTrackItem>();
            TrVectorNode vectorNode = tn.TrVectorNode;

            if (vectorNode.TrItemRefs == null)
            {
                return(tracknodeItems);
            }

            foreach (int trackItemIndex in vectorNode.TrItemRefs)
            {
                TrItem trItem = trackDB.TrItemTable[trackItemIndex];
                if (supportedTrackTypes.Contains(trItem.ItemType))
                {
                    var travellerAtItem = new Traveller(tsectionDat, trackDB.TrackNodes, tn,
                                                        trItem.TileX, trItem.TileZ, trItem.X, trItem.Z, Traveller.TravellerDirection.Forward);

                    if (travellerAtItem != null)
                    {
                        tracknodeItems.Add(new ChartableTrackItem(trItem, travellerAtItem));
                    }
                }
            }
            tracknodeItems.Sort(new AlongTrackComparer());
            cachedItems[tn] = tracknodeItems;
            return(tracknodeItems);
        }
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="originalTrItem">The original track item that we are representing for drawing</param>
        public DrawablePlatformItem(TrItem originalTrItem)
            : base(originalTrItem)
        {
            Description = "platform";
            PlatformItem platform = originalTrItem as PlatformItem;

            this.itemName    = platform.ItemName;
            this.stationName = platform.Station;
        }
Example #3
0
 public TrackPDP(TrItem item)
 {
     TileX        = item.TileX;
     TileZ        = item.TileZ;
     X            = item.X;
     Y            = item.Y;
     Z            = item.Z;
     junctionFlag = 0;
     invalidFlag  = 0;
 }
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="originalTrItem">The original track item that we are representing for drawing</param>
        public DrawableSignalItem(TrItem originalTrItem)
            : base(originalTrItem)
        {
            this.Description = "signal";
            this.isNormal    = true; // default value
            SignalItem originalSignalItem = originalTrItem as SignalItem;

            this.direction  = originalSignalItem.Direction == 0 ? Traveller.TravellerDirection.Forward : Traveller.TravellerDirection.Backward;
            this.signalType = originalSignalItem.SignalType;
        }
Example #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="item"></param>
 /// <param name="signal"></param>
 public AESignalItem(SignalItem item, SignalObject signal, TDBFile TDB)
 {
     typeWidget  = (int)TypeWidget.SIGNAL_WIDGET;
     Item        = item;
     Signal      = signal;
     sigFonction = new List <SignalHead.MstsSignalFunction>();
     foreach (var sig in Signal.SignalHeads)
     {
         sigFonction.Add(sig.sigFunction);
         if (sig.sigFunction == SignalHead.MstsSignalFunction.SPEED)
         {
             File.AppendAllText(@"C:\temp\AE.txt", "SPEED\n");
         }
     }
     foreach (var fn in sigFonction)
     {
         File.AppendAllText(@"C:\temp\AE.txt", "FN " + fn + "\n");
     }
     hasDir     = false;
     Location.X = item.TileX * 2048 + item.X;
     Location.Y = item.TileZ * 2048 + item.Z;
     try
     {
         var     node = TDB.TrackDB.TrackNodes[signal.trackNode];
         Vector2 v2;
         if (node.TrVectorNode != null)
         {
             var ts = node.TrVectorNode.TrVectorSections[0];
             v2 = new Vector2(ts.TileX * 2048 + ts.X, ts.TileZ * 2048 + ts.Z);
         }
         else if (node.TrJunctionNode != null)
         {
             var ts = node.UiD;
             v2 = new Vector2(ts.TileX * 2048 + ts.X, ts.TileZ * 2048 + ts.Z);
         }
         else
         {
             throw new Exception();
         }
         var v1 = new Vector2(Location.X, Location.Y);
         var v3 = v1 - v2;
         v3.Normalize();
         //v2 = v1 - Vector2.Multiply(v3, signal.direction == 0 ? 12f : -12f);
         v2    = v1 - Vector2.Multiply(v3, 12f);
         Dir.X = (float)v2.X;
         Dir.Y = (float)v2.Y;
         //v2 = v1 - Vector2.Multiply(v3, signal.direction == 0 ? 1.5f : -1.5f);//shift signal along the dir for 2m, so signals will not be overlapped
         v2         = v1 - Vector2.Multiply(v3, 1.5f);
         Location.X = (float)v2.X;
         Location.Y = (float)v2.Y;
         hasDir     = true;
     }
     catch { }
 }
        public TrackPDP SearchNextPathNode(TrackPDP endPoint)
        {
            TrItem   trItem  = null;
            TrackPDP newNode = null;

            trItem = searchTraveller.MoveToNextItem(AllItems, (int)endPoint.TileX, (int)endPoint.TileZ, endPoint.X, endPoint.Z);
            if (trItem != null)
            {
                //newNode = new TrackPDP(trItem);
            }

            return(newNode);
        }
Example #7
0
        protected void addTrItem(TrackSegment lineSeg, TrItem item)
        {
            AETraveller travel = new AETraveller(traveller);

            if (item.ItemType == TrItem.trItemType.trSIDING || item.ItemType == TrItem.trItemType.trPLATFORM)
            {
                SideItem siding = mstsItems.AddSiding(lineSeg, item, travel);
                orRouteConfig.AddItem((GlobalItem)siding);
            }
            else if (item.ItemType == TrItem.trItemType.trCROSSOVER)
            {
                AECrossOver crossOver = mstsItems.AddCrossOver(lineSeg, item, travel);
                orRouteConfig.AddItem((GlobalItem)crossOver);
            }
        }
Example #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sideItem"></param>
 /// <param name="signal"></param>
 public AESignalItem(SignalItem item, AESignalObject signal, TrackDatabaseFile TDB)
 {
     typeItem    = (int)TypeItem.SIGNAL_ITEM;
     Item        = item;
     Signal      = signal;
     sigFonction = new List <MstsSignalFunction>();
     foreach (var sig in Signal.SignalHeads)
     {
         sigFonction.Add(sig.sigFunction);
     }
     hasDir     = false;
     Location.X = item.TileX * 2048 + item.X;
     Location.Y = item.TileZ * 2048 + item.Z;
     try
     {
         associateNode = TDB.TrackDB.TrackNodes[signal.trackNode];
         Vector2 v2;
         if (associateNode.TrVectorNode != null)
         {
             associateNodeIdx = (int)associateNode.Index;
             var ts = associateNode.TrVectorNode.TrVectorSections[0];
             v2 = new Vector2(ts.TileX * 2048 + ts.X, ts.TileZ * 2048 + ts.Z);
         }
         else if (associateNode.TrJunctionNode != null)
         {
             associateNodeIdx = associateNode.TrJunctionNode.Idx;
             var ts = associateNode.UiD;
             v2 = new Vector2(ts.TileX * 2048 + ts.X, ts.TileZ * 2048 + ts.Z);
         }
         else
         {
             throw new Exception();
         }
         var v1 = new Vector2(Location.X, Location.Y);
         var v3 = v1 - v2;
         v3.Normalize();
         v2 = v1 - Vector2.Multiply(v3, signal.direction == 0 ? 12f : -12f);
         //v2 = v1 - Vector2.Multiply(v3, 12f);
         Dir.X = (float)v2.X;
         Dir.Y = (float)v2.Y;
         //v2 = v1 - Vector2.Multiply(v3, signal.direction == 0 ? 1.5f : -1.5f);//shift signal along the dir for 2m, so signals will not be overlapped
         v2         = v1 - Vector2.Multiply(v3, 1.5f);
         Location.X = (float)v2.X;
         Location.Y = (float)v2.Y;
         hasDir     = true;
     }
     catch { }
 }
 /// <summary>
 /// Factory method. This will return a proper subclass of DrawableTrackItem that represents the correct type of track item.
 /// </summary>
 /// <param name="originalTrItem">The original track item that needs to be represented while drawing</param>
 /// <returns>A drawable trackitem, with proper subclass</returns>
 public static DrawableTrackItem CreateDrawableTrItem(TrItem originalTrItem)
 {
     if (originalTrItem is SignalItem)
     {
         return(new DrawableSignalItem(originalTrItem));
     }
     if (originalTrItem is PlatformItem)
     {
         return(new DrawablePlatformItem(originalTrItem));
     }
     if (originalTrItem is SidingItem)
     {
         return(new DrawableSidingItem(originalTrItem));
     }
     if (originalTrItem is SpeedPostItem)
     {
         return(new DrawableSpeedPostItem(originalTrItem));
     }
     if (originalTrItem is HazzardItem)
     {
         return(new DrawableHazardItem(originalTrItem));
     }
     if (originalTrItem is PickupItem)
     {
         return(new DrawablePickupItem(originalTrItem));
     }
     if (originalTrItem is LevelCrItem)
     {
         return(new DrawableLevelCrItem(originalTrItem));
     }
     if (originalTrItem is SoundRegionItem)
     {
         return(new DrawableSoundRegionItem(originalTrItem));
     }
     if (originalTrItem is RoadLevelCrItem)
     {
         return(new DrawableRoadLevelCrItem(originalTrItem));
     }
     if (originalTrItem is CarSpawnerItem)
     {
         return(new DrawableCarSpawnerItem(originalTrItem));
     }
     if (originalTrItem is CrossoverItem)
     {
         return(new DrawableCrossoverItem(originalTrItem));
     }
     return(new DrawableEmptyItem(originalTrItem));
 }
Example #10
0
 /// <summary>
 /// Try to load the file.
 /// Possibly this might raise an exception. That exception is not caught here
 /// </summary>
 /// <param name="file">The file that needs to be loaded</param>
 public override void TryLoading(string file)
 {
     TrItem[] items;
     if (_TDB == null)
     {
         //It is not clear that 10000 items is enough, which would give wrong warnings
         Console.WriteLine("");
         Console.Write("  Not using the proper .tdb, but just an empty array of TrItems for loading the .ws file: ");
         items = new TrItem[100000];
     }
     else
     {
         items = _TDB.TrItemTable;
     }
     var wf = new WorldSoundFile(file, items);
 }
Example #11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="item"></param>
 /// <param name="signal"></param>
 public AESidingItem(TrItem item)
 {
     typeWidget = (int)TypeWidget.SIDING_WIDGET;
     if (Item1 == null)
     {
         Item1    = item;
         Name     = Item1.ItemName;
         Location = new PointF(Item1.TileX * 2048f + Item1.X, Item1.TileZ * 2048f + Item1.Z);
         type     = Item1.ItemType;
     }
     else
     {
         Item2 = item;
     }
     sizeSiding = 0;
 }
Example #12
0
        /// <summary>
        /// The underlying track sideItem.
        /// </summary>

        public SideEndItem(TrackSegment trSegment, TrItem item, SideStartItem siding)
        {
            if (siding == null)
            {
                return;
            }
            typeItem    = siding.typeItem;
            type        = siding.trItem.ItemType;
            startSiding = siding;
            if (siding.sizeSiding != item.SData1)
            {
                sizeSiding = item.SData1 - siding.sizeSiding;
            }
            typeSiding = (int)TypeSiding.SIDING_END;
            trItem     = item;
            Location   = new PointF(trItem.TileX * 2048f + trItem.X, trItem.TileZ * 2048f + trItem.Z);
        }
Example #13
0
        /// <summary>
        /// The underlying track sideItem.
        /// </summary>

        /// <param name="sideItem"></param>
        /// <param name="signal"></param>
        public SideStartItem(TrackSegment trSegment, TrItem item)
        {
            if (item.ItemType == TrItem.trItemType.trPLATFORM)
            {
                typeSiding = (int)TypeSiding.PLATFORM_START;
            }
            else if (item.ItemType == TrItem.trItemType.trSIDING)
            {
                typeSiding = (int)TypeSiding.SIDING_START;
            }
            typeItem = (int)TypeItem.SIDING_START;

            trItem     = item;
            Name       = trItem.ItemName;
            Location   = new PointF(trItem.TileX * 2048f + trItem.X, trItem.TileZ * 2048f + trItem.Z);
            type       = trItem.ItemType;
            sizeSiding = item.SData1;
        }
Example #14
0
        private List <string> StationNamesBetweenNodes(TrainpathNode firstNode, TrainpathNode secondNode)
        {
            var stationNames = new List <string>();
            int tvnIndex     = firstNode.NextMainTvnIndex;

            if (tvnIndex < 0)
            {
                return(stationNames);
            }

            TrackNode    tn  = trackDB.TrackNodes[tvnIndex];
            TrVectorNode tvn = tn.TrVectorNode;

            if (tvn == null)
            {
                return(stationNames);
            }
            if (tvn.TrItemRefs == null)
            {
                return(stationNames);
            }

            foreach (int trackItemIndex in tvn.TrItemRefs)
            {
                TrItem trItem = trackDB.TrItemTable[trackItemIndex];
                if (trItem.ItemType == TrItem.trItemType.trPLATFORM)
                {
                    var traveller = new Traveller(tsectionDat, trackDB.TrackNodes, tn,
                                                  trItem.TileX, trItem.TileZ, trItem.X, trItem.Z, Traveller.TravellerDirection.Forward);
                    if (traveller != null)
                    {
                        var platformNode = new TrainpathVectorNode(firstNode, traveller);
                        if (platformNode.IsBetween(firstNode, secondNode))
                        {
                            PlatformItem platform = trItem as PlatformItem;
                            stationNames.Add(platform.Station);
                        }
                    }
                }
            }

            return(stationNames);
        }
Example #15
0
        /// <summary>
        /// Add information from platform and station name
        /// </summary>
        /// <param name="trackViewer">The trackviewer we need to find the trackDB</param>
        /// <param name="description">The description of the item we might want to show, needed to make sure it is a proper item</param>
        /// <param name="index">The index of the item to show</param>
        private void AddNamesStatus(TrackViewer trackViewer, string description, uint index)
        {
            if (!Properties.Settings.Default.statusShowNames)
            {
                return;
            }
            if (!String.Equals(description, "platform"))
            {
                return;
            }

            TrItem       item     = trackViewer.RouteData.TrackDB.TrItemTable[index];
            PlatformItem platform = item as PlatformItem;

            if (platform == null)
            {
                return;
            }
            statusAdditional.Text += string.Format(System.Globalization.CultureInfo.CurrentCulture,
                                                   "{0} ({1})", platform.Station, platform.ItemName);
        }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="originalTrItem">The original track item that we are representing for drawing</param>
 public DrawableRoadLevelCrItem(TrItem originalTrItem)
     : base(originalTrItem)
 {
     Description = "crossing (road)";
 }
Example #17
0
 public void setItem2(TrItem tr)
 {
     Item2     = tr;
     Location2 = new PointF(Item2.TileX * 2048f + Item2.X, Item2.TileZ * 2048f + Item2.Z);
 }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="originalTrItem">The original track item that we are representing for drawing</param>
 public DrawableSidingItem(TrItem originalTrItem)
     : base(originalTrItem)
 {
     Description   = "siding";
     this.itemName = (originalTrItem as SidingItem).ItemName;
 }
Example #19
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="item">The original track item</param>
        /// <param name="travellerAtItem">The traveller located at the location of the track item</param>
        public ChartableTrackItem(TrItem item, Traveller travellerAtItem)
        {
            this.Height   = item.Y;
            this.ItemText = string.Empty;
            this.ItemType = ChartableTrackItemType.Station;
            switch (item.ItemType)
            {
            case TrItem.trItemType.trEMPTY:
                break;

            case TrItem.trItemType.trCROSSOVER:
                break;

            case TrItem.trItemType.trSIGNAL:
                break;

            case TrItem.trItemType.trSPEEDPOST:
                SpeedPostItem speedPost = item as SpeedPostItem;
                this.ItemText = speedPost.SpeedInd.ToString(System.Globalization.CultureInfo.CurrentCulture);
                if (speedPost.IsMilePost)
                {
                    this.ItemType = ChartableTrackItemType.MilePost;
                }
                if (speedPost.IsLimit)
                {
                    float relativeAngle   = Microsoft.Xna.Framework.MathHelper.WrapAngle(travellerAtItem.RotY + speedPost.Angle - (float)Math.PI / 2);
                    bool  inSameDirection = Math.Abs(relativeAngle) < Math.PI / 2;
                    if (inSameDirection)
                    {
                        this.ItemType = ChartableTrackItemType.SpeedLimitForward;
                    }
                    else
                    {
                        this.ItemType = ChartableTrackItemType.SpeedLimitReverse;
                    }
                }
                break;

            case TrItem.trItemType.trPLATFORM:
                this.ItemText = (item as PlatformItem).Station;
                this.ItemType = ChartableTrackItemType.Station;
                break;

            case TrItem.trItemType.trSOUNDREGION:
                break;

            case TrItem.trItemType.trXING:
                break;

            case TrItem.trItemType.trSIDING:
                break;

            case TrItem.trItemType.trHAZZARD:
                break;

            case TrItem.trItemType.trPICKUP:
                break;

            case TrItem.trItemType.trCARSPAWNER:
                break;

            default:
                break;
            }


            this.TrackVectorSectionIndex = travellerAtItem.TrackVectorSectionIndex;
            var travellerAtSectionStart = new Traveller(travellerAtItem);

            travellerAtSectionStart.MoveInSection(float.MinValue); // Move to begin of section
            this.TrackVectorSectionOffset = travellerAtItem.TrackNodeOffset - travellerAtSectionStart.TrackNodeOffset;
        }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="originalTrItem">The original track item that we are representing for drawing</param>
 public DrawableHazardItem(TrItem originalTrItem)
     : base(originalTrItem)
 {
     Description = "hazard";
 }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="originalTrItem">The original track item that we are representing for drawing</param>
 public DrawablePickupItem(TrItem originalTrItem)
     : base(originalTrItem)
 {
     Description = "pickup";
 }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="originalTrItem">The original track item that we are representing for drawing</param>
 public DrawableEmptyItem(TrItem originalTrItem)
     : base(originalTrItem)
 {
     Description = "empty";
 }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="originalTrItem">The original track item that we are representing for drawing</param>
 public DrawableCarSpawnerItem(TrItem originalTrItem)
     : base(originalTrItem)
 {
     Description = "carspawner";
 }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="originalTrItem">The original track item that we are representing for drawing</param>
 protected DrawableTrackItem(TrItem originalTrItem)
 {
     this.Index         = originalTrItem.TrItemId;
     this.WorldLocation = new WorldLocation(originalTrItem.TileX, originalTrItem.TileZ, originalTrItem.X, originalTrItem.Y, originalTrItem.Z);
     this.Description   = "unknown";
 }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="originalTrItem">The original track item that we are representing for drawing</param>
 public DrawableCrossoverItem(TrItem originalTrItem)
     : base(originalTrItem)
 {
     Description = "crossover";
 }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="originalTrItem">The original track item that we are representing for drawing</param>
 public DrawableSpeedPostItem(TrItem originalTrItem)
     : base(originalTrItem)
 {
     Description  = "speedpost";
     originalItem = originalTrItem as SpeedPostItem;
 }
Example #27
0
 public AECrossOver(TrackSegment trSegment, TrItem item)
 {
     trItem   = item;
     Location = new PointF(trItem.TileX * 2048f + trItem.X, trItem.TileZ * 2048f + trItem.Z);
 }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="originalTrItem">The original track item that we are representing for drawing</param>
 public DrawableSoundRegionItem(TrItem originalTrItem)
     : base(originalTrItem)
 {
     Description = "soundregion";
 }
Example #29
0
 public LevelCrossingItem(TrackNode trackNode, TrItem trItem)
 {
     TrackNode = trackNode;
     Location  = new WorldLocation(trItem.TileX, trItem.TileZ, trItem.X, trItem.Y, trItem.Z);
 }
Example #30
0
 public FuelPickupItem(TrackNode trackNode, TrItem trItem)
 {
     TrackNode = trackNode;
     Location  = new WorldLocation(trItem.TileX, trItem.TileZ, trItem.X, trItem.Y, trItem.Z);
 }