示例#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));
            }
        }
示例#2
0
        public FDMoveRange CalculateMoveRange()
        {
            FDPosition  central = this.creature.Position;
            FDMoveRange range   = new FDMoveRange(central);

            int movePoint = creature.Data.CalculatedMv;

            positionQueue = new Queue <MoveRangeQueueObject>();

            range.AddPosition(central, null);
            positionQueue.Enqueue(new MoveRangeQueueObject(central, movePoint));

            while (positionQueue.Count > 0)
            {
                MoveRangeQueueObject queueObject = positionQueue.Dequeue();
                WalkOnPosition(queueObject.Position, queueObject.LeftMovePoint, range);
            }

            // Remove the friend creatures from range
            List <FDCreature> creatureInRange = gameAction.GetCreatureInRange(range, creature.Faction);

            if (creature.Faction == CreatureFaction.Friend)
            {
                creatureInRange.AddRange(gameAction.GetCreatureInRange(range, CreatureFaction.Npc));
            }
            else if (creature.Faction == CreatureFaction.Npc)
            {
                creatureInRange.AddRange(gameAction.GetCreatureInRange(range, CreatureFaction.Friend));
            }

            foreach (FDCreature c in creatureInRange)
            {
                if (c.CreatureId == creature.CreatureId)
                {
                    continue;
                }

                range.AddSkipPosition(c.Position);
            }

            return(range);
        }