Ticket #1688: belgian_uplands2012-10-3.diff

File belgian_uplands2012-10-3.diff, 23.7 KB (added by FeXoR, 12 years ago)

The SVN .diff

  • binaries/data/mods/public/art/textures/ui/session/icons/mappreview/belgian_uplands.png

    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
  • binaries/data/mods/public/maps/random/belgian_uplands.js

    Property changes on: binaries/data/mods/public/art/textures/ui/session/icons/mappreview/belgian_uplands.png
    ___________________________________________________________________
    Added: svn:mime-type
    ## -0,0 +1 ##
    +application/octet-stream
    \ No newline at end of property
     
     1// Prepare progress calculation
     2// var timeArray = [];
     3// timeArray.push(new Date().getTime());
     4
     5// Importing rmgen libraries
     6RMS.LoadLibrary("rmgen");
     7
     8const BUILDING_ANGlE = -PI/4;
     9
     10// initialize map
     11
     12log("Initializing map...");
     13
     14InitMap();
     15
     16var numPlayers = getNumPlayers();
     17var mapSize = getMapSize();
     18
     19
     20//////////
     21// Heightmap functionality
     22//////////
     23
     24// Some general heightmap settings
     25const MIN_HEIGHT = - SEA_LEVEL; // 20, should be set in the libs!
     26const MAX_HEIGHT = 0xFFFF/HEIGHT_UNITS_PER_METRE - SEA_LEVEL; // A bit smaler than 90, should be set in the libs!
     27
     28// Random heightmap generation
     29function getRandomReliefmap(minHeight, maxHeight)
     30{
     31    minHeight = (minHeight || MIN_HEIGHT);
     32    maxHeight = (maxHeight || MAX_HEIGHT);
     33    if (minHeight < MIN_HEIGHT)
     34        warn("getRandomReliefmap: Argument minHeight is smaler then the supported minimum height of " + MIN_HEIGHT + " (const MIN_HEIGHT): " + minHeight)
     35    if (maxHeight > MAX_HEIGHT)
     36        warn("getRandomReliefmap: Argument maxHeight is smaler then the supported maximum height of " + MAX_HEIGHT + " (const MAX_HEIGHT): " + maxHeight)
     37    var reliefmap = [];
     38    for (var x = 0; x <= mapSize; x++)
     39    {
     40        reliefmap.push([]);
     41        for (var y = 0; y <= mapSize; y++)
     42        {
     43            reliefmap[x].push(randFloat(minHeight, maxHeight));
     44        }
     45    }
     46    return reliefmap;
     47}
     48
     49// Apply a heightmap
     50function setReliefmap(reliefmap)
     51{
     52    // g_Map.height = reliefmap;
     53    for (var x = 0; x <= mapSize; x++)
     54    {
     55        for (var y = 0; y <= mapSize; y++)
     56        {
     57            setHeight(x, y, reliefmap[x][y]);
     58        }
     59    }
     60}
     61
     62// Get minimum and maxumum height used in a heightmap
     63function getMinAndMaxHeight(reliefmap)
     64{
     65    var height = {};
     66    height.min = Infinity;
     67    height.max = -Infinity;
     68    for (var x = 0; x <= mapSize; x++)
     69    {
     70        for (var y = 0; y <= mapSize; y++)
     71        {
     72            if (reliefmap[x][y] < height.min)
     73                height.min = reliefmap[x][y];
     74            else if (reliefmap[x][y] > height.max)
     75                height.max = reliefmap[x][y];
     76        }
     77    }
     78    return height;
     79}
     80
     81// Rescale a heightmap (Waterlevel is not taken into consideration!)
     82function getRescaledReliefmap(reliefmap, minHeight, maxHeight)
     83{
     84    var newReliefmap = deepcopy(reliefmap);
     85    minHeight = (minHeight || MIN_HEIGHT);
     86    maxHeight = (maxHeight || MAX_HEIGHT);
     87    if (minHeight < MIN_HEIGHT)
     88        warn("getRescaledReliefmap: Argument minHeight is smaler then the supported minimum height of " + MIN_HEIGHT + " (const MIN_HEIGHT): " + minHeight)
     89    if (maxHeight > MAX_HEIGHT)
     90        warn("getRescaledReliefmap: Argument maxHeight is smaler then the supported maximum height of " + MAX_HEIGHT + " (const MAX_HEIGHT): " + maxHeight)
     91    var oldHeightRange = getMinAndMaxHeight(reliefmap);
     92    for (var x = 0; x <= mapSize; x++)
     93    {
     94        for (var y = 0; y <= mapSize; y++)
     95        {
     96            newReliefmap[x][y] = minHeight + (reliefmap[x][y] - oldHeightRange.min) / (oldHeightRange.max - oldHeightRange.min) * (maxHeight - minHeight);
     97        }
     98    }
     99    return newReliefmap
     100}
     101
     102// Applying decay errosion (terrain independent)
     103function getHeightErrosionedReliefmap(reliefmap, strength)
     104{
     105    var newReliefmap = deepcopy(reliefmap);
     106    strength = (strength || 1.0); // Values much higher then 1 (1.32+ for an 8 tile map, 1.45+ for a 12 tile map, 1.62+ @ 20 tile map, 0.99 @ 4 tiles) will result in a resonance disaster/self interference
     107    var map = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]; // Default
     108    for (var x = 0; x <= mapSize; x++)
     109    {
     110        for (var y = 0; y <= mapSize; y++)
     111        {
     112            var div = 0;
     113            for (var i = 0; i < map.length; i++)
     114                newReliefmap[x][y] += strength / map.length * (reliefmap[(x + map[i][0] + mapSize + 1) % (mapSize + 1)][(y + map[i][1] + mapSize + 1) % (mapSize + 1)] - reliefmap[x][y]); // Not entirely sure if scaling with map.length is perfect but tested values seam to indicate it is
     115        }
     116    }
     117    return newReliefmap;
     118}
     119
     120
     121//////////
     122// Apply hightmap munipulation
     123//////////
     124
     125// Set target min and max height depending on map size to make average stepness the same on all map sizes
     126var heightRange = {"min": MIN_HEIGHT * mapSize / 512, "max": MAX_HEIGHT * mapSize / 512};
     127
     128// Set average water coverage
     129var averageWaterCoverage = 1/3; // NOTE: Since errosion is not predictable actual water coverage might differ much with the same value
     130if (mapSize < 200) // Sink the waterlevel on tiny maps to ensure enough space
     131    averageWaterCoverage = 2/3 * averageWaterCoverage;
     132var waterHeight = -MIN_HEIGHT + heightRange.min + averageWaterCoverage * (heightRange.max - heightRange.min);
     133var waterHeightAdjusted = waterHeight + MIN_HEIGHT;
     134setWaterHeight(waterHeight);
     135
     136// Time check 1
     137// timeArray.push(new Date().getTime());
     138RMS.SetProgress(2);
     139
     140
     141// Generate reliefmap
     142var myReliefmap = getRandomReliefmap(heightRange.min, heightRange.max);
     143// Cycles depend on mapsize (more cycles -> bigger structures)
     144for (var i = 0; i < 50 + mapSize/4; i++)
     145    myReliefmap = getHeightErrosionedReliefmap(myReliefmap, 1);
     146myReliefmap = getRescaledReliefmap(myReliefmap, heightRange.min, heightRange.max);
     147setReliefmap(myReliefmap);
     148
     149// Time check 2
     150// timeArray.push(new Date().getTime());
     151RMS.SetProgress(66);
     152
     153
     154//////////
     155// Apply terrain texture by height
     156//////////
     157
     158var textueByHeight = [];
     159
     160// Deep water
     161textueByHeight.push({"upperHeightLimit": heightRange.min + 1/3 * (waterHeightAdjusted - heightRange.min), "terrain": "temp_sea_rocks"});
     162// Medium deep water (with fish)
     163var terreins = ["temp_sea_weed"];
     164terreins = terreins.concat(terreins, terreins, terreins, terreins);
     165terreins = terreins.concat(terreins, terreins, terreins, terreins);
     166terreins.push("temp_sea_weed|gaia/fauna_fish");
     167textueByHeight.push({"upperHeightLimit": heightRange.min + 2/3 * (waterHeightAdjusted - heightRange.min), "terrain": terreins});
     168// Flat Water
     169textueByHeight.push({"upperHeightLimit": heightRange.min + 3/3 * (waterHeightAdjusted - heightRange.min), "terrain": "temp_mud_a"});
     170// Water surroundings/bog (with stone/metal some rabits and bushes)
     171var terreins = ["temp_plants_bog", "temp_plants_bog_aut", "temp_dirt_gravel_plants", "temp_grass_d"];
     172terreins = terreins.concat(terreins, terreins, terreins, terreins, terreins);
     173terreins = ["temp_plants_bog|gaia/flora_bush_temperate"].concat(terreins, terreins);
     174terreins = ["temp_dirt_gravel_plants|gaia/geology_metal_temperate", "temp_dirt_gravel_plants|gaia/geology_stone_temperate", "temp_plants_bog|gaia/fauna_rabbit"].concat(terreins, terreins);
     175terreins = ["temp_plants_bog_aut|gaia/flora_tree_dead"].concat(terreins, terreins);
     176textueByHeight.push({"upperHeightLimit": waterHeightAdjusted + 1/6 * (heightRange.max - waterHeightAdjusted), "terrain": terreins});
     177// Juicy grass near bog
     178textueByHeight.push({"upperHeightLimit": waterHeightAdjusted + 2/6 * (heightRange.max - waterHeightAdjusted),
     179    "terrain": ["temp_grass", "temp_grass_d", "temp_grass_long_b", "temp_grass_plants"]});
     180// Medium level grass
     181// var testActor = "actor|geology/decal_stone_medit_a.xml";
     182textueByHeight.push({"upperHeightLimit": waterHeightAdjusted + 3/6 * (heightRange.max - waterHeightAdjusted),
     183    "terrain": ["temp_grass", "temp_grass_b", "temp_grass_c", "temp_grass_mossy"]});
     184// Long grass near forest border
     185textueByHeight.push({"upperHeightLimit": waterHeightAdjusted + 4/6 * (heightRange.max - waterHeightAdjusted),
     186    "terrain": ["temp_grass", "temp_grass_b", "temp_grass_c", "temp_grass_d", "temp_grass_long_b", "temp_grass_clovers_2", "temp_grass_mossy", "temp_grass_plants"]});
     187// Forest border (With wood/food plants/deer/rabits)
     188var terreins = ["temp_grass_plants|gaia/flora_tree_euro_beech", "temp_grass_mossy|gaia/flora_tree_poplar", "temp_grass_mossy|gaia/flora_tree_poplar_lombardy",
     189    "temp_grass_long|gaia/flora_bush_temperate", "temp_mud_plants|gaia/flora_bush_temperate", "temp_mud_plants|gaia/flora_bush_badlands",
     190    "temp_grass_long|gaia/flora_tree_apple", "temp_grass_clovers|gaia/flora_bush_berry", "temp_grass_clovers_2|gaia/flora_bush_grapes",
     191    "temp_grass_plants|gaia/fauna_deer", "temp_grass_long_b|gaia/fauna_rabbit"];
     192var numTerreins = terreins.length;
     193for (var i = 0; i < numTerreins; i++)
     194    terreins.push("temp_grass_plants");
     195textueByHeight.push({"upperHeightLimit": waterHeightAdjusted + 5/6 * (heightRange.max - waterHeightAdjusted), "terrain": terreins});
     196// Unpassable woods
     197textueByHeight.push({"upperHeightLimit": waterHeightAdjusted + 6/6 * (heightRange.max - waterHeightAdjusted),
     198    "terrain": ["temp_grass_mossy|gaia/flora_tree_oak", "temp_forestfloor_pine|gaia/flora_tree_pine",
     199    "temp_grass_mossy|gaia/flora_tree_oak", "temp_forestfloor_pine|gaia/flora_tree_pine",
     200    "temp_mud_plants|gaia/flora_tree_dead", "temp_plants_bog|gaia/flora_tree_oak_large",
     201    "temp_dirt_gravel_plants|gaia/flora_tree_aleppo_pine", "temp_forestfloor_autumn|gaia/flora_tree_carob"]});
     202var minTerrainDistToBorder = 3;
     203
     204// Paint terrain by height and add props
     205var propDensity = 1; // 1 means as determined in the loop, less for large maps as set below
     206if (mapSize > 500)
     207    propDensity = 1/4;
     208else if (mapSize > 400)
     209    propDensity = 3/4;
     210for(var x = minTerrainDistToBorder; x < mapSize - minTerrainDistToBorder; x++)
     211{
     212    for (var y = minTerrainDistToBorder; y < mapSize - minTerrainDistToBorder; y++)
     213    {
     214        var textureMinHeight = heightRange.min;
     215        for (var i = 0; i < textueByHeight.length; i++)
     216        {
     217            if (getHeight(x, y) >= textureMinHeight && getHeight(x, y) <= textueByHeight[i].upperHeightLimit)
     218            {
     219                placeTerrain(x, y, textueByHeight[i].terrain);
     220                // Add some props at...
     221                if (i == 0) // ...deep water
     222                {
     223                    if (randFloat() < 1/50 * propDensity)
     224                        placeObject(x, y, "actor|props/flora/pond_lillies_large.xml", 0, randFloat(0, 2*PI));
     225                    else if (randFloat() < 1/20 * propDensity)
     226                        placeObject(x, y, "actor|props/flora/water_lillies.xml", 0, randFloat(0, 2*PI));
     227                }
     228                if (i == 1) // ...medium water (with fish)
     229                {
     230                    if (randFloat() < 1/100 * propDensity)
     231                        placeObject(x, y, "actor|props/flora/pond_lillies_large.xml", 0, randFloat(0, 2*PI));
     232                    else if (randFloat() < 1/50 * propDensity)
     233                        placeObject(x, y, "actor|props/flora/water_lillies.xml", 0, randFloat(0, 2*PI));
     234                }
     235                if (i == 2) // ...low water/mud
     236                {
     237                    if (randFloat() < 1/100 * propDensity)
     238                        placeObject(x, y, "actor|props/flora/water_log.xml", 0, randFloat(0, 2*PI));
     239                    else if (randFloat() < 1/50 * propDensity)
     240                        placeObject(x, y, "actor|props/flora/water_lillies.xml", 0, randFloat(0, 2*PI));
     241                    else if (randFloat() < 1/20 * propDensity)
     242                        placeObject(x, y, "actor|geology/highland_c.xml", 0, randFloat(0, 2*PI));
     243                    else if (randFloat() < 1/10 * propDensity)
     244                        placeObject(x, y, "actor|props/flora/reeds_pond_lush_b.xml", 0, randFloat(0, 2*PI));
     245                    else if (randFloat() < 1/5 * propDensity)
     246                        placeObject(x, y, "actor|props/flora/reeds_pond_lush_a.xml", 0, randFloat(0, 2*PI));
     247                }
     248                if (i == 3) // ...water suroundings/bog
     249                {
     250                    if (randFloat() < 1/100 * propDensity)
     251                        placeObject(x, y, "actor|props/flora/water_log.xml", 0, randFloat(0, 2*PI));
     252                    else if (randFloat() < 1/50 * propDensity)
     253                        placeObject(x, y, "actor|geology/highland_c.xml", 0, randFloat(0, 2*PI));
     254                    else if (randFloat() < 1/20 * propDensity)
     255                        placeObject(x, y, "actor|props/flora/reeds_pond_lush_a.xml", 0, randFloat(0, 2*PI));
     256                }
     257                if (i == 4) // ...low height grass
     258                {
     259                    if (randFloat() < 1/400 * propDensity)
     260                        placeObject(x, y, "actor|props/flora/grass_field_flowering_tall.xml", 0, randFloat(0, 2*PI));
     261                    else if (randFloat() < 1/200 * propDensity)
     262                        placeObject(x, y, "actor|geology/gray_rock1.xml", 0, randFloat(0, 2*PI));
     263                    else if (randFloat() < 1/100 * propDensity)
     264                        placeObject(x, y, "actor|props/flora/bush_tempe_sm_lush.xml", 0, randFloat(0, 2*PI));
     265                    else if (randFloat() < 1/50 * propDensity)
     266                        placeObject(x, y, "actor|props/flora/bush_tempe_b.xml", 0, randFloat(0, 2*PI));
     267                    else if (randFloat() < 1/20 * propDensity)
     268                        placeObject(x, y, "actor|props/flora/grass_soft_small_tall.xml", 0, randFloat(0, 2*PI));
     269                }
     270                if (i == 5) // ...medium height grass
     271                {
     272                    if (randFloat() < 1/400 * propDensity)
     273                        placeObject(x, y, "actor|geology/decal_stone_medit_a.xml", 0, randFloat(0, 2*PI));
     274                    else if (randFloat() < 1/200 * propDensity)
     275                        placeObject(x, y, "actor|props/flora/decals_flowers_daisies.xml", 0, randFloat(0, 2*PI));
     276                    else if (randFloat() < 1/100 * propDensity)
     277                        placeObject(x, y, "actor|props/flora/bush_tempe_underbrush.xml", 0, randFloat(0, 2*PI));
     278                    else if (randFloat() < 1/50 * propDensity)
     279                        placeObject(x, y, "actor|props/flora/grass_soft_small_tall.xml", 0, randFloat(0, 2*PI));
     280                    else if (randFloat() < 1/20 * propDensity)
     281                        placeObject(x, y, "actor|props/flora/grass_temp_field.xml", 0, randFloat(0, 2*PI));
     282                }
     283                if (i == 6) // ...high height grass
     284                {
     285                    if (randFloat() < 1/200 * propDensity)
     286                        placeObject(x, y, "actor|geology/stone_granite_boulder.xml", 0, randFloat(0, 2*PI));
     287                    else if (randFloat() < 1/100 * propDensity)
     288                        placeObject(x, y, "actor|props/flora/foliagebush.xml", 0, randFloat(0, 2*PI));
     289                    else if (randFloat() < 1/50 * propDensity)
     290                        placeObject(x, y, "actor|props/flora/bush_tempe_underbrush.xml", 0, randFloat(0, 2*PI));
     291                    else if (randFloat() < 1/20 * propDensity)
     292                        placeObject(x, y, "actor|props/flora/grass_soft_small_tall.xml", 0, randFloat(0, 2*PI));
     293                    else if (randFloat() < 1/10 * propDensity)
     294                        placeObject(x, y, "actor|props/flora/ferns.xml", 0, randFloat(0, 2*PI));
     295                }
     296                if (i == 7) // ...forest border (with wood/food plants/deer/rabits)
     297                {
     298                    if (randFloat() < 1/200 * propDensity)
     299                        placeObject(x, y, "actor|geology/highland_c.xml", 0, randFloat(0, 2*PI));
     300                    else if (randFloat() < 1/100 * propDensity)
     301                        placeObject(x, y, "actor|props/flora/bush_tempe_a.xml", 0, randFloat(0, 2*PI));
     302                    else if (randFloat() < 1/50 * propDensity)
     303                        placeObject(x, y, "actor|props/flora/ferns.xml", 0, randFloat(0, 2*PI));
     304                    else if (randFloat() < 1/20 * propDensity)
     305                        placeObject(x, y, "actor|props/flora/grass_soft_tuft_a.xml", 0, randFloat(0, 2*PI));
     306                }
     307                if (i == 8) // ...woods
     308                {
     309                    if (randFloat() < 1/100 * propDensity)
     310                        placeObject(x, y, "actor|geology/highland2_moss.xml", 0, randFloat(0, 2*PI));
     311                    else if (randFloat() < 1/50 * propDensity)
     312                        placeObject(x, y, "actor|props/flora/grass_soft_tuft_a.xml", 0, randFloat(0, 2*PI));
     313                    else if (randFloat() < 1/20 * propDensity)
     314                        placeObject(x, y, "actor|props/flora/ferns.xml", 0, randFloat(0, 2*PI));
     315                }
     316                break;
     317            }
     318            else
     319            {
     320                textureMinHeight = textueByHeight[i].upperHeightLimit;
     321            }
     322        }
     323    }
     324}
     325
     326// Time check 3
     327// timeArray.push(new Date().getTime());
     328RMS.SetProgress(88);
     329
     330
     331//////////
     332// Find good start position tiles
     333//////////
     334
     335var startPositions = [];
     336var possibleStartPositions = [];
     337var neededDistance = 7;
     338var distToBorder = 2 * neededDistance; // Has to be greater than neededDistance! Otherwise the check if low/high ground is near will fail...
     339var lowerHeightLimit = textueByHeight[3].upperHeightLimit;
     340var upperHeightLimit = textueByHeight[6].upperHeightLimit;
     341// Check for valid points by height
     342for (var x = distToBorder + minTerrainDistToBorder; x < mapSize - distToBorder - minTerrainDistToBorder; x++)
     343{
     344    for (var y = distToBorder + minTerrainDistToBorder; y < mapSize - distToBorder - minTerrainDistToBorder; y++)
     345    {
     346        var actualHeight = getHeight(x, y);
     347        if (actualHeight > lowerHeightLimit && actualHeight < upperHeightLimit)
     348        {
     349            // Check for points within a valid area by height (rectangular since faster)
     350            var isPossible = true;
     351            for (var offX = - neededDistance; offX <= neededDistance; offX++)
     352            {
     353                for (var offY = - neededDistance; offY <= neededDistance; offY++)
     354                {
     355                    var testHeight = getHeight(x + offX, y + offY);
     356                    if (testHeight <= lowerHeightLimit || testHeight >= upperHeightLimit)
     357                    {
     358                        isPossible = false;
     359                        break;
     360                    }
     361                }
     362            }
     363            if (isPossible)
     364            {
     365                possibleStartPositions.push([x, y]);
     366                // placeTerrain(x, y, "blue"); // For debug reasons. Plz don't remove.
     367            }
     368        }
     369    }
     370}
     371
     372// Time check 4
     373// timeArray.push(new Date().getTime());
     374RMS.SetProgress(91);
     375
     376// Trying to reduce the number of possible start locations...
     377
     378// ...by beeing in a circle of mapSize / 2 distance to the center
     379var possibleStartPositionsTemp = [];
     380var maxDistToCenter = mapSize / 2;
     381for (var i = 0; i < possibleStartPositions.length; i++)
     382{
     383    var deltaX = possibleStartPositions[i][0] - mapSize / 2;
     384    var deltaY = possibleStartPositions[i][1] - mapSize / 2;
     385    var distToCenter = Math.pow(Math.pow(deltaX, 2) + Math.pow(deltaY, 2), 1/2);
     386    if (distToCenter < maxDistToCenter)
     387    {
     388        possibleStartPositionsTemp.push(possibleStartPositions[i]);
     389        // placeTerrain(possibleStartPositions[i][0], possibleStartPositions[i][1], "purple"); // For debug reasons. Plz don't remove.
     390    }
     391}
     392possibleStartPositions = deepcopy(possibleStartPositionsTemp);
     393
     394// ...by checking if low and high ground is near. Rectangular check since faster...
     395var possibleStartPositionsTemp = [];
     396var maxDistToResources = distToBorder; // Has to be <= distToBorder!
     397var minNumLowTiles = 10;
     398var minNumHighTiles = 10;
     399for (var i = 0; i < possibleStartPositions.length; i++)
     400{
     401    var numLowTiles = 0;
     402    var numHighTiles = 0;
     403    for (var dx = - maxDistToResources; dx < maxDistToResources; dx++)
     404    {
     405        for (var dy = - maxDistToResources; dy < maxDistToResources; dy++)
     406        {
     407            var testHeight = getHeight(possibleStartPositions[i][0] + dx, possibleStartPositions[i][1] + dy);
     408            if (testHeight < lowerHeightLimit)
     409                numLowTiles++;
     410            if (testHeight > upperHeightLimit)
     411                numHighTiles++;
     412            if (numLowTiles > minNumLowTiles && numHighTiles > minNumHighTiles)
     413                break;
     414        }
     415        if (numLowTiles > minNumLowTiles && numHighTiles > minNumHighTiles)
     416            break;
     417    }
     418    if (numLowTiles > minNumLowTiles && numHighTiles > minNumHighTiles)
     419    {
     420        possibleStartPositionsTemp.push(possibleStartPositions[i]);
     421        // placeTerrain(possibleStartPositions[i][0], possibleStartPositions[i][1], "red"); // For debug reasons. Plz don't remove.
     422    }
     423}
     424possibleStartPositions = deepcopy(possibleStartPositionsTemp);
     425
     426// Time check 5
     427// timeArray.push(new Date().getTime());
     428RMS.SetProgress(97);
     429
     430
     431////////
     432// Find a good start position derivation
     433////////
     434
     435// Get some random start location derivations. NOTE: Itterating over all possible derivations is just to much (valid points ** numPlayers)
     436var maxTries = 100000; // floor(800000 / (Math.pow(numPlayers, 2) / 2));
     437var possibleDerivations = [];
     438for (var i = 0; i < maxTries; i++)
     439{
     440    var vector = [];
     441    for (var p = 0; p < numPlayers; p++)
     442        vector.push(randInt(possibleStartPositions.length));
     443    possibleDerivations.push(vector);
     444}
     445
     446// Choose the start location derivation with the greatest minimum distance between players
     447var maxMinDist = 0;
     448for (var d = 0; d < possibleDerivations.length; d++)
     449{
     450    var minDist = 2 * mapSize;
     451    for (var p1 = 0; p1 < numPlayers - 1; p1++)
     452    {
     453        for (var p2 = p1 + 1; p2 < numPlayers; p2++)
     454        {
     455            if (p1 != p2)
     456            {
     457                var StartPositionP1 = possibleStartPositions[possibleDerivations[d][p1]];
     458                var StartPositionP2 = possibleStartPositions[possibleDerivations[d][p2]];
     459                var actualDist = Math.pow(Math.pow(StartPositionP1[0] - StartPositionP2[0], 2) + Math.pow(StartPositionP1[1] - StartPositionP2[1], 2), 1/2);
     460                if (actualDist < minDist)
     461                    minDist = actualDist;
     462                if (minDist < maxMinDist)
     463                    break;
     464            }
     465        }
     466        if (minDist < maxMinDist)
     467            break;
     468    }
     469    if (minDist > maxMinDist)
     470    {
     471        maxMinDist = minDist;
     472        var bestDerivation = possibleDerivations[d];
     473    }
     474}
     475
     476// Time check 6
     477// timeArray.push(new Date().getTime());
     478RMS.SetProgress(99);
     479
     480// Place players
     481for (var p = 0; p < numPlayers; p++)
     482{
     483    var actualX = possibleStartPositions[bestDerivation[p]][0];
     484    var actualY = possibleStartPositions[bestDerivation[p]][1];
     485    placeCivDefaultEntities(actualX, actualY, p + 1, BUILDING_ANGlE, {"iberWall" : false});
     486    var uDist = 8;
     487    var uSpace = 1;
     488    for (var j = 1; j <= 4; ++j)
     489    {
     490        var uAngle = BUILDING_ANGlE - PI * (2-j) / 2;
     491        var count = 4;
     492        for (var numberofentities = 0; numberofentities < count; numberofentities++)
     493        {
     494            var ux = actualX + uDist * cos(uAngle) + numberofentities * uSpace * cos(uAngle + PI/2) - (0.75 * uSpace * floor(count / 2) * cos(uAngle + PI/2));
     495            var uz = actualY + uDist * sin(uAngle) + numberofentities * uSpace * sin(uAngle + PI/2) - (0.75 * uSpace * floor(count / 2) * sin(uAngle + PI/2));
     496            if (j % 2 == 0)
     497                placeObject(ux, uz, "gaia/flora_bush_berry", 0, randFloat(0, 2*PI));
     498            else
     499                placeObject(ux, uz, "gaia/flora_tree_cypress", 0, randFloat(0, 2*PI));
     500        }
     501    }
     502}
     503
     504
     505// Export map data
     506ExportMap();
     507
     508
     509// // Time check 7
     510// timeArray.push(new Date().getTime());
     511// RMS.SetProgress(100);
     512
     513// var generationTime = timeArray[timeArray.length - 1] - timeArray[0];
     514// log("Total generation time (ms): " + generationTime);
     515// for (var i = 0; i < timeArray.length; i++)
     516// {
     517    // var timeSinceStart = timeArray[i] - timeArray[0];
     518    // var progressPercentage = 100 * timeSinceStart / generationTime;
     519    // log("Time check " + i + ": Progress (%): " + progressPercentage);
     520// }
  • binaries/data/mods/public/maps/random/belgian_uplands.json

     
     1{
     2    "settings" : {
     3        "Name" : "Belgian Uplands",
     4        "Script" : "belgian_uplands.js",
     5        "Description" : "An experimental map with its hightmap generated by erosion to look more natural. Not all seeds will be fair though! More then 2 players on a tiny map may wind up right next to each other (suggest 3 players: small+, 5 Players: medium+). Giant maps may raise out of memory errors.",
     6        "CircularMap" : false,
     7        "BaseTerrain" : ["temp_grass", "temp_grass_b", "temp_grass_c", "temp_grass_d", "temp_grass_long_b", "temp_grass_clovers_2", "temp_grass_mossy", "temp_grass_plants"],
     8        "BaseHeight" : 0,
     9        "Preview" : "belgian_uplands.png",
     10        "XXXXXX" : "Optionally define other things here, like we would for a scenario"
     11    }
     12}