Made ResourceClaimLayer trait optional on World actor to fix cnc and d2k.
This commit is contained in:
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var mobileInfo = self.Info.Traits.Get<MobileInfo>();
|
||||
var resLayer = self.World.WorldActor.Trait<ResourceLayer>();
|
||||
var territory = self.World.WorldActor.Trait<ResourceClaimLayer>();
|
||||
var territory = self.World.WorldActor.TraitOrDefault<ResourceClaimLayer>();
|
||||
|
||||
// Find harvestable resources nearby:
|
||||
var path = self.World.WorldActor.Trait<PathFinder>().FindPath(
|
||||
@@ -79,9 +79,12 @@ namespace OpenRA.Mods.RA.Activities
|
||||
// Can the harvester collect this kind of resource?
|
||||
if (!harvInfo.Resources.Contains(resType.info.Name)) return 1;
|
||||
|
||||
// Another harvester has claimed this resource:
|
||||
ResourceClaim claim;
|
||||
if (territory.IsClaimedByAnyoneElse(self, loc, out claim)) return 1;
|
||||
if (territory != null)
|
||||
{
|
||||
// Another harvester has claimed this resource:
|
||||
ResourceClaim claim;
|
||||
if (territory.IsClaimedByAnyoneElse(self, loc, out claim)) return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
})
|
||||
@@ -105,8 +108,11 @@ namespace OpenRA.Mods.RA.Activities
|
||||
}
|
||||
|
||||
// Attempt to claim a resource as ours:
|
||||
if (!territory.ClaimResource(self, path[0]))
|
||||
return Util.SequenceActivities(new Wait(25), new FindResources());
|
||||
if (territory != null)
|
||||
{
|
||||
if (!territory.ClaimResource(self, path[0]))
|
||||
return Util.SequenceActivities(new Wait(25), new FindResources());
|
||||
}
|
||||
|
||||
// If not given a direct order, assume ordered to the first resource location we find:
|
||||
if (harv.LastOrderLocation == null)
|
||||
@@ -130,10 +136,10 @@ namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
if (isHarvesting) return this;
|
||||
|
||||
var territory = self.World.WorldActor.Trait<ResourceClaimLayer>();
|
||||
var territory = self.World.WorldActor.TraitOrDefault<ResourceClaimLayer>();
|
||||
if (IsCanceled)
|
||||
{
|
||||
territory.UnclaimByActor(self);
|
||||
if (territory != null) territory.UnclaimByActor(self);
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
@@ -142,7 +148,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
|
||||
if (harv.IsFull)
|
||||
{
|
||||
territory.UnclaimByActor(self);
|
||||
if (territory != null) territory.UnclaimByActor(self);
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
@@ -150,7 +156,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
var resource = resLayer.Harvest(self.Location);
|
||||
if (resource == null)
|
||||
{
|
||||
territory.UnclaimByActor(self);
|
||||
if (territory != null) territory.UnclaimByActor(self);
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
|
||||
@@ -152,7 +152,9 @@ namespace OpenRA.Mods.RA
|
||||
self.QueueActivity(mobile.MoveTo(moveTo, 1));
|
||||
self.SetTargetLine(Target.FromCell(moveTo), Color.Gray, false);
|
||||
|
||||
self.World.WorldActor.Trait<ResourceClaimLayer>().ClaimResource(self, moveTo);
|
||||
var territory = self.World.WorldActor.TraitOrDefault<ResourceClaimLayer>();
|
||||
if (territory != null) territory.ClaimResource(self, moveTo);
|
||||
|
||||
self.QueueActivity(new FindResources());
|
||||
return;
|
||||
}
|
||||
@@ -258,10 +260,19 @@ namespace OpenRA.Mods.RA
|
||||
if (order.TargetLocation != CPos.Zero)
|
||||
{
|
||||
var loc = order.TargetLocation;
|
||||
var territory = self.World.WorldActor.Trait<ResourceClaimLayer>();
|
||||
var territory = self.World.WorldActor.TraitOrDefault<ResourceClaimLayer>();
|
||||
|
||||
// Find the nearest claimable cell to the order location (useful for group-select harvest):
|
||||
loc = mobile.NearestCell(loc, p => mobile.CanEnterCell(p) && territory.ClaimResource(self, p), 1, 6);
|
||||
if (territory != null)
|
||||
{
|
||||
// Find the nearest claimable cell to the order location (useful for group-select harvest):
|
||||
loc = mobile.NearestCell(loc, p => mobile.CanEnterCell(p) && territory.ClaimResource(self, p), 1, 6);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Find the nearest cell to the order location (useful for group-select harvest):
|
||||
var taken = new HashSet<CPos>();
|
||||
loc = mobile.NearestCell(loc, p => mobile.CanEnterCell(p) && taken.Add(p), 1, 6);
|
||||
}
|
||||
|
||||
self.QueueActivity(mobile.MoveTo(loc, 0));
|
||||
self.SetTargetLine(Target.FromCell(loc), Color.Red);
|
||||
@@ -310,7 +321,7 @@ namespace OpenRA.Mods.RA
|
||||
var harvInfo = self.Info.Traits.Get<HarvesterInfo>();
|
||||
var mobileInfo = self.Info.Traits.Get<MobileInfo>();
|
||||
var resLayer = self.World.WorldActor.Trait<ResourceLayer>();
|
||||
var territory = self.World.WorldActor.Trait<ResourceClaimLayer>();
|
||||
var territory = self.World.WorldActor.TraitOrDefault<ResourceClaimLayer>();
|
||||
|
||||
// Find any harvestable resources:
|
||||
var path = self.World.WorldActor.Trait<PathFinder>().FindPath(
|
||||
@@ -325,8 +336,11 @@ namespace OpenRA.Mods.RA
|
||||
if (!harvInfo.Resources.Contains(resType.info.Name)) return 1;
|
||||
|
||||
// Another harvester has claimed this resource:
|
||||
ResourceClaim claim;
|
||||
if (territory.IsClaimedByAnyoneElse(self, loc, out claim)) return 1;
|
||||
if (territory != null)
|
||||
{
|
||||
ResourceClaim claim;
|
||||
if (territory.IsClaimedByAnyoneElse(self, loc, out claim)) return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user