From 0f54e9bff6a7fa1900aa6988965cb17abdd26521 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 2 Nov 2023 16:26:15 +0100 Subject: Add and use helper to list units by area. --- rules.js | 52 ++++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/rules.js b/rules.js index abf1b38..bd94490 100644 --- a/rules.js +++ b/rules.js @@ -546,7 +546,7 @@ function neutralize_unit(u) { set_unit_box(u, OC) } -function remove_unit(u, to=DEPLOY) { +function remove_unit(u, to=DEPLOY, verbose) { let loc = unit_loc(u) logi(`U${u} from A${loc}.`) set_unit_loc(u, to) @@ -4305,18 +4305,9 @@ states.gov_airmobilize_select_units = { log_br() log("Airmobilize") - for (let loc = 0; loc < area_count; ++loc) { - let first = true - for (let u of list) { - if (unit_loc(u) === loc) { - if (first) { - logi("A" + loc) - first = false - } - logii("U" + u) - set_unit_airmobile(u) - } - } + log_area_unit_list(list) + for (let u of list) { + set_unit_airmobile(u) } logi(`-${cost} Helo PTS`) log_br() @@ -5256,18 +5247,7 @@ states.gov_coup_attempt_free_mobilize = { done() { log_br() log("Mobilization") - for (let loc = 0; loc < area_count; ++loc) { - let first = true - for (let u of game.summary) { - if (unit_loc(u) === loc) { - if (first) { - logi("A" + loc) - first = false - } - logii("U" + u) - } - } - } + log_area_unit_list(game.summary) log_br() game.summary = null @@ -5329,10 +5309,11 @@ states.gov_coup_attempt_select_units = { let list = game.selected game.selected = [] - // TODO: summary by region - log("Removed:") + log("Removed") + log_area_unit_list(list) + for (let u of list) { - remove_unit(u, ELIMINATED) + remove_unit(u, ELIMINATED, false) } log_sep() @@ -5516,6 +5497,21 @@ function goto_next_turn() { // #region LOGGING +function log_area_unit_list(list) { + for (let loc = 0; loc < area_count; ++loc) { + let first = true + for (let u of list) { + if (unit_loc(u) === loc) { + if (first) { + logi("A" + loc) + first = false + } + logii("U" + u) + } + } + } +} + function log(msg) { game.log.push(msg) } -- cgit v1.2.3