diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-06-19 12:06:38 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-07-07 18:39:37 +0200 |
commit | f0a3de684843c21695118b62b36ef6821fe4cba3 (patch) | |
tree | 47adc76d4e57fb0d263f483d0d69e6c59e369021 /play.js | |
parent | 19fd5d79b8e58b6806bb711c2c53054f73b2a282 (diff) | |
download | time-of-crisis-f0a3de684843c21695118b62b36ef6821fe4cba3.tar.gz |
Allow for variable number of barbarians per tribe.
... to make room for barbarian leaders if necessary.
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 95 |
1 files changed, 44 insertions, 51 deletions
@@ -2,8 +2,6 @@ // === SYNC with rules.js === -const TRIBE_COUNT = [ 0, 5, 3, 4, 5 ] - const ITALIA = 0 const ASIA = 1 const GALLIA = 2 @@ -35,7 +33,10 @@ const UNAVAILABLE = 22 const ARMY = 23 +const TRIBE_COUNT = [ 0, 5, 3, 4, 5 ] +const BARBARIAN_COUNT = [ 0, 50, 30, 40, 50 ] const first_barbarian = [ 0, 10, 20, 30, 40 ] +const last_barbarian = [ 9, 19, 29, 39, 49 ] const first_governor = [ 0, 6, 12, 18 ] const first_general = [ 0, 6, 12, 18 ] @@ -105,6 +106,7 @@ function set_has(set, item) { } const PLAYER_CLASS = [ "red", "blue", "yellow", "green" ] +const BARBARIAN_CLASS = [ "alamanni", "franks", "goths", "nomads", "sassanids" ] const BOXES = { "Thracia Support": [1502,720,258,52], @@ -315,7 +317,7 @@ function register_action(target, action, id) { function on_click_action(evt, target) { if (evt.button === 0) { - if (target.my_stack) { + if (typeof target.my_stack === "number") { evt.stopPropagation() if (focus_stack(target.my_stack)) if (!send_action(target.my_action, target.my_id)) @@ -378,13 +380,9 @@ function on_init() { ui.rival_emperors[1] = create_piece(1, "rival_emperor", "rival_emperor", "priest_king") ui.rival_emperors[2] = create_piece(2, "rival_emperor", "rival_emperor", "zenobia") - for (let i = 0; i < 10; ++i) { - ui.barbarians[0][i] = create_piece(0 + i, "barbarian", "alamanni") - ui.barbarians[1][i] = create_piece(10 + i, "barbarian", "franks") - ui.barbarians[2][i] = create_piece(20 + i, "barbarian", "goths") - ui.barbarians[3][i] = create_piece(30 + i, "barbarian", "nomads") - ui.barbarians[4][i] = create_piece(40 + i, "barbarian", "sassanids") - } + for (let tribe = 0; tribe < 5; ++tribe) + for (let id = first_barbarian[tribe]; id <= last_barbarian[tribe]; ++id) + ui.barbarians[id] = create_piece(id, "barbarian", BARBARIAN_CLASS[tribe]) for (let p = 0; p < 4; ++p) { for (let g = 0; g < 6; ++g) { @@ -421,8 +419,8 @@ function on_init() { } let stack_count = new Array(12 + 5).fill(0) -let stack_focus = 0 -let stack_cache = {} +let stack_focus = -1 +let stack_cache = [] function focus_stack(id) { if (stack_focus !== id) { @@ -435,8 +433,8 @@ function focus_stack(id) { } function blur_stack() { - if (stack_focus !== 0) { - stack_focus = 0 + if (stack_focus >= 0) { + stack_focus = -1 on_update() } } @@ -447,7 +445,8 @@ function layout_stack(id, list, region, in_capital) { let dy = 8 let z = 1 - stack_cache[id] = list + if (id >= 0) + stack_cache[id] = list if (in_capital) { x += 5 @@ -462,7 +461,7 @@ function layout_stack(id, list, region, in_capital) { dy = 5 } - if (stack_focus === id) { + if (id >= 0 && stack_focus === id) { dx = 24 dy = 16 } @@ -507,7 +506,8 @@ function layout_governor_unavailable(e, color, ix) { function on_update() { let player_count = view.legacy.length - stack_cache = {} + for (let i = 0; i < 24; ++i) + stack_cache[i] = null ui.body.classList.toggle("p2", player_count === 2) ui.body.classList.toggle("p3", player_count === 3) @@ -615,44 +615,38 @@ function on_update() { // TODO: Cniva, Ardashir, and Shapur // TODO: Zenobia, Postumus, Priest King - let tribe_count = TRIBE_COUNT[player_count] - for (let tribe = 0; tribe < TRIBE_COUNT[player_count]; ++tribe) { - for (let i = 0; i < 10; ++i) { - show(ui.barbarians[tribe][i]) - if (is_barbarian_inactive(first_barbarian[tribe] + i)) - ui.barbarians[tribe][i].classList.toggle("inactive", true) - else - ui.barbarians[tribe][i].classList.toggle("inactive", false) - } + for (let id = 0; id < BARBARIAN_COUNT[player_count]; ++id) { + show(ui.barbarians[id]) + if (is_barbarian_inactive(id)) + ui.barbarians[id].classList.toggle("inactive", true) + else + ui.barbarians[id].classList.toggle("inactive", false) } - for (let tribe = TRIBE_COUNT[player_count]; tribe < 5; ++tribe) { - for (let i = 0; i < 10; ++i) { - hide(ui.barbarians[tribe][i]) - } - } + for (let id = BARBARIAN_COUNT[player_count]; id < ui.barbarians.length; ++id) + hide(ui.barbarians[id]) stack_count.fill(1) for (let region = 0; region < 12 + 5; ++region) { - for (let tribe = 0; tribe < tribe_count; ++tribe) { + for (let tribe = 0; tribe < TRIBE_COUNT[player_count]; ++tribe) { let active_barbarians = [] let inactive_barbarians = [] // TODO: Cniva, Ardashir, and Shapur - for (let i = 0; i < 10; ++i) { - let loc = get_barbarian_location(first_barbarian[tribe], i) - let inactive = is_barbarian_inactive(first_barbarian[tribe], i) + for (let id = first_barbarian[tribe]; id <= last_barbarian[tribe]; ++id) { + let loc = get_barbarian_location(id) + let inactive = is_barbarian_inactive(id) if (loc === region) { if (inactive) - inactive_barbarians.push(ui.barbarians[tribe][i]) + inactive_barbarians.push(ui.barbarians[id]) else - active_barbarians.push(ui.barbarians[tribe][i]) + active_barbarians.push(ui.barbarians[id]) } } if (active_barbarians.length > 0) - layout_stack(region * 10 + tribe * 2 + 0, active_barbarians, region, false) + layout_stack(-1, active_barbarians, region, false) if (inactive_barbarians.length > 0) - layout_stack(region * 10 + tribe * 2 + 1, inactive_barbarians, region, false) + layout_stack(-1, inactive_barbarians, region, false) } } @@ -675,10 +669,10 @@ function on_update() { let mcastra = has_militia_castra(region) if (mcastra) { show(ui.mcastra[region]) - layout_stack(0, [ ui.militia[region], ui.mcastra[region] ], region, true) + layout_stack(-1, [ ui.militia[region], ui.mcastra[region] ], region, true) } else { hide(ui.mcastra[region]) - layout_stack(0, [ ui.militia[region] ], region, true) + layout_stack(-1, [ ui.militia[region] ], region, true) } } } @@ -698,7 +692,7 @@ function on_update() { for (let pi = 0; pi < player_count; ++pi) { let avail_stack = [] for (let ai = 0; ai < 6; ++ai) { - let id = ARMY + first_general[pi] + ai + let army = ARMY + first_general[pi] + ai let region = get_general_location(first_general[pi] + ai) let inside = is_general_inside_capital(first_general[pi] + ai) let castra = has_general_castra(first_general[pi] + ai) @@ -710,17 +704,17 @@ function on_update() { if (has_militia(region) && inside) stack.push(ui.militia[region]) - for (let tribe = 0; tribe < tribe_count; ++tribe) { - for (let i = 0; i < 10; ++i) { - let loc = get_barbarian_location(first_barbarian[tribe] + i) - if (loc === id) - stack.push(ui.barbarians[tribe][i]) + for (let tribe = 0; tribe < TRIBE_COUNT[player_count]; ++tribe) { + for (let id = first_barbarian[tribe]; id <= last_barbarian[tribe]; ++id) { + let loc = get_barbarian_location(id) + if (loc === army) + stack.push(ui.barbarians[id]) } } for (let i = 0; i < 33; ++i) { let loc = get_legion_location(i) - if (loc === id) + if (loc === army) stack.push(ui.legions[i]) } @@ -734,9 +728,9 @@ function on_update() { } if (inside) - layout_stack(id, stack, region, true) + layout_stack(pi * 6 + ai, stack, region, true) else - layout_stack(id, stack, region, false) + layout_stack(pi * 6 + ai, stack, region, false) } else { avail_stack.push(e) } @@ -749,7 +743,6 @@ function on_update() { for (let pi = 0; pi < player_count; ++pi) { let avail_stack = [] for (let ai = 0; ai < 6; ++ai) { - let id = 100 + 100 * pi + ai let region = get_governor_location(first_governor[pi] + ai) let e = ui.governors[pi][ai] if (region < 12) { |