Esempio n. 1
0
        public static uint getSectionIndex(this TrackNode node, int direction)
        {
            uint index = 0;

            if (node.TrEndNode)
            {
                index = (uint)node.UiD.WorldId;
            }
            else if (node.TrJunctionNode != null)
            {
                index = (uint)node.TrJunctionNode.Idx;
            }
            else if (node.TrVectorNode.TrVectorSections != null && node.TrVectorNode.TrVectorSections.Length > 1)
            {
                if (direction == 0)
                {
                    TrVectorSection section = node.TrVectorNode.TrVectorSections.Last();
                    index = section.SectionIndex;
                }
                else
                {
                    TrVectorSection section = node.TrVectorNode.TrVectorSections.First();
                    index = section.SectionIndex;
                }
            }
            else if (node.TrVectorNode.TrVectorSections != null)
            {
                index = node.TrVectorNode.TrVectorSections[0].SectionIndex;
            }
            else
            {
                index = (uint)node.UiD.WorldId;
            }
            return(index);
        }
Esempio n. 2
0
        private static object AddKeys(Track track, TrackNode node1, TrackNode node2)
        {
            switch (track.ParamType)
            {
            case TrackParamType.Integer:
                return(node1.GetValue <int>() + node2.GetValue <int>());

            case TrackParamType.Color:
            {
                var c1 = node1.GetValue <Color4>();
                var c2 = node2.GetValue <Color4>();
                return(new Color4
                    {
                        Alpha = c1.Alpha + c2.Alpha,
                        Blue = c1.Blue + c2.Blue,
                        Green = c1.Green + c2.Green,
                        Red = c1.Red + c2.Red
                    });
            }

            case TrackParamType.Vector2:
                return(node1.GetValue <Vector2>() + node2.GetValue <Vector2>());

            case TrackParamType.Vector3:
                return(node1.GetValue <Vector3>() + node2.GetValue <Vector3>());

            case TrackParamType.Quaternion:
                return(node1.GetValue <Quaternion>() * node2.GetValue <Quaternion>());

            default:
                throw new IndexOutOfRangeException($"Unsupported ParamType for ADD: {track.ParamType}");
            }
        }
        }                                                         // set if approaching moving table, is index in access path list
                                                                  // used for moving table approach in timetable mode

        //================================================================================================//
        /// <summary>
        /// Constructor from tracknode
        /// </summary>

        public TrackCircuitRouteElement(TrackNode node, int trackCircuitIndex, TrackDirection direction)
        {
            if (null == node)
            {
                throw new ArgumentNullException(nameof(node));
            }

            TrackCircuitSection      = TrackCircuitSection.TrackCircuitList[node.TrackCircuitCrossReferences[trackCircuitIndex].Index];
            Direction                = direction;
            OutPin[Location.NearEnd] = direction;
            OutPin[Location.FarEnd]  = TrackDirection.Ahead;          // always 0 for NORMAL sections, updated for JUNCTION sections

            if (TrackCircuitSection.CircuitType == TrackCircuitType.Crossover)
            {
                TrackDirection outPinLink = direction;
                int            nextIndex;
                nextIndex = direction == TrackDirection.Reverse ? node.TrackCircuitCrossReferences[trackCircuitIndex - 1].Index : node.TrackCircuitCrossReferences[trackCircuitIndex + 1].Index;
                OutPin[Location.FarEnd] = (TrackCircuitSection.Pins[outPinLink, Location.NearEnd].Link == nextIndex) ? TrackDirection.Ahead : TrackDirection.Reverse;
            }

            FacingPoint = (TrackCircuitSection.CircuitType == TrackCircuitType.Junction && TrackCircuitSection.Pins[direction, Location.FarEnd].Link != -1);

            UsedAlternativePath     = -1;
            MovingTableApproachPath = -1;
        }
Esempio n. 4
0
 public void updateNode(TrackNode node)
 {
     allowedDirections = new List <string>();
     allowedDirections.Add("   ");
     allowedDirections.Add("In");
     allowedDirections.Add("Out");
     allowedDirections.Add("Both");
     //DirBuffer = AllowedDir.NONE;
     if (NameBuffer != null && NameBuffer.Length > 0 && DirBuffer != AllowedDir.NONE)
     {
         Configured = true;
     }
     else
     {
         Configured = false;
     }
     typeItem      = (int)TypeItem.BUFFER_ITEM;
     associateNode = node;
     //associateNodeIdx = (int)componentItem.Index;
     associateSectionIdx = 0;
     Coord        = new MSTSCoord(node);
     Location.X   = associateNode.UiD.TileX * 2048f + associateNode.UiD.X;
     Location.Y   = associateNode.UiD.TileZ * 2048f + associateNode.UiD.Z;
     node.Reduced = true;
 }
Esempio n. 5
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>();
            TrackVectorNode           vectorNode     = tn as TrackVectorNode;

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

            foreach (int trackItemIndex in vectorNode.TrackItemIndices)
            {
                TrackItem trItem = trackDB.TrackItems[trackItemIndex];
                if (trItem is PlatformItem || trItem is SpeedPostItem)
                {
                    var travellerAtItem = new Traveller(tsectionDat, trackDB.TrackNodes, vectorNode, trItem.Location, Traveller.TravellerDirection.Forward);

                    if (travellerAtItem != null)
                    {
                        tracknodeItems.Add(new ChartableTrackItem(trItem, travellerAtItem));
                    }
                }
            }
            tracknodeItems.Sort(new AlongTrackComparer());
            cachedItems[tn] = tracknodeItems;
            return(tracknodeItems);
        }
Esempio n. 6
0
    private StepChain GetStepChains(TrackNode startNode, List <TrackNode> connections)
    {
        var steps = new StepChain();
        var i     = 0;

        if (startNode == null)
        {
            startNode = connections[i];
            i        += 1;
        }

        steps.Add(startNode.Position);

        for (; i < connections.Count; i++)
        {
            var endNode = connections[i];

            steps.AddRange(GetSteps(startNode, endNode));

            if (endNode.Connections.Count > 0)
            {
                steps.ChildChains.Add(GetStepChains(endNode, endNode.Connections));
            }

            startNode = endNode;
        }

        return(steps);
    }
Esempio n. 7
0
        public virtual void Update()
        {
            if (CurrentNode.Next == null || CurrentNode.Prev == null)
            {
                return;
            }
            float elapsedSeconds = Engine.Instance.FrameTime;

            Direction = Vector3.TransformNormal(Direction, Matrix.CreateFromAxisAngle(Up, _rotationChange));
            Position += Speed * Direction * Engine.Instance.FrameTime * 2.5f;

            UpdateSteering();
            UpdateTrackNode();
            if (CurrentNode.Next == null || CurrentNode.Prev == null)
            {
                return;
            }
            TrackNode node = null, nextNode = null;

            if (Distance2d(Position, CurrentNode.Next.Position) < Distance2d(Position, CurrentNode.Prev.Position))
            {
                node     = CurrentNode;
                nextNode = CurrentNode.Next;
            }
            else
            {
                node     = CurrentNode.Prev;
                nextNode = CurrentNode;
            }

            FollowTrackOrientation(node, nextNode);
            ApplyGravity();
        }
Esempio n. 8
0
 //================================================================================================//
 /// <summary>
 ///  check if linked route is set
 /// </summary>
 public int VerifyRouteSet()
 {
     // call route_set routine from main signal
     if (TrackJunctionNode > 0)
     {
         return(MainSignal.CheckRouteSet(JunctionMainNode, TrackJunctionNode) ? 1 : 0);
     }
     //added by JTang
     else if (MultiPlayerManager.IsMultiPlayer())
     {
         TrackNode node = Simulator.Instance.TrackDatabase.TrackDB.TrackNodes[MainSignal.TrackNode];
         if (!(node is TrackJunctionNode) && node.TrackPins != null && (int)MainSignal.TrackCircuitDirection < node.TrackPins.Length)
         {
             node = Simulator.Instance.TrackDatabase.TrackDB.TrackNodes[node.TrackPins[(int)MainSignal.TrackCircuitDirection].Link];
             if (!(node is TrackJunctionNode junctionNode))
             {
                 return(0);
             }
             for (int pin = junctionNode.InPins; pin < junctionNode.InPins + junctionNode.OutPins; pin++)
             {
                 if (junctionNode.TrackPins[pin].Link == MainSignal.TrackNode && pin - junctionNode.InPins != junctionNode.SelectedRoute)
                 {
                     return(0);
                 }
             }
         }
     }
     return(1);
 }
Esempio n. 9
0
        /// <summary>
        /// Draw (possibly part of) the track of a MSTS vectorNode (from track database)
        /// </summary>
        /// <param name="drawArea">Area to draw upon</param>
        /// <param name="tn">The tracknode from track database (assumed to be a vector node)</param>
        /// <param name="colors">Colorscheme to use</param>
        /// <param name="tvsiStart">Index of first track vector section to draw (at least partially)</param>
        /// <param name="tvsiStop">Index of last track vector section to draw (at least partially)</param>
        /// <param name="sectionOffsetStart">start-offset in the first track section to draw</param>
        /// <param name="sectionOffsetStop">stop-offset in the last track section to draw</param>
        /// <remarks>Very similar to DrawVectorNode in class DrawTrackDB, but this one allows to draw partial vector nodes.</remarks>
        private void DrawVectorNode(DrawArea drawArea, TrackNode tn, ColorScheme colors, int tvsiStart, int tvsiStop,
                float sectionOffsetStart, float sectionOffsetStop)
        {
            TrVectorSection tvs;
            if (tvsiStart == tvsiStop)
            {
                tvs = tn.TrVectorNode.TrVectorSections[tvsiStart];
                DrawTrackSection(drawArea, tvs, colors, sectionOffsetStart, sectionOffsetStop);
            }
            else
            {
                // first section
                tvs = tn.TrVectorNode.TrVectorSections[tvsiStart];
                DrawTrackSection(drawArea, tvs, colors, sectionOffsetStart, -1);

                // all intermediate sections
                for (int tvsi = tvsiStart + 1; tvsi <= tvsiStop - 1; tvsi++)
                {
                    tvs = tn.TrVectorNode.TrVectorSections[tvsi];
                    DrawTrackSection(drawArea, tvs, colors, 0, -1);
                }

                // last section
                tvs = tn.TrVectorNode.TrVectorSections[tvsiStop];
                DrawTrackSection(drawArea, tvs, colors, 0, sectionOffsetStop);
            }
        }
Esempio n. 10
0
        private static object LerpKeys(Track track, float t, TrackNode node1, TrackNode node2, TrackNode offset)
        {
            switch (track.ParamType)
            {
            case TrackParamType.Integer:
                return(LerpInteger(node1.GetValue <int>(), node2.GetValue <int>(), t, offset.GetValue <int>()));

            case TrackParamType.Color:
                return(LerpColor(node1.GetValue <Color4>(), node2.GetValue <Color4>(), t,
                                 offset.GetValue <Color4>()));

            case TrackParamType.Vector2:
                return(Vector2.Lerp(node1.GetValue <Vector2>(), node2.GetValue <Vector2>(), t) +
                       offset.GetValue <Vector2>());

            case TrackParamType.Vector3:
                return(Vector3.Lerp(node1.GetValue <Vector3>(), node2.GetValue <Vector3>(), t) +
                       offset.GetValue <Vector3>());

            case TrackParamType.Quaternion:
                return(Quaternion.Lerp(node1.GetValue <Quaternion>(), node2.GetValue <Quaternion>(), t) *
                       offset.GetValue <Quaternion>());

            default:
                throw new IndexOutOfRangeException($"Unsupported ParamType for LERP: {track.ParamType}");
            }
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
 /// <summary>
 /// Default constructor used during file parsing.
 /// </summary>
 /// <param name="stf">The STFreader containing the file stream</param>
 internal RoadTrackDB(STFReader stf)
 {
     stf.MustMatchBlockStart();
     stf.ParseBlock(new STFReader.TokenProcessor[] {
         new STFReader.TokenProcessor("tracknodes", () => {
             stf.MustMatchBlockStart();
             int count  = stf.ReadInt(null);
             TrackNodes = new TrackNode[count + 1];
             int idx    = 1;
             stf.ParseBlock(new STFReader.TokenProcessor[] {
                 new STFReader.TokenProcessor("tracknode", () => { TrackNodes[idx] = TrackNode.ReadTrackNode(stf, idx, count); ++idx; }),
             });
         }),
         new STFReader.TokenProcessor("tritemtable", () => {
             stf.MustMatchBlockStart();
             int count   = stf.ReadInt(null);
             TrItemTable = new TrackItem[count];
             int idx     = -1;
             stf.ParseBlock(() => ++ idx == -1, new STFReader.TokenProcessor[] {
                 new STFReader.TokenProcessor("levelcritem", () => { TrItemTable[idx] = new RoadLevelCrossingItem(stf, idx); }),
                 new STFReader.TokenProcessor("emptyitem", () => { TrItemTable[idx] = new EmptyItem(stf, idx); }),
                 new STFReader.TokenProcessor("carspawneritem", () => { TrItemTable[idx] = new RoadCarSpawner(stf, idx); })
             });
         }),
     });
 }
Esempio n. 13
0
    int FindNearestNode()
    {
        TrackNodeTool trackNodeToolScript = (TrackNodeTool)target;
        TrackNode     trackNode           = trackNodeToolScript.trackNode;
        Vector3       result = Vector3.zero;
        int           ind    = -1;

        if (trackNode != null)
        {
            Transform trackNodeToolTransform = trackNodeToolScript.GetComponent <Transform>();

            float distance = float.MaxValue;
            for (int index = 0; index < trackNode.GetNodeCount(); index++)
            {
                float possibleDistance = Vector3.Distance(trackNodeToolTransform.position, trackNode.GetNode(index));
                if (possibleDistance < distance)
                {
                    distance = possibleDistance;
                    result   = trackNodeToolTransform.position;
                    ind      = index;
                }
            }
        }

        return(ind);
    }
Esempio n. 14
0
        /// <summary>
        /// Check wether this vector node is closest to the mouse location
        /// </summary>
        /// <param name="location">Location to check</param>
        /// <param name="mouseLocation">Current mouse location</param>
        /// <param name="trackNode">The trackNode that will be stored when indeed it is the closest to the mouse location</param>
        /// <param name="vectorSection">the vectorSection that will be stored when indeed it is closest to the mouse location</param>
        /// <param name="tvsi">Current index of the trackvectorsection</param>
        /// <param name="pixelsPerMeter"></param>
        public void CheckMouseDistance(WorldLocation location, WorldLocation mouseLocation, 
            TrackNode trackNode, TrVectorSection vectorSection, int tvsi, double pixelsPerMeter)
        {
            storedMouseLocation = mouseLocation;
            float distanceSquared = CloseToMouse.GetGroundDistanceSquared(location, mouseLocation);
            // to make unique distances becasue they also act as Key
            double distanceSquaredIndexed = ((double)distanceSquared) * (1 + 1e-16 * trackNode.Index);
            if (distanceSquaredIndexed < sortedTrackCandidates.First().Key)
            {
                if (!sortedTrackCandidates.ContainsKey(distanceSquaredIndexed))
                {
                    sortedTrackCandidates.Add(distanceSquaredIndexed, new TrackCandidate(trackNode, vectorSection, tvsi, 0));

                    // The next one is a bit tricky. The problem is that the first culling is done based on the trackvector section location
                    // Which is only at one side of the section. So the other end might be quiet far away.
                    // Unfortunately, this means that we need to keep track of many candidates to make sure we can calculate the closest one
                    // Which is costing performance.
                    // The biggest issue is for a long track close to a region with lots junctions and hence small track segments
                    // By making this number zoom dependent, we get good results for big zooms, and not a large
                    // performance penalty for wide views
                    int maxNumberOfCandidates = 50 + (int)(100 * pixelsPerMeter);
                    while (sortedTrackCandidates.Count > maxNumberOfCandidates)
                    {
                        sortedTrackCandidates.RemoveAt(0); // First one has largest distance
                    }
                }
            }
        }
        /// <summary>
        /// Scan the current orRouteConfig and search for items related to the given node
        /// </summary>
        /// <param name="iNode">The current node index</param>
        /// <param name="orRouteConfig">The Open Rail configuration coming from Editor</param>
        /// <param name="trackNodes">The list of MSTS Track Nodes</param>
        /// <param name="tsectiondat">The list of MSTS Section datas</param>
        public List <TrackCircuitElement> GetORItemForNode(int iNode, TrackNode[] trackNodes, TrackSectionsFile tsectiondat)
        {
            List <TrackCircuitElement> trackCircuitElements = new List <TrackCircuitElement>();

            if (AllItems.Count <= 0)
            {
                return(trackCircuitElements);
            }
            foreach (var item in AllItems)
            {
                switch (item.typeItem)
                {
                case (int)TypeItem.STATION_CONNECTOR:
                    if (item.associateNodeIdx != iNode)
                    {
                        continue;
                    }
                    TrackNode   node   = trackNodes[iNode];
                    AETraveller travel = new AETraveller(traveller);
                    travel.place(node);
                    float position = travel.DistanceTo(item);
                    TrackCircuitElement element = (TrackCircuitElement) new TrackCircuitElementConnector(item, position);
                    trackCircuitElements.Add(element);
                    break;

                default:
                    break;
                }
            }

            return(trackCircuitElements);
        }
Esempio n. 16
0
    TrackNode GetTrackNode()
    {
        TrackNodeTool trackNodeToolScript = (TrackNodeTool)target;
        TrackNode     trackNode           = trackNodeToolScript.trackNode;

        return(trackNode);
    }
Esempio n. 17
0
        public static uint getShapeIdx(this TrackNode node, int direction)
        {
            uint shapeIdx = 0;

            if (node.TrEndNode || node.TrJunctionNode != null)
            {
                shapeIdx = 0;
            }
            else if (node.TrVectorNode.TrVectorSections.Length > 1)
            {
                if (direction == 0)
                {
                    TrVectorSection section = node.TrVectorNode.TrVectorSections.Last();
                    shapeIdx = section.ShapeIndex;
                }
                else
                {
                    TrVectorSection section = node.TrVectorNode.TrVectorSections.First();
                    shapeIdx = section.ShapeIndex;
                }
            }
            else
            {
                shapeIdx = 0;
            }
            return(shapeIdx);
        }
Esempio n. 18
0
 public TrackCandidate(TrackNode node, TrVectorSection section, int tvsi, float lon)
 {
     trackNode = node;
     vectorSection = section;
     trackVectorSectionIndex = tvsi;
     distanceAlongSection = lon;
 }
Esempio n. 19
0
        public void AddSegments(TrackNode node)
        {
            List <KeyValuePair <int, int> > listTrItems = distributeTrItem(node);

            TrVectorSection[] items = node.TrVectorNode.TrVectorSections;
            for (int idx = 0; idx < items.Length - 1; idx++)
            {
                //Program.actEditor.DisplayStatusMessage("Init data for display...  Load Vector Nodes: " + node.Index + "." + idx);
                TrVectorSection item1 = node.TrVectorNode.TrVectorSections[idx];
                TrVectorSection item2 = node.TrVectorNode.TrVectorSections[idx + 1];

                AESegment    aeSegment = new AESegment(item1, item2);
                TrackSegment lineSeg   = new TrackSegment(aeSegment, node, idx, item1.Flag2, TSectionDat);
                var          values    = listTrItems.GroupBy(x => x.Key == idx);
                foreach (var idxTrItem in values)
                {
                    if (!idxTrItem.Key)
                    {
                        break;
                    }
                    foreach (var val in idxTrItem)
                    {
                        var item = TDB.TrackDB.TrItemTable[val.Value];
                        addTrItem(lineSeg, item);
                    }
                }
                //Program.actEditor.DisplayStatusMessage("Init data for display...  Load Vector Nodes: " + node.Index + "." + idx + ".");
                mstsItems.AddSegment(lineSeg);

                //lineSeg = new TrackSegment(node, i, TSectionDat);
                areaRoute.manageTiles(item1.TileX, item1.TileZ);
            }
            areaRoute.manageTiles(items[items.Length - 1].TileX, items[items.Length - 1].TileZ);
        }
Esempio n. 20
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        TrackNode trackNode = collider.GetComponent <TrackNode>();

        if (trackNode)
        {
            int trackNodeIndex = trackNode.GetIndex();
            // If Player moved to the next waypoint of passed lap-start position
            // TODO: here is small bug - if player will go back on start and then pass start - condition will be met. Seems like not-real scenario.
            if (lastPassedWaypoint < trackNodeIndex || (lastPassedWaypoint > trackNodeIndex && trackNodeIndex == 1))
            {
                // if start passed
                if (lastPassedWaypoint > trackNodeIndex && trackNodeIndex == 1)
                {
                    if (_dashNumberAvailable < INITIAL_NUMBER_OF_DASHES)
                    {
                        _dashNumberAvailable = INITIAL_NUMBER_OF_DASHES;
                    }
                }

                waypointSum       += WAYPOINT_VALUE;
                lastPassedWaypoint = trackNodeIndex;
            }
        }
    }
Esempio n. 21
0
 /// <summary>
 /// Constructor that immediately sets the closest item (and distance)
 /// </summary>
 /// <param name="tn">Tracknode that will be stored as closest item</param>
 /// <param name="tsectionDat">The track section Dat file that we can use to calculate the distance to the track</param>
 public CloseToMouseTrack(TrackSectionsFile tsectionDat, TrackNode tn)
 {
     this.tsectionDat = tsectionDat;
     sortedTrackCandidates = new SortedList<double, TrackCandidate>(new ReverseDoubleComparer());
     sortedTrackCandidates.Add(0, new TrackCandidate(tn, null, 0, 0));
     realDistancesAreCalculated = true; // we do not want to calculate distance if we override the highlight
 }
Esempio n. 22
0
 /// <summary>
 /// Default constructor used during file parsing.
 /// </summary>
 /// <param name="stf">The STFreader containing the file stream</param>
 public TrackDB(STFReader stf)
 {
     stf.MustMatchBlockStart();
     stf.ParseBlock(new STFReader.TokenProcessor[] {
         new STFReader.TokenProcessor("tracknodes", () => {
             stf.MustMatchBlockStart();
             int numberOfTrackNodes = stf.ReadInt(null);
             TrackNodes             = new TrackNode[numberOfTrackNodes + 1];
             int idx = 1;
             stf.ParseBlock(new STFReader.TokenProcessor[] {
                 new STFReader.TokenProcessor("tracknode", () => {
                     TrackNodes[idx] = TrackNode.ReadTrackNode(stf, idx, numberOfTrackNodes);
                     if (TrackNodes[idx] is TrackJunctionNode junctionNode)
                     {
                         string key = $"{junctionNode.UiD.WorldId}-{junctionNode.UiD.Location.TileX}-{junctionNode.UiD.Location.TileZ}";
                         if (!junctionNodes.ContainsKey(key))
                         {
                             junctionNodes.Add(key, junctionNode);
                         }
                         // only need any (first) junction node with that key here to relate back to ShapeIndex
                     }
                     ++idx;
                 }),
             });
         }),
Esempio n. 23
0
        /// <summary>
        /// Try to find the index of the vector node connecting this path node to the (given) nextNode.
        /// </summary>
        /// <returns>The index of the vector node connection, or -1</returns>
        public override int FindTvnIndex(TrainpathNode nextNode)
        {
            TrainpathVectorNode nextAsVectorNode = nextNode as TrainpathVectorNode;

            if (nextAsVectorNode != null)
            {   // from junction to vector node.
                if (this.ConnectsToTrack(nextAsVectorNode.TvnIndex))
                {
                    return(nextAsVectorNode.TvnIndex);
                }
                else
                {   //node is perhaps not broken, but connecting track is
                    return(-1);
                }
            }

            //both this node and the next node are junctions: find the vector node connecting them.
            //Probably this can be faster, by just finding the TrPins from this and next junction and find the common one.
            int nextJunctionIndex = (nextNode as TrainpathJunctionNode).JunctionIndex;

            for (int i = 0; i < TrackDB.TrackNodes.Count(); i++)
            {
                TrackNode tn = TrackDB.TrackNodes[i];
                if (tn == null || tn.TrVectorNode == null)
                {
                    continue;
                }
                if ((tn.JunctionIndexAtStart() == this.JunctionIndex && tn.JunctionIndexAtEnd() == nextJunctionIndex) ||
                    (tn.JunctionIndexAtEnd() == this.JunctionIndex && tn.JunctionIndexAtStart() == nextJunctionIndex))
                {
                    return(i);
                }
            }
            return(-1);
        }
Esempio n. 24
0
 public MSTSCoord(TrackNode node)
 {
     TileX   = node.UiD.TileX;
     TileY   = node.UiD.TileZ;
     X       = node.UiD.X;
     Y       = node.UiD.Z;
     Reduced = node.Reduced;
 }
Esempio n. 25
0
        /// <summary>
        /// From the current pathnode and the linking tracknode, fin the junctionIndex of the next junction (or possibly end-point)
        /// </summary>
        /// <param name="linkingTrackNodeIndex">The index of the tracknode leaving the node</param>
        /// <returns>The index of the junction index at the end of the track (as seen from the node)</returns>
        public override int GetNextJunctionIndex(int linkingTrackNodeIndex)
        {
            TrackNode linkingTrackNode = TrackDB.TrackNodes[linkingTrackNodeIndex];

            return(ForwardOriented
                ? linkingTrackNode.JunctionIndexAtEnd()
                : linkingTrackNode.JunctionIndexAtStart());
        }
Esempio n. 26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="item"></param>
        /// <param name="signal"></param>
        public AEBufferItem(TrackNode item)
        {
            typeWidget = (int)TypeWidget.BUFFER_WIDGET;;
            Item       = item;

            Location.X = Item.UiD.TileX * 2048f + Item.UiD.X;
            Location.Y = Item.UiD.TileZ * 2048f + Item.UiD.Z;
        }
Esempio n. 27
0
 public static uint getWorldFileUiD(this TrackNode node)
 {
     if (node.getVectorSection() != null)
     {
         return(node.getVectorSection().WorldFileUiD);
     }
     return(0);
 }
Esempio n. 28
0
        public MSTSBase(TrackDatabaseFile TDB)
        {
            double minTileX = double.PositiveInfinity;
            double minTileY = double.PositiveInfinity;

            TrackNode[] nodes = TDB.TrackDB.TrackNodes;
            for (int nodeIdx = 0; nodeIdx < nodes.Length; nodeIdx++)
            {
                if (nodes[nodeIdx] == null)
                {
                    continue;
                }
                TrackNode currNode = nodes[nodeIdx];
                if (currNode.TrVectorNode != null && currNode.TrVectorNode.TrVectorSections != null)
                {
                    if (currNode.TrVectorNode.TrVectorSections.Length > 1)
                    {
                        foreach (TrPin pin in currNode.TrPins)
                        {
                            if (minTileX > nodes[pin.Link].UiD.TileX)
                            {
                                minTileX = nodes[pin.Link].UiD.TileX;
                            }
                            if (minTileY > nodes[pin.Link].UiD.TileZ)
                            {
                                minTileY = nodes[pin.Link].UiD.TileZ;
                            }
                        }
                    }
                    else
                    {
                        TrVectorSection s;
                        s = currNode.TrVectorNode.TrVectorSections[0];
                        if (minTileX > s.TileX)
                        {
                            minTileX = s.TileX;
                        }
                        if (minTileY > s.TileZ)
                        {
                            minTileY = s.TileZ;
                        }
                    }
                }
                else if (currNode.TrJunctionNode != null)
                {
                    if (minTileX > currNode.UiD.TileX)
                    {
                        minTileX = currNode.UiD.TileX;
                    }
                    if (minTileY > currNode.UiD.TileZ)
                    {
                        minTileY = currNode.UiD.TileZ;
                    }
                }
            }
            TileX = minTileX;
            TileY = minTileY;
        }
Esempio n. 29
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sideItem"></param>
 /// <param name="signal"></param>
 public AEJunctionItem(TrackNode item)
 {
     typeItem            = (int)TypeItem.SWITCH_ITEM;
     associateNode       = item;
     associateNodeIdx    = item.TrJunctionNode.Idx;
     associateSectionIdx = 0;
     Location.X          = associateNode.UiD.TileX * 2048f + associateNode.UiD.X;
     Location.Y          = associateNode.UiD.TileZ * 2048f + associateNode.UiD.Z;
 }
Esempio n. 30
0
        private double zoom;          // zoom factor


        /// <summary>
        /// Create a new, empty track.
        /// </summary>
        public Track()
        {
            InitializeComponent();
            DoubleBuffered    = true;
            this.baseFontSize = this.label.Font.SizeInPoints;
            Selection         = null;
            Zoom      = 1.0;
            this.node = null;
        }