summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--play.js10
-rw-r--r--rules.js97
2 files changed, 62 insertions, 45 deletions
diff --git a/play.js b/play.js
index eb86314..f4411ec 100644
--- a/play.js
+++ b/play.js
@@ -22,6 +22,10 @@ const BLOCKADE_ZONES = [ "Sea1", "Sea2", "Sea3", "Sea4", "Sea5", "Sea6", "Sea7"
const P_BRITAIN = "Britain"
const P_AMERICA = "America"
+const F_REGULARS = 2
+const F_EUROPEAN_WAR = 4
+const F_MUTINIES = 16
+
const space_count = 66
const general_count = data.generals.length
@@ -266,7 +270,7 @@ function update_units() {
const cuY = 10
update_marker(ui.turn, "Game Turn " + view.year)
- if (view.regulars)
+ if (view.flags & F_REGULARS)
ui.turn.classList.remove("no-regulars")
else
ui.turn.classList.add("no-regulars")
@@ -274,7 +278,7 @@ function update_units() {
update_marker(ui.congress, view.congress)
update_marker(ui.french_alliance, "French Alliance Track " + view.french_alliance)
- if (view.european_war)
+ if (view.flags & F_EUROPEAN_WAR)
ui.french_alliance.classList.add("european-war")
else
ui.french_alliance.classList.remove("european-war")
@@ -371,7 +375,7 @@ build_map()
function player_info(player, nc, nq) {
let info = ""
if (player == P_AMERICA) {
- if (view.pennsylvania_and_new_jersey_line_mutinies || view.congress === CONTINENTAL_CONGRESS_DISPERSED)
+ if ((view.flags & F_MUTINIES) || view.congress === CONTINENTAL_CONGRESS_DISPERSED)
info += "\u{1f6ab} "
}
if (nq > 0)
diff --git a/rules.js b/rules.js
index 6e0c3e1..865f75f 100644
--- a/rules.js
+++ b/rules.js
@@ -4,8 +4,6 @@
// TODO: campaign messed up who is who after battle
// TODO: retreat with 0 CU after battle
-// TODO: bit flags for regulars, european_war, french alliance triggered, etc
-
/* DATA */
const data = require("./data.js")
@@ -92,6 +90,14 @@ const BARON_VON_STEUBEN = 86
// const WAR_ENDS_1779 = 71
// const BENJAMIN_FRANKLIN = 101
+const F_RESHUFFLE = 1
+const F_REGULARS = 2
+const F_EUROPEAN_WAR = 4
+const F_FRENCH_ALLIANCE_TRIGGERED = 8
+const F_MUTINIES = 16
+const F_CONGRESS_WAS_DISPERSED = 32
+const F_LANDING_PARTY = 64
+
const general_count = data.generals.length
const space_count = 66
const all_spaces = new Array(space_count).fill(0).map((_,i)=>i)
@@ -117,12 +123,7 @@ function setup_game(seed) {
// tracks
year: 1775,
- french_alliance_triggered: false,
- european_war: false,
- regulars: true,
- congress_was_dispersed: false,
- pennsylvania_and_new_jersey_line_mutinies: false,
- reshuffle: false,
+ flags: F_REGULARS,
// played cards
war_ends: 0,
@@ -200,6 +201,18 @@ function setup_game(seed) {
/* GAME STATE */
+function has_flag(f) {
+ return (game.flags & f) !== 0
+}
+
+function set_flag(f) {
+ return game.flags |= f
+}
+
+function clear_flag(f) {
+ return game.flags &= ~f
+}
+
function create_deck() {
game.deck = []
for (let i = 1; i <= 110; ++i) {
@@ -213,7 +226,7 @@ function create_deck() {
function reshuffle_deck() {
log("Reshuffled the deck.")
- game.reshuffle = false
+ clear_flag(F_RESHUFFLE)
// Reconstitute deck, minus removed cards, cards in hand, war_ends, and reinforcement cards.
// Rule 6.1B clarification.
@@ -254,7 +267,7 @@ function play_card(c, reason) {
else
log(game.active[0] + " played #" + c)
if (CARDS[c].reshuffle === "if_played")
- game.reshuffle = true
+ set_flag(F_RESHUFFLE)
set_delete(active_hand(), c)
game.last_played = c
if (CARDS[c].once) {
@@ -266,7 +279,7 @@ function play_card(c, reason) {
function discard_card_from_hand(hand, c) {
set_delete(hand, c)
if (CARDS[c].reshuffle === "if_discarded")
- game.reshuffle = true
+ set_flag(F_RESHUFFLE)
logp("discarded #" + c)
}
@@ -292,11 +305,11 @@ function can_play_event(c) {
let card = CARDS[c]
switch (card.when) {
case "before_french_alliance":
- return !game.french_alliance_triggered
+ return !has_flag(F_FRENCH_ALLIANCE_TRIGGERED)
case "after_french_alliance":
- return game.french_alliance_triggered
+ return has_flag(F_FRENCH_ALLIANCE_TRIGGERED)
case "european_war_in_effect":
- return game.european_war
+ return has_flag(F_EUROPEAN_WAR)
}
switch (card.event) {
case "john_glovers_marblehead_regiment":
@@ -355,7 +368,7 @@ function is_winter_quarter_space(where) {
function allowed_to_place_american_pc() {
if (is_continental_congress_dispersed())
return false
- if (game.pennsylvania_and_new_jersey_line_mutinies)
+ if (has_flag(F_MUTINIES))
return false
return true
}
@@ -736,7 +749,7 @@ function move_general(who, where) {
function capture_washington() {
set_general_location(WASHINGTON, NOWHERE)
- if (!game.french_alliance_triggered) {
+ if (!has_flag(F_FRENCH_ALLIANCE_TRIGGERED)) {
game.french_alliance -= 3
if (game.french_alliance < 0)
game.french_alliance = 0
@@ -949,7 +962,7 @@ function surrender_british_army(where) {
function disperse_continental_congress() {
log("Contintental Congress dispersed!")
game.congress = CONTINENTAL_CONGRESS_DISPERSED
- game.congress_was_dispersed = true
+ set_flag(F_CONGRESS_WAS_DISPERSED)
}
/* MOVE GENERATORS */
@@ -1173,7 +1186,7 @@ function goto_start_year() {
shuffle(game.deck)
}
- if (game.reshuffle)
+ if (has_flag(F_RESHUFFLE))
reshuffle_deck()
game.a_queue = 0
@@ -1203,18 +1216,18 @@ states.british_declare_first = {
}
},
card_campaign(c) {
- game.congress_was_dispersed = false
+ clear_flag(F_CONGRESS_WAS_DISPERSED)
logp("went first by playing a campaign card")
game.active = P_BRITAIN
goto_campaign(c)
},
pass() {
- if (game.congress_was_dispersed)
+ if (has_flag(F_CONGRESS_WAS_DISPERSED))
game.active = P_BRITAIN
else
game.active = P_AMERICA
game.state = "choose_first_player"
- game.congress_was_dispersed = false
+ clear_flag(F_CONGRESS_WAS_DISPERSED)
},
}
@@ -1319,14 +1332,14 @@ function end_strategy_card() {
game.state = "ops_general_who"
return
} else {
- delete game.landing_party
+ clear_flag(F_LANDING_PARTY)
delete game.campaign
}
}
- if (!game.french_alliance_triggered && game.french_alliance === 9) {
+ if (!has_flag(F_FRENCH_ALLIANCE_TRIGGERED) && game.french_alliance === 9) {
log("The French signed an alliance with the Americans!")
- game.french_alliance_triggered = true
+ set_flag(F_FRENCH_ALLIANCE_TRIGGERED)
if (game.french_navy === -1) {
game.active = P_AMERICA
game.state = "place_french_navy_trigger"
@@ -1695,24 +1708,24 @@ function goto_ops_general(c) {
states.ops_general_who = {
prompt() {
- if (game.campaign && game.landing_party)
+ if (game.campaign && !has_flag(F_LANDING_PARTY))
view.prompt = "Campaign: Activate a general or use a landing party. " + game.campaign + " left."
else if (game.campaign)
view.prompt = "Campaign: Activate a general. " + game.campaign + " left."
else
view.prompt = "Activate a general with strategy rating " + game.count + " or lower."
- if (game.landing_party)
+ if (has_flag(F_LANDING_PARTY))
gen_landing_party()
gen_activate_general()
gen_pass()
},
place_british_pc(where) {
- game.landing_party = 0
+ clear_flag(F_LANDING_PARTY)
place_british_pc(where)
end_strategy_card()
},
flip_pc(where) {
- game.landing_party = 0
+ clear_flag(F_LANDING_PARTY)
flip_pc(where)
end_strategy_card()
},
@@ -2164,7 +2177,10 @@ function goto_campaign(c) {
play_card(c)
game.state = "campaign"
game.campaign = CARDS[c].count
- game.landing_party = game.active === P_BRITAIN ? 1 : 0
+ if (game.active === P_BRITAIN)
+ set_flag(F_LANDING_PARTY)
+ else
+ clear_flag(F_LANDING_PARTY)
game.count = 3 // can activate any general!
game.state = "ops_general_who"
}
@@ -2213,9 +2229,9 @@ function advance_french_alliance(count) {
}
function lose_regular_advantage() {
- if (game.regulars) {
+ if (has_flag(F_REGULARS)) {
log("British Regulars Advantage lost!")
- game.regulars = false
+ clear_flag(F_REGULARS)
advance_french_alliance(2)
}
}
@@ -2518,7 +2534,7 @@ function gen_remove_british_cu() {
events.pennsylvania_and_new_jersey_line_mutinies = function (c, card) {
play_card(c)
- game.pennsylvania_and_new_jersey_line_mutinies = true
+ set_flag(F_MUTINIES)
game.state = "pennsylvania_and_new_jersey_line_mutinies"
game.count = 2
delete game.where
@@ -3026,7 +3042,7 @@ function resolve_battle() {
a_log.push("+" + a_br + " Actual Battle Rating")
let b_drm = b_cu + b_br + game.combat.b_bonus
- if (game.regulars) {
+ if (has_flag(F_REGULARS)) {
b_log.push("+1 British Regulars' Advantage")
b_drm += 1
}
@@ -3490,19 +3506,20 @@ function norths_government_falls() {
}
function goto_end_phase() {
- if (game.french_alliance_triggered && !game.european_war) {
- game.european_war = true
+ if (has_flag(F_FRENCH_ALLIANCE_TRIGGERED) && !has_flag(F_EUROPEAN_WAR)) {
+ set_flag(F_EUROPEAN_WAR)
game.count = 2
game.active = P_AMERICA
game.state = "european_war"
- game.reshuffle = true
+ set_flag(F_RESHUFFLE)
return
}
if ((game.war_ends && game.year >= CARDS[game.war_ends].year) || game.year === 1783)
return norths_government_falls()
- delete game.pennsylvania_and_new_jersey_line_mutinies
+ clear_flag(F_MUTINIES)
+
game.a_queue = game.b_queue = 0
game.year += 1
goto_start_year()
@@ -3565,13 +3582,12 @@ exports.view = function (state, current) {
view = {
year: state.year,
+ flags: state,flags
war_ends: state.war_ends,
reinforcements: state.reinforcements,
french_alliance: state.french_alliance,
- european_war: state.european_war,
congress: state.congress,
french_navy: state.french_navy,
- regulars: state.regulars,
loca: state.loca,
cupc: state.cupc,
@@ -3585,9 +3601,6 @@ exports.view = function (state, current) {
log: state.log,
}
- if (state.pennsylvania_and_new_jersey_line_mutinies)
- view.pennsylvania_and_new_jersey_line_mutinies = true
-
if (current === P_AMERICA)
view.hand = state.a_hand
else if (current === P_BRITAIN)