Move random biome system to a separate mapgen library.

Proposed library and directoryname agreed with FeXoR.
Make the rmgen/ biome agnostic by moving the biome constants in
createForests to the randombiome globals.
Don't pass a non-randombiome constant in gulf of bothnia to the
createForests function that expected a randombiome constant, refs
e17dd1ac12, accepted by Grugnas.
Remove unused trivial unrecommended randomizeBiome function,
make Biomes autocompletable in the gamesetup chat, refs D852.

This was SVN commit r20127.
This commit is contained in:
elexis 2017-09-07 15:34:15 +00:00
parent e95f4e9744
commit cc0d4f25da
41 changed files with 105 additions and 101 deletions

View File

@ -483,6 +483,7 @@ var g_Dropdowns = {
g_GameAttributes.settings.Biome = g_BiomeList && g_BiomeList.Id[idx];
},
"hidden": () => !g_BiomeList,
"autocomplete": 0,
"initOrder": 1000
},
"numPlayers": {

View File

@ -3,6 +3,7 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmgen2");
RMS.LoadLibrary("rmbiome");
InitMap();

View File

@ -1,5 +1,6 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmgen2");
RMS.LoadLibrary("rmbiome");
InitMap();

View File

@ -1,4 +1,5 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmbiome");
TILE_CENTERED_HEIGHT_MAP = true;
@ -223,9 +224,8 @@ createForests(
[tMainTerrain, tForestFloor1, tForestFloor2, pForest1, pForest2],
[avoidClasses(clPlayer, 20, clForest, 17, clHill, 0), stayClasses(clLand, 4)],
clForest,
1.0,
currentBiome()
);
1,
...rBiomeTreeCount(1));
RMS.SetProgress(50);
log("Creating dirt patches...");

View File

@ -179,14 +179,11 @@ createMountains(tCliff, avoidClasses(clPlayer, 20, clHill, 8), clHill, scaleByMa
RMS.SetProgress(25);
// create forests
createForests(
[tGrass, tForestFloor, tForestFloor, pForest1, pForest2],
avoidClasses(clPlayer, 20, clForest, 14, clHill, 1),
clForest,
0.6,
0
);
0.6);
RMS.SetProgress(40);

View File

@ -3,6 +3,7 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmgen2");
RMS.LoadLibrary("rmbiome");
InitMap();

View File

@ -1,4 +1,5 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmbiome");
RMS.LoadLibrary("heightmap");
InitMap();

View File

@ -1,4 +1,5 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmbiome");
setSelectedBiome();
@ -376,13 +377,12 @@ createHills([tCliff, tCliff, tHill], [avoidClasses(clPlayer, 2, clHill, 8, clHil
// create hills outside the canyon
createHills([tCliff, tCliff, tMainTerrain], avoidClasses(clLand, 1, clHill, 1), clHill, scaleByMapSize(20, 150), undefined, undefined, undefined, undefined, 40);
// create forests
createForests(
[tMainTerrain, tForestFloor1, tForestFloor2, pForest1, pForest2],
[avoidClasses(clPlayer, 1, clForest, 15, clHill, 1, clHill2, 0), stayClasses(clLand, 4)],
clForest,
1.0,
currentBiome()
1,
...rBiomeTreeCount(1)
);
RMS.SetProgress(50);

View File

@ -1,4 +1,5 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmbiome");
setSelectedBiome();
@ -230,14 +231,12 @@ if (randBool())
else
createMountains(tCliff, [avoidClasses(clPlayer, 20, clHill, 15, clBaseResource, 3), stayClasses(clLand, 5)], clHill, scaleByMapSize(1, 4) * numPlayers);
// create forests
createForests(
[tMainTerrain, tForestFloor1, tForestFloor2, pForest1, pForest2],
[avoidClasses(clPlayer, 20, clForest, 17, clHill, 0, clBaseResource,2), stayClasses(clLand, 4)],
clForest,
1.0,
currentBiome()
);
...rBiomeTreeCount(1));
RMS.SetProgress(50);

View File

@ -1,5 +1,6 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmgen2");
RMS.LoadLibrary("rmbiome");
InitMap();

View File

@ -277,7 +277,6 @@ createForests(
avoidClasses(clPlayer, 20, clForest, 17, clHill, 0, clWater, 6),
clForest,
1.0,
0
);
RMS.SetProgress(70);

View File

@ -1,4 +1,5 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmbiome");
setSelectedBiome();
@ -306,8 +307,7 @@ createForests(
[avoidClasses(clPlayer, 25, clForest, 10, clBaseResource, 3, clMetal, 6, clRock, 3, clMountain, 2), stayClasses(clHill, 6)],
clForest,
0.7,
currentBiome()
);
...rBiomeTreeCount(0.7));
log("Creating straggeler trees...");
let types = [oTree1, oTree2, oTree4, oTree3];
@ -404,8 +404,7 @@ createForests(
avoidClasses(clPlayer, 30, clHill, 10, clFood, 5),
clForest,
0.1,
currentBiome()
);
...rBiomeTreeCount(0.1));
log("Creating small grass tufts...");
group = new SimpleGroup(

View File

@ -1,5 +1,6 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmgen2");
RMS.LoadLibrary("rmbiome");
InitMap();

View File

@ -1,4 +1,5 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmbiome");
TILE_CENTERED_HEIGHT_MAP = true;
@ -362,9 +363,8 @@ createForests(
[tMainTerrain, tForestFloor1, tForestFloor2, pForest1, pForest2],
avoidClasses(clPlayer, 20, clForest, 17, clHill, 0, clWater, 2),
clForest,
1.0,
currentBiome()
);
1,
...rBiomeTreeCount(1));
RMS.SetProgress(50);

View File

@ -273,14 +273,11 @@ paintTerrainBasedOnHeight(-8, 1, 2, tWater);
// create bumps
createBumps([avoidClasses(clPlayer, 20, clRiver, 1), stayClasses(clLand, 3)]);
// create forests
createForests(
[tGrass, tForestFloorP, tForestFloorC, pForestC, pForestP],
[avoidClasses(clPlayer, 20, clForest, 17, clHill, 0, clRiver, 1), stayClasses(clLand, 7)],
clForest,
1.0,
0
);
1.0);
RMS.SetProgress(50);

View File

@ -355,14 +355,11 @@ if (randBool())
else
createMountains(tCliff, avoidClasses(clPlayer, 20, clHill, 15, clWater, 0), clHill, scaleByMapSize(1, 4) * numPlayers);
// create forests
createForests(
[tPrimary, tForestFloor, tForestFloor, pForest, pForest],
avoidClasses(clPlayer, 20, clForest, 16, clHill, 0, clWater, 2),
clForest,
1.0,
random_terrain
);
1.0);
RMS.SetProgress(60);

View File

@ -1,5 +1,6 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmgen2");
RMS.LoadLibrary("rmbiome");
InitMap();

View File

@ -1,5 +1,6 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmgen2");
RMS.LoadLibrary("rmbiome");
InitMap();

View File

@ -3,6 +3,7 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmgen2");
RMS.LoadLibrary("rmbiome");
InitMap();

View File

@ -12,6 +12,7 @@ function getPlayerTileCoordinates(playerIdx, teamIdx, fractionX, fractionZ)
}
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmbiome");
RMS.LoadLibrary("heightmap");
const g_InitialMines = 1;
@ -373,9 +374,8 @@ createForests(
[tMainTerrain, tForestFloor1, tForestFloor2, pForest1, pForest2],
[avoidClasses(clPlayer, 10, clForest, 20, clHill, 10, clBaseResource, 5, clRock, 6, clMetal, 6), stayClasses(clLand, 3)],
clForest,
1.0,
currentBiome()
);
1,
...rBiomeTreeCount(1));
log("Creating hills...");
let placer = new ChainPlacer(1, floor(scaleByMapSize(4, 6)), floor(scaleByMapSize(16, 40)), 0.5);

View File

@ -1,4 +1,5 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmbiome");
TILE_CENTERED_HEIGHT_MAP = true;

View File

@ -1,4 +1,5 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmbiome");
setSelectedBiome();
@ -243,14 +244,12 @@ if (randBool())
else
createMountains(tCliff, avoidClasses(clPlayer, 20, clHill, 15, clWater, 2), clHill, scaleByMapSize(1, 4) * numPlayers);
// create forests
createForests(
[tMainTerrain, tForestFloor1, tForestFloor2, pForest1, pForest2],
avoidClasses(clPlayer, 20, clForest, 17, clHill, 0, clWater, 2),
clForest,
1.0,
currentBiome()
);
1,
...rBiomeTreeCount(1));
RMS.SetProgress(50);

View File

@ -1,5 +1,6 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmgen2");
RMS.LoadLibrary("rmbiome");
InitMap();

View File

@ -1,6 +1,6 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmbiome");
//random terrain textures
setSelectedBiome();
const tMainTerrain = rBiomeT1();
@ -192,14 +192,12 @@ if (randBool())
else
createMountains(tCliff, avoidClasses(clPlayer, 20, clHill, 15), clHill, scaleByMapSize(3, 15));
// create forests
createForests(
[tMainTerrain, tForestFloor1, tForestFloor2, pForest1, pForest2],
avoidClasses(clPlayer, 20, clForest, 18, clHill, 0),
clForest,
1.0,
currentBiome()
);
1,
...rBiomeTreeCount(1));
RMS.SetProgress(50);

View File

@ -3,6 +3,7 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmgen2");
RMS.LoadLibrary("rmbiome");
InitMap();

View File

@ -3,6 +3,7 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmgen2");
RMS.LoadLibrary("rmbiome");
InitMap();

View File

@ -1,4 +1,5 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmbiome");
setSelectedBiome();

View File

@ -3,6 +3,7 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmgen2");
RMS.LoadLibrary("rmbiome");
InitMap();

View File

@ -3,6 +3,7 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmgen2");
RMS.LoadLibrary("rmbiome");
InitMap();

View File

@ -3,6 +3,7 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmgen2");
RMS.LoadLibrary("rmbiome");
InitMap();

View File

@ -3,6 +3,7 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmgen2");
RMS.LoadLibrary("rmbiome");
InitMap();

View File

@ -1,4 +1,5 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmbiome");
setSelectedBiome();
@ -373,14 +374,12 @@ if (randBool())
else
createMountains(tCliff, avoidClasses(clPlayer, 20, clHill, 15, clWater, 2), clHill, scaleByMapSize(3, 15));
// create forests
createForests(
[tMainTerrain, tForestFloor1, tForestFloor2, pForest1, pForest2],
avoidClasses(clPlayer, 20, clForest, 17, clHill, 0, clWater, 2),
clForest,
1.0,
currentBiome()
);
1,
...rBiomeTreeCount(1));
RMS.SetProgress(50);

View File

@ -69,6 +69,12 @@ var g_Decoratives = {
"tree": "actor|flora/trees/oak.xml"
};
var g_TreeCount = {
"minTrees": 500,
"maxTrees": 3000,
"forestProbability": 0.7
};
function currentBiome()
{
return g_BiomeID;
@ -85,12 +91,6 @@ function setSelectedBiome()
setBiome(g_MapSettings.Biome);
}
function randomizeBiome()
{
setBiome(pickRandom(g_Biomes));
return g_BiomeID;
}
function setBiome(biomeID)
{
if (g_Biomes.indexOf(biomeID) == -1)
@ -579,10 +579,15 @@ function setBiome(biomeID)
"bushSmall": "actor|props/flora/bush_dry_a.xml",
"tree": "actor|flora/trees/baobab.xml"
};
g_TreeCount = {
"minTrees": 200,
"maxTrees": 1250,
"forestProbability": 0
};
}
else if (g_BiomeID == g_BiomeTropic)
{
// Bora-Bora ish. Quite transparent, not wavy.
// Mostly for shallow maps. Maps where the water level goes deeper should use a much darker Water Color to simulate deep water holes.
setWaterColor(0.584,0.824,0.929);
@ -643,6 +648,12 @@ function setBiome(biomeID)
"bushSmall": "actor|props/flora/plant_tropic_large.xml",
"tree": "actor|flora/trees/tree_tropic.xml"
};
g_TreeCount = {
"minTrees": 1000,
"maxTrees": 6000,
"forestProbabilityp": 0.52
};
}
else if (g_BiomeID == g_BiomeAutumn)
{
@ -709,6 +720,15 @@ function setBiome(biomeID)
}
}
function rBiomeTreeCount(multiplier = 1)
{
return [
g_TreeCount.minTrees * multiplier,
g_TreeCount.maxTrees * multiplier,
g_TreeCount.forestProbability
];
}
function rBiomeT1()
{
return g_Terrains.mainTerrain;

View File

@ -77,64 +77,39 @@ function createMountains(terrain, constraint, tileclass, count, maxHeight, minRa
);
}
function createForests(terrainset, constraint, tileclass, numMultiplier, biomeID)
function createForests(terrainset, constraint, tileclass, numMultiplier = 1, minTrees = 500, maxTrees = 3000, forestProbability = 0.7)
{
log("Creating forests...");
tileclass = (tileclass !== undefined ? tileclass : clForest);
constraint = (constraint !== undefined ? constraint : avoidClasses(clPlayer, 20, clForest, 17, clHill, 0));
numMultiplier = (numMultiplier !== undefined ? numMultiplier : 1.0);
biomeID = (biomeID !== undefined ? biomeID : 0);
tileclass = tileclass || clForest;
constraint = constraint || avoidClasses(clPlayer, 20, clForest, 17, clHill, 0);
var [tM, tFF1, tFF2, tF1, tF2] = terrainset;
var totalTrees = scaleByMapSize(minTrees, maxTrees);
var numForest = totalTrees * forestProbability;
g_numStragglerTrees = totalTrees * (1.0 - forestProbability);
if (biomeID == g_BiomeSavanna)
{
var MIN_TREES = 200 * numMultiplier;
var MAX_TREES = 1250 * numMultiplier;
var P_FOREST = 0;
}
else if (biomeID == g_BiomeTropic)
{
var MIN_TREES = 1000 * numMultiplier;
var MAX_TREES = 6000 * numMultiplier;
var P_FOREST = 0.52;
}
else
{
var MIN_TREES = 500 * numMultiplier;
var MAX_TREES = 3000 * numMultiplier;
var P_FOREST = 0.7;
}
var totalTrees = scaleByMapSize(MIN_TREES, MAX_TREES);
var numForest = totalTrees * P_FOREST;
g_numStragglerTrees = totalTrees * (1.0 - P_FOREST);
if (!forestProbability)
return;
log("Creating forests...");
var types = [
let types = [
[[tFF2, tM, tF1], [tFF2, tF1]],
[[tFF1, tM, tF2], [tFF1, tF2]]
]; // some variation
];
if (biomeID != g_BiomeSavanna)
{
var size = numForest / (scaleByMapSize(3,6) * numPlayers);
var num = floor(size / types.length);
for (var i = 0; i < types.length; ++i)
{
var placer = new ChainPlacer(1, floor(scaleByMapSize(3, 5)), numForest / num, 0.5);
var painter = new LayeredPainter(
types[i], // terrains
[2] // widths
);
createAreas(
placer,
[painter, paintClass(tileclass)],
constraint,
num
);
}
}
let num = Math.floor(numForest / (scaleByMapSize(3,6) * numPlayers) / types.length);
for (let type of types)
createAreas(
new ChainPlacer(1, Math.floor(scaleByMapSize(3, 5)), numForest / num, 0.5),
[
new LayeredPainter(type, [2]),
paintClass(tileclass)
],
constraint,
num
);
}
function createLayeredPatches(sizes, terrainset, twidthset, constraint, count, tileclass, failfraction)

View File

@ -1,4 +1,5 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmbiome");
setSelectedBiome();

View File

@ -1,5 +1,6 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmgen2");
RMS.LoadLibrary("rmbiome");
InitMap();

View File

@ -1,4 +1,5 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmbiome");
setSelectedBiome();
@ -185,8 +186,7 @@ createForests(
[avoidClasses(clPlayer, 20, clForest, 5, clHill, 0, clBaseResource,2, clWomen, 5), stayClasses(clLand, 4)],
clForest,
1,
currentBiome()
);
...rBiomeTreeCount(1));
if (randBool())
createHills(

View File

@ -1,4 +1,5 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmbiome");
TILE_CENTERED_HEIGHT_MAP = true;

View File

@ -1,4 +1,5 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmbiome");
TILE_CENTERED_HEIGHT_MAP = true;

View File

@ -1,4 +1,5 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmbiome");
TILE_CENTERED_HEIGHT_MAP = true;

View File

@ -1,4 +1,5 @@
RMS.LoadLibrary("rmgen");
RMS.LoadLibrary("rmbiome");
RMS.LoadLibrary("heightmap");
InitMap();