mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
refactor: routes continue
This commit is contained in:
parent
910e782f1f
commit
aff29d9d71
3 changed files with 15 additions and 11 deletions
|
|
@ -29,7 +29,7 @@ export function specifyBurgs(
|
||||||
): TBurgs {
|
): TBurgs {
|
||||||
TIME && console.time("specifyBurgs");
|
TIME && console.time("specifyBurgs");
|
||||||
|
|
||||||
const burgs: IBurg[] = [...capitals, ...towns].map(burgData => {
|
const burgs = [...capitals, ...towns].map(burgData => {
|
||||||
const {cell, culture, capital} = burgData;
|
const {cell, culture, capital} = burgData;
|
||||||
const state = stateIds[cell];
|
const state = stateIds[cell];
|
||||||
|
|
||||||
|
|
@ -38,9 +38,10 @@ export function specifyBurgs(
|
||||||
const [x, y] = defineLocation(cell, port);
|
const [x, y] = defineLocation(cell, port);
|
||||||
|
|
||||||
const type = defineType(cell, port, population);
|
const type = defineType(cell, port, population);
|
||||||
const coa = defineEmblem(state, culture, port, capital, type, cultures, states);
|
const coa: ICoa = defineEmblem(state, culture, port, capital, type, cultures, states);
|
||||||
|
|
||||||
return {...burgData, state, port, population, x, y, type, coa};
|
const burg: IBurg = {...burgData, state, port, population, x, y, type, coa};
|
||||||
|
return burg;
|
||||||
});
|
});
|
||||||
|
|
||||||
TIME && console.timeEnd("specifyBurgs");
|
TIME && console.timeEnd("specifyBurgs");
|
||||||
|
|
|
||||||
|
|
@ -19,18 +19,18 @@ const getRoads = function (burgs: TBurgs) {
|
||||||
|
|
||||||
if (capitals.length < 2) return []; // not enough capitals to build main roads
|
if (capitals.length < 2) return []; // not enough capitals to build main roads
|
||||||
|
|
||||||
const paths = []; // array to store path segments
|
const routes = []; // array to store path segments
|
||||||
|
|
||||||
for (const b of capitals) {
|
for (const {i, feature, cell: fromCell} of capitals) {
|
||||||
const connect = capitals.filter(c => c.feature === b.feature && c !== b);
|
const sameFeatureCapitals = capitals.filter(capital => i !== capital.i && feature === capital.feature);
|
||||||
for (const t of connect) {
|
for (const {cell: toCell} of sameFeatureCapitals) {
|
||||||
const [from, exit] = findLandPath(b.cell, t.cell, true);
|
const [from, exit] = findLandPath(fromCell, toCell, true);
|
||||||
const segments = restorePath(b.cell, exit, "main", from);
|
const segments = restorePath(fromCell, exit, "main", from);
|
||||||
segments.forEach(s => paths.push(s));
|
segments.forEach(s => routes.push(s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cells.i.forEach(i => (cells.s[i] += cells.road[i] / 2)); // add roads to suitability score
|
cells.i.forEach(i => (cells.s[i] += cells.road[i] / 2)); // add roads to suitability score
|
||||||
TIME && console.timeEnd("generateMainRoads");
|
TIME && console.timeEnd("generateMainRoads");
|
||||||
return paths;
|
return routes;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
3
src/types/pack/burgs.d.ts
vendored
3
src/types/pack/burgs.d.ts
vendored
|
|
@ -1,11 +1,14 @@
|
||||||
interface IBurg {
|
interface IBurg {
|
||||||
i: number;
|
i: number;
|
||||||
name: string;
|
name: string;
|
||||||
|
feature: number;
|
||||||
|
state: number;
|
||||||
cell: number;
|
cell: number;
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
population: number;
|
population: number;
|
||||||
type: TCultureType;
|
type: TCultureType;
|
||||||
|
coa: ICoa | "string";
|
||||||
capital: Logical; // 1 - capital, 0 - burg
|
capital: Logical; // 1 - capital, 0 - burg
|
||||||
port: number; // port feature id, 0 - not a port
|
port: number; // port feature id, 0 - not a port
|
||||||
shanty?: number;
|
shanty?: number;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue