Rework harvester resource claiming:

* Maintains lists of claims, and only restricts
   reservations for friendly units.
 * Removes OnNotifyResourceClaimLost; it's not
   clear whether that is still useful, and it
   prevents future necessary cleanups.
 * Moves other code without changing behaviour.

This fixed stale claims from dead units and enemy
claims from preventing otherwise valid harvest
activities.
This commit is contained in:
Paul Chote
2017-07-15 12:36:41 +00:00
committed by reaperrr
parent 9097837e6d
commit afd8b9ab86
9 changed files with 79 additions and 192 deletions

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Activities
readonly Harvester harv;
readonly HarvesterInfo harvInfo;
readonly IFacing facing;
readonly ResourceClaimLayer territory;
readonly ResourceClaimLayer claimLayer;
readonly ResourceLayer resLayer;
readonly BodyOrientation body;
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Activities
harvInfo = self.Info.TraitInfo<HarvesterInfo>();
facing = self.Trait<IFacing>();
body = self.Trait<BodyOrientation>();
territory = self.World.WorldActor.TraitOrDefault<ResourceClaimLayer>();
claimLayer = self.World.WorldActor.Trait<ResourceClaimLayer>();
resLayer = self.World.WorldActor.Trait<ResourceLayer>();
}
@@ -38,8 +38,7 @@ namespace OpenRA.Mods.Common.Activities
{
if (IsCanceled)
{
if (territory != null)
territory.UnclaimByActor(self);
claimLayer.RemoveClaim(self);
return NextActivity;
}
@@ -47,8 +46,7 @@ namespace OpenRA.Mods.Common.Activities
if (harv.IsFull)
{
if (territory != null)
territory.UnclaimByActor(self);
claimLayer.RemoveClaim(self);
return NextActivity;
}
@@ -64,8 +62,7 @@ namespace OpenRA.Mods.Common.Activities
var resource = resLayer.Harvest(self.Location);
if (resource == null)
{
if (territory != null)
territory.UnclaimByActor(self);
claimLayer.RemoveClaim(self);
return NextActivity;
}