summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-06-26 01:06:20 +0200
committerTor Andersson <tor@ccxvii.net>2023-07-07 19:05:52 +0200
commit3ec19c1c349ed7fb81bca5f1d1a02c532eb2e81b (patch)
treee882d3894b0033a7fe1d8996193e34310eb16501
parentd91729e13fd3081907bf38b5a6823aab161c6509 (diff)
downloadtime-of-crisis-3ec19c1c349ed7fb81bca5f1d1a02c532eb2e81b.tar.gz
Combine crisis + dice array. Split IP array.
-rw-r--r--play.css25
-rw-r--r--play.js11
-rw-r--r--rules.js158
3 files changed, 96 insertions, 98 deletions
diff --git a/play.css b/play.css
index 03453d0..9350ba0 100644
--- a/play.css
+++ b/play.css
@@ -495,7 +495,7 @@ body.shift #zenobia { background-image: url(images/rival_back.png) }
background-size: 250px 350px;
background-repeat: no-repeat;
border-radius: 16px;
- box-shadow: 0 0 4px #000;
+ box-shadow: 0 0 0px 1px #444, 0 0 4px #000;
}
.card.event.event_0 { background-color: #b73c26 }
@@ -505,23 +505,24 @@ body.shift #zenobia { background-image: url(images/rival_back.png) }
.card.action {
transition: transform 100ms ease;
- box-shadow: 0 0 0px 3px #fff;
transform: translate(0px, 0px);
+ box-shadow: 0 0 0px 1px #444, 0 0 0px 4px white;
}
-#played .influence_m1, #played .influence_s1, #played .influence_p1, .card.used {
- filter: brightness(75%)
+#discard .card.action {
+ box-shadow: 0 0 0px 1px #444, 0 0 0px 3px red;
}
-#played { background-image: repeating-linear-gradient(45deg, #555, #555 40px, #444 40px, #444 80px) }
-#market { background-image: repeating-linear-gradient(135deg, darkgray, darkgray 60px, gray 60px, gray 120px) }
-
-#discard .card.action {
- box-shadow: 0 0 0px 3px #a00;
+#market .card.action {
+ box-shadow: 0 0 0px 1px #444, 0 0 0px 3px gold;
}
.card.action:hover {
- transform: translate(0px, -12px);
+ transform: translate(0px, -6px);
+}
+
+#played .influence_m1, #played .influence_s1, #played .influence_p1, .card.used {
+ filter: brightness(75%)
}
#hand, #draw, #discard {
@@ -637,6 +638,10 @@ body.shift #zenobia { background-image: url(images/rival_back.png) }
min-height: 350px;
}
+#market {
+ background-image: repeating-linear-gradient(135deg, #555555, #555555 60px, #505050 60px, #505050 120px);
+}
+
/* COMBAT MASK */
#combat_mask {
diff --git a/play.js b/play.js
index cf7d345..20f7187 100644
--- a/play.js
+++ b/play.js
@@ -1376,12 +1376,11 @@ function on_update() {
ui.body.classList.toggle("senate", view.color === 1)
ui.body.classList.toggle("populace", view.color === 2)
- ui.dice[0].className = "dice black d" + view.dice[0]
- ui.dice[1].className = "dice white d" + view.dice[1]
-
- ui.dice[2].className = "dice black d" + view.dice[2]
- ui.dice[3].className = "dice white d" + view.dice[3]
- layout_barbarian_dice(ui.dice[2], ui.dice[3], view.crisis)
+ layout_barbarian_dice(ui.dice[2], ui.dice[3], view.crisis[0])
+ ui.dice[0].className = "dice black d" + view.crisis[1]
+ ui.dice[1].className = "dice white d" + view.crisis[2]
+ ui.dice[2].className = "dice black d" + view.crisis[3]
+ ui.dice[3].className = "dice white d" + view.crisis[4]
ui.active_event.replaceChildren()
ui.active_event.appendChild(ui.event_cards[view.event])
diff --git a/rules.js b/rules.js
index afce366..2c06cc5 100644
--- a/rules.js
+++ b/rules.js
@@ -6,12 +6,8 @@ TODO
striped backgorund for "Played" when not your turn
-action bar icons for mip/sip/pip
-
hover over event card name for popup
-combine - mip/sip/pip/pp
-combine dice/crisis
combine flags
[ ] combat battle screen - splay stack / dialog for watching contents and taking hits
@@ -429,7 +425,12 @@ function play_card_event(c) {
function add_card_ip(c) {
let value = CARD_INFO[CARD_INDEX[c]].value
let type = CARD_INFO[CARD_INDEX[c]].type
- game.ip[type] += value
+ if (type === MILITARY)
+ game.mip += value
+ else if (type === SENATE)
+ game.sip += value
+ else if (type === POPULACE)
+ game.pip += value
}
function is_region(where) {
@@ -803,15 +804,15 @@ function has_available_governor() {
}
function spend_military(n) {
- game.ip[MILITARY] -= n
+ game.mip -= n
}
function spend_senate(n) {
- game.ip[SENATE] -= n
+ game.sip -= n
}
function spend_populace(n) {
- game.ip[POPULACE] -= n
+ game.pip -= n
}
function can_place_governor(where) {
@@ -1200,27 +1201,27 @@ function goto_upkeep() {
// === CRISIS ===
function goto_crisis() {
- game.crisis = -1
- game.dice[0] = roll_die()
- game.dice[1] = roll_die()
- game.dice[2] = 0
- game.dice[3] = 0
+ game.crisis[0] = -1
+ game.crisis[1] = roll_die()
+ game.crisis[2] = roll_die()
+ game.crisis[3] = 0
+ game.crisis[4] = 0
+
+ let sum = game.crisis[1] + game.crisis[2]
- let sum = game.dice[0] + game.dice[1]
- let msg = "Crisis B" + game.dice[0] + " W" + game.dice[1]
+ log("Crisis B" + game.crisis[1] + " W" + game.crisis[2])
if (sum === 2) {
- log(msg + " - Ira Deorum")
+ logi("Ira Deorum")
return goto_ira_deorum()
}
if (sum === 12) {
- log(msg + " - Pax Deorum")
+ logi("Pax Deorum")
return goto_pax_deorum()
}
if (sum === 7) {
- log(msg + " - Event")
return goto_crisis_event()
}
@@ -1232,7 +1233,6 @@ function goto_crisis() {
else
tribe = CRISIS_TABLE_4P[sum - 2]
- log(msg)
goto_barbarian_crisis(tribe)
}
@@ -1320,7 +1320,7 @@ states.pax_deorum_done = {
// CRISIS: BARBARIAN INVASION
function goto_barbarian_crisis(tribe) {
- game.crisis = tribe
+ game.crisis[0] = tribe
if (find_inactive_barbarian_at_home(tribe) >= 0)
game.state = "barbarian_crisis"
else
@@ -1328,24 +1328,24 @@ function goto_barbarian_crisis(tribe) {
}
states.barbarian_crisis = {
- get inactive() { return BARBARIAN_NAME[game.crisis] },
+ get inactive() { return BARBARIAN_NAME[game.crisis[0]] },
prompt() {
- let tribe = game.crisis
+ let tribe = game.crisis[0]
prompt(BARBARIAN_NAME[tribe] + ": Activate one barbarian.")
gen_action_barbarian(find_inactive_barbarian_at_home(tribe))
},
barbarian(id) {
- let tribe = game.crisis
+ let tribe = game.crisis[0]
set_barbarian_active(id)
roll_barbarian_crisis()
},
}
function roll_barbarian_crisis() {
- let tribe = game.crisis
+ let tribe = game.crisis[0]
- let black = game.dice[2] = roll_die()
- let white = game.dice[3] = roll_die()
+ let black = game.crisis[3] = roll_die()
+ let white = game.crisis[4] = roll_die()
logi(BARBARIAN_NAME[tribe] + " B" + black + " W" + white)
@@ -1378,9 +1378,9 @@ function goto_barbarian_invasion(tribe, black) {
}
states.barbarian_invasion = {
- get inactive() { return BARBARIAN_NAME[game.crisis] },
+ get inactive() { return BARBARIAN_NAME[game.crisis[0]] },
prompt() {
- let tribe = game.crisis
+ let tribe = game.crisis[0]
prompt(BARBARIAN_NAME[tribe] + " invade!")
gen_action_barbarian(find_active_barbarian_at_home(tribe))
},
@@ -1391,8 +1391,8 @@ states.barbarian_invasion = {
}
function invade_with_barbarian(id) {
- let tribe = game.crisis
- let white = game.dice[3]
+ let tribe = game.crisis[0]
+ let white = game.crisis[4]
let path = null
for (let list of BARBARIAN_INVASION[tribe])
@@ -1617,7 +1617,7 @@ states.ludi_saeculares_done = {
function goto_take_actions() {
log_br()
game.state = "take_actions"
- game.ip = [ 0, 0, 0 ]
+ game.mip = game.sip = game.pip = 0
game.played = []
game.used = []
@@ -1628,18 +1628,16 @@ function goto_take_actions() {
states.take_actions = {
get inactive() {
- let [ mip, sip, pip ] = game.ip
- return `Take Actions \u2013 ${mip} military, ${sip} senate, ${pip} populace`
+ return `Take Actions \u2013 ${game.mip} military, ${game.sip} senate, ${game.pip} populace`
},
prompt() {
- let [ mip, sip, pip ] = game.ip
let hand = current_hand()
- prompt(`Take Actions: ${mip} military, ${sip} senate, ${pip} populace.`)
+ prompt(`Take Actions: ${game.mip} military, ${game.sip} senate, ${game.pip} populace.`)
let where = UNAVAILABLE
- if (game.selected_governor < 0 && game.selected_general < 0 && hand.length > 0 && mip + sip + pip === 0)
+ if (game.selected_governor < 0 && game.selected_general < 0 && hand.length > 0 && game.mip + game.sip + game.pip === 0)
view.actions.play_all = 1
view.actions.end_actions = 1
@@ -1676,16 +1674,16 @@ states.take_actions = {
if (id !== game.selected_governor) {
switch (get_governor_location(id)) {
case UNAVAILABLE:
- if (sip >= i)
+ if (game.sip >= i)
gen_action_governor(id)
break
case AVAILABLE:
- if (sip >= 1)
+ if (game.sip >= 1)
gen_action_governor(id)
break
default:
// TODO: can_select_governor (check possible actions)
- if (sip >= 2 || pip >= 2)
+ if (game.sip >= 2 || game.pip >= 2)
gen_action_governor(id)
break
}
@@ -1694,7 +1692,7 @@ states.take_actions = {
// Select Militia (if can Disperse Mobs or Initiate Battle)
let loc = get_governor_location(id)
if (is_province(loc) && has_lone_militia(loc) && loc !== game.selected_militia) {
- if (mip >= 1 && (get_mobs(loc)) || can_militia_initiate_battle(loc))
+ if (game.mip >= 1 && (get_mobs(loc)) || can_militia_initiate_battle(loc))
gen_action_militia(loc)
}
}
@@ -1705,16 +1703,16 @@ states.take_actions = {
if (id !== game.selected_general) {
switch (get_general_location(id)) {
case UNAVAILABLE:
- if (mip >= i)
+ if (game.mip >= i)
gen_action_general(id)
break
case AVAILABLE:
- if (mip >= 1)
+ if (game.mip >= 1)
gen_action_general(id)
break
default:
// TODO: can_select_general (check possible actions)
- if (mip >= 1)
+ if (game.mip >= 1)
gen_action_general(id)
break
}
@@ -1724,26 +1722,26 @@ states.take_actions = {
// Recruit Governor
if (game.selected_governor >= 0 && where === UNAVAILABLE) {
view.actions.recruit_governor = 0
- if (sip >= game.selected_governor % 6)
+ if (game.sip >= game.selected_governor % 6)
view.actions.recruit_governor = 1
}
// Recruit General
if (game.selected_general >= 0 && where === UNAVAILABLE) {
view.actions.recruit_general = 0
- if (mip >= game.selected_general % 6)
+ if (game.mip >= game.selected_general % 6)
view.actions.recruit_general = 1
}
// Place Governor
if (game.selected_governor >= 0 && where === AVAILABLE) {
- if (sip >= 1)
+ if (game.sip >= 1)
gen_place_governor()
}
// Create Army
if (game.selected_general >= 0 && where === AVAILABLE) {
- if (mip >= 1 && find_unused_legion() >= 0)
+ if (game.mip >= 1 && find_unused_legion() >= 0)
gen_create_army()
}
@@ -1754,31 +1752,31 @@ states.take_actions = {
view.actions.build_improvement = 0
// Recall Governor
- if (sip >= 2)
+ if (game.sip >= 2)
view.actions.recall_governor = 1
// Increase Support Level
let support = get_support(where)
if (where !== ITALIA && support < 4) {
- if (pip > support)
+ if (game.pip > support)
gen_action_support(where, support + 1)
}
// Place Militia
if (!has_militia(where) && is_capital_free_of_enemy(where)) {
- if (pip >= 2)
+ if (game.pip >= 2)
view.actions.place_militia = 1
}
// Hold Games
if (get_mobs(where)) {
- if (pip >= 2)
+ if (game.pip >= 2)
view.actions.hold_games = 1
}
// Build an Improvement
if (can_build_improvement(where))
- if (pip >= get_improvement_cost())
+ if (game.pip >= get_improvement_cost())
view.actions.build_improvement = 1
}
@@ -1790,20 +1788,20 @@ states.take_actions = {
// Disperse Mob
if (get_mobs(where) && is_own_province(where)) {
- if (mip >= 1)
+ if (game.mip >= 1)
view.actions.disperse_mob = 1
}
// Train Legions
if (has_reduced_legions_in_army(game.selected_general)) {
- if (mip >= 1)
+ if (game.mip >= 1)
view.actions.train_legions = 1
}
// Add Legion to Army
if (is_own_province(where)) {
let cost = count_legions_in_army(game.selected_general) + 1
- if (mip >= cost)
+ if (game.mip >= cost)
view.actions.add_legion_to_army = 1
}
@@ -1829,7 +1827,7 @@ states.take_actions = {
// Militia Actions
if (game.selected_militia >= 0) {
view.actions.disperse_mob = 0
- if (mip >= 1)
+ if (game.mip >= 1)
view.actions.disperse_mob = 1
// Initiate Battle with Militia not stacked with General
@@ -2170,7 +2168,6 @@ function calc_needed_votes(where, pg) {
states.place_governor = {
inactive: "Place Governor",
prompt() {
- let sip = game.ip[SENATE]
let need = calc_needed_votes(game.where, false)
let votes = game.count
if (game.where === ITALIA)
@@ -2178,8 +2175,8 @@ states.place_governor = {
view.color = SENATE
view.selected_region = game.where
view.selected_governor = game.selected_governor
- prompt(`Place Governor: ${sip} senate. Rolling ${votes} dice. ${need} votes needed.`)
- if (sip >= 1)
+ prompt(`Place Governor: ${game.sip} senate. Rolling ${votes} dice. ${need} votes needed.`)
+ if (game.sip >= 1)
view.actions.spend_senate = 1
else
view.actions.spend_senate = 0
@@ -2199,7 +2196,6 @@ states.place_governor = {
states.praetorian_guard = {
inactive: "Praetorian Guard",
prompt() {
- let mip = game.ip[MILITARY]
let need = calc_needed_votes(game.where, true)
let votes = game.count
if (game.where === ITALIA)
@@ -2207,8 +2203,8 @@ states.praetorian_guard = {
view.color = MILITARY
view.selected_region = game.where
view.selected_governor = game.selected_governor
- prompt(`Praetorian Guard: ${mip} Military. Rolling ${votes} dice. ${need} votes needed.`)
- if (mip >= 1)
+ prompt(`Praetorian Guard: ${game.mip} Military. Rolling ${votes} dice. ${need} votes needed.`)
+ if (game.mip >= 1)
view.actions.spend_military = 1
else
view.actions.spend_military = 0
@@ -2281,7 +2277,7 @@ function can_play_praetorian_guard() {
for (let i = 0; i < 6; ++i) {
let id = game.current * 6 + i
if (get_governor_location(id) === AVAILABLE)
- return game.ip[MILITARY] >= 1 && !is_emperor_player() && !has_placed_governor(ITALIA)
+ return game.mip >= 1 && !is_emperor_player() && !has_placed_governor(ITALIA)
}
return false
}
@@ -2412,15 +2408,14 @@ function create_army(where) {
// ACTION: MOVE ARMY
function gen_move_army() {
- let mip = game.ip[MILITARY]
let from = get_general_location(game.selected_general)
- if (mip >= 1) {
+ if (game.mip >= 1) {
for (let to of ADJACENT[from]) {
if (!is_sea(to)) {
gen_action_region(to)
if (can_enter_capital(to))
gen_action_capital(to)
- } else if (mip >= 2)
+ } else if (game.mip >= 2)
gen_action_region(to)
}
}
@@ -2429,8 +2424,7 @@ function gen_move_army() {
states.move_army_at_sea = {
inactive: "Move Army",
prompt() {
- let mip = game.ip[MILITARY]
- prompt("Move Army: " + mip + " Military.")
+ prompt("Move Army: " + game.mip + " Military.")
view.color = MILITARY
view.selected_general = game.selected_general
gen_move_army()
@@ -2961,7 +2955,7 @@ function goto_battle(type, where, attacker, target) {
}
function gen_initiate_battle(where) {
- if (game.ip[MILITARY] >= 1) {
+ if (game.mip >= 1) {
for_each_general((id, loc) => {
if (loc === where && is_enemy_general(id))
gen_action_general(id)
@@ -3422,7 +3416,7 @@ states.combat_victory = {
else if (de || game.battle.dtaken > game.battle.ataken)
prompt("Combat: You win the battle!")
else
- prompt("Combat: The defenders win the battle!")
+ prompt("Combat: Defenders win the battle!")
view.actions.done = 1
},
done() {
@@ -4157,23 +4151,23 @@ exports.setup = function (seed, scenario, options) {
active: 0,
current: 0,
state: "setup_province",
- first: 0,
- events: null,
- active_event: 0,
- ip: [],
- pp: 0,
selected_governor: -1,
selected_general: -1,
selected_militia: -1,
+ mip: 0,
+ sip: 0,
+ pip: 0,
+ pp: 0,
+ where: 0,
+ count: 0,
played: [],
used: [],
- killed: 0,
+
placed: 0,
battled: 0,
mbattled: 0,
- count: 0,
- where: 0,
+ killed: 0,
battle: null,
provinces: new Array(3 * player_count).fill(1),
@@ -4182,11 +4176,12 @@ exports.setup = function (seed, scenario, options) {
legions: new Array(LEGION_COUNT).fill(AVAILABLE),
barbarians: new Array(BARBARIAN_COUNT[player_count - 2]).fill(AVAILABLE),
- crisis: -1,
- dice: [ 0, 0, 0, 0 ], // first two are crisis table dice, second two are barbarian homeland dice
+ crisis: [ -1, 0, 0, 0, 0 ], // crisis tribe, 2x crisis dice, 2x barbarian dice
+ events: null,
+ active_event: 0,
market: null,
- // per-player data
+ first: 0,
legacy: new Array(player_count).fill(0),
emperor_turns: new Array(player_count).fill(0),
hand: [],
@@ -4278,7 +4273,6 @@ exports.view = function (state, player_name) {
first: game.first,
crisis: game.crisis,
- dice: game.dice,
event: game.active_event,
market: game.market.map(m => m[0] | 0),