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:
parent
cbcf71a731
commit
bd7486cc99
|
|
@ -27,6 +27,7 @@ import {
|
||||||
partitionMapIntoRooms,
|
partitionMapIntoRooms,
|
||||||
spawnMonsterPacksByRooms,
|
spawnMonsterPacksByRooms,
|
||||||
spawnPacksInRoom,
|
spawnPacksInRoom,
|
||||||
|
PACK_RADIUS_PX,
|
||||||
} from './monster-rooms.ts'
|
} from './monster-rooms.ts'
|
||||||
import type { MapRoom } from './monster-rooms.ts'
|
import type { MapRoom } from './monster-rooms.ts'
|
||||||
|
|
||||||
|
|
@ -453,14 +454,7 @@ export interface MonsterPack {
|
||||||
readonly superUniqueId?: string
|
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 {
|
function isInsideSafeZone(x: number, y: number, safeZones: readonly SafeZone[] | undefined): boolean {
|
||||||
if (safeZones === undefined || safeZones.length === 0) return false
|
if (safeZones === undefined || safeZones.length === 0) return false
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import type {
|
||||||
PlacedPresetRect,
|
PlacedPresetRect,
|
||||||
} from './wilderness.ts'
|
} from './wilderness.ts'
|
||||||
import { stampDs1, TILES_PER_BLOCK, emptyFloor, emptyWall } from './wilderness.ts'
|
import { stampDs1, TILES_PER_BLOCK, emptyFloor, emptyWall } from './wilderness.ts'
|
||||||
|
import { SUB_TILES_PER_TILE } from './map.ts'
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- *
|
/* ------------------------------------------------------------------------- *
|
||||||
* Statistics interfaces
|
* Statistics interfaces
|
||||||
|
|
@ -344,8 +345,8 @@ export function initAct2OutdoorLevel(
|
||||||
canvas.objects.push({
|
canvas.objects.push({
|
||||||
type: 2,
|
type: 2,
|
||||||
id: 66 + i,
|
id: 66 + i,
|
||||||
x: (tc.x + 3) * 5,
|
x: (tc.x + 3) * SUB_TILES_PER_TILE,
|
||||||
y: (tc.y + 3) * 5,
|
y: (tc.y + 3) * SUB_TILES_PER_TILE,
|
||||||
flags: 0,
|
flags: 0,
|
||||||
})
|
})
|
||||||
tombEntrances += 1
|
tombEntrances += 1
|
||||||
|
|
@ -369,8 +370,8 @@ export function initAct2OutdoorLevel(
|
||||||
canvas.objects.push({
|
canvas.objects.push({
|
||||||
type: 2,
|
type: 2,
|
||||||
id: 74,
|
id: 74,
|
||||||
x: (warpX + 4) * 5,
|
x: (warpX + 4) * SUB_TILES_PER_TILE,
|
||||||
y: (warpY + 4) * 5,
|
y: (warpY + 4) * SUB_TILES_PER_TILE,
|
||||||
flags: 0,
|
flags: 0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2560,22 +2560,38 @@ function applySubstitutions(
|
||||||
* landmarks: the fallen bivouac camp, the pond, the cow corral, and swamp/stone
|
* landmarks: the fallen bivouac camp, the pond, the cow corral, and swamp/stone
|
||||||
* fills.
|
* 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[]>> = {
|
export const SPECIAL_PRESETS_BY_LEVEL: Readonly<Record<number, readonly string[]>> = {
|
||||||
2: [
|
2: BLOOD_MOOR_RIVER_PRESETS,
|
||||||
'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',
|
|
||||||
],
|
|
||||||
3: [
|
3: [
|
||||||
'Act 1 - Cave Entrance',
|
'Act 1 - Cave Entrance',
|
||||||
'Act 1 - Fallen Camp Bishibosh',
|
'Act 1 - Fallen Camp Bishibosh',
|
||||||
|
|
@ -5375,35 +5391,7 @@ export function generateWilderness(request: WildernessRequest): WildernessResult
|
||||||
if (request.levelId === 2) {
|
if (request.levelId === 2) {
|
||||||
// Blood Moor has a chance (50%) of spawning river water + bridge, or pond
|
// Blood Moor has a chance (50%) of spawning river water + bridge, or pond
|
||||||
const hasRiver = rng.int(0, 1) === 0
|
const hasRiver = rng.int(0, 1) === 0
|
||||||
specialPresetNames = hasRiver
|
specialPresetNames = hasRiver ? BLOOD_MOOR_RIVER_PRESETS : BLOOD_MOOR_POND_PRESETS
|
||||||
? [
|
|
||||||
'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',
|
|
||||||
]
|
|
||||||
} else {
|
} else {
|
||||||
specialPresetNames = SPECIAL_PRESETS_BY_LEVEL[request.levelId] ?? []
|
specialPresetNames = SPECIAL_PRESETS_BY_LEVEL[request.levelId] ?? []
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue