Mercurial > repos > IBDev-IBBoard.WarFoundry.API
diff api/Requirements/UnitRequiresAtLeastRequirement.cs @ 82:3ea0ab04352b
* Fix line terminators
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 27 Jun 2009 18:59:49 +0000 |
parents | 306558904c2a |
children | 2f3cafb69799 |
line wrap: on
line diff
--- a/api/Requirements/UnitRequiresAtLeastRequirement.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Requirements/UnitRequiresAtLeastRequirement.cs Sat Jun 27 18:59:49 2009 +0000 @@ -2,28 +2,28 @@ // // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. -using System; +using System; using System.Collections.Generic; using System.Text; using IBBoard.WarFoundry.API; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Requirements -{ - /// <summary> - /// Summary description for UnitRequiresRequirement. - /// </summary> - public class UnitRequiresAtLeastRequirement : UnitRequirement - { +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API.Requirements +{ + /// <summary> + /// Summary description for UnitRequiresRequirement. + /// </summary> + public class UnitRequiresAtLeastRequirement : UnitRequirement + { private UnitType[] requiredTypes; private int[] requiredCounts; - private String unitList; - - public UnitRequiresAtLeastRequirement(UnitType type, UnitType requiredUnitType) : this(type, new UnitType[]{requiredUnitType}, new int[]{1}) - { + private String unitList; + + public UnitRequiresAtLeastRequirement(UnitType type, UnitType requiredUnitType) : this(type, new UnitType[]{requiredUnitType}, new int[]{1}) + { } - public UnitRequiresAtLeastRequirement(UnitType type, UnitType[] requiredUnitTypes, int[] minNumsRequired) : base(type) + public UnitRequiresAtLeastRequirement(UnitType type, UnitType[] requiredUnitTypes, int[] minNumsRequired) : base(type) { if (requiredUnitTypes.Length != minNumsRequired.Length) { @@ -33,52 +33,52 @@ { throw new ArgumentException("List of required unit types must not be empty"); } - + requiredTypes = requiredUnitTypes; - requiredCounts = minNumsRequired; - - if (requiredTypes.Length > 1) - { - StringBuilder sb = new StringBuilder(requiredCounts[0]+" x "+requiredTypes[0].Name); - - for (int i = 1; i<requiredTypes.Length; i++) - { - sb.Append(", "+requiredCounts[i]+" x "+requiredTypes[i].Name); - } - - unitList = sb.ToString(); - } - else - { - unitList = requiredTypes[0].Name; - } - } - - public override string Description - { - get { return "The army must include at least the following units to include a unit of type "+unitType.Name+": "+unitList; } - } - - protected override AbstractFailedRequirement CanRemoveFromArmy(Army army, UnitType type) - { - return null; - } - - protected override AbstractFailedRequirement CanAddToArmy(Army army, UnitType type) + requiredCounts = minNumsRequired; + + if (requiredTypes.Length > 1) + { + StringBuilder sb = new StringBuilder(requiredCounts[0]+" x "+requiredTypes[0].Name); + + for (int i = 1; i<requiredTypes.Length; i++) + { + sb.Append(", "+requiredCounts[i]+" x "+requiredTypes[i].Name); + } + + unitList = sb.ToString(); + } + else + { + unitList = requiredTypes[0].Name; + } + } + + public override string Description + { + get { return "The army must include at least the following units to include a unit of type "+unitType.Name+": "+unitList; } + } + + protected override AbstractFailedRequirement CanRemoveFromArmy(Army army, UnitType type) + { + return null; + } + + protected override AbstractFailedRequirement CanAddToArmy(Army army, UnitType type) { FailedRequirement failure = null; int count = requiredTypes.Length; for (int i = 0; i < count; i++) - { - if (army.GetUnitTypeCount(requiredTypes[i]) < requiredCounts[i]) - { + { + if (army.GetUnitTypeCount(requiredTypes[i]) < requiredCounts[i]) + { failure = new FailedRequirement(this); - break; + break; } } - return failure; - } - } -} + return failure; + } + } +}