diff options
author | Tor Andersson <tor@ccxvii.net> | 2021-06-18 12:05:48 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-02-18 12:12:42 +0100 |
commit | 6eb8fe0b485129f62d8006b1ea71117e716be6d2 (patch) | |
tree | a869f6fae6a33898abcaa8b961dc99c511bc6a82 | |
parent | 71acb4ba7c5e970c9a8fa4d9409c0d6ba57fd75d (diff) | |
download | shores-of-tripoli-6eb8fe0b485129f62d8006b1ea71117e716be6d2.tar.gz |
tripoli: Summarize naval battle losses.
-rw-r--r-- | rules.js | 44 |
1 files changed, 29 insertions, 15 deletions
@@ -270,22 +270,27 @@ function logp(...args) { game.log.push(game.active + " " + s); } -function flush_summary(text, nothing="none") { +function flush_summary(text, add_plural_s=false) { game.summary.sort(); let last = game.summary[0]; let n = 0; for (let entry of game.summary) { if (entry != last) { - text += "\n" + n + " " + last; + if (add_plural_s && n > 1) + text += "\n" + n + " " + last + "s"; + else + text += "\n" + n + " " + last; n = 0; } ++n; last = entry; } - if (n > 0) + if (add_plural_s && n > 1) + text += "\n" + n + " " + last + "s"; + else if (n > 0) text += "\n" + n + " " + last; else - text += "\n" + nothing; + text += "\n" + "none"; log(text); delete game.summary; } @@ -1217,6 +1222,7 @@ function goto_naval_battle_round() { log("United States scores " + game.n_tr_hits + (game.n_tr_hits == 1 ? " hit." : " hits.")); log("Tripolitania scores " + game.n_us_hits + (game.n_us_hits == 1 ? " hit." : " hits.")); + game.summary = []; if (game.save_active == US) goto_allocate_american_hits(); else @@ -1263,16 +1269,15 @@ states.allocate_us_hits = { --game.n_us_hits; if (US_FRIGATES.includes(p)) { if (game.damaged.includes(p)) { - log("American frigate sinks."); + game.summary.push("American frigate sunk"); game.location[p] = TRIPOLITAN_SUPPLY; remove_from_array(game.damaged, p); } else { - log("American frigate is damaged."); game.damaged.push(p); } } if (US_GUNBOATS.includes(p)) { - log("American gunboat sinks."); + game.summary.push("American gunboat"); move_one_piece(US_GUNBOATS, game.where, UNITED_STATES_SUPPLY); } }, @@ -1315,20 +1320,19 @@ states.allocate_tr_hits = { --game.n_tr_hits; if (TR_FRIGATES.includes(p)) { if (game.damaged.includes(p)) { - log("Tripolitan frigate sinks."); + game.summary.push("Tripolitan frigate sunk"); game.location[p] = TRIPOLITAN_SUPPLY; remove_from_array(game.damaged, p); } else { - log("Tripolitan frigate is damaged."); game.damaged.push(p); } } if (TR_CORSAIRS.includes(p)) { - log("Tripolitan corsair sinks."); + game.summary.push("Tripolitan corsair"); move_one_piece(TR_CORSAIRS, game.where, TRIPOLITAN_SUPPLY); } if (AL_CORSAIRS.includes(p)) { - log("Allied corsair sinks."); + game.summary.push("Allied corsair"); move_one_piece(AL_CORSAIRS, game.where, TRIPOLITAN_SUPPLY); } }, @@ -1351,18 +1355,26 @@ function move_damaged_frigate_to_year_track(p, supply) { } function remove_damaged_frigates() { - for (let p of US_FRIGATES) - if (game.damaged.includes(p)) + for (let p of US_FRIGATES) { + if (game.damaged.includes(p)) { + game.summary.push("American frigate"); move_damaged_frigate_to_year_track(p, UNITED_STATES_SUPPLY); - for (let p of TR_FRIGATES) - if (game.damaged.includes(p)) + } + } + for (let p of TR_FRIGATES) { + if (game.damaged.includes(p)) { + game.summary.push("Tripolitan frigate"); move_damaged_frigate_to_year_track(p, TRIPOLITAN_SUPPLY); + } + } } function resume_naval_battle() { delete game.the_guns_of_tripoli; delete game.prebles_boys_take_aim; + flush_summary("Ships sunk:", true) + if (game.active_card == ASSAULT_ON_TRIPOLI) { let n_tr = count_tripolitan_frigates(game.where) + count_tripolitan_corsairs(game.where); let n_us = count_american_frigates(game.where) + count_american_gunboats(game.where); @@ -1381,7 +1393,9 @@ function resume_naval_battle() { delete game.save_active; + game.summary = []; remove_damaged_frigates(); + flush_summary("Ships damaged:", true) move_all_pieces(US_FRIGATES, game.where, MALTA); move_all_pieces(US_GUNBOATS, game.where, MALTA); |