Ensure starting units or units granted by a crate are not isolated.
When spawning starting units, or spawning units when collecting a crate, nearby locations will be used. If a nearby location cannot be reached, e.g. it is on top of a cliff or blocked in by trees, then any unit spawned there will be isolated which is not ideal. Use the PathMightExistForLocomotorBlockedByImmovable method to filter nearby locations to those where the spawned unit can path back to the original location. This ensures the spawned unit is not isolated.
This commit is contained in:
committed by
Matthias Mailänder
parent
6bc613e93f
commit
2c435c0506
@@ -86,10 +86,26 @@ namespace OpenRA.Mods.Common.Traits
|
||||
collector.World.AddFrameEndTask(w =>
|
||||
{
|
||||
var candidateCells = collector.World.Map.FindTilesInCircle(collector.Location, info.MaxRadius)
|
||||
.Where(c => positionable.CanEnterCell(c)).Shuffle(collector.World.SharedRandom)
|
||||
.Where(c => positionable.CanEnterCell(c));
|
||||
|
||||
var pathFinder = w.WorldActor.TraitOrDefault<IPathFinder>();
|
||||
if (pathFinder != null)
|
||||
{
|
||||
var actorRules = w.Map.Rules.Actors[collector.Info.Name];
|
||||
var locomotorName = actorRules.TraitInfoOrDefault<MobileInfo>()?.Locomotor;
|
||||
if (locomotorName != null)
|
||||
{
|
||||
var locomotor = w.WorldActor.TraitsImplementing<Locomotor>().Single(l => l.Info.Name == locomotorName);
|
||||
candidateCells = candidateCells
|
||||
.Where(c => pathFinder.PathMightExistForLocomotorBlockedByImmovable(locomotor, c, collector.Location));
|
||||
}
|
||||
}
|
||||
|
||||
var shuffledCandidateCells = candidateCells
|
||||
.Shuffle(collector.World.SharedRandom)
|
||||
.ToArray();
|
||||
|
||||
var duplicates = Math.Min(candidateCells.Length, info.MaxAmount);
|
||||
var duplicates = Math.Min(shuffledCandidateCells.Length, info.MaxAmount);
|
||||
|
||||
// Restrict duplicate count to a maximum value
|
||||
if (info.MaxDuplicateValue > 0)
|
||||
@@ -103,7 +119,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var actor = w.CreateActor(collector.Info.Name, new TypeDictionary
|
||||
{
|
||||
new LocationInit(candidateCells[i]),
|
||||
new LocationInit(shuffledCandidateCells[i]),
|
||||
new OwnerInit(info.Owner ?? collector.Owner.InternalName)
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user