Add priority levels to Exit.
This commit is contained in:
@@ -32,6 +32,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Number of ticks to wait before moving into the world.")]
|
||||
public readonly int ExitDelay = 0;
|
||||
|
||||
[Desc("Exits with larger priorities will be used before lower priorities.")]
|
||||
public readonly int Priority = 1;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new Exit(init, this); }
|
||||
}
|
||||
|
||||
@@ -46,7 +49,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public static Exit FirstExitOrDefault(this Actor actor, string productionType = null)
|
||||
{
|
||||
var all = actor.TraitsImplementing<Exit>()
|
||||
.Where(Exts.IsTraitEnabled);
|
||||
.Where(Exts.IsTraitEnabled)
|
||||
.OrderBy(e => e.Info.Priority);
|
||||
|
||||
if (string.IsNullOrEmpty(productionType))
|
||||
return all.FirstOrDefault(e => e.Info.ProductionTypes.Count == 0);
|
||||
@@ -71,8 +75,18 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!allOfType.Any())
|
||||
return null;
|
||||
|
||||
var shuffled = allOfType.Shuffle(world.SharedRandom);
|
||||
return p != null ? shuffled.FirstOrDefault(p) : shuffled.First();
|
||||
foreach (var g in allOfType.GroupBy(e => e.Info.Priority))
|
||||
{
|
||||
var shuffled = g.Shuffle(world.SharedRandom);
|
||||
if (p == null)
|
||||
return shuffled.First();
|
||||
|
||||
var valid = shuffled.FirstOrDefault(p);
|
||||
if (valid != null)
|
||||
return valid;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user