summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js72
1 files changed, 61 insertions, 11 deletions
diff --git a/rules.js b/rules.js
index a3daf79..aa2bd66 100644
--- a/rules.js
+++ b/rules.js
@@ -1,5 +1,9 @@
"use strict"
+// TODO: manual take hits?
+// TODO: manual "enter reserves" ?
+// TODO: manual "pursuit" ?
+
const data = require("./data.js")
const P1 = "First"
@@ -189,9 +193,9 @@ function add_cubes(c, n) {
map_set(game.cubes, c, Math.min(limit, old + n))
}
-function remove_cube(c) {
+function remove_cubes(c, n) {
let old = map_get(game.cubes, c, 0)
- map_set(game.cubes, c, Math.min(0, old - 1))
+ map_set(game.cubes, c, Math.min(0, old - n))
}
function add_sticks(c, n) {
@@ -210,9 +214,16 @@ function remove_dice(c) {
set_dice_location(i, POOL)
}
+function eliminate_card(c) {
+ remove_dice(c)
+ remove_cubes(c, 3)
+ array_remove_item(game.front[0], c)
+ array_remove_item(game.front[1], c)
+}
+
function pay_for_action(c) {
if (data.cards[c].special)
- remove_cube(c)
+ remove_cubes(c, 1)
else
remove_dice(c)
}
@@ -507,7 +518,7 @@ function check_all_3(c, x, y, z) {
function check_all_4(c, x, y, z, w) {
if (!can_place_value(c, x))
return false
- return pool_has_single(c, x) && pool_has_single(y) && pool_has_single(z) && pool_has_single(w)
+ return pool_has_single(x) && pool_has_single(y) && pool_has_single(z) && pool_has_single(w)
}
function check_straight_3(c) {
@@ -652,6 +663,7 @@ function goto_roll_phase() {
for (let i = 0; i < 6; ++i)
if (get_player_dice_location(p, i) < 0)
set_player_dice_value(p, i, 0)
+
game.state = "roll"
}
@@ -662,16 +674,18 @@ states.roll = {
},
roll() {
clear_undo()
-
- let p = player_index()
- for (let i = 0; i < 6; ++i)
- if (get_player_dice_location(p, i) < 0)
- set_player_dice_value(p, i, random(6) + 1)
-
- game.state = "place"
+ roll_dice_in_pool()
},
}
+function roll_dice_in_pool() {
+ let p = player_index()
+ for (let i = 0; i < 6; ++i)
+ if (get_player_dice_location(p, i) < 0)
+ set_player_dice_value(p, i, random(6) + 1)
+ game.state = "place"
+}
+
function gen_place_dice_select_card() {
let p = player_index()
for (let c of game.front[p]) {
@@ -887,6 +901,7 @@ states.action = {
prompt() {
view.prompt = "Take an action."
view.actions.pass = 1
+ view.actions.roll = 1
let p = player_index()
for (let c of game.front[p]) {
@@ -914,6 +929,12 @@ states.action = {
}
}
},
+ retire(c) {
+ push_undo()
+ log(card_name(c) + " retired.")
+ eliminate_card(c)
+ end_action_phase()
+ },
a1(c) {
push_undo()
goto_take_action(c, 0)
@@ -934,6 +955,11 @@ states.action = {
push_undo()
goto_roll_phase()
},
+ roll() {
+ push_undo()
+ goto_roll_phase()
+ roll_dice_in_pool()
+ },
}
function goto_fizzle(c) {
@@ -989,6 +1015,7 @@ states.bombard = {
view.actions.bombard = 1
},
bombard() {
+ log(card_name(game.selected) + " bombarded.")
let opp = 1 - player_index()
game.morale[opp] --
pay_for_action(game.selected)
@@ -1004,6 +1031,7 @@ states.attack = {
gen_action_card(t)
},
card(c) {
+ log(card_name(game.selected) + " attacked " + card_name(c) + ".")
game.target = c
apply_attack(current_action())
pay_for_action(game.selected)
@@ -1019,6 +1047,7 @@ states.command = {
gen_action_card(t)
},
card(c) {
+ log(card_name(game.selected) + " commanded " + card_name(c) + " out of reserve.")
let p = player_index()
array_remove_item(game.reserve[p], c)
// TODO: insert where?
@@ -1028,7 +1057,28 @@ states.command = {
},
}
+function has_reserve_target_routed(reserve) {
+ for (let c of reserve)
+ if (!game.front[0].includes(c) && !game.front[1].includes(c))
+ return true
+ return false
+}
+
function end_action_phase() {
+ // Bring on reinforcements (on both sides).
+ for (let p = 0; p <= 1; ++p) {
+ for (let i = 0; i < game.reserve[p].length; ++i) {
+ let c = game.reserve[p][i]
+ if (has_reserve_target_routed(data.cards[c].reserve)) {
+ console.log("COMING OUT!", c)
+ log(card_name(c) + " came out of reserve.")
+ game.front[p].push(c)
+ array_remove(game.reserve[p], i)
+ --i
+ }
+ }
+ }
+
goto_roll_phase()
}