From 7ac4ee43314c20d5da560d32d2f2b39507a7305a Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 25 Apr 2023 16:52:21 +0200 Subject: Fix placement skip logic. Only allow skipping if _no_ suitable piece is available. --- events.txt | 2 +- rules.js | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/events.txt b/events.txt index 720486a..8c7f505 100644 --- a/events.txt +++ b/events.txt @@ -929,7 +929,7 @@ SHADED 57 # TODO: prompt "Replace a Police with any Cartels piece in 2 spaces." space 2 has_police(s) prompt "Replace a Police with any Cartels piece." - piece 1 is_piece_in_event_space(p) && is_police(p) && can_replace_with(s, CARTELS, GUERRILLA) + piece 1 is_piece_in_event_space(p) && is_police(p) && (can_replace_with(s, CARTELS, GUERRILLA) || can_replace_with(s, CARTELS, BASE)) remove place CARTELS BASE_GUERRILLA endpiece diff --git a/rules.js b/rules.js index 10b4690..2adce9a 100644 --- a/rules.js +++ b/rules.js @@ -1734,7 +1734,7 @@ function gen_piece_in_space(space, faction, type) { function gen_place_piece(space, faction, type) { if (!can_stack_piece(space, faction, type)) - return true + return false let p0 = first_piece[faction][type] let p1 = last_piece[faction][type] let can_place = false @@ -1751,7 +1751,7 @@ function gen_place_piece(space, faction, type) { if (piece_space(p) !== space || (type === GUERRILLA && !is_underground(p))) gen_action_piece(p) } - return !can_place + return can_place } function gen_underground_guerrillas(s, faction) { @@ -7471,34 +7471,41 @@ states.vm_place = { let faction = vm_operand(3) let type = vm_operand(4) let where = space_name[game.vm.s] + let possible = false view.where = game.vm.s if (typeof faction === "object" && typeof type === "object") { event_prompt(`Place piece in ${where}.`) for (let f of faction) { for (let t of type) { if (f === GOVT && (t === BASE || t === TROOPS || t === POLICE)) - skip |= gen_place_piece(game.vm.s, f, t) + if (gen_place_piece(game.vm.s, f, t)) + possible = true if (f !== GOVT && (t === BASE || t === GUERRILLA)) - skip |= gen_place_piece(game.vm.s, f, t) + if (gen_place_piece(game.vm.s, f, t)) + possible = true } } } else if (typeof faction === "object") { event_prompt(`Place ${piece_type_name[type]} in ${where}.`) for (let f of faction) { if (f === GOVT && (type === BASE || type === TROOPS || type === POLICE)) - skip |= gen_place_piece(game.vm.s, f, type) + if (gen_place_piece(game.vm.s, f, type)) + possible = true if (f !== GOVT && (type === BASE || type === GUERRILLA)) - skip |= gen_place_piece(game.vm.s, f, type) + if (gen_place_piece(game.vm.s, f, type)) + possible = true } } else if (typeof type === "object") { event_prompt(`Place ${faction_name[faction]} piece in ${where}.`) for (let t of type) - skip |= gen_place_piece(game.vm.s, faction, t) + if (gen_place_piece(game.vm.s, faction, t)) + possible = true } else { event_prompt(`Place ${piece_faction_type_name[faction][type]} in ${where}.`) - skip |= gen_place_piece(game.vm.s, faction, type) + if (gen_place_piece(game.vm.s, faction, type)) + possible = true } - if (skip) + if (skip || !possible) view.actions.skip = 1 }, piece(p) { @@ -9437,7 +9444,7 @@ CODE[57 * 2 + 1] = [ [ vm_prompt, "In each of 2 spaces replace a Police with any Cartels piece." ], [ vm_space, true, 2, 2, (s)=>has_police(s) ], [ vm_prompt, "Replace a Police with any Cartels piece." ], - [ vm_piece, false, 1, 1, (p,s)=>is_piece_in_event_space(p) && is_police(p) && can_replace_with(s, CARTELS, GUERRILLA) ], + [ vm_piece, false, 1, 1, (p,s)=>is_piece_in_event_space(p) && is_police(p) && (can_replace_with(s, CARTELS, GUERRILLA) || can_replace_with(s, CARTELS, BASE)) ], [ vm_remove ], [ vm_place, false, 0, CARTELS, BASE_GUERRILLA ], [ vm_endpiece ], -- cgit v1.2.3