diff options
-rw-r--r-- | play.js | 27 | ||||
-rw-r--r-- | rules.js | 113 |
2 files changed, 87 insertions, 53 deletions
@@ -620,7 +620,7 @@ function on_init() { } ui.elector = [ [], [], [], [], [], [] ] - for (let i = 0; i < 30; ++i) { + for (let i = 0; i < 50; ++i) { ui.elector[P_FRANCE].push(create_conquest("marker elector_marker_france")) ui.elector[P_PRUSSIA].push(create_conquest("marker elector_marker_prussia")) ui.elector[P_PRAGMATIC].push(create_conquest("marker elector_marker_austria_pragmatic")) @@ -663,8 +663,10 @@ function on_init() { ui.combat.id = "combat" ui.combat.style.zIndex = 2000 - ui.tcbreak = document.createElement("div") - ui.tcbreak.className = "draw-break" + ui.tcbreak1 = document.createElement("div") + ui.tcbreak1.className = "draw-break" + ui.tcbreak2 = document.createElement("div") + ui.tcbreak2.className = "draw-break" ui.turn = document.createElement("div") ui.turn.className = "marker turn_marker" @@ -1153,22 +1155,19 @@ function on_update() { */ ui.hand[pow].replaceChildren() - if (typeof view.hand[pow] === "number") { - for (let i = 0; i < view.hand[pow]; ++i) - ui.hand[pow].appendChild(ui.tc_hand[pow][i]) - } else { - view.hand[pow].sort(cmp_tc) - for (let c of view.hand[pow]) { + for (let c of view.hand1[pow].slice().sort(cmp_tc)) + ui.hand[pow].appendChild(show_tc(c)) + if (view.hand2[pow].length > 0) { + ui.hand[pow].appendChild(ui.tcbreak1) + for (let c of view.hand2[pow].slice().sort(cmp_tc)) ui.hand[pow].appendChild(show_tc(c)) - } } } if (view.draw) { - view.draw.sort(cmp_tc) - if (view.hand[view.power].length > 0) - ui.hand[view.power].appendChild(ui.tcbreak) - for (let c of view.draw) + if (view.hand1[view.power].length + view.hand2[view.power].length > 0) + ui.hand[view.power].appendChild(ui.tcbreak2) + for (let c of view.draw.slice().sort(cmp_tc)) ui.hand[view.power].appendChild(ui.tc[c]) } @@ -19,6 +19,7 @@ UI: show TC modifiers UI: show subsidy contracts when are subsidies given? + when drawn when are subsidies created? example france subsidy to prussia at france's stage? @@ -1287,6 +1288,26 @@ function search_hussar_bfs(from) { /* TACTICAL CARDS */ +function for_each_card_in_hand(f) { + for (let c of game.hand1[game.power]) + f(c) + for (let c of game.hand2[game.power]) // subsidies and returned cards + f(c) +} + +function gen_cards_in_hand() { + for_each_card_in_hand(gen_action_card) +} + +function remove_card_in_hand(c) { + set_delete(game.hand1[game.power], c) + set_delete(game.hand2[game.power], c) +} + +function count_cards_in_hand() { + return game.hand1[game.power].length + game.hand2[game.power].length > 0 +} + function find_largest_discard(u) { for (let i = 0; i < 4; ++i) if (u[i] <= u[0] && u[i] <= u[1] && u[i] <= u[2] && u[i] <= u[3]) @@ -1299,7 +1320,9 @@ function count_used_cards() { // count cards in hands for (let pow of all_powers) { - for (let c of game.hand[pow]) + for (let c of game.hand1[pow]) + held[to_deck(c)]++ + for (let c of game.hand2[pow]) held[to_deck(c)]++ } @@ -1419,8 +1442,12 @@ states.tactical_cards_show = { } function end_tactical_cards() { + for (let c of game.hand2[game.power]) + set_add(game.hand1[game.power], c) + game.hand2[game.power] = [] + for (let c of game.draw) - set_add(game.hand[game.power], c) + set_add(game.hand1[game.power], c) delete game.draw // draw minor power's cards after major power @@ -1682,14 +1709,13 @@ states.supply_hussars = { str += "." if (paid < debt) - for (let c of game.hand[game.power]) - gen_action_card(c) + gen_cards_in_hand() prompt(str) view.draw = game.supply.pool - if (debt === 0 || (!can_pay && game.hand[game.power].length === 0)) + if (debt === 0 || (!can_pay && count_cards_in_hand() === 0)) view.actions.next = 1 }, piece(p) { @@ -1707,7 +1733,7 @@ states.supply_hussars = { }, card(c) { push_undo() - set_delete(game.hand[game.power], c) + remove_card_in_hand(c) set_add(game.supply.pool, c) }, next() { @@ -1728,7 +1754,7 @@ states.supply_hussars = { // put back into hand unused cards for (let c of game.supply.pool) - set_add(game.hand[game.power], c) + set_add(game.hand2[game.power], c) // TODO: or hand1 delete game.supply.pool delete game.supply.used @@ -2464,10 +2490,8 @@ states.re_enter_train = { } } - if (paid / 4 < av_trains) { - for (let c of game.hand[game.power]) - gen_action_card(c) - } + if (paid / 4 < av_trains) + gen_cards_in_hand() if (game.recruit.used.length > 0) view.actions.next = 1 @@ -2498,7 +2522,7 @@ states.re_enter_train = { }, card(c) { push_undo() - set_delete(game.hand[game.power], c) + remove_card_in_hand(c) set_add(game.recruit.pool, c) }, next() { @@ -2541,7 +2565,7 @@ function end_re_enter_train() { // put back into hand unused cards for (let c of game.recruit.pool) - set_add(game.hand[game.power], c) + set_add(game.hand2[game.power], c) // TODO: or hand1 delete game.recruit @@ -2688,10 +2712,8 @@ states.recruit = { view.draw = game.recruit.pool if (av_troops > 0) { - if (paid / 4 < av_troops) { - for (let c of game.hand[game.power]) - gen_action_card(c) - } + if (paid / 4 < av_troops) + gen_cards_in_hand() if (paid >= 4) { for (let p of all_power_generals[game.power]) { @@ -2708,7 +2730,7 @@ states.recruit = { }, card(c) { push_undo() - set_delete(game.hand[game.power], c) + remove_card_in_hand(c) set_add(game.recruit.pool, c) }, piece(p) { @@ -2829,7 +2851,7 @@ function end_recruit() { // put back into hand unused cards for (let c of game.recruit.pool) - set_add(game.hand[game.power], c) + set_add(game.hand2[game.power], c) // TODO: or hand1 delete game.recruit } else { @@ -3049,7 +3071,7 @@ function gen_play_card(suit) { let score = Math.abs(game.count) let has_suit = false - for (let c of game.hand[game.power]) { + for_each_card_in_hand(c => { let c_suit = to_suit(c) if (c_suit === suit) { has_suit = true @@ -3057,7 +3079,7 @@ function gen_play_card(suit) { } else if (c_suit === RESERVE) { gen_action_card(c) } - } + }) // cannot pass if at 0 (and can play) if (score === 0 && has_suit) @@ -3095,7 +3117,7 @@ function play_reserve(v, sign) { function play_combat_card(c, sign, resume, next_state) { push_undo() - array_remove_item(game.hand[game.power], c) + remove_card_in_hand(c) if (is_reserve(c)) { game.state = next_state game.reserve = c @@ -3594,7 +3616,7 @@ function goto_politics() { // 25.1 Return face-down (previously placed) TCs to the players for (let pow of all_major_powers) { for (let c of game.face_down[pow]) - set_add(game.hand[pow], c) + set_add(game.hand2[pow], c) game.face_down[pow] = [] } @@ -3653,14 +3675,13 @@ states.place_tc_on_display = { inactive: "place TC on political display", prompt() { prompt(`Place TC on political display (${suit_name[game.trump]} is trump).`) - for (let c of game.hand[game.power]) - gen_action_card(c) + gen_cards_in_hand() view.actions.pass = 1 }, card(c) { push_undo() log(power_name[game.power] + " placed a TC.") - set_delete(game.hand[game.power], c) + remove_card_in_hand(c) set_add(game.face_down[game.power], c) game.state = "place_tc_on_display_done" }, @@ -3985,7 +4006,7 @@ states.political_troops_draw = { let info = event_troops[current_political_effect()] if (info.tcs > 0) { for (let c of game.draw) - set_add(game.hand[game.power], c) + set_add(game.hand1[game.power], c) delete game.draw } game.state = "political_troops_place" @@ -4949,9 +4970,12 @@ function make_tactics_discard(n) { return make_tactics_deck(n).filter(c => { if (game.draw && set_has(game.draw, c)) return false - for (let pow of all_powers) - if (set_has(game.hand[pow], c)) + for (let pow of all_powers) { + if (set_has(game.hand1[pow], c)) + return false + if (set_has(game.hand2[pow], c)) return false + } for (let pow of all_major_powers) { if (set_has(game.face_up[pow], c)) return false @@ -4989,7 +5013,8 @@ exports.setup = function (seed, _scenario, _options) { pol_deck: null, deck: null, - hand: [ [], [], [], [], [], [] ], + hand1: [ [], [], [], [], [], [] ], + hand2: [ [], [], [], [], [], [] ], // face-up (saved) TCs face_up: [ [], [], [], [] ], @@ -5031,7 +5056,7 @@ exports.setup = function (seed, _scenario, _options) { // Deal initial cards for (let pow of all_powers) for (let i = 0; i < setup_initial_tcs[pow]; ++i) - set_add(game.hand[pow], game.deck.pop()) + set_add(game.hand1[pow], game.deck.pop()) log("# 1741") @@ -5158,16 +5183,24 @@ function mask_troops(player) { return view_troops } -function mask_hand(player) { +function mask_hand1(player) { + let view_hand = [] + for (let pow of all_powers) { + if (player_from_power(pow) === player) + view_hand[pow] = game.hand1[pow] + else + view_hand[pow] = game.hand1[pow].map(c => c & ~127) + } + return view_hand +} + +function mask_hand2(player) { let view_hand = [] for (let pow of all_powers) { if (player_from_power(pow) === player) - view_hand[pow] = game.hand[pow] + view_hand[pow] = game.hand2[pow] else - view_hand[pow] = game.hand[pow].map(c => c & ~127) - //view_hand[pow] = game.hand[pow].length - //view_hand[pow] = Math.ceil(game.hand[pow].length / 3) * 3 - //view_hand[pow] = Math.ceil(game.hand[pow].length / 5) + view_hand[pow] = game.hand2[pow].map(c => c & ~127) } return view_hand } @@ -5211,7 +5244,8 @@ exports.view = function (state, player) { oos: game.oos, supreme: game.supreme, troops: mask_troops(player), - hand: mask_hand(player), + hand1: mask_hand1(player), + hand2: mask_hand2(player), pt: total_troops_list(), discard: total_discard_list(), @@ -5234,7 +5268,8 @@ exports.view = function (state, player) { if (game.state === "game_over") { view.prompt = game.victory view.troops = game.troops - view.hand = game.hand + view.hand1 = game.hand1 + view.hand2 = game.hand2 } else if (game.active !== player) { let inactive = states[game.state].inactive || game.state if (typeof inactive === "function") |