mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
refactor: lake name generator
This commit is contained in:
parent
4b874246e3
commit
b2f16c4b8f
6 changed files with 25 additions and 27 deletions
|
|
@ -252,7 +252,6 @@ export function open(options) {
|
||||||
BurgsAndStates.drawStateLabels();
|
BurgsAndStates.drawStateLabels();
|
||||||
|
|
||||||
Rivers.specify();
|
Rivers.specify();
|
||||||
Lakes.generateName();
|
|
||||||
|
|
||||||
Military.generate();
|
Military.generate();
|
||||||
Markers.generate();
|
Markers.generate();
|
||||||
|
|
@ -441,7 +440,6 @@ export function open(options) {
|
||||||
|
|
||||||
if (erosionAllowed) {
|
if (erosionAllowed) {
|
||||||
Rivers.specify();
|
Rivers.specify();
|
||||||
Lakes.generateName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// restore zones from grid
|
// restore zones from grid
|
||||||
|
|
|
||||||
|
|
@ -8,20 +8,6 @@ import {DISTANCE_FIELD, MIN_LAND_HEIGHT} from "config/generation";
|
||||||
import {byId} from "utils/shorthands";
|
import {byId} from "utils/shorthands";
|
||||||
|
|
||||||
window.Lakes = (function () {
|
window.Lakes = (function () {
|
||||||
const generateName = function () {
|
|
||||||
Math.random = aleaPRNG(seed);
|
|
||||||
for (const feature of pack.features) {
|
|
||||||
if (feature.type !== "lake") continue;
|
|
||||||
feature.name = getName(feature);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const getName = function (feature) {
|
|
||||||
const landCell = pack.cells.c[feature.firstCell].find(c => pack.cells.h[c] >= 20);
|
|
||||||
const culture = pack.cells.culture[landCell];
|
|
||||||
return Names.getCulture(culture);
|
|
||||||
};
|
|
||||||
|
|
||||||
const {LAND_COAST, WATER_COAST} = DISTANCE_FIELD;
|
const {LAND_COAST, WATER_COAST} = DISTANCE_FIELD;
|
||||||
|
|
||||||
function addLakesInDeepDepressions(grid: IGraph & Partial<IGrid>) {
|
function addLakesInDeepDepressions(grid: IGraph & Partial<IGrid>) {
|
||||||
|
|
|
||||||
|
|
@ -281,7 +281,6 @@ window.Submap = (function () {
|
||||||
BurgsAndStates.drawStateLabels();
|
BurgsAndStates.drawStateLabels();
|
||||||
|
|
||||||
Rivers.specify();
|
Rivers.specify();
|
||||||
Lakes.generateName();
|
|
||||||
|
|
||||||
stage("Porting military.");
|
stage("Porting military.");
|
||||||
for (const s of pack.states) {
|
for (const s of pack.states) {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
// @ts-nocheckd
|
|
||||||
import * as d3 from "d3";
|
import * as d3 from "d3";
|
||||||
|
|
||||||
import {rn} from "utils/numberUtils";
|
import {rn} from "utils/numberUtils";
|
||||||
import {getRealHeight} from "utils/unitUtils";
|
import {getRealHeight} from "utils/unitUtils";
|
||||||
|
|
||||||
|
const {Names} = window;
|
||||||
|
|
||||||
export interface ILakeClimateData extends IPackFeatureLake {
|
export interface ILakeClimateData extends IPackFeatureLake {
|
||||||
flux: number;
|
flux: number;
|
||||||
temp: number;
|
temp: number;
|
||||||
|
|
@ -45,7 +46,7 @@ export const getClimateData = function (
|
||||||
return lakeData;
|
return lakeData;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const mergeLakeDataToFeatures = function (
|
export const mergeLakeData = function (
|
||||||
features: TPackFeatures,
|
features: TPackFeatures,
|
||||||
lakeData: ILakeClimateData[],
|
lakeData: ILakeClimateData[],
|
||||||
rivers: Pick<IRiver, "i">[]
|
rivers: Pick<IRiver, "i">[]
|
||||||
|
|
@ -101,3 +102,17 @@ function defineLakeGroup({
|
||||||
|
|
||||||
return "freshwater";
|
return "freshwater";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function generateLakeNames(features: TPackFeatures, culture: UintArray) {
|
||||||
|
const updatedFeatures = features.map(feature => {
|
||||||
|
if (!feature) return 0;
|
||||||
|
if (feature.type !== "lake") return feature;
|
||||||
|
|
||||||
|
const landCell = feature.shoreline[0];
|
||||||
|
const cultureId = culture[landCell];
|
||||||
|
const name = Names.getCulture(cultureId) as string;
|
||||||
|
return {...feature, name};
|
||||||
|
});
|
||||||
|
|
||||||
|
return updatedFeatures as TPackFeatures;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ export function createPack(grid: IGrid): IPack {
|
||||||
// BurgsAndStates.drawStateLabels();
|
// BurgsAndStates.drawStateLabels();
|
||||||
|
|
||||||
// Rivers.specify();
|
// Rivers.specify();
|
||||||
// Lakes.generateName();
|
// const updatedFeatures = generateLakeNames();
|
||||||
|
|
||||||
// Military.generate();
|
// Military.generate();
|
||||||
// Markers.generate();
|
// Markers.generate();
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import {DISTANCE_FIELD, MAX_HEIGHT, MIN_LAND_HEIGHT} from "config/generation";
|
||||||
import {getInputNumber} from "utils/nodeUtils";
|
import {getInputNumber} from "utils/nodeUtils";
|
||||||
import {pick} from "utils/functionUtils";
|
import {pick} from "utils/functionUtils";
|
||||||
import {byId} from "utils/shorthands";
|
import {byId} from "utils/shorthands";
|
||||||
import {mergeLakeDataToFeatures, getClimateData, ILakeClimateData} from "./lakes";
|
import {mergeLakeData, getClimateData, ILakeClimateData} from "./lakes";
|
||||||
import {drawArrow} from "utils/debugUtils";
|
import {drawArrow} from "utils/debugUtils";
|
||||||
|
|
||||||
const {Rivers} = window;
|
const {Rivers} = window;
|
||||||
|
|
@ -44,7 +44,7 @@ export function generateRivers(
|
||||||
const {r, conf, rivers} = defineRivers();
|
const {r, conf, rivers} = defineRivers();
|
||||||
const heights = downcutRivers(currentCellHeights);
|
const heights = downcutRivers(currentCellHeights);
|
||||||
|
|
||||||
const mergedFeatures = mergeLakeDataToFeatures(features, lakeData, rivers);
|
const mergedFeatures = mergeLakeData(features, lakeData, rivers);
|
||||||
|
|
||||||
TIME && console.timeEnd("generateRivers");
|
TIME && console.timeEnd("generateRivers");
|
||||||
|
|
||||||
|
|
@ -97,7 +97,7 @@ export function generateRivers(
|
||||||
}
|
}
|
||||||
|
|
||||||
lake.outlet = riverIds[lakeCell];
|
lake.outlet = riverIds[lakeCell];
|
||||||
flowDown(lakeCell, cellId, flux[lakeCell], lake.outlet);
|
flowDown(cellId, flux[lakeCell], lake.outlet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lakesDrainingToCell.length && lakesDrainingToCell[0].outlet) {
|
if (lakesDrainingToCell.length && lakesDrainingToCell[0].outlet) {
|
||||||
|
|
@ -125,6 +125,8 @@ export function generateRivers(
|
||||||
min = cells.c[cellId].sort((a, b) => currentCellHeights[a] - currentCellHeights[b])[0];
|
min = cells.c[cellId].sort((a, b) => currentCellHeights[a] - currentCellHeights[b])[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// drawArrow(cells.p[fromCell], cells.p[toCell]);
|
||||||
|
|
||||||
// cells is depressed
|
// cells is depressed
|
||||||
if (currentCellHeights[cellId] <= currentCellHeights[min]) return;
|
if (currentCellHeights[cellId] <= currentCellHeights[min]) return;
|
||||||
|
|
||||||
|
|
@ -141,14 +143,12 @@ export function generateRivers(
|
||||||
nextRiverId++;
|
nextRiverId++;
|
||||||
}
|
}
|
||||||
|
|
||||||
flowDown(cellId, min, flux[cellId], riverIds[cellId]);
|
flowDown(min, flux[cellId], riverIds[cellId]);
|
||||||
});
|
});
|
||||||
|
|
||||||
return {flux, lakeData};
|
return {flux, lakeData};
|
||||||
|
|
||||||
function flowDown(fromCell: number, toCell: number, fromFlux: number, riverId: number) {
|
function flowDown(toCell: number, fromFlux: number, riverId: number) {
|
||||||
// drawArrow(cells.p[fromCell], cells.p[toCell]);
|
|
||||||
|
|
||||||
const toFlux = flux[toCell] - confluence[toCell];
|
const toFlux = flux[toCell] - confluence[toCell];
|
||||||
const toRiver = riverIds[toCell];
|
const toRiver = riverIds[toCell];
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue