# HG changeset patch # User IBBoard # Date 1254166372 0 # Node ID 4a02c07278e74c9eb31cb45b0822f544f197e6f1 # Parent dd892567f05434113a3ace175d5ce64272e29a8d Re #185: Problems with decimals in race definitions * Fix race factory so that it parses unit costs as doubles, not ints Also: * Line ending clean-up diff -r dd892567f054 -r 4a02c07278e7 api/Exporters/WarFoundryHtmlExporter.cs --- a/api/Exporters/WarFoundryHtmlExporter.cs Sat Sep 26 19:57:06 2009 +0000 +++ b/api/Exporters/WarFoundryHtmlExporter.cs Mon Sep 28 19:32:52 2009 +0000 @@ -56,10 +56,10 @@ body.AppendChild(header); foreach (XmlElement table in CreateTables(army, doc)) - { - if (!IsTableOnlyHeader(table)) - { - body.AppendChild(table); + { + if (!IsTableOnlyHeader(table)) + { + body.AppendChild(table); } } @@ -73,11 +73,11 @@ { writer.Close(); } - } - - private bool IsTableOnlyHeader(XmlElement table) - { - return table.ChildNodes.Count == 1; + } + + private bool IsTableOnlyHeader(XmlElement table) + { + return table.ChildNodes.Count == 1; } private XmlElement[] CreateTables(Army army, XmlDocument doc) diff -r dd892567f054 -r 4a02c07278e7 api/Factories/Xml/WarFoundryXmlRaceFactory.cs --- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Sat Sep 26 19:57:06 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Mon Sep 28 19:32:52 2009 +0000 @@ -129,8 +129,8 @@ type.MaxSize = XmlTools.GetIntValueFromAttribute(elem, "maxSize"); type.MinSize = XmlTools.GetIntValueFromAttribute(elem, "minSize"); type.BaseSize = XmlTools.GetIntValueFromAttribute(elem, "baseSize"); - type.CostPerTrooper = XmlTools.GetIntValueFromAttribute(elem, "points"); - type.BaseUnitCost = XmlTools.GetIntValueFromAttribute(elem, "unitPoints"); + type.CostPerTrooper = XmlTools.GetDoubleValueFromAttribute(elem, "points"); + type.BaseUnitCost = XmlTools.GetDoubleValueFromAttribute(elem, "unitPoints"); string mainCatID = elem.GetAttribute("cat"); Category cat = type.Race.GetCategory(mainCatID); @@ -154,29 +154,29 @@ if (equipItem!=null) { - string mutexGroupString = equip.GetAttribute("exclusivityGroups"); - string[] mutexGroups; - - if (mutexGroupString == "") - { - mutexGroupString = equip.GetAttribute("exclusivityGroup"); - } - - if (mutexGroupString != "") - { - string[] groups = mutexGroupString.Split(','); - int groupCount = groups.Length; - - for (int i = 0; i < groupCount; i++) - { - groups[i] = groups[i].Trim(); - } - - mutexGroups = groups; - } - else - { - mutexGroups = new string[0]; + string mutexGroupString = equip.GetAttribute("exclusivityGroups"); + string[] mutexGroups; + + if (mutexGroupString == "") + { + mutexGroupString = equip.GetAttribute("exclusivityGroup"); + } + + if (mutexGroupString != "") + { + string[] groups = mutexGroupString.Split(','); + int groupCount = groups.Length; + + for (int i = 0; i < groupCount; i++) + { + groups[i] = groups[i].Trim(); + } + + mutexGroups = groups; + } + else + { + mutexGroups = new string[0]; } UnitEquipmentItem unitEquipItem = new UnitEquipmentItem(equipItem, type, mutexGroups); diff -r dd892567f054 -r 4a02c07278e7 api/Objects/Unit.cs --- a/api/Objects/Unit.cs Sat Sep 26 19:57:06 2009 +0000 +++ b/api/Objects/Unit.cs Mon Sep 28 19:32:52 2009 +0000 @@ -433,39 +433,39 @@ public bool CanEquipWithItem(UnitEquipmentItem item) { - string[] mutexes = item.MutexGroups; - bool canEquip = false; - - if (mutexes.Length == 0) - { - canEquip = true; - } - else - { - canEquip = GetBlockingEquipmentItems(item).Count == 0; + string[] mutexes = item.MutexGroups; + bool canEquip = false; + + if (mutexes.Length == 0) + { + canEquip = true; + } + else + { + canEquip = GetBlockingEquipmentItems(item).Count == 0; } return canEquip; - } - - /// - /// Gets a list of all s that would stop the unit taking item because of mutex groups. - /// - /// The item to check blocking items for - /// a list of all s that would stop the unit taking item - public List GetBlockingEquipmentItems(UnitEquipmentItem item) - { - List items = new List(); - - foreach (UnitEquipmentItem unitItem in GetEquipment()) - { - if (unitItem.IsMutuallyExclusive(item)) - { - items.Add(unitItem); - } - } - - return items; + } + + /// + /// Gets a list of all s that would stop the unit taking item because of mutex groups. + /// + /// The item to check blocking items for + /// a list of all s that would stop the unit taking item + public List GetBlockingEquipmentItems(UnitEquipmentItem item) + { + List items = new List(); + + foreach (UnitEquipmentItem unitItem in GetEquipment()) + { + if (unitItem.IsMutuallyExclusive(item)) + { + items.Add(unitItem); + } + } + + return items; } public bool CanEquipWithItem(string equipID) diff -r dd892567f054 -r 4a02c07278e7 api/Objects/UnitEquipmentItem.cs --- a/api/Objects/UnitEquipmentItem.cs Sat Sep 26 19:57:06 2009 +0000 +++ b/api/Objects/UnitEquipmentItem.cs Mon Sep 28 19:32:52 2009 +0000 @@ -20,7 +20,7 @@ private double minPercentage; private double maxPercentage; private double costMultiplier; - private RoundType roundType; + private RoundType roundType; private string[] mutexGroups; private UnitType unitType; @@ -35,7 +35,7 @@ unitType = equipmentFor; this.mutexGroups = mutexGroups; unitType.AddEquipmentItem(this); - } + } public override string Name { @@ -108,11 +108,11 @@ public string MutexGroup { get { return (mutexGroups.Length == 0 ? "" : mutexGroups[0]); } - } - - public String[] MutexGroups - { - get { return (string[]) mutexGroups.Clone(); } + } + + public String[] MutexGroups + { + get { return (string[]) mutexGroups.Clone(); } } public UnitType EquipmentForUnit @@ -227,31 +227,31 @@ public bool CanBeUsedWithArmourType(ArmourType otherItemType) { return EquipmentItem.CanBeUsedWithArmourType(otherItemType); - } - - /// - /// Checks the "mutex" (mutual exclusion) groups of the other item against its own and determines whether the two items are mutually exclusive (share at least one mutex group) - /// - /// the item to check against - /// true if the two items share at least one mutex group, else false - public bool IsMutuallyExclusive(UnitEquipmentItem item) - { - bool areMutex = false; - - foreach (string mutex in MutexGroups) - { - foreach (string otherMutex in item.MutexGroups) - { - if (mutex.Equals(otherMutex)) - { - areMutex = true; - goto postLoop; - } - } - } - postLoop: - - return areMutex; - } + } + + /// + /// Checks the "mutex" (mutual exclusion) groups of the other item against its own and determines whether the two items are mutually exclusive (share at least one mutex group) + /// + /// the item to check against + /// true if the two items share at least one mutex group, else false + public bool IsMutuallyExclusive(UnitEquipmentItem item) + { + bool areMutex = false; + + foreach (string mutex in MutexGroups) + { + foreach (string otherMutex in item.MutexGroups) + { + if (mutex.Equals(otherMutex)) + { + areMutex = true; + goto postLoop; + } + } + } + postLoop: + + return areMutex; + } } } diff -r dd892567f054 -r 4a02c07278e7 api/Objects/UnitType.cs --- a/api/Objects/UnitType.cs Sat Sep 26 19:57:06 2009 +0000 +++ b/api/Objects/UnitType.cs Mon Sep 28 19:32:52 2009 +0000 @@ -295,24 +295,24 @@ } public UnitEquipmentItem[] GetEquipmentItemsByExclusionGroup(string group) - { + { return GetEquipmentItemsByExclusionGroups(new string[] { group }); } public UnitEquipmentItem[] GetEquipmentItemsByExclusionGroups(string[] groups) { - List list = new List(); - - foreach (string group in groups) - { - List groupList = DictionaryUtils.GetValue(equipmentExclusionGroups, group); - - if (groupList != null) - { - list.AddRange(groupList); - } - } - + List list = new List(); + + foreach (string group in groups) + { + List groupList = DictionaryUtils.GetValue(equipmentExclusionGroups, group); + + if (groupList != null) + { + list.AddRange(groupList); + } + } + return list.ToArray(); }