From f7da02615b5a876d752757dee71598726d21b300 Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Wed, 27 Nov 2024 07:31:01 -0800 Subject: [PATCH] support fill_ter --- _test/all.meta.json | 2 +- src/types.ts | 2 +- src/types/item/spawnLocations.ts | 33 +++++++++++++++++++++++++------- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/_test/all.meta.json b/_test/all.meta.json index ebfa6c66..38eabbb8 100644 --- a/_test/all.meta.json +++ b/_test/all.meta.json @@ -1 +1 @@ -{"buildNum":"cdda-experimental-2024-11-11-0430","sha":"bb558e50f9b73d5b992c0d80c961fc05821e745a4c5dc79e3296d1853931c3af"} \ No newline at end of file +{"buildNum":"cdda-experimental-2024-11-27-0633","sha":"3be13d3a705a4d1c3f2afca7959f487d1de04777fe0f81d903d1c7282ca2be8c"} \ No newline at end of file diff --git a/src/types.ts b/src/types.ts index 51e47e51..f7da38fb 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1151,7 +1151,7 @@ export type MapgenPlaceFurniture = { }; export interface MapgenObject { - fill_ter?: string; + fill_ter?: MapgenValue; rows?: string[]; terrain?: PlaceMappingAlternative; place_terrain?: PlaceList; diff --git a/src/types/item/spawnLocations.ts b/src/types/item/spawnLocations.ts index 1d5f022e..3e8877c5 100644 --- a/src/types/item/spawnLocations.ts +++ b/src/types/item/spawnLocations.ts @@ -537,6 +537,16 @@ function getMapgenValueDistribution(val: raw.MapgenValue): Map { return new Map(); } +function toLoot(distribution: Map): Loot { + // TODO: i'm not sure this is correct? + return new Map( + [...distribution.entries()].map(([id, prob]) => [ + id, + { prob, expected: prob }, + ]) + ); +} + let onStack = 0; function lootForChunks( data: CddaData, @@ -677,19 +687,20 @@ export function getTerrainForMapgen(data: CddaData, mapgen: raw.Mapgen): Loot { if (terrainForMapgenCache.has(mapgen)) return terrainForMapgenCache.get(mapgen)!; const palette = parseTerrainPalette(data, mapgen.object); - const place_terrain = (mapgen.object.place_terrain ?? []).map(({ ter }) => { - const distribution = getMapgenValueDistribution(ter); - const loot = new Map(); - for (const [id, prob] of distribution.entries()) - loot.set(id, { prob, expected: prob }); - return loot; - }); + const fill_ter = mapgen.object.fill_ter + ? getMapgenValueDistribution(mapgen.object.fill_ter) + : new Map(); + const place_terrain = (mapgen.object.place_terrain ?? []).map(({ ter }) => + toLoot(getMapgenValueDistribution(ter)) + ); const additional_items = collection([...place_terrain]); const countByPalette = new Map(); + let fillCount = 0; for (const row of mapgen.object.rows ?? []) for (const char of row) if (palette.has(char)) countByPalette.set(char, (countByPalette.get(char) ?? 0) + 1); + else fillCount += 1; const items: Loot[] = []; for (const [sym, count] of countByPalette.entries()) { const loot = palette.get(sym)!; @@ -699,6 +710,14 @@ export function getTerrainForMapgen(data: CddaData, mapgen: raw.Mapgen): Loot { } items.push(multipliedLoot); } + if (fillCount > 0) { + const loot = toLoot(fill_ter); + const multipliedLoot: Loot = new Map(); + for (const [id, chance] of loot.entries()) { + multipliedLoot.set(id, repeatItemChance(chance, [fillCount, fillCount])); + } + items.push(multipliedLoot); + } items.push(additional_items); const loot = collection(items); loot.delete("t_null");