changeset 121:53654e938982

Re #54: Add army file loading * Add equipment loading (currently fails because of ID mismatch - in the test race we create UnitEquipmentItems with the ID Empire1equip1 but in the army saving/loading we use equip1)
author IBBoard <dev@ibboard.co.uk>
date Sun, 23 Aug 2009 11:05:37 +0000
parents fcbc3beea498
children 571eee2b7b30
files api/Factories/Xml/WarFoundryXmlArmyParser.cs
diffstat 1 files changed, 37 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlArmyParser.cs	Sun Aug 23 11:03:09 2009 +0000
+++ b/api/Factories/Xml/WarFoundryXmlArmyParser.cs	Sun Aug 23 11:05:37 2009 +0000
@@ -80,7 +80,43 @@
 					army.AddUnit(unit);
 					units.Add(id, unit);
 
-					//LoadUnitEquipment(
+					LoadUnitEquipment(unitElem, unit);
+				}
+			}
+		}
+
+		private void LoadUnitEquipment(XmlElement unitElem, Unit unit)
+		{
+			foreach (XmlElement elem in WarFoundryXmlFactoryUtils.SelectNodes(unitElem, "army:equipment/army:equipItem"))
+			{
+				string equipID = elem.GetAttribute("id");
+				bool isCustom = XmlTools.GetBoolValueFromAttribute(elem, "isCustomEquipment");
+
+				if (!isCustom)
+				{
+					UnitEquipmentItem item = unit.UnitType.GetEquipmentItem(equipID);
+	
+					if (item == null)
+					{
+						throw new RequiredDataMissingException(file.Name, "equipItem ID", equipID);
+					}
+	
+					double amount = XmlTools.GetDoubleValueFromAttribute(elem, "amount");
+					string equipTypeString = elem.GetAttribute("amountType");
+
+					if (equipTypeString == "ratio")
+					{
+						unit.SetEquipmentRatio(item, amount);
+					}
+					else
+					{
+						//amount should be a whole number, so do type-cast rounding
+						unit.SetEquipmentAmount(item, (int) amount);
+					}
+				}
+				else
+				{
+					//TODO: Load custom equipment
 				}
 			}
 		}