Skip to content

Commit

Permalink
Delayed unloading. Remove LocalStorage from proc.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote committed Jan 2, 2011
1 parent 3674acc commit de5d9ab
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 14 deletions.
5 changes: 5 additions & 0 deletions OpenRA.Game/Traits/Player/PlayerResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public PlayerResources(Actor self)
public int DisplayCash;
public int DisplayOre;

public bool CanGiveOre(int amount)
{
return Ore + amount <= OreCapacity;
}

public void GiveOre(int num)
{
Ore += num;
Expand Down
1 change: 0 additions & 1 deletion OpenRA.Mods.Cnc/Activities/HarvesterDockSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public HarvesterDockSequence(Actor self, Actor proc)

IActivity NextActivity { get; set; }

int unloadTicks = 0;
public IActivity Tick(Actor self)
{
switch (state)
Expand Down
30 changes: 23 additions & 7 deletions OpenRA.Mods.RA/Harvester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -82,17 +83,32 @@ public void AcceptResource(ResourceType type)
}

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


Expand Down
8 changes: 8 additions & 0 deletions OpenRA.Mods.RA/OreRefinery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ public IEnumerable<TraitPair<Harvester>> GetLinkedHarvesters()
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)
{
Expand Down
1 change: 1 addition & 0 deletions OpenRA.Mods.RA/TraitsInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface IAcceptOre
{
void OnDock(Actor harv, DeliverResources dockOrder);
void GiveOre(int amount);
bool CanGiveOre(int amount);
int2 DeliverOffset { get; }
}

Expand Down
6 changes: 0 additions & 6 deletions mods/cnc/rules/structures.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit de5d9ab

Please sign in to comment.