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
use sc2_proto::common;
use sc2_proto::sc2api;

use constants::sc2_bug_tag;
use {FromProto, IntoProto, Result};

/// Race of the player.
#[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 => unreachable!(
                "{}: I assumed NoRace was not a legitimate value",
                sc2_bug_tag()
            ),
        })
    }
}

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,
        })
    }
}

/// Difficulty setting for built-in StarCraft II AI.
#[allow(missing_docs)]
#[derive(Debug, Copy, Clone)]
pub enum Difficulty {
    VeryEasy,
    Easy,
    Medium,
    MediumHard,
    Hard,
    Harder,
    VeryHard,
    CheatVision,
    CheatMoney,
    CheatInsane,
}

impl Difficulty {
    /// convert to protobuf data
    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,
        }
    }
}

/// Settings for players.
#[derive(Debug, Copy, Clone)]
pub enum PlayerSetup {
    /// Add a built-in StarCraft II bot with the given race and difficulty.
    Computer(Race, Difficulty),
    /// Add a user-controlled player.
    Player(Race),
    //Observer,
}

impl PlayerSetup {
    /// Does the PlayerSetup represent a player?
    pub fn is_player(&self) -> bool {
        match self {
            &PlayerSetup::Player(_) => true,
            _ => false,
        }
    }

    /// Does the PlayerSetup represent a computer?
    pub fn is_computer(&self) -> bool {
        match self {
            &PlayerSetup::Computer(_, _) => true,
            _ => false,
        }
    }

    /*/// does the player setup represent an observer
    pub fn is_observer(&self) -> bool {
        match self {
            &PlayerSetup::Observer => true,
            _ => false,
        }
    }*/
}