Methapolis  0.27
 All Classes Namespaces Files Functions Variables Enumerator
ResearchTree.java
Go to the documentation of this file.
1 package micropolisj.research;
2 
3 import java.io.Serializable;
4 import java.util.HashSet;
5 import java.util.ResourceBundle;
6 
7 import micropolisj.engine.MapState;
8 import micropolisj.engine.MicropolisTool;
9 
10 public class ResearchTree implements Serializable {
11 
12  int rocketNameDecider = 0;
13  int policeNameDecider = 0;
14  int fireNameDecider = 0;
15  int pollNameDecider = 0;
16  int rocketDescDecider = 0;
17  int policeDescDecider = 0;
18  int fireDescDecider = 0;
19  int pollDescDecider = 0;
20 
21  static ResourceBundle strings = ResourceBundle.getBundle("micropolisj.GuiStrings");
22 
23  static ResearchNode[] possible_nodes;
24  static int[][] needed = {
25  {}, {0}, {1},
26  {}, {3}, {4},
27  {}, {6}, {7},
28  {}, {9}, {10}
29  };
30  int height = 2, width = 2;
31  static int[] positionsX = {
32  25, 25, 25
33  , 290, 290, 290
34  , 555, 555, 555
35  , 820, 820, 820
36  };
37 
38  static int[] positionsY = {
39  25, 130, 235
40  , 25, 130, 235
41  , 25, 130, 235
42  , 25, 130, 235
43  };
44 
45  //Set costs here
46  public ResearchTree() {
47  possible_nodes = new ResearchNode[] {
48  new RocketNode(1, 1000), new RocketNode(2, 2500), new RocketNode(3, 5000)
49  , new PoliceNode(1, 150), new PoliceNode(2, 350), new PoliceNode(3, 650)
50  , new FiremanNode(1, 150), new FiremanNode(2, 350), new FiremanNode(3, 650)
51  , new EnvironmentNode(1, 150), new EnvironmentNode(2, 350), new EnvironmentNode(3, 650)
52  };
53  }
54 
55  boolean isReachable(HashSet<Integer> reached_nodes, int node_id) {
56  for(int nid : needed[node_id]) {
57  if(!reached_nodes.contains(nid))
58  return false;
59  }
60  return true;
61 
62  }
63 
64  // INNER CLASSES FOR UPGRADE FEATURES
65  class RocketNode implements ResearchNode {
66 
67  int id=0;
68  int cost=150;
69 
70  public RocketNode(int st, int cost){
71  id = st;
72  this.cost = cost;
73  }
74 
75  @Override
76  public String getName() {
77 
78  switch(rocketNameDecider) {
79  case 0:
80  rocketNameDecider ++;
81  return strings.getString("research.ROCKET_T1_NAME");
82 
83  case 1:
84  rocketNameDecider ++;
85  return strings.getString("research.ROCKET_T2_NAME");
86 
87  case 2:
88  rocketNameDecider = 0;
89  return strings.getString("research.ROCKET_T3_NAME");
90 
91  default:
92  throw new Error("unreachable Research String");
93  }
94  }
95 
96  @Override
97  public String getDesc() {
98 
99  switch(rocketDescDecider) {
100  case 0:
101  rocketDescDecider ++;
102  return strings.getString("research.ROCKET_T1_DESCRIPTION");
103 
104  case 1:
105  rocketDescDecider ++;
106  return strings.getString("research.ROCKET_T2_DESCRIPTION");
107 
108  case 2:
109  rocketDescDecider = 0;
110  return strings.getString("research.ROCKET_T3_DESCRIPTION");
111 
112  default:
113  throw new Error("unreachable Research String");
114  }
115  }
116 
117  @Override
118  public String getIcon() {
119  return "/firestation.png";
120  }
121 
122  @Override
123  public int getCost() {
124  return cost;
125  }
126 
127  // @Override
128  // public int getId(){return 0;}
129 
130  @Override
131  public void makeChanges(ResearchState state) {
132  state.rocketResearch = id;
133  state.toolBtns.get(MicropolisTool.ROCKET).setVisible(true);
134  }
135  }
136  // INNER CLASSES FOR UPGRADE FEATURES
137  class PoliceNode implements ResearchNode {
138 
139  int id=0;
140  int cost=150;
141 
142  public PoliceNode(int st, int cost){
143  id = st;
144  this.cost = cost;
145  }
146 
147  @Override
148  public String getName() {
149 
150  switch(policeNameDecider) {
151  case 0:
152  policeNameDecider ++;
153  return strings.getString("research.POLICE_T1_NAME");
154 
155  case 1:
156  policeNameDecider ++;
157  return strings.getString("research.POLICE_T2_NAME");
158 
159  case 2:
160  policeNameDecider = 0;
161  return strings.getString("research.POLICE_T3_NAME");
162 
163  default:
164  throw new Error("unreachable Research String");
165  }
166  }
167 
168  @Override
169  public String getDesc() {
170 
171  switch(policeDescDecider) {
172  case 0:
173  policeDescDecider ++;
174  return strings.getString("research.POLICE_T1_DESCRIPTION");
175 
176  case 1:
177  policeDescDecider ++;
178  return strings.getString("research.POLICE_T2_DESCRIPTION");
179 
180  case 2:
181  policeDescDecider = 0;
182  return strings.getString("research.POLICE_T3_DESCRIPTION");
183 
184  default:
185  throw new Error("unreachable Research String");
186  }
187  }
188 
189  @Override
190  public String getIcon() {
191  return "/firestation.png";
192  }
193 
194  @Override
195  public int getCost() {
196  return cost;
197  }
198  @Override
199  public void makeChanges(ResearchState state) {
200  state.policeResearch = id;
201  }
202  }
203  // INNER CLASSES FOR UPGRADE FEATURES
204  class FiremanNode implements ResearchNode {
205 
206  int id=0;
207  int cost=150;
208 
209  public FiremanNode(int st, int cost){
210  id = st;
211  this.cost = cost;
212  }
213 
214  @Override
215  public String getName() {
216 
217  switch(fireNameDecider) {
218  case 0:
219  fireNameDecider ++;
220  return strings.getString("research.FIRE_T1_NAME");
221 
222  case 1:
223  fireNameDecider ++;
224  return strings.getString("research.FIRE_T2_NAME");
225 
226  case 2:
227  fireNameDecider = 0;
228  return strings.getString("research.FIRE_T3_NAME");
229 
230  default:
231  throw new Error("unreachable Research String");
232  }
233  }
234 
235  @Override
236  public String getDesc() {
237 
238  switch(fireDescDecider) {
239  case 0:
240  fireDescDecider ++;
241  return strings.getString("research.FIRE_T1_DESCRIPTION");
242 
243  case 1:
244  fireDescDecider ++;
245  return strings.getString("research.FIRE_T2_DESCRIPTION");
246 
247  case 2:
248  fireDescDecider = 0;
249  return strings.getString("research.FIRE_T3_DESCRIPTION");
250 
251  default:
252  throw new Error("unreachable Research String");
253  }
254  }
255 
256  @Override
257  public String getIcon() {
258  return "/firestation.png";
259  }
260 
261  @Override
262  public int getCost() {
263  return cost;
264  }
265  @Override
266  public void makeChanges(ResearchState state) {
267  state.firemanResearch = id;
268  }
269  }
270  // INNER CLASSES FOR UPGRADE FEATURES
271  class EnvironmentNode implements ResearchNode {
272 
273  int id=0;
274  int cost=150;
275 
276  public EnvironmentNode(int st, int cost){
277  id = st;
278  this.cost = cost;
279  }
280 
281  @Override
282  public String getName() {
283 
284  switch(pollNameDecider) {
285  case 0:
286  pollNameDecider ++;
287  return strings.getString("research.POLL_T1_NAME");
288 
289  case 1:
290  pollNameDecider ++;
291  return strings.getString("research.POLL_T2_NAME");
292 
293  case 2:
294  pollNameDecider = 0;
295  return strings.getString("research.POLL_T3_NAME");
296 
297  default:
298  throw new Error("unreachable Research String");
299  }
300  }
301 
302  @Override
303  public String getDesc() {
304 
305  switch(pollDescDecider) {
306  case 0:
307  pollDescDecider ++;
308  return strings.getString("research.POLL_T1_DESCRIPTION");
309 
310  case 1:
311  pollDescDecider ++;
312  return strings.getString("research.POLL_T2_DESCRIPTION");
313 
314  case 2:
315  pollDescDecider = 0;
316  return strings.getString("research.POLL_T3_DESCRIPTION");
317 
318  default:
319  throw new Error("unreachable Research String");
320  }
321  }
322 
323  @Override
324  public String getIcon() {
325  return "/firestation.png";
326  }
327 
328  @Override
329  public int getCost() {
330  return cost;
331  }
332  @Override
333  public void makeChanges(ResearchState state) {
334  state.environmentResearch = id;
335  }
336  }
337 }