calculate consumption on category level

This commit is contained in:
Azgaar 2021-08-15 16:54:16 +03:00
parent 11991cc403
commit b5245e8da0
5 changed files with 600 additions and 590 deletions

View file

@ -1,554 +0,0 @@
'use strict';
window.FMG.data.resources = [
{
i: 1,
name: 'Wood',
category: 'Construction',
icon: 'resource-wood',
color: '#966F33',
value: 2,
chance: 4,
model: 'Any_forest',
unit: 'pile',
bonus: {fleet: 2, defence: 1},
culture: {Hunting: 2}
},
{
i: 2,
name: 'Stone',
category: 'Construction',
icon: 'resource-stone',
color: '#979EA2',
value: 2,
chance: 4,
model: 'Hills',
unit: 'pallet',
bonus: {prestige: 1, defence: 2},
culture: {Hunting: 0.6, Nomadic: 0.6}
},
{
i: 3,
name: 'Marble',
category: 'Construction',
icon: 'resource-marble',
color: '#d6d0bf',
value: 7,
chance: 1,
model: 'Mountains',
unit: 'pallet',
bonus: {prestige: 2},
culture: {Highland: 2}
},
{
i: 4,
name: 'Iron',
category: 'Ore',
icon: 'resource-iron',
color: '#5D686E',
value: 4,
chance: 4,
model: 'Mountains_and_wetlands',
unit: 'wagon',
bonus: {artillery: 1, infantry: 1, defence: 1},
culture: {Highland: 2}
},
{
i: 5,
name: 'Copper',
category: 'Ore',
icon: 'resource-copper',
color: '#b87333',
value: 5,
chance: 3,
model: 'Mountains',
unit: 'wagon',
bonus: {artillery: 2, defence: 1, prestige: 1},
culture: {Highland: 2}
},
{
i: 6,
name: 'Lead',
category: 'Ore',
icon: 'resource-lead',
color: '#454343',
value: 4,
chance: 3,
model: 'Mountains',
unit: 'wagon',
bonus: {artillery: 1, defence: 1},
culture: {Highland: 2}
},
{
i: 7,
name: 'Silver',
category: 'Ore',
icon: 'resource-silver',
color: '#C0C0C0',
value: 8,
chance: 3,
model: 'Mountains',
unit: 'bullion',
bonus: {prestige: 2},
culture: {Hunting: 0.5, Highland: 2, Nomadic: 0.5}
},
{
i: 8,
name: 'Gold',
category: 'Ore',
icon: 'resource-gold',
color: '#d4af37',
value: 15,
chance: 1,
model: 'Headwaters',
unit: 'bullion',
bonus: {prestige: 3},
culture: {Highland: 2, Nomadic: 0.5}
},
{
i: 9,
name: 'Grain',
category: 'Food',
icon: 'resource-grain',
color: '#F5DEB3',
value: 1,
chance: 4,
model: 'More_habitable',
unit: 'wain',
bonus: {population: 4},
culture: {River: 3, Lake: 2, Nomadic: 0.5}
},
{
i: 10,
name: 'Cattle',
category: 'Food',
icon: 'resource-cattle',
color: '#56b000',
value: 2,
chance: 4,
model: 'Pastures_and_temperate_forest',
unit: 'head',
bonus: {population: 2},
culture: {Nomadic: 3}
},
{
i: 11,
name: 'Fish',
category: 'Food',
icon: 'resource-fish',
color: '#7fcdff',
value: 1,
chance: 2,
model: 'Marine_and_rivers',
unit: 'wain',
bonus: {population: 2},
culture: {River: 2, Lake: 3, Naval: 3, Nomadic: 0.5}
},
{
i: 12,
name: 'Game',
category: 'Food',
icon: 'resource-game',
color: '#c38a8a',
value: 2,
chance: 3,
model: 'Any_forest',
unit: 'wain',
bonus: {archers: 2, population: 1},
culture: {Naval: 0.6, Nomadic: 2, Hunting: 3}
},
{
i: 13,
name: 'Wine',
category: 'Food',
icon: 'resource-wine',
color: '#963e48',
value: 2,
chance: 3,
model: 'Tropical_forests',
unit: 'barrel',
bonus: {population: 1, prestige: 1},
culture: {Highland: 1.2, Nomadic: 0.5}
},
{
i: 14,
name: 'Olives',
category: 'Food',
icon: 'resource-olives',
color: '#BDBD7D',
value: 2,
chance: 3,
model: 'Tropical_forests',
unit: 'barrel',
bonus: {population: 1},
culture: {Generic: 0.8, Nomadic: 0.5}
},
{
i: 15,
name: 'Honey',
category: 'Food',
icon: 'resource-honey',
color: '#DCBC66',
value: 2,
chance: 3,
model: 'Temperate_and_boreal_forests',
unit: 'barrel',
bonus: {population: 1},
culture: {Hunting: 2, Highland: 2}
},
{
i: 16,
name: 'Salt',
category: 'Food',
icon: 'resource-salt',
color: '#E5E4E5',
value: 3,
chance: 3,
model: 'Arid_land_and_salt_lakes',
unit: 'bag',
bonus: {population: 1, defence: 1},
culture: {Naval: 1.2, Nomadic: 1.4}
},
{
i: 17,
name: 'Dates',
category: 'Food',
icon: 'resource-dates',
color: '#dbb2a3',
value: 2,
chance: 2,
model: 'Hot_desert',
unit: 'wain',
bonus: {population: 1},
culture: {Hunting: 0.8, Highland: 0.8}
},
{
i: 18,
name: 'Horses',
category: 'Supply',
icon: 'resource-horses',
color: '#ba7447',
value: 5,
chance: 4,
model: 'Grassland_and_cold_desert',
unit: 'head',
bonus: {cavalry: 2},
culture: {Nomadic: 3}
},
{
i: 19,
name: 'Elephants',
category: 'Supply',
icon: 'resource-elephants',
color: '#C5CACD',
value: 7,
chance: 2,
model: 'Hot_biomes',
unit: 'head',
bonus: {cavalry: 1},
culture: {Nomadic: 1.2, Highland: 0.5}
},
{
i: 20,
name: 'Camels',
category: 'Supply',
icon: 'resource-camels',
color: '#C19A6B',
value: 7,
chance: 3,
model: 'Deserts',
unit: 'head',
bonus: {cavalry: 1},
culture: {Nomadic: 3}
},
{
i: 21,
name: 'Hemp',
category: 'Material',
icon: 'resource-hemp',
color: '#069a06',
value: 2,
chance: 3,
model: 'Deciduous_forests',
unit: 'wain',
bonus: {fleet: 2},
culture: {River: 2, Lake: 2, Naval: 2}
},
{
i: 22,
name: 'Pearls',
category: 'Luxury',
icon: 'resource-pearls',
color: '#EAE0C8',
value: 16,
chance: 2,
model: 'Tropical_waters',
unit: 'pearl',
bonus: {prestige: 1},
culture: {Naval: 3}
},
{
i: 23,
name: 'Gemstones',
category: 'Luxury',
icon: 'resource-gemstones',
color: '#e463e4',
value: 17,
chance: 2,
model: 'Mountains',
unit: 'stone',
bonus: {prestige: 1},
culture: {Naval: 2}
},
{
i: 24,
name: 'Dyes',
category: 'Luxury',
icon: 'resource-dyes',
color: '#fecdea',
value: 6,
chance: 0.5,
model: 'Habitable_biome_or_marine',
unit: 'bag',
bonus: {prestige: 1},
culture: {Generic: 2}
},
{
i: 25,
name: 'Incense',
category: 'Luxury',
icon: 'resource-incense',
color: '#ebe5a7',
value: 12,
chance: 2,
model: 'Hot_desert_and_tropical_forest',
unit: 'chest',
bonus: {prestige: 2},
culture: {Generic: 2}
},
{
i: 26,
name: 'Silk',
category: 'Luxury',
icon: 'resource-silk',
color: '#e0f0f8',
value: 15,
chance: 1,
model: 'Tropical_rainforest',
unit: 'bolt',
bonus: {prestige: 2},
culture: {River: 1.2, Lake: 1.2}
},
{
i: 27,
name: 'Spices',
category: 'Luxury',
icon: 'resource-spices',
color: '#e99c75',
value: 15,
chance: 2,
model: 'Tropical_rainforest',
unit: 'chest',
bonus: {prestige: 2},
culture: {Generic: 2}
},
{
i: 28,
name: 'Amber',
category: 'Luxury',
icon: 'resource-amber',
color: '#e68200',
value: 7,
chance: 2,
model: 'Foresty_seashore',
unit: 'stone',
bonus: {prestige: 1},
culture: {Generic: 2}
},
{
i: 29,
name: 'Furs',
category: 'Material',
icon: 'resource-furs',
color: '#8a5e51',
value: 6,
chance: 2,
model: 'Boreal_forests',
unit: 'pelt',
bonus: {prestige: 1},
culture: {Hunting: 3}
},
{
i: 30,
name: 'Sheep',
category: 'Material',
icon: 'resource-sheeps',
color: '#53b574',
value: 2,
chance: 3,
model: 'Pastures_and_temperate_forest',
unit: 'head',
bonus: {infantry: 1},
culture: {Naval: 2, Highland: 2}
},
{
i: 31,
name: 'Slaves',
category: 'Supply',
icon: 'resource-slaves',
color: '#757575',
value: 5,
chance: 2,
model: 'Less_habitable_seashore',
unit: 'slave',
bonus: {population: 2},
culture: {Naval: 2, Nomadic: 3, Hunting: 0.6, Highland: 0.4}
},
{
i: 32,
name: 'Tar',
category: 'Material',
icon: 'resource-tar',
color: '#727272',
value: 2,
chance: 3,
model: 'Any_forest',
unit: 'barrel',
bonus: {fleet: 1},
culture: {Hunting: 3}
},
{
i: 33,
name: 'Saltpeter',
category: 'Material',
icon: 'resource-saltpeter',
color: '#e6e3e3',
value: 3,
chance: 2,
model: 'Less_habitable_biomes',
unit: 'barrel',
bonus: {artillery: 3},
culture: {Generic: 2}
},
{
i: 34,
name: 'Coal',
category: 'Material',
icon: 'resource-coal',
color: '#36454f',
value: 2,
chance: 3,
model: 'Hills',
unit: 'wain',
bonus: {artillery: 2},
culture: {Generic: 2}
},
{
i: 35,
name: 'Oil',
category: 'Material',
icon: 'resource-oil',
color: '#565656',
value: 3,
chance: 2,
model: 'Less_habitable_biomes',
unit: 'barrel',
bonus: {artillery: 1},
culture: {Generic: 2, Nomadic: 2}
},
{
i: 36,
name: 'Tropical timber',
category: 'Luxury',
icon: 'resource-tropicalTimber',
color: '#a45a52',
value: 10,
chance: 2,
model: 'Tropical_rainforest',
unit: 'pile',
bonus: {prestige: 1},
culture: {Generic: 2}
},
{
i: 37,
name: 'Whales',
category: 'Food',
icon: 'resource-whales',
color: '#cccccc',
value: 2,
chance: 3,
model: 'Arctic_waters',
unit: 'barrel',
bonus: {population: 1},
culture: {Naval: 2}
},
{
i: 38,
name: 'Sugar',
category: 'Food',
icon: 'resource-sugar',
color: '#7abf87',
value: 3,
chance: 3,
model: 'Tropical_rainforest',
unit: 'bag',
bonus: {population: 1},
culture: {Lake: 2, River: 2}
},
{
i: 39,
name: 'Tea',
category: 'Luxury',
icon: 'resource-tea',
color: '#d0f0c0',
value: 5,
chance: 3,
model: 'Hilly_tropical_rainforest',
unit: 'bag',
bonus: {prestige: 1},
culture: {Lake: 2, River: 2, Highland: 2}
},
{
i: 40,
name: 'Tobacco',
category: 'Luxury',
icon: 'resource-tobacco',
color: '#6D5843',
value: 5,
chance: 2,
model: 'Tropical_rainforest',
unit: 'bag',
bonus: {prestige: 1},
culture: {Lake: 2, River: 2}
}
];
window.FMG.data.resourceModels = {
Deciduous_forests: 'biome(6, 7, 8)',
Any_forest: 'biome(5, 6, 7, 8, 9)',
Temperate_and_boreal_forests: 'biome(6, 8, 9)',
Hills: 'minHeight(40) || (minHeight(30) && nth(10))',
Mountains: 'minHeight(60) || (minHeight(20) && nth(10))',
Mountains_and_wetlands: 'minHeight(60) || (biome(12) && nth(7)) || (minHeight(20) && nth(10))',
Headwaters: 'river() && minHeight(40)',
More_habitable: 'minHabitability(20) && habitability()',
Marine_and_rivers: 'shore(-1) && (type("ocean", "freshwater", "salt") || (river() && shore(1, 2)))',
Pastures_and_temperate_forest: '(biome(3, 4) && !elevation()) || (biome(6) && random(70)) || (biome(5) && nth(5))',
Tropical_forests: 'biome(5, 7)',
Arid_land_and_salt_lakes: 'shore(1) && type("salt", "dry") || (biome(1, 2) && random(70)) || (biome(12) && nth(10))',
Hot_desert: 'biome(1)',
Deserts: 'biome(1, 2)',
Grassland_and_cold_desert: 'biome(3) || (biome(2) && nth(4))',
Hot_biomes: 'biome(1, 3, 5, 7)',
Hot_desert_and_tropical_forest: 'biome(1, 7)',
Tropical_rainforest: 'biome(7)',
Tropical_waters: 'shore(-1) && minTemp(18)',
Hilly_tropical_rainforest: 'minHeight(40) && biome(7)',
Subtropical_waters: 'shore(-1) && minTemp(14)',
Habitable_biome_or_marine: 'shore(-1) || minHabitability(1)',
Foresty_seashore: 'shore(1) && biome(6, 7, 8, 9)',
Boreal_forests: 'biome(9) || (biome(10) && nth(2)) || (biome(6, 8) && nth(5)) || (biome(12) && nth(10))',
Less_habitable_seashore: 'shore(1) && minHabitability(1) && !habitability()',
Less_habitable_biomes: 'minHabitability(1) && !habitability()',
Arctic_waters: 'shore(-1) && biome(0) && maxTemp(7)'
};

View file

@ -35,12 +35,6 @@
<link rel="stylesheet" href="index.css"> <link rel="stylesheet" href="index.css">
<link rel="stylesheet" href="icons.css"> <link rel="stylesheet" href="icons.css">
<link rel="stylesheet" href="libs/jquery-ui.css"> <link rel="stylesheet" href="libs/jquery-ui.css">
<script>
window.FMG = {
data: {}
};
</script>
</head> </head>
<body> <body>
<svg id="map" width="100%" height="100%" version="1.1" <svg id="map" width="100%" height="100%" version="1.1"
@ -4520,7 +4514,6 @@
<script src="modules/lakes.js"></script> <script src="modules/lakes.js"></script>
<script src="modules/names-generator.js"></script> <script src="modules/names-generator.js"></script>
<script src="modules/cultures-generator.js"></script> <script src="modules/cultures-generator.js"></script>
<script src="data/resources.js"></script>
<script src="modules/resources-generator.js"></script> <script src="modules/resources-generator.js"></script>
<script src="modules/burgs-and-states.js"></script> <script src="modules/burgs-and-states.js"></script>
<script src="modules/production-generator.js"></script> <script src="modules/production-generator.js"></script>

View file

@ -3,6 +3,561 @@
window.Resources = (function () { window.Resources = (function () {
let cells, cellId; let cells, cellId;
const defaultResources = [
{
i: 1,
name: 'Wood',
category: 'Construction',
icon: 'resource-wood',
color: '#966F33',
value: 2,
chance: 4,
model: 'Any_forest',
unit: 'pile',
bonus: {fleet: 2, defence: 1},
culture: {Hunting: 2}
},
{
i: 2,
name: 'Stone',
category: 'Construction',
icon: 'resource-stone',
color: '#979EA2',
value: 2,
chance: 4,
model: 'Hills',
unit: 'pallet',
bonus: {prestige: 1, defence: 2},
culture: {Hunting: 0.6, Nomadic: 0.6}
},
{
i: 3,
name: 'Marble',
category: 'Construction',
icon: 'resource-marble',
color: '#d6d0bf',
value: 7,
chance: 1,
model: 'Mountains',
unit: 'pallet',
bonus: {prestige: 2},
culture: {Highland: 2}
},
{
i: 4,
name: 'Iron',
category: 'Ore',
icon: 'resource-iron',
color: '#5D686E',
value: 4,
chance: 4,
model: 'Mountains_and_wetlands',
unit: 'wagon',
bonus: {artillery: 1, infantry: 1, defence: 1},
culture: {Highland: 2}
},
{
i: 5,
name: 'Copper',
category: 'Ore',
icon: 'resource-copper',
color: '#b87333',
value: 5,
chance: 3,
model: 'Mountains',
unit: 'wagon',
bonus: {artillery: 2, defence: 1, prestige: 1},
culture: {Highland: 2}
},
{
i: 6,
name: 'Lead',
category: 'Ore',
icon: 'resource-lead',
color: '#454343',
value: 4,
chance: 3,
model: 'Mountains',
unit: 'wagon',
bonus: {artillery: 1, defence: 1},
culture: {Highland: 2}
},
{
i: 7,
name: 'Silver',
category: 'Ore',
icon: 'resource-silver',
color: '#C0C0C0',
value: 8,
chance: 3,
model: 'Mountains',
unit: 'bullion',
bonus: {prestige: 2},
culture: {Hunting: 0.5, Highland: 2, Nomadic: 0.5}
},
{
i: 8,
name: 'Gold',
category: 'Ore',
icon: 'resource-gold',
color: '#d4af37',
value: 15,
chance: 1,
model: 'Headwaters',
unit: 'bullion',
bonus: {prestige: 3},
culture: {Highland: 2, Nomadic: 0.5}
},
{
i: 9,
name: 'Grain',
category: 'Food',
icon: 'resource-grain',
color: '#F5DEB3',
value: 1,
chance: 4,
model: 'More_habitable',
unit: 'wain',
bonus: {population: 4},
culture: {River: 3, Lake: 2, Nomadic: 0.5}
},
{
i: 10,
name: 'Cattle',
category: 'Food',
icon: 'resource-cattle',
color: '#56b000',
value: 2,
chance: 4,
model: 'Pastures_and_temperate_forest',
unit: 'head',
bonus: {population: 2},
culture: {Nomadic: 3}
},
{
i: 11,
name: 'Fish',
category: 'Food',
icon: 'resource-fish',
color: '#7fcdff',
value: 1,
chance: 2,
model: 'Marine_and_rivers',
unit: 'wain',
bonus: {population: 2},
culture: {River: 2, Lake: 3, Naval: 3, Nomadic: 0.5}
},
{
i: 12,
name: 'Game',
category: 'Food',
icon: 'resource-game',
color: '#c38a8a',
value: 2,
chance: 3,
model: 'Any_forest',
unit: 'wain',
bonus: {archers: 2, population: 1},
culture: {Naval: 0.6, Nomadic: 2, Hunting: 3}
},
{
i: 13,
name: 'Wine',
category: 'Food',
icon: 'resource-wine',
color: '#963e48',
value: 2,
chance: 3,
model: 'Tropical_forests',
unit: 'barrel',
bonus: {population: 1, prestige: 1},
culture: {Highland: 1.2, Nomadic: 0.5}
},
{
i: 14,
name: 'Olives',
category: 'Food',
icon: 'resource-olives',
color: '#BDBD7D',
value: 2,
chance: 3,
model: 'Tropical_forests',
unit: 'barrel',
bonus: {population: 1},
culture: {Generic: 0.8, Nomadic: 0.5}
},
{
i: 15,
name: 'Honey',
category: 'Preservative',
icon: 'resource-honey',
color: '#DCBC66',
value: 2,
chance: 3,
model: 'Temperate_and_boreal_forests',
unit: 'barrel',
bonus: {population: 1},
culture: {Hunting: 2, Highland: 2}
},
{
i: 16,
name: 'Salt',
category: 'Preservative',
icon: 'resource-salt',
color: '#E5E4E5',
value: 3,
chance: 3,
model: 'Arid_land_and_salt_lakes',
unit: 'bag',
bonus: {population: 1, defence: 1},
culture: {Naval: 1.2, Nomadic: 1.4}
},
{
i: 17,
name: 'Dates',
category: 'Food',
icon: 'resource-dates',
color: '#dbb2a3',
value: 2,
chance: 2,
model: 'Hot_desert',
unit: 'wain',
bonus: {population: 1},
culture: {Hunting: 0.8, Highland: 0.8}
},
{
i: 18,
name: 'Horses',
category: 'Supply',
icon: 'resource-horses',
color: '#ba7447',
value: 5,
chance: 4,
model: 'Grassland_and_cold_desert',
unit: 'head',
bonus: {cavalry: 2},
culture: {Nomadic: 3}
},
{
i: 19,
name: 'Elephants',
category: 'Supply',
icon: 'resource-elephants',
color: '#C5CACD',
value: 7,
chance: 2,
model: 'Hot_biomes',
unit: 'head',
bonus: {cavalry: 1},
culture: {Nomadic: 1.2, Highland: 0.5}
},
{
i: 20,
name: 'Camels',
category: 'Supply',
icon: 'resource-camels',
color: '#C19A6B',
value: 7,
chance: 3,
model: 'Deserts',
unit: 'head',
bonus: {cavalry: 1},
culture: {Nomadic: 3}
},
{
i: 21,
name: 'Hemp',
category: 'Material',
icon: 'resource-hemp',
color: '#069a06',
value: 2,
chance: 3,
model: 'Deciduous_forests',
unit: 'wain',
bonus: {fleet: 2},
culture: {River: 2, Lake: 2, Naval: 2}
},
{
i: 22,
name: 'Pearls',
category: 'Luxury',
icon: 'resource-pearls',
color: '#EAE0C8',
value: 16,
chance: 2,
model: 'Tropical_waters',
unit: 'pearl',
bonus: {prestige: 1},
culture: {Naval: 3}
},
{
i: 23,
name: 'Gemstones',
category: 'Luxury',
icon: 'resource-gemstones',
color: '#e463e4',
value: 17,
chance: 2,
model: 'Mountains',
unit: 'stone',
bonus: {prestige: 1},
culture: {Naval: 2}
},
{
i: 24,
name: 'Dyes',
category: 'Luxury',
icon: 'resource-dyes',
color: '#fecdea',
value: 6,
chance: 0.5,
model: 'Habitable_biome_or_marine',
unit: 'bag',
bonus: {prestige: 1},
culture: {Generic: 2}
},
{
i: 25,
name: 'Incense',
category: 'Luxury',
icon: 'resource-incense',
color: '#ebe5a7',
value: 12,
chance: 2,
model: 'Hot_desert_and_tropical_forest',
unit: 'chest',
bonus: {prestige: 2},
culture: {Generic: 2}
},
{
i: 26,
name: 'Silk',
category: 'Luxury',
icon: 'resource-silk',
color: '#e0f0f8',
value: 15,
chance: 1,
model: 'Tropical_rainforest',
unit: 'bolt',
bonus: {prestige: 2},
culture: {River: 1.2, Lake: 1.2}
},
{
i: 27,
name: 'Spices',
category: 'Luxury',
icon: 'resource-spices',
color: '#e99c75',
value: 15,
chance: 2,
model: 'Tropical_rainforest',
unit: 'chest',
bonus: {prestige: 2},
culture: {Generic: 2}
},
{
i: 28,
name: 'Amber',
category: 'Luxury',
icon: 'resource-amber',
color: '#e68200',
value: 7,
chance: 2,
model: 'Foresty_seashore',
unit: 'stone',
bonus: {prestige: 1},
culture: {Generic: 2}
},
{
i: 29,
name: 'Furs',
category: 'Material',
icon: 'resource-furs',
color: '#8a5e51',
value: 6,
chance: 2,
model: 'Boreal_forests',
unit: 'pelt',
bonus: {prestige: 1},
culture: {Hunting: 3}
},
{
i: 30,
name: 'Sheep',
category: 'Material',
icon: 'resource-sheeps',
color: '#53b574',
value: 2,
chance: 3,
model: 'Pastures_and_temperate_forest',
unit: 'head',
bonus: {infantry: 1},
culture: {Naval: 2, Highland: 2}
},
{
i: 31,
name: 'Slaves',
category: 'Supply',
icon: 'resource-slaves',
color: '#757575',
value: 5,
chance: 2,
model: 'Less_habitable_seashore',
unit: 'slave',
bonus: {population: 2},
culture: {Naval: 2, Nomadic: 3, Hunting: 0.6, Highland: 0.4}
},
{
i: 32,
name: 'Tar',
category: 'Material',
icon: 'resource-tar',
color: '#727272',
value: 2,
chance: 3,
model: 'Any_forest',
unit: 'barrel',
bonus: {fleet: 1},
culture: {Hunting: 3}
},
{
i: 33,
name: 'Saltpeter',
category: 'Material',
icon: 'resource-saltpeter',
color: '#e6e3e3',
value: 3,
chance: 2,
model: 'Less_habitable_biomes',
unit: 'barrel',
bonus: {artillery: 3},
culture: {Generic: 2}
},
{
i: 34,
name: 'Coal',
category: 'Material',
icon: 'resource-coal',
color: '#36454f',
value: 2,
chance: 3,
model: 'Hills',
unit: 'wain',
bonus: {artillery: 2},
culture: {Generic: 2}
},
{
i: 35,
name: 'Oil',
category: 'Material',
icon: 'resource-oil',
color: '#565656',
value: 3,
chance: 2,
model: 'Less_habitable_biomes',
unit: 'barrel',
bonus: {artillery: 1},
culture: {Generic: 2, Nomadic: 2}
},
{
i: 36,
name: 'Tropical timber',
category: 'Luxury',
icon: 'resource-tropicalTimber',
color: '#a45a52',
value: 10,
chance: 2,
model: 'Tropical_rainforest',
unit: 'pile',
bonus: {prestige: 1},
culture: {Generic: 2}
},
{
i: 37,
name: 'Whales',
category: 'Food',
icon: 'resource-whales',
color: '#cccccc',
value: 2,
chance: 3,
model: 'Arctic_waters',
unit: 'barrel',
bonus: {population: 1},
culture: {Naval: 2}
},
{
i: 38,
name: 'Sugar',
category: 'Preservative',
icon: 'resource-sugar',
color: '#7abf87',
value: 3,
chance: 3,
model: 'Tropical_rainforest',
unit: 'bag',
bonus: {population: 1},
culture: {Lake: 2, River: 2}
},
{
i: 39,
name: 'Tea',
category: 'Luxury',
icon: 'resource-tea',
color: '#d0f0c0',
value: 5,
chance: 3,
model: 'Hilly_tropical_rainforest',
unit: 'bag',
bonus: {prestige: 1},
culture: {Lake: 2, River: 2, Highland: 2}
},
{
i: 40,
name: 'Tobacco',
category: 'Luxury',
icon: 'resource-tobacco',
color: '#6D5843',
value: 5,
chance: 2,
model: 'Tropical_rainforest',
unit: 'bag',
bonus: {prestige: 1},
culture: {Lake: 2, River: 2}
}
];
// const categoryPriority = ['Food', 'Preservative', 'Construction', 'Ore', 'Material', 'Supply', 'Luxury'];
const models = {
Deciduous_forests: 'biome(6, 7, 8)',
Any_forest: 'biome(5, 6, 7, 8, 9)',
Temperate_and_boreal_forests: 'biome(6, 8, 9)',
Hills: 'minHeight(40) || (minHeight(30) && nth(10))',
Mountains: 'minHeight(60) || (minHeight(20) && nth(10))',
Mountains_and_wetlands: 'minHeight(60) || (biome(12) && nth(7)) || (minHeight(20) && nth(10))',
Headwaters: 'river() && minHeight(40)',
More_habitable: 'minHabitability(20) && habitability()',
Marine_and_rivers: 'shore(-1) && (type("ocean", "freshwater", "salt") || (river() && shore(1, 2)))',
Pastures_and_temperate_forest: '(biome(3, 4) && !elevation()) || (biome(6) && random(70)) || (biome(5) && nth(5))',
Tropical_forests: 'biome(5, 7)',
Arid_land_and_salt_lakes: 'shore(1) && type("salt", "dry") || (biome(1, 2) && random(70)) || (biome(12) && nth(10))',
Hot_desert: 'biome(1)',
Deserts: 'biome(1, 2)',
Grassland_and_cold_desert: 'biome(3) || (biome(2) && nth(4))',
Hot_biomes: 'biome(1, 3, 5, 7)',
Hot_desert_and_tropical_forest: 'biome(1, 7)',
Tropical_rainforest: 'biome(7)',
Tropical_waters: 'shore(-1) && minTemp(18)',
Hilly_tropical_rainforest: 'minHeight(40) && biome(7)',
Subtropical_waters: 'shore(-1) && minTemp(14)',
Habitable_biome_or_marine: 'shore(-1) || minHabitability(1)',
Foresty_seashore: 'shore(1) && biome(6, 7, 8, 9)',
Boreal_forests: 'biome(9) || (biome(10) && nth(2)) || (biome(6, 8) && nth(5)) || (biome(12) && nth(10))',
Less_habitable_seashore: 'shore(1) && minHabitability(1) && !habitability()',
Less_habitable_biomes: 'minHabitability(1) && !habitability()',
Arctic_waters: 'shore(-1) && biome(0) && maxTemp(7)'
};
const methods = { const methods = {
random: (number) => number >= 100 || (number > 0 && number / 100 > Math.random()), random: (number) => number >= 100 || (number > 0 && number / 100 > Math.random()),
nth: (number) => !(cellId % number), nth: (number) => !(cellId % number),
@ -25,10 +580,10 @@ window.Resources = (function () {
cells = pack.cells; cells = pack.cells;
cells.resource = new Uint8Array(cells.i.length); // resources array [0, 255] cells.resource = new Uint8Array(cells.i.length); // resources array [0, 255]
const resourceMaxCells = Math.ceil((200 * cells.i.length) / 5000); const resourceMaxCells = Math.ceil((200 * cells.i.length) / 5000);
if (!pack.resources) pack.resources = FMG.data.resources; if (!pack.resources) pack.resources = defaultResources;
pack.resources.forEach((r) => { pack.resources.forEach((r) => {
r.cells = 0; r.cells = 0;
const model = r.custom || FMG.data.resourceModels[r.model]; const model = r.custom || models[r.model];
r.fn = new Function(allMethods, 'return ' + model); r.fn = new Function(allMethods, 'return ' + model);
}); });
@ -59,5 +614,5 @@ window.Resources = (function () {
const getStroke = (color) => d3.color(color).darker(2).hex(); const getStroke = (color) => d3.color(color).darker(2).hex();
const get = (i) => pack.resources.find((resource) => resource.i === i); const get = (i) => pack.resources.find((resource) => resource.i === i);
return {generate, methods, getStroke, get}; return {generate, methods, models, getStroke, get};
})(); })();

View file

@ -56,21 +56,34 @@ window.Trade = (function () {
for (const tradeCenter of trade.centers) { for (const tradeCenter of trade.centers) {
const {i: centerId, burg: centerBurg, x: x0, y: y0} = tradeCenter; const {i: centerId, burg: centerBurg, x: x0, y: y0} = tradeCenter;
const goods = {}; const tradeCenterGoods = {};
for (const burg of burgs) { for (const burg of burgs) {
const {i, removed, tradeCenter, produced, population, state, x, y} = burg; const {i, removed, tradeCenter, produced, population, food, state, x, y} = burg;
if (!i || removed || tradeCenter !== centerBurg) continue; if (!i || removed || tradeCenter !== centerBurg) continue;
const consumption = Math.ceil(population); const consumption = Math.ceil(population);
const distance = Math.hypot(x - x0, y - y0); const distance = Math.hypot(x - x0, y - y0);
const transportFee = (distance / DEFAULT_TRANSPORT_DIST) ** 0.8 || 0.02; const transportFee = (distance / DEFAULT_TRANSPORT_DIST) ** 0.8 || 0.02;
const salesTax = states[state].salesTax || 0; const salesTax = states[state].salesTax || 0;
let income = 0;
const categorized = {};
for (const resourceId in produced) { for (const resourceId in produced) {
const production = produced[resourceId]; const {category} = Resources.get(+resourceId);
const quantity = production - consumption; if (!categorized[category]) categorized[category] = {};
if (quantity < 1) continue; categorized[category][resourceId] = produced[resourceId];
}
for (const category in categorized) {
const categoryProduction = d3.sum(Object.values(categorized[category]));
const exportQuantity = categoryProduction - consumption;
if (exportQuantity <= 0) continue;
for (const resourceId in categorized[category]) {
const production = categorized[category][resourceId];
const quantity = Math.round((production / categoryProduction) * exportQuantity);
if (quantity <= 0) continue;
const {value, name} = Resources.get(+resourceId); const {value, name} = Resources.get(+resourceId);
@ -84,13 +97,17 @@ window.Trade = (function () {
if (burgIncome < 1 || burgIncome < basePrice / 4) continue; if (burgIncome < 1 || burgIncome < basePrice / 4) continue;
trade.deals.push({resourceId: +resourceId, name, quantity, exporter: i, tradeCenter: centerId, basePrice, transportCost, stateIncome, burgIncome}); trade.deals.push({resourceId: +resourceId, name, quantity, exporter: i, tradeCenter: centerId, basePrice, transportCost, stateIncome, burgIncome});
income += burgIncome;
if (!goods[resourceId]) goods[resourceId] = quantity; if (!tradeCenterGoods[resourceId]) tradeCenterGoods[resourceId] = quantity;
else goods[resourceId] += quantity; else tradeCenterGoods[resourceId] += quantity;
} }
} }
tradeCenter.goods = goods; burg.income = income;
}
tradeCenter.goods = tradeCenterGoods;
} }
}; };

View file

@ -155,14 +155,13 @@ function editResources() {
} }
function changeModel(resource, line, el) { function changeModel(resource, line, el) {
const defaultModels = FMG.data.resourceModels;
const model = line.dataset.model; const model = line.dataset.model;
const modelOptions = Object.keys(defaultModels) const modelOptions = Object.keys(models)
.sort() .sort()
.map((m) => `<option ${m === model ? 'selected' : ''} value="${m}">${m.replaceAll('_', ' ')}</option>`) .map((m) => `<option ${m === model ? 'selected' : ''} value="${m}">${m.replaceAll('_', ' ')}</option>`)
.join(''); .join('');
const wikiURL = 'https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Resources:-spread-functions'; const wikiURL = 'https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Resources:-spread-functions';
const onSelect = "resouceModelFunction.innerHTML = FMG.data.resourceModels[this.value] || ' '; resouceModelCustomName.value = ''; resouceModelCustomFunction.value = ''"; const onSelect = "resouceModelFunction.innerHTML = Resources.models[this.value] || ' '; resouceModelCustomName.value = ''; resouceModelCustomFunction.value = ''";
alertMessage.innerHTML = ` alertMessage.innerHTML = `
<fieldset data-tip="Select one of the predefined spread models from the list" style="border: 1px solid #999; margin-bottom: 1em"> <fieldset data-tip="Select one of the predefined spread models from the list" style="border: 1px solid #999; margin-bottom: 1em">
@ -178,7 +177,7 @@ function editResources() {
<div style="margin-bottom:.2em"> <div style="margin-bottom:.2em">
<div style="display: inline-block; width: 6em">Function:</div> <div style="display: inline-block; width: 6em">Function:</div>
<div id="resouceModelFunction" style="display: inline-block; width: 18em; font-family: monospace; border: 1px solid #ccc; padding: 3px; font-size: .95em;vertical-align: middle"> <div id="resouceModelFunction" style="display: inline-block; width: 18em; font-family: monospace; border: 1px solid #ccc; padding: 3px; font-size: .95em;vertical-align: middle">
${defaultModels[model] || ' '} ${models[model] || ' '}
</div> </div>
</div> </div>
</fieldset> </fieldset>