From 07563bb8c48d168c8f8886262793e61fafee0073 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 12 Aug 2024 16:08:30 +0200 Subject: v2: click to use market and port improvements --- rules.js | 95 ++++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 30 deletions(-) (limited to 'rules.js') diff --git a/rules.js b/rules.js index b993b2d..034fb49 100644 --- a/rules.js +++ b/rules.js @@ -1938,10 +1938,6 @@ function can_select_governor(id) { if (game.pip >= get_improvement_cost()) return true - // Goto Market - if (has_market(where) && !has_used_market(where) && game.mip + game.sip + game.pip > 0) - return true - return false } @@ -2021,6 +2017,13 @@ states.take_actions = { for (let c of hand) gen_action_card(c) + // Goto Market + if (is_deluxe() && game.mip + game.sip + game.pip > 0) { + for (let s = 0; s < 12; ++s) + if (has_market(s) && !has_used_market(s) && is_own_province(s)) + gen_action_use_market(s) + } + // Use events on played cards for (let c of game.played) if (!set_has(game.used, c) && can_play_card_event(c)) @@ -2124,14 +2127,6 @@ states.take_actions = { if (can_build_improvement(where)) if (game.pip >= get_improvement_cost()) view.actions.build_improvement = 1 - - // Goto Market - if (is_deluxe() && has_market(where)) { - if (!has_used_market(where) && game.mip + game.sip + game.pip > 0) - view.actions.market = 1 - else - view.actions.market = 0 - } } // General Actions @@ -2392,28 +2387,60 @@ states.take_actions = { enter_capital() }, - market() { + use_port(s) { + push_undo() + game.state = "use_port" + }, + + use_market(s) { push_undo() game.state = "use_market" + game.where = s + }, +} + +// IMPROVEMENT: PORT + +states.use_port = { + prompt() { + let from = get_general_location(game.selected_general) + view.prompt = "Use Port to sail to a distant province." + view.color = MILITARY + view.selected_general = game.selected_general + view.selected_port = from + + for (let to = 0; to < 12; ++to) { + if (to !== from && !is_adjacent(from, to)) { + gen_action_region(to) + if (can_enter_capital(to)) + gen_action_capital(to) + } + } + }, + region(where) { + move_army_to(game.selected_general, where, false) + }, + capital(where) { + move_army_to(game.selected_general, where, true) }, } // IMPROVEMENT: MARKET function use_market_effect(mip, sip, pip) { - let where = get_governor_location(game.selected_governor) - log("Used Market in %" + where + ".") + log("Used Market in %" + game.where + ".") game.mip += mip game.sip += sip game.pip += pip game.state = "take_actions" - set_used_market(where) + set_used_market(game.where) } states.use_market = { inactive: "Market", prompt() { prompt(`Market: ${game.mip} military, ${game.sip} senate, ${game.pip} populace.`) + view.selected_market = game.where if (game.mip > 0) { view.actions.mip_to_sip = 1 view.actions.mip_to_pip = 1 @@ -3133,18 +3160,6 @@ function create_army(where, capital) { // ACTION: MOVE ARMY -function gen_sail_army(from) { - if (is_own_province(from) && has_port(from) && !has_used_port(from)) { - for (let to = 0; to < 12; ++to) { - if (to !== from) { - gen_action_region(to) - if (can_enter_capital(to)) - gen_action_capital(to) - } - } - } -} - function gen_move_army() { let from = get_general_location(game.selected_general) if (game.mip >= 1) { @@ -3157,7 +3172,8 @@ function gen_move_army() { gen_action_region(to) } if (is_deluxe()) - gen_sail_army(from) + if (has_port(from) && !has_used_port(from) && is_own_province(from)) + gen_action_use_port(from) } } @@ -3879,7 +3895,8 @@ states.force_march = { } } if (is_deluxe()) - gen_sail_army(where) + if (has_port(from) && !has_used_port(from) && is_own_province(from)) + gen_action_use_port(from) } // Free Action: Enter/Leave Capital @@ -3937,6 +3954,11 @@ states.force_march = { remove_general_castra(game.selected_general) resume_take_actions() }, + + use_port(s) { + push_undo() + game.state = "use_port" + }, } // CARD: Frumentarii @@ -6024,6 +6046,11 @@ exports.view = function (state, player_name) { emperor_turns: game.emperor_turns, } + if (is_deluxe()) { + view.umarket = game.umarket + view.uport = game.uport + } + if (game.combat && states[game.state].show_battle) { view.combat = game.combat view.combat_region = game.where @@ -6140,6 +6167,14 @@ function gen_action_support(where, level) { gen_action("support", where << 3 | level) } +function gen_action_use_market(where) { + gen_action("use_market", where) +} + +function gen_action_use_port(where) { + gen_action("use_port", where) +} + function gen_action_card(c) { gen_action("card", c) } -- cgit v1.2.3