Line data Source code
1 : var g_BiomeID; 2 : 3 0 : var g_Terrains = {}; 4 0 : var g_Gaia = {}; 5 0 : var g_Decoratives = {}; 6 0 : var g_ResourceCounts = {}; 7 0 : var g_Heights = {}; 8 : 9 : function currentBiome() 10 : { 11 0 : return g_BiomeID; 12 : } 13 : 14 : function setSelectedBiome() 15 : { 16 : // TODO: Replace ugly default for atlas by a dropdown 17 0 : setBiome(g_MapSettings.Biome || "generic/alpine"); 18 : } 19 : 20 : function setBiome(biomeID) 21 : { 22 0 : RandomMapLogger.prototype.printDirectly("Setting biome " + biomeID + ".\n"); 23 : 24 0 : loadBiomeFile("defaultbiome"); 25 : 26 0 : setSkySet(pickRandom(["default", "cirrus", "cumulus", "sunny"])); 27 0 : setSunRotation(randomAngle()); 28 0 : setSunElevation(Math.PI * randFloat(1/6, 1/3)); 29 : 30 0 : g_BiomeID = biomeID; 31 : 32 0 : loadBiomeFile(biomeID); 33 : 34 0 : Engine.LoadLibrary("rmbiome/" + dirname(biomeID)); 35 0 : let setupBiomeFunc = global["setupBiome_" + basename(biomeID)]; 36 0 : if (setupBiomeFunc) 37 0 : setupBiomeFunc(); 38 : } 39 : 40 : /** 41 : * Copies JSON contents to defined global variables. 42 : */ 43 : function loadBiomeFile(file) 44 : { 45 0 : let path = "maps/random/rmbiome/" + file + ".json"; 46 : 47 0 : if (!Engine.FileExists(path)) 48 : { 49 0 : error("Could not load biome file '" + file + "'"); 50 0 : return; 51 : } 52 : 53 0 : let biome = Engine.ReadJSONFile(path); 54 : 55 0 : let copyProperties = (from, to) => { 56 0 : for (let prop in from) 57 : { 58 0 : if (from[prop] !== null && typeof from[prop] == "object" && !Array.isArray(from[prop])) 59 : { 60 0 : if (!to[prop]) 61 0 : to[prop] = {}; 62 : 63 0 : copyProperties(from[prop], to[prop]); 64 : } 65 : else 66 0 : to[prop] = from[prop]; 67 : } 68 : }; 69 : 70 0 : for (let rmsGlobal in biome) 71 : { 72 0 : if (rmsGlobal == "Description") 73 0 : continue; 74 : 75 0 : if (!global["g_" + rmsGlobal]) 76 0 : throw new Error(rmsGlobal + " not defined!"); 77 : 78 0 : copyProperties(biome[rmsGlobal], global["g_" + rmsGlobal]); 79 : } 80 : } 81 : 82 : function rBiomeTreeCount(multiplier = 1) 83 : { 84 0 : return [ 85 : g_ResourceCounts.trees.min * multiplier, 86 : g_ResourceCounts.trees.max * multiplier, 87 : g_ResourceCounts.trees.forestProbability 88 : ]; 89 : }