# HG changeset patch # User IBBoard # Date 1256241102 0 # Node ID 22429737cd77849ccf0ce7ca20f4c2cef54731ad # Parent 996816199b72f59da217131ebd6fb3b2c74ea902 Re #198: Add slots with counts to units * Migrate to using new Limit objects from ibboard:ticket:24 * Parse new objects * Move more data type definitions in to Core schema for re-use * Make UnitType just return limit objects diff -r 996816199b72 -r 22429737cd77 api/Factories/Xml/WarFoundryXmlRaceFactory.cs --- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Wed Oct 21 19:01:13 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Thu Oct 22 19:51:42 2009 +0000 @@ -8,6 +8,7 @@ using System.Xml; using IBBoard.Xml; using IBBoard.IO; +using IBBoard.Limits; using IBBoard.CustomMath; using ICSharpCode.SharpZipLib.Zip; using IBBoard.WarFoundry.API.Objects; @@ -156,13 +157,52 @@ private void LoadEquipmentSlotsForUnitType(XmlElement elem, UnitType type) { - foreach (XmlElement equip in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:equipmentSlots/race:equipmentSlot")) + foreach (XmlElement equipSlot in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:equipmentSlots/race:equipmentSlot")) { - string slotName = equip.GetAttribute("name"); - int slotLimit = XmlTools.GetIntValueFromAttribute(equip, "limit"); - type.AddEquipmentSlot(slotName, slotLimit); + LoadEquipmentSlotForUnitType (type, equipSlot); + } + } + + private static void LoadEquipmentSlotForUnitType (UnitType type, XmlElement equipSlot) + { + string slotName = equipSlot.GetAttribute ("name"); + XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(equipSlot, "race:maxLimit/*[1]"); + AbstractLimit limit = GetLimitFromElement(limitElem); + + if (limit!=null) + { + type.AddEquipmentSlot (slotName, limit); } } + + private static AbstractLimit GetLimitFromElement(XmlElement limitElem) + { + AbstractLimit limit = null; + + switch(limitElem.Name) + { + case "percentageLimit": + double limitPercent = XmlTools.GetDoubleValueFromAttribute (limitElem, "limit"); + bool roundUp = limitElem.GetAttribute("round").Equals("up"); + limit = new SimpleRoundedPercentageLimit(limitPercent, roundUp); + break; + case "sizeConstrainedLimit": + limit = new NumericSizeConstrainedLimit(XmlTools.GetIntValueFromAttribute(limitElem, "limit")); + break; + case "absoluteLimit": + limit = new AbsoluteNumericLimit(XmlTools.GetIntValueFromAttribute(limitElem, "limit")); + break; + case "unlimitedLimit": + limit = new UnlimitedLimit(); + break; + default: + //TODO: Warn of missing handler for when we've extended the limit list + break; + } + + return limit; + } + private void LoadEquipmentForUnitType(XmlElement elem, UnitType type) { diff -r 996816199b72 -r 22429737cd77 api/Objects/UnitType.cs --- a/api/Objects/UnitType.cs Wed Oct 21 19:01:13 2009 +0000 +++ b/api/Objects/UnitType.cs Thu Oct 22 19:51:42 2009 +0000 @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Xml; +using IBBoard.Limits; using IBBoard.Logging; using IBBoard.WarFoundry.API.Requirements; @@ -31,7 +32,7 @@ private String notes = ""; private List containedTypes = new List(); private Dictionary extraData = new Dictionary(); - private Dictionary slotLimits = new Dictionary(); + private Dictionary slotLimits = new Dictionary(); public UnitType(string id, string typeName, Race parentRace) : base(id, typeName) @@ -450,7 +451,7 @@ } } - public void AddEquipmentSlot(string slotName, int slotLimit) + public void AddEquipmentSlot(string slotName, AbstractLimit slotLimit) { slotLimits.Add(slotName, slotLimit); } @@ -461,18 +462,23 @@ } /// - /// Gets the maximum number of items allowed in a single slot + /// Gets the maximum limit on the number of items allowed in a single slot /// - /// The name of the equipment slot to get the limit for the named slot - /// The maximum number of items allowed in a slot, or -1 if the slot is the default one or has not been specified - public int GetEquipmentSlotLimit(string slotName) + /// The name of the equipment slot to get the limit for + /// The limit of the number of items allowed in a slot, or an infinite limit if the slot is the default one or has not been specified + public AbstractLimit GetEquipmentSlotLimit(string slotName) { - int slotLimit = -1; + AbstractLimit slotLimit = null; if (HasEquipmentSlot(slotName)) { slotLimit = DictionaryUtils.GetValue(slotLimits, slotName); } + + if (slotLimit == null) + { + slotLimit = new UnlimitedLimit(); + } return slotLimit; } diff -r 996816199b72 -r 22429737cd77 dtds/race.xsd --- a/dtds/race.xsd Wed Oct 21 19:01:13 2009 +0000 +++ b/dtds/race.xsd Thu Oct 22 19:51:42 2009 +0000 @@ -33,14 +33,11 @@ - - - - - - - - + + + + + @@ -61,7 +58,7 @@ - + @@ -199,12 +196,6 @@ - - - - - - diff -r 996816199b72 -r 22429737cd77 dtds/warfoundry-core.xsd --- a/dtds/warfoundry-core.xsd Wed Oct 21 19:01:13 2009 +0000 +++ b/dtds/warfoundry-core.xsd Thu Oct 22 19:51:42 2009 +0000 @@ -7,7 +7,35 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -40,4 +68,10 @@ + + + + + + \ No newline at end of file