annotate API/Objects/Race.cs @ 430:7e95b880f9cc

Re #356: Stack overflow with certain equipment limits * Set sensible default equipment cost multiplier
author IBBoard <dev@ibboard.co.uk>
date Sun, 06 Nov 2011 20:44:53 +0000
parents 71fceea2725b
children 95c1b68a600b
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
419
71fceea2725b Code tidy-up - remove warnings
IBBoard <dev@ibboard.co.uk>
parents: 357
diff changeset
63 public override int GetHashCode()
71fceea2725b Code tidy-up - remove warnings
IBBoard <dev@ibboard.co.uk>
parents: 357
diff changeset
64 {
71fceea2725b Code tidy-up - remove warnings
IBBoard <dev@ibboard.co.uk>
parents: 357
diff changeset
65 return ID.GetHashCode() + SubID.GetHashCode() + GameSystem.GetHashCode() + ArmyDefaultName.GetHashCode();
71fceea2725b Code tidy-up - remove warnings
IBBoard <dev@ibboard.co.uk>
parents: 357
diff changeset
66 }
71fceea2725b Code tidy-up - remove warnings
IBBoard <dev@ibboard.co.uk>
parents: 357
diff changeset
67
357
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
68 public string SubID
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
69 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
70 get { return subID; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
71 set { subID = (value == null ? "" : value.Trim()); }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
72 }
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 public GameSystem GameSystem
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 get { return system; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
77 set
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 if (value == null)
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 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
82 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
83
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
84 system = value;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
85 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
86 }
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 public string ArmyDefaultName
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 get { return defaultArmyName; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
91 set
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 if (value == null)
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 throw new ArgumentException("No default army name");
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
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
98 defaultArmyName = value;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
99 }
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 public void AddCategory(Category cat)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
103 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
104 categories[cat.ID] = cat;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
105 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
106
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
107 /// <summary>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
108 /// 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
109 /// </summary>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
110 /// <param name="id">
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
111 /// The ID of the category to get
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
112 /// </param>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
113 /// <returns>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
114 /// 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
115 /// </returns>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
116 public Category GetCategory(string id)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
117 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
118 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
119 Category cat = null;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
120 categories.TryGetValue(id, out cat);
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 if (cat == null)
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 cat = GameSystem.GetCategory(id);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
125 }
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 return cat;
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
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
130 public Category[] Categories
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 get
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 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
135 Category[] cats;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
136
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
137 if (!HasCategoryOverrides())
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
138 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
139 cats = GameSystem.Categories;
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 else
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 cats = DictionaryUtils.ToArray<string, Category>(categories);
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
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
146 return cats;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
147 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
148 }
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 public bool HasCategoryOverrides()
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
151 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
152 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
153 return categories.Count > 0;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
154 }
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 public void AddEquipmentItem(EquipmentItem item)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
157 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
158 //TODO: Throw DuplicateItemException
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
159 equipment.Add(item.ID, item);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
160 }
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 public EquipmentItem GetEquipmentItem(string id)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
163 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
164 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
165 return DictionaryUtils.GetValue(equipment, id);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
166 }
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 public List<EquipmentItem> GetEquipmentList()
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 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
171 List<EquipmentItem> items = new List<EquipmentItem>();
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 foreach (EquipmentItem item in equipment.Values)
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 items.Add(item);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
176 }
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 return items;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
179 }
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 public void AddUnitType(UnitType type)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
182 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
183 CacheUnitType(type);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
184 unitTypes.Add(type.ID, type);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
185 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
186
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
187 public UnitType[] GetUnitTypes(Category cat)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
188 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
189 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
190 BuildUnitTypesByCategoryCache();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
191 Dictionary<string, UnitType> unitTypesDictionary;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
192 unitTypesByCat.TryGetValue(cat, out unitTypesDictionary);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
193 UnitType[] unitTypesArray;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
194
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
195 if (unitTypesDictionary == null)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
196 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
197 unitTypesArray = new UnitType[0];
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 else
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 unitTypesArray = DictionaryUtils.ToArray<string, UnitType>(unitTypesDictionary);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
202 }
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 return unitTypesArray;
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
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
207 private void CacheUnitType(UnitType unit)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
208 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
209 BuildUnitTypesByCategoryCache();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
210
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
211 foreach (Category cat in unit.Categories)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
212 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
213 Dictionary<string, UnitType> catUnitTypes = DictionaryUtils.GetValue(unitTypesByCat, cat);
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 if (catUnitTypes == null)
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 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
218 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
219
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
220 catUnitTypes.Add(unit.ID, unit);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
221 }
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
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
224 private void BuildUnitTypesByCategoryCache()
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 if (unitTypesByCat == null)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
227 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
228 DoBuildUnitTypesByCategoryCache();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
229 }
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
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
232 private void DoBuildUnitTypesByCategoryCache()
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
233 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
234 unitTypesByCat = new Dictionary<Category,Dictionary<string,UnitType>>();
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 (Category category in Categories)
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 unitTypesByCat.Add(category, new Dictionary<string, UnitType>());
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 foreach (UnitType unit in unitTypes.Values)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
242 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
243 CacheUnitType(unit);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
244 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
245 }
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 public UnitType GetUnitType(string id)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
248 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
249 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
250 return DictionaryUtils.GetValue(unitTypes, id);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
251 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
252
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
253 public List<Ability> GetAbilityList()
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 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
256 List<Ability> items = new List<Ability>();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
257 items.AddRange(abilities.Values);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
258 return items;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
259 }
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 public void AddAbility(Ability newAbility)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
262 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
263 //TODO: Throw DuplicateItemException
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
264 abilities.Add(newAbility.ID, newAbility);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
265 }
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 public Ability GetAbility(string id)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
268 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
269 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
270 return DictionaryUtils.GetValue(abilities, id);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
271 }
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 protected virtual Dictionary<string, UnitType> RaceUnitTypes
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
274 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
275 get { return RaceRawUnitTypes; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
276 set { RaceRawUnitTypes = value; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
277 }
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 protected virtual Dictionary<string, EquipmentItem> RaceEquipment
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
280 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
281 get { return RaceRawEquipment; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
282 set { RaceRawEquipment = value; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
283 }
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 protected virtual Dictionary<string, Ability> RaceAbilities
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
286 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
287 get { return RaceRawAbilities; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
288 set { RaceRawAbilities = value; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
289 }
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 protected Dictionary<string, UnitType> RaceRawUnitTypes
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
292 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
293 get { return unitTypes; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
294 set { unitTypes = value; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
295 }
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 protected Dictionary<string, EquipmentItem> RaceRawEquipment
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
298 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
299 get { return equipment; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
300 set { equipment = value; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
301 }
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 protected Dictionary<string, Ability> RaceRawAbilities
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
304 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
305 get { return abilities; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
306 set { abilities = value; }
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 public void AddUnitMemberType(UnitMemberType memberType)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
310 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
311 memberTypes[memberType.ID] = memberType;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
312 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
313
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
314 /// <summary>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
315 /// Gets a unit member type by its ID.
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
316 /// </summary>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
317 /// <param name="id">
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
318 /// The ID of the unit member type to get
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
319 /// </param>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
320 /// <returns>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
321 /// 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
322 /// </returns>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
323 public UnitMemberType GetUnitMemberType(string id)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
324 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
325 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
326 return DictionaryUtils.GetValue(memberTypes, id);
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
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
329 public UnitMemberType[] UnitMemberTypes
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 get
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 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
334 return DictionaryUtils.ToArray(memberTypes);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
335 }
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
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
338 public ICollection<IRequirement> GetRequirements()
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
339 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
340 ICollection<IRequirement> reqs = new List<IRequirement>();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
341
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
342 foreach (UnitType unitType in unitTypes.Values)
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 foreach (IRequirement requirement in unitType.GetRequirements())
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
345 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
346 reqs.Add(requirement);
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 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
349
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
350 return reqs;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
351 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
352 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
353 }