rust/hedgewars-engine-messages/src/lib.rs
author unc0rr
Tue, 13 Nov 2018 07:43:36 +0100
changeset 14210 a8fe9cd51154
child 14211 257b296169a8
permissions -rw-r--r--
Move engine messages into separate lib for reuse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14210
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
     1
use crate::command::Command;
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
     2
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
     3
pub enum KeystrokeAction {
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
     4
    Press,
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
     5
    Release,
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
     6
}
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
     7
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
     8
pub enum SyncedEngineMessage {
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
     9
    Left(KeystrokeAction),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    10
    Right(KeystrokeAction),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    11
    Up(KeystrokeAction),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    12
    Down(KeystrokeAction),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    13
    Precise(KeystrokeAction),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    14
    Attack(KeystrokeAction),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    15
    NextTurn,
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    16
    Switch,
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    17
    Empty,
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    18
    Timer(u8),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    19
    Slot(u8),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    20
    SetWeapon(u8),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    21
    Put(i32, i32),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    22
    HighJump,
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    23
    LowJump,
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    24
    Skip,
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    25
    TeamControlGained(String),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    26
    TeamControlLost(String),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    27
}
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    28
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    29
pub enum UnsyncedEngineMessage {
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    30
    Ping,
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    31
    Pong,
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    32
    Say(String),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    33
    Taunt(u8),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    34
    GameType(u8),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    35
    Warning(String),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    36
    StopSyncing,
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    37
    GameOver,
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    38
    GameInterrupted,
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    39
    GameSetupChecksum(String),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    40
}
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    41
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    42
pub enum ConfigEngineMessage {
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    43
    ConfigRequest,
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    44
    SetAmmo(String),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    45
    SetScript(String),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    46
    SetScriptParam(String),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    47
    Spectate,
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    48
    TeamLocality(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    49
    SetMap(String),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    50
    SetTheme(String),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    51
    SetSeed(String),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    52
    SetTemplateFilter(String),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    53
    SetMapGenerator(String),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    54
    SetFeatureSize(u8),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    55
    SetDelay(u32),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    56
    SetReadyDelay(u32),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    57
    SetCratesFrequency(u8),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    58
    SetHealthCrateProbability(u8),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    59
    SetHealthCratesNumber(u8),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    60
    SetRoundsTilSuddenDeath(u8),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    61
    SetSuddenDeathWaterRiseSpeed(u8),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    62
    SetSuddenDeathHealthDecreaseRate(u8),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    63
    SetDamageMultiplier(u32),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    64
    SetRopeLength(u32),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    65
    SetGetawayTime(u32),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    66
    SetDudMinesPercent(u8),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    67
    SetMinesNumber(u32),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    68
    SetAirMinesNumber(u32),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    69
    SetBarrelsNumber(u32),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    70
    SetTurnTime(u32),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    71
    SetMinesTime(u32),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    72
    SetWorldEdge(u8),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    73
    Draw, // TODO
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    74
    SetVoicePack(String),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    75
    AddHedgehog(String, u8, u32),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    76
    AddTeam(String, u8),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    77
    SetHedgehogCoordinates(i32, i32),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    78
    SetFort(String),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    79
    SetGrave(String),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    80
    SetHat(String),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    81
    SetFlag(String),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    82
    SetOwner(String),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    83
    SetOneClanMode(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    84
    SetMultishootMode(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    85
    SetSolidLand(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    86
    SetBorders(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    87
    SetDivideTeams(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    88
    SetLowGravity(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    89
    SetLaserSight(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    90
    SetInvulnerability(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    91
    SetHealthReset(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    92
    SetVampiric(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    93
    SetKarma(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    94
    SetArtilleryMode(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    95
    SetHedgehogSwitch(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    96
    SetRandomOrder(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    97
    SetKingMode(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    98
    SetPlaceHedgehog(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
    99
    SetSharedAmmo(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   100
    SetGirdersEnabled(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   101
    SetLandObjectsEnabled(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   102
    SetAISurvivalMode(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   103
    SetInfiniteAttack(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   104
    SetResetWeapons(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   105
    SetAmmoPerHedgehog(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   106
    SetWindMode(u8),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   107
    SetTagTeam(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   108
    SetBottomBorder(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   109
    SetShoppaBorder(bool),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   110
}
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   111
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   112
pub enum EngineMessage {
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   113
    Synced(SyncedEngineMessage, u32),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   114
    Unsynced(UnsyncedEngineMessage),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   115
    Config(ConfigEngineMessage),
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   116
}
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   117
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   118
impl EngineMessage {
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   119
    fn from_bytes(buf: &[u8]) -> Self {
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   120
        unimplemented!()
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   121
    }
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   122
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   123
    fn to_bytes(&self) -> Vec<u8> {
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   124
        unimplemented!()
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   125
    }
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   126
}
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   127
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   128
#[cfg(test)]
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   129
mod tests {
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   130
    #[test]
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   131
    fn it_works() {
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   132
        assert_eq!(2 + 2, 4);
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   133
    }
a8fe9cd51154 Move engine messages into separate lib for reuse
unc0rr
parents:
diff changeset
   134
}