From 6b3319a0b88c234a7a0c5ed72954c381ec1ec327 Mon Sep 17 00:00:00 2001 From: Joël Simoneau Date: Wed, 19 Mar 2025 22:25:42 -0400 Subject: Transfer cavalry --- rules.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-) (limited to 'rules.js') diff --git a/rules.js b/rules.js index 6706763..5cdab7f 100644 --- a/rules.js +++ b/rules.js @@ -155,18 +155,17 @@ exports.view = function (state, role) { else view.prompt = "Unknown state: " + game.state - if (states[game.state]) if (!states[game.state].disable_negotiation) { view.actions.ask_resources = 1 if (game.resources[game.current] > 0) view.actions.transfer_resources = 1 else view.actions.transfer_resources = 0 - if (game.cavalry[game.current] > 0) + if (n_cavalry(game.current) > 0) view.actions.transfer_cavalry = 1 else view.actions.transfer_cavalry = 0 - if (true) // TODO: can_ask_cavalry() + if (can_ask_cavalry()) view.actions.ask_cavalry = 1 else view.actions.ask_cavalry = 0 @@ -612,7 +611,7 @@ function is_timurid() { /* STATES */ states.eligible = { - disable_negotiation: true, + disable_negotiation: false, inactive: "Eligible Faction", prompt() { if (!did_option(SOP_COMMAND_DECREE) && !did_option(SOP_EVENT_OR_COMMAND)) { @@ -3333,6 +3332,10 @@ function gen_action_token(t) { gen_action("token", t) } +function gen_action_faction(f) { + gen_action("space", 17+f) +} + function gen_choose_faction(faction) { if (game.current === faction) { switch (faction) { @@ -3472,6 +3475,10 @@ states.transfer_resources = { }, } +function can_ask_cavalry() { + return game.cavalry.some(c => ![-1, game.current].includes(c)) +} + function action_ask_cavalry() { push_undo() game.transfer = { @@ -3530,6 +3537,48 @@ states.give_cavalry = { }, } +function action_transfer_cavalry() { + push_undo() + game.transfer = { + current: game.current, + state: game.state, + count: null + } + game.state = "transfer_cavalry" +} + +states.transfer_cavalry = { + disable_negotiation: true, + prompt() { + view.prompt = "Transfer Cavalry tokens to another faction." + if (n_cavalry(game.current) >= 1) { + if (!is_player_ds()) + gen_action_faction(DS) + if (!is_player_bk()) + gen_action_faction(BK) + if (!is_player_ve()) + gen_action_faction(VE) + } + if (game.transfer.count) + view.actions.done = 1 + else + view.actions.done = 0 + }, + space(s) { + let to = s - 17 + if (!game.transfer.count) + game.transfer.count = [0, 0, 0] + let c = find_cavalry(game.current) + game.transfer.count[to]++ + set_cavalry_faction(c, to) + }, + done() { + for (let i = 0; i < 3; ++i) + if (game.transfer.count[i] > 0) + log_transfer_cavalry(game.current, i, game.transfer.count[i]) + end_negotiation() + }, +} function end_negotiation() { game.current = game.transfer.current -- cgit v1.2.3