mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 13:04:10 +00:00
Stop identifying TileClasses by a customly defined TileClassID, but just identify the prototype instance directly, refs #4804, 0e0ed94926.
Delete hence unneeded validClass, getTileClass, addToClass and removeFromClass. Use vectors for the TileClass add and remove function, refs #4992. Use createArea call for addCivicCenterAreaToClass. This was SVN commit r21025.
This commit is contained in:
@@ -87,7 +87,7 @@ for (var ix = 0; ix < mapSize; ix++)
|
||||
let h = g_Map.getHeight(position);
|
||||
if (h > heightRavineHill)
|
||||
{
|
||||
addToClass(ix,iz,clHill);
|
||||
clHill.add(position);
|
||||
|
||||
// Add hill noise
|
||||
var x = ix / (mapSize + 1.0);
|
||||
@@ -253,8 +253,6 @@ for (let size of [scaleByMapSize(50, 800), scaleByMapSize(50, 400), scaleByMapSi
|
||||
Engine.SetProgress(50);
|
||||
|
||||
var explorablePoints = [];
|
||||
var playerClass = getTileClass(clPlayer);
|
||||
var hillDecoClass = getTileClass(clHillDeco);
|
||||
|
||||
for (var ix = 0; ix < mapSize; ix++)
|
||||
for (var iz = 0; iz < mapSize; iz++)
|
||||
@@ -262,11 +260,11 @@ for (var ix = 0; ix < mapSize; ix++)
|
||||
let position = new Vector2D(ix, iz);
|
||||
let h = g_Map.getHeight(position);
|
||||
|
||||
if(h > 15 && h < 45 && playerClass.countMembersInRadius(ix, iz, 1) == 0)
|
||||
if (h > 15 && h < 45 && clPlayer.countMembersInRadius(ix, iz, 1) == 0)
|
||||
explorablePoints.push(position);
|
||||
|
||||
if (h > 35 && randBool(0.1) ||
|
||||
h < 15 && randBool(0.05) && hillDecoClass.countMembersInRadius(ix, iz, 1) == 0)
|
||||
h < 15 && randBool(0.05) && clHillDeco.countMembersInRadius(ix, iz, 1) == 0)
|
||||
placeObject(Vector2D.add(position, new Vector2D(1, 1).mult(randFloat(0, 1))), pickRandom(aTrees), 0, randomAngle());
|
||||
}
|
||||
|
||||
|
||||
@@ -276,16 +276,16 @@ for (let mapX = 0; mapX < mapSize; ++mapX)
|
||||
createTerrain(terrain).place(position);
|
||||
|
||||
if (terrain == tCliffs || terrain == tSteepCliffs)
|
||||
addToClass(mapX, mapZ, clCliffs);
|
||||
clCliffs.add(position);
|
||||
}
|
||||
|
||||
function getCosricaSardiniaTerrain(mapX, mapZ)
|
||||
{
|
||||
let position = new Vector2D(mapX, mapZ);
|
||||
let isWater = getTileClass(clWater).countMembersInRadius(mapX, mapZ, 3);
|
||||
let isShore = getTileClass(clShore).countMembersInRadius(mapX, mapZ, 2);
|
||||
let isPassage = getTileClass(clPassage).countMembersInRadius(mapX, mapZ, 2);
|
||||
let isSettlement = getTileClass(clSettlement).countMembersInRadius(mapX, mapZ, 2);
|
||||
let isWater = clWater.countMembersInRadius(mapX, mapZ, 3);
|
||||
let isShore = clShore.countMembersInRadius(mapX, mapZ, 2);
|
||||
let isPassage = clPassage.countMembersInRadius(mapX, mapZ, 2);
|
||||
let isSettlement = clSettlement.countMembersInRadius(mapX, mapZ, 2);
|
||||
|
||||
if (isSettlement)
|
||||
return undefined;
|
||||
|
||||
@@ -381,15 +381,15 @@ paintRiver({
|
||||
// Distinguish left and right shoreline
|
||||
if (0 < height && height < 1 &&
|
||||
position.y > ShorelineDistance && position.y < mapSize - ShorelineDistance)
|
||||
addToClass(position.x, position.y, clShore[position.x < mapCenter.x ? 0 : 1]);
|
||||
clShore[position.x < mapCenter.x ? 0 : 1].add(position);
|
||||
},
|
||||
"landFunc": (position, shoreDist1, shoreDist2) => {
|
||||
|
||||
if (shoreDist1 > 0)
|
||||
addToClass(position.x, position.y, clLand[0]);
|
||||
clLand[0].add(position);
|
||||
|
||||
if (shoreDist2 < 0)
|
||||
addToClass(position.x, position.y, clLand[1]);
|
||||
clLand[1].add(position);
|
||||
}
|
||||
});
|
||||
Engine.SetProgress(30);
|
||||
@@ -712,7 +712,7 @@ for (let i = 0; i < 2; ++i)
|
||||
1);
|
||||
|
||||
log("Creating patrol points for land attackers...");
|
||||
addToClass(mapCenter.x, mapCenter.y, clMiddle);
|
||||
clMiddle.add(mapCenter);
|
||||
|
||||
log("Creating triggerpoint to allow the triggerscript to determine the river direction...");
|
||||
placeObject(Vector2D.add(mapCenter, new Vector2D(0, 1).rotate(startAngle)), triggerPointRiverDirection, 0, 0);
|
||||
|
||||
@@ -148,7 +148,7 @@ Engine.SetProgress(60);
|
||||
|
||||
log("Placing temple...");
|
||||
placeObject(mapCenter, templateTemple, 0, randomAngle());
|
||||
addToClass(mapCenter.x, mapCenter.y, clBaseResource);
|
||||
clBaseResource.add(mapCenter);
|
||||
|
||||
log("Creating central mountain...");
|
||||
createArea(
|
||||
|
||||
@@ -111,7 +111,7 @@ for (let i = 0; i < numPlayers; ++i)
|
||||
ty - tx - minBoundY + minBoundX < tilesSize)
|
||||
{
|
||||
createTerrain(tRoad).place(position);
|
||||
addToClass(tx, ty, clPlayer);
|
||||
clPlayer.add(position);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ paintRiver({
|
||||
"meanderShort": 12,
|
||||
"meanderLong": 0,
|
||||
"waterFunc": (position, height, z) => {
|
||||
addToClass(position.x, position.y, clRiver);
|
||||
clRiver.add(position);
|
||||
createTerrain(tWater).place(position);
|
||||
|
||||
if (height < heightShallow && (
|
||||
@@ -134,7 +134,7 @@ paintRiver({
|
||||
z > 0.7 && z < 0.8))
|
||||
{
|
||||
g_Map.setHeight(position, heightShallow);
|
||||
addToClass(position.x, position.y, clShallow);
|
||||
clShallow.add(position);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -110,12 +110,12 @@ paintRiver({
|
||||
"landFunc": (position, shoreDist1, shoreDist2) => {
|
||||
|
||||
if (waterPosition + shoreDist1 > highlandsPosition)
|
||||
addToClass(position.x, position.y, clHighlands);
|
||||
clHighlands.add(position);
|
||||
},
|
||||
"waterFunc": (position, height, riverFraction) => {
|
||||
|
||||
if (height < heightShore2)
|
||||
addToClass(position.x, position.y, clWater);
|
||||
clWater.add(position);
|
||||
|
||||
createTerrain(height < heightShore1 ? tWater : tShore).place(position);
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ for (let i = 0; i < scaleByMapSize(12, 30); ++i)
|
||||
if (avoidClasses(clPlayer, 30, clRock, 25, clWater, 10).allows(position))
|
||||
{
|
||||
createStoneMineFormation(position, oStoneSmall, tDirt4);
|
||||
addToClass(position.x, position.y, clRock);
|
||||
clRock.add(position);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -106,10 +106,10 @@ paintRiver({
|
||||
"meanderLong": 0,
|
||||
"landFunc": (position, shoreDist1, shoreDist2) => {
|
||||
if (waterPosition + shoreDist1 > mountainPosition)
|
||||
addToClass(position.x, position.y, clMountains);
|
||||
clMountains.add(position);
|
||||
},
|
||||
"waterFunc": (position, height, riverFraction) => {
|
||||
addToClass(position.x, position.y, clWater);
|
||||
clWater.add(position);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ for (let x of [mapBounds.left, mapBounds.right])
|
||||
"meanderShort": 0,
|
||||
"meanderLong": 0,
|
||||
"waterFunc": (position, height, z) => {
|
||||
addToClass(position.x, position.y, clWater);
|
||||
clWater.add(position);
|
||||
}
|
||||
});
|
||||
Engine.SetProgress(10);
|
||||
@@ -241,13 +241,13 @@ for (var ix = 0; ix < mapSize; ix++)
|
||||
t = tBeachGrass;
|
||||
|
||||
if (minH < 0)
|
||||
addToClass(ix, iz, clWater);
|
||||
clWater.add(position);
|
||||
|
||||
// cliffs
|
||||
if (diffH > 2.9 && minH > -7)
|
||||
{
|
||||
t = tCliff;
|
||||
addToClass(ix, iz, clCliff);
|
||||
clCliff.add(position);
|
||||
}
|
||||
else if (diffH > 2.5 && minH > -5 || maxH - minAdjHeight > 2.9 && minH > 0)
|
||||
{
|
||||
@@ -258,12 +258,12 @@ for (var ix = 0; ix < mapSize; ix++)
|
||||
else
|
||||
t = [tDirtCliff, tGrassCliff, tGrassCliff, tGrassRock, tCliff];
|
||||
|
||||
addToClass(ix, iz, clCliff);
|
||||
clCliff.add(position);
|
||||
}
|
||||
|
||||
// Don't place resources onto potentially impassable mountains
|
||||
if (minH >= 20)
|
||||
addToClass(ix, iz, clCliff);
|
||||
clCliff.add(position);
|
||||
|
||||
// forests
|
||||
if (g_Map.getHeight(position) < 11 && diffH < 2 && minH > 1)
|
||||
@@ -284,12 +284,12 @@ for (var ix = 0; ix < mapSize; ix++)
|
||||
else
|
||||
t = pPineForest;
|
||||
|
||||
addToClass(ix, iz, clForest);
|
||||
clForest.add(position);
|
||||
}
|
||||
else if (minH < 4)
|
||||
{
|
||||
t = pPalmForest;
|
||||
addToClass(ix, iz, clForest);
|
||||
clForest.add(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@ for (var sandx = 0; sandx < mapSize; sandx += 4)
|
||||
createObjectGroup(group, 0);
|
||||
}
|
||||
|
||||
if (getTileClass(clPassage).countMembersInRadius(sandx, sandz, 2) > 0)
|
||||
if (clPassage.countMembersInRadius(sandx, sandz, 2))
|
||||
{
|
||||
if (randBool(0.4))
|
||||
{
|
||||
|
||||
@@ -244,7 +244,7 @@ for (let ix = 1; ix < mapSize - 1; ++ix)
|
||||
for (let iz = 1; iz < mapSize - 1; ++iz)
|
||||
{
|
||||
let position = new Vector2D(ix, iz);
|
||||
if (g_Map.validHeight(position) && getTileClass(clPyrenneans).countMembersInRadius(ix, iz, 1))
|
||||
if (g_Map.validHeight(position) && clPyrenneans.countMembersInRadius(ix, iz, 1))
|
||||
{
|
||||
let height = g_Map.getHeight(position);
|
||||
let index = 1 / (1 + Math.max(0, height / 7));
|
||||
@@ -280,7 +280,7 @@ for (let ix = 1; ix < mapSize - 1; ++ix)
|
||||
for (let iz = 1; iz < mapSize - 1; ++iz)
|
||||
{
|
||||
let position = new Vector2D(ix, iz);
|
||||
if (g_Map.inMapBounds(position) && getTileClass(clPyrenneans).countMembersInRadius(ix, iz, 1))
|
||||
if (g_Map.inMapBounds(position) && clPyrenneans.countMembersInRadius(ix, iz, 1))
|
||||
{
|
||||
let heightNeighbor = g_Map.getAverageHeight(position);
|
||||
let index = 1 / (1 + Math.max(0, (g_Map.getHeight(position) - 10) / 7));
|
||||
@@ -303,7 +303,7 @@ for (let ix = 1; ix < mapSize - 1; ++ix)
|
||||
for (let iz = 1; iz < mapSize - 1; ++iz)
|
||||
{
|
||||
let position = new Vector2D(ix, iz);
|
||||
if (!g_Map.inMapBounds(position) || !getTileClass(clWater).countMembersInRadius(ix, iz, smoothDist))
|
||||
if (!g_Map.inMapBounds(position) || !clWater.countMembersInRadius(ix, iz, smoothDist))
|
||||
continue;
|
||||
let averageHeight = 0;
|
||||
let todivide = 0;
|
||||
@@ -360,7 +360,7 @@ for (let x = 0; x < mapSize; ++x)
|
||||
let height = g_Map.getHeight(position);
|
||||
let heightDiff = g_Map.getSlope(position);
|
||||
|
||||
if (getTileClass(clPyrenneans).countMembersInRadius(x, z, 2))
|
||||
if (clPyrenneans.countMembersInRadius(x, z, 2))
|
||||
{
|
||||
let layer = terrainPerHeight.find(layer => height < layer.maxHeight);
|
||||
createTerrain(heightDiff > layer.steepness ? layer.terrainSteep : layer.terrainGround).place(position);
|
||||
@@ -376,10 +376,10 @@ function getShoreTerrain(height, heightDiff, x, z)
|
||||
if (height <= -14)
|
||||
return tWater;
|
||||
|
||||
if (height <= -2 && getTileClass(clWater).countMembersInRadius(x, z, 2))
|
||||
if (height <= -2 && clWater.countMembersInRadius(x, z, 2))
|
||||
return heightDiff < 2.5 ? tSand : tMidRangeCliffs;
|
||||
|
||||
if (height <= 0 && getTileClass(clWater).countMembersInRadius(x, z, 3))
|
||||
if (height <= 0 && clWater.countMembersInRadius(x, z, 3))
|
||||
return heightDiff < 2.5 ? tSandTransition : tMidRangeCliffs;
|
||||
|
||||
return undefined;
|
||||
|
||||
@@ -131,7 +131,7 @@ for (let i = 0; i < numRivers; ++i)
|
||||
"meanderLong": 0,
|
||||
"waterFunc": (position, height, riverFraction) => {
|
||||
|
||||
addToClass(position.x, position.y, clWater);
|
||||
clWater.add(position);
|
||||
|
||||
let isShallow = height < heightShallows &&
|
||||
riverFraction > shallowLocation &&
|
||||
@@ -146,7 +146,7 @@ for (let i = 0; i < numRivers; ++i)
|
||||
createTerrain(height >= 0 ? tShore : tWater).place(position);
|
||||
|
||||
if (isShallow)
|
||||
addToClass(position.x, position.y, clShallow);
|
||||
clShallow.add(position);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -59,9 +59,9 @@ AvoidTextureConstraint.prototype.allows = function(position)
|
||||
/**
|
||||
* The AvoidTileClassConstraint is met if there are no tiles marked with the given TileClass within the given radius of the tile.
|
||||
*/
|
||||
function AvoidTileClassConstraint(tileClassID, distance)
|
||||
function AvoidTileClassConstraint(tileClass, distance)
|
||||
{
|
||||
this.tileClass = getTileClass(tileClassID);
|
||||
this.tileClass = tileClass;
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
@@ -73,9 +73,9 @@ AvoidTileClassConstraint.prototype.allows = function(position)
|
||||
/**
|
||||
* The StayInTileClassConstraint is met if every tile within the given radius of the tile is marked with the given TileClass.
|
||||
*/
|
||||
function StayInTileClassConstraint(tileClassID, distance)
|
||||
function StayInTileClassConstraint(tileClass, distance)
|
||||
{
|
||||
this.tileClass = getTileClass(tileClassID);
|
||||
this.tileClass = tileClass;
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
@@ -89,9 +89,9 @@ StayInTileClassConstraint.prototype.allows = function(position)
|
||||
* tiles not marked with the given TileClass within distanceInside of the tile and
|
||||
* tiles marked with the given TileClass within distanceOutside of the tile.
|
||||
*/
|
||||
function BorderTileClassConstraint(tileClassID, distanceInside, distanceOutside)
|
||||
function BorderTileClassConstraint(tileClass, distanceInside, distanceOutside)
|
||||
{
|
||||
this.tileClass = getTileClass(tileClassID);
|
||||
this.tileClass = tileClass;
|
||||
this.distanceInside = distanceInside;
|
||||
this.distanceOutside = distanceOutside;
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ function createMountain(maxHeight, minRadius, maxRadius, numCircles, constraints
|
||||
createTerrain(terrain).place(position);
|
||||
|
||||
if (tileClass !== undefined)
|
||||
addToClass(ix, iz, tileClass);
|
||||
tileClass.add(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -566,7 +566,7 @@ function createPassage(args)
|
||||
passageHeight);
|
||||
|
||||
if (args.tileClass !== undefined)
|
||||
addToClass(location.x, location.y, args.tileClass);
|
||||
args.tileClass.add(location);
|
||||
|
||||
if (args.edgeTerrain && smoothDistance > 0)
|
||||
createTerrain(args.edgeTerrain).place(location);
|
||||
|
||||
@@ -46,11 +46,13 @@ SimpleGroup.prototype.place = function(player, constraint)
|
||||
// Add all objects to the map
|
||||
for (let obj of resultObjs)
|
||||
{
|
||||
if (g_Map.validTile(new Vector2D(obj.position.x, obj.position.z)))
|
||||
let position = new Vector2D(obj.position.x, obj.position.z);
|
||||
|
||||
if (g_Map.validTile(position))
|
||||
g_Map.addObject(obj);
|
||||
|
||||
if (this.tileClass !== undefined)
|
||||
getTileClass(this.tileClass).add(Math.floor(obj.position.x), Math.floor(obj.position.z));
|
||||
this.tileClass.add(position.clone().floor());
|
||||
}
|
||||
|
||||
return resultObjs;
|
||||
|
||||
@@ -189,14 +189,6 @@ function placeObject(position, type, player, angle)
|
||||
g_Map.addObject(new Entity(type, player, position.x, position.y, angle));
|
||||
}
|
||||
|
||||
function getTileClass(id)
|
||||
{
|
||||
if (!g_Map.validClass(id))
|
||||
return undefined;
|
||||
|
||||
return g_Map.tileClasses[id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new Area shaped by the Placer meeting the Constraints and calls the Painters there.
|
||||
* Supports both Centered and Non-Centered Placers.
|
||||
@@ -250,28 +242,6 @@ function createObjectGroup(group, player, constraints)
|
||||
return group.place(player, new AndConstraint(constraints));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add point to given class by id
|
||||
*/
|
||||
function addToClass(x, z, id)
|
||||
{
|
||||
let tileClass = getTileClass(id);
|
||||
|
||||
if (tileClass !== null)
|
||||
tileClass.add(x, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove point from the given class by id
|
||||
*/
|
||||
function removeFromClass(x, z, id)
|
||||
{
|
||||
let tileClass = getTileClass(id);
|
||||
|
||||
if (tileClass !== null)
|
||||
tileClass.remove(x, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an avoid constraint for the given classes by the given distances
|
||||
*/
|
||||
|
||||
@@ -6,29 +6,29 @@
|
||||
/**
|
||||
* Marks the affected area with the given tileclass.
|
||||
*/
|
||||
function TileClassPainter(tileClassID)
|
||||
function TileClassPainter(tileClass)
|
||||
{
|
||||
this.tileClass = getTileClass(tileClassID);
|
||||
this.tileClass = tileClass;
|
||||
}
|
||||
|
||||
TileClassPainter.prototype.paint = function(area)
|
||||
{
|
||||
for (let point of area.points)
|
||||
this.tileClass.add(point.x, point.y);
|
||||
this.tileClass.add(point);
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the given tileclass from a given area.
|
||||
*/
|
||||
function TileClassUnPainter(tileClassID)
|
||||
function TileClassUnPainter(tileClass)
|
||||
{
|
||||
this.tileClass = getTileClass(tileClassID);
|
||||
this.tileClass = tileClass;
|
||||
}
|
||||
|
||||
TileClassUnPainter.prototype.paint = function(area)
|
||||
{
|
||||
for (let point of area.points)
|
||||
this.tileClass.remove(point.x, point.y);
|
||||
this.tileClass.remove(point);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -189,15 +189,9 @@ function defaultPlayerBaseRadius()
|
||||
*/
|
||||
function addCivicCenterAreaToClass(position, tileClass)
|
||||
{
|
||||
let pos = position.clone().round();
|
||||
|
||||
addToClass(pos.x, pos.y, tileClass);
|
||||
|
||||
addToClass(pos.x, pos.y + 5, tileClass);
|
||||
addToClass(pos.x, pos.y - 5, tileClass);
|
||||
|
||||
addToClass(pos.x + 5, pos.y, tileClass);
|
||||
addToClass(pos.x - 5, pos.y, tileClass);
|
||||
createArea(
|
||||
new ClumpPlacer(diskArea(5), 1, 1, Infinity, position),
|
||||
new TileClassPainter(tileClass));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -329,7 +323,7 @@ function placePlayerBaseMines(args)
|
||||
if (args.types[i].type && args.types[i].type == "stone_formation")
|
||||
{
|
||||
createStoneMineFormation(pos[i], args.types[i].template, args.types[i].terrain);
|
||||
addToClass(pos[i].x, pos[i].y, args.BaseResourceClass);
|
||||
args.BaseResourceClass.add(pos[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,9 +58,6 @@ function RandomMap(baseHeight, baseTerrain)
|
||||
// Array of Entities
|
||||
this.objects = [];
|
||||
|
||||
// Array of integers
|
||||
this.tileClasses = [];
|
||||
|
||||
this.areaID = 0;
|
||||
|
||||
// Starting entity ID, arbitrary number to leave some space for player entities
|
||||
@@ -160,14 +157,6 @@ RandomMap.prototype.validHeight = function(position)
|
||||
return position.x <= this.size && position.y <= this.size;
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests if there is a tileclass with the given ID.
|
||||
*/
|
||||
RandomMap.prototype.validClass = function(tileClassID)
|
||||
{
|
||||
return tileClassID >= 0 && tileClassID < this.tileClasses.length;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the name of the texture of the given tile.
|
||||
*/
|
||||
@@ -250,14 +239,9 @@ RandomMap.prototype.createArea = function(points)
|
||||
return new Area(points, areaID);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an unused tileclass ID.
|
||||
*/
|
||||
RandomMap.prototype.createTileClass = function()
|
||||
{
|
||||
let newID = this.tileClasses.length;
|
||||
this.tileClasses.push(new TileClass(this.size, newID));
|
||||
return newID;
|
||||
return new TileClass(this.size);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,44 +60,36 @@ RangeOp.prototype.get = function(start, end)
|
||||
return ret;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// TileClass
|
||||
//
|
||||
// Class for representing terrain types and containing all the tiles
|
||||
// within that type
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
function TileClass(size, id)
|
||||
/**
|
||||
* Class that can be tagged to any tile. Can be used to constrain placers and entity placement to given areas.
|
||||
*/
|
||||
function TileClass(size)
|
||||
{
|
||||
this.id = id;
|
||||
this.size = size;
|
||||
this.inclusionCount = [];
|
||||
this.rangeCount = [];
|
||||
|
||||
for (var i=0; i < size; ++i)
|
||||
for (let i=0; i < size; ++i)
|
||||
{
|
||||
this.inclusionCount[i] = new Int16Array(size); //int16
|
||||
this.rangeCount[i] = new RangeOp(size);
|
||||
}
|
||||
}
|
||||
|
||||
TileClass.prototype.add = function(x, z)
|
||||
TileClass.prototype.add = function(position)
|
||||
{
|
||||
let position = new Vector2D(x, z);
|
||||
if (!this.inclusionCount[position.x][position.y] && g_Map.validTile(position))
|
||||
this.rangeCount[z].add(x, 1);
|
||||
this.rangeCount[position.y].add(position.x, 1);
|
||||
|
||||
this.inclusionCount[x][z]++;
|
||||
++this.inclusionCount[position.x][position.y];
|
||||
};
|
||||
|
||||
TileClass.prototype.remove = function(x, z)
|
||||
TileClass.prototype.remove = function(position)
|
||||
{
|
||||
this.inclusionCount[x][z]--;
|
||||
if(!this.inclusionCount[x][z])
|
||||
{
|
||||
this.rangeCount[z].add(x, -1);
|
||||
}
|
||||
--this.inclusionCount[position.x][position.y];
|
||||
|
||||
if (!this.inclusionCount[position.x][position.y])
|
||||
this.rangeCount[position.y].add(position.x, -1);
|
||||
};
|
||||
|
||||
TileClass.prototype.countInRadius = function(cx, cy, radius, returnMembers)
|
||||
|
||||
@@ -996,7 +996,7 @@ function unreachableBluff(bb, corners, baseLine, endLine)
|
||||
function removeBluff(points)
|
||||
{
|
||||
for (let point of points)
|
||||
addToClass(point.x, point.y, g_TileClasses.mountain);
|
||||
g_TileClasses.mountain.add(point);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -115,7 +115,7 @@ for (var i = 0; i < scaleByMapSize(12,30); ++i)
|
||||
if (avoidClasses(clPlayer, 30, clRock, 25, clWater, 10).allows(position))
|
||||
{
|
||||
createStoneMineFormation(position, oStoneSmall, tDirt4);
|
||||
addToClass(position.x, position.y, clRock);
|
||||
clRock.add(position);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ for (let i = 0; i < numPlayers; ++i)
|
||||
|
||||
log("Placing treasure seeker woman...");
|
||||
let femaleLocation = findLocationInDirectionBasedOnHeight(playerPosition[i], mapCenter, -3 , 3.5, 3).round();
|
||||
addToClass(femaleLocation.x, femaleLocation.y, clWomen);
|
||||
clWomen.add(femaleLocation);
|
||||
placeObject(femaleLocation, oTreasureSeeker, playerIDs[i], playerAngle[i] + Math.PI);
|
||||
|
||||
log("Placing attacker spawn point....");
|
||||
@@ -102,8 +102,8 @@ for (let i = 0; i < numPlayers; ++i)
|
||||
|
||||
log("Preventing mountains in the area between player and attackers...");
|
||||
addCivicCenterAreaToClass(playerPosition[i], clPlayer);
|
||||
addToClass(attacker[i].x, attacker[i].y, clPlayer);
|
||||
addToClass(halfway[i].x, halfway[i].y, clPlayer);
|
||||
clPlayer.add(attacker);
|
||||
clPlayer.add(halfway);
|
||||
}
|
||||
Engine.SetProgress(20);
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ paintRiver({
|
||||
"meanderLong": 50,
|
||||
"waterFunc": (position, height, riverFraction) => {
|
||||
|
||||
addToClass(position.x, position.y, clWater);
|
||||
clWater.add(position);
|
||||
createTerrain(tShore).place(position);
|
||||
|
||||
// Place river bushes
|
||||
@@ -165,7 +165,7 @@ paintRiver({
|
||||
if (riv.left < +shoreDist1 && +shoreDist1 < riv.right ||
|
||||
riv.left < -shoreDist2 && -shoreDist2 < riv.right)
|
||||
{
|
||||
addToClass(position.x, position.y, riv.tileClass);
|
||||
riv.tileClass.add(position);
|
||||
|
||||
if (riv.terrain)
|
||||
createTerrain(riv.terrain).place(position);
|
||||
|
||||
@@ -292,11 +292,11 @@ function unknownCentralSea()
|
||||
"meanderLong": 0,
|
||||
"waterFunc": (position, height, riverFraction) => {
|
||||
if (height < 0)
|
||||
addToClass(position.x, position.y, clWater);
|
||||
clWater.add(position);
|
||||
},
|
||||
"landFunc": (position, shoreDist1, shoreDist2) => {
|
||||
g_Map.setHeight(position, 3.1);
|
||||
addToClass(position.x, position.y, clLand);
|
||||
clLand.add(position);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user