Add quadratic scaling function in rmgen library and use it for decorations.

Patch By: FeldeFeld
Reviewed By: Stan, smiley
Differential Revision: D4212
This was SVN commit r25894.
This commit is contained in:
bb 2021-09-04 09:48:06 +00:00
parent bd24a30567
commit 480228f964
30 changed files with 140 additions and 115 deletions

View File

@ -233,7 +233,7 @@ createDecoration(
]
],
[
scaleByMapSize(16, 262),
scaleByMapAreaAbsolute(16),
scaleByMapSize(40, 360)
],
avoidClasses(clWater, 2, clForest, 0, clPlayer, 0, clHill, 1));

View File

@ -192,8 +192,8 @@ createDecoration(
[new SimpleObject(aRock, 1,2, 0,1)]
],
[
scaleByMapSize(8, 131),
scaleByMapSize(8, 131)
scaleByMapAreaAbsolute(8),
scaleByMapAreaAbsolute(8)
],
avoidClasses(clWater, 0, clForest, 0, clPlayer, 0, clHill, 0));
Engine.SetProgress(75);

View File

@ -205,11 +205,11 @@ createDecoration(
[new SimpleObject(aBushMedium, 1, 2, 0, 2), new SimpleObject(aBushSmall, 2, 4, 0, 2)]
],
[
scaleByMapSize(16, 262),
scaleByMapSize(8, 131),
scaleByMapSize(13, 200),
scaleByMapSize(13, 200),
scaleByMapSize(13, 200)
scaleByMapAreaAbsolute(16),
scaleByMapAreaAbsolute(8),
scaleByMapAreaAbsolute(13),
scaleByMapAreaAbsolute(13),
scaleByMapAreaAbsolute(13)
],
avoidClasses(clWater, 0, clForest, 0, clPlayer, 0, clHill, 0));

View File

@ -203,11 +203,11 @@ createDecoration(
[new SimpleObject(aBushMedium, 1, 2, 0, 2), new SimpleObject(aBushSmall, 2, 4, 0, 2)]
],
[
scaleByMapSize(16, 262),
scaleByMapSize(8, 131),
planetm * scaleByMapSize(13, 200),
planetm * scaleByMapSize(13, 200),
planetm * scaleByMapSize(13, 200)
scaleByMapAreaAbsolute(16),
scaleByMapAreaAbsolute(8),
planetm * scaleByMapAreaAbsolute(13),
planetm * scaleByMapAreaAbsolute(13),
planetm * scaleByMapAreaAbsolute(13)
],
[avoidClasses(clForest, 0, clPlayer, 0, clHill, 0), stayClasses(clLand, 5)]);
Engine.SetProgress(70);

View File

@ -221,8 +221,8 @@ createDecoration(
]
],
[
scaleByMapSize(16, 262),
scaleByMapSize(8, 131),
scaleByMapAreaAbsolute(16),
scaleByMapAreaAbsolute(8),
],
avoidClasses(
clWater, 0,

View File

@ -145,11 +145,11 @@ createDecoration(
[new SimpleObject(aBushMedium, 1, 2, 0, 2), new SimpleObject(aBushSmall, 2, 4, 0, 2)]
],
[
scaleByMapSize(16, 262),
scaleByMapSize(8, 131),
scaleByMapSize(13, 200),
scaleByMapSize(13, 200),
scaleByMapSize(13, 200)
scaleByMapAreaAbsolute(16),
scaleByMapAreaAbsolute(8),
scaleByMapAreaAbsolute(13),
scaleByMapAreaAbsolute(13),
scaleByMapAreaAbsolute(13)
],
avoidClasses(clForest, 0, clPlayer, 0, clHill, 0));

View File

@ -224,11 +224,11 @@ createDecoration(
[new SimpleObject(aBushMedium, 1, 2, 0, 2), new SimpleObject(aBushSmall, 2, 4, 0, 2)]
],
[
scaleByMapSize(16, 262),
scaleByMapSize(8, 131),
scaleByMapSize(13, 200),
scaleByMapSize(13, 200),
scaleByMapSize(13, 200)
scaleByMapAreaAbsolute(16),
scaleByMapAreaAbsolute(8),
scaleByMapAreaAbsolute(13),
scaleByMapAreaAbsolute(13),
scaleByMapAreaAbsolute(13)
],
avoidClasses(clWater, 0, clForest, 0, clPlayer, 0, clHill, 0));
Engine.SetProgress(70);

View File

@ -285,11 +285,11 @@ createDecoration(
[new SimpleObject(aBushMedium, 1, 2, 0, 2), new SimpleObject(aBushSmall, 2, 4, 0, 2)]
],
[
3 * scaleByMapSize(16, 262),
3 * scaleByMapSize(8, 131),
planetm * scaleByMapSize(13, 200),
planetm * scaleByMapSize(13, 200),
planetm * scaleByMapSize(13, 200)
3 * scaleByMapAreaAbsolute(16),
3 * scaleByMapAreaAbsolute(8),
planetm * scaleByMapAreaAbsolute(13),
planetm * scaleByMapAreaAbsolute(13),
planetm * scaleByMapAreaAbsolute(13)
],
avoidClasses(clForest, 0, clPlayer, 0, clHill, 0));

View File

@ -196,11 +196,11 @@ createDecoration(
[new SimpleObject(aBushMedium, 1, 2, 0, 2), new SimpleObject(aBushSmall, 2, 4, 0, 2)]
],
[
scaleByMapSize(16, 262),
scaleByMapSize(8, 131),
planetm * scaleByMapSize(13, 200),
planetm * scaleByMapSize(13, 200),
planetm * scaleByMapSize(13, 200)
scaleByMapAreaAbsolute(16),
scaleByMapAreaAbsolute(8),
planetm * scaleByMapAreaAbsolute(13),
planetm * scaleByMapAreaAbsolute(13),
planetm * scaleByMapAreaAbsolute(13)
],
[avoidClasses(clForest, 0, clPlayer, 0, clHill, 0), stayClasses(clLand, 5)]);

View File

@ -253,7 +253,7 @@ createDecoration(
]
],
[
scaleByMapSize(16, 262),
scaleByMapAreaAbsolute(16),
scaleByMapSize(40, 360)
],
avoidClasses(clWater, 2, clForest, 0, clPlayer, 5, clBaseResource, 6, clHill, 1, clRock, 6, clMetal, 6));

View File

@ -554,15 +554,15 @@ for (let i = 0; i < 2; ++i)
[new SimpleObject(aFerns, 2, 5, 2, 4)]
],
[
scaleByMapSize(5, 80),
scaleByMapSize(5, 80),
scaleByMapSize(5, 80),
scaleByMapSize(5, 80),
scaleByMapAreaAbsolute(5),
scaleByMapAreaAbsolute(5),
scaleByMapAreaAbsolute(5),
scaleByMapAreaAbsolute(5),
scaleByMapSize(5, 80),
scaleByMapSize(5, 80),
scaleByMapSize(5, 80),
scaleByMapSize(5, 80),
scaleByMapAreaAbsolute(5),
scaleByMapAreaAbsolute(5),
scaleByMapAreaAbsolute(5),
scaleByMapAreaAbsolute(5),
scaleByMapSize(20, 80)
],

View File

@ -324,7 +324,7 @@ createDecoration(
]
],
[
scaleByMapSize(16, 262),
scaleByMapAreaAbsolute(16),
scaleByMapSize(40, 360)
],
avoidClasses(clWater, 4, clPlayer, 5, clVolcano, 4, clForest, 1, clBaseResource, 4, clRock, 4, clMetal, 4, clHill, 1));

View File

@ -190,11 +190,11 @@ createDecoration(
[new SimpleObject(aBushMedium, 1, 2, 0, 2), new SimpleObject(aBushSmall, 2, 4, 0, 2)]
],
[
scaleByMapSize(16, 262),
scaleByMapSize(8, 131),
scaleByMapSize(13, 200),
scaleByMapSize(13, 200),
scaleByMapSize(13, 200)
scaleByMapAreaAbsolute(16),
scaleByMapAreaAbsolute(8),
scaleByMapAreaAbsolute(13),
scaleByMapAreaAbsolute(13),
scaleByMapAreaAbsolute(13)
],
avoidClasses(clWater, 1, clForest, 0, clPlayer, 0, clHill, 0));

View File

@ -317,9 +317,9 @@ createDecoration(
]
],
[
scaleByMapSize(15, 200),
scaleByMapSize(15, 200),
scaleByMapSize(15, 200)
scaleByMapAreaAbsolute(15),
scaleByMapAreaAbsolute(15),
scaleByMapAreaAbsolute(15)
],
[
stayClasses(clGrass, 0),

View File

@ -265,11 +265,11 @@ createDecoration(
[new SimpleObject(aBushMedium, 1, 5, 0, 2), new SimpleObject(aBushSmall, 2, 4, 0, 2)]
],
[
scaleByMapSize(16, 262),
scaleByMapSize(8, 131),
planetm * scaleByMapSize(13, 200),
planetm * scaleByMapSize(13, 200),
planetm * scaleByMapSize(13, 200)
scaleByMapAreaAbsolute(16),
scaleByMapAreaAbsolute(8),
planetm * scaleByMapAreaAbsolute(13),
planetm * scaleByMapAreaAbsolute(13),
planetm * scaleByMapAreaAbsolute(13)
],
avoidClasses(clForest, 2, clPlayer, 20, clMountain, 5, clFood, 1, clBaseResource, 2));

View File

@ -239,11 +239,11 @@ createDecoration(
[new SimpleObject(aBushMedium, 1, 2, 0, 2), new SimpleObject(aBushSmall, 2, 4, 0, 2)]
],
[
scaleByMapSize(16, 262),
scaleByMapSize(8, 131),
scaleByMapSize(13, 200),
scaleByMapSize(13, 200),
scaleByMapSize(13, 200)
scaleByMapAreaAbsolute(16),
scaleByMapAreaAbsolute(8),
scaleByMapAreaAbsolute(13),
scaleByMapAreaAbsolute(13),
scaleByMapAreaAbsolute(13)
],
avoidClasses(clWater, 0, clForest, 0, clPlayer, 1, clHill, 0));
Engine.SetProgress(80);

View File

@ -273,11 +273,11 @@ createDecoration(
[new SimpleObject(aBushMedium, 1, 2, 0, 2), new SimpleObject(aBushSmall, 2, 4, 0, 2)]
],
[
scaleByMapSize(16, 262),
scaleByMapSize(8, 131),
planetm * scaleByMapSize(13, 200),
planetm * scaleByMapSize(13, 200),
planetm * scaleByMapSize(13, 200)
scaleByMapAreaAbsolute(16),
scaleByMapAreaAbsolute(8),
planetm * scaleByMapAreaAbsolute(13),
planetm * scaleByMapAreaAbsolute(13),
planetm * scaleByMapAreaAbsolute(13)
],
avoidClasses(clWater, 0, clForest, 0, clPlayer, 0, clHill, 0));

View File

@ -204,11 +204,11 @@ createDecoration(
[new SimpleObject(aBushMedium, 1, 2, 0, 2), new SimpleObject(aBushSmall, 2, 4, 0, 2)]
],
[
scaleByMapSize(16, 262),
scaleByMapSize(8, 131),
scaleByMapSize(13, 200),
scaleByMapSize(13, 200),
scaleByMapSize(13, 200)
scaleByMapAreaAbsolute(16),
scaleByMapAreaAbsolute(8),
scaleByMapAreaAbsolute(13),
scaleByMapAreaAbsolute(13),
scaleByMapAreaAbsolute(13)
],
[avoidClasses(clPlayer, 1, clDirt, 1, clRiver, 1), stayClasses(clLand, 6)]);
@ -219,8 +219,8 @@ createDecoration(
[new SimpleObject(aLillies, 1, 2, 0, 1)]
],
[
scaleByMapSize(800, 12800),
scaleByMapSize(800, 12800)
scaleByMapAreaAbsolute(800),
scaleByMapAreaAbsolute(800)
],
stayClasses(clShallow, 0));

View File

@ -203,8 +203,8 @@ createDecoration(
[new SimpleObject(aBushMedium, 1, 2, 0, 2), new SimpleObject(aBushSmall, 2, 4, 0, 2)]
],
[
scaleByMapSize(16, 262),
scaleByMapSize(8, 131),
scaleByMapAreaAbsolute(16),
scaleByMapAreaAbsolute(8),
scaleByMapSize(bushCount.min, bushCount.max),
scaleByMapSize(bushCount.min, bushCount.max),
scaleByMapSize(bushCount.min, bushCount.max)

View File

@ -445,10 +445,10 @@ for (let biome of ["lowlands", "highlands"])
]
],
[
scaleByMapSize(20, 300),
scaleByMapSize(13, 200),
scaleByMapSize(13, 200),
scaleByMapSize(13, 200)
scaleByMapAreaAbsolute(20),
scaleByMapAreaAbsolute(13),
scaleByMapAreaAbsolute(13),
scaleByMapAreaAbsolute(13)
],
[
biome == "highlands" ? constraintHighlands : constraintLowlands,
@ -460,7 +460,7 @@ for (let biome of ["lowlands", "highlands"])
biomes[biome].actors.stones.map(template => new SimpleObject(actorTemplate(template), 1, 3, 0, 1))
],
[
biomes[biome].actors.stones.map(template => scaleByMapSize(2, 40) * randIntInclusive(1, 3))
biomes[biome].actors.stones.map(template => scaleByMapAreaAbsolute(2) * randIntInclusive(1, 3))
],
[
biome == "highlands" ? constraintHighlands : constraintLowlands,

View File

@ -194,11 +194,11 @@ createDecoration(
[new SimpleObject(aBushMedium, 1, 2, 0, 2), new SimpleObject(aBushSmall, 2, 4, 0, 2)]
],
[
scaleByMapSize(16, 262),
scaleByMapSize(8, 131),
planetm * scaleByMapSize(13, 200),
planetm * scaleByMapSize(13, 200),
planetm * scaleByMapSize(13, 200)
scaleByMapAreaAbsolute(16),
scaleByMapAreaAbsolute(8),
planetm * scaleByMapAreaAbsolute(13),
planetm * scaleByMapAreaAbsolute(13),
planetm * scaleByMapAreaAbsolute(13)
],
avoidClasses(clWater, 0, clForest, 0, clPlayer, 0, clHill, 0));

View File

@ -149,11 +149,11 @@ createDecoration(
[new SimpleObject(aBushMedium, 1, 2, 0, 2), new SimpleObject(aBushSmall, 2, 4, 0, 2)]
],
[
scaleByMapSize(16, 262),
scaleByMapSize(8, 131),
planetm * scaleByMapSize(13, 200),
planetm * scaleByMapSize(13, 200),
planetm * scaleByMapSize(13, 200)
scaleByMapAreaAbsolute(16),
scaleByMapAreaAbsolute(8),
planetm * scaleByMapAreaAbsolute(13),
planetm * scaleByMapAreaAbsolute(13),
planetm * scaleByMapAreaAbsolute(13)
],
avoidClasses(clForest, 0, clPlayer, 0, clHill, 0));

View File

@ -178,8 +178,8 @@ createDecoration(
]
],
[
scaleByMapSize(16, 262),
scaleByMapSize(8, 131),
scaleByMapAreaAbsolute(16),
scaleByMapAreaAbsolute(8),
],
avoidClasses(clWater, 0, clPlayer, 0));
@ -188,7 +188,7 @@ createDecoration(
[new SimpleObject(aIceberg, 1, 1, 1, 1)]
],
[
scaleByMapSize(8, 131)
scaleByMapAreaAbsolute(8)
],
[stayClasses(clWater, 4), avoidClasses(clHill, 2)]);
Engine.SetProgress(80);

View File

@ -320,8 +320,8 @@ createDecoration(
[new SimpleObject(g_Decoratives.lillies, 1, 2, 0, 1)]
],
[
200 * Math.pow(scaleByMapSize(3, 12), 2),
100 * Math.pow(scaleByMapSize(3, 12), 2)
scaleByMapAreaAbsolute(1800),
scaleByMapAreaAbsolute(900)
],
new HeightConstraint(heightReedsMin, heightShoreline)
);

View File

@ -220,11 +220,11 @@ createDecoration(
[new SimpleObject(aBushMedium, 1, 2, 0, 2), new SimpleObject(aBushSmall, 2, 4, 0, 2)]
],
[
scaleByMapSize(16, 262),
scaleByMapSize(8, 131),
planetm * scaleByMapSize(13, 200),
planetm * scaleByMapSize(13, 200),
planetm * scaleByMapSize(13, 200)
scaleByMapAreaAbsolute(16),
scaleByMapAreaAbsolute(8),
planetm * scaleByMapAreaAbsolute(13),
planetm * scaleByMapAreaAbsolute(13),
planetm * scaleByMapAreaAbsolute(13)
],
avoidClasses(clWater, 0, clForest, 0, clPlayer, 0, clHill, 0));
@ -234,8 +234,8 @@ createDecoration(
[new SimpleObject(aLillies, 1, 2, 0, 1)]
],
[
scaleByMapSize(800, 12800),
scaleByMapSize(800, 12800)
scaleByMapAreaAbsolute(800),
scaleByMapAreaAbsolute(800)
],
stayClasses(clShallow, 0));

View File

@ -138,6 +138,11 @@ RandomMap.prototype.getSize = function()
return this.size;
};
RandomMap.prototype.getArea = function(size = this.size)
{
return this.isCircularMap ? diskArea(size / 2) : size * size;
};
/**
* Returns the center tile coordinates of the map.
*/

View File

@ -80,6 +80,26 @@ function scaleByMapSize(min, max, minMapSize = 128, maxMapSize = 512)
return min + (max - min) * (g_MapSettings.Size - minMapSize) / (maxMapSize - minMapSize);
}
/**
* Interpolate quadratic between (min, minMapArea) and (max, maxMapArea) with respect to the mapSize.
* Default values set on the area of tiny and giant map sizes according to the map shape (square or circular).
*/
function scaleByMapArea(min, max, minMapArea = g_Map.getArea(128), maxMapArea = g_Map.getArea(256))
{
return min + (max - min) * (g_Map.getArea() - minMapArea) / (maxMapArea - minMapArea);
}
/**
* Interpolate quadraticly between (0,0) and (base, baseArea) with respect to the map size.
* @param base - Value we should attain at baseArea.
* @param disallowedArea - Area deducted from the map area.
* @param baseArea - Area at which the base value should be attained. Defaults to the map area of a tiny map of current shape (square or circular).
*/
function scaleByMapAreaAbsolute(base, disallowedArea = 0, baseArea = g_Map.getArea(128))
{
return scaleByMapArea(0, base, disallowedArea, baseArea + disallowedArea);
}
function randomPositionOnTile(tilePosition)
{
return Vector2D.add(tilePosition, new Vector2D(randFloat(0, 1), randFloat(0, 1)));

View File

@ -244,11 +244,11 @@ createDecoration(
[new SimpleObject(aBushMedium, 1, 2, 0, 2), new SimpleObject(aBushSmall, 2, 4, 0, 2)]
],
[
scaleByMapSize(16, 262),
scaleByMapSize(8, 131),
scaleByMapSize(13, 200),
scaleByMapSize(13, 200),
scaleByMapSize(13, 200)
scaleByMapAreaAbsolute(16),
scaleByMapAreaAbsolute(8),
scaleByMapAreaAbsolute(13),
scaleByMapAreaAbsolute(13),
scaleByMapAreaAbsolute(13)
],
avoidClasses(clForest, 1, clPlayer, 0, clPath, 3, clWater, 3));

View File

@ -233,7 +233,7 @@ createDecoration(
]
],
[
scaleByMapSize(16, 262),
scaleByMapAreaAbsolute(16),
scaleByMapSize(40, 360)
],
avoidClasses(clWater, 2, clForest, 0, clPlayer, 20, clHill, 1));

View File

@ -186,11 +186,11 @@ createDecoration(
[new SimpleObject(aBushMedium, 1, 2, 0, 2), new SimpleObject(aBushSmall, 2, 4, 0, 2)]
],
[
scaleByMapSize(16, 262),
scaleByMapSize(8, 131),
planetm * scaleByMapSize(13, 200),
planetm * scaleByMapSize(13, 200),
planetm * scaleByMapSize(13, 200)
scaleByMapAreaAbsolute(16),
scaleByMapAreaAbsolute(8),
planetm * scaleByMapAreaAbsolute(13),
planetm * scaleByMapAreaAbsolute(13),
planetm * scaleByMapAreaAbsolute(13)
],
[avoidClasses(clForest, 0, clPlayer, 0, clHill, 0), landConstraint]);
Engine.SetProgress(90);