summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-05-19 17:41:24 +0200
committerTor Andersson <tor@ccxvii.net>2024-08-21 00:28:20 +0200
commit6595a0e76d5ee24f352c529cd82ceb794fa37697 (patch)
treeb800b092dd24c57dfcc993aab8e02acf69f66bdf /rules.js
parent427167da7870d5eea6cf7196322cd5bb1e7c7b94 (diff)
downloadwashingtons-war-6595a0e76d5ee24f352c529cd82ceb794fa37697.tar.gz
stuff
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js41
1 files changed, 21 insertions, 20 deletions
diff --git a/rules.js b/rules.js
index 865f75f..e470b8c 100644
--- a/rules.js
+++ b/rules.js
@@ -930,7 +930,7 @@ function overrun(where) {
function retreat_american_army(from, to) {
let g = find_american_or_french_general(from)
- if (g)
+ if (g !== NOBODY)
move_general(g, to)
move_american_cu(from, to, count_american_cu(from))
move_french_cu(from, to, count_french_cu(from))
@@ -938,14 +938,14 @@ function retreat_american_army(from, to) {
function retreat_british_army(from, to) {
let g = find_british_general(from)
- if (g)
+ if (g !== NOBODY)
move_general(g, to)
move_british_cu(from, to, count_british_cu(from))
}
function surrender_american_army(where) {
let g = find_american_or_french_general(where)
- if (g)
+ if (g !== NOBODY)
capture_american_or_french_general(where)
remove_american_cu(where, count_american_cu(where))
remove_french_cu(where, count_french_cu(where))
@@ -953,7 +953,7 @@ function surrender_american_army(where) {
function surrender_british_army(where) {
let g = find_british_general(where)
- if (g)
+ if (g !== NOBODY)
capture_british_general(where)
game.combat.british_losses += count_british_cu(where)
remove_british_cu(where, count_british_cu(where))
@@ -1991,7 +1991,6 @@ states.ops_general_move = {
function resume_moving() {
if (has_enemy_cu(game.move.to)) {
- end_move()
goto_start_battle()
}
}
@@ -2698,7 +2697,6 @@ function goto_start_battle() {
function goto_retreat_before_battle() {
game.active = P_AMERICA
- game.who = find_american_or_french_general(game.move.to)
game.state = "retreat_before_battle"
}
@@ -2709,14 +2707,15 @@ states.retreat_before_battle = {
gen_defender_retreat()
},
move(to) {
- let agility = GENERALS[game.who].agility
- if (GENERALS[game.who].bonus)
+ let who = find_american_or_french_general(game.move.to)
+ let agility = GENERALS[who].agility
+ if (GENERALS[who].bonus)
agility += 2
let roll = roll_d6()
if (roll <= agility) {
logp("successfully retreated before battle: " + roll + " <= " + agility)
pickup_max_american_cu(game.move.to)
- move_army(game.who, game.move.to, to)
+ move_army(who, game.move.to, to)
goto_remove_general_after_retreat_before_battle(to)
} else {
logp("failed to retreat before battle: " + roll + " > " + agility)
@@ -2817,7 +2816,6 @@ function gen_attacker_retreat() {
}
function end_retreat_before_battle() {
- delete game.who
goto_play_attacker_battle_card()
}
@@ -3134,12 +3132,12 @@ function resolve_battle() {
function goto_retreat_after_battle(victor) {
if (victor === P_BRITAIN) {
- game.who = find_american_or_french_general(game.move.to)
- if (game.who === NOBODY && count_american_and_french_cu(game.move.to) === 0)
+ let who = find_american_or_french_general(game.move.to)
+ if (who === NOBODY && count_american_and_french_cu(game.move.to) === 0)
return end_battle()
} else {
- game.who = find_british_general(game.move.to)
- if (game.who === NOBODY && count_british_cu(game.move.to) === 0)
+ let who = find_british_general(game.move.to)
+ if (who === NOBODY && count_british_cu(game.move.to) === 0)
return end_battle()
}
game.active = ENEMY[victor]
@@ -3196,7 +3194,8 @@ function end_battle() {
set_add(game.a_hand, deal_card())
delete game.combat
- delete game.move
+
+ end_move()
end_strategy_card()
}
@@ -3535,7 +3534,7 @@ states.game_over = {
function gen_action(action, argument) {
if (argument === undefined) {
- view.actions.action = 1
+ view.actions[action] = 1
} else {
if (!(action in view.actions))
view.actions[action] = []
@@ -3559,7 +3558,7 @@ exports.setup = function (seed, scenario, options) {
exports.action = function (state, current, action, arg) {
game = state
- Object.seal(game) // don't allow adding properties!
+ //Object.seal(game) // don't allow adding properties!
// TODO: check against action list
if (current === game.active) {
@@ -3581,8 +3580,10 @@ exports.view = function (state, current) {
game = state
view = {
+ prompt: null,
+ log: state.log,
year: state.year,
- flags: state,flags
+ flags: state.flags,
war_ends: state.war_ends,
reinforcements: state.reinforcements,
french_alliance: state.french_alliance,
@@ -3597,8 +3598,6 @@ exports.view = function (state, current) {
a_queue: state.a_queue,
b_queue: state.b_queue,
last_played: state.last_played,
- who: state.who,
- log: state.log,
}
if (current === P_AMERICA)
@@ -3918,3 +3917,5 @@ function map_delete(map, key) {
}
}
}
+
+console.log(events)