From 593a5fb24156af994ab0a37b5bd3dc13a99c8e78 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 5 Jul 2023 15:13:50 +0200 Subject: Don't battle twice with Militia. --- rules.js | 89 +++++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 29 deletions(-) (limited to 'rules.js') diff --git a/rules.js b/rules.js index aa9b107..28638e1 100644 --- a/rules.js +++ b/rules.js @@ -596,6 +596,10 @@ function has_militia_battled(province) { return game.mbattled & (1 << province) function set_militia_battled(province) { game.mbattled |= (1 << province) } function clear_militia_battled(province) { game.mbattled &= ~(1 << province) } +function has_militia_force_marched(province) { return game.mbattled & (4096 << province) } +function set_militia_force_marched(province) { game.mbattled |= (4096 << province) } +function clear_militia_force_marched(province) { game.mbattled &= ~(4096 << province) } + // === COMPOUND STATE === function get_selected_region() { @@ -1092,6 +1096,7 @@ function eliminate_rival_emperor(id) { function eliminate_militia(where) { remove_militia(where) clear_militia_battled(where) + clear_militia_force_marched(where) remove_militia_castra(where) } @@ -1961,7 +1966,7 @@ states.take_actions = { game.selected_militia = -1 } else { push_undo() - goto_battle_vs_general(get_general_location(game.selected_general), game.selected_general, id) + goto_battle_vs_general(get_selected_region(), game.selected_general, id, false) } }, @@ -1972,10 +1977,20 @@ states.take_actions = { game.selected_militia = where } else { push_undo() - goto_battle_vs_militia(where, game.selected_general) + goto_battle_vs_militia(where, game.selected_general, false) } }, + barbarian(id) { + push_undo() + goto_battle_vs_barbarian(get_selected_region(), game.selected_general, id, false) + }, + + rival_emperor(id) { + push_undo() + goto_battle_vs_rival_emperor(get_selected_region(), game.selected_general, id, false) + }, + recruit_governor() { push_undo() log("Recruit Governor " + (game.selected_governor % 6) + ".") @@ -2088,16 +2103,6 @@ states.take_actions = { move_army_to(game.selected_general, where) enter_capital() }, - - barbarian(id) { - push_undo() - goto_battle_vs_barbarian(get_selected_region(), game.selected_general, id) - }, - - rival_emperor(id) { - push_undo() - goto_battle_vs_rival_emperor(get_selected_region(), game.selected_general, id) - }, } // ACTION: BUILD IMPROVEMENT @@ -3201,6 +3206,10 @@ function can_play_force_march() { if (has_general_battled(id) && !has_general_force_marched(id)) return true } + for (let i = 0; i < 12; ++i) { + if (has_lone_militia(i) && has_militia_battled(i) && is_own_province(i)) + return true + } } return false } @@ -3220,6 +3229,10 @@ states.force_march_who = { if (is_region(where) && has_general_battled(id) && !has_general_force_marched(id)) gen_action_general(id) } + for (let i = 0; i < 12; ++i) { + if (has_lone_militia(i) && has_militia_battled(i) && is_own_province(i)) + gen_action_militia(i) + } }, general(id) { log("Force March.") @@ -3229,6 +3242,14 @@ states.force_march_who = { game.selected_militia = -1 game.state = "force_march" }, + militia(where) { + log("Force March.") + set_militia_force_marched(where) + game.selected_governor = -1 + game.selected_general = -1 + game.selected_militia = where + game.state = "force_march" + }, } states.force_march = { @@ -3273,22 +3294,22 @@ states.force_march = { general(id) { push_undo() - goto_battle_vs_general(get_general_location(game.selected_general), game.selected_general, id) + goto_battle_vs_general(get_general_location(game.selected_general), game.selected_general, id, true) }, militia(where) { push_undo() - goto_battle_vs_militia(where, game.selected_general) + goto_battle_vs_militia(where, game.selected_general, true) }, barbarian(id) { push_undo() - goto_battle_vs_barbarian(get_selected_region(), game.selected_general, id) + goto_battle_vs_barbarian(get_selected_region(), game.selected_general, id, true) }, rival_emperor(id) { push_undo() - goto_battle_vs_rival_emperor(get_selected_region(), game.selected_general, id) + goto_battle_vs_rival_emperor(get_selected_region(), game.selected_general, id, true) }, region(where) { @@ -3552,24 +3573,30 @@ function play_spiculum() { game.state = "spiculum" } -function goto_battle_vs_general(where, attacker, target) { - goto_battle("general", where, attacker, target) +function goto_battle_vs_general(where, attacker, target, is_force_march) { + goto_battle("general", where, attacker, target, is_force_march) } -function goto_battle_vs_barbarian(where, attacker, target) { +function goto_battle_vs_barbarian(where, attacker, target, is_force_march) { let tribe = get_barbarian_tribe(target) - goto_battle("barbarians", where, attacker, tribe) + goto_battle("barbarians", where, attacker, tribe, is_force_march) } -function goto_battle_vs_rival_emperor(where, attacker, target) { - goto_battle("rival_emperor", where, attacker, target) +function goto_battle_vs_rival_emperor(where, attacker, target, is_force_march) { + goto_battle("rival_emperor", where, attacker, target, is_force_march) } -function goto_battle_vs_militia(where, attacker) { - goto_battle("militia", where, attacker, -1) +function goto_battle_vs_militia(where, attacker, is_force_march) { + goto_battle("militia", where, attacker, -1, is_force_march) } -function goto_battle(type, where, attacker, target) { +function can_militia_battle_with_army(where, attacker, is_force_march) { + if (attacker >= 0 && (!has_militia_battled(where) || is_force_march)) + return 1 + return 0 +} + +function goto_battle(type, where, attacker, target, is_force_march) { log_h2("Battle in %" + where) spend_military(1) game.where = where @@ -3580,11 +3607,15 @@ function goto_battle(type, where, attacker, target) { dtaken: 0, ataken: 0, staken: 0, dhits: 0, ahits: 0, shits: 0, killed: 0, + militia: can_militia_battle_with_army(where, attacker, is_force_march) } game.state = "initiate_battle" if (attacker >= 0) { - if (is_general_inside_capital(attacker)) + if (is_general_inside_capital(attacker)) { remove_militia_castra(where) + if (has_militia(where)) + set_militia_battled(where) + } remove_general_castra(attacker) set_general_battled(attacker) } else { @@ -3766,7 +3797,7 @@ function roll_general_dice(general) { n += roll_dice(barbarians, 4 + drm) } - if (is_general_inside_capital(general) && has_militia(game.where)) { + if (is_general_inside_capital(general) && has_militia(game.where) && game.combat.militia) { log("Militia") n += roll_dice(1, 5 + drm) } @@ -3898,7 +3929,7 @@ function gen_hits_barbarians(tribe) { function has_hits_general(general) { let army = ARMY + general - if (is_general_inside_capital(general) && has_militia(game.where)) + if (is_general_inside_capital(general) && has_militia(game.where) && game.combat.militia) return true for (let id = 3; id < game.barbarians.length; ++id) if (get_barbarian_location(id) === army) @@ -3914,7 +3945,7 @@ function gen_hits_general(general) { let done = false - if (is_general_inside_capital(general) && has_militia(game.where)) { + if (is_general_inside_capital(general) && has_militia(game.where) && game.combat.militia) { gen_action_militia(game.where) done = true } -- cgit v1.2.3