X-Git-Url: https://git.yukkurigames.com/?p=heroik.git;a=blobdiff_plain;f=scenarios.js;h=12bfa3e857c16bd2559200fbb1d6357711478ad8;hp=035d492262e2947eb0e0a7c266069c1106547086;hb=80f79d9125ef2ed4a368ce3a17f7dd81ba95bd30;hpb=5b2feaf09e2767f845af03d74e13cebfe8b61baa diff --git a/scenarios.js b/scenarios.js index 035d492..12bfa3e 100644 --- a/scenarios.js +++ b/scenarios.js @@ -85,16 +85,17 @@ var EVENTS = [ { name: "Psi assault.", effect: "You cannot use ultimate powers.", + lock: ["ultimates"], unique: true }, -/* TODO: Figure out how to implement this well. { name: "Entering an anti-magic zone.", effect: "You cannot use ultimate powers.", - unique: true, + lock: ["ultimates"], duration: 3, later: { name: "Leaving the anti-magic zone.", - effect: "You may use ultimate powers again." } + effect: "You may use ultimate powers again.", + clear: ["ultimates"] } }, -*/ + // Events from Sean Allen's random scenario generator. // http://boardgamegeek.com/filepage/57107/random-scenario-generator { name: "Fire from above.", @@ -150,7 +151,7 @@ var EVENTS = [ unique: true }, { name: "Infighting.", effect: "Greenskins have Undead +1, Demons -1. Demons have Greenskins +1, Undead -1. Undead have Demons +1, Greenskins -1.", - requires: ["noncanonical"], + requires: ["noncanonical", "demons", "undead"], unique: true }, { name: "New moon.", effect: "Demons have Veil of Shadow.", @@ -181,11 +182,15 @@ var EVENTS = [ var NOP = [ { name: "Nothing happens." }, { name: "A draft blows down the hallway.", - requires: ["noncanonical"] }, + unique: true, requires: ["noncanonical"] }, { name: "You sneeze.", - requires: ["noncanonical"] }, + unique: true, requires: ["noncanonical"] }, { name: "There's a skittering in the distance.", - requires: ["noncanonical"] }, + unique: true, requires: ["noncanonical"] }, + { name: "The torch flickers.", + unique: true, requires: ["noncanonical"] }, + { name: "Shadows dance across the walls.", + unique: true, requires: ["noncanonical"] }, ]; var HELPFUL = [ @@ -210,13 +215,34 @@ function generate (flags, events, nop) { var chosen = []; var i; + var pending = []; + var locks = []; + var event; + + function pend (event, i) { + while (pending[i]) ++i + pending[i] = event; + } + function canStillHappen (event) { return issubset(event.requires || [], flags) - && !(event.unique && contains.call(chosen, event)); + && !(event.unique && contains.call(chosen, event)) + && !(event.lock && intersects(event.lock || [], locks)); + } + + for (i = 0; i < events; ++i) { + event = pending.shift() + || choice(EVENTS.filter(canStillHappen)); + chosen.push(event); + if (event.later) + pend(event.later, (Math.random() * chosen[i].duration) | 0); + locks = locks.concat(event.lock || []) + .filter(not(contains), event.clear || []); } - for (i = 0; i < events; ++i) - chosen.push(choice(EVENTS.filter(canStillHappen))); + for (i = 0; i < pending.length; ++i) + if (pending[i]) + chosen.push(pending[i]); for (i = 0; i < nop / 2; ++i) {