Implement instant refineries.

AKA RA2 refinery logic.
This commit is contained in:
Zimmermann Gyula
2017-04-18 11:45:28 +02:00
committed by reaperrr
parent a29360f313
commit cb36dfa532

View File

@@ -37,6 +37,9 @@ namespace OpenRA.Mods.Common.Traits
[Desc("In how many steps to perform the dragging?")] [Desc("In how many steps to perform the dragging?")]
public readonly int DragLength = 0; public readonly int DragLength = 0;
[Desc("Store resources in silos. Adds cash directly without storing if set to false.")]
public readonly bool UseStorage = true;
[Desc("Discard resources once silo capacity has been reached.")] [Desc("Discard resources once silo capacity has been reached.")]
public readonly bool DiscardExcessResources = false; public readonly bool DiscardExcessResources = false;
@@ -89,13 +92,20 @@ namespace OpenRA.Mods.Common.Traits
.Where(a => a.Trait.LinkedProc == self); .Where(a => a.Trait.LinkedProc == self);
} }
public bool CanGiveResource(int amount) { return info.DiscardExcessResources || playerResources.CanGiveResources(amount); } public bool CanGiveResource(int amount) { return !info.UseStorage || info.DiscardExcessResources || playerResources.CanGiveResources(amount); }
public void GiveResource(int amount) public void GiveResource(int amount)
{ {
if (info.DiscardExcessResources) if (info.UseStorage)
amount = Math.Min(amount, playerResources.ResourceCapacity - playerResources.Resources); {
playerResources.GiveResources(amount); if (info.DiscardExcessResources)
amount = Math.Min(amount, playerResources.ResourceCapacity - playerResources.Resources);
playerResources.GiveResources(amount);
}
else
playerResources.GiveCash(amount);
if (info.ShowTicks) if (info.ShowTicks)
currentDisplayValue += amount; currentDisplayValue += amount;
} }