Ejemplo n.º 1
0
        public bool MoveToFormation(UnitSelector unit)
        {
            if (failedTypes.Contains(unit.Unit.UnitType))
            {
                return(false);
            }

            var targetTile = map.GetTileByTopLeftCorner(spiral.Current);

            while (targetTile == null &&
                   (spiral.ContainingSquareSize < map.Width ||
                    spiral.ContainingSquareSize < map.Length))
            {
                //Move the spiral coords
                spiral.MoveNext();
            }

            if (targetTile == null)
            {
                return(false);
            }

            if (unit.Order(new MoveOrder(map.PathFinding.GetTileNode(targetTile))))
            {
                //Move the spiral coords only on successfully filling the position
                spiral.MoveNext();
                return(true);
            }

            failedTypes.Add(unit.Unit.UnitType);
            return(false);
        }
Ejemplo n.º 2
0
        public MapFormationController(IMap map, ITile tile)
        {
            this.map = map;
            spiral   = new Spiral(tile.MapLocation).GetSpiralEnumerator();
            spiral.MoveNext();

            failedTypes = new HashSet <UnitType>();
        }
Ejemplo n.º 3
0
        public bool MoveToFormation(UnitSelector unit)
        {
            bool executed = false;

            while (!executed &&
                   spiralPositions.MoveNext() &&
                   spiralPositions.ContainingSquareSize < maxSize &&
                   nodes.TryGetValue(map.GetTileByMapLocation(spiralPositions.Current), out IBuildingNode buildingNode))
            {
                executed = unit.Order(new MoveOrder(buildingNode));
            }

            return(executed);
        }