Ceremonial PR: fix map gen #39
| @@ -274,12 +274,14 @@ export class Grid<T> { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   #invalidPosition(position: Point): boolean { |   #invalidPosition(position: Point): boolean { | ||||||
|     return position.x < 0 || |     return ( | ||||||
|  |       position.x < 0 || | ||||||
|       position.x >= this.size.w || |       position.x >= this.size.w || | ||||||
|       Math.floor(position.x) != position.x || |       Math.floor(position.x) != position.x || | ||||||
|       position.y < 0 || |       position.y < 0 || | ||||||
|       position.y >= this.size.h || |       position.y >= this.size.h || | ||||||
|       Math.floor(position.y) != position.y;; |       Math.floor(position.y) != position.y | ||||||
|  |     ); | ||||||
|   } |   } | ||||||
|   #checkPosition(position: Point) { |   #checkPosition(position: Point) { | ||||||
|     if (this.#invalidPosition(position)) { |     if (this.#invalidPosition(position)) { | ||||||
|   | |||||||
| @@ -108,7 +108,7 @@ class Knife { | |||||||
|               if (typeof resolved === "number") { |               if (typeof resolved === "number") { | ||||||
|                 r = resolved; |                 r = resolved; | ||||||
|               } else { |               } else { | ||||||
|                 errors.push(`${loc} is region ${r}, not found in merged`) |                 errors.push(`${loc} is region ${r}, not found in merged`); | ||||||
|               } |               } | ||||||
|               if (r < 0) { |               if (r < 0) { | ||||||
|                 return "!"; |                 return "!"; | ||||||
| @@ -569,7 +569,10 @@ function connectRegions(knife: Knife) { | |||||||
|     let sources: number[] = dedup(basicRegions.map((i) => merged[i])); |     let sources: number[] = dedup(basicRegions.map((i) => merged[i])); | ||||||
|     let dest: number | undefined = sources.pop(); |     let dest: number | undefined = sources.pop(); | ||||||
|     if (dest == undefined) { |     if (dest == undefined) { | ||||||
|       throw new BadMapError(`each connector should touch more than one region but ${connector} does not`, knife.map); |       throw new BadMapError( | ||||||
|  |         `each connector should touch more than one region but ${connector} does not`, | ||||||
|  |         knife.map, | ||||||
|  |       ); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (Math.random() > EXTRA_CONNECTOR_CHANCE) { |     if (Math.random() > EXTRA_CONNECTOR_CHANCE) { | ||||||
|   | |||||||
| @@ -114,7 +114,7 @@ export class LoadedNewMap { | |||||||
|     const found: Point | null = (() => { |     const found: Point | null = (() => { | ||||||
|       for (let x = 0; x < size.w; x++) { |       for (let x = 0; x < size.w; x++) { | ||||||
|         for (let y = 0; y < size.w; y++) { |         for (let y = 0; y < size.w; y++) { | ||||||
|           const p = new Point(x, y) |           const p = new Point(x, y); | ||||||
|           if (this.#architecture.get(p) == Architecture.Floor) { |           if (this.#architecture.get(p) == Architecture.Floor) { | ||||||
|             return p; |             return p; | ||||||
|           } |           } | ||||||
| @@ -124,7 +124,7 @@ export class LoadedNewMap { | |||||||
|     })(); |     })(); | ||||||
|     if (found === null) { |     if (found === null) { | ||||||
|       // technically, all open floors on the map are indeed connected |       // technically, all open floors on the map are indeed connected | ||||||
|       return true |       return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     let stack: Point[] = [found]; |     let stack: Point[] = [found]; | ||||||
| @@ -132,7 +132,10 @@ export class LoadedNewMap { | |||||||
|     while (stack.length > 0) { |     while (stack.length > 0) { | ||||||
|       const loc = stack.pop() as Point; |       const loc = stack.pop() as Point; | ||||||
|       for (var p of loc.neighbors()) { |       for (var p of loc.neighbors()) { | ||||||
|         if ((this.#architecture.maybeGet(p) === Architecture.Floor) && !reached.get(p)) { |         if ( | ||||||
|  |           this.#architecture.maybeGet(p) === Architecture.Floor && | ||||||
|  |           !reached.get(p) | ||||||
|  |         ) { | ||||||
|           reached.set(p, true); |           reached.set(p, true); | ||||||
|           stack.push(p); |           stack.push(p); | ||||||
|         } |         } | ||||||
| @@ -141,8 +144,11 @@ export class LoadedNewMap { | |||||||
|  |  | ||||||
|     for (let x = 0; x < size.w; x++) { |     for (let x = 0; x < size.w; x++) { | ||||||
|       for (let y = 0; y < size.w; y++) { |       for (let y = 0; y < size.w; y++) { | ||||||
|         const p = new Point(x, y) |         const p = new Point(x, y); | ||||||
|         if (this.#architecture.get(p) == Architecture.Floor && !reached.get(p)) { |         if ( | ||||||
|  |           this.#architecture.get(p) == Architecture.Floor && | ||||||
|  |           !reached.get(p) | ||||||
|  |         ) { | ||||||
|           return false; |           return false; | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user