Fix #1157: Removed HARV minining from cell in front / using MoveAdjacentTo in logic. Was causing harvesters to get stuck - need to revisit this.
This commit is contained in:
@@ -8,10 +8,10 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Drawing;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
@@ -20,36 +20,61 @@ namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class FindResources : Activity
|
||||
{
|
||||
public override Activity Tick( Actor self )
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
if( IsCanceled || NextActivity != null) return NextActivity;
|
||||
if (IsCanceled || NextActivity != null) return NextActivity;
|
||||
|
||||
var harv = self.Trait<Harvester>();
|
||||
if( harv.IsFull )
|
||||
return Util.SequenceActivities( new DeliverResources(), NextActivity );
|
||||
if (harv.IsFull)
|
||||
return Util.SequenceActivities(new DeliverResources(), NextActivity);
|
||||
|
||||
var mobileInfo = self.Info.Traits.Get<MobileInfo>();
|
||||
var harvInfo = self.Info.Traits.Get<HarvesterInfo>();
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var mobileInfo = self.Info.Traits.Get<MobileInfo>();
|
||||
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 => canHarvest(loc) ? 0 : 1)
|
||||
.FromPoint(self.Location));
|
||||
.WithHeuristic(loc => (res.GetResource(loc) != null && harvInfo.Resources.Contains(res.GetResource(loc).info.Name)) ? 0 : 1)
|
||||
.FromPoint(self.Location));
|
||||
|
||||
if (path.Count == 0)
|
||||
return NextActivity;
|
||||
|
||||
self.SetTargetLine(Target.FromCell(path[0]), Color.Red, false);
|
||||
return Util.SequenceActivities( new MoveAdjacentTo(Target.FromCell(path[0])), new HarvestResource(self, path[0]), this );
|
||||
return Util.SequenceActivities(mobile.MoveTo(path[0], 1), new HarvestResource(), this);
|
||||
}
|
||||
|
||||
public override IEnumerable<Target> GetTargets( Actor self )
|
||||
public override IEnumerable<Target> GetTargets(Actor self)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,9 +61,9 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
if (LastHarvestedCell.HasValue)
|
||||
{
|
||||
var target = Target.FromCell(LastHarvestedCell.Value);
|
||||
self.QueueActivity( new MoveAdjacentTo(target) );
|
||||
self.SetTargetLine(target, Color.Red, false);
|
||||
var mobile = self.Trait<Mobile>();
|
||||
self.QueueActivity( mobile.MoveTo(LastHarvestedCell.Value, 5) );
|
||||
self.SetTargetLine(Target.FromCell(LastHarvestedCell.Value), Color.Red, false);
|
||||
}
|
||||
self.QueueActivity( new FindResources() );
|
||||
}
|
||||
@@ -152,12 +152,11 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
if (order.OrderString == "Harvest")
|
||||
{
|
||||
var target = Target.FromOrder(order);
|
||||
var mobile = self.Trait<Mobile>();
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new MoveAdjacentTo(target));
|
||||
self.QueueActivity(new HarvestResource(self, order.TargetLocation));
|
||||
self.QueueActivity(mobile.MoveTo(order.TargetLocation, 0));
|
||||
self.QueueActivity(new FindResources());
|
||||
self.SetTargetLine(target, Color.Red);
|
||||
self.SetTargetLine(Target.FromOrder(order), Color.Red);
|
||||
}
|
||||
else if (order.OrderString == "Deliver")
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -67,7 +67,6 @@
|
||||
<Compile Include="Activities\EnterTransport.cs" />
|
||||
<Compile Include="Activities\FindResources.cs" />
|
||||
<Compile Include="Activities\Follow.cs" />
|
||||
<Compile Include="Activities\HarvestResource.cs" />
|
||||
<Compile Include="Activities\Heal.cs" />
|
||||
<Compile Include="Activities\Infiltrate.cs" />
|
||||
<Compile Include="Activities\LayMines.cs" />
|
||||
@@ -334,6 +333,7 @@
|
||||
<Compile Include="Widgets\Logic\ConnectionDialogsLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CreateServerMenuLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\DeveloperModeLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\DiplomacyLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\IngameChromeLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\IngameObserverChromeLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\LobbyLogic.cs" />
|
||||
@@ -386,4 +386,4 @@
|
||||
copy "$(TargetPath)" "$(SolutionDir)mods/ra/"
|
||||
cd "$(SolutionDir)"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user