From df330f3151c772df4d9959fbc326ef2d8b006bb8 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 12 Jan 2010 15:47:11 +1300 Subject: [PATCH] fixing some more bits --- OpenRa.Game/Traits/Activities/HeliFly.cs | 3 ++- OpenRa.Game/Traits/AttackTurreted.cs | 4 ++-- OpenRa.Game/Traits/Building.cs | 25 ++++++++++++++---------- OpenRa.Game/Traits/Cargo.cs | 3 ++- OpenRa.Game/Traits/Plane.cs | 2 +- OpenRa.Game/Traits/RallyPoint.cs | 6 ++++-- 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/OpenRa.Game/Traits/Activities/HeliFly.cs b/OpenRa.Game/Traits/Activities/HeliFly.cs index fd1ac6aa50..9699a01853 100644 --- a/OpenRa.Game/Traits/Activities/HeliFly.cs +++ b/OpenRa.Game/Traits/Activities/HeliFly.cs @@ -39,7 +39,8 @@ namespace OpenRa.Game.Traits.Activities } var desiredFacing = Util.GetFacing(dist, unit.Facing); - Util.TickFacing(ref unit.Facing, desiredFacing, self.LegacyInfo.ROT); + Util.TickFacing(ref unit.Facing, desiredFacing, + self.Info.Traits.Get().ROT); var rawSpeed = .2f * Util.GetEffectiveSpeed(self); self.CenterLocation += (rawSpeed / dist.Length) * dist; diff --git a/OpenRa.Game/Traits/AttackTurreted.cs b/OpenRa.Game/Traits/AttackTurreted.cs index c8305e192c..33aef0b1ad 100755 --- a/OpenRa.Game/Traits/AttackTurreted.cs +++ b/OpenRa.Game/Traits/AttackTurreted.cs @@ -36,11 +36,11 @@ 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.LegacyInfo.Primary ?? order.Subject.LegacyInfo.Secondary; + var weapon = order.Subject.GetPrimaryWeapon() ?? order.Subject.GetSecondaryWeapon(); if (self.traits.Contains()) self.QueueActivity( new Traits.Activities.Follow( order.TargetActor, - Math.Max( 0, (int)Rules.WeaponInfo[ weapon ].Range - RangeTolerance ) ) ); + Math.Max( 0, (int)weapon.Range - RangeTolerance ) ) ); target = order.TargetActor; diff --git a/OpenRa.Game/Traits/Building.cs b/OpenRa.Game/Traits/Building.cs index 66608059ae..b351c14202 100644 --- a/OpenRa.Game/Traits/Building.cs +++ b/OpenRa.Game/Traits/Building.cs @@ -39,32 +39,36 @@ namespace OpenRa.Game.Traits class Building : INotifyDamage, IResolveOrder, ITick { readonly Actor self; - public readonly LegacyBuildingInfo unitInfo; + [Obsolete] public readonly LegacyBuildingInfo unitInfo; + public readonly BuildingInfo Info; [Sync] bool isRepairing = false; [Sync] bool manuallyDisabled = false; public bool ManuallyDisabled { get { return manuallyDisabled; } } - public bool Disabled { get { return (manuallyDisabled || (unitInfo.Powered && self.Owner.GetPowerState() != PowerState.Normal)); } } + public bool Disabled { get { return (manuallyDisabled || (Info.RequiresPower && self.Owner.GetPowerState() != PowerState.Normal)); } } bool wasDisabled = false; public Building(Actor self) { this.self = self; + Info = self.Info.Traits.Get(); unitInfo = (LegacyBuildingInfo)self.LegacyInfo; self.CenterLocation = Game.CellSize - * ((float2)self.Location + .5f * (float2)unitInfo.Dimensions); + * ((float2)self.Location + .5f * (float2)Info.Dimensions); } public int GetPowerUsage() { if (manuallyDisabled) return 0; - - if (unitInfo.Power > 0) /* todo: is this how real-ra scales it? */ - return (self.Health * unitInfo.Power) / unitInfo.Strength; + + var maxHP = self.Info.Traits.Get().HP; + + if (Info.Power > 0) /* todo: is this how real-ra scales it? */ + return (self.Health * Info.Power) / maxHP; else - return unitInfo.Power; + return Info.Power; } public void Damaged(Actor self, AttackInfo e) @@ -106,8 +110,9 @@ namespace OpenRa.Game.Traits if (remainingTicks == 0) { - var costPerHp = (Rules.General.URepairPercent * self.LegacyInfo.Cost) / self.LegacyInfo.Strength; - var hpToRepair = Math.Min(Rules.General.URepairStep, self.LegacyInfo.Strength - self.Health); + var maxHP = self.Info.Traits.Get().HP; + var costPerHp = (Rules.General.URepairPercent * self.Info.Traits.Get().Cost) / maxHP; + var hpToRepair = Math.Min(Rules.General.URepairStep, maxHP - self.Health); var cost = (int)Math.Ceiling(costPerHp * hpToRepair); if (!self.Owner.TakeCash(cost)) { @@ -117,7 +122,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.LegacyInfo.Strength) + if (self.Health == maxHP) { isRepairing = false; return; diff --git a/OpenRa.Game/Traits/Cargo.cs b/OpenRa.Game/Traits/Cargo.cs index 72d774eb61..99707546bc 100644 --- a/OpenRa.Game/Traits/Cargo.cs +++ b/OpenRa.Game/Traits/Cargo.cs @@ -9,6 +9,7 @@ namespace OpenRa.Game.Traits { class CargoInfo : ITraitInfo { + public readonly int Passengers = 0; public readonly UnitMovementType[] PassengerTypes = { }; public readonly int UnloadFacing = 0; @@ -64,7 +65,7 @@ namespace OpenRa.Game.Traits public IEnumerable GetPips( Actor self ) { - for (var i = 0; i < self.LegacyInfo.Passengers; i++) + for (var i = 0; i < self.Info.Traits.Get().Passengers; i++) if (i >= cargo.Count) yield return PipType.Transparent; else diff --git a/OpenRa.Game/Traits/Plane.cs b/OpenRa.Game/Traits/Plane.cs index 96c2884d6c..fefa10a17c 100644 --- a/OpenRa.Game/Traits/Plane.cs +++ b/OpenRa.Game/Traits/Plane.cs @@ -64,7 +64,7 @@ namespace OpenRa.Game.Traits self.CancelActivity(); self.QueueActivity(new ReturnToBase(self, order.TargetActor)); - self.QueueActivity(order.TargetActor.LegacyInfo == Rules.UnitInfo["AFLD"] + self.QueueActivity(order.TargetActor.Info.Name == "afld" ? (IActivity)new Rearm() : new Repair()); } } diff --git a/OpenRa.Game/Traits/RallyPoint.cs b/OpenRa.Game/Traits/RallyPoint.cs index 1daf34c844..6a7fc5c434 100644 --- a/OpenRa.Game/Traits/RallyPoint.cs +++ b/OpenRa.Game/Traits/RallyPoint.cs @@ -6,6 +6,8 @@ namespace OpenRa.Game.Traits { class RallyPointInfo : ITraitInfo { + public readonly int[] RallyPoint = { 1, 3 }; + public object Create(Actor self) { return new RallyPoint(self); } } @@ -17,8 +19,8 @@ namespace OpenRa.Game.Traits public RallyPoint(Actor self) { - var bi = self.traits.Get().unitInfo; - rallyPoint = self.Location + new int2(bi.RallyPoint[0], bi.RallyPoint[1]); + var info = self.Info.Traits.Get(); + rallyPoint = self.Location + new int2(info.RallyPoint[0], info.RallyPoint[1]); anim = new Animation("flagfly"); anim.PlayRepeating("idle"); }