summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-06-24 16:51:18 +0200
committerTor Andersson <tor@ccxvii.net>2023-07-07 18:39:37 +0200
commitc88979589d322a2549109049b51759ab88927533 (patch)
tree9316212ab8b200dcd7787581002d0b0bcbddac62 /rules.js
parentf944c920db683e2b345b08df55bc51aa35232b77 (diff)
downloadtime-of-crisis-c88979589d322a2549109049b51759ab88927533.tar.gz
Misc bugs.
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js428
1 files changed, 226 insertions, 202 deletions
diff --git a/rules.js b/rules.js
index 326cfe8..476db80 100644
--- a/rules.js
+++ b/rules.js
@@ -4,6 +4,16 @@
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
[ ] killed leader stash for buy/trash phase
@@ -1279,6 +1289,7 @@ states.pax_deorum = {
gen_action_card(c)
},
card(c) {
+ push_undo()
set_add(game.hand[game.current], c)
set_delete(game.draw[game.current], c)
game.state = "pax_deorum_done"
@@ -1467,6 +1478,7 @@ states.crisis_barbarian_leader = {
gen_action_region(game.where)
},
region(where) {
+ logi("Barbarian leader in %" + where + ".")
set_barbarian_location(game.count, where)
goto_take_actions()
},
@@ -1486,6 +1498,7 @@ states.crisis_rival_emperor = {
gen_action_region(game.where)
},
region(where) {
+ logi("Rival emperor in %" + where + ".")
set_rival_emperor_location(game.count, where)
goto_take_actions()
},
@@ -1609,8 +1622,8 @@ states.take_actions = {
let where = UNAVAILABLE
// XXX
- // if (game.selected_governor < 0 && game.selected_general < 0 && current_hand().length > 0 && mip + sip + pip === 0)
- // view.actions.play_all = 1
+ if (game.selected_governor < 0 && game.selected_general < 0 && current_hand().length > 0 && mip + sip + pip === 0)
+ view.actions.play_all = 1
view.actions.end_actions = 1
@@ -1655,7 +1668,7 @@ states.take_actions = {
break
default:
// TODO: can_select_governor (check possible actions)
- if (sip >= 1 || pip >= 2)
+ if (sip >= 2 || pip >= 2)
gen_action_governor(id)
break
}
@@ -1707,15 +1720,24 @@ states.take_actions = {
// Place Governor
if (game.selected_governor >= 0 && where === AVAILABLE) {
- view.actions.place_governor = 1
- // gen_place_governor()
+ if (sip >= 1) {
+ view.prompt += " Choose a province to Place Governor."
+ gen_place_governor()
+ }
+ //view.actions.place_governor = 1
+ //else
+ //view.actions.place_governor = 0
}
// Create Army
if (game.selected_general >= 0 && where === AVAILABLE) {
- if (mip >= 1 && find_unused_legion() >= 0)
- // gen_create_army()
- view.actions.create_army = 1
+ if (mip >= 1 && find_unused_legion() >= 0) {
+ view.prompt += " Choose a province to Create Army."
+ gen_create_army()
+ }
+ //view.actions.create_army = 1
+ //else
+ //view.actions.create_army = 0
}
// Governor Actions
@@ -1812,20 +1834,9 @@ states.take_actions = {
end_actions() {
push_undo()
-
- // If a castra is on lone militia, but general is now in the space, move it to the general.
- for (let where = 0; where < 12; ++where) {
- if (is_own_province(where) && has_militia_castra(where)) {
- let id = get_capital_general(where)
- if (is_own_general(id)) {
- remove_militia_castra(where)
- add_general_castra(id)
- }
- }
- }
-
game.selected_governor = -1
game.selected_general = -1
+ game.selected_militia = -1
goto_support_check()
},
@@ -1879,7 +1890,7 @@ states.take_actions = {
game.selected_militia = where
} else {
push_undo()
- goto_battle_vs_militia(get_selected_region(), game.selected_general)
+ goto_battle_vs_militia(where, game.selected_general)
}
},
@@ -1964,6 +1975,7 @@ states.take_actions = {
leave() {
push_undo()
set_general_outside_capital(game.selected_general)
+ remove_general_castra(game.selected_general)
},
disperse_mob() {
@@ -1976,7 +1988,7 @@ states.take_actions = {
if (game.selected_general >= 0)
n += count_units_in_army(game.selected_general)
n = Math.min(get_mobs(where), n)
- log("Disperse " + n + " Mobs in %" + where)
+ log("Disperse " + n + " Mobs in %" + where + ".")
set_mobs(where, get_mobs(where) - n)
reduce_support(where)
},
@@ -2015,116 +2027,6 @@ states.take_actions = {
},
}
-// FREE ACTION: ENTER PROVINCIAL CAPITAL
-
-function enter_capital() {
- let where = get_general_location(game.selected_general)
-
- set_general_inside_capital(game.selected_general)
-
- if (is_pretender_province(where) && is_enemy_province(where)) {
- game.count = get_province_governor(where) / 6 | 0
- game.where = where
- if (is_seat_of_power(where)) {
- game.state = "occupy_seat_of_power_1"
- return
- } else {
- game.state = "occupy_breakaway"
- return
- }
- }
-
- if (game.battle)
- end_battle()
-}
-
-function resume_occupy_seat_of_power() {
- for (let where = 1; where < 12; ++where) {
- if (is_breakaway(where) && (get_province_governor(where) / 6 | 0) === game.count) {
- game.state = "occupy_seat_of_power_2"
- return
- }
- }
- goto_replace_pretender()
-}
-
-states.occupy_seat_of_power_1 = {
- prompt() {
- prompt("Occupy Pretender Provincial Capital: Remove seat of power marker and governor.")
- view.color = POPULACE
- gen_action_region(game.where)
- },
- region(where) {
- push_undo()
- log("Removed Seat of Power in %" + where + ".")
- remove_seat_of_power(where)
- remove_governor(where)
- resume_occupy_seat_of_power()
- },
-}
-
-states.occupy_seat_of_power_2 = {
- prompt() {
- prompt("Occupy Pretender Provincial Capital: Remove breakaway markers.")
- view.color = POPULACE
- for (let where = 1; where < 12; ++where)
- if (is_breakaway(where) && (get_province_governor(where) / 6 | 0) === game.count)
- gen_action_region(where)
- },
- region(where) {
- push_undo()
- log("Removed Breakaway in %" + where + ".")
- remove_breakaway(where)
- resume_occupy_seat_of_power()
- },
-}
-
-states.occupy_breakaway = {
- prompt() {
- prompt("Occupy Pretender Provincial Capital: Remove breakaway marker and governor.")
- view.color = POPULACE
- gen_action_region(game.where)
- },
- region(where) {
- push_undo()
- log("Removed Breakaway in %" + where + ".")
- remove_breakaway(where)
- remove_governor(where)
- goto_replace_pretender()
- },
-}
-
-function goto_replace_pretender() {
- if (has_available_governor())
- game.state = "replace_pretender_governor"
- else
- game.state = "take_actions"
-}
-
-states.replace_pretender_governor = {
- prompt() {
- prompt("Occupy Pretender Provincial Capital: You may place an available governor.")
- view.selected_region = game.where
- view.color = SENATE
- for (let i = 0; i < 6; ++i) {
- let id = game.current * 6 + i
- if (get_governor_location(id) === AVAILABLE)
- gen_action_governor(id)
- }
- view.actions.pass = 1
- },
- governor(id) {
- push_undo()
- log("Placed Governor in %" + game.where)
- set_governor_location(id, game.where)
- game.state = "take_actions"
- },
- pass() {
- push_undo()
- game.state = "take_actions"
- },
-}
-
// ACTION: BUILD IMPROVEMENT
states.build_improvement = {
@@ -2390,56 +2292,7 @@ function roll_to_place_governor(pg) {
}
}
-// ACTION: DAMNATIO MEMORIAE
-
-states.damnatio_memoriae = {
- prompt() {
- prompt("Place Governor: You may play Damnatio Memoriae.")
- gen_card_event(CARD_S4)
- gen_card_event(CARD_S4B)
- view.actions.pass = 1
- },
- card(c) {
- push_undo()
- log("Damnatio Memoriae.")
- set_add(game.used, c)
- play_card_event(c)
- },
- pass() {
- push_undo()
- game.state = "take_actions"
- },
-}
-
-function play_damnatio_memoriae() {
- award_legacy(game.count >> 3, "Damnatio Memoriae", -get_support(ITALIA))
- game.state = "damnatio_memoriae_mobs"
- game.count = game.count & 7
-}
-
-function play_damnatio_memoriae_exp() {
- award_legacy(game.count >> 3, "Damnatio Memoriae", -get_support(ITALIA))
- game.state = "take_actions"
-}
-
-states.damnatio_memoriae_mobs = {
- prompt() {
- prompt("Damnatio Memoriae: Place " + game.count + " mobs in provinces you govern.")
- view.color = SENATE
- for (let where = 0; where < 12; ++where)
- if (is_own_province(where) && get_mobs(where) < 6)
- gen_action_region(where)
- },
- region(where) {
- push_undo()
- log("Added Mob to %" + where)
- set_mobs(where, get_mobs(where) + 1)
- if (--game.count === 0)
- game.state = "take_actions"
- },
-}
-
-// ACTION: PRAETORIAN GUARD
+// CARD: PRAETORIAN GUARD
function can_play_praetorian_guard() {
for (let i = 0; i < 6; ++i) {
@@ -2501,6 +2354,55 @@ states.praetorian_guard_italia = {
},
}
+// CARD: DAMNATIO MEMORIAE
+
+states.damnatio_memoriae = {
+ prompt() {
+ prompt("Place Governor: You may play Damnatio Memoriae.")
+ gen_card_event(CARD_S4)
+ gen_card_event(CARD_S4B)
+ view.actions.pass = 1
+ },
+ card(c) {
+ push_undo()
+ log("Damnatio Memoriae.")
+ set_add(game.used, c)
+ play_card_event(c)
+ },
+ pass() {
+ push_undo()
+ game.state = "take_actions"
+ },
+}
+
+function play_damnatio_memoriae() {
+ award_legacy(game.count >> 3, "Damnatio Memoriae", -get_support(ITALIA))
+ game.state = "damnatio_memoriae_mobs"
+ game.count = game.count & 7
+}
+
+function play_damnatio_memoriae_exp() {
+ award_legacy(game.count >> 3, "Damnatio Memoriae", -get_support(ITALIA))
+ game.state = "take_actions"
+}
+
+states.damnatio_memoriae_mobs = {
+ prompt() {
+ prompt("Damnatio Memoriae: Place " + game.count + " mobs in provinces you govern.")
+ view.color = SENATE
+ for (let where = 0; where < 12; ++where)
+ if (is_own_province(where) && get_mobs(where) < 6)
+ gen_action_region(where)
+ },
+ region(where) {
+ push_undo()
+ log("Added Mob in %" + where + ".")
+ set_mobs(where, get_mobs(where) + 1)
+ if (--game.count === 0)
+ game.state = "take_actions"
+ },
+}
+
// ACTION: CREATE ARMY
function gen_create_army() {
@@ -2518,7 +2420,6 @@ function create_army(where) {
if (can_enter_capital(where))
set_general_inside_capital(game.selected_general)
set_legion_location(find_unused_legion(), ARMY + game.selected_general)
- game.state = "take_actions"
}
states.create_army = {
@@ -2531,6 +2432,7 @@ states.create_army = {
region(where) {
push_undo()
create_army(where)
+ game.state = "take_actions"
},
}
@@ -2584,6 +2486,118 @@ function move_army_to(who, to) {
game.state = "take_actions"
}
+// FREE ACTION: MOVE INTO PROVINCIAL CAPITAL
+
+function enter_capital() {
+ let where = get_general_location(game.selected_general)
+
+ set_general_inside_capital(game.selected_general)
+ remove_general_castra(game.selected_general)
+
+ if (is_pretender_province(where) && is_enemy_province(where)) {
+ game.count = get_province_governor(where) / 6 | 0
+ game.where = where
+ if (is_seat_of_power(where)) {
+ game.state = "occupy_seat_of_power_1"
+ return
+ } else {
+ game.state = "occupy_breakaway"
+ return
+ }
+ }
+
+ if (game.battle)
+ end_battle()
+}
+
+function resume_occupy_seat_of_power() {
+ for (let where = 1; where < 12; ++where) {
+ if (is_breakaway(where) && (get_province_governor(where) / 6 | 0) === game.count) {
+ game.state = "occupy_seat_of_power_2"
+ return
+ }
+ }
+ goto_replace_pretender()
+}
+
+states.occupy_seat_of_power_1 = {
+ prompt() {
+ prompt("Occupy Pretender Provincial Capital: Remove seat of power marker and governor.")
+ view.color = POPULACE
+ gen_action_region(game.where)
+ },
+ region(where) {
+ push_undo()
+ log("Removed Seat of Power in %" + where + ".")
+ remove_seat_of_power(where)
+ remove_governor(where)
+ resume_occupy_seat_of_power()
+ },
+}
+
+states.occupy_seat_of_power_2 = {
+ prompt() {
+ prompt("Occupy Pretender Provincial Capital: Remove breakaway markers.")
+ view.color = POPULACE
+ for (let where = 1; where < 12; ++where)
+ if (is_breakaway(where) && (get_province_governor(where) / 6 | 0) === game.count)
+ gen_action_region(where)
+ },
+ region(where) {
+ push_undo()
+ log("Removed Breakaway in %" + where + ".")
+ remove_breakaway(where)
+ resume_occupy_seat_of_power()
+ },
+}
+
+states.occupy_breakaway = {
+ prompt() {
+ prompt("Occupy Pretender Provincial Capital: Remove breakaway marker and governor.")
+ view.color = POPULACE
+ gen_action_region(game.where)
+ },
+ region(where) {
+ push_undo()
+ log("Removed Breakaway in %" + where + ".")
+ remove_breakaway(where)
+ remove_governor(where)
+ goto_replace_pretender()
+ },
+}
+
+function goto_replace_pretender() {
+ if (has_available_governor())
+ game.state = "replace_pretender_governor"
+ else
+ game.state = "take_actions"
+}
+
+states.replace_pretender_governor = {
+ prompt() {
+ prompt("Occupy Pretender Provincial Capital: You may place an available governor.")
+ view.selected_region = game.where
+ view.color = SENATE
+ for (let i = 0; i < 6; ++i) {
+ let id = game.current * 6 + i
+ if (get_governor_location(id) === AVAILABLE)
+ gen_action_governor(id)
+ }
+ view.actions.pass = 1
+ },
+ governor(id) {
+ push_undo()
+ log("Replaced Governor in %" + game.where + ".")
+ set_governor_location(id, game.where)
+ game.state = "take_actions"
+ },
+ pass() {
+ push_undo()
+ game.state = "take_actions"
+ },
+}
+
+
// CARD: CASTRA
function can_play_castra() {
@@ -2620,7 +2634,6 @@ states.castra = {
game.state = "take_actions"
},
general(id) {
- push_undo()
let where = get_general_location(id)
log("Castra on army in %" + where + ".")
add_general_castra(id)
@@ -2650,8 +2663,7 @@ states.quaestor = {
gen_action_region(where)
},
region(where) {
- push_undo()
- log("Quaestor in %" + where)
+ log("Quaestor in %" + where + ".")
add_quaestor(where)
game.state = "take_actions"
}
@@ -2683,10 +2695,9 @@ states.tribute = {
}
},
barbarian(target) {
- push_undo()
let where = get_barbarian_location(target)
let tribe = get_barbarian_tribe(target)
- log("Tribute " + BARBARIAN_NAME[tribe] + " in %" + where)
+ log("Tribute " + BARBARIAN_NAME[tribe] + " in %" + where + ".")
for (let id = first_barbarian[tribe]; id <= last_barbarian[tribe]; ++id)
if (get_barbarian_location(id) === where && is_barbarian_active(id))
set_barbarian_inactive(id)
@@ -2762,13 +2773,11 @@ states.foederati = {
}
},
general(id) {
- push_undo()
game.count = id
game.where = get_general_location(id)
game.state = "foederati_general"
},
militia(where) {
- push_undo()
game.count = -1
game.where = where
game.state = "foederati_militia"
@@ -2787,7 +2796,6 @@ states.foederati_general = {
gen_foederati(to)
},
barbarian(id) {
- push_undo()
let tribe = get_barbarian_tribe(id)
let from = get_barbarian_location(id)
log("Foederati " + BARBARIAN_NAME[tribe] + " from %" + from + ".")
@@ -2809,7 +2817,6 @@ states.foederati_militia = {
gen_foederati(to)
},
barbarian(id) {
- push_undo()
let tribe = get_barbarian_tribe(id)
let from = get_barbarian_location(id)
log("Foederati " + BARBARIAN_NAME[tribe] + " from %" + from + ".")
@@ -2886,7 +2893,7 @@ states.pretender_seat_of_power = {
},
region(where) {
push_undo()
- log("Seat of Power in %" + where)
+ log("Seat of Power in %" + where + ".")
add_seat_of_power(where)
remove_quaestor(where) // no effect anymore
goto_pretender_breakaway()
@@ -2915,7 +2922,7 @@ states.pretender_breakaway = {
},
region(where) {
push_undo()
- log("Breakaway in %" + where)
+ log("Breakaway in %" + where + ".")
add_breakaway(where)
remove_quaestor(where) // no effect anymore
goto_pretender_breakaway()
@@ -3063,7 +3070,7 @@ function roll_combat_dice() {
function roll_flanking_maneuver_dice() {
log_h4("FLANKING MANEUVER")
- game.battle.dhits = roll_defender_dice()
+ game.battle.dhits = roll_attacker_dice()
log("Total " + game.battle.dhits + " hits!")
log_br()
}
@@ -3481,9 +3488,14 @@ 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 && can_free_increase_support_level(game.where)) {
- game.state = "free_increase_support_level"
- return
+ if (game.battle.killed) {
+ if (can_free_increase_support_level(game.where)) {
+ game.state = "free_increase_support_level"
+ return
+ } else {
+ log("Kept for cost reduction.")
+ game.killed |= game.battle.killed
+ }
}
game.battle = null
game.state = "take_actions"
@@ -3508,7 +3520,7 @@ states.free_increase_support_level = {
},
keep() {
push_undo()
- log("Saved for cost reduction.")
+ log("Kept for cost reduction.")
game.killed |= game.battle.killed
game.battle = null
game.state = "take_actions"
@@ -3518,6 +3530,17 @@ states.free_increase_support_level = {
// === SUPPORT CHECK ===
function goto_support_check() {
+ // If a castra is on lone militia, but general is now in the space, move it to the general.
+ for (let where = 0; where < 12; ++where) {
+ if (is_own_province(where) && has_militia_castra(where)) {
+ let id = get_capital_general(where)
+ if (is_own_general(id)) {
+ remove_militia_castra(where)
+ add_general_castra(id)
+ }
+ }
+ }
+
game.count = 0
resume_support_check()
}
@@ -3676,11 +3699,11 @@ states.legitimize_claim = {
}
function goto_gain_legacy_emperor() {
- award_legacy(game.current, "Emperor", Math.max(0, get_support(ITALIA) - count_pretender_provinces()))
if (!is_any_rival_emperor_or_pretender()) {
- log(PLAYER_NAMES[game.current] + " gained Emperor Turn")
+ log(PLAYER_NAMES[game.current] + " +1 Emperor Turn.")
game.emperor_turns[game.current] += 1
}
+ award_legacy(game.current, "Emperor", Math.max(0, get_support(ITALIA) - count_pretender_provinces()))
goto_gain_legacy_provinces()
}
@@ -4114,7 +4137,7 @@ exports.setup = function (seed, scenario, options) {
legions: new Array(LEGION_COUNT).fill(AVAILABLE),
barbarians: new Array(BARBARIAN_COUNT[player_count - 2]).fill(AVAILABLE),
- crisis: 0,
+ crisis: -1,
dice: [ 0, 0, 0, 0 ], // first two are crisis table dice, second two are barbarian homeland dice
market: null,
@@ -4156,6 +4179,7 @@ exports.setup = function (seed, scenario, options) {
game.hand[player] = []
game.draw[player] = setup_player_deck(player)
game.discard[player] = []
+ //for (let i = 0; i < 9; ++i) set_add(game.draw[player], game.market[i].pop())
}
update_neutral_italia()