summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authoriainp5 <iain.pearce.ip@gmail.com>2024-12-10 20:27:19 +0000
committeriainp5 <iain.pearce.ip@gmail.com>2024-12-10 20:27:19 +0000
commitc41b9834c835555c8a595ae88af630da2e357537 (patch)
tree009f3c9cdcc87d8b41bab739015f6669cced34c0 /rules.js
parentf8d5e9c44d178897da6d1748661f2169ce77e6aa (diff)
download1989-dawn-of-freedom-c41b9834c835555c8a595ae88af630da2e357537.tar.gz
Add icons
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js159
1 files changed, 138 insertions, 21 deletions
diff --git a/rules.js b/rules.js
index ebdb035..3235a31 100644
--- a/rules.js
+++ b/rules.js
@@ -2203,7 +2203,9 @@ states.stasi_resolve_common_european_home = {
function add_infl(space, ops) {
push_undo()
- log_summary(`£ in %${space}`)
+ //log_summary(`£ in %${space}`)
+
+ let starting_control = check_control(space)
// If AHBR - check AHBR conditions
if (game.persistent_events.includes(C_AUSTRIA_HUNGARY_BORDER_REOPENED)) {
@@ -2234,9 +2236,25 @@ function add_infl(space, ops) {
// Update influence values
if (game.active === COM) {
game.comInfl[space]++
+ /*if (check_com_control(space))
+ logi(`£CC in %${space}`)
+ else
+ logi(`£CU in %${space}`) */
} else {
game.demInfl[space]++
+ /*if (check_dem_control(space))
+ logi(`£DC in %${space}`)
+ else
+ logi(`£DU in %${space}`)*/
}
+
+ let end_control = check_control(space)
+
+ console.log('starting_control', starting_control, 'end_control', end_control)
+
+ log_summary('£ in %' + space + get_icons(starting_control,end_control))
+
+ console.log('influence add, game.summary', game.summary)
check_tyrant()
// Check Austria Hungary Border Reopened is true and condition has been met
@@ -2276,7 +2294,8 @@ function add_infl(space, ops) {
function remove_infl(space, ops) {
push_undo()
- log_summary(`£ in %${space}`)
+ //log_summary(`£ in %${space}`)
+ let starting_control = check_control(space)
if (game.remove_opponent_infl === true) {
if (game.active === COM) {
@@ -2290,7 +2309,6 @@ function remove_infl(space, ops) {
game.valid_spaces = game.valid_spaces.filter(id => id !== space)
}
}
- check_tyrant()
} else {
if (game.active === COM) {
@@ -2304,8 +2322,10 @@ function remove_infl(space, ops) {
game.valid_spaces = game.valid_spaces.filter(id => id !== space)
}
}
- check_tyrant()
}
+ let end_control = check_control(space)
+ log_summary('£ from %' + space + get_icons(starting_control,end_control))
+ check_tyrant()
game[ops]--
if (game.vm_influence_added && game.vm_influence_added[space] >= 0) {
game.vm_influence_added[space]++
@@ -2320,6 +2340,7 @@ function do_sc(space) {
let tear_gas_start = game.persistent_events.includes(C_TEAR_GAS)
let the_wall_start = game.persistent_events.includes(C_THE_WALL)
log(`%${space}:`)
+ let starting_control = check_control(space)
let roll = roll_d6()
// Check for The Wall
@@ -2441,7 +2462,6 @@ function do_sc(space) {
logii(`-${stability*2} (stability * 2)`)
const change_infl = Math.max(0, roll - stability*2)
if (change_infl > 0) {
- logi(`Change: ${change_infl} SP`)
if (game.active === DEM) {
if (change_infl > game.comInfl[space]) {
const residual = change_infl - game.comInfl[space]
@@ -2465,6 +2485,8 @@ function do_sc(space) {
game.valid_spaces = game.valid_spaces.filter(id => id !== space)
}
}
+ let end_control = check_control(space)
+ logi('Change: ' + change_infl + ' SP' + get_icons(starting_control, end_control))
check_tyrant_sc()
} else {
@@ -2693,7 +2715,7 @@ function count_adj(space_id) {
return {dem_adj, com_adj}
}
-function check_control(space_id) {
+function is_controlled(space_id) {
if ((game.comInfl[space_id] - game.demInfl[space_id]) >= spaces[space_id].stability) {
return true
} else if ((game.demInfl[space_id] - game.comInfl[space_id]) >= spaces[space_id].stability) {
@@ -2729,6 +2751,53 @@ function check_com_control(space_id) {
}
}
+function check_control(space) {
+ if (check_dem_control(space))
+ return DEM
+ else if (check_com_control(space))
+ return COM
+ else if (game.demInfl[space] > game.comInfl[space])
+ return 'd_ahead'
+ else if (game.comInfl[space] > game.demInfl[space])
+ return 'c_ahead'
+ else
+ return "none"
+}
+
+function get_icons(starting_control, end_control) {
+ console.log('starting_control', starting_control, 'end_control', end_control)
+ if (starting_control !== end_control) {
+ console.log('in long bit')
+ if (starting_control === DEM && end_control === COM)
+ return ' (£DC .to £CC)'
+ else if (starting_control === COM && end_control === COM)
+ return ' (£CC .to £DC)'
+ else if (starting_control === 'd_ahead' && end_control === DEM)
+ return ' (£DU .to £DC)'
+ else if (starting_control === 'd_ahead' && end_control === COM)
+ return ' (£DU .to £DC)'
+ else if (starting_control === 'c_ahead' && end_control === DEM)
+ return ' (£CU .to £DC)'
+ else if (starting_control === 'c_ahead' && end_control === COM)
+ return ' (£CU .to £CC)'
+ else if (starting_control === DEM && (end_control === 'd_ahead' || 'none'))
+ return ' (£DC .to £DU)'
+ else if (starting_control === DEM && end_control === 'c_ahead')
+ return ' (£DC .to £CU)'
+ else if (starting_control === COM && (end_control === 'c_ahead' || 'none'))
+ return ' (£CC .to £CU)'
+ else if (starting_control === COM && end_control === 'd_ahead')
+ return ' (£CC .to £DU)'
+ else if (starting_control === 'none' && end_control === DEM)
+ return ' (£DU .to £DC)'
+ else if (starting_control === 'none' && end_control === COM)
+ return ' (£CU .to £CC)'
+ else
+ return ''
+ } else
+ return ''
+}
+
function do_tst_attempt() {
let roll = roll_d6()
log(`Roll: D${roll}`)
@@ -3338,7 +3407,7 @@ function is_auto_resolve(card) {
return true
}
} else if (card === C_GOVERNMENT_RESIGNS && game.active === COM) {
- let uncontrolled_elites = spaces.filter(space => spaces[space.space_id].socio === SOCIO_ELITE && game.comInfl[space.space_id] > 0 && !check_control(space.space_id)).length
+ let uncontrolled_elites = spaces.filter(space => spaces[space.space_id].socio === SOCIO_ELITE && game.comInfl[space.space_id] > 0 && !is_controlled(space.space_id)).length
if (uncontrolled_elites === 0) {
if (!game.state.startsWith('vm')) {
log('No uncontrolled Elite spaces.')
@@ -4294,7 +4363,7 @@ function pop_summary() {
}
game.summary = []
}
-
+/*
function pop_summary_i() {
if (game.summary.length > 0) {
for (let [n, msg] of game.summary) {
@@ -4302,10 +4371,48 @@ function pop_summary_i() {
}
}
game.summary = []
-}
+} */
+
+ function pop_summary_i() {
+ if (game.summary.length > 0) {
+ // Create a map to group by space and track totals and details
+ let grouped_summary = new Map();
+
+ for (let [n, msg] of game.summary) {
+ // Extract the space identifier (e.g., %67) from the message
+ let space_match = msg.match(/%\d+/);
+ let space = space_match ? space_match[0] : "unknown";
+
+ // Extract any details (e.g., £CU to £CC) from the message
+ let details_match = msg.match(/\(.*?\)$/);
+ let details = details_match ? details_match[0] : "";
+
+ // Update or initialize the entry for the space
+ if (!grouped_summary.has(space)) {
+ grouped_summary.set(space, { total: 0, details });
+ }
+ let entry = grouped_summary.get(space);
+ entry.total += n;
+
+ // Always keep the most specific details (non-empty)
+ if (details) {
+ entry.details = details;
+ }
+ }
+
+ // Log the grouped results
+ for (let [space, { total, details }] of grouped_summary) {
+ logi(`${total} in ${space} ${details}`);
+ }
+ }
+ game.summary = [];
+ }
+
+
function do_log_summary() {
if (game.summary.length > 0) {
+ console.log('game.summary', game.summary)
pop_summary_i()
}
}
@@ -4707,7 +4814,7 @@ function vm_valid_spaces_solidarity_legalised() {
let valid_spaces = []
for (let i = 0; i < spaces.length; i++) {
let space = spaces[i]
- let uncontrolled = !check_control(i) && !check_opp_control(i)
+ let uncontrolled = !is_controlled(i) && !check_opp_control(i)
if (
(space.country === 'Poland' && uncontrolled && space.socio === SOCIO_WORKER) ||
(space.country === 'Poland' && uncontrolled && space.socio === SOCIO_FARMER)
@@ -4729,6 +4836,7 @@ function vm_take_control_prep() {
}
function vm_take_control(space) {
+ let starting_control = check_control(space)
if (game.active === DEM) {
let current_infl = game.demInfl[space]
let opponent_infl = game.comInfl[space]
@@ -4747,22 +4855,25 @@ function vm_take_control(space) {
}
}
game.valid_spaces = game.valid_spaces.filter(id => id !== space)
+ let end_control = check_control(space)
if (game.state === 'vm_kremlin_coup_take_control')
- logi(`Took control of %${space}.`)
+ logi('Took control of %' + space + get_icons(starting_control, end_control) +'.')
else
- log(`Took control of %${space}.`)
+ log('Took control of %' + space + get_icons(starting_control, end_control) +'.')
}
function vm_do_add_infl_free(space) {
push_undo()
- log_summary(`£ in %${space}`)
-
+ //log_summary(`£ in %${space}`)
+ let starting_control = check_control(space)
// Update influence values
if (game.active === COM) {
game.comInfl[space]++
} else {
game.demInfl[space]++
}
+ let end_control = check_control(space)
+ log_summary('£ in %' + space + get_icons(starting_control,end_control))
game.vm_available_ops--
check_tyrant()
}
@@ -4812,7 +4923,8 @@ function vm_add_limited_infl() {
function vm_do_add_limited_infl(space, max_infl) {
push_undo()
- log_summary(`£ in %${space}`)
+ //log_summary(`£ in %${space}`)
+ let starting_control = check_control(space)
game.vm_available_ops --
if (!game.vm_influence_added) {
@@ -4829,6 +4941,8 @@ function vm_do_add_limited_infl(space, max_infl) {
game.demInfl[space] ++
}
+ let end_control = check_control(space)
+ log_summary('£ in %' + space + get_icons(starting_control,end_control))
game.vm_influence_added[space] ++
if (game.vm_influence_added[space] === max_infl) {
@@ -4865,7 +4979,7 @@ function vm_remove_x_opp_infl() {
function vm_do_remove_x_infl(space) {
push_undo()
-
+ let starting_control = check_control(space)
if (game.remove_opponent_infl) {
if (game.active === COM) {
if (game.demInfl[space] >= game.vm_available_ops) {
@@ -4899,8 +5013,8 @@ function vm_do_remove_x_infl(space) {
}
}
}
-
- logi(`${game.vm_available_ops} - %${space}`)
+ let end = check_control(space)
+ logi(`${game.vm_available_ops} from %${space}${get_icons(starting_control, end_control)}`)
check_tyrant()
game.vm_available_ops = 0
game.valid_spaces = []
@@ -4916,7 +5030,8 @@ function vm_remove_limited_opp_infl() {
function vm_do_remove_limited_infl(space, max_infl) {
push_undo()
- log_summary(`£ in %${space}`)
+ //log_summary(`£ in %${space}`)
+ let starting_control = check_control(space)
game.vm_available_ops --
if (!game.vm_influence_added) {
@@ -4945,6 +5060,8 @@ function vm_do_remove_limited_infl(space, max_infl) {
game.valid_spaces = game.valid_spaces.filter(id => id !== space)
}
+ let end_control = check_control(space)
+ log_summary('£ from %' + space + get_icons(starting_control,end_control))
check_tyrant()
if (game.vm_available_ops === 0) {
game.valid_spaces = []
@@ -4958,7 +5075,7 @@ function vm_remove_all_infl() {
function vm_do_remove_all_infl(space) {
push_undo()
-
+
if (game.remove_opponent_infl === true) {
if (game.active === COM) {
log(`Removed all Democratic SP from %${space}.`)
@@ -5356,7 +5473,7 @@ function vm_goodbye_lenin() {
function vm_government_resigns() {
for (let i = 0; i < spaces.length; i++) {
let space = spaces[i]
- if (space.socio === SOCIO_ELITE && game.comInfl[i] > 0 && !check_control(i)) {
+ if (space.socio === SOCIO_ELITE && game.comInfl[i] > 0 && !is_controlled(i)) {
game.valid_spaces.push(i)
}
}