private Vector3 GetWardPos(Vector3 lastPos, int radius = 165, int precision = 3) { //Vector3 averagePos = Vector3.Zero; int count = precision; //int calculated = 0; while (count > 0) { int vertices = radius; var wardLocations = new WardLocation[vertices]; double angle = 2 * Math.PI / vertices; for (int i = 0; i < vertices; i++) { double th = angle * i; var pos = new Vector3((float)(lastPos.X + radius * Math.Cos(th)), (float)(lastPos.Y + radius * Math.Sin(th)), 0); //wardPos.Z wardLocations[i] = new WardLocation(pos, NavMesh.IsWallOfGrass(pos, 10)); } var grassLocations = new List <GrassLocation>(); for (int i = 0; i < wardLocations.Length; i++) { if (wardLocations[i].Grass) { if (i != 0 && wardLocations[i - 1].Grass) { grassLocations.Last().Count++; } else { grassLocations.Add(new GrassLocation(i, 1)); } } } GrassLocation grassLocation = grassLocations.OrderByDescending(x => x.Count).FirstOrDefault(); if (grassLocation != null) //else: no pos found. increase/decrease radius? { var midelement = (int)Math.Ceiling(grassLocation.Count / 2f); //averagePos += wardLocations[grassLocation.Index + midelement - 1].Pos; //uncomment if using averagePos lastPos = wardLocations[grassLocation.Index + midelement - 1].Pos; //comment if using averagePos radius = (int)Math.Floor(radius / 2f); //precision recommended: 2-3; comment if using averagePos //calculated++; //uncomment if using averagePos } count--; } return(lastPos); //averagePos /= calculated; //uncomment if using averagePos }
private Vector3 GetWardPos(Vector3 lastPos, int radius = 165, int precision = 3) //maybe reverse autobushward code from the bots? { //old: Vector3 wardPos = enemy.Position + Vector3.Normalize(enemy.Position - ObjectManager.Player.Position) * 150; var count = precision; while (count > 0) { var vertices = radius; var wardLocations = new WardLocation[vertices]; var angle = 2 * Math.PI / vertices; for (var i = 0; i < vertices; i++) { var th = angle * i; var pos = new Vector3( (float)(lastPos.X + radius * Math.Cos(th)), (float)(lastPos.Y + radius * Math.Sin(th)), 0); wardLocations[i] = new WardLocation(pos, NavMesh.IsWallOfGrass(pos, 5)); } var grassLocations = new List <GrassLocation>(); for (var i = 0; i < wardLocations.Length; i++) { if (!wardLocations[i].Grass) { continue; } if (i != 0 && wardLocations[i - 1].Grass) { grassLocations.Last().Count++; } else { grassLocations.Add(new GrassLocation(i, 1)); } } var grassLocation = grassLocations.OrderByDescending(x => x.Count).FirstOrDefault(); if (grassLocation != null) //else: no pos found. increase/decrease radius? { var midelement = (int)Math.Ceiling(grassLocation.Count / 2f); lastPos = wardLocations[grassLocation.Index + midelement - 1].Pos; radius = (int)Math.Floor(radius / 2f); } count--; } return(lastPos); }
private static Vector3 GetWardPos(Vector3 lastPos, int radius = 165, int precision = 3) { var count = precision; while (count > 0) { var vertices = radius; var wardLocations = new WardLocation[vertices]; var angle = 2 * Math.PI / vertices; for (var i = 0; i < vertices; i++) { var th = angle * i; var pos = new Vector3((float)(lastPos.X + radius * Math.Cos(th)), (float)(lastPos.Y + radius * Math.Sin(angle * i)), 0); wardLocations[i] = new WardLocation(pos, NavMesh.IsWallOfGrass(pos, 50)); } var grassLocations = new List <GrassLocation>(); for (var i = 0; i < wardLocations.Length; i++) { if (!wardLocations[i].Grass) { continue; } if (i != 0 && wardLocations[i - 1].Grass) { grassLocations.Last().Count++; } else { grassLocations.Add(new GrassLocation(i, 1)); } } var grassLocation = grassLocations.OrderByDescending(x => x.Count).FirstOrDefault(); if (grassLocation != null) { var midelement = (int)Math.Ceiling(grassLocation.Count / 2f); lastPos = wardLocations[grassLocation.Index + midelement - 1].Pos; radius = (int)Math.Floor(radius / 2f); } count--; } return(lastPos); }
private Vector3 GetWardPos(Vector3 lastPos, int radius = 165, int precision = 3) { //Vector3 averagePos = Vector3.Zero; int count = precision; //int calculated = 0; while (count > 0) { int vertices = radius; var wardLocations = new WardLocation[vertices]; double angle = 2*Math.PI/vertices; for (int i = 0; i < vertices; i++) { double th = angle*i; var pos = new Vector3((float) (lastPos.X + radius*Math.Cos(th)), (float) (lastPos.Y + radius*Math.Sin(th)), 0); //wardPos.Z wardLocations[i] = new WardLocation(pos, NavMesh.IsWallOfGrass(pos, 10)); } var grassLocations = new List<GrassLocation>(); for (int i = 0; i < wardLocations.Length; i++) { if (wardLocations[i].Grass) { if (i != 0 && wardLocations[i - 1].Grass) grassLocations.Last().Count++; else grassLocations.Add(new GrassLocation(i, 1)); } } GrassLocation grassLocation = grassLocations.OrderByDescending(x => x.Count).FirstOrDefault(); if (grassLocation != null) //else: no pos found. increase/decrease radius? { var midelement = (int) Math.Ceiling(grassLocation.Count/2f); //averagePos += wardLocations[grassLocation.Index + midelement - 1].Pos; //uncomment if using averagePos lastPos = wardLocations[grassLocation.Index + midelement - 1].Pos; //comment if using averagePos radius = (int) Math.Floor(radius/2f); //precision recommended: 2-3; comment if using averagePos //calculated++; //uncomment if using averagePos } count--; } return lastPos; //averagePos /= calculated; //uncomment if using averagePos }
//maybe reverse autobushward code from the bots? Vector3 GetWardPos(Vector3 lastPos, int radius = 165, int precision = 3) { //old: Vector3 wardPos = enemy.Position + Vector3.Normalize(enemy.Position - ObjectManager.Player.Position) * 150; var count = precision; while (count > 0) { var vertices = radius; var wardLocations = new WardLocation[vertices]; var angle = 2 * Math.PI / vertices; for (var i = 0; i < vertices; i++) { var th = angle * i; var pos = new Vector3((float)(lastPos.X + radius * Math.Cos(th)), (float)(lastPos.Y + radius * Math.Sin(th)), 0); wardLocations[i] = new WardLocation(pos, NavMesh.IsWallOfGrass(pos, 5)); } var grassLocations = new List<GrassLocation>(); for (var i = 0; i < wardLocations.Length; i++) { if (!wardLocations[i].Grass) continue; if (i != 0 && wardLocations[i - 1].Grass) grassLocations.Last().Count++; else grassLocations.Add(new GrassLocation(i, 1)); } var grassLocation = grassLocations.OrderByDescending(x => x.Count).FirstOrDefault(); if (grassLocation != null) //else: no pos found. increase/decrease radius? { var midelement = (int)Math.Ceiling(grassLocation.Count / 2f); lastPos = wardLocations[grassLocation.Index + midelement - 1].Pos; radius = (int)Math.Floor(radius / 2f); } count--; } return lastPos; }
private static Vector3 GetWardPos(Vector3 lastPos, int radius = 165, int precision = 3) { var count = precision; while (count > 0) { var vertices = radius; var wardLocations = new WardLocation[vertices]; var angle = 2 * Math.PI / vertices; for (var i = 0; i < vertices; i++) { var th = angle * i; var pos = new Vector3((float)(lastPos.X + radius * Math.Cos(th)), (float)(lastPos.Y + radius * Math.Sin(angle * i)), 0); wardLocations[i] = new WardLocation(pos, NavMesh.IsWallOfGrass(pos, 50)); } var grassLocations = new List<GrassLocation>(); for (var i = 0; i < wardLocations.Length; i++) { if (!wardLocations[i].Grass) { continue; } if (i != 0 && wardLocations[i - 1].Grass) { grassLocations.Last().Count++; } else { grassLocations.Add(new GrassLocation(i, 1)); } } var grassLocation = grassLocations.OrderByDescending(x => x.Count).FirstOrDefault(); if (grassLocation != null) { var midelement = (int)Math.Ceiling(grassLocation.Count / 2f); lastPos = wardLocations[grassLocation.Index + midelement - 1].Pos; radius = (int)Math.Floor(radius / 2f); } count--; } return lastPos; }