changeset 85:46ad6f478203

Re #50: Complete core loading of WarFoundry XML files * Start loading of UnitEquipmentItems * Fix XPath queries for equipment items and abilities * Allow UnitEquipmentItem to be created without a UnitType * Make adding UnitEquipmentItem to UnitType set UnitType of UnitEquipmentItem * Make loading of abilities and equipment items add the item to the race Also: * Code cleanup (line endings) * Make method to get equipment by ID return null instead of throwing "no such key" exception
author IBBoard <dev@ibboard.co.uk>
date Sat, 01 Aug 2009 16:06:25 +0000
parents 2b977962302a
children 129636305ad7
files api/Factories/Xml/WarFoundryXmlRaceFactory.cs api/Objects/Race.cs api/Objects/Unit.cs api/Objects/UnitEquipmentItem.cs api/Objects/UnitType.cs
diffstat 5 files changed, 55 insertions(+), 20 deletions(-) [+]
line diff
     1.1 --- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs	Sun Jul 05 09:50:40 2009 +0000
     1.2 +++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs	Sat Aug 01 16:06:25 2009 +0000
     1.3 @@ -64,12 +64,12 @@
     1.4  				CreateCategoryFromElement(node, race);
     1.5  			}
     1.6  							
     1.7 -			foreach (XmlElement node  in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:equipment/cat:equipmentItem"))
     1.8 +			foreach (XmlElement node  in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:equipment/race:equipmentItem"))
     1.9  			{
    1.10  				CreateEquipmentItemFromElement(node, race);
    1.11  			}
    1.12  							
    1.13 -			foreach (XmlElement node  in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:abilities/cat:ability"))
    1.14 +			foreach (XmlElement node  in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:abilities/race:ability"))
    1.15  			{
    1.16  				CreateAbilityFromElement(node, race);
    1.17  			}
    1.18 @@ -148,6 +148,32 @@
    1.19  
    1.20  		private void LoadEquipmentForUnitType(XmlElement elem, UnitType type)
    1.21  		{
    1.22 +			foreach (XmlElement equip in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitEquipment/race:unitEquipmentItem"))
    1.23 +			{
    1.24 +													/*	<xs:attribute name="id" type="xs:IDREF" />
    1.25 +														<xs:attribute name="required" type="xs:boolean" default="false"/>
    1.26 +														<xs:attribute name="exclusivityGroup" type="xs:string" default=""/>
    1.27 +														<xs:attribute name="minNum" type="core:nonNegativeOrInfiniteInteger" default="-1"/>
    1.28 +														<xs:attribute name="maxNum" type="core:nonNegativeOrInfiniteInteger" default="-1"/>
    1.29 +														<xs:attribute name="minPercentage" type="core:percentage" default="100"/>
    1.30 +														<xs:attribute name="maxPercentage" type="core:percentage" default="100"/>
    1.31 +														<xs:attribute name="roundDirection" type="updowntype" default="up"/>
    1.32 +														<xs:attribute name="costMultiplier" type="core:nonNegativeDouble" default="1"/>
    1.33 +														<xs:attribute name="costRounding" type="costroundingtype" default="UpToHalf"/>*/
    1.34 +				string id = equip.GetAttribute("id");
    1.35 +				EquipmentItem equipItem = type.Race.GetEquipmentItem(id);
    1.36 +				
    1.37 +				if (equipItem!=null)
    1.38 +				{
    1.39 +					UnitEquipmentItem unitEquipItem = new UnitEquipmentItem(equipItem);
    1.40 +					type.AddEquipmentItem(unitEquipItem);
    1.41 +				}
    1.42 +				else
    1.43 +				{
    1.44 +					//TODO: Warn about missing item	
    1.45 +				}
    1.46 +			}
    1.47 +				
    1.48  		}
    1.49  		
    1.50  		private void LoadAbilitiesForUnitType(XmlElement elem, UnitType type)
    1.51 @@ -227,7 +253,7 @@
    1.52  			string id = elem.GetAttribute("id");
    1.53  			EquipmentItem item = race.GetEquipmentItem(id);
    1.54  
    1.55 -			if (item==null)
    1.56 +			if (item == null)
    1.57  			{
    1.58  				item = CreateEquipmentItemFromElement(elem, id, race);
    1.59  			}
    1.60 @@ -263,7 +289,7 @@
    1.61  			//TODO: Parse equipment stats if there are any
    1.62  			item.Cost = cost;
    1.63  			item.ItemArmourType = armourType;
    1.64 -			
    1.65 +			race.AddEquipmentItem(item);			
    1.66  			return item;
    1.67  		}
    1.68  		
    1.69 @@ -274,6 +300,7 @@
    1.70  			Ability ability = new Ability(id, name);
    1.71  			XmlNode node = elem.SelectSingleNode("description", WarFoundryXmlFactoryUtils.GetNamespaceManager());
    1.72  			ability.Description = (node == null) ? "" : node.InnerText;
    1.73 +			race.AddAbility(ability);
    1.74  			return ability;
    1.75  		}
    1.76  	}
     2.1 --- a/api/Objects/Race.cs	Sun Jul 05 09:50:40 2009 +0000
     2.2 +++ b/api/Objects/Race.cs	Sat Aug 01 16:06:25 2009 +0000
     2.3 @@ -131,10 +131,10 @@
     2.4  			}
     2.5  		}
     2.6  
     2.7 -		public  EquipmentItem GetEquipmentItem(string id)
     2.8 +		public EquipmentItem GetEquipmentItem(string id)
     2.9  		{
    2.10  			EnsureFullyLoaded();
    2.11 -			return (EquipmentItem)equipment[id];
    2.12 +			return DictionaryUtils.GetValue(equipment, id);
    2.13  		}
    2.14  		
    2.15  		public List<EquipmentItem> GetEquipmentList()
     3.1 --- a/api/Objects/Unit.cs	Sun Jul 05 09:50:40 2009 +0000
     3.2 +++ b/api/Objects/Unit.cs	Sat Aug 01 16:06:25 2009 +0000
     3.3 @@ -24,12 +24,12 @@
     3.4  		private List<Unit> containedUnits = new List<Unit>();
     3.5  		public event DoubleValChangedDelegate PointsValueChanged;
     3.6  		public event IntValChangedDelegate UnitSizeChanged;
     3.7 -		public event DoubleValChangedDelegate UnitEquipmentAmountChanged;
     3.8 -
     3.9 -		public Unit(UnitType unitType, ArmyCategory parentArmyCat) : this(unitType, unitType.MinSize, parentArmyCat) { }
    3.10 -
    3.11 +		public event DoubleValChangedDelegate UnitEquipmentAmountChanged;
    3.12 +
    3.13 +		public Unit(UnitType unitType, ArmyCategory parentArmyCat) : this(unitType, unitType.MinSize, parentArmyCat) { }
    3.14 +
    3.15  		public Unit(UnitType unitType, int startSize, ArmyCategory parentArmyCat)
    3.16 -		{
    3.17 +		{
    3.18  			Category = parentArmyCat;
    3.19  			type = unitType;
    3.20  			Size = startSize;
    3.21 @@ -151,10 +151,10 @@
    3.22  		}
    3.23  
    3.24  		public ArmyCategory Category
    3.25 -		{
    3.26 -			get
    3.27 -			{
    3.28 -				return cat;
    3.29 +		{
    3.30 +			get
    3.31 +			{
    3.32 +				return cat;
    3.33  			}
    3.34  			set { cat = value; }
    3.35  		}
     4.1 --- a/api/Objects/UnitEquipmentItem.cs	Sun Jul 05 09:50:40 2009 +0000
     4.2 +++ b/api/Objects/UnitEquipmentItem.cs	Sat Aug 01 16:06:25 2009 +0000
     4.3 @@ -25,10 +25,9 @@
     4.4  		private string mutexGroup;
     4.5  		private UnitType unitType;
     4.6  
     4.7 -		protected UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipForType)
     4.8 +		public UnitEquipmentItem(EquipmentItem equipmentItem)
     4.9  		{
    4.10  			item = equipmentItem;
    4.11 -			EquipmentForUnit = equipForType;
    4.12  		}
    4.13  		
    4.14  		public override string Name
    4.15 @@ -98,6 +97,7 @@
    4.16  				if (value != null)
    4.17  				{
    4.18  					unitType = value;
    4.19 +					unitType.AddEquipmentItem(this);
    4.20  				}
    4.21  			}
    4.22  		}
    4.23 @@ -175,6 +175,10 @@
    4.24  			{
    4.25  				return false;
    4.26  			}
    4.27 +			else if (EquipmentForUnit == null)
    4.28 +			{
    4.29 +				return false;
    4.30 +			}
    4.31  			else
    4.32  			{
    4.33  				//If the number of items in the MutEx group is greater than one then it must be this item plus another
     5.1 --- a/api/Objects/UnitType.cs	Sun Jul 05 09:50:40 2009 +0000
     5.2 +++ b/api/Objects/UnitType.cs	Sat Aug 01 16:06:25 2009 +0000
     5.3 @@ -229,9 +229,13 @@
     5.4  		
     5.5  		public void AddEquipmentItem(UnitEquipmentItem item)
     5.6  		{
     5.7 -			equipment.Add(item.ID, item);
     5.8 -			equipmentKeyOrder.Add(item.ID);
     5.9 -			AddToMutexGroup(item);
    5.10 +			if (!equipment.ContainsKey(item.ID))
    5.11 +			{
    5.12 +				equipment.Add(item.ID, item);
    5.13 +				equipmentKeyOrder.Add(item.ID);
    5.14 +				AddToMutexGroup(item);
    5.15 +				item.EquipmentForUnit = this;
    5.16 +			}
    5.17  		}
    5.18  		
    5.19  		private void AddToMutexGroup(UnitEquipmentItem item)