diff api/Objects/Unit.cs @ 161:81abc04b3dbe

Re #192: Improve "clean coding" practice * Move some calculation methods for equipment out of the encapsulation objects
author IBBoard <dev@ibboard.co.uk>
date Sun, 04 Oct 2009 12:00:16 +0000
parents eb9a6d91a6db
children 624422e91a1c
line wrap: on
line diff
--- a/api/Objects/Unit.cs	Sun Oct 04 10:49:17 2009 +0000
+++ b/api/Objects/Unit.cs	Sun Oct 04 12:00:16 2009 +0000
@@ -6,7 +6,8 @@
 using System.Collections.Generic;
 using System.Text;
 using System.Xml;
-using IBBoard.Lang;
+using IBBoard.Lang;
+using IBBoard.WarFoundry.API.Util;
 
 namespace IBBoard.WarFoundry.API.Objects
 {
@@ -220,39 +221,10 @@
 			}
 		}
 
+		[Obsolete("Use UnitEquipmentUtil.GetAllowedEquipmentItems(Unit) instead")]
 		public UnitEquipmentItem[] GetAllowedAdditionalEquipment()
-		{
-			List<UnitEquipmentItem> list = new List<UnitEquipmentItem>();
-			List<string> existingMutexGroups = new List<string>();
-			
-			foreach (UnitEquipmentItem item in GetEquipment())
-			{
-				foreach (string mutex in item.MutexGroups)
-				{
-					existingMutexGroups.Add(mutex);
-				}
-			}
-
-			foreach (UnitEquipmentItem item in UnitType.GetEquipmentItems())
-			{
-				bool mutexMatch = false;
-
-				foreach (string mutex in item.MutexGroups)
-				{
-					if (existingMutexGroups.Contains(mutex))
-					{
-						mutexMatch = true;
-						break;
-					}
-				}
-
-				if (!mutexMatch)
-				{
-					list.Add(item);
-				}
-			}
-
-			return list.ToArray();
+		{
+			return UnitEquipmentUtil.GetAllowedEquipmentItems(this);
 		}
 
 		public UnitEquipmentItem[] GetEquipment()
@@ -468,24 +440,10 @@
 			return canEquip;
 		}
 
-		/// <summary>
-		/// Gets a list of all <see cref="UnitEquipmentItem"/>s that would stop the unit taking <code>item</code> because of mutex groups.
-		/// </summary>
-		/// <param name="item">The item to check blocking items for</param>
-		/// <returns>a list of all <see cref="UnitEquipmentItem"/>s that would stop the unit taking <code>item</code></returns>
+		[Obsolete("Use UnitEquipmentUtil.GetBlockingEquipmentItems(Unit, UnitEquipmentItem) instead")]
 		public List<UnitEquipmentItem> GetBlockingEquipmentItems(UnitEquipmentItem item)
-		{
-			List<UnitEquipmentItem> items = new List<UnitEquipmentItem>();
-
-			foreach (UnitEquipmentItem unitItem in GetEquipment())
-			{
-				if (unitItem.IsMutuallyExclusive(item))
-				{
-					items.Add(unitItem);
-				}
-			}
-
-			return items;
+		{
+			return UnitEquipmentUtil.GetBlockingEquipmentItems(this, item);
 		}
 
 		public bool CanEquipWithItem(string equipID)