summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2021-06-19 15:46:46 +0200
committerTor Andersson <tor@ccxvii.net>2023-02-18 12:12:42 +0100
commit14979ff33faefd644be51ca58d813c9049d7aa08 (patch)
tree11a20205628856a149fa5566e7662dd382e51d64
parentd70b3cdf98919c89f1ba481a700d79d84fe3c43d (diff)
downloadshores-of-tripoli-14979ff33faefd644be51ca58d813c9049d7aa08.tar.gz
tripoli: Auto-allocate and select battle when only one available.
Pause to show bombardment results.
-rw-r--r--rules.js57
1 files changed, 48 insertions, 9 deletions
diff --git a/rules.js b/rules.js
index f2c6bd7..69a507d 100644
--- a/rules.js
+++ b/rules.js
@@ -997,7 +997,10 @@ states.move_us_frigate_from = {
},
next: function () {
flush_summary("Frigates moved:");
- if (count_naval_battle_or_bombardment_locations() > 0)
+ let n = count_naval_battle_or_bombardment_locations();
+ if (n == 1)
+ auto_allocate_gunboats();
+ else if (n > 1)
goto_allocate_gunboats();
else
end_american_play();
@@ -1037,6 +1040,19 @@ states.move_us_frigate_to = {
undo: pop_undo
}
+function auto_allocate_gunboats() {
+ for (let space of BATTLE_SPACES) {
+ if (is_naval_battle_location(space)) {
+ move_all_pieces(US_GUNBOATS, MALTA, space);
+ return goto_naval_battle(space);
+ }
+ if (is_naval_bombardment_location(space)) {
+ move_all_pieces(US_GUNBOATS, MALTA, space);
+ return goto_naval_bombardment(space);
+ }
+ }
+}
+
function goto_allocate_gunboats() {
if (count_american_gunboats(MALTA) == 0)
return goto_select_battle();
@@ -1103,7 +1119,7 @@ states.select_battle = {
function goto_naval_bombardment(space) {
game.where = space;
naval_bombardment_round();
- end_naval_bombardment();
+ game.state = 'naval_bombardment_results';
}
function naval_bombardment_round() {
@@ -1118,11 +1134,25 @@ function naval_bombardment_round() {
if (n_hits > n_infantry)
n_hits = n_infantry;
log("Infantry eliminated: " + n_hits + ".");
+ game.flash = n_hits + " infantry eliminated."
for (let i = 0; i < n_hits; ++i)
move_one_piece(TR_INFANTRY, game.where, TRIPOLITAN_SUPPLY);
}
}
+states.naval_bombardment_results = {
+ prompt: function (view, current) {
+ view.prompt = "Naval Bombardment in " + SPACES[game.where] + " \u2014 " + game.flash;
+ if (is_inactive_player(current))
+ return;
+ gen_action(view, 'next');
+ },
+ next: function (card) {
+ delete game.flash;
+ end_naval_bombardment();
+ },
+}
+
function end_naval_bombardment() {
move_all_pieces(US_FRIGATES, game.where, MALTA);
move_all_pieces(US_GUNBOATS, game.where, MALTA);
@@ -1448,20 +1478,29 @@ states.land_battle_move_frigates = {
let n = count_american_frigates(game.where);
log(n + " American frigates move to " + SPACES[game.where] + ".");
move_all_pieces(US_GUNBOATS, MALTA, game.where);
- goto_land_battle();
+ naval_bombardment_round();
+ game.state = 'land_battle_bombardment_results';
},
undo: pop_undo
}
-function goto_land_battle() {
- naval_bombardment_round();
+states.land_battle_bombardment_results = {
+ prompt: function (view, current) {
+ view.prompt = "Naval Bombardment in " + SPACES[game.where] + " \u2014 " + game.flash;
+ if (is_inactive_player(current))
+ return;
+ gen_action(view, 'next');
+ },
+ next: function (card) {
+ delete game.flash;
- move_all_pieces(US_FRIGATES, game.where, MALTA);
- move_all_pieces(US_GUNBOATS, game.where, MALTA);
+ move_all_pieces(US_FRIGATES, game.where, MALTA);
+ move_all_pieces(US_GUNBOATS, game.where, MALTA);
- log("Land Battle in " + SPACES[game.where] + ".");
+ log("Land Battle in " + SPACES[game.where] + ".");
- goto_land_battle_american_card();
+ goto_land_battle_american_card();
+ },
}
function goto_land_battle_american_card() {