annotate API/Objects/Race.cs @ 357:50d0d3b39a0b

Re #140: Add equality methods * Add equality method for RequiresAtLeastNUnitsRequirement * Update equality method on GameSystem and No More Than limit to use new helper class * Add equality methods on Race and UnitType as a dependent of equality of requirements
author IBBoard <dev@ibboard.co.uk>
date Tue, 26 Apr 2011 19:19:08 +0000
parents 12a56786120c
children 71fceea2725b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
357
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
1 // This file (Race.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard.
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
2 //
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
4 using System;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
5 using System.Collections.Generic;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
6 using System.IO;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
7 using System.Xml;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
8 using IBBoard.IO;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
9 using IBBoard.WarFoundry.API.Factories;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
10 using IBBoard.WarFoundry.API.Objects.Requirement;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
11
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
12 namespace IBBoard.WarFoundry.API.Objects
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
13 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
14 public class Race : WarFoundryStagedLoadingObject
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
15 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
16 public static string SYSTEM_DEFAULT_RACE_ID = "GameDefault";
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
17
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
18 private string subID;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
19 private GameSystem system;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
20 private string defaultArmyName = "";
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
21 private Dictionary<Category, Dictionary<string, UnitType>> unitTypesByCat;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
22 private Dictionary<string, UnitType> unitTypes = new Dictionary<string,UnitType>();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
23 private Dictionary<string, EquipmentItem> equipment = new Dictionary<string,EquipmentItem>();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
24 private Dictionary<string, Ability> abilities = new Dictionary<string,Ability>();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
25 private Dictionary<string, Category> categories = new Dictionary<string,Category>();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
26 private Dictionary<string, UnitMemberType> memberTypes = new Dictionary<string, UnitMemberType>();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
27
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
28 public Race(string raceID, string raceName, GameSystem gameSystem, IWarFoundryFactory creatingFactory) : this(raceID, "", raceName, gameSystem, creatingFactory)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
29 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
30 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
31
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
32 public Race(string raceID, string raceSubID, string raceName, GameSystem gameSystem, IWarFoundryFactory creatingFactory) : base(raceID + (raceSubID != "" ? "_" + raceSubID : ""), raceName, creatingFactory)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
33 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
34 subID = (raceSubID == null ? "" : raceSubID);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
35 system = gameSystem;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
36 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
37
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
38 public override bool Equals (object obj)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
39 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
40 if (obj == null)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
41 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
42 return false;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
43 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
44 else if (!(obj is Race))
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
45 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
46 return false;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
47 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
48 else
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
49 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
50 Race other = (Race)obj;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
51
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
52 if (!ID.Equals(other.ID) || !SubID.Equals(other.SubID) || !GameSystem.Equals(other.GameSystem))
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
53 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
54 return false;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
55 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
56 else
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
57 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
58 return true;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
59 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
60 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
61 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
62
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
63 public string SubID
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
64 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
65 get { return subID; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
66 set { subID = (value == null ? "" : value.Trim()); }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
67 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
68
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
69 public GameSystem GameSystem
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
70 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
71 get { return system; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
72 set
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
73 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
74 if (value == null)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
75 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
76 throw new ArgumentException("Game system for a race cannot be null");
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
77 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
78
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
79 system = value;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
80 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
81 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
82
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
83 public string ArmyDefaultName
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
84 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
85 get { return defaultArmyName; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
86 set
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
87 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
88 if (value == null)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
89 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
90 throw new ArgumentException("No default army name");
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
91 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
92
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
93 defaultArmyName = value;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
94 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
95 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
96
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
97 public void AddCategory(Category cat)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
98 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
99 categories[cat.ID] = cat;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
100 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
101
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
102 /// <summary>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
103 /// Gets a category from its ID. Attempts to get the category from the race's overrides, or else it falls back to getting the Game System's category with that ID.
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
104 /// </summary>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
105 /// <param name="id">
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
106 /// The ID of the category to get
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
107 /// </param>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
108 /// <returns>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
109 /// The <code>Category</code> with the specified ID, or null if one doesn't exist.
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
110 /// </returns>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
111 public Category GetCategory(string id)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
112 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
113 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
114 Category cat = null;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
115 categories.TryGetValue(id, out cat);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
116
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
117 if (cat == null)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
118 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
119 cat = GameSystem.GetCategory(id);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
120 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
121
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
122 return cat;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
123 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
124
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
125 public Category[] Categories
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
126 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
127 get
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
128 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
129 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
130 Category[] cats;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
131
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
132 if (!HasCategoryOverrides())
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
133 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
134 cats = GameSystem.Categories;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
135 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
136 else
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
137 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
138 cats = DictionaryUtils.ToArray<string, Category>(categories);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
139 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
140
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
141 return cats;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
142 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
143 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
144
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
145 public bool HasCategoryOverrides()
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
146 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
147 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
148 return categories.Count > 0;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
149 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
150
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
151 public void AddEquipmentItem(EquipmentItem item)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
152 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
153 //TODO: Throw DuplicateItemException
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
154 equipment.Add(item.ID, item);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
155 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
156
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
157 public EquipmentItem GetEquipmentItem(string id)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
158 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
159 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
160 return DictionaryUtils.GetValue(equipment, id);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
161 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
162
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
163 public List<EquipmentItem> GetEquipmentList()
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
164 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
165 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
166 List<EquipmentItem> items = new List<EquipmentItem>();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
167
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
168 foreach (EquipmentItem item in equipment.Values)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
169 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
170 items.Add(item);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
171 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
172
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
173 return items;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
174 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
175
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
176 public void AddUnitType(UnitType type)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
177 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
178 CacheUnitType(type);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
179 unitTypes.Add(type.ID, type);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
180 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
181
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
182 public UnitType[] GetUnitTypes(Category cat)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
183 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
184 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
185 BuildUnitTypesByCategoryCache();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
186 Dictionary<string, UnitType> unitTypesDictionary;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
187 unitTypesByCat.TryGetValue(cat, out unitTypesDictionary);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
188 UnitType[] unitTypesArray;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
189
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
190 if (unitTypesDictionary == null)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
191 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
192 unitTypesArray = new UnitType[0];
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
193 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
194 else
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
195 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
196 unitTypesArray = DictionaryUtils.ToArray<string, UnitType>(unitTypesDictionary);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
197 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
198
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
199 return unitTypesArray;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
200 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
201
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
202 private void CacheUnitType(UnitType unit)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
203 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
204 BuildUnitTypesByCategoryCache();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
205
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
206 foreach (Category cat in unit.Categories)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
207 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
208 Dictionary<string, UnitType> catUnitTypes = DictionaryUtils.GetValue(unitTypesByCat, cat);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
209
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
210 if (catUnitTypes == null)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
211 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
212 throw new InvalidFileException(String.Format("Unit type {0} with name {1} is a unit of an undefined category ({2})", unit.ID, unit.Name, cat.ID));
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
213 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
214
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
215 catUnitTypes.Add(unit.ID, unit);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
216 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
217 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
218
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
219 private void BuildUnitTypesByCategoryCache()
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
220 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
221 if (unitTypesByCat == null)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
222 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
223 DoBuildUnitTypesByCategoryCache();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
224 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
225 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
226
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
227 private void DoBuildUnitTypesByCategoryCache()
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
228 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
229 unitTypesByCat = new Dictionary<Category,Dictionary<string,UnitType>>();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
230
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
231 foreach (Category category in Categories)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
232 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
233 unitTypesByCat.Add(category, new Dictionary<string, UnitType>());
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
234 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
235
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
236 foreach (UnitType unit in unitTypes.Values)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
237 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
238 CacheUnitType(unit);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
239 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
240 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
241
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
242 public UnitType GetUnitType(string id)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
243 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
244 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
245 return DictionaryUtils.GetValue(unitTypes, id);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
246 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
247
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
248 public List<Ability> GetAbilityList()
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
249 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
250 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
251 List<Ability> items = new List<Ability>();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
252 items.AddRange(abilities.Values);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
253 return items;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
254 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
255
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
256 public void AddAbility(Ability newAbility)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
257 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
258 //TODO: Throw DuplicateItemException
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
259 abilities.Add(newAbility.ID, newAbility);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
260 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
261
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
262 public Ability GetAbility(string id)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
263 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
264 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
265 return DictionaryUtils.GetValue(abilities, id);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
266 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
267
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
268 protected virtual Dictionary<string, UnitType> RaceUnitTypes
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
269 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
270 get { return RaceRawUnitTypes; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
271 set { RaceRawUnitTypes = value; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
272 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
273
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
274 protected virtual Dictionary<string, EquipmentItem> RaceEquipment
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
275 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
276 get { return RaceRawEquipment; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
277 set { RaceRawEquipment = value; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
278 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
279
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
280 protected virtual Dictionary<string, Ability> RaceAbilities
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
281 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
282 get { return RaceRawAbilities; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
283 set { RaceRawAbilities = value; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
284 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
285
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
286 protected Dictionary<string, UnitType> RaceRawUnitTypes
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
287 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
288 get { return unitTypes; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
289 set { unitTypes = value; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
290 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
291
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
292 protected Dictionary<string, EquipmentItem> RaceRawEquipment
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
293 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
294 get { return equipment; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
295 set { equipment = value; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
296 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
297
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
298 protected Dictionary<string, Ability> RaceRawAbilities
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
299 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
300 get { return abilities; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
301 set { abilities = value; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
302 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
303
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
304 public void AddUnitMemberType(UnitMemberType memberType)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
305 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
306 memberTypes[memberType.ID] = memberType;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
307 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
308
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
309 /// <summary>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
310 /// Gets a unit member type by its ID.
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
311 /// </summary>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
312 /// <param name="id">
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
313 /// The ID of the unit member type to get
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
314 /// </param>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
315 /// <returns>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
316 /// The <code>UnitMemberType</code> with the specified ID, or null if one doesn't exist.
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
317 /// </returns>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
318 public UnitMemberType GetUnitMemberType(string id)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
319 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
320 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
321 return DictionaryUtils.GetValue(memberTypes, id);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
322 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
323
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
324 public UnitMemberType[] UnitMemberTypes
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
325 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
326 get
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
327 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
328 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
329 return DictionaryUtils.ToArray(memberTypes);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
330 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
331 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
332
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
333 public ICollection<IRequirement> GetRequirements()
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
334 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
335 ICollection<IRequirement> reqs = new List<IRequirement>();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
336
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
337 foreach (UnitType unitType in unitTypes.Values)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
338 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
339 foreach (IRequirement requirement in unitType.GetRequirements())
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
340 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
341 reqs.Add(requirement);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
342 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
343 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
344
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
345 return reqs;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
346 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
347 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
348 }