This commit is contained in:
Chris Forbes
2010-01-10 13:06:39 +13:00
parent 68fcd29816
commit 409a48b22a
15 changed files with 61 additions and 24 deletions

View File

@@ -12,7 +12,7 @@ namespace OpenRa.Game
{
[Sync]
public readonly TypeDictionary traits = new TypeDictionary();
public readonly UnitInfo Info;
public readonly LegacyUnitInfo Info;
public readonly uint ActorID;
[Sync]
@@ -36,7 +36,7 @@ namespace OpenRa.Game
public Actor( ActorInfo info, int2 location, Player owner )
{
ActorID = Game.world.NextAID();
Info = (UnitInfo)info; // temporary
Info = (LegacyUnitInfo)info; // temporary
Location = location;
CenterLocation = Traits.Util.CenterOfCell(Location);
Owner = owner;

View File

@@ -13,7 +13,7 @@ namespace OpenRa.Game
public static IniFile AllRules;
public static Dictionary<string, List<string>> Categories = new Dictionary<string, List<string>>();
public static Dictionary<string, string> UnitCategory;
public static InfoLoader<UnitInfo> UnitInfo;
public static InfoLoader<LegacyUnitInfo> UnitInfo;
public static InfoLoader<WeaponInfo> WeaponInfo;
public static InfoLoader<WarheadInfo> WarheadInfo;
public static InfoLoader<ProjectileInfo> ProjectileInfo;
@@ -64,13 +64,13 @@ namespace OpenRa.Game
"Plane");
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<UnitInfo>(
Pair.New<string, Func<string, UnitInfo>>("Building", s => new BuildingInfo(s)),
Pair.New<string, Func<string, UnitInfo>>("Defense", s => new BuildingInfo(s)),
Pair.New<string, Func<string, UnitInfo>>("Infantry", s => new InfantryInfo(s)),
Pair.New<string, Func<string, UnitInfo>>("Vehicle", s => new VehicleInfo(s)),
Pair.New<string, Func<string, UnitInfo>>("Ship", s => new VehicleInfo(s)),
Pair.New<string, Func<string, UnitInfo>>("Plane", s => new VehicleInfo(s)));
UnitInfo = new InfoLoader<LegacyUnitInfo>(
Pair.New<string, Func<string, LegacyUnitInfo>>("Building", s => new BuildingInfo(s)),
Pair.New<string, Func<string, LegacyUnitInfo>>("Defense", s => new BuildingInfo(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>>("Ship", s => new VehicleInfo(s)),
Pair.New<string, Func<string, LegacyUnitInfo>>("Plane", s => new VehicleInfo(s)));
LoadCategories(
"Weapon",

View File

@@ -6,7 +6,7 @@ namespace OpenRa.Game.GameRules
{
class TechTree
{
readonly Cache<string, List<UnitInfo>> producesIndex = new Cache<string, List<UnitInfo>>( x => new List<UnitInfo>() );
readonly Cache<string, List<LegacyUnitInfo>> producesIndex = new Cache<string, List<LegacyUnitInfo>>( x => new List<LegacyUnitInfo>() );
public TechTree()
{
@@ -26,7 +26,7 @@ namespace OpenRa.Game.GameRules
return ret;
}
public bool CanBuild( UnitInfo unit, Player player, Cache<string, List<Actor>> playerBuildings )
public bool CanBuild( LegacyUnitInfo unit, Player player, Cache<string, List<Actor>> playerBuildings )
{
if( unit.TechLevel == -1 )
return false;
@@ -59,7 +59,7 @@ namespace OpenRa.Game.GameRules
.Where(x => Rules.UnitInfo[x].Owner.Contains(player.Race)); /* todo: fix for dual-race scenarios (captured buildings) */
}
public IEnumerable<UnitInfo> UnitBuiltAt( UnitInfo info )
public IEnumerable<LegacyUnitInfo> UnitBuiltAt( LegacyUnitInfo info )
{
if( info.BuiltAt.Length != 0 )
return info.BuiltAt.Select( x => Rules.UnitInfo[ x.ToLowerInvariant() ] );

View File

@@ -11,7 +11,7 @@ namespace OpenRa.Game.GameRules
concrete = 4,
}
public class UnitInfo : ActorInfo
public class LegacyUnitInfo : ActorInfo
{
public readonly string Name;
@@ -64,10 +64,10 @@ namespace OpenRa.Game.GameRules
public readonly int[] PrimaryLocalOffset = { };
public readonly int[] SecondaryLocalOffset = { };
public UnitInfo(string name) { Name = name; }
public LegacyUnitInfo(string name) { Name = name; }
}
public class LegacyMobileInfo : UnitInfo
public class LegacyMobileInfo : LegacyUnitInfo
{
public readonly int Speed = 0;
public readonly bool NoMovingFire = false;
@@ -94,7 +94,7 @@ namespace OpenRa.Game.GameRules
public VehicleInfo(string name) : base(name) { }
}
public class BuildingInfo : UnitInfo
public class BuildingInfo : LegacyUnitInfo
{
public readonly int2 Dimensions = new int2(1, 1);
public readonly string Footprint = "x";

View File

@@ -33,7 +33,7 @@ namespace OpenRa.Game.Orders
&& a.traits.WithInterface<Chronoshiftable>().Any()
&& a.Info.Selectable).FirstOrDefault();
var unit = underCursor != null ? underCursor.Info as UnitInfo : null;
var unit = underCursor != null ? underCursor.Info as LegacyUnitInfo : null;
if (unit != null)
yield return new Order("ChronosphereSelect", underCursor, null, int2.Zero, power.Name);

View File

@@ -33,7 +33,7 @@ namespace OpenRa.Game.Orders
&& a.traits.Contains<IronCurtainable>()
&& a.Info.Selectable).FirstOrDefault();
var unit = underCursor != null ? underCursor.Info as UnitInfo : null;
var unit = underCursor != null ? underCursor.Info as LegacyUnitInfo : null;
if (unit != null)
yield return new Order("IronCurtain", underCursor, null, int2.Zero, power.Name);

View File

@@ -6,6 +6,13 @@ using OpenRa.Game.Effects;
namespace OpenRa.Game.Traits
{
class AttackBaseInfo : ITraitInfo
{
public object Create(Actor self) { return new AttackBase(self); }
}
class AttackBase : IIssueOrder, IResolveOrder, ITick
{
[Sync] public Actor target;

View File

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

View File

@@ -5,6 +5,11 @@ using System.Linq;
namespace OpenRa.Game.Traits
{
class ChronoshiftableInfo : ITraitInfo
{
public object Create(Actor self) { return new Chronoshiftable(self); }
}
class Chronoshiftable : IResolveOrder, ISpeedModifier, ITick
{
// Return-to-sender logic

View File

@@ -11,7 +11,7 @@ namespace OpenRa.Game.Traits
public Production( Actor self ) { }
public virtual int2? CreationLocation( Actor self, UnitInfo producee )
public virtual int2? CreationLocation( Actor self, LegacyUnitInfo producee )
{
return ( 1 / 24f * self.CenterLocation ).ToInt2();
}
@@ -21,7 +21,7 @@ namespace OpenRa.Game.Traits
return newUnit.Info.InitialFacing;
}
public bool Produce( Actor self, UnitInfo producee )
public bool Produce( Actor self, LegacyUnitInfo producee )
{
var location = CreationLocation( self, producee );
if( location == null || Game.UnitInfluence.GetUnitsAt( location.Value ).Any() )

View File

@@ -24,7 +24,7 @@ namespace OpenRa.Game.Traits
return null;
}
public override int2? CreationLocation(Actor self, UnitInfo producee)
public override int2? CreationLocation(Actor self, LegacyUnitInfo producee)
{
return FindAdjacentTile(self, producee.WaterBound ?
UnitMovementType.Float : UnitMovementType.Wheel); /* hackety hack */

View File

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

View File

@@ -6,6 +6,11 @@ using OpenRa.Game.Traits.Activities;
namespace OpenRa.Game.Traits
{
class RepairableInfo : ITraitInfo
{
public object Create(Actor self) { return new Repairable(self); }
}
class Repairable : IIssueOrder, IResolveOrder
{
IDisposable reservation;

View File

@@ -24,7 +24,7 @@ namespace OpenRa.Game.Traits
interface IProducer
{
bool Produce( Actor self, UnitInfo producee );
bool Produce( Actor self, LegacyUnitInfo producee );
void SetPrimaryProducer(Actor self, bool isPrimary);
}
interface IOccupySpace { IEnumerable<int2> OccupiedCells(); }

View File

@@ -1,6 +1,16 @@

using OpenRa.Game.GameRules;
namespace OpenRa.Game.Traits
{
class UnitInfo : ITraitInfo
{
public readonly int HP = 0;
public readonly ArmorType Armor = ArmorType.none;
public readonly bool Crewed = false; // replace with trait?
public object Create(Actor self) { return new Unit(self); }
}
class Unit : INotifyDamage
{
[Sync]