Merge branch 'minelayer'

This commit is contained in:
Chris Forbes
2009-12-28 18:06:17 +13:00
10 changed files with 138 additions and 19 deletions

View File

@@ -181,6 +181,9 @@
<Compile Include="Traits\Fake.cs" />
<Compile Include="Traits\Harvester.cs" />
<Compile Include="Traits\Helicopter.cs" />
<Compile Include="Traits\InvisibleToOthers.cs" />
<Compile Include="Traits\MineImmune.cs" />
<Compile Include="Traits\Minelayer.cs" />
<Compile Include="Traits\SquishByTank.cs" />
<Compile Include="Traits\Plane.cs" />
<Compile Include="Traits\ProductionQueue.cs" />
@@ -256,11 +259,11 @@
<None Include="Graphics\Graphics.cd" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -5,16 +5,20 @@ using OpenRa.Game.GameRules;
using OpenRa.Game.Effects;
namespace OpenRa.Game.Traits
{
class APMine : ICrushable
class APMine : ICrushable, IOccupySpace
{
readonly Actor self;
public APMine(Actor self)
{
this.self = self;
Game.UnitInfluence.Add(self, this);
}
public void OnCrush(Actor crusher)
{
if (crusher.traits.Contains<MineImmune>() && crusher.Owner == self.Owner)
return;
Game.world.AddFrameEndTask(_ =>
{
Game.world.Remove(self);
@@ -33,9 +37,15 @@ namespace OpenRa.Game.Traits
// Mines should explode indiscriminantly of player
switch (umt)
{
case UnitMovementType.Foot: return true;
case UnitMovementType.Foot:
case UnitMovementType.Wheel:
case UnitMovementType.Track:
return true;
default: return false;
}
}
public IEnumerable<int2> OccupiedCells() { yield return self.Location; }
}
}

View File

@@ -6,16 +6,20 @@ using OpenRa.Game.Effects;
namespace OpenRa.Game.Traits
{
class ATMine : ICrushable
class ATMine : ICrushable, IOccupySpace
{
readonly Actor self;
public ATMine(Actor self)
{
this.self = self;
Game.UnitInfluence.Add(self, this);
}
public void OnCrush(Actor crusher)
{
if (crusher.traits.Contains<MineImmune>() && crusher.Owner == self.Owner)
return;
Game.world.AddFrameEndTask(_ =>
{
Game.world.Remove(self);
@@ -39,5 +43,7 @@ namespace OpenRa.Game.Traits
default: return false;
}
}
public IEnumerable<int2> OccupiedCells() { yield return self.Location; }
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRa.Game.Traits
{
class InvisibleToOthers : IRenderModifier
{
public InvisibleToOthers(Actor self) { }
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
{
return Game.LocalPlayer == self.Owner
? r : new Renderable[] { };
}
}
}

View File

@@ -0,0 +1,8 @@

namespace OpenRa.Game.Traits
{
class MineImmune
{
public MineImmune(Actor self) { }
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRa.Game.Traits
{
class Minelayer : IOrder
{
public Minelayer(Actor self) { }
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
{
// todo: check for ammo
if (mi.Button == MouseButton.Right && underCursor == self)
return new Order("Deploy", self, null, int2.Zero, null);
return null;
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString == "Deploy")
{
// todo: check for and adjust ammo
// todo: delay a bit?
Game.world.AddFrameEndTask(
w => w.Add(new Actor(Rules.UnitInfo[self.Info.Primary], self.Location, self.Owner)));
}
}
}
}

View File

@@ -83,7 +83,7 @@ namespace OpenRa.Game.Traits
case "Plane":
return UnitMovementType.Fly;
default:
throw new InvalidOperationException("GetMovementType on unit that shouldn't be aable to move.");
throw new InvalidOperationException("GetMovementType on unit that shouldn't be able to move.");
}
}