Mercurial > repos > IBBoard.WarFoundry.API
diff api/Requirements/UnitRequiresAtLeastRequirement.cs @ 229:6083010a005c
Re #223: Use translations within the API
* Update requirements to use translations
* Remove duplicate classes
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 21 Dec 2009 20:37:35 +0000 |
parents | 2f3cafb69799 |
children | 73da8d13ce69 |
line wrap: on
line diff
--- a/api/Requirements/UnitRequiresAtLeastRequirement.cs Sun Dec 20 20:59:28 2009 +0000 +++ b/api/Requirements/UnitRequiresAtLeastRequirement.cs Mon Dec 21 20:37:35 2009 +0000 @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Text; +using IBBoard.Lang; using IBBoard.WarFoundry.API; using IBBoard.WarFoundry.API.Objects; @@ -15,48 +16,37 @@ /// </summary> public class UnitRequiresAtLeastRequirement : UnitRequirement { - private UnitType[] requiredTypes; - private int[] requiredCounts; + private UnitRequirementItem[] requiredTypes; private String unitList; - public UnitRequiresAtLeastRequirement(UnitType type, UnitType requiredUnitType) : this(type, new UnitType[]{requiredUnitType}, new int[]{1}) + public UnitRequiresAtLeastRequirement(UnitType type, UnitType requiredUnitType) : this(type, new UnitRequirementItem[]{new UnitRequirementItem(requiredUnitType)}) { } - public UnitRequiresAtLeastRequirement(UnitType type, UnitType[] requiredUnitTypes, int[] minNumsRequired) : base(type) - { - if (requiredUnitTypes.Length != minNumsRequired.Length) - { - throw new ArgumentException("List of required unit types and list of number of units required must be equal"); - } - else if (requiredUnitTypes.Length == 1) - { - throw new ArgumentException("List of required unit types must not be empty"); - } - + public UnitRequiresAtLeastRequirement(UnitType type, UnitRequirementItem[] requiredUnitTypes) : base(type) + { requiredTypes = requiredUnitTypes; - requiredCounts = minNumsRequired; - - if (requiredTypes.Length > 1) + bool first = true; + + foreach (UnitRequirementItem req in requiredTypes) { - StringBuilder sb = new StringBuilder(requiredCounts[0]+" x "+requiredTypes[0].Name); - - for (int i = 1; i<requiredTypes.Length; i++) + string reqString = Translation.GetTranslation("requirementUnitTypeAtLeastSingle", "{1} {0}", req.UnitType.Name, req.Amount); + + if (first) { - sb.Append(", "+requiredCounts[i]+" x "+requiredTypes[i].Name); + first = false; + unitList = reqString; } - - unitList = sb.ToString(); - } - else - { - unitList = requiredTypes[0].Name; + else + { + unitList = Translation.GetTranslation("requirementUnitTypeAtLeastJoiner", "{0}, {1}", unitList, reqString); + } } } public override string Description { - get { return "The army must include at least the following units to include a unit of type "+unitType.Name+": "+unitList; } + get { return Translation.GetTranslation("requirementUnitTypeAtLeast", "the army must include at least the following units to include a unit of type {0}: {1}", unitType.Name, unitList); } } protected override AbstractFailedRequirement CanRemoveFromArmy(Army army, UnitType type)