From 0b55f794a180c8afc87a71775e858fcc01fc3bf2 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 24 Jun 2023 15:25:26 +0200 Subject: Select Militia. Build Improvement in 2 steps. --- rules.js | 150 +++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 99 insertions(+), 51 deletions(-) (limited to 'rules.js') diff --git a/rules.js b/rules.js index f9e3c21..7ad0685 100644 --- a/rules.js +++ b/rules.js @@ -558,6 +558,8 @@ function get_selected_region() { return get_governor_location(game.selected_governor) if (game.selected_general >= 0) return get_general_location(game.selected_general) + if (game.selected_militia >= 0) + return game.selected_militia return UNAVAILABLE } @@ -775,6 +777,14 @@ function has_enemy_general_in_capital(where) { return is_enemy_general(get_capital_general(where)) } +function can_militia_initiate_battle(where) { + if (some_general((id, loc) => loc === where && is_enemy_general(id))) + return true + if (some_barbarian((id, loc) => loc === where)) + return true + return false +} + function has_available_governor() { for (let i = 0; i < 6; ++i) if (get_governor_location(game.current * 6 + i) === AVAILABLE) @@ -1625,6 +1635,11 @@ states.take_actions = { where = get_general_location(game.selected_general) } + if (game.selected_militia >= 0) { + view.selected_militia = game.selected_militia + where = game.selected_militia + } + // Select Governor for (let i = 0; i < 6; ++i) { let id = game.current * 6 + i @@ -1639,10 +1654,19 @@ states.take_actions = { gen_action_governor(id) break default: - gen_action_governor(id) + // TODO: can_select_governor (check possible actions) + if (sip >= 1 || pip >= 2) + gen_action_governor(id) break } } + + // Select Militia (if can Disperse Mobs or Initiate Battle) + let loc = get_governor_location(id) + if (is_province(loc) && has_lone_militia(loc) && loc !== game.selected_militia) { + if (mip >= 1 && (get_mobs(loc)) || can_militia_initiate_battle(loc)) + gen_action_militia(loc) + } } // Select General @@ -1659,7 +1683,9 @@ states.take_actions = { gen_action_general(id) break default: - gen_action_general(id) + // TODO: can_select_general (check possible actions) + if (mip >= 1) + gen_action_general(id) break } } @@ -1692,14 +1718,13 @@ states.take_actions = { // Governor Actions if (game.selected_governor >= 0 && is_province(where)) { + view.actions.hold_games = 0 view.actions.place_militia = 0 - view.actions.amphitheater = 0 - view.actions.basilica = 0 - view.actions.limes = 0 + view.actions.build_improvement = 0 // Recall Governor if (sip >= 2) - gen_action_recall(where) + view.actions.recall_governor = 1 // Increase Support Level let support = get_support(where) @@ -1716,31 +1741,15 @@ states.take_actions = { // Hold Games if (get_mobs(where)) { - view.actions.disperse_mob = 0 view.actions.hold_games = 0 - if (has_lone_militia(where) && mip >= 1) - view.actions.disperse_mob = 1 if (pip >= 2) view.actions.hold_games = 1 } // Build an Improvement - if (can_build_improvement(where)) { - if (pip >= get_improvement_cost()) { - if (!has_amphitheater(where)) - view.actions.amphitheater = 1 - if (!has_basilica(where)) - view.actions.basilica = 1 - if (!has_limes(where)) - view.actions.limes = 1 - } - } - - // Initiate Battle with Militia not stacked with General - if (!has_militia_battled(where)) { - if (has_lone_militia(where)) - gen_initiate_battle(where) - } + if (can_build_improvement(where)) + if (pip >= get_improvement_cost()) + view.actions.build_improvement = 1 } // General Actions @@ -1787,6 +1796,16 @@ states.take_actions = { } } + // Militia Actions + if (game.selected_militia >= 0) { + view.actions.disperse_mob = 0 + if (mip >= 1) + view.actions.disperse_mob = 1 + + // Initiate Battle with Militia not stacked with General + if (!has_militia_battled(where)) + gen_initiate_battle(where) + } }, end_actions() { @@ -1837,18 +1856,31 @@ states.take_actions = { governor(id) { game.selected_governor = id game.selected_general = -1 + game.selected_militia = -1 }, general(id) { if (is_own_general(id)) { game.selected_governor = -1 game.selected_general = id + game.selected_militia = -1 } else { push_undo() goto_battle_vs_general(get_general_location(game.selected_general), game.selected_general, id) } }, + militia(where) { + if (is_own_province(where)) { + game.selected_governor = -1 + game.selected_general = -1 + game.selected_militia = where + } else { + push_undo() + goto_battle_vs_militia(get_selected_region(), game.selected_general) + } + }, + recruit_governor() { push_undo() log("Recruit Governor " + (game.selected_governor % 6) + ".") @@ -1863,7 +1895,7 @@ states.take_actions = { set_general_location(game.selected_general, AVAILABLE) }, - recall() { + recall_governor() { push_undo() recall_governor() }, @@ -1888,28 +1920,11 @@ states.take_actions = { set_mobs(where, get_mobs(where) - 1) }, - amphitheater() { - push_undo() - spend_populace(get_improvement_cost()) - let where = get_governor_location(game.selected_governor) - add_amphitheater(where) - log("Built Amphitheater in %" + where + ".") - }, - - basilica() { + build_improvement() { push_undo() + game.where = get_governor_location(game.selected_governor) spend_populace(get_improvement_cost()) - let where = get_governor_location(game.selected_governor) - add_basilica(where) - log("Built Basilica in %" + where + ".") - }, - - limes() { - push_undo() - spend_populace(get_improvement_cost()) - let where = get_governor_location(game.selected_governor) - add_limes(where) - log("Built Limes in %" + where + ".") + game.state = "build_improvement" }, add_legion_to_army() { @@ -1984,11 +1999,6 @@ states.take_actions = { push_undo() goto_battle_vs_rival_emperor(get_selected_region(), game.selected_general, id) }, - - militia(_) { - push_undo() - goto_battle_vs_militia(get_selected_region(), game.selected_general) - }, } // FREE ACTION: ENTER PROVINCIAL CAPITAL @@ -2101,6 +2111,42 @@ states.replace_pretender_governor = { }, } +// ACTION: BUILD IMPROVEMENT + +states.build_improvement = { + prompt() { + prompt("Build Improvement in " + REGION_NAME[game.where] + ".") + view.color = POPULACE + view.selected_region = game.where + + view.actions.amphitheater = 0 + view.actions.basilica = 0 + view.actions.limes = 0 + + if (!has_amphitheater(game.where)) + view.actions.amphitheater = 1 + if (!has_basilica(game.where)) + view.actions.basilica = 1 + if (!has_limes(game.where)) + view.actions.limes = 1 + }, + amphitheater() { + add_amphitheater(game.where) + log("Build Amphitheater in %" + game.where + ".") + game.state = "take_actions" + }, + basilica() { + add_basilica(game.where) + log("Build Basilica in %" + game.where + ".") + game.state = "take_actions" + }, + limes() { + add_limes(game.where) + log("Build Limes in %" + game.where + ".") + game.state = "take_actions" + }, +} + // ACTION: IMPROVE SUPPORT function improve_support() { @@ -2719,6 +2765,7 @@ states.foederati_general = { states.foederati_militia = { prompt() { prompt("Foederati: Remove a barbarian.") + view.selected_militia = game.where gen_foederati(game.where) for (let to of ADJACENT[game.where]) gen_foederati(to) @@ -4012,6 +4059,7 @@ exports.setup = function (seed, scenario, options) { pp: 0, selected_governor: -1, selected_general: -1, + selected_militia: -1, played: [], used: [], killed: 0, -- cgit v1.2.3