Skip to content

Commit

Permalink
fix: his_patches
Browse files Browse the repository at this point in the history
  • Loading branch information
trevelyan committed Jan 25, 2024
1 parent e259dc0 commit 61cf971
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 54 deletions.
16 changes: 16 additions & 0 deletions lib/templates/gametemplate-src/gametemplate-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,14 @@ class GameQueue {
}

if (gmv[2] == 'push') {
if (game_self.old_fhand) {
for (let i = 0; i < game_self.old_fhand.length; i++) {
if (i == 0) { game_self.game.deck[deckidx - 1].fhand = []; }
game_self.game.deck[deckidx - 1].fhand.push(
game_self.old_fhand[i]
);
}
}
for (let i = 0; i < game_self.old_hand.length; i++) {
game_self.game.deck[deckidx - 1].hand.push(
game_self.old_hand[i]
Expand All @@ -1978,6 +1986,14 @@ class GameQueue {
);
}
} else {
if (game_self.old_fhand) {
for (let i = game_self.old_fhand.length - 1; i >= 0; i--) {
if (i == 0) { game_self.game.deck[deckidx - 1].fhand = []; }
game_self.game.deck[deckidx - 1].fhand.unshift(
game_self.old_fhand[i]
);
}
}
for (let i = game_self.old_hand.length - 1; i >= 0; i--) {
game_self.game.deck[deckidx - 1].hand.unshift(
game_self.old_hand[i]
Expand Down
119 changes: 92 additions & 27 deletions mods/his/his.js
Original file line number Diff line number Diff line change
Expand Up @@ -3377,7 +3377,7 @@ if (space.key === "bordeaux") {
if (space.units[key][i].type === "squadron") {
$('.option').off();
his_self.updateStatus("Papacy removes squadron");
his_self.addMove("remove_unit\t"+land_or_sea+"\t"+faction+"\t"+"squadron"+"\t"+spacekey+"\t"+0);
his_self.addMove("remove_unit\t"+land_or_sea+"\t"+key+"\t"+"squadron"+"\t"+spacekey+"\t"+0);
his_self.addMove("NOTIFY\tPapacy removes squadron from "+his_self.returnSpaceName(spacekey));
his_self.endTurn();
return 0;
Expand All @@ -3394,7 +3394,7 @@ if (space.key === "bordeaux") {
if (space.units[key][i].type === "squadron") {
$('.option').off();
his_self.updateStatus("Protestants remove squadron");
his_self.addMove("remove_unit\t"+land_or_sea+"\t"+faction+"\t"+"squadron"+"\t"+spacekey+"\t"+0);
his_self.addMove("remove_unit\t"+land_or_sea+"\t"+key+"\t"+"squadron"+"\t"+spacekey+"\t"+0);
his_self.addMove("NOTIFY\tProtestant removes squadron from "+his_self.returnSpaceName(spacekey));
his_self.endTurn();
return 0;
Expand Down Expand Up @@ -11340,7 +11340,7 @@ console.log("TESTING: " + JSON.stringify(space.units));
let cards = JSON.parse(mv[3]);

console.log("SHARE HAND CARDS: " + JSON.stringify(cards));
his_self.deck_overlay.render("Venetian Informant", cards);
his_self.deck_overlay.render("Venetian Informant", cards);

let p1 = his_self.returnPlayerOfFaction(faction_taking);
let p2 = his_self.returnPlayerOfFaction(faction_giving);
Expand All @@ -11360,6 +11360,8 @@ his_self.deck_overlay.render("Venetian Informant", cards);

if (mv[0] == "venetian_informant") {

his_self.game.queue.splice(qe, 1);

let faction = mv[1];
let player = his_self.returnPlayerOfFaction(faction);

Expand All @@ -11375,7 +11377,7 @@ his_self.deck_overlay.render("Venetian Informant", cards);
his_self.endTurn();
}

return;
return 0;

} else {

Expand Down Expand Up @@ -11404,10 +11406,8 @@ his_self.deck_overlay.render("Venetian Informant", cards);

}

his_self.game.queue.splice(qe, 1);
return 0;


}

return 1;
Expand Down Expand Up @@ -12083,7 +12083,12 @@ his_self.deck_overlay.render("Venetian Informant", cards);
0
);

return 1;
if (res.length > 0) {
return 1;
}

return 0;

}

isSpaceAdjacentToReligion(space, religion) {
Expand Down Expand Up @@ -12826,6 +12831,14 @@ console.log("no...");
// if transit_seas and faction is specified, we can only cross if
// there are no ports in a zone with non-faction ships.
//
returnNeighboursAsArrayOfKeys(space, transit_passes=1, transit_seas=0, faction="") {
let res = [];
let x = this.returnNeighbours(space, transit_passes, transit_seas, faction);
for (let i = 0; i < x.length; i++) {
res.push(x[i].neighbour);
}
return res;
}
returnNeighbours(space, transit_passes=1, transit_seas=0, faction="") {

let is_naval_space = false;
Expand All @@ -12837,13 +12850,17 @@ console.log("no...");

if (transit_seas == 0 && is_naval_space != true) {
if (transit_passes == 1) {
return space.neighbours;
let res = [];
for (let z = 0; z < space.neighbours.length; z++) {
res.push({ neighbour : space.neighbours[z] , overseas : false });
}
return res;
}
let neighbours = [];
for (let i = 0; i < space.neighbours.length; i++) {
let x = space.neighbours[i];
if (!space.pass.includes[x]) {
neighbours.push(x);
neighbours.push({ neighbour : x , overseas : false });
}
}
return neighbours;
Expand All @@ -12852,13 +12869,16 @@ console.log("no...");
let neighbours = [];

if (transit_passes == 1 && is_naval_space != true) {
neighbours = JSON.parse(JSON.stringify(space.neighbours));
neighbours = [];
for (let z = 0; z < space.neighbours.length; z++) {
neighbours.push({ neighbour : space.neighbours[z] , overseas : false });
}
} else {
for (let i = 0; i < space.neighbours.length; i++) {
let x = space.neighbours[i];
if (is_naval_space != true) {
if (!space.pass.includes[x]) {
neighbours.push(x);
neighbours.push({ neighbour : x , overseas : false });
}
}
}
Expand Down Expand Up @@ -12888,8 +12908,14 @@ console.log("no...");
}
}
for (let z = 0; z < navalspace.ports.length; z++) {
if (!neighbours.includes(navalspace.ports[z]) && any_unfriendly_ships == false) {
neighbours.push(navalspace.ports[z]);
let already_listed = false;
for (let zz = 0; zz < neighbours.length; zz++) {
if (neighbours[zz].neighbour === navalspace.ports[z]) {
already_listed = true;
}
}
if (already_listed == false && any_unfriendly_ships == false) {
neighbours.push({ neighbour : navalspace.ports[z] , overseas : true });
};
}
}
Expand Down Expand Up @@ -13099,10 +13125,21 @@ console.log("searching for: " + sourcekey);
//
// put the neighbours into pending
//
//let n = this.returnNeighboursAsArrayOfKeys(sourcekey, transit_passes, transit_seas, faction);
let n = this.returnNeighbours(sourcekey, transit_passes, transit_seas, faction);


if (sourcekey === "candia") {

console.log("^");
console.log("^");
console.log("^ NEIGHBOURS ");
console.log(JSON.stringify(n));

}

for (let i = 0; i < n.length; i++) {
pending_spaces[n[i]] = { hops : 0 , key : n[i] };
pending_spaces[n[i].neighbour] = { hops : 0 , key : n[i] , overseas : n[i].overseas };
}

//
Expand All @@ -13111,6 +13148,10 @@ console.log("searching for: " + sourcekey);
let continue_searching = 1;
while (continue_searching) {

if (sourcekey === "candia") {
console.log("loop: " + JSON.stringify(pending_spaces));
}

let count = 0;
for (let key in pending_spaces) {

Expand All @@ -13119,7 +13160,7 @@ console.log("searching for: " + sourcekey);

if (destination_filter(key)) {
// found results? this is last pass
results.push({ hops : (hops+1) , key : key });
results.push({ hops : (hops+1) , key : key , overseas : pending_spaces[key].overseas });
continue_searching = 0;
if (searched_spaces[key]) {
// we've searched for this before
Expand All @@ -13128,26 +13169,36 @@ console.log("searching for: " + sourcekey);
}
} else {
if (propagation_filter(key)) {
for (let i = 0; i < this.game.spaces[key].neighbours.length; i++) {
if (searched_spaces[this.game.spaces[key].neighbours[i]]) {
let nn = [];
if (pending_spaces[key].overseas) {
nn = this.returnNeighbours(key, transit_passes, 0, faction);
} else {
nn = this.returnNeighbours(key, transit_passes, 1, faction);
}
for (let i = 0; i < nn.length; i++) {
if (searched_spaces[nn[i].neighbour]) {
// don't add to pending as we've transversed before
} else {
pending_spaces[this.game.spaces[key].neighbours[i]] = { hops : (hops+1) , key : this.game.spaces[key].neighbours[i] };
pending_spaces[nn[i].neighbour] = { hops : (hops+1) , key : this.game.spaces[key].neighbours[i] , overseas : nn[i].overseas };
}
}
}
searched_spaces[key] = { hops : (hops+1) , key : key };
searched_spaces[key] = { hops : (hops+1) , key : key , overseas : 0 };
}
delete pending_spaces[key];

}

if (count == 0) {
continue_searching = 0;
for (let newkey in pending_spaces) {
if (pending_spaces[newkey]) { continue_searching = 1; }
}
}
}
if (sourcekey == "candia") {
console.log(JSON.stringify(results));
}


//
// at this point we have results or not
Expand Down Expand Up @@ -17731,8 +17782,8 @@ if (this.game.state.scenario != "is_testing") {
this.addNavalSquadron("france", "genoa", 4);


//this.addCard("papacy", "105");
this.addCard("protestant", "031");
this.addCard("papacy", "109");
// this.addCard("protestant", "031");

this.game.queue.splice(qe, 1);

Expand Down Expand Up @@ -18490,7 +18541,7 @@ console.log("NO-ONE BUT US, ADD ALLY CHECK!");
let attacker_comes_from_this_spacekey = mv[3];
this.game.state.attacker_comes_from_this_spacekey = mv[3];
let space = this.game.spaces[spacekey];
let neighbours = this.returnNeighbours(spacekey, 0); // 0 cannot intercept across passes
let neighbours = this.returnNeighboursAsArrayOfKeys(spacekey, 0); // 0 cannot intercept across passes
let attacking_player = this.returnPlayerOfFaction(attacker);

let io = this.returnImpulseOrder();
Expand Down Expand Up @@ -18551,7 +18602,7 @@ console.log("NO-ONE BUT US, ADD ALLY CHECK!");
if (this.game.spaces[spacekey]) { space = this.game.spaces[spacekey]; }
if (this.game.navalspaces[spacekey]) { space = this.game.spaces[spacekey]; }

let neighbours = this.returnNeighbours(spacekey, 0); // 0 cannot intercept across passes
let neighbours = this.returnNeighboursAsArrayOfKeys(spacekey, 0); // 0 cannot intercept across passes
let attacking_player = this.returnPlayerOfFaction(attacker);

let io = this.returnImpulseOrder();
Expand Down Expand Up @@ -18735,7 +18786,7 @@ console.log("NO-ONE BUT US, ADD ALLY CHECK!");
let includes_cavalry = parseInt(mv[3]);

let space = this.game.spaces[spacekey];
let neighbours = this.returnNeighbours(spacekey, 0); // 0 cannot intercept across passes
let neighbours = this.returnNeighboursAsArrayOfKeys(spacekey, 0); // 0 cannot intercept across passes

let attacking_player = this.returnPlayerCommandingFaction(faction);

Expand Down Expand Up @@ -23929,6 +23980,11 @@ console.log(JSON.stringify(this.game.state.players_info[i].factions));

if (mv[0] === "card_draw_phase") {

console.log("###");
console.log("###");
console.log("###");
console.log("Cards in Hand: " + JSON.stringify(this.game.deck[0].fhand));

//
// deal cards and add home card
//
Expand Down Expand Up @@ -25063,6 +25119,11 @@ console.log("RESHUFFLE: " + JSON.stringify(reshuffle_cards));

if (this.game.player == player) {

console.log("$$$");
console.log("$$$");
console.log("$$$");
console.log("fhand: " + JSON.stringify(this.game.deck[deckidx].fhand));

if (!this.game.deck[deckidx].fhand) { this.game.deck[deckidx].fhand = []; }
while (this.game.deck[deckidx].fhand.length < (fhand_idx+1)) { this.game.deck[deckidx].fhand.push([]); }

Expand Down Expand Up @@ -29678,8 +29739,11 @@ return;
for (let z = 0; removed_space == false && z < ns.length; z++) {
let n = his_self.game.spaces[ns[z]];
if (his_self.returnHostileLandUnitsInSpace(faction, n) > 0) {
conquerable_spaces.splice(i, 1); // remove
removed_space = true;
// unless we are there
if (his_self.returnFactionLandUnitsInSpace(faction, conquerable_spaces[i]) > 0) {} else {
conquerable_spaces.splice(i, 1); // remove
removed_space = true;
}
}
}
}
Expand Down Expand Up @@ -29880,6 +29944,7 @@ return;
$('.option').on('click', function () {

let id = parseInt($(this).attr("id"));
his_self.updateStatus("selecting...");
his_self.language_zone_overlay.hide();

if (id == 1 || id == 4) {
Expand Down
12 changes: 6 additions & 6 deletions mods/his/src/his-cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ if (space.key === "bordeaux") {
if (space.units[key][i].type === "squadron") {
$('.option').off();
his_self.updateStatus("Papacy removes squadron");
his_self.addMove("remove_unit\t"+land_or_sea+"\t"+faction+"\t"+"squadron"+"\t"+spacekey+"\t"+0);
his_self.addMove("remove_unit\t"+land_or_sea+"\t"+key+"\t"+"squadron"+"\t"+spacekey+"\t"+0);
his_self.addMove("NOTIFY\tPapacy removes squadron from "+his_self.returnSpaceName(spacekey));
his_self.endTurn();
return 0;
Expand All @@ -407,7 +407,7 @@ if (space.key === "bordeaux") {
if (space.units[key][i].type === "squadron") {
$('.option').off();
his_self.updateStatus("Protestants remove squadron");
his_self.addMove("remove_unit\t"+land_or_sea+"\t"+faction+"\t"+"squadron"+"\t"+spacekey+"\t"+0);
his_self.addMove("remove_unit\t"+land_or_sea+"\t"+key+"\t"+"squadron"+"\t"+spacekey+"\t"+0);
his_self.addMove("NOTIFY\tProtestant removes squadron from "+his_self.returnSpaceName(spacekey));
his_self.endTurn();
return 0;
Expand Down Expand Up @@ -8353,7 +8353,7 @@ console.log("TESTING: " + JSON.stringify(space.units));
let cards = JSON.parse(mv[3]);

console.log("SHARE HAND CARDS: " + JSON.stringify(cards));
his_self.deck_overlay.render("Venetian Informant", cards);
his_self.deck_overlay.render("Venetian Informant", cards);

let p1 = his_self.returnPlayerOfFaction(faction_taking);
let p2 = his_self.returnPlayerOfFaction(faction_giving);
Expand All @@ -8373,6 +8373,8 @@ his_self.deck_overlay.render("Venetian Informant", cards);

if (mv[0] == "venetian_informant") {

his_self.game.queue.splice(qe, 1);

let faction = mv[1];
let player = his_self.returnPlayerOfFaction(faction);

Expand All @@ -8388,7 +8390,7 @@ his_self.deck_overlay.render("Venetian Informant", cards);
his_self.endTurn();
}

return;
return 0;

} else {

Expand Down Expand Up @@ -8417,10 +8419,8 @@ his_self.deck_overlay.render("Venetian Informant", cards);

}

his_self.game.queue.splice(qe, 1);
return 0;


}

return 1;
Expand Down
Loading

0 comments on commit 61cf971

Please sign in to comment.