diff options
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 161 |
1 files changed, 144 insertions, 17 deletions
@@ -279,6 +279,12 @@ var LAYOUT = { "Wroclaw": [595,565,127,75], "action_1": [708,143,48,44], "action_8": [1080,143,47,43], + "box_bulgaria": [935,2101,15,100], + "box_czechoslovakia": [473,736,15,100], + "box_east_germany": [578,262,15,100], + "box_hungary": [1054,1421,15,100], + "box_poland": [1202,400,15,100], + "box_romania": [1307,1450,15,100], "country_bulgaria": [915,1999,46,41], "country_czechoslovakia": [463,624,44,39], "country_east_germany": [560,160,43,37], @@ -398,6 +404,22 @@ function create_country(id, name) { ui.countries[id] = e document.getElementById("markers").appendChild(e) } +/* +function create_score_box(id, name) { + let [ x, y, w, h ] = LAYOUT[name] + let xc = Math.round(x + w / 2) + let yc = Math.round(y + h / 2) + + //Create dynamic scoring box + let b = document.createElement("div") + b.className = "box" + b.style.left = xc - 110 + "px" + b.style.top = yc - 76 + "px" + b.id = name + ui.score_box[id] = b + + document.getElementById("markers").appendChild(b) +}*/ const INF_DX = 33 const INF_DY = 10 @@ -507,12 +529,19 @@ function create_ui() { } ui.countries = [] + ui.score_box = [] create_country(0, "country_poland") create_country(1, "country_hungary") create_country(2, "country_east_germany") create_country(3, "country_bulgaria") create_country(4, "country_czechoslovakia") create_country(5, "country_romania") + /*create_score_box(0, "box_poland") + create_score_box(1, "box_hungary") + create_score_box(2, "box_east_germany") + create_score_box(3, "box_bulgaria") + create_score_box(4, "box_czechoslovakia") + create_score_box(5, "box_romania")*/ } function layout_turn_marker() { @@ -595,15 +624,32 @@ function layout_vp_marker() { } function layout_country(id) { - for (let i = 0; i < 6; i++) { // TODO: what number to display? - if (view.revolutions[id]) - ui.countries[id].className = "marker demInfl ctl v" + view.times_held[id] - else if (view.times_held[id] > 0) - ui.countries[id].className = "marker comInfl ctl v" + view.times_held[id] - else - ui.countries[id].className = "marker hide" - } + if (view.revolutions[id]) + ui.countries[id].className = "marker demInfl ctl v" + view.times_held[id] + else if (view.times_held[id] > 0) + ui.countries[id].className = "marker comInfl ctl v" + view.times_held[id] + else + ui.countries[id].className = "marker hide" +} + +function layout_score_box(id) { + console.log('ui.score_box[i]', ui.score_box[id]) + let country = ui.score_box[id].id.replace(/^box_/,'') + let status = check_presence(country) + ui.score_box[id].className = 'box' + if (status.dem_spaces > 0) + ui.score_box[id].classList.add('d_pres') + if (status.com_spaces >0) + ui.score_box[id].classList.add('c_pres') + if (status.dem_domination) + ui.score_box[id].classList.add('d_dom') + if (status.com_domination) + ui.score_box[id].classList.add('c_dom') + if (status.dem_control) + ui.score_box[id].classList.add('d_ctrl') + if (status.com_control) + ui.score_box[id].classList.add('c_ctrl') } function layout_inf_markers(cn, one, two, three, v, ctl) { @@ -628,6 +674,80 @@ function layout_inf_markers(cn, one, two, three, v, ctl) { } } + +function check_presence(country) { + + let dem_spaces = 0 + let com_spaces = 0 + let dem_battlegrounds = 0 + let com_battlegrounds = 0 + //console.log('checking country', country) + for (let i = 0; i < spaces.length; i++) { + let space = spaces[i] + //console.log('checking space', space.ascii_name, 'space.country', space.country.toLowerCase) + if (space.country.toLowerCase() === country) { + //console.log('space', space.ascii_name, 'is in', country) + if (check_dem_control(i)) { + dem_spaces++ + if (space.battleground === 1) + dem_battlegrounds++ + } + if (check_com_control(i)) { + com_spaces++ + if (space.battleground === 1) + com_battlegrounds++ + } + } + } + + // Determine domination + let dem_domination = dem_battlegrounds > com_battlegrounds && dem_spaces > com_spaces && dem_spaces - dem_battlegrounds > 0 + let com_domination = com_battlegrounds > dem_battlegrounds && com_spaces > dem_spaces && com_spaces - com_battlegrounds > 0 + + // Determine control + let total_battlegrounds = battlegrounds(country) + let dem_control = dem_battlegrounds === total_battlegrounds && dem_spaces > com_spaces + let com_control = com_battlegrounds === total_battlegrounds && com_spaces > dem_spaces + console.log(country, 'dem_battlegrounds', dem_battlegrounds, 'total_battlegrounds', total_battlegrounds, 'dem_spaces', dem_spaces, 'com_spaces', com_spaces) + return { + dem_spaces: dem_spaces, + com_spaces: com_spaces, + dem_domination: dem_domination, + com_domination: com_domination, + dem_control: dem_control, + com_control: com_control, + } +} + +function battlegrounds(country) { + let battlegrounds = 0 + if (country === 'hungary') { + battlegrounds = 4 + } else if (country === 'bulgaria') { + battlegrounds = 5 + } else { + battlegrounds = 6 + } + return battlegrounds +} + +function check_dem_control(space_id) { + if ((view.demInfl[space_id] - view.comInfl[space_id]) >= spaces[space_id].stability) { + return true + } else { + return false + } +} + +function check_com_control(space_id) { + if ((view.comInfl[space_id] - view.demInfl[space_id]) >= spaces[space_id].stability) { + return true + } else { + return false + } +} + + function on_update() { if (!ui.spaces) create_ui() @@ -713,9 +833,10 @@ function on_update() { // UPDATE COUNTRY MARKERS - for (let i = 0; i < 6; ++i) + for (let i = 0; i < 6; ++i) { layout_country(i) - + /*layout_score_box(i)*/ + } // UPDATE CARD DISPLAYS ui.samizdat_card.replaceChildren() @@ -864,12 +985,11 @@ function sub_die(match) { } function sub_icon(match) { - console.log('sub_icon called, match', match) return ICONS[match] || match } function sub_arrow(match) { - return '<span>→</span>' + return '<span> → </span>' } const ICONS = { @@ -877,6 +997,7 @@ const ICONS = { '£CU': '<span class="icon com_nc"></span>', '£DC': '<span class="icon dem_c"></span>', '£DU': '<span class="icon dem_nc"></span>', + '£UU': '<span class="number icon"></span>', '.dT5': '<span class="number d_tst">5</span>', '.dT6': '<span class="number d_tst">6</span>', '.dT7': '<span class="number d_tst">7</span>', @@ -901,7 +1022,7 @@ const die = { function on_log(text, ix) { let p = document.createElement("div") - console.log('text', text) + //console.log('text', text) let event_string = text.match(/^C(\d+)/) if (event_string) event_n = parseInt(event_string[1]) @@ -915,18 +1036,16 @@ function on_log(text, ix) { p.className = "i" } - console.log('text', text) - text = text.replace(/_/g, " ") text = text.replace(/C(\d+)/g, sub_card_name) text = text.replace(/P(\d+)/g, sub_power_card_name) text = text.replace(/V(\d+)/g, sub_power_card_value) text = text.replace(/%(\d+)/g, sub_space_name) text = text.replace(/D[1-6]/g, sub_die) - text = text.replace(/£[CD][CU]\b/g, sub_icon) + text = text.replace(/£[CDU][CU]\b/g, sub_icon) text = text.replace(/\.cT(\d+)/g, sub_icon) text = text.replace(/\.dT(\d+)/g, sub_icon) - text = text.replace(/\.to/g, sub_arrow) + text = text.replace(/\s\.to\s/g, sub_arrow) if (text.match(/^\.h1/)) { text = text.substring(4) @@ -980,6 +1099,14 @@ function on_log(text, ix) { text = text.substring(4) p.className = "h3" log_event = 0 + } else if (text.match(/^\.h4/)) { + text = text.substring(4) + p.className = "h4" + log_event = 0 + } else if (text.match(/^\.h5/)) { + text = text.substring(4) + p.className = "h5" + log_event = 0 } //Group events |