From 150a83852e3e9c28f4aea068a0327060f817d355 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Fri, 16 Apr 2010 21:06:54 +1200 Subject: [PATCH] introduce 'Valued' trait, which is almost Buildable without being buildable. --- OpenRA.Game/Chrome.cs | 2 +- OpenRA.Game/Traits/AI/EmitInfantryOnSell.cs | 4 ++-- OpenRA.Game/Traits/Activities/Repair.cs | 2 +- OpenRA.Game/Traits/Activities/Sell.cs | 2 +- OpenRA.Game/Traits/Buildable.cs | 18 ++++++++++++++---- mods/ra/infantry.yaml | 6 ++++++ 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs index 6de20bb8b0..226814e8b0 100644 --- a/OpenRA.Game/Chrome.cs +++ b/OpenRA.Game/Chrome.cs @@ -119,7 +119,7 @@ namespace OpenRA var actor = world.FindUnitsAtMouse(lastMousePos).FirstOrDefault(); if (actor == null) return; - var text = actor.Info.Traits.Contains() ? actor.Info.Traits.Get().Description : actor.Info.Name; + var text = actor.Info.Traits.Contains() ? actor.Info.Traits.Get().Description : actor.Info.Name; var text2 = (actor.Owner == world.LocalPlayer) ? "" : (actor.Owner == world.NeutralPlayer ? "{0}" : "{0} ({1})").F(actor.Owner.PlayerName, world.LocalPlayer.Stances[actor.Owner]); diff --git a/OpenRA.Game/Traits/AI/EmitInfantryOnSell.cs b/OpenRA.Game/Traits/AI/EmitInfantryOnSell.cs index 58d6db21fa..c9938c845f 100644 --- a/OpenRA.Game/Traits/AI/EmitInfantryOnSell.cs +++ b/OpenRA.Game/Traits/AI/EmitInfantryOnSell.cs @@ -21,13 +21,13 @@ namespace OpenRA.Traits.AI { var info = self.Info.Traits.Get(); var csv = self.Info.Traits.GetOrDefault(); - var cost = csv != null ? csv.Value : self.Info.Traits.Get().Cost; + var cost = csv != null ? csv.Value : self.Info.Traits.Get().Cost; var hp = self.Info.Traits.Get().HP; var hpFraction = Math.Max(info.MinHpFraction, hp / self.GetMaxHP()); var dudesValue = (int)(hpFraction * info.ValueFraction * cost); var eligibleLocations = Footprint.Tiles(self).ToList(); // todo: fix this for unbuildables in ActorTypes, like civilians. - var actorTypes = info.ActorTypes.Select(a => new { Name = a, Cost = Rules.Info[a].Traits.Get().Cost }).ToArray(); + var actorTypes = info.ActorTypes.Select(a => new { Name = a, Cost = Rules.Info[a].Traits.Get().Cost }).ToArray(); while (eligibleLocations.Count > 0 && actorTypes.Any(a => a.Cost <= dudesValue)) { diff --git a/OpenRA.Game/Traits/Activities/Repair.cs b/OpenRA.Game/Traits/Activities/Repair.cs index 9cee11846c..2a543373f1 100644 --- a/OpenRA.Game/Traits/Activities/Repair.cs +++ b/OpenRA.Game/Traits/Activities/Repair.cs @@ -39,7 +39,7 @@ namespace OpenRA.Traits.Activities var hostBuilding = self.World.FindUnits(self.CenterLocation, self.CenterLocation) .FirstOrDefault(a => a.traits.Contains()); - var unitCost = self.Info.Traits.Get().Cost; + var unitCost = self.Info.Traits.Get().Cost; var hp = self.Info.Traits.Get().HP; var costPerHp = (hostBuilding.Info.Traits.Get().URepairPercent * unitCost) / hp; diff --git a/OpenRA.Game/Traits/Activities/Sell.cs b/OpenRA.Game/Traits/Activities/Sell.cs index 3dccb60157..c15415a21d 100644 --- a/OpenRA.Game/Traits/Activities/Sell.cs +++ b/OpenRA.Game/Traits/Activities/Sell.cs @@ -31,7 +31,7 @@ namespace OpenRA.Traits.Activities void DoSell(Actor self) { var csv = self.Info.Traits.GetOrDefault(); - var cost = csv != null ? csv.Value : self.Info.Traits.Get().Cost; + var cost = csv != null ? csv.Value : self.Info.Traits.Get().Cost; var hp = self.Info.Traits.Get().HP; var refund = self.World.Defaults.RefundPercent * self.Health * cost / hp; diff --git a/OpenRA.Game/Traits/Buildable.cs b/OpenRA.Game/Traits/Buildable.cs index e710f97960..8286018638 100755 --- a/OpenRA.Game/Traits/Buildable.cs +++ b/OpenRA.Game/Traits/Buildable.cs @@ -20,19 +20,29 @@ namespace OpenRA.Traits { - class BuildableInfo : TraitInfo + class ValuedInfo : ITraitInfo + { + public readonly int Cost = 0; + public readonly string Description = ""; + public readonly string LongDesc = ""; + + public virtual object Create(Actor self) { return new Valued(); } + } + + class BuildableInfo : ValuedInfo { public readonly int TechLevel = -1; public readonly string[] Prerequisites = { }; public readonly string[] BuiltAt = { }; public readonly string[] Owner = { }; - public readonly int Cost = 0; - public readonly string Description = ""; - public readonly string LongDesc = ""; + public readonly string Icon = null; public readonly string[] AlternateName = { }; public readonly int BuildPaletteOrder = 50; + + public override object Create(Actor self) { return new Buildable(); } } + class Valued { } /* halfway to buildable */ class Buildable { } } diff --git a/mods/ra/infantry.yaml b/mods/ra/infantry.yaml index e469e2c24b..a8986bb995 100644 --- a/mods/ra/infantry.yaml +++ b/mods/ra/infantry.yaml @@ -209,6 +209,9 @@ C1: Selectable: Voice: CivilianMaleVoice Bounds: 12,17,0,-9 + Valued: + Cost: 70 + Description: Technician Unit: HP: 20 Sight: 2 @@ -221,6 +224,9 @@ C2: Selectable: Voice: CivilianFemaleVoice Bounds: 12,17,0,-9 + Valued: + Cost: 70 + Description: Technician Unit: HP: 20 Sight: 2