refactor(engine): eliminate duplicated presets and constants (single source of truth)

- Define BLOOD_MOOR_RIVER_PRESETS and BLOOD_MOOR_POND_PRESETS to make SPECIAL_PRESETS_BY_LEVEL[2] canonical and eliminate inline duplicates
- Import PACK_RADIUS_PX from monster-rooms.ts in combat.ts to establish a single source of truth
- Replace literal * 5 with * SUB_TILES_PER_TILE in wilderness-acts.ts

TAG=agy
CONV=2a1934de-30ef-464e-b3f3-fcbcdbbc49f1
This commit is contained in:
troytt 2026-09-17 15:50:24 +00:00
parent cbcf71a731
commit bd7486cc99
3 changed files with 39 additions and 56 deletions

View File

@ -27,6 +27,7 @@ import {
partitionMapIntoRooms,
spawnMonsterPacksByRooms,
spawnPacksInRoom,
PACK_RADIUS_PX,
} from './monster-rooms.ts'
import type { MapRoom } from './monster-rooms.ts'
@ -453,14 +454,7 @@ export interface MonsterPack {
readonly superUniqueId?: string
}
/**
* How far a pack's members sit from their camp centre, in pixels.
*
* Two cells across. A pack has to read as one thing from the player's distance
* — close enough that pulling one pulls the rest, far enough that the sprites
* do not overlap. A cell is 80 wide, and a monster body is about 20.
*/
const PACK_RADIUS_PX = 96
function isInsideSafeZone(x: number, y: number, safeZones: readonly SafeZone[] | undefined): boolean {
if (safeZones === undefined || safeZones.length === 0) return false

View File

@ -22,6 +22,7 @@ import type {
PlacedPresetRect,
} from './wilderness.ts'
import { stampDs1, TILES_PER_BLOCK, emptyFloor, emptyWall } from './wilderness.ts'
import { SUB_TILES_PER_TILE } from './map.ts'
/* ------------------------------------------------------------------------- *
* Statistics interfaces
@ -344,8 +345,8 @@ export function initAct2OutdoorLevel(
canvas.objects.push({
type: 2,
id: 66 + i,
x: (tc.x + 3) * 5,
y: (tc.y + 3) * 5,
x: (tc.x + 3) * SUB_TILES_PER_TILE,
y: (tc.y + 3) * SUB_TILES_PER_TILE,
flags: 0,
})
tombEntrances += 1
@ -369,8 +370,8 @@ export function initAct2OutdoorLevel(
canvas.objects.push({
type: 2,
id: 74,
x: (warpX + 4) * 5,
y: (warpY + 4) * 5,
x: (warpX + 4) * SUB_TILES_PER_TILE,
y: (warpY + 4) * SUB_TILES_PER_TILE,
flags: 0,
})
}

View File

@ -2560,22 +2560,38 @@ function applySubstitutions(
* landmarks: the fallen bivouac camp, the pond, the cow corral, and swamp/stone
* fills.
*/
export const BLOOD_MOOR_RIVER_PRESETS: readonly string[] = [
'Act 1 - DOE Entrance',
'Act 1 - River Upper',
'Act 1 - River Lower',
'Act 1 - Bridge',
'Act 1 - Fence Fill 1',
'Act 1 - Fence Fill 3',
'Act 1 - Ruin',
'Act 1 - Cottages 1',
'Act 1 - Corral Fill',
'Act 1 - Fence Fill 4',
'Act 1 - Fence Fill 5',
'Act 1 - Stone Fill 1',
'Act 1 - Stone Fill 2',
]
export const BLOOD_MOOR_POND_PRESETS: readonly string[] = [
'Act 1 - DOE Entrance',
'Act 1 - Pond',
'Act 1 - Fence Fill 1',
'Act 1 - Fence Fill 3',
'Act 1 - Ruin',
'Act 1 - Cottages 1',
'Act 1 - Corral Fill',
'Act 1 - Fence Fill 4',
'Act 1 - Fence Fill 5',
'Act 1 - Stone Fill 1',
'Act 1 - Stone Fill 2',
]
export const SPECIAL_PRESETS_BY_LEVEL: Readonly<Record<number, readonly string[]>> = {
2: [
'Act 1 - DOE Entrance',
'Act 1 - River Upper',
'Act 1 - River Lower',
'Act 1 - Bridge',
'Act 1 - Fence Fill 1',
'Act 1 - Fence Fill 3',
'Act 1 - Ruin',
'Act 1 - Cottages 1',
'Act 1 - Corral Fill',
'Act 1 - Fence Fill 4',
'Act 1 - Fence Fill 5',
'Act 1 - Stone Fill 1',
'Act 1 - Stone Fill 2',
],
2: BLOOD_MOOR_RIVER_PRESETS,
3: [
'Act 1 - Cave Entrance',
'Act 1 - Fallen Camp Bishibosh',
@ -5375,35 +5391,7 @@ export function generateWilderness(request: WildernessRequest): WildernessResult
if (request.levelId === 2) {
// Blood Moor has a chance (50%) of spawning river water + bridge, or pond
const hasRiver = rng.int(0, 1) === 0
specialPresetNames = hasRiver
? [
'Act 1 - DOE Entrance',
'Act 1 - River Upper',
'Act 1 - River Lower',
'Act 1 - Bridge',
'Act 1 - Fence Fill 1',
'Act 1 - Fence Fill 3',
'Act 1 - Ruin',
'Act 1 - Cottages 1',
'Act 1 - Corral Fill',
'Act 1 - Fence Fill 4',
'Act 1 - Fence Fill 5',
'Act 1 - Stone Fill 1',
'Act 1 - Stone Fill 2',
]
: [
'Act 1 - DOE Entrance',
'Act 1 - Pond',
'Act 1 - Fence Fill 1',
'Act 1 - Fence Fill 3',
'Act 1 - Ruin',
'Act 1 - Cottages 1',
'Act 1 - Corral Fill',
'Act 1 - Fence Fill 4',
'Act 1 - Fence Fill 5',
'Act 1 - Stone Fill 1',
'Act 1 - Stone Fill 2',
]
specialPresetNames = hasRiver ? BLOOD_MOOR_RIVER_PRESETS : BLOOD_MOOR_POND_PRESETS
} else {
specialPresetNames = SPECIAL_PRESETS_BY_LEVEL[request.levelId] ?? []
}