summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data.js12
-rw-r--r--rules.js111
-rw-r--r--tools/gendata.js12
3 files changed, 54 insertions, 81 deletions
diff --git a/data.js b/data.js
index 8a9f0e4..57c97b4 100644
--- a/data.js
+++ b/data.js
@@ -1,11 +1,11 @@
const data = {
seaports:[0,1,5,6,14,15,17,19,20,21,22,24,26,35,37,51,52,54,55,56,57,58,59,60],
-exile_1:[55],
-exile_2:[52],
-exile_3:[54],
-sea_1:[60],
-sea_2:[58],
-sea_3:[59],
+exile_1:55,
+exile_2:52,
+exile_3:54,
+sea_1:60,
+sea_2:58,
+sea_3:59,
port_1:[0,1,35,37,56,57],
port_2:[14,15,17,19,20,21,22,24,51],
port_3:[5,6,26],
diff --git a/rules.js b/rules.js
index 6c997ed..cb2928a 100644
--- a/rules.js
+++ b/rules.js
@@ -3498,12 +3498,36 @@ function parley_adjacent(here, _) {
}
function find_ports_from_exile(here) {
- if (set_has(data.exile_1, here))
- return data.port_1
- if (set_has(data.exile_2, here))
- return data.port_2
- if (set_has(data.exile_3, here))
- return data.port_3
+ switch (here) {
+ case data.exile_1: return data.port_1
+ case data.exile_2: return data.port_2
+ case data.exile_3: return data.port_3
+ }
+ return null
+}
+
+function find_ports_from_sea(here) {
+ switch (here) {
+ case data.sea_1: return data.port_1
+ case data.sea_2: return data.port_2
+ case data.sea_3: return data.port_3
+ }
+ return null
+}
+
+function find_destinations_from_port(here) {
+ switch (true) {
+ case here === data.exile_1: return data.way_exile_1
+ case here === data.exile_2: return data.way_exile_2
+ case here === data.exile_3: return data.way_exile_3
+ case here === data.sea_1: return data.way_sea_1
+ case here === data.sea_2: return data.way_sea_2
+ case here === data.sea_3: return data.way_sea_3
+ case set_has(data.port_1, here): return data.way_port_1
+ case set_has(data.port_2, here): return data.way_port_2
+ case set_has(data.port_3, here): return data.way_port_3
+ }
+ return null
}
function find_parley_targets(lord, acceptfn, adjacentfn) {
@@ -4536,11 +4560,10 @@ function can_action_sail() {
return false
// and a valid destination
- for (let to of data.seaports) {
- if (to !== here && !has_enemy_lord(to))
- return true
- if (has_enemy_lord(to) && lord_has_capability(game.command, AOW_LANCASTER_HIGH_ADMIRAL))
- return true
+ for (let to of find_destinations_from_port(here)) {
+ if (to !== here)
+ if (!has_enemy_lord(to) || lord_has_capability(game.command, AOW_LANCASTER_HIGH_ADMIRAL))
+ return true
}
return false
}
@@ -4565,44 +4588,10 @@ states.sail = {
if (overflow_prov <= 0 && overflow_cart <= 0) {
view.prompt = `Sail: Select a destination Seaport.`
- let from = 0
- switch (true) {
- case set_has(data.exile_1, here):
- from = data.way_exile_1
- break
- case set_has(data.exile_2, here):
- from = data.way_exile_2
- break
- case set_has(data.exile_3, here):
- from = data.way_exile_3
- break
- case set_has(data.sea_1, here):
- from = data.way_sea_1
- break
- case set_has(data.sea_2, here):
- from = data.way_sea_2
- break
- case set_has(data.sea_3, here):
- from = data.way_sea_3
- break
- case set_has(data.port_1, here):
- from = data.way_port_1
- break
- case set_has(data.port_2, here):
- from = data.way_port_2
- break
- case set_has(data.port_3, here):
- from = data.way_port_3
- break
- }
- for (let to of from) {
- if (to === here)
- continue
- if (
- !has_enemy_lord(to) ||
- (has_enemy_lord(to) && lord_has_capability(game.command, AOW_LANCASTER_HIGH_ADMIRAL))
- )
- gen_action_locale(to)
+ for (let to of find_destinations_from_port(here)) {
+ if (to !== here)
+ if (!has_enemy_lord(to) || lord_has_capability(game.command, AOW_LANCASTER_HIGH_ADMIRAL))
+ gen_action_locale(to)
}
} else if (overflow_cart > 0) {
view.prompt = `Sailing with ${ships} Ships. Please discard ${overflow_cart} Cart`
@@ -7360,26 +7349,11 @@ function do_disembark() {
return success
}
-function for_each_port(sea, f) {
- let ports = null
- if (set_has(data.sea_1, sea))
- ports = data.port_1
- if (set_has(data.sea_2, sea))
- ports = data.port_2
- if (set_has(data.sea_3, sea))
- ports = data.port_3
- if (ports)
- for (let loc of ports)
- f(loc)
-}
-
function has_safe_ports(sea) {
- let result = false
- for_each_port(sea, loc => {
+ for (let loc of find_ports_from_sea(sea))
if (!has_enemy_lord(loc))
- result = true
- })
- return result
+ return true
+ return false
}
states.disembark = {
@@ -7396,10 +7370,9 @@ states.disembark = {
}
} else {
let sea = get_lord_locale(game.who)
- for_each_port(sea, loc => {
+ for (let loc of find_ports_from_sea(sea))
if (!has_enemy_lord(loc))
gen_action_locale(loc)
- })
}
if (done) {
view.actions.done = 1
diff --git a/tools/gendata.js b/tools/gendata.js
index de65737..6d4850a 100644
--- a/tools/gendata.js
+++ b/tools/gendata.js
@@ -730,13 +730,13 @@ let way_port_3 = ["Bristol","Pembroke","Harlech", "Irish Sea"].map(name => locma
-let sea_1 = ["North Sea"].map(name => locmap[name]).sort(cmpnum)
-let sea_2 = ["English Channel"].map(name => locmap[name]).sort(cmpnum)
-let sea_3 = ["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 exile_1 = ["Burgundy"].map(name => locmap[name]).sort(cmpnum)
-let exile_2 = ["France"].map(name => locmap[name]).sort(cmpnum)
-let exile_3 = ["Ireland"].map(name => locmap[name]).sort(cmpnum)
+let exile_1 = locmap["Burgundy"]
+let exile_2 = locmap["France"]
+let exile_3 = locmap["Ireland"]
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)