diff --git a/OpenRA.Game/Traits/Player/PlayerResources.cs b/OpenRA.Game/Traits/Player/PlayerResources.cs index c1da65a4bb..383c743f51 100644 --- a/OpenRA.Game/Traits/Player/PlayerResources.cs +++ b/OpenRA.Game/Traits/Player/PlayerResources.cs @@ -45,6 +45,11 @@ namespace OpenRA.Traits public int DisplayCash; public int DisplayOre; + public bool CanGiveOre(int amount) + { + return Ore + amount <= OreCapacity; + } + public void GiveOre(int num) { Ore += num; diff --git a/OpenRA.Mods.Cnc/Activities/HarvesterDockSequence.cs b/OpenRA.Mods.Cnc/Activities/HarvesterDockSequence.cs index 2443368df5..55bdaa347e 100644 --- a/OpenRA.Mods.Cnc/Activities/HarvesterDockSequence.cs +++ b/OpenRA.Mods.Cnc/Activities/HarvesterDockSequence.cs @@ -50,7 +50,6 @@ namespace OpenRA.Mods.Cnc IActivity NextActivity { get; set; } - int unloadTicks = 0; public IActivity Tick(Actor self) { switch (state) diff --git a/OpenRA.Mods.RA/Harvester.cs b/OpenRA.Mods.RA/Harvester.cs index 5ae9078e8b..08e4ad7379 100644 --- a/OpenRA.Mods.RA/Harvester.cs +++ b/OpenRA.Mods.RA/Harvester.cs @@ -20,7 +20,8 @@ namespace OpenRA.Mods.RA { public class HarvesterInfo : ITraitInfo { - public readonly int Capacity = 28; + public readonly int Capacity = 28; + public readonly int UnloadTicksPerBale = 4; public readonly int PipCount = 7; public readonly string[] Resources = { }; public readonly decimal FullyLoadedSpeed = .85m; @@ -82,17 +83,32 @@ namespace OpenRA.Mods.RA } // TODO: N-tick harvester unload. - // Currently unloads everything in one go // Returns true when unloading is complete + int currentUnloadTicks; public bool TickUnload(Actor self, Actor proc) { if (!proc.IsInWorld) return false; // fail to deliver if there is no proc. - - // TODO: Unload part of the load. Return false if the proc is full. - proc.Trait().GiveOre(contents.Sum(kv => kv.Key.ValuePerUnit * kv.Value)); - contents.Clear(); - return true; + + // Wait until the next bale is ready + if (--currentUnloadTicks > 0) + return false; + + if (contents.Keys.Count > 0) + { + var type = contents.First().Key; + var iao = proc.Trait(); + if (!iao.CanGiveOre(type.ValuePerUnit)) + return false; + + iao.GiveOre(type.ValuePerUnit); + if (--contents[type] == 0) + contents.Remove(type); + + currentUnloadTicks = Info.UnloadTicksPerBale; + } + + return contents.Count == 0; } diff --git a/OpenRA.Mods.RA/OreRefinery.cs b/OpenRA.Mods.RA/OreRefinery.cs index e063f40135..a5710c658e 100644 --- a/OpenRA.Mods.RA/OreRefinery.cs +++ b/OpenRA.Mods.RA/OreRefinery.cs @@ -56,6 +56,14 @@ namespace OpenRA.Mods.RA return self.World.Queries.WithTrait() .Where(a => a.Trait.LinkedProc == self); } + + public bool CanGiveOre(int amount) + { + if (!Info.LocalStorage) + return PlayerResources.CanGiveOre(amount); + else + return Ore + amount <= Info.Capacity; + } public void GiveOre (int amount) { diff --git a/OpenRA.Mods.RA/TraitsInterfaces.cs b/OpenRA.Mods.RA/TraitsInterfaces.cs index 5b82f047ff..fb7a02029f 100755 --- a/OpenRA.Mods.RA/TraitsInterfaces.cs +++ b/OpenRA.Mods.RA/TraitsInterfaces.cs @@ -16,6 +16,7 @@ namespace OpenRA.Mods.RA { void OnDock(Actor harv, DeliverResources dockOrder); void GiveOre(int amount); + bool CanGiveOre(int amount); int2 DeliverOffset { get; } } diff --git a/mods/cnc/rules/structures.yaml b/mods/cnc/rules/structures.yaml index 4bfdd9db5d..7daa6213d3 100644 --- a/mods/cnc/rules/structures.yaml +++ b/mods/cnc/rules/structures.yaml @@ -79,13 +79,7 @@ PROC: Range: 6 Bib: OreRefinery: - LocalStorage: yes - PipCount: 15 - PipColor: Red DockOffset: 0,2 - Capacity: 1000 - ProcessTick: 25 - ProcessAmount: 50 StoresOre: PipColor: Green PipCount: 15