finished building *Infos

This commit is contained in:
Chris Forbes
2010-01-10 17:28:05 +13:00
parent 9add15464c
commit 12b84a8468
48 changed files with 121 additions and 147 deletions

View File

@@ -647,7 +647,7 @@ namespace OpenRa.Game
DrawRightAligned( "${0}".F(info.Cost), pos + new int2(-5,5), DrawRightAligned( "${0}".F(info.Cost), pos + new int2(-5,5),
Game.LocalPlayer.Cash + Game.LocalPlayer.Ore >= info.Cost ? Color.White : Color.Red); Game.LocalPlayer.Cash + Game.LocalPlayer.Ore >= info.Cost ? Color.White : Color.Red);
var bi = info as BuildingInfo; var bi = info as LegacyBuildingInfo;
if (bi != null) if (bi != null)
DrawRightAligned("ϟ{0}".F(bi.Power), pos + new int2(-5, 20), DrawRightAligned("ϟ{0}".F(bi.Power), pos + new int2(-5, 20),
Game.LocalPlayer.PowerProvided - Game.LocalPlayer.PowerDrained + bi.Power >= 0 Game.LocalPlayer.PowerProvided - Game.LocalPlayer.PowerDrained + bi.Power >= 0

View File

@@ -321,7 +321,7 @@ namespace OpenRa.Game
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 */
public static bool CanPlaceBuilding(BuildingInfo building, int2 xy, Actor toIgnore, bool adjust) public static bool CanPlaceBuilding(LegacyBuildingInfo building, int2 xy, Actor toIgnore, bool adjust)
{ {
return !Footprint.Tiles(building, xy, adjust).Any( return !Footprint.Tiles(building, xy, adjust).Any(
t => !Rules.Map.IsInMap(t.X, t.Y) || Rules.Map.ContainsResource(t) || !Game.IsCellBuildable(t, t => !Rules.Map.IsInMap(t.X, t.Y) || Rules.Map.ContainsResource(t) || !Game.IsCellBuildable(t,
@@ -329,7 +329,7 @@ namespace OpenRa.Game
toIgnore)); toIgnore));
} }
public static bool IsCloseEnoughToBase(Player p, BuildingInfo bi, int2 position) public static bool IsCloseEnoughToBase(Player p, LegacyBuildingInfo bi, int2 position)
{ {
var maxDistance = bi.Adjacent + 1; var maxDistance = bi.Adjacent + 1;
@@ -338,7 +338,7 @@ namespace OpenRa.Game
heuristic = loc => heuristic = loc =>
{ {
var b = Game.BuildingInfluence.GetBuildingAt(loc); var b = Game.BuildingInfluence.GetBuildingAt(loc);
if (b != null && b.Owner == p && (b.Info as BuildingInfo).BaseNormal) return 0; if (b != null && b.Owner == p && (b.Info as LegacyBuildingInfo).BaseNormal) return 0;
if ((loc - position).Length > maxDistance) if ((loc - position).Length > maxDistance)
return float.PositiveInfinity; /* not quite right */ return float.PositiveInfinity; /* not quite right */
return 1; return 1;

View File

@@ -6,12 +6,12 @@ namespace OpenRa.Game.GameRules
{ {
static class Footprint static class Footprint
{ {
public static IEnumerable<int2> Tiles( BuildingInfo buildingInfo, int2 position ) public static IEnumerable<int2> Tiles( LegacyBuildingInfo buildingInfo, int2 position )
{ {
return Tiles(buildingInfo, position, true); return Tiles(buildingInfo, position, true);
} }
public static IEnumerable<int2> Tiles( BuildingInfo buildingInfo, int2 position, bool adjustForPlacement ) public static IEnumerable<int2> Tiles( LegacyBuildingInfo buildingInfo, int2 position, bool adjustForPlacement )
{ {
var dim = buildingInfo.Dimensions; var dim = buildingInfo.Dimensions;
@@ -33,7 +33,7 @@ namespace OpenRa.Game.GameRules
return Tiles( building.unitInfo, a.Location, false ); return Tiles( building.unitInfo, a.Location, false );
} }
public static IEnumerable<int2> UnpathableTiles( BuildingInfo buildingInfo, int2 position ) public static IEnumerable<int2> UnpathableTiles( LegacyBuildingInfo buildingInfo, int2 position )
{ {
var footprint = buildingInfo.Footprint.Where( x => !char.IsWhiteSpace( x ) ).ToArray(); var footprint = buildingInfo.Footprint.Where( x => !char.IsWhiteSpace( x ) ).ToArray();
foreach( var tile in TilesWhere( buildingInfo.Name, buildingInfo.Dimensions, footprint, a => a == 'x' ) ) foreach( var tile in TilesWhere( buildingInfo.Name, buildingInfo.Dimensions, footprint, a => a == 'x' ) )
@@ -52,7 +52,7 @@ namespace OpenRa.Game.GameRules
yield return new int2( x, y ); yield return new int2( x, y );
} }
public static int2 AdjustForBuildingSize( BuildingInfo unitInfo ) public static int2 AdjustForBuildingSize( LegacyBuildingInfo unitInfo )
{ {
var dim = unitInfo.Dimensions; var dim = unitInfo.Dimensions;
return new int2( dim.X / 2, dim.Y > 1 ? ( dim.Y + 1 ) / 2 : 0 ); return new int2( dim.X / 2, dim.Y > 1 ? ( dim.Y + 1 ) / 2 : 0 );

View File

@@ -65,8 +65,8 @@ namespace OpenRa.Game
UnitCategory = Categories.SelectMany(x => x.Value.Select(y => new KeyValuePair<string, string>(y, x.Key))).ToDictionary(x => x.Key, x => x.Value); UnitCategory = Categories.SelectMany(x => x.Value.Select(y => new KeyValuePair<string, string>(y, x.Key))).ToDictionary(x => x.Key, x => x.Value);
UnitInfo = new InfoLoader<LegacyUnitInfo>( UnitInfo = new InfoLoader<LegacyUnitInfo>(
Pair.New<string, Func<string, LegacyUnitInfo>>("Building", s => new BuildingInfo(s)), Pair.New<string, Func<string, LegacyUnitInfo>>("Building", s => new LegacyBuildingInfo(s)),
Pair.New<string, Func<string, LegacyUnitInfo>>("Defense", s => new BuildingInfo(s)), Pair.New<string, Func<string, LegacyUnitInfo>>("Defense", s => new LegacyBuildingInfo(s)),
Pair.New<string, Func<string, LegacyUnitInfo>>("Infantry", s => new InfantryInfo(s)), Pair.New<string, Func<string, LegacyUnitInfo>>("Infantry", s => new InfantryInfo(s)),
Pair.New<string, Func<string, LegacyUnitInfo>>("Vehicle", s => new VehicleInfo(s)), Pair.New<string, Func<string, LegacyUnitInfo>>("Vehicle", s => new VehicleInfo(s)),
Pair.New<string, Func<string, LegacyUnitInfo>>("Ship", s => new VehicleInfo(s)), Pair.New<string, Func<string, LegacyUnitInfo>>("Ship", s => new VehicleInfo(s)),

View File

@@ -12,7 +12,7 @@ namespace OpenRa.Game.GameRules
{ {
foreach( var b in Rules.Categories[ "Building" ] ) foreach( var b in Rules.Categories[ "Building" ] )
{ {
var info = (BuildingInfo)Rules.UnitInfo[ b ]; var info = (LegacyBuildingInfo)Rules.UnitInfo[ b ];
foreach( var p in info.Produces ) foreach( var p in info.Produces )
producesIndex[ p ].Add( info ); producesIndex[ p ].Add( info );
} }
@@ -21,7 +21,7 @@ namespace OpenRa.Game.GameRules
public Cache<string, List<Actor>> GatherBuildings( Player player ) public Cache<string, List<Actor>> GatherBuildings( Player player )
{ {
var ret = new Cache<string, List<Actor>>( x => new List<Actor>() ); var ret = new Cache<string, List<Actor>>( x => new List<Actor>() );
foreach( var b in Game.world.Actors.Where( x => x.Owner == player && x.Info is BuildingInfo ) ) foreach( var b in Game.world.Actors.Where( x => x.Owner == player && x.Info is LegacyBuildingInfo ) )
ret[ b.Info.Name ].Add( b ); ret[ b.Info.Name ].Add( b );
return ret; return ret;
} }

View File

@@ -94,7 +94,7 @@ namespace OpenRa.Game.GameRules
public VehicleInfo(string name) : base(name) { } public VehicleInfo(string name) : base(name) { }
} }
public class BuildingInfo : LegacyUnitInfo public class LegacyBuildingInfo : LegacyUnitInfo
{ {
public readonly int2 Dimensions = new int2(1, 1); public readonly int2 Dimensions = new int2(1, 1);
public readonly string Footprint = "x"; public readonly string Footprint = "x";
@@ -112,6 +112,6 @@ namespace OpenRa.Game.GameRules
public readonly int[] RallyPoint = { 1, 3 }; public readonly int[] RallyPoint = { 1, 3 };
public readonly float[] SpawnOffset = null; public readonly float[] SpawnOffset = null;
public BuildingInfo(string name) : base(name) { } public LegacyBuildingInfo(string name) : base(name) { }
} }
} }

View File

@@ -6,12 +6,12 @@ namespace OpenRa.Game.Orders
class PlaceBuildingOrderGenerator : IOrderGenerator class PlaceBuildingOrderGenerator : IOrderGenerator
{ {
readonly Actor Producer; readonly Actor Producer;
readonly BuildingInfo Building; readonly LegacyBuildingInfo Building;
public PlaceBuildingOrderGenerator(Actor producer, string name) public PlaceBuildingOrderGenerator(Actor producer, string name)
{ {
Producer = producer; Producer = producer;
Building = (BuildingInfo)Rules.UnitInfo[ name ]; Building = (LegacyBuildingInfo)Rules.UnitInfo[ name ];
} }
public IEnumerable<Order> Order(int2 xy, MouseInput mi) public IEnumerable<Order> Order(int2 xy, MouseInput mi)

View File

@@ -27,7 +27,7 @@ namespace OpenRa.Game.Orders
&& a.traits.Contains<Building>() && a.traits.Contains<Building>()
&& a.Info.Selectable).FirstOrDefault(); && a.Info.Selectable).FirstOrDefault();
var building = underCursor != null ? underCursor.Info as BuildingInfo : null; var building = underCursor != null ? underCursor.Info as LegacyBuildingInfo : null;
if (building != null) if (building != null)
yield return new Order("PowerDown", underCursor, null, int2.Zero, null); yield return new Order("PowerDown", underCursor, null, int2.Zero, null);

View File

@@ -27,7 +27,7 @@ namespace OpenRa.Game.Orders
&& a.traits.Contains<Building>() && a.traits.Contains<Building>()
&& a.Info.Selectable).FirstOrDefault(); && a.Info.Selectable).FirstOrDefault();
var building = underCursor != null ? underCursor.Info as BuildingInfo : null; var building = underCursor != null ? underCursor.Info as LegacyBuildingInfo : null;
if (building != null && building.Repairable && underCursor.Health < building.Strength) if (building != null && building.Repairable && underCursor.Health < building.Strength)
yield return new Order("Repair", underCursor, null, int2.Zero, null); yield return new Order("Repair", underCursor, null, int2.Zero, null);

View File

@@ -27,7 +27,7 @@ namespace OpenRa.Game.Orders
&& a.traits.Contains<Building>() && a.traits.Contains<Building>()
&& a.Info.Selectable).FirstOrDefault(); && a.Info.Selectable).FirstOrDefault();
var building = underCursor != null ? underCursor.Info as BuildingInfo : null; var building = underCursor != null ? underCursor.Info as LegacyBuildingInfo : null;
if (building != null && !building.Unsellable) if (building != null && !building.Unsellable)
yield return new Order("Sell", underCursor, null, int2.Zero, null); yield return new Order("Sell", underCursor, null, int2.Zero, null);

View File

@@ -69,7 +69,7 @@ namespace OpenRa.Game.Orders
else else
return Cursor.MoveBlocked; return Cursor.MoveBlocked;
case "DeployMcv": case "DeployMcv":
var factBuildingInfo = (BuildingInfo)Rules.UnitInfo["fact"]; var factBuildingInfo = (LegacyBuildingInfo)Rules.UnitInfo["fact"];
if (Game.CanPlaceBuilding(factBuildingInfo, a.Location - new int2(1, 1), a, false)) if (Game.CanPlaceBuilding(factBuildingInfo, a.Location - new int2(1, 1), a, false))
return Cursor.Deploy; return Cursor.Deploy;
else else

View File

@@ -16,7 +16,7 @@ namespace OpenRa.Game.Orders
Game.world.AddFrameEndTask( _ => Game.world.AddFrameEndTask( _ =>
{ {
var queue = order.Player.PlayerActor.traits.Get<Traits.ProductionQueue>(); var queue = order.Player.PlayerActor.traits.Get<Traits.ProductionQueue>();
var building = (BuildingInfo)Rules.UnitInfo[ order.TargetString ]; var building = (LegacyBuildingInfo)Rules.UnitInfo[ order.TargetString ];
var producing = queue.CurrentItem(Rules.UnitCategory[order.TargetString]); var producing = queue.CurrentItem(Rules.UnitCategory[order.TargetString]);
if( producing == null || producing.Item != order.TargetString || producing.RemainingTime != 0 ) if( producing == null || producing.Item != order.TargetString || producing.RemainingTime != 0 )
return; return;

View File

@@ -84,7 +84,7 @@ namespace OpenRa.Game
{ {
OreCapacity = Game.world.Actors OreCapacity = Game.world.Actors
.Where(a => a.Owner == this && a.traits.Contains<StoresOre>()) .Where(a => a.Owner == this && a.traits.Contains<StoresOre>())
.Select(a => a.Info as BuildingInfo) .Select(a => a.Info as LegacyBuildingInfo)
.Where(b => b != null) .Where(b => b != null)
.Sum(b => b.Storage); .Sum(b => b.Storage);
} }

View File

@@ -1,10 +1,13 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using OpenRa.Game.GameRules;
using OpenRa.Game.Effects; using OpenRa.Game.Effects;
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class APMineInfo : ITraitInfo
{
public object Create(Actor self) { return new APMine(self); }
}
class APMine : ICrushable, IOccupySpace class APMine : ICrushable, IOccupySpace
{ {
readonly Actor self; readonly Actor self;

View File

@@ -1,11 +1,13 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using OpenRa.Game.GameRules;
using OpenRa.Game.Effects; using OpenRa.Game.Effects;
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class ATMineInfo : ITraitInfo
{
public object Create(Actor self) { return new ATMine(self); }
}
class ATMine : ICrushable, IOccupySpace class ATMine : ICrushable, IOccupySpace
{ {
readonly Actor self; readonly Actor self;

View File

@@ -2,6 +2,11 @@
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class AcceptsOreInfo : ITraitInfo
{
public object Create(Actor self) { return new AcceptsOre(self); }
}
class AcceptsOre class AcceptsOre
{ {
public AcceptsOre(Actor self) public AcceptsOre(Actor self)

View File

@@ -34,7 +34,7 @@ namespace OpenRa.Game.Traits.Activities
if (res != null) if (res != null)
self.traits.Get<Helicopter>().reservation = res.Reserve(self); self.traits.Get<Helicopter>().reservation = res.Reserve(self);
var offset = (dest.Info as BuildingInfo).SpawnOffset; var offset = (dest.Info as LegacyBuildingInfo).SpawnOffset;
var offsetVec = offset != null ? new float2(offset[0], offset[1]) : float2.Zero; var offsetVec = offset != null ? new float2(offset[0], offset[1]) : float2.Zero;
return Util.SequenceActivities( return Util.SequenceActivities(

View File

@@ -8,9 +8,7 @@ namespace OpenRa.Game.Traits
{ {
class AttackBaseInfo : ITraitInfo class AttackBaseInfo : ITraitInfo
{ {
public virtual object Create(Actor self) { return new AttackBase(self); }
public object Create(Actor self) { return new AttackBase(self); }
} }
class AttackBase : IIssueOrder, IResolveOrder, ITick class AttackBase : IIssueOrder, IResolveOrder, ITick

View File

@@ -2,6 +2,11 @@
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class AttackHeliInfo : AttackBaseInfo
{
public override object Create(Actor self) { return new AttackHeli(self); }
}
class AttackHeli : AttackFrontal class AttackHeli : AttackFrontal
{ {
public AttackHeli(Actor self) : base(self, 20) { } public AttackHeli(Actor self) : base(self, 20) { }

View File

@@ -2,6 +2,11 @@
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class AttackPlaneInfo : AttackBaseInfo
{
public override object Create(Actor self) { return new AttackPlane(self); }
}
class AttackPlane : AttackFrontal class AttackPlane : AttackFrontal
{ {
public AttackPlane(Actor self) : base(self, 20) { } public AttackPlane(Actor self) : base(self, 20) { }

View File

@@ -3,11 +3,14 @@ using OpenRa.Game.GameRules;
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class AttackTurretedInfo : AttackBaseInfo { } class AttackTurretedInfo : AttackBaseInfo
{
public override object Create(Actor self) { return new AttackTurreted( self ); }
}
class AttackTurreted : AttackBase, INotifyBuildComplete class AttackTurreted : AttackBase, INotifyBuildComplete
{ {
public AttackTurreted( Actor self ) : base(self) { self.traits.Get<Turreted>(); } public AttackTurreted(Actor self) : base(self) { }
public override void Tick(Actor self) public override void Tick(Actor self)
{ {

View File

@@ -3,10 +3,10 @@ using OpenRa.Game.Traits.Activities;
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class AutoHealInfo : StatelessTraitInfo<AutoHeal> { }
class AutoHeal : ITick class AutoHeal : ITick
{ {
public AutoHeal(Actor self) { }
void AttackTarget(Actor self, Actor target) void AttackTarget(Actor self, Actor target)
{ {
var attack = self.traits.WithInterface<AttackBase>().First(); var attack = self.traits.WithInterface<AttackBase>().First();

View File

@@ -2,15 +2,10 @@
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class AutoTargetInfo : ITraitInfo class AutoTargetInfo : StatelessTraitInfo<AutoTarget> { }
{
public object Create(Actor self) { return new AutoTarget(self); }
}
class AutoTarget : ITick, INotifyDamage class AutoTarget : ITick, INotifyDamage
{ {
public AutoTarget(Actor self) {}
void AttackTarget(Actor self, Actor target) void AttackTarget(Actor self, Actor target)
{ {
var attack = self.traits.WithInterface<AttackBase>().First(); var attack = self.traits.WithInterface<AttackBase>().First();

View File

@@ -3,10 +3,10 @@ using System.Linq;
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class BelowUnitsInfo : StatelessTraitInfo<BelowUnits> { }
class BelowUnits : IRenderModifier class BelowUnits : IRenderModifier
{ {
public BelowUnits(Actor self) { }
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r) public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
{ {
return r.Select(a => a.WithZOffset(-1)); return r.Select(a => a.WithZOffset(-1));

View File

@@ -5,7 +5,7 @@ using System.Text;
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class BuildableInfo : ITraitInfo class BuildableInfo : StatelessTraitInfo<Buildable>
{ {
public readonly int TechLevel = -1; public readonly int TechLevel = -1;
public readonly string Tab = null; public readonly string Tab = null;
@@ -15,12 +15,7 @@ namespace OpenRa.Game.Traits
public readonly string Description = ""; public readonly string Description = "";
public readonly string LongDesc = ""; public readonly string LongDesc = "";
public readonly string Icon = null; public readonly string Icon = null;
public object Create(Actor self) { return new Buildable(self); }
} }
class Buildable class Buildable { }
{
public Buildable( Actor self ) { }
}
} }

View File

@@ -9,10 +9,15 @@ using OpenRa.Game.Graphics;
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class BuildingInfo : ITraitInfo
{
public object Create(Actor self) { return new Building(self); }
}
class Building : INotifyDamage, IResolveOrder, ITick class Building : INotifyDamage, IResolveOrder, ITick
{ {
readonly Actor self; readonly Actor self;
public readonly BuildingInfo unitInfo; public readonly LegacyBuildingInfo unitInfo;
[Sync] [Sync]
bool isRepairing = false; bool isRepairing = false;
[Sync] [Sync]
@@ -24,7 +29,7 @@ namespace OpenRa.Game.Traits
public Building(Actor self) public Building(Actor self)
{ {
this.self = self; this.self = self;
unitInfo = (BuildingInfo)self.Info; unitInfo = (LegacyBuildingInfo)self.Info;
self.CenterLocation = Game.CellSize self.CenterLocation = Game.CellSize
* ((float2)self.Location + .5f * (float2)unitInfo.Dimensions); * ((float2)self.Location + .5f * (float2)unitInfo.Dimensions);
} }

View File

@@ -2,10 +2,10 @@
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class C4DemolitionInfo : StatelessTraitInfo<C4Demolition> { }
class C4Demolition : IIssueOrder, IResolveOrder class C4Demolition : IIssueOrder, IResolveOrder
{ {
public C4Demolition(Actor self) { }
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
{ {
if (mi.Button != MouseButton.Right) return null; if (mi.Button != MouseButton.Right) return null;

View File

@@ -4,6 +4,11 @@ using OpenRa.Game.Orders;
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class ChronoshiftDeployInfo : ITraitInfo
{
public object Create(Actor self) { return new ChronoshiftDeploy(self); }
}
class ChronoshiftDeploy : IIssueOrder, IResolveOrder, ISpeedModifier, ITick, IPips class ChronoshiftDeploy : IIssueOrder, IResolveOrder, ISpeedModifier, ITick, IPips
{ {
// Recharge logic // Recharge logic

View File

@@ -3,6 +3,9 @@ using OpenRa.Game.Graphics;
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
// this is NOT bound through rules (it belongs on the world actor!)
// so no *Info required
class ChronoshiftPaletteEffect : IPaletteModifier, ITick class ChronoshiftPaletteEffect : IPaletteModifier, ITick
{ {
const int chronoEffectLength = 20; const int chronoEffectLength = 20;

View File

@@ -5,8 +5,6 @@ using System.Text;
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class Chronosphere class ChronosphereInfo : StatelessTraitInfo<Chronosphere> { }
{ class Chronosphere { }
public Chronosphere(Actor self) { }
}
} }

View File

@@ -4,6 +4,11 @@ using OpenRa.Game.Graphics;
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class CloakInfo : ITraitInfo
{
public object Create(Actor self) { return new Cloak(self); }
}
class Cloak : IRenderModifier, INotifyAttack, ITick class Cloak : IRenderModifier, INotifyAttack, ITick
{ {
[Sync] [Sync]

View File

@@ -2,17 +2,12 @@
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class EngineerCaptureInfo : ITraitInfo class EngineerCaptureInfo : StatelessTraitInfo<EngineerCapture> { }
{
public object Create(Actor self) { return new EngineerCapture(self); }
}
class EngineerCapture : IIssueOrder, IResolveOrder class EngineerCapture : IIssueOrder, IResolveOrder
{ {
public const int EngineerDamage = 300; // todo: push into rules, as a weapon public const int EngineerDamage = 300; // todo: push into rules, as a weapon
public EngineerCapture(Actor self) { }
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
{ {
if (mi.Button != MouseButton.Right) return null; if (mi.Button != MouseButton.Right) return null;

View File

@@ -2,15 +2,10 @@
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class ExplodesInfo : ITraitInfo class ExplodesInfo : StatelessTraitInfo<Explodes> { }
{
public object Create(Actor self) { return new Explodes(self); }
}
class Explodes : INotifyDamage class Explodes : INotifyDamage
{ {
public Explodes(Actor self) {}
public void Damaged(Actor self, AttackInfo e) public void Damaged(Actor self, AttackInfo e)
{ {
if (self.IsDead) if (self.IsDead)

View File

@@ -2,18 +2,10 @@
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class FakeInfo : ITraitInfo class FakeInfo : StatelessTraitInfo<Fake> { }
{
public object Create(Actor self) { return new Fake(self); }
}
class Fake : ITags class Fake : ITags
{ {
public Fake(Actor self){} public IEnumerable<TagType> GetTags() { yield return TagType.Fake; }
public IEnumerable<TagType> GetTags()
{
yield return TagType.Fake;
}
} }
} }

View File

@@ -2,10 +2,6 @@
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class GpsLaunchSiteInfo : ITraitInfo class GpsLaunchSiteInfo : StatelessTraitInfo<GpsLaunchSite> { }
{ class GpsLaunchSite { }
public object Create(Actor self) { return new GpsLaunchSite(self); }
}
class GpsLaunchSite { public GpsLaunchSite(Actor self) { } }
} }

View File

@@ -5,7 +5,7 @@ namespace OpenRa.Game.Traits
{ {
class HarvesterInfo : ITraitInfo class HarvesterInfo : ITraitInfo
{ {
public object Create(Actor self) { return new Harvester(self); } public object Create(Actor self) { return new Harvester(); }
} }
class Harvester : IIssueOrder, IResolveOrder, IPips class Harvester : IIssueOrder, IResolveOrder, IPips
@@ -18,8 +18,6 @@ namespace OpenRa.Game.Traits
public bool IsFull { get { return oreCarried + gemsCarried == Rules.General.BailCount; } } public bool IsFull { get { return oreCarried + gemsCarried == Rules.General.BailCount; } }
public bool IsEmpty { get { return oreCarried == 0 && gemsCarried == 0; } } public bool IsEmpty { get { return oreCarried == 0 && gemsCarried == 0; } }
public Harvester(Actor self) { }
public void AcceptResource(bool isGem) public void AcceptResource(bool isGem)
{ {
if (isGem) gemsCarried++; if (isGem) gemsCarried++;

View File

@@ -6,6 +6,9 @@ namespace OpenRa.Game.Traits
{ {
class HelicopterInfo : ITraitInfo class HelicopterInfo : ITraitInfo
{ {
public readonly int ROT = 0;
public readonly int Speed = 0;
public object Create(Actor self) { return new Helicopter(self); } public object Create(Actor self) { return new Helicopter(self); }
} }
@@ -60,7 +63,7 @@ namespace OpenRa.Game.Traits
if (res != null) if (res != null)
reservation = res.Reserve(self); reservation = res.Reserve(self);
var offset = (order.TargetActor.Info as BuildingInfo).SpawnOffset; var offset = (order.TargetActor.Info as LegacyBuildingInfo).SpawnOffset;
var offsetVec = offset != null ? new float2(offset[0], offset[1]) : float2.Zero; var offsetVec = offset != null ? new float2(offset[0], offset[1]) : float2.Zero;
self.CancelActivity(); self.CancelActivity();

View File

@@ -2,15 +2,10 @@
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class InvisibleToOthersInfo : ITraitInfo class InvisibleToOthersInfo : StatelessTraitInfo<InvisibleToOthers> { }
{
public object Create(Actor self) { return new InvisibleToOthers(self); }
}
class InvisibleToOthers : IRenderModifier class InvisibleToOthers : IRenderModifier
{ {
public InvisibleToOthers(Actor self) { }
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r) public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
{ {
return Game.LocalPlayer == self.Owner return Game.LocalPlayer == self.Owner

View File

@@ -1,17 +1,6 @@
using System; 
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class IronCurtainInfo : ITraitInfo class IronCurtainInfo : StatelessTraitInfo<IronCurtain> { }
{ class IronCurtain { }
public object Create(Actor self) { return new IronCurtain(self); }
}
class IronCurtain
{
public IronCurtain(Actor self) {}
}
} }

View File

@@ -5,7 +5,7 @@ namespace OpenRa.Game.Traits
{ {
class IronCurtainableInfo : ITraitInfo class IronCurtainableInfo : ITraitInfo
{ {
public object Create(Actor self) { return new IronCurtain(self); } public object Create(Actor self) { return new IronCurtainable(); }
} }
class IronCurtainable : IResolveOrder, IDamageModifier, ITick class IronCurtainable : IResolveOrder, IDamageModifier, ITick
@@ -13,8 +13,6 @@ namespace OpenRa.Game.Traits
[Sync] [Sync]
int RemainingTicks = 0; int RemainingTicks = 0;
public IronCurtainable(Actor self) { }
public void Tick(Actor self) public void Tick(Actor self)
{ {
if (RemainingTicks > 0) if (RemainingTicks > 0)

View File

@@ -24,7 +24,7 @@ namespace OpenRa.Game.Traits
{ {
if( order.OrderString == "DeployMcv" ) if( order.OrderString == "DeployMcv" )
{ {
var factBuildingInfo = (BuildingInfo)Rules.UnitInfo[ "fact" ]; var factBuildingInfo = (LegacyBuildingInfo)Rules.UnitInfo[ "fact" ];
if( Game.CanPlaceBuilding( factBuildingInfo, self.Location - new int2( 1, 1 ), self, false ) ) if( Game.CanPlaceBuilding( factBuildingInfo, self.Location - new int2( 1, 1 ), self, false ) )
{ {
self.CancelActivity(); self.CancelActivity();

View File

@@ -1,13 +1,6 @@
 
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class MineImmuneInfo : ITraitInfo class MineImmuneInfo : StatelessTraitInfo<MineImmune> { }
{ class MineImmune { }
public object Create(Actor self) { return new MineImmune(self); }
}
class MineImmune
{
public MineImmune(Actor self) { }
}
} }

View File

@@ -1,27 +1,19 @@
using System; using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class MinelayerInfo : ITraitInfo class MinelayerInfo : StatelessTraitInfo<Minelayer> { }
{
public object Create(Actor self) { return new Minelayer(self); }
}
class Minelayer : IIssueOrder, IResolveOrder class Minelayer : IIssueOrder, IResolveOrder
{ {
public Minelayer(Actor self) { }
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
{ {
var limitedAmmo = self.traits.GetOrDefault<LimitedAmmo>(); var limitedAmmo = self.traits.GetOrDefault<LimitedAmmo>();
if (limitedAmmo != null && !limitedAmmo.HasAmmo()) if (limitedAmmo != null && !limitedAmmo.HasAmmo())
return null; return null;
// Ensure that the cell is empty except for the minelayer // Ensure that the cell is empty except for the minelayer
if (Game.UnitInfluence.GetUnitsAt( xy ).Any(a => a != self)) if (Game.UnitInfluence.GetUnitsAt(xy).Any(a => a != self))
return null; return null;
if (mi.Button == MouseButton.Right && underCursor == self) if (mi.Button == MouseButton.Right && underCursor == self)

View File

@@ -5,6 +5,9 @@ namespace OpenRa.Game.Traits
{ {
class PlaneInfo : ITraitInfo class PlaneInfo : ITraitInfo
{ {
public readonly int ROT = 0;
public readonly int Speed = 0;
public object Create(Actor self) { return new Plane(self); } public object Create(Actor self) { return new Plane(self); }
} }

View File

@@ -43,7 +43,7 @@ namespace OpenRa.Game.Traits
newUnit.QueueActivity( new Activities.Move( rp.rallyPoint, 1 ) ); newUnit.QueueActivity( new Activities.Move( rp.rallyPoint, 1 ) );
} }
var bi = self.Info as BuildingInfo; var bi = self.Info as LegacyBuildingInfo;
if (bi != null && bi.SpawnOffset != null) if (bi != null && bi.SpawnOffset != null)
newUnit.CenterLocation = self.CenterLocation newUnit.CenterLocation = self.CenterLocation
+ new float2(bi.SpawnOffset[0], bi.SpawnOffset[1]); + new float2(bi.SpawnOffset[0], bi.SpawnOffset[1]);
@@ -83,12 +83,12 @@ namespace OpenRa.Game.Traits
} }
// Cancel existing primaries // Cancel existing primaries
foreach (var p in (self.Info as BuildingInfo).Produces) foreach (var p in (self.Info as LegacyBuildingInfo).Produces)
{ {
foreach (var b in Game.world.Actors.Where(x => x.traits.Contains<Production>() foreach (var b in Game.world.Actors.Where(x => x.traits.Contains<Production>()
&& x.Owner == self.Owner && x.Owner == self.Owner
&& x.traits.Get<Production>().IsPrimary == true && x.traits.Get<Production>().IsPrimary == true
&& (x.Info as BuildingInfo).Produces.Contains(p))) && (x.Info as LegacyBuildingInfo).Produces.Contains(p)))
{ {
b.traits.Get<Production>().SetPrimaryProducer(b, false); b.traits.Get<Production>().SetPrimaryProducer(b, false);
} }

View File

@@ -14,7 +14,7 @@ namespace OpenRa.Game.Traits
public void OnSteal(Actor self, Actor thief) public void OnSteal(Actor self, Actor thief)
{ {
// Steal half the ore the building holds // Steal half the ore the building holds
var toSteal = (self.Info as BuildingInfo).Storage/2; var toSteal = (self.Info as LegacyBuildingInfo).Storage/2;
self.Owner.TakeCash(toSteal); self.Owner.TakeCash(toSteal);
thief.Owner.GiveCash(toSteal); thief.Owner.GiveCash(toSteal);

View File

@@ -2,10 +2,8 @@
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class WaterPaletteRotationInfo : ITraitInfo // this is NOT bound through rules (it belongs on the world actor!)
{ // so no *Info required
public object Create(Actor self) { return new WaterPaletteRotation(self); }
}
class WaterPaletteRotation : ITick, IPaletteModifier class WaterPaletteRotation : ITick, IPaletteModifier
{ {

View File

@@ -42,7 +42,7 @@ namespace OpenRa.Game
spriteRenderer.DrawSprite(unitDebug, Game.CellSize * new float2(i, j), 0); spriteRenderer.DrawSprite(unitDebug, Game.CellSize * new float2(i, j), 0);
} }
public void DrawBuildingGrid( BuildingInfo bi ) public void DrawBuildingGrid( LegacyBuildingInfo bi )
{ {
var position = Game.controller.MousePosition.ToInt2(); var position = Game.controller.MousePosition.ToInt2();
var isCloseEnough = Game.IsCloseEnoughToBase(Game.LocalPlayer, bi, position); var isCloseEnough = Game.IsCloseEnoughToBase(Game.LocalPlayer, bi, position);