summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-12-18 15:29:00 +0100
committerTor Andersson <tor@ccxvii.net>2024-01-08 16:36:48 +0100
commit80fcfa68dbce7b9dd79b5c9e6ec3917258a62d9d (patch)
tree5110bf6ac0e5eb8116693dc26a0cbe08eed2e4a4
parent3a65f3f621ccb4455f4bfd80c7c713a56c14ba84 (diff)
downloadtable-battles-80fcfa68dbce7b9dd79b5c9e6ec3917258a62d9d.tar.gz
remember original attack target
-rw-r--r--rules.js64
1 files changed, 34 insertions, 30 deletions
diff --git a/rules.js b/rules.js
index 0678e19..a497feb 100644
--- a/rules.js
+++ b/rules.js
@@ -420,6 +420,7 @@ exports.setup = function (seed, scenario, options) {
self: 0,
// for breastworks etc
+ attack_target: -1, // original target
self2: 0,
target2: -1,
hits2: 0,
@@ -1420,6 +1421,7 @@ function take_straight_4(c, d) {
function goto_roll_phase() {
game.selected = -1
+ game.attack_target = -1
game.target = -1
game.target2 = -1
game.action = 0
@@ -2611,17 +2613,19 @@ function goto_attack(target) {
}
game.state = "attack"
+ game.attack_target = target
game.target = target
- update_attack1(true)
+ update_attack1()
update_attack2()
}
// Update hits and self hits.
-function update_attack1(direct) {
+function update_attack1() {
let a = current_action()
let n = count_dice_on_card(game.selected)
+ let target = game.attack_target
switch (a.effect) {
default:
@@ -2697,23 +2701,23 @@ function update_attack1(direct) {
case "1 hit per die (2 hits per die versus Blenheim). 1 self.":
game.self = 1
game.hits = n
- if (direct && game.target === S41_BLENHEIM_CARD)
+ if (target === S41_BLENHEIM_CARD)
game.hits = 2 * n
break
case "1 hit per die (2 hits per die versus Villars's Left). 1 self.":
game.self = 1
game.hits = n
- if (direct && game.target === S43_VILLARS_LEFT)
+ if (target === S43_VILLARS_LEFT)
game.hits = 2 * n
break
case "1 hit per die versus Driesen. 2 hits per die versus Retzow.":
- case "1 hit per die (2 hits per die versus Retzow).":
game.self = 0
- game.hits = n
- if (direct && game.target === S49_RETZOW)
+ if (target === S49_RETZOW)
game.hits = 2 * n
+ else
+ game.hits = n
break
case "1 hit per die. 1 extra hit if Fourth Line is in play.":
@@ -2733,21 +2737,21 @@ function update_attack1(direct) {
case "1 hit per die. 1 self. 1 extra vs Dutch Left Foot.":
game.self = 1
game.hits = n
- if (direct && game.target === S38_DUTCH_LEFT_FOOT)
+ if (target === S38_DUTCH_LEFT_FOOT)
game.hits += 1
break
case "1 hit per die. 1 self. 1 extra vs Essex.":
game.self = 1
game.hits = n
- if (game.target === S30_ESSEX)
+ if (target === S30_ESSEX)
game.hits += 1
break
case "1 hit per die. 1 self. 1 extra vs Tullibardine.":
game.self = 1
game.hits = n
- if (direct && game.target === S34_TULLIBARDINE)
+ if (target === S34_TULLIBARDINE)
game.hits += 1
break
@@ -2759,16 +2763,16 @@ function update_attack1(direct) {
if (game.scenario === S2_MARSTON_MOOR) {
if (is_card_in_play(S2_RUPERTS_LIFEGUARD)) {
- if (game.target === S2_TILLIERS_LEFT)
+ if (target === S2_TILLIERS_LEFT)
game.hits -= 1
- if (game.target === S2_TILLIERS_RIGHT)
+ if (target === S2_TILLIERS_RIGHT)
game.hits -= 1
}
}
if (game.scenario === S9_ST_ALBANS) {
// Defensive Works (negated by Archers)
- if (game.target === S9_SHROPSHIRE_LANE || game.target === S9_SOPWELL_LANE) {
+ if (target === S9_SHROPSHIRE_LANE || target === S9_SOPWELL_LANE) {
if (is_card_in_play(S9_HENRY_VI))
if (!has_any_cubes_on_card(S9_ARCHERS))
game.hits = Math.min(1, game.hits)
@@ -2776,14 +2780,14 @@ function update_attack1(direct) {
}
if (game.scenario === S15_TEWKESBURY) {
- if (game.target === S15_SOMERSET) {
+ if (target === S15_SOMERSET) {
if (has_any_dice_on_card(S15_A_PLUMP_OF_SPEARS))
game.hits += 1
}
}
if (game.scenario === S22_GABIENE) {
- if (game.target === S22_SILVER_SHIELDS) {
+ if (target === S22_SILVER_SHIELDS) {
if (is_card_in_play(S22_EUMENES_CAMP)) {
game.hits = Math.min(1, game.hits - 1)
}
@@ -2796,7 +2800,7 @@ function update_attack1(direct) {
game.hits += 1
}
}
- if (game.target === S31_WENTWORTH) {
+ if (target === S31_WENTWORTH) {
if (has_any_dice_on_card(S31_BYRON) && is_card_in_play(S31_SKIPPON)) {
game.hits -= 1
}
@@ -2805,7 +2809,7 @@ function update_attack1(direct) {
if (game.scenario === S37_INKERMAN) {
// Until the first Fog Cube is lifted.
- if (game.target === S37_SOIMONOFF && get_cubes(S37_THE_FOG) === 3) {
+ if (target === S37_SOIMONOFF && get_cubes(S37_THE_FOG) === 3) {
game.hits -= 1
}
}
@@ -2822,7 +2826,7 @@ function update_attack1(direct) {
}
if (game.scenario === S44_HOHENFRIEDBERG) {
- if (game.target === S44_CHARLES) {
+ if (target === S44_CHARLES) {
if (game.selected === S44_LEOPOLDS_L || game.selected === S44_LEOPOLDS_C || game.selected === S44_LEOPOLDS_R)
game.self = 0
}
@@ -2830,7 +2834,7 @@ function update_attack1(direct) {
// Oblique Attack (CAL expansion rule)
if (is_infantry(game.selected)) {
- if (get_sticks(game.selected) >= get_sticks(game.target) + 3)
+ if (get_sticks(game.selected) >= get_sticks(target) + 3)
game.hits += 1
}
@@ -2839,13 +2843,13 @@ function update_attack1(direct) {
game.hits += 1
// Linked Formations (TGA and CAL expansion rule)
- if (card_has_active_link(game.target))
+ if (card_has_active_link(target))
game.hits = Math.max(0, game.hits - 1)
- if (card_has_rule(game.target, "suffer_1_less"))
+ if (card_has_rule(target, "suffer_1_less"))
game.hits = Math.max(0, game.hits - 1)
- if (card_has_rule(game.target, "suffer_1_less_1_max"))
+ if (card_has_rule(target, "suffer_1_less_1_max"))
game.hits = Math.max(0, Math.min(1, game.hits - 1))
}
@@ -2930,7 +2934,7 @@ states.attack = {
let may_take_from = card_has_rule(game.selected, "may_take_from")
if (may_take_from) {
take_all_dice(from, game.selected)
- update_attack1(true)
+ update_attack1()
update_attack2()
return
}
@@ -2939,7 +2943,7 @@ states.attack = {
if (may_take_from_extra) {
take_all_dice(from, game.selected)
game.self2 = 1
- update_attack1(true)
+ update_attack1()
update_attack2()
return
}
@@ -2948,7 +2952,7 @@ states.attack = {
if (game.selected === S39_CATINAT && from === S39_BAYONETS) {
take_all_dice(from, game.selected)
game.target2 = S39_BAYONETS
- update_attack1(true)
+ update_attack1()
update_attack2()
return
}
@@ -2958,7 +2962,7 @@ states.attack = {
if (from === S49_THE_LEUTHEN_CHORALE) {
take_all_dice(from, game.selected)
game.target2 = S49_THE_LEUTHEN_CHORALE
- update_attack1(true)
+ update_attack1()
update_attack2()
return
}
@@ -3330,7 +3334,7 @@ function goto_screen(c, a) {
game.target = c
- update_attack1(false)
+ update_attack1()
switch (a.effect)
{
@@ -3390,7 +3394,7 @@ function goto_absorb(c, a) {
game.target = c
- update_attack1(false)
+ update_attack1()
switch (a.effect)
{
@@ -3426,7 +3430,7 @@ states.s29_meade = {
card(c) {
remove_dice(S29_MEADE)
game.target = c
- update_attack1(false)
+ update_attack1()
update_attack2()
game.state = "absorb"
}
@@ -3455,7 +3459,7 @@ states.absorb = {
function goto_counterattack(c, a) {
game.reacted = player_index()
- update_attack1(false)
+ update_attack1()
switch (a.effect)
{