# HG changeset patch # User IBBoard # Date 1251025537 0 # Node ID 53654e938982eed4625f751e419225ef4df747d2 # Parent fcbc3beea498e7c4c36dd14acb6493eb5582c4ec 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) diff -r fcbc3beea498 -r 53654e938982 api/Factories/Xml/WarFoundryXmlArmyParser.cs --- 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 } } }