renamed Info to LegacyInfo, marked Obsolete. added NewUnitInfo ref as Info.

This commit is contained in:
Chris Forbes
2010-01-10 18:28:24 +13:00
parent 74a2ed9624
commit 99a61ca8d9
52 changed files with 142 additions and 137 deletions

View File

@@ -12,7 +12,10 @@ namespace OpenRa.Game
{
[Sync]
public readonly TypeDictionary traits = new TypeDictionary();
public readonly LegacyUnitInfo Info;
[Obsolete]
public readonly LegacyUnitInfo LegacyInfo;
public readonly NewUnitInfo Info;
public readonly uint ActorID;
[Sync]
@@ -26,19 +29,21 @@ namespace OpenRa.Game
public Actor( ActorInfo info, int2 location, Player owner )
{
ActorID = Game.world.NextAID();
Info = (LegacyUnitInfo)info; // temporary
LegacyInfo = (LegacyUnitInfo)info; // temporary
Location = location;
CenterLocation = Traits.Util.CenterOfCell(Location);
Owner = owner;
if (Info == null) return;
if (LegacyInfo == null) return;
Health = Info.Strength; /* todo: fix walls, etc so this is always true! */
Health = LegacyInfo.Strength; /* todo: fix walls, etc so this is always true! */
if( Info.Traits == null )
throw new InvalidOperationException( "No Actor traits for {0}; add Traits= to units.ini for appropriate unit".F(Info.Name) );
if( LegacyInfo.Traits == null )
throw new InvalidOperationException( "No Actor traits for {0}; add Traits= to units.ini for appropriate unit".F(LegacyInfo.Name) );
foreach (var trait in Rules.NewUnitInfo[Info.Name.ToLower()].Traits.WithInterface<ITraitInfo>())
Info = Rules.NewUnitInfo[LegacyInfo.Name.ToLowerInvariant()];
foreach (var trait in Info.Traits.WithInterface<ITraitInfo>())
traits.Add(trait.Create(this));
}
@@ -65,8 +70,8 @@ namespace OpenRa.Game
{
get
{
if (Info != null && Info.SelectionSize != null)
return new float2(Info.SelectionSize[0], Info.SelectionSize[1]);
if (LegacyInfo != null && LegacyInfo.SelectionSize != null)
return new float2(LegacyInfo.SelectionSize[0], LegacyInfo.SelectionSize[1]);
var firstSprite = Render().FirstOrDefault();
if (firstSprite.Sprite == null) return float2.Zero;
@@ -92,7 +97,7 @@ namespace OpenRa.Game
var loc = mi.Location + Game.viewport.Location;
var underCursor = Game.FindUnits(loc, loc).FirstOrDefault();
if (underCursor != null && !underCursor.Info.Selectable)
if (underCursor != null && !underCursor.LegacyInfo.Selectable)
underCursor = null;
return traits.WithInterface<IIssueOrder>()
@@ -104,8 +109,8 @@ namespace OpenRa.Game
{
var size = SelectedSize;
var loc = CenterLocation - 0.5f * size;
if (Info != null && Info.SelectionSize != null && Info.SelectionSize.Length > 2)
loc += new float2(Info.SelectionSize[2], Info.SelectionSize[3]);
if (LegacyInfo != null && LegacyInfo.SelectionSize != null && LegacyInfo.SelectionSize.Length > 2)
loc += new float2(LegacyInfo.SelectionSize[2], LegacyInfo.SelectionSize[3]);
if (useAltitude)
{
@@ -122,7 +127,7 @@ namespace OpenRa.Game
public DamageState GetDamageState()
{
if (Health <= 0) return DamageState.Dead;
var halfStrength = Info.Strength * Rules.General.ConditionYellow;
var halfStrength = LegacyInfo.Strength * Rules.General.ConditionYellow;
return Health < halfStrength ? DamageState.Half : DamageState.Normal;
}
@@ -145,8 +150,8 @@ namespace OpenRa.Game
Game.world.AddFrameEndTask(w => w.Remove(this));
}
if (Health > Info.Strength)
Health = Info.Strength;
if (Health > LegacyInfo.Strength)
Health = LegacyInfo.Strength;
var newState = GetDamageState();

View File

@@ -49,7 +49,7 @@ namespace OpenRa.Game
var distance = (target.CenterLocation - loc).Length*1/24f;
var rawDamage = weapon.Damage * (float)Math.Exp(-distance / warhead.Spread);
var multiplier = warhead.EffectivenessAgainst(target.Info.Armor);
var multiplier = warhead.EffectivenessAgainst(target.LegacyInfo.Armor);
return rawDamage * multiplier;
}
@@ -59,7 +59,7 @@ namespace OpenRa.Game
var warhead = Rules.WarheadInfo[weapon.Warhead];
var unit = target.traits.GetOrDefault<Unit>();
if (warhead.EffectivenessAgainst(target.Info.Armor) <= 0)
if (warhead.EffectivenessAgainst(target.LegacyInfo.Armor) <= 0)
return false;
if (target.traits.Contains<Submarine>())
@@ -68,7 +68,7 @@ namespace OpenRa.Game
if (unit != null && unit.Altitude > 0)
return projectile.AA;
if (projectile.UnderWater && !target.Info.WaterBound)
if (projectile.UnderWater && !target.LegacyInfo.WaterBound)
return false;
return projectile.AG;
@@ -76,10 +76,10 @@ namespace OpenRa.Game
public static bool HasAnyValidWeapons(Actor self, Actor target)
{
if (self.Info.Primary != null &&
WeaponValidForTarget(Rules.WeaponInfo[self.Info.Primary], target)) return true;
if (self.Info.Secondary != null &&
WeaponValidForTarget(Rules.WeaponInfo[self.Info.Secondary], target)) return true;
if (self.LegacyInfo.Primary != null &&
WeaponValidForTarget(Rules.WeaponInfo[self.LegacyInfo.Primary], target)) return true;
if (self.LegacyInfo.Secondary != null &&
WeaponValidForTarget(Rules.WeaponInfo[self.LegacyInfo.Secondary], target)) return true;
return false;
}

View File

@@ -15,7 +15,7 @@ namespace OpenRa.Game.Effects
public Corpse(Actor fromActor, int death)
{
anim = new Animation(fromActor.Info.Image ?? fromActor.Info.Name);
anim = new Animation(fromActor.LegacyInfo.Image ?? fromActor.LegacyInfo.Name);
anim.PlayThen("die{0}".F(death + 1),
() => Game.world.AddFrameEndTask(w => w.Remove(this)));

View File

@@ -61,7 +61,7 @@ namespace OpenRa.Game
world = new World();
Game.world.ActorAdded += a =>
{
if (a.Owner != null && a.Info != null)
if (a.Owner != null && a.LegacyInfo != null)
a.Owner.Shroud.Explore(a);
};
@@ -310,8 +310,8 @@ namespace OpenRa.Game
public static IEnumerable<Actor> SelectActorsInBox(float2 a, float2 b)
{
return FindUnits(a, b)
.Where( x => x.Info.Selectable )
.GroupBy(x => (x.Owner == LocalPlayer) ? x.Info.SelectionPriority : 0)
.Where( x => x.LegacyInfo.Selectable )
.GroupBy(x => (x.Owner == LocalPlayer) ? x.LegacyInfo.SelectionPriority : 0)
.OrderByDescending(g => g.Key)
.Select( g => g.AsEnumerable() )
.DefaultIfEmpty( new Actor[] {} )
@@ -338,7 +338,7 @@ namespace OpenRa.Game
heuristic = loc =>
{
var b = Game.BuildingInfluence.GetBuildingAt(loc);
if (b != null && b.Owner == p && (b.Info as LegacyBuildingInfo).BaseNormal) return 0;
if (b != null && b.Owner == p && (b.LegacyInfo as LegacyBuildingInfo).BaseNormal) return 0;
if ((loc - position).Length > maxDistance)
return float.PositiveInfinity; /* not quite right */
return 1;

View File

@@ -21,8 +21,8 @@ namespace OpenRa.Game.GameRules
public Cache<string, List<Actor>> GatherBuildings( Player player )
{
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 LegacyBuildingInfo ) )
ret[ b.Info.Name ].Add( b );
foreach( var b in Game.world.Actors.Where( x => x.Owner == player && x.LegacyInfo is LegacyBuildingInfo ) )
ret[ b.LegacyInfo.Name ].Add( b );
return ret;
}

View File

@@ -97,7 +97,7 @@ namespace OpenRa.Game.Graphics
public void GoToStartLocation()
{
Center(Game.world.Actors.Where(a => a.Info != null && a.Owner == Game.LocalPlayer));
Center(Game.world.Actors.Where(a => a.LegacyInfo != null && a.Owner == Game.LocalPlayer));
}
}
}

View File

@@ -169,7 +169,7 @@ namespace OpenRa.Game.Graphics
lineRenderer.DrawLine(xy + new float2(0, -2), xy + new float2(0, -4), c, c);
lineRenderer.DrawLine(Xy + new float2(0, -2), Xy + new float2(0, -4), c, c);
var healthAmount = (float)selectedUnit.Health / selectedUnit.Info.Strength;
var healthAmount = (float)selectedUnit.Health / selectedUnit.LegacyInfo.Strength;
var healthColor = (healthAmount < Rules.General.ConditionRed) ? Color.Red
: (healthAmount < Rules.General.ConditionYellow) ? Color.Yellow
: Color.LimeGreen;

View File

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

View File

@@ -31,9 +31,9 @@ namespace OpenRa.Game.Orders
var underCursor = Game.FindUnits(loc, loc)
.Where(a => a.Owner == Game.LocalPlayer
&& a.traits.Contains<IronCurtainable>()
&& a.Info.Selectable).FirstOrDefault();
&& a.LegacyInfo.Selectable).FirstOrDefault();
var unit = underCursor != null ? underCursor.Info as LegacyUnitInfo : null;
var unit = underCursor != null ? underCursor.LegacyInfo as LegacyUnitInfo : null;
if (unit != null)
yield return new Order("IronCurtain", underCursor, null, int2.Zero, power.Name);

View File

@@ -25,9 +25,9 @@ namespace OpenRa.Game.Orders
var underCursor = Game.FindUnits(loc, loc)
.Where(a => a.Owner == Game.LocalPlayer
&& a.traits.Contains<Building>()
&& a.Info.Selectable).FirstOrDefault();
&& a.LegacyInfo.Selectable).FirstOrDefault();
var building = underCursor != null ? underCursor.Info as LegacyBuildingInfo : null;
var building = underCursor != null ? underCursor.LegacyInfo as LegacyBuildingInfo : null;
if (building != null)
yield return new Order("PowerDown", underCursor, null, int2.Zero, null);

View File

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

View File

@@ -25,9 +25,9 @@ namespace OpenRa.Game.Orders
var underCursor = Game.FindUnits(loc, loc)
.Where(a => a.Owner == Game.LocalPlayer
&& a.traits.Contains<Building>()
&& a.Info.Selectable).FirstOrDefault();
&& a.LegacyInfo.Selectable).FirstOrDefault();
var building = underCursor != null ? underCursor.Info as LegacyBuildingInfo : null;
var building = underCursor != null ? underCursor.LegacyInfo as LegacyBuildingInfo : null;
if (building != null && !building.Unsellable)
yield return new Order("Sell", underCursor, null, int2.Zero, null);

View File

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

View File

@@ -32,7 +32,7 @@ namespace OpenRa.Game
public void Explore(Actor a)
{
foreach (var t in Game.FindTilesInCircle((1f / Game.CellSize * a.CenterLocation).ToInt2(), a.Info.Sight))
foreach (var t in Game.FindTilesInCircle((1f / Game.CellSize * a.CenterLocation).ToInt2(), a.LegacyInfo.Sight))
explored[t.X, t.Y] = true;
dirty = true;

View File

@@ -92,7 +92,7 @@ namespace OpenRa.Game
{
if (voicedUnit == null) return;
var mi = voicedUnit.Info as LegacyMobileInfo;
var mi = voicedUnit.LegacyInfo as LegacyMobileInfo;
if (mi == null) return;
var vi = Rules.VoiceInfo[mi.Voice];

View File

@@ -19,7 +19,7 @@ namespace OpenRa.Game.Traits.Activities
if (target.Owner == self.Owner)
{
if (target.Health == target.Info.Strength)
if (target.Health == target.LegacyInfo.Strength)
return NextActivity;
target.InflictDamage(self, -EngineerCapture.EngineerDamage, Rules.WarheadInfo["Super"]);
}

View File

@@ -31,7 +31,7 @@ namespace OpenRa.Game.Traits.Activities
var desiredFacing = Util.GetFacing(d, unit.Facing);
if (unit.Altitude == CruiseAltitude)
Util.TickFacing(ref unit.Facing, desiredFacing, self.Info.ROT);
Util.TickFacing(ref unit.Facing, desiredFacing, self.LegacyInfo.ROT);
var speed = .2f * Util.GetEffectiveSpeed(self);
var angle = unit.Facing / 128f * Math.PI;

View File

@@ -30,11 +30,11 @@ namespace OpenRa.Game.Traits.Activities
return this;
}
var range = Rules.WeaponInfo[ self.Info.Primary ].Range - 1;
var range = Rules.WeaponInfo[ self.LegacyInfo.Primary ].Range - 1;
var dist = target.CenterLocation - self.CenterLocation;
var desiredFacing = Util.GetFacing(dist, unit.Facing);
Util.TickFacing(ref unit.Facing, desiredFacing, self.Info.ROT);
Util.TickFacing(ref unit.Facing, desiredFacing, self.LegacyInfo.ROT);
if (!float2.WithinEpsilon(float2.Zero, dist, range * Game.CellSize))
{

View File

@@ -39,7 +39,7 @@ namespace OpenRa.Game.Traits.Activities
}
var desiredFacing = Util.GetFacing(dist, unit.Facing);
Util.TickFacing(ref unit.Facing, desiredFacing, self.Info.ROT);
Util.TickFacing(ref unit.Facing, desiredFacing, self.LegacyInfo.ROT);
var rawSpeed = .2f * Util.GetEffectiveSpeed(self);
self.CenterLocation += (rawSpeed / dist.Length) * dist;

View File

@@ -14,7 +14,7 @@ namespace OpenRa.Game.Traits.Activities
static Actor ChooseHelipad(Actor self)
{
return Game.world.Actors.FirstOrDefault(
a => a.Info == Rules.UnitInfo["HPAD"] &&
a => a.LegacyInfo == Rules.UnitInfo["HPAD"] &&
a.Owner == self.Owner &&
!Reservable.IsReserved(a));
}
@@ -26,7 +26,7 @@ namespace OpenRa.Game.Traits.Activities
if (dest == null)
return Util.SequenceActivities(
new Turn(self.Info.InitialFacing),
new Turn(self.LegacyInfo.InitialFacing),
new HeliLand(true),
NextActivity);
@@ -34,12 +34,12 @@ namespace OpenRa.Game.Traits.Activities
if (res != null)
self.traits.Get<Helicopter>().reservation = res.Reserve(self);
var offset = (dest.Info as LegacyBuildingInfo).SpawnOffset;
var offset = (dest.LegacyInfo as LegacyBuildingInfo).SpawnOffset;
var offsetVec = offset != null ? new float2(offset[0], offset[1]) : float2.Zero;
return Util.SequenceActivities(
new HeliFly(dest.CenterLocation + offsetVec),
new Turn(self.Info.InitialFacing),
new Turn(self.LegacyInfo.InitialFacing),
new HeliLand(false),
new Rearm(),
NextActivity);

View File

@@ -28,7 +28,7 @@ namespace OpenRa.Game.Traits.Activities
--unit.Altitude;
var desiredFacing = Util.GetFacing(d, unit.Facing);
Util.TickFacing(ref unit.Facing, desiredFacing, self.Info.ROT);
Util.TickFacing(ref unit.Facing, desiredFacing, self.LegacyInfo.ROT);
var speed = .2f * Util.GetEffectiveSpeed(self);
var angle = unit.Facing / 128f * Math.PI;

View File

@@ -16,8 +16,8 @@ namespace OpenRa.Game.Traits.Activities
if (isCanceled) return NextActivity;
if (remainingTicks == 0)
{
var costPerHp = (Rules.General.URepairPercent * self.Info.Cost) / self.Info.Strength;
var hpToRepair = Math.Min(Rules.General.URepairStep, self.Info.Strength - self.Health);
var costPerHp = (Rules.General.URepairPercent * self.LegacyInfo.Cost) / self.LegacyInfo.Strength;
var hpToRepair = Math.Min(Rules.General.URepairStep, self.LegacyInfo.Strength - self.Health);
var cost = (int)Math.Ceiling(costPerHp * hpToRepair);
if (!self.Owner.TakeCash(cost))
{
@@ -26,7 +26,7 @@ namespace OpenRa.Game.Traits.Activities
}
self.InflictDamage(self, -hpToRepair, Rules.WarheadInfo["Super"]);
if (self.Health == self.Info.Strength)
if (self.Health == self.LegacyInfo.Strength)
return NextActivity;
var hostBuilding = Game.FindUnits(self.CenterLocation, self.CenterLocation)

View File

@@ -19,7 +19,7 @@ namespace OpenRa.Game.Traits.Activities
Actor ChooseAirfield(Actor self)
{
var airfield = Game.world.Actors
.Where(a => a.Info == Rules.UnitInfo["AFLD"] /* todo: generalize this */
.Where(a => a.LegacyInfo == Rules.UnitInfo["AFLD"] /* todo: generalize this */
&& a.Owner == self.Owner
&& !Reservable.IsReserved(a))
.FirstOrDefault();
@@ -41,7 +41,7 @@ namespace OpenRa.Game.Traits.Activities
var unit = self.traits.Get<Unit>();
var speed = .2f * Util.GetEffectiveSpeed(self);
var approachStart = landPos - new float2(unit.Altitude * speed, 0);
var turnRadius = (128f / self.Info.ROT) * speed / (float)Math.PI;
var turnRadius = (128f / self.LegacyInfo.ROT) * speed / (float)Math.PI;
/* work out the center points */
var fwd = -float2.FromAngle(unit.Facing / 128f * (float)Math.PI);

View File

@@ -14,7 +14,7 @@ namespace OpenRa.Game.Traits.Activities
void DoSell(Actor self)
{
var refund = Rules.General.RefundPercent
* self.Health * self.Info.Cost / self.Info.Strength;
* self.Health * self.LegacyInfo.Cost / self.LegacyInfo.Strength;
self.Owner.GiveCash((int)refund);
self.Health = 0;

View File

@@ -19,7 +19,7 @@ namespace OpenRa.Game.Traits.Activities
if( desiredFacing == unit.Facing )
return NextActivity;
Util.TickFacing( ref unit.Facing, desiredFacing, self.Info.ROT );
Util.TickFacing( ref unit.Facing, desiredFacing, self.LegacyInfo.ROT );
return this;
}

View File

@@ -33,8 +33,8 @@ namespace OpenRa.Game.Traits.Activities
// if we're a thing that can turn, turn to the
// right facing for the unload animation
var unit = self.traits.GetOrDefault<Unit>();
if (unit != null && unit.Facing != self.Info.UnloadFacing)
return new Turn(self.Info.UnloadFacing) { NextActivity = this };
if (unit != null && unit.Facing != self.LegacyInfo.UnloadFacing)
return new Turn(self.LegacyInfo.UnloadFacing) { NextActivity = this };
// todo: handle the BS of open/close sequences, which are inconsistent,
// for reasons that probably make good sense to the westwood guys.

View File

@@ -28,8 +28,8 @@ namespace OpenRa.Game.Traits
public AttackBase(Actor self)
{
var primaryWeapon = self.Info.Primary != null ? Rules.WeaponInfo[self.Info.Primary] : null;
var secondaryWeapon = self.Info.Secondary != null ? Rules.WeaponInfo[self.Info.Secondary] : null;
var primaryWeapon = self.LegacyInfo.Primary != null ? Rules.WeaponInfo[self.LegacyInfo.Primary] : null;
var secondaryWeapon = self.LegacyInfo.Secondary != null ? Rules.WeaponInfo[self.LegacyInfo.Secondary] : null;
primaryBurst = primaryWeapon != null ? primaryWeapon.Burst : 1;
secondaryBurst = secondaryWeapon != null ? secondaryWeapon.Burst : 1;
@@ -79,18 +79,18 @@ namespace OpenRa.Game.Traits
{
var unit = self.traits.GetOrDefault<Unit>();
if (self.Info.Primary != null && CheckFire(self, unit, self.Info.Primary, ref primaryFireDelay,
self.Info.PrimaryOffset, ref primaryBurst, self.Info.PrimaryLocalOffset))
if (self.LegacyInfo.Primary != null && CheckFire(self, unit, self.LegacyInfo.Primary, ref primaryFireDelay,
self.LegacyInfo.PrimaryOffset, ref primaryBurst, self.LegacyInfo.PrimaryLocalOffset))
{
secondaryFireDelay = Math.Max(4, secondaryFireDelay);
primaryRecoil = 1;
return;
}
if (self.Info.Secondary != null && CheckFire(self, unit, self.Info.Secondary, ref secondaryFireDelay,
self.Info.SecondaryOffset ?? self.Info.PrimaryOffset, ref secondaryBurst, self.Info.SecondaryLocalOffset))
if (self.LegacyInfo.Secondary != null && CheckFire(self, unit, self.LegacyInfo.Secondary, ref secondaryFireDelay,
self.LegacyInfo.SecondaryOffset ?? self.LegacyInfo.PrimaryOffset, ref secondaryBurst, self.LegacyInfo.SecondaryLocalOffset))
{
if (self.Info.SecondaryOffset != null) secondaryRecoil = 1;
if (self.LegacyInfo.SecondaryOffset != null) secondaryRecoil = 1;
else primaryRecoil = 1;
return;
}
@@ -132,7 +132,7 @@ namespace OpenRa.Game.Traits
var thisTarget = target; // closure.
var destUnit = thisTarget.traits.GetOrDefault<Unit>();
ScheduleDelayedAction(self.Info.FireDelay, () =>
ScheduleDelayedAction(self.LegacyInfo.FireDelay, () =>
{
var srcAltitude = unit != null ? unit.Altitude : 0;
var destAltitude = destUnit != null ? destUnit.Altitude : 0;
@@ -166,7 +166,7 @@ namespace OpenRa.Game.Traits
{
if (mi.Button == MouseButton.Left || underCursor == null) return null;
if (self == underCursor) return null;
var isHeal = Rules.WeaponInfo[self.Info.Primary].Damage < 0;
var isHeal = Rules.WeaponInfo[self.LegacyInfo.Primary].Damage < 0;
if (((underCursor.Owner == self.Owner) ^ isHeal)
&& !mi.Modifiers.HasModifier( Modifiers.Ctrl )) return null;
if (!Combat.HasAnyValidWeapons(self, underCursor)) return null;
@@ -191,7 +191,7 @@ namespace OpenRa.Game.Traits
{
const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */
/* todo: choose the appropriate weapon, when only one works against this target */
var weapon = order.Subject.Info.Primary ?? order.Subject.Info.Secondary;
var weapon = order.Subject.LegacyInfo.Primary ?? order.Subject.LegacyInfo.Secondary;
self.QueueActivity(new Activities.Attack(order.TargetActor,
Math.Max(0, (int)Rules.WeaponInfo[weapon].Range - RangeTolerance)));

View File

@@ -36,7 +36,7 @@ namespace OpenRa.Game.Traits
const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */
/* todo: choose the appropriate weapon, when only one works against this target */
var weapon = order.Subject.Info.Primary ?? order.Subject.Info.Secondary;
var weapon = order.Subject.LegacyInfo.Primary ?? order.Subject.LegacyInfo.Secondary;
if (self.traits.Contains<Mobile>())
self.QueueActivity( new Traits.Activities.Follow( order.TargetActor,

View File

@@ -19,7 +19,7 @@ namespace OpenRa.Game.Traits
float GetMaximumRange(Actor self)
{
return new[] { self.Info.Primary, self.Info.Secondary }
return new[] { self.LegacyInfo.Primary, self.LegacyInfo.Secondary }
.Where(w => w != null)
.Max(w => Rules.WeaponInfo[w].Range);
}
@@ -33,7 +33,7 @@ namespace OpenRa.Game.Traits
return true; // he's dead.
if ((attack.target.Location - self.Location).LengthSquared > range * range + 2)
return true; // wandered off faster than we could follow
if (attack.target.Health == attack.target.Info.Strength)
if (attack.target.Health == attack.target.LegacyInfo.Strength)
return true; // fully healed
return false;
@@ -55,7 +55,7 @@ namespace OpenRa.Game.Traits
return inRange
.Where(a => a.Owner == self.Owner && a != self) /* todo: one day deal with friendly players */
.Where(a => Combat.HasAnyValidWeapons(self, a))
.Where(a => a.Health < a.Info.Strength)
.Where(a => a.Health < a.LegacyInfo.Strength)
.OrderBy(a => (a.Location - self.Location).LengthSquared)
.FirstOrDefault();
}

View File

@@ -15,7 +15,7 @@ namespace OpenRa.Game.Traits
float GetMaximumRange(Actor self)
{
return new[] { self.Info.Primary, self.Info.Secondary }
return new[] { self.LegacyInfo.Primary, self.LegacyInfo.Secondary }
.Where(w => w != null)
.Max(w => Rules.WeaponInfo[w].Range);
}

View File

@@ -29,7 +29,7 @@ namespace OpenRa.Game.Traits
public Building(Actor self)
{
this.self = self;
unitInfo = (LegacyBuildingInfo)self.Info;
unitInfo = (LegacyBuildingInfo)self.LegacyInfo;
self.CenterLocation = Game.CellSize
* ((float2)self.Location + .5f * (float2)unitInfo.Dimensions);
}
@@ -84,8 +84,8 @@ namespace OpenRa.Game.Traits
if (remainingTicks == 0)
{
var costPerHp = (Rules.General.URepairPercent * self.Info.Cost) / self.Info.Strength;
var hpToRepair = Math.Min(Rules.General.URepairStep, self.Info.Strength - self.Health);
var costPerHp = (Rules.General.URepairPercent * self.LegacyInfo.Cost) / self.LegacyInfo.Strength;
var hpToRepair = Math.Min(Rules.General.URepairStep, self.LegacyInfo.Strength - self.Health);
var cost = (int)Math.Ceiling(costPerHp * hpToRepair);
if (!self.Owner.TakeCash(cost))
{
@@ -95,7 +95,7 @@ namespace OpenRa.Game.Traits
Game.world.AddFrameEndTask(w => w.Add(new RepairIndicator(self)));
self.InflictDamage(self, -hpToRepair, Rules.WarheadInfo["Super"]);
if (self.Health == self.Info.Strength)
if (self.Health == self.LegacyInfo.Strength)
{
isRepairing = false;
return;

View File

@@ -46,7 +46,7 @@ namespace OpenRa.Game.Traits
public bool IsFull(Actor self)
{
return cargo.Count == self.Info.Passengers;
return cargo.Count == self.LegacyInfo.Passengers;
}
public bool IsEmpty(Actor self)
@@ -63,7 +63,7 @@ namespace OpenRa.Game.Traits
public IEnumerable<PipType> GetPips( Actor self )
{
for (var i = 0; i < self.Info.Passengers; i++)
for (var i = 0; i < self.LegacyInfo.Passengers; i++)
if (i >= cargo.Count)
yield return PipType.Transparent;
else

View File

@@ -44,7 +44,7 @@ namespace OpenRa.Game.Traits
int2 detonateLocation = self.CenterLocation.ToInt2();
Game.world.AddFrameEndTask(
w => w.Add(new Bullet(self.Info.Primary, detonatedBy.Owner, detonatedBy,
w => w.Add(new Bullet(self.LegacyInfo.Primary, detonatedBy.Owner, detonatedBy,
detonateLocation, detonateLocation, altitude, altitude)));
}
}

View File

@@ -20,8 +20,8 @@ namespace OpenRa.Game.Traits
// todo: push into data!
static bool HeliCanEnter(Actor a)
{
if (a.Info == Rules.UnitInfo["HPAD"]) return true;
if (a.Info == Rules.UnitInfo["FIX"]) return true;
if (a.LegacyInfo == Rules.UnitInfo["HPAD"]) return true;
if (a.LegacyInfo == Rules.UnitInfo["FIX"]) return true;
return false;
}
@@ -52,7 +52,7 @@ namespace OpenRa.Game.Traits
{
self.CancelActivity();
self.QueueActivity(new HeliFly(Util.CenterOfCell(order.TargetLocation)));
self.QueueActivity(new Turn(self.Info.InitialFacing));
self.QueueActivity(new Turn(self.LegacyInfo.InitialFacing));
self.QueueActivity(new HeliLand(true));
}
@@ -63,14 +63,14 @@ namespace OpenRa.Game.Traits
if (res != null)
reservation = res.Reserve(self);
var offset = (order.TargetActor.Info as LegacyBuildingInfo).SpawnOffset;
var offset = (order.TargetActor.LegacyInfo as LegacyBuildingInfo).SpawnOffset;
var offsetVec = offset != null ? new float2(offset[0], offset[1]) : float2.Zero;
self.CancelActivity();
self.QueueActivity(new HeliFly(order.TargetActor.CenterLocation + offsetVec));
self.QueueActivity(new Turn(self.Info.InitialFacing));
self.QueueActivity(new Turn(self.LegacyInfo.InitialFacing));
self.QueueActivity(new HeliLand(false));
self.QueueActivity(order.TargetActor.Info == Rules.UnitInfo["HPAD"]
self.QueueActivity(order.TargetActor.LegacyInfo == Rules.UnitInfo["HPAD"]
? (IActivity)new Rearm() : new Repair());
}
}

View File

@@ -17,14 +17,14 @@ namespace OpenRa.Game.Traits
public LimitedAmmo(Actor self)
{
ammo = self.Info.Ammo;
ammo = self.LegacyInfo.Ammo;
this.self = self;
}
public bool HasAmmo() { return ammo > 0; }
public bool GiveAmmo()
{
if (ammo >= self.Info.Ammo) return false;
if (ammo >= self.LegacyInfo.Ammo) return false;
++ammo;
return true;
}
@@ -33,7 +33,7 @@ namespace OpenRa.Game.Traits
public IEnumerable<PipType> GetPips(Actor self)
{
return Graphics.Util.MakeArray(self.Info.Ammo,
return Graphics.Util.MakeArray(self.LegacyInfo.Ammo,
i => ammo > i ? PipType.Green : PipType.Transparent);
}
}

View File

@@ -33,7 +33,7 @@ namespace OpenRa.Game.Traits
// todo: delay a bit? (req making deploy-mine an activity)
Game.world.AddFrameEndTask(
w => w.Add(new Actor(Rules.UnitInfo[self.Info.Primary], self.Location, self.Owner)));
w => w.Add(new Actor(Rules.UnitInfo[self.LegacyInfo.Primary], self.Location, self.Owner)));
}
}
}

View File

@@ -87,12 +87,12 @@ namespace OpenRa.Game.Traits
public UnitMovementType GetMovementType()
{
switch (Rules.UnitCategory[self.Info.Name])
switch (Rules.UnitCategory[self.LegacyInfo.Name])
{
case "Infantry":
return UnitMovementType.Foot;
case "Vehicle":
return (self.Info as VehicleInfo).Tracked ? UnitMovementType.Track : UnitMovementType.Wheel;
return (self.LegacyInfo as VehicleInfo).Tracked ? UnitMovementType.Track : UnitMovementType.Wheel;
case "Ship":
return UnitMovementType.Float;
case "Plane":

View File

@@ -20,7 +20,7 @@ namespace OpenRa.Game.Traits
return null;
var umt = self.traits.WithInterface<IMovement>().First().GetMovementType();
if (!underCursor.Info.PassengerTypes.Contains(umt))
if (!underCursor.LegacyInfo.PassengerTypes.Contains(umt))
return null;
return new Order("EnterTransport", self, underCursor, int2.Zero, null);

View File

@@ -20,8 +20,8 @@ namespace OpenRa.Game.Traits
// todo: push into data!
static bool PlaneCanEnter(Actor a)
{
if (a.Info == Rules.UnitInfo["AFLD"]) return true;
if (a.Info == Rules.UnitInfo["FIX"]) return true;
if (a.LegacyInfo == Rules.UnitInfo["AFLD"]) return true;
if (a.LegacyInfo == Rules.UnitInfo["FIX"]) return true;
return false;
}
@@ -64,7 +64,7 @@ namespace OpenRa.Game.Traits
self.CancelActivity();
self.QueueActivity(new ReturnToBase(self, order.TargetActor));
self.QueueActivity(order.TargetActor.Info == Rules.UnitInfo["AFLD"]
self.QueueActivity(order.TargetActor.LegacyInfo == Rules.UnitInfo["AFLD"]
? (IActivity)new Rearm() : new Repair());
}
}

View File

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

View File

@@ -133,7 +133,7 @@ namespace OpenRa.Game.Traits
// Prioritise primary structure in build order
var primaryProducers = Game.world.Actors
.Where(x => x.traits.Contains<Production>()
&& producerTypes.Contains(x.Info)
&& producerTypes.Contains(x.LegacyInfo)
&& x.Owner == self.Owner
&& x.traits.Get<Production>().IsPrimary == true);
@@ -153,7 +153,7 @@ namespace OpenRa.Game.Traits
if (producer == null)
{
producer = Game.world.Actors
.Where( x => producerTypes.Contains( x.Info ) && x.Owner == self.Owner )
.Where( x => producerTypes.Contains( x.LegacyInfo ) && x.Owner == self.Owner )
.FirstOrDefault();
}

View File

@@ -26,7 +26,7 @@ namespace OpenRa.Game.Traits
public RenderWarFactory(Actor self)
{
this.self = self;
roof = new Animation(self.Info.Image ?? self.Info.Name);
roof = new Animation(self.LegacyInfo.Image ?? self.LegacyInfo.Name);
}
public void BuildingComplete( Actor self )

View File

@@ -18,7 +18,7 @@ namespace OpenRa.Game.Traits
public RenderSimple(Actor self)
{
anims.Add( "", new Animation( self.Info.Image ?? self.Info.Name ) );
anims.Add( "", new Animation( self.LegacyInfo.Image ?? self.LegacyInfo.Name ) );
}
public virtual IEnumerable<Renderable> Render( Actor self )

View File

@@ -15,17 +15,17 @@ namespace OpenRa.Game.Traits
public RenderUnitMuzzleFlash(Actor self)
: base(self)
{
if (!self.Info.MuzzleFlash) throw new InvalidOperationException("wtf??");
if (!self.LegacyInfo.MuzzleFlash) throw new InvalidOperationException("wtf??");
var unit = self.traits.Get<Unit>();
var attack = self.traits.WithInterface<AttackBase>().First();
var muzzleFlash = new Animation(self.Info.Name);
var muzzleFlash = new Animation(self.LegacyInfo.Name);
muzzleFlash.PlayFetchIndex("muzzle",
() => (Util.QuantizeFacing(unit.Facing, 8)) * 6 + (int)(attack.primaryRecoil * 5.9f));
anims.Add( "muzzle", new AnimationWithOffset(
muzzleFlash,
() => self.Info.PrimaryOffset.AbsOffset(),
() => self.LegacyInfo.PrimaryOffset.AbsOffset(),
() => attack.primaryRecoil <= 0 ) );
}
}

View File

@@ -16,20 +16,20 @@ namespace OpenRa.Game.Traits
{
var unit = self.traits.Get<Unit>();
rotorAnim = new Animation(self.Info.Name);
rotorAnim = new Animation(self.LegacyInfo.Name);
rotorAnim.PlayRepeating("rotor");
anims.Add( "rotor_1", new AnimationWithOffset(
rotorAnim,
() => Util.GetTurretPosition( self, unit, self.Info.RotorOffset, 0 ),
() => Util.GetTurretPosition( self, unit, self.LegacyInfo.RotorOffset, 0 ),
null ) );
if (self.Info.RotorOffset2 == null) return;
if (self.LegacyInfo.RotorOffset2 == null) return;
secondRotorAnim = new Animation( self.Info.Name );
secondRotorAnim = new Animation( self.LegacyInfo.Name );
secondRotorAnim.PlayRepeating( "rotor2" );
anims.Add( "rotor_2", new AnimationWithOffset(
secondRotorAnim,
() => Util.GetTurretPosition(self, unit, self.Info.RotorOffset2, 0),
() => Util.GetTurretPosition(self, unit, self.LegacyInfo.RotorOffset2, 0),
null ) );
}

View File

@@ -15,11 +15,11 @@ namespace OpenRa.Game.Traits
{
var unit = self.traits.Get<Unit>();
var spinnerAnim = new Animation( self.Info.Name );
var spinnerAnim = new Animation( self.LegacyInfo.Name );
spinnerAnim.PlayRepeating( "spinner" );
anims.Add( "spinner", new AnimationWithOffset(
spinnerAnim,
() => Util.GetTurretPosition( self, unit, self.Info.PrimaryOffset, 0 ),
() => Util.GetTurretPosition( self, unit, self.LegacyInfo.PrimaryOffset, 0 ),
null ) );
}
}

View File

@@ -18,30 +18,30 @@ namespace OpenRa.Game.Traits
var turreted = self.traits.Get<Turreted>();
var attack = self.traits.WithInterface<AttackBase>().FirstOrDefault();
var turretAnim = new Animation(self.Info.Name);
var turretAnim = new Animation(self.LegacyInfo.Name);
turretAnim.PlayFacing( "turret", () => turreted.turretFacing );
if( self.Info.PrimaryOffset != null )
if( self.LegacyInfo.PrimaryOffset != null )
anims.Add("turret_1", new AnimationWithOffset(
turretAnim,
() => Util.GetTurretPosition(self, unit, self.Info.PrimaryOffset, attack.primaryRecoil),
() => Util.GetTurretPosition(self, unit, self.LegacyInfo.PrimaryOffset, attack.primaryRecoil),
null) { ZOffset = 1 });
if( self.Info.SecondaryOffset != null )
if( self.LegacyInfo.SecondaryOffset != null )
anims.Add("turret_2", new AnimationWithOffset(
turretAnim,
() => Util.GetTurretPosition(self, unit, self.Info.SecondaryOffset, attack.secondaryRecoil),
() => Util.GetTurretPosition(self, unit, self.LegacyInfo.SecondaryOffset, attack.secondaryRecoil),
null) { ZOffset = 1 });
if( self.Info.MuzzleFlash )
if( self.LegacyInfo.MuzzleFlash )
{
var muzzleFlash = new Animation( self.Info.Name );
var muzzleFlash = new Animation( self.LegacyInfo.Name );
muzzleFlash.PlayFetchIndex( "muzzle",
() => ( Util.QuantizeFacing( self.traits.Get<Turreted>().turretFacing, 8 ) ) * 6
+ (int)( attack.primaryRecoil * 5.9f ) ); /* hack: recoil can be 1.0f, but don't overflow into next anim */
anims.Add( "muzzle_flash", new AnimationWithOffset(
muzzleFlash,
() => Util.GetTurretPosition( self, unit, self.Info.PrimaryOffset, attack.primaryRecoil ),
() => Util.GetTurretPosition( self, unit, self.LegacyInfo.PrimaryOffset, attack.primaryRecoil ),
() => attack.primaryRecoil <= 0 ) );
}
}

View File

@@ -21,7 +21,7 @@ namespace OpenRa.Game.Traits
if (mi.Button != MouseButton.Right) return null;
if (underCursor == null) return null;
if (underCursor.Info == Rules.UnitInfo["FIX"]
if (underCursor.LegacyInfo == Rules.UnitInfo["FIX"]
&& underCursor.Owner == self.Owner
&& !Reservable.IsReserved(underCursor))
return new Order("Enter", self, underCursor, int2.Zero, null);

View File

@@ -14,7 +14,7 @@ namespace OpenRa.Game.Traits
public void OnSteal(Actor self, Actor thief)
{
// Steal half the ore the building holds
var toSteal = (self.Info as LegacyBuildingInfo).Storage/2;
var toSteal = (self.LegacyInfo as LegacyBuildingInfo).Storage/2;
self.Owner.TakeCash(toSteal);
thief.Owner.GiveCash(toSteal);
@@ -28,9 +28,9 @@ namespace OpenRa.Game.Traits
public IEnumerable<PipType> GetPips(Actor self)
{
for (int i = 0; i < self.Info.OrePips; i++)
for (int i = 0; i < self.LegacyInfo.OrePips; i++)
{
if (Game.LocalPlayer.GetSiloFullness() > i * 1.0f / self.Info.OrePips)
if (Game.LocalPlayer.GetSiloFullness() > i * 1.0f / self.LegacyInfo.OrePips)
{
yield return PipType.Yellow;
continue;

View File

@@ -14,13 +14,13 @@ namespace OpenRa.Game.Traits
public Turreted(Actor self)
{
turretFacing = self.Info.InitialFacing;
turretFacing = self.LegacyInfo.InitialFacing;
}
public void Tick( Actor self )
{
var df = desiredFacing ?? ( self.traits.Contains<Unit>() ? self.traits.Get<Unit>().Facing : turretFacing );
Util.TickFacing( ref turretFacing, df, self.Info.ROT );
Util.TickFacing( ref turretFacing, df, self.LegacyInfo.ROT );
}
}
}

View File

@@ -82,14 +82,14 @@ namespace OpenRa.Game.Traits
static float2 GetRecoil(Actor self, float recoil)
{
if (self.Info.Recoil == 0) return float2.Zero;
if (self.LegacyInfo.Recoil == 0) return float2.Zero;
var rut = self.traits.WithInterface<RenderUnitTurreted>().FirstOrDefault();
if (rut == null) return float2.Zero;
var facing = self.traits.Get<Turreted>().turretFacing;
var quantizedFacing = QuantizeFacing(facing, rut.anim.CurrentSequence.Length) * (256 / rut.anim.CurrentSequence.Length);
return RotateVectorByFacing(new float2(0, recoil * self.Info.Recoil), quantizedFacing, .7f);
return RotateVectorByFacing(new float2(0, recoil * self.LegacyInfo.Recoil), quantizedFacing, .7f);
}
public static float2 CenterOfCell(int2 loc)
@@ -127,7 +127,7 @@ namespace OpenRa.Game.Traits
public static float GetEffectiveSpeed(Actor self)
{
var mi = self.Info as LegacyMobileInfo;
var mi = self.LegacyInfo as LegacyMobileInfo;
if (mi == null) return 0f;
var modifier = self.traits

View File

@@ -36,7 +36,7 @@ namespace OpenRa.Game
var crusher = GetUnitsAt(cell).Where(b => a != b && Game.IsActorCrushableByActor(a, b)).FirstOrDefault();
if (crusher != null)
{
Log.Write("{0} crushes {1}", crusher.Info.Name, a.Info.Name);
Log.Write("{0} crushes {1}", crusher.LegacyInfo.Name, a.LegacyInfo.Name);
// Apply the crush action
foreach (var crush in a.traits.WithInterface<ICrushable>())
crush.OnCrush(crusher);