Delete createShallowsPassage / passageMaker from bc805bd357 and use the unified createPassage function from 0c70fb3036 (9016b8d866, a796800bb1) to achieve the same shallows generation, refs #4805.

Place shallows at every tributary river rather than leaving out the last
35 percent of the mapsize.
Use vector algebra to do the horizontal/vertical rotation, refs #4845.

This was SVN commit r20780.
This commit is contained in:
elexis 2018-01-06 22:59:56 +00:00
parent d9d76d450b
commit ae2e045df5
4 changed files with 68 additions and 98 deletions

View file

@ -38,6 +38,7 @@ const pForestR = [tGrassDForest + TERRAIN_SEPARATOR + oBeech, tGrassDForest, tGr
InitMap();
const numPlayers = getNumPlayers();
const mapSize = getMapSize();
var clPlayer = createTileClass();
var clHill = createTileClass();
@ -51,6 +52,8 @@ var clBaseResource = createTileClass();
var clShallow = createTileClass();
var waterHeight = -4;
var shallowHeight = -2;
var shallowWidth = scaleByMapSize(8, 12);
var [playerIDs, playerX, playerZ] = playerPlacementRiver(Math.PI / 2, 0.5);
@ -133,6 +136,7 @@ for (var i = 0; i < numPlayers; i++)
);
createObjectGroup(group, 0, avoidClasses(clBaseResource,2));
}
Engine.SetProgress(20);
log("Creating the main river...");
var river1 = [1, fractionToTiles(0.5)];
@ -141,6 +145,7 @@ createArea(
new PathPlacer(...river1, ...river2, scaleByMapSize(10, 20), 0.5, 3 * scaleByMapSize(1, 4), 0.1, 0.01),
new SmoothElevationPainter(ELEVATION_SET, waterHeight, 4),
avoidClasses(clPlayer, 4));
Engine.SetProgress(25);
log("Creating small puddles at the map border to ensure players being separated...");
for (let [fx, fz] of [river1, river2])
@ -148,24 +153,25 @@ for (let [fx, fz] of [river1, river2])
new ClumpPlacer(Math.floor(diskArea(scaleByMapSize(5, 10))), 0.95, 0.6, 10, fx, fz),
new SmoothElevationPainter(ELEVATION_SET, waterHeight, 2),
avoidClasses(clPlayer, 8));
Engine.SetProgress(30);
log("Creating the shallows of the main river...");
for (let i = 0; i <= randIntInclusive(3, scaleByMapSize(4, 6)); ++i)
{
let cLocation = Math.floor(fractionToTiles(randFloat(0.15, 0.85)));
createShallowsPassage(
cLocation,
Math.floor(fractionToTiles(0.35)),
cLocation,
Math.floor(fractionToTiles(0.65)),
scaleByMapSize(4, 8),
-2,
-2,
2,
clShallow,
undefined,
waterHeight);
let location = randFloat(0.15, 0.85);
createPassage({
"start": new Vector2D(location, 0).mult(mapSize),
"end": new Vector2D(location, 1).mult(mapSize),
"startWidth": shallowWidth,
"endWidth": shallowWidth,
"smoothWidth": 2,
"startHeight": shallowHeight,
"endHeight": shallowHeight,
"maxHeight": shallowHeight,
"tileClass": clShallow
});
}
Engine.SetProgress(35);
createTributaryRivers(
true,
@ -178,6 +184,8 @@ createTributaryRivers(
clShallow,
avoidClasses(clPlayer, 3, clBaseResource, 4));
Engine.SetProgress(40);
paintTerrainBasedOnHeight(-5, 1, 1, tWater);
paintTerrainBasedOnHeight(1, 2, 1, pForestR);
paintTileClassBasedOnHeight(-6, 0.5, 1, clWater);

View file

@ -466,6 +466,7 @@ function createTributaryRivers(horizontal, riverCount, riverWidth, waterHeight,
let smoothness = scaleByMapSize(3, 12);
let offset = 0.1;
let tapering = 0.05;
let shallowHeight = -2;
let riverAngle = horizontal ? 0 : Math.PI / 2;
let mapSize = getMapSize();
@ -521,65 +522,17 @@ function createTributaryRivers(horizontal, riverCount, riverWidth, waterHeight,
// Create shallows
if (shallowTileClass)
for (let z of [0.25, 0.75])
{
let m1 = [Math.round(fractionToTiles(0.2)), Math.round(fractionToTiles(z))];
let m2 = [Math.round(fractionToTiles(0.8)), Math.round(fractionToTiles(z))];
if (!horizontal)
{
m1.reverse();
m2.reverse();
}
createShallowsPassage(...m1, ...m2, scaleByMapSize(4, 8), -2, -2, 2, shallowTileClass, undefined, waterHeight);
}
}
/**
* Create shallow water between (x1, z1) and (x2, z2) of tiles below maxHeight.
*/
function createShallowsPassage(x1, z1, x2, z2, width, maxHeight, shallowHeight, smooth, tileClass, terrain, riverHeight)
{
let a = z1 - z2;
let b = x2 - x1;
let distance = Math.euclidDistance2D(x1, z1, x2, z2);
let mapSize = getMapSize();
for (let ix = 0; ix < mapSize; ++ix)
for (let iz = 0; iz < mapSize; ++iz)
{
let c = a * (ix - x1) + b * (iz - z1);
let my = iz - b * c / Math.square(distance);
let inline = 0;
let dis;
if (b == 0)
{
dis = Math.abs(ix - x1);
if (iz >= Math.min(z1, z2) && iz <= Math.max(z1, z2))
inline = 1;
}
else if (my >= Math.min(z1, z2) && my <= Math.max(z1, z2))
{
dis = Math.abs(c) / distance;
inline = 1;
}
if (dis > width || !inline || getHeight(ix, iz) > maxHeight)
continue;
if (dis > width - smooth)
setHeight(ix, iz, ((width - dis) * shallowHeight + riverHeight * (smooth - width + dis)) / smooth);
else if (dis <= width - smooth)
setHeight(ix, iz, shallowHeight);
if (tileClass !== undefined)
addToClass(ix, iz, tileClass);
if (terrain !== undefined)
placeTerrain(ix, iz, terrain);
}
createPassage({
"start": new Vector2D(0, z).mult(mapSize).rotateAround(riverAngle, mapCenter),
"end": new Vector2D(1, z).mult(mapSize).rotateAround(riverAngle, mapCenter),
"startWidth": scaleByMapSize(8, 12),
"endWidth": scaleByMapSize(8, 12),
"smoothWidth": 2,
"startHeight": shallowHeight,
"endHeight": shallowHeight,
"maxHeight": shallowHeight,
"tileClass": shallowTileClass
});
}
/**
@ -592,6 +545,7 @@ function createShallowsPassage(x1, z1, x2, z2, width, maxHeight, shallowHeight,
* @property {number} endWidth
* @property {number} [startHeight] - Fixed height to be used if the height at the location shouldn't be used.
* @property {number} [endHeight]
* @property {number} [maxHeight] - If given, do not touch any terrain above this height.
* @property {number} smoothWidth - Number of tiles at the passage border to apply height interpolation.
* @property {number} [tileClass] - Marks the passage with this tile class.
* @property {string} [terrain] - Texture to be painted on the passage area.
@ -618,7 +572,8 @@ function createPassage(args)
{
let location = Vector2D.add(locationLength, Vector2D.mult(widthDirection, stepWidth)).round();
if (!g_Map.inMapBounds(location.x, location.y))
if (!g_Map.inMapBounds(location.x, location.y) ||
args.maxHeight !== undefined && getHeight(location.x, location.y) > args.maxHeight)
continue;
let smoothDistance = args.smoothWidth + Math.abs(stepWidth) - halfPassageWidth;

View file

@ -38,6 +38,7 @@ const pForest = [tForestFloor + TERRAIN_SEPARATOR + oBaobab, tForestFloor + TERR
InitMap();
const numPlayers = getNumPlayers();
const mapSize = getMapSize();
const mapCenter = getMapCenter();
var clPlayer = createTileClass();
@ -53,6 +54,9 @@ var clShallows = createTileClass();
var [playerIDs, playerX, playerZ, playerAngle, startAngle] = radialPlayerPlacement();
var waterHeight = -4;
var shallowHeight = -2;
for (var i = 0; i < numPlayers; i++)
{
var id = playerIDs[i];
@ -143,7 +147,7 @@ for (let i = 0; i < numPlayers; ++i)
createArea(
new ClumpPlacer(Math.floor(diskArea(scaleByMapSize(10, 50)) / 3), 0.95, 0.6, 10, riverStart[0][i], riverStart[1][i]),
[
new SmoothElevationPainter(ELEVATION_SET, -4, 4),
new SmoothElevationPainter(ELEVATION_SET, waterHeight, 4),
paintClass(clWater)
],
avoidClasses(clPlayer, 5));
@ -153,7 +157,7 @@ for (let i = 0; i < numPlayers; ++i)
new PathPlacer(riverStart[0][i], riverStart[1][i], riverEnd[0][i], riverEnd[1][i], scaleByMapSize(10, 50), 0.2, 3 * scaleByMapSize(1, 4), 0.2, 0.05),
[
new LayeredPainter([tShore, tWater, tWater], [1, 3]),
new SmoothElevationPainter(ELEVATION_SET, -4, 4),
new SmoothElevationPainter(ELEVATION_SET, waterHeight, 4),
paintClass(clWater)
],
avoidClasses(clPlayer, 5));
@ -162,24 +166,23 @@ for (let i = 0; i < numPlayers; ++i)
createArea(
new ClumpPlacer(Math.floor(diskArea(scaleByMapSize(10, 50)) / 5), 0.95, 0.6, 10, riverEnd[0][i], riverEnd[1][i]),
[
new SmoothElevationPainter(ELEVATION_SET, -4, 4),
new SmoothElevationPainter(ELEVATION_SET, waterHeight, 4),
paintClass(clWater)
],
avoidClasses(clPlayer, 5));
log("Creating shallows between neighbors...");
createShallowsPassage(
Math.round(fractionToTiles(playerX[i])),
Math.round(fractionToTiles(playerZ[i])),
Math.round(fractionToTiles(playerX[neighborID])),
Math.round(fractionToTiles(playerZ[neighborID])),
6,
-2,
-2,
4,
clShallows,
undefined,
-4);
createPassage({
"start": new Vector2D(playerX[i], playerZ[i]).mult(mapSize).round(),
"end": new Vector2D(playerX[neighborID], playerZ[neighborID]).mult(mapSize).round(),
"startWidth": 10,
"endWidth": 10,
"smoothWidth": 4,
"startHeight": shallowHeight,
"endHeight": shallowHeight,
"maxHeight": shallowHeight,
"tileClass": clShallows
});
log("Creating animals in shallows...");
let objects = [

View file

@ -354,10 +354,11 @@ function unknownCentralSea()
function unknownCentralRiver()
{
let waterHeight = -4;
let shallowHeight = -2;
initHeight(landHeight);
let horizontal = randBool();
let riverAngle = horizontal ? 0 : Math.PI / 2;
if (g_PlayerBases)
{
@ -384,15 +385,18 @@ function unknownCentralRiver()
log("Creating the shallows of the main river...");
for (let i = 0; i <= randIntInclusive(1, scaleByMapSize(4, 8)); ++i)
{
let cLocation = randFloat(0.15, 0.85);
let x1 = [fractionToTiles(cLocation), fractionToTiles(0.35)];
let x2 = [fractionToTiles(cLocation), fractionToTiles(0.65)];
if (!horizontal)
{
x1.reverse();
x2.reverse();
}
createShallowsPassage(...x1, ...x2, scaleByMapSize(4, 8), -2, -2, 2, clShallow, undefined, waterHeight);
let location = randFloat(0.15, 0.85);
createPassage({
"start": new Vector2D(location, 0).mult(mapSize).rotateAround(riverAngle, mapCenter),
"end": new Vector2D(location, 1).mult(mapSize).rotateAround(riverAngle, mapCenter),
"startWidth": scaleByMapSize(8, 12),
"endWidth": scaleByMapSize(8, 12),
"smoothWidth": 2,
"startHeight": shallowHeight,
"endHeight": shallowHeight,
"maxHeight": shallowHeight,
"tileClass": clShallow
});
}
}