/* 1st Darklord module */

#include "vdi.h"
#include "aes.h"
#include "stdlib.h"
#include "mod_head.h"

#define MAX_SPOTS 2000		/* number of spots before restoring screen if desired */
#define DK_PATTERN 1
#define DK_SOLID 2
#define NO_REDRAW 1
#define REDRAW 2

int calc_num(int, int);

int main(DKL_INFO *dark_pars)
{
short handle, xres, yres, col, xpos, ypos, radius;
int counter, *exit_flag;
int max_colours, fill_flag, redraw_flag;
int min_rad, max_rad;
int style, fill_type, max_fill_type;

	xres=dark_pars->dk_xres;
	yres=dark_pars->dk_yres;
	handle=dark_pars->dk_handle;
	exit_flag=dark_pars->dklord_flag;
	max_colours=dark_pars->dk_pens;
	fill_flag=dark_pars->dk_flag1;		/* solid or pattern fill, 1=pattern, 2=solid */
	redraw_flag=dark_pars->dk_flag2;	/* redraw screen regularly or not, 1=don't redraw, 2=redraw after MAX_SPOTS spots are drawn */
	min_rad=dark_pars->dk_start1;
	max_rad=dark_pars->dk_start2;

	vsf_perimeter(handle, 1);
	vsf_interior(handle, FIS_SOLID);
	vsf_color(handle, 1);
	counter=0;
	while(*exit_flag) {
		if(fill_flag==DK_PATTERN) {		/* pattern fill */
			style=calc_num(FIS_PATTERN, FIS_HATCH);
			if(style==FIS_PATTERN) max_fill_type=24;
			else max_fill_type=12;
			fill_type=calc_num(1, max_fill_type);
			vsf_interior(handle, style);
			vsf_style(handle, fill_type);
		}
		if(fill_flag==DK_SOLID) col=calc_num(0, max_colours);	/* allow background colour for solid fills */
		else col=calc_num(1, max_colours);	/* but not for pattern fills */
		vsf_color(handle, col);
		xpos=(short)calc_num(5, xres-5);	/* exclude outer margins of screen */
		ypos=(short)calc_num(5, yres-5);
		radius=(short)calc_num(min_rad, max_rad);
		v_circle(handle, xpos, ypos, radius);
		counter++;
		if(redraw_flag==REDRAW && counter>=MAX_SPOTS) break;
	}
	return 0;	/* no errors possible for this module */
}
/* ------------------------------------------------------------------ */
int calc_num(int min, int max)
{
int diff;

	diff=max-min;
	if(!diff) diff=1;	/* avoid divide-by-zero exception */
	return ((rand()%diff)+min);
}
/* -------------------------------------------------------------------- */
