Mercurial > repos > snowblizz-super-API-ideas
changeset 154:4a02c07278e7
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
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 28 Sep 2009 19:32:52 +0000 |
parents | dd892567f054 |
children | df61d26c23fb |
files | api/Exporters/WarFoundryHtmlExporter.cs api/Factories/Xml/WarFoundryXmlRaceFactory.cs api/Objects/Unit.cs api/Objects/UnitEquipmentItem.cs api/Objects/UnitType.cs |
diffstat | 5 files changed, 110 insertions(+), 110 deletions(-) [+] |
line wrap: on
line diff
--- 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)
--- 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);
--- 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; - } - - /// <summary> - /// Gets a list of all <see cref="UnitEquipmentItem"/>s that would stop the unit taking <code>item</code> because of mutex groups. - /// </summary> - /// <param name="item">The item to check blocking items for</param> - /// <returns>a list of all <see cref="UnitEquipmentItem"/>s that would stop the unit taking <code>item</code></returns> - public List<UnitEquipmentItem> GetBlockingEquipmentItems(UnitEquipmentItem item) - { - List<UnitEquipmentItem> items = new List<UnitEquipmentItem>(); - - foreach (UnitEquipmentItem unitItem in GetEquipment()) - { - if (unitItem.IsMutuallyExclusive(item)) - { - items.Add(unitItem); - } - } - - return items; + } + + /// <summary> + /// Gets a list of all <see cref="UnitEquipmentItem"/>s that would stop the unit taking <code>item</code> because of mutex groups. + /// </summary> + /// <param name="item">The item to check blocking items for</param> + /// <returns>a list of all <see cref="UnitEquipmentItem"/>s that would stop the unit taking <code>item</code></returns> + public List<UnitEquipmentItem> GetBlockingEquipmentItems(UnitEquipmentItem item) + { + List<UnitEquipmentItem> items = new List<UnitEquipmentItem>(); + + foreach (UnitEquipmentItem unitItem in GetEquipment()) + { + if (unitItem.IsMutuallyExclusive(item)) + { + items.Add(unitItem); + } + } + + return items; } public bool CanEquipWithItem(string equipID)
--- 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); - } - - /// <summary> - /// 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) - /// </summary> - /// <param name="item">the item to check against</param> - /// <returns><code>true</code> if the two items share at least one mutex group, else <code>false</code></returns> - 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; - } + } + + /// <summary> + /// 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) + /// </summary> + /// <param name="item">the item to check against</param> + /// <returns><code>true</code> if the two items share at least one mutex group, else <code>false</code></returns> + 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; + } } }
--- 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<UnitEquipmentItem> list = new List<UnitEquipmentItem>(); - - foreach (string group in groups) - { - List<UnitEquipmentItem> groupList = DictionaryUtils.GetValue(equipmentExclusionGroups, group); - - if (groupList != null) - { - list.AddRange(groupList); - } - } - + List<UnitEquipmentItem> list = new List<UnitEquipmentItem>(); + + foreach (string group in groups) + { + List<UnitEquipmentItem> groupList = DictionaryUtils.GetValue(equipmentExclusionGroups, group); + + if (groupList != null) + { + list.AddRange(groupList); + } + } + return list.ToArray(); }