Make Harvester conditional.
This commit is contained in:
committed by
abcdefg30
parent
cd90c70cdf
commit
dcb70d12e3
@@ -43,6 +43,9 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
public override bool Tick(Actor self)
|
||||
{
|
||||
if (harv.IsTraitDisabled)
|
||||
Cancel(self, true);
|
||||
|
||||
if (IsCanceling)
|
||||
return true;
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
public override bool Tick(Actor self)
|
||||
{
|
||||
if (IsCanceling)
|
||||
if (IsCanceling || harv.IsTraitDisabled)
|
||||
return true;
|
||||
|
||||
if (NextActivity != null)
|
||||
|
||||
@@ -53,6 +53,9 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
public override bool Tick(Actor self)
|
||||
{
|
||||
if (harv.IsTraitDisabled)
|
||||
Cancel(self, true);
|
||||
|
||||
if (IsCanceling || harv.IsFull)
|
||||
return true;
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return false;
|
||||
|
||||
case DockingState.Drag:
|
||||
if (IsCanceling || !Refinery.IsInWorld || Refinery.IsDead)
|
||||
if (IsCanceling || !Refinery.IsInWorld || Refinery.IsDead || Harv.IsTraitDisabled)
|
||||
return true;
|
||||
|
||||
dockingState = DockingState.Dock;
|
||||
@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return false;
|
||||
|
||||
case DockingState.Dock:
|
||||
if (!IsCanceling && Refinery.IsInWorld && !Refinery.IsDead)
|
||||
if (!IsCanceling && Refinery.IsInWorld && !Refinery.IsDead && !Harv.IsTraitDisabled)
|
||||
OnStateDock(self);
|
||||
else
|
||||
dockingState = DockingState.Undock;
|
||||
@@ -77,7 +77,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return false;
|
||||
|
||||
case DockingState.Loop:
|
||||
if (IsCanceling || !Refinery.IsInWorld || Refinery.IsDead || Harv.TickUnload(self, Refinery))
|
||||
if (IsCanceling || !Refinery.IsInWorld || Refinery.IsDead || Harv.IsTraitDisabled || Harv.TickUnload(self, Refinery))
|
||||
dockingState = DockingState.Undock;
|
||||
|
||||
return false;
|
||||
|
||||
@@ -22,7 +22,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class HarvesterInfo : TraitInfo, Requires<MobileInfo>
|
||||
public class HarvesterInfo : ConditionalTraitInfo, Requires<MobileInfo>
|
||||
{
|
||||
public readonly HashSet<string> DeliveryBuildings = new HashSet<string>();
|
||||
|
||||
@@ -106,10 +106,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public override object Create(ActorInitializer init) { return new Harvester(init.Self, this); }
|
||||
}
|
||||
|
||||
public class Harvester : IIssueOrder, IResolveOrder, IOrderVoice,
|
||||
public class Harvester : ConditionalTrait<HarvesterInfo>, IIssueOrder, IResolveOrder, IOrderVoice,
|
||||
ISpeedModifier, ISync, INotifyCreated
|
||||
{
|
||||
public readonly HarvesterInfo Info;
|
||||
public readonly IReadOnlyDictionary<string, int> Contents;
|
||||
|
||||
readonly Mobile mobile;
|
||||
@@ -140,21 +139,23 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
public Harvester(Actor self, HarvesterInfo info)
|
||||
: base(info)
|
||||
{
|
||||
Info = info;
|
||||
Contents = new ReadOnlyDictionary<string, int>(contents);
|
||||
mobile = self.Trait<Mobile>();
|
||||
resourceLayer = self.World.WorldActor.Trait<IResourceLayer>();
|
||||
claimLayer = self.World.WorldActor.Trait<ResourceClaimLayer>();
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
protected override void Created(Actor self)
|
||||
{
|
||||
UpdateCondition(self);
|
||||
|
||||
// Note: This is queued in a FrameEndTask because otherwise the activity is dropped/overridden while moving out of a factory.
|
||||
if (Info.SearchOnCreation)
|
||||
self.World.AddFrameEndTask(w => self.QueueActivity(new FindAndDeliverResources(self)));
|
||||
|
||||
base.Created(self);
|
||||
}
|
||||
|
||||
public void LinkProc(Actor self, Actor proc)
|
||||
@@ -294,6 +295,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsTraitDisabled)
|
||||
yield break;
|
||||
|
||||
yield return new EnterAlliedActorTargeter<IAcceptResourcesInfo>(
|
||||
"Deliver",
|
||||
5,
|
||||
@@ -370,6 +374,16 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return 100 - (100 - Info.FullyLoadedSpeed) * contents.Values.Sum() / Info.Capacity;
|
||||
}
|
||||
|
||||
protected override void TraitDisabled(Actor self)
|
||||
{
|
||||
LastLinkedProc = null;
|
||||
LinkedProc = null;
|
||||
contents.Clear();
|
||||
|
||||
if (conditionToken != Actor.InvalidConditionToken)
|
||||
conditionToken = self.RevokeCondition(conditionToken);
|
||||
}
|
||||
|
||||
class HarvestOrderTargeter : IOrderTargeter
|
||||
{
|
||||
public string OrderID => "Harvest";
|
||||
|
||||
@@ -407,7 +407,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
template.Get<LabelWidget>("ASSETS").GetText = () => assetsText.Update(stats.AssetsValue);
|
||||
|
||||
var harvesters = template.Get<LabelWidget>("HARVESTERS");
|
||||
harvesters.GetText = () => world.ActorsHavingTrait<Harvester>().Count(a => a.Owner == player && !a.IsDead).ToString();
|
||||
harvesters.GetText = () => world.ActorsWithTrait<Harvester>().Count(a => a.Actor.Owner == player && !a.Actor.IsDead && !a.Trait.IsTraitDisabled).ToString();
|
||||
|
||||
var derricks = template.GetOrNull<LabelWidget>("DERRICKS");
|
||||
if (derricks != null)
|
||||
|
||||
Reference in New Issue
Block a user