sc2_proxy/
sc2.rs

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
//! SC2 data and types

#![allow(missing_docs)]


use sc2_proto;

use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
pub enum Race {
    Protoss,
    Terran,
    Zerg,
    Random,
}
impl Race {
    pub fn from_proto(race: sc2_proto::common::Race) -> Self {
        use sc2_proto::common::Race;
        match race {
            Race::Protoss => Self::Protoss,
            Race::Terran => Self::Terran,
            Race::Zerg => Self::Zerg,
            Race::Random => Self::Random,
            Race::NoRace => panic!("NoRace not alloed"),
        }
    }

    pub fn to_proto(&self) -> sc2_proto::common::Race {
        use sc2_proto::common::Race;
        match self {
            Self::Protoss => Race::Protoss,
            Self::Terran => Race::Terran,
            Self::Zerg => Race::Zerg,
            Self::Random => Race::Random,
        }
    }
}
impl Default for Race {
    fn default() -> Self {
        Race::Random
    }
}

/// Builtin AI difficulty level
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
pub enum Difficulty {
    VeryEasy,
    Easy,
    Medium,
    MediumHard,
    Hard,
    Harder,
    VeryHard,
    CheatVision,
    CheatMoney,
    CheatInsane,
}
impl Difficulty {
    pub fn to_proto(&self) -> sc2_proto::sc2api::Difficulty {
        use sc2_proto::sc2api::Difficulty;
        match self {
            Self::VeryEasy => Difficulty::VeryEasy,
            Self::Easy => Difficulty::Easy,
            Self::Medium => Difficulty::Medium,
            Self::MediumHard => Difficulty::MediumHard,
            Self::Hard => Difficulty::Hard,
            Self::Harder => Difficulty::Harder,
            Self::VeryHard => Difficulty::VeryHard,
            Self::CheatVision => Difficulty::CheatVision,
            Self::CheatMoney => Difficulty::CheatMoney,
            Self::CheatInsane => Difficulty::CheatInsane,
        }
    }
}
impl Default for Difficulty {
    fn default() -> Self {
        Difficulty::Hard
    }
}

#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
pub struct BuiltinAI {
    pub race: Race,
    pub difficulty: Difficulty,
}

/// Result of a player
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum PlayerResult {
    Victory,
    Defeat,
    Tie,
}
impl PlayerResult {
    pub fn from_proto(race: sc2_proto::sc2api::Result) -> Self {
        use sc2_proto::sc2api::Result;
        match race {
            Result::Victory => Self::Victory,
            Result::Defeat => Self::Defeat,
            Result::Tie => Self::Tie,
            Result::Undecided => panic!("Undecided result not alloed"),
        }
    }

    pub fn to_proto(&self) -> sc2_proto::sc2api::Result {
        use sc2_proto::sc2api::Result;
        match self {
            Self::Victory => Result::Victory,
            Self::Defeat => Result::Defeat,
            Self::Tie => Result::Tie,
        }
    }
}