예제 #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);
        }
예제 #2
0
        public MapFormationController(IMap map, ITile tile)
        {
            this.map = map;
            spiral   = new Spiral(tile.MapLocation).GetSpiralEnumerator();
            spiral.MoveNext();

            failedTypes = new HashSet <UnitType>();
        }
예제 #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);
        }