annotate api/Objects/Race.cs @ 38:548cfc776f54

Fixes #34 - Remove "Choices" and "Base/Increment" from Category * Remove Choices and Base/Increment from code Re #47: Remove magic numbers * Replace "-1" magic number with WarFoundryCore.INFINITY * Use INFINITY instead of -1 in code * Use INF in schemas instead of -1 * Handle and parse INF as a special value in XML Factory
author IBBoard <dev@ibboard.co.uk>
date Thu, 19 Mar 2009 20:11:07 +0000
parents 306558904c2a
children 85f2b9c3609c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
306558904c2a Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
1 // This file (Race.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard.
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
15
306558904c2a Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System.Collections.Generic;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using System.IO;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using System.Xml;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 using IBBoard.IO;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 using IBBoard.WarFoundry.API.Factories;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 namespace IBBoard.WarFoundry.API.Objects
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 {
8
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
14 public class Race : WarFoundryStagedLoadingObject
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 public static string SYSTEM_DEFAULT_RACE_ID = "GameDefault";
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 private string subID;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 private string systemID;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 private GameSystem system;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 private Dictionary<Category, Dictionary<string, UnitType>> unitTypesByCat;
8
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
22 private Dictionary<string, UnitType> unitTypes = new Dictionary<string,UnitType>();
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
23 private Dictionary<string, EquipmentItem> equipment = new Dictionary<string,EquipmentItem>();
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
24 private Dictionary<string, Ability> abilities = new Dictionary<string,Ability>();
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
25 private Dictionary<string, Category> categories = new Dictionary<string,Category>();
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26
8
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
27 public Race(string raceID, string raceName, string gameSystemID, IWarFoundryFactory creatingFactory) : this(raceID, "", raceName, gameSystemID, creatingFactory)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30
8
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
31 public Race(string raceID, string raceSubID, string raceName, string gameSystemID, IWarFoundryFactory creatingFactory) : base(raceID + (raceSubID!="" ? "_"+raceSubID : ""), raceName, creatingFactory)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 subID = (raceSubID == null ? "" : raceSubID);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 systemID = gameSystemID;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 public string SubID
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 get { return subID; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 set { subID = (value == null ? "" : value.Trim()); }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 public GameSystem GameSystem
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 get
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 if (system == null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 system = WarFoundryLoader.GetDefault().GetGameSystem(systemID);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 return system;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 set
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 if (value == null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 throw new ArgumentException("Game system for a race cannot be null");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 system = value;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 }
8
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
63 }
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
64
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
65 public void AddCategory(Category cat)
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
66 {
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
67 categories[cat.ID] = cat;
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 /// 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.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 /// <param name="id">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 /// The ID of the category to get
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 /// The <code>Category</code> with the specified ID, or null if one doesn't exist.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78 /// </returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 public Category GetCategory(string id)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 {
8
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
81 EnsureFullyLoaded();
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 Category cat = null;
8
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
83 categories.TryGetValue(id, out cat);
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
84
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
85 if (cat == null)
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
86 {
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
87 cat = GameSystem.GetCategory(id);
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
88 }
8
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
89
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90 return cat;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93 public Category[] Categories
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 get
8
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
96 {
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
97 EnsureFullyLoaded();
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
98 Category[] cats;
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
99
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
100 if (!HasCategoryOverrides())
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
101 {
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
102 cats = GameSystem.Categories;
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
103 }
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
104 else
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
105 {
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
106 cats = DictionaryUtils.ToArray<string, Category>(categories);
8
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
107 }
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
108
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
109 return cats;
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
110 }
8
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
111 }
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
112
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
113 public bool HasCategoryOverrides()
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
114 {
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
115 return categories.Count > 0;
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
116 }
11
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
117
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
118 public void AddEquipmentItem(EquipmentItem item)
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
119 {
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
120 //TODO: Throw DuplicateItemException
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
121 equipment.Add(item.ID, item);
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
122 }
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
123
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
124 [Obsolete("Use AddEquipmentItem method instead")]
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
125 public void SetEquipmentItems(Dictionary<string, EquipmentItem> items)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
126 {
11
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
127 foreach (EquipmentItem item in items.Values)
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
128 {
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
129 AddEquipmentItem(item);
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
130 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
131 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
132
8
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
133 public EquipmentItem GetEquipmentItem(string id)
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
134 {
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
135 EnsureFullyLoaded();
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
136 return (EquipmentItem)equipment[id];
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
137 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
138
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
139 public List<EquipmentItem> GetEquipmentList()
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
140 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
141 List<EquipmentItem> items = new List<EquipmentItem>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
142
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
143 foreach (EquipmentItem item in equipment.Values)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
144 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
145 items.Add(item);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
146 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
147
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
148 return items;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
149 }
11
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
150
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
151 public void AddUnitType(UnitType type)
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
152 {
13
ad8eaed12e66 Re #9 - Load in smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
153 CacheUnitType(type);
11
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
154 unitTypes.Add(type.ID, type);
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
155 }
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
156
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
157 [Obsolete("Use AddUnitType method instead")]
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
158 public void SetUnitTypes(Dictionary<string, UnitType> types)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
159 {
11
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
160 foreach (UnitType type in types.Values)
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
161 {
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
162 AddUnitType(type);
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
163 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
164 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
165
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
166 public UnitType[] GetUnitTypes(Category cat)
11
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
167 {
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
168 BuildUnitTypesByCategoryCache();
8
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
169 Dictionary<string, UnitType> unitTypesDictionary;
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
170 unitTypesByCat.TryGetValue(cat, out unitTypesDictionary);
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
171 UnitType[] unitTypesArray;
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
172
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
173 if (unitTypesDictionary == null)
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
174 {
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
175 unitTypesArray = new UnitType[0];
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
176 }
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
177 else
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
178 {
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
179 unitTypesArray = DictionaryUtils.ToArray<string, UnitType>(unitTypesDictionary);
8
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
180 }
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
181
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
182 return unitTypesArray;
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
183 }
11
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
184
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
185 private void CacheUnitType(UnitType unit)
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
186 {
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
187 BuildUnitTypesByCategoryCache();
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
188 Dictionary<string,UnitType> catUnitTypes;
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
189 unitTypesByCat.TryGetValue(unit.MainCategory, out catUnitTypes);
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
190
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
191 if (catUnitTypes == null)
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
192 {
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
193 throw new InvalidFileException(String.Format("Unit type {0} with name {1} is a unit of an undefined category", unit.ID, unit.Name));
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
194 }
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
195
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
196 catUnitTypes.Add(unit.ID, unit);
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
197 }
8
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
198
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
199 private void BuildUnitTypesByCategoryCache()
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
200 {
11
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
201 if (unitTypesByCat == null)
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
202 {
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
203 DoBuildUnitTypesByCategoryCache();
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
204 }
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
205 }
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
206
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
207 private void DoBuildUnitTypesByCategoryCache()
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
208 {
8
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
209 unitTypesByCat = new Dictionary<Category,Dictionary<string,UnitType>>();
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
210
11
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
211 foreach (Category category in Categories)
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
212 {
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
213 unitTypesByCat.Add(category, new Dictionary<string, UnitType>());
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
214 }
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
215
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
216 foreach (UnitType unit in unitTypes.Values)
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
217 {
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
218 CacheUnitType(unit);
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
219 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
220 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
221
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
222 public UnitType GetUnitType(string id)
11
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
223 {
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
224 UnitType type = null;
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
225 unitTypes.TryGetValue(id, out type);
5a1df00b0359 Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
226 return type;
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
227 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
228
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
229 public List<Ability> GetAbilityList()
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
230 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
231 List<Ability> items = new List<Ability>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
232
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
233 foreach (Ability ability in abilities.Values)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
234 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
235 items.Add(ability);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
236 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
237
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
238 return items;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
239 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
240
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
241 public void SetAbilities(Dictionary<string, Ability> newAbilities)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
242 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
243 abilities = newAbilities;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
244 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
245
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
246 public Ability GetAbility(string id)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
247 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
248 Ability ability = null;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
249 abilities.TryGetValue(id, out ability);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
250 return ability;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
251 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
252
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
253 protected virtual Dictionary<string, UnitType> RaceUnitTypes
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
254 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
255 get { return RaceRawUnitTypes; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
256 set { RaceRawUnitTypes = value; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
257 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
258
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
259 protected virtual Dictionary<string, EquipmentItem> RaceEquipment
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
260 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
261 get { return RaceRawEquipment; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
262 set { RaceRawEquipment = value; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
263 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
264
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
265 protected virtual Dictionary<string, Ability> RaceAbilities
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
266 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
267 get { return RaceRawAbilities; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
268 set { RaceRawAbilities = value; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
269 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
270
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
271 protected Dictionary<string, UnitType> RaceRawUnitTypes
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
272 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
273 get { return unitTypes; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
274 set { unitTypes = value; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
275 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
276
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
277 protected Dictionary<string, EquipmentItem> RaceRawEquipment
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
278 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
279 get { return equipment; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
280 set { equipment = value; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
281 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
282
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
283 protected Dictionary<string, Ability> RaceRawAbilities
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
284 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
285 get { return abilities; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
286 set { abilities = value; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
287 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
288 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
289 }