15804
|
1 |
use serde_derive::{Deserialize, Serialize};
|
|
2 |
|
|
3 |
pub const MAX_HEDGEHOGS_PER_TEAM: u8 = 8;
|
|
4 |
|
|
5 |
#[derive(PartialEq, Eq, Clone, Debug)]
|
|
6 |
pub enum ServerVar {
|
|
7 |
MOTDNew(String),
|
|
8 |
MOTDOld(String),
|
|
9 |
LatestProto(u16),
|
|
10 |
}
|
|
11 |
|
|
12 |
#[derive(PartialEq, Eq, Clone, Debug)]
|
|
13 |
pub enum GameCfg {
|
|
14 |
FeatureSize(u32),
|
|
15 |
MapType(String),
|
|
16 |
MapGenerator(u32),
|
|
17 |
MazeSize(u32),
|
|
18 |
Seed(String),
|
|
19 |
Template(u32),
|
|
20 |
|
|
21 |
Ammo(String, Option<String>),
|
|
22 |
Scheme(String, Vec<String>),
|
|
23 |
Script(String),
|
|
24 |
Theme(String),
|
|
25 |
DrawnMap(String),
|
|
26 |
}
|
|
27 |
|
|
28 |
#[derive(PartialEq, Eq, Clone, Debug, Default)]
|
|
29 |
pub struct TeamInfo {
|
|
30 |
pub owner: String,
|
|
31 |
pub name: String,
|
|
32 |
pub color: u8,
|
|
33 |
pub grave: String,
|
|
34 |
pub fort: String,
|
|
35 |
pub voice_pack: String,
|
|
36 |
pub flag: String,
|
|
37 |
pub difficulty: u8,
|
|
38 |
pub hedgehogs_number: u8,
|
|
39 |
pub hedgehogs: [HedgehogInfo; MAX_HEDGEHOGS_PER_TEAM as usize],
|
|
40 |
}
|
|
41 |
|
|
42 |
#[derive(PartialEq, Eq, Clone, Debug, Default)]
|
|
43 |
pub struct HedgehogInfo {
|
|
44 |
pub name: String,
|
|
45 |
pub hat: String,
|
|
46 |
}
|
|
47 |
|
|
48 |
#[derive(Clone, Serialize, Deserialize, Debug)]
|
|
49 |
pub struct Ammo {
|
|
50 |
pub name: String,
|
|
51 |
pub settings: Option<String>,
|
|
52 |
}
|
|
53 |
|
|
54 |
#[derive(Clone, Serialize, Deserialize, Debug)]
|
|
55 |
pub struct Scheme {
|
|
56 |
pub name: String,
|
|
57 |
pub settings: Vec<String>,
|
|
58 |
}
|
|
59 |
|
|
60 |
#[derive(Clone, Serialize, Deserialize, Debug)]
|
|
61 |
pub struct RoomConfig {
|
|
62 |
pub feature_size: u32,
|
|
63 |
pub map_type: String,
|
|
64 |
pub map_generator: u32,
|
|
65 |
pub maze_size: u32,
|
|
66 |
pub seed: String,
|
|
67 |
pub template: u32,
|
|
68 |
|
|
69 |
pub ammo: Ammo,
|
|
70 |
pub scheme: Scheme,
|
|
71 |
pub script: String,
|
|
72 |
pub theme: String,
|
|
73 |
pub drawn_map: Option<String>,
|
|
74 |
}
|
|
75 |
|
|
76 |
impl RoomConfig {
|
|
77 |
pub fn new() -> RoomConfig {
|
|
78 |
RoomConfig {
|
|
79 |
feature_size: 12,
|
|
80 |
map_type: "+rnd+".to_string(),
|
|
81 |
map_generator: 0,
|
|
82 |
maze_size: 0,
|
|
83 |
seed: "seed".to_string(),
|
|
84 |
template: 0,
|
|
85 |
|
|
86 |
ammo: Ammo {
|
|
87 |
name: "Default".to_string(),
|
|
88 |
settings: None,
|
|
89 |
},
|
|
90 |
scheme: Scheme {
|
|
91 |
name: "Default".to_string(),
|
|
92 |
settings: Vec::new(),
|
|
93 |
},
|
|
94 |
script: "Normal".to_string(),
|
|
95 |
theme: "\u{1f994}".to_string(),
|
|
96 |
drawn_map: None,
|
|
97 |
}
|
|
98 |
}
|
|
99 |
|
|
100 |
pub fn set_config(&mut self, cfg: GameCfg) {
|
|
101 |
match cfg {
|
|
102 |
GameCfg::FeatureSize(s) => self.feature_size = s,
|
|
103 |
GameCfg::MapType(t) => self.map_type = t,
|
|
104 |
GameCfg::MapGenerator(g) => self.map_generator = g,
|
|
105 |
GameCfg::MazeSize(s) => self.maze_size = s,
|
|
106 |
GameCfg::Seed(s) => self.seed = s,
|
|
107 |
GameCfg::Template(t) => self.template = t,
|
|
108 |
|
|
109 |
GameCfg::Ammo(n, s) => {
|
|
110 |
self.ammo = Ammo {
|
|
111 |
name: n,
|
|
112 |
settings: s,
|
|
113 |
}
|
|
114 |
}
|
|
115 |
GameCfg::Scheme(n, s) => {
|
|
116 |
self.scheme = Scheme {
|
|
117 |
name: n,
|
|
118 |
settings: s,
|
|
119 |
}
|
|
120 |
}
|
|
121 |
GameCfg::Script(s) => self.script = s,
|
|
122 |
GameCfg::Theme(t) => self.theme = t,
|
|
123 |
GameCfg::DrawnMap(m) => self.drawn_map = Some(m),
|
|
124 |
};
|
|
125 |
}
|
|
126 |
|
|
127 |
pub fn to_map_config(&self) -> Vec<String> {
|
|
128 |
vec![
|
|
129 |
self.feature_size.to_string(),
|
|
130 |
self.map_type.to_string(),
|
|
131 |
self.map_generator.to_string(),
|
|
132 |
self.maze_size.to_string(),
|
|
133 |
self.seed.to_string(),
|
|
134 |
self.template.to_string(),
|
|
135 |
]
|
|
136 |
}
|
|
137 |
|
|
138 |
pub fn to_game_config(&self) -> Vec<GameCfg> {
|
|
139 |
use GameCfg::*;
|
|
140 |
let mut v = vec![
|
|
141 |
Ammo(self.ammo.name.to_string(), self.ammo.settings.clone()),
|
|
142 |
Scheme(self.scheme.name.to_string(), self.scheme.settings.clone()),
|
|
143 |
Script(self.script.to_string()),
|
|
144 |
Theme(self.theme.to_string()),
|
|
145 |
];
|
|
146 |
if let Some(ref m) = self.drawn_map {
|
|
147 |
v.push(DrawnMap(m.to_string()))
|
|
148 |
}
|
|
149 |
v
|
|
150 |
}
|
|
151 |
}
|
|
152 |
|
|
153 |
#[derive(PartialEq, Eq, Clone, Debug)]
|
|
154 |
pub enum VoteType {
|
|
155 |
Kick(String),
|
|
156 |
Map(Option<String>),
|
|
157 |
Pause,
|
|
158 |
NewSeed,
|
|
159 |
HedgehogsPerTeam(u8),
|
|
160 |
}
|
|
161 |
|
|
162 |
pub struct Vote {
|
|
163 |
pub is_pro: bool,
|
|
164 |
pub is_forced: bool,
|
|
165 |
}
|