diff --git a/VERSION b/VERSION index 8fe9a83..aa35920 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v202611-00008 +v202611-00009 diff --git a/src/game.rs b/src/game.rs index cc183cd..e29356f 100644 --- a/src/game.rs +++ b/src/game.rs @@ -138,6 +138,7 @@ pub struct St { } pub const RUNE_TOOL: usize = 20; // index of the rune forge tower in ui::TOOLS +pub const SUMMON_TOOL: usize = 11; // index of summoning in ui::TOOLS pub fn st(k: EK) -> St { let s = |name, hp, atk, range, speed, interval, wage, bounty| St { name, hp, atk, range, speed, interval, wage, bounty }; @@ -1123,7 +1124,7 @@ impl Game { self.ents.iter().filter(|e| e.alive && e.creature()).count() } pub fn worker_count(&self) -> usize { - self.ents.iter().filter(|e| e.alive && !e.hero && e.kind == EK::Worker).count() + self.ents.iter().filter(|e| e.alive && !e.hero && e.kind == EK::Worker && e.side == self.me_side && !e.chained).count() } pub fn summon_cost(&self) -> f32 { 80.0 + 20.0 * (self.worker_count() as f32 - 4.0).max(0.0) @@ -1137,6 +1138,7 @@ impl Game { e.id = id; e.kind = kind; e.hero = hero; + e.side = self.me_side; e.x = x; e.y = y; e.disp_x = x; @@ -1377,6 +1379,12 @@ impl Game { } self.carve_master_area(*side, cores[k]); self.add_master(*side, cores[k]); + self.switch_to(*side); + let (cx, cy) = cores[k]; + // a new master needs the same starting crew side 0 already has + for j in 0..4 { + self.spawn(EK::Worker, false, cx as f32 - 0.5, cy as f32 + j as f32 * 0.7 + 0.3, 1); + } } self.local_side = local; self.switch_to(local); diff --git a/src/netplay.rs b/src/netplay.rs index a27eb92..c6c6e55 100644 --- a/src/netplay.rs +++ b/src/netplay.rs @@ -52,6 +52,15 @@ impl Game { if !self.start_masters(sides, local) { return false; } + // every master has to be able to build his dungeon at once + if let Some(v) = self.known.get_mut(crate::game::SUMMON_TOOL) { + *v = true; + } + for m in self.masters.iter_mut() { + if let Some(v) = m.known.get_mut(crate::game::SUMMON_TOOL) { + *v = true; + } + } self.netplay = Some(Netplay::default()); true } @@ -271,6 +280,22 @@ mod tests { assert_eq!(a.checksum(), b.checksum()); } + #[test] + fn a_new_match_master_can_summon_at_once() { + let mut g = client(24, 2); + assert!(g.tool_allowed(crate::game::SUMMON_TOOL), "summoning is known in a match"); + assert_eq!(g.worker_count(), 4, "a new master starts with his own four imps"); + let (cx, cy) = core_of(&g, Owner::Rival1); + let mana = g.mana; + let cost = g.summon_cost(); + g.queue(Act::Summon { x: cx as f32 - 0.5, y: cy as f32 + 0.5 }); + let turn = g.take_orders(); + g.receive_turn(&turn); + assert!(cost > 0.0 && g.mana < mana, "summoning costs mana"); + assert!(g.ents.iter().any(|e| e.kind == crate::game::EK::Worker && e.side == 2 && e.alive), "the summoned imp belongs to the master who summoned it"); + assert_eq!(g.worker_count(), 5, "the summon counts as the master's own worker"); + } + #[test] fn a_client_without_the_next_turn_stands_still_and_its_orders_wait() { let mut g = client(22, 0);