summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-04-27 22:15:13 +0200
committerTor Andersson <tor@ccxvii.net>2023-07-07 18:39:23 +0200
commit18de9c65450661610d29f151e6ef31ab05905ac3 (patch)
tree1c029c5a21122d441e616b204a961431a6f6b319 /rules.js
parent390c2cda3e78be50b20d227348cce355e599db35 (diff)
downloadtime-of-crisis-18de9c65450661610d29f151e6ef31ab05905ac3.tar.gz
UI and piece layout.
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js213
1 files changed, 192 insertions, 21 deletions
diff --git a/rules.js b/rules.js
index 3562286..2ed6982 100644
--- a/rules.js
+++ b/rules.js
@@ -2,6 +2,67 @@
// === CONSTANTS AND DATA ===
+// Barbarian possible locations:
+/*
+FRANKS
+ BRITANNIA
+ GALLIA
+ HISPANIA
+ PANNONIA
+ ITALIA
+
+ALAMANNI
+ PANNONIA
+ ITALIA
+ THRACIA
+ MACEDONIA
+
+GOTHS
+ THRACIA
+ MACEDONIA
+ ASIA
+ GALATIA
+ SYRIA
+
+
+SASSANIDS
+ GALATIA
+ ASIA
+ SYRIA
+ AEGYPTUS
+
+NOMADS
+ AFRCIA
+ HISPANIA
+ AEGYPTUS
+ SYRIA
+
+NOMAD STACKS in PROVINCES
+ AEGYPTUS NOMADS
+ AEGYPTUS SASSANIDS
+ AFRICA NOMADS
+ ASIA GOTHS
+ ASIA SASSANIDS
+ BRITANNIA FRANKS
+ GALATIA GOTHS
+ GALATIA SASSANIDS
+ GALLIA FRANKS
+ HISPANIA FRANKS
+ HISPANIA NOMADS
+ ITALIA ALAMANNI
+ ITALIA FRANKS
+ MACEDONIA ALAMANNI
+ MACEDONIA GOTHS
+ PANNONIA ALAMANNI
+ PANNONIA FRANKS
+ SYRIA GOTHS
+ SYRIA NOMADS
+ SYRIA SASSANIDS
+ THRACIA ALAMANNI
+ THRACIA GOTHS
+*/
+
+
const P1 = "Red"
const P2 = "Blue"
const P3 = "Yellow"
@@ -39,6 +100,10 @@ const FRANKS_HOMELAND = 13
const GOTHS_HOMELAND = 14
const NOMADS_HOMELAND = 15
const SASSANIDS_HOMELAND = 16
+const MARE_OCCIDENTALE = 17
+const MARE_ORIENTALE = 18
+const OCEANUS_ATLANTICUS = 19
+const PONTUS_EUXINUS = 20
const ARMY = [
[ 100, 101, 102, 103, 104, 105 ],
@@ -230,12 +295,12 @@ function setup_market_pile(cards) {
}
function setup_barbarians(tribe) {
- for (let i = BARBARIAN_UNITS[0]; i <= BARBARIAN_UNITS[1]; ++i)
- game.barbarians[i] = BARBARIAN_HOMELAND[i]
+ for (let i = BARBARIAN_UNITS[tribe][0]; i <= BARBARIAN_UNITS[tribe][1]; ++i)
+ game.barbarians[i] = BARBARIAN_HOMELAND[tribe]
}
function remove_barbarians(tribe) {
- for (let i = BARBARIAN_UNITS[0]; i <= BARBARIAN_UNITS[1]; ++i)
+ for (let i = BARBARIAN_UNITS[tribe][0]; i <= BARBARIAN_UNITS[tribe][1]; ++i)
game.barbarians[i] = OFF_MAP
}
@@ -247,31 +312,41 @@ exports.setup = function (seed, scenario, options) {
log: [],
undo: [],
active: 0,
- state: "none",
- players: [],
- events: setup_events(),
+ state: "setup",
+ first: 0,
+ events: null,
active_events: [],
- has_militia: new Array(12).fill(0),
support: new Array(12).fill(1),
+ mobs: 0,
+ militia: 0,
+ quaestor: 0,
legions: new Array(33).fill(OFF_MAP),
is_legion_reduced: new Array(33).fill(0),
barbarians: new Array(50).fill(OFF_MAP),
- is_barbarian_inactive: new Array(50).fill(0),
+ is_barbarian_inactive: new Array(50).fill(1),
barbarian_leaders: [ OFF_MAP, OFF_MAP, OFF_MAP ],
rival_emperors: [ OFF_MAP, OFF_MAP, OFF_MAP ],
- market: [
- setup_market_pile(CARD_M2),
- setup_market_pile(CARD_S2),
- setup_market_pile(CARD_P2),
- setup_market_pile(CARD_M3),
- setup_market_pile(CARD_S3),
- setup_market_pile(CARD_P3),
- setup_market_pile(CARD_M4),
- setup_market_pile(CARD_S4),
- setup_market_pile(CARD_P4),
- ],
+ amphitheater: 0,
+ basilica: 0,
+ limes: 0,
+ dice: [ 0, 0, 0, 0 ], // first two are crisis table dice, second two are barbarian homeland dice
+ market: null,
+ players: [],
}
+ game.events = setup_events()
+ game.market = [
+ setup_market_pile(CARD_M2),
+ setup_market_pile(CARD_S2),
+ setup_market_pile(CARD_P2),
+ setup_market_pile(CARD_M3),
+ setup_market_pile(CARD_S3),
+ setup_market_pile(CARD_P3),
+ setup_market_pile(CARD_M4),
+ setup_market_pile(CARD_S4),
+ setup_market_pile(CARD_P4),
+ ]
+
setup_barbarians(ALAMANNI)
setup_barbarians(FRANKS)
setup_barbarians(GOTHS)
@@ -287,6 +362,8 @@ exports.setup = function (seed, scenario, options) {
discard: [],
generals: [ AVAILABLE, UNAVAILABLE, UNAVAILABLE, UNAVAILABLE, UNAVAILABLE, UNAVAILABLE ],
governors: [ AVAILABLE, UNAVAILABLE, UNAVAILABLE, UNAVAILABLE, UNAVAILABLE, UNAVAILABLE ],
+ capital: 0,
+ castra: 0,
}
}
@@ -314,6 +391,9 @@ exports.setup = function (seed, scenario, options) {
remove_barbarians(SASSANIDS)
}
+ game.first = game.active = random(player_count)
+ log(PLAYER_NAMES[game.first] + " is First Player!")
+
return save_game()
}
@@ -350,6 +430,34 @@ exports.view = function (state, player_name) {
log: game.log,
active: PLAYER_NAMES[game.active],
prompt: null,
+
+ militia: game.militia,
+ support: game.support,
+ quaestor: game.quaestor,
+ mobs: game.mobs,
+ legions: game.legions,
+ is_legion_reduced: game.is_legion_reduced,
+ barbarians: game.barbarians,
+ is_barbarian_inactive: game.is_barbarian_inactive,
+ barbarian_leaders: game.barbarian_leaders,
+ rival_emperors: game.rival_emperors,
+ amphitheater: game.amphitheater,
+ basilica: game.basilica,
+ limes: game.limes,
+ dice: game.dice,
+ market: game.market,
+ players: [],
+ }
+
+ for (let i = 0; i < game.players.length; ++i) {
+ view.players[i] = {
+ legacy: game.players[i].legacy,
+ emperor_turns: game.players[i].emperor_turns,
+ generals: game.players[i].generals,
+ governors: game.players[i].governors,
+ capital: game.players[i].capital,
+ castra: game.players[i].castra,
+ }
}
if (game.state === "game_over") {
@@ -358,6 +466,10 @@ exports.view = function (state, player_name) {
let inactive = states[game.state].inactive || game.state
view.prompt = `Waiting for ${PLAYER_NAMES[game.active]} \u2014 ${inactive}...`
} else {
+ view.hand = game.players[player].hand
+ view.draw = game.players[player].draw
+ view.discard = game.players[player].discard
+
view.actions = {}
states[game.state].prompt()
view.prompt = PLAYER_NAMES[game.active] + ": " + view.prompt
@@ -379,12 +491,71 @@ function log(msg) {
// === STATES ===
-states.none = {
- prompt() {}
+function get_governor(r) {
+ for (let p = 0; p < game.players.length; ++p) {
+ for (let i = 0; i < 6; ++i)
+ if (game.players[p].governors[i] === r)
+ return p
+ }
+ return -1
+}
+
+function is_neutral_province(r) {
+ return (game.support[r] !== NO_PLACE_GOVERNOR) && (get_governor(r) < 0)
+}
+
+function find_legion() {
+ for (let i = 0; i < 33; ++i)
+ if (game.legions[i] < 0)
+ return i
+ return -1
+}
+
+function add_militia(r) {
+ game.militia |= (1 << r)
+}
+
+function remove_militia(r) {
+ game.militia &= ~(1 << r)
+}
+
+function get_support(r) {
+ return game.support[r]
+}
+
+function set_support(r, level) {
+ game.support[r] = level
+}
+
+states.setup = {
+ prompt() {
+ view.prompt = "Select a starting Province."
+ for (let r = 1; r < 12; ++r)
+ if (is_neutral_province(r))
+ gen_action("capital", r)
+ },
+ capital(r) {
+ let p = game.active
+ game.players[p].generals[0] = r
+ game.players[p].governors[0] = r
+ game.players[p].capital = 1
+ game.legions[find_legion()] = ARMY[p][0]
+ add_militia(r)
+
+ game.active = (game.active + 1) % game.players.length
+ if (game.active === game.first)
+ goto_start_turn()
+ },
}
// === COMMON LIBRARY ===
+function gen_action(action, argument) {
+ if (!(action in view.actions))
+ view.actions[action] = []
+ set_add(view.actions[action], argument)
+}
+
function clear_undo() {
if (game.undo.length > 0)
game.undo = []