diff options
author | Joël Simoneau <simoneaujoel@gmail.com> | 2025-03-18 15:45:52 -0400 |
---|---|---|
committer | Joël Simoneau <simoneaujoel@gmail.com> | 2025-03-18 15:45:52 -0400 |
commit | bc7486013da17071c180181085f64393964624d2 (patch) | |
tree | 01a1f2a2a8455230366199835d3328753285a1a2 | |
parent | d0985b0efe668540b54fbbdd47986655e8cc683a (diff) | |
download | vijayanagara-bc7486013da17071c180181085f64393964624d2.tar.gz |
Better replace
-rw-r--r-- | const.js | 2 | ||||
-rw-r--r-- | events.txt | 57 | ||||
-rw-r--r-- | rules.js | 170 | ||||
-rw-r--r-- | tools/gencode.js | 10 |
4 files changed, 127 insertions, 112 deletions
@@ -24,7 +24,7 @@ const AVAILABLE = -1 const OUT_OF_PLAY = -2 const ANY_PIECES = [ DISC, ELITE, TROOPS ] const PIECE_FACTION_TYPE_NAME = [ - [ "Qasbah", "Governor", "Troops" ], + [ "Qasbah", "Governor", "Troop" ], [ "Fort", "Amir", null ], [ "Temple", "Raja", null ], [ null, null, "Invader" ] @@ -79,10 +79,7 @@ EVENT 4 current REBEL_FACTIONS prompt `Replace 1 Governor with an Obedient or Rebelling ${PIECE_FACTION_TYPE_NAME[game.current][ELITE]}.` piece 1 is_governor(p) - set_piece_space - remove - auto_place (game.current) ELITE - event_4 + replace_choice (game.current) ELITE endpiece SHADED 4 @@ -95,11 +92,8 @@ EVENT 5 stay_eligible current REBEL_FACTIONS prompt `Replace up to 2 Delhi Sultanate Units with Rebelling ${PIECE_FACTION_TYPE_NAME[game.current][ELITE]}.` - piece_undo_opt 2 (is_adjacent_to_city(C_CHITTOR, piece_space(p)) && can_place_piece(piece_space(p), game.current, ELITE) && is_ds_unit(p)) - set_piece_space - remove - auto_place_rebel (game.current) ELITE - set_space -1 + piece_undo_opt 2 (is_adjacent_to_city(C_CHITTOR, piece_space(p)) && is_ds_unit(p)) + replace_rebel (game.current) ELITE endpiece prompt `Place a ${PIECE_FACTION_TYPE_NAME[game.current][DISC]} in Rajput Kingdoms.` space_opt 1 (s === S_RAJPUT_KINGDOMS && can_place_piece(s, game.current, DISC)) @@ -110,11 +104,8 @@ SHADED 5 stay_eligible current DS prompt "Replace up to 3 opposing Units adjacent to Chittor." - piece_undo_opt 3 (is_adjacent_to_city(C_CHITTOR, piece_space(p)) && can_place_piece(piece_space(p), DS, TROOPS) && is_enemy_piece(p)) - set_piece_space - remove - auto_place DS TROOPS - set_space -1 + piece_undo_opt 3 (is_adjacent_to_city(C_CHITTOR, piece_space(p)) && is_enemy_piece(p)) + replace DS TROOPS endpiece prompt "Place a Qasbah in Rajput Kingdoms." space_opt 1 (s === S_RAJPUT_KINGDOMS && can_place_piece(s, DS, DISC)) @@ -160,10 +151,10 @@ SHADED 7 EVENT 8 current REBEL_FACTIONS prompt `In each Province, replace a Delhi Sultanate Unit with a ${PIECE_FACTION_TYPE_NAME[game.current][ELITE]}.` - space_opt all (is_adjacent_to_city(C_DEVAGIRI, s) || is_adjacent_to_city(C_GULBARGA, s)) && has_ds_unit(s) && can_place_piece(s, game.current, ELITE) + space_opt all (is_adjacent_to_city(C_DEVAGIRI, s) || is_adjacent_to_city(C_GULBARGA, s)) && has_ds_unit(s) + prompt `In each Province, replace a Delhi Sultanate Unit with a ${PIECE_FACTION_TYPE_NAME[game.current][ELITE]}.` piece 1 is_ds_unit(p) && is_piece_in_event_space(p) - remove - auto_place (game.current) ELITE + replace (game.current) ELITE endpiece endspace @@ -323,11 +314,10 @@ SHADED 14 EVENT 15 stay_eligible prompt "Replace Governors with Rebelling Amirs in Provinces adjacent to Devagiri." - piece_undo_opt all is_adjacent_to_city(C_DEVAGIRI, piece_space(p)) && can_place_piece(piece_space(p), BK, ELITE) && is_governor(p) + piece_undo_opt all is_adjacent_to_city(C_DEVAGIRI, piece_space(p)) && is_governor(p) set_piece_space mark_space - remove - auto_place_rebel BK ELITE + replace_rebel BK ELITE set_space -1 endpiece prompt "Remove a Tributary marker in one Province." @@ -338,10 +328,9 @@ EVENT 15 SHADED 15 stay_eligible prompt "Replace an Amir with a Governor and place a Tributary marker in a Province adjacent to Devagiri." - space 1 is_adjacent_to_city(C_DEVAGIRI, s) && can_place_piece(s, DS, ELITE) && !is_tributary(s) + space 1 is_adjacent_to_city(C_DEVAGIRI, s) && !is_tributary(s) asm game.vm.p = find_piece(game.vm.s, BK, ELITE) - remove - auto_place DS ELITE + replace DS ELITE place_tributary endspace @@ -416,11 +405,8 @@ SHADED 18 stay_eligible current [DS VE] prompt `Replace an Amir with a ${PIECE_FACTION_TYPE_NAME[game.current][ELITE]}.` - piece_opt 1 is_amir(p) && can_place_piece(s, game.current, ELITE) && is_piece_on_map(p) - set_piece_space - remove - auto_place (game.current) ELITE - set_space -1 + piece_opt 1 is_amir(p) && is_piece_on_map(p) + replace (game.current) ELITE endpiece remove_influence BK @@ -518,8 +504,7 @@ EVENT 23 prompt "In each Province with a Temple, replace a Unit with a Raja." space_opt all has_temple(s) && has_units_enemy_faction(s) piece_opt 1 is_enemy_unit(p) && is_piece_in_event_space(p) - remove - auto_place VE ELITE + replace VE ELITE endpiece endspace @@ -545,11 +530,8 @@ EVENT 24 log_br prompt "Replace a Unit with a Raja." clean_p - piece_opt 1 (can_place_piece(0, VE, ELITE) && set_has(game.vm.m, piece_space(p)) && is_enemy_unit(p)) - set_piece_space - remove - auto_place (game.current) ELITE - set_space -1 + piece_opt 1 (set_has(game.vm.m, piece_space(p)) && is_enemy_unit(p)) + replace (game.current) ELITE endpiece SHADED 24 @@ -706,10 +688,7 @@ EVENT 32 remove_influence (other_rebel_faction(game.current)) prompt `Replace up to 2 ${PIECE_FACTION_TYPE_NAME[game.current][ELITE]}s with 2 ${PIECE_FACTION_TYPE_NAME[other_rebel_faction(game.current)][ELITE]}s.` piece_opt 2 is_enemy_piece(p) && is_rebel_faction_elite(p) && is_piece_on_map(p) - set_piece_space - remove - auto_place (game.current) ELITE - set_space -1 + replace (game.current) ELITE endpiece SHADED 32 @@ -1904,8 +1904,9 @@ function init_decree(type) { } game.decree = { spaces: [], + pieces: [], + type: type, } - game.decree.type = type } function init_free_decree(type, s) { @@ -2006,11 +2007,8 @@ function can_start_campaign_in_space(s) { function goto_campaign() { init_decree("Campaign") - game.decree = { - campaign: [], - pieces: [], - selected: [] - } + game.decree.campaign = [] + game.decree.selected = [] game.state = "campaign" } @@ -2320,7 +2318,6 @@ function can_conspire_in_space(s) { function goto_conspire() { init_decree("Conspire") game.decree.count = 2 - game.decree.spaces = [] game.state = "conspire" } @@ -2370,17 +2367,19 @@ function conspire_piece(p) { logi("1 " + piece_name(p)) log_br() let rebel = is_rebel(p) + let is_gov = is_governor(p) remove_piece(p) let amir = find_piece(AVAILABLE, BK, ELITE) let pp = place_piece(amir, game.decree.where) if (rebel) to_rebel(pp) game.decree.count -= 1 - game.state = "conspire" + if (is_gov) { + game.state = "rebel_or_obedient" + } else + game.state = "conspire" } states.conspire_space = { - // TODO: Make sure that the rebel status carry over - // TODO: Simply non-choices? prompt () { if (game.inf[BK] < 2) { view.prompt = "Conspire: Select a Governor to convert to an Amir." @@ -4493,6 +4492,76 @@ states.vm_place = { }, } +// VM: REPLACE + +function vm_replace() { + game.vm.rs = piece_space(game.vm.p) + remove_piece(game.vm.p) + game.state = "vm_replace" +} + +states.vm_replace = { + prompt() { + let faction = vm_operand(1) + let type = vm_operand(2) + let rebel_p = vm_operand(3) + + if (count_pieces(AVAILABLE, faction, type) > 0) { + event_prompt(`Replace with a ${rebel_p ? "Rebelling " : ""}${PIECE_FACTION_TYPE_NAME[faction][type]}?`) + gen_place_piece(faction, type) + } else { + event_prompt(`No available ${PIECE_FACTION_TYPE_NAME[faction][type]}.`) + } + + view.actions.skip = 1 + }, + piece(p) { + push_undo() + p = place_piece(p, game.vm.rs) + let rebel_p = vm_operand(3) + if (rebel_p) { + to_rebel(p) + } + log(`Replaced a ${piece_name(game.vm.p)} for a ${rebel_p ? "Rebelling " : ""}${piece_name(p)} in S${game.vm.m}.`) + + if (vm_operand(4)) + goto_rebel_or_obedient(game.vm.rs) + else + vm_next() + }, + skip: vm_next +} + +function goto_rebel_or_obedient(s) { + if (!game.decree) + game.decree = {} + game.decree.where = s + game.state = "rebel_or_obedient" +} + +states.rebel_or_obedient = { + prompt() { + event_prompt(`Obedient or Rebelling ${PIECE_FACTION_TYPE_NAME[game.current][ELITE]}.`) + + view.actions.obedient = 1 + view.actions.rebelling = 1 + }, + obedient() { + push_undo() + vm_next() + }, + rebelling() { + push_undo() + let p = find_piece(game.decree.where, game.current, ELITE) + to_rebel(p) + log(`A ${piece_name(p)} in S${game.decree.where} to Rebel.`) + if (game.vm) + vm_next() + else + game.state = "conspire" + } +} + // VM: GAIN_CAVALRY function vm_gain_cavalry() { @@ -5095,28 +5164,6 @@ states.vm_any_limited_command = { skip: vm_next } - -// VM: EVENT_4 - -function vm_event_4() { game.state = "event_4" } - -states.event_4 = { - prompt() { - event_prompt(`Obedient or Rebelling ${PIECE_FACTION_TYPE_NAME[game.current][ELITE]}.`) - - view.actions.obedient = 1 - view.actions.rebelling = 1 - }, - obedient() { - vm_next() - }, - rebelling() { - let p = find_piece(game.vm.s, game.current, ELITE) - to_rebel(p) - vm_next() - } -} - // VM: SHADED_6 function vm_shaded_6() { @@ -5254,7 +5301,7 @@ const AVAILABLE = -1 const OUT_OF_PLAY = -2 const ANY_PIECES = [ DISC, ELITE, TROOPS ] const PIECE_FACTION_TYPE_NAME = [ - [ "Qasbah", "Governor", "Troops" ], + [ "Qasbah", "Governor", "Troop" ], [ "Fort", "Amir", null ], [ "Temple", "Raja", null ], [ null, null, "Invader" ] @@ -5370,10 +5417,7 @@ CODE[4 * 2 + 0] = [ [ vm_current, REBEL_FACTIONS ], [ vm_prompt, ()=>`Replace 1 Governor with an Obedient or Rebelling ${PIECE_FACTION_TYPE_NAME[game.current][ELITE]}.` ], [ vm_piece, false, 1, 1, (p,s)=>is_governor(p) ], - [ vm_set_piece_space ], - [ vm_remove ], - [ vm_auto_place, false, 0, false, ()=>(game.current), ELITE ], - [ vm_event_4 ], + [ vm_replace, ()=>(game.current), ELITE, false, true ], [ vm_endpiece ], [ vm_return ], ] @@ -5392,11 +5436,8 @@ CODE[5 * 2 + 0] = [ [ vm_stay_eligible ], [ vm_current, REBEL_FACTIONS ], [ vm_prompt, ()=>`Replace up to 2 Delhi Sultanate Units with Rebelling ${PIECE_FACTION_TYPE_NAME[game.current][ELITE]}.` ], - [ vm_piece, true, 0, 2, (p,s)=>(is_adjacent_to_city(C_CHITTOR, piece_space(p)) && can_place_piece(piece_space(p), game.current, ELITE) && is_ds_unit(p)) ], - [ vm_set_piece_space ], - [ vm_remove ], - [ vm_auto_place, false, 0, true, ()=>(game.current), ELITE ], - [ vm_set_space, -1 ], + [ vm_piece, true, 0, 2, (p,s)=>(is_adjacent_to_city(C_CHITTOR, piece_space(p)) && is_ds_unit(p)) ], + [ vm_replace, ()=>(game.current), ELITE, true, false ], [ vm_endpiece ], [ vm_prompt, ()=>`Place a ${PIECE_FACTION_TYPE_NAME[game.current][DISC]} in Rajput Kingdoms.` ], [ vm_space, true, 0, 1, (s)=>(s === S_RAJPUT_KINGDOMS && can_place_piece(s, game.current, DISC)) ], @@ -5410,11 +5451,8 @@ CODE[5 * 2 + 1] = [ [ vm_stay_eligible ], [ vm_current, DS ], [ vm_prompt, "Replace up to 3 opposing Units adjacent to Chittor." ], - [ vm_piece, true, 0, 3, (p,s)=>(is_adjacent_to_city(C_CHITTOR, piece_space(p)) && can_place_piece(piece_space(p), DS, TROOPS) && is_enemy_piece(p)) ], - [ vm_set_piece_space ], - [ vm_remove ], - [ vm_auto_place, false, 0, false, DS, TROOPS ], - [ vm_set_space, -1 ], + [ vm_piece, true, 0, 3, (p,s)=>(is_adjacent_to_city(C_CHITTOR, piece_space(p)) && is_enemy_piece(p)) ], + [ vm_replace, DS, TROOPS, false, false ], [ vm_endpiece ], [ vm_prompt, "Place a Qasbah in Rajput Kingdoms." ], [ vm_space, true, 0, 1, (s)=>(s === S_RAJPUT_KINGDOMS && can_place_piece(s, DS, DISC)) ], @@ -5475,10 +5513,10 @@ CODE[7 * 2 + 1] = [ CODE[8 * 2 + 0] = [ [ vm_current, REBEL_FACTIONS ], [ vm_prompt, ()=>`In each Province, replace a Delhi Sultanate Unit with a ${PIECE_FACTION_TYPE_NAME[game.current][ELITE]}.` ], - [ vm_space, true, 0, 999, (s)=>(is_adjacent_to_city(C_DEVAGIRI, s) || is_adjacent_to_city(C_GULBARGA, s)) && has_ds_unit(s) && can_place_piece(s, game.current, ELITE) ], + [ vm_space, true, 0, 999, (s)=>(is_adjacent_to_city(C_DEVAGIRI, s) || is_adjacent_to_city(C_GULBARGA, s)) && has_ds_unit(s) ], + [ vm_prompt, ()=>`In each Province, replace a Delhi Sultanate Unit with a ${PIECE_FACTION_TYPE_NAME[game.current][ELITE]}.` ], [ vm_piece, false, 1, 1, (p,s)=>is_ds_unit(p) && is_piece_in_event_space(p) ], - [ vm_remove ], - [ vm_auto_place, false, 0, false, ()=>(game.current), ELITE ], + [ vm_replace, ()=>(game.current), ELITE, false, false ], [ vm_endpiece ], [ vm_endspace ], [ vm_return ], @@ -5680,11 +5718,10 @@ CODE[14 * 2 + 1] = [ CODE[15 * 2 + 0] = [ [ vm_stay_eligible ], [ vm_prompt, "Replace Governors with Rebelling Amirs in Provinces adjacent to Devagiri." ], - [ vm_piece, true, 0, 999, (p,s)=>is_adjacent_to_city(C_DEVAGIRI, piece_space(p)) && can_place_piece(piece_space(p), BK, ELITE) && is_governor(p) ], + [ vm_piece, true, 0, 999, (p,s)=>is_adjacent_to_city(C_DEVAGIRI, piece_space(p)) && is_governor(p) ], [ vm_set_piece_space ], [ vm_mark_space ], - [ vm_remove ], - [ vm_auto_place, false, 0, true, BK, ELITE ], + [ vm_replace, BK, ELITE, true, false ], [ vm_set_space, -1 ], [ vm_endpiece ], [ vm_prompt, "Remove a Tributary marker in one Province." ], @@ -5698,10 +5735,9 @@ CODE[15 * 2 + 0] = [ CODE[15 * 2 + 1] = [ [ vm_stay_eligible ], [ vm_prompt, "Replace an Amir with a Governor and place a Tributary marker in a Province adjacent to Devagiri." ], - [ vm_space, true, 1, 1, (s)=>is_adjacent_to_city(C_DEVAGIRI, s) && can_place_piece(s, DS, ELITE) && !is_tributary(s) ], + [ vm_space, true, 1, 1, (s)=>is_adjacent_to_city(C_DEVAGIRI, s) && !is_tributary(s) ], [ vm_asm, ()=>game.vm.p = find_piece(game.vm.s, BK, ELITE) ], - [ vm_remove ], - [ vm_auto_place, false, 0, false, DS, ELITE ], + [ vm_replace, DS, ELITE, false, false ], [ vm_place_tributary ], [ vm_endspace ], [ vm_return ], @@ -5794,11 +5830,8 @@ CODE[18 * 2 + 1] = [ [ vm_stay_eligible ], [ vm_current, [DS, VE] ], [ vm_prompt, ()=>`Replace an Amir with a ${PIECE_FACTION_TYPE_NAME[game.current][ELITE]}.` ], - [ vm_piece, false, 0, 1, (p,s)=>is_amir(p) && can_place_piece(s, game.current, ELITE) && is_piece_on_map(p) ], - [ vm_set_piece_space ], - [ vm_remove ], - [ vm_auto_place, false, 0, false, ()=>(game.current), ELITE ], - [ vm_set_space, -1 ], + [ vm_piece, false, 0, 1, (p,s)=>is_amir(p) && is_piece_on_map(p) ], + [ vm_replace, ()=>(game.current), ELITE, false, false ], [ vm_endpiece ], [ vm_remove_influence, BK ], [ vm_return ], @@ -5923,8 +5956,7 @@ CODE[23 * 2 + 0] = [ [ vm_prompt, "In each Province with a Temple, replace a Unit with a Raja." ], [ vm_space, true, 0, 999, (s)=>has_temple(s) && has_units_enemy_faction(s) ], [ vm_piece, false, 0, 1, (p,s)=>is_enemy_unit(p) && is_piece_in_event_space(p) ], - [ vm_remove ], - [ vm_auto_place, false, 0, false, VE, ELITE ], + [ vm_replace, VE, ELITE, false, false ], [ vm_endpiece ], [ vm_endspace ], [ vm_return ], @@ -5956,11 +5988,8 @@ CODE[24 * 2 + 0] = [ [ vm_log_br ], [ vm_prompt, "Replace a Unit with a Raja." ], [ vm_clean_p ], - [ vm_piece, false, 0, 1, (p,s)=>(can_place_piece(0, VE, ELITE) && set_has(game.vm.m, piece_space(p)) && is_enemy_unit(p)) ], - [ vm_set_piece_space ], - [ vm_remove ], - [ vm_auto_place, false, 0, false, ()=>(game.current), ELITE ], - [ vm_set_space, -1 ], + [ vm_piece, false, 0, 1, (p,s)=>(set_has(game.vm.m, piece_space(p)) && is_enemy_unit(p)) ], + [ vm_replace, ()=>(game.current), ELITE, false, false ], [ vm_endpiece ], [ vm_return ], ] @@ -6162,10 +6191,7 @@ CODE[32 * 2 + 0] = [ [ vm_remove_influence, ()=>(other_rebel_faction(game.current)) ], [ vm_prompt, ()=>`Replace up to 2 ${PIECE_FACTION_TYPE_NAME[game.current][ELITE]}s with 2 ${PIECE_FACTION_TYPE_NAME[other_rebel_faction(game.current)][ELITE]}s.` ], [ vm_piece, false, 0, 2, (p,s)=>is_enemy_piece(p) && is_rebel_faction_elite(p) && is_piece_on_map(p) ], - [ vm_set_piece_space ], - [ vm_remove ], - [ vm_auto_place, false, 0, false, ()=>(game.current), ELITE ], - [ vm_set_space, -1 ], + [ vm_replace, ()=>(game.current), ELITE, false, false ], [ vm_endpiece ], [ vm_return ], ] diff --git a/tools/gencode.js b/tools/gencode.js index b962a07..63b5994 100644 --- a/tools/gencode.js +++ b/tools/gencode.js @@ -132,6 +132,16 @@ for (let line of fs.readFileSync("events.txt", "utf-8").split("\n")) { emit([ "auto_place", false, 0, true, line[1], line[2] ]) break + case "replace": + emit([ "replace", line[1], line[2], false, false]) + break + case "replace_rebel": + emit([ "replace", line[1], line[2], true, false]) + break + case "replace_choice": + emit([ "replace", line[1], line[2], false, true]) + break + case "log": case "loge": case "prompt": |