/// <summary> /// Adds a supply line from this tile to a baseTile. /// </summary> /// <param name="baseTile">Tile to link a supply line to.</param> public void AddSupplyLine(GameObject baseTile) { //Add logic to check what the other is, and attempt to create a path to that location. HexEntity hex = baseTile.GetComponent <HexEntity>(); if (hex == null) { // do nothing. } else { //create a path between this tile and that one. if (pathObject != null) { Destroy(pathObject); pathObject = null; } GameObject armyTile = Global.MapFlyWeight.hexMap[Position]; pathObject = Instantiate(Global.MapFlyWeight.hexPathPrefab); HexPath path = pathObject.GetComponent <HexPath>(); path.Initialize(); List <GameObject> hexes = Global.MapFlyWeight.getPlayerAdjacencyMap(this.Controller).NearestAstar(armyTile, baseTile); path.AddHexes(hexes); supplyLines.Add(path); } }
public void DeleteOrder(HexPath path) { TransportOrder order = supplyLines.First(x => x.requestor == path); supplyLines.Remove(order); allocateLabor(); }
public void CreateOrder(HexPath path) { TransportOrder order = new TransportOrder(); order.requestor = path; order.amount = path.army.Manpower; supplyLines.Add(order); allocateLabor(); }
internal void AddPath(HexTile hexTile) { HexPath path = new HexPath(hexTile); Vector3 direction = hexTile.position - position; direction.y = 0.0f; float angle = Vector3.SignedAngle(Vector3.back, direction, Vector3.up) + 150.0f; path.index = Mathf.RoundToInt(angle / 60.0f); neighbors.Add(path); }
public bool AddNeighbour(HexNode neighbour) { foreach (HexPath path in neighbours) { if (path.toNode.IsAt(neighbour.pos)) { return(false); } } var outPath = new HexPath(this, neighbour); neighbours.Add(outPath); return(true); }
public void RefreshSupplyLines() { if (pathObject == null) { return; } HexPath path = pathObject.GetComponent <HexPath>(); if (path == null) { return; } GameObject armyTile = Global.MapFlyWeight.hexMap[Position]; List <GameObject> hexes = Global.MapFlyWeight.getPlayerAdjacencyMap(this.Controller).NearestAstar(armyTile, path.GetHex(path.Length() - 1)); path.Refresh(hexes); }
public void MoveToHex() { paths = new List <Vector3>(); List <Hex> path = new List <Hex>(); List <Vector3> points = new List <Vector3>(); path.Add(moveToHex); points.Add(moveToHex.position); /* * Vector3 normal = Vector3.Normalize() * points.Add(moveToHex.position);*/ while (path.Count != 3) { HexPath nextHex = movableHexes[path[path.Count - 1]]; path.Add(nextHex.from); points.Add(nextHex.from.position); if (nextHex.from == hex) { break; } } Vector3 normal = Vector3.Normalize(points[1] - points[0]) * 2f; points.Insert(0, points[0] - normal); normal = Vector3.Normalize(points[points.Count - 1] - points[points.Count - 2]) * 2f; points.Add(points[points.Count - 1] + normal); paths.AddRange(points); List <Vector3> movingPoints = CurveCreator.CreateCurve(points, 3, Alpha.Uniform); StartCoroutine(nameof(MoveAnimation), movingPoints); movableHexes.Clear(); hex = moveToHex; moveToHex = null; }
public static Dictionary <Hex, HexPath> GetMovableHexes(Hex startHex, int moveCount, Unit unit) { Dictionary <Hex, HexPath> movableHexes = new Dictionary <Hex, HexPath>(); Dictionary <Hex, HexPath> usedHexes = new Dictionary <Hex, HexPath>(); Queue <HexPath> queue = new Queue <HexPath>(); HexPath start = new HexPath(startHex); usedHexes.Add(startHex, start); queue.Enqueue(start); //MapController.sprites[startHex.x, startHex.y].color = Color.blue; while (queue.Count > 0) { HexPath hex = queue.Dequeue(); //queue.RemoveAt(queue.Count - 1); bool isOdd = hex.to.y % 2 != 0; for (int i = 0; i < 6; i++) { Hex neighbour; if (!Util.HexExist(isOdd, hex.to.x, hex.to.y, i, out neighbour)) { continue; } int distance = hex.distance + Util.GetDistanceFromHex(neighbour, unit); if (distance > moveCount) { if (!usedHexes.ContainsKey(neighbour)) { HexPath neighbourPathFailed = new HexPath(hex.to, neighbour, distance); usedHexes.Add(neighbour, neighbourPathFailed); } continue; } if (usedHexes.ContainsKey(neighbour)) { if (usedHexes[neighbour].distance <= distance) { continue; } if (!usedHexes.ContainsKey(neighbour)) { movableHexes.Add(neighbour, usedHexes[neighbour]); } usedHexes[neighbour].distance = distance; usedHexes[neighbour].from = hex.to; queue.Enqueue(usedHexes[neighbour]); //MapController.sprites[neighbour.x, neighbour.y].color = Color.green; //var texts = MapController.sprites[neighbour.x, neighbour.y].transform.GetComponentInChildren<Text>(); //texts.text = $"{distance}"; continue; } HexPath neighbourPath = new HexPath(hex.to, neighbour, distance); queue.Enqueue(neighbourPath); movableHexes.Add(neighbour, neighbourPath); //MapController.sprites[neighbour.x, neighbour.y].color = Color.green; //var text = MapController.sprites[neighbour.x, neighbour.y].transform.GetComponentInChildren<Text>(); //text.text = $"{neighbourPath.distance}"; usedHexes.Add(neighbour, neighbourPath); } } return(movableHexes); }