Exemplo n.º 1
0
 public PathRequest(Vector3 a, Vector3 b, int mapId, PathRequestFlags flags = PathRequestFlags.None, MovementType movementType = MovementType.MOVE_TO_POSITION)
 {
     A            = a;
     B            = b;
     MapId        = mapId;
     Flags        = flags;
     MovementType = movementType;
 }
Exemplo n.º 2
0
 public PathRequest(Vector3 a, Vector3 b, int mapId, PathRequestFlags flags = PathRequestFlags.None, MovementType movementType = MovementType.MoveToPosition)
 {
     A            = a;
     B            = b;
     MapId        = mapId;
     Flags        = flags;
     MovementType = movementType;
 }
 public PathRequest(int mapId, Vector3 a, Vector3 b, PathRequestFlags flags = PathRequestFlags.None, MovementType movementType = MovementType.FindPath)
 {
     Type         = 1;
     A            = a;
     B            = b;
     MapId        = mapId;
     Flags        = flags;
     MovementType = movementType;
 }
Exemplo n.º 4
0
        private string SendPathRequest(int mapId, Vector3 start, Vector3 end, PathRequestFlags pathRequestFlags, MovementType movementType)
        {
            string pathRequest = JsonConvert.SerializeObject(new PathRequest(start, end, mapId, pathRequestFlags, movementType));

            Writer.WriteLine(pathRequest + " >");
            Writer.Flush();

            string pathJson = Reader.ReadLine().Replace(">", string.Empty);

            return(pathJson);
        }
Exemplo n.º 5
0
        public static List <Vector3> GetPath(Vector3 start, Vector3 end, int mapId, PathRequestFlags flags, string clientIp)
        {
            int            pathSize;
            List <Vector3> path = new List <Vector3>();

            Stopwatch sw = new Stopwatch();

            sw.Start();

            lock (maplock)
            {
                if (!AmeisenNav.IsMapLoaded(mapId))
                {
                    AmeisenNav.LoadMap(mapId);
                }

                unsafe
                {
                    fixed(float *pointerStart = start.ToArray())
                    fixed(float *pointerEnd = end.ToArray())
                    {
                        float *path_raw = AmeisenNav.GetPath(mapId, pointerStart, pointerEnd, &pathSize);

                        // postprocess the raw path to a list of Vector3
                        // the raw path looks like this:
                        // [ x1, y1, z1, x2, y2, z2, ...]
                        for (int i = 0; i < pathSize * 3; i += 3)
                        {
                            path.Add(new Vector3(path_raw[i], path_raw[i + 1], path_raw[i + 2]));
                        }
                    }
                }
            }

            if (flags.HasFlag(PathRequestFlags.NaturalSteeringBehavior))
            {
                path = NaturalSteeringBehavior.Perform(path);
            }

            if (flags.HasFlag(PathRequestFlags.ChaikinCurve))
            {
                path = ChaikinCurve.Perform(path);
            }

            //// bugged atm path = NodeReduction.Perform(path);

            sw.Stop();
            LogQueue.Enqueue(new LogEntry($"[{clientIp}] ", ConsoleColor.Green, $"Building Path with {path.Count} Nodes took {sw.ElapsedMilliseconds}ms ({sw.ElapsedTicks} ticks)", LogLevel.INFO));

            return(path);
        }
        private T BuildAndSendPathRequest <T>(int mapId, Vector3 start, Vector3 end, MovementType movementType, PathRequestFlags pathRequestFlags = PathRequestFlags.None)
        {
            if (TcpClient.Connected)
            {
                try
                {
                    string pathJson = SendPathRequest(mapId, start, end, pathRequestFlags, movementType);

                    if (BotUtils.IsValidJson(pathJson))
                    {
                        return(JsonConvert.DeserializeObject <T>(pathJson.Trim()));
                    }
                }
                catch (Exception e)
                {
                    AmeisenLogger.Instance.Log("Pathfinding", $"BuildAndSendPathRequest failed:\n{e}", LogLevel.Error);
                }
            }

            return(default);
Exemplo n.º 7
0
        private unsafe bool SendPathRequest(int mapId, Vector3 start, Vector3 end, MovementType movementType, out Vector3[] path, PathRequestFlags pathRequestFlags = PathRequestFlags.None)
        {
            if (IsConnected)
            {
                try
                {
                    byte[] response = SendData(new PathRequest(mapId, start, end, pathRequestFlags, movementType), sizeof(PathRequest));

                    if (response != null && response.Length >= sizeof(Vector3))
                    {
                        int nodeCount = response.Length / sizeof(Vector3);

                        fixed(byte *pResult = response)
                        {
                            path = new Span <Vector3>(pResult, nodeCount).ToArray();
                            return(true);
                        }
                    }
                }
                catch (Exception e)
                {
                    AmeisenLogger.I.Log("Pathfinding", $"BuildAndSendRandomPointRequest failed:\n{e}", LogLevel.Error);
                }
            }

            path = null;
            return(false);
        }
Exemplo n.º 8
0
        public static List <Vector3> GetPath(Vector3 start, Vector3 end, float maxRadius, int mapId, MovementType movementType, PathRequestFlags flags, string clientIp)
        {
            int            pathSize;
            List <Vector3> path = new List <Vector3>();

            Stopwatch sw = new Stopwatch();

            sw.Start();

            lock (querylock)
            {
                if (!AmeisenNav.IsMapLoaded(mapId))
                {
                    AmeisenNav.LoadMap(mapId);
                }

                unsafe
                {
                    fixed(float *pointerStart = start.ToArray())
                    fixed(float *pointerEnd = end.ToArray())
                    {
                        switch (movementType)
                        {
                        case MovementType.MoveToPosition:
                            float[] movePath = AmeisenNav.GetPath(mapId, pointerStart, pointerEnd, &pathSize);

                            for (int i = 0; i < pathSize * 3; i += 3)
                            {
                                path.Add(new Vector3(movePath[i], movePath[i + 1], movePath[i + 2]));
                            }

                            if (flags.HasFlag(PathRequestFlags.ChaikinCurve))
                            {
                                path = ChaikinCurve.Perform(path);
                            }
                            break;

                        case MovementType.MoveAlongSurface:
                            float[] surfacePath = AmeisenNav.MoveAlongSurface(mapId, pointerStart, pointerEnd);
                            path.Add(new Vector3(surfacePath[0], surfacePath[1], surfacePath[2]));
                            break;

                        case MovementType.CastMovementRay:
                            if (AmeisenNav.CastMovementRay(mapId, pointerStart, pointerEnd))
                            {
                                // return end if target is in line of sight
                                path.Add(end);
                            }
                            else
                            {
                                // return none if target is not in line of sight
                                path.Clear();
                            }
                            break;

                        case MovementType.GetRandomPoint:
                            float[] randomPoint = AmeisenNav.GetRandomPoint(mapId);
                            path.Add(new Vector3(randomPoint[0], randomPoint[1], randomPoint[2]));
                            break;

                        case MovementType.GetRandomPointAround:
                            float[] randomPointAround = AmeisenNav.GetRandomPointAround(mapId, pointerStart, maxRadius);
                            path.Add(new Vector3(randomPointAround[0], randomPointAround[1], randomPointAround[2]));
                            break;
                        }
                    }
                }
            }

            sw.Stop();
            LogQueue.Enqueue(new LogEntry($"[{clientIp}] ", ConsoleColor.Green, $"{movementType} with {path.Count}/{Settings.MaxPointPathCount} Nodes took {sw.ElapsedMilliseconds}ms ({sw.ElapsedTicks} ticks)", LogLevel.INFO));
            return(path);
        }