diff api/Requirements/UnitRequirement.cs @ 0:520818033bb6

Initial commit of WarFoundry code
author IBBoard <dev@ibboard.co.uk>
date Fri, 19 Dec 2008 15:57:51 +0000
parents
children 306558904c2a
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/api/Requirements/UnitRequirement.cs	Fri Dec 19 15:57:51 2008 +0000
@@ -0,0 +1,92 @@
+using System;
+using System.Collections.Generic;
+using IBBoard.WarFoundry.API;
+using IBBoard.WarFoundry.API.Objects;
+
+namespace IBBoard.WarFoundry.API.Requirements
+{
+	/// <summary>
+	/// Summary description for UnitRequirement.
+	/// </summary>
+	public abstract class UnitRequirement : AbstractArmyRequirement
+	{
+		protected UnitType unitType;
+		
+		protected UnitRequirement(UnitType requirementFor)
+		{
+			unitType = requirementFor;	
+		}		
+		
+		/// <summary>
+		/// Checks whether the specified unit type can be added to the specified army. Returns a <see cref="FailedRequirement"> obejct if a unit of that type cannot legally be added, or no failure (null) if it can be added. 
+		/// </summary>
+		/// <param name="army">
+		/// The <see cref="Army"/> that the unit should be checked for adding to
+		/// </param>
+		/// <param name="type">
+		/// The <see cref="UnitType"/> that is being checked.
+		/// </param>
+		/// <returns>
+		/// A <see cref="AbstractFailedRequirement"/> if the requirement means the <see cref="UnitType"/> cannot be legally added, else <code>null</code>.
+		/// </returns>
+		protected abstract AbstractFailedRequirement CanAddToArmy(Army army, UnitType type);
+		
+		/// <summary>
+		/// Checks whether the specified unit can be added to the specified army. Returns a <see cref="FailedRequirement"> obejct if the unit cannot legally be added, or no failure (null) if it can be added. 
+		/// </summary>
+		/// <param name="army">
+		/// The <see cref="Army"/> that the unit should be checked for adding to
+		/// </param>
+		/// <param name="type">
+		/// The <see cref="Unit"/> that is being checked.
+		/// </param>
+		/// <returns>
+		/// A <see cref="AbstractFailedRequirement"/> if the requirement means the <see cref="Unit"/> cannot be legally added, else <code>null</code>.
+		/// </returns>
+		protected AbstractFailedRequirement CanAddToArmy(Army army, Unit unit)
+		{
+			return CanAddToArmy(army, unit.UnitType);
+		}
+		
+		/// <summary>
+		/// Checks whether the specified unit type can be removed from the specified army. Returns a <see cref="FailedRequirement"> obejct if a unit of that type cannot legally be removed, or no failure (null) if it can be removed. 
+		/// </summary>
+		/// <param name="army">
+		/// The <see cref="Army"/> that the unit should be checked for adding to
+		/// </param>
+		/// <param name="type">
+		/// The <see cref="UnitType"/> that is being checked.
+		/// </param>
+		/// <returns>
+		/// A <see cref="AbstractFailedRequirement"/> if the requirement means the <see cref="UnitType"/> cannot be legally added, else <code>null</code>.
+		/// </returns>
+		protected abstract AbstractFailedRequirement CanRemoveFromArmy(Army army, UnitType type);
+		
+		/// <summary>
+		/// Checks whether the specified unit can be removed from the specified army. Returns a <see cref="FailedRequirement"> obejct if the unit cannot legally be removed, or no failure (null) if it can be removed. 
+		/// </summary>
+		/// <param name="army">
+		/// The <see cref="Army"/> that the unit should be checked for adding to
+		/// </param>
+		/// <param name="type">
+		/// The <see cref="Unit"/> that is being checked.
+		/// </param>
+		/// <returns>
+		/// A <see cref="AbstractFailedRequirement"/> if the requirement means the <see cref="Unit"/> cannot be legally removed, else <code>null</code>.
+		/// </returns>
+		protected AbstractFailedRequirement CanRemoveFromArmy(Army army, Unit unit)
+		{
+			return CanRemoveFromArmy(army, unit.UnitType);
+		}
+				
+		protected override AbstractFailedRequirement CanAddToArmy(Army army)
+		{
+			return CanAddToArmy(army, unitType);
+		}
+		
+		protected override AbstractFailedRequirement CanRemoveFromArmy(Army army)
+		{
+			return CanRemoveFromArmy(army, unitType);
+		}
+	}
+}