summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-10-21 23:40:51 +0200
committerTor Andersson <tor@ccxvii.net>2024-10-21 23:40:51 +0200
commitfc71ebf81c6a7c672e0b13e1c274cef3a2e63b81 (patch)
tree5974010e11c138b61f36b260daf3da42f6d820b4 /rules.js
parentde5fa586b5709f33ea0aee96c4c30390c626d137 (diff)
downloadmaria-fc71ebf81c6a7c672e0b13e1c274cef3a2e63b81.tar.gz
Gain/lose battle and supply elimination VP markers
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js76
1 files changed, 67 insertions, 9 deletions
diff --git a/rules.js b/rules.js
index 27097ea..7e2dc29 100644
--- a/rules.js
+++ b/rules.js
@@ -1541,17 +1541,20 @@ states.supply_suffer = {
gen_action_piece(p)
},
piece(p) {
+ log(`>P${p} at S${game.pos[p]}`)
set_delete(game.supply.suffer, p)
if (is_out_of_supply(p)) {
- log(`>P${p} at S${game.pos[p]} -2 troops`)
+ //log(`>P${p} at S${game.pos[p]} -2 troops`)
game.troops[p] -= 2
} else {
- log(`>P${p} at S${game.pos[p]} -1 troop`)
+ //log(`>P${p} at S${game.pos[p]} -1 troop`)
set_out_of_supply(p)
game.troops[p] -= 1
}
- if (game.troops[p] <= 0)
+ if (game.troops[p] <= 0) {
eliminate_general(p, true)
+ lose_vp(coop_major_power(game.power), 1)
+ }
if (game.supply.suffer.length === 0)
resume_supply()
},
@@ -2273,8 +2276,10 @@ states.re_enter_train_where = {
// remove hussars
for (let p of all_hussars) {
- log("P" + p + " removed.")
- game.pos[p] = ELIMINATED
+ if (game.pos[p] === to) {
+ log("P" + p + " removed.")
+ game.pos[p] = ELIMINATED
+ }
}
},
}
@@ -2913,6 +2918,19 @@ function goto_retreat() {
if (lost[pow] > 0)
log(power_name[pow] + " lost " + (lost[pow]) + " troops.")
+ // track VP gained and lost
+ if (game.count > 0) {
+ game.winner_power = coop_major_power(get_stack_power(game.attacker))
+ game.loser_power = coop_major_power(get_stack_power(game.defender))
+ } else {
+ game.winner_power = coop_major_power(get_stack_power(game.defender))
+ game.loser_power = coop_major_power(get_stack_power(game.attacker))
+ }
+ game.lost_generals = 0
+ game.lost_troops = 0
+ for (let pow of all_powers)
+ game.lost_troops += lost[pow]
+
resume_retreat()
}
@@ -2920,6 +2938,7 @@ function resume_retreat() {
// eliminate generals with no more hits
for (let p of game.selected) {
if (game.troops[p] === 0) {
+ game.lost_generals += 1
game.state = "retreat_eliminate_hits"
return
}
@@ -2941,7 +2960,7 @@ function resume_retreat() {
}
// no retreat if generals wiped out
- next_combat()
+ finish_combat()
}
states.retreat_eliminate_hits = {
@@ -2969,9 +2988,12 @@ states.retreat_eliminate_trapped = {
},
piece(_) {
log("Trapped.")
- for (let p of game.selected)
+ for (let p of game.selected) {
+ game.lost_generals += 1
+ game.lost_troops += game.troops[p]
eliminate_general(p, false)
- next_combat()
+ }
+ finish_combat()
},
}
@@ -3075,10 +3097,46 @@ states.retreat_done = {
view.actions.next = 1
},
next() {
- next_combat()
+ finish_combat()
},
}
+function gain_vp(pow, n) {
+ let old_vp = game.vp[pow]
+ game.vp[pow] = Math.min(2, game.vp[pow] + n)
+ if (game.vp[pow] > old_vp)
+ log(`${power_name[pow]} +${game.vp[pow] - old_vp} VP.`)
+}
+
+function lose_vp(pow, n) {
+ let old_vp = game.vp[pow]
+ game.vp[pow] = Math.max(0, game.vp[pow] - n)
+ if (game.vp[pow] < old_vp)
+ log(`${power_name[pow]} -${old_vp - game.vp[pow]} VP.`)
+}
+
+function finish_combat() {
+ let n = 0
+ if (game.lost_troops >= 6)
+ n = 2
+ else if (game.lost_troops >= 3)
+ n = 1
+ else if (game.lost_generals > 0)
+ n = 1
+
+ if (n > 0) {
+ gain_vp(game.winner_power, n)
+ lose_vp(game.loser_power, n)
+ }
+
+ delete game.loser_power
+ delete game.winner_power
+ delete game.lost_generals
+ delete game.lost_troops
+
+ next_combat()
+}
+
/* RETRO-ACTIVE CONQUEST */
function log_conquest(conq) {