Files
OpenRA/OpenRA.Mods.RA/Activities/RAHarvesterDockSequence.cs
James Dunne 80123b6aa4 Many harvester behavior improvements; summary below.
Implemented Harvester territory marking with a simple resource claim system in ResourceClaimLayer trait added to World.
Added customCost for PathSearch to support new Harvester search preferences.
Explicit delivery order forces harvester to always deliver to that refinery.
Explicit harvest order frees harvester from forced delivery refinery and allows for auto-balancing.
Harvesters auto-balance refinery choice such that no more than 3 harvesters are linked to any one refinery at a time.
Harvesters try very hard to not block the refinery dock location.
Harvesters try to avoid enemy territory when searching for resources.
Group-select harvest order intelligently disperses harvesters around the order location.
Fixed PathFinder caching to not be a sliding window. This is a correctness issue. Sliding window causes no-route paths to be cached permanently in tight move loops and doesn't allow eventual progress to be made. This may have negative performance implications.
2012-06-24 20:26:00 -05:00

78 lines
1.9 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* 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. For more information,
* see COPYING.
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
public class RAHarvesterDockSequence : Activity
{
enum State { Wait, Turn, Dock, Loop, Undock, Complete };
readonly Actor proc;
readonly Harvester harv;
readonly RenderUnit ru;
State state;
public RAHarvesterDockSequence(Actor self, Actor proc)
{
this.proc = proc;
state = State.Turn;
harv = self.Trait<Harvester>();
ru = self.Trait<RenderUnit>();
}
public override Activity Tick(Actor self)
{
switch (state)
{
case State.Wait:
return this;
case State.Turn:
state = State.Dock;
return Util.SequenceActivities(new Turn(64), this);
case State.Dock:
ru.PlayCustomAnimation(self, "dock", () => {ru.PlayCustomAnimRepeating(self, "dock-loop"); state = State.Loop;});
state = State.Wait;
return this;
case State.Loop:
if (harv.TickUnload(self, proc))
state = State.Undock;
return this;
case State.Undock:
ru.PlayCustomAnimBackwards(self, "dock", () => state = State.Complete);
state = State.Wait;
return this;
case State.Complete:
harv.LastLinkedProc = harv.LinkedProc;
harv.LinkedProc = null;
return NextActivity;
}
throw new InvalidOperationException("Invalid harvester dock state");
}
public override void Cancel(Actor self)
{
state = State.Undock;
base.Cancel(self);
}
public override IEnumerable<Target> GetTargets( Actor self )
{
yield return Target.FromActor(proc);
}
}
}