changeset 341:5f94b8a40876

Re #27: Unit requirements * Switch remaining unit requirement to using enum
author IBBoard <dev@ibboard.co.uk>
date Mon, 04 Apr 2011 19:28:44 +0000
parents 7bd2a7cdbfbd
children 407757e597f9
files API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs
diffstat 1 files changed, 20 insertions(+), 20 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs	Mon Apr 04 19:06:01 2011 +0000
     1.2 +++ b/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs	Mon Apr 04 19:28:44 2011 +0000
     1.3 @@ -1,34 +1,34 @@
     1.4  // This file (RequiresNoMoreThanNOfUnitTypeRequirement.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard
     1.5 -// 
     1.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.
     1.7 +// 
     1.8 +// 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.
     1.9  using System;
    1.10  using IBBoard.WarFoundry.API.Objects;
    1.11 -using System.Collections.Generic;
    1.12 -
    1.13 -namespace IBBoard.WarFoundry.API.Objects.Requirement
    1.14 +using System.Collections.Generic;
    1.15 +
    1.16 +namespace IBBoard.WarFoundry.API.Objects.Requirement
    1.17  {
    1.18  	/// <summary>
    1.19  	/// A requirement where a WarFoundryObject cannot be taken in an army if more than N of a UnitType will be in the army.
    1.20 -	/// </summary>
    1.21 -	public class RequiresNoMoreThanNOfUnitTypeRequirement
    1.22 +	/// </summary>
    1.23 +	public class RequiresNoMoreThanNOfUnitTypeRequirement
    1.24  	{
    1.25  		private List<UnitCountRequirementData> limitedTypes;
    1.26 -
    1.27 -		public RequiresNoMoreThanNOfUnitTypeRequirement(params UnitType[] limitedUnitTypes)
    1.28 +
    1.29 +		public RequiresNoMoreThanNOfUnitTypeRequirement(params UnitType[] limitedUnitTypes)
    1.30  		{
    1.31  			limitedTypes = new List<UnitCountRequirementData>();
    1.32  
    1.33  			foreach (UnitType unitType in limitedUnitTypes)
    1.34  			{
    1.35  				AddUnitTypeRequirement(unitType, 0);
    1.36 -			}
    1.37 +			}
    1.38  		}
    1.39  
    1.40  		/// <summary>
    1.41  		/// Checks whether the supplied WarFoundryObject can be added to the supplied army.
    1.42  		/// </summary>
    1.43  		/// <returns>
    1.44 -		/// <c>true</c> if the object can be added, else <c>false</c>
    1.45 +		/// A <code>Validation</code> enum to show the result of the validation
    1.46  		/// </returns>
    1.47  		/// <param name='wfObject'>
    1.48  		/// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement
    1.49 @@ -36,19 +36,19 @@
    1.50  		/// <param name='toArmy'>
    1.51  		/// The army to add the object to.
    1.52  		/// </param>
    1.53 -		public bool AllowsAdding(WarFoundryObject wfObject, Army toArmy)
    1.54 +		public Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy)
    1.55  		{
    1.56 -			bool canAdd = true;
    1.57 -
    1.58 +			Validation canAdd = Validation.Passed;
    1.59 +			
    1.60  			foreach (UnitCountRequirementData limit in limitedTypes)
    1.61  			{
    1.62  				if (toArmy.GetUnitTypeCount(limit.UnitType) > limit.Count)
    1.63  				{
    1.64 -					canAdd = false;
    1.65 +					canAdd = Validation.Failed;
    1.66  					break;
    1.67  				}
    1.68  			}
    1.69 -
    1.70 +			
    1.71  			return canAdd;
    1.72  		}
    1.73  
    1.74 @@ -64,7 +64,7 @@
    1.75  		public void AddUnitTypeRequirement(UnitType unitType, int minCount)
    1.76  		{
    1.77  			limitedTypes.Add(new UnitCountRequirementData(unitType, minCount));
    1.78 -		}
    1.79 -	}
    1.80 -}
    1.81 -
    1.82 +		}
    1.83 +	}
    1.84 +}
    1.85 +