Example #1
0
    void ShowWayPoints()
    {
        GameObject path_image    = CResourceMgr.LoadMapImage("PathImage");
        GameObject images_parent = Instantiate <GameObject>(CResourceMgr.LoadMapImage("ImagesParent"), new Vector3(0.0f, 0.0f, ImageDefaultPosZ), new Quaternion());

        for (int y = 0; y < Size; ++y)
        {
            for (int x = 0; x < Size; ++x)
            {
                if (WayPoints.Contains(y * Size + x))
                {
                    GameObject new_object = Instantiate <GameObject>(path_image, new Vector3(x, y, ImageDefaultPosZ), new Quaternion());
                    new_object.isStatic = true;
                    new_object.tag      = "PathImage";
                    new_object.transform.SetParent(images_parent.transform);
                }
            }
        }
    }
Example #2
0
    public void OnBuildWayPointPaths()
    {
        CTimeCheck.Start(0);

        OnMakeWayPoints();

        CAStar AStar = new CAStar();

        AStar.InitTiles(ref Tiles);

        for (int i = WayPoints.Count / 2; i < WayPoints.Count; ++i)
        {
            for (int j = WayPoints.Count / 2 - 1; 0 <= j; --j)
            {
                int StartPosIndex = (int)WayPoints[i];
                int EndPosIndex   = (int)WayPoints[j];

                if (StartPosIndex == EndPosIndex)
                {
                    continue;
                }

                int Key = StartPosIndex < EndPosIndex ? StartPosIndex * 10000 + EndPosIndex : EndPosIndex * 10000 + StartPosIndex;
                if (WayPointPaths.ContainsKey(Key))
                {
                    continue;
                }


                ArrayList FindedPaths = AStar.FindPaths(StartPosIndex, EndPosIndex, 0);

                ArrayList RemoveIndexs = new ArrayList();
                for (int k = 0; k < FindedPaths.Count; ++k)
                {
                    if (!WayPoints.Contains(FindedPaths[k]))
                    {
                        RemoveIndexs.Add(FindedPaths[k]);
                    }
                }
                for (int a = 0; a < RemoveIndexs.Count; ++a)
                {
                    FindedPaths.Remove(RemoveIndexs[a]);
                }

                if (3 < FindedPaths.Count)
                {
                    int PathCount = FindedPaths.Count / 2;
                    for (int count = 1; count < PathCount; ++count)
                    {
                        int NewStartIndex = (int)FindedPaths[count];
                        int NewEndIndex   = (int)FindedPaths[FindedPaths.Count - 1 - count];
                        int NewKey        = NewStartIndex < NewEndIndex ? NewStartIndex * 10000 + NewEndIndex : NewEndIndex * 10000 + NewStartIndex;

                        if (WayPointPaths.ContainsKey(NewKey))
                        {
                            continue;
                        }

                        ArrayList clone = (ArrayList)FindedPaths.Clone();
                        clone.RemoveAt(FindedPaths.Count - count);
                        clone.RemoveAt(count - 1);
                        //clone = clone.GetRange(count, FindedPaths.Count - 1 - count);
                        WayPointPaths.Add(NewKey, clone);
                    }
                }
                WayPointPaths.Add(Key, FindedPaths);
            }
        }

        for (int i = 0; i < WayPoints.Count; ++i)
        {
            for (int j = i + 1; j < WayPoints.Count; ++j)
            {
                int StartPosIndex = (int)WayPoints[i];
                int EndPosIndex   = (int)WayPoints[j];

                if (StartPosIndex == EndPosIndex)
                {
                    continue;
                }

                int Key = StartPosIndex < EndPosIndex ? StartPosIndex * 10000 + EndPosIndex : EndPosIndex * 10000 + StartPosIndex;
                if (WayPointPaths.ContainsKey(Key))
                {
                    continue;
                }

                ArrayList FindedPaths = AStar.FindPaths(StartPosIndex, EndPosIndex, 0);

                ArrayList RemoveIndexs = new ArrayList();
                for (int k = 0; k < FindedPaths.Count; ++k)
                {
                    if (!WayPoints.Contains(FindedPaths[k]))
                    {
                        RemoveIndexs.Add(FindedPaths[k]);
                    }
                }
                for (int a = 0; a < RemoveIndexs.Count; ++a)
                {
                    FindedPaths.Remove(RemoveIndexs[a]);
                }

                if (3 < FindedPaths.Count)
                {
                    int PathCount = FindedPaths.Count / 2;
                    for (int count = 1; count < PathCount; ++count)
                    {
                        int NewStartIndex = (int)FindedPaths[count];
                        int NewEndIndex   = (int)FindedPaths[FindedPaths.Count - 1 - count];
                        int NewKey        = NewStartIndex < NewEndIndex ? NewStartIndex * 10000 + NewEndIndex : NewEndIndex * 10000 + NewStartIndex;

                        if (WayPointPaths.ContainsKey(NewKey))
                        {
                            continue;
                        }

                        ArrayList clone = (ArrayList)FindedPaths.Clone();
                        clone.RemoveAt(FindedPaths.Count - count);
                        clone.RemoveAt(count - 1);
                        //clone = clone.GetRange(count, FindedPaths.Count - 1 - count);
                        WayPointPaths.Add(NewKey, clone);
                    }
                }
                WayPointPaths.Add(Key, FindedPaths);
            }
        }

        CTimeCheck.End(ELogType.MapGenerator, "BuildFastPaths");
    }
Example #3
0
    public void OnMakeWayPoints()
    {
        WayPoints.Clear();
        for (int i = 0; i < TileFullSize; ++i)
        {
            if (Tiles[i])
            {
                int a = i + Size - 1;
                if (0 <= a)
                {
                    if (a < Tiles.Length && Tiles[a] == false &&
                        a + 1 < Tiles.Length && Tiles[a + 1] == false &&
                        a - Size < Tiles.Length && Tiles[a - Size] == false)
                    {
                        if (WayPoints.Contains(a))
                        {
                            string   str = "WayPoint Same Index : {0}";
                            object[] arg = { a };
                            CDebugLog.LogFormat(ELogType.MapGenerator, str, arg);
                        }
                        else
                        {
                            WayPoints.Add(a);
                        }
                    }
                }

                int b = i + Size + 1;
                if (0 <= b)
                {
                    if (b < Tiles.Length && Tiles[b] == false &&
                        b - 1 < Tiles.Length && Tiles[b - 1] == false &&
                        b - Size < Tiles.Length && Tiles[b - Size] == false)
                    {
                        if (WayPoints.Contains(b))
                        {
                            string   str = "WayPoint Same Index : {0}";
                            object[] arg = { b };
                            CDebugLog.LogFormat(ELogType.MapGenerator, str, arg);
                        }
                        else
                        {
                            WayPoints.Add(b);
                        }
                    }
                }

                int c = i - Size - 1;
                if (0 <= c)
                {
                    if (c < Tiles.Length && Tiles[c] == false &&
                        c + 1 < Tiles.Length && Tiles[c + 1] == false &&
                        c + Size < Tiles.Length && Tiles[c + Size] == false)
                    {
                        if (WayPoints.Contains(c))
                        {
                            string   str = "WayPoint Same Index : {0}";
                            object[] arg = { c };
                            CDebugLog.LogFormat(ELogType.MapGenerator, str, arg);
                        }
                        else
                        {
                            WayPoints.Add(c);
                        }
                    }
                }

                int d = i - Size + 1;
                if (0 <= d)
                {
                    if (d < Tiles.Length && Tiles[d] == false && 0 < d - 1 &&
                        d - 1 < Tiles.Length && Tiles[d - 1] == false &&
                        d + Size < Tiles.Length && Tiles[d + Size] == false)
                    {
                        if (WayPoints.Contains(d))
                        {
                            string   str = "WayPoint Same Index : {0}";
                            object[] arg = { d };
                            CDebugLog.LogFormat(ELogType.MapGenerator, str, arg);
                        }
                        else
                        {
                            WayPoints.Add(d);
                        }
                    }
                }
            }
        }
        ShowWayPoints();
    }