diff options
Diffstat (limited to 'rules.ts')
-rw-r--r-- | rules.ts | 51 |
1 files changed, 26 insertions, 25 deletions
@@ -335,7 +335,7 @@ const engine_functions: Record<string, Function> = { start_year, resolve_fascist_test, resolve_final_bid, - log_trigger, + place_blank_marker, // Unique card effects card1_event2, card3_event2, @@ -652,6 +652,7 @@ export function setup(seed: number, _scenario: string, options: Record<string,bo [], ], triggered_track_effects: [], + untriggered_track_effects: [], log: [], undo: [], used_medallions: [], @@ -2066,7 +2067,7 @@ states.player_turn = { function remove_blank_marker(b: number) { 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}`); } @@ -3152,21 +3153,18 @@ function move_track_to(track_id: number, new_value: number) { 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) - ) + !game.triggered_track_effects.includes(blank) && + !game.untriggered_track_effects.includes(blank) ) { - if (space_id !== 0) { - game.triggered_track_effects.push( - get_blank_marker_id(track_id, space_id) - ); - } + 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])); } } }); @@ -3580,9 +3578,12 @@ function log_header(msg: string, prefix: string | number) { 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(); } @@ -3970,19 +3971,19 @@ function array_insert<T>(array: T[], index: number, item: T) { // return false; // } -// function set_add<T>(set: T[], item: T) { -// // eslint-disable-line @typescript-eslint/no-unused-vars -// 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_add<T>(set: T[], item: T) { + // eslint-disable-line @typescript-eslint/no-unused-vars + 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<T>(set: T[], item: T) { // let a = 0; |