summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-10-24 11:55:21 +0200
committerTor Andersson <tor@ccxvii.net>2024-10-24 11:55:21 +0200
commit45a517567b44ed1a0a01bee24a181889566480e0 (patch)
treeb68392e153f6fe5520ca708fe262dd14b272d824
parent98478071c29c919828dec77a04246df1e94c7f37 (diff)
downloadmaria-45a517567b44ed1a0a01bee24a181889566480e0.tar.gz
subsidy contract representation
-rw-r--r--rules.js85
1 files changed, 61 insertions, 24 deletions
diff --git a/rules.js b/rules.js
index 8541933..15da8c1 100644
--- a/rules.js
+++ b/rules.js
@@ -864,14 +864,6 @@ const tc_per_turn_table = [ 5, 3, 3, 5, 1, 1 ]
function tc_per_turn() {
let n = tc_per_turn_table[game.power]
- // TODO: subsidies
- if (game.turn <= 3) {
- if (game.power === P_FRANCE)
- --n
- if (game.power === P_BAVARIA)
- ++n
- }
-
// Saxony track
if (game.power === P_SAXONY) {
if (game.saxony > 4)
@@ -1386,14 +1378,20 @@ function total_discard_list() {
return discard
}
-function draw_tc(n, verbose = true) {
- game.draw = []
+function log_draw_tc(k, pow) {
+ if (pow >= 0 && k >= 0) {
+ if (pow !== game.power)
+ log(`${power_name[pow]} ${k} TC (${power_name[game.power]}).`)
+ else
+ log(`${power_name[pow]} ${k} TC.`)
+ }
+}
+function draw_tc(draw, n, pow) {
let k = 0
while (n > 0) {
if (game.deck.length === 0) {
- if (verbose && k > 0)
- log(power_name[game.power] + " " + k + " TC.")
+ log_draw_tc(k, pow)
k = 0
next_tactics_deck()
if (game.deck.length === 0) {
@@ -1401,13 +1399,24 @@ function draw_tc(n, verbose = true) {
break
}
}
- set_add(game.draw, game.deck.pop())
+ set_add(draw, game.deck.pop())
++k
--n
}
- if (verbose && k > 0)
- log(power_name[game.power] + " " + k + " TC.")
+ log_draw_tc(k, pow)
+}
+
+function give_subsidy(other) {
+ if (other === P_BAVARIA && is_enemy_controlled_fortress(MUNCHEN)) {
+ log("Bavaria 1 TC lost (S" + MUNCHEN + " is enemy controlled)")
+ return
+ }
+ if (other === P_SAXONY && is_enemy_controlled_fortress(DRESDEN)) {
+ log("Saxony 1 TC lost (S" + DRESDEN + " is enemy controlled)")
+ return
+ }
+ draw_tc(game.hand2[other], 1, other)
}
function goto_tactical_cards() {
@@ -1416,14 +1425,35 @@ function goto_tactical_cards() {
if (game.power === P_SAXONY)
game.flags |= F_SAXONY_TC_ONCE
+ game.draw = []
+
if (game.power === P_BAVARIA && is_enemy_controlled_fortress(MUNCHEN)) {
log("S" + MUNCHEN + " is enemy controlled.")
- game.draw = []
} else if (game.power === P_SAXONY && is_enemy_controlled_fortress(DRESDEN)) {
log("S" + DRESDEN + " is enemy controlled.")
- game.draw = []
} else {
- draw_tc(tc_per_turn())
+ let n_cards = tc_per_turn()
+
+ // count active subsidies
+ if (game.contracts[game.power])
+ for (let other of all_powers)
+ if (map_get(game.contracts[game.power], other, 0) > 0)
+ --n_cards
+
+ draw_tc(game.draw, n_cards, game.power)
+
+ if (game.contracts[game.power]) {
+ for (let other of all_powers) {
+ let contract = map_get(game.contracts[game.power], other, 0)
+ if (contract > 0) {
+ give_subsidy(other)
+ if (contract > 1)
+ map_set(game.contracts[game.power], other, contract - 1)
+ else
+ map_delete(game.contracts[game.power], other)
+ }
+ }
+ }
}
game.state = "tactical_cards_show"
@@ -3637,13 +3667,13 @@ function goto_politics() {
game.state = "determine_trump_suit"
} else {
for (;;) {
- draw_tc(1, false)
- log("Trump " + format_card(game.draw[0]) + ".")
- if (!is_reserve(game.draw[0])) {
- game.trump = to_suit(game.draw[0])
+ let list = []
+ draw_tc(list, 1, -1)
+ log("Trump " + format_card(list[0]) + ".")
+ if (!is_reserve(list[0])) {
+ game.trump = to_suit(list[0])
break
}
- delete game.draw
}
log_br()
goto_place_tc_on_display()
@@ -3981,7 +4011,7 @@ states.political_troop_power = {
let info = event_troops[current_political_effect()]
set_active_to_power(pow)
if (info.tcs > 0) {
- draw_tc(info.tcs)
+ draw_tc(game.draw = [], info.tcs, game.power)
game.state = "political_troops_draw"
} else {
game.state = "political_troops_place"
@@ -5016,6 +5046,13 @@ exports.setup = function (seed, _scenario, _options) {
hand1: [ [], [], [], [], [], [] ],
hand2: [ [], [], [], [], [], [] ],
+ contracts: [
+ [ P_BAVARIA, 3 ],
+ [],
+ [],
+ []
+ ],
+
// face-up (saved) TCs
face_up: [ [], [], [], [] ],
// face-down (placed) TCs