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 diff
     1.1 --- a/api/Exporters/WarFoundryHtmlExporter.cs	Sat Sep 26 19:57:06 2009 +0000
     1.2 +++ b/api/Exporters/WarFoundryHtmlExporter.cs	Mon Sep 28 19:32:52 2009 +0000
     1.3 @@ -56,10 +56,10 @@
     1.4  			body.AppendChild(header);
     1.5  			
     1.6  			foreach (XmlElement table in CreateTables(army, doc))
     1.7 -			{
     1.8 -				if (!IsTableOnlyHeader(table))
     1.9 -				{
    1.10 -					body.AppendChild(table);
    1.11 +			{
    1.12 +				if (!IsTableOnlyHeader(table))
    1.13 +				{
    1.14 +					body.AppendChild(table);
    1.15  				}
    1.16  			}
    1.17  			
    1.18 @@ -73,11 +73,11 @@
    1.19  			{
    1.20  				writer.Close();
    1.21  			}
    1.22 -		}
    1.23 -
    1.24 -		private bool IsTableOnlyHeader(XmlElement table)
    1.25 -		{
    1.26 -			return table.ChildNodes.Count == 1;
    1.27 +		}
    1.28 +
    1.29 +		private bool IsTableOnlyHeader(XmlElement table)
    1.30 +		{
    1.31 +			return table.ChildNodes.Count == 1;
    1.32  		}
    1.33  		
    1.34  		private XmlElement[] CreateTables(Army army, XmlDocument doc)
     2.1 --- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs	Sat Sep 26 19:57:06 2009 +0000
     2.2 +++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs	Mon Sep 28 19:32:52 2009 +0000
     2.3 @@ -129,8 +129,8 @@
     2.4  			type.MaxSize = XmlTools.GetIntValueFromAttribute(elem, "maxSize");
     2.5  			type.MinSize = XmlTools.GetIntValueFromAttribute(elem, "minSize");
     2.6  			type.BaseSize = XmlTools.GetIntValueFromAttribute(elem, "baseSize");
     2.7 -			type.CostPerTrooper = XmlTools.GetIntValueFromAttribute(elem, "points");
     2.8 -			type.BaseUnitCost = XmlTools.GetIntValueFromAttribute(elem, "unitPoints");
     2.9 +			type.CostPerTrooper = XmlTools.GetDoubleValueFromAttribute(elem, "points");
    2.10 +			type.BaseUnitCost = XmlTools.GetDoubleValueFromAttribute(elem, "unitPoints");
    2.11  			string mainCatID = elem.GetAttribute("cat");
    2.12  			Category cat = type.Race.GetCategory(mainCatID);
    2.13  			
    2.14 @@ -154,29 +154,29 @@
    2.15  				
    2.16  				if (equipItem!=null)
    2.17  				{
    2.18 -					string mutexGroupString = equip.GetAttribute("exclusivityGroups");
    2.19 -					string[] mutexGroups;
    2.20 -
    2.21 -					if (mutexGroupString == "")
    2.22 -					{
    2.23 -						mutexGroupString = equip.GetAttribute("exclusivityGroup");
    2.24 -					}
    2.25 -
    2.26 -					if (mutexGroupString != "")
    2.27 -					{
    2.28 -						string[] groups = mutexGroupString.Split(',');
    2.29 -						int groupCount = groups.Length;
    2.30 -
    2.31 -						for (int i = 0; i < groupCount; i++)
    2.32 -						{
    2.33 -							groups[i] = groups[i].Trim();
    2.34 -						}
    2.35 -
    2.36 -						mutexGroups = groups;
    2.37 -					}
    2.38 -					else
    2.39 -					{
    2.40 -						mutexGroups = new string[0];
    2.41 +					string mutexGroupString = equip.GetAttribute("exclusivityGroups");
    2.42 +					string[] mutexGroups;
    2.43 +
    2.44 +					if (mutexGroupString == "")
    2.45 +					{
    2.46 +						mutexGroupString = equip.GetAttribute("exclusivityGroup");
    2.47 +					}
    2.48 +
    2.49 +					if (mutexGroupString != "")
    2.50 +					{
    2.51 +						string[] groups = mutexGroupString.Split(',');
    2.52 +						int groupCount = groups.Length;
    2.53 +
    2.54 +						for (int i = 0; i < groupCount; i++)
    2.55 +						{
    2.56 +							groups[i] = groups[i].Trim();
    2.57 +						}
    2.58 +
    2.59 +						mutexGroups = groups;
    2.60 +					}
    2.61 +					else
    2.62 +					{
    2.63 +						mutexGroups = new string[0];
    2.64  					}
    2.65  
    2.66  					UnitEquipmentItem unitEquipItem = new UnitEquipmentItem(equipItem, type, mutexGroups);
     3.1 --- a/api/Objects/Unit.cs	Sat Sep 26 19:57:06 2009 +0000
     3.2 +++ b/api/Objects/Unit.cs	Mon Sep 28 19:32:52 2009 +0000
     3.3 @@ -433,39 +433,39 @@
     3.4  		
     3.5  		public bool CanEquipWithItem(UnitEquipmentItem item)
     3.6  		{
     3.7 -			string[] mutexes = item.MutexGroups;
     3.8 -			bool canEquip = false;
     3.9 -
    3.10 -			if (mutexes.Length == 0)
    3.11 -			{
    3.12 -				canEquip = true;
    3.13 -			}
    3.14 -			else
    3.15 -			{
    3.16 -				canEquip = GetBlockingEquipmentItems(item).Count == 0;
    3.17 +			string[] mutexes = item.MutexGroups;
    3.18 +			bool canEquip = false;
    3.19 +
    3.20 +			if (mutexes.Length == 0)
    3.21 +			{
    3.22 +				canEquip = true;
    3.23 +			}
    3.24 +			else
    3.25 +			{
    3.26 +				canEquip = GetBlockingEquipmentItems(item).Count == 0;
    3.27  			}
    3.28  
    3.29  			return canEquip;
    3.30 -		}
    3.31 -
    3.32 -		/// <summary>
    3.33 -		/// Gets a list of all <see cref="UnitEquipmentItem"/>s that would stop the unit taking <code>item</code> because of mutex groups.
    3.34 -		/// </summary>
    3.35 -		/// <param name="item">The item to check blocking items for</param>
    3.36 -		/// <returns>a list of all <see cref="UnitEquipmentItem"/>s that would stop the unit taking <code>item</code></returns>
    3.37 -		public List<UnitEquipmentItem> GetBlockingEquipmentItems(UnitEquipmentItem item)
    3.38 -		{
    3.39 -			List<UnitEquipmentItem> items = new List<UnitEquipmentItem>();
    3.40 -
    3.41 -			foreach (UnitEquipmentItem unitItem in GetEquipment())
    3.42 -			{
    3.43 -				if (unitItem.IsMutuallyExclusive(item))
    3.44 -				{
    3.45 -					items.Add(unitItem);
    3.46 -				}
    3.47 -			}
    3.48 -
    3.49 -			return items;
    3.50 +		}
    3.51 +
    3.52 +		/// <summary>
    3.53 +		/// Gets a list of all <see cref="UnitEquipmentItem"/>s that would stop the unit taking <code>item</code> because of mutex groups.
    3.54 +		/// </summary>
    3.55 +		/// <param name="item">The item to check blocking items for</param>
    3.56 +		/// <returns>a list of all <see cref="UnitEquipmentItem"/>s that would stop the unit taking <code>item</code></returns>
    3.57 +		public List<UnitEquipmentItem> GetBlockingEquipmentItems(UnitEquipmentItem item)
    3.58 +		{
    3.59 +			List<UnitEquipmentItem> items = new List<UnitEquipmentItem>();
    3.60 +
    3.61 +			foreach (UnitEquipmentItem unitItem in GetEquipment())
    3.62 +			{
    3.63 +				if (unitItem.IsMutuallyExclusive(item))
    3.64 +				{
    3.65 +					items.Add(unitItem);
    3.66 +				}
    3.67 +			}
    3.68 +
    3.69 +			return items;
    3.70  		}
    3.71  
    3.72  		public bool CanEquipWithItem(string equipID)
     4.1 --- a/api/Objects/UnitEquipmentItem.cs	Sat Sep 26 19:57:06 2009 +0000
     4.2 +++ b/api/Objects/UnitEquipmentItem.cs	Mon Sep 28 19:32:52 2009 +0000
     4.3 @@ -20,7 +20,7 @@
     4.4  		private double minPercentage;
     4.5  		private double maxPercentage;
     4.6  		private double costMultiplier;
     4.7 -		private RoundType roundType;
     4.8 +		private RoundType roundType;
     4.9  		private string[] mutexGroups;
    4.10  		private UnitType unitType;
    4.11  
    4.12 @@ -35,7 +35,7 @@
    4.13  			unitType = equipmentFor;
    4.14  			this.mutexGroups = mutexGroups;
    4.15  			unitType.AddEquipmentItem(this);
    4.16 -		}
    4.17 +		}
    4.18  		
    4.19  		public override string Name
    4.20  		{
    4.21 @@ -108,11 +108,11 @@
    4.22  		public string MutexGroup
    4.23  		{
    4.24  			get { return (mutexGroups.Length == 0 ? "" : mutexGroups[0]); }
    4.25 -		}
    4.26 -
    4.27 -		public String[] MutexGroups
    4.28 -		{
    4.29 -			get { return (string[]) mutexGroups.Clone(); }
    4.30 +		}
    4.31 +
    4.32 +		public String[] MutexGroups
    4.33 +		{
    4.34 +			get { return (string[]) mutexGroups.Clone(); }
    4.35  		}
    4.36  
    4.37  		public UnitType EquipmentForUnit
    4.38 @@ -227,31 +227,31 @@
    4.39  		public bool CanBeUsedWithArmourType(ArmourType otherItemType)
    4.40  		{
    4.41  			return EquipmentItem.CanBeUsedWithArmourType(otherItemType);
    4.42 -		}
    4.43 -
    4.44 -		/// <summary>
    4.45 -		/// 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)
    4.46 -		/// </summary>
    4.47 -		/// <param name="item">the item to check against</param>
    4.48 -		/// <returns><code>true</code> if the two items share at least one mutex group, else <code>false</code></returns>
    4.49 -		public bool IsMutuallyExclusive(UnitEquipmentItem item)
    4.50 -		{
    4.51 -			bool areMutex = false;
    4.52 -
    4.53 -			foreach (string mutex in MutexGroups)
    4.54 -			{
    4.55 -				foreach (string otherMutex in item.MutexGroups)
    4.56 -				{
    4.57 -					if (mutex.Equals(otherMutex))
    4.58 -					{
    4.59 -						areMutex = true;
    4.60 -						goto postLoop;
    4.61 -					}
    4.62 -				}
    4.63 -			}
    4.64 -			postLoop:
    4.65 -
    4.66 -			return areMutex;
    4.67 -		}
    4.68 +		}
    4.69 +
    4.70 +		/// <summary>
    4.71 +		/// 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)
    4.72 +		/// </summary>
    4.73 +		/// <param name="item">the item to check against</param>
    4.74 +		/// <returns><code>true</code> if the two items share at least one mutex group, else <code>false</code></returns>
    4.75 +		public bool IsMutuallyExclusive(UnitEquipmentItem item)
    4.76 +		{
    4.77 +			bool areMutex = false;
    4.78 +
    4.79 +			foreach (string mutex in MutexGroups)
    4.80 +			{
    4.81 +				foreach (string otherMutex in item.MutexGroups)
    4.82 +				{
    4.83 +					if (mutex.Equals(otherMutex))
    4.84 +					{
    4.85 +						areMutex = true;
    4.86 +						goto postLoop;
    4.87 +					}
    4.88 +				}
    4.89 +			}
    4.90 +			postLoop:
    4.91 +
    4.92 +			return areMutex;
    4.93 +		}
    4.94  	}
    4.95  }
     5.1 --- a/api/Objects/UnitType.cs	Sat Sep 26 19:57:06 2009 +0000
     5.2 +++ b/api/Objects/UnitType.cs	Mon Sep 28 19:32:52 2009 +0000
     5.3 @@ -295,24 +295,24 @@
     5.4  		}
     5.5  
     5.6  		public UnitEquipmentItem[] GetEquipmentItemsByExclusionGroup(string group)
     5.7 -		{
     5.8 +		{
     5.9  			return GetEquipmentItemsByExclusionGroups(new string[] { group });
    5.10  		}
    5.11  
    5.12  		public UnitEquipmentItem[] GetEquipmentItemsByExclusionGroups(string[] groups)
    5.13  		{
    5.14 -			List<UnitEquipmentItem> list = new List<UnitEquipmentItem>();
    5.15 -
    5.16 -			foreach (string group in groups)
    5.17 -			{
    5.18 -				List<UnitEquipmentItem> groupList = DictionaryUtils.GetValue(equipmentExclusionGroups, group);
    5.19 -
    5.20 -				if (groupList != null)
    5.21 -				{
    5.22 -					list.AddRange(groupList);
    5.23 -				}
    5.24 -			}
    5.25 -
    5.26 +			List<UnitEquipmentItem> list = new List<UnitEquipmentItem>();
    5.27 +
    5.28 +			foreach (string group in groups)
    5.29 +			{
    5.30 +				List<UnitEquipmentItem> groupList = DictionaryUtils.GetValue(equipmentExclusionGroups, group);
    5.31 +
    5.32 +				if (groupList != null)
    5.33 +				{
    5.34 +					list.AddRange(groupList);
    5.35 +				}
    5.36 +			}
    5.37 +
    5.38  			return list.ToArray();
    5.39  		}
    5.40