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