Revert "Logging for the tunnel digger"

This reverts commit 6f0f1fd337.
This commit is contained in:
Eryn Wells 2023-02-04 18:18:52 -08:00
parent 6f0f1fd337
commit 3c25f2041a

View file

@ -360,8 +360,6 @@ class TunnelGenerator {
let fromRoom = rooms[i]; let fromRoom = rooms[i];
let toRoom = rooms[i + offset]; let toRoom = rooms[i + offset];
console.log(`Connecting rooms ${i} to ${i + offset}:`, fromRoom.bounds, toRoom.bounds);
let [fromPoint, toPoint] = this.#findPointFromRoomToRoom(fromRoom, toRoom); let [fromPoint, toPoint] = this.#findPointFromRoomToRoom(fromRoom, toRoom);
for (let neighbor of fromPoint.neighbors()) { for (let neighbor of fromPoint.neighbors()) {
@ -433,87 +431,60 @@ class TunnelGenerator {
let steps = 0; let steps = 0;
while (curX !== toX || curY !== toY) { while (curX !== toX || curY !== toY) {
if (steps++ > MAX_STEPS) { if (steps++ > MAX_STEPS) {
console.log("Exceeded max step count for this corridor");
return false; return false;
} }
curX += dx; curX += dx;
curY += dy; curY += dy;
console.groupCollapsed(`${steps}: (${curX}, ${curY})`);
console.log(`dx = ${dx}, dy = ${dy}`);
if (curX >= this.#grid.width - 1 || curX <= 0 || curY <= 0 || curY >= this.#grid.height - 1) { if (curX >= this.#grid.width - 1 || curX <= 0 || curY <= 0 || curY >= this.#grid.height - 1) {
console.error(`Out of bounds: (${curX}, ${curY})`);
console.groupEnd();
return false; return false;
} }
let cell = this.#grid.cellAt(curX, curY); let cell = this.#grid.cellAt(curX, curY);
if (cell.isEmpty()) { if (cell.isEmpty()) {
console.log("Digging corridor");
cell.corridor(); cell.corridor();
} else if (!cell.isCorridor()) { } else if (!cell.isCorridor()) {
console.error("Found a weird cell type:", cell.character);
console.groupEnd();
return false; return false;
} }
let dix = Math.abs(curX - toX); let dix = Math.abs(curX - toX);
let diy = Math.abs(curY - toY); let diy = Math.abs(curY - toY);
console.log(`1. dix = ${dix}, diy = ${diy}`);
if (dix > diy && diy) { if (dix > diy && diy) {
const random = randomInt(dix - diy + 1); const random = randomInt(dix - diy + 1);
console.log(`Randomness: ${random}`);
if (!random) { if (!random) {
dix = 0; dix = 0;
} }
} else if (diy > dix && dix) { } else if (diy > dix && dix) {
const random = randomInt(dix - diy + 1); const random = randomInt(dix - diy + 1);
console.log(`Randomness: ${random}`);
if (!random) { if (!random) {
diy = 0; diy = 0;
} }
} }
console.log(`2. dix = ${dix}, diy = ${diy}`);
if (dy && dix > diy) { if (dy && dix > diy) {
const ddx = curX > toX ? -1 : 1; const ddx = curX > toX ? -1 : 1;
console.log(`ddx = ${ddx}`);
let cell = this.#grid.cellAt(curX + ddx, curY); let cell = this.#grid.cellAt(curX + ddx, curY);
console.log(`Checking cell at (${curX + ddx}, ${curY})`, cell.character);
if (cell.isEmpty() || cell.isCorridor()) { if (cell.isEmpty() || cell.isCorridor()) {
dx = ddx; dx = ddx;
dy = 0; dy = 0;
console.log(`Adjusted dx = ${dx}, dy = ${dy}`);
console.groupEnd();
continue; continue;
} }
} else if (dx && diy > dix) { } else if (dx && diy > dix) {
const ddy = curY > toY ? -1 : 1; const ddy = curY > toY ? -1 : 1;
console.log(`ddy = ${ddy}`);
let cell = this.#grid.cellAt(curX, curY + ddy); let cell = this.#grid.cellAt(curX, curY + ddy);
console.log(`Checking cell at (${curX}, ${curY + ddy})`, cell.character);
if (cell.isEmpty() || cell.isCorridor()) { if (cell.isEmpty() || cell.isCorridor()) {
dy = ddy; dy = ddy;
dx = 0; dx = 0;
console.log(`Adjusted dx = ${dx}, dy = ${dy}`);
console.groupEnd();
continue; continue;
} }
} }
cell = this.#grid.cellAt(curX + dx, curY + dy); cell = this.#grid.cellAt(curX + dx, curY + dy);
console.log(`2. Checking cell at (${curX + dx}, ${curY + dy})`, cell.character);
if (cell.isEmpty() || cell.isCorridor()) { if (cell.isEmpty() || cell.isCorridor()) {
console.groupEnd();
continue; continue;
} }
@ -525,20 +496,13 @@ class TunnelGenerator {
dx = toX < curX ? -1 : 1; dx = toX < curX ? -1 : 1;
} }
console.log(`Adjusting dx = ${dx}, dy = ${dy}`);
cell = this.#grid.cellAt(curX + dx, curY + dy); cell = this.#grid.cellAt(curX + dx, curY + dy);
console.log(`3. Checking cell at (${curX + dx}, ${curY + dy})`, cell.character);
if (cell.isEmpty() || cell.isCorridor()) { if (cell.isEmpty() || cell.isCorridor()) {
console.groupEnd();
continue; continue;
} }
dy = -dy; dy = -dy;
dx = -dx; dx = -dx;
console.log(`Adjusting dx = ${dx}, dy = ${dy}`);
console.groupEnd();
} }
return true; return true;