/************************************************
 ******         LV Tiles (Default)         ******
 ******            Version 1.0             ******
 ******           July 08, 2007            ******
 ************************************************/

function line() {

	line.prototype.Create = Create;
	line.prototype.Prob = Prob;

	var x;
	var y;
	var length;
	var height;
	var probability = 5;

	function Prob() {
		return probability;
	}

	function Create() {
			// To create a tile function, you usually have to iterate over the array, based on length and
			// height values. For example, put solid tiles in (length) number of spaces starting at
			// one corner of a box, or one end of a line. Once those tiles are set, move down from the
			// corner and set the next row to solid tiles. This is the nature of a two-dimensional for-loop.

		this.x = Math.floor(Math.random()*31);
		this.y = Math.floor(Math.random()*23);
		this.length = Math.ceil(Math.random()*Math.random()*31);	// Random^2 means lower numbers on average
		this.height = Math.ceil(Math.random()*Math.random()*23);	// but still allows for larger ones.

		if (Math.random()>0.5) {					// Horizontal

			for (var i=this.length;i>0;i--) {

				if (this.x+i > 30) {i = 30-this.x};

				if (arrayTiles[this.x+i][this.y] == 0) {

					arrayTiles[this.x+i][this.y] = 1;

					if (i==this.length && decoration>Math.random()) {	// Decorate the ends of the line.

						if (Math.random()>0.5) {	// There are two tiles that can go
										// on the end of any given line.

							arrayTiles[this.x+i][this.y] = arrayTileGroups[tileGroup][0];

						} else {

							arrayTiles[this.x+i][this.y] = arrayTileGroups[tileGroup][3];

						}
					}

					if (i==0 && decoration>Math.random()) {

						if (Math.random()>0.5) {
							arrayTiles[this.x][this.y] = arrayTileGroups[tileGroup][1];
						} else {
							arrayTiles[this.x][this.y] = arrayTileGroups[tileGroup][2];
						}
					}
				}
			}

		} else {

			for (var i=this.height;i>0;i--) {			// Vertical

				if (this.y+i > 22) {i = 22-this.y};

				if (arrayTiles[this.x][this.y+i] == 0) {

					arrayTiles[this.x][this.y+i] = 1;

					if (i==this.height && decoration>Math.random()) {	// Decorate the ends of the line.

						if (Math.random()>0.5) {
							arrayTiles[this.x][this.y+i] = arrayTileGroups[tileGroup][2];
						} else {
							arrayTiles[this.x][this.y+i] = arrayTileGroups[tileGroup][3];
						}
					}

					if (i==0 && decoration>Math.random()) {

						if (Math.random()>0.5) {
							arrayTiles[this.x][this.y+i] = arrayTileGroups[tileGroup][0];
						} else {
							arrayTiles[this.x][this.y+i] = arrayTileGroups[tileGroup][1];
						}
					}
				}
			}
		}
	}
}


function rectangle() {

	rectangle.prototype.Create = Create;
	rectangle.prototype.Prob = Prob;

	var x;
	var y;
	var length;
	var height;
	var probability = 5;

	function Prob() {
		return probability;
	}

	function Create() {

		this.x = Math.floor(Math.random()*31);
		this.y = Math.floor(Math.random()*23);
		this.length = Math.ceil(Math.random()*Math.random()*31);
		this.height = Math.ceil(Math.random()*Math.random()*23);

		for (var i=this.length;i>=0;i--) {
			for (var j=this.height;j>=0;j--) {
				if (this.x+i<=30 && this.y+j<=22) {	// Check that the tile added is within the array.

					arrayTiles[this.x+i][this.y+j] = 1;

						// Check that each corner is inside the tile array, and check if it's
						// meant to be decorated. If both are true, then change the corner to
						// a styled tile.
					if (this.x<=30 && this.x>=0 && this.y<=22 && this.y>=0 &&
					decoration>Math.random()) {
						arrayTiles[this.x][this.y] = arrayTileGroups[tileGroup][1];
					}
					if (this.x+this.length<=30 && this.x+this.length>=0 && this.y<=22 && this.y>=0 &&
					decoration>Math.random()) {
						arrayTiles[this.x+this.length][this.y] = arrayTileGroups[tileGroup][0];
					}
					if (this.x+this.length<=30 && this.x+this.length>=0 && this.y+this.height<=22 &&
					this.y+this.height>=0 && decoration>Math.random()) {
						arrayTiles[this.x+this.length][this.y+this.height] = arrayTileGroups[tileGroup][3];
					}
					if (this.x<=30 && this.x>=0 && this.y+this.height<=22 && this.y+this.height>=0 &&
					decoration>Math.random()) {
						arrayTiles[this.x][this.y+this.height] = arrayTileGroups[tileGroup][2];
					}
				}
			}
		}
	}
}


function dottedLine() {
		// The dotted line works by adding 2 to the current position when iterating, instead of 1.

	dottedLine.prototype.Create = Create;
	dottedLine.prototype.Prob = Prob;

	var x;
	var y;
	var length;
	var height;
	var probability = 1;

	function Prob() {
		return probability;
	}

	function Create() {

		this.x = Math.floor(Math.random()*31);
		this.y = Math.floor(Math.random()*23);
		this.length = Math.ceil(Math.random()*Math.random()*Math.random()*15);
		this.height = Math.ceil(Math.random()*Math.random()*Math.random()*11);

		if (Math.random()>0.5) {				// Horizontal

			for (var i=this.length;i>0;i--) {

				if (this.x+i > 29) {i = 29-this.x};

				if (arrayTiles[this.x+i+1][this.y] == 0) {

					arrayTiles[this.x+i][this.y] = 1;

					if (i==this.length && decoration>Math.random()) {	// Decorate the ends of the line.

						if (Math.random()>0.5) {			// There are two tiles that can go
												// on the end of any given line.
							arrayTiles[this.x+i][this.y] = arrayTileGroups[tileGroup][0];

						} else {

							arrayTiles[this.x+i][this.y] = arrayTileGroups[tileGroup][3];
						}
					}

					if (i==0 && decoration>Math.random()) {

						if (Math.random()>0.5) {

							arrayTiles[this.x][this.y] = arrayTileGroups[tileGroup][1];

						} else {

							arrayTiles[this.x][this.y] = arrayTileGroups[tileGroup][2];
						}
					}
				}
			}

		} else {

			for (var i=this.height;i>0;i--) {	// Vertical

				if (this.y+i > 21) {i = 21-this.y};

				if (arrayTiles[this.x][this.y+i+1] == 0) {

					arrayTiles[this.x][this.y] = 1;

					if (i==this.height && decoration>Math.random()) {	// Decorate the ends of the line.

						if (Math.random()>0.5) {

							arrayTiles[this.x][this.y+i] = arrayTileGroups[tileGroup][2];

						} else {

							arrayTiles[this.x][this.y+i] = arrayTileGroups[tileGroup][3];
						}
					}

					if (i==0 && decoration>Math.random()) {

						if (Math.random()>0.5) {

							arrayTiles[this.x][this.y+i] = arrayTileGroups[tileGroup][0];

						} else {

							arrayTiles[this.x][this.y+i] = arrayTileGroups[tileGroup][1];
						}
					}
				}
			}
		}
	}
}


function scatter() {
		// This function is complete, but I think its output is ugly.
		// It just selects a rectangle of area and puts random tiles on it.

	scatter.prototype.Create = Create;
	scatter.prototype.Prob = Prob;

	var x;
	var y;
	var length;
	var height;
	var openness;			// lower means more crowded, higher is more open.
	var probability = 1;

	function Prob() {
		return probability;
	}

	function Create() {

		this.x = Math.floor(Math.random()*31);
		this.y = Math.floor(Math.random()*23);
		this.length = Math.ceil(Math.random()*Math.random()*31);
		this.height = Math.ceil(Math.random()*Math.random()*23);
		this.openness = Math.ceil(Math.random()*7);

		for (var i=Math.floor(this.length*this.height/openness);i>0;i--) {

			this.x = Math.floor(Math.random()*this.length) + this.x;
			this.y = Math.floor(Math.random()*this.height) + this.y;

			if (this.x > 30) {this.x = 30};
			if (this.y > 22) {this.y = 22};

			if (arrayTiles[this.x][this.y] == 0) {		// Decide whether to use a solid tile or a styled one.
				if (decoration>Math.random()) {

					tileSc = Math.floor(Math.random()*3)
					arrayTiles[this.x][this.y] = arrayTileGroups[tileGroup][tileSc]

				} else {

					arrayTiles[this.x][this.y] = 1;
				}
			}
		}
	}
}


function outerCorners() {
		// Decorate outer tileset corners.

	outerCorners.prototype.Create = Create;
	outerCorners.prototype.Prob = Prob;

	var probability = 0;

	function Prob() {
		return probability;
	}

	function Create() {

		if (decoration>Math.random()) {
			if (arrayTiles[0][0]==0) {
				arrayTiles[0][0] = arrayTileGroups[tileGroup][3];
			}
			if (arrayTiles[30][0]==0) {
				arrayTiles[30][0] = arrayTileGroups[tileGroup][2];
			}
			if (arrayTiles[30][22]==0) {
				arrayTiles[30][22] = arrayTileGroups[tileGroup][1];
			}
			if (arrayTiles[0][22]==0) {
				arrayTiles[0][22] = arrayTileGroups[tileGroup][0];
			}
		}
	}
}
