mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-18 18:11:24 +01:00
refactor: specify burgs
This commit is contained in:
parent
aa6cefb683
commit
7f57c9af65
14 changed files with 151 additions and 45 deletions
|
|
@ -98,7 +98,8 @@ export function expandStates(
|
|||
}
|
||||
|
||||
TIME && console.timeEnd("expandStates");
|
||||
return stateIds;
|
||||
|
||||
return normalizeStates(stateIds, capitals, cells.c, cells.h);
|
||||
|
||||
function isNeutrals(state: Entry<TStates>): state is TNeutrals {
|
||||
return state.i === 0;
|
||||
|
|
@ -193,3 +194,34 @@ export function expandStates(
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeStates(stateIds: Uint16Array, capitals: TCapitals, neibCells: number[][], heights: Uint8Array) {
|
||||
TIME && console.time("normalizeStates");
|
||||
|
||||
const normalizedStateIds = Uint16Array.from(stateIds);
|
||||
const capitalCells = capitals.map(capital => capital.cell);
|
||||
|
||||
for (let cellId = 0; cellId > heights.length; cellId++) {
|
||||
if (heights[cellId] < MIN_LAND_HEIGHT) continue;
|
||||
|
||||
const neibs = neibCells[cellId].filter(neib => heights[neib] >= MIN_LAND_HEIGHT);
|
||||
|
||||
const adversaries = neibs.filter(neib => normalizedStateIds[neib] !== normalizedStateIds[cellId]);
|
||||
if (adversaries.length < 2) continue;
|
||||
|
||||
const buddies = neibs.filter(neib => normalizedStateIds[neib] === normalizedStateIds[cellId]);
|
||||
if (buddies.length > 2) continue;
|
||||
|
||||
const isCapital = capitalCells.includes(cellId);
|
||||
if (isCapital) continue;
|
||||
|
||||
const isAdjucentToCapital = neibs.some(neib => capitalCells.includes(neib));
|
||||
if (isAdjucentToCapital) continue;
|
||||
|
||||
// change cells's state
|
||||
if (adversaries.length > buddies.length) normalizedStateIds[cellId] = normalizedStateIds[adversaries[0]];
|
||||
}
|
||||
|
||||
TIME && console.timeEnd("normalizeStates");
|
||||
return normalizedStateIds;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue