summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
Diffstat (limited to 'play.js')
-rw-r--r--play.js170
1 files changed, 170 insertions, 0 deletions
diff --git a/play.js b/play.js
index 2870dff..7071231 100644
--- a/play.js
+++ b/play.js
@@ -1,5 +1,37 @@
"use strict"
+function set_has(set, item) {
+ let a = 0
+ let b = set.length - 1
+ while (a <= b) {
+ let m = (a + b) >> 1
+ let x = set[m]
+ if (item < x)
+ b = m - 1
+ else if (item > x)
+ a = m + 1
+ else
+ return true
+ }
+ 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 LANCASTER = "Lancaster"
const YORK = "York"
const ENEMY = { York: "Lancaster", Lancaster: "York" }
@@ -76,6 +108,100 @@ const LONG_NAME = {
"Gloucester": "Duke of Gloucester",
}
+// :!r node tools/genborders.js
+const BORDERS_XY = {
+ "English Channel / Calais": [1317,1792],
+ "English Channel / France": [378,125],
+ "English Channel / Cornwall": [382,1762],
+ "English Channel / Dorset": [860,1660],
+ "English Channel / Kent": [1437,1565],
+ "English Channel / Sussex": [1090,1631],
+ "Irish Sea / France": [185,245],
+ "Irish Sea / Ireland": [176,396],
+ "Irish Sea / Scotland": [575,284],
+ "Irish Sea / Caernarvon": [524,816],
+ "Irish Sea / Chester": [627,782],
+ "Irish Sea / Cornwall": [286,1646],
+ "Irish Sea / Cumbria": [570,482],
+ "Irish Sea / Glamorgan": [459,1366],
+ "Irish Sea / Isle of Man": [389,467],
+ "Irish Sea / Lancaster": [645,654],
+ "Irish Sea / Pembroke": [303,1187],
+ "Irish Sea / Somerset": [688,1418],
+ "North Sea / Calais": [1565,1760],
+ "North Sea / Scotland": [844,16],
+ "North Sea / East Anglia": [1582,972],
+ "North Sea / East Yorks": [1224,643],
+ "North Sea / Essex": [1504,1295],
+ "North Sea / Kent": [1562,1445],
+ "North Sea / Lincoln": [1305,801],
+ "North Sea / Middlesex": [1382,1392],
+ "North Sea / Northumbria": [952,248],
+ "North Sea / Rutland": [1298,965],
+ "Scotland / Cumbria": [679,248],
+ "Scotland / Northumbria": [774,171],
+ "Caernarvon / Chester": [677,920],
+ "Caernarvon / Pembroke": [479,1071],
+ "Caernarvon / Powys": [522,995],
+ "Chester / Derby": [842,879],
+ "Chester / Hereford": [717,1012],
+ "Chester / Lancaster": [762,794],
+ "Chester / Powys": [610,986],
+ "Chester / Warwick": [793,982],
+ "Cornwall / Dorset": [613,1627],
+ "Cornwall / Somerset": [528,1574],
+ "Cumbria / Lancaster": [740,517],
+ "Cumbria / North Yorks": [819,478],
+ "Cumbria / Northumbria": [782,342],
+ "Derby / Lancaster": [881,784],
+ "Derby / Leicester": [1029,943],
+ "Derby / Lincoln": [1098,840],
+ "Derby / South Yorks": [986,814],
+ "Derby / Warwick": [878,981],
+ "Dorset / Somerset": [716,1566],
+ "Dorset / Sussex": [965,1582],
+ "Dorset / Wilts": [879,1558],
+ "East Anglia / Essex": [1452,1168],
+ "East Anglia / Rutland": [1354,1042],
+ "East Yorks / North Yorks": [971,521],
+ "East Yorks / Northumbria": [997,431],
+ "East Yorks / South Yorks": [1039,654],
+ "Essex / Leicester": [1218,1165],
+ "Essex / Middlesex": [1300,1261],
+ "Essex / Rutland": [1287,1132],
+ "Glamorgan / Hereford": [712,1226],
+ "Glamorgan / Pembroke": [447,1274],
+ "Glamorgan / Powys": [563,1195],
+ "Gloucester / Hereford": [799,1282],
+ "Gloucester / Oxford": [956,1254],
+ "Gloucester / Somerset": [786,1397],
+ "Gloucester / Warwick": [881,1208],
+ "Gloucester / Wilts": [913,1351],
+ "Hereford / Powys": [640,1112],
+ "Hereford / Warwick": [793,1127],
+ "Kent / Middlesex": [1329,1401],
+ "Kent / Sussex": [1276,1509],
+ "Lancaster / North Yorks": [791,623],
+ "Lancaster / South Yorks": [880,701],
+ "Leicester / Lincoln": [1145,937],
+ "Leicester / Middlesex": [1157,1180],
+ "Leicester / Oxford": [1051,1173],
+ "Leicester / Rutland": [1172,1057],
+ "Leicester / Warwick": [974,1048],
+ "Lincoln / Rutland": [1211,967],
+ "Lincoln / South Yorks": [1111,741],
+ "Middlesex / Oxford": [1138,1298],
+ "Middlesex / Sussex": [1152,1413],
+ "North Yorks / Northumbria": [905,434],
+ "North Yorks / South Yorks": [939,611],
+ "Oxford / Sussex": [1085,1404],
+ "Oxford / Warwick": [975,1128],
+ "Oxford / Wilts": [1032,1363],
+ "Pembroke / Powys": [517,1141],
+ "Somerset / Wilts": [838,1452],
+ "Sussex / Wilts": [1018,1495],
+}
+
function toggle_blocks() {
document.getElementById("map").classList.toggle("hide_blocks")
}
@@ -85,6 +211,7 @@ let ui = {
card_backs: {},
areas: {},
blocks: {},
+ borders: [],
battle_menu: {},
battle_block: {},
present: new Set(),
@@ -458,6 +585,23 @@ function build_map() {
build_battle_block(b, block)
build_map_block(b, block)
}
+
+ for (let name in BORDERS_XY) {
+ let [x, y] = BORDERS_XY[name]
+ let [a, b] = name.split(" / ")
+ let id = area_index[a] * 100 + area_index[b]
+ let type = BORDERS[id] || "sea"
+ if (type !== "sea") {
+ let e = document.createElement("div")
+ e.my_id = id
+ e.my_show = "border " + type
+ e.className = "hide"
+ e.style.left = (x - 12) + "px"
+ e.style.top = (y - 12) + "px"
+ ui.borders.push(e)
+ document.getElementById("borders").appendChild(e)
+ }
+ }
}
function update_steps(b, steps, element) {
@@ -672,6 +816,32 @@ function update_map() {
if (view.who !== NOBODY)
ui.blocks[view.who].classList.add('selected')
}
+
+ for (let e of ui.borders) {
+ let u = map_get(view.last_used, e.my_id, 0)
+ let n = map_get(view.border_limit, e.my_id, "")
+ if (view.main_border && set_has(view.main_border, e.my_id))
+ n += "*"
+ switch (u) {
+ case 1:
+ e.className = "border Lancaster"
+ e.textContent = n
+ break
+ case 2:
+ e.className = "border York"
+ e.textContent = n
+ break
+ case 0:
+ if (n) {
+ e.className = e.my_show
+ e.textContent = n
+ } else {
+ e.className = "hide"
+ e.textContent = ""
+ }
+ break
+ }
+ }
}
function update_cards() {