Delayed unloading. Remove LocalStorage from proc.

This commit is contained in:
Paul Chote
2011-01-02 15:27:29 +13:00
parent 3674accd0c
commit de5d9abec3
6 changed files with 37 additions and 14 deletions

View File

@@ -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;

View File

@@ -50,7 +50,6 @@ namespace OpenRA.Mods.Cnc
IActivity NextActivity { get; set; }
int unloadTicks = 0;
public IActivity Tick(Actor self)
{
switch (state)

View File

@@ -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;
}

View File

@@ -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)
{

View File

@@ -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; }
}

View File

@@ -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