summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-01-15 01:03:17 +0100
committerTor Andersson <tor@ccxvii.net>2023-02-18 11:54:52 +0100
commit63719ad9f9f394b2ab4130880330908747b17dbe (patch)
treed93d0f47cbb21e0dd7f7c6e84315d1152c0555a6
parent449a547bd178a7dfdcf7289d515619ee37faac93 (diff)
downloadwilderness-war-63719ad9f9f394b2ab4130880330908747b17dbe.tar.gz
Break siege. Manual retreat.
-rw-r--r--rules.js85
1 files changed, 52 insertions, 33 deletions
diff --git a/rules.js b/rules.js
index 4d8d0b3..02c72a3 100644
--- a/rules.js
+++ b/rules.js
@@ -2110,12 +2110,11 @@ console.log("GOTO_MOVE_PIECE", who);
resume_move();
}
-function goto_break_siege(who) {
+function goto_break_siege() {
+ console.log("GOTO_BREAK_SIEGE");
let here = moving_piece_space();
game.move.path = { [here]: here };
- // TODO: may defenders attempt to avoid battle when breaking out of siege?
- goto_battle_check();
- console.log("GOTO_BREAK_SIEGE", who);
+ goto_avoid_battle();
}
function may_naval_move(who) {
@@ -3166,7 +3165,6 @@ function determine_winner_battle() {
} else {
log("DEFENDER WON RAID BATTLE VS MILITIA");
retreat_attacker(game.raid.where, game.raid.from[game.raid.where] | 0);
- goto_pick_raid();
}
return;
}
@@ -3191,13 +3189,6 @@ function determine_winner_battle() {
let from = game.battle.where;
let to = moving_piece_came_from(game.battle.where);
retreat_attacker(from, to);
-
- // if raiders need to retreat again, they go back to this
- // space, unless they retreat to join other raiders
- if (!game.raid.from[to])
- game.raid.from[to] = from;
-
- end_retreat();
}
}
@@ -3254,31 +3245,59 @@ function can_attacker_retreat_from_to(p, from, to) {
function retreat_attacker(from, to) {
set_active(game.battle.attacker);
+ game.state = 'retreat_attacker';
+ game.retreat = { from, to };
+}
- // TODO: manual user to click on retreat location
-
- console.log("RETREAT ATTACKER", space_name(from), "to", space_name(to));
+states.retreat_attacker = {
+ prompt() {
+ let from = game.retreat.from;
+ let to = game.retreat.to;
+ if (from === to)
+ view.prompt = `Retreat losing leaders and units back into ${space_name(to)}.`;
+ else
+ view.prompt = `Retreat losing leaders and units from ${space_name(from)} to ${space_name(to)}.`;
+ view.where = from;
+ gen_action_space(to);
+ },
+ space(_) {
+ let from = game.retreat.from;
+ let to = game.retreat.to;
+ delete game.retreat;
+
+ console.log("RETREAT ATTACKER", space_name(from), "to", space_name(to));
+
+ // NOTE: Besieged pieces assaulting out are already inside so not affected by the code below.
+ // NOTE: We unstack forces here by retreating individual units before leaders!
+ for_each_friendly_unit_in_space(from, p => {
+ if (!is_piece_inside(p)) {
+ if (can_attacker_retreat_from_to(p, from, to))
+ move_piece_to(p, to);
+ else
+ eliminate_piece(p);
+ }
+ });
+ for_each_friendly_leader_in_space(from, p => {
+ if (!is_piece_inside(p)) {
+ if (can_attacker_retreat_from_to(p, from, to))
+ move_piece_to(p, to);
+ else
+ eliminate_piece(p);
+ }
+ });
- // NOTE: Besieged pieces assaulting out are already inside so not affected by the code below.
- // NOTE: We unstack forces here by retreating individual units before leaders!
- for_each_friendly_unit_in_space(from, p => {
- if (!is_piece_inside(p)) {
- if (can_attacker_retreat_from_to(p, from, to))
- move_piece_to(p, to);
- else
- eliminate_piece(p);
+ // Raid battle vs militia
+ if (game.raid && game.raid.where > 0) {
+ // if raiders need to retreat again, they go back to this
+ // space, unless they retreat to join other raiders
+ if (!game.raid.from[to])
+ game.raid.from[to] = from;
+ return goto_pick_raid();
}
- });
- for_each_friendly_leader_in_space(from, p => {
- if (!is_piece_inside(p)) {
- if (can_attacker_retreat_from_to(p, from, to))
- move_piece_to(p, to);
- else
- eliminate_piece(p);
- }
- });
- // TODO: lift siege if attack on enemy fort repulsed
+ // Normal battle
+ end_retreat();
+ }
}
function goto_retreat_defender() {