From 0e734312097ffd851faa90d5d1de7d0e7fda70fb Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 3 Mar 2010 21:56:33 +1300 Subject: [PATCH] harvester can be fussy now. --- OpenRA.Game/Traits/Activities/Harvest.cs | 6 +++- OpenRA.Game/Traits/Harvester.cs | 41 +++++++++++------------- OpenRA.Game/Traits/SeedsResource.cs | 2 +- mods/cnc/minimal.ini | 2 -- mods/cnc/vehicles.yaml | 2 ++ mods/ra/rules.ini | 2 -- mods/ra/rules.yaml | 6 ++-- 7 files changed, 31 insertions(+), 30 deletions(-) diff --git a/OpenRA.Game/Traits/Activities/Harvest.cs b/OpenRA.Game/Traits/Activities/Harvest.cs index 3c66a5d728..dafa4d4fbb 100644 --- a/OpenRA.Game/Traits/Activities/Harvest.cs +++ b/OpenRA.Game/Traits/Activities/Harvest.cs @@ -18,6 +18,8 @@ */ #endregion +using System.Linq; + namespace OpenRA.Traits.Activities { public class Harvest : IActivity @@ -65,13 +67,15 @@ namespace OpenRA.Traits.Activities void FindMoreOre(Actor self) { var res = self.World.WorldActor.traits.Get(); + var harv = self.Info.Traits.Get(); self.QueueActivity(new Move( () => { var search = new PathSearch { - heuristic = loc => (res.GetResource(loc) != null ? 0 : 1), + heuristic = loc => (res.GetResource(loc) != null + && harv.Resources.Any( r => res.GetResource(loc).Name == r )) ? 0 : 1, umt = UnitMovementType.Wheel, checkForBlocked = true }; diff --git a/OpenRA.Game/Traits/Harvester.cs b/OpenRA.Game/Traits/Harvester.cs index 3422ebadb7..d25f2d2355 100644 --- a/OpenRA.Game/Traits/Harvester.cs +++ b/OpenRA.Game/Traits/Harvester.cs @@ -19,24 +19,24 @@ #endregion using System.Collections.Generic; +using System.Linq; using OpenRA.Traits.Activities; +using OpenRA.FileFormats; namespace OpenRA.Traits { class HarvesterInfo : ITraitInfo { - public readonly int BailCount = 28; + public readonly int Capacity = 28; public readonly int PipCount = 7; + public readonly string[] Resources = { }; public object Create(Actor self) { return new Harvester(self); } } public class Harvester : IIssueOrder, IResolveOrder, IPips { - [Sync] - public int oreCarried = 0; /* sum of these must not exceed capacity */ - [Sync] - public int gemsCarried = 0; + Dictionary contents = new Dictionary(); Actor self; public Harvester(Actor self) @@ -44,22 +44,19 @@ namespace OpenRA.Traits this.self = self; } - public bool IsFull { get { return oreCarried + gemsCarried == self.Info.Traits.Get().BailCount; } } - public bool IsEmpty { get { return oreCarried == 0 && gemsCarried == 0; } } + public bool IsFull { get { return contents.Values.Sum() == self.Info.Traits.Get().Capacity; } } + public bool IsEmpty { get { return contents.Values.Sum() == 0; } } public void AcceptResource(ResourceTypeInfo type) { - // FIXME: harvester probably needs to know *exactly* what it is carrying. - if (type.Name == "Gems") gemsCarried++; - else oreCarried++; + if (!contents.ContainsKey(type)) contents[type] = 1; + else contents[type]++; } public void Deliver(Actor self, Actor proc) { - proc.Owner.GiveOre(oreCarried * Rules.General.GoldValue); - proc.Owner.GiveOre(gemsCarried * Rules.General.GemValue); - oreCarried = 0; - gemsCarried = 0; + proc.Owner.GiveOre(contents.Sum(kv => kv.Key.ValuePerUnit * kv.Value)); + contents.Clear(); } public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) @@ -71,7 +68,11 @@ namespace OpenRA.Traits && underCursor.traits.Contains() && !IsEmpty) return new Order("Deliver", self, underCursor); - if (underCursor == null && self.World.WorldActor.traits.Get().GetResource(xy) != null) + var res = self.World.WorldActor.traits.Get().GetResource(xy); + + if (underCursor == null && + res != null && self.Info.Traits.Get().Resources + .Any(r => r == res.Name)) return new Order("Harvest", self, xy); return null; @@ -95,16 +96,12 @@ namespace OpenRA.Traits public IEnumerable GetPips(Actor self) { int numPips = self.Info.Traits.Get().PipCount; + int n = contents.Values.Sum(); for (int i = 0; i < numPips; i++) { - if (gemsCarried * 1.0f / self.Info.Traits.Get().BailCount > i * 1.0f / numPips) - { - yield return PipType.Red; - continue; - } - - if ((gemsCarried + oreCarried) * 1.0f / self.Info.Traits.Get().BailCount > i * 1.0f / numPips) + // todo: pip colors based on ResourceTypeInfo + if (n * 1.0f / self.Info.Traits.Get().Capacity > i * 1.0f / numPips) { yield return PipType.Yellow; continue; diff --git a/OpenRA.Game/Traits/SeedsResource.cs b/OpenRA.Game/Traits/SeedsResource.cs index e3ba14ff28..e290e08ee6 100644 --- a/OpenRA.Game/Traits/SeedsResource.cs +++ b/OpenRA.Game/Traits/SeedsResource.cs @@ -18,8 +18,8 @@ */ #endregion -using System.Linq; using System; +using System.Linq; namespace OpenRA.Traits { diff --git a/mods/cnc/minimal.ini b/mods/cnc/minimal.ini index 40ec05ee6e..8888077132 100644 --- a/mods/cnc/minimal.ini +++ b/mods/cnc/minimal.ini @@ -10,8 +10,6 @@ URepairPercent=20% ; [units only] percent cost to fully repair as ratio of URepairStep=10 ; [units only] hit points to heal per repair 'tick' for units BuildSpeed=.1 ; general build speed [time (in minutes) to produce a 1000 credit cost item] -GemValue=50 ; gem credits per 'bail' carried by a harvester -GoldValue=25 ; gold credits per 'bail' carried by a harvester LowPowerSlowdown=3 ; slowdown factor for low power GapRegenInterval=.1 ; gap generators will regenerate their shroud at this time interval diff --git a/mods/cnc/vehicles.yaml b/mods/cnc/vehicles.yaml index 0f309385a0..ff84a70e6a 100644 --- a/mods/cnc/vehicles.yaml +++ b/mods/cnc/vehicles.yaml @@ -37,6 +37,8 @@ HARV: Selectable: Priority: 7 Harvester: + Resources: Tiberium + Capacity: 28 Unit: HP: 600 Armor: light diff --git a/mods/ra/rules.ini b/mods/ra/rules.ini index d29c1c836e..b699902464 100644 --- a/mods/ra/rules.ini +++ b/mods/ra/rules.ini @@ -49,8 +49,6 @@ Incoming=10 ; If an incoming projectile is as slow or slower than th ; income and production BuildSpeed=.8 ; general build speed [time (in minutes) to produce a 1000 credit cost item] BuildupTime=.06 ; average minutes that building build-up animation runs -GemValue=50 ; gem credits per 'bail' carried by a harvester -GoldValue=25 ; gold credits per 'bail' carried by a harvester OreTruckRate=1 ; speed that harvester truck manages ore [larger means slower] SeparateAircraft=no ; Is first helicopter to be purchased separately from helipad? SurvivorRate=.4 ; fraction of building cost to be converted to survivors when sold diff --git a/mods/ra/rules.yaml b/mods/ra/rules.yaml index eaa4194f9a..b61de4ae82 100644 --- a/mods/ra/rules.yaml +++ b/mods/ra/rules.yaml @@ -234,7 +234,7 @@ World: Overlays: 5,6,7,8 Palette: terrain SpriteNames: gold01,gold02,gold03,gold04 - ValuePerUnit: 30 + ValuePerUnit: 25 Name: Ore GrowthInterval: .3 SpreadInterval: .7 @@ -242,7 +242,7 @@ World: Overlays: 9,10,11,12 Palette: terrain SpriteNames: gem01,gem02,gem03,gem04 - ValuePerUnit: 60 + ValuePerUnit: 50 Name: Gems MGG: @@ -801,6 +801,8 @@ HARV: Selectable: Priority: 7 Harvester: + Capacity: 28 + Resources: Ore,Gems Unit: HP: 600 Armor: heavy