#!/usr/bin/perl -w

use strict;

my $xsize = 40;
my $ysize = 25;
my ($i, $j, $x, $y, $n, $xx, $yy, $height);
my @map;

# create 
print <<EOF
[game]
version=11105
server_state=0

[savefile]
options="heightmap"

# disabled separatepoles and tinyisles aren't needed, but I like them.
[map]
separatepoles=0
tinyisles=1
EOF
    ;
print "width=$xsize\n";
print "height=$ysize\n";

# initialise heightmap to zero
for($j=0; $j<$ysize; $j++) {
    for($i=0; $i<$xsize; $i++) {
	$map[$i][$j] = 0;
    }
}

my $numpunches = 500;
my $ys = 10;
my $xs = 10;
for($n=0; $n<$numpunches; $n++) {
    $x = int(rand($xsize));
    $y = int(rand($ysize));
    for($j=0; $j<$ys; $j++) {
	for($i=0; $i<$xs; $i++) {
	    $xx = $x+$i;
	    $yy = $y+$j;
	    $height = int(10*($xs/2 - abs($i-$xs/2) + 
			  $ys/2 - abs($j-$ys/2)) + rand(10));
	    if($xx >= $xsize) { $xx = $xx - $xsize; }
	    if($yy >= $ysize) { $yy = $yy - $ysize; }
	    $map[$xx][$yy] = $map[$xx][$yy] + $height;
	}
    }
}

# now print the contents of $map
for($j=0; $j<$ysize; $j++) {
    printf("H%03d=\"", $j);
    for($i=0; $i<$xsize; $i++) {
	printf("%04x", $map[$i][$j]);
    }
    print "\"\n";
}
