예제 #1
0
        public override ExtPoint GetEvadePos(CreatureEntity enemy)
        {
            ExtPoint result = ExtPoint.Empty;

            NWCreature self = (NWCreature)fSelf;

            if (Flock && fNearKinsfolk != null)
            {
                int  epX = fNearKinsfolk.PosX;
                int  epY = fNearKinsfolk.PosY;
                bool res = self.CanMove(self.CurrentField, epX, epY);
                if (res)
                {
                    return(new ExtPoint(epX, epY));
                }
            }

            Directions dangerDirs = new Directions();

            if (enemy.PosX > self.PosX)
            {
                dangerDirs.Include(Directions.DtEast);
            }
            if (enemy.PosX < self.PosX)
            {
                dangerDirs.Include(Directions.DtWest);
            }
            if (enemy.PosY > self.PosY)
            {
                dangerDirs.Include(Directions.DtSouth);
            }
            if (enemy.PosY < self.PosY)
            {
                dangerDirs.Include(Directions.DtNorth);
            }

            if (dangerDirs.ContainsAll(Directions.DtNorth, Directions.DtWest))
            {
                dangerDirs.Include(Directions.DtNorthWest);
            }
            if (dangerDirs.ContainsAll(Directions.DtNorth, Directions.DtEast))
            {
                dangerDirs.Include(Directions.DtNorthEast);
            }
            if (dangerDirs.ContainsAll(Directions.DtSouth, Directions.DtWest))
            {
                dangerDirs.Include(Directions.DtSouthWest);
            }
            if (dangerDirs.ContainsAll(Directions.DtSouth, Directions.DtEast))
            {
                dangerDirs.Include(Directions.DtSouthEast);
            }

            for (int dir = Directions.DtFlatFirst; dir <= Directions.DtFlatLast; dir++)
            {
                if (!dangerDirs.Contains(dir))
                {
                    int epX = self.PosX + Directions.Data[dir].DX;
                    int epY = self.PosY + Directions.Data[dir].DY;

                    if (self.CanMove(self.CurrentField, epX, epY))
                    {
                        return(new ExtPoint(epX, epY));
                    }
                }
            }

            return(result);
        }