public Vector2 nearest_cover(Vector2 pos, Vector2 enemy_pos) { List <_Node> ret = new List <_Node>(); Nav_area_generic area = get_area(pos); //Get a list of nodes where the enemy doesn't have a LOS to if (area != null) { int idx = 0; do { for (int i = 0; i < area.area_nodes.Count; i++) { bool seen = LOS(enemy_pos, area.area_nodes[i].position, -1, LOS_block); if (!seen) { ret.Add(area.area_nodes[i]); } } if (ret.Count > 0) { break; } area = nav_areas[idx]; idx++; }while (idx <= nav_areas.Length); } if (ret.Count == 0) { Debug.LogError("Position: " + pos + "cant find a cover"); return(CONSTANTS.VEC_NULL); } //Find the closest cover float min_dist = Vector2.Distance(pos, ret[0].position); int j = 0; for (int i = 1; i < ret.Count; i++) { if (Vector2.Distance(pos, ret[i].position) < min_dist) { min_dist = Vector2.Distance(pos, ret[i].position); j = i; } } return(ret[j].position); }
//Get the surrounding nodes within the area public List <_Node> surround_nodes(Vector2 position, float size, float min_dist) { List <_Node> ret = new List <_Node>(); Nav_area_generic area = get_area(position); if (area != null) { for (int i = 0; i < area.area_nodes.Count; i++) { bool seen = LOS(position, area.area_nodes[i].position, size, Path_block); if (seen && Vector2.Distance(position, area.area_nodes[i].position) > size) { ret.Add(area.area_nodes[i]); } } } else if (ret.Count == 0) { //Debug.LogError("Position: " + position + " cant find surrounding nodes"); } return(ret); }