private bool IsValidUnitItem(
            BasicCharacterObject o,
            BasicCultureObject culture,
            ArmyCompositionGroupVM.TroopType troopType)
        {
            if (o == null || culture != o.Culture)
            {
                return(false);
            }
            switch (troopType)
            {
            case ArmyCompositionGroupVM.TroopType.MeleeInfantry:
                return(o.DefaultFormationClass == FormationClass.Infantry || o.DefaultFormationClass == FormationClass.HeavyInfantry);

            case ArmyCompositionGroupVM.TroopType.RangedInfantry:
                return(o.DefaultFormationClass == FormationClass.Ranged);

            case ArmyCompositionGroupVM.TroopType.MeleeCavalry:
                return(o.DefaultFormationClass == FormationClass.Cavalry || o.DefaultFormationClass == FormationClass.HeavyCavalry || o.DefaultFormationClass == FormationClass.LightCavalry);

            case ArmyCompositionGroupVM.TroopType.RangedCavalry:
                return(o.DefaultFormationClass == FormationClass.HorseArcher);

            default:
                return(false);
            }
        }
 private void PopulateTroopTypeList(
     ArmyCompositionGroupVM.TroopType troopType,
     BasicCultureObject cultureOfTroops)
 {
     if (troopType == ArmyCompositionGroupVM.TroopType.MeleeInfantry)
     {
         this._meleeInfantryTypes.Clear();
         this._meleeInfantryTypes.AddRange(this._allCharacterObjects.Where <BasicCharacterObject>((Func <BasicCharacterObject, bool>)(o => this.IsValidUnitItem(o, cultureOfTroops, troopType))));
         this.SelectedMeleeInfantryTypes.Clear();
         this.SelectedMeleeInfantryTypes.Add(CustomBattleState.Helper.GetDefaultTroopOfFormationForFaction(cultureOfTroops, FormationClass.Infantry));
     }
     else if (troopType == ArmyCompositionGroupVM.TroopType.RangedInfantry)
     {
         this._rangedInfantryTypes.Clear();
         this._rangedInfantryTypes.AddRange(this._allCharacterObjects.Where <BasicCharacterObject>((Func <BasicCharacterObject, bool>)(o => this.IsValidUnitItem(o, cultureOfTroops, troopType))));
         this.SelectedRangedInfantryTypes.Clear();
         this.SelectedRangedInfantryTypes.Add(CustomBattleState.Helper.GetDefaultTroopOfFormationForFaction(cultureOfTroops, FormationClass.Ranged));
     }
     else if (troopType == ArmyCompositionGroupVM.TroopType.MeleeCavalry)
     {
         this._meleeCavalryTypes.Clear();
         this._meleeCavalryTypes.AddRange(this._allCharacterObjects.Where <BasicCharacterObject>((Func <BasicCharacterObject, bool>)(o => this.IsValidUnitItem(o, cultureOfTroops, troopType))));
         this.SelectedMeleeCavalryTypes.Clear();
         this.SelectedMeleeCavalryTypes.Add(CustomBattleState.Helper.GetDefaultTroopOfFormationForFaction(cultureOfTroops, FormationClass.Cavalry));
     }
     else
     {
         if (troopType != ArmyCompositionGroupVM.TroopType.RangedCavalry)
         {
             return;
         }
         this._rangedCavalryTypes.Clear();
         this._rangedCavalryTypes.AddRange(this._allCharacterObjects.Where <BasicCharacterObject>((Func <BasicCharacterObject, bool>)(o => this.IsValidUnitItem(o, cultureOfTroops, troopType))));
         this.SelectedRangedCavalryTypes.Clear();
         this.SelectedRangedCavalryTypes.Add(CustomBattleState.Helper.GetDefaultTroopOfFormationForFaction(cultureOfTroops, FormationClass.HorseArcher));
     }
 }