Allow harvester definitions to exist on non-mobile actors
This commit is contained in:
committed by
Matthias Mailänder
parent
8e7fa26709
commit
d67e0a4eef
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
Actor = actor;
|
Actor = actor;
|
||||||
Harvester = actor.Trait<Harvester>();
|
Harvester = actor.Trait<Harvester>();
|
||||||
Parachutable = actor.TraitOrDefault<Parachutable>();
|
Parachutable = actor.TraitOrDefault<Parachutable>();
|
||||||
Mobile = actor.Trait<Mobile>();
|
Mobile = actor.TraitOrDefault<Mobile>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,6 +110,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
// Find idle harvesters and give them orders:
|
// Find idle harvesters and give them orders:
|
||||||
foreach (var h in harvesters)
|
foreach (var h in harvesters)
|
||||||
{
|
{
|
||||||
|
if (h.Value.Mobile == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (!h.Key.IsIdle)
|
if (!h.Key.IsIdle)
|
||||||
{
|
{
|
||||||
// Ignore this actor if FindAndDeliverResources is working fine or it is performing a different activity
|
// Ignore this actor if FindAndDeliverResources is working fine or it is performing a different activity
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
public class HarvesterInfo : DockClientBaseInfo, Requires<MobileInfo>, Requires<IStoresResourcesInfo>, IRulesetLoaded
|
public class HarvesterInfo : DockClientBaseInfo, Requires<IStoresResourcesInfo>, IRulesetLoaded
|
||||||
{
|
{
|
||||||
[Desc("Docking type")]
|
[Desc("Docking type")]
|
||||||
public readonly BitSet<DockType> Type = new("Unload");
|
public readonly BitSet<DockType> Type = new("Unload");
|
||||||
@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public class Harvester : DockClientBase<HarvesterInfo>, IIssueOrder, IResolveOrder, IOrderVoice,
|
public class Harvester : DockClientBase<HarvesterInfo>, IIssueOrder, IResolveOrder, IOrderVoice,
|
||||||
ISpeedModifier, ISync, INotifyCreated
|
ISpeedModifier, ISync, INotifyCreated
|
||||||
{
|
{
|
||||||
readonly Mobile mobile;
|
Mobile mobile;
|
||||||
readonly IResourceLayer resourceLayer;
|
readonly IResourceLayer resourceLayer;
|
||||||
readonly ResourceClaimLayer claimLayer;
|
readonly ResourceClaimLayer claimLayer;
|
||||||
readonly IStoresResources[] storesResources;
|
readonly IStoresResources[] storesResources;
|
||||||
@@ -104,7 +104,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public Harvester(Actor self, HarvesterInfo info)
|
public Harvester(Actor self, HarvesterInfo info)
|
||||||
: base(self, info)
|
: base(self, info)
|
||||||
{
|
{
|
||||||
mobile = self.Trait<Mobile>();
|
|
||||||
storesResources = self.TraitsImplementing<IStoresResources>().Where(sr => info.Resources.Any(r => sr.HasType(r))).ToArray();
|
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>();
|
||||||
@@ -112,10 +111,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
protected override void Created(Actor self)
|
protected override void Created(Actor self)
|
||||||
{
|
{
|
||||||
|
mobile = self.TraitOrDefault<Mobile>();
|
||||||
UpdateCondition(self);
|
UpdateCondition(self);
|
||||||
|
|
||||||
// Note: This is queued in a FrameEndTask because otherwise the activity is dropped/overridden while moving out of a factory.
|
// Note: This is queued in a FrameEndTask because otherwise the activity is dropped/overridden while moving out of a factory.
|
||||||
if (Info.SearchOnCreation)
|
if (Info.SearchOnCreation && mobile != null)
|
||||||
self.World.AddFrameEndTask(w => self.QueueActivity(new FindAndDeliverResources(self)));
|
self.World.AddFrameEndTask(w => self.QueueActivity(new FindAndDeliverResources(self)));
|
||||||
|
|
||||||
base.Created(self);
|
base.Created(self);
|
||||||
@@ -218,7 +218,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (IsTraitDisabled)
|
if (IsTraitDisabled || mobile == null)
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
yield return new HarvestOrderTargeter();
|
yield return new HarvestOrderTargeter();
|
||||||
@@ -235,7 +235,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
string IOrderVoice.VoicePhraseForOrder(Actor self, Order order)
|
string IOrderVoice.VoicePhraseForOrder(Actor self, Order order)
|
||||||
{
|
{
|
||||||
if (order.OrderString == "Harvest")
|
if (order.OrderString == "Harvest" && mobile != null)
|
||||||
return Info.HarvestVoice;
|
return Info.HarvestVoice;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -243,7 +243,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
void IResolveOrder.ResolveOrder(Actor self, Order order)
|
void IResolveOrder.ResolveOrder(Actor self, Order order)
|
||||||
{
|
{
|
||||||
if (order.OrderString == "Harvest")
|
if (order.OrderString == "Harvest" && mobile != null)
|
||||||
{
|
{
|
||||||
CPos loc;
|
CPos loc;
|
||||||
if (order.Target.Type != TargetType.Invalid)
|
if (order.Target.Type != TargetType.Invalid)
|
||||||
|
|||||||
Reference in New Issue
Block a user