Ajout des ressources
This commit is contained in:
@@ -1,51 +1,63 @@
|
|||||||
exports.planetType = {
|
exports.planetType = {
|
||||||
"Tempérée" : {
|
"Tempérée" : {
|
||||||
"population" : 100,
|
"population" : 100,
|
||||||
"elements" : ["Roches", "Eau", "Bois", "Poissons communs", "Plantes communes"]
|
"elements" : ["Roches", "Eau", "Bois"],
|
||||||
|
"resources" : ["Poissons communs", "Plantes communes", "Faune domestique", "Céréales"]
|
||||||
},
|
},
|
||||||
"Glacée" : {
|
"Glacée" : {
|
||||||
"population" : 1,
|
"population" : 1,
|
||||||
"elements" : ["Roches", "Glace", "Gaz"]
|
"elements" : ["Roches", "Glace", "Gaz"],
|
||||||
|
"resources" : ["Artefacts", "Epaves", "Minerais rares"]
|
||||||
},
|
},
|
||||||
"Volcanique" : {
|
"Volcanique" : {
|
||||||
"population" : 2,
|
"population" : 2,
|
||||||
"elements" : ["Gaz", "Roches", "Carbone"]
|
"elements" : ["Gaz", "Roches", "Carbone"],
|
||||||
|
"resources" : ["Minerais rares", "Gaz toxiques"]
|
||||||
},
|
},
|
||||||
"Marécageuse" : {
|
"Marécageuse" : {
|
||||||
"population" : 10,
|
"population" : 10,
|
||||||
"elements" : ["Eau", "Bois", "Terre", "Faune sauvage"]
|
"elements" : ["Eau", "Bois", "Terre"],
|
||||||
|
"resources" : ["Faune sauvage", "Bois renforcé", "Eau toxique"]
|
||||||
},
|
},
|
||||||
"Forestière" : {
|
"Forestière" : {
|
||||||
"population" : 20,
|
"population" : 20,
|
||||||
"elements" : ["Bois", "Bois ancien", "Plantes rares"]
|
"elements" : ["Bois"],
|
||||||
|
"resources" : ["Plantes rares", "Plantes communes", "Bois commun", "Bois renforcé"]
|
||||||
},
|
},
|
||||||
"Océanique" : {
|
"Océanique" : {
|
||||||
"population" : 25,
|
"population" : 25,
|
||||||
"elements" : ["Eau"]
|
"elements" : ["Eau"],
|
||||||
|
"resources" : ["Poissons communs", "Poissons rares", "Minérais communs"]
|
||||||
},
|
},
|
||||||
"Oecuménopole" : {
|
"Oecuménopole" : {
|
||||||
"population" : 2000,
|
"population" : 2000,
|
||||||
"elements" : ["Roches"]
|
"elements" : ["Roches"],
|
||||||
|
"resources" : ["Biens de consommation", "Biens de luxe"]
|
||||||
},
|
},
|
||||||
"Désert" : {
|
"Désert" : {
|
||||||
"population" : 50,
|
"population" : 50,
|
||||||
"elements" : ["Sable", "Roches"]
|
"elements" : ["Sable", "Roches"],
|
||||||
|
"resources" : ["Artefacts", "Epaves", "Minerais communs", "Gemmes"]
|
||||||
},
|
},
|
||||||
"Minéralogique" : {
|
"Minéralogique" : {
|
||||||
"population" : 3,
|
"population" : 3,
|
||||||
"elements" : ["Roches"]
|
"elements" : ["Roches"],
|
||||||
|
"resources" : ["Minerais communs", "Minerais rares", "Gemmes"]
|
||||||
},
|
},
|
||||||
"Gazeuse" : {
|
"Gazeuse" : {
|
||||||
"population" : 1,
|
"population" : 1,
|
||||||
"elements" : ["Gaz"]
|
"elements" : ["Gaz"],
|
||||||
|
"resources" : ["Gaz toxiques", "Gaz nobles"]
|
||||||
},
|
},
|
||||||
"Acide" : {
|
"Acide" : {
|
||||||
"population" : 1,
|
"population" : 1,
|
||||||
"elements" : ["Gaz", "Acide"]
|
"elements" : ["Gaz", "Acide"],
|
||||||
|
"resources" : ["Gaz toxique", "Minerais communs", "Eau toxique"]
|
||||||
},
|
},
|
||||||
"Monde usine" : {
|
"Monde usine" : {
|
||||||
"population" : 500,
|
"population" : 500,
|
||||||
"elements" : ["Acide", "Roche"]
|
"elements" : ["Acide", "Roche"],
|
||||||
|
"resources" : ["Epaves", "Minerais communs", "Biens de consommation", "Eau toxique"]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
// Imports
|
||||||
const stat = require("./plStat.js");
|
const stat = require("./plStat.js");
|
||||||
|
|
||||||
|
// Simple functions to get random values
|
||||||
const getRandomValue = (min, max) => {return Math.floor(Math.random() * (max - min + 1)) + min;}
|
const getRandomValue = (min, max) => {return Math.floor(Math.random() * (max - min + 1)) + min;}
|
||||||
const Random = (array) => {return array[Math.floor(Math.random() * array.length)];}
|
const Random = (array) => {return array[Math.floor(Math.random() * array.length)];}
|
||||||
const RandomPlanet = (planet) => {
|
const RandomPlanet = (planet) => {
|
||||||
@@ -7,19 +9,30 @@ const RandomPlanet = (planet) => {
|
|||||||
return keys[Math.floor(Math.random() * keys.length)];
|
return keys[Math.floor(Math.random() * keys.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Main function generating planets
|
||||||
const GeneratePlanet = () => {
|
const GeneratePlanet = () => {
|
||||||
const planetTypeGeneration = RandomPlanet(stat.planetType);
|
const planetTypeGeneration = RandomPlanet(stat.planetType);
|
||||||
const planetName = Random(stat.planetNamePrefix) + Random(stat.planetNameSuffix);
|
const planetName = Random(stat.planetNamePrefix) + Random(stat.planetNameSuffix);
|
||||||
const planetPopulationPeople = Random(stat.planetPopulationType);
|
const planetPopulationPeople = Random(stat.planetPopulationType);
|
||||||
const planetPopulationNumber = stat.planetType[planetTypeGeneration]["population"] * getRandomValue(5, 15) / 10;
|
const planetPopulationNumber = stat.planetType[planetTypeGeneration]["population"] * getRandomValue(5, 15) / 10;
|
||||||
|
|
||||||
|
// Elements and resources generation
|
||||||
|
// Elements
|
||||||
const planetElements = stat.planetType[planetTypeGeneration].distributedElements;
|
const planetElements = stat.planetType[planetTypeGeneration].distributedElements;
|
||||||
let elementsDescription = '';
|
let elementsDescription = '';
|
||||||
for (let element in planetElements) {
|
for (let element in planetElements) {
|
||||||
elementsDescription += `
|
elementsDescription += `
|
||||||
${element}: ${planetElements[element].toFixed(2)}%`;
|
${element}: ${planetElements[element].toFixed(2)}%`;
|
||||||
}
|
}
|
||||||
|
// Resources
|
||||||
|
const planetResources = stat.planetType[planetTypeGeneration].distributedResources;
|
||||||
|
let resourcesDescription = '';
|
||||||
|
for (let resource in planetResources) {
|
||||||
|
resourcesDescription += `
|
||||||
|
${resource}: ${planetResources[resource].toFixed(2)}%`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Description = planet formatting
|
||||||
const planetDescription =
|
const planetDescription =
|
||||||
// Keep this formatting, or else play with the console.log of func PlanetLoop
|
// Keep this formatting, or else play with the console.log of func PlanetLoop
|
||||||
(`
|
(`
|
||||||
@@ -30,6 +43,9 @@ Type : ${planetTypeGeneration}
|
|||||||
Eléments :
|
Eléments :
|
||||||
${elementsDescription}
|
${elementsDescription}
|
||||||
|
|
||||||
|
Ressources naturelles :
|
||||||
|
${resourcesDescription}
|
||||||
|
|
||||||
Population :
|
Population :
|
||||||
|
|
||||||
${planetPopulationNumber} milliards
|
${planetPopulationNumber} milliards
|
||||||
@@ -37,6 +53,7 @@ Population :
|
|||||||
return planetDescription;
|
return planetDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generating planets in loop
|
||||||
const PlanetLoop = (number) => {
|
const PlanetLoop = (number) => {
|
||||||
let count = 1;
|
let count = 1;
|
||||||
while (count <= number) {
|
while (count <= number) {
|
||||||
@@ -71,11 +88,17 @@ const distributeElementsRandomly = (elements) => {
|
|||||||
|
|
||||||
const distributePlanetTypesRandomly = (planetType) => {
|
const distributePlanetTypesRandomly = (planetType) => {
|
||||||
for (const key in planetType) {
|
for (const key in planetType) {
|
||||||
if (Array.isArray(planetType[key].elements)) {
|
if (Array.isArray(planetType[key]["elements"])) {
|
||||||
const elements = planetType[key].elements;
|
const elements = planetType[key]["elements"];
|
||||||
const distributedElements = distributeElementsRandomly(elements);
|
const distributedElements = distributeElementsRandomly(elements);
|
||||||
planetType[key].distributedElements = distributedElements;
|
planetType[key].distributedElements = distributedElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(planetType[key]["resources"])) {
|
||||||
|
const resources = planetType[key]["resources"];
|
||||||
|
const distributedResources = distributeElementsRandomly(resources);
|
||||||
|
planetType[key].distributedResources = distributedResources;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user