merged ATMine/APMine. differences are now all in traitinfo.

This commit is contained in:
Chris Forbes
2010-01-16 10:00:23 +13:00
parent baca523c3c
commit 7a57781080
7 changed files with 101 additions and 131 deletions

View File

@@ -205,8 +205,7 @@
<Compile Include="Traits\Activities\Turn.cs" />
<Compile Include="Traits\Activities\UndeployMcv.cs" />
<Compile Include="Traits\Activities\UnloadCargo.cs" />
<Compile Include="Traits\APMine.cs" />
<Compile Include="Traits\ATMine.cs" />
<Compile Include="Traits\Mine.cs" />
<Compile Include="Traits\AttackBase.cs" />
<Compile Include="Traits\AttackFrontal.cs" />
<Compile Include="Traits\AttackHeli.cs" />

View File

@@ -1,54 +0,0 @@
using System.Collections.Generic;
using OpenRa.Game.Effects;
namespace OpenRa.Game.Traits
{
class APMineInfo : ITraitInfo
{
public object Create(Actor self) { return new APMine(self); }
}
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);
Game.world.Add(new Explosion(self.CenterLocation.ToInt2(), 5, false));
crusher.InflictDamage(crusher, Rules.General.APMineDamage, Rules.WarheadInfo["APMine"]);
});
}
public bool IsPathableCrush(UnitMovementType umt, Player player)
{
return (player != Game.LocalPlayer); // Units should avoid friendly mines
}
public bool IsCrushableBy(UnitMovementType umt, Player player)
{
// Mines should explode indiscriminantly of player
switch (umt)
{
case UnitMovementType.Foot:
case UnitMovementType.Wheel:
case UnitMovementType.Track:
return true;
default: return false;
}
}
public IEnumerable<int2> OccupiedCells() { yield return self.Location; }
}
}

View File

@@ -1,51 +0,0 @@
using System.Collections.Generic;
using OpenRa.Game.Effects;
namespace OpenRa.Game.Traits
{
class ATMineInfo : ITraitInfo
{
public object Create(Actor self) { return new ATMine(self); }
}
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);
Game.world.Add(new Explosion(self.CenterLocation.ToInt2(), 3, false));
crusher.InflictDamage(crusher, Rules.General.AVMineDamage, Rules.WarheadInfo["ATMine"]);
});
}
public bool IsPathableCrush(UnitMovementType umt, Player player)
{
return (player != Game.LocalPlayer); // Units should avoid friendly mines
}
public bool IsCrushableBy(UnitMovementType umt, Player player)
{
// Mines should explode indiscriminantly of player
switch (umt)
{
case UnitMovementType.Wheel:
case UnitMovementType.Track: return true;
default: return false;
}
}
public IEnumerable<int2> OccupiedCells() { yield return self.Location; }
}
}

View File

@@ -0,0 +1,54 @@
using System.Collections.Generic;
using System.Linq;
using OpenRa.Game.Effects;
namespace OpenRa.Game.Traits
{
class MineInfo : ITraitInfo
{
public readonly int Damage = 0;
public readonly UnitMovementType[] TriggeredBy = { };
public readonly string Warhead = "ATMine";
public readonly bool AvoidFriendly = true;
public object Create(Actor self) { return new Mine(self); }
}
class Mine : ICrushable, IOccupySpace
{
readonly Actor self;
public Mine(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;
var info = self.Info.Traits.Get<MineInfo>();
var warhead = Rules.WarheadInfo[info.Warhead];
Game.world.AddFrameEndTask(_ =>
{
Game.world.Remove(self);
Game.world.Add(new Explosion(self.CenterLocation.ToInt2(), warhead.Explosion, false));
crusher.InflictDamage(crusher, info.Damage, warhead);
});
}
public bool IsPathableCrush(UnitMovementType umt, Player player)
{
return !self.Info.Traits.Get<MineInfo>().AvoidFriendly || (player != Game.LocalPlayer);
}
public bool IsCrushableBy(UnitMovementType umt, Player player)
{
return self.Info.Traits.Get<MineInfo>().TriggeredBy.Contains(umt);
}
public IEnumerable<int2> OccupiedCells() { yield return self.Location; }
}
}

View File

@@ -12,3 +12,17 @@ MGG:
GAP:
GeneratesGap:
Range: 10
MINP:
Mine:
Damage: 1000
Warhead: APMine
TriggeredBy: Foot, Wheel, Track
AvoidFriendly: yes
MINV:
Mine:
Damage: 1200
Warhead: ATMine
TriggeredBy: Wheel, Track
AvoidFriendly: yes

52
ra.yaml
View File

@@ -51,6 +51,36 @@ GAP:
RenderBuilding:
IronCurtainable:
MINP:
Mine:
Damage: 1000
Warhead: APMine
TriggeredBy: Foot, Wheel, Track
AvoidFriendly: yes
Inherits: ^Building
Unit:
HP: 1
RenderUnit:
BelowUnits:
InvisibleToOthers:
-Selectable:
-Building:
MINV:
Mine:
Damage: 1200
Warhead: ATMine
TriggeredBy: Wheel, Track
AvoidFriendly: yes
Inherits: ^Building
Unit:
HP: 1
RenderUnit:
BelowUnits:
InvisibleToOthers:
-Selectable:
-Building:
V2RL:
Inherits: ^Vehicle
Buildable:
@@ -1403,28 +1433,6 @@ DOMF:
Image: DOME
Fake:
MINP:
Inherits: ^Building
Unit:
HP: 1
RenderUnit:
APMine:
BelowUnits:
InvisibleToOthers:
-Selectable:
-Building:
MINV:
Inherits: ^Building
Unit:
HP: 1
RenderUnit:
ATMine:
BelowUnits:
InvisibleToOthers:
-Selectable:
-Building:
T01:
Inherits: ^Building
Building:

View File

@@ -526,11 +526,11 @@ LongDesc=Looks like a Radar Dome
[MINV]
Traits=Unit,RenderUnit,ATMine,BelowUnits,InvisibleToOthers
Traits=Unit,RenderUnit,BelowUnits,InvisibleToOthers
Selectable=no
[MINP]
Traits=Unit,RenderUnit,APMine,BelowUnits,InvisibleToOthers
Traits=Unit,RenderUnit,BelowUnits,InvisibleToOthers
Selectable=no
[InfantryTypes]