# HG changeset patch # User IBBoard # Date 1239115384 0 # Node ID e0ce5578e7c2a40bfc3cad16bb6fd6a0429bfb97 # Parent 9561ef46c6fb47284b821236d035dabca0332e1a Re #61 - Complete structure of WarFoundry API objects * Add methods for adding and getting Notes and contained UnitTypes of a UnitType * Add method to get requirements of a unit * Separate out required abilities from optional abilities * Remove UnitAbility and handle by passing a boolean to the AddAbility method diff -r 9561ef46c6fb -r e0ce5578e7c2 IBBoard.WarFoundry.API.csproj --- a/IBBoard.WarFoundry.API.csproj Sun Apr 05 19:57:32 2009 +0000 +++ b/IBBoard.WarFoundry.API.csproj Tue Apr 07 14:43:04 2009 +0000 @@ -124,7 +124,6 @@ - diff -r 9561ef46c6fb -r e0ce5578e7c2 api/Objects/UnitAbility.cs --- a/api/Objects/UnitAbility.cs Sun Apr 05 19:57:32 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -// This file (UnitAbility.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard -// -// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. -// - -using System; - -namespace IBBoard.WarFoundry.API.Objects -{ - public class UnitAbility : WarFoundryObject - { - private Ability ability; - private bool isRequired; - - public UnitAbility(Ability ability) - { - this.ability = ability; - } - - public Ability Ability - { - get { return ability; } - } - - public bool IsRequired - { - get { return isRequired; } - set { isRequired = value; } - } - - public override int GetHashCode () - { - return typeof(UnitAbility).GetHashCode() + ability.GetHashCode(); - } - - public override bool Equals (object obj) - { - bool equal = true; - - if (obj == this) - { - equal = true; - } - else if (obj != null && GetType().Equals(obj.GetType())) - { - UnitAbility other = (UnitAbility)obj; - - if (!Ability.Equals(other.Ability)) - { - equal = false; - } - else if (IsRequired != other.IsRequired) - { - equal = false; - } - } - else - { - equal = false; - } - - return equal; - } - - - } -} diff -r 9561ef46c6fb -r e0ce5578e7c2 api/Objects/UnitType.cs --- a/api/Objects/UnitType.cs Sun Apr 05 19:57:32 2009 +0000 +++ b/api/Objects/UnitType.cs Tue Apr 07 14:43:04 2009 +0000 @@ -26,7 +26,10 @@ private Dictionary equipment = new Dictionary(); private Dictionary> equipmentExclusionGroups = new Dictionary>(); private List equipmentKeyOrder = new List(); - private Dictionary abilities = new Dictionary(); + private Dictionary requiredAbilities = new Dictionary(); + private Dictionary optionalAbilities = new Dictionary(); + private List notes = new List(); + private List containedTypes = new List(); public UnitType(string id, string typeName, Race parentRace) : base(id, typeName) @@ -251,71 +254,59 @@ /// public UnitEquipmentItem[] GetEquipmentItems() { - UnitEquipmentItem[] items = new UnitEquipmentItem[equipment.Count]; - int i = 0; - - foreach (string itemID in equipmentKeyOrder) - { - items[i++] = equipment[itemID]; - } - - return items; + return DictionaryUtils.ToArray(equipment); } - - public ICollection GetAbilities() + + public UnitEquipmentItem[] GetEquipmentItemsByExclusionGroup(string group) { - ICollection abilitiesList = new List(); - - foreach (UnitAbility ability in abilities.Values) + List list = null; + equipmentExclusionGroups.TryGetValue(group, out list); + + if (list == null) { - abilitiesList.Add(ability.Ability); + return new UnitEquipmentItem[0]; } - - return abilitiesList; + else + { + return list.ToArray(); + } } public ICollection GetRequiredAbilities() { - ICollection requiredAbilities = new List(); - - foreach (UnitAbility ability in abilities.Values) - { - if (ability.IsRequired) - { - requiredAbilities.Add(ability.Ability); - } - } - - return requiredAbilities; + return requiredAbilities.Values; } public ICollection GetOptionalAbilities() { - ICollection optionalAbilities = new List(); - - foreach (UnitAbility ability in abilities.Values) - { - if (!ability.IsRequired) - { - optionalAbilities.Add(ability.Ability); - } - } - - return optionalAbilities; + return optionalAbilities.Values; } - public void AddAbility(Ability ability) - { - if (!abilities.ContainsKey(ability.ID)) - { - UnitAbility unitAbility = new UnitAbility(ability); - abilities[ability.ID] = unitAbility; + public void AddAbility(Ability ability, bool isRequired) + { + string id = ability.ID; + + if (!requiredAbilities.ContainsKey(id) && !optionalAbilities.ContainsKey(id)) + { + if (isRequired) + { + requiredAbilities[id] = ability; + } + else + { + optionalAbilities[id] = ability; + } } } public void AddRequirement(UnitRequirement requirement) { requirements.Add(requirement); + } + + public UnitRequirement[] Requirements + { + get { return requirements.ToArray(); } } public List CanAddToArmy(Army army) @@ -356,21 +347,26 @@ } return failures; - } - - public UnitEquipmentItem[] GetEquipmentItemsByExclusionGroup(string group) - { - List list = null; - equipmentExclusionGroups.TryGetValue(group, out list); - - if (list == null) - { - return new UnitEquipmentItem[0]; - } - else - { - return list.ToArray(); - } + } + + public string[] Notes + { + get { return notes.ToArray(); } + } + + public void AddNote(string note) + { + notes.Add(note); + } + + public UnitType[] ContainedUnitTypes + { + get { return containedTypes.ToArray(); } + } + + public void AddContainedUnitType(UnitType containedType) + { + containedTypes.Add(containedType); } } }