summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoël Simoneau <simoneaujoel@gmail.com>2025-01-16 22:44:44 -0500
committerJoël Simoneau <simoneaujoel@gmail.com>2025-01-16 22:44:44 -0500
commit8b3cba4c8faaa5e603a1c9cba5d994258d9069a4 (patch)
tree34697127e676ae9731824896894ed6f710ba1e51
parenta259fb59db9718c4d2ae41c9fa7e75134303b638 (diff)
downloadvijayanagara-8b3cba4c8faaa5e603a1c9cba5d994258d9069a4.tar.gz
Event 3
-rw-r--r--const.js2
-rw-r--r--events.txt18
-rw-r--r--rules.js115
3 files changed, 127 insertions, 8 deletions
diff --git a/const.js b/const.js
index 90862ef..462afdc 100644
--- a/const.js
+++ b/const.js
@@ -4,6 +4,8 @@ const DS = 0
const BK = 1
const VE = 2
const MI = 3
+const FACTIONS = [DS, BK, VE]
+const REBEL_FACTIONS = [BK, VE]
// Role names
const NAME_DS = "DS"
diff --git a/events.txt b/events.txt
index 644f373..1d18102 100644
--- a/events.txt
+++ b/events.txt
@@ -13,10 +13,24 @@ SHADED 2
log "NOT IMPLEMENTED"
EVENT 3
- log "NOT IMPLEMENTED"
+ current REBEL_FACTIONS
+ prompt "Free Rally and gain 2 Resources in each Province adjacent to Warangal with your presence."
+ space_opt all (is_adjacent_to_city(C_WARANGAL, s) && has_piece_faction(s, game.current))
+ free_rally
+ resources (game.current) 2
+ endspace
SHADED 3
- log "NOT IMPLEMENTED"
+ current DS
+ prompt "In each Province adjacent to Warangal with you presence, steal 2 Resources from each other Faction present."
+ space_opt all (is_adjacent_to_city(C_WARANGAL, s) && has_piece_faction(s, DS) && has_piece_enemy_faction(s, DS))
+ if has_piece_faction(game.vm.s, BK)
+ steal DS BK 2
+ endif
+ if has_piece_faction(game.vm.s, VE)
+ steal DS VE 2
+ endif
+ endspace
EVENT 4
log "NOT IMPLEMENTED"
diff --git a/rules.js b/rules.js
index ebbd942..f4594ab 100644
--- a/rules.js
+++ b/rules.js
@@ -258,7 +258,7 @@ exports.setup = function (seed, scenario, _options) {
}
function setup_deck() {
- game.deck = [ 33, 36, 10, 37, 11, 2, 41, 3, 4, 5, 6, 7, 8, 9, 10, 1, 12, 13, 14 ]
+ game.deck = [ 3, 36, 10, 37, 11, 2, 41, 4, 5, 6, 7, 8, 9, 10, 1, 12, 13, 14 ]
}
function setup_standard() {
@@ -811,6 +811,18 @@ function init_command(type) {
game.cmd.type = type
}
+function init_free_command(type, s) {
+ game.cmd = {
+ type: type,
+ limited: s >= 0 ? 1 : 0,
+ free: 1,
+ spaces: [],
+ where: s,
+ }
+ if (s >= 0)
+ set_add(game.cmd.spaces, s)
+}
+
function gen_any_command() {
if (game.current === DS) {
view.actions.conscript = can_conscript() ? 1 : 0
@@ -839,7 +851,10 @@ function end_command() {
}
log_br()
game.cmd = null
- game.state = "main_phase"
+ if (game.vm)
+ vm_next()
+ else
+ game.state = "main_phase"
}
function end_decree() {
@@ -2325,6 +2340,12 @@ function has_piece_faction(s, faction) {
return count_faction_pieces(s, faction) > 0
}
+function has_piece_enemy_faction(s, faction) {
+ return FACTIONS
+ .filter(f => f != faction)
+ .some(f => count_faction_pieces(s, f) > 0)
+}
+
function has_unmoved_piece(space, faction) {
let unmoved = false
for_each_movable(faction, p => {
@@ -2369,7 +2390,6 @@ function has_valid_support_attackers(s, faction) {
}
function gen_place_piece(faction, type) {
- console.log("GEN_PLACE ", faction, type)
let can_place = false
for_each_piece(faction, type, p => {
if (piece_space(p) === AVAILABLE) {
@@ -3369,6 +3389,38 @@ function vm_goto(cmd, nop, dir, step) {
vm_exec()
}
+function vm_if() {
+ if (!vm_operand(1)) {
+ let balance = 1
+ while (balance > 0) {
+ ++game.vm.ip
+ switch (vm_operand(0)) {
+ case vm_if:
+ ++balance
+ break
+ case vm_endif:
+ --balance
+ break
+ case vm_else:
+ if (balance === 1)
+ --balance
+ break
+ }
+ if (game.vm.ip < 0 || game.vm.ip > CODE[game.vm.fp].length)
+ throw "ERROR"
+ }
+ }
+ vm_next()
+}
+
+function vm_else() {
+ vm_goto(vm_endif, vm_if, 1, 1)
+}
+
+function vm_endif() {
+ vm_next()
+}
+
function vm_inst(a) {
return CODE[game.vm.fp][game.vm.ip][a]
}
@@ -3507,7 +3559,6 @@ function vm_save_space() {
// VM: PIECE ITERATOR
function vm_piece() {
- console.log("IN VM_PIECE", can_vm_piece())
if (can_vm_piece()) {
game.state = "vm_piece"
} else {
@@ -3678,6 +3729,42 @@ states.vm_resources = {
}
}
+function vm_steal() {
+ game.state = "vm_steal"
+}
+
+states.vm_steal = {
+ prompt() {
+ let f1 = vm_operand(1)
+ let f2 = vm_operand(2)
+ let n = Math.min(vm_operand(3), game.resources[f2])
+ if (n == 0) {
+ event_prompt(`${faction_name[f2]} has no Resource.`)
+ view.actions.skip = 1
+ } else {
+ event_prompt(`Steal ${n} Resources from ${faction_name[f2]}.`)
+ gen_action_resources(f2)
+ }
+ },
+ resources(f) {
+ let n = Math.min(vm_operand(3), game.resources[f])
+ add_resources(game.current, n)
+ add_resources(f, -n)
+ log(`${faction_name[game.current]} steals ${n} Resources from ${faction_name[f]}.`)
+ vm_next()
+ },
+ skip() {
+ vm_next()
+ }
+}
+
+// VM : RALLY
+
+function vm_free_rally() {
+ init_free_command("Rally", game.vm.s)
+ goto_rally_space()
+}
+
// === CONST ===
// Factions
@@ -3685,6 +3772,8 @@ const DS = 0
const BK = 1
const VE = 2
const MI = 3
+const FACTIONS = [DS, BK, VE]
+const REBEL_FACTIONS = [BK, VE]
// Role names
const NAME_DS = "DS"
@@ -3746,13 +3835,27 @@ CODE[2 * 2 + 1] = [
// EVENT 3
CODE[3 * 2 + 0] = [
- [ vm_log, "NOT IMPLEMENTED" ],
+ [ vm_current, REBEL_FACTIONS ],
+ [ vm_prompt, "Free Rally and gain 2 Resources in each Province adjacent to Warangal with your presence." ],
+ [ vm_space, true, 0, 999, (s)=>(is_adjacent_to_city(C_WARANGAL, s) && has_piece_faction(s, game.current)) ],
+ [ vm_free_rally ],
+ [ vm_resources, false, ()=>(game.current), 2 ],
+ [ vm_endspace ],
[ vm_return ],
]
// SHADED 3
CODE[3 * 2 + 1] = [
- [ vm_log, "NOT IMPLEMENTED" ],
+ [ vm_current, DS ],
+ [ vm_prompt, "In each Province adjacent to Warangal with you presence, steal 2 Resources from each other Faction present." ],
+ [ vm_space, true, 0, 999, (s)=>(is_adjacent_to_city(C_WARANGAL, s) && has_piece_faction(s, DS) && has_piece_enemy_faction(s, DS)) ],
+ [ vm_if, ()=>has_piece_faction(game.vm.s, BK) ],
+ [ vm_steal, DS, BK, 2 ],
+ [ vm_endif ],
+ [ vm_if, ()=>has_piece_faction(game.vm.s, VE) ],
+ [ vm_steal, DS, VE, -2 ],
+ [ vm_endif ],
+ [ vm_endspace ],
[ vm_return ],
]