public void SAVE()
    {
        StreamWriter streamWriter = new StreamWriter("RPTest.txt");
        string       value        = string.Empty;

        foreach (short current in this.m_RPList.Keys)
        {
            for (int i = 0; i < this.m_RPList[current].Count; i++)
            {
                GxRP   gxRP = this.m_RPList[current][i];
                string text = string.Empty;
                for (int j = 0; j < 4; j++)
                {
                    text = text + gxRP.GetLinkedRP(j).ToString() + "/";
                }
                value = string.Concat(new string[]
                {
                    gxRP.GetIndex().ToString(),
                    "/",
                    gxRP.GetMapIndex().ToString(),
                    "/",
                    gxRP.GetPos().x.ToString(),
                    "/",
                    gxRP.GetPos().y.ToString(),
                    "/",
                    gxRP.GetPos().z.ToString(),
                    "/",
                    text
                });
                streamWriter.WriteLine(value);
            }
        }
        streamWriter.WriteLine("<End>");
        streamWriter.Close();
    }
Exemple #2
0
 private void SetMovePath(Vector3 vDestPos)
 {
     this.DirectionCheck(vDestPos, ref this.m_RPPath);
     this.m_MovePath.Clear();
     foreach (GxRpAsNode current in this.m_RPPath)
     {
         GxRP    rP  = this.m_cGxRoadPointMgr.GetRP(current.sMapIdx, (int)current.RPIdx);
         Vector3 pos = rP.GetPos();
         this.m_MovePath.AddLast(new Vector3(pos.x, pos.y, pos.z));
     }
     this.m_Debugstring.Add("DEST POS : " + vDestPos);
     if (vDestPos != Vector3.zero)
     {
         if (vDestPos.y == 0f)
         {
             vDestPos.y = NrCharMove.CalcHeight(vDestPos);
         }
         this.m_MovePath.AddLast(new Vector3(vDestPos.x, vDestPos.y, vDestPos.z));
     }
     if (this.m_MovePath.Count > 0)
     {
         this.m_bAutoMove = true;
         this.SetFollowHeroCamera(true);
     }
 }
    private short GetTmpRP(GxRoadPointAstar.TMPRPINDEX tempRPIndex, short p_MapIdx, short x, short y)
    {
        List <short> list = new List <short>();

        this.m_pkRPSys.GetValidRangeRPIndexes(p_MapIdx, x, y, ref list);
        GxRP gxRP = (tempRPIndex != GxRoadPointAstar.TMPRPINDEX.RAS_TMPSP_INDEX) ? this.m_dTmpRP : this.m_sTmpRP;

        this.m_sRPIdx = ((tempRPIndex != GxRoadPointAstar.TMPRPINDEX.RAS_TMPSP_INDEX) ? this.m_sRPIdx : -100);
        this.m_dRPIdx = ((tempRPIndex != GxRoadPointAstar.TMPRPINDEX.RAS_TMPDP_INDEX) ? this.m_dRPIdx : -200);
        gxRP.ClearData();
        gxRP.SetData((short)tempRPIndex, p_MapIdx, x, y);
        if (list.Count != 0)
        {
            foreach (short current in list)
            {
                if (!gxRP.AddLinkedRP(current))
                {
                    break;
                }
            }
        }
        else
        {
            short nerestRP = this.m_pkRPSys.GetNerestRP(p_MapIdx, x, y, false, false);
            gxRP.AddLinkedRP(nerestRP);
        }
        return((short)tempRPIndex);
    }
    public short GetNerestRP(short sMapIndex, short x, short y, bool bValidRangeUse, bool bValidRangeMinUse)
    {
        short num  = 0;
        int   num2 = 100000;
        int   num3 = (int)((!bValidRangeMinUse) ? 0 : this.m_iValidRadiusMin);
        short num4 = 1;

        while ((int)num4 < this.m_RPList[sMapIndex].Count)
        {
            int num5 = this.m_RPList[sMapIndex][(int)num4].CalcDistance(x, y);
            if (num5 < num2)
            {
                num  = num4;
                num2 = num5;
            }
            num4 += 1;
        }
        if (bValidRangeUse)
        {
            GxRP rP   = this.GetRP(sMapIndex, (int)num);
            int  num6 = rP.CalcDistance(x, y);
            if (num6 > (int)this.m_iValidRadiusMin || num6 < num3)
            {
                num = 0;
            }
        }
        return(num);
    }
Exemple #5
0
 public void DirectionCheck(Vector3 vDest, ref LinkedList <GxRpAsNode> RPPath)
 {
     if (RPPath.Count > 1)
     {
         GxRpAsNode value = RPPath.First.Value;
         GxRP       rP    = this.m_cGxRoadPointMgr.GetRP(value.sMapIdx, (int)value.RPIdx);
         value = RPPath.First.Next.Value;
         GxRP    rP2      = this.m_cGxRoadPointMgr.GetRP(value.sMapIdx, (int)value.RPIdx);
         Vector3 position = this.m_pkUserObj.transform.position;
         Vector3 from     = rP2.GetPos() - rP.GetPos();
         from.y = 0f;
         Vector3 to = position - rP.GetPos();
         to.y = 0f;
         float value2 = Vector3.Angle(from, to);
         if (Math.Abs(value2) < 90f)
         {
             RPPath.RemoveFirst();
         }
     }
     if (RPPath.Count > 1)
     {
         GxRpAsNode value3 = RPPath.Last.Value;
         GxRP       rP3    = this.m_cGxRoadPointMgr.GetRP(value3.sMapIdx, (int)value3.RPIdx);
         value3 = RPPath.Last.Previous.Value;
         GxRP    rP4   = this.m_cGxRoadPointMgr.GetRP(value3.sMapIdx, (int)value3.RPIdx);
         Vector3 from2 = rP4.GetPos() - rP3.GetPos();
         from2.y = 0f;
         Vector3 to2 = vDest - rP3.GetPos();
         to2.y = 0f;
         float value4 = Vector3.Angle(from2, to2);
         if (Math.Abs(value4) < 90f)
         {
             RPPath.RemoveLast();
         }
     }
     if (RPPath.Count == 1)
     {
         GxRpAsNode value5    = RPPath.First.Value;
         GxRP       rP5       = this.m_cGxRoadPointMgr.GetRP(value5.sMapIdx, (int)value5.RPIdx);
         Vector3    position2 = this.m_pkUserObj.transform.position;
         Vector3    from3     = position2 - rP5.GetPos();
         from3.y = 0f;
         Vector3 to3 = vDest - rP5.GetPos();
         to3.y = 0f;
         float value6 = Vector3.Angle(from3, to3);
         if (Math.Abs(value6) < 90f)
         {
             RPPath.RemoveFirst();
         }
     }
 }
    private void CreateChild(ref GxRpAsNode parentNode, short sMapIndex)
    {
        GxRpAsNode gxRpAsNode = null;
        GxRP       gxRP       = (parentNode.RPIdx <= 0) ? ((parentNode.RPIdx != -100) ? this.m_dTmpRP : this.m_sTmpRP) : this.m_pkRPSys.GetRP(parentNode.sMapIdx, (int)parentNode.RPIdx);

        for (int i = 0; i < 4; i++)
        {
            if (gxRP.GetLinkedRP(i) != 0)
            {
                gxRpAsNode = new GxRpAsNode(gxRP.GetLinkedRP(i));
                this.LinkedChild(sMapIndex, ref parentNode, ref gxRpAsNode);
            }
        }
    }
    public short AddRP(short sMapIndex, Vector3 v3Pos)
    {
        if (sMapIndex < 0 || v3Pos.x < 0f || v3Pos.y < 0f || v3Pos.z < 0f)
        {
            return(-3);
        }
        if (!this.m_RPList.ContainsKey(sMapIndex))
        {
            this.m_RPList.Add(sMapIndex, new List <GxRP>());
        }
        if (this.FindRP(sMapIndex, v3Pos))
        {
            return(-1);
        }
        List <GxRP> list = this.m_RPList[sMapIndex];

        if (list.Count == 0)
        {
            GxRP gxRP = new GxRP();
            gxRP.SetData(0, sMapIndex, Vector3.zero);
            list.Add(gxRP);
        }
        GxRP  gxRP2      = new GxRP();
        short emptyRPidx = this.GetEmptyRPidx(sMapIndex);
        short sRPIndex   = (short)list.Count;

        if (emptyRPidx == 0)
        {
            gxRP2.SetData(sRPIndex, sMapIndex, v3Pos);
            list.Add(gxRP2);
        }
        else
        {
            gxRP2.SetData(emptyRPidx, sMapIndex, v3Pos);
            list[(int)emptyRPidx] = gxRP2;
            sRPIndex = emptyRPidx;
        }
        if (!this.AutoLinkRPs(sMapIndex, sRPIndex))
        {
            Debug.Log("AutoLinkRPs Faild\n");
        }
        if (emptyRPidx != 0)
        {
            return(emptyRPidx);
        }
        return((short)(list.Count - 1));
    }
    private void LinkedChild(short sMapIndex, ref GxRpAsNode parentNode, ref GxRpAsNode childNode)
    {
        short      rPIdx      = childNode.RPIdx;
        GxRP       gxRP       = (rPIdx <= 0) ? ((rPIdx != -100) ? this.m_dTmpRP : this.m_sTmpRP) : this.m_pkRPSys.GetRP(sMapIndex, (int)rPIdx);
        int        num        = parentNode.g + 1;
        GxRpAsNode gxRpAsNode = null;

        gxRpAsNode = this.CheckList(this.m_pOpen, rPIdx);
        if (gxRpAsNode != null)
        {
            parentNode.child.Add(gxRpAsNode);
            if (num < gxRpAsNode.g)
            {
                gxRpAsNode.parent = parentNode;
                gxRpAsNode.g      = num;
                gxRpAsNode.f      = num + gxRpAsNode.h;
            }
        }
        else
        {
            gxRpAsNode = this.CheckList(this.m_pClosed, rPIdx);
            if (gxRpAsNode != null)
            {
                parentNode.child.Add(gxRpAsNode);
                if (num < gxRpAsNode.g)
                {
                    gxRpAsNode.parent = parentNode;
                    gxRpAsNode.g      = num;
                    gxRpAsNode.f      = num + gxRpAsNode.h;
                    this.UpdateParents(ref gxRpAsNode);
                }
            }
            else
            {
                GxRpAsNode gxRpAsNode2 = new GxRpAsNode(rPIdx);
                gxRpAsNode2.parent  = parentNode;
                gxRpAsNode2.g       = num;
                gxRpAsNode2.h       = Math.Abs((int)gxRP.GetX() - this.m_iDX) + Math.Abs((int)gxRP.GetY() - this.m_iDY);
                gxRpAsNode2.f       = gxRpAsNode2.g + gxRpAsNode2.h;
                gxRpAsNode2.sMapIdx = sMapIndex;
                this.AddToOpen(ref gxRpAsNode2);
                parentNode.child.Add(gxRpAsNode2);
            }
        }
    }
    public bool UnLinkRP(short MapIndex, short sRPIdx1, short sRPIdx2)
    {
        GxRP rP = this.GetRP(MapIndex, (int)sRPIdx1);

        if (rP == null)
        {
            return(false);
        }
        GxRP rP2 = this.GetRP(MapIndex, (int)sRPIdx2);

        if (rP2 == null)
        {
            return(false);
        }
        rP.DelLinkedRP(sRPIdx2);
        rP2.DelLinkedRP(sRPIdx1);
        return(true);
    }
    public bool LinkRP(short MapIndex, short sRPIdx1, short sRPIdx2)
    {
        GxRP rP = this.GetRP(MapIndex, (int)sRPIdx1);

        if (rP == null || rP.GetLinkedCount() <= 4)
        {
            return(false);
        }
        GxRP rP2 = this.GetRP(MapIndex, (int)sRPIdx2);

        if (rP2 == null || rP2.GetLinkedCount() <= 4)
        {
            return(false);
        }
        rP.AddLinkedRP(sRPIdx2);
        rP2.AddLinkedRP(sRPIdx1);
        return(true);
    }
    public bool ParseDataFromNDT(TsDataReader dr)
    {
        this.m_RPList.Clear();
        ROAD_POINT rOAD_POINT = new ROAD_POINT();

        foreach (TsDataReader.Row data in dr)
        {
            rOAD_POINT.SetData(data);
            rOAD_POINT.MAP_IDX = 0;
            GxRP gxRP = new GxRP();
            gxRP.SetData(rOAD_POINT);
            if (!this.m_RPList.ContainsKey(rOAD_POINT.MAP_IDX))
            {
                this.m_RPList.Add(rOAD_POINT.MAP_IDX, new List <GxRP>());
            }
            this.m_RPList[rOAD_POINT.MAP_IDX].Insert((int)rOAD_POINT.ROADPOINT_IDX, gxRP);
        }
        return(true);
    }
    public bool _EraseRP(short MapIndex, short nRoadPointIndex)
    {
        GxRP rP = this.GetRP(MapIndex, (int)nRoadPointIndex);

        if (rP == null)
        {
            return(false);
        }
        for (int i = 0; i < rP.GetLinkedCount(); i++)
        {
            GxRP rP2 = this.GetRP(MapIndex, (int)rP.GetLinkedRP(i));
            if (rP2 != null)
            {
                rP2.DelLinkedRP(nRoadPointIndex);
            }
        }
        rP.ClearData();
        rP.SetData(nRoadPointIndex, MapIndex, Vector3.zero);
        return(true);
    }
 private bool UnLinkAll(short MapIndex, short sRPIndex)
 {
     try
     {
         GxRP gxRP = this.m_RPList[MapIndex][(int)sRPIndex];
         if (gxRP == null)
         {
             return(false);
         }
         for (int i = 0; i < 4; i++)
         {
             this.UnLinkRP(MapIndex, sRPIndex, gxRP.GetLinkedRP(i));
         }
     }
     catch (Exception arg)
     {
         Debug.Log(arg + "sRPIndex :" + sRPIndex.ToString());
     }
     return(true);
 }
    private bool StepInitialize(short MapIdx, short sRPIndex, short dRPIndex)
    {
        this.ClearNodes();
        this.m_sRPIdx = sRPIndex;
        this.m_dRPIdx = dRPIndex;
        GxRP gxRP  = (this.m_sRPIdx <= 0) ? this.m_sTmpRP : this.m_pkRPSys.GetRP(MapIdx, (int)this.m_sRPIdx);
        GxRP gxRP2 = (this.m_dRPIdx <= 0) ? this.m_dTmpRP : this.m_pkRPSys.GetRP(MapIdx, (int)this.m_dRPIdx);

        this.m_iSX = (int)gxRP.GetX();
        this.m_iSY = (int)gxRP.GetY();
        this.m_iDX = (int)gxRP2.GetX();
        this.m_iDY = (int)gxRP2.GetY();
        GxRpAsNode gxRpAsNode = new GxRpAsNode(this.m_sRPIdx);

        gxRpAsNode.g = 0;
        gxRpAsNode.h = Math.Abs((int)(gxRP2.GetX() - gxRP.GetX())) + Math.Abs((int)(gxRP2.GetY() - gxRP.GetY()));
        gxRpAsNode.f = gxRpAsNode.g + gxRpAsNode.h;
        this.m_pOpen = gxRpAsNode;
        return(true);
    }
Exemple #15
0
    public bool GenerateMinLenPath(short l_StartIdx, short l_Destindex, ref LinkedList <GxRpAsNode> RPPath)
    {
        if (l_StartIdx == l_Destindex)
        {
            return(true);
        }
        this.m_PathForward.Clear();
        this.m_cGxRoadPointAstar.GeneratePath(0, l_StartIdx, l_Destindex, ref this.m_PathForward);
        this.m_PathBackward.Clear();
        this.m_cGxRoadPointAstar.GeneratePath(0, l_Destindex, l_StartIdx, ref this.m_PathBackward);
        float num  = 0f;
        float num2 = 0f;
        GxRP  gxRP = null;

        foreach (GxRpAsNode current in this.m_PathForward)
        {
            GxRP    rP  = this.m_cGxRoadPointMgr.GetRP(0, (int)current.RPIdx);
            Vector2 pos = rP.GetPos2();
            if (gxRP != null)
            {
                Vector2 pos2 = gxRP.GetPos2();
                num += Vector2.Distance(pos, pos2);
            }
            gxRP = rP;
        }
        gxRP = null;
        foreach (GxRpAsNode current2 in this.m_PathBackward)
        {
            GxRP    rP2  = this.m_cGxRoadPointMgr.GetRP(0, (int)current2.RPIdx);
            Vector2 pos3 = rP2.GetPos2();
            if (gxRP != null)
            {
                Vector2 pos4 = gxRP.GetPos2();
                num2 += Vector2.Distance(pos3, pos4);
            }
            gxRP = rP2;
        }
        if (num != 0f && num2 != 0f)
        {
            if (num <= num2)
            {
                foreach (GxRpAsNode current3 in this.m_PathForward)
                {
                    RPPath.AddLast(current3);
                }
            }
            else
            {
                foreach (GxRpAsNode current4 in this.m_PathBackward)
                {
                    RPPath.AddFirst(current4);
                }
            }
        }
        else if (num == 0f && num2 != 0f)
        {
            Debug.LogError(string.Concat(new object[]
            {
                "NotFind Rp FOWARD Path : start ",
                l_StartIdx,
                " end",
                l_Destindex
            }));
            foreach (GxRpAsNode current5 in this.m_PathBackward)
            {
                RPPath.AddFirst(current5);
            }
        }
        else if (num != 0f && num2 == 0f)
        {
            Debug.LogError(string.Concat(new object[]
            {
                "NotFind Rp BACK Path : start ",
                l_StartIdx,
                " end",
                l_Destindex
            }));
            foreach (GxRpAsNode current6 in this.m_PathForward)
            {
                RPPath.AddLast(current6);
            }
        }
        else
        {
            Debug.LogError(string.Concat(new object[]
            {
                "NotFind Rp Path : start ",
                l_StartIdx,
                " end",
                l_Destindex
            }));
        }
        return(true);
    }
    private bool AutoLinkRPs(short MapIndex, short sRPIndex)
    {
        if (!this.UnLinkAll(MapIndex, sRPIndex))
        {
            return(false);
        }
        GxRP gxRP = this.m_RPList[MapIndex][(int)sRPIndex];
        int  num  = 0;

        this.m_ValidList.Clear();
        this.m_FinalList.Clear();
        this.GetValidRangeRPIndexes(gxRP.GetMapIndex(), gxRP.GetX(), gxRP.GetY(), false);
        if (this.m_ValidList.Count <= 4)
        {
            for (int i = 0; i < this.m_ValidList.Count; i++)
            {
                this.LinkRP(MapIndex, sRPIndex, this.m_ValidList[i]);
            }
            return(true);
        }
        for (int j = 0; j < this.m_ValidList.Count; j++)
        {
            if (sRPIndex != this.m_ValidList[j])
            {
                GxRP rP = this.GetRP(MapIndex, (int)this.m_ValidList[j]);
                if (rP.GetLinkedCount() > 1)
                {
                    short num2 = this.m_ValidList[j];
                    int   num3 = rP.CalcCost(rP.GetX(), rP.GetY());
                    for (int k = 0; k < 4; k++)
                    {
                        if (rP.GetLinkedRP(k) != 0)
                        {
                            if (this.m_ValidList.Contains(rP.GetLinkedRP(k)))
                            {
                                GxRP rP2  = this.GetRP(MapIndex, (int)rP.GetLinkedRP(k));
                                int  num4 = rP2.CalcCost(gxRP.GetX(), gxRP.GetY());
                                if (rP2 != null && num4 <= num3)
                                {
                                    num2 = rP.GetLinkedRP(j);
                                    num3 = num4;
                                }
                            }
                        }
                    }
                    if (!this.m_FinalList.Contains(num2))
                    {
                        this.m_FinalList.AddFirst(num2);
                        num++;
                    }
                    if (num2 != this.m_ValidList[j] && !this.m_FinalList.Contains(this.m_ValidList[j]))
                    {
                        this.m_FinalList.AddLast(this.m_ValidList[j]);
                    }
                }
                else
                {
                    this.m_FinalList.AddFirst(this.m_ValidList[j]);
                    num++;
                }
            }
        }
        if (num > 4)
        {
            Debug.Log("MAX_LINK Over :" + sRPIndex.ToString());
            return(false);
        }
        int num5 = 0;

        foreach (short current in this.m_FinalList)
        {
            if (num5 == 4)
            {
                break;
            }
            this.LinkRP(MapIndex, sRPIndex, current);
            num5++;
        }
        return(true);
    }