Ejemplo n.º 1
0
        public virtual bool CanAddAdjacentToReachable(PathFinding search, CellData adjacent)
        {
            // 如果已经在关闭集
            if (search.IsCellInExpored(adjacent))
            {
                return(false);
            }

            // 已经加入过开放集
            if (search.IsCellInReachable(adjacent))
            {
                return(false);
            }

            // 计算消耗 = 当前cell的消耗 + 邻居cell的消耗
            float g = search.currentCell.g + CalcGPerCell(search, adjacent);

            // 不在范围内
            if (g < 0f || g > search.range.y)
            {
                return(false);
            }

            adjacent.g = g;

            return(true);
        }
Ejemplo n.º 2
0
        public override bool CanAddAdjacentToReachable(PathFinding search, CellData adjacent)
        {
            //// 没有Tile
            //if (!adjacent.hasTile)
            //{
            //    return false;
            //}

            //// 已经有对象了
            //if (adjacent.hasMapObject)
            //{
            //    return false;
            //}

            // 是否可移动
            if (!adjacent.canMove)
            {
                return(false);
            }

            // 如果已经在关闭集
            if (search.IsCellInExpored(adjacent))
            {
                return(false);
            }

            // 计算消耗 = 当前cell的消耗 + 邻居cell的消耗
            float g = search.currentCell.g + CalcGPerCell(search, adjacent);

            // 已经加入过开放集
            if (search.IsCellInReachable(adjacent))
            {
                // 如果新消耗更低
                if (g < adjacent.g)
                {
                    adjacent.g        = g;
                    adjacent.previous = search.currentCell;
                }
                return(false);
            }

            // 不在范围内
            if (g < 0f || g > search.range.y)
            {
                return(false);
            }

            adjacent.g        = g;
            adjacent.previous = search.currentCell;

            return(true);
        }
Ejemplo n.º 3
0
        public virtual bool IsFinishedOnChose(PathFinding search)
        {
            if (search.currentCell == null)
            {
                return(true);
            }

            if (!search.IsCellInExpored(search.currentCell))
            {
                search.explored.Add(search.currentCell);
            }
            return(false);
        }
Ejemplo n.º 4
0
        public virtual bool CanAddAdjacentToReachable(PathFinding search, CellData adjacent)
        {
            // 如果已经在关闭集
            if (search.IsCellInExpored(adjacent))
            {
                return(false);
            }

            // 已经加入过开放集
            if (search.IsCellInReachable(adjacent))
            {
                return(false);
            }

            //// 计算消耗 = 当前cell的消耗 + 邻居cell的消耗
            //float g = search.currentCell.g + CalcGPerCell(search, adjacent);

            // 计算攻击距离
            float h = CalcH(search, adjacent);

            //// 不在范围内
            //if (g < 0f || g > search.range.y)
            //{
            //    return false;
            //}

            // 攻击距离不在范围内
            if (h < 0f || h > search.range.y)
            {
                return(false);
            }

            //adjacent.g = g;
            adjacent.h = h;

            return(true);
        }
Ejemplo n.º 5
0
        public override bool IsFinishedOnChose(PathFinding search)
        {
            // 如果开放集中已经空了,则说明没有达到目标点
            if (search.currentCell == null)
            {
                // 使用h最小值建立结果
                CellData minHCell = search.explored.First(cell => cell.h == search.explored.Min(c => c.h));
                search.BuildPath(minHCell, true);
                return(true);
            }

            // 找到了目标点
            if (search.currentCell == search.endCell)
            {
                return(true);
            }

            if (!search.IsCellInExpored(search.currentCell))
            {
                search.explored.Add(search.currentCell);
            }

            return(false);
        }