mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 14:43:52 +00:00
Delete createRamp which is the same as createPassage, refs #4805, f3823847b0, 9016b8d866, a796800bb1.
Use vector algebra to compute the ramp position, refs #4845. This was SVN commit r20761.
This commit is contained in:
@@ -57,43 +57,34 @@ var clMetal = createTileClass();
|
||||
var clFood = createTileClass();
|
||||
var clBaseResource = createTileClass();
|
||||
|
||||
var playerHillRadius = scaleByMapSize(15, 25);
|
||||
var playerHillElevation = 20;
|
||||
|
||||
var rampDist = scaleByMapSize(15, 25);
|
||||
var rampLength = 15;
|
||||
var rampWidth = 12;
|
||||
var rampOffset = 3;
|
||||
|
||||
var [playerIDs, playerX, playerZ, playerAngle] = radialPlayerPlacement();
|
||||
|
||||
log("Creating player hills and ramps...");
|
||||
for (let i = 0; i < numPlayers; ++i)
|
||||
{
|
||||
let fx = fractionToTiles(playerX[i]);
|
||||
let fz = fractionToTiles(playerZ[i]);
|
||||
|
||||
let playerPos = new Vector2D(playerX[i], playerZ[i]).mult(mapSize);
|
||||
createArea(
|
||||
new ClumpPlacer(diskArea(scaleByMapSize(15, 25)), 0.95, 0.6, 10, Math.round(fx), Math.round(fz)),
|
||||
new ClumpPlacer(diskArea(scaleByMapSize(15, 25)), 0.95, 0.6, 10, Math.round(playerPos.x), Math.round(playerPos.y)),
|
||||
[
|
||||
new LayeredPainter([tCliff, tHill], [2]),
|
||||
new SmoothElevationPainter(ELEVATION_SET, playerHillElevation, 2),
|
||||
paintClass(clPlayer)
|
||||
],
|
||||
null);
|
||||
]);
|
||||
|
||||
let rampAngle = playerAngle[i] + Math.PI * (1 + randFloat(-1, 1) / 8);
|
||||
createRamp(
|
||||
Math.round(fx + (rampDist + rampLength) * Math.cos(rampAngle)),
|
||||
Math.round(fz + (rampDist + rampLength) * Math.sin(rampAngle)),
|
||||
Math.round(fx + (rampDist - rampOffset) * Math.cos(rampAngle)),
|
||||
Math.round(fz + (rampDist - rampOffset) * Math.sin(rampAngle)),
|
||||
3,
|
||||
playerHillElevation,
|
||||
rampWidth,
|
||||
2,
|
||||
tHill,
|
||||
tCliff,
|
||||
clPlayer);
|
||||
let angle = playerAngle[i] + Math.PI * (1 + randFloat(-1, 1) / 8);
|
||||
createPassage({
|
||||
"start": Vector2D.add(playerPos, new Vector2D(playerHillRadius + 15, 0).rotate(-angle)),
|
||||
"end": Vector2D.add(playerPos, new Vector2D(playerHillRadius - 3, 0).rotate(-angle)),
|
||||
"startWidth": 10,
|
||||
"endWidth": 10,
|
||||
"smoothWidth": 2,
|
||||
"tileClass": clPlayer,
|
||||
"terrain": tHill,
|
||||
"edgeTerrain": tCliff
|
||||
});
|
||||
}
|
||||
|
||||
for (var i = 0; i < numPlayers; i++)
|
||||
@@ -101,7 +92,7 @@ for (var i = 0; i < numPlayers; i++)
|
||||
var id = playerIDs[i];
|
||||
log("Creating base for player " + id + "...");
|
||||
|
||||
var radius = scaleByMapSize(15,25);
|
||||
var radius = playerHillRadius;
|
||||
|
||||
// get the x and z in tiles
|
||||
var fx = fractionToTiles(playerX[i]);
|
||||
|
||||
@@ -598,6 +598,7 @@ function createShallowsPassage(x1, z1, x2, z2, width, maxHeight, shallowHeight,
|
||||
* @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.
|
||||
* @property {string} [edgeTerrain] - Texture to be painted on the borders of the passage.
|
||||
*/
|
||||
function createPassage(args)
|
||||
{
|
||||
@@ -632,63 +633,17 @@ function createPassage(args)
|
||||
(getHeight(location.x, location.y) * smoothDistance + passageHeight / smoothDistance) / (smoothDistance + 1 / smoothDistance) :
|
||||
passageHeight);
|
||||
|
||||
if (args.tileClass)
|
||||
if (args.tileClass !== undefined)
|
||||
addToClass(location.x, location.y, args.tileClass);
|
||||
|
||||
if (args.terrain)
|
||||
if (args.edgeTerrain && smoothDistance > 0)
|
||||
placeTerrain(location.x, location.y, args.edgeTerrain);
|
||||
else if (args.terrain)
|
||||
placeTerrain(location.x, location.y, args.terrain);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ramp from (x1, y1) to (x2, y2).
|
||||
*/
|
||||
function createRamp(x1, y1, x2, y2, minHeight, maxHeight, width, smoothLevel, mainTerrain, edgeTerrain, tileClass)
|
||||
{
|
||||
let halfWidth = width / 2;
|
||||
|
||||
let rampStart = new Vector2D(x1, y1);
|
||||
let rampEnd = new Vector2D(x2, y2);
|
||||
let ramp = Vector2D.sub(rampStart, rampEnd);
|
||||
let rampLength = ramp.length();
|
||||
let rampX = Vector2D.add(rampEnd, ramp.perpendicular());
|
||||
|
||||
let minBoundX = Math.max(Math.min(x1, x2) - halfWidth, 0);
|
||||
let minBoundY = Math.max(Math.min(y1, y2) - halfWidth, 0);
|
||||
let maxBoundX = Math.min(Math.max(x1, x2) + halfWidth, getMapSize());
|
||||
let maxBoundY = Math.min(Math.max(y1, y2) + halfWidth, getMapSize());
|
||||
|
||||
for (let x = minBoundX; x < maxBoundX; ++x)
|
||||
for (let y = minBoundY; y < maxBoundY; ++y)
|
||||
{
|
||||
let point = new Vector2D(x, y);
|
||||
let lDist = Math.abs(distanceOfPointFromLine(rampX, rampEnd, point));
|
||||
let sDist = Math.abs(distanceOfPointFromLine(rampStart, rampEnd, point));
|
||||
|
||||
if (lDist > rampLength || sDist > halfWidth)
|
||||
continue;
|
||||
|
||||
let height = maxHeight - lDist / rampLength * (maxHeight - minHeight);
|
||||
|
||||
if (sDist >= halfWidth - smoothLevel)
|
||||
{
|
||||
height = (height - minHeight) * (halfWidth - sDist) / smoothLevel + minHeight;
|
||||
|
||||
if (edgeTerrain)
|
||||
placeTerrain(x, y, edgeTerrain);
|
||||
}
|
||||
else if (mainTerrain)
|
||||
placeTerrain(x, y, mainTerrain);
|
||||
|
||||
if (tileClass !== undefined)
|
||||
addToClass(x, y, tileClass);
|
||||
|
||||
if (getHeight(Math.floor(x), Math.floor(y)) < height && height <= maxHeight)
|
||||
setHeight(x, y, height);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get The Intended Point In A Direction Based On Height.
|
||||
* Retrieves the N'th point with a specific height in a line and returns it as a [x, y] array.
|
||||
|
||||
Reference in New Issue
Block a user