示例#1
0
        private void WalkOnPosition(FDPosition position, int leftMovePoint, FDMoveRange range)
        {
            int moveCost = GetMoveCost(position, creature);

            if (moveCost == -1 || leftMovePoint < moveCost)
            {
                // Nothing to walk
                return;
            }

            // If this is ZOC, stop the move
            if (!position.AreSame(this.creature.Position) && HasAdjacentEnemy(position))
            {
                return;
            }

            int leftPoint = leftMovePoint - moveCost;

            foreach (FDPosition direction in position.GetAdjacentPositions())
            {
                if (direction.X <= 0 || direction.X > gameField.Width ||
                    direction.Y <= 0 || direction.Y > gameField.Height)
                {
                    continue;
                }

                if (range.Contains(direction))
                {
                    continue;
                }

                // If already occupied by creature
                FDCreature existing = gameAction.GetCreatureAt(direction);
                if (existing != null && existing.IsOppositeFaction(creature))
                {
                    continue;
                }

                if (GetMoveCost(direction, creature) == -1)
                {
                    // Cannot land on target direction
                    continue;
                }

                range.AddPosition(direction, position);
                positionQueue.Enqueue(new MoveRangeQueueObject(direction, leftPoint));
            }
        }