summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-06-25 11:40:54 +0200
committerTor Andersson <tor@ccxvii.net>2023-07-07 19:05:52 +0200
commitd91729e13fd3081907bf38b5a6823aab161c6509 (patch)
tree5fd098cb0ea4db756a81110b57f851188b25c501 /rules.js
parent0648e171052fb2ecc6a9ee94b33dede1846dec99 (diff)
downloadtime-of-crisis-d91729e13fd3081907bf38b5a6823aab161c6509.tar.gz
Combat overlay to show battle lines expanded.
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js53
1 files changed, 45 insertions, 8 deletions
diff --git a/rules.js b/rules.js
index 2102329..afce366 100644
--- a/rules.js
+++ b/rules.js
@@ -2989,14 +2989,15 @@ function gen_initiate_battle(where) {
function format_battle_target() {
switch (game.battle.type) {
- case "militia": return "militia"
+ case "militia": return PLAYER_NAMES[get_province_player(game.battle.target)] + " militia"
case "barbarians": return BARBARIAN_NAME[game.battle.target]
- case "general": return GENERAL_NAME[game.battle.target]
+ case "general": return PLAYER_NAMES[game.battle.target / 6 | 0] + " army"
case "rival_emperor": return RIVAL_EMPEROR_NAME[game.battle.target]
}
}
states.battle = {
+ show_battle: true,
inactive: "Combat",
prompt() {
prompt("Initiate Battle against " + format_battle_target() + " in " + REGION_NAME[game.where] + ".")
@@ -3023,10 +3024,18 @@ states.battle = {
}
function format_hits() {
- return `${game.battle.ahits} hits to attacker vs ${game.battle.dhits} hits to defender`
+ let s = "Defender rolled " + game.battle.ahits + " hit"
+ if (game.battle.ahits !== 1)
+ s += "s"
+ s += ", attacker rolled " + game.battle.dhits + " hit"
+ if (game.battle.dhits !== 1)
+ s += "s"
+ return s
}
states.flanking_maneuver = {
+ show_battle: true,
+ get inactive() { return "Flanking Maneuver. " + format_hits() },
inactive: "Flanking Maneuver",
prompt() {
prompt("Flanking Maneuver: " + format_hits() + ".")
@@ -3299,13 +3308,14 @@ function goto_assign_hits_on_defender() {
if (has_hits_on_defender())
game.state = "assign_hits_on_defender"
else
- goto_combat_victory()
+ game.state = "combat_victory"
}
states.assign_hits_on_attacker = {
- inactive: "Combat",
+ show_battle: true,
+ get inactive() { return "Combat. " + format_hits() },
prompt() {
- prompt("Combat: " + format_hits() + " \u2013 assign " + (game.battle.ahits - game.battle.ataken) + " hits to attacker!")
+ prompt("Combat: " + format_hits() + ".")
if (game.battle.attacker < 0)
gen_hits_militia()
else
@@ -3332,9 +3342,10 @@ states.assign_hits_on_attacker = {
}
states.assign_hits_on_defender = {
- inactive: "Combat",
+ show_battle: true,
+ get inactive() { return "Combat. " + format_hits() },
prompt() {
- prompt("Combat: " + format_hits() + " \u2013 assign " + (game.battle.dhits - game.battle.dtaken) + " hits to defender!")
+ prompt("Combat: " + format_hits() + ".")
switch (game.battle.type) {
case "militia":
gen_hits_militia()
@@ -3400,6 +3411,25 @@ function is_defender_eliminated() {
return false
}
+states.combat_victory = {
+ show_battle: true,
+ inactive: "Combat",
+ prompt() {
+ let de = is_defender_eliminated()
+ let ae = is_attacker_eliminated()
+ if (de && ae)
+ prompt("Combat: There is no winner.")
+ else if (de || game.battle.dtaken > game.battle.ataken)
+ prompt("Combat: You win the battle!")
+ else
+ prompt("Combat: The defenders win the battle!")
+ view.actions.done = 1
+ },
+ done() {
+ goto_combat_victory()
+ },
+}
+
function goto_combat_victory() {
let de = is_defender_eliminated()
let ae = is_attacker_eliminated()
@@ -3489,6 +3519,7 @@ function end_battle() {
// Deselect eliminated general...
if (game.selected_general >= 0 && get_general_location(game.selected_general) === AVAILABLE)
game.selected_general = -1
+
if (game.battle.killed) {
if (can_free_increase_support_level(game.where)) {
game.state = "free_increase_support_level"
@@ -3498,6 +3529,7 @@ function end_battle() {
game.killed |= game.battle.killed
}
}
+
game.battle = null
game.state = "take_actions"
}
@@ -4257,6 +4289,11 @@ exports.view = function (state, player_name) {
emperor_turns: game.emperor_turns,
}
+ if (game.battle && states[game.state].show_battle) {
+ view.battle = game.battle
+ view.battle_region = game.where
+ }
+
if (game.state === "game_over") {
view.prompt = game.victory
} else if (game.current !== player) {