diff api/Objects/ArmyCategory.cs @ 82:3ea0ab04352b

* Fix line terminators no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Sat, 27 Jun 2009 18:59:49 +0000
parents e53ed2d613a1
children 89cc29b4c012
line wrap: on
line diff
--- a/api/Objects/ArmyCategory.cs	Wed May 27 19:43:09 2009 +0000
+++ b/api/Objects/ArmyCategory.cs	Sat Jun 27 18:59:49 2009 +0000
@@ -2,160 +2,161 @@
 //
 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
 
-using System;
+using System;
 using System.Collections.Generic;
-using IBBoard.WarFoundry.API.Requirements;
-
-namespace IBBoard.WarFoundry.API.Objects
-{
-	/// <summary>
-	/// Summary description for ArmyCategory.
-	/// </summary>
-	public class ArmyCategory : WarFoundryObject
-	{
-		private Category category;
-		private Army parentArmy;
-		private double pointsTotal;
-		private List<Unit> units;
-		private Dictionary<string, int> unitTypes;
-		private DoubleValChangedDelegate PointsValueChangedMethod;
-		public event DoubleValChangedDelegate PointsValueChanged;
-		public event ObjectAddDelegate UnitAdded;
-		public event ObjectRemoveDelegate UnitRemoved;
-
-		public ArmyCategory(Army army, Category cat) : base()
-		{
-			parentArmy = army;
-			category = cat;
-			cat.NameChanged+=new StringValChangedDelegate(cat_NameChanged);
-			PointsValueChangedMethod = new DoubleValChangedDelegate(PointsValueChangedHandler);
-			units = new List<Unit>();
-			unitTypes = new Dictionary<string,int>();
-		}
-
-		public Category Category
-		{
-			get { return category; }
-		}
-
-		public Army ParentArmy
-		{
-			get { return parentArmy; }
-		}
-
-		public override string ID
-		{
-			get
-			{
-				return Category.ID;
-			}
-			set
-			{
-				Category.ID = value;
-			}
-		}
-
-		public override string Name
-		{
-			get { return category.Name; }
-			set 
-			{
-				category.Name = value;
-			}
-		}
-
-		internal void AddUnit(Unit unit)
-		{
-			units.Add(unit);
-			unit.Category = this;
+using IBBoard.WarFoundry.API.Requirements;
+
+namespace IBBoard.WarFoundry.API.Objects
+{
+	/// <summary>
+	/// Summary description for ArmyCategory.
+	/// </summary>
+	public class ArmyCategory : WarFoundryObject
+	{
+		private Category category;
+		private Army parentArmy;
+		private double pointsTotal;
+		private List<Unit> units;
+		private Dictionary<string, int> unitTypes;
+		private DoubleValChangedDelegate PointsValueChangedMethod;
+		public event DoubleValChangedDelegate PointsValueChanged;
+		public event ObjectAddDelegate UnitAdded;
+		public event ObjectRemoveDelegate UnitRemoved;
+
+		public ArmyCategory(Army army, Category cat) : base()
+		{
+			parentArmy = army;
+			category = cat;
+			cat.NameChanged+=new StringValChangedDelegate(cat_NameChanged);
+			PointsValueChangedMethod = new DoubleValChangedDelegate(PointsValueChangedHandler);
+			units = new List<Unit>();
+			unitTypes = new Dictionary<string,int>();
+		}
+
+		public Category Category
+		{
+			get { return category; }
+		}
+
+		public Army ParentArmy
+		{
+			get { return parentArmy; }
+		}
+
+		public override string ID
+		{
+			get
+			{
+				return Category.ID;
+			}
+			set
+			{
+				Category.ID = value;
+			}
+		}
+
+		public override string Name
+		{
+			get { return category.Name; }
+			set 
+			{
+				category.Name = value;
+			}
+		}
+
+		internal void AddUnit(Unit unit)
+		{
+			List<FailedUnitRequirement> failedReqs = ParentArmy.CanAddUnit(unit);
+			units.Add(unit);
+			unit.Category = this;
 			unit.PointsValueChanged+= PointsValueChangedMethod;
-			int unitTypeCount;
-			unitTypes.TryGetValue(unit.UnitType.ID, out unitTypeCount);
-			unitTypes[unit.UnitType.ID] = (int)unitTypeCount + 1;
+			int unitTypeCount;
+			unitTypes.TryGetValue(unit.UnitType.ID, out unitTypeCount);
+			unitTypes[unit.UnitType.ID] = (int)unitTypeCount + 1;
 			TotalPoints+= unit.PointsValue;
-			OnUnitAdded(unit);
-		}
-
-		internal void RemoveUnit(Unit unit)
-		{
-			units.Remove(unit);
-			unitTypes[unit.UnitType.ID] = ((int)unitTypes[unit.UnitType.ID])-1;
-			TotalPoints-= unit.PointsValue;
+			OnUnitAdded(unit);
+		}
+
+		internal void RemoveUnit(Unit unit)
+		{
+			units.Remove(unit);
+			unitTypes[unit.UnitType.ID] = ((int)unitTypes[unit.UnitType.ID])-1;
+			TotalPoints-= unit.PointsValue;
 			unit.PointsValueChanged-= PointsValueChangedMethod;
-			OnUnitRemoved(unit);
-		}
-
-		public int GetUnitTypeCount(UnitType unitType)
-		{
-			return unitTypes.ContainsKey(unitType.ID) ? (int)unitTypes[unitType.ID] : 0;
-		}
-
-		public Unit[] GetUnits()
-		{
-			return units.ToArray();
-		}
-
-		private double TotalPoints
-		{
-			get { return pointsTotal; }
-			set 
-			{
-				double oldVal = pointsTotal;
-				pointsTotal = value;
-
-				if (oldVal!=pointsTotal)
-				{
-					OnPointsValueChanged(oldVal, pointsTotal);
-				}
-			}
-		}
-
-		public double PointsTotal
-		{
-			get { return TotalPoints; }
-		}
-
-		private void PointsValueChangedHandler(WarFoundryObject obj, double oldVal, double newVal)
-		{
-			if (obj is Unit)
-			{
-				double diff = newVal - oldVal;
-				TotalPoints+= diff;
-			}
-		}
-
-		private void OnUnitAdded(Unit unit)
-		{
-			if (UnitAdded!=null)
-			{
-				UnitAdded(unit);
-			}
-		}
-
-		private void OnUnitRemoved(Unit unit)
-		{
-			if (UnitRemoved!=null)
-			{
-				UnitRemoved(unit);
-			}
-		}
-
-		protected virtual void OnPointsValueChanged(double oldValue, double newValue)
-		{
-			if (PointsValueChanged!=null)
-			{
-				PointsValueChanged(this, oldValue, newValue);
-			}
-		}
-
-		protected void cat_NameChanged(WarFoundryObject obj, string oldValue, string newValue)
-		{
-			OnNameChanged(oldValue, newValue);
-		}
-				
-		public int GetPointsPercentage()
-		{
-			return (int)Math.Round((PointsTotal / ParentArmy.MaxPoints) * 100, 0);
-		}
-	}
-}
+			OnUnitRemoved(unit);
+		}
+
+		public int GetUnitTypeCount(UnitType unitType)
+		{
+			return unitTypes.ContainsKey(unitType.ID) ? (int)unitTypes[unitType.ID] : 0;
+		}
+
+		public Unit[] GetUnits()
+		{
+			return units.ToArray();
+		}
+
+		private double TotalPoints
+		{
+			get { return pointsTotal; }
+			set 
+			{
+				double oldVal = pointsTotal;
+				pointsTotal = value;
+
+				if (oldVal!=pointsTotal)
+				{
+					OnPointsValueChanged(oldVal, pointsTotal);
+				}
+			}
+		}
+
+		public double PointsTotal
+		{
+			get { return TotalPoints; }
+		}
+
+		private void PointsValueChangedHandler(WarFoundryObject obj, double oldVal, double newVal)
+		{
+			if (obj is Unit)
+			{
+				double diff = newVal - oldVal;
+				TotalPoints+= diff;
+			}
+		}
+
+		private void OnUnitAdded(Unit unit)
+		{
+			if (UnitAdded!=null)
+			{
+				UnitAdded(unit);
+			}
+		}
+
+		private void OnUnitRemoved(Unit unit)
+		{
+			if (UnitRemoved!=null)
+			{
+				UnitRemoved(unit);
+			}
+		}
+
+		protected virtual void OnPointsValueChanged(double oldValue, double newValue)
+		{
+			if (PointsValueChanged!=null)
+			{
+				PointsValueChanged(this, oldValue, newValue);
+			}
+		}
+
+		protected void cat_NameChanged(WarFoundryObject obj, string oldValue, string newValue)
+		{
+			OnNameChanged(oldValue, newValue);
+		}
+				
+		public int GetPointsPercentage()
+		{
+			return (int)Math.Round((PointsTotal / ParentArmy.MaxPoints) * 100, 0);
+		}
+	}
+}