summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js101
1 files changed, 63 insertions, 38 deletions
diff --git a/rules.js b/rules.js
index 1925270..11614a2 100644
--- a/rules.js
+++ b/rules.js
@@ -65,11 +65,18 @@ function logbr() {
game.log.push("")
}
-function log(...args) {
- let s = Array.from(args).join("")
+function log(s) {
game.log.push(s)
}
+function logi(s) {
+ game.log.push(">" + s)
+}
+
+function logii(s) {
+ game.log.push(">>" + s)
+}
+
function log_battle(s) {
game.log.push(game.active[0] + ": " + s)
}
@@ -80,16 +87,16 @@ function logp(s) {
function log_move_start(from, to, mark = false) {
if (mark)
- game.turn_buf = [ space_name(from), space_name(to) + mark ]
+ game.turn_buf = [ from, to, mark ]
else
- game.turn_buf = [ space_name(from), space_name(to) ]
+ game.turn_buf = [ from, to ]
}
function log_move_continue(to, mark = false) {
if (mark)
- game.turn_buf.push(space_name(to) + mark)
+ game.turn_buf.push(to, mark)
else
- game.turn_buf.push(space_name(to))
+ game.turn_buf.push(to)
}
function log_move_end() {
@@ -100,30 +107,42 @@ function log_move_end() {
}
function log_levy(where) {
- game.turn_log.push([space_name(where)])
+ game.turn_log.push([where])
}
function print_turn_log_no_active(text) {
- function print_move(last) {
- return "\n" + n + " " + last.join(" \u2192 ")
- }
- game.turn_log.sort()
- let last = game.turn_log[0]
+ let lines = game.turn_log.map(function (move) {
+ let s = ""
+ for (let i = 0; i < move.length; ++i) {
+ let x = move[i]
+ if (typeof x === 'string') {
+ s += x
+ } else {
+ if (i > 0)
+ s += " \u2192 "
+ s += "#" + x
+ }
+ }
+ return s
+ }).sort()
+ delete game.turn_log
+
+ log(text)
+
+ let last = lines[0]
let n = 0
- for (let entry of game.turn_log) {
- if (entry.toString() !== last.toString()) {
- text += print_move(last)
+ for (let entry of lines) {
+ if (entry !== last) {
+ logi(n + " " + last)
n = 0
}
++n
last = entry
}
if (n > 0)
- text += print_move(last)
+ logi(n + " " + last)
else
- text += "\nnothing."
- log(text)
- delete game.turn_log
+ logi("nothing.")
}
function print_turn_log(verb) {
@@ -868,7 +887,7 @@ states.free_deployment_to = {
function start_year() {
logbr()
- log("Start Year " + game.year)
+ log(".h1 Year " + game.year)
game.turn = 1
let deck = reset_deck()
game.c_hand = deal_cards(deck, 6)
@@ -983,7 +1002,7 @@ function start_first_turn() {
game.moved = []
game.reserves = []
logbr()
- log("Start Turn " + game.turn + " of Year " + game.year)
+ log(".h2 Turn " + game.turn + " of Year " + game.year)
reveal_cards()
}
@@ -1002,7 +1021,7 @@ function start_turn() {
game.show_cards = false
game.surprise = 0
logbr()
- log("Start Turn " + game.turn + " of Year " + game.year)
+ log(".h2 Turn " + game.turn + " of Year " + game.year)
}
function resume_play_card() {
@@ -1135,7 +1154,7 @@ function reveal_cards() {
function start_player_turn() {
logbr()
- log("Start " + game.active)
+ log(".h3 " + game.active)
reset_road_limits()
game.activated = []
@@ -1259,8 +1278,8 @@ states.jupiter_to = {
gen_action_space(view, to)
},
space: function (to) {
- log(block_name(game.who) + " joined " + game.active + ":\n" +
- game.location[game.who] + " \u2192 " + space_name(to) + ".")
+ log(block_name(game.who) + " joined " + game.active + ":")
+ logi("#"+game.location[game.who] + " \u2192 #" + to + ".")
game.location[game.who] = to
game.who = -1
end_player_turn()
@@ -1277,7 +1296,7 @@ states.vulcan = {
gen_action_space(view, s)
},
space: function (city) {
- log("Vulcan struck " + space_name(city) + "!")
+ log("Vulcan struck #" + city + "!")
if (game.automatic_disruption) {
for (let b = 0; b < block_count; ++b)
if (game.location[b] === city)
@@ -1332,7 +1351,7 @@ function goto_mars_and_neptune() {
}
if (game.surprise_list.length === 1) {
game.surprise = game.surprise_list[0]
- log("Surprise attack in " + space_name(game.surprise) + ".")
+ log("Surprise attack in #" + game.surprise + ".")
delete game.surprise_list
return end_player_turn()
}
@@ -1350,7 +1369,7 @@ states.mars_and_neptune = {
},
space: function (where) {
game.surprise = where
- log("Surprise attack in " + space_name(game.surprise) + ".")
+ log("Surprise attack in #" + game.surprise + ".")
delete game.surprise_list
end_player_turn()
},
@@ -1480,7 +1499,7 @@ states.move_where = {
}
} else {
if (!game.activated.includes(from)) {
- logp("activated " + space_name(from) + ".")
+ logp("activated #" + from + ".")
game.moves --
game.activated.push(from)
}
@@ -1570,7 +1589,7 @@ states.mercury_move_1 = {
space: function (to) {
let from = game.location[game.who]
if (!game.activated.includes(from)) {
- logp("activated " + space_name(from) + ".")
+ logp("activated #" + from + ".")
game.moves --
game.activated.push(from)
}
@@ -1801,7 +1820,7 @@ function start_battle() {
game.battle_round = 0
game.flash = ""
logbr()
- log("Battle in " + space_name(game.where))
+ log(".h4 Battle in #" + game.where)
if (game.surprise === game.where)
log("Surprise attack.")
game.state = 'battle_round'
@@ -1854,7 +1873,7 @@ function end_disrupt_reserves() {
game.flash = ""
delete game.disrupted
bring_on_reserves()
- log("~ Battle Round " + game.battle_round + " ~")
+ log(".h5 Battle Round " + game.battle_round)
pump_battle_round()
}
@@ -1876,7 +1895,7 @@ states.disrupt_reserves = {
function start_battle_round() {
if (++game.battle_round <= 4) {
if (game.turn_log && game.turn_log.length > 0)
- print_turn_log_no_active("Retreated from " + game.where + ":")
+ print_turn_log_no_active("Retreated from #" + game.where + ":")
game.turn_log = []
reset_road_limits()
@@ -1899,7 +1918,7 @@ function start_battle_round() {
bring_on_reserves()
}
- log("~ Battle Round " + game.battle_round + " ~")
+ log(".h5 Battle Round " + game.battle_round)
pump_battle_round()
} else {
@@ -1965,7 +1984,7 @@ function pump_battle_round() {
function end_battle() {
if (game.turn_log && game.turn_log.length > 0)
- print_turn_log_no_active("Retreated from " + game.where + ":")
+ print_turn_log_no_active("Retreated from #" + game.where + ":")
if (game.surprise === game.where)
game.surprise = 0
game.flash = ""
@@ -2254,7 +2273,7 @@ function goto_regroup() {
game.active = get_attacker(game.where)
if (is_enemy_space(game.where))
game.active = enemy(game.active)
- log(game.active + " won the battle in " + space_name(game.where) + "!")
+ log(game.active + " won the battle in #" + game.where + "!")
game.state = 'regroup'
game.turn_log = []
clear_undo()
@@ -2355,7 +2374,7 @@ function check_victory() {
end_game()
} else {
logbr()
- log("Start Winter Turn of Year " + game.year)
+ log(".h2 Winter Turn of Year " + game.year)
logbr()
start_navis_to_port()
}
@@ -2587,8 +2606,14 @@ exports.setup = function (seed, scenario, options) {
if (options.rng)
game.rng = options.rng
+ if (scenario === "Historical")
+ log(".h1 Historical Deployment")
+ else
+ log(".h1 " + scenario)
+ logbr()
+
if (options.tournament) {
- log("Tournament rule:\nCaesar is the first player on the very first turn of the game.")
+ log("Tournament rule: Caesar is the first player on the very first turn of the game.")
game.tournament = 1
}