コード例 #1
0
 private void CalculatePathDStar(WorldObject sel, LayerTile end)
 {
     if (sel != null && !sel.IsDestroyed() && !sel.IsActionBlocking())
     {
         LayerTile start = map.GetTileByWorldPosition(sel.GetCenteredPosition());
         DStarLite dstar = sel.Owner.FindComponent <DStarLite>();
         if (dstar != null)
         {
             List <LayerTile> dPath = dstar.DStar(start, end);
             Trace.WriteLine("path: " + dPath.Count.ToString());
             SendPath(dPath);
         }
     }
 }
コード例 #2
0
        /**
         * <summary>
         * Finds adjacent and possibly free tiles to the one given
         * </summary>
         */
        private List <LayerTile> IsAdjacentTileFree(LayerTile tile, DStarLite dstar)
        {
            List <LayerTile> res = new List <LayerTile>();

            if (tile != null)
            {
                foreach (Point neighborPoint in fog.Adjacents(tile, dstar.adjPoints))
                {
                    LayerTile u = map.GetTileByMapCoordinates(neighborPoint.X, neighborPoint.Y);
                    if (dstar.CalculateDistance(u) != float.PositiveInfinity)
                    {
                        res.Add(u);
                    }
                }
            }
            return(res);
        }
コード例 #3
0
        /**
         * <summary>
         * Method for executing an action if requires adjacency,
         * or computes a path and stores the action for when it finishes moving closer
         * </summary>
         */
        private void HandleMovementAction(WorldObject wo, LayerTile currentTile, ActionBehavior act)
        {
            if (selectedWO != null && !selectedWO.IsDestroyed() && !selectedWO.IsActionBlocking())
            {
                if (wo.IsAdjacent(selectedWO))
                {
                    SendCommand(act, wo, false);
                }
                else if (selectedWO.IsMobile())
                {
                    List <LayerTile> dPath = new List <LayerTile>();

                    DStarLite dstar = selectedWO.Owner.FindComponent <DStarLite>();

                    LayerTile start = map.GetTileByWorldPosition(selectedWO.GetCenteredPosition());
                    if (currentTile != start)
                    {
                        dPath = dstar.DStar(start, currentTile);
                    }
                    else
                    {
                        //we are in the same tile, we move to an adjacent an enqueue action
                        dPath.Add(start);
                        List <LayerTile> neighbors = IsAdjacentTileFree(start, dstar);
                        if (neighbors.Count > 0)
                        {
                            dPath.Add(neighbors[0]);
                        }
                    }
                    if (dPath.Count > 1)
                    {
                        SendPath(dPath);
                        SendCommand(act, wo, true);
                    }
                }
            }
        }