summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-12-29 13:51:23 +0100
committerTor Andersson <tor@ccxvii.net>2023-02-18 13:02:38 +0100
commitfe861a54da448078aac87288a1e8929a8bc2c5fb (patch)
tree1d5184abf235a59a4a9c6aab74eed9e1dcd4188d
parent70e483427c41dd44ab150d25e47c1f80a8c494dd (diff)
downloadnevsky-fe861a54da448078aac87288a1e8929a8bc2c5fb.tar.gz
Event discard helper.
-rw-r--r--rules.js32
1 files changed, 14 insertions, 18 deletions
diff --git a/rules.js b/rules.js
index 8aaf2ed..1504fb5 100644
--- a/rules.js
+++ b/rules.js
@@ -1470,6 +1470,18 @@ function discard_card(c) {
set_add(game.deck2, c)
}
+function discard_events(when) {
+ for (let i = 0; i < game.events.length; ) {
+ let c = game.events[i]
+ if (data.cards[c].when === when) {
+ array_remove(game.events, i)
+ discard_card(c)
+ } else {
+ ++i
+ }
+ }
+}
+
exports.setup = function (seed, scenario, options) {
game = {
seed,
@@ -2606,15 +2618,7 @@ function end_levy_call_to_arms() {
function goto_levy_discard_events() {
// Discard "This Levy" events from play.
- for (let i = 0; i < game.events.length; ) {
- let c = game.events[i]
- if (data.cards[c].when === "this_levy") {
- array_remove(game.events, i)
- discard_card(c)
- } else {
- ++i
- }
- }
+ discard_events("this_levy")
set_active(P1)
goto_capability_discard()
@@ -7480,15 +7484,7 @@ function goto_reset() {
}
// Discard "This Campaign" events from play.
- for (let i = 0; i < game.events.length; ) {
- let c = game.events[i]
- if (data.cards[c].when === "this_campaign") {
- array_remove(game.events, i)
- discard_card(c)
- } else {
- ++i
- }
- }
+ discard_events("this_campaign")
goto_advance_campaign()
}