0ad/binaries/data/mods/public/maps/random/rmgen/terrain.js
historic_bruno 0e0ed94926 Implements random map system, fixes #6.
Includes default library "rmgen" w/ API based on rmgen tool.
Modifies rmgen scripts Cantabrian Highlands, Neareastern Badlands, and
Latium.
Old map support dropped from MapReader.
Fixes a few bugs in existing game setup and initialization scripts.

This was SVN commit r9096.
2011-03-22 01:34:45 +00:00

58 lines
1.5 KiB
JavaScript

//////////////////////////////////////////////////////////////////////
// Terrain
//////////////////////////////////////////////////////////////////////
function Terrain() {}
Terrain.prototype.place = function(x, y)
{
// Clear old array
g_Map.terrainObjects[x][y] = [];
this.placeNew(x, y);
};
Terrain.prototype.placeNew = function() {};
//////////////////////////////////////////////////////////////////////
// SimpleTerrain
//////////////////////////////////////////////////////////////////////
function SimpleTerrain(texture, treeType)
{
if (texture === undefined)
error("SimpleTerrain: texture not defined");
this.texture = texture;
this.treeType = treeType;
}
SimpleTerrain.prototype = new Terrain();
SimpleTerrain.prototype.constructor = SimpleTerrain;
SimpleTerrain.prototype.placeNew = function(x, y)
{
if (this.treeType !== undefined)
g_Map.terrainObjects[x][y].push(new Entity(this.treeType, 0, x+0.5, y+0.5, randFloat()*PI));
g_Map.texture[x][y] = g_Map.getID(this.texture);
};
//////////////////////////////////////////////////////////////////////
// RandomTerrain
//////////////////////////////////////////////////////////////////////
function RandomTerrain(terrains)
{
if (!(terrains instanceof Array) || !terrains.length)
error("Invalid terrains array");
this.terrains = terrains;
}
RandomTerrain.prototype = new Terrain();
RandomTerrain.prototype.constructor = RandomTerrain;
RandomTerrain.prototype.placeNew = function(x, y)
{
this.terrains[randInt(this.terrains.length)].placeNew(x, y);
};