added AutoTarget trait
This commit is contained in:
@@ -239,7 +239,6 @@ namespace OpenRa.Game
|
|||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Random SharedRandom = new Random(0); /* for things that require sync */
|
public static Random SharedRandom = new Random(0); /* for things that require sync */
|
||||||
public static Random CosmeticRandom = new Random(); /* for things that are just fluff */
|
public static Random CosmeticRandom = new Random(); /* for things that are just fluff */
|
||||||
|
|
||||||
|
|||||||
@@ -157,6 +157,7 @@
|
|||||||
<Compile Include="Traits\Activities\Turn.cs" />
|
<Compile Include="Traits\Activities\Turn.cs" />
|
||||||
<Compile Include="Traits\AttackBase.cs" />
|
<Compile Include="Traits\AttackBase.cs" />
|
||||||
<Compile Include="Traits\AttackTurreted.cs" />
|
<Compile Include="Traits\AttackTurreted.cs" />
|
||||||
|
<Compile Include="Traits\AutoTarget.cs" />
|
||||||
<Compile Include="Traits\Building.cs" />
|
<Compile Include="Traits\Building.cs" />
|
||||||
<Compile Include="Traits\Harvester.cs" />
|
<Compile Include="Traits\Harvester.cs" />
|
||||||
<Compile Include="Traits\Helicopter.cs" />
|
<Compile Include="Traits\Helicopter.cs" />
|
||||||
|
|||||||
30
OpenRa.Game/Traits/AutoTarget.cs
Normal file
30
OpenRa.Game/Traits/AutoTarget.cs
Normal file
@@ -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<AttackBase>().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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -278,7 +278,7 @@ Footprint=_ x
|
|||||||
SelectionPriority=3
|
SelectionPriority=3
|
||||||
[GUN]
|
[GUN]
|
||||||
Description=Turret
|
Description=Turret
|
||||||
Traits=Building, Turreted, RenderBuildingTurreted, AttackTurreted
|
Traits=Building, Turreted, RenderBuildingTurreted, AttackTurreted, AutoTarget
|
||||||
Dimensions=1,1
|
Dimensions=1,1
|
||||||
Footprint=x
|
Footprint=x
|
||||||
SelectionPriority=3
|
SelectionPriority=3
|
||||||
|
|||||||
Reference in New Issue
Block a user