summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js36
1 files changed, 28 insertions, 8 deletions
diff --git a/rules.js b/rules.js
index d792ea0..3709972 100644
--- a/rules.js
+++ b/rules.js
@@ -206,7 +206,7 @@ const engine_functions = {
start_year,
resolve_fascist_test,
resolve_final_bid,
- log_trigger,
+ place_blank_marker,
card1_event2,
card3_event2,
card10_event2,
@@ -456,6 +456,7 @@ function setup(seed, _scenario, options) {
[],
],
triggered_track_effects: [],
+ untriggered_track_effects: [],
log: [],
undo: [],
used_medallions: [],
@@ -1692,7 +1693,7 @@ states.player_turn = {
function remove_blank_marker(b) {
const track_id = Math.floor(b / 11);
const space_id = b % 11;
- array_remove_item(game.triggered_track_effects, b);
+ set_delete(game.triggered_track_effects, b);
logi(`Removed Blank from ${get_track_name(track_id)} ${space_id}`);
}
states.remove_blank_marker = {
@@ -2573,15 +2574,16 @@ function move_track_to(track_id, new_value) {
: make_list(new_value, current_value - 1);
triggered_spaces.forEach((space_id) => {
const trigger = tracks[track_id].triggers[space_id];
+ const blank = get_blank_marker_id(track_id, space_id);
if (trigger !== null &&
- !game.triggered_track_effects.includes(get_blank_marker_id(track_id, space_id))) {
- if (space_id !== 0) {
- game.triggered_track_effects.push(get_blank_marker_id(track_id, space_id));
- }
+ !game.triggered_track_effects.includes(blank) &&
+ !game.untriggered_track_effects.includes(blank)) {
+ set_delete(game.triggered_track_effects, blank);
+ set_add(game.untriggered_track_effects, blank);
const node = resolve_effect(trigger, tracks[track_id].action);
if (node !== null) {
insert_after_active_node(node);
- insert_after_active_node(create_function_node('log_trigger', [track_id, space_id]));
+ insert_after_active_node(create_function_node('place_blank_marker', [track_id, space_id]));
}
}
});
@@ -2888,9 +2890,12 @@ function log_header(msg, prefix) {
log(`#${prefix} ${msg}`);
log_br();
}
-function log_trigger(args) {
+function place_blank_marker(args) {
let [track_id, space_id] = args;
+ let blank = get_blank_marker_id(track_id, space_id);
log(`Trigger ${get_track_name(track_id)} ${space_id}:`);
+ set_delete(game.untriggered_track_effects, blank);
+ set_add(game.triggered_track_effects, blank);
resolve_active_and_proceed();
}
function logi(msg) {
@@ -3190,6 +3195,21 @@ function array_insert(array, index, item) {
array[i] = array[i - 1];
array[index] = item;
}
+function set_add(set, item) {
+ let a = 0;
+ let b = set.length - 1;
+ while (a <= b) {
+ const m = (a + b) >> 1;
+ const x = set[m];
+ if (item < x)
+ b = m - 1;
+ else if (item > x)
+ a = m + 1;
+ else
+ return set;
+ }
+ return array_insert(set, a, item);
+}
function set_delete(set, item) {
let a = 0;
let b = set.length - 1;