summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-11-06 13:53:50 +0100
committerTor Andersson <tor@ccxvii.net>2024-11-06 13:53:50 +0100
commite90132edeae9935442e1288101eddc06620b81e2 (patch)
treee0c508236d19190ea588baf6af2a330620a19532
parent647b03bd968d583ab0140117916d66ef2a07dede (diff)
downloadmaria-e90132edeae9935442e1288101eddc06620b81e2.tar.gz
WIP draw pause
-rw-r--r--play.js4
-rw-r--r--rules.js110
2 files changed, 89 insertions, 25 deletions
diff --git a/play.js b/play.js
index f92ac77..77d71a4 100644
--- a/play.js
+++ b/play.js
@@ -1588,12 +1588,11 @@ function on_update() {
action_button("execute", "Execute")
action_button("discard", "Discard")
-
+ action_button("draw", "Draw")
action_button("save", "Save")
action_button("stop", "Stop")
action_button("pass", "Pass")
action_button("next", "Next")
- action_button("done", "Done")
confirm_action_button("restart", "Restart",
"Restart movement phase on Flanders map?")
@@ -1602,7 +1601,6 @@ function on_update() {
action_button("end_political_card", "End political card")
action_button("end_place_hussars", "End place hussars")
- action_button("end_cards", "End card draw")
action_button("end_setup", "End setup")
action_button("end_recruit", "End recruit")
action_button("end_flanders", "End Flanders")
diff --git a/rules.js b/rules.js
index 607e5a0..1224f2f 100644
--- a/rules.js
+++ b/rules.js
@@ -516,6 +516,10 @@ const all_prussia_pragmatic_austria_bavaria_saxony_pieces = [ all_prussia_pieces
/* DATA */
+function is_major_power(pow) {
+ return pow < 4
+}
+
function is_bohemia_space(s) {
return s >= 0 && s <= 401
}
@@ -1081,13 +1085,16 @@ function is_two_player() {
return game.flags & F_TWO_PLAYER
}
-const tc_per_turn_table = [ 5, 3, 3, 5, 1, 1 ]
-
-function tc_per_turn() {
- let n = tc_per_turn_table[game.power]
+const TC_PER_TURN_TABLE = [ 5, 3, 3, 5, 1, 1 ]
+function tc_per_turn_base() {
if (game.power === P_FRANCE && is_intro())
- n = 3
+ return 3
+ return TC_PER_TURN_TABLE[game.power]
+}
+
+function tc_per_turn_modifier() {
+ let n = 0
// Saxony track
if (game.power === P_SAXONY) {
@@ -1131,6 +1138,28 @@ function tc_per_turn() {
return n
}
+function tc_per_turn() {
+ return tc_per_turn_base() + tc_per_turn_modifier()
+}
+
+function count_subsidies(pow) {
+ let n = 0
+ if (game.contracts[game.power])
+ for (let other of all_powers)
+ if (map_get(game.contracts[game.power], other, 0) > 0)
+ ++n
+ return n
+}
+
+function list_subsidies(pow) {
+ let result = []
+ if (game.contracts[game.power])
+ for (let other of all_powers)
+ if (map_get(game.contracts[game.power], other, 0) > 0)
+ result.push(power_name[other])
+ return result
+}
+
function player_from_power(pow) {
if (is_two_player()) {
switch (pow) {
@@ -1714,7 +1743,7 @@ function total_discard_list() {
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]}).`)
+ log(`${power_name[pow]} ${k} TC (subsidy).`)
else
log(`${power_name[pow]} ${k} TC.`)
}
@@ -1753,8 +1782,6 @@ function give_subsidy(other) {
}
function goto_tactical_cards() {
- clear_undo() // reveal random cards
-
if (game.power === P_SAXONY) {
if (game.flags & F_SAXONY_TC_ONCE) {
next_sequence_of_play()
@@ -1763,8 +1790,15 @@ function goto_tactical_cards() {
game.flags |= F_SAXONY_TC_ONCE
}
- game.draw = []
+ if (is_major_power(game.power))
+ game.state = "tactical_cards_draw"
+ else
+ draw_tactical_cards()
+}
+function draw_tactical_cards() {
+ clear_undo() // reveal random cards
+ game.draw = []
if (game.power === P_BAVARIA && is_enemy_controlled_fortress(MUNCHEN)) {
log("Bavaria TC draw lost\nS" + MUNCHEN + " is enemy controlled.")
} else if (game.power === P_SAXONY && is_enemy_controlled_fortress(DRESDEN)) {
@@ -1839,18 +1873,6 @@ function goto_tactical_cards() {
game.state = "tactical_cards_show"
}
-states.tactical_cards_show = {
- inactive: "draw tactical cards",
- prompt() {
- view.draw = game.draw
- prompt("Draw " + format_card_list_prompt(game.draw) + ".")
- view.actions.end_cards = 1
- },
- end_cards() {
- end_tactical_cards()
- },
-}
-
function end_tactical_cards() {
for (let c of game.hand2[game.power])
set_add(game.hand1[game.power], c)
@@ -1863,6 +1885,48 @@ function end_tactical_cards() {
next_sequence_of_play()
}
+states.tactical_cards_draw = {
+ inactive: "draw tactical cards",
+ prompt() {
+ let base = tc_per_turn_base()
+ let mod = tc_per_turn_modifier()
+ let sub = count_subsidies(game.power)
+
+ let str = "Draw " + base + " "
+ if (mod < 0)
+ str += "\u2212" + (-mod) + " "
+ else if (mod > 0)
+ str += "+" + (mod) + " "
+ str += "TC."
+
+ if (sub > 0)
+ str += " Give " + sub + " TC to " + list_subsidies().join(" and ") + "."
+
+ prompt(str)
+ if (base + mod - sub >= 0)
+ view.actions.draw = 1
+ else
+ view.actions.draw = 0
+ // else cancel contracts!
+ // TODO: force france to cancel one subsidy if prussia cannot draw cards
+ },
+ draw() {
+ draw_tactical_cards()
+ },
+}
+
+states.tactical_cards_show = {
+ inactive: "draw tactical cards",
+ prompt() {
+ view.draw = game.draw
+ prompt("Draw " + format_card_list_prompt(game.draw) + ".")
+ view.actions.next = 1
+ },
+ next() {
+ end_tactical_cards()
+ },
+}
+
/* PAYMENT */
function sum_card_values(list) {
@@ -4515,7 +4579,7 @@ states.determine_trump_suit = {
// 25.4 Place TCs on the political display
function goto_place_tc_on_display() {
- log("Place TCs on political display")
+ log("Place TC on political display")
next_place_tc_on_display()
}
@@ -6184,6 +6248,7 @@ states.cancel_subsidy_approve_both = {
let to = game.proposal.to
prompt(`Cancel subsidy contract from ${power_name[from]} to ${power_name[to]}?`)
view.actions.accept = 1
+ // TODO: cannot refuse if minor power fortress is occupied!
view.actions.refuse = 1
},
accept() {
@@ -6206,6 +6271,7 @@ states.cancel_subsidy_approve_last = {
let to = game.proposal.to
prompt(`Cancel subsidy contract from ${power_name[from]} to ${power_name[to]}?`)
view.actions.accept = 1
+ // TODO: cannot refuse if minor power fortress is occupied!
view.actions.refuse = 1
},
accept() {