diff api/Objects/Race.cs @ 258:3b395ab8784d

Re #270: Add multiple categories to API * Make Race cache new units against each category
author IBBoard <dev@ibboard.co.uk>
date Wed, 19 May 2010 19:23:29 +0000
parents a54da5a8b5bb
children cd657faa0c05 8981fc45fe17
line wrap: on
line diff
--- a/api/Objects/Race.cs	Tue May 18 19:59:17 2010 +0000
+++ b/api/Objects/Race.cs	Wed May 19 19:23:29 2010 +0000
@@ -162,15 +162,18 @@
 		private void CacheUnitType(UnitType unit)
 		{
 			BuildUnitTypesByCategoryCache();
-			Dictionary<string,UnitType> catUnitTypes;
-			unitTypesByCat.TryGetValue(unit.MainCategory, out catUnitTypes);
-
-			if (catUnitTypes == null)
+			
+			foreach (Category cat in unit.Categories)
 			{
-				throw new InvalidFileException(String.Format("Unit type {0} with name {1} is a unit of an undefined category", unit.ID, unit.Name));
+				Dictionary<string, UnitType> catUnitTypes = DictionaryUtils.GetValue(unitTypesByCat, cat);
+	
+				if (catUnitTypes == null)
+				{
+					throw new InvalidFileException(String.Format("Unit type {0} with name {1} is a unit of an undefined category ({2})", unit.ID, unit.Name, cat.ID));
+				}
+
+				catUnitTypes.Add(unit.ID, unit);
 			}
-
-			catUnitTypes.Add(unit.ID, unit);
 		}
 		
 		private void BuildUnitTypesByCategoryCache()