annotate API/Objects/Race.cs @ 468:95c1b68a600b

Re #359: Add "only contained" attribute to unit types * Exclude "contained only" units from Race's list of available units
author IBBoard <dev@ibboard.co.uk>
date Sat, 14 Apr 2012 16:57:34 +0100
parents 71fceea2725b
children
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 {
468
95c1b68a600b Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
34 subID = raceSubID ?? "";
357
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 {
468
95c1b68a600b Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
209 if (unit.IsContainedOnly)
95c1b68a600b Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
210 {
95c1b68a600b Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
211 return;
95c1b68a600b Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
212 }
95c1b68a600b Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
213
357
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
214 BuildUnitTypesByCategoryCache();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
215
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
216 foreach (Category cat in unit.Categories)
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 Dictionary<string, UnitType> catUnitTypes = DictionaryUtils.GetValue(unitTypesByCat, cat);
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 if (catUnitTypes == null)
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 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
223 }
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 catUnitTypes.Add(unit.ID, unit);
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 }
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 private void BuildUnitTypesByCategoryCache()
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 if (unitTypesByCat == null)
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 DoBuildUnitTypesByCategoryCache();
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
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
237 private void DoBuildUnitTypesByCategoryCache()
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
238 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
239 unitTypesByCat = new Dictionary<Category,Dictionary<string,UnitType>>();
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 (Category category in Categories)
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 unitTypesByCat.Add(category, new Dictionary<string, UnitType>());
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 foreach (UnitType unit in unitTypes.Values)
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 CacheUnitType(unit);
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 }
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 public UnitType GetUnitType(string id)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
253 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
254 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
255 return DictionaryUtils.GetValue(unitTypes, id);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
256 }
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 public List<Ability> GetAbilityList()
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 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
261 List<Ability> items = new List<Ability>();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
262 items.AddRange(abilities.Values);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
263 return items;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
264 }
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 public void AddAbility(Ability newAbility)
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 //TODO: Throw DuplicateItemException
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
269 abilities.Add(newAbility.ID, newAbility);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
270 }
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 public Ability GetAbility(string id)
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 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
275 return DictionaryUtils.GetValue(abilities, id);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
276 }
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 protected virtual Dictionary<string, UnitType> RaceUnitTypes
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 get { return RaceRawUnitTypes; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
281 set { RaceRawUnitTypes = value; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
282 }
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 protected virtual Dictionary<string, EquipmentItem> RaceEquipment
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 get { return RaceRawEquipment; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
287 set { RaceRawEquipment = value; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
288 }
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 protected virtual Dictionary<string, Ability> RaceAbilities
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 get { return RaceRawAbilities; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
293 set { RaceRawAbilities = value; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
294 }
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 protected Dictionary<string, UnitType> RaceRawUnitTypes
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 get { return unitTypes; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
299 set { unitTypes = value; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
300 }
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 protected Dictionary<string, EquipmentItem> RaceRawEquipment
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 get { return equipment; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
305 set { equipment = value; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
306 }
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 protected Dictionary<string, Ability> RaceRawAbilities
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
309 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
310 get { return abilities; }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
311 set { abilities = value; }
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 public void AddUnitMemberType(UnitMemberType memberType)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
315 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
316 memberTypes[memberType.ID] = memberType;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
317 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
318
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
319 /// <summary>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
320 /// Gets a unit member type by its ID.
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
321 /// </summary>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
322 /// <param name="id">
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
323 /// The ID of the unit member type to get
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
324 /// </param>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
325 /// <returns>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
326 /// 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
327 /// </returns>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
328 public UnitMemberType GetUnitMemberType(string id)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
329 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
330 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
331 return DictionaryUtils.GetValue(memberTypes, id);
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
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
334 public UnitMemberType[] UnitMemberTypes
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 get
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 EnsureFullyLoaded();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
339 return DictionaryUtils.ToArray(memberTypes);
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 }
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 public ICollection<IRequirement> GetRequirements()
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 ICollection<IRequirement> reqs = new List<IRequirement>();
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 foreach (UnitType unitType in unitTypes.Values)
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 foreach (IRequirement requirement in unitType.GetRequirements())
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
350 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
351 reqs.Add(requirement);
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 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
354
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
355 return reqs;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
356 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
357 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 349
diff changeset
358 }