summaryrefslogtreecommitdiff
path: root/rules.ts
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-05-01 20:05:37 +0200
committerTor Andersson <tor@ccxvii.net>2024-05-01 20:05:37 +0200
commit8c7af923173b105e4664191afe84584d46bb56ce (patch)
treecfcc978b59549902788ca435fbd7d71663d5f29a /rules.ts
parent2ae260091bccf711b04694dd88cba672bafc6a95 (diff)
downloadplantagenet-8c7af923173b105e4664191afe84584d46bb56ce.tar.gz
test rout/unrout reroll
Diffstat (limited to 'rules.ts')
-rw-r--r--rules.ts77
1 files changed, 41 insertions, 36 deletions
diff --git a/rules.ts b/rules.ts
index 875de2b..aa45513 100644
--- a/rules.ts
+++ b/rules.ts
@@ -149,8 +149,9 @@ interface Battle {
target: Lord[] | null,
ahits: number,
dhits: number,
- culverins?: Lord[],
+ reroll: 0 | 1,
final_charge: 0 | 1,
+ culverins?: Lord[],
ravine?: Lord,
caltrops?: Lord,
force?: Force,
@@ -1617,6 +1618,10 @@ function rout_vassal(_lord: Lord, vassal: Vassal) {
set_add(game.battle.routed_vassals, vassal)
}
+function unrout_vassal(_lord: Lord, vassal: Vassal) {
+ set_delete(game.battle.routed_vassals, vassal)
+}
+
// === STATE: LOCALE ===
function is_friendly_locale(loc: Locale) {
@@ -5879,6 +5884,7 @@ function goto_battle() {
target: null,
ahits: 0,
dhits: 0,
+ reroll: 0,
final_charge: 0,
}
@@ -7349,9 +7355,16 @@ states.assign_hits = {
view.actions.regroup = 1
view.actions.done = 1
}
+
+ if (game.battle.reroll)
+ view.actions.valour = 1
},
retinue(lord) {
- if ((lord === LORD_MARGARET) && (lord_has_capability(lord, AOW_LANCASTER_YEOMEN_OF_THE_CROWN)) && get_lord_forces(lord, MEN_AT_ARMS) > 0)
+ if (
+ lord === LORD_MARGARET &&
+ lord_has_capability(lord, AOW_LANCASTER_YEOMEN_OF_THE_CROWN) &&
+ get_lord_forces(lord, MEN_AT_ARMS) > 0
+ )
action_assign_hits(lord, MEN_AT_ARMS)
else
action_assign_hits(lord, RETINUE)
@@ -7373,8 +7386,7 @@ states.assign_hits = {
action_assign_hits(lord, MILITIA)
},
vassal(vassal) {
- let lord = get_vassal_lord(vassal)
- action_assign_hits(lord, VASSAL, vassal)
+ action_assign_hits(get_vassal_lord(vassal), VASSAL, vassal)
},
regroup() {
push_undo()
@@ -7388,6 +7400,14 @@ states.assign_hits = {
else
end_defender_assign_hits()
},
+ valour() {
+ let protection = get_modified_protection(game.who, game.battle.force)
+ spend_valour(game.who)
+ game.battle.reroll = 0
+ logi(`Reroll:`)
+ if (!assign_hit_roll(get_force_name(game.who, game.battle.force, game.vassal), protection, ""))
+ unrout_unit(game.who, game.battle.force, game.vassal)
+ },
}
function rout_unit(lord: Lord, type: Force, v: Vassal = NOVASSAL) {
@@ -7408,6 +7428,15 @@ function rout_unit(lord: Lord, type: Force, v: Vassal = NOVASSAL) {
finish_action_assign_hits(lord)
}
+function unrout_unit(lord: Lord, type: Force, v: Vassal = NOVASSAL) {
+ if (type === VASSAL) {
+ unrout_vassal(lord, v)
+ } else {
+ add_lord_forces(lord, type, 1)
+ add_lord_routed_forces(lord, type, -1)
+ }
+}
+
function assign_hit_roll(what, prot, extra) {
let die = roll_die()
if (die <= prot) {
@@ -7489,18 +7518,21 @@ function action_assign_hits(lord: Lord, type: Force, v=NOVASSAL) {
let protection = get_modified_protection(lord, type)
let extra = ""
+ game.battle.reroll = 0
+ game.vassal = NOVASSAL
+
if (assign_hit_roll(get_force_name(lord, type, v), protection, extra)) {
if (get_lord_remaining_valour(lord) > 0) {
- game.state = "spend_valour"
+ game.battle.reroll = 1
game.battle.force = type
if (type === VASSAL)
game.vassal = v
- } else {
- rout_unit(lord, type, v)
}
- } else {
- finish_action_assign_hits(lord)
}
+
+ rout_unit(lord, type, v)
+
+ finish_action_assign_hits(lord)
}
function finish_action_assign_hits(lord: Lord) {
@@ -7519,33 +7551,6 @@ function finish_action_assign_hits(lord: Lord) {
goto_defender_assign_hits()
}
-states.spend_valour = {
- get inactive() {
- view.engaged = game.battle.engagements[0]
- return format_strike_step()
- },
- prompt() {
- view.prompt = `Spend Valour: Reroll hit on ${get_force_name(game.who, game.battle.force, game.vassal)}?`
- view.engaged = game.battle.engagements[0]
- view.actions.valour = 1
- view.actions.pass = 1
- },
- pass() {
- rout_unit(game.who, game.battle.force, game.vassal)
- },
- valour() {
- let protection = get_modified_protection(game.who, game.battle.force)
-
- spend_valour(game.who)
- log(`Reroll:`)
- if (assign_hit_roll(get_force_name(game.who, game.battle.force, game.vassal), protection, "")) {
- rout_unit(game.who, game.battle.force, game.vassal)
- } else {
- finish_action_assign_hits(game.who)
- }
- },
-}
-
// === 4.4.2 BATTLE ROUNDS: LORD ROUT ===
function rout_lord(lord: Lord) {