Esempio n. 1
0
        public Cell[] GetCells(Cell centerCell, Map map)
        {
            var result = new List<Cell>();

            if (Radius == 0)
            {
                if (MinRadius == 0 && !DiagonalFree)
                    result.Add(centerCell);

                return result.ToArray();
            }

            int x = (int)( centerCell.X - Radius );
            int y;
            while (x <= centerCell.X + Radius)
            {
                y = (int) (centerCell.Y - Radius);
                while (y <= centerCell.Y - Radius)
                {
                    if (MinRadius == 0 || Math.Abs(centerCell.X - x) + Math.Abs(centerCell.Y - y) >= MinRadius)
                        if (!DiagonalFree || Math.Abs(centerCell.X - x) != Math.Abs(centerCell.Y - y))
                             AddCellIfValid(x, y, map, result);

                    y++;
                }

                x++;
            }

            return result.ToArray();
        }
Esempio n. 2
0
 public LOSMap(MapContext<Fighter> map, bool throughEntities = false)
 {
     _losMap = null;
     _mapF = map;
     _pivotCell = null;
     _throughEntities = throughEntities;
 }
Esempio n. 3
0
        public Cell[] GetCells(Cell centerCell, Map map)
        {
            var result = new List<Cell>();

            if (MinRadius == 0)
                result.Add(centerCell);

            for (int i = 1; i <= Radius; i++)
            {
                switch (Direction)
                {
                    case DirectionsEnum.DIRECTION_NORTH_WEST:
                        AddCellIfValid(centerCell.X + i, centerCell.Y + i, map, result);
                        AddCellIfValid(centerCell.X + i, centerCell.Y - i, map, result);
                        break;

                    case DirectionsEnum.DIRECTION_NORTH_EAST:
                        AddCellIfValid(centerCell.X - i, centerCell.Y - i, map, result);
                        AddCellIfValid(centerCell.X + i, centerCell.Y - i, map, result);
                        break;

                    case DirectionsEnum.DIRECTION_SOUTH_EAST:
                        AddCellIfValid(centerCell.X - i, centerCell.Y + i, map, result);
                        AddCellIfValid(centerCell.X - i, centerCell.Y - i, map, result);
                        break;

                    case DirectionsEnum.DIRECTION_SOUTH_WEST:
                        AddCellIfValid(centerCell.X - i, centerCell.Y + i, map, result);
                        AddCellIfValid(centerCell.X + i, centerCell.Y + i, map, result);
                        break;
                }
            }

            return result.ToArray();
        }
Esempio n. 4
0
 public LOSMap(MapContext<RolePlayActor> map, bool throughEntities = false)
 {
     _losMap = null;
     _mapRP = map;
     _pivotCell = null;
     _throughEntities = throughEntities;
 }
Esempio n. 5
0
 public SpellTarget(double efficiency = 0, Cell source = null, Cell target = null, Spell spell = null)
 {
     Efficiency = efficiency;
     FromCell = source;
     TargetCell = target;
     Spell = spell;
     cast = spell == null;
 }
Esempio n. 6
0
        public ObjectPosition(Map map, Cell cell, DirectionsEnum direction)
        {
            if (map == null) throw new ArgumentNullException("map");
            if (cell == null) throw new ArgumentNullException("cell");

            Map = map;
            Cell = cell;
            Direction = direction;
        }
Esempio n. 7
0
 public TimedPathElement(Cell currentCell, Cell nextCell, DateTime startTime, DateTime endTime, double velocity, DirectionsEnum direction)
 {
     CurrentCell = currentCell;
     NextCell = nextCell;
     StartTime = startTime;
     EndTime = endTime;
     Velocity = velocity;
     Direction = direction;
 }
Esempio n. 8
0
        /// <summary>
        /// Set a new target for the LoSMap.
        /// If the target and Cell Id are same as previous, and forceUpdate is not set, then nothing is done.
        /// Otherwise, reset the map for new compute of LOS. 
        /// </summary>
        /// <param name="target">The Fighter for which you want to check if he can be seen from any cell of the map</param>
        /// <param name="throughEntities">Set if actors block LoS</param>
        /// <param name="delayComputed">If set, force immediate compute of the full map. Otherwise, only compute needed cells on demand</param>
        /// <param name="forceUpdate">Should be used when obstacles (like actors) may have moved</param>
        /// <returns></returns>
        public bool UpdateTargetCell(Cell pivotCell, bool delayComputed, bool forceUpdate)
        {
            if (pivotCell == null)
            {
                _losMap = null;
                _pivotCell = null;
                return false;
            }

            if (_pivotCell != null && _pivotCell.Id == pivotCell.Id && !forceUpdate) return true;
            _pivotCell = pivotCell;
            _losMap = new bool?[cells.Count()];
            if (!delayComputed)
                foreach (Cell testCell in cells)
                    _losMap[testCell.Id] = CanBeSeen(testCell, _throughEntities);
            return true;
        }
Esempio n. 9
0
        public Cell[] GetCells(Cell centerCell, Map map)
        {
            var result = new List<Cell>();

            if (Radius == 0)
            {
                if (MinRadius == 0)
                    result.Add(centerCell);

                return result.ToArray();
            }

            int x = (int) (centerCell.X - Radius);
            int y = 0;
            int i = 0;
            int j = 1;
            while (x <= centerCell.X + Radius)
            {
                y = -i;

                while (y <= i)
                {
                    if (MinRadius == 0 || Math.Abs(centerCell.X - x) + Math.Abs(y) >= MinRadius)
                        AddCellIfValid(x, y + centerCell.Y, map, result);

                    y++;
                }

                if (i == Radius)
                {
                    j = -j;
                }

                i = i + j;
                x++;
            }

            return result.ToArray();
        }
Esempio n. 10
0
 public int GetMapLinkedToCell(Cell cell)
 {
     MapNeighbour neighbour = Map.GetDirectionOfTransitionCell(cell);
     return GetNeighbourId(neighbour);
 }
Esempio n. 11
0
        public bool Move(Path path, Cell dest, bool cancelMove = true)
        {
            if (IsMoving())
                if (cancelMove)
                    CancelMove(false);
                else
                {
                    if (_actionAfterMove != null) return false; // Can't remember this move
                    _actionAfterMove = () => Move(path, dest, cancelMove);
                    return true;
                }

            // DEBUG
            //SendMessage(String.Format("Move {0} => {1} : {2}", Cell, dest, String.Join<Cell>(",", path.Cells)));
            //ResetCellsHighlight();
            //HighlightCells(path.Cells, Color.YellowGreen);
            if (path.IsEmpty())
            {
                SendMessage("Empty path skipped", Color.Gray);
                return false;
            }
            else
                if (path.Start.Id != Cell.Id)
                {
                    SendMessage(String.Format("Path start with {0} instead of {1}", path.Start, Cell), Color.Red);
                    return false;
                }

            Bot.SendToServer(new GameMapMovementRequestMessage(path.GetClientPathKeys(), Map.Id));
            return true;

        }
Esempio n. 12
0
 public bool CellMarked(Cell cell)
 {
     return(false);
 }
Esempio n. 13
0
        void IDisposable.Dispose()
        {
            if (_pivotCell != null)
                _pivotCell = null;
            if (_mapRP != null)
                _mapRP = null;
            if (_mapF != null)
                _mapF = null;
            if (_losMap != null)
                _losMap = null;

        }
Esempio n. 14
0
        public bool IsCellWalkable(Cell cell, bool throughEntities = false, Cell previousCell = null)
        {
            if (!cell.Walkable)
                return false;

            if (cell.NonWalkableDuringRP)
                return false;

            // compare the floors
            if (UsingNewMovementSystem && previousCell != null)
            {
                var floorDiff = Math.Abs(cell.Floor) - Math.Abs(previousCell.Floor);

                if (cell.MoveZone != previousCell.MoveZone || cell.MoveZone == previousCell.MoveZone && cell.MoveZone == 0 && floorDiff > Map.ElevationTolerance)
                    return false;
            }

            // todo : LoS

            return true;
        }
Esempio n. 15
0
 public bool IsChangeZone(Cell cell)
 {
     return MoveZone != cell.MoveZone && Math.Abs(Floor) == Math.Abs(cell.Floor);
 }
Esempio n. 16
0
 public bool IsAdjacentTo(Cell cell)
 {
     return ManhattanDistanceTo(cell) == 1;
 }
Esempio n. 17
0
 public uint DistanceTo(Cell cell)
 {
     return (uint)Math.Sqrt(( cell.X - Point.X ) * ( cell.X - Point.X ) + ( cell.Y - Point.Y ) * ( cell.Y - Point.Y ));
 }
Esempio n. 18
0
 public static bool IsInMap(Cell cell)
 {
     return IsInMap(cell.X, cell.Y);
 }
Esempio n. 19
0
 public Cell[] GetCells(Cell centerCell, Map map)
 {
     return m_shape.GetCells(centerCell, map);
 }
Esempio n. 20
0
 public bool IsCellMarked(Cell cell)
 {
     // todo
     return(false);
 }
Esempio n. 21
0
 public bool IsActor(Cell cell)
 {
     return Actors.Any(entry => entry.Position != null && entry.Position.Cell == cell);
 }
Esempio n. 22
0
 public bool IsCellMarked(Cell cell)
 {
     // todo
     return false;
 }
Esempio n. 23
0
 public uint ManhattanDistanceTo(Cell cell)
 {
     return (uint)( Math.Abs(Point.X - cell.X) + Math.Abs(Point.Y - cell.Y) );
 }
Esempio n. 24
0
        public DirectionsEnum OrientationTo(Cell cell, Boolean diagonal = true)
        {
            int dx = cell.X - X;
            int dy = Y - cell.Y;

            double distance = Math.Sqrt(dx * dx + dy * dy);
            double angleInRadians = Math.Acos(dx / distance);

            double angleInDegrees = angleInRadians * 180 / Math.PI;
            double transformedAngle = angleInDegrees * ( cell.Y > Y ? ( -1 ) : ( 1 ) );

            double orientation = !diagonal ? Math.Round(transformedAngle / 90) * 2 + 1 : Math.Round(transformedAngle / 45) + 1;

            if (orientation < 0)
            {
                orientation = orientation + 8;
            }

            return (DirectionsEnum)(uint)orientation;
        }
Esempio n. 25
0
        public DirectionsEnum OrientationToAdjacent(Cell cell)
        {
            var vector = new Point
                             {
                                 X = cell.X > Point.X ? ( 1 ) : ( cell.X < Point.X ? ( -1 ) : ( 0 ) ),
                                 Y = cell.Y > Point.Y ? ( 1 ) : ( cell.Y < Point.Y ? ( -1 ) : ( 0 ) )
                             };

            if (vector == s_vectorRight)
            {
                return DirectionsEnum.DIRECTION_EAST;
            }
            if (vector == s_vectorDownRight)
            {
                return DirectionsEnum.DIRECTION_SOUTH_EAST;
            }
            if (vector == s_vectorDown)
            {
                return DirectionsEnum.DIRECTION_SOUTH;
            }
            if (vector == s_vectorDownLeft)
            {
                return DirectionsEnum.DIRECTION_SOUTH_WEST;
            }
            if (vector == s_vectorLeft)
            {
                return DirectionsEnum.DIRECTION_WEST;
            }
            if (vector == s_vectorUpLeft)
            {
                return DirectionsEnum.DIRECTION_NORTH_WEST;
            }
            if (vector == s_vectorUp)
            {
                return DirectionsEnum.DIRECTION_NORTH;
            }
            if (vector == s_vectorUpRight)
            {
                return DirectionsEnum.DIRECTION_NORTH_EAST;
            }

            return DirectionsEnum.DIRECTION_EAST;
        }
Esempio n. 26
0
 private bool CanBeSeen(Cell targetCell, bool throughEntities)
 {
     if (_mapF == null) return _mapRP.CanBeSeen(_pivotCell, targetCell, throughEntities);
     return _mapF.CanBeSeen(_pivotCell, targetCell, throughEntities);
 }
Esempio n. 27
0
 public bool IsActor(Cell cell)
 {
     return(Actors.Any(entry => entry.Position != null && entry.Position.Cell == cell));
 }
Esempio n. 28
0
 public ContextActor[] GetContextActors(Cell cell)
 {
     return(Actors.Where(entry => entry.Position != null && entry.Position.Cell == cell).Select(entry => (ContextActor)entry).ToArray());
 }
Esempio n. 29
0
 public bool CellMarked(Cell cell)
 {
     return false;
 }
Esempio n. 30
0
 public bool this[Cell cell]
 {
     get { return _losMap[cell.Id] ?? (_losMap[cell.Id] = CanBeSeen(cell, _throughEntities)).Value; }
 }
Esempio n. 31
0
 public ContextActor[] GetActors(Cell cell)
 {
     return Actors.Where(entry => entry.Position != null && entry.Position.Cell == cell).Select(entry => (ContextActor)entry).ToArray();
 }
Esempio n. 32
0
        public bool Move(Cell cell, ISimplePathFinder pathFinder = null, int minDistance = 0, bool cautious = false, bool cancelMove = true)
        {
            if (cell == null) throw new ArgumentNullException("cell");

            if (!CanMove())
                return false;
            if (pathFinder == null)
                pathFinder = new BiM.Behaviors.Game.World.Pathfinding.FFPathFinding.PathFinder(Map, false);
            Path path = null;
            if (pathFinder is IAdvancedPathFinder)
                path = (pathFinder as IAdvancedPathFinder).FindPath(Cell, cell, true, -1, minDistance, cautious);
            else
                path = pathFinder.FindPath(Cell, cell, true, -1);

            return Move(path, cell);
        }
Esempio n. 33
0
 public object[] GetMarks(Cell cell)
 {
     return new object[0];
 }
Esempio n. 34
0
 public void HighlightCell(Cell cell, Color color)
 {
     Bot.SendToClient(new DebugHighlightCellsMessage(color.ToArgb(), new[] { cell.Id }));
 }
Esempio n. 35
0
 public object[] GetMarks(Cell cell)
 {
     return(new object[0]);
 }