diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-06-21 01:13:46 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-07-07 18:39:37 +0200 |
commit | 2d5f74c94b1ac69598c0b00a2bfb3601a5703c61 (patch) | |
tree | 4602875933cae6a116291e3d0500549e50814d0f /rules.js | |
parent | d68a8f5426e335fce66c8b366646657115bbe65a (diff) | |
download | time-of-crisis-2d5f74c94b1ac69598c0b00a2bfb3601a5703c61.tar.gz |
Streamline UI action flow.
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 259 |
1 files changed, 133 insertions, 126 deletions
@@ -352,8 +352,8 @@ function get_barbarian_tribe(id) { // === BOARD STATE === -function is_no_place_governor(province) { - return province >= game.support.length +function is_no_place_governor(where) { + return where >= game.support.length } function get_support(province) { return game.support[province] } @@ -652,6 +652,8 @@ function spend_ip(type, n) { } function can_place_governor(where) { + if (is_no_place_governor(where)) + return false if (is_own_province(where)) return false // Recalled or already attempted to place. @@ -783,7 +785,7 @@ states.setup_province = { prompt() { view.prompt = "Select a starting Province." for (let where = 2; where <= 12; ++where) - if (is_neutral_province(where)) + if (is_neutral_province(where) && !is_no_place_governor(where)) gen_action("capital", where) }, capital(where) { @@ -1039,8 +1041,15 @@ function action_take_actions_governor(id) { } function action_take_actions_general(id) { - game.who = id - game.state = "take_actions_general" + if (is_own_general(id)) { + game.who = id + game.state = "take_actions_general" + } else { + if (game.state === "take_actions_general") + goto_battle_vs_general(get_general_location(game.who), game.who, id) + else + goto_battle_vs_general(get_general_location(game.who), -1, id) + } } function action_take_actions_end_actions() { @@ -1066,12 +1075,13 @@ states.take_actions_governor = { let where = get_governor_location(game.who) - prompt_take_actions("Take Governor Actions", game.who, -1) + prompt_take_actions("Take Actions", game.who, -1) // Recruit Governor if (where === UNAVAILABLE) { + view.actions.recruit_governor = 0 if (sip >= game.who % 6) - view.actions.recruit = 1 + view.actions.recruit_governor = 1 } // Place Governor @@ -1080,9 +1090,15 @@ states.take_actions_governor = { } if (is_province(where)) { + view.actions.hold_games = 0 + view.actions.place_militia = 0 + view.actions.amphitheater = 0 + view.actions.basilica = 0 + view.actions.limes = 0 + // Recall Governor if (sip >= 2) - view.actions.recall = 1 + gen_action_support(where, 0) // Increase Support Level let support = game.support[where] @@ -1104,10 +1120,15 @@ states.take_actions_governor = { } // Build an Improvement - if (!has_amphitheater(where) || !has_basilica(where) || !has_limes(where)) { - if (can_build_improvement(where)) - if (pip >= 3) - view.actions.build_improvement = 1 + if (can_build_improvement(where)) { + if (pip >= 3) { + if (!has_amphitheater(where)) + view.actions.amphitheater = 1 + if (!has_basilica(where)) + view.actions.basilica = 1 + if (!has_limes(where)) + view.actions.limes = 1 + } } // Initiate Battle with Militia not stacked with General @@ -1121,41 +1142,34 @@ states.take_actions_governor = { end_actions: action_take_actions_end_actions, card: action_take_actions_card, governor: action_take_actions_governor, - general(id) { - if (is_own_general(id)) - action_take_actions_general(id) - else - goto_battle_vs_general(get_governor_location(game.who), -1, id) - }, - recruit() { + general: action_take_actions_general, + + recruit_governor() { push_undo() log("Recruited Governor " + (game.who % 6) + ".") spend_ip(SENATE, game.who % 6) set_governor_location(game.who, AVAILABLE) }, - recall() { - push_undo() - let where = get_governor_location(game.who) - log("Recalled Governor from S" + where + ".") - spend_ip(SENATE, 2) - set_placed_governor(where) - remove_governor(where) - update_neutral_italia() - }, - support() { + + support(arg) { push_undo() - let where = get_governor_location(game.who) - let support = game.support[where] - log("Built Support in S" + where + ".") - spend_ip(POPULACE, support + 1) - game.support[where] = support + 1 + let level = arg & 7 + if (level > 0) + improve_support() + else + recall_governor() }, + place_militia() { push_undo() let where = get_governor_location(game.who) spend_ip(POPULACE, 2) add_militia(where) }, + capital() { + this.place_militia() + }, + hold_games() { push_undo() let where = get_governor_location(game.who) @@ -1163,29 +1177,42 @@ states.take_actions_governor = { spend_ip(POPULACE, 3) remove_one_mob(where) }, - build_improvement() { + + region(where) { + push_undo() + spend_ip(SENATE, 1) + game.misc = { spend: 1, where: where } + game.state = "place_governor" + }, + + amphitheater() { push_undo() - game.state = "build_improvement" spend_ip(POPULACE, 3) + let where = get_governor_location(game.who) + add_amphitheater(where) + log("Built Amphitheater in S" + where + ".") }, - initiate_battle() { + basilica() { push_undo() - spend_ip(MILITARY, 1) - game.state = "initiate_battle" - game.misc = { attacker: -1, where: get_governor_location(game.who) } - set_militia_battled(get_governor_location(game.who)) + spend_ip(POPULACE, 3) + let where = get_governor_location(game.who) + add_basilica(where) + log("Built Basilica in S" + where + ".") }, - region(where) { + limes() { push_undo() - spend_ip(SENATE, 1) - game.misc = { spend: 1, where: where } - game.state = "place_governor" + spend_ip(POPULACE, 3) + let where = get_governor_location(game.who) + add_limes(where) + log("Built Limes in S" + where + ".") }, barbarian(id) { + push_undo() goto_battle_vs_barbarian(get_governor_location(game.who), -1, id) }, rival_emperor(id) { + push_undo() goto_battle_vs_rival_emperor(get_governor_location(game.who), -1, id) }, } @@ -1195,12 +1222,13 @@ states.take_actions_general = { let [ mip, sip, pip ] = game.ip let where = get_general_location(game.who) - prompt_take_actions("Take General Actions", -1, game.who) + prompt_take_actions("Take Actions", -1, game.who) // Recruit General if (where === UNAVAILABLE) { + view.actions.recruit_general = 0 if (mip >= game.who % 6) - view.actions.recruit = 1 + view.actions.recruit_general = 1 } // Create Army @@ -1210,11 +1238,14 @@ states.take_actions_general = { } if (is_region(where)) { - // Add Legion to Army - if (is_own_province(where)) { - let cost = count_legions_in_army(game.who) + 1 - if (mip >= cost) - view.actions.add_legion_to_army = 1 + view.actions.disperse_mob = 0 + view.actions.train_legions = 0 + view.actions.add_legion_to_army = 0 + + // Disperse Mob + if (has_mob(where)) { + if (mip >= 1) + view.actions.disperse_mob = 1 } // Train Legions @@ -1223,10 +1254,11 @@ states.take_actions_general = { view.actions.train_legions = 1 } - // Disperse Mob - if (has_mob(where)) { - if (mip >= 1) - view.actions.disperse_mob = 1 + // Add Legion to Army + if (is_own_province(where)) { + let cost = count_legions_in_army(game.who) + 1 + if (mip >= cost) + view.actions.add_legion_to_army = 1 } if (!has_general_battled(game.who)) { @@ -1247,29 +1279,20 @@ states.take_actions_general = { } } } - }, end_actions: action_take_actions_end_actions, card: action_take_actions_card, governor: action_take_actions_governor, - general(id) { - if (is_own_general(id)) - action_take_actions_general(id) - else - goto_battle_vs_general(get_general_location(game.who), game.who, id) - }, - recruit() { + general: action_take_actions_general, + + recruit_general() { push_undo() log("Recruited General " + (game.who % 6) + ".") spend_ip(MILITARY, game.who % 6) set_general_location(game.who, AVAILABLE) }, - create_army() { - push_undo() - spend_ip(MILITARY, 1) - game.state = "create_army" - }, + add_legion_to_army() { push_undo() log("Added Legion to Army.") @@ -1288,7 +1311,8 @@ states.take_actions_general = { if (get_general_location(game.who) === AVAILABLE) create_army(to) else - move_army_to(game.who, to, false) + // XXX move_army_to(game.who, to, false) + move_army_to(game.who, to, true) }, capital(to) { push_undo() @@ -1299,6 +1323,7 @@ states.take_actions_general = { else move_army_to(game.who, to, true) }, + enter() { push_undo() set_general_inside_capital(game.who) @@ -1308,16 +1333,39 @@ states.take_actions_general = { set_general_outside_capital(game.who) }, - initiate_battle() { + barbarian(id) { push_undo() - spend_ip(MILITARY, 1) - game.state = "initiate_battle" - game.misc = { attacker: game.who, where: get_general_location(game.who) } + goto_battle_vs_barbarian(get_general_location(game.who), game.who, id) + }, + rival_emperor(id) { + push_undo() + goto_battle_vs_rival_emperor(get_general_location(game.who), game.who, id) + }, + militia(where) { + push_undo() + goto_battle_vs_militia(get_general_location(game.who), game.who) }, +} + +// ACTION: IMPROVE SUPPORT - barbarian(id) { goto_battle_vs_barbarian(get_general_location(game.who), game.who, id) }, - rival_emperor(id) { goto_battle_vs_rival_emperor(get_general_location(game.who), game.who, id) }, - militia(where) { goto_battle_vs_militia(get_general_location(game.who), game.who) }, +function improve_support() { + let where = get_governor_location(game.who) + let support = game.support[where] + log("Built Support in S" + where + ".") + spend_ip(POPULACE, support + 1) + game.support[where] = support + 1 +} + +// ACTION: RECALL GOVERNOR + +function recall_governor() { + let where = get_governor_location(game.who) + log("Recalled Governor from S" + where + ".") + spend_ip(SENATE, 2) + set_placed_governor(where) + remove_governor(where) + update_neutral_italia() } // ACTION: PLACE GOVERNOR @@ -1416,14 +1464,11 @@ states.place_governor = { prompt(`Place Governor: ${sip} Senate. Rolling ${votes} dice. ${need} votes needed.`) - if (sip >= 1) - view.actions.spend = 1 - else - view.actions.spend = 0 + view.actions.spend_senate = (sip >= 1) view.actions.roll = 1 }, - spend() { + spend_senate() { push_undo() spend_ip(SENATE, 1) game.misc.spend += 1 @@ -1457,40 +1502,6 @@ states.place_governor = { }, } -// ACTION: BUILD IMPROVEMENT - -states.build_improvement = { - prompt() { - let where = get_governor_location(game.who) - view.selected_governor = game.who - prompt("Build Improvement.") - if (!has_amphitheater(where)) - view.actions.amphitheater = 1 - if (!has_basilica(where)) - view.actions.basilica = 1 - if (!has_limes(where)) - view.actions.limes = 1 - }, - amphitheater() { - let where = get_governor_location(game.who) - add_amphitheater(where) - log("Built Amphitheater in S" + where + ".") - game.state = "take_actions_governor" - }, - basilica() { - let where = get_governor_location(game.who) - add_basilica(where) - log("Built Basilica in S" + where + ".") - game.state = "take_actions_governor" - }, - limes() { - let where = get_governor_location(game.who) - add_limes(where) - log("Built Limes in S" + where + ".") - game.state = "take_actions_governor" - }, -} - // ACTION: CREATE ARMY function gen_create_army() { @@ -1502,7 +1513,6 @@ function gen_create_army() { } function create_army(where) { - push_undo() spend_ip(MILITARY, 1) log("Created Army in S" + where + ".") set_general_location(game.who, where) @@ -1528,8 +1538,8 @@ function gen_move_army() { } function gen_move_to_region(to) { - if (is_province(to) && can_enter_capital(to)) - gen_action_capital(to) +// if (is_province(to) && can_enter_capital(to)) +// gen_action_capital(to) gen_action_region(to) } @@ -1542,7 +1552,8 @@ states.move_army_at_sea = { }, region(to) { push_undo() - move_army_to(game.who, to, false) + // XXX move_army_to(game.who, to, false) + move_army_to(game.who, to, true) }, capital(to) { push_undo() @@ -1567,25 +1578,21 @@ function move_army_to(who, to, go_inside) { // === ACTION: INITIATE BATTLE === function goto_battle_vs_general(where, attacker, target) { - push_undo() log("Initiate Battle vs " + GENERAL_NAME[target] + " in S" + where) goto_battle("general", where, attacker, target) } function goto_battle_vs_barbarian(where, attacker, target) { - push_undo() log("Initiate Battle vs " + BARBARIAN_NAME[target] + " in S" + where) goto_battle("barbarians", where, attacker, get_barbarian_tribe(target)) } function goto_battle_vs_rival_emperor(where, attacker, target) { - push_undo() log("Initiate Battle vs Rival Emperor in S" + where) goto_battle("rival_emperor", where, attacker, target) } function goto_battle_vs_militia(where, attacker) { - push_undo() log("Initiate Battle vs Militia in S" + where) goto_battle("militia", where, attacker, -1) } @@ -2093,8 +2100,8 @@ exports.setup = function (seed, scenario, options) { // grab bag of temporary data for the current procedure misc: null, - support: new Array(12).fill(1), - mobs: new Array(12).fill(0), + support: new Array(player_count * 3).fill(1), + mobs: new Array(player_count * 3).fill(0), militia: 0, quaestor: 0, castra: 0, |