From 6fc4d02d7d171b90e880468fc5e51072e4e4a346 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 1 Feb 2023 21:39:35 +0100 Subject: Manual strikes. --- images/garrison_action.svg | 4 ++++ play.html | 4 ++++ play.js | 12 +++++++++++ rules.js | 54 ++++++++++++++++++++++++++++------------------ 4 files changed, 53 insertions(+), 21 deletions(-) create mode 100644 images/garrison_action.svg diff --git a/images/garrison_action.svg b/images/garrison_action.svg new file mode 100644 index 0000000..f5af5b7 --- /dev/null +++ b/images/garrison_action.svg @@ -0,0 +1,4 @@ + + + + diff --git a/play.html b/play.html index 82c9afb..1933de4 100644 --- a/play.html +++ b/play.html @@ -278,6 +278,10 @@ body.Teutons #plan_actions .russian { display: none } margin: 0 auto; } +#garrison.action { + background-image: url(images/garrison_action.svg); +} + #garrison.hide { display: none } #garrison .unit { position: static } diff --git a/play.js b/play.js index ad5a7ba..c270365 100644 --- a/play.js +++ b/play.js @@ -321,6 +321,10 @@ function is_veche_action() { return !!(view.actions && view.actions.veche === 1) } +function is_garrison_action() { + return !!(view.actions && view.actions.garrison === 1) +} + function is_calendar_action(turn) { return !!(view.actions && view.actions.calendar && set_has(view.actions.calendar, turn)) } @@ -824,6 +828,11 @@ function on_click_array(evt) { send_action('array', evt.target.my_id) } +function on_click_garrison(evt) { + if (evt.button === 0) + send_action('garrison') +} + function on_blur(evt) { document.getElementById("status").textContent = "" } @@ -1619,6 +1628,7 @@ function update_battle() { } ui.garrison.classList.toggle("hide", !view.battle.storm) + ui.garrison.classList.toggle("action", is_garrison_action()) ui.garrison.replaceChildren() if (view.battle.garrison) { @@ -2164,6 +2174,8 @@ function build_map() { build_plan() + ui.garrison.addEventListener("mousedown", on_click_garrison) + for (let i = 0; i < 12; ++i) { ui.battle_grid_array[i].my_id = i ui.battle_grid_array[i].addEventListener("mousedown", on_click_array) diff --git a/rules.js b/rules.js index 5f1b48d..538126d 100644 --- a/rules.js +++ b/rules.js @@ -1,5 +1,7 @@ "use strict" +// TODO: log end victory conditions at scenario start + // FIXME: lift_sieges / besieged needs checking! (automatic after disband_lord, manual after move/sail, extra careful manual after battle) // FIXME: remove_legate_if_endangered needs checking! (automatic after disband_lord, manual after move/sail, manual after battle) @@ -11,6 +13,7 @@ const data = require("./data.js") const AUTOWALK = true +const AUTOSTRIKE = false const BOTH = "Both" const TEUTONS = "Teutons" @@ -8422,26 +8425,27 @@ states.assign_left_right = { function goto_strike_group() { game.state = "strike_group" - // Auto-strike if only one group - let first_striker = -1 - let first_target = -1 - let target - for (let pos of current_strike_positions()) { - if (has_strike(pos)) { - if ((pos === SA1 || pos === SA2 || pos === SA3) && is_sa_without_rg()) - target = 100 // just a unique target id - else - target = find_strike_target(pos) - if (first_target < 0) { - first_striker = pos - first_target = target - } else if (first_target !== target) { - return // more than one target! + if (AUTOSTRIKE) { + // Auto-strike if only one group + let first_striker = -1 + let first_target = -1 + let target + for (let pos of current_strike_positions()) { + if (has_strike(pos)) { + if ((pos === SA1 || pos === SA2 || pos === SA3) && is_sa_without_rg()) + target = 100 // just a unique target id + else + target = find_strike_target(pos) + if (first_target < 0) { + first_striker = pos + first_target = target + } else if (first_target !== target) { + return // more than one target! + } } } + select_strike_group(first_striker) } - - select_strike_group(first_striker) } function select_strike_group(pos) { @@ -8462,14 +8466,22 @@ states.strike_group = { return format_strike_step() + " \u2014 Strike" }, prompt() { - view.prompt = `${format_strike_step()}: Strike with a Lord.` - for (let pos of current_strike_positions()) - if (has_strike(pos)) - gen_action_lord(game.battle.array[pos]) + if (is_defender_step() && has_garrison() && !filled(D2)) { + view.prompt = `${format_strike_step()}: Strike with Garrison.` + view.actions.garrison = 1 + } else { + view.prompt = `${format_strike_step()}: Strike with a Lord.` + for (let pos of current_strike_positions()) + if (has_strike(pos)) + gen_action_lord(game.battle.array[pos]) + } }, lord(lord) { select_strike_group(get_lord_array_position(lord)) }, + garrison() { + select_strike_group(-1) + }, } // === BATTLE: TOTAL HITS (ROUND UP) === -- cgit v1.2.3