Mercurial > repos > IBBoard.WarFoundry.API
changeset 427:3882b533d99d
Re #27: Define unit requirements
* Add ID to requirements so that it isn't just defined in factories
* Make factory use ID from requirement class to avoid duplication and possible mismatch
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 30 Oct 2011 20:31:43 +0000 |
parents | 61fae5cbba02 |
children | 8f5125740316 |
files | API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs API/Objects/Requirement/AbstractRequirement.cs API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs |
diffstat | 4 files changed, 46 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs Fri Oct 28 20:52:29 2011 +0100 +++ b/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs Sun Oct 30 20:31:43 2011 +0000 @@ -7,6 +7,20 @@ namespace IBBoard.WarFoundry.API.Factories.Requirement { + /// <summary> + /// Factory for creating instances of <see cref="UnitRequiresAtLeastNUnitsRequirement" />. Data must be in the format: + /// + /// <code>unitID[:count][|unitID[:count][|...]]</code> + /// + /// e.g.: + /// + /// <code>Swordsmen:2|Bowmen</code> + /// + /// would generate a requirement to allow any number of the unit type after 1 unit with ID Bowmen or 2 units with ID Swordsmen were added. + /// </summary> + /// <exception cref='InvalidRequirementException'> + /// Is thrown when the invalid requirement exception. + /// </exception> public class UnitRequiresAtLeastNUnitsRequirementFactory : IRequirementFactory { public UnitRequiresAtLeastNUnitsRequirementFactory() @@ -16,7 +30,7 @@ public string AppliesToID { get { - return "RequiresAtLeastNUnits"; + return UnitRequiresAtLeastNUnitsRequirement.REQUIREMENT_ID; } }
--- a/API/Objects/Requirement/AbstractRequirement.cs Fri Oct 28 20:52:29 2011 +0100 +++ b/API/Objects/Requirement/AbstractRequirement.cs Sun Oct 30 20:31:43 2011 +0000 @@ -8,6 +8,15 @@ { public abstract class AbstractRequirement : IRequirement { + /// <summary> + /// Gets the ID of the requirement type. This is used by the requirement factories. + /// It may be, but is not required to be, the name of the class. + /// </summary> + /// <value> + /// The requirement I. + /// </value> + public abstract string RequirementID { get; } + public override bool Equals (object obj) { if (obj == null)
--- a/API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs Fri Oct 28 20:52:29 2011 +0100 +++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs Sun Oct 30 20:31:43 2011 +0000 @@ -9,10 +9,13 @@ namespace IBBoard.WarFoundry.API.Objects.Requirement { /// <summary> - /// A requirement where a WarFoundryObject requires at least N units of one or more unit types before any number of that object can be taken in an army. + /// A requirement where a WarFoundryObject requires at least N units of any of the specified unit types before any number of that object can be taken in an army. + /// + /// The definition for how this requirement is built from a data file is defined in the <see cref="UnitRequiresAtLeastNUnitsRequirementFactory"/> class. /// </summary> public class RequiresAtLeastNUnitsRequirement : AbstractRequirement { + public static readonly string REQUIREMENT_ID = "RequiresAtLeastNUnits"; private List<UnitCountRequirementData> requiredTypes; public RequiresAtLeastNUnitsRequirement(params UnitType[] requiredUnitTypes) @@ -26,6 +29,15 @@ } } + + public override string RequirementID + { + get + { + return REQUIREMENT_ID; + } + } + protected override bool TypeEquals (object obj) { RequiresAtLeastNUnitsRequirement otherReq = (RequiresAtLeastNUnitsRequirement)obj;
--- a/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs Fri Oct 28 20:52:29 2011 +0100 +++ b/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs Sun Oct 30 20:31:43 2011 +0000 @@ -13,6 +13,7 @@ /// </summary> public class RequiresNoMoreThanNOfUnitTypeRequirement : AbstractRequirement { + public static readonly string REQUIREMENT_ID = "RequiresNoMoreThanNUnits"; private List<UnitCountRequirementData> limitedTypes; public RequiresNoMoreThanNOfUnitTypeRequirement(params UnitType[] limitedUnitTypes) @@ -26,6 +27,14 @@ } } + public override string RequirementID + { + get + { + return REQUIREMENT_ID; + } + } + /// <summary> /// Checks whether the supplied WarFoundryObject can be added to the supplied army. /// </summary>