Prevent multiple enumeration of validCells in SpawnMPUnits
This commit is contained in:
@@ -103,20 +103,20 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
var actorRules = w.Map.Rules.Actors[s.ToLowerInvariant()];
|
var actorRules = w.Map.Rules.Actors[s.ToLowerInvariant()];
|
||||||
var ip = actorRules.TraitInfo<IPositionableInfo>();
|
var ip = actorRules.TraitInfo<IPositionableInfo>();
|
||||||
var validCells = supportSpawnCells.Where(c => ip.CanEnterCell(w, null, c));
|
var validCell = supportSpawnCells.Shuffle(w.SharedRandom).FirstOrDefault(c => ip.CanEnterCell(w, null, c));
|
||||||
if (!validCells.Any())
|
|
||||||
|
if (validCell == CPos.Zero)
|
||||||
{
|
{
|
||||||
Log.Write("debug", "No cells available to spawn starting unit {0} for player {1}".F(s, p));
|
Log.Write("debug", "No cells available to spawn starting unit {0} for player {1}".F(s, p));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var cell = validCells.Random(w.SharedRandom);
|
var subCell = ip.SharesCell ? w.ActorMap.FreeSubCell(validCell) : 0;
|
||||||
var subCell = ip.SharesCell ? w.ActorMap.FreeSubCell(cell) : 0;
|
|
||||||
|
|
||||||
w.CreateActor(s.ToLowerInvariant(), new TypeDictionary
|
w.CreateActor(s.ToLowerInvariant(), new TypeDictionary
|
||||||
{
|
{
|
||||||
new OwnerInit(p),
|
new OwnerInit(p),
|
||||||
new LocationInit(cell),
|
new LocationInit(validCell),
|
||||||
new SubCellInit(subCell),
|
new SubCellInit(subCell),
|
||||||
new FacingInit(unitGroup.SupportActorsFacing < 0 ? w.SharedRandom.Next(256) : unitGroup.SupportActorsFacing)
|
new FacingInit(unitGroup.SupportActorsFacing < 0 ? w.SharedRandom.Next(256) : unitGroup.SupportActorsFacing)
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user