diff options
author | Joël Simoneau <simoneaujoel@gmail.com> | 2024-10-23 19:19:26 -0400 |
---|---|---|
committer | Joël Simoneau <simoneaujoel@gmail.com> | 2024-10-23 19:19:26 -0400 |
commit | 3654f1e6e0d9f3ce204c34ba8d090f23d30ee59d (patch) | |
tree | f024438916d67f29ab3d305515e0892f901c413e | |
parent | 6ae7f23ec0dc3ff03274aa5021e5a9c99aa66b2e (diff) | |
download | vijayanagara-3654f1e6e0d9f3ce204c34ba8d090f23d30ee59d.tar.gz |
Pass.
-rw-r--r-- | rules.js | 137 |
1 files changed, 137 insertions, 0 deletions
@@ -91,6 +91,7 @@ exports.view = function (state, role) { bk_inf: 0, ve_inf: 0, deck: [ this_card, deck_size, game.of_gods_and_kings ], + cylinder: game.cylinder, pieces: game.pieces, } @@ -197,9 +198,17 @@ exports.setup = function (seed, scenario, _options) { // Setup setup_standard() + setup_deck() + + goto_card() + return save_game() } +function setup_deck() { + game.deck = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ] +} + function setup_standard() { setup_piece(DS, DISC, 1, "S_ANDHRA") setup_piece(DS, ELITE, 1, S_MALWA) @@ -234,6 +243,128 @@ function setup_piece(faction, type, count, where) { } } + +// === SEQUENCE OF PLAY === + +function this_card() { + return game.deck[0] +} + +function goto_card() { + log_h1("C" + this_card()) + if (this_card() === "todo") + console.log("todo") + else + resume_event_card() +} + +function resume_event_card() { + clear_undo() + let did_1st = (did_option(SOP_COMMAND_DECREE) || did_option(SOP_EVENT_OR_COMMAND)) + let did_2nd = (did_option(SOP_COMMAND_DECREE) || did_option(SOP_EVENT_OR_COMMAND)) + if (did_1st && did_2nd) + end_card() + else + goto_eligible() +} + +function end_card() { + clear_undo() + + adjust_eligibility(DS) + adjust_eligibility(BK) + adjust_eligibility(VE) + + array_remove(game.deck, 0) + goto_card() +} + +function goto_eligible() { + game.current = next_eligible_faction() + if (game.current < 0) { + end_card() + } else { + game.state = "eligible" + game.op = { + limited: 0, + free: 0, + spaces: [], + where: -1, + pass: 1 + } + } +} + +function is_eligible(faction) { + return game.cylinder[faction] === ELIGIBLE +} + +function did_option(e) { + return ( + game.cylinder[DS] === e || + game.cylinder[BK] === e || + game.cylinder[VE] === e + ) +} + +function next_eligible_faction() { + let order = data.card_order[this_card()] + for (let faction of order) + if (is_eligible(faction)) + return faction + return -1 +} + +function adjust_eligibility(faction) { + if (game.cylinder[faction] === INELIGIBLE || game.cylinder[faction] === SOP_PASS || game.cylinder[faction] === SOP_LIMITED_COMMAND) + game.cylinder[faction] = ELIGIBLE + else if (game.cylinder[faction] !== ELIGIBLE) + game.cylinder[faction] = INELIGIBLE +} + +function goto_pass() { + push_undo() + + game.op = 0 + game.sa = 0 + + game.cylinder[game.current] = SOP_PASS + log_h2(faction_name[game.current] + " - Pass") + if (game.current === DS) { + log_resources(game.current, 3) + add_resources(game.current, 3) + } else { + log_resources(game.current, 1) + add_resources(game.current, 1) + } + resume_event_card() +} + +/* STATES */ + +states.eligible = { + disable_negotiation: true, + inactive: "Eligible Faction", + prompt() { + if (did_option(SOP_COMMAND_DECREE)) { + view.prompt = `${data.card_title[this_card()]}: Event or Command.` + } else if (did_option(SOP_EVENT_OR_COMMAND)) { + view.prompt = `${data.card_title[this_card()]}: Command & Decree.` + } else { + view.prompt = `${data.card_title[this_card()]}: Event or Command & Decree.` + } + view.actions.pass = 1 + }, + pass: goto_pass, +} + +/* UTILS */ + +function add_resources(faction, n) { + game.resources[faction] = Math.max(0, Math.min(24, game.resources[faction] + n)) +} + + /* LOGGING */ function log(msg) { @@ -326,6 +457,12 @@ function log_summary_remove(p) { log_summary("Removed % " + piece_name(p)) } +function log_resources(faction, n) { + if (n > 0) + log(faction_name[faction] + " Resources +" + n + ".") + else + log(faction_name[faction] + " Resources " + n + ".") +} // === MISC PIECE QUERIES === |