summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2021-06-22 15:07:03 +0200
committerTor Andersson <tor@ccxvii.net>2022-11-16 19:19:38 +0100
commit880049b3d4f7aa57e16633684f0a1f1519087339 (patch)
tree41e184322093e6caf27871a303be1e6294d927f3 /rules.js
parent602054c2e04379e2621d26e5eeb2c851d44e29f4 (diff)
downloadcrusader-rex-880049b3d4f7aa57e16633684f0a1f1519087339.tar.gz
crusader: Track castle owner reliably.
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js32
1 files changed, 13 insertions, 19 deletions
diff --git a/rules.js b/rules.js
index 3ae1924..66ca07e 100644
--- a/rules.js
+++ b/rules.js
@@ -1650,16 +1650,19 @@ function start_combat() {
if (!is_under_siege(game.where)) {
console.log("START SIEGE");
log("~ Combat Deployment ~");
- game.active = ENEMY[game.attacker[game.where]];
+ game.castle_owner = ENEMY[game.attacker[game.where]];
+ game.active = game.castle_owner;
game.state = 'combat_deployment';
} else {
- game.attacker[game.where] = besieging_player(game.where);
+ game.castle_owner = besieged_player(game.where);
+ game.attacker[game.where] = ENEMY[game.castle_owner];
console.log("CONTINUE SIEGE");
log("Existing siege continues.");
next_combat_round();
}
} else {
console.log("START NON-SIEGE");
+ game.castle_owner = null;
next_combat_round();
}
}
@@ -1672,6 +1675,7 @@ function end_combat() {
if (game.jihad == game.where)
game.jihad = null;
+ delete game.castle_owner;
delete game.storming;
delete game.sallying;
game.where = null;
@@ -2181,17 +2185,11 @@ states.field_battle = {
gen_action(view, 'battle_harry', b);
}
- // Defender refused siege, but can still withdraw into castle if friendly.
- if (game.active != game.attacker[game.where]) {
- if (game.sallying.length == 0) {
- let n = count_blocks_in_castle(game.where);
- if (n == 0) {
- gen_action(view, 'battle_withdraw', b);
- } else if (n < castle_limit(game.where)) {
- if (game.active == besieged_player(game.where))
- gen_action(view, 'battle_withdraw', b);
- }
- }
+ // Defender can withdraw into castle if friendly and there is room.
+ if (game.active != game.attacker[game.where] && game.active == game.castle_owner) {
+ // TODO: allow swapping place of sallying block, leaving it to die if it cannot withdraw?
+ if (game.sallying.length + count_blocks_in_castle(game.where) < castle_limit(game.where))
+ gen_action(view, 'battle_withdraw', b);
}
}
// All Frank B blocks are knights who can Charge
@@ -2646,15 +2644,11 @@ function compare_block_initiative(a, b) {
}
function make_battle_view() {
- let castle_owner = besieged_player(game.where);
- if (!castle_owner)
- castle_owner = ENEMY[game.attacker[game.where]];
-
let battle = {
FR: [], FC: [], FF: [],
SR: [], SC: [], SF: [],
- FCS: (castle_owner == FRANKS) ? castle_limit(game.where) : 0,
- SCS: (castle_owner == SARACENS) ? castle_limit(game.where) : 0,
+ FCS: (game.castle_owner == FRANKS) ? castle_limit(game.where) : 0,
+ SCS: (game.castle_owner == SARACENS) ? castle_limit(game.where) : 0,
storming: game.storming,
sallying: game.sallying,
halfhit: game.halfhit,