diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs
index efe5d1610b..e9cbb0011a 100644
--- a/OpenRa.Game/Game.cs
+++ b/OpenRa.Game/Game.cs
@@ -239,7 +239,6 @@ namespace OpenRa.Game
.FirstOrDefault();
}
-
public static Random SharedRandom = new Random(0); /* for things that require sync */
public static Random CosmeticRandom = new Random(); /* for things that are just fluff */
diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj
index d1c5f7b95b..0aa18fa011 100644
--- a/OpenRa.Game/OpenRa.Game.csproj
+++ b/OpenRa.Game/OpenRa.Game.csproj
@@ -157,6 +157,7 @@
+
diff --git a/OpenRa.Game/Traits/AutoTarget.cs b/OpenRa.Game/Traits/AutoTarget.cs
new file mode 100644
index 0000000000..9ecc2f2f39
--- /dev/null
+++ b/OpenRa.Game/Traits/AutoTarget.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace OpenRa.Game.Traits
+{
+ class AutoTarget : ITick
+ {
+ public AutoTarget(Actor self) {}
+
+ public void Tick(Actor self)
+ {
+ var attack = self.traits.WithInterface().First();
+
+ if (attack.target == null)
+ attack.target = ChooseTarget(self,
+ Rules.WeaponInfo[self.Info.Primary].Range);
+ }
+
+ Actor ChooseTarget(Actor self, float range)
+ {
+ var inRange = Game.FindUnitsInCircle(self.CenterLocation, Game.CellSize * range);
+
+ return inRange.Where(a => a.Owner != self.Owner) /* todo: one day deal with friendly players */
+ .OrderBy(a => (a.Location - self.Location).LengthSquared)
+ .FirstOrDefault();
+ }
+ }
+}
diff --git a/units.ini b/units.ini
index c9a405dd94..8b2b01bbe5 100755
--- a/units.ini
+++ b/units.ini
@@ -278,7 +278,7 @@ Footprint=_ x
SelectionPriority=3
[GUN]
Description=Turret
-Traits=Building, Turreted, RenderBuildingTurreted, AttackTurreted
+Traits=Building, Turreted, RenderBuildingTurreted, AttackTurreted, AutoTarget
Dimensions=1,1
Footprint=x
SelectionPriority=3