From 39f63d040a198f0d7e57dc41f4e68576141217e2 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 28 Jan 2024 16:26:47 +0100 Subject: Fix placement possibility checks for old guard and grand battery. --- rules.js | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'rules.js') diff --git a/rules.js b/rules.js index 51c71e4..137e3ff 100644 --- a/rules.js +++ b/rules.js @@ -923,17 +923,44 @@ function can_place_detachment(p, hq) { let x = piece_hex(p) if (x === AVAILABLE_P1 || x === AVAILABLE_P2) { if (pieces_are_associated(p, hq)) { - if (p === GRAND_BATTERY || p === OLD_GUARD) { + + if (p === GRAND_BATTERY) { + if (hq === NAPOLEON_HQ && piece_mode(NAPOLEON_HQ)) + return can_place_detachment_grand_battery() + return false + } + + if (p === OLD_GUARD) { if (hq === NAPOLEON_HQ && piece_mode(NAPOLEON_HQ)) - return can_place_detachment_anywhere() - } else { - return can_place_detachment_anywhere() + return can_place_detachment_old_guard() + return false } + + return can_place_detachment_anywhere() } } return false } +function can_place_detachment_grand_battery() { + for (let p of friendly_units()) { + let x = piece_hex(p) + if (calc_distance(piece_hex(NAPOLEON_HQ), x) <= 3) + if (!hex_has_any_piece(x, p1_det)) + return true + } + return false +} + +function can_place_detachment_old_guard() { + let result = false + for_each_within_x3(piece_hex(NAPOLEON_HQ), (next) => { + if (!is_enemy_zoc(next) && is_empty_hex(next)) + result = true + }) + return result +} + states.place_detachment_hq = { inactive: "place detachments", prompt() { -- cgit v1.2.3