Co-op campaign matches and command markers: mission relay, allied masters, temporary flags
This commit is contained in:
1 parent
dc22e27184
commit
5928acf7f6
12 files changed
+433
-27
No files matched your search
+21
-2
@@ -75,6 +75,7 @@ pub struct StartInfo {
|
||||
pub difficulty: u8,
|
||||
pub sides: Vec<u8>,
|
||||
pub local_side: Option<u8>,
|
||||
pub mission: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
@@ -169,6 +170,14 @@ impl MatchClient {
|
||||
}
|
||||
|
||||
pub fn create(&mut self, sides: &[u8], map_w: usize, map_h: usize, difficulty: u8) {
|
||||
self.send_create(sides, map_w, map_h, difficulty, None);
|
||||
}
|
||||
|
||||
pub fn create_coop(&mut self, mission: usize, sides: &[u8], map_w: usize, map_h: usize, difficulty: u8) {
|
||||
self.send_create(sides, map_w, map_h, difficulty, Some(mission));
|
||||
}
|
||||
|
||||
fn send_create(&mut self, sides: &[u8], map_w: usize, map_h: usize, difficulty: u8, mission: Option<usize>) {
|
||||
if !self.connected {
|
||||
return;
|
||||
}
|
||||
@@ -176,7 +185,7 @@ impl MatchClient {
|
||||
self.status = None;
|
||||
self.chat.clear();
|
||||
self.chat_seen = 0;
|
||||
self.outbox.push_back(json!({"t":"create","sides":sides,"map_w":map_w,"map_h":map_h,"difficulty":difficulty}).to_string());
|
||||
self.outbox.push_back(json!({"t":"create","sides":sides,"map_w":map_w,"map_h":map_h,"difficulty":difficulty,"mission":mission}).to_string());
|
||||
}
|
||||
|
||||
pub fn join(&mut self, code: &str) {
|
||||
@@ -384,6 +393,7 @@ impl MatchClient {
|
||||
let map_h = v.get("map_h").and_then(|x| x.as_u64()).unwrap_or(128) as usize;
|
||||
let difficulty = v.get("difficulty").and_then(|x| x.as_u64()).unwrap_or(1) as u8;
|
||||
let sides = array_bytes(v.get("sides"));
|
||||
let mission = v.get("mission").and_then(|x| x.as_u64()).map(|x| x as usize);
|
||||
let local_side = self.room.as_ref().and_then(|r| r.seats.iter().find(|s| s.name == self.name && s.connected).map(|s| s.side));
|
||||
self.local_side = local_side;
|
||||
if let Some(r) = self.room.as_mut() {
|
||||
@@ -395,7 +405,7 @@ impl MatchClient {
|
||||
r.sides = sides.clone();
|
||||
}
|
||||
}
|
||||
self.start = Some(StartInfo { seed, map_w, map_h, difficulty, sides, local_side });
|
||||
self.start = Some(StartInfo { seed, map_w, map_h, difficulty, sides, local_side, mission });
|
||||
self.error = None;
|
||||
self.status = None;
|
||||
}
|
||||
@@ -499,6 +509,15 @@ mod tests {
|
||||
let start = client.take_start().expect("start info");
|
||||
assert_eq!(start.seed, 7);
|
||||
assert_eq!(start.local_side, Some(0));
|
||||
assert_eq!(start.mission, None);
|
||||
|
||||
client.create_coop(2, &[0, 2], 80, 72, 1);
|
||||
let coop = pop(&mut client);
|
||||
assert_eq!(coop["t"].as_str(), Some("create"));
|
||||
assert_eq!(coop["mission"].as_u64(), Some(2));
|
||||
client.feed(r#"{"t":"start","seed":8,"map_w":80,"map_h":72,"difficulty":1,"sides":[0,2],"mission":2}"#);
|
||||
let coop_start = client.take_start().expect("co-op start info");
|
||||
assert_eq!(coop_start.mission, Some(2));
|
||||
|
||||
client.send_commands(&[Command { side: 0, seq: 0, act: Act::Dig(Rect::new(1, 2, 3, 4)) }]);
|
||||
let req = pop(&mut client);
|
||||
|
||||
Reference in new issue
Block a user