changeset 338:4497ebce9a57

Re #27: Unit requirements * Add "is applicable" checking to army validation
author IBBoard <dev@ibboard.co.uk>
date Sun, 03 Apr 2011 19:03:30 +0000
parents 3c4a6403a88c
children 50cd43bf51b3
files API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs
diffstat 2 files changed, 35 insertions(+), 16 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs	Sun Apr 03 18:50:32 2011 +0000
     1.2 +++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs	Sun Apr 03 19:03:30 2011 +0000
     1.3 @@ -75,7 +75,7 @@
     1.4  		/// <param name='toValidate'>
     1.5  		/// The army to validate
     1.6  		/// </param>
     1.7 -		public bool ValidatesArmy(Army toValidate)
     1.8 +		public virtual bool ValidatesArmy(Army toValidate)
     1.9  		{
    1.10  			bool canAdd = true;
    1.11  
     2.1 --- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs	Sun Apr 03 18:50:32 2011 +0000
     2.2 +++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs	Sun Apr 03 19:03:30 2011 +0000
     2.3 @@ -1,22 +1,22 @@
     2.4  // This file (UnitRequiresAtLeastNUnitsRequirement.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 +// 
     2.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.
     2.9  using System;
    2.10  using System.Collections.Generic;
    2.11 -using IBBoard.WarFoundry.API.Objects;
    2.12 -
    2.13 -namespace IBBoard.WarFoundry.API.Objects.Requirement
    2.14 +using IBBoard.WarFoundry.API.Objects;
    2.15 +
    2.16 +namespace IBBoard.WarFoundry.API.Objects.Requirement
    2.17  {
    2.18  	/// <summary>
    2.19  	/// 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.
    2.20 -	/// </summary>
    2.21 -	public class UnitRequiresAtLeastNUnitsRequirement : RequiresAtLeastNUnitsRequirement
    2.22 +	/// </summary>
    2.23 +	public class UnitRequiresAtLeastNUnitsRequirement : RequiresAtLeastNUnitsRequirement
    2.24  	{
    2.25  		private UnitType requirementOnType;
    2.26 -
    2.27 -		public UnitRequiresAtLeastNUnitsRequirement(UnitType requirementOn) : base()
    2.28 +
    2.29 +		public UnitRequiresAtLeastNUnitsRequirement(UnitType requirementOn) : base()
    2.30  		{
    2.31 -			requirementOnType = requirementOn;
    2.32 +			requirementOnType = requirementOn;
    2.33  		}
    2.34  
    2.35  		/// <summary>
    2.36 @@ -36,10 +36,29 @@
    2.37  			return IsApplicable(wfObject, toArmy) ? base.ValidatesArmy(toArmy) : true;
    2.38  		}
    2.39  
    2.40 -		public bool IsApplicable (WarFoundryObject wfObject, Army toArmy)
    2.41 +
    2.42 +		private bool IsApplicable(WarFoundryObject toObject, Army toArmy)
    2.43  		{
    2.44 -			return toArmy.GetUnitTypeCount(requirementOnType) > 0 || requirementOnType.Equals(wfObject) || (wfObject is Unit && requirementOnType.Equals(((Unit)wfObject).UnitType));
    2.45 +			return IsApplicable(toArmy) || IsApplicable(toObject);
    2.46  		}
    2.47 -	}
    2.48 -}
    2.49 -
    2.50 +
    2.51 +
    2.52 +		private bool IsApplicable(Army toArmy)
    2.53 +		{
    2.54 +			return toArmy.GetUnitTypeCount(requirementOnType) > 0;
    2.55 +		}
    2.56 +
    2.57 +
    2.58 +		private bool IsApplicable(WarFoundryObject toObject)
    2.59 +		{
    2.60 +			return requirementOnType.Equals(toObject) || (toObject is Unit && requirementOnType.Equals(((Unit)toObject).UnitType));
    2.61 +		}
    2.62 +
    2.63 +
    2.64 +		public override bool ValidatesArmy(Army toArmy)
    2.65 +		{
    2.66 +			return IsApplicable(toArmy) ? base.ValidatesArmy(toArmy) : true;
    2.67 +		}
    2.68 +	}
    2.69 +}
    2.70 +