private List <PathStatistics> GetNewPaths(PathStatistics sequence, TeleportNode endNode) { TeleportNode lastNode = sequence.path.Last(); if (lastNode.ID != endNode.ID) { List <PathStatistics> sequenses = new List <PathStatistics>(); foreach (ushort nextNodeID in lastNode.Costs.Keys) { TeleportNode nextNode = database.Points[nextNodeID]; TeleportNodeComparer comparer = new TeleportNodeComparer(); if (!sequence.path.Contains(nextNode, comparer)) { //flag = true; PathStatistics newSequence = (PathStatistics)sequence.Clone(); newSequence.path.Add(nextNode); newSequence.cost += lastNode.GetCost(nextNodeID); sequenses.Add(newSequence); } } return(sequenses); } else { return(null); } }
internal void GetPointAbsoluteCoordinates(ushort pointID, out float absoluteX, out float absoluteY) { //TeleportPoint point = points[pointID]; TeleportNode point = database.Points[pointID]; absoluteX = point.AbsoluteX; absoluteY = point.AbsoluteY; }
private void DrawConnectedPaths(Pen pen, TeleportNode point) { foreach (ushort connectedPointID in point.Costs.Keys) { DrawPath(point.ID, connectedPointID); DrawPoint(connectedPointID); } }
public PathStatistics(TeleportNode point) { cost = 0; efficiency = 0; flyTime = 0; path = new List <TeleportNode>(); path.Add(point); rideTime = 0; teleportTime = 0; walkTime = 0; }
internal List <PathStatistics> GetPaths(float absX1, float absY1, float absX2, float absY2) { List <PathStatistics> statistics = new List <PathStatistics>(); float dummy; List <TeleportNodeDistance> points = GetClosestPoint(absX1, absY1, out dummy, out dummy, out dummy); List <TeleportNodeDistance> possibleStartNodes = new List <TeleportNodeDistance>(points.GetRange(0, Settings.Default.ClosestTeleportNodesCount)); TeleportNode endNode = GetClosestPoint(absX2, absY2, out dummy, out dummy, out dummy)[0].point; TeleportNode closestStartPoint = possibleStartNodes[0].point; PathStatistics closestStartPointStatistics = new PathStatistics(closestStartPoint); List <PathStatistics> sequences = new List <PathStatistics>(); sequences.Add(closestStartPointStatistics); List <PathStatistics> newSequences = new List <PathStatistics>(); while (flag) { foreach (PathStatistics sequence in sequences) { List <PathStatistics> tmp = GetNewPaths(sequence, endNode); if (tmp != null) { newSequences.AddRange(tmp); } else { flag = false; newSequences.Add(sequence); } } sequences = new List <PathStatistics>(newSequences); newSequences.Clear(); } flag = true; foreach (PathStatistics sequence in sequences) { if (sequence.path.Last().ID == endNode.ID) { newSequences.Add(sequence); } } return(newSequences); }
internal void ProcessMouseCoordinates(object stateInfo) { KeyValuePair <MouseEventArgs, CultureInfo> kvp = (KeyValuePair <MouseEventArgs, CultureInfo>)stateInfo; MouseEventArgs e = kvp.Key; CultureInfo currentCulture = kvp.Value; try { float absoluteX = (float)e.X / g.VisibleClipBounds.Width; float absoluteY = 1 - (float)e.Y / g.VisibleClipBounds.Height; float pointX; float pointY; float distance; List <TeleportNodeDistance> points = graphLayer.GetClosestPoint(absoluteX, absoluteY, out pointX, out pointY, out distance); if (distance < Settings.Default.MinimalDistanceToTeleportNode) { Console.WriteLine("Hit mouse {0} {1}", absoluteX, absoluteY); Console.WriteLine("Hit node at {0} {1}", pointX, pointY); offScreenDC.DrawImage(offScreenInitialImage, 0, 0); offScreenDC.DrawEllipse(pen, pointX * g.VisibleClipBounds.Width - 2, (1 - pointY) * g.VisibleClipBounds.Height - 2, 4, 4); //offScreenDC.DrawEllipse(pen, kvp.Value.AbsoluteX * g.VisibleClipBounds.Width - 2, (1 - kvp.Value.AbsoluteY) * g.VisibleClipBounds.Height - 2, 4, 4); //unsortedPoints.Sort(new TeleportPointDistanceComparer()); TeleportNode point = points[0].point; DrawConnectedPaths(pen, point); g.DrawImage(offScreenCurrentImage, 0, 0, g.VisibleClipBounds.Width, g.VisibleClipBounds.Height); GetNodeNameEventHandler temp = GetNodeName; if (temp != null) { temp(point.Names[currentCulture]); } } } catch (InvalidOperationException ex) { InvalidOperationException ex2 = ex; //throw; } }
private Dictionary <ushort, TeleportNode> AddTranslation(Dictionary <ushort, TeleportNode> points, XmlDocument doc, CultureInfo culture) { XmlNode translationsNode = doc.DocumentElement; // Version check // if (translationsNode.Attributes != null) { Console.WriteLine("Attributes"); foreach (XmlAttribute attr in translationsNode.Attributes) { Console.WriteLine("{0}: {1}", attr.Name, attr.Value); if (attr.Name == "Version") { if (!CheckTranslationVersion(attr.Value)) { return(null); } } if (attr.Name == "Culture") { if (culture.Name != attr.Value) { Logger.WriteLine("Desired culture: " + culture.Name + ", actual culture: " + attr.Value); MessageBox.Show("Culture in file does not match desired culture!", "Culture mismatch", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } Console.WriteLine(); } else { throw new XmlException("File version is absent"); } Console.WriteLine("{0}: {1}", translationsNode.Name, translationsNode.Value); // Translation enumeration // foreach (XmlNode translationNode in translationsNode.ChildNodes) { foreach (XmlNode translationElementNode in translationNode.ChildNodes) { if (translationElementNode.Name == "ID") { ushort id = ushort.Parse(translationElementNode.InnerText); if (!points.ContainsKey(id)) { MessageBox.Show("Costs collection does not match translation!", "Data consistency error", MessageBoxButtons.OK, MessageBoxIcon.Stop); return(null); } else { XmlNode nameNode = translationElementNode.NextSibling; TeleportNode point = points[id]; point.SetName(culture, nameNode.InnerText); points[id] = point; } } } } return(points); }
private Dictionary <ushort, TeleportNode> CreatePoints(XmlDocument doc) { Dictionary <ushort, TeleportNode> points = new Dictionary <ushort, TeleportNode>(); XmlNode teleportPointsNode = doc.DocumentElement; // Version check // if (teleportPointsNode.Attributes != null) { Console.WriteLine("Attributes"); foreach (XmlAttribute attr in teleportPointsNode.Attributes) { Console.WriteLine("{0}: {1}", attr.Name, attr.Value); if (attr.Name == "Version") { if (!CheckCostsVersion(attr.Value)) { return(null); } } } Console.WriteLine(); } else { throw new XmlException("File version is absent"); } Console.WriteLine("{0}: {1}", teleportPointsNode.Name, teleportPointsNode.Value); // TeleportPoint enumeration // foreach (XmlNode teleportPointNode in teleportPointsNode.ChildNodes) { TeleportNode point = new TeleportNode(); // Inner nodes // foreach (XmlNode teleportPointElementNode in teleportPointNode.ChildNodes) { if (teleportPointElementNode.ChildNodes.Count == 1) { switch (teleportPointElementNode.Name) { case "ID": point.ID = ushort.Parse(teleportPointElementNode.InnerText); break; case "X": point.X = int.Parse(teleportPointElementNode.InnerText); break; case "Y": point.Y = int.Parse(teleportPointElementNode.InnerText); break; case "AbsoluteX": point.AbsoluteX = float.Parse(teleportPointElementNode.InnerText, CultureInfo.InvariantCulture.NumberFormat); break; case "AbsoluteY": point.AbsoluteY = float.Parse(teleportPointElementNode.InnerText, CultureInfo.InvariantCulture.NumberFormat); break; default: break; } Console.WriteLine("{0}: {1}", teleportPointElementNode.Name, teleportPointElementNode.InnerText); } // Processed number of subelements of TeleportCost byte countedElements = 0; ushort id = 0; uint cost = 0; // TeleportCost // if (teleportPointElementNode.Name == "TeleportCost") { foreach (XmlNode teleportCostNode in teleportPointElementNode.ChildNodes) { if (teleportCostNode.Name == "ID") { id = ushort.Parse(teleportCostNode.InnerText); countedElements++; } if (teleportCostNode.Name == "Cost") { cost = uint.Parse(teleportCostNode.InnerText); countedElements++; } if (countedElements == Settings.Default.TeleportCostsElementCount) { point.SetCost(id, cost); } Console.WriteLine("{0}: {1}", teleportCostNode.Name, teleportCostNode.InnerText); } } } points.Add(point.ID, point); } return(points); }
private void btnWriteCoordsData_Click(object sender, EventArgs e) { XmlDocument doc = XmlStore.ValidateXmlDoc("http://TeleportCalculator/TeleportSchema.xsd", Settings.Default.XsdSchemataFolderName + @"\TeleportSchema.xsd", Path.Combine(Application.StartupPath, Settings.Default.XmlCostsName)); if (doc != null) { doc.Load(Path.Combine(Application.StartupPath, Settings.Default.XmlCostsName)); } XmlNode teleportPointsNode = doc.DocumentElement; // Version check // if (teleportPointsNode.Attributes != null) { Console.WriteLine("Attributes"); foreach (XmlAttribute attr in teleportPointsNode.Attributes) { Console.WriteLine("{0}: {1}", attr.Name, attr.Value); if (attr.Name == "Version") { if (!XmlStore.CheckCostsVersion(attr.Value)) { MessageBox.Show("Version check failed"); } } } Console.WriteLine(); } else { throw new XmlException("File version is absent"); } Console.WriteLine("{0}: {1}", teleportPointsNode.Name, teleportPointsNode.Value); // TeleportPoint enumeration // foreach (XmlNode teleportPointNode in teleportPointsNode.ChildNodes) { TeleportNode point = null; // Inner nodes // foreach (XmlNode teleportPointElementNode in teleportPointNode.ChildNodes) { if (teleportPointElementNode.ChildNodes.Count == 1) { switch (teleportPointElementNode.Name) { case "ID": point = database.Points[ushort.Parse(teleportPointElementNode.InnerText)]; XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("ab", teleportPointNode.NamespaceURI); XmlNode absoluteXNode = teleportPointNode.SelectSingleNode("ab:AbsoluteX", nsmgr); XmlNode absoluteYNode = teleportPointNode.SelectSingleNode("ab:AbsoluteY", nsmgr); absoluteXNode.LastChild.Value = point.AbsoluteX.ToString("0.00000", CultureInfo.InvariantCulture.NumberFormat); absoluteYNode.LastChild.Value = point.AbsoluteY.ToString("0.00000", CultureInfo.InvariantCulture.NumberFormat); continue; break; default: break; } Console.WriteLine("{0}: {1}", teleportPointElementNode.Name, teleportPointElementNode.InnerText); } } } doc.Save(Path.Combine(Application.StartupPath, Settings.Default.XmlCostsName)); MessageBox.Show("File successfully saved"); }
public TeleportNodeDistance(float distance, TeleportNode point) { this.distance = distance; this.point = point; }