changeset 373:e10630f39ec2

Re #351: Add extensible requirement handling method * Add handling of different requirements: * Multiple unit types * Unit types with numbers
author IBBoard <dev@ibboard.co.uk>
date Tue, 14 Jun 2011 14:27:14 +0000
parents 2f8b2467ba99
children 13793f3a2a2e
files API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs
diffstat 1 files changed, 19 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs	Tue Jun 14 13:58:16 2011 +0000
     1.2 +++ b/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs	Tue Jun 14 14:27:14 2011 +0000
     1.3 @@ -14,12 +14,29 @@
     1.4  			//Do nothing special
     1.5  		}
     1.6  
     1.7 -		public UnitRequiresAtLeastNUnitsRequirement CreateRequirement (UnitType type, string data)
     1.8 +		public UnitRequiresAtLeastNUnitsRequirement CreateRequirement(UnitType type, string data)
     1.9  		{
    1.10  			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(type);
    1.11 -			req.AddUnitTypeRequirement(type.Race.GetUnitType(data));
    1.12 +			Race race = type.Race;
    1.13 +			AddRequirements(req, race, data);
    1.14  			return req;
    1.15  		}
    1.16 +
    1.17 +		private void AddRequirements(UnitRequiresAtLeastNUnitsRequirement req, Race race, string data)
    1.18 +		{
    1.19 +			foreach (string requirement in data.Split('|'))
    1.20 +			{
    1.21 +				string[] requirementParts = requirement.Split(':');
    1.22 +				if (requirementParts.Length == 2)
    1.23 +				{
    1.24 +					req.AddUnitTypeRequirement(race.GetUnitType(requirementParts[0]), Int32.Parse(requirementParts[1]));
    1.25 +				}
    1.26 +				else
    1.27 +				{
    1.28 +					req.AddUnitTypeRequirement(race.GetUnitType(requirementParts[0]));
    1.29 +				}
    1.30 +			}
    1.31 +		}
    1.32  	}
    1.33  }
    1.34