Exemplo n.º 1
0
        protected virtual bool FindEnemies()
        {
            if (Location == null)
            {
                hountingPath = null;
                return(false);
            }

            ILiveEntity enemy       = null;
            ITile       matchedTile = null;

            globalSearcher.StartSearch(Location.Tile, Location.Tile, Math.Max(DetectRange, SightRange), (tile, layer, bundle) =>
            {
                enemy = tile.LayoutManager.Entities.FirstOrDefault(e => RelationManager.IsEnemy(e.RelationManager.RelationToken));
                if (enemy != null)
                {
                    globalSearcher.StopSearch();
                    matchedTile = tile;
                }
            });
            if (enemy != null)
            {
                hountingPath = globalSearcher.GetShortestRoute(matchedTile);
                //$"{this} found enemies at {hountingPath.Last().GridPosition}".Dump();
                return(true);
            }
            else
            {
                hountingPath = null;
                return(false);
            }
        }
Exemplo n.º 2
0
        private IReadOnlyList <Tile> FindNextWatchLocation()
        {
            var  maxTravelDistance = random.Next(2, 2 * watchAroundRadius + 1);
            Tile destTile          = Location.Tile;
            uint destTileUsages    = 0;
            int  desDist           = 0;

            watchAroundArea.StartSearch(watchAroungOrigin, Location.Tile, watchAroundRadius, (tile, distance, bundle) =>
            {
                if (tile == null)
                {
                    throw new Exception();
                }

                if (distance > maxTravelDistance)
                {
                    watchAroundArea.StopSearch();
                }

                if ((desDist < distance) || (desDist == distance && destTileUsages < bundle))
                {
                    destTile       = tile;
                    destTileUsages = bundle;
                    desDist        = distance;
                }
            });

            if (destTile == null)
            {
                throw new Exception();
            }

            return(watchAroundArea.GetShortestRoute(destTile));
        }
Exemplo n.º 3
0
        protected virtual IReadOnlyList <ITile> FindNextWatchLocation()
        {
            if (Location == null)
            {
                return(Enumerable.Empty <ITile>().ToList());
            }

            var   maxTravelDistance = random.Next(2, 2 * watchAroundRadius + 1);
            ITile destTile          = Location.Tile;
            uint  destTileUsages    = 0;
            int   desDist           = 0;

            //TODO current location is outside of range ?? shouldnt by solved by go home rutine ?
            int distanceFromOrigin = (int)(watchAroungOrigin.GridPosition - Location.Tile.GridPosition).ToVector2().Length();

            watchAroundArea.StartSearch(watchAroungOrigin, Location.Tile, Math.Max(distanceFromOrigin, watchAroundRadius), (tile, distance, bundle) =>
            {
                if (tile == null)
                {
                    throw new Exception();
                }

                if (distance > maxTravelDistance)
                {
                    watchAroundArea.StopSearch();
                }

                if ((desDist < distance) || (desDist == distance && destTileUsages < bundle))
                {
                    destTile       = tile;
                    destTileUsages = bundle;
                    desDist        = distance;
                }
            });

            if (destTile == null)
            {
                throw new Exception();
            }

            return(watchAroundArea.GetShortestRoute(destTile));
        }