Esempio n. 1
0
    private Stack <Vector2> GetAPath(Vector2 vTarget, ANavAgent pTarget, out EPathRes result)
    {
        result = EPathRes.EPR_Done;
        return(null);

        /*
         * if (m_pUnit is APawn)
         * {
         *  if (!(m_pUnit as APawn).IsGroundPawn())
         *  {
         *      //这货是飞的
         *      result = EPathFindingConst.PathFound;
         *      bStraight = true;
         *      return new[] { m_vLastPos, vTarget };
         *  }
         * }
         *
         * if (!m_pOwner.EdgeCheckWithAgent(m_vLastPos, vTarget, this, pTarget))
         * {
         *  result = EPathFindingConst.PathFound;
         *  bStraight = true;
         *
         *  return new[] { m_vLastPos, vTarget };
         * }
         *
         * bStraight = false;
         * if (null != StaticInfo.m_pBattle
         * && null != StaticInfo.m_pBattle.m_pGrid
         * && null != StaticInfo.m_pBattle.m_pGrid.m_pNav
         * && m_pOwner == StaticInfo.m_pBattle.m_pGrid.m_pNav
         * && StaticInfo.m_pBattle.m_bBattleStarted
         *  //&& false
         *  )
         * {
         *  Vector2[] ret = StaticInfo.m_pBattle.m_pGrid.AStarFindPathFromToV(m_vLastPos, vTarget, out result);
         *  if (null == ret || ret.Length < 2)
         *  {
         *      ret = new[] { m_vLastPos, (vTarget - m_vLastPos) * 0.1f + m_vLastPos };
         *  }
         *  return ret;
         * }
         *
         * return m_pOwner.PortalFindPathWithAgent(this, pTarget, m_vLastPos, vTarget, out result);
         */
    }
Esempio n. 2
0
    public void MoveTo(Vector2 vPos, bool bAttack = false, float fStopDist = 0.01f, ANavAgent pTarget = null)
    {
        EPathRes result = EPathRes.EPR_NoPath;

        if (m_bBuilding)
        {
            return;
        }

        if (null != m_pOwner)
        {
            Stack <Vector2> path = GetAPath(vPos, pTarget, out result);

            if (EPathRes.EPR_NoPath == result)
            {
                m_Task.m_eProgress     = EPathProgress.EPP_GiveUp;
                m_Task.m_vPathFound    = null;
                m_Task.m_vTargetPoint  = vPos;
                m_Task.m_bAttack       = bAttack; //for attack, change to hold
                m_Task.m_fBlockTime    = 0.0f;
                m_Task.m_fNotMoveTime  = 0.0f;
                m_Task.m_fStopDistance = fStopDist; //for range attack
                m_Task.m_pTarget       = pTarget;
                m_Task.m_fWalkTime     = 0.0f;
                m_Task.m_pOwner        = this;
            }
            else
            {
                m_Task.m_eProgress     = EPathProgress.EPP_Walking;
                m_Task.m_vPathFound    = path;
                m_Task.m_vTargetPoint  = vPos;
                m_Task.m_bAttack       = bAttack;
                m_Task.m_fBlockTime    = 0.0f;
                m_Task.m_fNotMoveTime  = 0.0f;
                m_Task.m_fStopDistance = fStopDist;
                m_Task.m_pTarget       = pTarget;
                m_Task.m_fWalkTime     = 0.0f;
                m_Task.m_pOwner        = this;
            }
        }

        return;
    }
Esempio n. 3
0
    void Update()
    {
        #region Editor test

        if (TestPath)
        {
            TestPath = false;

            if (null != m_pStart && null != m_pEnd)
            {
                switch (m_eGizmo)
                {
                case EPathGizmoShow.EPGS_StrictAStar:
                {
                    m_bHasStrictAStarPath = true;
                    float      flength = 0.0f;
                    S2DPoint[] res     = GridMath.StrictAStar(
                        new Vector2(m_pStart.transform.position.x, m_pStart.transform.position.z),
                        new Vector2(m_pEnd.transform.position.x, m_pEnd.transform.position.z),
                        m_pPathData.m_byGridStateData,
                        out flength
                        );

                    m_v2PathStrictAStar = new Vector2[res.Length];
                    for (int i = 0; i < res.Length; ++i)
                    {
                        m_v2PathStrictAStar[i] = res[i].ToV2();
                    }
                    CRuntimeLogger.Log(flength);
                }
                break;

/*
 *                  case EPathGizmoShow.EPGS_Swamp:
 *                      {
 *                      m_pPathData.ResetGrids();
 *                      EPathRes eres = EPathRes.EPR_NoPath;
 *                      m_v2PathSwamp = m_pPathData.FindPathAStar(
 *                          new Vector2(m_pStart.transform.position.x, m_pStart.transform.position.z),
 *                          new Vector2(m_pEnd.transform.position.x, m_pEnd.transform.position.z),
 *                          -1,
 *                          out eres
 *                          );
 *                      m_bSwampPath = true;
 *                      }
 *                      break;
 */
                case EPathGizmoShow.EPGS_JPS:
                {
                    m_pPathData.BakePruningRule();
                    m_pPathData.InitialBlockbasedGrid();
                    m_pPathData.ResetGrids();

                    EPathRes eres = EPathRes.EPR_NoPath;
                    m_v2PathJPS = m_pPathData.FindPathJPS(
                        new Vector2(m_pStart.transform.position.x, m_pStart.transform.position.z),
                        new Vector2(m_pEnd.transform.position.x, m_pEnd.transform.position.z),
                        30,
                        out eres
                        );
                    m_bJPSPath = true;
                }
                break;

/*
 *                  case EPathGizmoShow.EPGS_BlockAStar:
 *                      {
 *                          m_pPathData.ResetBlockAStarBlocks();
 *
 *                          EPathRes eres = EPathRes.EPR_NoPath;
 *                          m_v2PathBlockAStar = m_pPathData.FindPathBlockAStar(
 *                                  new Vector2(m_pStart.transform.position.x, m_pStart.transform.position.z),
 *                                  new Vector2(m_pEnd.transform.position.x, m_pEnd.transform.position.z),
 *                                  -1,
 *                                  out eres
 *                                  );
 *                          m_bBlockAStarPath = true;
 *                      }
 *                      break;
 */
                }
            }
        }

        #endregion

        #region Running Test

        if (StartPerformanceTest)
        {
            for (int i = 0; i < 200; ++i)
            {
                S2DPoint p1   = S2DPoint.random;
                S2DPoint p2   = S2DPoint.random;
                EPathRes eres = EPathRes.EPR_NoPath;

                //m_pPathData.FindPathAStarOld(p1.ToV2(), p2.ToV2(), -1, out eres);
                //m_pPathData.FindPathAStar(p1.ToV2(), p2.ToV2(), -1, out eres);
                //m_pPathData.FindPathBlockAStar(p1.ToV2(), p2.ToV2(), -1, out eres);
                //m_pPathData.FindPathJPSOld(p1.ToV2(), p2.ToV2(), -1, out eres);
                //m_pPathData.FindPathJPS(p1.ToV2(), p2.ToV2(), -1, out eres);
                //m_pPathData.FindPathJPSMJ(p1.ToV2(), p2.ToV2(), -1, out eres);
                //blocked jps without multi-jump is the best, it expand more open-list at same time!(so it should be slower..but, not...)

                //for a partial path, or non-reachable, expand more open-list is even better!
                m_pPathData.FindPathJPS(p1.ToV2(), p2.ToV2(), 30, out eres);
                m_pPathData.FindPathJPSMJ(p1.ToV2(), p2.ToV2(), 7, out eres);
            }
        }

        #endregion
    }