/*
Contest undead desert terrain generator
Copyright (C) 2007 konijn aka Tom J Demuyt
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
//Desert generator with some huts and evil undeadz
//Open File
f = openTextFile("prototype.html" , "w" );
//Write html header
. ' Desert Map';
. 'This code is GPL due to the use of Wesnoth images.
';
. 'You can only enjoy this map with a real browser that supports transparency ( not Internet Explorer )
';
. ' Code
';
width = 20;
heigh = 25;
scatterMode = false;
scatteredTiles = [];
//Draw desert
for( x = 1 ; x < width ; x++ ){
for( y = 1 ; y < heigh; y++ ){
dropHexagon(x, y, "desert" @ random(1,18) @ ".png" );
}
}
//Draw scenery : drop a few settlement, undeadz and bonez
scatterMode = true;
for( counter = 1 ; counter < 7 ; counter++ ){
scatter( "fire4.png" , [ "tent-ruin-1.png" , "tent-ruin-1.png" ] );
scatter( "draug.png" , [ "skeleton.png" , "soulshooter.png" ] );
dropHexagon( random(1,width-1), random(1,heigh-1), "bones.png" );
dropHexagon( random(1,width-1), random(1,heigh-1), "scorpion.png" );
}
//write html 'footer'
. '';
//close file
f.close();
//Place a hexagon image on the page
//Modern browsers only due to transparency in png images
function dropHexagon( x , y ,file){
imageSize = 36; //in the images it is 72, but 36 looks better I find
//Odd multipliers to make hexagonal work
parameters = { size = imageSize , src = file , left = y.isOdd()?x * imageSize * 1.5:x * imageSize * 1.5 + imageSize * 0.75 , top = 50+y * imageSize / 2 };
//Make sure we dont overwrite scenery
if( scatterMode ){
if(scatteredTiles.exists( parameters ) )return;
scatteredTiles.add( parameters );
}
. '
'.replaceTags( parameters , '@' );
}
//Scatter a few tiles around a center tile
function scatter ( centerFile , otherFiles ){
//Some declare magic in table instead of in code
//This basically states that a tile in the topleft of another tile has
//the same x cordinate and its y coordinate is 1 lower and so forth
topleft = { x = 0 , y = -1 };
toprigh = { x = 1 , y = -1 };
lowleft = { x = 0 , y = +1 };
lowrigh = { x = 1 , y = +1 };
//This consider the 4 axes the other tiles can be in
axes = [ [topleft,toprigh] , [ topleft , lowleft ] , [ toprigh, lowrigh] , [ lowleft, lowrigh ] ];
//We assume the map is at least 6 on 6
centerX = random(3,width-3);
centerY = random(3,heigh-3);
axis = random(0 , axes.length()-1 );
//Drop center tile
dropHexagon( centerX , centerY , centerFile );
//Drop surrounding tiles
for file in otherFiles {
dropHexagon( centerX + axes[axis][loopIndex()].x , centerY + axes[axis][loopIndex()].y , file);
}
}