-
Notifications
You must be signed in to change notification settings - Fork 22
/
BoostManager.java
72 lines (58 loc) · 2.24 KB
/
BoostManager.java
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
package rlbotexample.boost;
import rlbot.cppinterop.RLBotDll;
import rlbot.flat.BoostPadState;
import rlbot.flat.FieldInfo;
import rlbot.flat.GameTickPacket;
import rlbotexample.vector.Vector3;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Information about where boost pads are located on the field and what status they have.
*
* This class is here for your convenience, it is NOT part of the framework. You can change it as much
* as you want, or delete it.
*/
public class BoostManager {
private static final List<BoostPad> orderedBoosts = new ArrayList<>();
private static final List<BoostPad> fullBoosts = new ArrayList<>();
private static final List<BoostPad> smallBoosts = new ArrayList<>();
public static List<BoostPad> getFullBoosts() {
return fullBoosts;
}
public static List<BoostPad> getSmallBoosts() {
return smallBoosts;
}
private static void loadFieldInfo(FieldInfo fieldInfo) {
synchronized (orderedBoosts) {
orderedBoosts.clear();
fullBoosts.clear();
smallBoosts.clear();
for (int i = 0; i < fieldInfo.boostPadsLength(); i++) {
rlbot.flat.BoostPad flatPad = fieldInfo.boostPads(i);
BoostPad ourPad = new BoostPad(new Vector3(flatPad.location()), flatPad.isFullBoost());
orderedBoosts.add(ourPad);
if (ourPad.isFullBoost()) {
fullBoosts.add(ourPad);
} else {
smallBoosts.add(ourPad);
}
}
}
}
public static void loadGameTickPacket(GameTickPacket packet) {
if (packet.boostPadStatesLength() > orderedBoosts.size()) {
try {
loadFieldInfo(RLBotDll.getFieldInfo());
} catch (IOException e) {
e.printStackTrace();
return;
}
}
for (int i = 0; i < packet.boostPadStatesLength(); i++) {
BoostPadState boost = packet.boostPadStates(i);
BoostPad existingPad = orderedBoosts.get(i); // existingPad is also referenced from the fullBoosts and smallBoosts lists
existingPad.setActive(boost.isActive());
}
}
}