view api/Requirements/UnitRequirement.cs @ 112:863518044d38

Re #54: Add Army support to WarFoundryFactory * Stop "custom equipment" node being mandatory * Remove unused "ratio" definition * Change "integer or ratio" definition to "integer or percentage" * Use "integer or percentage" definition in army XSD * Add exception to say that required objects were missing (Game System and Race) * Throw exceptions on creating army if game system or race is missing Re #53: Add saving of Army to XML file * Add namespace attributes to XML root node
author IBBoard <dev@ibboard.co.uk>
date Sat, 22 Aug 2009 18:18:20 +0000
parents 2f3cafb69799
children
line wrap: on
line source

// This file (UnitRequirement.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2008, 2009 IBBoard.
//
// 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.

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);
		}
	}
}