From 17832efb7d5f7e183ceb20324e82a95ddb9537a5 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 28 Dec 2022 23:09:12 +0100 Subject: Growth. --- play.js | 1 + rules.js | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/play.js b/play.js index 8e9c523..0204626 100644 --- a/play.js +++ b/play.js @@ -1524,6 +1524,7 @@ function on_update() { action_button("end_disband", "End disband") action_button("end_disband", "End disband") action_button("end_feed", "End feed") + action_button("end_growth", "End growth") action_button("end_levy", "End levy") action_button("end_muster", "End muster") action_button("end_pay", "End pay") diff --git a/rules.js b/rules.js index 264f038..c964daf 100644 --- a/rules.js +++ b/rules.js @@ -1078,6 +1078,10 @@ function add_ravaged_marker(loc) { set_add(game.pieces.ravaged, loc) } +function remove_ravaged_marker(loc) { + set_delete(game.pieces.ravaged, loc) +} + function count_siege_markers(loc) { return map_get(game.pieces.sieges, loc, 0) } @@ -7082,15 +7086,73 @@ function goto_remove_markers() { goto_command_activation() } +// === END CAMPAIGN: GROWTH === + +function count_enemy_ravaged() { + let n = 0 + for (let loc of game.pieces.ravaged) + if (is_friendly_territory(loc)) + ++n + return n +} + +function goto_growth() { + game.count = count_enemy_ravaged() >> 1 + if (game.active === TEUTONS) + log_h3("Teutonic Growth") + else + log_h3("Russian Growth") + if (game.count === 0) { + logi("Nothing") + end_growth() + } else { + game.state = "growth" + } +} + +function end_growth() { + set_active_enemy() + if (game.active === P2) + goto_growth() + else + goto_game_end() +} + +states.growth = { + prompt() { + view.prompt = `Growth: Remove ${game.count} enemy ravaged markers.` + if (game.count > 0) { + for (let loc of game.pieces.ravaged) + if (is_friendly_territory(loc)) + gen_action_locale(loc) + } else { + view.actions.end_growth = 1 + } + }, + locale(loc) { + push_undo() + logi(`%${loc}`) + remove_ravaged_marker(loc) + game.count-- + }, + end_growth() { + clear_undo() + end_growth() + }, +} + // === END CAMPAIGN: GAME END === function goto_end_campaign() { log_h1("End Campaign") - set_active(P1) if (game.scenario === "Crusade on Novgorod") { - if (game.turn === 8 || game.turn === 16) - log("TODO: Grow - Teutons then Rus remove 1/2 enemy's ravage") + if (game.turn === 8 || game.turn === 16) { + set_active(P1) + log_h2("Growth") + goto_growth() + return + } } goto_game_end() -- cgit v1.2.3