mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
refactor(religions): expand religions
This commit is contained in:
parent
0a77845ebc
commit
707cdd77ac
11 changed files with 136 additions and 42 deletions
|
|
@ -26,6 +26,7 @@ import {createGrid} from "./grid/grid";
|
|||
import {createPack} from "./pack/pack";
|
||||
import {getInputValue, setInputValue} from "utils/nodeUtils";
|
||||
import {calculateMapCoordinates} from "modules/coordinates";
|
||||
import {drawPolygons} from "utils/debugUtils";
|
||||
|
||||
const {Zoom, ThreeD} = window;
|
||||
|
||||
|
|
@ -70,6 +71,8 @@ async function generate(options?: IGenerationOptions) {
|
|||
renderLayer("burgs");
|
||||
renderLayer("routes");
|
||||
|
||||
drawPolygons(pack.cells.religion, pack.cells.v, pack.vertices.p, {fillOpacity: 0.8, excludeZeroes: true});
|
||||
|
||||
WARN && console.warn(`TOTAL: ${rn((performance.now() - timeStart) / 1000, 2)}s`);
|
||||
// showStatistics();
|
||||
INFO && console.groupEnd();
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ export function createPack(grid: IGrid): IPack {
|
|||
burg: burgIds
|
||||
});
|
||||
|
||||
const {religionIds} = generateReligions({
|
||||
const {religionIds, religions} = generateReligions({
|
||||
states,
|
||||
cultures,
|
||||
burgs,
|
||||
|
|
@ -143,7 +143,8 @@ export function createPack(grid: IGrid): IPack {
|
|||
pop: population,
|
||||
culture: cultureIds,
|
||||
burg: burgIds,
|
||||
state: stateIds
|
||||
state: stateIds,
|
||||
route: cellRoutes
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -191,11 +192,12 @@ export function createPack(grid: IGrid): IPack {
|
|||
// province
|
||||
},
|
||||
features: mergedFeatures,
|
||||
rivers: rawRivers, // "name" | "basin" | "type"
|
||||
// rivers: rawRivers, // "name" | "basin" | "type"
|
||||
cultures,
|
||||
states,
|
||||
burgs,
|
||||
routes
|
||||
routes,
|
||||
religions
|
||||
};
|
||||
|
||||
return pack;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
import FlatQueue from "flatqueue";
|
||||
|
||||
import {ROUTES} from "config/generation";
|
||||
import {getInputNumber} from "utils/nodeUtils";
|
||||
import {gauss} from "utils/probabilityUtils";
|
||||
import {isReligion} from "utils/typeUtils";
|
||||
|
||||
type TReligionData = Pick<IReligion, "i" | "type" | "center" | "culture" | "expansion" | "expansionism">;
|
||||
type TCellsData = Pick<IPack["cells"], "i" | "c" | "culture">;
|
||||
type TCellsData = Pick<IPack["cells"], "i" | "c" | "biome" | "culture" | "state" | "route">;
|
||||
|
||||
export function expandReligions(religions: TReligionData[], cells: TCellsData) {
|
||||
const religionIds = spreadFolkReligions(religions, cells);
|
||||
|
|
@ -15,6 +17,10 @@ export function expandReligions(religions: TReligionData[], cells: TCellsData) {
|
|||
const neutralInput = getInputNumber("neutralInput");
|
||||
const maxExpansionCost = (cells.i.length / 25) * gauss(1, 0.3, 0.2, 2, 2) * neutralInput;
|
||||
|
||||
const biomePassageCost = (cellId: number) => biomesData.cost[cells.biome[cellId]];
|
||||
const isMainRoad = (cellId: number) => cells.route[cellId] === ROUTES.MAIN_ROAD;
|
||||
const isSeaRoute = (cellId: number) => cells.route[cellId] === ROUTES.SEA_ROUTE;
|
||||
|
||||
for (const religion of religions) {
|
||||
if (!isReligion(religion as IReligion) || (religion as IReligion).type === "Folk") continue;
|
||||
|
||||
|
|
@ -24,6 +30,37 @@ export function expandReligions(religions: TReligionData[], cells: TCellsData) {
|
|||
queue.push({cellId, religionId}, 0);
|
||||
}
|
||||
|
||||
const religionsMap = new Map<number, TReligionData>(religions.map(religion => [religion.i, religion]));
|
||||
|
||||
while (queue.length) {
|
||||
const priority = queue.peekValue()!;
|
||||
const {cellId, religionId} = queue.pop()!;
|
||||
|
||||
const {culture, center, expansion, expansionism} = religionsMap.get(religionId)!;
|
||||
|
||||
cells.c[cellId].forEach(neibCellId => {
|
||||
// if (neibCellId === center && religionIds[neibCellId]) return; // do not overwrite center cells
|
||||
if (expansion === "culture" && culture !== cells.culture[neibCellId]) return;
|
||||
if (expansion === "state" && cells.state[center] !== cells.state[neibCellId]) return;
|
||||
|
||||
const cultureCost = culture !== cells.culture[neibCellId] ? 50 : 0;
|
||||
const stateCost = cells.state[center] !== cells.state[neibCellId] ? 50 : 0;
|
||||
const passageCost = isMainRoad(neibCellId) ? 1 : biomePassageCost(neibCellId); // [1, 5000]
|
||||
const waterCost = isSeaRoute(neibCellId) ? 50 : 1000;
|
||||
|
||||
const cellCost = Math.max(cultureCost + stateCost + passageCost + waterCost, 0);
|
||||
const totalCost = priority + 10 + cellCost / expansionism;
|
||||
if (totalCost > maxExpansionCost) return;
|
||||
|
||||
if (!cost[neibCellId] || totalCost < cost[neibCellId]) {
|
||||
if (cells.culture[neibCellId]) religionIds[neibCellId] = religionId; // assign religion to cell
|
||||
cost[neibCellId] = totalCost;
|
||||
|
||||
queue.push({cellId: neibCellId, religionId}, totalCost);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return religionIds;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import {specifyReligions} from "./specifyReligions";
|
|||
|
||||
type TCellsData = Pick<
|
||||
IPack["cells"],
|
||||
"i" | "c" | "p" | "g" | "h" | "t" | "biome" | "pop" | "culture" | "burg" | "state"
|
||||
"i" | "c" | "p" | "g" | "h" | "t" | "biome" | "pop" | "culture" | "burg" | "state" | "route"
|
||||
>;
|
||||
|
||||
export function generateReligions({
|
||||
|
|
@ -29,7 +29,7 @@ export function generateReligions({
|
|||
cultures,
|
||||
states,
|
||||
burgs,
|
||||
pick(cells, "i", "c", "culture", "burg", "state")
|
||||
pick(cells, "i", "c", "biome", "culture", "burg", "state", "route")
|
||||
);
|
||||
|
||||
console.log(religions);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export function specifyReligions(
|
|||
cultures: TCultures,
|
||||
states: TStates,
|
||||
burgs: TBurgs,
|
||||
cells: Pick<IPack["cells"], "i" | "c" | "culture" | "burg" | "state">
|
||||
cells: Pick<IPack["cells"], "i" | "c" | "biome" | "culture" | "burg" | "state" | "route">
|
||||
): {religions: TReligions; religionIds: Uint16Array} {
|
||||
const rawReligions = religionsData.map(({type, form, culture: cultureId, center}, index) => {
|
||||
const supreme = getDeityName(cultures, cultureId);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue