changeset 455:afc6410e4efc

Re #379: Fix validation of requirements to check for unit * Move to "Unit" requirements, since we assume things depend on units * Rename some classes to more meaningful names from unit-based change * Rename "requires N for M" requirement as we can make it more flexible
author IBBoard <dev@ibboard.co.uk>
date Wed, 22 Feb 2012 20:45:39 +0000
parents def5d333c5e8
children 52baffdd2ab9
files API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactory.cs API/Objects/Requirement/AbstractRequirement.cs API/Objects/Requirement/AbstractUnitRequirement.cs API/Objects/Requirement/IRequirement.cs API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs API/Objects/Requirement/RequiresNUnitsForMObjectsRequirement.cs API/Objects/Requirement/RequiresNUnitsForMUnitsRequirement.cs API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirement.cs API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs API/Objects/UnitType.cs IBBoard.WarFoundry.API.csproj
diffstat 13 files changed, 597 insertions(+), 499 deletions(-) [+]
line diff
     1.1 --- a/API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactory.cs	Tue Jan 31 20:58:09 2012 +0000
     1.2 +++ b/API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactory.cs	Wed Feb 22 20:45:39 2012 +0000
     1.3 @@ -19,19 +19,19 @@
     1.4  		{
     1.5  			get
     1.6  			{
     1.7 -				return RequiresNUnitsForMUnitsRequirement.REQUIREMENT_ID;
     1.8 +				return UnitRequiresNUnitsForMUnitsRequirement.REQUIREMENT_ID;
     1.9  			}
    1.10  		}
    1.11  
    1.12  		public IRequirement CreateRequirement<SOURCE_FILE_TYPE, ENTRY_TYPE>(UnitType type, string data, IRaceFactory<SOURCE_FILE_TYPE, ENTRY_TYPE> raceFactory)
    1.13  		{
    1.14 -			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(type);
    1.15 +			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(type);
    1.16  			Race race = type.Race;
    1.17  			AddRequirements(req, race, data, raceFactory);
    1.18  			return req;
    1.19  		}
    1.20  
    1.21 -		private void AddRequirements<SOURCE_FILE_TYPE, ENTRY_TYPE>(RequiresNUnitsForMUnitsRequirement req, Race race, string data, IRaceFactory<SOURCE_FILE_TYPE, ENTRY_TYPE> raceFactory)
    1.22 +		private void AddRequirements<SOURCE_FILE_TYPE, ENTRY_TYPE>(UnitRequiresNUnitsForMUnitsRequirement req, Race race, string data, IRaceFactory<SOURCE_FILE_TYPE, ENTRY_TYPE> raceFactory)
    1.23  		{
    1.24  			foreach (string requirement in data.Split('|'))
    1.25  			{
     2.1 --- a/API/Objects/Requirement/AbstractRequirement.cs	Tue Jan 31 20:58:09 2012 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,105 +0,0 @@
     2.4 -// This file (AbstractRequirement.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard
     2.5 -// 
     2.6 -// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
     2.7 -using System;
     2.8 -
     2.9 -namespace IBBoard.WarFoundry.API.Objects.Requirement
    2.10 -{
    2.11 -	public abstract class AbstractRequirement : IRequirement
    2.12 -	{
    2.13 -		public abstract string RequirementID { get; }
    2.14 -
    2.15 -		public override bool Equals(object obj)
    2.16 -		{
    2.17 -			if (obj == null)
    2.18 -			{
    2.19 -				return false;
    2.20 -			}
    2.21 -			else if (obj.GetType().Equals(this.GetType()))
    2.22 -			{
    2.23 -				return TypeEquals(obj);
    2.24 -			}
    2.25 -			else
    2.26 -			{
    2.27 -				return false;
    2.28 -			}
    2.29 -		}
    2.30 -
    2.31 -		public override abstract int GetHashCode();
    2.32 -
    2.33 -		/// <summary>
    2.34 -		/// Type-specific equality checking - must be implemented by each class
    2.35 -		/// </summary>
    2.36 -		/// <returns>
    2.37 -		/// <code>true</code> if this object is equal to <code>obj</code>, else <code>false</code>
    2.38 -		/// </returns>
    2.39 -		/// <param name='obj'>
    2.40 -		/// The object to compare to
    2.41 -		/// </param>
    2.42 -		protected abstract bool TypeEquals(object obj);
    2.43 -
    2.44 -		protected virtual bool IsApplicable(WarFoundryObject toObjectAdded, Army toArmy)
    2.45 -		{
    2.46 -			return IsApplicable(toArmy) || IsApplicable(toObjectAdded);
    2.47 -		}
    2.48 -
    2.49 -		protected virtual bool IsApplicable(Army toArmy)
    2.50 -		{
    2.51 -			return true;
    2.52 -		}
    2.53 -
    2.54 -		protected virtual bool IsApplicable(WarFoundryObject toObject)
    2.55 -		{
    2.56 -			return true;
    2.57 -		}
    2.58 -
    2.59 -		public string GetValidationMessage(Army army)
    2.60 -		{
    2.61 -			string message = "";
    2.62 -
    2.63 -			Validation result = ValidatesArmy(army);
    2.64 -			if (!Validates.AsOkay(result))
    2.65 -			{
    2.66 -				message = GetValidationFailedMessage(army);
    2.67 -			}
    2.68 -
    2.69 -			return message;
    2.70 -		}
    2.71 -
    2.72 -		protected virtual string ValidationFailedMessage { get { return "Army must contain: {0}."; } }
    2.73 -
    2.74 -		private string GetValidationFailedMessage(Army army)
    2.75 -		{
    2.76 -			return String.Format(ValidationFailedMessage, GetFailedRequirementsString(army));
    2.77 -		}
    2.78 -
    2.79 -		protected abstract string GetFailedRequirementsString(Army army);
    2.80 -
    2.81 -		public string GetAllowsAddingMessage(UnitType toAdd, Army toArmy)
    2.82 -		{
    2.83 -			string message = "";
    2.84 -
    2.85 -			Validation result = AllowsAdding(toAdd, toArmy);
    2.86 -			if (!Validates.AsOkay(result))
    2.87 -			{
    2.88 -				message = GetAllowsAddingFailedMessage(toAdd, toArmy);
    2.89 -			}
    2.90 -
    2.91 -			return message;
    2.92 -		}
    2.93 -
    2.94 -		protected virtual string AllowsAddingFailedMessage { get { return ValidationFailedMessage; } }
    2.95 -
    2.96 -		protected string GetAllowsAddingFailedMessage(UnitType toAdd, Army toArmy)
    2.97 -		{
    2.98 -			return String.Format(AllowsAddingFailedMessage, GetFailedAddingRequirementsString(toAdd, toArmy));
    2.99 -		}
   2.100 -
   2.101 -		protected abstract string GetFailedAddingRequirementsString(UnitType toAdd, Army toArmy);
   2.102 -
   2.103 -		public abstract  Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy);
   2.104 -
   2.105 -		public abstract  Validation ValidatesArmy(Army army);
   2.106 -	}
   2.107 -}
   2.108 -
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/API/Objects/Requirement/AbstractUnitRequirement.cs	Wed Feb 22 20:45:39 2012 +0000
     3.3 @@ -0,0 +1,164 @@
     3.4 +// This file (AbstractRequirement.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard
     3.5 +// 
     3.6 +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
     3.7 +using System;
     3.8 +using System.Collections.Generic;
     3.9 +
    3.10 +namespace IBBoard.WarFoundry.API.Objects.Requirement
    3.11 +{
    3.12 +	public abstract class AbstractUnitRequirement<OBJECT_TYPE> : IRequirement where OBJECT_TYPE : IWarFoundryObject
    3.13 +	{
    3.14 +		private List<UnitCountRequirementData> requiredTypes;
    3.15 +		private OBJECT_TYPE allowedObject;
    3.16 +
    3.17 +		public AbstractUnitRequirement(OBJECT_TYPE allowedObject, params UnitType[] requiredUnitTypes)
    3.18 +		{
    3.19 +			this.allowedObject = allowedObject;
    3.20 +			requiredTypes = new List<UnitCountRequirementData>();
    3.21 +
    3.22 +			foreach (UnitType unitType in requiredUnitTypes)
    3.23 +			{
    3.24 +				AddUnitTypeRequirement(unitType);
    3.25 +			}
    3.26 +		}
    3.27 +
    3.28 +		public abstract string RequirementID { get; }
    3.29 +
    3.30 +		protected List<UnitCountRequirementData> RequiredTypes { get { return requiredTypes; } }
    3.31 +
    3.32 +		public abstract void AddUnitTypeRequirement(UnitType unitType);
    3.33 +
    3.34 +		public override bool Equals(object obj)
    3.35 +		{
    3.36 +			if (obj == null)
    3.37 +			{
    3.38 +				return false;
    3.39 +			}
    3.40 +			else if (obj.GetType().Equals(this.GetType()))
    3.41 +			{
    3.42 +				return TypeEquals(obj);
    3.43 +			}
    3.44 +			else
    3.45 +			{
    3.46 +				return false;
    3.47 +			}
    3.48 +		}
    3.49 +
    3.50 +		public override abstract int GetHashCode();
    3.51 +
    3.52 +		/// <summary>
    3.53 +		/// Type-specific equality checking - must be implemented by each class
    3.54 +		/// </summary>
    3.55 +		/// <returns>
    3.56 +		/// <code>true</code> if this object is equal to <code>obj</code>, else <code>false</code>
    3.57 +		/// </returns>
    3.58 +		/// <param name='obj'>
    3.59 +		/// The object to compare to
    3.60 +		/// </param>
    3.61 +		protected abstract bool TypeEquals(object obj);
    3.62 +
    3.63 +		protected virtual bool IsApplicable(IWarFoundryObject toObjectAdded, Army toArmy)
    3.64 +		{
    3.65 +			return IsApplicable(toArmy) || IsApplicable(toObjectAdded);
    3.66 +		}
    3.67 +
    3.68 +		protected virtual bool IsApplicable(Army toArmy)
    3.69 +		{
    3.70 +			return true;
    3.71 +		}
    3.72 +
    3.73 +		protected virtual bool IsApplicable(IWarFoundryObject toObject)
    3.74 +		{
    3.75 +			return true;
    3.76 +		}
    3.77 +
    3.78 +		public string GetValidationMessage(Army army)
    3.79 +		{
    3.80 +			string message = "";
    3.81 +
    3.82 +			Validation result = ValidatesArmy(army);
    3.83 +			if (!Validates.AsOkay(result))
    3.84 +			{
    3.85 +				message = GetValidationFailedMessage(army);
    3.86 +			}
    3.87 +
    3.88 +			return message;
    3.89 +		}
    3.90 +
    3.91 +		protected virtual string ValidationFailedMessage { get { return "Army must contain: {0}."; } }
    3.92 +
    3.93 +		private string GetValidationFailedMessage(Army army)
    3.94 +		{
    3.95 +			return String.Format(ValidationFailedMessage, GetFailedRequirementsString(army));
    3.96 +		}
    3.97 +
    3.98 +		protected abstract string GetFailedRequirementsString(Army army);
    3.99 +
   3.100 +		public string GetAllowsAddingMessage(IWarFoundryObject toAdd, Army toArmy)
   3.101 +		{
   3.102 +			string message = "";
   3.103 +
   3.104 +			Validation result = AllowsAdding(toAdd, toArmy);
   3.105 +			if (!Validates.AsOkay(result))
   3.106 +			{
   3.107 +				message = GetAllowsAddingFailedMessage(toAdd, toArmy);
   3.108 +			}
   3.109 +
   3.110 +			return message;
   3.111 +		}
   3.112 +
   3.113 +		protected virtual string AllowsAddingFailedMessage { get { return ValidationFailedMessage; } }
   3.114 +
   3.115 +		protected string GetAllowsAddingFailedMessage(IWarFoundryObject toAdd, Army toArmy)
   3.116 +		{
   3.117 +			return String.Format(AllowsAddingFailedMessage, GetFailedAddingRequirementsString(toAdd, toArmy));
   3.118 +		}
   3.119 +
   3.120 +		protected abstract string GetFailedAddingRequirementsString(IWarFoundryObject toAdd, Army toArmy);
   3.121 +
   3.122 +		public abstract  Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy);
   3.123 +
   3.124 +		public abstract  Validation ValidatesArmy(Army army);
   3.125 +
   3.126 +		protected UnitType GetUnitTypeFromObject(IWarFoundryObject toObject)
   3.127 +		{
   3.128 +			UnitType unitType = null;
   3.129 +
   3.130 +			if (toObject is UnitType)
   3.131 +			{
   3.132 +				unitType = (UnitType)toObject;
   3.133 +			}
   3.134 +			else if (toObject is Unit)
   3.135 +			{
   3.136 +				unitType = ((Unit)toObject).UnitType;
   3.137 +			}
   3.138 +
   3.139 +			return unitType;
   3.140 +		}
   3.141 +
   3.142 +		protected int GetUnitTypeCount(Army toArmy, UnitType unitType, IWarFoundryObject wfObject)
   3.143 +		{
   3.144 +			return toArmy.GetUnitTypeCount(unitType) + GetCountFromObject(wfObject, unitType);
   3.145 +		}
   3.146 +
   3.147 +		protected int GetCountFromObject(IWarFoundryObject wfObject, UnitType limitedType)
   3.148 +		{
   3.149 +			return (limitedType.Equals(wfObject) || (wfObject is Unit && ((Unit)wfObject).UnitType.Equals(limitedType))) ? 1 : 0;
   3.150 +		}
   3.151 +
   3.152 +		protected int GetObjectCount(Army toArmy, IWarFoundryObject wfObject)
   3.153 +		{
   3.154 +			return GetObjectCountFromArmy(toArmy) + GetObjectCountFromObject(wfObject);
   3.155 +		}
   3.156 +
   3.157 +		protected abstract int GetObjectCountFromArmy(Army toArmy);
   3.158 +
   3.159 +		protected virtual int GetObjectCountFromObject(IWarFoundryObject wfObject)
   3.160 +		{
   3.161 +			return allowedObject.Equals(wfObject) ? 1 : 0;
   3.162 +		}
   3.163 +
   3.164 +		public OBJECT_TYPE AllowedObject { get { return allowedObject; } }
   3.165 +	}
   3.166 +}
   3.167 +
     4.1 --- a/API/Objects/Requirement/IRequirement.cs	Tue Jan 31 20:58:09 2012 +0000
     4.2 +++ b/API/Objects/Requirement/IRequirement.cs	Wed Feb 22 20:45:39 2012 +0000
     4.3 @@ -6,7 +6,7 @@
     4.4  namespace IBBoard.WarFoundry.API.Objects.Requirement
     4.5  {
     4.6  	/// <summary>
     4.7 -	/// Base interface for a Requirement that constrains the units/equipment that can be taken in an army
     4.8 +	/// Base interface for a Requirement that constrains the IWarFoundryObjects that can be taken in an army
     4.9  	/// </summary>
    4.10  	public interface IRequirement
    4.11  	{
    4.12 @@ -20,7 +20,7 @@
    4.13  		string RequirementID { get; }
    4.14  
    4.15  		/// <summary>
    4.16 -		/// Checks whether the supplied WarFoundryObject can be added to the supplied army.
    4.17 +		/// Checks whether the supplied IWarFoundryObject can be added to the supplied army.
    4.18  		/// </summary>
    4.19  		/// <returns>
    4.20  		/// A <code>Validation</code> enum to show the result of the validation
    4.21 @@ -31,7 +31,7 @@
    4.22  		/// <param name='toArmy'>
    4.23  		/// The army to add the object to.
    4.24  		/// </param>
    4.25 -		Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy);
    4.26 +		Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy);
    4.27  
    4.28  		/// <summary>
    4.29  		/// Checks whether the supplied army is currently valid according to this requirement.
    4.30 @@ -56,18 +56,18 @@
    4.31  		string GetValidationMessage(Army army);
    4.32  
    4.33  		/// <summary>
    4.34 -		/// Gets the validation message for adding a unit to the army
    4.35 +		/// Gets the validation message for adding an IWarFoundryObject to the army
    4.36  		/// </summary>
    4.37  		/// <returns>
    4.38 -		/// A validation message, if the type cannot be added, else an empty string.
    4.39 +		/// A validation message, if the object cannot be added, else an empty string.
    4.40  		/// </returns>
    4.41  		/// <param name='toAdd'>
    4.42 -		/// The unit type to try to add
    4.43 +		/// The IWarFoundryObject to try to add
    4.44  		/// </param>
    4.45  		/// <param name='toArmy'>
    4.46 -		/// The army the unit will be added to
    4.47 +		/// The army the object will be added to
    4.48  		/// </param>
    4.49 -		string GetAllowsAddingMessage(UnitType toAdd, Army toArmy);
    4.50 +		string GetAllowsAddingMessage(IWarFoundryObject toAdd, Army toArmy);
    4.51  	}
    4.52  }
    4.53  
     5.1 --- a/API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs	Tue Jan 31 20:58:09 2012 +0000
     5.2 +++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs	Wed Feb 22 20:45:39 2012 +0000
     5.3 @@ -13,19 +13,13 @@
     5.4  	///
     5.5  	/// The definition for how this requirement is built from a data file is defined in the <see cref="UnitRequiresAtLeastNUnitsRequirementFactory"/> class.
     5.6  	/// </summary>
     5.7 -	public class RequiresAtLeastNUnitsRequirement : AbstractRequirement
     5.8 +	public class RequiresAtLeastNUnitsRequirement<OBJECT_TYPE> : AbstractUnitRequirement<OBJECT_TYPE> where OBJECT_TYPE : IWarFoundryObject
     5.9  	{
    5.10  		public static readonly string REQUIREMENT_ID = "RequiresAtLeastNUnits";
    5.11 -		private List<UnitCountRequirementData> requiredTypes;
    5.12  
    5.13 -		public RequiresAtLeastNUnitsRequirement(params UnitType[] requiredUnitTypes)
    5.14 +		public RequiresAtLeastNUnitsRequirement(OBJECT_TYPE requirementOn, params UnitType[] requiredUnitTypes) : base(requirementOn, requiredUnitTypes)
    5.15  		{
    5.16 -			requiredTypes = new List<UnitCountRequirementData>();
    5.17 -
    5.18 -			foreach (UnitType unitType in requiredUnitTypes)
    5.19 -			{
    5.20 -				AddUnitTypeRequirement(unitType);
    5.21 -			}
    5.22 +			//Do nothing
    5.23  		}
    5.24  
    5.25  		public override string RequirementID
    5.26 @@ -38,8 +32,8 @@
    5.27  
    5.28  		protected override bool TypeEquals(object obj)
    5.29  		{
    5.30 -			RequiresAtLeastNUnitsRequirement otherReq = (RequiresAtLeastNUnitsRequirement)obj;
    5.31 -			if (!Collections.Collections.AreEqual(requiredTypes, otherReq.requiredTypes))
    5.32 +			RequiresAtLeastNUnitsRequirement<OBJECT_TYPE> otherReq = (RequiresAtLeastNUnitsRequirement<OBJECT_TYPE>)obj;
    5.33 +			if (!Collections.Collections.AreEqual(RequiredTypes, otherReq.RequiredTypes))
    5.34  			{
    5.35  				return false;
    5.36  			}
    5.37 @@ -53,7 +47,7 @@
    5.38  		{
    5.39  			int hash = 0;
    5.40  
    5.41 -			foreach (UnitCountRequirementData req in requiredTypes)
    5.42 +			foreach (UnitCountRequirementData req in RequiredTypes)
    5.43  			{
    5.44  				hash += req.UnitType.GetHashCode();
    5.45  			}
    5.46 @@ -73,7 +67,7 @@
    5.47  		/// <param name='toArmy'>
    5.48  		/// The army to add the object to.
    5.49  		/// </param>
    5.50 -		public override Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy)
    5.51 +		public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy)
    5.52  		{
    5.53  			return IsApplicable(wfObject, toArmy) ? CheckAllowsAdding(wfObject, toArmy) : Validation.NotApplicable;
    5.54  		}
    5.55 @@ -83,7 +77,7 @@
    5.56  			return false;
    5.57  		}
    5.58  
    5.59 -		protected override bool IsApplicable(WarFoundryObject toObject)
    5.60 +		protected override bool IsApplicable(IWarFoundryObject toObject)
    5.61  		{
    5.62  			bool isApplicable = false;
    5.63  			UnitType unitType = GetUnitTypeFromObject(toObject);
    5.64 @@ -96,26 +90,10 @@
    5.65  			return isApplicable;
    5.66  		}
    5.67  
    5.68 -		protected UnitType GetUnitTypeFromObject(WarFoundryObject toObject)
    5.69 -		{
    5.70 -			UnitType unitType = null;
    5.71 -
    5.72 -			if (toObject is UnitType)
    5.73 -			{
    5.74 -				unitType = (UnitType)toObject;
    5.75 -			}
    5.76 -			else if (toObject is Unit)
    5.77 -			{
    5.78 -				unitType = ((Unit)toObject).UnitType;
    5.79 -			}
    5.80 -
    5.81 -			return unitType;
    5.82 -		}
    5.83 -
    5.84  		private bool IsApplicable(UnitType unitType)
    5.85  		{
    5.86  			bool isApplicable = false;
    5.87 -			foreach (UnitCountRequirementData requirement in requiredTypes)
    5.88 +			foreach (UnitCountRequirementData requirement in RequiredTypes)
    5.89  			{
    5.90  				if (requirement.UnitType.Equals(unitType))
    5.91  				{
    5.92 @@ -126,11 +104,11 @@
    5.93  			return isApplicable;
    5.94  		}
    5.95  
    5.96 -		private Validation CheckAllowsAdding(WarFoundryObject wfObject, Army toArmy)
    5.97 +		private Validation CheckAllowsAdding(IWarFoundryObject wfObject, Army toArmy)
    5.98  		{
    5.99  			Validation isValid = Validation.Passed;
   5.100  			
   5.101 -			foreach (UnitCountRequirementData requirement in requiredTypes)
   5.102 +			foreach (UnitCountRequirementData requirement in RequiredTypes)
   5.103  			{
   5.104  				if (GetUnitTypeCount(toArmy, requirement.UnitType, wfObject) < requirement.Count)
   5.105  				{
   5.106 @@ -142,16 +120,6 @@
   5.107  			return isValid;
   5.108  		}
   5.109  
   5.110 -		private int GetUnitTypeCount(Army toArmy, UnitType unitType, WarFoundryObject wfObject)
   5.111 -		{
   5.112 -			return toArmy.GetUnitTypeCount(unitType) + GetCountFromObject(wfObject, unitType);
   5.113 -		}
   5.114 -
   5.115 -		private int GetCountFromObject(WarFoundryObject wfObject, UnitType limitedType)
   5.116 -		{
   5.117 -			return (limitedType.Equals(wfObject) || (wfObject is Unit && ((Unit)wfObject).UnitType.Equals(limitedType))) ? 1 : 0;
   5.118 -		}
   5.119 -
   5.120  		/// <summary>
   5.121  		/// Adds a requirement for there to be at least minCount of a given UnitType
   5.122  		/// </summary>
   5.123 @@ -163,7 +131,7 @@
   5.124  		/// </param>
   5.125  		public void AddUnitTypeRequirement(UnitType unitType, int minCount)
   5.126  		{
   5.127 -			requiredTypes.Add(new UnitCountRequirementData(unitType, minCount));
   5.128 +			RequiredTypes.Add(new UnitCountRequirementData(unitType, minCount));
   5.129  		}
   5.130  
   5.131  		/// <summary>
   5.132 @@ -172,7 +140,7 @@
   5.133  		/// <param name='unitType'>
   5.134  		/// The unit type to require.
   5.135  		/// </param>
   5.136 -		public void AddUnitTypeRequirement(UnitType unitType)
   5.137 +		public override void AddUnitTypeRequirement(UnitType unitType)
   5.138  		{
   5.139  			AddUnitTypeRequirement(unitType, 1);
   5.140  		}
   5.141 @@ -190,7 +158,7 @@
   5.142  		{
   5.143  			Validation isValid = Validation.Passed;
   5.144  
   5.145 -			foreach (UnitCountRequirementData requirement in requiredTypes)
   5.146 +			foreach (UnitCountRequirementData requirement in RequiredTypes)
   5.147  			{
   5.148  				if (toValidate.GetUnitTypeCount(requirement.UnitType) < requirement.Count)
   5.149  				{
   5.150 @@ -211,7 +179,7 @@
   5.151  		{
   5.152  			List<string> failures = new List<string>();
   5.153  
   5.154 -			foreach (UnitCountRequirementData requirement in requiredTypes)
   5.155 +			foreach (UnitCountRequirementData requirement in RequiredTypes)
   5.156  			{
   5.157  				int unitCount = army.GetUnitTypeCount(requirement.UnitType);
   5.158  
   5.159 @@ -224,18 +192,18 @@
   5.160  			return failures;
   5.161  		}
   5.162  
   5.163 -		protected override string GetFailedAddingRequirementsString(UnitType toAdd, Army toArmy)
   5.164 +		protected override string GetFailedAddingRequirementsString(IWarFoundryObject toAdd, Army toArmy)
   5.165  		{
   5.166  			return String.Join("; ", GetFailedAddingRequirements(toAdd, toArmy).ToArray());
   5.167  		}
   5.168  
   5.169 -		private List<string> GetFailedAddingRequirements(UnitType unitType, Army army)
   5.170 +		private List<string> GetFailedAddingRequirements(IWarFoundryObject toAdd, Army army)
   5.171  		{
   5.172  			List<string> failures = new List<string>();
   5.173  
   5.174 -			foreach (UnitCountRequirementData requirement in requiredTypes)
   5.175 +			foreach (UnitCountRequirementData requirement in RequiredTypes)
   5.176  			{
   5.177 -				int unitCount = GetUnitTypeCount(army, requirement.UnitType, unitType);
   5.178 +				int unitCount = GetUnitTypeCount(army, requirement.UnitType, toAdd);
   5.179  
   5.180  				if (unitCount < requirement.Count)
   5.181  				{
   5.182 @@ -245,6 +213,11 @@
   5.183  
   5.184  			return failures;
   5.185  		}
   5.186 +
   5.187 +		protected override int GetObjectCountFromArmy(Army toArmy)
   5.188 +		{
   5.189 +			return 0;
   5.190 +		}
   5.191  	}
   5.192  }
   5.193  
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/API/Objects/Requirement/RequiresNUnitsForMObjectsRequirement.cs	Wed Feb 22 20:45:39 2012 +0000
     6.3 @@ -0,0 +1,281 @@
     6.4 +// This file(RequiresNUnitsForMUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard
     6.5 +// 
     6.6 +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or(at your option) any later version. Please see COPYING for more information and the full license.
     6.7 +using System;
     6.8 +using System.Collections.Generic;
     6.9 +using System.Text;
    6.10 +
    6.11 +namespace IBBoard.WarFoundry.API.Objects.Requirement
    6.12 +{
    6.13 +	public abstract class RequiresNUnitsForMObjectsRequirement<OBJECT_TYPE> : AbstractUnitRequirement<OBJECT_TYPE> where OBJECT_TYPE : IWarFoundryObject
    6.14 +	{
    6.15 +		public RequiresNUnitsForMObjectsRequirement(OBJECT_TYPE allowedObject, params UnitType[] requiredUnitTypes) : base(allowedObject, requiredUnitTypes)
    6.16 +		{
    6.17 +			//Do nothing
    6.18 +		}
    6.19 +
    6.20 +		public override int GetHashCode()
    6.21 +		{
    6.22 +			int hash = 0;
    6.23 +
    6.24 +			foreach (UnitCountRequirementData req in RequiredTypes)
    6.25 +			{
    6.26 +				hash += req.UnitType.GetHashCode();
    6.27 +			}
    6.28 +
    6.29 +			return hash;
    6.30 +		}
    6.31 +
    6.32 +		protected override bool TypeEquals(object obj)
    6.33 +		{
    6.34 +			RequiresNUnitsForMObjectsRequirement<OBJECT_TYPE> otherReq = (RequiresNUnitsForMObjectsRequirement<OBJECT_TYPE>)obj;
    6.35 +			if (!Collections.Collections.AreEqual(RequiredTypes, otherReq.RequiredTypes))
    6.36 +			{
    6.37 +				return false;
    6.38 +			}
    6.39 +			else
    6.40 +			{
    6.41 +				return true;
    6.42 +			}
    6.43 +		}
    6.44 +
    6.45 +		protected override string GetFailedAddingRequirementsString(IWarFoundryObject toAdd, Army toArmy)
    6.46 +		{
    6.47 +			return String.Join("; ", GetFailedAddingRequirements(toAdd, toArmy).ToArray());
    6.48 +		}
    6.49 +
    6.50 +		private List<string> GetFailedAddingRequirements(IWarFoundryObject obj, Army toArmy)
    6.51 +		{
    6.52 +			List<string> failures = new List<string>();
    6.53 +			int allowedObjectCount = GetAllowedObjectCount(toArmy, AllowedObject, obj);
    6.54 +
    6.55 +			foreach (UnitCountRequirementData limit in RequiredTypes)
    6.56 +			{
    6.57 +				int limitedTypeCount = GetUnitTypesCount(toArmy, limit.UnitTypes, obj);
    6.58 +
    6.59 +				if (!IsValidByRequirement(obj, toArmy, limit, allowedObjectCount))
    6.60 +				{
    6.61 +					string unitTypeList = GetUnitTypeList(limit);
    6.62 +					failures.Add(String.Format("{0} × {1} for every {2} × {3} (would have {4} for {5})", limit.Count, unitTypeList, limit.AllowsCount, AllowedObject.Name, limitedTypeCount, allowedObjectCount));
    6.63 +				}
    6.64 +			}
    6.65 +
    6.66 +			return failures;
    6.67 +		}
    6.68 +
    6.69 +		private string GetUnitTypeList(UnitCountRequirementData limit)
    6.70 +		{
    6.71 +			List<String> namesList = new List<String>();
    6.72 +
    6.73 +			foreach (UnitType unitType in limit.UnitTypes)
    6.74 +			{
    6.75 +				namesList.Add(unitType.Name);
    6.76 +			}
    6.77 +
    6.78 +			string[] names = namesList.ToArray();
    6.79 +			return String.Join(" or ", names);
    6.80 +		}
    6.81 +
    6.82 +		private bool IsValidByRequirement(IWarFoundryObject wfObject, Army toArmy, UnitCountRequirementData limit, int allowedTypeCount)
    6.83 +		{
    6.84 +			int limitedTypeCount = GetUnitTypesCount(toArmy, limit.UnitTypes, wfObject);
    6.85 +			return IsValidByRequirement(limit, allowedTypeCount, limitedTypeCount);
    6.86 +		}
    6.87 +
    6.88 +		private bool IsValidByRequirement(UnitCountRequirementData limit, int allowedTypeCount, int limitedTypeCount)
    6.89 +		{
    6.90 +			int wholeNumLimited = (limitedTypeCount / limit.Count);
    6.91 +			double allowedRatio = (limit.AllowsCount / (limit.Count * 1.0));
    6.92 +			return allowedRatio * wholeNumLimited >= allowedTypeCount;
    6.93 +		}
    6.94 +
    6.95 +		public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy)
    6.96 +		{
    6.97 +			Validation canAdd = Validation.NotApplicable;
    6.98 +			UnitType addedUnitType = (wfObject is Unit) ? ((Unit)wfObject).UnitType : wfObject as UnitType;
    6.99 +			bool typeFound = (wfObject == (IWarFoundryObject)AllowedObject);
   6.100 +			int allowedTypeCount = GetAllowedObjectCount(toArmy, AllowedObject, wfObject);
   6.101 +
   6.102 +			foreach (UnitCountRequirementData limit in RequiredTypes)
   6.103 +			{
   6.104 +				typeFound |= (addedUnitType == limit.UnitType);
   6.105 +
   6.106 +				if (!IsValidByRequirement(wfObject, toArmy, limit, allowedTypeCount))
   6.107 +				{
   6.108 +					canAdd = Validation.Failed;
   6.109 +					break;
   6.110 +				}
   6.111 +			}
   6.112 +
   6.113 +			if (typeFound && canAdd == Validation.NotApplicable)
   6.114 +			{
   6.115 +				canAdd = Validation.Passed;
   6.116 +			}
   6.117 +
   6.118 +			return canAdd;
   6.119 +		}
   6.120 +
   6.121 +		private int GetUnitTypesCount(Army toArmy, UnitType[] unitTypes, IWarFoundryObject wfObject)
   6.122 +		{
   6.123 +			int count = 0;
   6.124 +
   6.125 +			foreach (UnitType unitType in unitTypes)
   6.126 +			{
   6.127 +				count += GetUnitTypeCount(toArmy, unitType, wfObject);
   6.128 +			}
   6.129 +
   6.130 +			return count;
   6.131 +		}
   6.132 +
   6.133 +		private int GetAllowedObjectCount(Army toArmy, OBJECT_TYPE obj, IWarFoundryObject wfObject)
   6.134 +		{
   6.135 +			return GetObjectCountFromArmy(toArmy, obj) + GetCountFromObject(wfObject, obj);
   6.136 +		}
   6.137 +
   6.138 +		protected abstract int GetObjectCountFromArmy(Army toArmy, OBJECT_TYPE obj);
   6.139 +
   6.140 +		private int GetCountFromObject(IWarFoundryObject wfObject, OBJECT_TYPE limitedType)
   6.141 +		{
   6.142 +			return (limitedType.Equals(wfObject) || (wfObject is Unit && ((Unit)wfObject).UnitType.Equals(limitedType))) ? 1 : 0;
   6.143 +		}
   6.144 +
   6.145 +		public override Validation ValidatesArmy(Army army)
   6.146 +		{
   6.147 +			Validation canAdd = Validation.NotApplicable;
   6.148 +			int allowedTypeCount = GetObjectCountFromArmy(army, AllowedObject);
   6.149 +			bool typeFound = (allowedTypeCount > 0);
   6.150 +
   6.151 +			foreach (UnitCountRequirementData limit in RequiredTypes)
   6.152 +			{
   6.153 +				int limitedTypeCount = GetUnitTypesCount(army, limit.UnitTypes);
   6.154 +				typeFound |= (limitedTypeCount > 0);
   6.155 +
   6.156 +				if (!IsValidByRequirement(limit, allowedTypeCount, limitedTypeCount))
   6.157 +				{
   6.158 +					canAdd = Validation.Failed;
   6.159 +					break;
   6.160 +				}
   6.161 +			}
   6.162 +
   6.163 +			if (typeFound && canAdd == Validation.NotApplicable)
   6.164 +			{
   6.165 +				canAdd = Validation.Passed;
   6.166 +			}
   6.167 +
   6.168 +			return canAdd;
   6.169 +		}
   6.170 +
   6.171 +		protected override string GetFailedRequirementsString(Army army)
   6.172 +		{
   6.173 +			return String.Join("; ", GetFailedValidationRequirements(army).ToArray());
   6.174 +		}
   6.175 +
   6.176 +		private List<string> GetFailedValidationRequirements(Army army)
   6.177 +		{
   6.178 +			List<string> failures = new List<string>();
   6.179 +			int allowedTypeCount = GetAllowedObjectCount(army);
   6.180 +
   6.181 +			foreach (UnitCountRequirementData limit in RequiredTypes)
   6.182 +			{
   6.183 +				int limitedTypeCount = GetUnitTypesCount(army, limit.UnitTypes);
   6.184 +
   6.185 +				if (!IsValidByRequirement(limit, allowedTypeCount, limitedTypeCount))
   6.186 +				{
   6.187 +					string unitTypeList = GetUnitTypeList(limit);
   6.188 +					failures.Add(String.Format("{0} × {1} for every {2} × {3} (have {4} for {5})", limit.Count, unitTypeList, limit.AllowsCount, AllowedObject.Name, limitedTypeCount, allowedTypeCount));
   6.189 +				}
   6.190 +			}
   6.191 +
   6.192 +			return failures;
   6.193 +		}
   6.194 +
   6.195 +		protected abstract int GetAllowedObjectCount(Army army);
   6.196 +
   6.197 +		private int GetUnitTypesCount(Army army, UnitType[] unitTypes)
   6.198 +		{
   6.199 +			return GetUnitTypesCount(army, unitTypes, null);
   6.200 +		}
   6.201 +
   6.202 +		/// <summary>
   6.203 +		/// Adds a requirement for there to be at least minCount of a given UnitType, allowing allowedCount of this UnitType
   6.204 +		/// </summary>
   6.205 +		/// <param name='unitType'>
   6.206 +		/// The unit type to require.
   6.207 +		/// </param>
   6.208 +		/// <param name='minCount'>
   6.209 +		/// The minimum number of that type that must exist.
   6.210 +		/// </param>
   6.211 +		/// <param name='allowedCount'>
   6.212 +		/// The number of units allowed for every minCount units of the supplied unit type.
   6.213 +		/// </param>
   6.214 +		public void AddUnitTypeRequirement(UnitType unitType, int minCount, int allowedCount)
   6.215 +		{
   6.216 +			RequiredTypes.Add(new UnitCountRequirementData(unitType, minCount, allowedCount));
   6.217 +		}
   6.218 +
   6.219 +		/// <summary>
   6.220 +		/// Adds a requirement for there to be at least one of a given UnitType, allowing allowedCount of this UnitType
   6.221 +		/// </summary>
   6.222 +		/// <param name='unitType'>
   6.223 +		/// The unit type to require.
   6.224 +		/// </param>
   6.225 +		/// <param name='allowedCount'>
   6.226 +		/// The number of units allowed for each unit of the supplied unit type.
   6.227 +		/// </param>
   6.228 +		public void AddUnitTypeRequirement(UnitType unitType, int allowedCount)
   6.229 +		{
   6.230 +			AddUnitTypeRequirement(allowedCount, unitType);
   6.231 +		}
   6.232 +
   6.233 +		public override void AddUnitTypeRequirement(UnitType unitType)
   6.234 +		{
   6.235 +			AddUnitTypeRequirement(1, unitType);
   6.236 +		}
   6.237 +
   6.238 +		/// <summary>
   6.239 +		/// Adds a requirement for there to be one or more of the given UnitTypes, allowing one of this UnitType. If multiple unit types
   6.240 +		/// are supplied here then the number is additive (so 1 x unitType1 and 1 x unitType2 allows two of this UnitType).
   6.241 +		/// </summary>
   6.242 +		/// <param name='unitType'>
   6.243 +		/// The unit type or types to require.
   6.244 +		/// </param>
   6.245 +		public void AddUnitTypeRequirement(params UnitType[] unitTypes)
   6.246 +		{
   6.247 +			AddUnitTypeRequirement(1, unitTypes);
   6.248 +		}
   6.249 +
   6.250 +		/// <summary>
   6.251 +		/// Adds a requirement for there to be one or more of the given UnitTypes, allowing allowsAmount of this UnitType. If multiple unit types
   6.252 +		/// are supplied here then the number is additive (so 1 x unitType1 and 1 x unitType2 allows two of this UnitType).
   6.253 +		/// </summary>
   6.254 +		/// <param name="allowsAmount">
   6.255 +		/// The number of units to be allowed for each 1 of unitType
   6.256 +		/// </param>
   6.257 +		/// <param name='unitType'>
   6.258 +		/// The unit type or types to require.
   6.259 +		/// </param>
   6.260 +		public void AddUnitTypeRequirement(int allowsAmount, params UnitType[] unitTypes)
   6.261 +		{
   6.262 +			RequiredTypes.Add(new UnitCountRequirementData(unitTypes, 1, allowsAmount));
   6.263 +		}
   6.264 +
   6.265 +		/// <summary>
   6.266 +		/// Adds a requirement for there to be minCount or more of the given UnitTypes, allowing allowsAmount of this UnitType. If multiple unit types
   6.267 +		/// are supplied here then the number is additive (so 1 x unitType1 and 1 x unitType2 allows two of this UnitType).
   6.268 +		/// </summary>
   6.269 +		/// <param name='minCount'>
   6.270 +		/// The minimum number of that type that must exist.
   6.271 +		/// </param>
   6.272 +		/// <param name="allowsAmount">
   6.273 +		/// The number of units to be allowed for each 1 of unitType
   6.274 +		/// </param>
   6.275 +		/// <param name='unitType'>
   6.276 +		/// The unit type or types to require.
   6.277 +		/// </param>
   6.278 +		public void AddUnitTypeRequirement(int minCount, int allowsAmount, params UnitType[] unitTypes)
   6.279 +		{
   6.280 +			RequiredTypes.Add(new UnitCountRequirementData(unitTypes, minCount, allowsAmount));
   6.281 +		}
   6.282 +	}
   6.283 +}
   6.284 +
     7.1 --- a/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirement.cs	Tue Jan 31 20:58:09 2012 +0000
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,290 +0,0 @@
     7.4 -// This file(RequiresNUnitsForMUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard
     7.5 -// 
     7.6 -// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or(at your option) any later version. Please see COPYING for more information and the full license.
     7.7 -using System;
     7.8 -using System.Collections.Generic;
     7.9 -using System.Text;
    7.10 -
    7.11 -namespace IBBoard.WarFoundry.API.Objects.Requirement
    7.12 -{
    7.13 -	public class RequiresNUnitsForMUnitsRequirement : AbstractRequirement
    7.14 -	{
    7.15 -		public static readonly string REQUIREMENT_ID = "RequiresNUnitsForMUnits";
    7.16 -		private List<UnitCountRequirementData> requiredTypes;
    7.17 -		private UnitType allowedType;
    7.18 -
    7.19 -		public RequiresNUnitsForMUnitsRequirement(UnitType allowedType, params UnitType[] requiredUnitTypes)
    7.20 -		{
    7.21 -			this.allowedType = allowedType;
    7.22 -			requiredTypes = new List<UnitCountRequirementData>();
    7.23 -
    7.24 -			foreach (UnitType unitType in requiredUnitTypes)
    7.25 -			{
    7.26 -				AddUnitTypeRequirement(unitType);
    7.27 -			}
    7.28 -		}
    7.29 -
    7.30 -		public override int GetHashCode()
    7.31 -		{
    7.32 -			int hash = 0;
    7.33 -
    7.34 -			foreach (UnitCountRequirementData req in requiredTypes)
    7.35 -			{
    7.36 -				hash += req.UnitType.GetHashCode();
    7.37 -			}
    7.38 -
    7.39 -			return hash;
    7.40 -		}
    7.41 -
    7.42 -		protected override bool TypeEquals(object obj)
    7.43 -		{
    7.44 -			RequiresNUnitsForMUnitsRequirement otherReq = (RequiresNUnitsForMUnitsRequirement)obj;
    7.45 -			if (!Collections.Collections.AreEqual(requiredTypes, otherReq.requiredTypes))
    7.46 -			{
    7.47 -				return false;
    7.48 -			}
    7.49 -			else
    7.50 -			{
    7.51 -				return true;
    7.52 -			}
    7.53 -		}
    7.54 -
    7.55 -		protected override string GetFailedAddingRequirementsString(UnitType toAdd, Army toArmy)
    7.56 -		{
    7.57 -			return String.Join("; ", GetFailedAddingRequirements(toAdd, toArmy).ToArray());
    7.58 -		}
    7.59 -
    7.60 -		private List<string> GetFailedAddingRequirements(UnitType unitType, Army toArmy)
    7.61 -		{
    7.62 -			List<string> failures = new List<string>();
    7.63 -			int allowedTypeCount = GetUnitTypeCount(toArmy, allowedType, unitType);
    7.64 -
    7.65 -			foreach (UnitCountRequirementData limit in requiredTypes)
    7.66 -			{
    7.67 -				int limitedTypeCount = GetUnitTypesCount(toArmy, limit.UnitTypes, unitType);
    7.68 -
    7.69 -				if (!IsValidByRequirement(unitType, toArmy, limit, allowedTypeCount))
    7.70 -				{
    7.71 -					string unitTypeList = GetUnitTypeList(limit);
    7.72 -					failures.Add(String.Format("{0} × {1} for every {2} × {3} (would have {4} for {5})", limit.Count, unitTypeList, limit.AllowsCount, allowedType.Name, limitedTypeCount, allowedTypeCount));
    7.73 -				}
    7.74 -			}
    7.75 -
    7.76 -			return failures;
    7.77 -		}
    7.78 -
    7.79 -		private string GetUnitTypeList(UnitCountRequirementData limit)
    7.80 -		{
    7.81 -			List<String> namesList = new List<String>();
    7.82 -
    7.83 -			foreach (UnitType unitType in limit.UnitTypes)
    7.84 -			{
    7.85 -				namesList.Add(unitType.Name);
    7.86 -			}
    7.87 -
    7.88 -			string[] names = namesList.ToArray();
    7.89 -			return String.Join(" or ", names);
    7.90 -		}
    7.91 -
    7.92 -		private bool IsValidByRequirement(WarFoundryObject wfObject, Army toArmy, UnitCountRequirementData limit, int allowedTypeCount)
    7.93 -		{
    7.94 -			int limitedTypeCount = GetUnitTypesCount(toArmy, limit.UnitTypes, wfObject);
    7.95 -			return IsValidByRequirement(limit, allowedTypeCount, limitedTypeCount);
    7.96 -		}
    7.97 -
    7.98 -		private bool IsValidByRequirement(UnitCountRequirementData limit, int allowedTypeCount, int limitedTypeCount)
    7.99 -		{
   7.100 -			int wholeNumLimited = (limitedTypeCount / limit.Count);
   7.101 -			double allowedRatio = (limit.AllowsCount / (limit.Count * 1.0));
   7.102 -			return allowedRatio * wholeNumLimited >= allowedTypeCount;
   7.103 -		}
   7.104 -
   7.105 -		public override Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy)
   7.106 -		{
   7.107 -			Validation canAdd = Validation.NotApplicable;
   7.108 -			UnitType addedUnitType = (wfObject is Unit) ? ((Unit)wfObject).UnitType : wfObject as UnitType;
   7.109 -			bool typeFound = (addedUnitType == allowedType);
   7.110 -			int allowedTypeCount = GetUnitTypeCount(toArmy, allowedType, wfObject);
   7.111 -
   7.112 -			foreach (UnitCountRequirementData limit in requiredTypes)
   7.113 -			{
   7.114 -				typeFound |= (addedUnitType == limit.UnitType);
   7.115 -
   7.116 -				if (!IsValidByRequirement(wfObject, toArmy, limit, allowedTypeCount))
   7.117 -				{
   7.118 -					canAdd = Validation.Failed;
   7.119 -					break;
   7.120 -				}
   7.121 -			}
   7.122 -
   7.123 -			if (typeFound && canAdd == Validation.NotApplicable)
   7.124 -			{
   7.125 -				canAdd = Validation.Passed;
   7.126 -			}
   7.127 -
   7.128 -			return canAdd;
   7.129 -		}
   7.130 -
   7.131 -		private int GetUnitTypesCount(Army toArmy, UnitType[] unitTypes, WarFoundryObject wfObject)
   7.132 -		{
   7.133 -			int count = 0;
   7.134 -
   7.135 -			foreach (UnitType unitType in unitTypes)
   7.136 -			{
   7.137 -				count += GetUnitTypeCount(toArmy, unitType, wfObject);
   7.138 -			}
   7.139 -
   7.140 -			return count;
   7.141 -		}
   7.142 -
   7.143 -		private int GetUnitTypeCount(Army toArmy, UnitType unitType, WarFoundryObject wfObject)
   7.144 -		{
   7.145 -			return toArmy.GetUnitTypeCount(unitType) + GetCountFromObject(wfObject, unitType);
   7.146 -		}
   7.147 -
   7.148 -		private int GetCountFromObject(WarFoundryObject wfObject, UnitType limitedType)
   7.149 -		{
   7.150 -			return (limitedType.Equals(wfObject) || (wfObject is Unit && ((Unit)wfObject).UnitType.Equals(limitedType))) ? 1 : 0;
   7.151 -		}
   7.152 -
   7.153 -		public override Validation ValidatesArmy(Army army)
   7.154 -		{
   7.155 -			Validation canAdd = Validation.NotApplicable;
   7.156 -			int allowedTypeCount = army.GetUnitTypeCount(allowedType);
   7.157 -			bool typeFound = (allowedTypeCount > 0);
   7.158 -
   7.159 -			foreach (UnitCountRequirementData limit in requiredTypes)
   7.160 -			{
   7.161 -				int limitedTypeCount = GetUnitTypesCount(army, limit.UnitTypes);
   7.162 -				typeFound |= (limitedTypeCount > 0);
   7.163 -
   7.164 -				if (!IsValidByRequirement(limit, allowedTypeCount, limitedTypeCount))
   7.165 -				{
   7.166 -					canAdd = Validation.Failed;
   7.167 -					break;
   7.168 -				}
   7.169 -			}
   7.170 -
   7.171 -			if (typeFound && canAdd == Validation.NotApplicable)
   7.172 -			{
   7.173 -				canAdd = Validation.Passed;
   7.174 -			}
   7.175 -
   7.176 -			return canAdd;
   7.177 -		}
   7.178 -
   7.179 -		protected override string GetFailedRequirementsString(Army army)
   7.180 -		{
   7.181 -			return String.Join("; ", GetFailedValidationRequirements(army).ToArray());
   7.182 -		}
   7.183 -
   7.184 -		private List<string> GetFailedValidationRequirements(Army army)
   7.185 -		{
   7.186 -			List<string> failures = new List<string>();
   7.187 -			int allowedTypeCount = army.GetUnitTypeCount(allowedType);
   7.188 -
   7.189 -			foreach (UnitCountRequirementData limit in requiredTypes)
   7.190 -			{
   7.191 -				int limitedTypeCount = GetUnitTypesCount(army, limit.UnitTypes);
   7.192 -
   7.193 -				if (!IsValidByRequirement(limit, allowedTypeCount, limitedTypeCount))
   7.194 -				{
   7.195 -					string unitTypeList = GetUnitTypeList(limit);
   7.196 -					failures.Add(String.Format("{0} × {1} for every {2} × {3} (have {4} for {5})", limit.Count, unitTypeList, limit.AllowsCount, allowedType.Name, limitedTypeCount, allowedTypeCount));
   7.197 -				}
   7.198 -			}
   7.199 -
   7.200 -			return failures;
   7.201 -		}
   7.202 -
   7.203 -		private int GetUnitTypesCount(Army army, UnitType[] unitTypes)
   7.204 -		{
   7.205 -			return GetUnitTypesCount(army, unitTypes, null);
   7.206 -		}
   7.207 -
   7.208 -		public override string RequirementID
   7.209 -		{
   7.210 -			get
   7.211 -			{
   7.212 -				return REQUIREMENT_ID;
   7.213 -			}
   7.214 -		}
   7.215 -
   7.216 -		/// <summary>
   7.217 -		/// Adds a requirement for there to be at least minCount of a given UnitType, allowing allowedCount of this UnitType
   7.218 -		/// </summary>
   7.219 -		/// <param name='unitType'>
   7.220 -		/// The unit type to require.
   7.221 -		/// </param>
   7.222 -		/// <param name='minCount'>
   7.223 -		/// The minimum number of that type that must exist.
   7.224 -		/// </param>
   7.225 -		/// <param name='allowedCount'>
   7.226 -		/// The number of units allowed for every minCount units of the supplied unit type.
   7.227 -		/// </param>
   7.228 -		public void AddUnitTypeRequirement(UnitType unitType, int minCount, int allowedCount)
   7.229 -		{
   7.230 -			requiredTypes.Add(new UnitCountRequirementData(unitType, minCount, allowedCount));
   7.231 -		}
   7.232 -
   7.233 -		/// <summary>
   7.234 -		/// Adds a requirement for there to be at least one of a given UnitType, allowing allowedCount of this UnitType
   7.235 -		/// </summary>
   7.236 -		/// <param name='unitType'>
   7.237 -		/// The unit type to require.
   7.238 -		/// </param>
   7.239 -		/// <param name='allowedCount'>
   7.240 -		/// The number of units allowed for each unit of the supplied unit type.
   7.241 -		/// </param>
   7.242 -		public void AddUnitTypeRequirement(UnitType unitType, int allowedCount)
   7.243 -		{
   7.244 -			AddUnitTypeRequirement(allowedCount, unitType);
   7.245 -		}
   7.246 -
   7.247 -		/// <summary>
   7.248 -		/// Adds a requirement for there to be one or more of the given UnitTypes, allowing one of this UnitType. If multiple unit types
   7.249 -		/// are supplied here then the number is additive (so 1 x unitType1 and 1 x unitType2 allows two of this UnitType).
   7.250 -		/// </summary>
   7.251 -		/// <param name='unitType'>
   7.252 -		/// The unit type or types to require.
   7.253 -		/// </param>
   7.254 -		public void AddUnitTypeRequirement(params UnitType[] unitTypes)
   7.255 -		{
   7.256 -			AddUnitTypeRequirement(1, unitTypes);
   7.257 -		}
   7.258 -
   7.259 -		/// <summary>
   7.260 -		/// Adds a requirement for there to be one or more of the given UnitTypes, allowing allowsAmount of this UnitType. If multiple unit types
   7.261 -		/// are supplied here then the number is additive (so 1 x unitType1 and 1 x unitType2 allows two of this UnitType).
   7.262 -		/// </summary>
   7.263 -		/// <param name="allowsAmount">
   7.264 -		/// The number of units to be allowed for each 1 of unitType
   7.265 -		/// </param>
   7.266 -		/// <param name='unitType'>
   7.267 -		/// The unit type or types to require.
   7.268 -		/// </param>
   7.269 -		public void AddUnitTypeRequirement(int allowsAmount, params UnitType[] unitTypes)
   7.270 -		{
   7.271 -			requiredTypes.Add(new UnitCountRequirementData(unitTypes, 1, allowsAmount));
   7.272 -		}
   7.273 -
   7.274 -		/// <summary>
   7.275 -		/// Adds a requirement for there to be minCount or more of the given UnitTypes, allowing allowsAmount of this UnitType. If multiple unit types
   7.276 -		/// are supplied here then the number is additive (so 1 x unitType1 and 1 x unitType2 allows two of this UnitType).
   7.277 -		/// </summary>
   7.278 -		/// <param name='minCount'>
   7.279 -		/// The minimum number of that type that must exist.
   7.280 -		/// </param>
   7.281 -		/// <param name="allowsAmount">
   7.282 -		/// The number of units to be allowed for each 1 of unitType
   7.283 -		/// </param>
   7.284 -		/// <param name='unitType'>
   7.285 -		/// The unit type or types to require.
   7.286 -		/// </param>
   7.287 -		public void AddUnitTypeRequirement(int minCount, int allowsAmount, params UnitType[] unitTypes)
   7.288 -		{
   7.289 -			requiredTypes.Add(new UnitCountRequirementData(unitTypes, minCount, allowsAmount));
   7.290 -		}
   7.291 -	}
   7.292 -}
   7.293 -
     8.1 --- a/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs	Tue Jan 31 20:58:09 2012 +0000
     8.2 +++ b/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs	Wed Feb 22 20:45:39 2012 +0000
     8.3 @@ -11,19 +11,14 @@
     8.4  	/// <summary>
     8.5  	/// A requirement where a WarFoundryObject cannot be taken in an army if more than N of a UnitType will be in the army.
     8.6  	/// </summary>
     8.7 -	public class RequiresNoMoreThanNOfUnitTypeRequirement : AbstractRequirement
     8.8 +	public class RequiresNoMoreThanNOfUnitTypeRequirement<OBJECT_TYPE> : AbstractUnitRequirement<OBJECT_TYPE> where OBJECT_TYPE : IWarFoundryObject
     8.9  	{
    8.10  		public static readonly string REQUIREMENT_ID = "RequiresNoMoreThanNUnits";
    8.11  		private List<UnitCountRequirementData> limitedTypes;
    8.12  
    8.13 -		public RequiresNoMoreThanNOfUnitTypeRequirement(params UnitType[] limitedUnitTypes)
    8.14 +		public RequiresNoMoreThanNOfUnitTypeRequirement(params UnitType[] limitedUnitTypes) : base(default(OBJECT_TYPE), limitedUnitTypes)
    8.15  		{
    8.16  			limitedTypes = new List<UnitCountRequirementData>();
    8.17 -
    8.18 -			foreach (UnitType unitType in limitedUnitTypes)
    8.19 -			{
    8.20 -				AddUnitTypeRequirement(unitType);
    8.21 -			}
    8.22  		}
    8.23  
    8.24  		public override string RequirementID
    8.25 @@ -46,7 +41,7 @@
    8.26  		/// <param name='toArmy'>
    8.27  		/// The army to add the object to.
    8.28  		/// </param>
    8.29 -		public override Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy)
    8.30 +		public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy)
    8.31  		{
    8.32  			Validation canAdd = Validation.Passed;
    8.33  			
    8.34 @@ -92,7 +87,7 @@
    8.35  		/// <param name='unitType'>
    8.36  		/// The unit type to limit.
    8.37  		/// </param>
    8.38 -		public void AddUnitTypeRequirement(UnitType unitType)
    8.39 +		public override void AddUnitTypeRequirement(UnitType unitType)
    8.40  		{
    8.41  			AddUnitTypeRequirement(unitType, 0);
    8.42  		}
    8.43 @@ -124,7 +119,7 @@
    8.44  
    8.45  		protected override bool TypeEquals(object obj)
    8.46  		{
    8.47 -			RequiresNoMoreThanNOfUnitTypeRequirement other = (RequiresNoMoreThanNOfUnitTypeRequirement)obj;
    8.48 +			RequiresNoMoreThanNOfUnitTypeRequirement<OBJECT_TYPE> other = (RequiresNoMoreThanNOfUnitTypeRequirement<OBJECT_TYPE>)obj;
    8.49  			return Collections.Collections.AreEqual(limitedTypes, other.limitedTypes);
    8.50  		}
    8.51  
    8.52 @@ -170,18 +165,18 @@
    8.53  			return failures;
    8.54  		}
    8.55  
    8.56 -		protected override string GetFailedAddingRequirementsString(UnitType toAdd, Army toArmy)
    8.57 +		protected override string GetFailedAddingRequirementsString(IWarFoundryObject toAdd, Army toArmy)
    8.58  		{
    8.59  			return String.Join("; ", GetFailedAddingRequirements(toAdd, toArmy).ToArray());
    8.60  		}
    8.61  
    8.62 -		private List<string> GetFailedAddingRequirements(UnitType unitType, Army army)
    8.63 +		private List<string> GetFailedAddingRequirements(IWarFoundryObject toAdd, Army army)
    8.64  		{
    8.65  			List<string> failures = new List<string>();
    8.66  
    8.67  			foreach (UnitCountRequirementData requirement in limitedTypes)
    8.68  			{
    8.69 -				int unitCount = GetUnitTypeCount(army, requirement.UnitType, unitType);
    8.70 +				int unitCount = GetUnitTypeCount(army, requirement.UnitType, toAdd);
    8.71  
    8.72  				if (unitCount > requirement.Count)
    8.73  				{
    8.74 @@ -191,6 +186,11 @@
    8.75  
    8.76  			return failures;
    8.77  		}
    8.78 +
    8.79 +		protected override int GetObjectCountFromArmy(Army toArmy)
    8.80 +		{
    8.81 +			return 0;
    8.82 +		}
    8.83  	}
    8.84  }
    8.85  
     9.1 --- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs	Tue Jan 31 20:58:09 2012 +0000
     9.2 +++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs	Wed Feb 22 20:45:39 2012 +0000
     9.3 @@ -10,28 +10,25 @@
     9.4  	/// <summary>
     9.5  	/// A requirement where a UnitType requires at least N units of one or more unit types before any number of that object can be taken in an army.
     9.6  	/// </summary>
     9.7 -	public class UnitRequiresAtLeastNUnitsRequirement : RequiresAtLeastNUnitsRequirement
     9.8 +	public class UnitRequiresAtLeastNUnitsRequirement : RequiresAtLeastNUnitsRequirement<UnitType>
     9.9  	{
    9.10 -		private UnitType requirementOnType;
    9.11 -
    9.12 -		public UnitRequiresAtLeastNUnitsRequirement(UnitType requirementOn) : base()
    9.13 +		public UnitRequiresAtLeastNUnitsRequirement(UnitType requirementOn) : base(requirementOn)
    9.14  		{
    9.15 -			requirementOnType = requirementOn;
    9.16  		}
    9.17  
    9.18 -		protected override bool IsApplicable(WarFoundryObject toObjectAdded)
    9.19 +		protected override bool IsApplicable(IWarFoundryObject toObjectAdded)
    9.20  		{
    9.21  			return base.IsApplicable(toObjectAdded) || IsRequirementOnType(toObjectAdded);
    9.22  		}
    9.23  
    9.24 -		private bool IsRequirementOnType(WarFoundryObject toObjectAdded)
    9.25 +		private bool IsRequirementOnType(IWarFoundryObject toObjectAdded)
    9.26  		{
    9.27 -			return requirementOnType.Equals(toObjectAdded) || (toObjectAdded is Unit && requirementOnType.Equals(((Unit)toObjectAdded).UnitType));
    9.28 +			return AllowedObject.Equals(toObjectAdded) || (toObjectAdded is Unit && AllowedObject.Equals(((Unit)toObjectAdded).UnitType));
    9.29  		}
    9.30  
    9.31  		protected override bool IsApplicable(Army toArmy)
    9.32  		{
    9.33 -			return toArmy.GetUnitTypeCount(requirementOnType) > 0;
    9.34 +			return toArmy.GetUnitTypeCount(AllowedObject) > 0;
    9.35  		}
    9.36  
    9.37  		public override Validation ValidatesArmy(Army toArmy)
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirement.cs	Wed Feb 22 20:45:39 2012 +0000
    10.3 @@ -0,0 +1,79 @@
    10.4 +// This file (UnitRequiresAtLeastNUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard
    10.5 +// 
    10.6 +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
    10.7 +using System;
    10.8 +using System.Collections.Generic;
    10.9 +using IBBoard.WarFoundry.API.Objects;
   10.10 +
   10.11 +namespace IBBoard.WarFoundry.API.Objects.Requirement
   10.12 +{
   10.13 +	/// <summary>
   10.14 +	/// A requirement where N of a UnitType can only be taken if there are M of a unit type in the army.
   10.15 +	/// </summary>
   10.16 +	public class UnitRequiresNUnitsForMUnitsRequirement : RequiresNUnitsForMObjectsRequirement<UnitType>
   10.17 +	{
   10.18 +		//Note: We're sticking with the old requirement name to prevent breakage
   10.19 +		public static readonly string REQUIREMENT_ID = "RequiresNUnitsForMUnits";
   10.20 +
   10.21 +		public UnitRequiresNUnitsForMUnitsRequirement(UnitType requirementOn, params UnitType[] requiredUnitTypes) : base(requirementOn, requiredUnitTypes)
   10.22 +		{
   10.23 +			//Do nothing
   10.24 +		}
   10.25 +
   10.26 +		/// <summary>
   10.27 +		/// Checks whether the supplied WarFoundryObject can be added to the supplied army.
   10.28 +		/// </summary>
   10.29 +		/// <returns>
   10.30 +		/// A <code>Validation</code> enum to show the result of the validation
   10.31 +		/// </returns>
   10.32 +		/// <param name='wfObject'>
   10.33 +		/// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement
   10.34 +		/// </param>
   10.35 +		/// <param name='toArmy'>
   10.36 +		/// The army to add the object to.
   10.37 +		/// </param>
   10.38 +		public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy)
   10.39 +		{
   10.40 +			return IsApplicable(wfObject, toArmy) ? base.AllowsAdding(wfObject, toArmy) : Validation.NotApplicable;
   10.41 +		}
   10.42 +
   10.43 +		protected override bool IsApplicable(IWarFoundryObject toObject, Army toArmy)
   10.44 +		{
   10.45 +			return IsApplicable(toArmy) || IsApplicable(toObject);
   10.46 +		}
   10.47 +
   10.48 +		protected override bool IsApplicable(Army toArmy)
   10.49 +		{
   10.50 +			return toArmy.GetUnitTypeCount(AllowedObject) > 0;
   10.51 +		}
   10.52 +
   10.53 +		protected override bool IsApplicable(IWarFoundryObject toObject)
   10.54 +		{
   10.55 +			return AllowedObject.Equals(toObject) || (toObject is Unit && AllowedObject.Equals(((Unit)toObject).UnitType));
   10.56 +		}
   10.57 +
   10.58 +		public override string RequirementID
   10.59 +		{
   10.60 +			get
   10.61 +			{
   10.62 +				return REQUIREMENT_ID;
   10.63 +			}
   10.64 +		}
   10.65 +
   10.66 +		protected override int GetObjectCountFromArmy(Army toArmy)
   10.67 +		{
   10.68 +			return GetObjectCountFromArmy(toArmy, AllowedObject);
   10.69 +		}
   10.70 +
   10.71 +		protected override int GetObjectCountFromArmy(Army toArmy, UnitType unitType)
   10.72 +		{
   10.73 +			return toArmy.GetUnitTypeCount(unitType);
   10.74 +		}
   10.75 +
   10.76 +		protected override int GetAllowedObjectCount(Army army)
   10.77 +		{
   10.78 +			return army.GetUnitTypeCount(AllowedObject);
   10.79 +		}
   10.80 +	}
   10.81 +}
   10.82 +
    11.1 --- a/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs	Tue Jan 31 20:58:09 2012 +0000
    11.2 +++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs	Wed Feb 22 20:45:39 2012 +0000
    11.3 @@ -10,7 +10,7 @@
    11.4  	/// <summary>
    11.5  	/// A requirement where a UnitType can only be taken if there are no more than N units of one or more unit in an army.
    11.6  	/// </summary>
    11.7 -	public class UnitRequiresNoMoreThanNOfUnitTypeRequirement : RequiresNoMoreThanNOfUnitTypeRequirement
    11.8 +	public class UnitRequiresNoMoreThanNOfUnitTypeRequirement : RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>
    11.9  	{
   11.10  		private UnitType requirementOnType;
   11.11  
   11.12 @@ -31,12 +31,12 @@
   11.13  		/// <param name='toArmy'>
   11.14  		/// The army to add the object to.
   11.15  		/// </param>
   11.16 -		public override Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy)
   11.17 +		public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy)
   11.18  		{
   11.19  			return IsApplicable(wfObject, toArmy) ? base.AllowsAdding(wfObject, toArmy) : Validation.NotApplicable;
   11.20  		}
   11.21  
   11.22 -		protected override bool IsApplicable(WarFoundryObject toObject, Army toArmy)
   11.23 +		protected override bool IsApplicable(IWarFoundryObject toObject, Army toArmy)
   11.24  		{
   11.25  			return IsApplicable(toArmy) || IsApplicable(toObject);
   11.26  		}
   11.27 @@ -46,7 +46,7 @@
   11.28  			return toArmy.GetUnitTypeCount(requirementOnType) > 0;
   11.29  		}
   11.30  
   11.31 -		protected override bool IsApplicable(WarFoundryObject toObject)
   11.32 +		protected override bool IsApplicable(IWarFoundryObject toObject)
   11.33  		{
   11.34  			return requirementOnType.Equals(toObject) || (toObject is Unit && requirementOnType.Equals(((Unit)toObject).UnitType));
   11.35  		}
    12.1 --- a/API/Objects/UnitType.cs	Tue Jan 31 20:58:09 2012 +0000
    12.2 +++ b/API/Objects/UnitType.cs	Wed Feb 22 20:45:39 2012 +0000
    12.3 @@ -1,7 +1,6 @@
    12.4  // This file (UnitType.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard.
    12.5  //
    12.6  // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
    12.7 -
    12.8  using System;
    12.9  using System.Collections.Generic;
   12.10  using System.Xml;
   12.11 @@ -37,14 +36,13 @@
   12.12  		private Dictionary<string, ILimit> slotLimits = new Dictionary<string, ILimit>();
   12.13  		private Dictionary<string, UnitMemberType> unitMemberTypes = new Dictionary<string, UnitMemberType>();
   12.14  		private List<Category> cats = new List<Category>();
   12.15 -			
   12.16  
   12.17  		public UnitType(string id, string typeName, Race parentRace) : base(id, typeName)
   12.18  		{
   12.19  			race = parentRace;
   12.20  		}
   12.21  
   12.22 -		public override bool Equals (object obj)
   12.23 +		public override bool Equals(object obj)
   12.24  		{
   12.25  			if (obj == null)
   12.26  			{
   12.27 @@ -190,7 +188,7 @@
   12.28  		/// </summary>
   12.29  		private void CheckMinimumNumber()
   12.30  		{
   12.31 -			if (MinNumber > MaxNumber && MaxNumber!=WarFoundryCore.INFINITY)
   12.32 +			if (MinNumber > MaxNumber && MaxNumber != WarFoundryCore.INFINITY)
   12.33  			{
   12.34  				MinNumber = MaxNumber;
   12.35  				LogNotifier.WarnFormat(GetType(), "Unit type {0} ({1}) had a minimum number greater than their maximum number.", Name, ID);
   12.36 @@ -202,7 +200,7 @@
   12.37  		/// </summary>
   12.38  		private void CheckMinimumSize()
   12.39  		{
   12.40 -			if (MinSize > MaxSize && MaxSize!=WarFoundryCore.INFINITY)
   12.41 +			if (MinSize > MaxSize && MaxSize != WarFoundryCore.INFINITY)
   12.42  			{
   12.43  				MinSize = MaxSize;
   12.44  				LogNotifier.WarnFormat(GetType(), "Unit type {0} ({1}) had a minimum size greater than their maximum size.", Name, ID);
   12.45 @@ -238,7 +236,7 @@
   12.46  
   12.47  		protected override string DefaultName()
   12.48  		{
   12.49 -			throw new InvalidOperationException("Unit type with id "+id+" did not have a name specified");
   12.50 +			throw new InvalidOperationException("Unit type with id " + id + " did not have a name specified");
   12.51  		}
   12.52  		
   12.53  		/// <value>
   12.54 @@ -279,7 +277,7 @@
   12.55  		
   12.56  		public string[] UnitStatsArrayIDs
   12.57  		{
   12.58 -			get 
   12.59 +			get
   12.60  			{
   12.61  				string[] ids;
   12.62  				
   12.63 @@ -345,7 +343,7 @@
   12.64  		
   12.65  		public Stat[] ExtendStatsArrayWithName(Stat[] statsArray)
   12.66  		{
   12.67 -			Stat[] extendedStats = new Stat[statsArray.Length+1];
   12.68 +			Stat[] extendedStats = new Stat[statsArray.Length + 1];
   12.69  			extendedStats[0] = new Stat(new StatSlot("name"), Name);
   12.70  			statsArray.CopyTo(extendedStats, 1);
   12.71  			return extendedStats;
   12.72 @@ -500,16 +498,16 @@
   12.73  
   12.74  			if (MinNumber != 0)
   12.75  			{
   12.76 -				RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
   12.77 -				req.AddUnitTypeRequirement(this, MinNumber);
   12.78 -				reqs.Add(req);
   12.79 +				//RequiresAtLeastNUnitsRequirement<Army> req = new RequiresAtLeastNUnitsRequirement<Army>();
   12.80 +				//req.AddUnitTypeRequirement(this, MinNumber);
   12.81 +				//reqs.Add(req);
   12.82  			}
   12.83  
   12.84  			if (MaxNumber != WarFoundryCore.INFINITY)
   12.85  			{
   12.86 -				RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement();
   12.87 -				req.AddUnitTypeRequirement(this, MaxNumber);
   12.88 -				reqs.Add(req);
   12.89 +				//RequiresNoMoreThanNOfUnitTypeRequirement<IWarFoundryObject> req = new RequiresNoMoreThanNOfUnitTypeRequirement<IWarFoundryObject>();
   12.90 +				//req.AddUnitTypeRequirement(this, MaxNumber);
   12.91 +				//reqs.Add(req);
   12.92  			}
   12.93  
   12.94  			return reqs.ToArray();
    13.1 --- a/IBBoard.WarFoundry.API.csproj	Tue Jan 31 20:58:09 2012 +0000
    13.2 +++ b/IBBoard.WarFoundry.API.csproj	Wed Feb 22 20:45:39 2012 +0000
    13.3 @@ -176,7 +176,6 @@
    13.4      <Compile Include="API\Objects\Requirement\UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs" />
    13.5      <Compile Include="API\Objects\Requirement\IRequirement.cs" />
    13.6      <Compile Include="API\Objects\Requirement\RequirementHandler.cs" />
    13.7 -    <Compile Include="API\Objects\Requirement\AbstractRequirement.cs" />
    13.8      <Compile Include="API\Factories\Requirement\UnitRequiresAtLeastNUnitsRequirementFactory.cs" />
    13.9      <Compile Include="API\Factories\Requirement\InvalidRequirementException.cs" />
   13.10      <Compile Include="API\Factories\Xml\CategoryLoader.cs" />
   13.11 @@ -191,8 +190,10 @@
   13.12      <None Include="data\SampleSystem.system">
   13.13        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
   13.14      </None>
   13.15 -    <Compile Include="API\Objects\Requirement\RequiresNUnitsForMUnitsRequirement.cs" />
   13.16      <Compile Include="API\Factories\Requirement\UnitRequiresNUnitsForMUnitsRequirementFactory.cs" />
   13.17 +    <Compile Include="API\Objects\Requirement\UnitRequiresNUnitsForMUnitsRequirement.cs" />
   13.18 +    <Compile Include="API\Objects\Requirement\RequiresNUnitsForMObjectsRequirement.cs" />
   13.19 +    <Compile Include="API\Objects\Requirement\AbstractUnitRequirement.cs" />
   13.20    </ItemGroup>
   13.21    <ItemGroup>
   13.22      <Reference Include="System.Xml" />