From a2e6df7b4b0428ed59f732541a3f7b3f0c98f183 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 30 Aug 2022 00:05:07 +0200 Subject: Don't regroup retreat to enemy hex! Auto-target non-artillery. --- rules.js | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/rules.js b/rules.js index c8e75ac..c25e4f7 100644 --- a/rules.js +++ b/rules.js @@ -3863,20 +3863,20 @@ function can_select_retreat_hex() { if (is_valid_retreat_hex(game.from2)) return true - if (game.to1) { + if (game.to1 && !has_undisrupted_enemy_unit(game.to1)) { let result = false for_each_hex_and_adjacent_hex(game.from1, x => { - if (result === false && is_valid_retreat_hex(x)) + if (result === false && x !== game.to1 && is_valid_retreat_hex(x)) result = true }) if (result) return true } - if (game.to2) { + if (game.to2 && !has_undisrupted_enemy_unit(game.to2)) { let result = false for_each_hex_and_adjacent_hex(game.from2, x => { - if (result === false && is_valid_retreat_hex(x)) + if (result === false && x !== game.to2 && is_valid_retreat_hex(x)) result = true }) if (result) @@ -4747,14 +4747,27 @@ function apply_auto_target() { return apply_battle_fire(INFANTRY) // only one class remains - if (hp[ARMOR] > 0 && hp[INFANTRY] === 0 && hp[ANTITANK] === 0 && hp[ARTILLERY] === 0) - return apply_battle_fire(ARMOR) - if (hp[ARMOR] === 0 && hp[INFANTRY] > 0 && hp[ANTITANK] === 0 && hp[ARTILLERY] === 0) - return apply_battle_fire(INFANTRY) - if (hp[ARMOR] === 0 && hp[INFANTRY] === 0 && hp[ANTITANK] > 0 && hp[ARTILLERY] === 0) - return apply_battle_fire(ANTITANK) - if (hp[ARMOR] === 0 && hp[INFANTRY] === 0 && hp[ANTITANK] === 0 && hp[ARTILLERY] > 0) - return apply_battle_fire(ARTILLERY) + if (fc === ARTILLERY) { + // Artillery may always target anything + if (hp[ARMOR] > 0 && hp[INFANTRY] === 0 && hp[ANTITANK] === 0 && hp[ARTILLERY] === 0) + return apply_battle_fire(ARMOR) + if (hp[ARMOR] === 0 && hp[INFANTRY] > 0 && hp[ANTITANK] === 0 && hp[ARTILLERY] === 0) + return apply_battle_fire(INFANTRY) + if (hp[ARMOR] === 0 && hp[INFANTRY] === 0 && hp[ANTITANK] > 0 && hp[ARTILLERY] === 0) + return apply_battle_fire(ANTITANK) + if (hp[ARMOR] === 0 && hp[INFANTRY] === 0 && hp[ANTITANK] === 0 && hp[ARTILLERY] > 0) + return apply_battle_fire(ARTILLERY) + } else { + // Non-artillery may only target artillery if no other targets remain + if (hp[ARMOR] > 0 && hp[INFANTRY] === 0 && hp[ANTITANK] === 0) + return apply_battle_fire(ARMOR) + if (hp[ARMOR] === 0 && hp[INFANTRY] > 0 && hp[ANTITANK] === 0) + return apply_battle_fire(INFANTRY) + if (hp[ARMOR] === 0 && hp[INFANTRY] === 0 && hp[ANTITANK] > 0) + return apply_battle_fire(ANTITANK) + if (hp[ARMOR] === 0 && hp[INFANTRY] === 0 && hp[ANTITANK] === 0 && hp[ARTILLERY] > 0) + return apply_battle_fire(ARTILLERY) + } } function gen_battle_hits() { @@ -5336,7 +5349,7 @@ states.buildup_eliminate_unsupplied = { }) }, unit(u) { - log(`Eliminated at #${unit_hex(u)}`) + log(`Eliminated at #${unit_hex(u)}.`) eliminate_unit(u) resume_buildup_eliminate_unsupplied() }, -- cgit v1.2.3