diff options
author | Joël Simoneau <simoneaujoel@gmail.com> | 2024-11-05 13:15:15 -0500 |
---|---|---|
committer | Joël Simoneau <simoneaujoel@gmail.com> | 2024-11-05 13:15:15 -0500 |
commit | 64d00d039aa3bf0aec0e6d453de34cd94ec5a51d (patch) | |
tree | b8a9d6cd36ca3899e9d40438a897d3ee1049da2e /rules.js | |
parent | 8ded7faaaa113d749546edfb21113d43ed406623 (diff) | |
download | vijayanagara-64d00d039aa3bf0aec0e6d453de34cd94ec5a51d.tar.gz |
Cavalry.
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 79 |
1 files changed, 74 insertions, 5 deletions
@@ -98,6 +98,7 @@ exports.view = function (state, role) { bk_inf: 0, ve_inf: 0, deck: [ this_card, deck_size, game.of_gods_and_kings ], + cavalry: game.cavalry, cylinder: game.cylinder, pieces: game.pieces, tributary: game.tributary, @@ -194,7 +195,7 @@ exports.setup = function (seed, scenario, _options) { control: [0, 0, 0], rebel: [null, 0, 0], // amir/raja rebel status pieces: Array(104).fill(AVAILABLE), // piece locations - cavalry: [0, 0, 0], + cavalry: Array(10).fill(AVAILABLE), deck: [], cmd: { type: null, @@ -261,6 +262,10 @@ function setup_standard() { setup_piece(VE, ELITE, 2, S_VE_INF_2) setup_piece(VE, ELITE, 2, S_VE_INF_3) setup_piece(VE, ELITE, 2, S_VE_INF_4) + + // Two cavalry to DS + set_cavalry_faction(0, DS) + set_cavalry_faction(1, DS) } function setup_piece(faction, type, count, where) { @@ -373,6 +378,11 @@ function goto_build() { game.state = "build" } +function goto_cavalry(n_cavalry) { + game.cmd.n_count = n_cavalry + game.state = "cavalry" +} + function goto_collect() { init_command("Collect") game.state = "collect" @@ -606,10 +616,24 @@ states.build = { } } +states.cavalry = { + prompt() { + view.prompt = `Gain Cavalry: Take ${game.cmd.n_count} calvary tokens` + + gen_take_cavalry(game.current) + }, + token(c) { + game.cmd.n_count -= 1 + set_cavalry_faction(c, game.current) + if (!game.cmd.n_count) + game.state = "command_decree" + + } +} + states.collect = { - // TODO : Add horses logic to trade prompt() { - view.prompt = `Collect tribute: Collect ${collect_count()} from half the Tributaries prosperity` + view.prompt = `Collect Tribute: Collect ${collect_count()} from half the Tributaries prosperity` gen_action_resources(DS) }, @@ -618,7 +642,7 @@ states.collect = { add_resources(DS, c) logi_resources(DS, c) game.decree = 0 - game.state = "command_decree" + goto_cavalry(2) } } @@ -897,7 +921,7 @@ states.trade = { add_resources(game.current, t) logi_resources(BK, t) game.decree = 0 - game.state = "command_decree" + goto_cavalry(trade_cavalry_count()) } } @@ -918,9 +942,12 @@ function gen_any_command() { view.actions.conscript = can_conscript() ? 1 : 0 view.actions.govern = can_govern() ? 1 : 0 view.actions.march = can_march() ? 1 : 0 + // view.actions.attack = can_attack() ? 1 : 0 } else if (game.current === BK || game.current === VE) { view.actions.rally = can_rally() ? 1 : 0 + // view.actions.migrate = can_migrate() ? 1 : 0 view.actions.rebel = can_rebel() ? 1 : 0 + // view.actions.attack = can_attack() ? 1 : 0 } } @@ -1317,6 +1344,43 @@ function piece_type(p) { throw "IMPOSSIBLE" } +/* CAVALRY */ + +function available_cavalry() { + let n = 0 + for (let c = 0; c <= LAST_CAVALRY; ++c) + if (game.cavalry[c] === AVAILABLE) + n += 1 + return n +} + +function gen_take_cavalry(faction) { + let can_place = false + for (let c = 0; c <= LAST_CAVALRY; ++c) { + if (game.cavalry[c] === AVAILABLE) { + gen_action_token(c) + can_place = true + } + } + if (!can_place && faction === game.current) { + for (let c = 0; c <= LAST_CAVALRY; ++c) { + if (game.cavalry[c] !== faction) + gen_action_token(c) + } + } + return can_place +} + +function set_cavalry_faction(c, f) { + game.cavalry[c] = f +} + +function trade_cavalry_count() { + if (game.bk_inf === 0) return 1; + if (game.bk_inf <= 2) return 2; + return 3; +} + /* UTILS */ function add_resources(faction, n) { @@ -1367,6 +1431,10 @@ function gen_action_space(s) { gen_action("space", s) } +function gen_action_token(t) { + gen_action("token", t) +} + /* LOGGING */ function log(msg) { @@ -1867,6 +1935,7 @@ const PIECE_FACTION_TYPE_NAME = [ [ "Temple", "Raja", null ], [ null, null, "Invader" ] ] +const LAST_CAVALRY = 9 // Sequence of Play options const ELIGIBLE = 0 |