summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authoriainp5 <iain.pearce.ip@gmail.com>2024-10-31 23:00:48 +0000
committeriainp5 <iain.pearce.ip@gmail.com>2024-10-31 23:00:48 +0000
commit94d52e8ea1f8919d2e9c0931318c460360828944 (patch)
tree0609073cc346761a50932e5539db45e1a0cf5875 /rules.js
parent158e551a2371d96a6af9b10bb30c2de61c00caac (diff)
download1989-dawn-of-freedom-94d52e8ea1f8919d2e9c0931318c460360828944.tar.gz
Remove unnecessary states and functions
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js269
1 files changed, 28 insertions, 241 deletions
diff --git a/rules.js b/rules.js
index 5e3168c..8344fdb 100644
--- a/rules.js
+++ b/rules.js
@@ -522,7 +522,7 @@ states.com_init = {
}
},
space(space) {
- add_infl(space)
+ add_infl(space, 'available_ops')
},
done() {
do_log_summary()
@@ -567,7 +567,7 @@ states.dem_init = {
}
},
space(space) {
- add_infl(space)
+ add_infl(space, 'available_ops')
},
done() {
do_log_summary()
@@ -801,13 +801,13 @@ states.resolve_opponent_event = {
if (game.persistent_events.includes(58)) {
game.austria_hungary_border_reopened_tracker = true
}
- game.state = 'finish_add_infl'
+ game.state = 'add_influence'
valid_spaces_infl()
},
support_check() {
push_undo()
game.available_ops = 2
- game.state = 'finish_support_check_prep'
+ game.state = 'support_check_prep'
valid_spaces_sc()
},
opp_event() {
@@ -841,96 +841,6 @@ states.resolve_opponent_event = {
}
}
-states.finish_add_infl = {
- inactive: 'add SPs.',
- prompt () {
- if (game.available_ops === 0) {
- view.prompt = 'Place SPs: done.'
- gen_action("end_round")
- return;
- }
- view.prompt = `Add SPs: ${game.available_ops} remaining.`
- for (let space_id of game.valid_spaces) {
- gen_action_space(space_id)
- }
- },
- space(space) {
- add_infl(space)
- },
- end_round() {
- push_undo()
- do_log_summary()
- end_round()
- }
-}
-
-states.finish_support_check_prep = {
- inactive: 'do support checks.',
- prompt () {
- if (game.available_ops === 0) {
- view.prompt = 'Support checks: done.'
- gen_action('end_round')
- } else {
- view.prompt = `Select a space. ${pluralize(game.available_ops, 'support check')} remaining.`
- console.log('valid_spaces', game.valid_spaces)
- for (let space_id of game.valid_spaces) {
- gen_action_space(space_id)
- }
- }
- },
- space(space) {
- push_undo()
- game.selected_space = space
- // Check for Austria-Hungary Border Reopened - check on first support check only
- if (game.persistent_events.includes(58)){
- if (game.active === DEM && game.available_ops > 1) {
- if (spaces[game.selected_space].country === 'East_Germany' && game.persistent_events.includes(58) && game.active === DEM) {
- game.state = 'finish_austria_hungary_border_reopened_check'
- return
- }
- }
- }
- game.state = 'finish_do_support_check'
- },
- end_round () {
- end_round()
- }
-}
-
-states.finish_austria_hungary_border_reopened_check = {
- inactive: 'decide Austria-Hungary Border Reopened',
- prompt() {
- view.prompt = 'Austria-Hungary Border Reopened: will both support checks be in East Germany?'
- gen_action('yes')
- gen_action('no')
- },
- yes() {
- game.austria_hungary_border_reopened_tracker = true
- game.state = 'finish_do_support_check'
- },
- no() {
- game.state = 'finish_do_support_check'
- }
-}
-
-states.finish_do_support_check = {
- inactive: 'do support checks',
- prompt () {
- view.prompt = `Support check: ${spaces[game.selected_space].name_unique}. Roll a die.`
- gen_action('roll')
- },
- roll() {
- clear_undo()
- do_sc(game.selected_space)
- game.available_ops--
- if (game.available_ops === 0) {
- game.valid_spaces = []
- }
- game.state = 'finish_support_check_prep'
- return
- }
-}
-
states.add_influence = {
inactive: 'add SPs.',
prompt () {
@@ -938,7 +848,7 @@ states.add_influence = {
view.prompt = 'Place SPs: done.'
if (!game.vm_event_to_do) {
gen_action("end_round")
- } else {
+ } else {add_influence
gen_action('done')
}
} else {
@@ -949,7 +859,7 @@ states.add_influence = {
}
},
space(space) {
- add_infl(space)
+ add_infl(space, 'available_ops')
},
end_round() {
push_undo()
@@ -1301,7 +1211,7 @@ states.the_crowd_turns_against_ceausescu_infl = {
}
},
space(space) {
- vm_do_add_infl(space)
+ add_infl(space, 'vm_available_ops')
},
done() {
do_log_summary()
@@ -1620,10 +1530,7 @@ states.support_loss ={
},
space(space) {
game.remove_opponent_infl = false /* Don't know why this is needed... */
- remove_infl(space)
- if (game.available_ops === 0 ) {
- game.valid_spaces = []
- }
+ remove_infl(space, 'available_ops')
},
done () {
do_log_summary()
@@ -2178,7 +2085,7 @@ states.stasi_resolve_common_european_home = {
// ==================== SUPPORTING STATE FUNCTIONS =============================
-function add_infl(space) {
+function add_infl(space, ops) {
push_undo()
log_summary(`Added £ SP in %${space}`)
@@ -2191,16 +2098,16 @@ function add_infl(space) {
// Check Genscher
if (game.persistent_events.includes(C_GENSCHER) && game.active === DEM && spaces[space].country === 'East_Germany' && check_com_control(space)) {
- game.available_ops--
+ game[ops]--
log_summary(`(-1 op due to C${C_GENSCHER})`)
} else if (check_opp_control(space)) {
- game.available_ops -= 2
+ game[ops] -= 2
//Check if Austria Hungary Border Reopened was used to place last SP in a controlled space in East Germany. If so, game.available_op will be negative
- if (game.available_ops < 0) {
+ if (game[ops] < 0) {
log_summary(`(Used +1 op from C${C_AUSTRIA_HUNGARY_BORDER_REOPENED})`)
}
} else {
- game.available_ops--
+ game[ops]--
}
// Update influence values
@@ -2212,8 +2119,8 @@ function add_infl(space) {
check_tyrant()
// Check Austria Hungary Border Reopened is true and condition has been met
- if (game.available_ops === 0 && game.active === DEM && game.persistent_events.includes(C_AUSTRIA_HUNGARY_BORDER_REOPENED) && game.austria_hungary_border_reopened_tracker) {
- game.available_ops ++
+ if (game[ops] === 0 && game.active === DEM && game.persistent_events.includes(C_AUSTRIA_HUNGARY_BORDER_REOPENED) && game.austria_hungary_border_reopened_tracker) {
+ game[ops] ++
log('+1 op from C58')
game.austria_hungary_border_reopened_tracker = false
game.valid_spaces = game.valid_spaces.filter(n => spaces[n].country === 'East_Germany')
@@ -2223,7 +2130,7 @@ function add_infl(space) {
// Check for Genscher & Austria Hungary Border Reopened
- if (game.available_ops === 1) {
+ if (game[ops] === 1) {
if (game.active === DEM) {
if (game.persistent_events.includes(63) || (game.persistent_events.includes(58) && game.austria_hungary_border_reopened_tracker)) {
game.valid_spaces = game.valid_spaces.filter(n => !(check_opp_control(n) && spaces[n].country !== 'East_Germany'))
@@ -2236,12 +2143,12 @@ function add_infl(space) {
}
//Clear valid spaces if no IP remaining.
- if (game.available_ops <= 0 ) {
+ if (game[ops] <= 0 ) {
game.valid_spaces = []
}
}
-function remove_infl(space) {
+function remove_infl(space, ops) {
push_undo()
log_summary(`Removed £ SP from %${space}.`)
@@ -2273,7 +2180,9 @@ function remove_infl(space) {
}
check_tyrant()
}
- game.available_ops--
+ game[ops]--
+ if (game.vm_influence_added && game.vm_influence_added[space]) {game.vm_influence_added[space]++}
+ if (game[ops]===0) {game.valid_spaces = []}
}
function do_sc(space) {
@@ -4364,84 +4273,6 @@ function vm_take_control(space) {
log(`Took control of %${space}`)
}
-
-function vm_do_add_infl(space) {
- push_undo()
- log_summary(`Added £ SP in %${space}.`)
-
- //If AHBR - check AHBR condition
- if (game.persistent_events.includes(C_AUSTRIA_HUNGARY_BORDER_REOPENED)) {
- if (spaces[space].country !== 'East_Germany'){
- game.austria_hungary_border_reopened_tracker = false
- }
- }
-
- // Check Genscher
- if (game.persistent_events.includes(C_GENSCHER) && game.active === DEM && spaces[space].country === 'East_Germany') {
- game.vm_available_ops--
- log_summary(`(-1 op due to C63)`)
- } else if (check_opp_control(space)) {
- game.vm_available_ops -= 2
- //Check if Austria Hungary Border Reopened was used to place last SP in a controlled space in East Germany. If so, game.vm_available_op will be negative
- if (game.vm_available_ops < 0) {
- log_summary(`(Used +1 op from C58)`)
- }
- } else {
- game.vm_available_ops--
- }
-
- // Update influence values
- if (game.active === COM) {
- game.comInfl[space]++
- } else {
- game.demInfl[space]++
- }
- check_tyrant()
-
- // Check Austria Hungary Border Reopened is true and condition has been met
- if (game.vm_available_ops === 0 && game.active === DEM && game.persistent_events.includes(C_AUSTRIA_HUNGARY_BORDER_REOPENED) && game.austria_hungary_border_reopened_tracker) {
- game.vm_available_ops ++
- log('+1 Op from C58')
- game.austria_hungary_border_reopened_tracker = false
- game.valid_spaces = game.valid_spaces.filter(n => spaces[n].country === 'East_Germany')
- }
-
- // If only 1 IP remaining, may not place in opponent controlled spaces
-
- // Check for Genscher & Austria Hungary Border Reopened
-
- if (game.vm_available_ops === 1) {
-
- if (game.active === DEM) {
- //Check Genscher and AHBR
- if (game.persistent_events.includes(C_GENSCHER) || (game.persistent_events.includes(C_AUSTRIA_HUNGARY_BORDER_REOPENED) && game.austria_hungary_border_reopened_tracker)) {
- game.valid_spaces = game.valid_spaces.filter(n => !(check_com_control(n) && spaces[n].country !== 'East_Germany'))
- } else {
- game.valid_spaces = game.valid_spaces.filter(n => !check_com_control(n))
- }
- } else {
- game.valid_spaces = game.valid_spaces.filter(n => !check_dem_control(n))
- }
- }
-
- //Clear valid spaces if no IP remaining.
- if (game.vm_available_ops <= 0 ) {
- game.valid_spaces = []
- }
-}
-
-function vm_do_add_infl_free(space) {
- push_undo()
- log_summary(`Added £ SP in %${space}.`)
- if (game.active === COM) {
- game.comInfl[space]++
- } else {
- game.demInfl[space]++
- }
- game.vm_available_ops--
- check_tyrant()
-}
-
function vm_add_infl() {
if (vm_operand(1)) {game.vm_available_ops = vm_operand(1)}
game.state = 'vm_add_infl'
@@ -4525,50 +4356,6 @@ function vm_remove_x_opp_infl() {
game.state = 'vm_remove_x_infl'
}
-function vm_do_remove_infl(space) {
- push_undo()
- log_summary(`Removed £ SP from %${space}.`)
-
- if (!game.vm_influence_added) {
- game.vm_influence_added = {};
- }
-
- if (!game.vm_influence_added[space]) {
- game.vm_influence_added[space] = 0;
- }
- if (game.remove_opponent_infl === true) {
- if (game.active === COM) {
- game.demInfl[space]--
- if (game.demInfl[space] === 0) {
- game.valid_spaces = game.valid_spaces.filter(id => id !== space);
- }
- } else {
- game.comInfl[space]--
- if (game.comInfl[space] === 0) {
- game.valid_spaces = game.valid_spaces.filter(id => id !== space);
- }
- }
-
-
- } else {
- if (game.active === COM) {
- game.comInfl[space]--
- if (game.comInfl[space] === 0) {
- game.valid_spaces = game.valid_spaces.filter(id => id !== space);
- }
- } else {
- game.demInfl[space]--
- if (game.demInfl[space] === 0) {
- game.valid_spaces = game.valid_spaces.filter(id => id !== space);
- }
- }
- }
- check_tyrant()
- game.vm_influence_added[space]++
- game.vm_available_ops--
- if (game.vm_available_ops===0) {game.valid_spaces = []}
-}
-
function vm_do_remove_x_infl(space) {
push_undo()
@@ -5663,7 +5450,7 @@ states.vm_add_infl = {
}
},
space(space) {
- vm_do_add_infl(space)
+ add_infl(space, 'vm_available_ops')
if (game.vm_available_ops === 0) {
game.valid_spaces = []
do_log_summary()
@@ -5813,8 +5600,7 @@ states.vm_remove_infl = {
}
},
space(space) {
- push_undo()
- vm_do_remove_infl(space)
+ remove_infl(space, 'vm_available_ops')
game.vm_active_country = spaces[space].country
if (game.vm_event !== C_INFLATIONARY_CURRENCY) {
if (game.vm_available_ops === 0 ) {
@@ -7237,11 +7023,12 @@ states.vm_shock_therapy = {
return `resolve ${clean_name(cards[game.played_card].name)}.`
},
prompt() {
+ console.log('game.vm_active_country', game.vm_active_country)
if (game.revolutions.every(n => n === false)) {
view.prompt = 'Shock Therapy: no countries to choose.'
gen_action('pass')
} else {
- if (game.vm_active_country === '' ) {
+ if (!game.vm_active_country || game.vm_active_country === '' ) {
view.prompt = 'Shock Therapy: choose a country where you hold Power:'
if (game.revolutions[0]) {gen_action('poland')}
if (game.revolutions[1]) {gen_action('hungary')}
@@ -7629,7 +7416,7 @@ states.vm_we_are_the_people_remove = {
}
},
space(space) {
- vm_do_remove_infl(space)
+ remove_infl(space, 'vm_available_ops')
},
done() {
do_log_summary()
@@ -7778,7 +7565,7 @@ states.vm_tst_4 = {
}
},
space(space) {
- vm_do_remove_infl(space)
+ remove_infl(space, 'vm_available_ops')
if (game.vm_available_ops === 0) {
do_log_summary()
vm_next()
@@ -7925,7 +7712,7 @@ states.vm_scare_tactics = {
},
space(space) {
push_undo()
- vm_do_remove_infl(space)
+ remove_infl(space, 'vm_available_ops')
},
done() {
do_log_summary()