/// <summary>Gets a skeleton version of this grid manager.</summary> /// <param name="forPlayer">The player that will use it. His nodes and segments are full instead of skeletons.</param> /// <param name="playerNodes">A list of all of the player's nodes.</param> /// <param name="playerSegs">A list of all of the player's segments.</param> /// <param name="allSegs">A list of all segments.</param> /// <param name="allNodes">A list of all nodes.</param> /// <returns>A skeleton version of this grid manager.</returns> public GridManager getSkeleton(Player forPlayer, out Node[] playerNodes, out Segment[] playerSegs, out NodeSkel[] allNodes, out SegmentSkel[] allSegs) { playerNodes = new Node[forPlayer.Nodes.Count]; playerSegs = new Segment[forPlayer.Segments.Count]; allNodes = new NodeSkel[InWorld.Nodes.Count]; allSegs = new SegmentSkel[InWorld.Segments.Count]; int nextPlyrNode = 0; int nextPlyrSeg = 0; int nextAllNode = 0; int nextAllSeg = 0; GridManager skeleton = new GridManager(NumCols, NumRows, InWorld, false); Dictionary<string, NodeSkel> nodes = new Dictionary<string, NodeSkel>(InWorld.Nodes.Count); Dictionary<string, SegmentSkel> segments = new Dictionary<string, SegmentSkel>(InWorld.Segments.Count); Dictionary<string, GeoSkel> geos = new Dictionary<string, GeoSkel>(InWorld.Geos.Count); // add nodes, segments, and geos to dictionary foreach (Node node in InWorld.Nodes) { if (node.Owner == forPlayer) { Node clone = new Node(node); nodes.Add(clone.ID, clone); playerNodes[nextPlyrNode] = clone; nextPlyrNode++; allNodes[nextAllNode] = clone; } else if (!node.Destroyed) { NodeSkel skel = node.getSkeleton(); nodes.Add(node.ID, skel); allNodes[nextAllNode] = skel; } nextAllNode++; } foreach (Segment seg in InWorld.Segments) { if (seg.Owner == forPlayer) { Segment clone = new Segment(seg); segments.Add(clone.ID, clone); playerSegs[nextPlyrSeg] = clone; nextPlyrSeg++; allSegs[nextAllSeg] = clone; nextAllSeg++; } else if (!seg.Destroyed) { SegmentSkel skel = seg.getSkeleton(); segments.Add(seg.ID, skel); allSegs[nextAllSeg] = skel; nextAllSeg++; } } foreach (Geo geo in InWorld.Geos) { geos.Add(geo.ID, geo.getSkeleton()); } // connect cloned nodes and segments to each other foreach (Node node in playerNodes) { for (int i = 0; i < node.Segments.Length; i++) { Segment seg = node.Segments[i]; if (seg != null) node.Segments[i] = (Segment)segments[seg.ID]; } for (int i = 0; i < node.Parents.Count; i++) { Node n = node.Parents[i]; node.Parents[i] = (Node)nodes[n.ID]; } } foreach (Segment seg in playerSegs) { for (int i = 0; i < seg.Nodes.Length; i++) { Node node = seg.Nodes[i]; if (!node.Destroyed) seg.Nodes[i] = (Node)nodes[node.ID]; else seg.Nodes[i] = new Node(node); } } // build grid skeleton.SqrSize = this.SqrSize; for (int row = 0; row < NumRows; row++) { for (int col = 0; col < NumRows; col++) { GridSqr sqr = Squares[row, col]; skeleton.Squares[row, col] = new GridSqr(new List<NodeSkel>(sqr.Nodes.Count), new List<SegmentSkel>(sqr.Segments.Count), new List<GeoSkel>(sqr.Geos.Count), new List<Hotspot>(sqr.Hotspots.Count), false); foreach (NodeSkel node in sqr.Nodes) { if (((Node)node).Active && !((Node)node).Destroyed) skeleton.Squares[row, col].Nodes.Add(nodes[node.ID]); } foreach (SegmentSkel seg in sqr.Segments) { if (!((Segment)seg).Destroyed) skeleton.Squares[row, col].Segments.Add(segments[seg.ID]); } foreach (GeoSkel geo in sqr.Geos) { skeleton.Squares[row, col].Geos.Add(geos[geo.ID]); } } } return skeleton; }
/// <summary>Resets all values to their defaults.</summary> public void clear() { Grid = null; }