View Javadoc

1   package org.inigma.utopia;
2   
3   import java.util.Calendar;
4   import java.util.Collection;
5   import java.util.UUID;
6   
7   import org.inigma.utopia.utils.CalendarUtils;
8   
9   public class Province {
10      private String id;
11      private String kingdomId;
12      private Coordinate coordinate;
13      private int acres;
14      private Calendar lastUpdate;
15      private boolean gender; // false = male, true = female
16      private String leader;
17      private String name;
18      private int networth;
19      private Race race;
20      private Rank rank;
21      private Personality personality;
22      private int peasants;
23      private int gold;
24      private int food;
25      private int runes;
26      private int tradeBalance;
27      private int soldiers;
28      private int offspecs;
29      private int defspecs;
30      private int elites;
31      private int horses;
32      private int thieves;
33      private int wizards;
34      private int prisoners;
35      private double offme;
36      private double defme;
37      private Military military;
38      private Science science;
39      private Survey survey;
40      private boolean self;
41      private boolean aggressionActive;
42      private boolean townWatchActive;
43  
44      public Province() {
45          this.id = UUID.randomUUID().toString();
46          this.rank = Rank.Unknown;
47          this.race = Race.Unknown;
48          this.personality = Personality.Unknown;
49          this.lastUpdate = CalendarUtils.getCalendar();
50          this.lastUpdate.setTimeInMillis(0);
51          this.offme = 1;
52          this.defme = 1;
53          this.thieves = -1;
54          this.wizards = -1;
55          this.self = false;
56          this.military = new Military(this);
57          this.science = new Science(this);
58          this.survey = new Survey(this);
59      }
60  
61      public Province(String provinceName, Coordinate coord) {
62          this();
63          this.coordinate = coord;
64          this.name = provinceName;
65      }
66  
67      public Province(String provinceName, String kingdomId) {
68          this();
69          this.kingdomId = kingdomId;
70          this.name = provinceName;
71      }
72  
73      public void clone(Province province) {
74          setAcres(province.getAcres());
75          setDefspecs(province.getDefspecs());
76          setElites(province.getElites());
77          setFood(province.getFood());
78          setGender(province.isGender());
79          setGold(province.getGold());
80          setHorses(province.getHorses());
81          setLastUpdate(province.getLastUpdate());
82          setLeader(province.getLeader());
83          if (province.getNetworth() != 0) {
84              setNetworth(province.getNetworth());
85          }
86          setOffspecs(province.getOffspecs());
87          setPeasants(province.getPeasants());
88          setPersonality(province.getPersonality());
89          setPrisoners(province.getPrisoners());
90          setRace(province.getRace());
91          setRank(province.getRank());
92          setRunes(province.getRunes());
93          setSoldiers(province.getSoldiers());
94          setThieves(province.getThieves());
95          setTradeBalance(province.getTradeBalance());
96          setWizards(province.getWizards());
97          setOffense(province.getOffense());
98          setDefense(province.getDefense());
99          setSelf(province.isSelf());
100         survey.setEfficiency(province.survey.getEfficiency());
101     }
102 
103     @Override
104     public boolean equals(Object obj) {
105         if (obj instanceof Province) {
106             return this.toString().equals(((Province) obj).toString());
107         }
108         return this.toString().equals(obj);
109     }
110 
111     public int getAcres() {
112         return acres;
113     }
114 
115     public Coordinate getCoordinate() {
116         return coordinate;
117     }
118 
119     public int getCurrentDefense() {
120         int soldierCount = soldiers;
121         int defspecCount = defspecs;
122         int eliteCount = elites;
123         Calendar now = CalendarUtils.getCalendar();
124         Collection<Army> armies = military.getArmies();
125         if (!military.isRaw()) {
126             for (Army army : armies) {
127                 if (army.getReturnTime().after(now)) {
128                     soldierCount -= army.getSoldiers();
129                     defspecCount -= army.getDefspecs();
130                     eliteCount -= army.getElites();
131                 }
132             }
133             return (int) (getRawDefense(soldierCount, defspecCount, eliteCount, aggressionActive, townWatchActive) * defme);
134         }
135         return getDefense();
136     }
137 
138     public int getCurrentOffense() {
139         int soldierCount = soldiers;
140         int offspecCount = offspecs;
141         int eliteCount = elites;
142         int horseCount = horses;
143         Calendar now = CalendarUtils.getCalendar();
144         Collection<Army> armies = military.getArmies();
145         if (!military.isRaw()) {
146             for (Army army : armies) {
147                 if (army.getReturnTime().after(now)) {
148                     soldierCount -= army.getSoldiers();
149                     offspecCount -= army.getOffspecs();
150                     eliteCount -= army.getElites();
151                     horseCount -= army.getHorses();
152                 }
153             }
154             return (int) (getRawOffense(soldierCount, offspecCount, eliteCount, horseCount, aggressionActive) * offme);
155         }
156         return getOffense();
157     }
158 
159     public int getDefense() {
160         return (int) (getRawDefense(soldiers, defspecs, elites, aggressionActive, townWatchActive) * defme);
161     }
162 
163     public double getDefme() {
164         return defme;
165     }
166 
167     public int getDefspecs() {
168         return defspecs;
169     }
170 
171     public int getElites() {
172         return elites;
173     }
174 
175     public int getFood() {
176         return food;
177     }
178 
179     public int getGold() {
180         return gold;
181     }
182 
183     public int getHorses() {
184         return horses;
185     }
186 
187     public String getId() {
188         return id;
189     }
190 
191     public String getKingdomId() {
192         return kingdomId;
193     }
194 
195     public Calendar getLastUpdate() {
196         return lastUpdate;
197     }
198 
199     public String getLeader() {
200         return leader;
201     }
202 
203     public Military getMilitary() {
204         return military;
205     }
206 
207     public String getName() {
208         return name;
209     }
210 
211     public int getNetworth() {
212         return networth;
213     }
214 
215     public int getOffense() {
216         return (int) (getRawOffense(soldiers, offspecs, elites, horses, aggressionActive) * offme);
217     }
218 
219     public double getOffme() {
220         return offme;
221     }
222 
223     public int getOffspecs() {
224         return offspecs;
225     }
226 
227     public int getPeasants() {
228         return peasants;
229     }
230 
231     public Personality getPersonality() {
232         return personality;
233     }
234 
235     public int getPrisoners() {
236         return prisoners;
237     }
238 
239     public Race getRace() {
240         return race;
241     }
242 
243     public Rank getRank() {
244         return rank;
245     }
246 
247     public int getRawDefense(int s, int specs, int e, boolean aggression, boolean townWatch) {
248         int defense = s * 1 + specs * race.getSpecDef() + e * race.getEliteDef();
249         if (aggression) {
250             defense -= s * 1;
251         }
252         if (townWatch) {
253             defense += peasants / 4;
254         }
255         return defense;
256     }
257 
258     public int getRawOffense(int s, int spec, int e, int h, boolean aggression) {
259         int offense = s * 1 + spec * race.getSpecOff() + e * race.getEliteOff() + h;
260         if (aggression) {
261             offense += s * 1;
262         }
263         return offense;
264     }
265 
266     public int getRunes() {
267         return runes;
268     }
269 
270     public Science getScience() {
271         return science;
272     }
273 
274     public int getSoldiers() {
275         return soldiers;
276     }
277 
278     public Survey getSurvey() {
279         return survey;
280     }
281 
282     public int getThieves() {
283         return thieves;
284     }
285 
286     public int getTradeBalance() {
287         return tradeBalance;
288     }
289 
290     public int getWizards() {
291         return wizards;
292     }
293 
294     @Override
295     public int hashCode() {
296         return this.toString().hashCode();
297     }
298 
299     public boolean isAggressionActive() {
300         return aggressionActive;
301     }
302 
303     public boolean isGender() {
304         return gender;
305     }
306 
307     public boolean isSelf() {
308         return self;
309     }
310 
311     public boolean isTownWatchActive() {
312         return townWatchActive;
313     }
314 
315     public void setAcres(int acres) {
316         this.acres = acres;
317     }
318 
319     public void setAggressionActive(boolean aggressionActive) {
320         this.aggressionActive = aggressionActive;
321     }
322 
323     public void setCoordinate(Coordinate coordinate) {
324         this.coordinate = coordinate;
325     }
326 
327     public void setDefense(int defense) {
328         this.defme = defense / (double) getRawDefense(soldiers, defspecs, elites, aggressionActive, townWatchActive);
329     }
330 
331     public void setDefspecs(int defspecs) {
332         this.defspecs = defspecs;
333     }
334 
335     public void setElites(int elites) {
336         this.elites = elites;
337     }
338 
339     public void setFood(int food) {
340         this.food = food;
341     }
342 
343     public void setGender(boolean gender) {
344         this.gender = gender;
345     }
346 
347     public void setGold(int gold) {
348         this.gold = gold;
349     }
350 
351     public void setHorses(int horses) {
352         this.horses = horses;
353     }
354 
355     public void setId(String id) {
356         this.id = id;
357     }
358 
359     public void setKingdomId(String kingdomId) {
360         this.kingdomId = kingdomId;
361     }
362 
363     public void setLastUpdate(Calendar last) {
364         this.lastUpdate = CalendarUtils.getCalendar(last);
365     }
366 
367     public void setLeader(String leader) {
368         this.leader = leader;
369     }
370 
371     public void setMilitary(Military military) {
372         this.military = military;
373     }
374 
375     public void setName(String name) {
376         this.name = name;
377     }
378 
379     public void setNetworth(int networth) {
380         this.networth = networth;
381     }
382 
383     public void setOffense(int offense) {
384         this.offme = offense / (double) getRawOffense(soldiers, offspecs, elites, horses, aggressionActive);
385     }
386 
387     public void setOffspecs(int offspecs) {
388         this.offspecs = offspecs;
389     }
390 
391     public void setPeasants(int peasants) {
392         this.peasants = peasants;
393     }
394 
395     public void setPersonality(Personality personality) {
396         this.personality = personality;
397     }
398 
399     public void setPrisoners(int prisoners) {
400         this.prisoners = prisoners;
401     }
402 
403     public void setRace(Race race) {
404         this.race = race;
405     }
406 
407     public void setRank(Rank rank) {
408         this.rank = rank;
409     }
410 
411     public void setRunes(int runes) {
412         this.runes = runes;
413     }
414 
415     public void setScience(Science science) {
416         this.science = science;
417     }
418 
419     public void setSelf(boolean self) {
420         this.self = self;
421     }
422 
423     public void setSoldiers(int soliders) {
424         this.soldiers = soliders;
425     }
426 
427     public void setSurvey(Survey survey) {
428         this.survey = survey;
429     }
430 
431     public void setThieves(int thieves) {
432         this.thieves = thieves;
433     }
434 
435     public void setTownWatchActive(boolean townWatchActive) {
436         this.townWatchActive = townWatchActive;
437     }
438 
439     public void setTradeBalance(int tradeBalance) {
440         this.tradeBalance = tradeBalance;
441     }
442 
443     public void setWizards(int wizards) {
444         this.wizards = wizards;
445     }
446 
447     @Override
448     public String toString() {
449         StringBuilder sb = new StringBuilder();
450         sb.append(name);
451         if (coordinate != null) {
452             sb.append(" ");
453             sb.append(coordinate);
454         }
455         return sb.toString();
456     }
457 
458     public String toStringDetailed() {
459         return String.format("%s (%s/%s)", name, race.getShortName(), personality.getShortName());
460     }
461 }