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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
use sc2_proto::common;
use sc2_proto::sc2api;
use super::super::{FromProto, IntoProto, Result};
#[allow(missing_docs)]
#[derive(Debug, Copy, Clone)]
pub enum Race {
Terran,
Zerg,
Protoss,
Random,
}
impl FromProto<common::Race> for Race {
fn from_proto(race: common::Race) -> Result<Self> {
Ok(match race {
common::Race::Terran => Race::Terran,
common::Race::Zerg => Race::Zerg,
common::Race::Protoss => Race::Protoss,
common::Race::Random => Race::Random,
common::Race::NoRace => panic!(concat!(
"NoRace value (Library Bug! please let us know that ",
"this can in fact happen!)"
)),
})
}
}
impl IntoProto<common::Race> for Race {
fn into_proto(self) -> Result<common::Race> {
Ok(match self {
Race::Zerg => common::Race::Zerg,
Race::Terran => common::Race::Terran,
Race::Protoss => common::Race::Protoss,
Race::Random => common::Race::Random,
})
}
}
#[allow(missing_docs)]
#[derive(Debug, Copy, Clone)]
pub enum Difficulty {
VeryEasy,
Easy,
Medium,
MediumHard,
Hard,
Harder,
VeryHard,
CheatVision,
CheatMoney,
CheatInsane,
}
impl Difficulty {
pub fn to_proto(&self) -> sc2api::Difficulty {
match *self {
Difficulty::VeryEasy => sc2api::Difficulty::VeryEasy,
Difficulty::Easy => sc2api::Difficulty::Easy,
Difficulty::Medium => sc2api::Difficulty::Medium,
Difficulty::MediumHard => sc2api::Difficulty::MediumHard,
Difficulty::Hard => sc2api::Difficulty::Hard,
Difficulty::Harder => sc2api::Difficulty::Harder,
Difficulty::VeryHard => sc2api::Difficulty::VeryHard,
Difficulty::CheatVision => sc2api::Difficulty::CheatVision,
Difficulty::CheatMoney => sc2api::Difficulty::CheatMoney,
Difficulty::CheatInsane => sc2api::Difficulty::CheatInsane,
}
}
}
#[derive(Debug, Copy, Clone)]
pub enum PlayerSetup {
Computer {
race: Race,
difficulty: Difficulty,
},
Player {
race: Race,
},
}
impl PlayerSetup {
pub fn is_player(&self) -> bool {
match self {
&PlayerSetup::Player { .. } => true,
_ => false,
}
}
pub fn is_computer(&self) -> bool {
match self {
&PlayerSetup::Computer { .. } => true,
_ => false,
}
}
}