Extract StoresResources from Harvester
This commit is contained in:
committed by
Matthias Mailänder
parent
60a446123b
commit
d427072cc9
@@ -173,7 +173,31 @@ namespace OpenRA.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
[RequireExplicitImplementation]
|
[RequireExplicitImplementation]
|
||||||
public interface IStoreResources { int Capacity { get; } }
|
public interface IStoresResourcesInfo : ITraitInfoInterface
|
||||||
|
{
|
||||||
|
string[] ResourceTypes { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IStoresResources
|
||||||
|
{
|
||||||
|
bool HasType(string resourceType);
|
||||||
|
|
||||||
|
/// <summary>The amount of resources that can be stored.</summary>
|
||||||
|
int Capacity { get; }
|
||||||
|
|
||||||
|
/// <summary>Stored resources.</summary>
|
||||||
|
/// <remarks>Dictionary key refers to resourceType, value refers to resource amount.</remarks>
|
||||||
|
IReadOnlyDictionary<string, int> Contents { get; }
|
||||||
|
|
||||||
|
/// <summary>A performance cheap method of getting the total sum of contents.</summary>
|
||||||
|
int ContentsSum { get; }
|
||||||
|
|
||||||
|
/// <summary>Returns the amount of <paramref name="value"/> that was not added.</summary>
|
||||||
|
int AddResource(string resourceType, int value);
|
||||||
|
|
||||||
|
/// <summary>Returns the amount of <paramref name="value"/> that was not removed.</summary>
|
||||||
|
int RemoveResource(string resourceType, int value);
|
||||||
|
}
|
||||||
|
|
||||||
public interface IEffectiveOwner
|
public interface IEffectiveOwner
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (resource.Type == null || resourceLayer.RemoveResource(resource.Type, self.Location) != 1)
|
if (resource.Type == null || resourceLayer.RemoveResource(resource.Type, self.Location) != 1)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
harv.AcceptResource(self, resource.Type);
|
harv.AddResource(self, resource.Type);
|
||||||
|
|
||||||
foreach (var t in notifyHarvestActions)
|
foreach (var t in notifyHarvestActions)
|
||||||
t.Harvested(self, resource.Type);
|
t.Harvested(self, resource.Type);
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Mods.Common.Activities;
|
using OpenRA.Mods.Common.Activities;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
@@ -19,7 +18,7 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
public class HarvesterInfo : DockClientBaseInfo, Requires<MobileInfo>
|
public class HarvesterInfo : DockClientBaseInfo, Requires<MobileInfo>, Requires<IStoresResourcesInfo>, IRulesetLoaded
|
||||||
{
|
{
|
||||||
[Desc("Docking type")]
|
[Desc("Docking type")]
|
||||||
public readonly BitSet<DockType> Type = new("Unload");
|
public readonly BitSet<DockType> Type = new("Unload");
|
||||||
@@ -27,9 +26,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Cell to move to when automatically unblocking DeliveryBuilding.")]
|
[Desc("Cell to move to when automatically unblocking DeliveryBuilding.")]
|
||||||
public readonly CVec UnblockCell = new(0, 4);
|
public readonly CVec UnblockCell = new(0, 4);
|
||||||
|
|
||||||
[Desc("How much resources it can carry.")]
|
|
||||||
public readonly int Capacity = 28;
|
|
||||||
|
|
||||||
public readonly int BaleLoadDelay = 4;
|
public readonly int BaleLoadDelay = 4;
|
||||||
|
|
||||||
[Desc("How fast it can dump its bales.")]
|
[Desc("How fast it can dump its bales.")]
|
||||||
@@ -41,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public readonly int HarvestFacings = 0;
|
public readonly int HarvestFacings = 0;
|
||||||
|
|
||||||
[Desc("Which resources it can harvest.")]
|
[Desc("Which resources it can harvest.")]
|
||||||
public readonly HashSet<string> Resources = new();
|
public readonly string[] Resources = Array.Empty<string>();
|
||||||
|
|
||||||
[Desc("Percentage of maximum speed when fully loaded.")]
|
[Desc("Percentage of maximum speed when fully loaded.")]
|
||||||
public readonly int FullyLoadedSpeed = 85;
|
public readonly int FullyLoadedSpeed = 85;
|
||||||
@@ -79,17 +75,25 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public readonly string HarvestCursor = "harvest";
|
public readonly string HarvestCursor = "harvest";
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new Harvester(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new Harvester(init.Self, this); }
|
||||||
|
|
||||||
|
void IRulesetLoaded<ActorInfo>.RulesetLoaded(Ruleset rules, ActorInfo info)
|
||||||
|
{
|
||||||
|
if (Resources.Length == 0)
|
||||||
|
throw new YamlException($"Harvester.{nameof(Resources)} is empty.");
|
||||||
|
|
||||||
|
var resourceTypes = Resources.Except(info.TraitInfos<IStoresResourcesInfo>().SelectMany(sr => sr.ResourceTypes)).ToArray();
|
||||||
|
if (resourceTypes.Length != 0)
|
||||||
|
throw new YamlException($"Invalid Harvester.{nameof(Resources)} types: {string.Join(',', resourceTypes)}.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Harvester : DockClientBase<HarvesterInfo>, IIssueOrder, IResolveOrder, IOrderVoice,
|
public class Harvester : DockClientBase<HarvesterInfo>, IIssueOrder, IResolveOrder, IOrderVoice,
|
||||||
ISpeedModifier, ISync, INotifyCreated
|
ISpeedModifier, ISync, INotifyCreated
|
||||||
{
|
{
|
||||||
public readonly IReadOnlyDictionary<string, int> Contents;
|
|
||||||
|
|
||||||
readonly Mobile mobile;
|
readonly Mobile mobile;
|
||||||
readonly IResourceLayer resourceLayer;
|
readonly IResourceLayer resourceLayer;
|
||||||
readonly ResourceClaimLayer claimLayer;
|
readonly ResourceClaimLayer claimLayer;
|
||||||
readonly Dictionary<string, int> contents = new();
|
readonly IStoresResources[] storesResources;
|
||||||
int conditionToken = Actor.InvalidConditionToken;
|
int conditionToken = Actor.InvalidConditionToken;
|
||||||
|
|
||||||
public override BitSet<DockType> GetDockType => Info.Type;
|
public override BitSet<DockType> GetDockType => Info.Type;
|
||||||
@@ -97,23 +101,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Sync]
|
[Sync]
|
||||||
int currentUnloadTicks;
|
int currentUnloadTicks;
|
||||||
|
|
||||||
[Sync]
|
|
||||||
public int ContentHash
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var value = 0;
|
|
||||||
foreach (var c in contents)
|
|
||||||
value += c.Value << c.Key.Length;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Harvester(Actor self, HarvesterInfo info)
|
public Harvester(Actor self, HarvesterInfo info)
|
||||||
: base(self, info)
|
: base(self, info)
|
||||||
{
|
{
|
||||||
Contents = new ReadOnlyDictionary<string, int>(contents);
|
|
||||||
mobile = self.Trait<Mobile>();
|
mobile = self.Trait<Mobile>();
|
||||||
|
storesResources = self.TraitsImplementing<IStoresResources>().Where(sr => info.Resources.Any(r => sr.HasType(r))).ToArray();
|
||||||
resourceLayer = self.World.WorldActor.Trait<IResourceLayer>();
|
resourceLayer = self.World.WorldActor.Trait<IResourceLayer>();
|
||||||
claimLayer = self.World.WorldActor.Trait<ResourceClaimLayer>();
|
claimLayer = self.World.WorldActor.Trait<ResourceClaimLayer>();
|
||||||
}
|
}
|
||||||
@@ -129,9 +121,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
base.Created(self);
|
base.Created(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsFull => contents.Values.Sum() == Info.Capacity;
|
public bool IsFull => storesResources.All(sr => sr.ContentsSum >= sr.Capacity);
|
||||||
public bool IsEmpty => contents.Values.Sum() == 0;
|
public bool IsEmpty => storesResources.All(sr => sr.ContentsSum == 0);
|
||||||
public int Fullness => contents.Values.Sum() * 100 / Info.Capacity;
|
public int Fullness => storesResources.Sum(sr => sr.ContentsSum * 100 / sr.Capacity) / storesResources.Length;
|
||||||
|
|
||||||
protected override bool CanDock()
|
protected override bool CanDock()
|
||||||
{
|
{
|
||||||
@@ -151,12 +143,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
conditionToken = self.RevokeCondition(conditionToken);
|
conditionToken = self.RevokeCondition(conditionToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AcceptResource(Actor self, string resourceType)
|
public void AddResource(Actor self, string resourceType)
|
||||||
{
|
{
|
||||||
if (!contents.ContainsKey(resourceType))
|
foreach (var sr in storesResources)
|
||||||
contents[resourceType] = 1;
|
if (sr.AddResource(resourceType, 1) == 0)
|
||||||
else
|
break;
|
||||||
contents[resourceType]++;
|
|
||||||
|
|
||||||
UpdateCondition(self);
|
UpdateCondition(self);
|
||||||
}
|
}
|
||||||
@@ -177,27 +168,23 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (--currentUnloadTicks > 0)
|
if (--currentUnloadTicks > 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (contents.Keys.Count > 0)
|
foreach (var sr in storesResources)
|
||||||
{
|
{
|
||||||
foreach (var c in contents)
|
foreach (var c in sr.Contents)
|
||||||
{
|
{
|
||||||
var resourceType = c.Key;
|
|
||||||
var count = Math.Min(c.Value, Info.BaleUnloadAmount);
|
var count = Math.Min(c.Value, Info.BaleUnloadAmount);
|
||||||
var accepted = acceptResources.AcceptResources(hostActor, resourceType, count);
|
var accepted = acceptResources.AcceptResources(hostActor, c.Key, count);
|
||||||
if (accepted == 0)
|
if (accepted == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
contents[resourceType] -= accepted;
|
sr.RemoveResource(c.Key, accepted);
|
||||||
if (contents[resourceType] <= 0)
|
|
||||||
contents.Remove(resourceType);
|
|
||||||
|
|
||||||
currentUnloadTicks = Info.BaleUnloadDelay;
|
currentUnloadTicks = Info.BaleUnloadDelay;
|
||||||
UpdateCondition(self);
|
UpdateCondition(self);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return contents.Count == 0;
|
return IsEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnDockCompleted(Actor self, Actor hostActor, IDockHost dock)
|
public override void OnDockCompleted(Actor self, Actor hostActor, IDockHost dock)
|
||||||
@@ -279,13 +266,12 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
int ISpeedModifier.GetSpeedModifier()
|
int ISpeedModifier.GetSpeedModifier()
|
||||||
{
|
{
|
||||||
return 100 - (100 - Info.FullyLoadedSpeed) * contents.Values.Sum() / Info.Capacity;
|
return 100 - (100 - Info.FullyLoadedSpeed) * Fullness / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void TraitDisabled(Actor self)
|
protected override void TraitDisabled(Actor self)
|
||||||
{
|
{
|
||||||
base.TraitDisabled(self);
|
base.TraitDisabled(self);
|
||||||
contents.Clear();
|
|
||||||
|
|
||||||
if (conditionToken != Actor.InvalidConditionToken)
|
if (conditionToken != Actor.InvalidConditionToken)
|
||||||
conditionToken = self.RevokeCondition(conditionToken);
|
conditionToken = self.RevokeCondition(conditionToken);
|
||||||
|
|||||||
@@ -206,12 +206,12 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddStorage(int capacity)
|
public void AddStorageCapacity(int capacity)
|
||||||
{
|
{
|
||||||
ResourceCapacity += capacity;
|
ResourceCapacity += capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveStorage(int capacity)
|
public void RemoveStorageCapacity(int capacity)
|
||||||
{
|
{
|
||||||
ResourceCapacity -= capacity;
|
ResourceCapacity -= capacity;
|
||||||
|
|
||||||
|
|||||||
@@ -10,12 +10,13 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits.Render
|
namespace OpenRA.Mods.Common.Traits.Render
|
||||||
{
|
{
|
||||||
public class WithHarvesterPipsDecorationInfo : WithDecorationBaseInfo, Requires<HarvesterInfo>
|
public class WithStoresResourcesPipsDecorationInfo : WithDecorationBaseInfo, Requires<IStoresResourcesInfo>
|
||||||
{
|
{
|
||||||
[FieldLoader.Require]
|
[FieldLoader.Require]
|
||||||
[Desc("Number of pips to display how filled unit is.")]
|
[Desc("Number of pips to display how filled unit is.")]
|
||||||
@@ -42,26 +43,27 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
[PaletteReference]
|
[PaletteReference]
|
||||||
public readonly string Palette = "chrome";
|
public readonly string Palette = "chrome";
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new WithHarvesterPipsDecoration(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new WithStoresResourcesPipsDecoration(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WithHarvesterPipsDecoration : WithDecorationBase<WithHarvesterPipsDecorationInfo>
|
public class WithStoresResourcesPipsDecoration : WithDecorationBase<WithStoresResourcesPipsDecorationInfo>
|
||||||
{
|
{
|
||||||
readonly Harvester harvester;
|
readonly IStoresResources storesResources;
|
||||||
readonly Animation pips;
|
readonly Animation pips;
|
||||||
|
|
||||||
public WithHarvesterPipsDecoration(Actor self, WithHarvesterPipsDecorationInfo info)
|
public WithStoresResourcesPipsDecoration(Actor self, WithStoresResourcesPipsDecorationInfo info)
|
||||||
: base(self, info)
|
: base(self, info)
|
||||||
{
|
{
|
||||||
harvester = self.Trait<Harvester>();
|
// TODO: allow to choose which stores resources trait to target.
|
||||||
|
storesResources = self.TraitsImplementing<IStoresResources>().First();
|
||||||
pips = new Animation(self.World, info.Image);
|
pips = new Animation(self.World, info.Image);
|
||||||
}
|
}
|
||||||
|
|
||||||
string GetPipSequence(int i)
|
string GetPipSequence(int i)
|
||||||
{
|
{
|
||||||
var n = i * harvester.Info.Capacity / Info.PipCount;
|
var n = i * storesResources.Capacity / Info.PipCount;
|
||||||
|
|
||||||
foreach (var rt in harvester.Contents)
|
foreach (var rt in storesResources.Contents)
|
||||||
{
|
{
|
||||||
if (n < rt.Value)
|
if (n < rt.Value)
|
||||||
{
|
{
|
||||||
67
OpenRA.Mods.Common/Traits/StoresPlayerResources.cs
Normal file
67
OpenRA.Mods.Common/Traits/StoresPlayerResources.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright (c) The OpenRA Developers and Contributors
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation, either version 3 of
|
||||||
|
* the License, or (at your option) any later version. For more
|
||||||
|
* information, see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using OpenRA.Primitives;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Traits
|
||||||
|
{
|
||||||
|
[Desc("Adds capacity to a player's harvested resource limit.")]
|
||||||
|
public class StoresPlayerResourcesInfo : TraitInfo
|
||||||
|
{
|
||||||
|
[FieldLoader.Require]
|
||||||
|
public readonly int Capacity = 0;
|
||||||
|
|
||||||
|
public override object Create(ActorInitializer init) { return new StoresPlayerResources(init.Self, this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class StoresPlayerResources : INotifyOwnerChanged, INotifyCapture, INotifyKilled, INotifyAddedToWorld, INotifyRemovedFromWorld
|
||||||
|
{
|
||||||
|
readonly StoresPlayerResourcesInfo info;
|
||||||
|
PlayerResources player;
|
||||||
|
|
||||||
|
public int Stored => player.ResourceCapacity == 0 ? 0 : (int)((long)info.Capacity * player.Resources / player.ResourceCapacity);
|
||||||
|
|
||||||
|
public StoresPlayerResources(Actor self, StoresPlayerResourcesInfo info)
|
||||||
|
{
|
||||||
|
this.info = info;
|
||||||
|
player = self.Owner.PlayerActor.Trait<PlayerResources>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||||
|
{
|
||||||
|
player = newOwner.PlayerActor.Trait<PlayerResources>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner, BitSet<CaptureType> captureTypes)
|
||||||
|
{
|
||||||
|
var resources = Stored;
|
||||||
|
oldOwner.PlayerActor.Trait<PlayerResources>().TakeResources(resources);
|
||||||
|
newOwner.PlayerActor.Trait<PlayerResources>().GiveResources(resources);
|
||||||
|
}
|
||||||
|
|
||||||
|
void INotifyKilled.Killed(Actor self, AttackInfo e)
|
||||||
|
{
|
||||||
|
// Lose the stored resources.
|
||||||
|
player.TakeResources(Stored);
|
||||||
|
}
|
||||||
|
|
||||||
|
void INotifyAddedToWorld.AddedToWorld(Actor self)
|
||||||
|
{
|
||||||
|
player.AddStorageCapacity(info.Capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void INotifyRemovedFromWorld.RemovedFromWorld(Actor self)
|
||||||
|
{
|
||||||
|
player.RemoveStorageCapacity(info.Capacity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,62 +9,100 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using OpenRA.Primitives;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Linq;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Adds capacity to a player's harvested resource limit.")]
|
[Desc("Allows the storage of resources.")]
|
||||||
public class StoresResourcesInfo : TraitInfo
|
public class StoresResourcesInfo : TraitInfo, IStoresResourcesInfo
|
||||||
{
|
{
|
||||||
[FieldLoader.Require]
|
[FieldLoader.Require]
|
||||||
public readonly int Capacity = 0;
|
[Desc("The amounts of resources that can be stored.")]
|
||||||
|
public readonly int Capacity = 28;
|
||||||
|
|
||||||
|
[Desc("Which resources can be stored.")]
|
||||||
|
public readonly string[] Resources = Array.Empty<string>();
|
||||||
|
|
||||||
|
string[] IStoresResourcesInfo.ResourceTypes => Resources;
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new StoresResources(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new StoresResources(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class StoresResources : INotifyOwnerChanged, INotifyCapture, IStoreResources, ISync, INotifyKilled, INotifyAddedToWorld, INotifyRemovedFromWorld
|
public class StoresResources : IStoresResources, ISync
|
||||||
{
|
{
|
||||||
|
readonly Dictionary<string, int> contents = new();
|
||||||
readonly StoresResourcesInfo info;
|
readonly StoresResourcesInfo info;
|
||||||
PlayerResources player;
|
|
||||||
|
|
||||||
[Sync]
|
[Sync]
|
||||||
public int Stored => player.ResourceCapacity == 0 ? 0 : (int)((long)info.Capacity * player.Resources / player.ResourceCapacity);
|
public int ContentHash
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var value = 0;
|
||||||
|
foreach (var c in contents)
|
||||||
|
value += c.Value << c.Key.Length;
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ContentsSum { get; private set; } = 0;
|
||||||
|
public IReadOnlyDictionary<string, int> Contents { get; }
|
||||||
|
int IStoresResources.Capacity => info.Capacity;
|
||||||
|
|
||||||
public StoresResources(Actor self, StoresResourcesInfo info)
|
public StoresResources(Actor self, StoresResourcesInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
player = self.Owner.PlayerActor.Trait<PlayerResources>();
|
|
||||||
|
foreach (var r in info.Resources)
|
||||||
|
contents[r] = 0;
|
||||||
|
|
||||||
|
Contents = new ReadOnlyDictionary<string, int>(contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
int IStoreResources.Capacity => info.Capacity;
|
public bool HasType(string resourceType)
|
||||||
|
|
||||||
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
|
||||||
{
|
{
|
||||||
player = newOwner.PlayerActor.Trait<PlayerResources>();
|
return info.Resources.Contains(resourceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner, BitSet<CaptureType> captureTypes)
|
int IStoresResources.AddResource(string resourceType, int value)
|
||||||
{
|
{
|
||||||
var resources = Stored;
|
if (!HasType(resourceType))
|
||||||
oldOwner.PlayerActor.Trait<PlayerResources>().TakeResources(resources);
|
return value;
|
||||||
newOwner.PlayerActor.Trait<PlayerResources>().GiveResources(resources);
|
|
||||||
|
if (ContentsSum + value > info.Capacity)
|
||||||
|
{
|
||||||
|
var added = info.Capacity - ContentsSum;
|
||||||
|
contents[resourceType] += added;
|
||||||
|
ContentsSum = info.Capacity;
|
||||||
|
return value - added;
|
||||||
|
}
|
||||||
|
|
||||||
|
contents[resourceType] += value;
|
||||||
|
ContentsSum += value;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyKilled.Killed(Actor self, AttackInfo e)
|
int IStoresResources.RemoveResource(string resourceType, int value)
|
||||||
{
|
{
|
||||||
// Lose the stored resources
|
if (!HasType(resourceType))
|
||||||
player.TakeResources(Stored);
|
return value;
|
||||||
}
|
|
||||||
|
|
||||||
void INotifyAddedToWorld.AddedToWorld(Actor self)
|
if (contents[resourceType] < value)
|
||||||
{
|
{
|
||||||
player.AddStorage(info.Capacity);
|
var leftover = value - contents[resourceType];
|
||||||
}
|
ContentsSum -= contents[resourceType];
|
||||||
|
contents[resourceType] = 0;
|
||||||
|
return leftover;
|
||||||
|
}
|
||||||
|
|
||||||
void INotifyRemovedFromWorld.RemovedFromWorld(Actor self)
|
contents[resourceType] -= value;
|
||||||
{
|
ContentsSum -= value;
|
||||||
player.RemoveStorage(info.Capacity);
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright (c) The OpenRA Developers and Contributors
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation, either version 3 of
|
||||||
|
* the License, or (at your option) any later version. For more
|
||||||
|
* information, see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.UpdateRules.Rules
|
||||||
|
{
|
||||||
|
public class ExtractResourceStorageFromHarvester : UpdateRule
|
||||||
|
{
|
||||||
|
public override string Name => "Renames StoresResources to StoresPlayerResources and extracts StoresResources from Harvester.";
|
||||||
|
|
||||||
|
public override string Description =>
|
||||||
|
"Resource storage was extracted from Harvester. WithHarvesterPipsDecoration was also renamed to WithStoresResourcesPipsDecoration.";
|
||||||
|
|
||||||
|
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNodeBuilder actorNode)
|
||||||
|
{
|
||||||
|
actorNode.RenameChildrenMatching("StoresResources", "StoresPlayerResources");
|
||||||
|
actorNode.RenameChildrenMatching("WithHarvesterPipsDecoration", "WithStoresResourcesPipsDecoration");
|
||||||
|
|
||||||
|
var harvester = actorNode.LastChildMatching("Harvester", false);
|
||||||
|
if (harvester == null)
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
var storesResources = new MiniYamlNodeBuilder("StoresResources", "");
|
||||||
|
var capacity = harvester.LastChildMatching("Capacity", false);
|
||||||
|
if (capacity != null)
|
||||||
|
{
|
||||||
|
storesResources.AddNode(capacity);
|
||||||
|
harvester.RemoveNode(capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
var resources = harvester.LastChildMatching("Resources", false);
|
||||||
|
if (resources != null)
|
||||||
|
storesResources.AddNode(resources);
|
||||||
|
|
||||||
|
actorNode.AddNode(storesResources);
|
||||||
|
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -109,6 +109,7 @@ namespace OpenRA.Mods.Common.UpdateRules
|
|||||||
{
|
{
|
||||||
// bleed only changes here.
|
// bleed only changes here.
|
||||||
new RemoveValidRelationsFromCapturable(),
|
new RemoveValidRelationsFromCapturable(),
|
||||||
|
new ExtractResourceStorageFromHarvester(),
|
||||||
|
|
||||||
// Execute these rules last to avoid premature yaml merge crashes.
|
// Execute these rules last to avoid premature yaml merge crashes.
|
||||||
new AbstractDocking(),
|
new AbstractDocking(),
|
||||||
|
|||||||
@@ -219,7 +219,7 @@
|
|||||||
red: pip-red
|
red: pip-red
|
||||||
|
|
||||||
^StoresResources:
|
^StoresResources:
|
||||||
StoresResources:
|
StoresPlayerResources:
|
||||||
WithResourceStoragePipsDecoration:
|
WithResourceStoragePipsDecoration:
|
||||||
Position: BottomLeft
|
Position: BottomLeft
|
||||||
Margin: 4, 3
|
Margin: 4, 3
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ PROC:
|
|||||||
IsDragRequired: True
|
IsDragRequired: True
|
||||||
DragOffset: -554,512,0
|
DragOffset: -554,512,0
|
||||||
DragLength: 12
|
DragLength: 12
|
||||||
StoresResources:
|
StoresPlayerResources:
|
||||||
Capacity: 1000
|
Capacity: 1000
|
||||||
Selectable:
|
Selectable:
|
||||||
Bounds: 3072, 2389
|
Bounds: 3072, 2389
|
||||||
@@ -291,7 +291,7 @@ SILO:
|
|||||||
-WithSpriteBody:
|
-WithSpriteBody:
|
||||||
WithResourceLevelSpriteBody:
|
WithResourceLevelSpriteBody:
|
||||||
Sequence: stages
|
Sequence: stages
|
||||||
StoresResources:
|
StoresPlayerResources:
|
||||||
Capacity: 3000
|
Capacity: 3000
|
||||||
-SpawnActorsOnSell:
|
-SpawnActorsOnSell:
|
||||||
Power:
|
Power:
|
||||||
|
|||||||
@@ -56,13 +56,15 @@ HARV:
|
|||||||
DecorationBounds: 1536, 1536
|
DecorationBounds: 1536, 1536
|
||||||
Harvester:
|
Harvester:
|
||||||
Resources: Tiberium, BlueTiberium
|
Resources: Tiberium, BlueTiberium
|
||||||
Capacity: 20
|
|
||||||
BaleLoadDelay: 12
|
BaleLoadDelay: 12
|
||||||
BaleUnloadDelay: 6
|
BaleUnloadDelay: 6
|
||||||
SearchFromProcRadius: 15
|
SearchFromProcRadius: 15
|
||||||
SearchFromHarvesterRadius: 8
|
SearchFromHarvesterRadius: 8
|
||||||
HarvestFacings: 8
|
HarvestFacings: 8
|
||||||
EmptyCondition: no-tiberium
|
EmptyCondition: no-tiberium
|
||||||
|
StoresResources:
|
||||||
|
Capacity: 20
|
||||||
|
Resources: Tiberium, BlueTiberium
|
||||||
DockClientManager:
|
DockClientManager:
|
||||||
Mobile:
|
Mobile:
|
||||||
Speed: 72
|
Speed: 72
|
||||||
@@ -89,7 +91,7 @@ HARV:
|
|||||||
Explodes:
|
Explodes:
|
||||||
RequiresCondition: !no-tiberium
|
RequiresCondition: !no-tiberium
|
||||||
Weapon: TiberiumExplosion
|
Weapon: TiberiumExplosion
|
||||||
WithHarvesterPipsDecoration:
|
WithStoresResourcesPipsDecoration:
|
||||||
Position: BottomLeft
|
Position: BottomLeft
|
||||||
Margin: 4, 3
|
Margin: 4, 3
|
||||||
RequiresSelection: true
|
RequiresSelection: true
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ refinery:
|
|||||||
Type: Unload
|
Type: Unload
|
||||||
DockAngle: 640
|
DockAngle: 640
|
||||||
DockOffset: 1c0,512,0
|
DockOffset: 1c0,512,0
|
||||||
StoresResources:
|
StoresPlayerResources:
|
||||||
Capacity: 2000
|
Capacity: 2000
|
||||||
CustomSellValue:
|
CustomSellValue:
|
||||||
Value: 500
|
Value: 500
|
||||||
@@ -357,7 +357,7 @@ silo:
|
|||||||
-WithSpriteBody:
|
-WithSpriteBody:
|
||||||
WithResourceLevelSpriteBody:
|
WithResourceLevelSpriteBody:
|
||||||
Sequence: stages
|
Sequence: stages
|
||||||
StoresResources:
|
StoresPlayerResources:
|
||||||
Capacity: 2000
|
Capacity: 2000
|
||||||
-SpawnActorsOnSell:
|
-SpawnActorsOnSell:
|
||||||
Power:
|
Power:
|
||||||
|
|||||||
@@ -70,12 +70,14 @@ harvester:
|
|||||||
Class: harvester
|
Class: harvester
|
||||||
DecorationBounds: 1344, 1344
|
DecorationBounds: 1344, 1344
|
||||||
Harvester:
|
Harvester:
|
||||||
Capacity: 28
|
|
||||||
HarvestFacings: 8
|
HarvestFacings: 8
|
||||||
Resources: Spice
|
Resources: Spice
|
||||||
BaleUnloadDelay: 5
|
BaleUnloadDelay: 5
|
||||||
SearchFromProcRadius: 30
|
SearchFromProcRadius: 30
|
||||||
SearchFromHarvesterRadius: 15
|
SearchFromHarvesterRadius: 15
|
||||||
|
StoresResources:
|
||||||
|
Capacity: 28
|
||||||
|
Resources: Spice
|
||||||
DockClientManager:
|
DockClientManager:
|
||||||
CarryableHarvester:
|
CarryableHarvester:
|
||||||
Health:
|
Health:
|
||||||
@@ -107,7 +109,7 @@ harvester:
|
|||||||
Delay: 3
|
Delay: 3
|
||||||
StartIfBelow: 50
|
StartIfBelow: 50
|
||||||
-RevealOnFire:
|
-RevealOnFire:
|
||||||
WithHarvesterPipsDecoration:
|
WithStoresResourcesPipsDecoration:
|
||||||
Position: BottomLeft
|
Position: BottomLeft
|
||||||
Margin: 1, 4
|
Margin: 1, 4
|
||||||
RequiresSelection: true
|
RequiresSelection: true
|
||||||
|
|||||||
@@ -1290,7 +1290,7 @@ PROC:
|
|||||||
Type: Unload
|
Type: Unload
|
||||||
DockAngle: 256
|
DockAngle: 256
|
||||||
DockOffset: 0, 1c0, 0
|
DockOffset: 0, 1c0, 0
|
||||||
StoresResources:
|
StoresPlayerResources:
|
||||||
Capacity: 2000
|
Capacity: 2000
|
||||||
CustomSellValue:
|
CustomSellValue:
|
||||||
Value: 300
|
Value: 300
|
||||||
@@ -1375,7 +1375,7 @@ SILO:
|
|||||||
-WithSpriteBody:
|
-WithSpriteBody:
|
||||||
WithResourceLevelSpriteBody:
|
WithResourceLevelSpriteBody:
|
||||||
Sequence: stages
|
Sequence: stages
|
||||||
StoresResources:
|
StoresPlayerResources:
|
||||||
Capacity: 3000
|
Capacity: 3000
|
||||||
-SpawnActorsOnSell:
|
-SpawnActorsOnSell:
|
||||||
Power:
|
Power:
|
||||||
|
|||||||
@@ -320,13 +320,15 @@ HARV:
|
|||||||
Selectable:
|
Selectable:
|
||||||
DecorationBounds: 1792, 1792
|
DecorationBounds: 1792, 1792
|
||||||
Harvester:
|
Harvester:
|
||||||
Capacity: 20
|
|
||||||
Resources: Ore,Gems
|
Resources: Ore,Gems
|
||||||
BaleUnloadDelay: 1
|
BaleUnloadDelay: 1
|
||||||
SearchFromProcRadius: 15
|
SearchFromProcRadius: 15
|
||||||
SearchFromHarvesterRadius: 8
|
SearchFromHarvesterRadius: 8
|
||||||
HarvestFacings: 8
|
HarvestFacings: 8
|
||||||
EmptyCondition: no-ore
|
EmptyCondition: no-ore
|
||||||
|
StoresResources:
|
||||||
|
Capacity: 20
|
||||||
|
Resources: Ore,Gems
|
||||||
DockClientManager:
|
DockClientManager:
|
||||||
Health:
|
Health:
|
||||||
HP: 60000
|
HP: 60000
|
||||||
@@ -357,7 +359,7 @@ HARV:
|
|||||||
WithHarvesterSpriteBody:
|
WithHarvesterSpriteBody:
|
||||||
ImageByFullness: harvempty, harvhalf, harv
|
ImageByFullness: harvempty, harvhalf, harv
|
||||||
-WithFacingSpriteBody:
|
-WithFacingSpriteBody:
|
||||||
WithHarvesterPipsDecoration:
|
WithStoresResourcesPipsDecoration:
|
||||||
Position: BottomLeft
|
Position: BottomLeft
|
||||||
Margin: 4, 3
|
Margin: 4, 3
|
||||||
RequiresSelection: true
|
RequiresSelection: true
|
||||||
|
|||||||
@@ -593,7 +593,7 @@ NAWAST:
|
|||||||
Type: UnloadWeed
|
Type: UnloadWeed
|
||||||
DockAngle: 640
|
DockAngle: 640
|
||||||
DockOffset: 724,724,0
|
DockOffset: 724,724,0
|
||||||
StoresResources:
|
StoresPlayerResources:
|
||||||
Capacity: 56
|
Capacity: 56
|
||||||
Power:
|
Power:
|
||||||
Amount: -40
|
Amount: -40
|
||||||
|
|||||||
@@ -352,13 +352,15 @@ WEED:
|
|||||||
Description: Collects veins for processing.\n Unarmed
|
Description: Collects veins for processing.\n Unarmed
|
||||||
Harvester:
|
Harvester:
|
||||||
Type: UnloadWeed
|
Type: UnloadWeed
|
||||||
Capacity: 7
|
|
||||||
Resources: Veins
|
Resources: Veins
|
||||||
BaleUnloadDelay: 20
|
BaleUnloadDelay: 20
|
||||||
BaleLoadDelay: 40
|
BaleLoadDelay: 40
|
||||||
SearchFromProcRadius: 72
|
SearchFromProcRadius: 72
|
||||||
SearchFromHarvesterRadius: 36
|
SearchFromHarvesterRadius: 36
|
||||||
HarvestVoice: Attack
|
HarvestVoice: Attack
|
||||||
|
StoresResources:
|
||||||
|
Capacity: 7
|
||||||
|
Resources: Veins
|
||||||
DockClientManager:
|
DockClientManager:
|
||||||
Voice: Move
|
Voice: Move
|
||||||
Mobile:
|
Mobile:
|
||||||
@@ -381,7 +383,7 @@ WEED:
|
|||||||
WithVoxelUnloadBody:
|
WithVoxelUnloadBody:
|
||||||
-DamagedByTerrain@VEINS:
|
-DamagedByTerrain@VEINS:
|
||||||
-LeavesTrails@VEINS:
|
-LeavesTrails@VEINS:
|
||||||
WithHarvesterPipsDecoration:
|
WithStoresResourcesPipsDecoration:
|
||||||
Position: BottomLeft
|
Position: BottomLeft
|
||||||
RequiresSelection: true
|
RequiresSelection: true
|
||||||
Margin: 5, 2
|
Margin: 5, 2
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ PROC:
|
|||||||
Type: Unload
|
Type: Unload
|
||||||
DockAngle: 640
|
DockAngle: 640
|
||||||
DockOffset: 362,362,0
|
DockOffset: 362,362,0
|
||||||
StoresResources:
|
StoresPlayerResources:
|
||||||
Capacity: 2000
|
Capacity: 2000
|
||||||
CustomSellValue:
|
CustomSellValue:
|
||||||
Value: 600
|
Value: 600
|
||||||
@@ -211,7 +211,7 @@ GASILO:
|
|||||||
RequiresCondition: !build-incomplete
|
RequiresCondition: !build-incomplete
|
||||||
Sequence: idle-lights-bright
|
Sequence: idle-lights-bright
|
||||||
Palette: bright
|
Palette: bright
|
||||||
StoresResources:
|
StoresPlayerResources:
|
||||||
Capacity: 1500
|
Capacity: 1500
|
||||||
Power:
|
Power:
|
||||||
Amount: -10
|
Amount: -10
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ HARV:
|
|||||||
Bounds: 1086, 2172
|
Bounds: 1086, 2172
|
||||||
DecorationBounds: 1086, 2172
|
DecorationBounds: 1086, 2172
|
||||||
Harvester:
|
Harvester:
|
||||||
Capacity: 28
|
|
||||||
Resources: Tiberium, BlueTiberium
|
Resources: Tiberium, BlueTiberium
|
||||||
BaleLoadDelay: 15
|
BaleLoadDelay: 15
|
||||||
BaleUnloadDelay: 15
|
BaleUnloadDelay: 15
|
||||||
@@ -68,6 +67,9 @@ HARV:
|
|||||||
SearchFromHarvesterRadius: 18
|
SearchFromHarvesterRadius: 18
|
||||||
HarvestVoice: Attack
|
HarvestVoice: Attack
|
||||||
EmptyCondition: no-tiberium
|
EmptyCondition: no-tiberium
|
||||||
|
StoresResources:
|
||||||
|
Capacity: 28
|
||||||
|
Resources: Tiberium, BlueTiberium
|
||||||
DockClientManager:
|
DockClientManager:
|
||||||
Voice: Move
|
Voice: Move
|
||||||
Mobile:
|
Mobile:
|
||||||
@@ -100,7 +102,7 @@ HARV:
|
|||||||
nod: harv.nod
|
nod: harv.nod
|
||||||
-DamagedByTerrain@VEINS:
|
-DamagedByTerrain@VEINS:
|
||||||
-LeavesTrails@VEINS:
|
-LeavesTrails@VEINS:
|
||||||
WithHarvesterPipsDecoration:
|
WithStoresResourcesPipsDecoration:
|
||||||
Position: BottomLeft
|
Position: BottomLeft
|
||||||
RequiresSelection: true
|
RequiresSelection: true
|
||||||
Margin: 5, 2
|
Margin: 5, 2
|
||||||
|
|||||||
Reference in New Issue
Block a user