diff options
-rw-r--r-- | play.js | 50 | ||||
-rw-r--r-- | rules.js | 74 |
2 files changed, 72 insertions, 52 deletions
@@ -211,6 +211,7 @@ const MOM_SENADO_FARC = 5 const MOM_SENADO_AUC = 6 const MOM_SENADO_CARTELS = 7 +const ATLANTICO = 11 const META_WEST = 14 const first_piece = data.first_piece @@ -218,6 +219,7 @@ const last_piece = data.last_piece const last_city = data.last_city const last_pop = data.last_pop +const first_dept = data.first_dept const last_dept = data.last_dept const first_loc = data.first_loc const last_loc = data.last_loc @@ -295,6 +297,7 @@ let ui = { spaces: [], control: [], support: [], + farc_zone: [], sabotage: [], terror: [], card_tip: document.getElementById("card_tip"), @@ -512,6 +515,7 @@ function init_ui() { if (i <= last_dept) { let [x, y] = LAYOUT[id] + if (i <= last_city) ui.control[i] = e = create("div", { className: "token govt_control" }) else @@ -528,8 +532,24 @@ function init_ui() { e.style.top = (y - 25) + "px" } document.getElementById("tokens").appendChild(e) + + if (i >= first_dept) { + ui.farc_zone[i] = e = create("div", { className: "token farc_zone hide" }) + if (i <= last_pop) { + e.style.left = (x - 25 - 49) + "px" + if (i === ATLANTICO || i === META_WEST) + e.style.top = (y - 25 - 50) + "px" + else + e.style.top = (y - 25 - 25) + "px" + } else { + e.style.top = (y - 25) + "px" + e.style.left = (x - 25 + 55) + "px" + } + } + document.getElementById("tokens").appendChild(e) } + if (i >= first_loc && i <= last_loc) { let [x, y] = LAYOUT[id] ui.sabotage[i] = e = create("div", { className: "hide" }) @@ -859,7 +879,7 @@ function layout_terror(tix, s, n) { tx += Math.round(r * Math.cos(a)) ty += Math.round(r * Math.sin(a)) } else { - if (set_has(view.farc_zones, s)) { + if (view.farc_zones & (1<<s)) { if (s <= last_pop) { ty -= 85 } else { @@ -880,7 +900,7 @@ function layout_terror(tix, s, n) { ui.terror[tix].className = "token terror" ui.terror[tix].style.left = tx + "px" ui.terror[tix].style.top = ty + "px" - if (s <= last_city || s > last_pop || set_has(view.farc_zones, s)) { + if (s <= last_city || s > last_pop || (view.farc_zones & (1<<s))) { tx += 10 ty -= 10 } else { @@ -892,23 +912,6 @@ function layout_terror(tix, s, n) { return tix } -function layout_farc_zone(s, elt) { - let [x, y] = get_layout_xy(s) - if (s <= last_pop) { - x -= 49 - if (s === META_WEST) - y -= 25 + 40 - else - y -= 25 - - } else { - x += 55 - } - elt.className = "token farc_zone" - elt.style.top = (y - 25) + "px" - elt.style.left = (x - 25) + "px" -} - const shipment_layout_dept = [ [ -18, 0, 2 ], [ 18, 0, 3 ], @@ -1111,11 +1114,12 @@ function on_update() { else ui.sabotage[s].className = "hide" } - + + if (s >= first_dept && s <= last_dept) { + ui.farc_zone[s].classList.toggle("hide", !(view.farc_zones & (1<<s))) + } + if (s <= last_dept) { - for (let i = 0; i < view.farc_zones.length; ++i) - if (view.farc_zones[i] === s) - layout_farc_zone(s, ui.farc_zones[i]) if (view.govt_control & (1<<s)) ui.control[s].className = "token govt_control" else if (view.farc_control & (1<<s)) @@ -2,16 +2,11 @@ // TODO: rules material - reference 6.3.3 Drug Profits to 5.2.2 should be 4.5.3 -// TODO: compact game.memory array instead of president/aid/cylinder/resources/samper/pieces/support/control -// TODO: bit array for momentum and capabilities instead of set lists +// TODO: compact game.memory array instead of president/aid/cylinder/resources/pieces/support/control // TODO: clean up init_free_operation stuff // TODO: check how often and where to push_undo -// TODO: log when resource/aid is capped - -// TODO: CODE separated by functions - CODE[game.vm.fp][game.vm.ip] - // TODO: auto-skip civic action // TODO: auto-skip agitation @@ -277,6 +272,7 @@ exports.setup = function (seed, scenario, options) { govt_control: 0, farc_control: 0, auc_control: 0, + farc_zones: 0, cylinder: [ ELIGIBLE, ELIGIBLE, ELIGIBLE, ELIGIBLE ], resources: [ 0, 0, 0, 0 ], shipments: [ 0, 0, 0, 0 ], @@ -285,7 +281,6 @@ exports.setup = function (seed, scenario, options) { support: Array(23).fill(NEUTRAL), deck: [], - farc_zones: [], terror: [], sabotage: [], @@ -419,7 +414,7 @@ function setup_quick() { setup_support(ARAUCA, NEUTRAL) setup_piece(AUC, GUERRILLA, 1, ARAUCA) - set_add(game.farc_zones, META_WEST) + add_farc_zone(META_WEST) setup_piece(FARC, GUERRILLA, 4, META_WEST) setup_support(HUILA, ACTIVE_OPPOSITION) @@ -930,8 +925,22 @@ function has_capability(bit) { return game.capabilities & (1 << bit) } +function has_any_farc_zones() { + return game.farc_zones !== 0 +} + function is_farc_zone(s) { - return set_has(game.farc_zones, s) + return (s <= last_dept) && game.farc_zones & (1 << s) +} + +function add_farc_zone(s) { + log(`FARC Zone in S${s}.`) + game.farc_zones |= (1 << s) +} + +function remove_farc_zone(s) { + log(`Removed Farc Zone from S${s}.`) + game.farc_zones &= ~(1 << s) } function has_govt_control(s) { @@ -1180,18 +1189,24 @@ function transfer_resources(from, to, n) { } function add_resources(faction, n) { - if (n > 0) + if (n > 0) { log(faction_name[faction] + " Resources +" + n + ".") - else + if (game.aid + n > 99) + log("Resources capped at 99.") + } else { log(faction_name[faction] + " Resources " + n + ".") + } game.resources[faction] = Math.max(0, Math.min(99, game.resources[faction] + n)) } function add_aid(n) { - if (n > 0) + if (n > 0) { log("Aid +" + n + ".") - else + if (game.aid + n > 29) + log("Aid capped at 29.") + } else { log("Aid " + n + ".") + } game.aid = Math.max(0, Math.min(29, game.aid + n)) } @@ -5643,7 +5658,7 @@ function goto_election() { log_h3("Election") log("Uribe is El Presidente!") game.president = URIBE - if (game.farc_zones.length > 0) { + if (has_any_farc_zones()) { game.state = "remove_farc_zones" return } @@ -5654,13 +5669,13 @@ function goto_election() { states.remove_farc_zones = { prompt() { view.prompt = "Election: Remove all FARC Zones." - for (let s of game.farc_zones) - gen_action_space(s) + for (let s = first_dept; s <= last_dept; ++s) + if (is_farc_zone(s)) + gen_action_space(s) }, space(s) { - log(`Removed Farc Zone from S${s}.`) - set_delete(game.farc_zones, s) - if (game.farc_zones.length === 0) + remove_farc_zone(s) + if (!has_any_farc_zones()) goto_elite_backing() }, } @@ -5851,8 +5866,8 @@ function vm_place_farc_zone() { } function has_govt_in_farc_zone() { - for (let s of game.farc_zones) - if (has_govt_piece(s)) + for (let s = first_dept; s <= last_dept; ++s) + if (is_farc_zone(s) && has_govt_piece(s)) return true return false } @@ -5866,8 +5881,7 @@ states.farc_zone_place = { }, space(s) { push_undo() - log(`FARC Zone in S${s}.`) - set_add(game.farc_zones, s) + add_farc_zone(s) if (game.vm) game.vm.farc_zone = s @@ -5885,10 +5899,12 @@ states.farc_zone_redeploy = { prompt() { view.prompt = "Redeploy Government from FARC Zone." if (game.redeploy < 0) { - for (let s of game.farc_zones) { - gen_piece_in_space(s, GOVT, TROOPS) - gen_piece_in_space(s, GOVT, POLICE) - gen_piece_in_space(s, GOVT, BASE) + for (let s = first_dept; s <= last_dept; ++s) { + if (is_farc_zone(s)) { + gen_piece_in_space(s, GOVT, TROOPS) + gen_piece_in_space(s, GOVT, POLICE) + gen_piece_in_space(s, GOVT, BASE) + } } } else { let p = game.redeploy @@ -6183,7 +6199,7 @@ function vm_remove() { } function vm_remove_farc_zone() { - set_delete(game.farc_zones, game.vm.s) + remove_farc_zone(game.vm.s) vm_next() } @@ -7130,8 +7146,8 @@ exports.view = function (state, role) { underground: game.underground, govt_control: game.govt_control, farc_control: game.farc_control, - support: game.support, farc_zones: game.farc_zones, + support: game.support, terror: game.terror, sabotage: game.sabotage, } |