summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-10-06 19:49:30 +0200
committerTor Andersson <tor@ccxvii.net>2023-12-10 18:16:55 +0100
commit509116f2d6226473f206bc58d1b40f4cddfb4061 (patch)
tree8e2343448172298e3d7ea0244bd5c2762aab546d /play.js
parent8b95b0ecd590f40fd6bb14d1f6c23731cacb25a7 (diff)
downloadplantagenet-509116f2d6226473f206bc58d1b40f4cddfb4061.tar.gz
Use common routed_vassals set (instead of one set per lord).
Diffstat (limited to 'play.js')
-rw-r--r--play.js25
1 files changed, 13 insertions, 12 deletions
diff --git a/play.js b/play.js
index 4beb59b..c82b651 100644
--- a/play.js
+++ b/play.js
@@ -392,15 +392,10 @@ function get_vassal_locale(vassal) {
return pack8_get(view.pieces.vassals[vassal], 1)
}
-function get_vassals_with_lord(lord) {
- let results = []
- for (let x = first_vassal; x < last_vassal; x++) {
- if (pack8_get(view.pieces.vassals[x], 0) === lord) {
- results.push(x)
- }
- }
-
- return results
+function for_each_vassal_with_lord(lord, f) {
+ for (let x = first_vassal; x < last_vassal; x++)
+ if (pack8_get(view.pieces.vassals[x], 0) === lord)
+ f(x)
}
function is_york_locale(loc) {
@@ -1104,9 +1099,15 @@ function update_forces(parent, forces, lord_ix, routed) {
parent.replaceChildren()
for (let i = 0; i < force_type_count; ++i) {
if (i === VASSAL) {
- get_vassals_with_lord(lord_ix)
- .filter(v => (view.battle === 0 && routed === false) || (view.battle !== 0 && view.battle.routed_vassals[lord_ix].includes(v) === routed))
- .forEach(v => add_vassal(parent, v, lord_ix, routed))
+ for_each_vassal_with_lord(lord_ix, v => {
+ if (view.battle) {
+ if (routed === false)
+ add_vassal(parent, v, lord_ix, routed)
+ } else {
+ if (set_has(view.battle.routed_vassals, v) === routed)
+ add_vassal(parent, v, lord_ix, routed)
+ }
+ })
} else {
let n = pack4_get(forces, i)
for (let k = 0; k < n; ++k) {