From 203e46b59e1948f7ce980fd76e95b88bfd49c4c6 Mon Sep 17 00:00:00 2001 From: elexis Date: Tue, 17 Oct 2017 10:23:54 +0000 Subject: [PATCH] Unify beyond ridiculous Snowflake Searocks duplication gore, refs rP11137. The island generation code was copied once for * the small mapsize and 2 players * the small mapsize and 3 players * the small mapsize and 4 players * the small mapsize and more than 4 players * the medium mapsize and up to 4 players * the medium mapsize and more than 4 players * the normal mapsize and up to 5 players * the normal mapsize and up to 7 players * the normal mapsize and 8 players * the large mapsize and up to 5 players * the large mapsize and more than 5 players Within each of these copies there were three copies of the island createArea+placer+painters call and about 10 unreadable island connection setter copies. Support mapgenerations with only one player. Cleanup createAreas calls as in rP20301 and broken indentation. Fix missing forests due to a missing parentheses in the forest count of that commit. git-svn-id: https://svn.wildfiregames.com/public/ps/trunk@20308 3db68df2-c116-0410-a063-a993310a9797 --- .../mods/public/maps/random/snowflake_searocks.js | 2305 +++++--------------- 1 file changed, 530 insertions(+), 1775 deletions(-) rewrite binaries/data/mods/public/maps/random/snowflake_searocks.js (81%) diff --git a/binaries/data/mods/public/maps/random/snowflake_searocks.js b/binaries/data/mods/public/maps/random/snowflake_searocks.js dissimilarity index 81% index 8f31e636c3..bdf18bd437 100644 --- a/binaries/data/mods/public/maps/random/snowflake_searocks.js +++ b/binaries/data/mods/public/maps/random/snowflake_searocks.js @@ -1,1775 +1,530 @@ -RMS.LoadLibrary("rmgen"); -RMS.LoadLibrary("rmbiome"); - -setSelectedBiome(); - -const tMainTerrain = g_Terrains.mainTerrain; -const tForestFloor1 = g_Terrains.forestFloor1; -const tForestFloor2 = g_Terrains.forestFloor2; -const tCliff = g_Terrains.cliff; -const tTier1Terrain = g_Terrains.tier1Terrain; -const tTier2Terrain = g_Terrains.tier2Terrain; -const tTier3Terrain = g_Terrains.tier3Terrain; -const tHill = g_Terrains.mainTerrain; -const tRoad = g_Terrains.road; -const tRoadWild = g_Terrains.roadWild; -const tTier4Terrain = g_Terrains.tier4Terrain; -const tWater = g_Terrains.water; - -const oTree1 = g_Gaia.tree1; -const oTree2 = g_Gaia.tree2; -const oTree3 = g_Gaia.tree3; -const oTree4 = g_Gaia.tree4; -const oTree5 = g_Gaia.tree5; -const oFruitBush = g_Gaia.fruitBush; -const oMainHuntableAnimal = g_Gaia.mainHuntableAnimal; -const oSecondaryHuntableAnimal = g_Gaia.secondaryHuntableAnimal; -const oStoneLarge = g_Gaia.stoneLarge; -const oStoneSmall = g_Gaia.stoneSmall; -const oMetalLarge = g_Gaia.metalLarge; - -const aGrass = g_Decoratives.grass; -const aGrassShort = g_Decoratives.grassShort; -const aRockLarge = g_Decoratives.rockLarge; -const aRockMedium = g_Decoratives.rockMedium; -const aBushMedium = g_Decoratives.bushMedium; -const aBushSmall = g_Decoratives.bushSmall; - -const pForest1 = [tForestFloor2 + TERRAIN_SEPARATOR + oTree1, tForestFloor2 + TERRAIN_SEPARATOR + oTree2, tForestFloor2]; -const pForest2 = [tForestFloor1 + TERRAIN_SEPARATOR + oTree4, tForestFloor1 + TERRAIN_SEPARATOR + oTree5, tForestFloor1]; - -InitMap(); - -const numPlayers = getNumPlayers(); -const mapSize = getMapSize(); -const mapArea = mapSize*mapSize; - -log(mapSize); - -var clPlayer = createTileClass(); -var clHill = createTileClass(); -var clForest = createTileClass(); -var clDirt = createTileClass(); -var clRock = createTileClass(); -var clMetal = createTileClass(); -var clFood = createTileClass(); -var clBaseResource = createTileClass(); -var clSettlement = createTileClass(); -var clLand = createTileClass(); - -initTerrain(tWater); - -const radius = scaleByMapSize(15,30); -const cliffRadius = 2; -const elevation = 20; - -var [playerIDs, playerX, playerZ, playerAngle, startAngle] = radialPlayerPlacement(); - -// Creating other islands -var numIslands = 0; -//**************************** -//---------------------------- -//Tiny and Small Size -//---------------------------- -//**************************** -if ((mapSize == 128)||(mapSize == 192)){ - //2 PLAYERS - //----------------- - //----------------- - if (numPlayers == 2){ - numIslands = 4*numPlayers+1; - var IslandX = new Array(numIslands); - var IslandZ = new Array(numIslands); - var isConnected = new Array(numIslands); - for (var q=0; q 4){ - numIslands = numPlayers + 1; - var IslandX = new Array(numIslands); - var IslandZ = new Array(numIslands); - var isConnected = new Array(numIslands); - for (var q=0; q 4){ - numIslands = 2*numPlayers; - var IslandX = new Array(numIslands); - var IslandZ = new Array(numIslands); - var isConnected = new Array(numIslands); - for (var q=0; q 383){ - //2,3,4,5 PLAYERS - //----------------- - //----------------- - if ((numPlayers == 2)||(numPlayers == 3)||(numPlayers == 4)||(numPlayers == 5)){ - numIslands = 4*numPlayers+1; - var IslandX = new Array(numIslands); - var IslandZ = new Array(numIslands); - var isConnected = new Array(numIslands); - for (var q=0; q = Math.min(IslandZ[m],IslandZ[n]))) - { - if (dis < 3) - { - var h = 20; - if (dis < 2) - var t = tHill; - else - var t = tCliff; - addToClass(ix, iz, clLand); - } - else - { - var h = 50 - 10 * dis; - var t = tCliff; - addToClass(ix, iz, clLand); - } - - if (getHeight(ix, iz)= 5 || z < Math.min(islandZ[m], islandZ[n]) || z > Math.max(islandZ[m], islandZ[n])) + continue; + + addToClass(ix, iz, clLand); + + let height; + let tileClass; + + let f = 3 - dis; + if (f > 0) + { + height = islandHeight; + tileClass = dis < 2 ? tHill : tCliff; + } + else + { + height = islandHeight + 10 * f; + tileClass = tCliff; + } + + if (getHeight(ix, iz) < height) + { + placeTerrain(ix, iz, tileClass); + setHeight(ix, iz, height); + } + } + +if (currentBiome() == "savanna") +{ + var MIN_TREES = 200; + var MAX_TREES = 1250; + var P_FOREST = 0.02; +} +else if (currentBiome() == "tropic") +{ + var MIN_TREES = 1000; + var MAX_TREES = 6000; + var P_FOREST = 0.6; +} +else +{ + var MIN_TREES = 500; + var MAX_TREES = 3000; + var P_FOREST = 0.7; +} + +var totalTrees = scaleByMapSize(MIN_TREES, MAX_TREES); +var numForest = totalTrees * P_FOREST; +var numStragglers = totalTrees * (1.0 - P_FOREST); + +log("Creating forests..."); +var types = [ + [[tForestFloor2, tMainTerrain, pForest1], [tForestFloor2, pForest1]], + [[tForestFloor1, tMainTerrain, pForest2], [tForestFloor1, pForest2]] +]; + +var size = numForest / (scaleByMapSize(2, 8) * numPlayers) * (currentBiome() == "savanna" ? 2 : 1); +var num = floor(size / types.length); +for (let type of types) + createAreas( + new ClumpPlacer(numForest / num, 0.1, 0.1, 1), + [ + new LayeredPainter(type, [2]), + paintClass(clForest) + ], + [avoidClasses(clPlayer, 6, clForest, 10, clHill, 0), stayClasses(clLand, 4)], + num); +RMS.SetProgress(55); + +log("Creating stone mines..."); +group = new SimpleGroup([new SimpleObject(oStoneSmall, 0,2, 0,4), new SimpleObject(oStoneLarge, 1,1, 0,4)], true, clRock); +createObjectGroupsDeprecated(group, 0, + [avoidClasses(clForest, 1, clPlayer, 10, clRock, 10, clHill, 1), stayClasses(clLand, 5)], + 5*scaleByMapSize(4,16), 100 +); + +log("Creating small stone quarries..."); +group = new SimpleGroup([new SimpleObject(oStoneSmall, 2,5, 1,3)], true, clRock); +createObjectGroupsDeprecated(group, 0, + [avoidClasses(clForest, 1, clPlayer, 10, clRock, 10, clHill, 1), stayClasses(clLand, 5)], + 5*scaleByMapSize(4,16), 100 +); + +log("Creating metal mines..."); +group = new SimpleGroup([new SimpleObject(oMetalLarge, 1,1, 0,4)], true, clMetal); +createObjectGroupsDeprecated(group, 0, + [avoidClasses(clForest, 1, clPlayer, 10, clMetal, 10, clRock, 5, clHill, 1), stayClasses(clLand, 5)], + 5*scaleByMapSize(4,16), 100 +); + +RMS.SetProgress(65); +log("Creating dirt patches..."); +for (let size of [scaleByMapSize(3, 48), scaleByMapSize(5, 84), scaleByMapSize(8, 128)]) + createAreas( + new ClumpPlacer(size, 0.3, 0.06, 0.5), + [ + new LayeredPainter([[tMainTerrain, tTier1Terrain],[tTier1Terrain, tTier2Terrain], [tTier2Terrain, tTier3Terrain]], [1, 1]), + paintClass(clDirt) + ], + [avoidClasses(clForest, 0, clHill, 0, clDirt, 5, clPlayer, 12), stayClasses(clLand, 5)], + scaleByMapSize(15, 45)); + +log("Creating grass patches..."); +for (let size of [scaleByMapSize(2, 32), scaleByMapSize(3, 48), scaleByMapSize(5, 80)]) + createAreas( + new ClumpPlacer(size, 0.3, 0.06, 0.5), + new TerrainPainter(tTier4Terrain), + [avoidClasses(clForest, 0, clHill, 0, clDirt, 5, clPlayer, 12), stayClasses(clLand, 5)], + scaleByMapSize(15, 45)); + +log("Creating small decorative rocks..."); +group = new SimpleGroup( + [new SimpleObject(aRockMedium, 1,3, 0,1)], + true +); +createObjectGroupsDeprecated( + group, 0, + [avoidClasses(clForest, 0, clPlayer, 0, clHill, 0), stayClasses(clLand, 4)], + scaleByMapSize(16, 262), 50 +); + +log("Creating large decorative rocks..."); +group = new SimpleGroup( + [new SimpleObject(aRockLarge, 1,2, 0,1), new SimpleObject(aRockMedium, 1,3, 0,2)], + true +); +createObjectGroupsDeprecated( + group, 0, + [avoidClasses(clForest, 0, clPlayer, 0, clHill, 0), stayClasses(clLand, 4)], + scaleByMapSize(8, 131), 50 +); + +RMS.SetProgress(70); + +log("Creating deer..."); +group = new SimpleGroup( + [new SimpleObject(oMainHuntableAnimal, 5,7, 0,4)], + true, clFood +); +createObjectGroupsDeprecated(group, 0, + [avoidClasses(clForest, 0, clPlayer, 10, clHill, 1, clFood, 20), stayClasses(clLand, 4)], + 3 * numPlayers, 50 +); + +RMS.SetProgress(75); + +log("Creating sheep..."); +group = new SimpleGroup( + [new SimpleObject(oSecondaryHuntableAnimal, 2,3, 0,2)], + true, clFood +); +createObjectGroupsDeprecated(group, 0, + [avoidClasses(clForest, 0, clPlayer, 10, clHill, 1, clFood, 20), stayClasses(clLand, 4)], + 3 * numPlayers, 50 +); + +log("Creating fruits..."); +group = new SimpleGroup( + [new SimpleObject(oFruitBush, 5,7, 0,4)], + true, clFood +); +createObjectGroupsDeprecated(group, 0, + [avoidClasses(clForest, 0, clPlayer, 10, clHill, 1, clFood, 20), stayClasses(clLand, 4)], + 3 * numPlayers, 50 +); +RMS.SetProgress(85); + +log("Creating straggler trees..."); +var types = [oTree1, oTree2, oTree4, oTree3]; +var num = floor(numStragglers / types.length); +for (let type of types) + createObjectGroupsDeprecated( + new SimpleGroup([new SimpleObject(type, 1, 1, 0, 3)], true, clForest), + 0, + [avoidClasses(clForest, 1, clHill, 1, clPlayer, 9, clMetal, 6, clRock, 6), stayClasses(clLand, 4)], + num); + +var planetm = 1; +if (currentBiome() == "tropic") + planetm = 8; + +log("Creating small grass tufts..."); +group = new SimpleGroup( + [new SimpleObject(aGrassShort, 1,2, 0,1, -PI/8,PI/8)] +); +createObjectGroupsDeprecated(group, 0, + [avoidClasses(clHill, 2, clPlayer, 2, clDirt, 0), stayClasses(clLand, 4)], + planetm * scaleByMapSize(13, 200) +); + +RMS.SetProgress(90); + +log("Creating large grass tufts..."); +group = new SimpleGroup( + [new SimpleObject(aGrass, 2,4, 0,1.8, -PI/8,PI/8), new SimpleObject(aGrassShort, 3,6, 1.2,2.5, -PI/8,PI/8)] +); +createObjectGroupsDeprecated(group, 0, + [avoidClasses(clHill, 2, clPlayer, 2, clDirt, 1, clForest, 0), stayClasses(clLand, 4)], + planetm * scaleByMapSize(13, 200) +); +RMS.SetProgress(95); + +log("Creating bushes..."); +group = new SimpleGroup( + [new SimpleObject(aBushMedium, 1,2, 0,2), new SimpleObject(aBushSmall, 2,4, 0,2)] +); +createObjectGroupsDeprecated(group, 0, + [avoidClasses(clHill, 1, clPlayer, 1, clDirt, 1), stayClasses(clLand, 4)], + planetm * scaleByMapSize(13, 200), 50 +); + +setSkySet(pickRandom(["cirrus", "cumulus", "sunny"])); +setSunRotation(randFloat(0, TWO_PI)); +setSunElevation(randFloat(PI/ 5, PI / 3)); + +ExportMap(); -- 2.11.4.GIT