diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-06-21 17:45:42 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-07-07 18:39:37 +0200 |
commit | 6a6a356451aeb720a7e0cac4c1bb9eb1c99eef05 (patch) | |
tree | f7503e47f7a5672b0c5ca41d98b509b65b1c5d8e | |
parent | 36535d6c382597e80dc88d619ff0924109fe6026 (diff) | |
download | time-of-crisis-6a6a356451aeb720a7e0cac4c1bb9eb1c99eef05.tar.gz |
Support checks.
-rw-r--r-- | rules.js | 117 |
1 files changed, 108 insertions, 9 deletions
@@ -1503,9 +1503,11 @@ states.take_actions = { disperse_mob() { push_undo() let where = get_selected_region() - let n = 1 + let n = 0 + if (has_militia(where)) + n += 1 if (game.selected_general >= 0) - n = count_units_in_army(game.selected_general) + n += count_units_in_army(game.selected_general) n = Math.min(game.mobs[where], n) log("Disperse " + n + " Mobs in S" + where) game.mobs[where] -= n @@ -2248,9 +2250,105 @@ function end_battle() { // === SUPPORT CHECK === function goto_support_check() { + game.count = 0 + resume_support_check() +} + +function is_any_rival_emperor_or_pretender() { + for (let i = 0; i < 3; ++i) + if (game.rival_emperors[i] !== UNAVAILABLE) + return true + for (let where = 0; where < 12; ++where) + if (is_seat_of_power(where) && is_enemy_province(where)) + return true + return false +} + +function resume_support_check() { + for (let where = 0; where < 12; ++where) { + if ((game.count & (1 << where)) === 0) { + if (is_own_province(where)) { + if (has_active_barbarians(where) || has_rival_emperor(where) || has_enemy_general_in_capital(where)) { + game.state = "support_check" + return + } + } + } + } + goto_support_check_emperor() +} + +states.support_check = { + prompt() { + prompt("Support Check: Reduce support where active Barbarians, Rival Emperors or opponent armies in capital.") + view.color = POPULACE + for (let where = 0; where < 12; ++where) + if ((game.count & (1 << where)) === 0) + if (is_own_province(where)) + if (has_active_barbarians(where) || has_rival_emperor(where) || has_enemy_general_in_capital(where)) + gen_action_region(where) + }, + region(where) { + push_undo() + game.count |= (1 << where) + if (game.support[where] > 1) + game.support[where] -= 1 + else + remove_governor(where) + resume_support_check() + }, +} + +function goto_support_check_emperor() { + if (is_own_province(ITALIA) && is_any_rival_emperor_or_pretender()) { + game.state = "support_check_emperor" + return + } + goto_support_check_mobs() +} + +states.support_check_emperor = { + prompt() { + prompt("Support Check: Reduce support in Italia for Rival Emperor and/or Pretender.") + view.color = POPULACE + gen_action_region(where) + }, + region(where) { + push_undo() + game.count |= (1 << where) + if (game.support[where] > 1) + game.support[where] -= 1 + else + remove_governor(where) + goto_support_check_mobs() + }, +} + +function goto_support_check_mobs() { + for (let where = 0; where < 12; ++where) { + if (is_own_province(where) && game.mobs[where] >= game.support[where]) { + game.state = "support_check_mobs" + return + } + } goto_expand_pretender_empire() } +states.support_check_mobs = { + prompt() { + prompt("Support Check: Remove Governors where number of Mobs exceed support.") + view.color = POPULACE + for (let where = 0; where < 12; ++where) + if (is_own_province(where) && game.mobs[where] >= game.support[where]) + gen_action_region(where) + }, + region(where) { + push_undo() + remove_governor(where) + goto_support_check_mobs() + }, +} + // === EXPAND PRETENDER EMPIRE === function goto_expand_pretender_empire() { @@ -2384,12 +2482,13 @@ states.grow_mobs = { prompt() { prompt("Grow Mobs in each province you govern.") view.color = POPULACE - for_each_governor((id, where) => { - if (is_province(where) && has_mob(where) && !has_amphitheater(where)) - gen_action_region(where) - }) + for (let where = 0; where < 12; ++where) + if ((game.count & (1 << where)) === 0) + if (is_own_province(where) && has_mob(where) && !has_amphitheater(where)) + gen_action_region(where) }, region(where) { + push_undo() game.count |= (1 << where) add_one_mob(where) goto_grow_mobs() @@ -2411,15 +2510,15 @@ states.flip_inactive_barbarians = { prompt("Flip all inactive barbarians in your provinces to their active side.") view.color = POPULACE let tribe_count = get_tribe_count() - for_each_governor((id, where) => { - if (is_province(where)) { + for (let where = 0; where < 12; ++where) { + if (is_own_province(where)) { for (let tribe = 0; tribe < tribe_count; ++tribe) { let id = find_inactive_barbarian_of_tribe(where, tribe) if (id >= 0) gen_action_barbarian(id) } } - }) + } }, barbarian(target) { let where = get_barbarian_location(target) |