summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-12-15 18:19:30 +0100
committerTor Andersson <tor@ccxvii.net>2024-01-08 16:36:48 +0100
commit508efabb4e9aa56aadb1f11d8590a87cd4fbde3e (patch)
tree69099a7a419adfe3022eea44bad02199ab72e826
parentcbfbf1e584bade8b681b1e460321b72fd667f809 (diff)
downloadtable-battles-508efabb4e9aa56aadb1f11d8590a87cd4fbde3e.tar.gz
move sticks
-rw-r--r--rules.js31
1 files changed, 19 insertions, 12 deletions
diff --git a/rules.js b/rules.js
index 7cd1d5d..f3ff4b2 100644
--- a/rules.js
+++ b/rules.js
@@ -521,6 +521,16 @@ function set_sticks(c, n) {
map_set(game.sticks, c, n)
}
+function move_sticks(from, to, n) {
+ log("moved N sticks")
+ set_sticks(from, get_sticks(from) - n)
+ set_sticks(to, get_sticks(to) + n)
+}
+
+function move_all_sticks(from, to) {
+ move_sticks(from, to, get_sticks(from))
+}
+
function get_shift_sticks(c) {
if (game.shift)
return map_get(game.shift, c, 0)
@@ -1643,8 +1653,9 @@ states.s41_clerambault = {
},
card(c) {
if (c === S41_BLENHEIM_CARD)
- set_sticks(S41_BLENHEIM_CARD, get_sticks(S41_BLENHEIM_CARD) + get_sticks(S41_CLERAMBAULT))
- set_sticks(S41_CLERAMBAULT, 0)
+ move_all_sticks(S41_CLERAMBAULT, S41_BLENHEIM_CARD)
+ else
+ set_sticks(S41_CLERAMBAULT, 0)
if (c === S41_CLERAMBAULT) {
rout_card(S41_CLERAMBAULT)
game.morale[0]++
@@ -2233,8 +2244,7 @@ states.shift_to = {
},
card(c) {
game.target2 = c
- set_sticks(game.selected, get_sticks(game.selected) - 1)
- set_shift_sticks(game.target2, get_shift_sticks(game.target2) + 1)
+ move_sticks(game.selected, game.target2, 1)
if (get_sticks(game.selected) === 1)
this.next()
},
@@ -2263,8 +2273,7 @@ states.s40_cassines = {
},
card(c) {
log(game.selected + " moved one stick from " + c)
- set_sticks(c, get_sticks(c) - 1)
- set_sticks(game.selected, get_sticks(game.selected) + 1)
+ move_sticks(c, game.selected, 1)
end_action_phase()
},
}
@@ -2285,8 +2294,7 @@ states.s41_prince_eugene = {
card(c) {
game.target2 = c
log(game.target2 + " moved one stick from " + game.selected)
- set_sticks(game.selected, get_sticks(game.selected) - 1)
- set_sticks(game.target2, get_sticks(game.target2) + 1)
+ move_sticks(game.selected, game.target2, 1)
if (--game.self === 0) {
pay_for_action(game.selected)
end_action_phase()
@@ -2307,8 +2315,7 @@ states.s42_marlborough = {
},
card(c) {
log(game.selected + " moved 4 sticks to " + c)
- set_sticks(c, get_sticks(c) + 4)
- set_sticks(S42_MARLBOROUGH, get_sticks(S42_MARLBOROUGH) - 4)
+ move_sticks(S42_MARLBOROUGH, c, 4)
pay_for_action(S42_MARLBOROUGH)
if (get_sticks(S42_MARLBOROUGH) === 0)
remove_card(S42_MARLBOROUGH)
@@ -3354,12 +3361,12 @@ function goto_routing() {
if (is_card_in_play(S2_RUPERTS_LIFEGUARD)) {
if (should_rout_card(S2_NORTHERN_HORSE)) {
log("Rupert's Lifeguard added to Northern Horse.")
- set_sticks(S2_NORTHERN_HORSE, 1)
+ move_all_sticks(S2_RUPERTS_LIFEGUARD, S2_NORTHERN_HORSE)
remove_card(S2_RUPERTS_LIFEGUARD)
}
if (should_rout_card(S2_BYRON)) {
log("Rupert's Lifeguard added to Byron.")
- set_sticks(S2_BYRON, 1)
+ move_all_sticks(S2_RUPERTS_LIFEGUARD, S2_BYRON)
remove_card(S2_RUPERTS_LIFEGUARD)
}
}