Harvesters harvest the cell in front of them; fix harvester target lines; split harvester activities into their own (correctly named) files.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
@@ -23,7 +24,6 @@ namespace OpenRA.Mods.RA.Activities
|
||||
|
||||
public override Activity Tick( Actor self )
|
||||
{
|
||||
// TODO: wtf is this?
|
||||
if( NextActivity != null )
|
||||
return NextActivity;
|
||||
|
||||
@@ -39,6 +39,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
var proc = harv.LinkedProc;
|
||||
var iao = proc.Trait<IAcceptOre>();
|
||||
|
||||
self.SetTargetLine(Target.FromActor(proc), Color.Green, false);
|
||||
if( self.Location != proc.Location + iao.DeliverOffset )
|
||||
return Util.SequenceActivities( mobile.MoveTo(proc.Location + iao.DeliverOffset, 0), this );
|
||||
|
||||
@@ -8,12 +8,13 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
@@ -21,23 +22,29 @@ namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public override Activity Tick( Actor self )
|
||||
{
|
||||
if( IsCanceled ) return NextActivity;
|
||||
if( NextActivity != null ) return NextActivity;
|
||||
if( IsCanceled || NextActivity != null) return NextActivity;
|
||||
|
||||
var harv = self.Trait<Harvester>();
|
||||
if( harv.IsFull )
|
||||
return Util.SequenceActivities( new DeliverResources(), NextActivity );
|
||||
|
||||
var harvInfo = self.Info.Traits.Get<HarvesterInfo>();
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var mobileInfo = self.Info.Traits.Get<MobileInfo>();
|
||||
var harvInfo = self.Info.Traits.Get<HarvesterInfo>();
|
||||
var res = self.World.WorldActor.Trait<ResourceLayer>();
|
||||
|
||||
Func<int2, bool> canHarvest = loc => loc != self.Location &&
|
||||
res.GetResource(loc) != null &&
|
||||
harvInfo.Resources.Contains( res.GetResource(loc).info.Name );
|
||||
|
||||
var path = self.World.WorldActor.Trait<PathFinder>().FindPath(PathSearch.Search(self.World, mobileInfo, self.Owner, true)
|
||||
.WithHeuristic(loc => (res.GetResource(loc) != null && harvInfo.Resources.Contains( res.GetResource(loc).info.Name )) ? 0 : 1)
|
||||
.WithHeuristic(loc => canHarvest(loc) ? 0 : 1)
|
||||
.FromPoint(self.Location));
|
||||
|
||||
if (path.Count == 0)
|
||||
return NextActivity;
|
||||
return Util.SequenceActivities( mobile.MoveTo(path[0], 1), new HarvestResource(), this );
|
||||
|
||||
self.SetTargetLine(Target.FromCell(path[0]), Color.Red, false);
|
||||
return Util.SequenceActivities( new MoveAdjacentTo(Target.FromCell(path[0])), new HarvestResource(self, path[0]), this );
|
||||
}
|
||||
|
||||
public override IEnumerable<Target> GetTargets( Actor self )
|
||||
@@ -45,33 +52,4 @@ namespace OpenRA.Mods.RA.Activities
|
||||
yield return Target.FromPos(self.Location);
|
||||
}
|
||||
}
|
||||
|
||||
public class HarvestResource : Activity
|
||||
{
|
||||
bool isHarvesting = false;
|
||||
|
||||
public override Activity Tick( Actor self )
|
||||
{
|
||||
if( isHarvesting ) return this;
|
||||
if( IsCanceled ) return NextActivity;
|
||||
var harv = self.Trait<Harvester>();
|
||||
harv.LastHarvestedCell = self.Location;
|
||||
|
||||
if( harv.IsFull )
|
||||
return NextActivity;
|
||||
|
||||
var renderUnit = self.Trait<RenderUnit>(); /* better have one of these! */
|
||||
var resource = self.World.WorldActor.Trait<ResourceLayer>().Harvest(self.Location);
|
||||
if (resource == null)
|
||||
return NextActivity;
|
||||
|
||||
if (renderUnit.anim.CurrentSequence.Name != "harvest")
|
||||
{
|
||||
isHarvesting = true;
|
||||
renderUnit.PlayCustomAnimation(self, "harvest", () => isHarvesting = false);
|
||||
}
|
||||
harv.AcceptResource(resource);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
63
OpenRA.Mods.RA/Activities/HarvestResource.cs
Executable file
63
OpenRA.Mods.RA/Activities/HarvestResource.cs
Executable file
@@ -0,0 +1,63 @@
|
||||
#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 OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class HarvestResource : Activity
|
||||
{
|
||||
Harvester harv;
|
||||
IFacing facing;
|
||||
RenderUnit renderUnit;
|
||||
ResourceLayer resourceLayer;
|
||||
bool isHarvesting = false;
|
||||
int2 harvestCell;
|
||||
|
||||
public HarvestResource(Actor self, int2 cell)
|
||||
{
|
||||
harv = self.Trait<Harvester>();
|
||||
facing = self.Trait<IFacing>();
|
||||
renderUnit = self.Trait<RenderUnit>();
|
||||
resourceLayer = self.World.WorldActor.Trait<ResourceLayer>();
|
||||
harvestCell = cell;
|
||||
}
|
||||
|
||||
public override Activity Tick( Actor self )
|
||||
{
|
||||
if( isHarvesting ) return this;
|
||||
if( IsCanceled ) return NextActivity;
|
||||
harv.LastHarvestedCell = harvestCell;
|
||||
|
||||
if( harv.IsFull )
|
||||
return NextActivity;
|
||||
|
||||
int2 dir = harvestCell - self.Location;
|
||||
var f = Util.GetFacing( dir, facing.Facing );
|
||||
if( f != facing.Facing )
|
||||
return Util.SequenceActivities( new Turn(f), this );
|
||||
|
||||
var resource = resourceLayer.Harvest(harvestCell);
|
||||
if (resource == null)
|
||||
return NextActivity;
|
||||
|
||||
if (renderUnit.anim.CurrentSequence.Name != "harvest")
|
||||
{
|
||||
isHarvesting = true;
|
||||
renderUnit.PlayCustomAnimation(self, "harvest", () => isHarvesting = false);
|
||||
}
|
||||
|
||||
harv.AcceptResource(resource);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,23 +18,30 @@ namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class MoveAdjacentTo : Activity
|
||||
{
|
||||
readonly Actor target;
|
||||
readonly Target target;
|
||||
|
||||
public MoveAdjacentTo( Actor target )
|
||||
{
|
||||
this.target = Target.FromActor(target);
|
||||
}
|
||||
|
||||
public MoveAdjacentTo( Target target )
|
||||
{
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public override Activity Tick( Actor self )
|
||||
{
|
||||
if( IsCanceled || target.Destroyed || !target.IsInWorld) return NextActivity;
|
||||
if( IsCanceled || !target.IsValid) return NextActivity;
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
Pair<int2, SubCell>[] cells = new Pair<int2, SubCell>[] {};
|
||||
if (target.IsActor)
|
||||
cells = target.Actor.Trait<IOccupySpace>().OccupiedCells().ToArray();
|
||||
|
||||
var cells = target.Trait<IOccupySpace>().OccupiedCells().ToArray();
|
||||
if (cells.Length == 0)
|
||||
cells = new OpenRA.FileFormats.Pair<int2, SubCell>[] {
|
||||
Pair.New(target.Location, SubCell.FullCell) };
|
||||
Pair.New(Util.CellContaining(target.CenterLocation), SubCell.FullCell) };
|
||||
|
||||
var ps1 = new PathSearch( self.World, mobile.Info, self.Owner )
|
||||
{
|
||||
@@ -51,7 +58,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
}
|
||||
ps1.heuristic = PathSearch.DefaultEstimator( mobile.toCell );
|
||||
|
||||
var ps2 = PathSearch.FromPoint( self.World, mobile.Info, self.Owner, mobile.toCell, target.Location, true );
|
||||
var ps2 = PathSearch.FromPoint( self.World, mobile.Info, self.Owner, mobile.toCell, Util.CellContaining(target.CenterLocation), true );
|
||||
var ret = self.World.WorldActor.Trait<PathFinder>().FindBidiPath( ps1, ps2 );
|
||||
if( ret.Count > 0 )
|
||||
ret.RemoveAt( 0 );
|
||||
|
||||
@@ -61,9 +61,9 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
if (LastHarvestedCell.HasValue)
|
||||
{
|
||||
var mobile = self.Trait<Mobile>();
|
||||
self.QueueActivity( mobile.MoveTo(LastHarvestedCell.Value, 5) );
|
||||
self.SetTargetLine(Target.FromCell(LastHarvestedCell.Value), Color.Red, false);
|
||||
var target = Target.FromCell(LastHarvestedCell.Value);
|
||||
self.QueueActivity( new MoveAdjacentTo(target) );
|
||||
self.SetTargetLine(target, Color.Red, false);
|
||||
}
|
||||
self.QueueActivity( new FindResources() );
|
||||
}
|
||||
@@ -152,12 +152,12 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
if (order.OrderString == "Harvest")
|
||||
{
|
||||
self.SetTargetLine(Target.FromOrder(order), Color.Red);
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var target = Target.FromOrder(order);
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(mobile.MoveTo(order.TargetLocation, 0));
|
||||
self.QueueActivity(new MoveAdjacentTo(target));
|
||||
self.QueueActivity(new HarvestResource(self, order.TargetLocation));
|
||||
self.QueueActivity(new FindResources());
|
||||
self.SetTargetLine(target, Color.Red);
|
||||
}
|
||||
else if (order.OrderString == "Deliver")
|
||||
{
|
||||
|
||||
@@ -60,7 +60,6 @@
|
||||
<Compile Include="Activities\Attack.cs" />
|
||||
<Compile Include="Activities\CallFunc.cs" />
|
||||
<Compile Include="Activities\DonateSupplies.cs" />
|
||||
<Compile Include="Activities\DeliverOre.cs" />
|
||||
<Compile Include="Activities\Demolish.cs" />
|
||||
<Compile Include="Activities\Enter.cs" />
|
||||
<Compile Include="Activities\EnterTransport.cs" />
|
||||
@@ -190,7 +189,6 @@
|
||||
<Compile Include="Effects\Corpse.cs" />
|
||||
<Compile Include="Effects\CrateEffect.cs" />
|
||||
<Compile Include="Effects\NukeLaunch.cs" />
|
||||
<Compile Include="Activities\Harvest.cs" />
|
||||
<Compile Include="EmitInfantryOnSell.cs" />
|
||||
<Compile Include="Explodes.cs" />
|
||||
<Compile Include="Fake.cs" />
|
||||
@@ -356,6 +354,9 @@
|
||||
<Compile Include="Widgets\Logic\RAInstallFromCDLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\RADownloadPackagesLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\RAInstallLogic.cs" />
|
||||
<Compile Include="Activities\FindResources.cs" />
|
||||
<Compile Include="Activities\HarvestResource.cs" />
|
||||
<Compile Include="Activities\DeliverResources.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
Reference in New Issue
Block a user