1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
package com.dabomstew.pkrandom.pokemon;
public class GenRestrictions {
public boolean allow_gen1, allow_gen2, allow_gen3, allow_gen4, allow_gen5;
public boolean assoc_g1_g2, assoc_g1_g4;
public boolean assoc_g2_g1, assoc_g2_g3, assoc_g2_g4;
public boolean assoc_g3_g2, assoc_g3_g4;
public boolean assoc_g4_g1, assoc_g4_g2, assoc_g4_g3;
public GenRestrictions() {
}
public GenRestrictions(int state) {
allow_gen1 = (state & 1) > 0;
allow_gen2 = (state & 2) > 0;
allow_gen3 = (state & 4) > 0;
allow_gen4 = (state & 8) > 0;
allow_gen5 = (state & 16) > 0;
assoc_g1_g2 = (state & 32) > 0;
assoc_g1_g4 = (state & 64) > 0;
assoc_g2_g1 = (state & 128) > 0;
assoc_g2_g3 = (state & 256) > 0;
assoc_g2_g4 = (state & 512) > 0;
assoc_g3_g2 = (state & 1024) > 0;
assoc_g3_g4 = (state & 2048) > 0;
assoc_g4_g1 = (state & 4096) > 0;
assoc_g4_g2 = (state & 8192) > 0;
assoc_g4_g3 = (state & 16384) > 0;
}
public boolean nothingSelected() {
return !allow_gen1 && !allow_gen2 && !allow_gen3 && !allow_gen4
&& !allow_gen5;
}
public int toInt() {
return makeIntSelected(allow_gen1, allow_gen2, allow_gen3, allow_gen4,
allow_gen5, assoc_g1_g2, assoc_g1_g4, assoc_g2_g1, assoc_g2_g3,
assoc_g2_g4, assoc_g3_g2, assoc_g3_g4, assoc_g4_g1,
assoc_g4_g2, assoc_g4_g3);
}
public void limitToGen(int generation) {
if (generation < 2) {
allow_gen2 = false;
assoc_g1_g2 = false;
assoc_g2_g1 = false;
}
if (generation < 3) {
allow_gen3 = false;
assoc_g2_g3 = false;
assoc_g3_g2 = false;
}
if (generation < 4) {
allow_gen4 = false;
assoc_g1_g4 = false;
assoc_g2_g4 = false;
assoc_g3_g4 = false;
assoc_g4_g1 = false;
assoc_g4_g2 = false;
assoc_g4_g3 = false;
}
if (generation < 5) {
allow_gen5 = false;
}
}
private int makeIntSelected(boolean... switches) {
if (switches.length > 32) {
// No can do
return 0;
}
int initial = 0;
int state = 1;
for (boolean b : switches) {
initial |= b ? state : 0;
state *= 2;
}
return initial;
}
}
|