コード例 #1
0
ファイル: SavePatFile.cs プロジェクト: robwor/openrails
        /// <summary>
        /// Add a single TrPathNode. Make sure the pdp's are updated as needed.
        /// </summary>
        /// <param name="node">path node, needed for location, and various flags</param>
        /// <param name="nextMainIndex">Index of the next main node</param>
        /// <param name="nextSidingIndex">Index of the next siding node</param>
        private static void AddNode(TrainpathNode node, uint nextMainIndex, uint nextSidingIndex)
        {
            int    pdpIndex;
            string trackPDPstart = String.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                 "\tTrackPDP ( {0,6:D} {1,6:D} {2,9} {3,9:F3} {4,9:F3}",
                                                 node.Location.TileX, node.Location.TileZ,
                                                 node.Location.Location.X.ToString("F3", System.Globalization.CultureInfo.CreateSpecificCulture("en-US")),
                                                 node.Location.Location.Y.ToString("F3", System.Globalization.CultureInfo.CreateSpecificCulture("en-US")),
                                                 node.Location.Location.Z.ToString("F3", System.Globalization.CultureInfo.CreateSpecificCulture("en-US")));

            pdpIndex = trackPDPs.Count(); // default PDP index
            TrainpathJunctionNode nodeAsJunction = node as TrainpathJunctionNode;

            if (nodeAsJunction != null)
            {
                int junctionIndex = nodeAsJunction.JunctionIndex;
                if (!node.IsBroken && pdpOfJunction.ContainsKey(junctionIndex))
                {
                    //this junction is already in the list of PDPs, so use another PDP index;
                    pdpIndex = pdpOfJunction[junctionIndex];
                }
                else
                {
                    trackPDPs.Add(String.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                "{0} {1} {2} )", trackPDPstart, 2, 0));
                    pdpOfJunction[junctionIndex] = pdpIndex;
                }
            }
            else
            {   // TrainpathVectorNode
                if (node.NodeType == TrainpathNodeType.Start || node.NodeType == TrainpathNodeType.End)
                {
                    trackPDPs.Add(String.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                "{0} {1} {2} )", trackPDPstart, 1, 0));
                }
                else
                {
                    trackPDPs.Add(String.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                "{0} {1} {2} )", trackPDPstart, 1, 1));
                }
            }

            trpathnodes.Add(String.Format(System.Globalization.CultureInfo.InvariantCulture,
                                          "\t\tTrPathNode ( {0} {1} {2} {3} )",
                                          node.FlagsToString(), nextMainIndex, nextSidingIndex, pdpIndex));
        }