class Player public int m_pid public Point m_pos public int m_bombs pu

 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
class Player
{
public int m_pid;
public Point m_pos;
public int m_bombs;
public int m_str;
public int m_speed;
public boolean m_infict;
public int m_controlSum;
private int m_bonuses; // 0x000...00ggggbbb; g - good, b - bad
public Player() {}
public Player(int _pid, Point _pos, int _bombs, int _bombsStrength, int _speed, boolean _isInfected) {
m_pid = _pid; m_pos = _pos; m_bombs = _bombs; m_str = _bombsStrength; m_speed = _speed; m_infict = _isInfected;
}
public void controlSumUpdate() {
m_controlSum = (m_bombs << 8) + (m_str << 4) + m_speed;
}
/** Add bonus to bit-mask */
public void addBonus (char _b) {
switch (_b) {
case 'b': m_bonuses |= m_goodBonus[0]; break;
case 'v': m_bonuses |= m_goodBonus[1]; break;
case 'f': m_bonuses |= m_goodBonus[2]; break;
case 'r': m_bonuses |= m_badBonus[0]; m_infict = true; break;
case 's': m_bonuses |= m_badBonus[1]; m_infict = true; break;
case 'u': m_bonuses |= m_badBonus[2]; m_infict = true; break;
case 'o': m_bonuses |= m_badBonus[3]; m_infict = true; break;
}
}
/** Remove bonus from bit-mask */
public void delBonus (char _b ) {
m_infict = true;
switch (_b) {
case 'b': m_bonuses &=~ m_goodBonus[0]; break;
case 'v': m_bonuses &=~ m_goodBonus[1]; break;
case 'f': m_bonuses &=~ m_goodBonus[2]; break;
case 'r': m_bonuses &=~ m_badBonus[0]; m_infict = false; break;
case 's': m_bonuses &=~ m_badBonus[1]; m_infict = false; break;
case 'u': m_bonuses &=~ m_badBonus[2]; m_infict = false; break;
case 'o': m_bonuses &=~ m_badBonus[3]; m_infict = false; break;
}
}
public void randomAdd()
{
int newControlSum = (m_bombs << 8) + (m_str << 4) + m_speed;
newControlSum = (m_controlSum ^ newControlSum);
if (newControlSum == 0) {} //TODO: check for bonuses 'r' and 'u' should be resolved in some way...
else if ((newControlSum >>= 4) == 0) {
if(m_infict) addBonus('s');
else addBonus('v');
}
else if ((newControlSum >>= 4) == 0) addBonus('f');
else {
if(m_infict) addBonus('o');
else addBonus('b');
}
controlSumUpdate();
}
public boolean checkBonus (char _b) {
switch (_b) {
case 'b': return (m_bonuses & m_goodBonus[0]) != 0;
case 'v': return (m_bonuses & m_goodBonus[1]) != 0;
case 'f': return (m_bonuses & m_goodBonus[2]) != 0;
case 'r': return (m_bonuses & m_badBonus[0]) != 0;
case 's': return (m_bonuses & m_badBonus[1]) != 0;
case 'u': return (m_bonuses & m_badBonus[2]) != 0;
case 'o': return (m_bonuses & m_badBonus[3]) != 0;
}
/* throw hidden exception!!! */
int error = 0; int isHere = 1 / error;
return false;
}
public final int[] m_goodBonus = {0x40, 0x20, 0x10}; // 'b', 'v', 'f'
public final int[] m_badBonus = {0x8, 0x4, 0x2, 0x1}; // 'r', 's', 'u', 'o'
}