summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2025-05-07 00:07:17 +0200
committerTor Andersson <tor@ccxvii.net>2025-05-07 00:07:17 +0200
commitf330f88d68f12782772fa24f2861fccdc75df9cf (patch)
treee20c5586a71d4716cb976a54ea30e1cf4d8e7b0b
parent4d20309060980a722b0f799277fc9df4cdb5e880 (diff)
downloadwilderness-war-f330f88d68f12782772fa24f2861fccdc75df9cf.tar.gz
Streamline picking up leaders units.
Separate buttons to pick up: - all (only if all can be picked uppossible) - leaders - drilled troops (as many as fit) - auxiliaries (as many as fit)
-rw-r--r--play.js3
-rw-r--r--rules.js140
2 files changed, 113 insertions, 30 deletions
diff --git a/play.js b/play.js
index c3769c4..208015c 100644
--- a/play.js
+++ b/play.js
@@ -1600,6 +1600,9 @@ function update_map() {
action_button("naval_move", "Naval")
action_button("eliminate", "Eliminate")
action_button("pick_up_all", "Pick up all")
+ action_button("pick_up_ld", "Pick up leaders")
+ action_button("pick_up_dt", "Pick up drilled troops")
+ action_button("pick_up_ax", "Pick up auxiliaries")
action_button("drop_off", "Drop off")
action_button("activate", "Activate")
action_button("intercept", "Intercept")
diff --git a/rules.js b/rules.js
index 4cfc3f2..681de95 100644
--- a/rules.js
+++ b/rules.js
@@ -2597,6 +2597,75 @@ const designate_force_reason_prompt = {
'avoid': "to avoid battle",
}
+function can_pick_up_all() {
+ var commander = game.force.commander
+ var where = piece_space(commander)
+ var box = leader_box(commander)
+
+ // count total available command
+ var cmd = force_command(commander)
+ for_each_friendly_leader_in_node(where, p => {
+ if (game.force.reason === "avoid" && is_piece_inside(p))
+ return // continue
+ if (game.activation && set_has(game.activation, p))
+ return // continue
+ if (p !== commander && leader_command(p) <= leader_command(commander))
+ cmd += leader_command(p)
+ })
+
+ // count how many units could be picked up
+ var m = count_non_british_iroquois_and_mohawk_units_in_force(commander)
+ var n = 0
+ for_each_friendly_unit_in_node(where, p => {
+ if (game.force.reason === "avoid" && is_piece_inside(p))
+ return // continue
+ if (is_british_iroquois_or_mohawk(p)) {
+ // 5.534 Only Johnson can command British Iroquois and Mohawk (and for free)
+ // so don't count them here
+ } else {
+ ++n
+ }
+ })
+
+ return n > 0 && n + m <= cmd
+}
+
+function do_pick_up_leaders() {
+ var commander = game.force.commander
+ var where = piece_space(commander)
+ var box = leader_box(commander)
+ for_each_friendly_leader_in_node(where, p => {
+ if (game.force.reason === "avoid" && is_piece_inside(p))
+ return // continue
+ if (game.activation && set_has(game.activation, p))
+ return // continue
+ if (p !== commander && leader_command(p) <= leader_command(commander))
+ move_piece_to(p, box)
+ })
+}
+
+function do_pick_up_units(pred) {
+ var commander = game.force.commander
+ var where = piece_space(commander)
+ var box = leader_box(commander)
+
+ // pick up as many units as possible
+ for_each_friendly_unit_in_node(where, p => {
+ if (game.force.reason === "avoid" && is_piece_inside(p))
+ return // continue
+ if (!pred(p))
+ return // continue
+ if (is_british_iroquois_or_mohawk(p)) {
+ // 5.534 Only Johnson can command British Iroquois and Mohawk (and for free)
+ if (is_piece_in_force(JOHNSON, commander))
+ move_piece_to(p, box)
+ } else {
+ if (count_non_british_iroquois_and_mohawk_units_in_force(commander) < force_command(commander))
+ move_piece_to(p, box)
+ }
+ })
+}
+
states.designate_force = {
inactive: "to designate force",
prompt() {
@@ -2610,7 +2679,9 @@ states.designate_force = {
view.prompt = `Designate force ${designate_force_reason_prompt[game.force.reason]} with ${piece_name(commander)} from ${space_name(where)} (${cmd_use}/${cmd_cap}).`
view.who = commander
- let can_pick_up = false
+ let can_pick_up_ld = false
+ let can_pick_up_ax = false
+ let can_pick_up_dt = false
// pick up sub-commanders
for_each_friendly_leader_in_node(where, p => {
@@ -2619,7 +2690,7 @@ states.designate_force = {
if (game.activation && set_has(game.activation, p))
return // continue
if (p !== commander && leader_command(p) <= leader_command(commander)) {
- can_pick_up = true
+ can_pick_up_ld = true
gen_action_piece(p)
}
})
@@ -2631,12 +2702,15 @@ states.designate_force = {
if (is_british_iroquois_or_mohawk(p)) {
// 5.534 Only Johnson can command British Iroquois and Mohawk (and for free)
if (is_piece_in_force(JOHNSON, commander)) {
- can_pick_up = true
+ can_pick_up_ax = true
gen_action_piece(p)
}
} else {
if (cmd_use < cmd_cap) {
- can_pick_up = true
+ if (is_auxiliary(p))
+ can_pick_up_ax = true
+ else if (is_drilled_troops(p))
+ can_pick_up_dt = true
gen_action_piece(p)
}
}
@@ -2653,8 +2727,25 @@ states.designate_force = {
gen_action_piece(p)
})
- if (can_pick_up)
+ if ((can_pick_up_ld || can_pick_up_dt || can_pick_up_ax) && can_pick_up_all())
view.actions.pick_up_all = 1
+ else
+ view.actions.pick_up_all = 0
+
+ if (can_pick_up_ld)
+ view.actions.pick_up_ld = 1
+ else
+ view.actions.pick_up_ld = 0
+
+ if (can_pick_up_dt)
+ view.actions.pick_up_dt = 1
+ else
+ view.actions.pick_up_dt = 0
+
+ if (can_pick_up_ax)
+ view.actions.pick_up_ax = 1
+ else
+ view.actions.pick_up_ax = 0
switch (game.force.reason) {
case 'campaign_1':
@@ -2684,34 +2775,23 @@ states.designate_force = {
pick_up_all() {
push_undo()
+ do_pick_up_leaders()
+ do_pick_up_units((_)=>true)
+ },
- let commander = game.force.commander
- let where = piece_space(commander)
- let box = leader_box(commander)
+ pick_up_ld() {
+ push_undo()
+ do_pick_up_leaders()
+ },
- // pick up all sub-commanders
- for_each_friendly_leader_in_node(where, p => {
- if (game.force.reason === 'avoid' && is_piece_inside(p))
- return // continue
- if (game.activation && set_has(game.activation, p))
- return // continue
- if (p !== commander && leader_command(p) <= leader_command(commander))
- move_piece_to(p, box)
- })
+ pick_up_dt() {
+ push_undo()
+ do_pick_up_units(is_drilled_troops)
+ },
- // pick up as many units as possible
- for_each_friendly_unit_in_node(where, p => {
- if (game.force.reason === 'avoid' && is_piece_inside(p))
- return // continue
- if (is_british_iroquois_or_mohawk(p)) {
- // 5.534 Only Johnson can command British Iroquois and Mohawk (and for free)
- if (is_piece_in_force(JOHNSON, commander))
- move_piece_to(p, box)
- } else {
- if (count_non_british_iroquois_and_mohawk_units_in_force(commander) < force_command(commander))
- move_piece_to(p, box)
- }
- })
+ pick_up_ax() {
+ push_undo()
+ do_pick_up_units(is_auxiliary)
},
piece(p) {