diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-11-12 03:04:36 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-11-18 00:46:17 +0100 |
commit | 8063f3b9ba28d439cad6c8317d3b58796d5a5ddb (patch) | |
tree | e7597d9119bf60c43a44e96268e7734a140be8e9 /play.js | |
parent | e66e845ef1d691d2086afc7984ec5807706a6121 (diff) | |
download | crusader-rex-8063f3b9ba28d439cad6c8317d3b58796d5a5ddb.tar.gz |
Show road limits.
Use maps instead of objects for road_limit, last_used and main_road.
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 249 |
1 files changed, 249 insertions, 0 deletions
@@ -16,6 +16,22 @@ function set_has(set, item) { return false } +function map_get(map, key, missing) { + let a = 0 + let b = (map.length >> 1) - 1 + while (a <= b) { + let m = (a + b) >> 1 + let x = map[m<<1] + if (key < x) + b = m - 1 + else if (key > x) + a = m + 1 + else + return map[(m<<1)+1] + } + return missing +} + const FRANKS = "Franks" const SARACENS = "Saracens" @@ -83,6 +99,193 @@ const VICTORY_TOWNS = [ town_index["Jerusalem"] ] +// :r !node tools/genroads.js +const ROADS_XY = { + "Germania / Aleppo": [975,64], + "Germania / St. Simeon": [297,100], + "Germania / Antioch": [512,54], + "Aleppo / Artah": [939,147], + "Aleppo / Zerdana": [1045,218], + "Artah / Zerdana": [941,227], + "Artah / Harim": [761,127], + "Zerdana / Hama": [1028,388], + "Zerdana / Albara": [942,342], + "Hama / Homs": [1133,571], + "Hama / Albara": [950,450], + "Hama / Monterrand": [964,554], + "Homs / Lacum": [980,780], + "Homs / Qaddas": [1156,780], + "Homs / Monterrand": [986,643], + "Homs / Krak": [927,726], + "Lacum / Qaddas": [1063,906], + "Lacum / Baalbek": [889,953], + "Lacum / Krak": [867,794], + "Qaddas / Damascus": [1170,1038], + "Baalbek / Anjar": [812,1082], + "Baalbek / Tripoli": [776,953], + "Anjar / Damascus": [869,1177], + "Anjar / Beirut": [635,1137], + "Anjar / Beaufort": [718,1198], + "Damascus / Banyas": [936,1267], + "Damascus / Ashtera": [1051,1339], + "Banyas / Ashtera": [907,1411], + "Banyas / Beaufort": [666,1389], + "Banyas / Tiberias": [730,1455], + "Ashtera / Ajlun": [1046,1491], + "Ajlun / Tiberias": [911,1554], + "Ajlun / Amman": [1035,1711], + "St. Simeon / Antioch": [412,208], + "Antioch / Harim": [600,127], + "Antioch / Kassab": [477,260], + "Harim / Shughur": [684,214], + "Kassab / Latakia": [406,388], + "Shughur / Saône": [635,374], + "Shughur / Albara": [704,345], + "Latakia / Saône": [524,432], + "Latakia / Margat": [492,488], + "Saône / Albara": [735,421], + "Margat / Tartus": [547,654], + "Monterrand / Krak": [851,664], + "Tartus / Krak": [689,722], + "Tartus / Tripoli": [669,786], + "Krak / Tripoli": [757,807], + "Tripoli / Botron": [571,933], + "Botron / Beirut": [567,1052], + "Beirut / Sidon": [503,1219], + "Sidon / Tyre": [460,1330], + "Sidon / Beaufort": [542,1324], + "Tyre / Beaufort": [546,1388], + "Tyre / Acre": [427,1492], + "Acre / Tiberias": [601,1572], + "Acre / Legio": [518,1653], + "Acre / Caesarea": [390,1658], + "Tiberias / Baisan": [759,1632], + "Legio / Baisan": [653,1685], + "Legio / Nablus": [619,1724], + "Baisan / Nablus": [675,1736], + "Baisan / Damiya": [811,1723], + "Caesarea / Nablus": [520,1777], + "Caesarea / Jaffa": [409,1837], + "Nablus / Damiya": [745,1797], + "Nablus / Jerusalem": [653,1883], + "Damiya / Amman": [934,1781], + "Damiya / Jericho": [845,1883], + "Amman / Jericho": [958,1892], + "Amman / Kerak": [1130,1973], + "Jaffa / Ramallah": [463,1932], + "Jaffa / Ascalon": [391,2004], + "Ramallah / Jerusalem": [586,1972], + "Ramallah / Ascalon": [448,2014], + "Jerusalem / Jericho": [789,1954], + "Jerusalem / Hebron": [677,2050], + "Jericho / Kerak": [952,1976], + "Ascalon / Lachish": [439,2128], + "Ascalon / Gaza": [330,2133], + "Lachish / Hebron": [556,2151], + "Lachish / Gaza": [430,2172], + "Hebron / Dimona": [658,2242], + "Hebron / Zoar": [779,2195], + "Kerak / Zoar": [998,2140], + "Gaza / Beersheba": [369,2265], + "Gaza / Egypt": [225,2266], + "Beersheba / Dimona": [539,2293], + "Beersheba / Egypt": [415,2312], + "Dimona / Zoar": [788,2291], +} + +const ROADS_BG = { + "Germania / Aleppo": "hsl(36, 72%, 76%)", + "Germania / St. Simeon": "hsl(37, 79%, 77%)", + "Germania / Antioch": "hsl(61, 30%, 58%)", + "Aleppo / Artah": "hsl(37, 80%, 78%)", + "Aleppo / Zerdana": "hsl(36, 81%, 81%)", + "Artah / Zerdana": "hsl(37, 82%, 78%)", + "Artah / Harim": "hsl(35, 68%, 70%)", + "Zerdana / Hama": "hsl(36, 78%, 77%)", + "Zerdana / Albara": "hsl(36, 76%, 77%)", + "Hama / Homs": "hsl(36, 78%, 77%)", + "Hama / Albara": "hsl(39, 69%, 74%)", + "Hama / Monterrand": "hsl(34, 76%, 67%)", + "Homs / Lacum": "hsl(42, 57%, 70%)", + "Homs / Qaddas": "hsl(36, 82%, 78%)", + "Homs / Monterrand": "hsl(34, 78%, 70%)", + "Homs / Krak": "hsl(36, 74%, 72%)", + "Lacum / Qaddas": "hsl(36, 60%, 75%)", + "Lacum / Baalbek": "hsl(45, 45%, 68%)", + "Lacum / Krak": "hsl(38, 59%, 65%)", + "Qaddas / Damascus": "hsl(36, 80%, 78%)", + "Baalbek / Anjar": "hsl(48, 43%, 68%)", + "Baalbek / Tripoli": "hsl(56, 30%, 55%)", + "Anjar / Damascus": "hsl(42, 59%, 73%)", + "Anjar / Beirut": "hsl(51, 39%, 61%)", + "Anjar / Beaufort": "hsl(47, 43%, 67%)", + "Damascus / Banyas": "hsl(38, 58%, 78%)", + "Damascus / Ashtera": "hsl(38, 65%, 74%)", + "Banyas / Ashtera": "hsl(38, 56%, 75%)", + "Banyas / Beaufort": "hsl(53, 36%, 59%)", + "Banyas / Tiberias": "hsl(54, 35%, 62%)", + "Ashtera / Ajlun": "hsl(37, 70%, 75%)", + "Ajlun / Tiberias": "hsl(46, 48%, 68%)", + "Ajlun / Amman": "hsl(37, 85%, 80%)", + "St. Simeon / Antioch": "hsl(66, 32%, 58%)", + "Antioch / Harim": "hsl(46, 48%, 69%)", + "Antioch / Kassab": "hsl(66, 32%, 58%)", + "Harim / Shughur": "hsl(41, 61%, 74%)", + "Kassab / Latakia": "hsl(66, 32%, 58%)", + "Shughur / Saône": "hsl(47, 48%, 69%)", + "Shughur / Albara": "hsl(41, 53%, 72%)", + "Latakia / Saône": "hsl(60, 31%, 61%)", + "Latakia / Margat": "hsl(63, 32%, 59%)", + "Saône / Albara": "hsl(41, 60%, 74%)", + "Margat / Tartus": "hsl(50, 39%, 61%)", + "Monterrand / Krak": "hsl(40, 57%, 68%)", + "Tartus / Krak": "hsl(62, 31%, 59%)", + "Tartus / Tripoli": "hsl(55, 35%, 65%)", + "Krak / Tripoli": "hsl(52, 39%, 64%)", + "Tripoli / Botron": "hsl(72, 33%, 57%)", + "Botron / Beirut": "hsl(44, 43%, 57%)", + "Beirut / Sidon": "hsl(42, 57%, 79%)", + "Sidon / Tyre": "hsl(45, 42%, 71%)", + "Sidon / Beaufort": "hsl(70, 33%, 57%)", + "Tyre / Beaufort": "hsl(69, 32%, 56%)", + "Tyre / Acre": "hsl(58, 33%, 63%)", + "Acre / Tiberias": "hsl(56, 27%, 60%)", + "Acre / Legio": "hsl(61, 31%, 57%)", + "Acre / Caesarea": "hsl(52, 40%, 70%)", + "Tiberias / Baisan": "hsl(49, 44%, 67%)", + "Legio / Baisan": "hsl(56, 38%, 64%)", + "Legio / Nablus": "hsl(58, 32%, 60%)", + "Baisan / Nablus": "hsl(48, 50%, 71%)", + "Baisan / Damiya": "hsl(51, 40%, 65%)", + "Caesarea / Nablus": "hsl(59, 32%, 60%)", + "Caesarea / Jaffa": "hsl(51, 40%, 70%)", + "Nablus / Damiya": "hsl(39, 64%, 77%)", + "Nablus / Jerusalem": "hsl(45, 51%, 71%)", + "Damiya / Amman": "hsl(46, 47%, 69%)", + "Damiya / Jericho": "hsl(48, 48%, 69%)", + "Amman / Jericho": "hsl(40, 66%, 75%)", + "Amman / Kerak": "hsl(36, 72%, 79%)", + "Jaffa / Ramallah": "hsl(58, 34%, 61%)", + "Jaffa / Ascalon": "hsl(46, 44%, 69%)", + "Ramallah / Jerusalem": "hsl(47, 46%, 68%)", + "Ramallah / Ascalon": "hsl(49, 43%, 66%)", + "Jerusalem / Jericho": "hsl(41, 52%, 70%)", + "Jerusalem / Hebron": "hsl(41, 62%, 75%)", + "Jericho / Kerak": "hsl(40, 58%, 72%)", + "Ascalon / Lachish": "hsl(44, 57%, 72%)", + "Ascalon / Gaza": "hsl(45, 51%, 74%)", + "Lachish / Hebron": "hsl(42, 56%, 71%)", + "Lachish / Gaza": "hsl(41, 65%, 74%)", + "Hebron / Dimona": "hsl(40, 60%, 73%)", + "Hebron / Zoar": "hsl(38, 59%, 72%)", + "Kerak / Zoar": "hsl(38, 78%, 77%)", + "Gaza / Beersheba": "hsl(36, 82%, 76%)", + "Gaza / Egypt": "hsl(50, 44%, 63%)", + "Beersheba / Dimona": "hsl(36, 71%, 78%)", + "Beersheba / Egypt": "hsl(34, 80%, 71%)", + "Dimona / Zoar": "hsl(36, 78%, 77%)", +} + let label_layout = window.localStorage['crusader-rex/label-layout'] || 'spread' function set_spread_layout() { @@ -105,6 +308,7 @@ let ui = { cards: [], card_backs: [], towns: [], + roads: [], blocks: [], battle_menu: [], battle_block: [], @@ -478,6 +682,21 @@ function build_map() { ui.blocks[b] = build_map_block(b, block) build_battle_block(b, block) } + + for (let name in ROADS_XY) { + let [x, y] = ROADS_XY[name] + let [a, b] = name.split(" / ") + let id = town_index[a] * 100 + town_index[b] + let e = document.createElement("div") + e.my_id = id + e.my_bgnd = ROADS_BG[name] + e.my_show = "road " + ROADS[id] + e.className = "hide" + e.style.left = (x - 12) + "px" + e.style.top = (y - 12) + "px" + ui.roads.push(e) + document.getElementById("roads").appendChild(e) + } } function update_steps(b, steps, element) { @@ -736,6 +955,36 @@ function update_map() { ui.blocks[view.who].classList.add('selected') for (let b of view.castle) ui.blocks[b].classList.add('castle') + + for (let e of ui.roads) { + let u = map_get(view.last_used, e.my_id, 0) + let n = map_get(view.road_limit, e.my_id, "") + if (view.main_road && set_has(view.main_road, e.my_id)) + n += "*" + switch (u) { + case 1: + e.style.backgroundColor = null + e.className = "road Franks" + e.textContent = n + break + case 2: + e.style.backgroundColor = null + e.className = "road Saracens" + e.textContent = n + break + case 0: + if (n) { + e.style.backgroundColor = e.my_bgnd + e.className = e.my_show + e.textContent = n + } else { + e.style.backgroundColor = null + e.className = "hide" + e.textContent = "" + } + break + } + } } function update_card_display(element, card, prior_card) { |