//I have made this it's own function so that I can extend the class and make slightly different versions //Picks the direction that leads to being the closest to the player protected List<Point> MakeDesision (MapNode node, Vector3 trackPosition) { List<Point> nextSet; float northDistance = Vector3.Distance (node.NorthNode.transform.position, trackPosition); float eastDistance = Vector3.Distance (node.EastNode.transform.position, trackPosition); float southDistance = Vector3.Distance (node.SouthNode.transform.position, trackPosition); float westDistance = Vector3.Distance (node.WestNode.transform.position, trackPosition); float[] distances = new float[]{ northDistance, eastDistance, southDistance, westDistance }; float minDistance = Mathf.Min (distances); if (minDistance == northDistance) { nextSet = node.North; } else if (minDistance == eastDistance) { nextSet = node.East; } else if (minDistance == southDistance) { nextSet = node.South; } else { nextSet = node.West; } //prevents backtracking or non valid direction //defaults to random in that case if (nextSet.Count <= 0 || (lastNode != null && node.GetNodeFor(nextSet) == lastNode)) { return base.MakeDesision (node); } return nextSet; }
public List<MapNode> GetNeighbors(MapNode currentNode) { int x = currentNode.x; int y = currentNode.y; List<MapNode> neighbors = new List <MapNode>(); for(int yBounds = -1; yBounds <= 1; yBounds += 1){ for(int xBounds = -1; xBounds <= 1; xBounds += 1){ if(xBounds == 0 && yBounds == 0){ continue; } if(IsWithinBounds(x + xBounds, y + yBounds)){ MapNode node = nodes[y + yBounds][x + xBounds]; if (node != null) { //node.movementCost = (xBounds == 0 || yBounds == 0) ? 10 : 14; neighbors.Add(node); } else { neighbors.Add(new MapNode(-1, -1, false)); } } else { neighbors.Add(new MapNode(-1, -1, false)); } } } return neighbors; }
// Update is called once per frame void Update () { currentLerpTime += Time.deltaTime; if(Input.GetMouseButtonDown(0)) { currentLerpTime = 0.0f; Ray ray = Camera.main.ScreenPointToRay( Input.mousePosition ); RaycastHit hit; if( Physics.Raycast( ray, out hit, 100 ) ){ checknode = hit.collider.GetComponent<MapNode>(); distance = Mathf.Abs(checknode.NodeValue - currentNode); target = checknode.location; currentNode = checknode.NodeValue; currentPosition = transform.position; targetSize = 2.4f; } //if node is valid, assigns target to node } //changes position over time to the target position GetComponent<Camera>().orthographicSize = Mathf.SmoothStep( currentSize, targetSize, currentLerpTime); transform.position = new Vector2( Mathf.SmoothStep( currentPosition.x, target.x, currentLerpTime), Mathf.SmoothStep( currentPosition.y, target.y, currentLerpTime)); }
public bool ConnectsToNode(MapNode node) { if (node == point1 || node == point2) return true; else return false; }
protected override List<Point> MakeDesision (MapNode node) { List<Point> nextSet; float yDirection = Player.player.transform.position.y - transform.position.y; float xDirection = Player.player.transform.position.x - transform.position.x; if (Mathf.Abs (xDirection) > Mathf.Abs (yDirection)) { if (xDirection > 0) { nextSet = node.East; } else { nextSet = node.West; } } else { if (yDirection > 0) { nextSet = node.North; } else { nextSet = node.South; } } //prevents backtracking or non valid direction //defaults to random in that case if (nextSet.Count <= 0 || (lastNode != null && node.GetNodeFor(nextSet) == lastNode)) { return base.MakeDesision (node); } return nextSet; }
/// <summary> /// Given a map node Decides what direction to go in /// </summary> /// <returns>The next set of directions.</returns> /// <param name="node">Node.</param> protected virtual List<Point> MakeDesision (MapNode node) { List<Point> nextSet; int random = Random.Range (1, 5); switch (random) { case 1: nextSet = node.North; break; case 2: nextSet = node.East; break; case 3: nextSet = node.South; break; case 4: nextSet = node.West; break; default: return MakeDesision (node); } //Make sure we're not choosing a path that doesn't exist if (nextSet.Count <= 0 || (lastNode != null && node.GetNodeFor(nextSet) == lastNode)) { return MakeDesision (node); } return nextSet; }
public MapNode GetOppositeEnd(MapNode point) { if (point == point1) return point2; else return point1; }
public void CreateRandom() { double LinkProb = 0.3; for(int x = 0; x < xLength; x++) { for(int y = 0; y < yLength; y++) { GridArray[x, y] = new MapNode(x, y, true); } } for(int x = 0; x < xLength; x++) { for(int y = 0; y < yLength; y++) { Node Current = GridArray[x, y]; Node[] Neighbors = GetAdjacent(Current); System.Random random = new System.Random(); foreach(Node n in Neighbors) { if(random.NextDouble() < LinkProb) { if(n.GetPosition().GetX() == Current.GetPosition().GetX() || n.GetPosition().GetY() == Current.GetPosition().GetY()) LinkNodes(Current, n, Cardinal); else LinkNodes(Current, n, Diagonal); } } } } }
public void ProcessNodeItem(MapNode heroNode, MapNode node) { fightIsOver = false; node.item.InteractWithHero(this); // do smth // and finally unset item }
public bool IsComplete(MapNode start, MapNode end) { if (path.Count > 0) { if (path[0] == start && path[path.Count-1] == end) return true; } return false; }
public int Compare(MapNode One, MapNode Two) { if(One.GetFScore() < Two.GetFScore ()) return -1; else if(One.GetFScore() > Two.GetFScore()) return 1; else return 0; }
public void Init(GameManager manager, string name, MapNode node) { this.gameManager = manager; this.itemName = name; originalColor = hoverSprite.color; node.item = this; this.node = node; }
public NodeConnection GetConnectionToNode(MapNode node) { foreach (NodeConnection connection in connections) { if (connection.ConnectsToNode(node)) return connection; } return null; }
public void AddNode(MapNode node) { path.Add(node); if (path.Count > 1) { NodeConnection connection = path[path.Count-2].GetConnectionToNode(path[path.Count-1]); length += connection.GetDistance(); combinedRisk += connection.risk; } }
public Map(int width, int height) { this.width = width; this.height = height; nodes = new MapNode[height][]; for (int i = 0; i < nodes.Length; i += 1) { nodes[i] = new MapNode[width]; } }
/// <summary> /// Initializes a new instance of the <see cref="MapEdge"/> class between the two given map nodes. The nodes' /// internal edge lists are updated to contain this instance. /// </summary> /// <param name='fromNode'> /// The "from" node. /// </param> /// <param name='toNode'> /// The "to" node. /// </param> public MapEdge(MapNode fromNode, MapNode toNode) { FromNode = fromNode; ToNode = toNode; fromNode.edges.Add(this); toNode.edges.Add(this); ruleType = toNode.ruleType; }
/* CreateGrid() uses info from MapLayoutManager for dimensions * of map to instantiate the grid. * */ void CreateGrid(MapNode[,] GridLength) { for(int x = 0; x < GridLength.GetLength(0); x++) { for(int z = 0; z < GridLength.GetLength(1); z++) { Transform gameObject = transform; Transform instance = (Transform) Instantiate(GridPrefab, new Vector3(x, 0, z), Quaternion.identity); instance.parent = gameObject; } } }
public void Create(string loc, DateTime lastModified, string prioity, ChangeFrequency changeFrequency) { var node = new MapNode { Loc = loc, Priority = prioity, ChangeFrequenty = changeFrequency.ToString().ToLowerInvariant(), LastModified = lastModified.ToString("yyyy-MM-ddThh:mm:ssK") }; List.Add(node); }
/* Instantiates Terrain by taking a message from MapLayoutManager. * Calls for information from each MapNode to instantiate different * prefabs for each terrain type. * */ private void InstantiateTerrain(MapNode[,] TerrainLayout) { for(int x = 0; x < TerrainLayout.GetLength(0); x++) { for(int z = 0; z < TerrainLayout.GetLength(1); z++) { Transform gameObject = transform; Transform instance = (Transform) Instantiate(TerrainLayout[x,z].GetTerrain(), new Vector3(x, 0, z), Quaternion.identity); instance.parent = gameObject; } } }
public void Init(MapNode node) { this.currentNode = node; currentRegion = regionManager.GetRegion(node.InternalName); nameText.text = currentRegion.DisplayedName; regionSpellsList.Init(currentRegion); yourRegionSpellsList.Init(currentRegion); gameObject.SetActive(true); }
public static void Open(MapNode node) { GameObject obj = (GameObject) Instantiate(Resources.Load("GUI/LocationInfoPanel")); obj.transform.SetParent(GameObject.Find("ScreenSpaceCanvas").transform, false); LocationInfoPanel panel = obj.GetComponent<LocationInfoPanel>(); panel.locationData = MapLocationDatabase.Instance.GetLocationData(node.locationID); panel.mapNode = node; if (currentOpenPanel != null) currentOpenPanel.Close(); currentOpenPanel = panel; }
// ADD A TILE OF TILE TYPE NUMBER tileNum AT COORD (x,y) // Return MapNode if successful, Return null and reject addition if tile already present at (x,y) public MapNode AddTileToMap(int x, int y, int tileNum) { //Debug.Log ("Add Tile At: "+x + " , " + y+ "???"); // First Check whether or not tile already exists if (DoesTileExist (x, y)) { return RegenerateTile(x,y); } // Make sure map is large enough - Expand if necessary if (x >= sizeE) { ExpandEast(); } if (y >= sizeN) { ExpandNorth(); } if ((0-x) >= sizeW ) { // Compare -x to sizeW ExpandWest(); } if ((0-y) >= sizeS) { // Compare -y to sizeS ExpandSouth(); } // Add Tile to relvant quadrant if (x >= 0 & y >= 0) { // Tile in NE Quadrant int e = x; // Convert x coord to east index int n = y; // Convert y coord to north index mapNE[e,n] = new MapNode(tileNum); return mapNE[e,n]; } if (x >= 0 & y < 0) { // Tile in SE Quadrant int e = x; // Convert x coord to east index int s = 0 - y; // Convert y coord to south index mapSE[e,s] = new MapNode(tileNum); return mapSE[e,s]; } if (x < 0 & y >= 0) { // Tile in NW Quadrant int w = 0 - x; // Convert x coord to west index int n = y; // Convert y coord to north index mapNW[w,n] = new MapNode(tileNum); return mapNW[w,n]; } if (x < 0 & y < 0) { // Tile in SW Quadrant int w = 0 - x; // Convert x coord to west index int s = 0 - y; // Convert y coord to south index mapSW[w,s] = new MapNode(tileNum); return mapSW[w,s]; } return null; }
public static MapPath GetMapPath(MapNode fromNode, MapNode toNode) { //Debug.Log("GetMapPath!"); //create a path to begin exploring MapPath bestPath = new MapPath(); bestPath.AddNode(fromNode); //create a list of possible paths List<MapPath> paths = new List<MapPath>(); paths.Add(bestPath); List<NodeConnection> newConnections; MapNode currentNode; MapNode tempNode; while (bestPath != null) { //Debug.Log ("-----------------------START LOOP!"); if (bestPath.IsComplete(fromNode, toNode)) { //Debug.Log("Found Complete path!"); break; } currentNode = bestPath.EndNode; newConnections = currentNode.GetConnections(); Debug.Log("Current node "+currentNode.name); for (int i = 0; i < newConnections.Count; i++) { tempNode = newConnections[i].GetOppositeEnd(currentNode); if (!bestPath.path.Contains(tempNode)) { //Debug.Log("Added new path!"); MapPath newPath = new MapPath(bestPath); newPath.AddNode(tempNode); paths.Add(newPath); } } paths.Remove(bestPath); bestPath = GetBestPath(paths); } return bestPath; }
void FollowDirections () { if (directionsIndex >= curDirections.Count) { //When a set of directions are over, the AI will be sitting on the next node MapNode curNode = MapInfo.map.GetNodeAt(transform.position.x, transform.position.y); //When the AI reaches the first node, this check catches the null ref //There is no way to back track back into enemy spawn so this is fine directionsIndex = 0; curDirections = MakeDesision (curNode); lastNode = curNode; } Point nextDirection = curDirections [directionsIndex]; directionsIndex++; MoveTo (nextDirection.x + transform.position.x, nextDirection.y + transform.position.y, FollowDirections); }
public void MoveToRegion(MapNode node, WizardMoveCallback callback) { Debug.Log("Moving Icon to Region"); this.moveCallback = callback; RectTransform rect = GetComponent<RectTransform>(); RectTransform target = node.GetComponent<RectTransform>(); start = new Vector2(rect.position.x, rect.position.y); end = new Vector2(target.position.x + OffsetX, target.position.y + OffsetY); progress = 0f; moving = true; }
// Use this for initialization void Start() { mNodes = new MapNode[7]; for (int i=0; i<mNodes.Length; i++) { mNodes[i] = new MapNode(); mNodes[i].mUnit = Instantiate(prefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject; mNodes[i].mId = i; if (i>0) { //Debug.Log(i % 6); mNodes[0].AddNeighbor((i % 6), mNodes[i], true); } } }
public void CreateStandard() { for(int x = 0; x < xLength; x++) { for(int y = 0; y < yLength; y++) { GridArray[x, y] = new MapNode(x, y, true); } } for(int x = 0; x < xLength; x++) { for(int y = 0; y < yLength; y++) { Node Current = GetNode(x, y); Node[] Neighbors = GetAdjacent(Current); foreach(Node n in Neighbors) { if(n.GetPosition().GetX() == x || n.GetPosition().GetY() == y) LinkNodes(Current, n, Cardinal); else LinkNodes(Current, n, Diagonal); } } } }
public void CheckConnect(int index, MapNode newNode, bool isLeft = true) { MapNode node = null; int edgeIndex = -1; int nodeConnectIndex = -1; if (isLeft) { edgeIndex = GetLeftEdge (index); node = mNeighbor [edgeIndex]; nodeConnectIndex = GetLeftEdge (GetOppsiteEdge (edgeIndex)); Debug.Log(nodeConnectIndex); } else { edgeIndex = GetRightEdge (index); node = mNeighbor [edgeIndex]; nodeConnectIndex = GetRightEdge (GetOppsiteEdge (edgeIndex)); } if (node != null) { node.AddNeighbor (nodeConnectIndex, newNode); } }
public void AddNeighbor(int index, MapNode node, bool assignPos = false) { if (mNeighbor [index] == null) { mNeighbor [index] = node; if (assignPos) { node.mUnit.transform.Translate(GetNeighborPosition(index)); } int oppsite = GetOppsiteEdge (index); node.AddNeighbor (oppsite, this); //Check connect left node node.CheckConnect (index, node, true); //Check connect right node node.CheckConnect (index, node, false); } }
public void Init(Map map, int x, int y, int endX, int endY) { this.map = map; // Debug.Log("Hero start at: ["+ x + ", " + y + "]"); currentGlobalNode = map.GetNode(x, y); //debugText = GameObject.FindGameObjectWithTag("DebugText").GetComponent<Text>(); //debugText.text = map.NeighborsToString(currentNode); thisTransform = GetComponent<Transform>(); destinations.Add(map.GetNode(endX, endY)); //SearchPath(currentNode); GameObject[] treasures = GameObject.FindGameObjectsWithTag("Gold"); if (treasures.Length > 0) { List<GameObject> sortedTransforms = new List<GameObject>(); for (int i = 0; i < treasures.Length; i += 1) { sortedTransforms.Add(treasures[i]); } sortedTransforms.Sort(delegate(GameObject c1, GameObject c2){ return Vector3.Distance(this.transform.position, c1.transform.position).CompareTo( Vector3.Distance(this.transform.position, c2.transform.position) ); }); for (int i = sortedTransforms.Count - 1; i > -1; i -= 1) { GameObject gold = sortedTransforms[i]; //Debug.Log(Vector3.Distance(this.transform.position, gold.transform.position)); MapNode node = map.GetNodeNormalized(gold.transform.position.x, gold.transform.position.z); //Debug.Log("NODE: ["+node.x +","+ node.y + "]"); destinations.Add(node); } } destination = destinations[destinations.Count - 1]; destinations.RemoveAt(destinations.Count - 1); openNodes.Add(currentGlobalNode); SearchPath(); gameManager = GameObject.FindGameObjectWithTag("GameManager").GetComponent<GameManager>(); }
private Dictionary <MapNode, double> GetWeightedMapNodeDistances(Board board, MapNode source, AllianceScenario allianceScenario) { Unit unit = board.OccupiedMapNodes[source]; TerritoryStrengths territoryStrengths = new TerritoryStrengths(); territoryStrengths.Init(board); Func <UndirectedEdge <MapNode>, double> WeightFunction = (edge) => { double powerCount = territoryStrengths.GetPowerCount(edge.Target.Territory, unit.Power); double totalAnimosity = allianceScenario.OutEdges(unit.Power) .Where(e => territoryStrengths.GetStrength(edge.Target.Territory, e.Target) > 0) .Sum(e => e.Animosity); return(1 + (powerCount - totalAnimosity)); }; var alg = new UndirectedDijkstraShortestPathAlgorithm <MapNode, UndirectedEdge <MapNode> >(unit.MyMap, WeightFunction); alg.SetRootVertex(source); _predecessorObserver.VertexPredecessors.Clear(); using (var foo = _predecessorObserver.Attach(alg)) { alg.Compute(); } return(alg.Distances); }
// Get the node above the given one in the map private MapNode NodeAbove(MapNode mn) { Vector2Int xy = PositionAt(mn); return((xy.y < 0 || xy.y >= height - 1) ? new MapNode() : nodes[nodes.IndexOf(mn) + width]); }
void SelectedNodes_NodeDeselected(MapNode node, SelectedNodes selectedNodes) { Canvas.Invalidate(); }
public void ClearHighlightedNode() { highlightedNode = null; Canvas.Invalidate(); }
public static void SetDueDate(MapNode node, DateTime value) { MapTree.AttributeSpec aspec = GetOrCreateAttributeSpec(node.Tree); node.AddUpdateAttribute(new MapNode.Attribute(aspec, DateHelper.ToString(value))); }
/// <summary> /// Draw node linker for the node and all its children /// </summary> /// <param name="node"></param> /// <param name="iView"></param> /// <param name="g"></param> /// <param name="drawChildren">if false, linkers are not drawn for children</param> public static void DrawNodeLinker(MapNode node, IView iView, Graphics g, bool drawChildren = true) { if (node.Parent != null) { NodeView nodeView = iView.GetNodeView(node); NodeView parentView = iView.GetNodeView(node.Parent); if (nodeView == null || parentView == null) { return; } float pos1X, pos1Y, // connector start point on parent node pos2X, pos2Y; // connector end point on current/child node float control1X, control1Y, control2X, control2Y; if (node.Pos == NodePosition.Right) { pos1X = parentView.Left + parentView.Width; } else { pos1X = parentView.Left; } pos1Y = node.Parent.Pos == NodePosition.Root || node.Parent.Shape == NodeShape.Bullet ? parentView.Top + (int)(parentView.Height / 2) - 1 : parentView.Top + parentView.Height - 1; pos2Y = node.Shape == NodeShape.Fork || node.Shape == NodeShape.None ? nodeView.Top + nodeView.Height - 1 : nodeView.Top + nodeView.Height / 2; if (node.Pos == NodePosition.Right) { pos2X = nodeView.Left; control1X = pos1X + 10; } else { pos2X = nodeView.Left + nodeView.Width; control1X = pos1X - 10; } control1Y = pos1Y; control2X = pos1X; control2Y = pos2Y; Pen p = Pens.Gray; bool disposePen = CreateCustomPen(node, ref p); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.DrawBezier(p, new PointF(pos1X, pos1Y), new PointF(control1X, control1Y), new PointF(control2X, control2Y), new PointF(pos2X, pos2Y)); DrawNodeShape(nodeView, g, p); DrawFoldedIndicator(nodeView, g, p); DrawFoldedIndicatorToNodeConnector(nodeView, g, p); if (disposePen) { p.Dispose(); } } // recursive if (drawChildren && !node.Folded) { foreach (MapNode cNode in node.ChildNodes) { DrawNodeLinker(cNode, iView, g); } } }
private void Start() { currentNode = startingLocation; }
public TextChange(MapNode node, string oldValue) { this.node = node; this.oldText = oldValue; }
/** * Helper function to draw a debug line between this and target pin * @param pin The target pin */ private void DrawDebugLine(MapNode pin) { Gizmos.color = Color.red; Gizmos.DrawLine(transform.position, pin.transform.position); }
public static List <RoutePoint> NavigateCapitals(string From, string To, double MaxLY, LocalCharacter lc, List <string> systemsToAvoid) { if (!(MapNodes.Keys.Contains(From)) || !(MapNodes.Keys.Contains(To)) || From == "" || To == "") { return(null); } double ExtraJumpFactor = 5.0; double AvoidFactor = 0.0; // clear the scores, values and parents from the list foreach (MapNode mapNode in MapNodes.Values) { mapNode.NearestToStart = null; mapNode.MinCostToStart = 0; mapNode.Visited = false; } MapNode Start = MapNodes[From]; MapNode End = MapNodes[To]; List <MapNode> OpenList = new List <MapNode>(); List <MapNode> ClosedList = new List <MapNode>(); MapNode CurrentNode = null; // add the start to the open list OpenList.Add(Start); while (OpenList.Count > 0) { // get the MapNode with the lowest F score double lowest = OpenList.Min(mn => mn.MinCostToStart); CurrentNode = OpenList.First(mn => mn.MinCostToStart == lowest); // add the list to the closed list ClosedList.Add(CurrentNode); // remove it from the open list OpenList.Remove(CurrentNode); // walk the connections foreach (JumpLink connection in CurrentNode.JumpableSystems) { if (connection.RangeLY > MaxLY) { continue; } MapNode CMN = MapNodes[connection.System]; if (CMN.Visited) { continue; } if (systemsToAvoid.Contains(connection.System)) { AvoidFactor = 10000; } else { AvoidFactor = 0.0; } if (CMN.MinCostToStart == 0 || CurrentNode.MinCostToStart + connection.RangeLY + ExtraJumpFactor + AvoidFactor < CMN.MinCostToStart) { CMN.MinCostToStart = CurrentNode.MinCostToStart + connection.RangeLY + ExtraJumpFactor + AvoidFactor; CMN.NearestToStart = CurrentNode; if (!OpenList.Contains(CMN)) { OpenList.Add(CMN); } } } CurrentNode.Visited = true; } // build the path List <string> Route = new List <string>(); CurrentNode = End; if (End.NearestToStart != null) { while (CurrentNode != null) { Route.Add(CurrentNode.Name); CurrentNode = CurrentNode.NearestToStart; } } List <RoutePoint> ActualRoute = new List <RoutePoint>(); for (int i = 0; i < Route.Count; i++) { RoutePoint RP = new RoutePoint(); RP.GateToTake = GateType.JumpTo; RP.LY = 0.0; RP.SystemName = Route[i]; if (i > 0) { RP.LY = EveManager.Instance.GetRangeBetweenSystems(Route[i], Route[i - 1]) / 9460730472580800.0; } ActualRoute.Add(RP); } ActualRoute.Reverse(); return(ActualRoute); }
public static List <RoutePoint> Navigate(string From, string To, bool UseJumpGates, bool UseThera, RoutingMode routingMode) { if (!(MapNodes.Keys.Contains(From)) || !(MapNodes.Keys.Contains(To)) || From == "" || To == "") { return(null); } // clear the scores, values and parents from the list foreach (MapNode mapNode in MapNodes.Values) { mapNode.NearestToStart = null; mapNode.MinCostToStart = 0; mapNode.Visited = false; switch (routingMode) { case RoutingMode.PreferLow: { if (mapNode.HighSec) { mapNode.Cost = 1000; } } break; case RoutingMode.Safest: { if (!mapNode.HighSec) { mapNode.Cost = 1000; } } break; case RoutingMode.Shortest: mapNode.Cost = 1; break; } } MapNode Start = MapNodes[From]; MapNode End = MapNodes[To]; List <MapNode> OpenList = new List <MapNode>(); List <MapNode> ClosedList = new List <MapNode>(); MapNode CurrentNode = null; // add the start to the open list OpenList.Add(Start); while (OpenList.Count > 0) { // get the MapNode with the lowest F score double lowest = OpenList.Min(mn => mn.MinCostToStart); CurrentNode = OpenList.First(mn => mn.MinCostToStart == lowest); // add the list to the closed list ClosedList.Add(CurrentNode); // remove it from the open list OpenList.Remove(CurrentNode); // walk the connections foreach (string connectionName in CurrentNode.Connections) { MapNode CMN = MapNodes[connectionName]; if (CMN.Visited) { continue; } if (CMN.MinCostToStart == 0 || CurrentNode.MinCostToStart + CMN.Cost < CMN.MinCostToStart) { CMN.MinCostToStart = CurrentNode.MinCostToStart + CMN.Cost; CMN.NearestToStart = CurrentNode; if (!OpenList.Contains(CMN)) { OpenList.Add(CMN); } } } if (UseJumpGates && CurrentNode.JBConnection != null) { MapNode JMN = MapNodes[CurrentNode.JBConnection]; if (!JMN.Visited && JMN.MinCostToStart == 0 || CurrentNode.MinCostToStart + JMN.Cost < JMN.MinCostToStart) { JMN.MinCostToStart = CurrentNode.MinCostToStart + JMN.Cost; JMN.NearestToStart = CurrentNode; if (!OpenList.Contains(JMN)) { OpenList.Add(JMN); } } } if (UseThera && CurrentNode.TheraConnections != null) { foreach (string theraConnection in CurrentNode.TheraConnections) { MapNode CMN = MapNodes[theraConnection]; if (CMN.Visited) { continue; } if (CMN.MinCostToStart == 0 || CurrentNode.MinCostToStart + CMN.Cost < CMN.MinCostToStart) { CMN.MinCostToStart = CurrentNode.MinCostToStart + CMN.Cost; CMN.NearestToStart = CurrentNode; if (!OpenList.Contains(CMN)) { OpenList.Add(CMN); } } } } /* Todo : Additional error checking * if (UseThera && !string.IsNullOrEmptyCurrent(Node.TheraInSig)) * { * //SJS HERE ERROR * } */ CurrentNode.Visited = true; } // build the path List <string> Route = new List <string>(); bool rootError = false; CurrentNode = End; if (End.NearestToStart != null) { while (CurrentNode != null) { Route.Add(CurrentNode.Name); CurrentNode = CurrentNode.NearestToStart; if (Route.Count > 2000) { rootError = true; break; } } Route.Reverse(); } List <RoutePoint> ActualRoute = new List <RoutePoint>(); if (!rootError) { for (int i = 0; i < Route.Count; i++) { RoutePoint RP = new RoutePoint(); RP.SystemName = Route[i]; RP.ActualSystem = EveManager.Instance.GetEveSystem(Route[i]); RP.GateToTake = GateType.StarGate; RP.LY = 0.0; if (i < Route.Count - 1) { MapNode mn = MapNodes[RP.SystemName]; if (mn.JBConnection != null && mn.JBConnection == Route[i + 1]) { RP.GateToTake = GateType.Ansiblex; } if (UseThera && mn.TheraConnections != null && mn.TheraConnections.Contains(Route[i + 1])) { RP.GateToTake = GateType.Thera; } } ActualRoute.Add(RP); } } return(ActualRoute); }
public static void InitNavigation(List <System> eveSystems, List <JumpBridge> jumpBridges) { MapNodes = new Dictionary <string, MapNode>(); TheraLinks = new List <string>(); // build up the nav structures foreach (System sys in eveSystems) { MapNode mn = new MapNode { Name = sys.Name, HighSec = sys.TrueSec > 0.45, Pochven = sys.Region == "Pochven", Connections = new List <string>(), JumpableSystems = new List <JumpLink>(), Cost = 1, MinCostToStart = 0, X = sys.ActualX, Y = sys.ActualY, Z = sys.ActualZ, F = 0, ActualSystem = sys }; foreach (string s in sys.Jumps) { mn.Connections.Add(s); } MapNodes[mn.Name] = mn; } UpdateJumpBridges(jumpBridges); double MaxRange = 10 * 9460730472580800.0; // now create the jumpable system links foreach (MapNode mn in MapNodes.Values) { foreach (System sys in eveSystems) { // cant jump into highsec systems if (sys.TrueSec > 0.45) { continue; } // cant jump into Pochven systems if (sys.Region == "Pochven") { continue; } double Distance = EveManager.Instance.GetRangeBetweenSystems(sys.Name, mn.Name); if (Distance < MaxRange && Distance > 0) { JumpLink jl = new JumpLink(); jl.System = sys.Name; jl.RangeLY = Distance / 9460730472580800.0; mn.JumpableSystems.Add(jl); } } } }
public bool TryGetMoveTargetValidateWithBoardMove(Board board, MapNode source, AllianceScenario allianceScenario, BoardMove boardMove, out List <MapNode> path, out UnitMove move) { if (!board.OccupiedMapNodes.ContainsKey(source)) { throw new Exception($"No unit occupies {source} in the given board"); } var movesAvailableForSource = boardMove.GetAvailableFallSpringMovesForMapNode(board, source); if (movesAvailableForSource.Count == 0) { // couldn't find anything. // this is caused by picking moves that lead to a contradiction. // Force the caller to deal, perhaps with a hold on all affected... path = null; move = null; return(false); } Unit unit = board.OccupiedMapNodes[source]; Coalition myCoalition = allianceScenario.GetPossibleCoalitions()[unit.Power]; List <KeyValuePair <MapNode, double> > orderedDistances = GetWeightedMapNodeDistances(board, source, allianceScenario) .OrderBy(kvp2 => kvp2.Value).ToList(); // are we sitting on a supplycenter that we want? If so, hold if (source.Territory.IsSupplyCenter && !board.SupplyCenterIsOwnedBy(source.Territory, myCoalition)) { UnitMove holdMove = new UnitMove(unit, source); if (boardMove == null || boardMove.CurrentlyAllowsFallSpring(holdMove)) { path = new List <MapNode>() { source }; move = holdMove; return(true); } } List <Func <MapNode, bool> > predicateList = new List <Func <MapNode, bool> >() { (mn) => { return(mn.Territory.IsSupplyCenter && !board.SupplyCenterIsOwnedBy(mn.Territory, myCoalition)); }, (mn) => { return(mn.Territory != source.Territory); }, (mn) => { return(mn.Territory == source.Territory); }, }; foreach (var predicate in predicateList) { path = GetPath(board, source, boardMove, orderedDistances, predicate); if (path != null) { MapNode moveTarget = path[1]; move = board.GetUnitMoves().FirstOrDefault(um => um.Edge.Source == source && um.Edge.Target == moveTarget); return(true); } } UnitMove lastResort = movesAvailableForSource.First(); path = new List <MapNode>() { lastResort.Edge.Target }; move = lastResort; return(true); }
private void Tree_TreeStructureChanged(MapNode node, TreeStructureChangedEventArgs e) { TreeChanged(); }
private void Tree_AttributeChanged(MapNode node, AttributeChangeEventArgs e) { TreeChanged(); }
/// <summary> /// Processes SPARQL Algebra /// </summary> /// <param name="algebra">Algebra</param> /// <param name="context">SPARQL Evaluation Context</param> public string ProcessAlgebra(ISparqlAlgebra algebra) { string sql = ""; if (algebra is IBgp) //a tripple pattern { //here use the value from mapping Bgp bgp = algebra as Bgp; //foreach(TriplePattern triplePattern in bgp.TriplePatterns) //{ // sql += this.mapping.GetMappingForTripple(triplePattern.Subject.ToString(), triplePattern.Predicate.ToString(), triplePattern.Object.ToString()); //} List <ITriplePattern> patterns = bgp.TriplePatterns.ToList(); if (patterns.Count >= 2) { TriplePattern p1 = patterns[0] as TriplePattern; TriplePattern p2 = patterns[1] as TriplePattern; MapNode mNode1 = mapping.GetMapNodeForTripple(p1.Subject.ToString(), p1.Predicate.ToString(), p1.Object.ToString()); MapNode mNode2 = mapping.GetMapNodeForTripple(p2.Subject.ToString(), p2.Predicate.ToString(), p2.Object.ToString()); //perform inner joins between them string sql1 = mapping.MergeSqlDBString(mNode1); string sql2 = mapping.MergeSqlDBString(mNode2); sql = $"{InnerJoin(sql1, sql2)}"; Console.WriteLine("\n\n{0}", sql); //sql += $"{InnerJoin(patterns[0], patterns[1])}"; } else { sql += $"({patterns[0]})"; } } else if (algebra is Select) { Select select = algebra as Select; string variables = select.IsSelectAll ? "*" : string.Join(",", select.FixedVariables); string from = ProcessAlgebra(select.InnerAlgebra); sql = $"SELECT {variables}\nFROM ({from}) \nWHERE *"; } //else if (algebra is IFilter) //{ // return this.ProcessFilter((IFilter)algebra); //} ////else if (algebra is Algebra.Graph) ////{ //// return this.ProcessGraph((Algebra.Graph)algebra, context); ////} //else if (algebra is IJoin) //{ // return this.ProcessJoin((IJoin)algebra); //} //else if (algebra is ILeftJoin) //{ // return this.ProcessLeftJoin((ILeftJoin)algebra); //} //else if (algebra is IUnion) //{ // return this.ProcessUnion((IUnion)algebra); //} //else //{ // //Unknown Algebra // throw new Exception("ProcessAlgebra(): Unknown algebra!"); //} return(sql); }
private IEnumerator FindPathCoroutine() { MapNode start = StartTile.Node; MapNode end = EndTile.Node; IPathfinder algo = PathfindersFactory.GetPathfinderForType(Settings.Pathfinder); yield return(algo.FindPath( start, end, Settings.AnimateSearch, (node) => { if (!node.HasObstacle) { Tile tile = _nodeToTile[node]; tile.SetColor(Color.green); if (_tileDebugStyle == TileDebugStyle.Cost) { tile.ShowCost(); } } }, (node) => { if (!node.HasObstacle) { Tile tile = _nodeToTile[node]; tile.SetColor(Color.gray); if (_tileDebugStyle == TileDebugStyle.Cost) { tile.ShowCost(); } } } )); List <MapNode> path = new List <MapNode>(); MapNode current = end.CameFrom; while (current != null) { if (current.CameFrom == null && current != start) { path = null; break; } if (current != start) { path.Add(current); } current = current.CameFrom; } if (path != null && path.Count > 0) { for (int i = path.Count - 1; i >= 0; i--) { if (!path[i].HasObstacle) { _nodeToTile[path[i]].SetColor(Color.white); yield return(new WaitForSeconds(0.05f)); } } } else { //notify the player string message = "Could not find a path"; Debug.Log(message); MessagePanel.ShowMessage(message); } yield return(null); }
static public MapData FromFile(string fileName) { MapData mapData = new MapData(); FileStream mapFile = new FileStream(fileName, FileMode.Open, FileAccess.Read); using (StreamReader sr = new StreamReader(mapFile)) { string s = sr.ReadLine(); string[] stringFormattedNode; if (s != null) { stringFormattedNode = s.Split(','); mapData.Name = stringFormattedNode[0]; mapData.Name2 = stringFormattedNode[1]; mapData.NotSure = new List <Point>(); for (int i = 2; i < stringFormattedNode.Length; i += 2) { mapData.NotSure.Add(new Point() { x = double.Parse(stringFormattedNode[i]), y = double.Parse(stringFormattedNode[i + 1]), z = 0 }); } mapData.MapBounds = new Bounds() { east = double.MaxValue, south = double.MaxValue, west = double.MinValue, north = double.MinValue }; } while (!sr.EndOfStream) { s = sr.ReadLine(); if ((s != null) && (s != "")) { stringFormattedNode = s.Split(','); if (stringFormattedNode.Length < 5) { continue; } MapNode mapNode = new MapNode(); mapNode.entity = stringFormattedNode[0][0]; mapNode.name = stringFormattedNode[1]; mapNode.color = stringFormattedNode[2]; int pointsStart = 4; if (mapNode.entity == 'P') { mapNode.numPoints = 1; pointsStart = 3; } else { mapNode.numPoints = double.Parse(stringFormattedNode[3]); } mapNode.points = new List <Point>(); int displacement = 0; for (; pointsStart < stringFormattedNode.Length; pointsStart += displacement) { double Z = 0; displacement = 2; if (mapNode.entity == 'M') { Z = double.Parse(stringFormattedNode[pointsStart + 2]); displacement = 3; } Point newPoint = new Point() { x = double.Parse(stringFormattedNode[pointsStart]), y = double.Parse(stringFormattedNode[pointsStart + 1]), z = Z }; mapNode.points.Add(newPoint); // Point is west of 0,0 if ((newPoint.x > mapData.MapBounds.west)) { mapData.MapBounds.west = newPoint.x; } // Point is east of 0,0 else if ((newPoint.x < mapData.MapBounds.east)) { mapData.MapBounds.east = newPoint.x; } // Point is north of 0,0 if ((newPoint.y > mapData.MapBounds.north)) { mapData.MapBounds.north = newPoint.y; } // Point is south of 0,0 else if ((newPoint.y < mapData.MapBounds.south)) { mapData.MapBounds.south = newPoint.y; } } mapData.Data.Add(mapNode); } } } return(mapData); }
public void TestMethod1() { SearchController sut = null; int eventNum = 1; Exception exception = null; Task task = Task.Run(() => { var t = new MapTree(); var r = new MapNode(t, "r"); var c1 = new MapNode(r, "c1"); var c11 = new MapNode(c1, "c11"); var c12 = new MapNode(c1, "c12"); var c121 = new MapNode(c12, "c121"); var c13 = new MapNode(c1, "c13"); var c131 = new MapNode(c13, "C131"); var c2 = new MapNode(r, "c2"); var c3 = new MapNode(r, "c3", NodePosition.Left); var c31 = new MapNode(c3, "c31"); var c32 = new MapNode(c3, "c32"); r.NoteText = "This is a note text."; c11.Icons.Add("button_ok"); c11.Icons.Add("desktop_new"); c3.Icons.Add("button_ok"); c131.Icons.Add("desktop_new"); var taskScheduler = new TaskScheduler.TaskScheduler(); taskScheduler.Start(); var control = new SearchControl(); sut = new SearchController(control, () => t, act => taskScheduler.AddTask(act, DateTime.Now)); var form = new Form(); form.Controls.Add(control); var timer = new System.Windows.Forms.Timer(); timer.Interval = 5; form.Shown += (o, e) => timer.Start(); var shown = new EventHandler((obj, evn) => ((Form)obj).DialogResult = DialogResult.OK); //for IconSelectorExt dialog timer.Tick += (o, e) => { try { switch (eventNum) { case 1: Assert.AreEqual(0, control.lstResults.Items.Count); break; case 2: control.txtSearch.Text = "c1"; break; case 3: while (taskScheduler.TaskCount != 0) { return; //return without moving to next eventNum } Assert.AreEqual(6, control.lstResults.Items.Count); break; case 4: control.txtSearch.Text = "c1"; control.txtSearch.Text = "c1"; control.txtSearch.Text = "c1"; control.txtSearch.Text = "c1"; control.txtSearch.Text = "c1"; break; case 5: while (taskScheduler.TaskCount != 0) { return; } Assert.AreEqual(6, control.lstResults.Items.Count); control.btnSelect.PerformClick(); Assert.AreEqual(6, t.SelectedNodes.Count); control.btnClear.PerformClick(); Assert.AreEqual(0, control.lstResults.Items.Count); break; case 6: control.txtSearch.Text = "rr"; break; case 7: while (taskScheduler.TaskCount != 0) { return; } Assert.AreEqual(0, control.lstResults.Items.Count); break; case 8: control.txtSearch.Text = "r"; control.btnSearch.PerformClick(); break; case 9: while (taskScheduler.TaskCount != 0) { return; } Assert.AreEqual(1, control.lstResults.Items.Count); break; case 10: Assert.IsFalse(r.Selected); control.lstResults.SelectedIndex = 0; Assert.IsTrue(r.Selected); break; case 11: control.ckbCase.Checked = true; control.txtSearch.Text = "R"; control.btnSearch.PerformClick(); break; case 12: while (taskScheduler.TaskCount != 0) { return; } Assert.AreEqual(0, control.lstResults.Items.Count); break; case 13: control.txtSearch.Text = "note text"; control.btnSearch.PerformClick(); break; case 14: while (taskScheduler.TaskCount != 0) { return; } Assert.AreEqual(1, control.lstResults.Items.Count); break; case 15: control.ckbExcludeNote.Checked = true; control.txtSearch.Text = "note text"; control.btnSearch.PerformClick(); break; case 16: while (taskScheduler.TaskCount != 0) { return; } Assert.AreEqual(0, control.lstResults.Items.Count); break; case 17: control.ckbSelectedNode.Checked = true; c1.Selected = true; control.txtSearch.Text = "c3"; break; case 18: while (taskScheduler.TaskCount != 0) { return; } Assert.AreEqual(0, control.lstResults.Items.Count); break; case 19: control.ckbSelectedNode.Checked = true; c2.AddToSelection(); foreach (var n in c2.Descendents) { n.AddToSelection(); } control.txtSearch.Text = "c3"; break; case 20: while (taskScheduler.TaskCount != 0) { return; } Assert.AreEqual(0, control.lstResults.Items.Count); break; case 21: control.txtSearch.Text = ""; control.btnSearch.PerformClick(); break; case 22: while (taskScheduler.TaskCount != 0) { return; } Assert.AreEqual(0, control.lstResults.Items.Count); break; case 23: IconSelectorExt.Instance.Shown += shown; IconSelectorExt.Instance.SelectedIcon = "button_ok"; control.btnAddIcon.PerformClick(); Assert.AreEqual(1, control.CreateSearchTerm().Icons.Count); IconSelectorExt.Instance.SelectedIcon = "desktop_new"; control.btnAddIcon.PerformClick(); Assert.AreEqual(2, control.CreateSearchTerm().Icons.Count); control.ckbSelectedNode.Checked = false; control.btnSearch.PerformClick(); break; case 24: while (taskScheduler.TaskCount != 0) { return; } Assert.AreEqual(1, control.lstResults.Items.Count); break; case 25: control.ckbAnyIcon.Checked = true; control.btnSearch.PerformClick(); break; case 26: while (taskScheduler.TaskCount != 0) { return; } Assert.AreEqual(3, control.lstResults.Items.Count); IconSelectorExt.Instance.SelectedIcon = IconSelectorExt.REMOVE_ICON_NAME; control.btnAddIcon.PerformClick(); Assert.AreEqual(1, control.CreateSearchTerm().Icons.Count); IconSelectorExt.Instance.SelectedIcon = IconSelectorExt.REMOVE_ALL_ICON_NAME; control.btnAddIcon.PerformClick(); Assert.AreEqual(0, control.CreateSearchTerm().Icons.Count); IconSelectorExt.Instance.SelectedIcon = IconSelectorExt.REMOVE_ICON_NAME; control.btnAddIcon.PerformClick(); Assert.AreEqual(0, control.CreateSearchTerm().Icons.Count); IconSelectorExt.Instance.Shown -= shown; break; default: form.Close(); break; } eventNum++; } catch (Exception exp) { exception = exp; timer.Stop(); form.Close(); } }; form.ShowDialog(); timer.Stop(); taskScheduler.Stop(); }); task.Wait(); if (exception != null) { throw new Exception("Check Inner exception", exception); } }
public override bool Process() { if (NetworkManager.IsClient) { return(false); } // 5x5, but remove corners for (int y = TargetY - 2; y <= TargetY + 2; y++) { for (int x = TargetX - 2; x <= TargetX + 2; x++) { // check for corner tiles :) if ((x == TargetX - 2 || x == TargetX + 2) && (y == TargetY - 2 || y == TargetY + 2)) { continue; } if (x < 0 || y < 0 || x >= MapLogic.Instance.Width || y >= MapLogic.Instance.Height) { continue; } // check if there are FIRE effects on this cell, don't spawn fog bool spawnblocked = false; foreach (MapObject mo in MapLogic.Instance.Nodes[x, y].Objects) { if (!(mo is MapProjectile)) { continue; } MapProjectile mp = (MapProjectile)mo; if (mp.Class == null || mp.Class.ID != (int)AllodsProjectile.PoisonCloud) { continue; } // don't remove if on edge of fire wall if (new Vector2(mp.ProjectileX - x + 0.5f, mp.ProjectileY - y + 0.5f).magnitude > 0.8f) { continue; } spawnblocked = true; break; } if (spawnblocked) { continue; } Server.SpawnProjectileEOT(AllodsProjectile.PoisonCloud, Spell.User, x + 0.5f, y + 0.5f, 0, (int)(MapLogic.TICRATE * Spell.GetDuration()), 40, 0, 0, 16, proj => { DamageFlags spdf = SphereToDamageFlags(Spell); // get projectile cells int axFrom = Mathf.Max(0, Mathf.FloorToInt(proj.ProjectileX)); int axTo = Mathf.Min(MapLogic.Instance.Width - 1, Mathf.CeilToInt(proj.ProjectileX)); int ayFrom = Mathf.Max(0, Mathf.FloorToInt(proj.ProjectileY)); int ayTo = Mathf.Min(MapLogic.Instance.Height - 1, Mathf.CeilToInt(proj.ProjectileY)); for (int py = ayFrom; py <= ayTo; py++) { for (int px = axFrom; px <= axTo; px++) { // check how much projectile is on this cell float pdst = 1f - Mathf.Min(1f, new Vector2(px + 0.5f - proj.ProjectileX, py + 0.5f - proj.ProjectileY).magnitude); // 0..1 effect power MapNode node = MapLogic.Instance.Nodes[px, py]; for (int i = 0; i < node.Objects.Count; i++) { MapObject mo = node.Objects[i]; if (!(mo is MapUnit)) { continue; } MapUnit mov = (MapUnit)mo; int dmg = (int)(Spell.GetIndirectPower() * pdst); if (dmg <= 0) { continue; // don't add null effects } SpellEffects.Effect eff = new SpellEffects.Poison(this, dmg, MapLogic.TICRATE * 8); // originally 8 seconds mov.AddSpellEffects(eff); } } } }); } } return(false); }
public void HighlightNode(MapNode node) { highlightedNode = node; Canvas.Invalidate(); }
/// <summary> /// Returns true if successfully refreshes all node positions. If canvas is not big enough, the operation is aborted and 'false' is returned. /// </summary> /// <param name="parent"></param> /// <param name="sideToRefresh"></param> /// <returns></returns> private bool RefreshChildNodePositionsRecursive(MapNode parent, NodePosition sideToRefresh) { NodeView nView = this.GetNodeView(parent); if (!parent.HasChildren || parent.Folded) { if (!NodeWithinCanvas(parent, 50)) { return(false); } return(true); } else { for (int i = 0; i < 2; i++) { IEnumerable <MapNode> childNodes; NodePosition rpos; if (i == 0) { rpos = NodePosition.Left; childNodes = parent.ChildLeftNodes; } else { rpos = NodePosition.Right; childNodes = parent.ChildRightNodes; } float left = nView.Left + nView.Width + HOR_MARGIN; float top = nView.Top - (int)((this.GetNodeHeight(parent, rpos) - nView.Height) / 2) - ((parent.Pos == NodePosition.Root) ? (int)(nView.Height / 2) : 0); int topOffset; foreach (MapNode rnode in childNodes) { NodeView tView = this.GetNodeView(rnode); topOffset = (int)((this.GetNodeHeight(rnode, rpos) - tView.Height) / 2); if (i == 0) { left = nView.Left - tView.Width - HOR_MARGIN; } tView.RefreshPosition(left, top + topOffset); top += (topOffset * 2) + tView.Height + VER_MARGIN; if (!rnode.Folded) { // recursive call bool continueProcess = RefreshChildNodePositionsRecursive(rnode, NodePosition.Undefined); if (!continueProcess) { return(false); } } } } } return(true); }
void tree_NodePropertyChanged(MapNode node, NodePropertyChangedEventArgs e) { if (node.NodeView == null) { return; } switch (e.ChangedProperty) { case NodeProperties.Text: node.NodeView.RefreshText(); if (node == tree.RootNode) { node.NodeView.RefreshPosition(node.NodeView.Left, node.NodeView.Top); } RefreshNodePositions(tree.RootNode, node.Pos); break; case NodeProperties.Label: throw new NotImplementedException(); case NodeProperties.NoteText: node.NodeView.RefreshNoteIcon(); if (node == Tree.RootNode) { node.NodeView.RefreshPosition(node.NodeView.Left, node.NodeView.Top); } RefreshNodePositions(node.Parent ?? node, NodePosition.Undefined); break; case NodeProperties.Bold: case NodeProperties.Italic: case NodeProperties.Strikeout: node.NodeView.RefreshFont(); if (node == tree.RootNode) { node.NodeView.RefreshPosition(node.NodeView.Left, node.NodeView.Top); } RefreshNodePositions(tree.RootNode, node.Pos); break; case NodeProperties.Folded: RefreshNodePositions(tree.RootNode, node.Pos); break; case NodeProperties.FontName: case NodeProperties.FontSize: node.NodeView.RefreshFont(); if (node == tree.RootNode) { node.NodeView.RefreshPosition(node.NodeView.Left, node.NodeView.Top); } RefreshNodePositions(tree.RootNode, node.Pos); break; case NodeProperties.Link: node.NodeView.RefreshLink(); if (node == tree.RootNode) { node.NodeView.RefreshPosition(node.NodeView.Left, node.NodeView.Top); RefreshNodePositions(node, NodePosition.Undefined); } else { RefreshNodePositions(node.Parent, NodePosition.Undefined); } break; case NodeProperties.Image: case NodeProperties.ImageAlignment: throw new NotImplementedException(); } Canvas.Invalidate(); }
// Get the x,y position of the MapNode public Vector2Int PositionAt(MapNode mn) { int result = nodes.IndexOf(mn); return(new Vector2Int(result % width, result / width)); }
public MapNode GetMapNodeFromPoint(System.Drawing.Point point) { MapNode node = this.Tree.RootNode; return(GetMapNodeFromPoint(point, node)); }
private void Tree_IconChanged(MapNode node, IconChangedEventArgs e) { TreeChanged(); }
/// <summary> /// /// </summary> /// <param name="mapNode">Shouldn't be root node</param> /// <param name="point"></param> /// <param name="topDown"></param> /// <returns></returns> private static MapNode GetMapNodeFromPoint(MapNode mapNode, Point point, bool topDown) { MapNode node = mapNode; MapNode nextNode = null; do { if (node.NodeView == null) { return(null); } if (node.NodeView.IsPointInsideNode(point)) { return(node); } else { nextNode = topDown ? node.Next : node.Previous; if (nextNode?.Pos != node.Pos) { nextNode = null; //this is required for first level only (children of root) } if (node.HasChildren && !node.Folded) { if ( ( (node.Pos == NodePosition.Right && point.X > node.NodeView.Right + MapView.HOR_MARGIN) || //right node (node.Pos == NodePosition.Left && point.X < node.NodeView.Left - MapView.HOR_MARGIN) //left node ) && (nextNode == null || ( (topDown && point.Y < nextNode.NodeView.Top) || (!topDown && point.Y > nextNode.NodeView.Bottom) ) ) ) { bool topDownForChildren = point.Y - node.NodeView.Top < 0; var result = GetMapNodeFromPoint(topDownForChildren? node.FirstChild : node.LastChild, point, topDownForChildren); if (result != null) { return(result); } } } } if (topDown) { if (point.Y < node.NodeView.Bottom) { break; } } else { if (point.Y > node.NodeView.Top) { break; } } //get next sibling node = nextNode; }while (node != null); return(null); }
// Get the node below the given one in the map private MapNode NodeBelow(MapNode mn) { Vector2Int xy = PositionAt(mn); return((xy.y < 1 || xy.y >= height) ? new MapNode() : nodes[nodes.IndexOf(mn) - width]); }
public bool TryGetMoveTarget(Board board, MapNode source, AllianceScenario allianceScenario, out List <MapNode> path, out UnitMove move) { return(TryGetMoveTargetValidateWithBoardMove(board, source, allianceScenario, null, out path, out move)); }
private void Tree_NodePropertyChanged(MapNode node, NodePropertyChangedEventArgs e) { TreeChanged(); }