add CarpetBomb trait for 1-pass airstrikes etc

This commit is contained in:
Chris Forbes
2010-04-10 11:17:52 +12:00
parent ee8f0fd04a
commit dd1415dda8
2 changed files with 59 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRA.Traits;
using OpenRA.GameRules;
namespace OpenRA.Mods.Cnc
{
class CarpetBombInfo : ITraitInfo
{
public readonly string Weapon = null;
public readonly int Interval = 0;
public readonly int Range = 0;
public object Create(Actor self) { return new CarpetBomb(self); }
}
class CarpetBomb : ITick
{
int2 Target;
int dropDelay;
public CarpetBomb(Actor self) { }
public void SetTarget(int2 targetCell) { Target = targetCell; }
public void Tick(Actor self)
{
var info = self.Info.Traits.Get<CarpetBombInfo>();
if ((self.Location - Target).LengthSquared > info.Range * info.Range)
return;
var limitedAmmo = self.traits.GetOrDefault<LimitedAmmo>();
if (limitedAmmo != null && !limitedAmmo.HasAmmo())
return;
if (--dropDelay <= 0)
{
dropDelay = info.Interval;
var args = new ProjectileArgs
{
srcAltitude = self.traits.Get<Unit>().Altitude,
destAltitude = 0,
src = self.CenterLocation.ToInt2(),
dest = self.CenterLocation.ToInt2(),
facing = self.traits.Get<Unit>().Facing,
firedBy = self,
weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()]
};
self.World.Add(args.weapon.Projectile.Create(args));
}
}
}
}

View File

@@ -46,6 +46,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AirstrikePower.cs" />
<Compile Include="CarpetBomb.cs" />
<Compile Include="CriticalBuildingState.cs" />
<Compile Include="Effects\IonCannon.cs" />
<Compile Include="IonCannonPower.cs" />