-
Notifications
You must be signed in to change notification settings - Fork 16
/
teams.cc
54 lines (44 loc) · 2.01 KB
/
teams.cc
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
#include "teams.h"
#include <stdexcept>
const TeamMeta TeamMeta::ALL[2];
SaveState::Team TeamMeta::command_team(SSL_Referee::Command command) {
switch (command) {
case SSL_Referee::PREPARE_KICKOFF_YELLOW: return SaveState::TEAM_YELLOW;
case SSL_Referee::PREPARE_KICKOFF_BLUE: return SaveState::TEAM_BLUE;
case SSL_Referee::PREPARE_PENALTY_YELLOW: return SaveState::TEAM_YELLOW;
case SSL_Referee::PREPARE_PENALTY_BLUE: return SaveState::TEAM_BLUE;
case SSL_Referee::DIRECT_FREE_YELLOW: return SaveState::TEAM_YELLOW;
case SSL_Referee::DIRECT_FREE_BLUE: return SaveState::TEAM_BLUE;
case SSL_Referee::INDIRECT_FREE_YELLOW: return SaveState::TEAM_YELLOW;
case SSL_Referee::INDIRECT_FREE_BLUE: return SaveState::TEAM_BLUE;
case SSL_Referee::TIMEOUT_YELLOW: return SaveState::TEAM_YELLOW;
case SSL_Referee::TIMEOUT_BLUE: return SaveState::TEAM_BLUE;
case SSL_Referee::GOAL_YELLOW: return SaveState::TEAM_YELLOW;
case SSL_Referee::GOAL_BLUE: return SaveState::TEAM_BLUE;
default: throw std::logic_error("Command is not team-specific!");
}
}
TeamMeta::TeamMeta() : COLOUR(team() == SaveState::TEAM_YELLOW ? u8"yellow" : u8"blue") {
}
SaveState::Team TeamMeta::team() const {
return static_cast<SaveState::Team>(this - ALL);
}
SaveState::Team TeamMeta::other() const {
return static_cast<SaveState::Team>((team() + 1U) % 2U);
}
SSL_Referee::TeamInfo &TeamMeta::team_info(SSL_Referee &ref) const {
return *(team() == SaveState::TEAM_YELLOW ? ref.mutable_yellow() : ref.mutable_blue());
}
const SSL_Referee::TeamInfo &TeamMeta::team_info(const SSL_Referee &ref) const {
return team() == SaveState::TEAM_YELLOW ? ref.yellow() : ref.blue();
}
uint32_t TeamMeta::penalty_goals(const SaveState &ss) const {
return team() == SaveState::TEAM_YELLOW ? ss.yellow_penalty_goals() : ss.blue_penalty_goals();
}
void TeamMeta::set_penalty_goals(SaveState &ss, uint32_t penalty_goals) const {
if (team() == SaveState::TEAM_YELLOW) {
ss.set_yellow_penalty_goals(penalty_goals);
} else {
ss.set_blue_penalty_goals(penalty_goals);
}
}