mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 01:41:22 +01:00
refactor(generation): cultures continue
This commit is contained in:
parent
34c98ed92c
commit
fa2b873bf8
10 changed files with 585 additions and 512 deletions
|
|
@ -7644,7 +7644,6 @@
|
||||||
<script type="module" src="/src/modules/rivers.js"></script>
|
<script type="module" src="/src/modules/rivers.js"></script>
|
||||||
<script type="module" src="/src/modules/names-generator.js"></script>
|
<script type="module" src="/src/modules/names-generator.js"></script>
|
||||||
<script type="module" src="/src/modules/biomes.js"></script>
|
<script type="module" src="/src/modules/biomes.js"></script>
|
||||||
<script type="module" src="/src/modules/cultures-generator.ts"></script>
|
|
||||||
<script type="module" src="/src/modules/burgs-and-states.js"></script>
|
<script type="module" src="/src/modules/burgs-and-states.js"></script>
|
||||||
<script type="module" src="/src/modules/routes-generator.js"></script>
|
<script type="module" src="/src/modules/routes-generator.js"></script>
|
||||||
<script type="module" src="/src/modules/religions-generator.js"></script>
|
<script type="module" src="/src/modules/religions-generator.js"></script>
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,3 @@
|
||||||
// const methods = {
|
|
||||||
// random: (number) => number >= 100 || (number > 0 && number / 100 > Math.random()),
|
|
||||||
// nth: (number) => !(cellId % number),
|
|
||||||
// minHabitability: (min) => biomesData.habitability[pack.cells.biome[cellId]] >= min,
|
|
||||||
// habitability: () => biomesData.habitability[cells.biome[cellId]] > Math.random() * 100,
|
|
||||||
// elevation: () => pack.cells.h[cellId] / 100 > Math.random(),
|
|
||||||
// biome: (...biomes) => biomes.includes(pack.cells.biome[cellId]),
|
|
||||||
// minHeight: (heigh) => pack.cells.h[cellId] >= heigh,
|
|
||||||
// maxHeight: (heigh) => pack.cells.h[cellId] <= heigh,
|
|
||||||
// minTemp: (temp) => grid.cells.temp[pack.cells.g[cellId]] >= temp,
|
|
||||||
// maxTemp: (temp) => grid.cells.temp[pack.cells.g[cellId]] <= temp,
|
|
||||||
// shore: (...rings) => rings.includes(pack.cells.t[cellId]),
|
|
||||||
// type: (...types) => types.includes(pack.features[cells.f[cellId]].group),
|
|
||||||
// river: () => pack.cells.r[cellId]
|
|
||||||
// };
|
|
||||||
// const allMethods = '{' + Object.keys(methods).join(', ') + '}';
|
|
||||||
|
|
||||||
// const model = 'minHeight(60) || (biome(12) && nth(7)) || (minHeight(20) && nth(10))',
|
|
||||||
// const fn = new Function(allMethods, 'return ' + model);
|
|
||||||
|
|
||||||
// const passed = fn({...methods});
|
|
||||||
|
|
||||||
import {rand} from "utils/probabilityUtils";
|
import {rand} from "utils/probabilityUtils";
|
||||||
|
|
||||||
const {Names, COA} = window;
|
const {Names, COA} = window;
|
||||||
|
|
@ -43,72 +21,72 @@ interface ICultureConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
const world = () => [
|
const world = () => [
|
||||||
{name: "Shwazen", base: 0, odd: 0.7, sort: "n / td(10) / bd([6, 8])", shield: "hessen"},
|
{name: "Shwazen", base: 0, odd: 0.7, sort: "n() / td(10) / bd([6, 8])", shield: "hessen"},
|
||||||
{name: "Angshire", base: 1, odd: 1, sort: "n / td(10) / sf(i)", shield: "heater"},
|
{name: "Angshire", base: 1, odd: 1, sort: "n() / td(10) / sf", shield: "heater"},
|
||||||
{name: "Luari", base: 2, odd: 0.6, sort: "n / td(12) / bd([6, 8])", shield: "oldFrench"},
|
{name: "Luari", base: 2, odd: 0.6, sort: "n() / td(12) / bd([6, 8])", shield: "oldFrench"},
|
||||||
{name: "Tallian", base: 3, odd: 0.6, sort: "n / td(15)", shield: "horsehead2"},
|
{name: "Tallian", base: 3, odd: 0.6, sort: "n() / td(15)", shield: "horsehead2"},
|
||||||
{name: "Astellian", base: 4, odd: 0.6, sort: "n / td(16)", shield: "spanish"},
|
{name: "Astellian", base: 4, odd: 0.6, sort: "n() / td(16)", shield: "spanish"},
|
||||||
{name: "Slovan", base: 5, odd: 0.7, sort: "(n / td(6)) * t", shield: "round"},
|
{name: "Slovan", base: 5, odd: 0.7, sort: "(n() / td(6)) * t()", shield: "round"},
|
||||||
{name: "Norse", base: 6, odd: 0.7, sort: "n / td(5)", shield: "heater"},
|
{name: "Norse", base: 6, odd: 0.7, sort: "n() / td(5)", shield: "heater"},
|
||||||
{name: "Elladan", base: 7, odd: 0.7, sort: "(n / td(18)) * h", shield: "boeotian"},
|
{name: "Elladan", base: 7, odd: 0.7, sort: "(n() / td(18)) * h()", shield: "boeotian"},
|
||||||
{name: "Romian", base: 8, odd: 0.7, sort: "n / td(15)", shield: "roman"},
|
{name: "Romian", base: 8, odd: 0.7, sort: "n() / td(15)", shield: "roman"},
|
||||||
{name: "Soumi", base: 9, odd: 0.3, sort: "(n / td(5) / bd([9])) * t", shield: "pavise"},
|
{name: "Soumi", base: 9, odd: 0.3, sort: "(n() / td(5) / bd([9])) * t()", shield: "pavise"},
|
||||||
{name: "Koryo", base: 10, odd: 0.1, sort: "n / td(12) / t", shield: "round"},
|
{name: "Koryo", base: 10, odd: 0.1, sort: "n() / td(12) / t()", shield: "round"},
|
||||||
{name: "Hantzu", base: 11, odd: 0.1, sort: "n / td(13)", shield: "banner"},
|
{name: "Hantzu", base: 11, odd: 0.1, sort: "n() / td(13)", shield: "banner"},
|
||||||
{name: "Yamoto", base: 12, odd: 0.1, sort: "n / td(15) / t", shield: "round"},
|
{name: "Yamoto", base: 12, odd: 0.1, sort: "n() / td(15) / t()", shield: "round"},
|
||||||
{name: "Portuzian", base: 13, odd: 0.4, sort: "n / td(17) / sf(i)", shield: "spanish"},
|
{name: "Portuzian", base: 13, odd: 0.4, sort: "n() / td(17) / sf()", shield: "spanish"},
|
||||||
{name: "Nawatli", base: 14, odd: 0.1, sort: "h / td(18) / bd([7])", shield: "square"},
|
{name: "Nawatli", base: 14, odd: 0.1, sort: "h / td(18) / bd([7])", shield: "square"},
|
||||||
{name: "Vengrian", base: 15, odd: 0.2, sort: "(n / td(11) / bd([4])) * t", shield: "wedged"},
|
{name: "Vengrian", base: 15, odd: 0.2, sort: "(n() / td(11) / bd([4])) * t()", shield: "wedged"},
|
||||||
{name: "Turchian", base: 16, odd: 0.2, sort: "n / td(13)", shield: "round"},
|
{name: "Turchian", base: 16, odd: 0.2, sort: "n() / td(13)", shield: "round"},
|
||||||
{name: "Berberan", base: 17, odd: 0.1, sort: "(n / td(19) / bd([1, 2, 3], 7)) * t", shield: "round"},
|
{name: "Berberan", base: 17, odd: 0.1, sort: "(n() / td(19) / bd([1, 2, 3], 7)) * t()", shield: "round"},
|
||||||
{name: "Eurabic", base: 18, odd: 0.2, sort: "(n / td(26) / bd([1, 2], 7)) * t", shield: "round"},
|
{name: "Eurabic", base: 18, odd: 0.2, sort: "(n() / td(26) / bd([1, 2], 7)) * t()", shield: "round"},
|
||||||
{name: "Inuk", base: 19, odd: 0.05, sort: "td(-1) / bd([10, 11]) / sf(i)", shield: "square"},
|
{name: "Inuk", base: 19, odd: 0.05, sort: "td(-1) / bd([10, 11]) / sf()", shield: "square"},
|
||||||
{name: "Euskati", base: 20, odd: 0.05, sort: "(n / td(15)) * h", shield: "spanish"},
|
{name: "Euskati", base: 20, odd: 0.05, sort: "(n() / td(15)) * h()", shield: "spanish"},
|
||||||
{name: "Yoruba", base: 21, odd: 0.05, sort: "n / td(15) / bd([5, 7])", shield: "vesicaPiscis"},
|
{name: "Yoruba", base: 21, odd: 0.05, sort: "n() / td(15) / bd([5, 7])", shield: "vesicaPiscis"},
|
||||||
{name: "Keltan", base: 22, odd: 0.05, sort: "(n / td(11) / bd([6, 8])) * t", shield: "vesicaPiscis"},
|
{name: "Keltan", base: 22, odd: 0.05, sort: "(n() / td(11) / bd([6, 8])) * t()", shield: "vesicaPiscis"},
|
||||||
{name: "Efratic", base: 23, odd: 0.05, sort: "(n / td(22)) * t", shield: "diamond"},
|
{name: "Efratic", base: 23, odd: 0.05, sort: "(n() / td(22)) * t()", shield: "diamond"},
|
||||||
{name: "Tehrani", base: 24, odd: 0.1, sort: "(n / td(18)) * h", shield: "round"},
|
{name: "Tehrani", base: 24, odd: 0.1, sort: "(n() / td(18)) * h()", shield: "round"},
|
||||||
{name: "Maui", base: 25, odd: 0.05, sort: "n / td(24) / sf(i) / t", shield: "round"},
|
{name: "Maui", base: 25, odd: 0.05, sort: "n() / td(24) / sf() / t()", shield: "round"},
|
||||||
{name: "Carnatic", base: 26, odd: 0.05, sort: "n / td(26)", shield: "round"},
|
{name: "Carnatic", base: 26, odd: 0.05, sort: "n() / td(26)", shield: "round"},
|
||||||
{name: "Inqan", base: 27, odd: 0.05, sort: "h / td(13)", shield: "square"},
|
{name: "Inqan", base: 27, odd: 0.05, sort: "h / td(13)", shield: "square"},
|
||||||
{name: "Kiswaili", base: 28, odd: 0.1, sort: "n / td(29) / bd([1, 3, 5, 7])", shield: "vesicaPiscis"},
|
{name: "Kiswaili", base: 28, odd: 0.1, sort: "n() / td(29) / bd([1, 3, 5, 7])", shield: "vesicaPiscis"},
|
||||||
{name: "Vietic", base: 29, odd: 0.1, sort: "n / td(25) / bd([7], 7) / t", shield: "banner"},
|
{name: "Vietic", base: 29, odd: 0.1, sort: "n() / td(25) / bd([7], 7) / t()", shield: "banner"},
|
||||||
{name: "Guantzu", base: 30, odd: 0.1, sort: "n / td(17)", shield: "banner"},
|
{name: "Guantzu", base: 30, odd: 0.1, sort: "n() / td(17)", shield: "banner"},
|
||||||
{name: "Ulus", base: 31, odd: 0.1, sort: "(n / td(5) / bd([2, 4, 10], 7)) * t", shield: "banner"}
|
{name: "Ulus", base: 31, odd: 0.1, sort: "(n() / td(5) / bd([2, 4, 10], 7)) * t()", shield: "banner"}
|
||||||
];
|
];
|
||||||
|
|
||||||
const european = () => [
|
const european = () => [
|
||||||
{name: "Shwazen", base: 0, odd: 1, sort: "n / td(10) / bd([6, 8])", shield: "swiss"},
|
{name: "Shwazen", base: 0, odd: 1, sort: "n() / td(10) / bd([6, 8])", shield: "swiss"},
|
||||||
{name: "Angshire", base: 1, odd: 1, sort: "n / td(10) / sf(i)", shield: "wedged"},
|
{name: "Angshire", base: 1, odd: 1, sort: "n() / td(10) / sf()", shield: "wedged"},
|
||||||
{name: "Luari", base: 2, odd: 1, sort: "n / td(12) / bd([6, 8])", shield: "french"},
|
{name: "Luari", base: 2, odd: 1, sort: "n() / td(12) / bd([6, 8])", shield: "french"},
|
||||||
{name: "Tallian", base: 3, odd: 1, sort: "n / td(15)", shield: "horsehead"},
|
{name: "Tallian", base: 3, odd: 1, sort: "n() / td(15)", shield: "horsehead"},
|
||||||
{name: "Astellian", base: 4, odd: 1, sort: "n / td(16)", shield: "spanish"},
|
{name: "Astellian", base: 4, odd: 1, sort: "n() / td(16)", shield: "spanish"},
|
||||||
{name: "Slovan", base: 5, odd: 1, sort: "(n / td(6)) * t", shield: "polish"},
|
{name: "Slovan", base: 5, odd: 1, sort: "(n() / td(6)) * t()", shield: "polish"},
|
||||||
{name: "Norse", base: 6, odd: 1, sort: "n / td(5)", shield: "heater"},
|
{name: "Norse", base: 6, odd: 1, sort: "n() / td(5)", shield: "heater"},
|
||||||
{name: "Elladan", base: 7, odd: 1, sort: "(n / td(18)) * h", shield: "boeotian"},
|
{name: "Elladan", base: 7, odd: 1, sort: "(n() / td(18)) * h()", shield: "boeotian"},
|
||||||
{name: "Romian", base: 8, odd: 0.2, sort: "n / td(15) / t", shield: "roman"},
|
{name: "Romian", base: 8, odd: 0.2, sort: "n() / td(15) / t()", shield: "roman"},
|
||||||
{name: "Soumi", base: 9, odd: 1, sort: "(n / td(5) / bd([9])) * t", shield: "pavise"},
|
{name: "Soumi", base: 9, odd: 1, sort: "(n() / td(5) / bd([9])) * t()", shield: "pavise"},
|
||||||
{name: "Portuzian", base: 13, odd: 1, sort: "n / td(17) / sf(i)", shield: "renaissance"},
|
{name: "Portuzian", base: 13, odd: 1, sort: "n() / td(17) / sf()", shield: "renaissance"},
|
||||||
{name: "Vengrian", base: 15, odd: 1, sort: "(n / td(11) / bd([4])) * t", shield: "horsehead2"},
|
{name: "Vengrian", base: 15, odd: 1, sort: "(n() / td(11) / bd([4])) * t()", shield: "horsehead2"},
|
||||||
{name: "Turchian", base: 16, odd: 0.05, sort: "n / td(14)", shield: "round"},
|
{name: "Turchian", base: 16, odd: 0.05, sort: "n() / td(14)", shield: "round"},
|
||||||
{name: "Euskati", base: 20, odd: 0.05, sort: "(n / td(15)) * h", shield: "oldFrench"},
|
{name: "Euskati", base: 20, odd: 0.05, sort: "(n() / td(15)) * h()", shield: "oldFrench"},
|
||||||
{name: "Keltan", base: 22, odd: 0.05, sort: "(n / td(11) / bd([6, 8])) * t", shield: "oval"}
|
{name: "Keltan", base: 22, odd: 0.05, sort: "(n() / td(11) / bd([6, 8])) * t()", shield: "oval"}
|
||||||
];
|
];
|
||||||
|
|
||||||
const oriental = () => [
|
const oriental = () => [
|
||||||
{name: "Koryo", base: 10, odd: 1, sort: "n / td(12) / t", shield: "round"},
|
{name: "Koryo", base: 10, odd: 1, sort: "n() / td(12) / t()", shield: "round"},
|
||||||
{name: "Hantzu", base: 11, odd: 1, sort: "n / td(13)", shield: "banner"},
|
{name: "Hantzu", base: 11, odd: 1, sort: "n() / td(13)", shield: "banner"},
|
||||||
{name: "Yamoto", base: 12, odd: 1, sort: "n / td(15) / t", shield: "round"},
|
{name: "Yamoto", base: 12, odd: 1, sort: "n() / td(15) / t()", shield: "round"},
|
||||||
{name: "Turchian", base: 16, odd: 1, sort: "n / td(12)", shield: "round"},
|
{name: "Turchian", base: 16, odd: 1, sort: "n() / td(12)", shield: "round"},
|
||||||
{name: "Berberan", base: 17, odd: 0.2, sort: "(n / td(19) / bd([1, 2, 3], 7)) * t", shield: "oval"},
|
{name: "Berberan", base: 17, odd: 0.2, sort: "(n() / td(19) / bd([1, 2, 3], 7)) * t()", shield: "oval"},
|
||||||
{name: "Eurabic", base: 18, odd: 1, sort: "(n / td(26) / bd([1, 2], 7)) * t", shield: "oval"},
|
{name: "Eurabic", base: 18, odd: 1, sort: "(n() / td(26) / bd([1, 2], 7)) * t()", shield: "oval"},
|
||||||
{name: "Efratic", base: 23, odd: 0.1, sort: "(n / td(22)) * t", shield: "round"},
|
{name: "Efratic", base: 23, odd: 0.1, sort: "(n() / td(22)) * t()", shield: "round"},
|
||||||
{name: "Tehrani", base: 24, odd: 1, sort: "(n / td(18)) * h", shield: "round"},
|
{name: "Tehrani", base: 24, odd: 1, sort: "(n() / td(18)) * h()", shield: "round"},
|
||||||
{name: "Maui", base: 25, odd: 0.2, sort: "n / td(24) / sf(i) / t", shield: "vesicaPiscis"},
|
{name: "Maui", base: 25, odd: 0.2, sort: "n() / td(24) / sf() / t()", shield: "vesicaPiscis"},
|
||||||
{name: "Carnatic", base: 26, odd: 0.5, sort: "n / td(26)", shield: "round"},
|
{name: "Carnatic", base: 26, odd: 0.5, sort: "n() / td(26)", shield: "round"},
|
||||||
{name: "Vietic", base: 29, odd: 0.8, sort: "n / td(25) / bd([7], 7) / t", shield: "banner"},
|
{name: "Vietic", base: 29, odd: 0.8, sort: "n() / td(25) / bd([7], 7) / t", shield: "banner"},
|
||||||
{name: "Guantzu", base: 30, odd: 0.5, sort: "n / td(17)", shield: "banner"},
|
{name: "Guantzu", base: 30, odd: 0.5, sort: "n() / td(17)", shield: "banner"},
|
||||||
{name: "Ulus", base: 31, odd: 1, sort: "(n / td(5) / bd([2, 4, 10], 7)) * t", shield: "banner"}
|
{name: "Ulus", base: 31, odd: 1, sort: "(n() / td(5) / bd([2, 4, 10], 7)) * t()", shield: "banner"}
|
||||||
];
|
];
|
||||||
|
|
||||||
const getEnglishName: () => string = () => Names.getBase(1, 5, 9, "", 0);
|
const getEnglishName: () => string = () => Names.getBase(1, 5, 9, "", 0);
|
||||||
|
|
@ -127,84 +105,84 @@ const english = () => [
|
||||||
];
|
];
|
||||||
|
|
||||||
const antique = () => [
|
const antique = () => [
|
||||||
{name: "Roman", base: 8, odd: 1, sort: "n / td(14) / t", shield: "roman"}, // Roman
|
{name: "Roman", base: 8, odd: 1, sort: "n() / td(14) / t()", shield: "roman"}, // Roman
|
||||||
{name: "Roman", base: 8, odd: 1, sort: "n / td(15) / sf(i)", shield: "roman"}, // Roman
|
{name: "Roman", base: 8, odd: 1, sort: "n() / td(15) / sf()", shield: "roman"}, // Roman
|
||||||
{name: "Roman", base: 8, odd: 1, sort: "n / td(16) / sf(i)", shield: "roman"}, // Roman
|
{name: "Roman", base: 8, odd: 1, sort: "n() / td(16) / sf()", shield: "roman"}, // Roman
|
||||||
{name: "Roman", base: 8, odd: 1, sort: "n / td(17) / t", shield: "roman"}, // Roman
|
{name: "Roman", base: 8, odd: 1, sort: "n() / td(17) / t()", shield: "roman"}, // Roman
|
||||||
{name: "Hellenic", base: 7, odd: 1, sort: "(n / td(18) / sf(i)) * h", shield: "boeotian"}, // Greek
|
{name: "Hellenic", base: 7, odd: 1, sort: "(n() / td(18) / sf) * h()", shield: "boeotian"}, // Greek
|
||||||
{name: "Hellenic", base: 7, odd: 1, sort: "(n / td(19) / sf(i)) * h", shield: "boeotian"}, // Greek
|
{name: "Hellenic", base: 7, odd: 1, sort: "(n() / td(19) / sf) * h()", shield: "boeotian"}, // Greek
|
||||||
{name: "Macedonian", base: 7, odd: 0.5, sort: "(n / td(12)) * h", shield: "round"}, // Greek
|
{name: "Macedonian", base: 7, odd: 0.5, sort: "(n() / td(12)) * h()", shield: "round"}, // Greek
|
||||||
{name: "Celtic", base: 22, odd: 1, sort: "n / td(11) ** 0.5 / bd([6, 8])", shield: "round"},
|
{name: "Celtic", base: 22, odd: 1, sort: "n() / td(11) ** 0.5 / bd([6, 8])", shield: "round"},
|
||||||
{name: "Germanic", base: 0, odd: 1, sort: "n / td(10) ** 0.5 / bd([6, 8])", shield: "round"},
|
{name: "Germanic", base: 0, odd: 1, sort: "n() / td(10) ** 0.5 / bd([6, 8])", shield: "round"},
|
||||||
{name: "Persian", base: 24, odd: 0.8, sort: "(n / td(18)) * h", shield: "oval"}, // Iranian
|
{name: "Persian", base: 24, odd: 0.8, sort: "(n() / td(18)) * h()", shield: "oval"}, // Iranian
|
||||||
{name: "Scythian", base: 24, odd: 0.5, sort: "n / td(11) ** 0.5 / bd([4])", shield: "round"}, // Iranian
|
{name: "Scythian", base: 24, odd: 0.5, sort: "n() / td(11) ** 0.5 / bd([4])", shield: "round"}, // Iranian
|
||||||
{name: "Cantabrian", base: 20, odd: 0.5, sort: "(n / td(16)) * h", shield: "oval"}, // Basque
|
{name: "Cantabrian", base: 20, odd: 0.5, sort: "(n() / td(16)) * h()", shield: "oval"}, // Basque
|
||||||
{name: "Estian", base: 9, odd: 0.2, sort: "(n / td(5)) * t", shield: "pavise"}, // Finnic
|
{name: "Estian", base: 9, odd: 0.2, sort: "(n() / td(5)) * t()", shield: "pavise"}, // Finnic
|
||||||
{name: "Carthaginian", base: 17, odd: 0.3, sort: "n / td(19) / sf(i)", shield: "oval"}, // Berber
|
{name: "Carthaginian", base: 17, odd: 0.3, sort: "n() / td(19) / sf()", shield: "oval"}, // Berber
|
||||||
{name: "Mesopotamian", base: 23, odd: 0.2, sort: "n / td(22) / bd([1, 2, 3])", shield: "oval"} // Mesopotamian
|
{name: "Mesopotamian", base: 23, odd: 0.2, sort: "n() / td(22) / bd([1, 2, 3])", shield: "oval"} // Mesopotamian
|
||||||
];
|
];
|
||||||
|
|
||||||
const highFantasy = () => [
|
const highFantasy = () => [
|
||||||
// fantasy races
|
// fantasy races
|
||||||
{name: "Quenian (Elfish)", base: 33, odd: 1, sort: "(n / bd([6, 7, 8, 9], 10)) * t", shield: "gondor"}, // Elves
|
{name: "Quenian (Elfish)", base: 33, odd: 1, sort: "(n() / bd([6, 7, 8, 9], 10)) * t()", shield: "gondor"}, // Elves
|
||||||
{name: "Eldar (Elfish)", base: 33, odd: 1, sort: "(n / bd([6, 7, 8, 9], 10)) * t", shield: "noldor"}, // Elves
|
{name: "Eldar (Elfish)", base: 33, odd: 1, sort: "(n() / bd([6, 7, 8, 9], 10)) * t()", shield: "noldor"}, // Elves
|
||||||
{name: "Trow (Dark Elfish)", base: 34, odd: 0.9, sort: "(n / bd([7, 8, 9, 12], 10)) * t", shield: "hessen"},
|
{name: "Trow (Dark Elfish)", base: 34, odd: 0.9, sort: "(n() / bd([7, 8, 9, 12], 10)) * t()", shield: "hessen"},
|
||||||
{name: "Lothian (Dark Elfish)", base: 34, odd: 0.3, sort: "(n / bd([7, 8, 9, 12], 10)) * t", shield: "wedged"},
|
{name: "Lothian (Dark Elfish)", base: 34, odd: 0.3, sort: "(n() / bd([7, 8, 9, 12], 10)) * t()", shield: "wedged"},
|
||||||
{name: "Dunirr (Dwarven)", base: 35, odd: 1, sort: "n + h", shield: "ironHills"}, // Dwarfs
|
{name: "Dunirr (Dwarven)", base: 35, odd: 1, sort: "n() + h()", shield: "ironHills"}, // Dwarfs
|
||||||
{name: "Khazadur (Dwarven)", base: 35, odd: 1, sort: "n + h", shield: "erebor"}, // Dwarfs
|
{name: "Khazadur (Dwarven)", base: 35, odd: 1, sort: "n() + h()", shield: "erebor"}, // Dwarfs
|
||||||
{name: "Kobold (Goblin)", base: 36, odd: 1, sort: "t - s", shield: "moriaOrc"}, // Goblin
|
{name: "Kobold (Goblin)", base: 36, odd: 1, sort: "t() - s()", shield: "moriaOrc"}, // Goblin
|
||||||
{name: "Uruk (Orkish)", base: 37, odd: 1, sort: "h * t", shield: "urukHai"}, // Orc
|
{name: "Uruk (Orkish)", base: 37, odd: 1, sort: "h() * t()", shield: "urukHai"}, // Orc
|
||||||
{name: "Ugluk (Orkish)", base: 37, odd: 0.5, sort: "(h * t) / bd([1, 2, 10, 11])", shield: "moriaOrc"}, // Orc
|
{name: "Ugluk (Orkish)", base: 37, odd: 0.5, sort: "(h * t) / bd([1, 2, 10, 11])", shield: "moriaOrc"}, // Orc
|
||||||
{name: "Yotunn (Giants)", base: 38, odd: 0.7, sort: "td(-10)", shield: "pavise"}, // Giant
|
{name: "Yotunn (Giants)", base: 38, odd: 0.7, sort: "td(-10)", shield: "pavise"}, // Giant
|
||||||
{name: "Rake (Drakonic)", base: 39, odd: 0.7, sort: "-s", shield: "fantasy2"}, // Draconic
|
{name: "Rake (Drakonic)", base: 39, odd: 0.7, sort: "- s()", shield: "fantasy2"}, // Draconic
|
||||||
{name: "Arago (Arachnid)", base: 40, odd: 0.7, sort: "t - s", shield: "horsehead2"}, // Arachnid
|
{name: "Arago (Arachnid)", base: 40, odd: 0.7, sort: "t() - s()", shield: "horsehead2"}, // Arachnid
|
||||||
{name: "Aj'Snaga (Serpents)", base: 41, odd: 0.7, sort: "n / bd([12], 10)", shield: "fantasy1"}, // Serpents
|
{name: "Aj'Snaga (Serpents)", base: 41, odd: 0.7, sort: "n() / bd([12], 10)", shield: "fantasy1"}, // Serpents
|
||||||
// fantasy human
|
// fantasy human
|
||||||
{name: "Anor (Human)", base: 32, odd: 1, sort: "n / td(10)", shield: "fantasy5"},
|
{name: "Anor (Human)", base: 32, odd: 1, sort: "n() / td(10)", shield: "fantasy5"},
|
||||||
{name: "Dail (Human)", base: 32, odd: 1, sort: "n / td(13)", shield: "roman"},
|
{name: "Dail (Human)", base: 32, odd: 1, sort: "n() / td(13)", shield: "roman"},
|
||||||
{name: "Rohand (Human)", base: 16, odd: 1, sort: "n / td(16)", shield: "round"},
|
{name: "Rohand (Human)", base: 16, odd: 1, sort: "n() / td(16)", shield: "round"},
|
||||||
{name: "Dulandir (Human)", base: 31, odd: 1, sort: "(n / td(5) / bd([2, 4, 10], 7)) * t", shield: "easterling"}
|
{name: "Dulandir (Human)", base: 31, odd: 1, sort: "(n() / td(5) / bd([2, 4, 10], 7)) * t()", shield: "easterling"}
|
||||||
];
|
];
|
||||||
|
|
||||||
const darkFantasy = () => [
|
const darkFantasy = () => [
|
||||||
// common real-world English
|
// common real-world English
|
||||||
{name: "Angshire", base: 1, odd: 1, sort: "n / td(10) / sf(i)", shield: "heater"},
|
{name: "Angshire", base: 1, odd: 1, sort: "n() / td(10) / sf()", shield: "heater"},
|
||||||
{name: "Enlandic", base: 1, odd: 1, sort: "n / td(12)", shield: "heater"},
|
{name: "Enlandic", base: 1, odd: 1, sort: "n() / td(12)", shield: "heater"},
|
||||||
{name: "Westen", base: 1, odd: 1, sort: "n / td(10)", shield: "heater"},
|
{name: "Westen", base: 1, odd: 1, sort: "n() / td(10)", shield: "heater"},
|
||||||
{name: "Nortumbic", base: 1, odd: 1, sort: "n / td(7)", shield: "heater"},
|
{name: "Nortumbic", base: 1, odd: 1, sort: "n() / td(7)", shield: "heater"},
|
||||||
{name: "Mercian", base: 1, odd: 1, sort: "n / td(9)", shield: "heater"},
|
{name: "Mercian", base: 1, odd: 1, sort: "n() / td(9)", shield: "heater"},
|
||||||
{name: "Kentian", base: 1, odd: 1, sort: "n / td(12)", shield: "heater"},
|
{name: "Kentian", base: 1, odd: 1, sort: "n() / td(12)", shield: "heater"},
|
||||||
// rare real-world western
|
// rare real-world western
|
||||||
{name: "Norse", base: 6, odd: 0.7, sort: "n / td(5) / sf(i)", shield: "oldFrench"},
|
{name: "Norse", base: 6, odd: 0.7, sort: "n() / td(5) / sf", shield: "oldFrench"},
|
||||||
{name: "Schwarzen", base: 0, odd: 0.3, sort: "n / td(10) / bd([6, 8])", shield: "gonfalon"},
|
{name: "Schwarzen", base: 0, odd: 0.3, sort: "n() / td(10) / bd([6, 8])", shield: "gonfalon"},
|
||||||
{name: "Luarian", base: 2, odd: 0.3, sort: "n / td(12) / bd([6, 8])", shield: "oldFrench"},
|
{name: "Luarian", base: 2, odd: 0.3, sort: "n() / td(12) / bd([6, 8])", shield: "oldFrench"},
|
||||||
{name: "Hetallian", base: 3, odd: 0.3, sort: "n / td(15)", shield: "oval"},
|
{name: "Hetallian", base: 3, odd: 0.3, sort: "n() / td(15)", shield: "oval"},
|
||||||
{name: "Astellian", base: 4, odd: 0.3, sort: "n / td(16)", shield: "spanish"},
|
{name: "Astellian", base: 4, odd: 0.3, sort: "n() / td(16)", shield: "spanish"},
|
||||||
// rare real-world exotic
|
// rare real-world exotic
|
||||||
{name: "Kiswaili", base: 28, odd: 0.05, sort: "n / td(29) / bd([1, 3, 5, 7])", shield: "vesicaPiscis"},
|
{name: "Kiswaili", base: 28, odd: 0.05, sort: "n() / td(29) / bd([1, 3, 5, 7])", shield: "vesicaPiscis"},
|
||||||
{name: "Yoruba", base: 21, odd: 0.05, sort: "n / td(15) / bd([5, 7])", shield: "vesicaPiscis"},
|
{name: "Yoruba", base: 21, odd: 0.05, sort: "n() / td(15) / bd([5, 7])", shield: "vesicaPiscis"},
|
||||||
{name: "Koryo", base: 10, odd: 0.05, sort: "n / td(12) / t", shield: "round"},
|
{name: "Koryo", base: 10, odd: 0.05, sort: "n() / td(12) / t", shield: "round"},
|
||||||
{name: "Hantzu", base: 11, odd: 0.05, sort: "n / td(13)", shield: "banner"},
|
{name: "Hantzu", base: 11, odd: 0.05, sort: "n() / td(13)", shield: "banner"},
|
||||||
{name: "Yamoto", base: 12, odd: 0.05, sort: "n / td(15) / t", shield: "round"},
|
{name: "Yamoto", base: 12, odd: 0.05, sort: "n() / td(15) / t", shield: "round"},
|
||||||
{name: "Guantzu", base: 30, odd: 0.05, sort: "n / td(17)", shield: "banner"},
|
{name: "Guantzu", base: 30, odd: 0.05, sort: "n() / td(17)", shield: "banner"},
|
||||||
{name: "Ulus", base: 31, odd: 0.05, sort: "(n / td(5) / bd([2, 4, 10], 7)) * t", shield: "banner"},
|
{name: "Ulus", base: 31, odd: 0.05, sort: "(n() / td(5) / bd([2, 4, 10], 7)) * t()", shield: "banner"},
|
||||||
{name: "Turan", base: 16, odd: 0.05, sort: "n / td(12)", shield: "round"},
|
{name: "Turan", base: 16, odd: 0.05, sort: "n() / td(12)", shield: "round"},
|
||||||
{name: "Berberan", base: 17, odd: 0.05, sort: "(n / td(19) / bd([1, 2, 3], 7)) * t", shield: "round"},
|
{name: "Berberan", base: 17, odd: 0.05, sort: "(n() / td(19) / bd([1, 2, 3], 7)) * t()", shield: "round"},
|
||||||
{name: "Eurabic", base: 18, odd: 0.05, sort: "(n / td(26) / bd([1, 2], 7)) * t", shield: "round"},
|
{name: "Eurabic", base: 18, odd: 0.05, sort: "(n() / td(26) / bd([1, 2], 7)) * t()", shield: "round"},
|
||||||
{name: "Slovan", base: 5, odd: 0.05, sort: "(n / td(6)) * t", shield: "round"},
|
{name: "Slovan", base: 5, odd: 0.05, sort: "(n() / td(6)) * t()", shield: "round"},
|
||||||
{name: "Keltan", base: 22, odd: 0.1, sort: "n / td(11) ** 0.5 / bd([6, 8])", shield: "vesicaPiscis"},
|
{name: "Keltan", base: 22, odd: 0.1, sort: "n() / td(11) ** 0.5 / bd([6, 8])", shield: "vesicaPiscis"},
|
||||||
{name: "Elladan", base: 7, odd: 0.2, sort: "(n / td(18) / sf(i)) * h", shield: "boeotian"},
|
{name: "Elladan", base: 7, odd: 0.2, sort: "(n() / td(18) / sf) * h()", shield: "boeotian"},
|
||||||
{name: "Romian", base: 8, odd: 0.2, sort: "n / td(14) / t", shield: "roman"},
|
{name: "Romian", base: 8, odd: 0.2, sort: "n() / td(14) / t", shield: "roman"},
|
||||||
// fantasy races
|
// fantasy races
|
||||||
{name: "Eldar", base: 33, odd: 0.5, sort: "(n / bd([6, 7, 8, 9], 10)) * t", shield: "fantasy5"}, // Elves
|
{name: "Eldar", base: 33, odd: 0.5, sort: "(n() / bd([6, 7, 8, 9], 10)) * t()", shield: "fantasy5"}, // Elves
|
||||||
{name: "Trow", base: 34, odd: 0.8, sort: "(n / bd([7, 8, 9, 12], 10)) * t", shield: "hessen"}, // Dark Elves
|
{name: "Trow", base: 34, odd: 0.8, sort: "(n() / bd([7, 8, 9, 12], 10)) * t()", shield: "hessen"}, // Dark Elves
|
||||||
{name: "Durinn", base: 35, odd: 0.8, sort: "n + h", shield: "erebor"}, // Dwarven
|
{name: "Durinn", base: 35, odd: 0.8, sort: "n() + h()", shield: "erebor"}, // Dwarven
|
||||||
{name: "Kobblin", base: 36, odd: 0.8, sort: "t - s", shield: "moriaOrc"}, // Goblin
|
{name: "Kobblin", base: 36, odd: 0.8, sort: "t() - s()", shield: "moriaOrc"}, // Goblin
|
||||||
{name: "Uruk", base: 37, odd: 0.8, sort: "(h * t) / bd([1, 2, 10, 11])", shield: "urukHai"}, // Orc
|
{name: "Uruk", base: 37, odd: 0.8, sort: "(h() * t()) / bd([1, 2, 10, 11])", shield: "urukHai"}, // Orc
|
||||||
{name: "Yotunn", base: 38, odd: 0.8, sort: "td(-10)", shield: "pavise"}, // Giant
|
{name: "Yotunn", base: 38, odd: 0.8, sort: "td(-10)", shield: "pavise"}, // Giant
|
||||||
{name: "Drake", base: 39, odd: 0.9, sort: "-s", shield: "fantasy2"}, // Draconic
|
{name: "Drake", base: 39, odd: 0.9, sort: "- s()", shield: "fantasy2"}, // Draconic
|
||||||
{name: "Rakhnid", base: 40, odd: 0.9, sort: "t - s", shield: "horsehead2"}, // Arachnid
|
{name: "Rakhnid", base: 40, odd: 0.9, sort: "t() - s()", shield: "horsehead2"}, // Arachnid
|
||||||
{name: "Aj'Snaga", base: 41, odd: 0.9, sort: "n / bd([12], 10)", shield: "fantasy1"} // Serpents
|
{name: "Aj'Snaga", base: 41, odd: 0.9, sort: "n() / bd([12], 10)", shield: "fantasy1"} // Serpents
|
||||||
];
|
];
|
||||||
|
|
||||||
const random = (culturesNumber: number) =>
|
const random = (culturesNumber: number) =>
|
||||||
|
|
|
||||||
|
|
@ -9,3 +9,32 @@ export enum DISTANCE_FIELD {
|
||||||
DEEPER_WATER = -2,
|
DEEPER_WATER = -2,
|
||||||
LANDLOCKED = 2
|
LANDLOCKED = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum ELEVATION {
|
||||||
|
MOUNTAINS = 70,
|
||||||
|
HILLS = 50,
|
||||||
|
LOWLANDS = 30
|
||||||
|
}
|
||||||
|
|
||||||
|
enum BIOME {
|
||||||
|
MARINE = 0,
|
||||||
|
HOT_DESERT = 1,
|
||||||
|
COLD_DESERT = 2,
|
||||||
|
SAVANNA = 3,
|
||||||
|
GRASSLAND = 4,
|
||||||
|
TROPICAL_SEASONAL_FOREST = 5,
|
||||||
|
TEMPERATE_DECIDUOUS_FOREST = 6,
|
||||||
|
TROPICAL_RAINFOREST = 7,
|
||||||
|
TEMPERATE_RAINFOREST = 8,
|
||||||
|
TAIGA = 9,
|
||||||
|
TUNDRA = 10,
|
||||||
|
GLACIER = 11,
|
||||||
|
WETLAND = 12
|
||||||
|
}
|
||||||
|
|
||||||
|
const {HOT_DESERT, COLD_DESERT, SAVANNA, GRASSLAND, TROPICAL_RAINFOREST, TEMPERATE_RAINFOREST, TAIGA, TUNDRA, WETLAND} =
|
||||||
|
BIOME;
|
||||||
|
|
||||||
|
export const NOMADIC_BIOMES = [HOT_DESERT, COLD_DESERT, GRASSLAND];
|
||||||
|
|
||||||
|
export const HUNTING_BIOMES = [SAVANNA, TROPICAL_RAINFOREST, TEMPERATE_RAINFOREST, TAIGA, TUNDRA, WETLAND];
|
||||||
|
|
|
||||||
|
|
@ -1,341 +0,0 @@
|
||||||
import * as d3 from "d3";
|
|
||||||
import FlatQueue from "flatqueue";
|
|
||||||
|
|
||||||
import {ERROR, TIME, WARN} from "config/logging";
|
|
||||||
import {getColors} from "utils/colorUtils";
|
|
||||||
import {rn, minmax} from "utils/numberUtils";
|
|
||||||
import {rand, P, biased} from "utils/probabilityUtils";
|
|
||||||
import {abbreviate} from "utils/languageUtils";
|
|
||||||
import {getInputNumber, getInputValue, getSelectedOption} from "utils/nodeUtils";
|
|
||||||
import {byId} from "utils/shorthands";
|
|
||||||
import {cultureSets, TCultureSetName} from "config/cultureSets";
|
|
||||||
import {DISTANCE_FIELD, ELEVATION, HUNTING_BIOMES, NOMADIC_BIOMES} from "config/generation";
|
|
||||||
|
|
||||||
const {COA, Names} = window;
|
|
||||||
|
|
||||||
const cultureTypeBaseExpansionism: {[key in TCultureType]: number} = {
|
|
||||||
Generic: 1,
|
|
||||||
Lake: 0.8,
|
|
||||||
Naval: 1.5,
|
|
||||||
River: 0.9,
|
|
||||||
Nomadic: 1.5,
|
|
||||||
Hunting: 0.7,
|
|
||||||
Highland: 1.2
|
|
||||||
};
|
|
||||||
|
|
||||||
const {MOUNTAINS, HILLS} = ELEVATION;
|
|
||||||
const {LAND_COAST, LANDLOCKED} = DISTANCE_FIELD;
|
|
||||||
|
|
||||||
window.Cultures = (function () {
|
|
||||||
let cells: IGraphCells & IPackCells;
|
|
||||||
|
|
||||||
const generate = function (pack: IPack): {culture: Uint16Array; cultures: TCultures} {
|
|
||||||
TIME && console.time("generateCultures");
|
|
||||||
cells = pack.cells;
|
|
||||||
|
|
||||||
const wildlands: IWilderness = {name: "Wildlands", i: 0, base: 1, origins: [null], shield: "round"};
|
|
||||||
const culture = new Uint16Array(cells.i.length); // cell cultures
|
|
||||||
|
|
||||||
const populatedCellIds = cells.i.filter(cellId => cells.pop[cellId] > 0);
|
|
||||||
|
|
||||||
const culturesNumber = getCulturesNumber(populatedCellIds.length);
|
|
||||||
if (!culturesNumber) return {culture, cultures: [wildlands]};
|
|
||||||
|
|
||||||
const culturesData = selectCulturesData(culturesNumber);
|
|
||||||
const colors = getColors(culturesNumber);
|
|
||||||
|
|
||||||
const powerInput = getInputNumber("powerInput");
|
|
||||||
const emblemShape = getInputValue("emblemShape");
|
|
||||||
const isEmblemShareRandom = emblemShape === "random";
|
|
||||||
|
|
||||||
const codes: string[] = [];
|
|
||||||
const centers = d3.quadtree();
|
|
||||||
|
|
||||||
const definedCultures: ICulture[] = culturesData.map((cultureData, index) => {
|
|
||||||
const sort = cultureData.sort || "n";
|
|
||||||
const sortingFn = new Function("return " + sort);
|
|
||||||
const cell = placeCenter(sortingFn);
|
|
||||||
|
|
||||||
const {name} = cultureData;
|
|
||||||
const base = checkNamesbase(cultureData.base);
|
|
||||||
const color = colors[index];
|
|
||||||
const type = defineCultureType(cell);
|
|
||||||
const expansionism = defineCultureExpansionism(type);
|
|
||||||
|
|
||||||
const origins = [0];
|
|
||||||
const code = abbreviate(name, codes);
|
|
||||||
const shield = isEmblemShareRandom ? COA.getRandomShield() : cultureData.shield;
|
|
||||||
|
|
||||||
centers.add(cells.p[cell]);
|
|
||||||
codes.push(code);
|
|
||||||
cells.culture[cell] = index + 1;
|
|
||||||
|
|
||||||
return {i: index + 1, name, base, cell, color, type, expansionism, origins, code, shield};
|
|
||||||
});
|
|
||||||
|
|
||||||
const cultures: TCultures = [wildlands, ...definedCultures];
|
|
||||||
|
|
||||||
TIME && console.timeEnd("generateCultures");
|
|
||||||
|
|
||||||
return {culture, cultures};
|
|
||||||
|
|
||||||
function getCulturesNumber(populatedCells: number) {
|
|
||||||
const culturesDesired = getInputNumber("culturesInput");
|
|
||||||
const culturesAvailable = Number(getSelectedOption("culturesSet").dataset.max);
|
|
||||||
const expectedNumber = Math.min(culturesDesired, culturesAvailable);
|
|
||||||
|
|
||||||
// normal case, enough populated cells to generate cultures
|
|
||||||
if (populatedCells >= expectedNumber * 25) return expectedNumber;
|
|
||||||
|
|
||||||
// not enough populated cells, reduce count
|
|
||||||
const reducedNumber = Math.floor(populatedCells / 50);
|
|
||||||
|
|
||||||
if (reducedNumber > 0) {
|
|
||||||
WARN &&
|
|
||||||
console.warn(`Not enough populated cells (${populatedCells}). Will generate only ${reducedNumber} cultures`);
|
|
||||||
|
|
||||||
byId("alertMessage")!.innerHTML = `Insufficient liveable area: ${populatedCells} populated cells.<br />
|
|
||||||
Only ${reducedNumber} out of ${culturesDesired} requested cultures can be created.<br />
|
|
||||||
Please consider changing climate settings in the World Configurator`;
|
|
||||||
} else {
|
|
||||||
WARN && console.warn(`No populated cells. Cannot generate cultures`);
|
|
||||||
|
|
||||||
byId("alertMessage")!.innerHTML = `The climate is harsh and people cannot live in this world.<br />
|
|
||||||
No cultures, states and burgs will be created.<br />
|
|
||||||
Please consider changing climate settings in the World Configurator`;
|
|
||||||
}
|
|
||||||
|
|
||||||
$("#alert").dialog({
|
|
||||||
resizable: false,
|
|
||||||
title: "Extreme climate warning",
|
|
||||||
buttons: {
|
|
||||||
Ok: function () {
|
|
||||||
$(this).dialog("close");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return reducedNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
function selectCulturesData(culturesNumber: number) {
|
|
||||||
let defaultCultures = getDefault(culturesNumber);
|
|
||||||
if (defaultCultures.length >= culturesNumber) return defaultCultures;
|
|
||||||
|
|
||||||
const culturesAvailable = Math.min(culturesNumber, defaultCultures.length);
|
|
||||||
const cultures = [];
|
|
||||||
|
|
||||||
for (let culture, rnd, i = 0; cultures.length < culturesAvailable && i < 200; i++) {
|
|
||||||
do {
|
|
||||||
rnd = rand(defaultCultures.length - 1);
|
|
||||||
culture = defaultCultures[rnd];
|
|
||||||
} while (!P(culture.odd));
|
|
||||||
cultures.push(culture);
|
|
||||||
defaultCultures.splice(rnd, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return cultures;
|
|
||||||
}
|
|
||||||
|
|
||||||
function placeCenter(sort: Function) {
|
|
||||||
let c;
|
|
||||||
let spacing = (graphWidth + graphHeight) / 2 / culturesNumber;
|
|
||||||
const sorted = Array.from(populatedCellIds).sort((a, b) => sort(b) - sort(a));
|
|
||||||
const max = Math.floor(sorted.length / 2);
|
|
||||||
|
|
||||||
do {
|
|
||||||
c = sorted[biased(0, max, 5)];
|
|
||||||
spacing *= 0.9;
|
|
||||||
} while (centers.find(cells.p[c][0], cells.p[c][1], spacing) !== undefined);
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
// set culture type based on culture center position
|
|
||||||
function defineCultureType(cellId: number): TCultureType {
|
|
||||||
const height = cells.h[cellId];
|
|
||||||
|
|
||||||
if (height > HILLS) return "Highland";
|
|
||||||
|
|
||||||
const biome = cells.biome[cellId];
|
|
||||||
if (height < MOUNTAINS && NOMADIC_BIOMES.includes(biome)) return "Nomadic";
|
|
||||||
|
|
||||||
if (cells.t[cellId] === LAND_COAST) {
|
|
||||||
const waterFeatureId = cells.f[cells.haven[cellId]];
|
|
||||||
const waterFeature = pack.features[waterFeatureId];
|
|
||||||
|
|
||||||
const isBigLakeCoast = waterFeature && waterFeature.type === "lake" && waterFeature.cells > 5;
|
|
||||||
if (isBigLakeCoast) return "Lake";
|
|
||||||
|
|
||||||
const isOceanCoast = waterFeature && waterFeature.type === "ocean";
|
|
||||||
if (isOceanCoast && P(0.1)) return "Naval";
|
|
||||||
|
|
||||||
const isSafeHarbor = cells.harbor[cellId] === 1;
|
|
||||||
if (isSafeHarbor && P(0.6)) return "Naval";
|
|
||||||
|
|
||||||
const cellFeature = pack.features[cells.f[cellId]];
|
|
||||||
const isIsle = cellFeature && cellFeature.group === "isle";
|
|
||||||
if (isIsle && P(0.4)) return "Naval";
|
|
||||||
}
|
|
||||||
|
|
||||||
const isOnBigRiver = cells.r[cellId] && cells.fl[cellId] > 100;
|
|
||||||
if (isOnBigRiver) return "River";
|
|
||||||
|
|
||||||
const isDeelyLandlocked = cells.t[cellId] > LANDLOCKED;
|
|
||||||
if (isDeelyLandlocked && HUNTING_BIOMES.includes(biome)) return "Hunting";
|
|
||||||
|
|
||||||
return "Generic";
|
|
||||||
}
|
|
||||||
|
|
||||||
function defineCultureExpansionism(type: TCultureType) {
|
|
||||||
const baseExp = cultureTypeBaseExpansionism[type];
|
|
||||||
return rn(((Math.random() * powerInput) / 2 + 1) * baseExp, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkNamesbase(base: number) {
|
|
||||||
// make sure namesbase exists in nameBases
|
|
||||||
if (!nameBases.length) {
|
|
||||||
ERROR && console.error("Name base is empty, default nameBases will be applied");
|
|
||||||
nameBases = Names.getNameBases();
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if base is in nameBases
|
|
||||||
if (base > nameBases.length) return base;
|
|
||||||
ERROR && console.error(`Name base ${base} is not available, applying a fallback one`);
|
|
||||||
return base % nameBases.length;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const add = function (center) {
|
|
||||||
const defaultCultures = getDefault();
|
|
||||||
let culture, base, name;
|
|
||||||
|
|
||||||
if (pack.cultures.length < defaultCultures.length) {
|
|
||||||
// add one of the default cultures
|
|
||||||
culture = pack.cultures.length;
|
|
||||||
base = defaultCultures[culture].base;
|
|
||||||
name = defaultCultures[culture].name;
|
|
||||||
} else {
|
|
||||||
// add random culture besed on one of the current ones
|
|
||||||
culture = rand(pack.cultures.length - 1);
|
|
||||||
name = Names.getCulture(culture, 5, 8, "");
|
|
||||||
base = pack.cultures[culture].base;
|
|
||||||
}
|
|
||||||
const code = abbreviate(
|
|
||||||
name,
|
|
||||||
pack.cultures.map(c => c.code)
|
|
||||||
);
|
|
||||||
const i = pack.cultures.length;
|
|
||||||
const color = d3.color(d3.scaleSequential(d3.interpolateRainbow)(Math.random())).hex();
|
|
||||||
|
|
||||||
// define emblem shape
|
|
||||||
let shield = culture.shield;
|
|
||||||
const emblemShape = document.getElementById("emblemShape").value;
|
|
||||||
if (emblemShape === "random") shield = COA.getRandomShield();
|
|
||||||
|
|
||||||
pack.cultures.push({
|
|
||||||
name,
|
|
||||||
color,
|
|
||||||
base,
|
|
||||||
center,
|
|
||||||
i,
|
|
||||||
expansionism: 1,
|
|
||||||
type: "Generic",
|
|
||||||
cells: 0,
|
|
||||||
area: 0,
|
|
||||||
rural: 0,
|
|
||||||
urban: 0,
|
|
||||||
origins: [0],
|
|
||||||
code,
|
|
||||||
shield
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const getDefault = function (culturesNumber: number) {
|
|
||||||
const cultureSet = getInputValue("culturesSet") as TCultureSetName;
|
|
||||||
if (cultureSet in cultureSets) {
|
|
||||||
return cultureSets[cultureSet](culturesNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error(`Unsupported culture set: ${cultureSet}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
// expand cultures across the map (Dijkstra-like algorithm)
|
|
||||||
const expand = function () {
|
|
||||||
TIME && console.time("expandCultures");
|
|
||||||
cells = pack.cells;
|
|
||||||
|
|
||||||
const queue = new FlatQueue();
|
|
||||||
pack.cultures.forEach(culture => {
|
|
||||||
if (!culture.i || culture.removed) return;
|
|
||||||
queue.push({cellId: culture.center, cultureId: culture.i}, 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
const neutral = (cells.i.length / 5000) * 3000 * neutralInput.value; // limit cost for culture growth
|
|
||||||
const cost = [];
|
|
||||||
|
|
||||||
while (queue.length) {
|
|
||||||
const priority = queue.peekValue();
|
|
||||||
const {cellId, cultureId} = queue.pop();
|
|
||||||
|
|
||||||
const type = pack.cultures[cultureId].type;
|
|
||||||
cells.c[cellId].forEach(neibCellId => {
|
|
||||||
const biome = cells.biome[neibCellId];
|
|
||||||
const biomeCost = getBiomeCost(cultureId, biome, type);
|
|
||||||
const biomeChangeCost = biome === cells.biome[cellId] ? 0 : 20; // penalty on biome change
|
|
||||||
const heightCost = getHeightCost(neibCellId, cells.h[neibCellId], type);
|
|
||||||
const riverCost = getRiverCost(cells.r[neibCellId], neibCellId, type);
|
|
||||||
const typeCost = getTypeCost(cells.t[neibCellId], type);
|
|
||||||
const totalCost =
|
|
||||||
priority +
|
|
||||||
(biomeCost + biomeChangeCost + heightCost + riverCost + typeCost) / pack.cultures[cultureId].expansionism;
|
|
||||||
|
|
||||||
if (totalCost > neutral) return;
|
|
||||||
|
|
||||||
if (!cost[neibCellId] || totalCost < cost[neibCellId]) {
|
|
||||||
if (cells.s[neibCellId] > 0) cells.culture[neibCellId] = cultureId; // assign culture to populated cell
|
|
||||||
cost[neibCellId] = totalCost;
|
|
||||||
queue.push({cellId: neibCellId, cultureId}, totalCost);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
TIME && console.timeEnd("expandCultures");
|
|
||||||
};
|
|
||||||
|
|
||||||
function getBiomeCost(c, biome, type) {
|
|
||||||
if (cells.biome[pack.cultures[c].center] === biome) return 10; // tiny penalty for native biome
|
|
||||||
if (type === "Hunting") return biomesData.cost[biome] * 5; // non-native biome penalty for hunters
|
|
||||||
if (type === "Nomadic" && biome > 4 && biome < 10) return biomesData.cost[biome] * 10; // forest biome penalty for nomads
|
|
||||||
return biomesData.cost[biome] * 2; // general non-native biome penalty
|
|
||||||
}
|
|
||||||
|
|
||||||
function getHeightCost(i, h, type) {
|
|
||||||
const f = pack.features[cells.f[i]],
|
|
||||||
a = cells.area[i];
|
|
||||||
if (type === "Lake" && f.type === "lake") return 10; // no lake crossing penalty for Lake cultures
|
|
||||||
if (type === "Naval" && h < 20) return a * 2; // low sea/lake crossing penalty for Naval cultures
|
|
||||||
if (type === "Nomadic" && h < 20) return a * 50; // giant sea/lake crossing penalty for Nomads
|
|
||||||
if (h < 20) return a * 6; // general sea/lake crossing penalty
|
|
||||||
if (type === "Highland" && h < 44) return 3000; // giant penalty for highlanders on lowlands
|
|
||||||
if (type === "Highland" && h < 62) return 200; // giant penalty for highlanders on lowhills
|
|
||||||
if (type === "Highland") return 0; // no penalty for highlanders on highlands
|
|
||||||
if (h >= 67) return 200; // general mountains crossing penalty
|
|
||||||
if (h >= 44) return 30; // general hills crossing penalty
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getRiverCost(r, i, type) {
|
|
||||||
if (type === "River") return r ? 0 : 100; // penalty for river cultures
|
|
||||||
if (!r) return 0; // no penalty for others if there is no river
|
|
||||||
return minmax(cells.fl[i] / 10, 20, 100); // river penalty from 20 to 100 based on flux
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTypeCost(t, type) {
|
|
||||||
if (t === 1) return type === "Naval" || type === "Lake" ? 0 : type === "Nomadic" ? 60 : 20; // penalty for coastline
|
|
||||||
if (t === 2) return type === "Naval" || type === "Nomadic" ? 30 : 0; // low penalty for land level 2 for Navals and nomads
|
|
||||||
if (t !== -1) return type === "Naval" || type === "Lake" ? 100 : 0; // penalty for mainland for navals
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {generate, add, expand, getDefault};
|
|
||||||
})();
|
|
||||||
371
src/scripts/generation/pack/cultures.ts
Normal file
371
src/scripts/generation/pack/cultures.ts
Normal file
|
|
@ -0,0 +1,371 @@
|
||||||
|
import * as d3 from "d3";
|
||||||
|
import FlatQueue from "flatqueue";
|
||||||
|
|
||||||
|
import {cultureSets, TCultureSetName} from "config/cultureSets";
|
||||||
|
import {DISTANCE_FIELD, ELEVATION, HUNTING_BIOMES, NOMADIC_BIOMES} from "config/generation";
|
||||||
|
import {ERROR, TIME, WARN} from "config/logging";
|
||||||
|
import {getColors} from "utils/colorUtils";
|
||||||
|
import {abbreviate} from "utils/languageUtils";
|
||||||
|
import {getInputNumber, getInputValue, getSelectedOption} from "utils/nodeUtils";
|
||||||
|
import {minmax, rn} from "utils/numberUtils";
|
||||||
|
import {biased, P, rand} from "utils/probabilityUtils";
|
||||||
|
import {byId} from "utils/shorthands";
|
||||||
|
|
||||||
|
const {COA, Names} = window;
|
||||||
|
|
||||||
|
const cultureTypeBaseExpansionism: {[key in TCultureType]: number} = {
|
||||||
|
Generic: 1,
|
||||||
|
Lake: 0.8,
|
||||||
|
Naval: 1.5,
|
||||||
|
River: 0.9,
|
||||||
|
Nomadic: 1.5,
|
||||||
|
Hunting: 0.7,
|
||||||
|
Highland: 1.2
|
||||||
|
};
|
||||||
|
|
||||||
|
const {MOUNTAINS, HILLS} = ELEVATION;
|
||||||
|
const {LAND_COAST, LANDLOCKED, WATER_COAST} = DISTANCE_FIELD;
|
||||||
|
|
||||||
|
export const generateCultures = function (
|
||||||
|
features: TPackFeatures,
|
||||||
|
cells: Pick<
|
||||||
|
IPack["cells"],
|
||||||
|
"p" | "i" | "g" | "t" | "h" | "haven" | "harbor" | "f" | "r" | "fl" | "s" | "pop" | "biome"
|
||||||
|
>,
|
||||||
|
temp: Int8Array
|
||||||
|
): {cultureIds: Uint16Array; cultures: TCultures} {
|
||||||
|
TIME && console.time("generateCultures");
|
||||||
|
|
||||||
|
const wildlands: IWilderness = {name: "Wildlands", i: 0, base: 1, origins: [null], shield: "round"};
|
||||||
|
const cultureIds = new Uint16Array(cells.i.length); // cell cultures
|
||||||
|
|
||||||
|
const populatedCellIds = cells.i.filter(cellId => cells.pop[cellId] > 0);
|
||||||
|
|
||||||
|
const culturesNumber = getCulturesNumber(populatedCellIds.length);
|
||||||
|
if (!culturesNumber) return {cultureIds, cultures: [wildlands]};
|
||||||
|
|
||||||
|
const culturesData = selectCulturesData(culturesNumber);
|
||||||
|
const colors = getColors(culturesNumber);
|
||||||
|
|
||||||
|
const powerInput = getInputNumber("powerInput");
|
||||||
|
const emblemShape = getInputValue("emblemShape");
|
||||||
|
const isEmblemShareRandom = emblemShape === "random";
|
||||||
|
|
||||||
|
const codes: string[] = [];
|
||||||
|
const centers = d3.quadtree();
|
||||||
|
|
||||||
|
const definedCultures: ICulture[] = culturesData.map((cultureData, index) => {
|
||||||
|
const {name, sort} = cultureData;
|
||||||
|
const center = placeCenter(sort || "n");
|
||||||
|
const base = checkNamesbase(cultureData.base);
|
||||||
|
const color = colors[index];
|
||||||
|
const type = defineCultureType(center);
|
||||||
|
const expansionism = defineCultureExpansionism(type);
|
||||||
|
|
||||||
|
const origins = [0];
|
||||||
|
const code = abbreviate(name, codes);
|
||||||
|
const shield = isEmblemShareRandom ? COA.getRandomShield() : cultureData.shield;
|
||||||
|
|
||||||
|
centers.add(cells.p[center]);
|
||||||
|
codes.push(code);
|
||||||
|
cultureIds[center] = index + 1;
|
||||||
|
|
||||||
|
return {i: index + 1, name, base, center, color, type, expansionism, origins, code, shield};
|
||||||
|
});
|
||||||
|
|
||||||
|
TIME && console.timeEnd("generateCultures");
|
||||||
|
return {cultureIds, cultures: [wildlands, ...definedCultures]};
|
||||||
|
|
||||||
|
function getCulturesNumber(populatedCells: number) {
|
||||||
|
const culturesDesired = getInputNumber("culturesInput");
|
||||||
|
const culturesAvailable = Number(getSelectedOption("culturesSet").dataset.max);
|
||||||
|
const expectedNumber = Math.min(culturesDesired, culturesAvailable);
|
||||||
|
|
||||||
|
// normal case, enough populated cells to generate cultures
|
||||||
|
if (populatedCells >= expectedNumber * 25) return expectedNumber;
|
||||||
|
|
||||||
|
// not enough populated cells, reduce count
|
||||||
|
const reducedNumber = Math.floor(populatedCells / 50);
|
||||||
|
|
||||||
|
if (reducedNumber > 0) {
|
||||||
|
WARN &&
|
||||||
|
console.warn(`Not enough populated cells (${populatedCells}). Will generate only ${reducedNumber} cultures`);
|
||||||
|
|
||||||
|
byId("alertMessage")!.innerHTML = `Insufficient liveable area: ${populatedCells} populated cells.<br />
|
||||||
|
Only ${reducedNumber} out of ${culturesDesired} requested cultures can be created.<br />
|
||||||
|
Please consider changing climate settings in the World Configurator`;
|
||||||
|
} else {
|
||||||
|
WARN && console.warn(`No populated cells. Cannot generate cultures`);
|
||||||
|
|
||||||
|
byId("alertMessage")!.innerHTML = `The climate is harsh and people cannot live in this world.<br />
|
||||||
|
No cultures, states and burgs will be created.<br />
|
||||||
|
Please consider changing climate settings in the World Configurator`;
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#alert").dialog({
|
||||||
|
resizable: false,
|
||||||
|
title: "Extreme climate warning",
|
||||||
|
buttons: {
|
||||||
|
Ok: function () {
|
||||||
|
$(this).dialog("close");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return reducedNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectCulturesData(culturesNumber: number) {
|
||||||
|
let defaultCultures = getDefault(culturesNumber);
|
||||||
|
if (defaultCultures.length >= culturesNumber) return defaultCultures;
|
||||||
|
|
||||||
|
const culturesAvailable = Math.min(culturesNumber, defaultCultures.length);
|
||||||
|
const cultures = [];
|
||||||
|
|
||||||
|
for (let culture, rnd, i = 0; cultures.length < culturesAvailable && i < 200; i++) {
|
||||||
|
do {
|
||||||
|
rnd = rand(defaultCultures.length - 1);
|
||||||
|
culture = defaultCultures[rnd];
|
||||||
|
} while (!P(culture.odd));
|
||||||
|
cultures.push(culture);
|
||||||
|
defaultCultures.splice(rnd, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cultures;
|
||||||
|
}
|
||||||
|
|
||||||
|
function placeCenter(sortingString: string) {
|
||||||
|
let cellId: number;
|
||||||
|
|
||||||
|
const sMax = d3.max(cells.s)!;
|
||||||
|
|
||||||
|
const sortingMethods = {
|
||||||
|
n: () => Math.ceil((cells.s[cellId] / sMax) * 3), // normalized cell score
|
||||||
|
td: (goalTemp: number) => {
|
||||||
|
const tempDelta = Math.abs(temp[cells.g[cellId]] - goalTemp);
|
||||||
|
return tempDelta ? tempDelta + 1 : 1;
|
||||||
|
},
|
||||||
|
bd: (biomes: number[], fee = 4) => {
|
||||||
|
return biomes.includes(cells.biome[cellId]) ? 1 : fee;
|
||||||
|
},
|
||||||
|
sf: (fee = 4) => {
|
||||||
|
const haven = cells.haven[cellId];
|
||||||
|
const havenHeature = features[haven];
|
||||||
|
return haven && havenHeature && havenHeature.type !== "lake" ? 1 : fee;
|
||||||
|
},
|
||||||
|
t: () => cells.t[cellId],
|
||||||
|
h: () => cells.h[cellId],
|
||||||
|
s: () => cells.s[cellId]
|
||||||
|
};
|
||||||
|
const allSortingMethods = `{${Object.keys(sortingMethods).join(", ")}}`;
|
||||||
|
|
||||||
|
const sortFn = new Function(allSortingMethods, "return " + sortingString);
|
||||||
|
const comparator = (a: number, b: number) => {
|
||||||
|
cellId = a;
|
||||||
|
const cellA = sortFn({...sortingMethods});
|
||||||
|
|
||||||
|
cellId = b;
|
||||||
|
const cellB = sortFn(sortingMethods);
|
||||||
|
|
||||||
|
return cellB - cellA;
|
||||||
|
};
|
||||||
|
|
||||||
|
let spacing = (graphWidth + graphHeight) / 2 / culturesNumber;
|
||||||
|
const sorted = Array.from(populatedCellIds).sort(comparator);
|
||||||
|
const max = Math.floor(sorted.length / 2);
|
||||||
|
|
||||||
|
do {
|
||||||
|
cellId = sorted[biased(0, max, 5)];
|
||||||
|
spacing *= 0.9;
|
||||||
|
} while (centers.find(...cells.p[cellId], spacing) !== undefined);
|
||||||
|
return cellId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set culture type based on culture center position
|
||||||
|
function defineCultureType(cellId: number): TCultureType {
|
||||||
|
const height = cells.h[cellId];
|
||||||
|
|
||||||
|
if (height > HILLS) return "Highland";
|
||||||
|
|
||||||
|
const biome = cells.biome[cellId];
|
||||||
|
if (height < MOUNTAINS && NOMADIC_BIOMES.includes(biome)) return "Nomadic";
|
||||||
|
|
||||||
|
if (cells.t[cellId] === LAND_COAST) {
|
||||||
|
const waterFeatureId = cells.f[cells.haven[cellId]];
|
||||||
|
const waterFeature = features[waterFeatureId];
|
||||||
|
|
||||||
|
const isBigLakeCoast = waterFeature && waterFeature.type === "lake" && waterFeature.cells > 5;
|
||||||
|
if (isBigLakeCoast) return "Lake";
|
||||||
|
|
||||||
|
const isOceanCoast = waterFeature && waterFeature.type === "ocean";
|
||||||
|
if (isOceanCoast && P(0.1)) return "Naval";
|
||||||
|
|
||||||
|
const isSafeHarbor = cells.harbor[cellId] === 1;
|
||||||
|
if (isSafeHarbor && P(0.6)) return "Naval";
|
||||||
|
|
||||||
|
const cellFeature = features[cells.f[cellId]];
|
||||||
|
const isIsle = cellFeature && cellFeature.group === "isle";
|
||||||
|
if (isIsle && P(0.4)) return "Naval";
|
||||||
|
}
|
||||||
|
|
||||||
|
const isOnBigRiver = cells.r[cellId] && cells.fl[cellId] > 100;
|
||||||
|
if (isOnBigRiver) return "River";
|
||||||
|
|
||||||
|
const isDeelyLandlocked = cells.t[cellId] > LANDLOCKED;
|
||||||
|
if (isDeelyLandlocked && HUNTING_BIOMES.includes(biome)) return "Hunting";
|
||||||
|
|
||||||
|
return "Generic";
|
||||||
|
}
|
||||||
|
|
||||||
|
function defineCultureExpansionism(type: TCultureType) {
|
||||||
|
const baseExp = cultureTypeBaseExpansionism[type];
|
||||||
|
return rn(((Math.random() * powerInput) / 2 + 1) * baseExp, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkNamesbase(base: number) {
|
||||||
|
// make sure namesbase exists in nameBases
|
||||||
|
if (!nameBases.length) {
|
||||||
|
ERROR && console.error("Name base is empty, default nameBases will be applied");
|
||||||
|
nameBases = Names.getNameBases();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if base is in nameBases
|
||||||
|
if (base > nameBases.length) return base;
|
||||||
|
ERROR && console.error(`Name base ${base} is not available, applying a fallback one`);
|
||||||
|
return base % nameBases.length;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getDefault = function (culturesNumber: number) {
|
||||||
|
const cultureSet = getInputValue("culturesSet") as TCultureSetName;
|
||||||
|
if (cultureSet in cultureSets) {
|
||||||
|
return cultureSets[cultureSet](culturesNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(`Unsupported culture set: ${cultureSet}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
// expand cultures across the map (Dijkstra-like algorithm)
|
||||||
|
export const expand = function () {
|
||||||
|
TIME && console.time("expandCultures");
|
||||||
|
|
||||||
|
const queue = new FlatQueue();
|
||||||
|
pack.cultures.forEach(culture => {
|
||||||
|
if (!culture.i || culture.removed) return;
|
||||||
|
queue.push({cellId: culture.center, cultureId: culture.i}, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
const neutral = (cells.i.length / 5000) * 3000 * neutralInput.value; // limit cost for culture growth
|
||||||
|
const cost = [];
|
||||||
|
|
||||||
|
while (queue.length) {
|
||||||
|
const priority = queue.peekValue();
|
||||||
|
const {cellId, cultureId} = queue.pop();
|
||||||
|
|
||||||
|
const type = pack.cultures[cultureId].type;
|
||||||
|
cells.c[cellId].forEach(neibCellId => {
|
||||||
|
const biome = cells.biome[neibCellId];
|
||||||
|
const biomeCost = getBiomeCost(cultureId, biome, type);
|
||||||
|
const biomeChangeCost = biome === cells.biome[cellId] ? 0 : 20; // penalty on biome change
|
||||||
|
const heightCost = getHeightCost(neibCellId, cells.h[neibCellId], type);
|
||||||
|
const riverCost = getRiverCost(cells.r[neibCellId], neibCellId, type);
|
||||||
|
const typeCost = getTypeCost(cells.t[neibCellId], type);
|
||||||
|
const totalCost =
|
||||||
|
priority +
|
||||||
|
(biomeCost + biomeChangeCost + heightCost + riverCost + typeCost) / pack.cultures[cultureId].expansionism;
|
||||||
|
|
||||||
|
if (totalCost > neutral) return;
|
||||||
|
|
||||||
|
if (!cost[neibCellId] || totalCost < cost[neibCellId]) {
|
||||||
|
if (cells.s[neibCellId] > 0) cells.culture[neibCellId] = cultureId; // assign culture to populated cell
|
||||||
|
cost[neibCellId] = totalCost;
|
||||||
|
queue.push({cellId: neibCellId, cultureId}, totalCost);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
TIME && console.timeEnd("expandCultures");
|
||||||
|
};
|
||||||
|
|
||||||
|
function getBiomeCost(cultureId: number, biome: number, type: TCultureType) {
|
||||||
|
const center = cultureId && (pack.cultures[cultureId] as ICulture).center;
|
||||||
|
const cultureBiome = cells.biome[center];
|
||||||
|
|
||||||
|
if (cultureBiome === biome) return 10; // tiny penalty for native biome
|
||||||
|
if (type === "Hunting") return biomesData.cost[biome] * 5; // non-native biome penalty for hunters
|
||||||
|
if (type === "Nomadic" && biome > 4 && biome < 10) return biomesData.cost[biome] * 10; // forest biome penalty for nomads
|
||||||
|
return biomesData.cost[biome] * 2; // general non-native biome penalty
|
||||||
|
}
|
||||||
|
|
||||||
|
function getHeightCost(cellId: number, height: number, type: TCultureType) {
|
||||||
|
const feature = pack.features[cells.f[cellId]];
|
||||||
|
const area = cells.area[cellId];
|
||||||
|
if (type === "Lake" && feature && feature.type === "lake") return 10; // no lake crossing penalty for Lake cultures
|
||||||
|
if (type === "Naval" && height < 20) return area * 2; // low sea/lake crossing penalty for Naval cultures
|
||||||
|
if (type === "Nomadic" && height < 20) return area * 50; // giant sea/lake crossing penalty for Nomads
|
||||||
|
if (height < 20) return area * 6; // general sea/lake crossing penalty
|
||||||
|
if (type === "Highland" && height < 44) return 3000; // giant penalty for highlanders on lowlands
|
||||||
|
if (type === "Highland" && height < 62) return 200; // giant penalty for highlanders on lowhills
|
||||||
|
if (type === "Highland") return 0; // no penalty for highlanders on highlands
|
||||||
|
if (height >= 67) return 200; // general mountains crossing penalty
|
||||||
|
if (height >= 44) return 30; // general hills crossing penalty
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRiverCost(riverId: number, cellId: number, type: TCultureType) {
|
||||||
|
if (type === "River") return riverId ? 0 : 100; // penalty for river cultures
|
||||||
|
if (!riverId) return 0; // no penalty for others if there is no river
|
||||||
|
return minmax(cells.fl[cellId] / 10, 20, 100); // river penalty from 20 to 100 based on flux
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTypeCost(t: number, type: TCultureType) {
|
||||||
|
if (t === LAND_COAST) return type === "Naval" || type === "Lake" ? 0 : type === "Nomadic" ? 60 : 20; // penalty for coastline
|
||||||
|
if (t === LANDLOCKED) return type === "Naval" || type === "Nomadic" ? 30 : 0; // low penalty for land level 2 for Navals and nomads
|
||||||
|
if (t !== WATER_COAST) return type === "Naval" || type === "Lake" ? 100 : 0; // penalty for mainland for navals
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const add = function (center: number) {
|
||||||
|
const defaultCultures = getDefault();
|
||||||
|
let culture, base, name;
|
||||||
|
|
||||||
|
if (pack.cultures.length < defaultCultures.length) {
|
||||||
|
// add one of the default cultures
|
||||||
|
culture = pack.cultures.length;
|
||||||
|
base = defaultCultures[culture].base;
|
||||||
|
name = defaultCultures[culture].name;
|
||||||
|
} else {
|
||||||
|
// add random culture besed on one of the current ones
|
||||||
|
culture = rand(pack.cultures.length - 1);
|
||||||
|
name = Names.getCulture(culture, 5, 8, "");
|
||||||
|
base = pack.cultures[culture].base;
|
||||||
|
}
|
||||||
|
const code = abbreviate(
|
||||||
|
name,
|
||||||
|
pack.cultures.map(c => c.code)
|
||||||
|
);
|
||||||
|
const i = pack.cultures.length;
|
||||||
|
const color = d3.color(d3.scaleSequential(d3.interpolateRainbow)(Math.random())).hex();
|
||||||
|
|
||||||
|
// define emblem shape
|
||||||
|
let shield = culture.shield;
|
||||||
|
const emblemShape = document.getElementById("emblemShape").value;
|
||||||
|
if (emblemShape === "random") shield = COA.getRandomShield();
|
||||||
|
|
||||||
|
pack.cultures.push({
|
||||||
|
name,
|
||||||
|
color,
|
||||||
|
base,
|
||||||
|
center,
|
||||||
|
i,
|
||||||
|
expansionism: 1,
|
||||||
|
type: "Generic",
|
||||||
|
cells: 0,
|
||||||
|
area: 0,
|
||||||
|
rural: 0,
|
||||||
|
urban: 0,
|
||||||
|
origins: [0],
|
||||||
|
code,
|
||||||
|
shield
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
@ -9,10 +9,11 @@ import {rankCells} from "scripts/generation/pack/rankCells";
|
||||||
import {createTypedArray} from "utils/arrayUtils";
|
import {createTypedArray} from "utils/arrayUtils";
|
||||||
import {pick} from "utils/functionUtils";
|
import {pick} from "utils/functionUtils";
|
||||||
import {rn} from "utils/numberUtils";
|
import {rn} from "utils/numberUtils";
|
||||||
|
import {generateCultures} from "./cultures";
|
||||||
import {generateRivers} from "./rivers";
|
import {generateRivers} from "./rivers";
|
||||||
|
|
||||||
const {LAND_COAST, WATER_COAST, DEEPER_WATER} = DISTANCE_FIELD;
|
const {LAND_COAST, WATER_COAST, DEEPER_WATER} = DISTANCE_FIELD;
|
||||||
const {Biomes, Cultures} = window;
|
const {Biomes} = window;
|
||||||
|
|
||||||
export function createPack(grid: IGrid): IPack {
|
export function createPack(grid: IGrid): IPack {
|
||||||
const {temp, prec} = grid.cells;
|
const {temp, prec} = grid.cells;
|
||||||
|
|
@ -51,7 +52,7 @@ export function createPack(grid: IGrid): IPack {
|
||||||
const {suitability, population} = rankCells(mergedFeatures, {
|
const {suitability, population} = rankCells(mergedFeatures, {
|
||||||
t: distanceField,
|
t: distanceField,
|
||||||
f: featureIds,
|
f: featureIds,
|
||||||
fl: riverIds,
|
fl: flux,
|
||||||
conf,
|
conf,
|
||||||
r: riverIds,
|
r: riverIds,
|
||||||
h: heights,
|
h: heights,
|
||||||
|
|
@ -61,10 +62,25 @@ export function createPack(grid: IGrid): IPack {
|
||||||
harbor
|
harbor
|
||||||
});
|
});
|
||||||
|
|
||||||
const {cultureIds, cultures}: {cultureIds: Uint16Array; cultures: ICulture[]} = Cultures.generate({
|
const {cultureIds, cultures} = generateCultures(
|
||||||
features: mergedFeatures,
|
mergedFeatures,
|
||||||
cells: {...cells, pop: population}
|
{
|
||||||
});
|
p: cells.p,
|
||||||
|
i: cells.i,
|
||||||
|
g: cells.g,
|
||||||
|
t: distanceField,
|
||||||
|
h: heights,
|
||||||
|
haven,
|
||||||
|
harbor,
|
||||||
|
f: featureIds,
|
||||||
|
r: riverIds,
|
||||||
|
fl: flux,
|
||||||
|
s: suitability,
|
||||||
|
pop: population,
|
||||||
|
biome
|
||||||
|
},
|
||||||
|
temp
|
||||||
|
);
|
||||||
|
|
||||||
// Cultures.expand();
|
// Cultures.expand();
|
||||||
// BurgsAndStates.generate();
|
// BurgsAndStates.generate();
|
||||||
|
|
@ -93,7 +109,7 @@ export function createPack(grid: IGrid): IPack {
|
||||||
vertices,
|
vertices,
|
||||||
cells: {
|
cells: {
|
||||||
...cells,
|
...cells,
|
||||||
h: new Uint8Array(heights),
|
h: heights,
|
||||||
f: featureIds,
|
f: featureIds,
|
||||||
t: distanceField,
|
t: distanceField,
|
||||||
haven,
|
haven,
|
||||||
|
|
|
||||||
32
src/types/pack/cultures.d.ts
vendored
Normal file
32
src/types/pack/cultures.d.ts
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
interface ICulture {
|
||||||
|
i: number;
|
||||||
|
type: TCultureType;
|
||||||
|
name: string;
|
||||||
|
base: number;
|
||||||
|
center: number;
|
||||||
|
code: string;
|
||||||
|
color: Hex | CssUrl;
|
||||||
|
expansionism: number;
|
||||||
|
origins: number[];
|
||||||
|
shield: string;
|
||||||
|
removed?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
type IWilderness = {
|
||||||
|
i: 0;
|
||||||
|
name: string;
|
||||||
|
base: number;
|
||||||
|
origins: [null];
|
||||||
|
shield: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type TCultures = [IWilderness, ...ICulture[]];
|
||||||
|
|
||||||
|
type TCultureType =
|
||||||
|
| "Generic" // no bonuses, standard penalties
|
||||||
|
| "Lake" // low water cross penalty and high for growth not along coastline
|
||||||
|
| "Naval" // low water cross penalty and high for non-along-coastline growth
|
||||||
|
| "River" // no River cross penalty, penalty for non-River growth
|
||||||
|
| "Nomadic" // high penalty in forest biomes and near coastline
|
||||||
|
| "Hunting" // high penalty in non-native biomes
|
||||||
|
| "Highland"; // no penalty for hills and moutains, high for other elevations
|
||||||
17
src/types/pack/pack.d.ts
vendored
17
src/types/pack/pack.d.ts
vendored
|
|
@ -2,7 +2,7 @@ interface IPack extends IGraph {
|
||||||
cells: IGraphCells & IPackCells;
|
cells: IGraphCells & IPackCells;
|
||||||
features: TPackFeatures;
|
features: TPackFeatures;
|
||||||
states: IState[];
|
states: IState[];
|
||||||
cultures: ICulture[];
|
cultures: TCultures;
|
||||||
provinces: IProvince[];
|
provinces: IProvince[];
|
||||||
burgs: IBurg[];
|
burgs: IBurg[];
|
||||||
rivers: IRiver[];
|
rivers: IRiver[];
|
||||||
|
|
@ -44,21 +44,6 @@ interface IState {
|
||||||
removed?: boolean;
|
removed?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ICulture {
|
|
||||||
i: number;
|
|
||||||
type: TCultureType;
|
|
||||||
name: string;
|
|
||||||
base: number;
|
|
||||||
code: string;
|
|
||||||
color: Hex | CssUrl;
|
|
||||||
expansionism: number;
|
|
||||||
origins: number[] | [null];
|
|
||||||
shield: string;
|
|
||||||
removed?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
type TCultureType = "Generic" | "Lake" | "Naval" | "River" | "Nomadic" | "Hunting" | "Highland";
|
|
||||||
|
|
||||||
interface IProvince {
|
interface IProvince {
|
||||||
i: number;
|
i: number;
|
||||||
name: string;
|
name: string;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import * as d3 from "d3";
|
import * as d3 from "d3";
|
||||||
|
|
||||||
const c12: Hex[] = [
|
const cardinal12: Hex[] = [
|
||||||
"#dababf",
|
"#dababf",
|
||||||
"#fb8072",
|
"#fb8072",
|
||||||
"#80b1d3",
|
"#80b1d3",
|
||||||
|
|
@ -26,9 +26,13 @@ const colorSchemeMap: Dict<ColorScheme> = {
|
||||||
|
|
||||||
export function getColors(number: number) {
|
export function getColors(number: number) {
|
||||||
const scheme = colorSchemeMap.bright;
|
const scheme = colorSchemeMap.bright;
|
||||||
const colors = d3
|
|
||||||
.range(number)
|
const colors = d3.range(number).map(index => {
|
||||||
.map(index => (index < 12 ? c12[index] : d3.color(scheme((index - 12) / (number - 12))!)!.formatHex()));
|
if (index < 12) return cardinal12[index];
|
||||||
|
|
||||||
|
const rgb = scheme((index - 12) / (number - 12))!;
|
||||||
|
return d3.color(rgb)!.formatHex() as Hex;
|
||||||
|
});
|
||||||
return d3.shuffle(colors);
|
return d3.shuffle(colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue