OpenRA.Player.ChooseFaction C# (CSharp) Method

ChooseFaction() static private method

static private ChooseFaction ( World world, string name, bool requireSelectable = true ) : FactionInfo
world World
name string
requireSelectable bool
return FactionInfo
        static FactionInfo ChooseFaction(World world, string name, bool requireSelectable = true)
        {
            var selectableFactions = world.Map.Rules.Actors["world"].TraitInfos<FactionInfo>()
                .Where(f => !requireSelectable || f.Selectable)
                .ToList();

            var selected = selectableFactions.FirstOrDefault(f => f.InternalName == name)
                ?? selectableFactions.Random(world.SharedRandom);

            // Don't loop infinite
            for (var i = 0; i <= 10 && selected.RandomFactionMembers.Any(); i++)
            {
                var faction = selected.RandomFactionMembers.Random(world.SharedRandom);
                selected = selectableFactions.FirstOrDefault(f => f.InternalName == faction);

                if (selected == null)
                    throw new YamlException("Unknown faction: {0}".F(faction));
            }

            return selected;
        }