Delayed unloading. Remove LocalStorage from proc.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -50,7 +50,6 @@ namespace OpenRA.Mods.Cnc
|
||||
|
||||
IActivity NextActivity { get; set; }
|
||||
|
||||
int unloadTicks = 0;
|
||||
public IActivity Tick(Actor self)
|
||||
{
|
||||
switch (state)
|
||||
|
||||
@@ -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<IAcceptOre>().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<IAcceptOre>();
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -56,6 +56,14 @@ namespace OpenRA.Mods.RA
|
||||
return self.World.Queries.WithTrait<Harvester>()
|
||||
.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)
|
||||
{
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user