diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-06-22 22:50:57 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-07-07 18:39:37 +0200 |
commit | fcfed0cab586ecf3e2e6803e27f7cb0b38cb0898 (patch) | |
tree | 81b7f834e61c3c9b9848f2e20f8c94689febe3c2 /play.js | |
parent | 5b91837ae8c298ca0110854c48a1bf2fb6bea69a (diff) | |
download | time-of-crisis-fcfed0cab586ecf3e2e6803e27f7cb0b38cb0898.tar.gz |
Pretender (part 1).
Create, display, and gain legacy.
Also renumber cards.
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 137 |
1 files changed, 118 insertions, 19 deletions
@@ -5,6 +5,63 @@ // === SYNC with rules.js === +const CARD_M1 = [ 0, 11 ] +const CARD_S1 = [ 12, 23 ] +const CARD_P1 = [ 24, 35 ] +const CARD_M2 = [ 36, 44 ] +const CARD_S2 = [ 45, 53 ] +const CARD_P2 = [ 54, 62 ] +const CARD_M2X = [ 63, 71 ] +const CARD_S2X = [ 72, 80 ] +const CARD_P2X = [ 81, 89 ] +const CARD_M3 = [ 90, 97 ] +const CARD_S3 = [ 98, 105 ] +const CARD_P3 = [ 106, 113 ] +const CARD_M3X = [ 114, 121 ] +const CARD_S3X = [ 122, 129 ] +const CARD_P3X = [ 130, 137 ] +const CARD_M4 = [ 138, 143 ] +const CARD_S4 = [ 144, 149 ] +const CARD_S4B = [ 150, 155 ] +const CARD_P4 = [ 156, 161 ] +const CARD_M4X = [ 162, 167 ] +const CARD_S4X = [ 168, 173 ] +const CARD_P4X = [ 174, 179 ] + +const CARD_INDEX = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, + 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, + 15, 15, 15, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 20, 20, + 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, +] + +const CARD_INFO = [ + { name: "M1", type: 0, cost: 1, event: "None" }, + { name: "S1", type: 1, cost: 1, event: "None" }, + { name: "P1", type: 2, cost: 1, event: "None" }, + { name: "M2", type: 0, cost: 2, event: "Castra" }, + { name: "S2", type: 1, cost: 2, event: "Tribute" }, + { name: "P2", type: 2, cost: 2, event: "Quaestor" }, + { name: "M2X", type: 0, cost: 2, event: "Cavalry" }, + { name: "S2X", type: 1, cost: 2, event: "Princeps Senatus" }, + { name: "P2X", type: 2, cost: 2, event: "Ambitus" }, + { name: "M3", type: 0, cost: 3, event: "Flanking Maneuver" }, + { name: "S3", type: 1, cost: 3, event: "Foederati" }, + { name: "P3", type: 2, cost: 3, event: "Mob" }, + { name: "M3X", type: 0, cost: 3, event: "Force March" }, + { name: "S3X", type: 1, cost: 3, event: "Frumentarii" }, + { name: "P3X", type: 2, cost: 3, event: "Mobile Vulgus" }, + { name: "M4", type: 0, cost: 4, event: "Praetorian Guard" }, + { name: "S4", type: 1, cost: 4, event: "Damnatio Memoriae" }, + { name: "S4B", type: 1, cost: 4, event: "Damnatio Memoriae (exp)" }, + { name: "P4", type: 2, cost: 4, event: "Pretender" }, + { name: "M4X", type: 0, cost: 4, event: "Spiculum" }, + { name: "S4X", type: 1, cost: 4, event: "Triumph" }, + { name: "P4X", type: 2, cost: 4, event: "Demagogue" }, +] + const ITALIA = 0 const ASIA = 1 const GALLIA = 2 @@ -129,6 +186,16 @@ function is_breakaway(province) { function is_seat_of_power(province) { return view.seat_of_power & (1 << province) } +function find_governor(f) { + let n = view.legacy.length * 6 + for (let id = 0; id < n; ++id) + if (f(id, get_governor_location(id))) + return id + return -1 +} +function get_province_governor(where) { + return find_governor((id, loc) => loc === where) +} // === END SYNC === @@ -227,6 +294,21 @@ const LAYOUT_SUPPORT = [ BOXES["Syria Support"], ] +const LAYOUT_QUAESTOR = [ + [ 971, 829 ], + [ 1622, 994 ], + [ 403, 501 ], + [ 1327, 930 ], + [ 1097, 620 ], + [ 1445, 714 ], + [ 1643, 1462 ], + [ 590, 1284 ], + [ 97, 974 ], + [ 174, 254 ], + [ 1897, 925 ], + [ 1977, 1274 ], +] + const LAYOUT_SEA = [ [ 0, 0 ] ] const LAYOUT_HOMELAND = [ @@ -529,6 +611,8 @@ let ui = { neutral_governors: [], barbarian_leaders: [], rival_emperors: [], + seat_of_power: [], + breakaway: [], legions: [], barbarians: [ [], [], [], [], [] ], generals: [ [], [], [], [] ], @@ -629,29 +713,25 @@ function is_action(action, arg) { } function on_init() { - let c = 1 - function init_cards(n, className) { - for (let i = 0; i < n; ++i) - ui.cards[c + i] = create("div", { className, my_action: "card", my_id: c + i }) - c += n + for (let c = 0; c < CARD_INDEX.length; ++c) { + let name = CARD_INFO[CARD_INDEX[c]].name + ui.cards[c] = create("div", { className: "card influence_" + name.toLowerCase(), my_action: "card", my_id: c }) } - init_cards(12, "card influence_m1") - init_cards(12, "card influence_s1") - init_cards(12, "card influence_p1") - init_cards(9, "card influence_m2") - init_cards(9, "card influence_s2") - init_cards(9, "card influence_p2") - init_cards(8, "card influence_m3") - init_cards(8, "card influence_s3") - init_cards(8, "card influence_p3") - init_cards(6, "card influence_m4") - init_cards(6, "card influence_s4") - init_cards(6, "card influence_p4") - for (let i = 0; i < 33; ++i) ui.legions[i] = create_piece(i, "legion", "legion", "legion_" + i) + for (let p = 0; p < 4; ++p) { + for (let i = 0; i < 12; ++i) { + ui.seat_of_power[p * 12 + i] = create_thing({ className: PLAYER_CLASS[p] + " seat_of_power hide" }) + ui.seat_of_power[p * 12 + i].style.left = LAYOUT_QUAESTOR[i][0] + "px" + ui.seat_of_power[p * 12 + i].style.top = LAYOUT_QUAESTOR[i][1] + "px" + ui.breakaway[p * 12 + i] = create_thing({ className: PLAYER_CLASS[p] + " breakaway hide" }) + ui.breakaway[p * 12 + i].style.left = LAYOUT_QUAESTOR[i][0] + "px" + ui.breakaway[p * 12 + i].style.top = LAYOUT_QUAESTOR[i][1] + "px" + } + } + ui.barbarian_leaders[0] = create_piece(0, "barbarian_leader", "goths", "cniva") ui.barbarian_leaders[1] = create_piece(1, "barbarian_leader", "sassanids", "ardashir") ui.barbarian_leaders[2] = create_piece(2, "barbarian_leader", "sassanids", "shapur") @@ -676,7 +756,9 @@ function on_init() { ui.mcastra[region] = create_thing({ className: "castra hide" }) ui.militia[region] = create_thing({ className: "militia hide", my_action: "militia", my_id: region }) ui.capital[region] = document.getElementById(REGION_NAME[region] + "_Capital") - ui.quaestor[region] = document.getElementById(REGION_NAME[region] + "_Quaestor") + ui.quaestor[region] = create_thing({ className: "quaestor hide" }) + ui.quaestor[region].style.left = LAYOUT_QUAESTOR[region][0] + "px" + ui.quaestor[region].style.top = LAYOUT_QUAESTOR[region][1] + "px" // at most 3 mobs per province ui.mobs[region * 3 + 0] = create_piece(region, "mob", "mob") @@ -851,6 +933,23 @@ function on_update() { } for (let region = 0; region < 12; ++region) { + for (let p = 0; p < 4; ++p) { + let gov = get_province_governor(region) + if (gov > 0 && (gov/6|0) === p) { + if (is_seat_of_power(region)) + show(ui.seat_of_power[region + p * 12]) + else + hide(ui.seat_of_power[region + p * 12]) + if (is_breakaway(region)) + show(ui.breakaway[region + p * 12]) + else + hide(ui.breakaway[region + p * 12]) + } else { + hide(ui.seat_of_power[region + p * 12]) + hide(ui.breakaway[region + p * 12]) + } + } + if (has_quaestor(region)) show(ui.quaestor[region]) else |