summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-09-16 17:16:36 +0200
committerTor Andersson <tor@ccxvii.net>2023-02-18 11:54:52 +0100
commit8eb9e23aa7ed0269cfc1cbbb8a9bfa9107bf3a25 (patch)
tree2cba58e6ce9e5ce9a77bbefc9f84d7e55a366bdc
parentcadc1dcca1b350672e340f3aee79f5c98df00d92 (diff)
downloadwilderness-war-8eb9e23aa7ed0269cfc1cbbb8a9bfa9107bf3a25.tar.gz
Oops! Supply lines do not radiate from water ways.
-rw-r--r--rules.js50
1 files changed, 29 insertions, 21 deletions
diff --git a/rules.js b/rules.js
index 87b4763..13aae8b 100644
--- a/rules.js
+++ b/rules.js
@@ -2035,32 +2035,45 @@ function update_vp(name, s) {
// SUPPLY LINES
+function is_cultivated_or_fortification_or_amphib(space) {
+ return is_cultivated(space) || has_friendly_fortifications(space) || has_friendly_amphib(space)
+}
+
function search_supply_spaces_imp(queue) {
+ let visited = new Array(spaces.length).fill(0)
// console.log("======")
let reached = []
- for (let s of queue)
+ for (let s of queue) {
set_add(reached, s)
+ visited[s] = 1
+ }
while (queue.length > 0) {
- let current = queue.shift()
- // If we must have come here by water way:
- let cultivated = is_cultivated(current) || has_friendly_fortifications(current) || has_friendly_amphib(current)
- // console.log("SUPPLY", space_name(current), cultivated)
- for_each_exit_with_type(current, (next, type) => {
- if (set_has(reached, next))
- return // continue
+ let here = queue.shift()
+ // console.log("SUPPLY", space_name(here))
+ for_each_exit_with_type(here, (next, type) => {
+ if (visited[next])
+ return
if (has_unbesieged_enemy_units(next) || has_unbesieged_enemy_fortifications(next))
return // continue
- if (!cultivated) {
- // came from wilderness by water, must continue by water
- if (type !== 'land') {
- // console.log(" ", space_name(next), "(adjacent-water)")
+ if (is_cultivated_or_fortification_or_amphib(here)) {
+ // came from cultivated/fortification,
+ // may continue by water or another fortification
+ // may stop at anything
+ if (type !== 'land' || is_cultivated_or_fortification_or_amphib(next)) {
+ // console.log(" ", space_name(next), "(from cultivated, continue)")
set_add(reached, next)
+ visited[next] = 1
queue.push(next)
+ } else {
+ // console.log(" ", space_name(next), "(from cultivated, stop)")
+ // allow re-visits in case we come by water a longer way
+ set_add(reached, next)
}
} else {
- // came from cultivated by any path, may continue to cultivated or by water
- if (is_cultivated(next) || has_friendly_fortifications(next) || has_friendly_amphib(next) || type !== 'land') {
- // console.log(" ", space_name(next), "(from land)")
+ // in wilderness, arrived by water, must continue by water
+ if (type !== 'land') {
+ // console.log(" ", space_name(next), "(from river)")
+ visited[next] = 1
set_add(reached, next)
queue.push(next)
}
@@ -2091,12 +2104,7 @@ function is_in_supply(from) {
search_supply_spaces()
if (set_has(supply_cache, from))
return true
- let x = false
- for_each_exit(from, next => {
- if (set_has(supply_cache, next))
- x = true
- })
- return x
+ return false
}
function query_supply() {