summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authoriainp5 <iain.pearce.ip@gmail.com>2025-02-10 07:47:22 +0000
committeriainp5 <iain.pearce.ip@gmail.com>2025-02-10 07:48:24 +0000
commit7ecd30111df91baf3f47670971bc35fc371dadc7 (patch)
tree3c5b7d60134f3a7caf6d9ffaa668b46f016f4888 /rules.js
parent192ea8c887c0c7949855c3b5681832845732f02f (diff)
download1989-dawn-of-freedom-7ecd30111df91baf3f47670971bc35fc371dadc7.tar.gz
Tidy up game over code
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js160
1 files changed, 68 insertions, 92 deletions
diff --git a/rules.js b/rules.js
index bcbb45c..eab845c 100644
--- a/rules.js
+++ b/rules.js
@@ -717,102 +717,87 @@ states.play_card = {
push_undo()
if (scoring_cards.includes(game.played_card)) {
log_struggle_banner(game.played_card)
- check_ligachev_event(game.played_card)
+ if (check_ligachev_event(game.played_card))
+ return
} else {
log_event_banner()
- check_ligachev_event(game.played_card)
+ if (check_ligachev_event(game.played_card))
+ return
log_event(game.played_card)
}
- if (game.state === 'game_over') {
- return
- } else {
- game.vm_infl_to_do = false
- game.return = game.active
- if (switch_events.includes(game.played_card)) {
- change_player()
- }
- game.vm_event = game.played_card
- goto_vm(game.vm_event)
+ game.vm_infl_to_do = false
+ game.return = game.active
+ if (switch_events.includes(game.played_card)) {
+ change_player()
}
+ game.vm_event = game.played_card
+ goto_vm(game.vm_event)
},
opp_event() {
push_undo()
log_ops_banner()
- check_ligachev_event(game.played_card)
- if (game.state === 'game_over') {
+ if (check_ligachev_event(game.played_card))
return
+ log_event(game.played_card)
+ game.vm_infl_to_do = true
+ game.return = game.active
+ game.vm_event = game.played_card
+ if (is_auto_resolve(game.played_card) || switch_events.includes(game.played_card)) {
+ goto_vm(game.vm_event)
} else {
- log_event(game.played_card)
- game.vm_infl_to_do = true
- game.return = game.active
- game.vm_event = game.played_card
- if (is_auto_resolve(game.played_card) || switch_events.includes(game.played_card)) {
- goto_vm(game.vm_event)
- } else {
- change_player()
- goto_vm(game.vm_event)
- }
+ change_player()
+ goto_vm(game.vm_event)
}
},
influence() {
push_undo()
log_ops_banner()
- check_ligachev_non_event()
- check_ceh()
- if (game.state === 'game_over') {
+ if (check_ligachev_non_event())
return
- } else {
- log('Placed SP:')
- finish_play_card()
+ if (check_ceh()) //TODO: Add new state to offer UNDO before game ends?
+ return
+ log('Placed SP:')
+ finish_play_card()
- // If ABHR - Set AHBR tracker to true
- if (game.persistent_events.includes(C_AUSTRIA_HUNGARY_BORDER_REOPENED)) {
- game.austria_hungary_border_reopened_tracker = true
- }
- game.state = 'add_influence'
- valid_spaces_infl()
+ if (game.persistent_events.includes(C_AUSTRIA_HUNGARY_BORDER_REOPENED)) {
+ game.austria_hungary_border_reopened_tracker = true
}
+ game.state = 'add_influence'
+ valid_spaces_infl()
},
tst() {
push_undo()
log_ops_banner()
- check_ligachev_non_event()
- check_ceh()
- if (game.state === 'game_over') {
+ if (check_ligachev_non_event())
return
- } else {
- log('Tiananmen Square Attempt:')
- finish_play_card()
- game.state = 'tiananmen_square_attempt'
- }
+ if (check_ceh()) //TODO: Add new state to offer UNDO before game ends?
+ return
+ log('Tiananmen Square Attempt:')
+ finish_play_card()
+ game.state = 'tiananmen_square_attempt'
},
support_check() {
push_undo()
log_ops_banner()
- check_ligachev_non_event()
- check_ceh()
- if (game.state === 'game_over') {
+ if (check_ligachev_non_event())
return
- } else {
- log('Support Checks:')
- finish_play_card()
- game.available_ops = 2
- game.state = 'support_check_prep'
- valid_spaces_sc()
- }
+ if (check_ceh()) //TODO: Add new state to offer UNDO before game ends?
+ return
+ log('Support Checks:')
+ finish_play_card()
+ game.available_ops = 2
+ game.state = 'support_check_prep'
+ valid_spaces_sc()
},
tst_7() { /* Cancel opponent event */
push_undo()
log_ops_banner()
- check_ligachev_non_event()
- if (game.state === 'game_over') {
+ if (check_ligachev_non_event())
return
- } else {
- log(`Event cancelled using TST Award.`)
- game.tst_7 = true
- game.vm_infl_to_do = true
- game.state = 'resolve_opponent_event'
- }
+ log(`Event cancelled using TST Award.`)
+ game.tst_7 = true
+ game.vm_infl_to_do = true
+ game.state = 'resolve_opponent_event'
},
tst_8() { /* Play card for ops and event */
push_undo()
@@ -2276,31 +2261,25 @@ states.stasi_play_ceh = {
push_undo()
log_ops_banner()
log(`Played C${game.played_card} with C${C_COMMON_EUROPEAN_HOME}.`)
- check_ligachev_non_event()
- if (game.state === 'game_over') {
+ if (check_ligachev_non_event())
return
- } else {
- log('Placed SP:')
- if (game.persistent_events.includes(C_AUSTRIA_HUNGARY_BORDER_REOPENED)) {
- game.austria_hungary_border_reopened_tracker = true
- }
- game.state = 'add_influence'
- valid_spaces_infl()
+ log('Placed SP:')
+ if (game.persistent_events.includes(C_AUSTRIA_HUNGARY_BORDER_REOPENED)) {
+ game.austria_hungary_border_reopened_tracker = true
}
+ game.state = 'add_influence'
+ valid_spaces_infl()
},
support_check() {
push_undo()
log_ops_banner()
log(`Played C${game.played_card} with C${C_COMMON_EUROPEAN_HOME}.`)
- check_ligachev_non_event()
- if (game.state === 'game_over') {
+ if (check_ligachev_non_event())
return
- } else {
- log('Support Checks:')
- game.available_ops = 2
- game.state = 'support_check_prep'
- valid_spaces_sc()
- }
+ log('Support Checks:')
+ game.available_ops = 2
+ game.state = 'support_check_prep'
+ valid_spaces_sc()
},
}
@@ -3253,7 +3232,7 @@ function check_ceh() {
logi(`+1 VP for playing C${C_COMMON_EUROPEAN_HOME} for Operations.`)
}
if (check_vp()) {
- return
+ return true
}
}
}
@@ -3311,7 +3290,7 @@ function check_ligachev_non_event() {
log(`-3 VP from C${C_LIGACHEV}.`)
game.vp -= 3
if (check_vp()) {
- return
+ return true
}
game.persistent_events = game.persistent_events.filter(n => n !== C_LIGACHEV)
game.strategy_removed.push(C_LIGACHEV)
@@ -3324,7 +3303,7 @@ function check_ligachev_event(card) {
log(`-3 VP from C${C_LIGACHEV}.`)
game.vp -= 3
if (check_vp()) {
- return
+ return true
}
}
game.persistent_events = game.persistent_events.filter(n => n !== C_LIGACHEV)
@@ -8208,17 +8187,14 @@ states.vm_tst_8 = {
},
event() {
push_undo()
- check_ligachev_event(game.played_card)
- if (game.state === 'game_over') {
+ if (check_ligachev_event(game.played_card))
return
- } else {
- log_event(game.played_card)
- game.vm_event_to_do = false
- game.return_state = 'vm_tst_8'
- game.return = game.active
- game.vm_event = game.played_card
- goto_vm(game.vm_event)
- }
+ log_event(game.played_card)
+ game.vm_event_to_do = false
+ game.return_state = 'vm_tst_8'
+ game.return = game.active
+ game.vm_event = game.played_card
+ goto_vm(game.vm_event)
},
ops() {
push_undo()