Rename docking activities
HarvesterDockSequence -> GenericDockSequence DeliverResources -> MoveToDock
This commit is contained in:
committed by
Matthias Mailänder
parent
55536bba4c
commit
da16e4ed99
96
OpenRA.Mods.Common/Activities/MoveToDock.cs
Normal file
96
OpenRA.Mods.Common/Activities/MoveToDock.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
#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;
|
||||
using System.Linq;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
public class MoveToDock : Activity
|
||||
{
|
||||
readonly IMove movement;
|
||||
readonly Harvester harv;
|
||||
readonly Actor targetActor;
|
||||
readonly INotifyHarvesterAction[] notifyHarvesterActions;
|
||||
|
||||
Actor proc;
|
||||
|
||||
public MoveToDock(Actor self, Actor targetActor = null)
|
||||
{
|
||||
movement = self.Trait<IMove>();
|
||||
harv = self.Trait<Harvester>();
|
||||
this.targetActor = targetActor;
|
||||
notifyHarvesterActions = self.TraitsImplementing<INotifyHarvesterAction>().ToArray();
|
||||
}
|
||||
|
||||
protected override void OnFirstRun(Actor self)
|
||||
{
|
||||
if (targetActor != null && targetActor.IsInWorld)
|
||||
harv.LinkProc(targetActor);
|
||||
}
|
||||
|
||||
public override bool Tick(Actor self)
|
||||
{
|
||||
if (harv.IsTraitDisabled)
|
||||
Cancel(self, true);
|
||||
|
||||
if (IsCanceling)
|
||||
return true;
|
||||
|
||||
// Find the nearest best refinery if not explicitly ordered to a specific refinery:
|
||||
if (harv.LinkedProc == null || !harv.LinkedProc.IsInWorld)
|
||||
harv.ChooseNewProc(self, null);
|
||||
|
||||
// No refineries exist; check again after delay defined in Harvester.
|
||||
if (harv.LinkedProc == null)
|
||||
{
|
||||
QueueChild(new Wait(harv.Info.SearchForDeliveryBuildingDelay));
|
||||
return false;
|
||||
}
|
||||
|
||||
proc = harv.LinkedProc;
|
||||
var iao = proc.Trait<IAcceptResources>();
|
||||
|
||||
if (self.CenterPosition != iao.DeliveryPosition)
|
||||
{
|
||||
foreach (var n in notifyHarvesterActions)
|
||||
n.MovingToRefinery(self, proc);
|
||||
|
||||
var target = Target.FromActor(proc);
|
||||
QueueChild(movement.MoveOntoTarget(self, target, iao.DeliveryPosition - proc.CenterPosition, iao.DeliveryAngle));
|
||||
return false;
|
||||
}
|
||||
|
||||
QueueChild(new Wait(10));
|
||||
iao.OnDock(self, this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Cancel(Actor self, bool keepQueue = false)
|
||||
{
|
||||
foreach (var n in notifyHarvesterActions)
|
||||
n.MovementCancelled(self);
|
||||
|
||||
base.Cancel(self, keepQueue);
|
||||
}
|
||||
|
||||
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
|
||||
{
|
||||
if (proc != null)
|
||||
yield return new TargetLineNode(Target.FromActor(proc), harv.Info.DeliverLineColor);
|
||||
else
|
||||
yield return new TargetLineNode(Target.FromActor(harv.LinkedProc), harv.Info.DeliverLineColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user