# HG changeset patch # User IBBoard # Date 1320006703 0 # Node ID 3882b533d99d3a578dba06238c74fdfabbfcc134 # Parent 61fae5cbba02f7a2df3d386f4382e95d7dc7607f 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 diff -r 61fae5cbba02 -r 3882b533d99d API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs --- 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 { + /// + /// Factory for creating instances of . Data must be in the format: + /// + /// unitID[:count][|unitID[:count][|...]] + /// + /// e.g.: + /// + /// Swordsmen:2|Bowmen + /// + /// 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. + /// + /// + /// Is thrown when the invalid requirement exception. + /// public class UnitRequiresAtLeastNUnitsRequirementFactory : IRequirementFactory { public UnitRequiresAtLeastNUnitsRequirementFactory() @@ -16,7 +30,7 @@ public string AppliesToID { get { - return "RequiresAtLeastNUnits"; + return UnitRequiresAtLeastNUnitsRequirement.REQUIREMENT_ID; } } diff -r 61fae5cbba02 -r 3882b533d99d API/Objects/Requirement/AbstractRequirement.cs --- 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 { + /// + /// 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. + /// + /// + /// The requirement I. + /// + public abstract string RequirementID { get; } + public override bool Equals (object obj) { if (obj == null) diff -r 61fae5cbba02 -r 3882b533d99d API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs --- 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 { /// - /// 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 class. /// public class RequiresAtLeastNUnitsRequirement : AbstractRequirement { + public static readonly string REQUIREMENT_ID = "RequiresAtLeastNUnits"; private List 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; diff -r 61fae5cbba02 -r 3882b533d99d API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs --- 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 @@ /// public class RequiresNoMoreThanNOfUnitTypeRequirement : AbstractRequirement { + public static readonly string REQUIREMENT_ID = "RequiresNoMoreThanNUnits"; private List limitedTypes; public RequiresNoMoreThanNOfUnitTypeRequirement(params UnitType[] limitedUnitTypes) @@ -26,6 +27,14 @@ } } + public override string RequirementID + { + get + { + return REQUIREMENT_ID; + } + } + /// /// Checks whether the supplied WarFoundryObject can be added to the supplied army. ///