From c747b7413c84a3f33b61cf547506955a8c3c5729 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 2 Aug 2024 15:42:14 +0200 Subject: v2: market --- play.js | 7 +++++++ rules.js | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/play.js b/play.js index 4bb85d2..42352b6 100644 --- a/play.js +++ b/play.js @@ -1609,6 +1609,13 @@ function on_update() { action_button("enter", "Enter Capital") action_button("leave", "Leave Capital") + action_button("mip_to_sip", "M > S") + action_button("mip_to_pip", "M > P") + action_button("sip_to_mip", "S > M") + action_button("sip_to_pip", "S > P") + action_button("pip_to_mip", "P > M") + action_button("pip_to_sip", "P > S") + action_button("automatic", "Automatic") action_button("spend_military", "Spend Military") action_button("spend_senate", "Spend Senate") diff --git a/rules.js b/rules.js index a5106d8..61aed2a 100644 --- a/rules.js +++ b/rules.js @@ -608,6 +608,9 @@ function has_militia_force_marched(province) { return game.mbattled & (4096 << p function set_militia_force_marched(province) { game.mbattled |= (4096 << province) } function clear_militia_force_marched(province) { game.mbattled &= ~(4096 << province) } +function has_used_market(province) { return game.umarket & (1 << province) } +function set_used_market(province) { game.umarket |= (1 << province) } + function has_used_port(province) { return game.uport & (1 << province) } function set_used_port(province) { game.uport |= (1 << province) } @@ -1349,6 +1352,7 @@ function goto_start_turn() { game.combat_legacy = 0 if (is_deluxe()) { + game.umarket = 0 game.uport = 0 } @@ -1934,6 +1938,10 @@ 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 } @@ -2116,6 +2124,14 @@ 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 @@ -2375,6 +2391,57 @@ states.take_actions = { else enter_capital() }, + + market() { + push_undo() + game.state = "use_market" + }, +} + +// IMPROVEMENT: MARKET + +function use_market_effect(mip, sip, pip) { + let where = get_governor_location(game.selected_governor) + log("Used Market in %" + where + ".") + game.mip += mip + game.sip += sip + game.pip += pip + game.state = "take_actions" + set_used_market(where) +} + +states.use_market = { + inactive: "Market", + prompt() { + prompt(`Market: ${game.mip} military, ${game.sip} senate, ${game.pip} populace.`) + if (game.mip > 0) { + view.actions.mip_to_sip = 1 + view.actions.mip_to_pip = 1 + } else { + view.actions.mip_to_sip = 0 + view.actions.mip_to_pip = 0 + } + if (game.sip > 0) { + view.actions.sip_to_mip = 1 + view.actions.sip_to_pip = 1 + } else { + view.actions.sip_to_mip = 0 + view.actions.sip_to_pip = 0 + } + if (game.pip > 0) { + view.actions.pip_to_mip = 1 + view.actions.pip_to_sip = 1 + } else { + view.actions.pip_to_mip = 0 + view.actions.pip_to_sip = 0 + } + }, + mip_to_sip() { use_market_effect(-1, 1, 0) }, + mip_to_pip() { use_market_effect(-1, 0, 1) }, + sip_to_mip() { use_market_effect(1, -1, 0) }, + sip_to_pip() { use_market_effect(0, -1, 1) }, + pip_to_mip() { use_market_effect(1, 0, -1) }, + pip_to_sip() { use_market_effect(0, 1, -1) }, } // ACTION: BUILD IMPROVEMENT -- cgit v1.2.3