fix(game): import canonical SUB_TILES_PER_TILE and use dynamic bounds/stride in siege

- Import canonical SUB_TILES_PER_TILE from map.ts in maze-objects.ts and level-links.ts
- Replace hardcoded y < 6 || y > 42 bounds with dynamic canvas.height - 6 bounds in wilderness-siege.ts
- Replace static i * 16 stride assumption with dynamic ds1.width and canvas.width stride

TAG=agy
CONV=2a1934de-30ef-464e-b3f3-fcbcdbbc49f1
This commit is contained in:
troytt 2026-09-17 14:09:31 +00:00
parent 955e9edbb1
commit 8ee3a4c971
3 changed files with 24 additions and 11 deletions

View File

@ -34,9 +34,7 @@
*/
import type { Side } from './world-graph.ts'
/** Sub-tiles per cell, matching `SUB_TILES_PER_TILE` in `map.ts`. */
const SUB_TILES_PER_TILE = 5
import { SUB_TILES_PER_TILE } from './map.ts'
/**
* How close the player must be to a border seam for it to fire, in sub-tiles.

View File

@ -20,8 +20,10 @@
import type { Ds1, Ds1Cell, Ds1Object } from '../formats/ds1.ts'
import { Rng } from './rng.ts'
import { SUB_TILES_PER_TILE } from './map.ts'
/** Subtiles per DS1 cell. */
export const SUB_TILES_PER_TILE = 5
export { SUB_TILES_PER_TILE }
/** Dynamic dungeon object categories. */
export type MazeObjectCategory = 'shrine' | 'chest' | 'rack' | 'container'

View File

@ -111,7 +111,7 @@ function stampTrench(
if (orientation === 'vertical') {
for (let dy = 0; dy < length; dy += 1) {
const y = startY + dy
if (y < 6 || y > 42) continue
if (y < 6 || y > canvas.height - 6) continue
for (let dx = 0; dx < width; dx += 1) {
const x = startX + dx
if (x < 4 || x >= canvas.width - 4) continue
@ -133,7 +133,7 @@ function stampTrench(
if (x < 4 || x >= canvas.width - 4) continue
for (let dy = 0; dy < width; dy += 1) {
const y = startY + dy
if (y < 6 || y > 42) continue
if (y < 6 || y > canvas.height - 6) continue
setFloor(canvas, x, y, {
style: 5,
sequence: rng.int(0, 5),
@ -169,7 +169,7 @@ function stampBreachedBarricade(
for (let dy = 0; dy < length; dy += 1) {
const y = startY + dy
if (y < 6 || y > 42) continue
if (y < 6 || y > canvas.height - 6) continue
if (y >= breachY && y < breachY + breachHeight) {
// Traversable breach gap: clear walls and trample floor
@ -226,7 +226,7 @@ function stampCatapultPlatform(
): void {
for (let dy = 0; dy < height; dy += 1) {
const y = originY + dy
if (y < 6 || y > 42) continue
if (y < 6 || y > canvas.height - 6) continue
for (let dx = 0; dx < width; dx += 1) {
const x = originX + dx
if (x < 4 || x >= canvas.width - 4) continue
@ -273,7 +273,7 @@ function stampFortRuin(
): void {
for (let dy = 0; dy < size; dy += 1) {
const y = originY + dy
if (y < 6 || y > 42) continue
if (y < 6 || y > canvas.height - 6) continue
for (let dx = 0; dx < size; dx += 1) {
const x = originX + dx
if (x < 4 || x >= canvas.width - 4) continue
@ -371,12 +371,25 @@ export function stampAct5SiegeStrips(
const placed = new Set<string>()
// 1. Assemble 15 strips West (x=0) to East (x=224)
const dynamicStripStride = canvas.width > 0
? Math.floor(canvas.width / ACT5_SIEGE_STRIP_NAMES.length)
: 16
let currentX = 0
for (let i = 0; i < ACT5_SIEGE_STRIP_NAMES.length; i += 1) {
const targetName = ACT5_SIEGE_STRIP_NAMES[i]!
const selection = selectStripPiece(pieces, targetName, i, rng)
if (!selection) continue
if (!selection) {
currentX += dynamicStripStride
continue
}
stampDs1(canvas, selection.ds1, i * 16, 0)
// DS1 tiles often include a +1 border overlap column (e.g. 17 width for 16 stride)
const ds1Width = selection.ds1.width
const stripStride = ds1Width > 0
? (ds1Width % 16 === 1 ? ds1Width - 1 : ds1Width)
: dynamicStripStride
stampDs1(canvas, selection.ds1, currentX, 0)
currentX += stripStride
placed.add(selection.piece.name)
stats.substitutions.push({
name: selection.piece.name,