diff options
-rw-r--r-- | data.js | 40 | ||||
-rw-r--r-- | play.js | 2 | ||||
-rw-r--r-- | rules.ts | 137 | ||||
-rw-r--r-- | tools/gendata.js | 133 |
4 files changed, 152 insertions, 160 deletions
@@ -1,6 +1,4 @@ const data = { -seaports:[0,1,5,6,14,15,17,19,20,21,22,24,26,35,37,51,52,54,55,56,57], -exile_boxes:[52,53,54,55], exile_1:55, exile_2:52, exile_3:54, @@ -8,20 +6,20 @@ exile_4:53, sea_1:60, sea_2:58, sea_3:59, -port_1:[0,1,35,37,56,57], +port_1:[1,35,37,56,57], port_2:[14,15,17,19,20,21,22,24,51], port_3:[5,6,26], -all_ports:[0,1,5,6,14,15,17,19,20,21,22,24,26,35,37,51,56,57], -way_exile_1:[1,35,37,55,56,57,60], -way_exile_2:[14,15,17,19,20,21,22,24,51,52,58], -way_exile_3:[5,6,26,54,59], -way_exile_4:[0,1,35,37,53,56,57,60], -way_sea_1:[0,1,14,15,17,19,20,21,22,24,35,37,51,56,57,58,60], -way_sea_2:[0,1,5,6,14,15,17,19,20,21,22,24,26,35,37,51,56,57,58,58,59,60], -way_sea_3:[5,6,14,15,17,19,20,21,22,24,26,51,58,59], -way_port_1:[0,1,35,37,56,57,60], -way_port_2:[14,15,17,19,20,21,22,24,51,58], -way_port_3:[5,6,26,59], +all_ports:[1,5,6,14,15,17,19,20,21,22,24,26,35,37,51,56,57], +sail_exile_1:[60,1,35,37,56,57], +sail_exile_2:[58,14,15,17,19,20,21,22,24,51], +sail_exile_3:[59,5,6,26], +sail_exile_4:[60,1,35,37,56,57], +sail_sea_1:[1,14,15,17,19,20,21,22,24,35,37,51,56,57,58], +sail_sea_2:[1,5,6,14,15,17,19,20,21,22,24,26,35,37,51,56,57,59,60], +sail_sea_3:[5,6,14,15,17,19,20,21,22,24,26,51,58], +sail_port_1:[60,1,35,37,56,57], +sail_port_2:[58,14,15,17,19,20,21,22,24,51], +sail_port_3:[59,5,6,26], locales:[ {"name":"Bamburgh","type":"fortress","region":"North","adjacent":[1],"highways":[1],"roads":[],"paths":[],"not_paths":[1],"box":{"x":637,"y":300,"w":60,"h":45}}, {"name":"Newcastle","type":"city","region":"North","adjacent":[0,2,3,50,56],"highways":[0,50],"roads":[2,3,56],"paths":[],"not_paths":[0,2,3,50,56],"box":{"x":656,"y":419,"w":70,"h":77}}, @@ -75,15 +73,15 @@ locales:[ {"name":"Lincoln","type":"city","region":"England","adjacent":[39,45,50,57],"highways":[39,50],"roads":[45,57],"paths":[],"not_paths":[39,45,50,57],"box":{"x":767,"y":760,"w":78,"h":64}}, {"name":"York","type":"city","region":"England","adjacent":[1,47,49,56,57],"highways":[1,49],"roads":[56,57],"paths":[47],"not_paths":[1,49,56,57],"box":{"x":691,"y":623,"w":76,"h":65}}, {"name":"Calais","type":"calais","region":"England","adjacent":[],"highways":[],"roads":[],"paths":[],"not_paths":[],"box":{"x":1134,"y":1418,"w":67,"h":79}}, -{"name":"France","type":"exile","region":"England","adjacent":[],"highways":[],"roads":[],"paths":[],"not_paths":[],"box":{"x":890,"y":1430,"w":109,"h":114}}, -{"name":"Scotland","type":"exile","region":"England","adjacent":[],"highways":[],"roads":[],"paths":[0,4],"not_paths":[],"box":{"x":450,"y":278,"w":111,"h":118}}, -{"name":"Ireland","type":"exile","region":"England","adjacent":[],"highways":[],"roads":[],"paths":[],"not_paths":[],"box":{"x":50,"y":949,"w":110,"h":121}}, -{"name":"Burgundy","type":"exile","region":"England","adjacent":[],"highways":[],"roads":[],"paths":[],"not_paths":[],"box":{"x":996,"y":688,"w":110,"h":121}}, +{"name":"France","type":"exile_box","region":null,"adjacent":[],"highways":[],"roads":[],"paths":[],"not_paths":[],"box":{"x":890,"y":1430,"w":109,"h":114}}, +{"name":"Scotland","type":"exile_box","region":null,"adjacent":[],"highways":[],"roads":[],"paths":[0,4],"not_paths":[],"box":{"x":450,"y":278,"w":111,"h":118}}, +{"name":"Ireland","type":"exile_box","region":null,"adjacent":[],"highways":[],"roads":[],"paths":[],"not_paths":[],"box":{"x":50,"y":949,"w":110,"h":121}}, +{"name":"Burgundy","type":"exile_box","region":null,"adjacent":[],"highways":[],"roads":[],"paths":[],"not_paths":[],"box":{"x":996,"y":688,"w":110,"h":121}}, {"name":"Scarborough","type":"town","region":"North","adjacent":[1,50],"highways":[],"roads":[1,50],"paths":[],"not_paths":[1,50],"box":{"x":791,"y":532,"w":78,"h":57}}, {"name":"Ravenspur","type":"fortress","region":"England","adjacent":[49,50],"highways":[],"roads":[49,50],"paths":[],"not_paths":[49,50],"box":{"x":835,"y":721,"w":72,"h":45}}, -{"name":"English Channel","type":"sea","region":"England","adjacent":[],"highways":[],"roads":[],"paths":[],"not_paths":[],"box":{"x":564,"y":1461,"w":173,"h":69}}, -{"name":"Irish Sea","type":"sea","region":"England","adjacent":[],"highways":[],"roads":[],"paths":[],"not_paths":[],"box":{"x":233,"y":667,"w":160,"h":93}}, -{"name":"North Sea","type":"sea","region":"England","adjacent":[],"highways":[],"roads":[],"paths":[],"not_paths":[],"box":{"x":1106,"y":749,"w":97,"h":117}}, +{"name":"English Channel","type":"sea","region":null,"adjacent":[],"highways":[],"roads":[],"paths":[],"not_paths":[],"box":{"x":564,"y":1461,"w":173,"h":69}}, +{"name":"Irish Sea","type":"sea","region":null,"adjacent":[],"highways":[],"roads":[],"paths":[],"not_paths":[],"box":{"x":233,"y":667,"w":160,"h":93}}, +{"name":"North Sea","type":"sea","region":null,"adjacent":[],"highways":[],"roads":[],"paths":[],"not_paths":[],"box":{"x":1106,"y":749,"w":97,"h":117}}, ], ways:[ [1,"highway"], @@ -739,7 +739,7 @@ function build_map() { locale_layout[i] = [] data.locales.forEach((locale, ix) => { - let region = clean_name(locale.region) + let region = locale.region ? clean_name(locale.region) : "" let { x, y, w, h } = locale.box let xc = Math.round(x + w / 2) let yc = Math.round(y + h / 2) @@ -21,11 +21,8 @@ NAVAL BLOCKADE - for Tax and Tax Collectors REGROUP - other timing windows - Manual ADD and REMOVE battle capability troops at reposition and aftermath - Scenario special rules. - Ia: Allied Networks (limit exile boxes) Ia: Capture of the King Ib: Norfolk is Late @@ -513,71 +510,30 @@ function is_lieutenant(lord: Lord) { } } -// TODO: optimize these functions with range checks (like wilderness war) -// TODO: use array tests (and compact NOWHERE/CALENDAR/CALENDAR_EXILE just before and after normal locales for them to also be in the array - -function is_seaport(loc: Locale) { - return set_has(data.seaports, loc) -} - -function is_stronghold(loc: Locale) { - if (loc === NOWHERE || loc >= CALENDAR) - return false - return data.locales[loc].type !== "exile" && data.locales[loc].type !== "sea" -} - -function is_exile_box(loc: Locale) { - if (loc === NOWHERE || loc >= CALENDAR) - return false - return data.locales[loc].type === "exile" -} - -function is_city(loc: Locale) { - if (loc === NOWHERE || loc >= CALENDAR) - return false - return data.locales[loc].type === "city" -} - -function is_town(loc: Locale) { - if (loc === NOWHERE || loc >= CALENDAR) - return false - return data.locales[loc].type === "town" -} - -function is_wales(loc: Locale) { - if (loc === NOWHERE || loc >= CALENDAR) - return false - return data.locales[loc].region === "Wales" -} - -function is_south(loc: Locale) { - if (loc === NOWHERE || loc >= CALENDAR) - return false - return data.locales[loc].region === "South" -} - -function is_north(loc: Locale) { - if (loc === NOWHERE || loc >= CALENDAR) - return false - return data.locales[loc].region === "North" -} - -function is_fortress(loc: Locale) { - if (loc === NOWHERE || loc >= CALENDAR) - return false - return data.locales[loc].type === "fortress" -} - -function is_sea(loc: Locale) { - if (loc === NOWHERE || loc >= CALENDAR) - return false - return data.locales[loc].type === "sea" -} +// from !node tools/gendata.js +function is_seaport(x: Locale) { return x === 1 || (x >= 5 && x <= 6) || (x >= 14 && x <= 15) || x === 17 || (x >= 19 && x <= 22) || x === 24 || x === 26 || x === 35 || x === 37 || x === 51 || (x >= 56 && x <= 57) } +function is_port_1(x: Locale) { return x === 1 || x === 35 || x === 37 || (x >= 56 && x <= 57) } +function is_port_2(x: Locale) { return (x >= 14 && x <= 15) || x === 17 || (x >= 19 && x <= 22) || x === 24 || x === 51 } +function is_port_3(x: Locale) { return (x >= 5 && x <= 6) || x === 26 } +function is_adjacent_north_sea(x: Locale) { return x === 1 || x === 35 || x === 37 || (x >= 56 && x <= 57) } +function is_adjacent_english_channel(x: Locale) { return (x >= 14 && x <= 15) || x === 17 || (x >= 19 && x <= 22) || x === 24 || x === 51 } +function is_adjacent_irish_sea(x: Locale) { return (x >= 5 && x <= 6) || x === 26 } +function is_stronghold(x: Locale) { return (x >= 52 && x <= 55) || (x >= 58 && x <= 60) } +function is_fortress(x: Locale) { return x === 0 || x === 6 || x === 9 || x === 37 || x === 57 } +function is_north(x: Locale) { return (x >= 0 && x <= 4) || x === 56 } +function is_city(x: Locale) { return x === 1 || x === 4 || (x >= 7 && x <= 8) || (x >= 10 && x <= 13) || x === 16 || x === 18 || x === 21 || x === 23 || (x >= 25 && x <= 28) || x === 36 || (x >= 38 && x <= 39) || x === 41 || x === 43 || (x >= 46 && x <= 47) || (x >= 49 && x <= 50) } +function is_town(x: Locale) { return (x >= 2 && x <= 3) || (x >= 14 && x <= 15) || x === 17 || (x >= 19 && x <= 20) || x === 22 || x === 24 || x === 29 || (x >= 31 && x <= 35) || x === 40 || x === 42 || (x >= 44 && x <= 45) || x === 48 || x === 56 } +function is_harlech(x: Locale) { return x === 5 } +function is_wales(x: Locale) { return (x >= 5 && x <= 10) } +function is_south(x: Locale) { return (x >= 11 && x <= 19) } +function is_england(x: Locale) { return (x >= 20 && x <= 51) || x === 57 } +function is_london(x: Locale) { return x === 30 } +function is_calais(x: Locale) { return x === 51 } +function is_exile_box(x: Locale) { return (x >= 52 && x <= 55) } +function is_sea(x: Locale) { return (x >= 58 && x <= 60) } function is_adjacent(a: Locale, b: Locale) { - if (a === NOWHERE || a >= CALENDAR) - return false - return set_has(data.locales[a].adjacent, b) + return is_stronghold(a) && is_stronghold(b) && set_has(data.locales[a].adjacent, b) } function find_ports(here: Locale, lord: Lord): Locale[] { @@ -595,30 +551,31 @@ function find_ports(here: Locale, lord: Lord): Locale[] { if (here === data.exile_2) return data.port_2 if (here === data.exile_3) return data.port_3 if (here === data.exile_4) return data.port_1 - if (set_has(data.port_1, here)) return data.port_1 - if (set_has(data.port_2, here)) return data.port_2 - if (set_has(data.port_3, here)) return data.port_3 + if (is_port_1(here)) return data.port_1 + if (is_port_2(here)) return data.port_2 + if (is_port_3(here)) return data.port_3 return null } function find_sail_locales(here: Locale): Locale[] { - if (here === data.sea_1) return data.way_sea_1 - if (here === data.sea_2) return data.way_sea_2 - if (here === data.sea_3) return data.way_sea_3 - if (here === data.exile_1) return data.way_exile_1 - if (here === data.exile_2) return data.way_exile_2 - if (here === data.exile_3) return data.way_exile_3 - if (set_has(data.port_1, here)) return data.way_port_1 - if (set_has(data.port_2, here)) return data.way_port_2 - if (set_has(data.port_3, here)) return data.way_port_3 + if (here === data.sea_1) return data.sail_sea_1 + if (here === data.sea_2) return data.sail_sea_2 + if (here === data.sea_3) return data.sail_sea_3 + if (here === data.exile_1) return data.sail_exile_1 + if (here === data.exile_2) return data.sail_exile_2 + if (here === data.exile_3) return data.sail_exile_3 + if (here === data.exile_4) return data.sail_exile_4 + if (is_port_1(here)) return data.sail_port_1 + if (is_port_2(here)) return data.sail_port_2 + if (is_port_3(here)) return data.sail_port_3 return null } function is_on_same_sea(a: Locale, b: Locale) { return ( - (set_has(data.port_1, a) && set_has(data.port_1, b)) || - (set_has(data.port_2, a) && set_has(data.port_2, b)) || - (set_has(data.port_3, a) && set_has(data.port_3, b)) + (is_port_1(a) && is_port_1(b)) || + (is_port_2(a) && is_port_2(b)) || + (is_port_3(a) && is_port_3(b)) ) } @@ -636,6 +593,7 @@ const all_wales_locales = make_locale_list(is_wales) const all_city_locales = make_locale_list(is_city) const all_town_locales = make_locale_list(is_town) const all_fortress_locales = make_locale_list(is_fortress) +const all_exile_boxes = make_locale_list(is_exile_box) const Y1 = find_card("Y1") const Y2 = find_card("Y2") @@ -1395,13 +1353,6 @@ function count_lord_all_forces(lord: Lord) { ) } -function lord_has_routed_vassals(lord: Lord) { - for (let v of game.battle.routed_vassals) - if (is_vassal_mustered_with(v, lord)) - return true - return false -} - function lord_has_unrouted_units(lord: Lord) { for (let x of all_force_types) if (get_lord_forces(lord, x) > 0) @@ -1757,10 +1708,10 @@ function has_favour_in_locale(side: Player, loc: Locale) { function is_at_or_adjacent_to_friendly_english_channel_port(loc: Locale) { if (is_stronghold(loc)) { - if (is_friendly_locale(loc) && set_has(data.port_2, loc)) + if (is_friendly_locale(loc) && is_adjacent_english_channel(loc)) return true for (let next of data.locales[loc].adjacent) - if (is_friendly_locale(next) && set_has(data.port_2, next)) + if (is_friendly_locale(next) && is_adjacent_english_channel(next)) return true } return false @@ -2710,7 +2661,7 @@ states.muster_exiles = { if (done) view.actions.done = true } else { - for (let loc of data.exile_boxes) { + for (let loc of all_exile_boxes) { if (can_use_exile_box(game.who, loc)) gen_action_locale(loc) } @@ -3257,7 +3208,7 @@ function can_add_troops_irishmen(lord: Lord, locale: Locale) { return ( can_add_troops(locale) && lord_has_capability(lord, AOW_YORK_IRISHMEN) && - (locale === LOC_IRELAND || !set_has(data.port_3, locale)) + (locale === LOC_IRELAND || is_adjacent_irish_sea(locale)) ) } @@ -11458,7 +11409,7 @@ states.exile_pact = { inactive: "Exile Pact", prompt() { view.prompt = "Exile Pact: Place your cylinder in a Friendly Exile box." - for (let loc of data.exile_boxes) { + for (let loc of all_exile_boxes) { if (has_favour_in_locale(game.active, loc)) gen_action_locale(loc) } diff --git a/tools/gendata.js b/tools/gendata.js index e2b4106..4d97854 100644 --- a/tools/gendata.js +++ b/tools/gendata.js @@ -338,6 +338,7 @@ var seat = [] var vassalbox = [] const scale = 1 +var is = { stronghold: [] } function defloc(region, type, name) { let [x, y, w, h] = boxes[name] @@ -346,7 +347,16 @@ function defloc(region, type, name) { w = Math.ceil(w) h = Math.ceil(h) locmap[name] = locales.length - locales.push({ name, type, region, adjacent: [], highways: [], roads: [], paths: [], not_paths: [], box: { x, y, w, h } }) + let id = locales.length + locales.push({ name, type, region, adjacent: [], highways: [], roads: [], paths: [], not_paths: [], box:{x,y,w,h} }) + if (!is[type]) is[type] = [] + is[type].push(id) + if (region) { + if (!is[region]) is[region] = [] + is[region].push(id) + } else { + is.stronghold.push(id) + } ways.push([]) } @@ -488,15 +498,18 @@ defloc("England", "town", "Lancaster") defloc("England", "city", "Lincoln") defloc("England", "city", "York") defloc("England", "calais", "Calais") -defloc("England", "exile", "France") -defloc("England", "exile", "Scotland") -defloc("England", "exile", "Ireland") -defloc("England", "exile", "Burgundy") + +defloc(null, "exile_box", "France") +defloc(null, "exile_box", "Scotland") +defloc(null, "exile_box", "Ireland") +defloc(null, "exile_box", "Burgundy") + defloc("North", "town", "Scarborough") defloc("England", "fortress", "Ravenspur") -defloc("England", "sea", "English Channel") -defloc("England", "sea", "Irish Sea") -defloc("England", "sea", "North Sea") + +defloc(null, "sea", "English Channel") +defloc(null, "sea", "Irish Sea") +defloc(null, "sea", "North Sea") // LOCALE DEPLETION @@ -766,42 +779,32 @@ map_set(ways[locmap.Scotland], locmap.Bamburgh, "path") locales[locmap.Scotland].paths.push(locmap.Carlisle) map_set(ways[locmap.Scotland], locmap.Carlisle, "path") -let way_sea_1 = ["North Sea", "English Channel", "Bamburgh", "Newcastle", "Scarborough", "Ravenspur", "Lynn", "Ipswich", "Dover", "Hastings", "Calais", "Arundel", "Southampton", "Dorchester", "Exeter", "Plymouth", "Truro"].map(name => locmap[name]).sort(cmpnum) -let way_sea_2 = ["English Channel","North Sea", "Irish Sea", "Bristol","Pembroke","Harlech", "English Channel","Bamburgh", "Newcastle", "Scarborough", "Ravenspur", "Lynn", "Ipswich","Dover", "Hastings", "Calais", "Arundel", "Southampton", "Dorchester", "Exeter", "Plymouth", "Truro" ].map(name => locmap[name]).sort(cmpnum) -let way_sea_3 = ["English Channel", "Bristol","Pembroke","Harlech", "Dover", "Hastings", "Calais", "Arundel", "Southampton", "Dorchester", "Exeter", "Plymouth", "Truro","Irish Sea"].map(name => locmap[name]).sort(cmpnum) - -let way_exile_1 = ["Burgundy", "Newcastle", "Scarborough", "Ravenspur", "Lynn", "Ipswich", "North Sea"].map(name => locmap[name]).sort(cmpnum) -let way_exile_2 = ["France", "English Channel", "Dover", "Hastings", "Calais", "Arundel", "Southampton", "Dorchester", "Exeter", "Plymouth", "Truro"].map(name => locmap[name]).sort(cmpnum) -let way_exile_3 = ["Ireland", "Irish Sea", "Bristol","Pembroke","Harlech"].map(name => locmap[name]).sort(cmpnum) -let way_exile_4 = ["Scotland", "Bamburgh", "Newcastle", "Scarborough", "Ravenspur", "Lynn", "Ipswich", "North Sea"].map(name => locmap[name]).sort(cmpnum) - -let way_port_1 = ["Bamburgh", "Newcastle", "Scarborough", "Ravenspur", "Lynn", "Ipswich", "North Sea"].map(name => locmap[name]).sort(cmpnum) -let way_port_2 = ["Dover", "Hastings", "Calais", "Arundel", "Southampton", "Dorchester", "Exeter", "Plymouth", "Truro", "English Channel"].map(name => locmap[name]).sort(cmpnum) -let way_port_3 = ["Bristol","Pembroke","Harlech", "Irish Sea"].map(name => locmap[name]).sort(cmpnum) - - - let sea_1 = locmap["North Sea"] let sea_2 = locmap["English Channel"] let sea_3 = locmap["Irish Sea"] +let port_1 = ["Newcastle", "Scarborough", "Ravenspur", "Lynn", "Ipswich"].map(name => locmap[name]).sort(cmpnum) +let port_2 = ["Dover", "Hastings", "Calais", "Arundel", "Southampton", "Dorchester", "Exeter", "Plymouth", "Truro"].map(name => locmap[name]).sort(cmpnum) +let port_3 = ["Bristol","Pembroke","Harlech"].map(name => locmap[name]).sort(cmpnum) +let all_ports = [ ...port_1, ...port_2, ...port_3 ].sort(cmpnum) + let exile_1 = locmap["Burgundy"] let exile_2 = locmap["France"] let exile_3 = locmap["Ireland"] let exile_4 = locmap["Scotland"] -let port_1 = ["Bamburgh", "Newcastle", "Scarborough", "Ravenspur", "Lynn", "Ipswich"].map(name => locmap[name]).sort(cmpnum) -let port_2 = ["Dover", "Hastings", "Calais", "Arundel", "Southampton", "Dorchester", "Exeter", "Plymouth", "Truro"].map(name => locmap[name]).sort(cmpnum) -let port_3 = ["Bristol","Pembroke","Harlech"].map(name => locmap[name]).sort(cmpnum) -let all_ports = [ ...port_1, ...port_2, ...port_3 ].sort(cmpnum) +let sail_sea_1 = [ ...port_1, ...port_2, sea_2 ].sort(cmpnum) +let sail_sea_2 = [ ...port_1, ...port_2, ...port_3, sea_1, sea_3 ].sort(cmpnum) +let sail_sea_3 = [ ...port_2, ...port_3, sea_2 ].sort(cmpnum) -let seaports = [ - "Bamburgh", "Newcastle", "Scarborough", "Ravenspur", "Lynn", "Ipswich", "Burgundy", "Dover", "Hastings", "Calais", "France", "Arundel", "Southampton","Dorchester","Exeter","Plymouth","Truro","Bristol","Pembroke","Harlech", "Ireland" -].map(name => locmap[name]).sort(cmpnum) +let sail_exile_1 = [ sea_1, ...port_1 ] +let sail_exile_2 = [ sea_2, ...port_2 ] +let sail_exile_3 = [ sea_3, ...port_3 ] +let sail_exile_4 = [ sea_1, ...port_1 ] -let exile_boxes = [ - "Burgundy", "France", "Ireland", "Scotland" -].map(name => locmap[name]).sort(cmpnum) +let sail_port_1 = [ sea_1, ...port_1 ] +let sail_port_2 = [ sea_2, ...port_2 ] +let sail_port_3 = [ sea_3, ...port_3 ] function dumplist(name, list) { print(name + ":[") @@ -1755,9 +1758,15 @@ vassal(0, "Thomas Stanley", -1, 0, "Thomas Stanley") vassal(0, "Montagu", -1, 0, "Alice Montagu") vassal(0, "Hastings", -1, 0, "Hastings") +function make_is_list(list) { + let out = [] + for (let i = 0; i < locales.length + 35; ++i) + out.push(list.includes(i) ? 1 : 0) + return out +} + print("const data = {") -print("seaports:" + JSON.stringify(seaports) + ",") -print("exile_boxes:" + JSON.stringify(exile_boxes) + ",") + print("exile_1:" + JSON.stringify(exile_1) + ",") print("exile_2:" + JSON.stringify(exile_2) + ",") print("exile_3:" + JSON.stringify(exile_3) + ",") @@ -1769,26 +1778,60 @@ print("port_1:" + JSON.stringify(port_1) + ",") print("port_2:" + JSON.stringify(port_2) + ",") print("port_3:" + JSON.stringify(port_3) + ",") print("all_ports:" + JSON.stringify(all_ports) + ",") -print("way_exile_1:" + JSON.stringify(way_exile_1) + ",") -print("way_exile_2:" + JSON.stringify(way_exile_2) + ",") -print("way_exile_3:" + JSON.stringify(way_exile_3) + ",") -print("way_exile_4:" + JSON.stringify(way_exile_4) + ",") -print("way_sea_1:" + JSON.stringify(way_sea_1) + ",") -print("way_sea_2:" + JSON.stringify(way_sea_2) + ",") -print("way_sea_3:" + JSON.stringify(way_sea_3) + ",") -print("way_port_1:" + JSON.stringify(way_port_1) + ",") -print("way_port_2:" + JSON.stringify(way_port_2) + ",") -print("way_port_3:" + JSON.stringify(way_port_3) + ",") +print("sail_exile_1:" + JSON.stringify(sail_exile_1) + ",") +print("sail_exile_2:" + JSON.stringify(sail_exile_2) + ",") +print("sail_exile_3:" + JSON.stringify(sail_exile_3) + ",") +print("sail_exile_4:" + JSON.stringify(sail_exile_4) + ",") +print("sail_sea_1:" + JSON.stringify(sail_sea_1) + ",") +print("sail_sea_2:" + JSON.stringify(sail_sea_2) + ",") +print("sail_sea_3:" + JSON.stringify(sail_sea_3) + ",") +print("sail_port_1:" + JSON.stringify(sail_port_1) + ",") +print("sail_port_2:" + JSON.stringify(sail_port_2) + ",") +print("sail_port_3:" + JSON.stringify(sail_port_3) + ",") + dumplist("locales", locales) dumplist("ways", ways) dumplist("lords", lords) dumplist("vassals", vassals) dumplist("cards", cards) + +// layout client only dumplist("favour", favour) dumplist("deplete",deplete) dumplist("seat", seat) dumplist("vassalbox", vassalbox) + print("}") + print("if (typeof module !== 'undefined') module.exports = data") fs.writeFileSync("data.js", data.join("\n") + "\n") + +function gen_test(name, set) { + let ranges = [] + let start = -1 + for (let x = 0; x < locales.length; ++x) { + if (set.includes(x)) { + if (start < 0) + start = x + } else { + if (start >= 0) { + ranges.push([ start, x - 1 ]) + start = -1 + } + } + } + if (start >= 0) + ranges.push([ start, locales.length - 1 ]) + console.log("function " + name + "(x: Locale) { return " + ranges.map(([ a, b ]) => (a!==b) ?`(x >= ${a} && x <= ${b})` : `x === ${a}`).join(" || ") + " }") +} + +gen_test("is_seaport", all_ports) +gen_test("is_port_1", port_1) +gen_test("is_port_2", port_2) +gen_test("is_port_3", port_3) +gen_test("is_adjacent_north_sea", port_1) +gen_test("is_adjacent_english_channel", port_2) +gen_test("is_adjacent_irish_sea", port_3) +for (let key in is) + gen_test("is_" + key.toLowerCase(), is[key]) |