Index: lua/helper.lua
===================================================================
--- lua/helper.lua	(revision 41922)
+++ lua/helper.lua	(working copy)
@@ -271,4 +271,20 @@
 	return math.max(hdist, vdist + math.floor(hdist / 2))
 end
 
+--! Returns the nearest unit to the imput_unit among the list_of_units
+function helper.nearest_unit(input_unit,list_of_units)
+
+	local output_unit = list_of_units[1];
+	local dist = helper.distance_between(  input_unit.x, input_unit.y, output_unit.x, output_unit.y)
+	
+	for i = 1, #list_of_units do
+		if(helper.distance_between(input_unit.x, input_unit.y,list_of_units[i].x,list_of_units[i].y) < dist) then 
+			output_unit = list_of_units[i];
+			dist = helper.distance_between(  input_unit.x, input_unit.y, output_unit.x, output_unit.y)
+		end
+	end
+	return output_unit	
+end
+
+
 return helper
Index: ai/lua/stdlib.lua
===================================================================
--- ai/lua/stdlib.lua	(revision 41922)
+++ ai/lua/stdlib.lua	(working copy)
@@ -11,6 +11,26 @@
        wesnoth.message(string.format("Hello from Lua AI which controls side %d! It's turn %d.", ai.side, wesnoth.current.turn))
 end
 
+--! Rreturns the enemy units that are within the given range surrounding ai_unit
+function ai.close_enemies(ai_unit, range)
+
+	local helper = wesnoth.require "lua/helper.lua"
+	local enemy_units = {} 
+	local all_units=wesnoth.get_units()
+	local index = 1;
+	
+	for i = 1, #all_units do
+		if all_units[i].side ~=  ai.side then
+			local dist = helper.distance_between(ai_unit.x,ai_unit.y,all_units[i].x,all_units[i].y)
+			if dist<= range then
+				enemy_units[index] = unit
+				index = index + 1
+			end
+		end
+	end
+	return enemy_units
+end
+
 --! ===========================
 end
 }
