mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
refactor: routes start
This commit is contained in:
parent
8c741a559e
commit
910e782f1f
8 changed files with 46 additions and 7 deletions
|
|
@ -1,2 +1,2 @@
|
|||
export const NO_BURG: TNoBurg = {name: undefined};
|
||||
export const NO_BURG: TNoBurg = {i: 0, name: undefined};
|
||||
export const NEUTRALS: TNeutrals = {i: 0, name: "Neutrals"};
|
||||
|
|
|
|||
|
|
@ -44,12 +44,9 @@ export function generateBurgsAndStates(
|
|||
pick(cells, "c", "h", "f", "t", "r", "fl", "s", "biome", "culture")
|
||||
);
|
||||
|
||||
const roadScores = new Uint16Array(cellsNumber); // TODO: define roads
|
||||
|
||||
const burgs = specifyBurgs(
|
||||
capitals,
|
||||
towns,
|
||||
roadScores,
|
||||
stateIds,
|
||||
features,
|
||||
temp,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ type TStatesReturn = ReturnType<typeof createStates>;
|
|||
export function specifyBurgs(
|
||||
capitals: TCapitals,
|
||||
towns: TTowns,
|
||||
roadScores: Uint16Array,
|
||||
stateIds: Uint16Array,
|
||||
features: TPackFeatures,
|
||||
temp: Int8Array,
|
||||
|
|
@ -64,7 +63,7 @@ export function specifyBurgs(
|
|||
|
||||
// get population in points, where 1 point = 1000 people by default
|
||||
function definePopulation(cellId: number, capital: Logical, port: number) {
|
||||
const basePopulation = (cells.s[cellId] + roadScores[cellId] / 2) / 4;
|
||||
const basePopulation = cells.s[cellId] / 4;
|
||||
const decimalPart = (cellId % 1000) / 1000;
|
||||
|
||||
const capitalMultiplier = capital ? 1.3 : 1;
|
||||
|
|
|
|||
36
src/scripts/generation/pack/generateRoutes.ts
Normal file
36
src/scripts/generation/pack/generateRoutes.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import {TIME} from "config/logging";
|
||||
|
||||
export function generateRoutes(burgs: TBurgs) {
|
||||
const routeScores = new Uint8Array(n); // cell road power
|
||||
getRoads(burgs);
|
||||
// const townRoutes = getTrails();
|
||||
// const oceanRoutes = getSearoutes();
|
||||
|
||||
return routeScores;
|
||||
}
|
||||
|
||||
const getRoads = function (burgs: TBurgs) {
|
||||
TIME && console.time("generateMainRoads");
|
||||
const cells = pack.cells;
|
||||
|
||||
const isBurg = (burg: TNoBurg | IBurg): burg is IBurg => burg.i > 0;
|
||||
const capitals = burgs.filter(burg => isBurg(burg) && burg.capital && !burg.removed) as IBurg[];
|
||||
capitals.sort((a, b) => a.population - b.population);
|
||||
|
||||
if (capitals.length < 2) return []; // not enough capitals to build main roads
|
||||
|
||||
const paths = []; // array to store path segments
|
||||
|
||||
for (const b of capitals) {
|
||||
const connect = capitals.filter(c => c.feature === b.feature && c !== b);
|
||||
for (const t of connect) {
|
||||
const [from, exit] = findLandPath(b.cell, t.cell, true);
|
||||
const segments = restorePath(b.cell, exit, "main", from);
|
||||
segments.forEach(s => paths.push(s));
|
||||
}
|
||||
}
|
||||
|
||||
cells.i.forEach(i => (cells.s[i] += cells.road[i] / 2)); // add roads to suitability score
|
||||
TIME && console.timeEnd("generateMainRoads");
|
||||
return paths;
|
||||
};
|
||||
|
|
@ -12,6 +12,7 @@ import {rn} from "utils/numberUtils";
|
|||
import {generateCultures, expandCultures} from "./cultures";
|
||||
import {generateRivers} from "./rivers";
|
||||
import {generateBurgsAndStates} from "./burgsAndStates/generateBurgsAndStates";
|
||||
import {generateRoutes} from "./generateRoutes";
|
||||
|
||||
const {LAND_COAST, WATER_COAST, DEEPER_WATER} = DISTANCE_FIELD;
|
||||
const {Biomes} = window;
|
||||
|
|
@ -116,6 +117,8 @@ export function createPack(grid: IGrid): IPack {
|
|||
}
|
||||
);
|
||||
|
||||
const routeScores = generateRoutes();
|
||||
|
||||
// Religions.generate();
|
||||
// BurgsAndStates.defineStateForms();
|
||||
// BurgsAndStates.generateProvinces();
|
||||
|
|
@ -154,7 +157,8 @@ export function createPack(grid: IGrid): IPack {
|
|||
pop: population,
|
||||
culture: cultureIds,
|
||||
burg: burgIds,
|
||||
state: stateIds
|
||||
state: stateIds,
|
||||
road: routeScores
|
||||
// religion, province
|
||||
},
|
||||
features: mergedFeatures,
|
||||
|
|
|
|||
1
src/types/overrides.d.ts
vendored
1
src/types/overrides.d.ts
vendored
|
|
@ -28,6 +28,7 @@ interface Window {
|
|||
Military: any;
|
||||
Markers: any;
|
||||
COA: any;
|
||||
Routes: any;
|
||||
}
|
||||
|
||||
interface Node {
|
||||
|
|
|
|||
1
src/types/pack/burgs.d.ts
vendored
1
src/types/pack/burgs.d.ts
vendored
|
|
@ -14,6 +14,7 @@ interface IBurg {
|
|||
}
|
||||
|
||||
type TNoBurg = {
|
||||
i: 0;
|
||||
name: undefined;
|
||||
};
|
||||
|
||||
|
|
|
|||
1
src/types/pack/pack.d.ts
vendored
1
src/types/pack/pack.d.ts
vendored
|
|
@ -29,6 +29,7 @@ interface IPackCells {
|
|||
burg: UintArray;
|
||||
haven: UintArray;
|
||||
harbor: UintArray;
|
||||
road: Uint8Array;
|
||||
q: Quadtree;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue