From e374b1ef04542fdfd57a035011f2895560829fd7 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 21 Jun 2023 11:56:16 +0200 Subject: More UI improvements. --- play.js | 6 ++++-- rules.js | 68 +++++++++++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 52 insertions(+), 22 deletions(-) diff --git a/play.js b/play.js index 64d9aef..4b767bc 100644 --- a/play.js +++ b/play.js @@ -1119,13 +1119,15 @@ function on_update() { action_button("spend_senate", "Spend Senate") action_button("roll", "Roll") - action_button("hold_games", "Hold Games") - action_button("place_militia", "Place Militia") action_button("disperse_mob", "Disperse Mob") action_button("train_legions", "Train Legions") action_button("add_legion_to_army", "Add Legion to Army") + action_button("hold_games", "Hold Games") + + action_button("place_militia", "Place Militia") + action_button("amphitheater", "Amphitheater") action_button("basilica", "Basilica") action_button("limes", "Limes") diff --git a/rules.js b/rules.js index 86550dc..8f436cb 100644 --- a/rules.js +++ b/rules.js @@ -519,7 +519,7 @@ function can_build_improvement(province) { return false if (has_rival_emperor(province)) return false - if (has_enemy_army_in_capital(province)) + if (has_enemy_general_in_capital(province)) return false return true } @@ -629,12 +629,8 @@ function is_emperor(governor) { return false } -function has_enemy_army_in_capital(where) { - if (is_enemy_general(get_capital_general(where))) - return true - if (has_militia(where) && is_enemy_governor(get_province_governor(where))) - return true - return false +function has_enemy_general_in_capital(where) { + return is_enemy_general(get_capital_general(where)) } function has_enemy_army_in_province(where) { @@ -723,6 +719,10 @@ function has_reduced_legions_in_army(id) { return find_reduced_legion_in_army(id) >= 0 } +function has_lone_militia(where) { + return has_militia(where) && get_capital_general(where) < 0 +} + function count_units_in_army(id) { let n = 0 for (let i = 0; i < LEGION_COUNT; ++i) @@ -779,6 +779,11 @@ function eliminate_barbarian(id) { set_barbarian_inactive(id) } +function flip_discard_to_available() { + game.draw[game.current] = game.discard[game.current] + game.discard[game.current] = [] +} + // === SETUP === states.setup_province = { @@ -1090,7 +1095,6 @@ 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 @@ -1115,6 +1119,10 @@ states.take_actions_governor = { // Hold Games if (has_mob(where)) { + view.actions.disperse_mob = 0 + view.actions.hold_games = 0 + if (has_lone_militia(where) && mip >= 1) + view.actions.disperse_mob = 1 if (pip >= 2) view.actions.hold_games = 1 } @@ -1133,7 +1141,7 @@ states.take_actions_governor = { // Initiate Battle with Militia not stacked with General if (!has_militia_battled(where)) { - if (has_militia(where) && !is_own_general(get_capital_general(where))) + if (has_lone_militia(where)) gen_initiate_battle(where) } } @@ -1618,7 +1626,7 @@ function gen_initiate_battle(where) { gen_action_barbarian(id) }) if (is_enemy_province(where)) { - if (has_militia(where) && get_capital_general(where) < 0) + if (has_lone_militia(where)) gen_action_militia(where) } } @@ -1739,9 +1747,9 @@ function roll_defender_dice() { function gen_hits_militia() { if (has_militia(game.misc.where)) { gen_action_militia(game.misc.where) - return true + return false } - return false + return true } function gen_hits_barbarians(tribe) { @@ -2001,6 +2009,12 @@ states.buy_trash = { function goto_end_of_turn() { // TODO: add mobs // TODO: flip inactive barbarians + goto_refill_hand() +} + +function goto_refill_hand() { + if (current_draw().length === 0) + flip_discard_to_available() game.state = "refill_hand" } @@ -2008,8 +2022,9 @@ states.refill_hand = { prompt() { view.prompt = "Refill your hand." let hand = current_hand() - if (hand.length < 5) { - for (let c of current_draw()) + let draw = current_draw() + if (hand.length < 5 && draw.length > 0) { + for (let c of draw) gen_action_card(c) } else { view.actions.done = 1 @@ -2017,12 +2032,12 @@ states.refill_hand = { }, card(c) { push_undo() - set_delete(current_draw(), c) - set_add(current_hand(), c) - if (current_draw().length === 0) { - game.draw[game.current] = game.discard[game.current] - game.discard[game.current] = [] - } + let hand = current_hand() + let draw = current_draw() + set_delete(draw, c) + set_add(hand, c) + if (draw.length === 0) + flip_discard_to_available() }, done() { clear_undo() @@ -2135,6 +2150,7 @@ exports.setup = function (seed, scenario, options) { game.events = setup_events() + /* game.market = [ setup_market_pile(CARD_M2), setup_market_pile(CARD_S2), @@ -2146,6 +2162,18 @@ exports.setup = function (seed, scenario, options) { setup_market_pile(CARD_S4), setup_market_pile(CARD_P4), ] + */ + game.market = [ + setup_market_pile(CARD_M2), + setup_market_pile(CARD_M3), + setup_market_pile(CARD_M4), + setup_market_pile(CARD_S2), + setup_market_pile(CARD_S3), + setup_market_pile(CARD_S4), + setup_market_pile(CARD_P2), + setup_market_pile(CARD_P3), + setup_market_pile(CARD_P4), + ] setup_barbarians(ALAMANNI, ALAMANNI_HOMELAND) setup_barbarians(FRANKS, FRANKS_HOMELAND) -- cgit v1.2.3