diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-06-21 16:23:20 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-07-07 18:39:37 +0200 |
commit | 36535d6c382597e80dc88d619ff0924109fe6026 (patch) | |
tree | cd3b9c579bcc55ccea7326823417de99958a3865 /rules.js | |
parent | f0ad2d92162d5faab8a5537a50f778febc442e9c (diff) | |
download | time-of-crisis-36535d6c382597e80dc88d619ff0924109fe6026.tar.gz |
Mobs grow!
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 102 |
1 files changed, 88 insertions, 14 deletions
@@ -14,9 +14,9 @@ TODO [x] tribute [x] foederati -[ ] mobs +[x] mobs -[ ] disperse mob +[x] disperse mob [ ] combat victory [ ] combat remove general if army is eliminated @@ -46,13 +46,12 @@ TODO [ ] provinces [ ] improvements -[ ] end turn - [ ] grow mobs - [ ] flip barbarians +[x] end turn + [x] grow mobs + [x] flip barbarians [ ] praetorian guard [ ] damnatio memoriae - [ ] pretender [ ] place [ ] expand @@ -543,7 +542,7 @@ function get_selected_region() { if (game.selected_governor >= 0) return get_governor_location(game.selected_governor) if (game.selected_general >= 0) - return get_governor_location(game.selected_general) + return get_general_location(game.selected_general) return UNAVAILABLE } @@ -590,7 +589,7 @@ function find_governor(f) { function for_each_barbarian(f) { let n = game.barbarians.length for (let id = 0; id < n; ++id) - f(id, get_barbarian_location(id), is_barbarian_inactive(id)) + f(id, get_barbarian_location(id), is_barbarian_active(id)) } function find_barbarian(f) { @@ -716,6 +715,10 @@ function has_active_barbarians(where) { return some_barbarian((id, loc, active) => loc === where && active) } +function has_inactive_barbarians(where) { + return some_barbarian((id, loc, active) => loc === where && !active) +} + function find_barbarian_of_tribe(where, tribe) { for (let id = first_barbarian[tribe]; id <= last_barbarian[tribe]; ++id) if (get_barbarian_location(id) === where) @@ -891,7 +894,6 @@ function count_own_basilicas() { function roll_dice(count, target) { let hits = 0 - console.log("roll_dice", count, target) while (count > 0) { let summary = [] let sixes = 0 @@ -1331,7 +1333,7 @@ states.take_actions = { view.actions.add_legion_to_army = 0 // Disperse Mob - if (has_mob(where)) { + if (has_mob(where) && is_own_province(where)) { if (mip >= 1) view.actions.disperse_mob = 1 } @@ -1498,6 +1500,18 @@ states.take_actions = { set_general_outside_capital(game.selected_general) }, + disperse_mob() { + push_undo() + let where = get_selected_region() + let n = 1 + if (game.selected_general >= 0) + 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 + reduce_support(where) + }, + region(where) { push_undo() if (game.selected_governor >= 0) { @@ -1625,7 +1639,6 @@ function calc_needed_votes(where) { if (army_general >= 0) { let army_player = army_general / 6 | 0 let army_size = count_units_in_army(army_general) - console.log("VOTES", old_player, army_player, game.current) if (army_player === old_player) n += army_size else if (army_player === game.current) @@ -1633,7 +1646,6 @@ function calc_needed_votes(where) { } if (has_militia(where)) n += 1 - console.log("votes needed", where, n) return Math.max(1, n) } @@ -2352,11 +2364,73 @@ states.buy_trash = { // === END OF TURN === function goto_end_of_turn() { - // TODO: add mobs - // TODO: flip inactive barbarians + game.count = 0 + goto_grow_mobs() +} + +function goto_grow_mobs() { + for (let where = 0; where < 12; ++where) { + if ((game.count & (1 << where)) === 0) { + if (is_own_province(where) && has_mob(where) && !has_amphitheater(where)) { + game.state = "grow_mobs" + return + } + } + } + goto_flip_inactive_barbarians() +} + +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) + }) + }, + region(where) { + game.count |= (1 << where) + add_one_mob(where) + goto_grow_mobs() + }, +} + +function goto_flip_inactive_barbarians() { + for (let where = 0; where < 12; ++where) { + if (is_own_province(where) && has_inactive_barbarians(where)) { + game.state = "flip_inactive_barbarians" + return + } + } goto_refill_hand() } +states.flip_inactive_barbarians = { + prompt() { + 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 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) + let tribe = get_barbarian_tribe(target) + for (let id = first_barbarian[tribe]; id <= last_barbarian[tribe]; ++id) + if (get_barbarian_location(id) === where && is_barbarian_inactive(id)) + set_barbarian_active(id) + goto_flip_inactive_barbarians() + }, +} + function goto_refill_hand() { if (current_draw().length === 0) flip_discard_to_available() |