#include <acknex.h>
#include <d3d9.h>
#include <default.c>
BMAP* map;
BMAP* plain_tile = "plain001.tga";
var plaincount = 0;
var plainmax = 500;
var active = 0;
int pixelcount = 0;
var position[3];
var groundsize = 2048;
STRING* wort = "BILDMENGE ANGEBEN\noder ESC um den Generator\nzu beenden:";
STRING* input = " ";
STRING* bitmapname = "Plain";
STRING* bitmapnumb = "1";
FONT* arial = "Arial#15";
PANEL* viewer =
{
pos_x = 5;
pos_y = 5;
layer = 10;
alpha = 100;
flags = SHOW | TRANSLUCENT;
}
PANEL* infos =
{
pos_x = 730;
pos_y = 50;
layer = 99990;
alpha = 100;
digits(5, 5, "INFOS:", arial, 1, 0);
digits(5, 15, "^^^^^^", arial, 1, 0);
digits(5, 25, "<> Bitmapcount = %.0f", arial, 1, plaincount);
digits(132, 25, "/", arial, 1, 0);
digits(140, 25, 4, arial, 1, plainmax);
digits(5, 115, "PLAIN NAME:", arial, 1, 0);
digits(5, 127, bitmapname, arial, 1,0);
digits(5, 145, "PIXELS SET:", arial, 1, 0);
digits(5, 157, 10, arial, 1,pixelcount);
flags = SHOW | TRANSLUCENT;
}
PANEL* frames =
{
pos_x = 0;
pos_y = 0;
layer = 1;
alpha = 100;
flags = SHOW | TRANSLUCENT;
}
TEXT* txt_input =
{
pos_x = 735;
pos_y = 95;
layer = 99999;
alpha = 100;
font = arial;
string(wort, input);
flags = SHOW | TRANSLUCENT;
}
void vec_trunc(var *vec, var limit)
{
vec[0] = minv(vec[0], limit);
vec[1] = minv(vec[1], limit);
vec[2] = minv(vec[2], limit);
}
void main()
{
video_mode = 8;
d3d_antialias = 9;
wait(1);
video_window(NULL, NULL, (2+16), "Heightmap Generator");
vec_set(sky_color, vector(1,1,1));
vec_set(screen_color, vector(1,1,1));
level_load(NULL);
wait(3);
map = bmap_createblack(groundsize, groundsize, 32);
bmap_fill(map, vector(50,50,50), 100);
viewer.bmap = map;
frames.bmap = bmap_createblack(726, 726, 24);
bmap_fill(frames.bmap, vector(255,255,255), 100);
if(groundsize >= 2048)
{
viewer.scale_x = 0.35;
viewer.scale_y = 0.35;
}
plaincount = 0;
var randompic = 1;
var little_format;
var big_format;
var alphablend;
var alphablend2;
var temp[3];
var temp2[3];
var a = 0;
var b = 0;
map = bmap_createblack(groundsize, groundsize, 32);
bmap_fill(map, vector(50,50,50), 100);
viewer.bmap = map;
while(1)
{
str_cpy(wort, "BILDMENGE ANGEBEN\noder ESC um den generator\nzu beenden:");
str_cpy(input, " ");
inkey(input);
while(inkey_active != 0)
{wait(1);}
if(str_cmpi(input, "esc"))
{break;}
str_cpy(wort, "GEWÄHLTE BILDMENGE:");
plainmax = str_to_num(input);
pixelcount = 0;
plaincount = 0;
bmap_fill(map, vector(50,50,50), 100);
big_format = bmap_lock(map, 0);
while(plainmax != 0 && plaincount < plainmax)
{
if(random(10) > 5) plain_tile = bmap_create("plain001.tga");//i've changed this part too
else plain_tile = bmap_create("plain002.tga");
position[0] = random(bmap_width(map));
position[1] = random(bmap_width(map));
position[2] = 0;
little_format = bmap_lock(plain_tile, 0);
for(a = 0; a<bmap_width(plain_tile); a++)
{
for(b = 0; b<bmap_height(plain_tile); b++)
{
if(position[0]+a >= bmap_width(map) || position[1]+b >= bmap_height(map)) continue;
//read map pixel
pixel_to_vec(temp, alphablend, big_format, pixel_for_bmap(map, position[0]+a, position[1]+b));
//read feature pixel
pixel_to_vec(temp2, alphablend2, little_format, pixel_for_bmap(plain_tile, a, b));
//color mixing in 3 steps
//1.multiply feature pixel's color with normalized alpha
vec_scale(temp2, alphablend2/100);
//2.add resulting color to the map pixel's color
vec_add(temp, temp2);
//3.check that resulting vector components stay within 0-255 range
vec_trunc(temp, 255);
//write the resulting color to the map
pixel_to_bmap(map, position[0]+a, position[1]+b, pixel_for_vec(temp, alphablend, big_format));
pixelcount += 1;
}
}
bmap_unlock(plain_tile);
plaincount += 1;
}
wait(1);
bmap_unlock(map);
}
sys_exit("");
}