From d195265a93d05a8466355c54ac4d211714d75014 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 15 Apr 2023 00:01:18 +0200 Subject: Automate shaded event 64. --- events.txt | 22 ++++++++++++++-------- rules.js | 8 ++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/events.txt b/events.txt index f5efe07..44a3fbb 100644 --- a/events.txt +++ b/events.txt @@ -1046,14 +1046,20 @@ EVENT 64 endrepeat SHADED 64 - prompt "Cartels Resources +2 for each Cartels Base in a City." - piece all is_cartels_base(p) && is_city(s) - auto_resources CARTELS 2 - endpiece - prompt "Cartels Resources +1 for each Cartels Base in a Department." - piece all is_cartels_base(p) && is_dept(s) - auto_resources CARTELS 1 - endpiece + if AUTOMATIC + asm game.vm.n = count_matching_pieces((p,s) => is_cartels_base(p) && is_city(s)) * 2 + asm game.vm.n += count_matching_pieces((p,s) => is_cartels_base(p) && is_dept(s)) + resources CARTELS (game.vm.n) + else + prompt "Cartels Resources +2 for each Cartels Base in a City." + piece all is_cartels_base(p) && is_city(s) + auto_resources CARTELS 2 + endpiece + prompt "Cartels Resources +1 for each Cartels Base in a Department." + piece all is_cartels_base(p) && is_dept(s) + auto_resources CARTELS 1 + endpiece + endif EVENT 65 # 5.1.3 - do both shipment and base if possible diff --git a/rules.js b/rules.js index ffda1b4..e46a1e5 100644 --- a/rules.js +++ b/rules.js @@ -631,6 +631,14 @@ function count_matching_spaces(f) { return n } +function count_matching_pieces(f) { + let n = 0 + for (let p = all_first_piece; p <= all_last_piece; ++p) + if (f(p, piece_space(p))) + ++n + return n +} + function count_faction_pieces(s, faction) { switch (faction) { case GOVT: -- cgit v1.2.3