diff options
author | Tor Andersson <tor@ccxvii.net> | 2024-10-21 11:57:59 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-10-21 13:00:54 +0200 |
commit | a25ffdc4eb68feb805bdb112ae62d3486ba055c2 (patch) | |
tree | fcc4eb550f407c1712f5e7135e3f73538f024473 /play.js | |
parent | d47d48c2d24f65ee8c753f175dcbb3e0b4ed18ec (diff) | |
download | maria-a25ffdc4eb68feb805bdb112ae62d3486ba055c2.tar.gz |
minor cleanups
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 127 |
1 files changed, 79 insertions, 48 deletions
@@ -22,19 +22,8 @@ function toggle_shift() { document.body.classList.toggle("shift") } -/* DATA */ - -const P_FRANCE = 0 -const P_BAVARIA = 1 -const P_PRUSSIA = 2 -const P_SAXONY = 3 -const P_PRAGMATIC = 4 -const P_AUSTRIA = 5 - const last_city = data.cities.name.length - 1 -const ELIMINATED = data.cities.name.length -const REMOVED = ELIMINATED + 1 const ELIMINATED_TRAIN_X = 340 const ELIMINATED_TRAIN_Y = 160 const ELIMINATED_TRAIN_DX = 33 @@ -45,8 +34,35 @@ const ELIMINATED_GENERAL_DX = 50 const HUSSAR_X = 2190 const HUSSAR_Y = 1630 +/* DATA (SHARED) */ + +const deck_name = [ "red", "green", "blue", "yellow" ] +const suit_name = [ "\u2660", "\u2663", "\u2665", "\u2666", "R" ] +const suit_class = [ "spades", "clubs", "hearts", "diamonds", "reserve" ] +const suit_letter = [ "S", "C", "H", "D", "R" ] + +const P_FRANCE = 0 +const P_BAVARIA = 1 +const P_PRUSSIA = 2 +const P_SAXONY = 3 +const P_PRAGMATIC = 4 +const P_AUSTRIA = 5 + +const power_name = [ "France", "Bavaria", "Prussia", "Saxony", "Pragmatic Army", "Austria" ] const power_class = [ "france", "bavaria", "prussia", "saxony", "pragmatic", "austria" ] -const power_name = [ "France", "Bavaria", "Prussia", "Saxony", "Pragmatic", "Austria" ] + +const is_major_power = [ 1, 0, 1, 0, 1, 1 ] +const is_minor_power = [ 0, 1, 0, 1, 0, 0 ] + +const SPADES = 0 +const CLUBS = 1 +const HEARTS = 2 +const DIAMONDS = 3 +const RESERVE = 4 + +const IMPERIAL_ELECTION = 25 + +const ELIMINATED = data.cities.name.length const all_powers = [ 0, 1, 2, 3, 4, 5 ] @@ -68,6 +84,10 @@ const all_power_trains = [ [ 27, 28, 29 ], ] +const last_piece = 29 + +const all_hussars = [ 30, 31 ] + const piece_power = [ P_FRANCE, P_FRANCE, P_FRANCE, P_FRANCE, P_FRANCE, P_BAVARIA, @@ -123,6 +143,36 @@ const piece_name = [ "Batthyány", "Neipperg", "Arenberg", + "supply train", "supply train", + "supply train", + "supply train", "supply train", + "supply train", + "supply train", + "supply train", "supply train", "supply train", + "hussar", "hussar", +] + +const piece_log_name = [ + "Moritz", + "Belle-Isle", + "Broglie", + "Maillebois", + "Noailles", + "Törring", + "Friedrich", + "Schwerin", + "Leopold", + "Dessauer", + "Rutowski", + "George II", + "Cumberland", + "Earl of Stair", + "Karl", + "Traun", + "Khevenhüller", + "Batthyány", + "Neipperg", + "Arenberg", "French ST", "French ST", "Bavarian ST", "Prussian ST", "Prussian ST", @@ -132,8 +182,11 @@ const piece_name = [ "Hussars", "Hussars", ] -let suit_class = [ "spades", "clubs", "hearts", "diamonds", "reserve" ] -let suit_letter = [ "S", "C", "H", "D", "R" ] + +const all_pieces = [ ...all_power_generals.flat(), ...all_power_trains.flat() ] +const all_trains = [ ...all_power_trains.flat() ] +const all_generals = [ ...all_power_generals.flat() ] +const all_generals_by_rank = all_generals.slice().sort((a,b)=>piece_rank[a]-piece_rank[b]) function to_deck(c) { return c >> 7 @@ -144,7 +197,7 @@ function to_suit(c) { } function to_value(c) { - if (to_suit(c) === 4) + if (to_suit(c) === RESERVE) return 8 return c & 15 } @@ -442,16 +495,6 @@ function make_political_card(fc) { return e } -function has_removed_all_pieces(pow) { - for (let p of all_power_generals[pow]) - if (view.pos[p] !== REMOVED) - return false - for (let p of all_power_trains[pow]) - if (view.pos[p] !== REMOVED) - return false - return true -} - function on_init() { ui.pieces = [ create_piece("piece", 0, "piece cylinder france france_1"), @@ -533,12 +576,13 @@ function on_init() { ] ui.tc_hand = [ - make_tc_deck_pile("deck_1"), - make_tc_deck_pile("deck_1"), - make_tc_deck_pile("deck_1"), - make_tc_deck_pile("deck_1"), - make_tc_deck_pile("deck_1"), - make_tc_deck_pile("deck_1"), + // TODO: or make_tc_deck_pile ??? + make_tc_deck_hand("deck_1"), + make_tc_deck_hand("deck_1"), + make_tc_deck_hand("deck_1"), + make_tc_deck_hand("deck_1"), + make_tc_deck_hand("deck_1"), + make_tc_deck_hand("deck_1"), ] ui.tc_discard = [ @@ -675,9 +719,9 @@ function on_blur_city() { function on_focus_piece(evt) { let p = evt.target.my_id if (p < 20 && view.troops[p] > 0) - ui.status.textContent = piece_name[evt.target.my_id] + " (" + view.troops[p] + " troops)" + ui.status.textContent = piece_log_name[evt.target.my_id] + " (" + view.troops[p] + " troops)" else - ui.status.textContent = piece_name[evt.target.my_id] + ui.status.textContent = piece_log_name[evt.target.my_id] } function on_blur_piece() { @@ -751,14 +795,6 @@ function layout_hussar(id, s) { function layout_general(id, s) { let x, y, n - if (s === REMOVED) { - if (ui.pieces[id].parentElement === ui.pieces_element) - e.remove() - if (ui.troops[id].parentElement === ui.pieces_element) - e.remove() - return - } - if (s === ELIMINATED) { n = layout_general_offset_elim(id) x = ELIMINATED_GENERAL_X + ELIMINATED_GENERAL_DX * get_cylinder_power(id) @@ -794,11 +830,6 @@ function layout_train(id, s) { let n = layout_train_offset(id, s) let x, y - if (s === REMOVED) { - if (e.parentElement === ui.pieces_element) - e.remove() - return - } if (e.parentElement !== ui.pieces_element) ui.pieces_element.appendChild(e) @@ -1067,7 +1098,7 @@ function on_update() { function sub_piece(match, p1) { let x = p1 | 0 - let n = piece_name[x] + let n = piece_log_name[x] let p = power_class[piece_power[x]] return `<span class="piece_tip ${p}" onclick="on_click_piece_tip(${x})" onmouseenter="on_focus_piece_tip(${x})" onmouseleave="on_blur_piece_tip(${x})">${n}</span>` } @@ -1082,7 +1113,7 @@ function sub_path(pieces_and_spaces) { let ps = pieces_and_spaces[0].split(",") let ss = pieces_and_spaces[1].split(",") let x = ss[ss.length-1] - let ps_name = ps.map(p => piece_name[p]).join(" and ") + let ps_name = ps.map(p => piece_log_name[p]).join(" and ") let ss_name = data.cities.name[x] return `<span onclick="on_click_city_tip(${x})" onmouseenter="on_focus_path_tip([${ps.join(",")}],[${ss.join(",")}])" onmouseleave="on_blur_path_tip()">${ps_name} to ${ss_name}.</span>` } |