Beispiel #1
0
/*
 * Move to a particular position and see if we hit a mine.
 * If not, then count the number of mines adjacent to us so it can be seen.
 * If we are stepping onto a location where we remembered a mine is at,
 * then don't do it.  Moving is only allowed to old locations, or to
 * locations adjacent to old ones.
 */
static void
movetopos(POS newpos)
{
    POS		fixpos;		/* position to fix up */
    CELL		cell;		/* current cell */
    GR_COUNT	count;		/* count of cells */
    GR_COUNT	i;		/* index for neighbors */

    if ((newpos < 0) || (newpos >= (FULLSIZE * FULLSIZE)) || !playing)
        return;

    cell = board[newpos];

    if (isedge(cell) || (isseen(cell)) || isold(cell))
        return;

    count = isold(cell);
    for (i = 0; i < 8; i++)
        if (isold(board[newpos + steptable[i]]))
            count++;

    if (count <= 0)
        return;

    cell = (cell & F_FLAGS) | F_OLD;
    steps++;

    PRINTSTEPS;

    if (ismine(cell)) {		/* we hit a mine */
        legs--;
        board[newpos] = (F_REMEMBER | F_MINE);
        cell = (F_EMPTY | F_OLD);
        board[newpos] = cell;
        drawbomb(newpos, redgc, GR_TRUE);
        clearcell(newpos);
        setcursor();
        for (i = 0; i < 8; i++) {
            fixpos = newpos + steptable[i];
            if (isold(board[fixpos])) {
                board[fixpos]--;
                drawcell(fixpos);
            }
        }
        drawstatus();
    }

    count = 0;
    for (i = 0; i < 8; i++)
        if (ismine(board[newpos + steptable[i]]))
            count++;
    board[newpos] = cell | (count + '0');

    drawcell(newpos);

    if ((legs <= 0) || (newpos == boardpos(size,size)))
        gameover();
}
Beispiel #2
0
void
drawchecked(Cell *brd)
{
	int i;

	for(i = 0; i < Psize; i++) {
		if(brd[i].locked)
			drawcell(i / Brdsize, i % Brdsize, brd[i].digit, fixed);
		else 
			drawcell(i / Brdsize, i % Brdsize, brd[i].digit, 
					checkpossible(brd, i / Brdsize, i % Brdsize, brd[i].digit) ? display->black : wrong);
	}
}
Beispiel #3
0
void
refresh_voters(ModeInfo * mi)
{
	int         col, row, colrow;
	voterstruct *vp;

	if (voters == NULL)
		return;
	vp = &voters[MI_SCREEN(mi)];
	if (vp->first == NULL)
		return;

	if (vp->painted) {
		MI_CLEARWINDOW(mi);
		vp->painted = False;
		for (row = 0; row < vp->nrows; row++)
			for (col = 0; col < vp->ncols; col++) {
				colrow = col + row * vp->ncols;
				/* Draw all old, will get corrected soon if wrong... */
				drawcell(mi, col, row,
					 (unsigned long) (MI_NPIXELS(mi) * vp->arr[colrow] / BITMAPS),
					 vp->arr[colrow], False);
			}
	}
}
Beispiel #4
0
static int rast_redraw(void)
{
    Erase_view(VIEW_MAP1);
    drawcell(VIEW_MAP1, 0);	/* 0 means don't initialize VIEW_MAP2 */
    display_points(1);
    return 0;
}
Beispiel #5
0
static void
draw_state(ModeInfo * mi, int state)
{
	dilemmastruct *dp = &dilemmas[MI_SCREEN(mi)];
	CellList   *current;


	current = dp->cellList[state];
	while (current) {
		int         col = current->pt.x;
		int         row = current->pt.y;
		int         colrow = col + row * dp->ncols;

		drawcell(mi, col, row,
		       dp->colors[(int) dp->sn[colrow]][(int) dp->s[colrow]],
			 dp->sn[colrow], False);
		if (dp->s[colrow] && !dp->sn[colrow])
			dp->defectors--;
		if (!dp->s[colrow] && dp->sn[colrow])
			dp->defectors++;
		dp->s[colrow] = dp->sn[colrow];
		current = current->next;
	}
	free_state(dp, state);
	XFlush(MI_DISPLAY(mi));
}
Beispiel #6
0
static void
advanceColors(ModeInfo * mi, int col, int row)
{
	voterstruct *vp = &voters[MI_SCREEN(mi)];
	CellList   *curr;

	curr = vp->first->next;
	while (curr != vp->last) {
		if (curr->info.col == col && curr->info.row == row) {
			curr = curr->next;
			removefrom_list(curr->previous);
		} else {
			if (curr->info.age > 0)
				curr->info.age--;
			else if (curr->info.age < 0)
				curr->info.age++;
			drawcell(mi, curr->info.col, curr->info.row,
				 (MI_NPIXELS(mi) + curr->info.age / FACTOR +
				  (MI_NPIXELS(mi) * curr->info.kind / BITMAPS)) % MI_NPIXELS(mi),
				 curr->info.kind, False);
			if (curr->info.age == 0) {
				curr = curr->next;
				removefrom_list(curr->previous);
			} else
				curr = curr->next;
		}
	}
}
Beispiel #7
0
void
refresh_life1d(ModeInfo * mi)
{
	int         row, col, nrow;
	life1dstruct *lp;

	if (life1ds == NULL)
		return;
	lp = &life1ds[MI_SCREEN(mi)];
	if (lp->buffer == NULL)
		return;

#ifdef HAVE_XPM
        if (lp->graphics_format >= IS_XPM) {
		/* This is needed when another program changes the colormap. */
		free_life1d(MI_DISPLAY(mi), lp);
		init_life1d(mi);
		return;
	}
#endif

	for (row = 0; row < lp->nrows; row++) {
		nrow = row * lp->ncols;
		for (col = 0; col < lp->ncols; col++)
			drawcell(mi, col, row, lp->buffer[col + nrow]);
	}
}
Beispiel #8
0
void
drawboard(void)
{
	int i;

	for(i = 0; i < Psize; i++) {
		drawcell(i / Brdsize, i % Brdsize, brd[i].digit, brd[i].locked ? fixed : display->black);
	}
}
Beispiel #9
0
/*
 * Redraw the board.
 */
static void
drawboard(void)
{
    GR_COORD	row;
    GR_COORD	col;

    for (row = 1; row < size; row++) {
        GrLine(boardwid, boardgc, 0, row * yp - 1, size * xp - 1,
               row * yp - 1);
        GrLine(boardwid, boardgc, row * xp - 1, 0,
               row * xp - 1, size * yp - 1);
    }
    for (row = 0; row < FULLSIZE; row++) {
        for (col = 0; col < FULLSIZE; col++) {
            drawcell(boardpos(row, col));
        }
    }
}
Beispiel #10
0
void drawScene(void)
{
	int i, j;

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

	for(i=0; i<N+boundary; i++){
		for(j=0; j<N+boundary; j++){
			drawcell(j, i, x[i+1][j+1]);
		}
	}


	glBegin(GL_LINES);
		glColor3f(1.0, 1.0, 1.0);
		glVertex2i(xoffset-BORDER, BORDER);
		glVertex2i(w-xoffset+BORDER, BORDER);

		glVertex2i(w-xoffset+BORDER, BORDER);
		glVertex2i(w-xoffset+BORDER, ROWS*CH+BORDER);

		glVertex2i(w-xoffset+BORDER, ROWS*CH+BORDER);
		glVertex2i(xoffset-BORDER, ROWS*CH+BORDER);

		glVertex2i(xoffset-BORDER, ROWS*CH+BORDER);
		glVertex2i(xoffset-BORDER, BORDER);
	glEnd();


	snprintf(itertext, 32, iterstr, iter, epsilon);
	bitmapString(font, itertext, w-w/5, h-BORDER/3);
	if(converged){
		snprintf(convtext, 128, convstr, iter, N, N, tol, omega);
		bitmapString(font, convtext, 48, h-BORDER/3);
	}
	if(paused){
		bitmapString(font, "-=: PAUSED :=-", w/2-40, BORDER/2);
	}
	glutSwapBuffers();


}
Beispiel #11
0
/*
 * Remember or forget the location of a mine.
 * This is for informational purposes only and does not affect anything.
 */
static void
togglecell(POS pos)
{
    CELL	cell;

    if ((pos <= 0) || !playing)
        return;

    cell = board[pos];
    if (isknown(cell)) {
        if (!isseen(cell))
            return;
        board[pos] = (board[pos] & F_FLAGS) | F_EMPTY;
        clearcell(pos);
        return;
    }

    board[pos] = (board[pos] & F_FLAGS) | F_REMEMBER;
    drawcell(pos);
}
Beispiel #12
0
static int zoom2(int x, int y)
{
    int top, bottom, left, right;
    int row, col;
    struct Cell_head cellhd;

    x2 = x;
    y2 = y;
    /* 
     * user has completed the zoom window.
     * must be in same view as first corner
     */
    if (x1 == x2 || y1 == y2)
	return 0;		/* ignore event */
    if (!In_view(pick_view, x2, y2))
	return 0;
    /*
     * ok, erase menu messages
     */
    Menu_msg("");

    /*
     * assign window coordinates to top,bottom,left,right
     */
    if (x1 < x2) {
	left = x1;
	right = x2;
    }
    else {
	left = x2;
	right = x1;
    }
    if (y1 < y2) {
	top = y1;
	bottom = y2;
    }
    else {
	top = y2;
	bottom = y1;
    }

    /* 
     * Determine the the zoom window (ie, cellhd)
     * must copy the current view cellhd first, to preserve header info
     * (such as projection, zone, and other items.)
     * compute zoom window northings,eastings, rows, cols, and resolution
     */

    G_copy(&cellhd, &pick_view->cell.head, sizeof(cellhd));

    /* convert top to northing at top edge of cell
     * left to easting at left edge
     */
    col = view_to_col(pick_view, left);
    row = view_to_row(pick_view, top);
    cellhd.north = row_to_northing(&pick_view->cell.head, row, 0.0);
    cellhd.west = col_to_easting(&pick_view->cell.head, col, 0.0);

    /* convert bottom to northing at bottom edge of cell
     * right to easting at right edge
     */
    col = view_to_col(pick_view, right);
    row = view_to_row(pick_view, bottom);
    cellhd.south = row_to_northing(&pick_view->cell.head, row, 1.0);
    cellhd.east = col_to_easting(&pick_view->cell.head, col, 1.0);


    cellhd.rows = bottom - top + 1;
    cellhd.cols = right - left + 1;
    cellhd.ns_res = (cellhd.north - cellhd.south) / cellhd.rows;
    cellhd.ew_res = (cellhd.east - cellhd.west) / cellhd.cols;

    /*
     * Outline the zoom window on the main map
     * Turn previous one to grey.
     */
    if (zoom_view->cell.configured) {
	R_standard_color(GREY);
	Outline_cellhd(main_view, &zoom_view->cell.head);
    }
    R_standard_color(RED);
    Outline_cellhd(main_view, &cellhd);


    /*
     * zoom
     */
    if (target_flag)
	select_target_env();
    G_adjust_window_to_box(&cellhd, &zoom_view->cell.head, zoom_view->nrows,
			   zoom_view->ncols);
    Configure_view(zoom_view, pick_view->cell.name, pick_view->cell.mapset,
		   pick_view->cell.ns_res, pick_view->cell.ew_res);
    drawcell(zoom_view);
    select_current_env();
    display_ref_points(1);
    return 1;			/* pop back */
}
Beispiel #13
0
void design (void) {
	int updflag=0;
	int dx,dy,tempx,n;
	int lastcell=1;
	int tempint;
	int drawmode=0;
	char tempstr[32];
	char tempfname[32];
	char tempstr2[12];
	char tempstr3[32];
	int new_col=0;
	int bc_x=0,bc_y=0,bc_w=0,bc_h=0;		// Block copy x,y and width,height
	int tx,ty;

	disy=0;
	designflag=1;
	gamecount=0;
	tempstr[0]='\0';
	tempfname[0]='\0';
	setorigin();
	dx=objs[0].x/16;
	dy=objs[0].y/16;
	drawboard();
	fontcolor (&statvp,1,0);
	clearvp (&statvp);

	do {
		if (drawmode) {
			setboard (dx,dy,lastcell);
			drawcell (dx,dy);
			updflag=1;
			}
		fontcolor (&statvp,3,0);						// memory usage
		wprint (&statvp,248,1,2,"       ");
		ultoa (coreleft(),tempstr3,10);
		wprint (&statvp,290-(1+strlen(tempstr3)*6),1,2,tempstr3);
		tempstr3[0]='\0';

		fontcolor (&statvp,1,0);
		wprint (&statvp,248,21,2, "# objs: ");
		fontcolor (&statvp,3,0);
		wprint (&statvp,296,21,2,itoa(numobjs,tempstr2,10));

		drawshape (&gamevp,0x0100,dx*16+4,dy*16+4);
		do {
			checkctrl(0);
			} while ((dx1==0)&&(dy1==0)&&(key==0)&&(updflag==0));
		updflag=0;
		modboard(dx,dy);
		upd_objs(0);
		refresh(0);
		purgeobjs();
		if ((dx1!=0)||(dy1!=0)) {
			dx+=dx1*(1+fire1*(scrnxs/2-1));
			dy+=dy1*(1+fire1*(scrnys/2-1));
			if (dx<0) dx=0;
			if (dx>=boardxs) dx=boardxs-1;
			if (dy<0) dy=0;
			if (dy>=boardys) dy=boardys-1;
			if ((dx*16)<gamevp.vpox) {
				gamevp.vpox-=scrnxs*8;
				if (gamevp.vpox<0) gamevp.vpox=0;
				drawboard();
				};
			if ((dx*16)>=(gamevp.vpox+16*scrnxs-16)) {
				gamevp.vpox+=scrnxs*8;
				if (gamevp.vpox>=(16*(boardxs-scrnxs)+8))
					gamevp.vpox=16*(boardxs-scrnxs)+8;
				drawboard();
				};
			if ((16*dy)<gamevp.vpoy) {
				gamevp.vpoy-=scrnys*8;
				if (gamevp.vpoy<0) gamevp.vpoy=0;
				drawboard();
				};
			if ((16*dy)>=(gamevp.vpoy+16*(scrnys-1))) {
				gamevp.vpoy+=scrnys*8;
				if (gamevp.vpoy>=(16*(boardys-scrnys+1)))
					gamevp.vpoy=(boardys-scrnys+1)*16;
				drawboard();
				};
			};

		switch (toupper(key)) {
			case k_f1:					// Mark top left corner of block
				bc_x=dx; bc_y=dy; break;
			case k_f2:
				// Mark bottom right corner of block and copy
				//	block of tile numbers into temp array bc_array
				if(dx<bc_x) break;
					// 0-width or negative width rectangle	(can't do that)
				if(dy<bc_y) break;
					// 0-height or negative height rectangle (can't do that)
				bc_w=(dx-bc_x)+1; bc_h=(dy-bc_y)+1;
				if((bc_w>normxs)||(bc_h>normys)) {			// Too big!!
					bc_w=0; bc_h=0; break;
					};
				for(ty=0; ty<bc_h; ty++) {
					for(tx=0; tx<bc_w; tx++) {
						bc_array[(ty*bc_w)+tx]=board(bc_x+tx,bc_y+ty);
						};
					};	break;
			case k_f3:
				for(ty=0; ty<bc_h; ty++) {
					for(tx=0; tx<bc_w; tx++) {
						setboard(dx+tx, dy+ty, bc_array[(ty*bc_w)+tx]);
						};
					};	updflag=1; break;
			case k_f4:
				do {
					upd_colors (); gamecount++; checkctrl0(0);
					} while (key==0); break;
			case enter:
				clearvp (&statvp);
				wprint (&statvp,2,1,1,"Put:");
				fontcolor (&statvp,6,0);
				winput (&statvp,2,11,1,tempstr,16);
				strupr (tempstr);
				for (tempint=0; tempint<numinfotypes; tempint++) {
					if (strcmp (tempstr,info[tempint].na)==0) {
						lastcell=tempint;
						setboard(dx,dy,tempint);
						shm_want[(info[tempint].sh>>8)&0x3f]=1;
						shm_do(); break;
						};
					};
				updflag=1; break;
			case 9: drawmode=!drawmode; break;				// tab
			case 'K': lastcell=board(dx,dy); break;
			case ' ':
				setboard(dx,dy,lastcell);
				updflag=1; break;
			case 'I':
				pl.score=1000;
				printhi (1);
				pl.score=0; break;
			case 'V':
				if (pl.numinv==0) addinv (inv_hero);
				else {
					pl.numinv=0;
					init_inv();
					};
				pl.score=0;
				pl.level=0; break;
			case 'H':
				tempint=board(dx,dy);
				tempx=dx;
				while (board(tempx,dy)==tempint) {
					setboard(tempx,dy,lastcell);
					drawcell (tempx,dy);
					tempx--;
					};
				tempx=dx+1;
				while (board(tempx,dy)==tempint) {
					setboard(tempx,dy,lastcell);
					drawcell (tempx,dy);
					tempx++;
					}; break;
			case 'O': updflag=objdesign(dx,dy); break;	// Object Mgmt
			case 'U':
				for (n=0; n<numobjs; n++) {
//					if (((kindflags[objs[n].objkind]&f_inside)==0)&&
//						(objs[n].inside!=NULL)) {
//						objs[n].inside=NULL;
//						sound(240);
//						delay(500);
//						nosound();
//						};
					setobjsize (n);
					}; break;
			case 'Z':
				infname ("Clear?",tempfname);
				if (toupper(tempfname[0])=='Y') {
					init_brd();
					init_objs();
					drawboard();
					}; break;
			case 'L':
				infname ("Load:",tempfname);
				if (tempfname[0]!='\0') {
					loadboard (tempfname);
					setorigin();
					dx=objs[0].x/16; dy=objs[0].y/16;
					drawboard();
					}; break;
			case 'Y':												// Disalign Y
				clearvp (&statvp);
				wprint (&statvp,2,1,1,"Dis Y:");
				itoa (disy,tempstr,10);
				winput (&statvp,2,11,1,tempstr,16);
				disy=atoi (tempstr);
				strupr (tempstr); break;
			case 'N':
				infname ("New board?",tempfname);
				if (toupper (tempfname[0])=='Y') {
					zapobjs();
					init_brd();
					}; break;
			case 'S':
				infname ("Save:",tempfname);
				if (tempfname[0]!='\0') saveboard (tempfname); break;
			case 'C':
				clearvp (&statvp);
				wprint (&statvp,2,1,1,"New Color:");
				fontcolor (&statvp,6,0);
				itoa (new_col,tempstr,10);
				winput (&statvp,2,11,1,tempstr,16);
				new_col=atoi (tempstr);

				switch (new_col) {
					case 0: setcolor (250,0,0,0);
						setcolor (251,0,0,0); break;				// reset all
					case 1: setcolor (251,0,0,0); break;		// reset #251
					case 2: setcolor (250,0,0,32);		 		// dk. blue sky
						setcolor (251,0,0,32); break;
					case 3:												// lt. blue sky
						setcolor (176,8,16,25); setcolor (177,8,20,29);
						setcolor (178,12,24,33); setcolor (179,16,28,41);
						setcolor (180,20,32,45); setcolor (181,24,40,49);
						setcolor (182,28,44,57); setcolor (183,36,48,60);
						setcolor (250,36,48,60); setcolor (251,36,48,60); break;
					case 4:												// yellow sky
						setcolor (176,32,0,0); setcolor (177,40,0,0);
						setcolor (178,52,0,0); setcolor (179,60,0,0);
						setcolor (180,60,28,0); setcolor (181,60,40,0);
						setcolor (182,60,52,0); setcolor (183,60,60,0);
						setcolor (250,60,60,0);	setcolor (251,60,60,0); break;
					case 5:												// emerald sky
						setcolor (176,0,12,12); setcolor (177,0,18,17);
						setcolor (178,0,25,23); setcolor (179,0,32,27);
						setcolor (180,0,39,32); setcolor (181,0,46,35);
						setcolor (182,0,53,38); setcolor (183,0,60,40);
						setcolor (250,0,60,40); setcolor (251,0,60,40); break;
					case 6: setcolor (250,32,32,24);				// olive green
						setcolor (251,32,32,24); break;
					case 7:												// violet sky
						setcolor (176,13,5,22); setcolor (177,18,8,27);
						setcolor (178,23,13,33); setcolor (179,29,19,39);
						setcolor (180,35,25,45); setcolor (181,42,32,51);
						setcolor (182,49,40,57); setcolor (183,57,50,63);
						setcolor (250,57,50,63); setcolor (251,57,50,63); break;
					case 8: setcolor (250,23,23,23);				// factory grey
						setcolor (251,23,23,23); break;
					case 9: setcolor (250,12,23,63);		 		// royal blue
						setcolor (251,12,23,63); break;
					case 10: setcolor (250,20,20,23);			// factory grey v3
						setcolor (251,20,20,23); break;
					};
			};
		} while (key!=escape);
Beispiel #14
0
void
draw_dilemma(ModeInfo * mi)
{
	int         col, row, mrow, colrow, n, i;
	dilemmastruct *dp;

	if (dilemmas == NULL)
		return;
	dp = &dilemmas[MI_SCREEN(mi)];
	if (dp->s == NULL)
		return;

	MI_IS_DRAWN(mi) = True;

	if (dp->state >= 2 * COLORS) {

		for (col = 0; col < dp->ncols; col++) {
			for (row = 0; row < dp->nrows; row++) {
				colrow = col + row * dp->ncols;
				if (conscious)
					dp->payoff[colrow] =
						dp->pm[(int) dp->s[colrow]][(int) dp->s[colrow]];
				else
					dp->payoff[colrow] = 0.0;
				for (n = 0; n < dp->neighbors; n++)
					dp->payoff[colrow] +=
						dp->pm[(int) dp->s[colrow]][(int)
						  dp->s[neighbor_position(dp,
					col, row, n * 360 / dp->neighbors)]];

			}
		}
		for (row = 0; row < dp->nrows; row++) {
			for (col = 0; col < dp->ncols; col++) {
				float       hp;
				int         position;

				colrow = col + row * dp->ncols;
				hp = dp->payoff[colrow];
				dp->sn[colrow] = dp->s[colrow];
				for (n = 0; n < dp->neighbors; n++) {
					position = neighbor_position(dp, col, row, n * 360 / dp->neighbors);
					if (ROUND_FLOAT(dp->payoff[position], 0.001) >
					    ROUND_FLOAT(hp, 0.001)) {
						hp = dp->payoff[position];
						dp->sn[colrow] = dp->s[position];
					}
				}
			}
		}
		mrow = 0;
		for (row = 0; row < dp->nrows; row++) {
			for (col = 0; col < dp->ncols; col++) {
				addtolist(mi, col, row,
					  dp->sn[col + mrow] * BITMAPS + dp->s[col + mrow]);
			}
			mrow += dp->ncols;
		}

		if (++dp->generation > MI_CYCLES(mi) ||
		    dp->defectors == dp->npositions || dp->defectors == 0)
			init_dilemma(mi);
		dp->state = 0;
	} else {
		if (dp->state < COLORS) {
			draw_state(mi, dp->state);
		}
		dp->state++;
	}
#if 1
	if (dp->redrawing) {
		for (i = 0; i < REDRAWSTEP; i++) {
			drawcell(mi, dp->redrawpos % dp->ncols, dp->redrawpos / dp->ncols,
				 dp->colors[(int) dp->sn[dp->redrawpos]][(int) dp->s[dp->redrawpos]],
				 dp->sn[dp->redrawpos], False);
			if (++(dp->redrawpos) >= dp->npositions) {
				dp->redrawing = 0;
				break;
			}
		}
	}
#endif
}
Beispiel #15
0
void
draw_dragon(ModeInfo * mi)
{
	int white, black;
	int         choose_layer, factor, orient, l;
	dragonstruct *dp;
	CellList *locallist;
	Bool detour = False;

	if (dragons == NULL)
		return;
	dp = &dragons[MI_SCREEN(mi)];
	if (dp->cellList == NULL)
		return;

	MI_IS_DRAWN(mi) = True;
	choose_layer= NRAND(6);
	if (dp->ncells[!dp->addlist] == 1) {
		/* Since the maze is infinite, it may not get to this last
		 * spot for a while.  Force it to do it right away so it
		 * does not appear to be stuck. */
		detour = True;
		white = black = 0; /* not used but make -Wall happy */
	} else {
		white = (choose_layer / 2);
		black = (choose_layer % 2) ?
			((white + 2) % 3) : ((white + 1) % 3);
		/* gray = (choose_layer % 2) ?
			((white + 1) % 3) : ((white + 2) % 3); */
	}
	locallist = dp->cellList[!dp->addlist];
	orient = dp->generation % 2;
	factor = 1;
	for (l = 0; l < dp->generation / 2; l++) {
		factor *= 3;
	}
	if (!locallist && dp->generation >= MI_CYCLES(mi)) {
		init_dragon(mi);
		return;
	}

	while (locallist) {
		int i, j, k;

		i = locallist->pt.x;
		j = locallist->pt.y;
		if (orient) {
			k = (j / factor) % 3;
		} else {
		 	if (j % 2) {
				/* Had trouble with this line... */
				k = ((i + factor / 2) / factor + 1) % 3;
			} else {
				k = (i / factor) % 3;
			}
		}
		if (detour) {
			k = (LRAND() & 1) + 1;
			dp->oldcell[j * dp->ncols + i] = k;
			drawcell(mi, i, j, k);
		} if (white == k) {
			dp->oldcell[j * dp->ncols + i] = 0;
			drawcell(mi, i, j, 0);
			if (!addtolist(mi, i, j)) {
				free_dragon(MI_DISPLAY(mi), dp);
				return;
			}
		} else if (black == k) {
			dp->oldcell[j * dp->ncols + i] = 1;
			drawcell(mi, i, j, 1);
		} else /* if (gray == k) */ {
			dp->oldcell[j * dp->ncols + i] = 2;
			drawcell(mi, i, j, 2);
		}
		dp->cellList[!dp->addlist] = dp->cellList[!dp->addlist]->next;
		free(locallist);
		dp->ncells[!dp->addlist]--;
		locallist = dp->cellList[!dp->addlist];
		if ((dp->cellList[!dp->addlist] == NULL) &&
		    (dp->cellList[dp->addlist] == NULL))
			dp->generation = 0;
	}
	dp->addlist = !dp->addlist;
	if (dp->redrawing) {
		int i;

		for (i = 0; i < REDRAWSTEP; i++) {
			if (dp->oldcell[dp->redrawpos] != 1) {
				drawcell(mi, dp->redrawpos % dp->ncols, dp->redrawpos / dp->ncols,
					 dp->oldcell[dp->redrawpos]);
			}
			if (++(dp->redrawpos) >= dp->ncols * dp->nrows) {
				dp->redrawing = 0;
				break;
			}
		}
	}
	dp->generation++;
}
Beispiel #16
0
int main(int argc, char *argv[])
{
    char name[GNAME_MAX], mapset[GMAPSET_MAX], xmapset[GMAPSET_MAX];
    struct Cell_head cellhd;
    struct GModule *module;
    struct Option *grp;

    /* must run in a term window */
    G_putenv("GRASS_UI_TERM", "1");

    G_gisinit(argv[0]);

    module = G_define_module();
    G_add_keyword(_("imagery"));
    G_add_keyword(_("geometry"));
    module->description =
	_("Mark ground control points on image to be rectified.");

    grp = G_define_option();
    grp->key = "group";
    grp->type = TYPE_STRING;
    grp->required = YES;
    grp->gisprompt = "old,group,group";
    grp->description = _("Name of imagery group to be registered");

    if (G_parser(argc, argv))
	exit(EXIT_FAILURE);


    Rast_suppress_masking();	/* need to do this for target location */

    interrupt_char = G_intr_char();
    tempfile1 = G_tempfile();
    tempfile2 = G_tempfile();
    cell_list = G_tempfile();
    vect_list = G_tempfile();
    group_list = G_tempfile();
    digit_points = G_tempfile();
    digit_results = G_tempfile();

    if (R_open_driver() != 0)
	G_fatal_error(_("No graphics device selected"));


    /* parse group name */
    /* only enforce local-mapset-only due to I_get_group_ref() not liking "@mapset" */
    if (G_name_is_fully_qualified(grp->answer, group.name, xmapset)) {
	if (0 != strcmp(G_mapset(), xmapset))
	    G_fatal_error(_("[%s] Only local groups may be used"),
			  grp->answer);
    }
    else {
	strncpy(group.name, grp->answer, GNAME_MAX - 1);
	group.name[GNAME_MAX - 1] = '\0';	/* strncpy() doesn't null terminate on overflow */
    }

    if (!I_get_group_ref(group.name, &group.ref))
	G_fatal_error(_("Group [%s] contains no maps, run i.group"),
		      group.name);

    if (group.ref.nfiles <= 0)
	G_fatal_error(_("Group [%s] contains no maps, run i.group"),
		      group.name);

    /* write group files to group list file */
    prepare_group_list();

    /* get target info and environment */
    get_target();
    find_target_files();

    /* read group control points, if any */
    G_suppress_warnings(1);
    if (!I_get_control_points(group.name, &group.points))
	group.points.count = 0;
    G_suppress_warnings(0);

    /* determine transformation equation */
    Compute_equation();


    signal(SIGINT, SIG_IGN);
    /*  signal (SIGQUIT, SIG_IGN); */

    Init_graphics();
    display_title(VIEW_MAP1);
    select_target_env();
    display_title(VIEW_MAP2);
    select_current_env();

    Begin_curses();
    G_set_error_routine(error);

    /*
       #ifdef SIGTSTP
       signal (SIGTSTP, SIG_IGN);
       #endif
     */


    /* ask user for group file to be displayed */
    do {
	if (!choose_groupfile(name, mapset))
	    quit(0);
	/* display this file in "map1" */
    }
    while (!G_find_raster2(name, mapset));
    Rast_get_cellhd(name, mapset, &cellhd);
    G_adjust_window_to_box(&cellhd, &VIEW_MAP1->cell.head, VIEW_MAP1->nrows,
			   VIEW_MAP1->ncols);
    Configure_view(VIEW_MAP1, name, mapset, cellhd.ns_res, cellhd.ew_res);

    drawcell(VIEW_MAP1);
    display_points(1);

    Curses_clear_window(PROMPT_WINDOW);

    /* determine initial input method. */
    setup_digitizer();
    if (use_digitizer) {
	from_digitizer = 1;
	from_keyboard = 0;
	from_flag = 1;
    }

    /* go do the work */
    driver();

    quit(0);
}
Beispiel #17
0
ENTRYPOINT void
draw_demon (ModeInfo * mi)
{
	int         i, j, k, l, mj = 0, ml;
	demonstruct *dp;

	if (demons == NULL)
		return;
	dp = &demons[MI_SCREEN(mi)];
	if (dp->cellList == NULL)
		return;

	MI_IS_DRAWN(mi) = True;
	if (dp->state >= dp->states) {
		(void) memcpy((char *) dp->newcell, (char *) dp->oldcell,
			      dp->ncols * dp->nrows * sizeof (unsigned char));

		if (dp->neighbors == 6) {
			for (j = 0; j < dp->nrows; j++) {
				for (i = 0; i < dp->ncols; i++) {
					/* NE */
					if (!(j & 1))
						k = (i + 1 == dp->ncols) ? 0 : i + 1;
					else
						k = i;
					l = (!j) ? dp->nrows - 1 : j - 1;
					ml = l * dp->ncols;
					if (dp->oldcell[k + ml] ==
					    (int) (dp->oldcell[i + mj] + 1) % dp->states)
						dp->newcell[i + mj] = dp->oldcell[k + ml];
					/* E */
					k = (i + 1 == dp->ncols) ? 0 : i + 1;
					ml = mj;
					if (dp->oldcell[k + ml] ==
					    (int) (dp->oldcell[i + mj] + 1) % dp->states)
						dp->newcell[i + mj] = dp->oldcell[k + ml];
					/* SE */
					if (!(j & 1))
						k = (i + 1 == dp->ncols) ? 0 : i + 1;
					else
						k = i;
					l = (j + 1 == dp->nrows) ? 0 : j + 1;
					ml = l * dp->ncols;
					if (dp->oldcell[k + ml] ==
					    (int) (dp->oldcell[i + mj] + 1) % dp->states)
						dp->newcell[i + mj] = dp->oldcell[k + ml];
					/* SW */
					if (j & 1)
						k = (!i) ? dp->ncols - 1 : i - 1;
					else
						k = i;
					l = (j + 1 == dp->nrows) ? 0 : j + 1;
					ml = l * dp->ncols;
					if (dp->oldcell[k + ml] ==
					    (int) (dp->oldcell[i + mj] + 1) % dp->states)
						dp->newcell[i + mj] = dp->oldcell[k + ml];
					/* W */
					k = (!i) ? dp->ncols - 1 : i - 1;
					ml = mj;
					if (dp->oldcell[k + ml] ==
					    (int) (dp->oldcell[i + mj] + 1) % dp->states)
						dp->newcell[i + mj] = dp->oldcell[k + ml];
					/* NW */
					if (j & 1)
						k = (!i) ? dp->ncols - 1 : i - 1;
					else
						k = i;
					l = (!j) ? dp->nrows - 1 : j - 1;
					ml = l * dp->ncols;
					if (dp->oldcell[k + ml] ==
					    (int) (dp->oldcell[i + mj] + 1) % dp->states)
						dp->newcell[i + mj] = dp->oldcell[k + ml];
				}
				mj += dp->ncols;
			}
		} else if (dp->neighbors == 4 || dp->neighbors == 8) {
			for (j = 0; j < dp->nrows; j++) {
				for (i = 0; i < dp->ncols; i++) {
					/* N */
					k = i;
					l = (!j) ? dp->nrows - 1 : j - 1;
					ml = l * dp->ncols;
					if (dp->oldcell[k + ml] ==
					    (int) (dp->oldcell[i + mj] + 1) % dp->states)
						dp->newcell[i + mj] = dp->oldcell[k + ml];
					/* E */
					k = (i + 1 == dp->ncols) ? 0 : i + 1;
					ml = mj;
					if (dp->oldcell[k + ml] ==
					    (int) (dp->oldcell[i + mj] + 1) % dp->states)
						dp->newcell[i + mj] = dp->oldcell[k + ml];
					/* S */
					k = i;
					l = (j + 1 == dp->nrows) ? 0 : j + 1;
					ml = l * dp->ncols;
					if (dp->oldcell[k + ml] ==
					    (int) (dp->oldcell[i + mj] + 1) % dp->states)
						dp->newcell[i + mj] = dp->oldcell[k + ml];
					/* W */
					k = (!i) ? dp->ncols - 1 : i - 1;
					l = j;
					ml = mj;
					if (dp->oldcell[k + ml] ==
					    (int) (dp->oldcell[i + mj] + 1) % dp->states)
						dp->newcell[i + mj] = dp->oldcell[k + ml];
				}
				mj += dp->ncols;
			}
			if (dp->neighbors == 8) {
				mj = 0;
				for (j = 0; j < dp->nrows; j++) {
					for (i = 0; i < dp->ncols; i++) {
						/* NE */
						k = (i + 1 == dp->ncols) ? 0 : i + 1;
						l = (!j) ? dp->nrows - 1 : j - 1;
						ml = l * dp->ncols;
						if (dp->oldcell[k + ml] ==
						    (int) (dp->oldcell[i + mj] + 1) % dp->states)
							dp->newcell[i + mj] = dp->oldcell[k + ml];
						/* SE */
						k = (i + 1 == dp->ncols) ? 0 : i + 1;
						l = (j + 1 == dp->nrows) ? 0 : j + 1;
						ml = l * dp->ncols;
						if (dp->oldcell[k + ml] ==
						    (int) (dp->oldcell[i + mj] + 1) % dp->states)
							dp->newcell[i + mj] = dp->oldcell[k + ml];
						/* SW */
						k = (!i) ? dp->ncols - 1 : i - 1;
						l = (j + 1 == dp->nrows) ? 0 : j + 1;
						ml = l * dp->ncols;
						if (dp->oldcell[k + ml] ==
						    (int) (dp->oldcell[i + mj] + 1) % dp->states)
							dp->newcell[i + mj] = dp->oldcell[k + ml];
						/* NW */
						k = (!i) ? dp->ncols - 1 : i - 1;
						l = (!j) ? dp->nrows - 1 : j - 1;
						ml = l * dp->ncols;
						if (dp->oldcell[k + ml] ==
						    (int) (dp->oldcell[i + mj] + 1) % dp->states)
							dp->newcell[i + mj] = dp->oldcell[k + ml];
					}
					mj += dp->ncols;
				}
			}
		} else if (dp->neighbors == 3 || dp->neighbors == 9 ||
			   dp->neighbors == 12) {
			for (j = 0; j < dp->nrows; j++) {
				for (i = 0; i < dp->ncols; i++) {
					if ((i + j) % 2) {	/* right */
						/* W */
						k = (!i) ? dp->ncols - 1 : i - 1;
						ml = mj;
						if (dp->oldcell[k + ml] ==
						    (int) (dp->oldcell[i + mj] + 1) % dp->states)
							dp->newcell[i + mj] = dp->oldcell[k + ml];
					} else {	/* left */
						/* E */
						k = (i + 1 == dp->ncols) ? 0 : i + 1;
						ml = mj;
						if (dp->oldcell[k + ml] ==
						    (int) (dp->oldcell[i + mj] + 1) % dp->states)
							dp->newcell[i + mj] = dp->oldcell[k + ml];
					}
					/* N */
					k = i;
					l = (!j) ? dp->nrows - 1 : j - 1;
					ml = l * dp->ncols;
					if (dp->oldcell[k + ml] ==
					    (int) (dp->oldcell[i + mj] + 1) % dp->states)
						dp->newcell[i + mj] = dp->oldcell[k + ml];
					/* S */
					k = i;
					l = (j + 1 == dp->nrows) ? 0 : j + 1;
					ml = l * dp->ncols;
					if (dp->oldcell[k + ml] ==
					    (int) (dp->oldcell[i + mj] + 1) % dp->states)
						dp->newcell[i + mj] = dp->oldcell[k + ml];
				}
				mj += dp->ncols;
			}
			if (dp->neighbors == 9 || dp->neighbors == 12) {
				mj = 0;
				for (j = 0; j < dp->nrows; j++) {
					for (i = 0; i < dp->ncols; i++) {
						/* NN */
						k = i;
						if (!j)
							l = dp->nrows - 2;
						else if (!(j - 1))
							l = dp->nrows - 1;
						else
							l = j - 2;
						ml = l * dp->ncols;
						if (dp->oldcell[k + ml] ==
						    (int) (dp->oldcell[i + mj] + 1) % dp->states)
							dp->newcell[i + mj] = dp->oldcell[k + ml];
						/* SS */
						k = i;
						if (j + 1 == dp->nrows)
							l = 1;
						else if (j + 2 == dp->nrows)
							l = 0;
						else
							l = j + 2;
						ml = l * dp->ncols;
						if (dp->oldcell[k + ml] ==
						    (int) (dp->oldcell[i + mj] + 1) % dp->states)
							dp->newcell[i + mj] = dp->oldcell[k + ml];
						/* NW */
						k = (!i) ? dp->ncols - 1 : i - 1;
						l = (!j) ? dp->nrows - 1 : j - 1;
						ml = l * dp->ncols;
						if (dp->oldcell[k + ml] ==
						    (int) (dp->oldcell[i + mj] + 1) % dp->states)
							dp->newcell[i + mj] = dp->oldcell[k + ml];
						/* NE */
						k = (i + 1 == dp->ncols) ? 0 : i + 1;
						l = (!j) ? dp->nrows - 1 : j - 1;
						ml = l * dp->ncols;
						if (dp->oldcell[k + ml] ==
						    (int) (dp->oldcell[i + mj] + 1) % dp->states)
							dp->newcell[i + mj] = dp->oldcell[k + ml];
						/* SW */
						k = (!i) ? dp->ncols - 1 : i - 1;
						l = (j + 1 == dp->nrows) ? 0 : j + 1;
						ml = l * dp->ncols;
						if (dp->oldcell[k + ml] ==
						    (int) (dp->oldcell[i + mj] + 1) % dp->states)
							dp->newcell[i + mj] = dp->oldcell[k + ml];
						/* SE */
						k = (i + 1 == dp->ncols) ? 0 : i + 1;
						l = (j + 1 == dp->nrows) ? 0 : j + 1;
						ml = l * dp->ncols;
						if (dp->oldcell[k + ml] ==
						    (int) (dp->oldcell[i + mj] + 1) % dp->states)
							dp->newcell[i + mj] = dp->oldcell[k + ml];
					}
					mj += dp->ncols;
				}
				if (dp->neighbors == 12) {
					mj = 0;
					for (j = 0; j < dp->nrows; j++) {
						for (i = 0; i < dp->ncols; i++) {
							if ((i + j) % 2) {	/* right */
								/* NNW */
								k = (!i) ? dp->ncols - 1 : i - 1;
								if (!j)
									l = dp->nrows - 2;
								else if (!(j - 1))
									l = dp->nrows - 1;
								else
									l = j - 2;
								ml = l * dp->ncols;
								if (dp->oldcell[k + ml] ==
								    (int) (dp->oldcell[i + mj] + 1) % dp->states)
									dp->newcell[i + mj] = dp->oldcell[k + ml];
								/* SSW */
								k = (!i) ? dp->ncols - 1 : i - 1;
								if (j + 1 == dp->nrows)
									l = 1;
								else if (j + 2 == dp->nrows)
									l = 0;
								else
									l = j + 2;
								ml = l * dp->ncols;
								if (dp->oldcell[k + ml] ==
								    (int) (dp->oldcell[i + mj] + 1) % dp->states)
									dp->newcell[i + mj] = dp->oldcell[k + ml];
								/* EE */
								k = (i + 1 == dp->ncols) ? 0 : i + 1;
								l = j;
								ml = mj;
								if (dp->oldcell[k + ml] ==
								    (int) (dp->oldcell[i + mj] + 1) % dp->states)
									dp->newcell[i + mj] = dp->oldcell[k + ml];
							} else {	/* left */
								/* NNE */
								k = (i + 1 == dp->ncols) ? 0 : i + 1;
								if (!j)
									l = dp->nrows - 2;
								else if (!(j - 1))
									l = dp->nrows - 1;
								else
									l = j - 2;
								ml = l * dp->ncols;
								if (dp->oldcell[k + ml] ==
								    (int) (dp->oldcell[i + mj] + 1) % dp->states)
									dp->newcell[i + mj] = dp->oldcell[k + ml];
								/* SSE */
								k = (i + 1 == dp->ncols) ? 0 : i + 1;
								if (j + 1 == dp->nrows)
									l = 1;
								else if (j + 2 == dp->nrows)
									l = 0;
								else
									l = j + 2;
								ml = l * dp->ncols;
								if (dp->oldcell[k + ml] ==
								    (int) (dp->oldcell[i + mj] + 1) % dp->states)
									dp->newcell[i + mj] = dp->oldcell[k + ml];
								/* WW */
								k = (!i) ? dp->ncols - 1 : i - 1;
								l = j;
								ml = mj;
								if (dp->oldcell[k + ml] ==
								    (int) (dp->oldcell[i + mj] + 1) % dp->states)
									dp->newcell[i + mj] = dp->oldcell[k + ml];
							}
						}
						mj += dp->ncols;
					}
				}
			}
		}
		mj = 0;
		for (j = 0; j < dp->nrows; j++) {
			for (i = 0; i < dp->ncols; i++)
				if (dp->oldcell[i + mj] != dp->newcell[i + mj]) {
					dp->oldcell[i + mj] = dp->newcell[i + mj];
					if (!addtolist(mi, i, j, dp->oldcell[i + mj])) {
						free_demon(MI_DISPLAY(mi), dp);
						return;
					}
				}
			mj += dp->ncols;
		}
		if (++dp->generation > MI_CYCLES(mi))
			init_demon(mi);
		dp->state = 0;
	} else {
		if (dp->ncells[dp->state])
			if (!draw_state(mi, dp->state)) {
				free_demon(MI_DISPLAY(mi), dp);
				return;
			}
		dp->state++;
	}
	if (dp->redrawing) {
		for (i = 0; i < REDRAWSTEP; i++) {
			if (dp->oldcell[dp->redrawpos]) {
				drawcell(mi, dp->redrawpos % dp->ncols, dp->redrawpos / dp->ncols,
					 dp->oldcell[dp->redrawpos]);
			}
			if (++(dp->redrawpos) >= dp->ncols * dp->nrows) {
				dp->redrawing = 0;
				break;
			}
		}
	}
}
Beispiel #18
0
void
draw_life1d(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	int         col;
	life1dstruct *lp;

	if (life1ds == NULL)
		return;
	lp = &life1ds[MI_SCREEN(mi)];
	if (lp->buffer == NULL)
		return;

	MI_IS_DRAWN(mi) = True;
	if (lp->busyLoop) {
		if (lp->busyLoop >= 250)
			lp->busyLoop = 0;
		else
			lp->busyLoop++;
		return;
	}
	if (lp->row == 0) {
		lp->repeating = 0;
		if (lp->screen_generation > MI_CYCLES(mi))
			init_life1d(mi);
		if (!lp->previousBuffer && lp->screen_generation > 1) {
			lp->previousBuffer = (unsigned char *) calloc(lp->ncols *
				lp->nrows, sizeof (unsigned char));
		}
		if (lp->previousBuffer) {
			(void) memcpy((char *) (lp->previousBuffer),
				(char *) (lp->buffer), lp->nrows * lp->ncols);
		}

		for (col = 0; col < lp->ncols; col++)
			if (lp->buffer[col] != lp->newcells[col + lp->border])
				drawcell(mi, col, 0, lp->newcells[col + lp->border]);
		(void) memcpy((char *) lp->buffer, (char *) (lp->newcells + lp->border),
			      lp->ncols);
	} else {
		for (col = 0; col < lp->ncols + 2 * lp->border; col++) {
			int         sum = 0, m;

			if (totalistic) {
				for (m = col - lp->r; m <= col + lp->r; m++)
					sum += lp->oldcells[m + maxradius];
			} else {
				int         pow_size = 1;

				for (m = col + lp->r; m >= col - lp->r; m--) {
					sum += lp->oldcells[m + maxradius] * pow_size;
					pow_size *= lp->k;
				}
			}
			lp->newcells[col] = (unsigned char) lp->nextstate[sum];
		}
		(void) memcpy((char *) (lp->oldcells + maxradius),
			  (char *) lp->newcells, lp->ncols + 2 * lp->border);

		for (col = 0; col < lp->ncols; col++) {
			if (lp->buffer[col + lp->row * lp->ncols] !=
			    lp->newcells[col + lp->border])
				drawcell(mi, col, lp->row, lp->newcells[col + lp->border]);
		}
		(void) memcpy((char *) (lp->buffer + lp->row * lp->ncols),
			    (char *) (lp->newcells + lp->border), lp->ncols);
		{
			int         temp = compare(mi);

			if (temp)
				lp->repeating += temp;
			else
				lp->repeating = 0;
		}
		lp->repeating += (lp->row == lp->nrows - 1) ?
			(lp->nrows - 1) * compare(mi) : 0;
	}
	if (lp->repeating >= 1) {
		XGCValues   gcv;

		gcv.stipple = lp->pixmaps[MAXSTATES - 1];
		gcv.fill_style = FillStippled;
		gcv.foreground = lp->black;
		XChangeGC(MI_DISPLAY(mi), lp->stippledGC,
			  GCStipple | GCFillStyle | GCForeground, &gcv);
		XFillRectangle(display, MI_WINDOW(mi), lp->stippledGC,
			       0, lp->yb + lp->ys * lp->row,
			       lp->width, lp->ys);
	}
	lp->row++;
	if (lp->repeating >= lp->nrows - 1) {
		if (lp->row < lp->nrows) {
			XSetForeground(display, lp->backGC, lp->black);
			XFillRectangle(display, MI_WINDOW(mi), lp->backGC,
				       0, lp->yb + lp->ys * lp->row,
			  lp->width, lp->height - lp->ys * lp->row - lp->yb);
		}
		lp->screen_generation = MI_CYCLES(mi);
		lp->row = lp->nrows;
	}
	if (lp->row >= lp->nrows) {
		lp->screen_generation++;
		lp->busyLoop = 1;
		lp->row = 0;
	}
}
Beispiel #19
0
int main(int argc, char *argv[]) {
	SDL_Event ev,az;
	SDL_Surface *screen;
	SDL_Surface *kep;
	SDL_TimerID id;
	FILE *fp;
	int x, y,click=0,clicktwo=0,aut=0,quit=0,gomb=0,egerx,egery,nothinghappened=1;
	cell cells[MAX][MAX]={0};

	kep=IMG_Load("sejt.png");
	if(!kep)
		fprintf(stderr, "Nem sikerult betolteni a kepfajlt!\n");

	/* SDL inicializálása és ablak megnyitása */
	SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
	screen=SDL_SetVideoMode(MAX*MERET+KERET*2+100, MAX*MERET+KERET*2-100, 0, SDL_FULLSCREEN);
	if (!screen) {
		fprintf(stderr, "Nem sikerult megnyitni az ablakot!\n");
		exit(1);
	} 
	SDL_WM_SetCaption("Game Of Life", "Game Of Life");
	
	SDL_FillRect(screen, NULL, 0x433e3f);
	boxColor(screen,KERET/3,KERET/3,MAX*MERET+KERET*2-KERET/3,MAX*MERET+KERET*2-KERET/3,KERETSZIN);

	drawcell(cells,screen,kep);



	while(!quit)
	{
		boxColor(screen, MAX*MERET+KERET*2+10,KERET+5,MAX*MERET+KERET*2+90,KERET+40,0xFFDFD2FF);
		boxColor(screen, MAX*MERET+KERET*2+14,KERET+9,MAX*MERET+KERET*2+86,KERET+36,0xE5C8BDFF);
		stringRGBA(screen, MAX*MERET+KERET*2+20, KERET+19, "Leptetes", 255, 255, 255, 255);

		boxColor(screen, MAX*MERET+KERET*2+10,KERET+5+HEZAG,MAX*MERET+KERET*2+90,KERET+40+HEZAG,0xFFDFD2FF);
		boxColor(screen, MAX*MERET+KERET*2+14,KERET+9+HEZAG,MAX*MERET+KERET*2+86,KERET+36+HEZAG,0xE5C8BDFF);
		if(aut==0)
			stringRGBA(screen, MAX*MERET+KERET*2+15, KERET+69, "Szimul.be", 255, 255, 255, 255);
		else
			stringRGBA(screen, MAX*MERET+KERET*2+15, KERET+69, "Szimul.ki", 255, 255, 255, 255);

		boxColor(screen, MAX*MERET+KERET*2+10,KERET+5+HEZAG*2,MAX*MERET+KERET*2+90,KERET+40+HEZAG*2,0xFFDFD2FF);
		boxColor(screen, MAX*MERET+KERET*2+14,KERET+9+HEZAG*2,MAX*MERET+KERET*2+86,KERET+36+HEZAG*2,0xE5C8BDFF);
		stringRGBA(screen, MAX*MERET+KERET*2+26, KERET+19+HEZAG*2, "Torles", 255, 255, 255, 255);

		boxColor(screen, MAX*MERET+KERET*2+10,KERET+5+HEZAG*3,MAX*MERET+KERET*2+90,KERET+40+HEZAG*3,0xFFDFD2FF);
		boxColor(screen, MAX*MERET+KERET*2+14,KERET+9+HEZAG*3,MAX*MERET+KERET*2+86,KERET+36+HEZAG*3,0xE5C8BDFF);
		stringRGBA(screen, MAX*MERET+KERET*2+27, KERET+19+HEZAG*3, "Kilovo", 255, 255, 255, 255);

		filledCircleColor(screen,MAX*MERET+2*KERET+80,9,8,0xFFDFD2FF);
		filledCircleColor(screen,MAX*MERET+2*KERET+80,9,6,0xE5C8BDFF);
		stringRGBA(screen,MAX*MERET+KERET*2+77,6,"X",255,255,255,255);
		
		SDL_Flip(screen);

		
		while(SDL_PollEvent(&ev)){
			switch(ev.type)
			{
				/*case SDL_KEYDOWN:
				switch(ev.key.keysym.sym)
				{
				case SDLK_s:
				mentes(cells);		   
				break;
				case SDLK_l:
				fp=fopen("save.txt","r");

				for(y=0;y<MAX;y++)
				for(x=0;x<MAX;x++)
				fscanf(fp,"%d ",&cells[y][x].alive);

				fclose (fp);

				drawcell(cells,screen,kep);
				SDL_Flip(screen);
				break;
				}
				break;*/

			case SDL_MOUSEBUTTONDOWN:
				if(ev.button.button==SDL_BUTTON_LEFT)
				{
					if(ev.button.x<=MAX*MERET+KERET){
						egerx=holazeger(ev.button.x);
						egery=holazeger(ev.button.y);

						if(cells[egery][egerx].alive==1)
							cells[egery][egerx].alive=0;
						else
							cells[egery][egerx].alive=1;
					}

					else if(incircle(ev.button.x,ev.button.y,MAX*MERET+2*KERET+80,9,8))
						quit=1;

					else if((ev.button.x<=MAX*MERET+KERET*2+90 && ev.button.x>=MAX*MERET+KERET*2+10) && (ev.button.y<=KERET+40 && ev.button.y>=KERET+5))//egyes lépés
					{
						round(cells);

					}
					else if((ev.button.x<=MAX*MERET+KERET*2+90 && ev.button.x>=MAX*MERET+KERET*2+10) && (ev.button.y<=KERET+90 && ev.button.y>=KERET+55))//szimulálás
					{
						if(aut==0)
							aut=1;
						else aut=0;	
					}
					else if((ev.button.x<=MAX*MERET+KERET*2+90 && ev.button.x>=MAX*MERET+KERET*2+10) && (ev.button.y<=KERET+40+HEZAG*2 && ev.button.y>=KERET+5+HEZAG*2))//egyes lépés
					{
						for(y=0;y<MAX;y++)
							for(x=0;x<MAX;x++)
								cells[y][x].alive=0;
					}
					else if((ev.button.x<=MAX*MERET+KERET*2+90 && ev.button.x>=MAX*MERET+KERET*2+10) && (ev.button.y<=KERET+40+HEZAG*3 && ev.button.y>=KERET+5+HEZAG*3))//egyes lépés
					{
						fp=fopen("save.txt","r");

						for(y=0;y<MAX;y++)
							for(x=0;x<MAX;x++)
								fscanf(fp,"%d ",&cells[y][x].alive);

						fclose (fp);

						drawcell(cells,screen,kep);
						SDL_Flip(screen);
					}
					drawcell(cells,screen,kep);
					SDL_Flip(screen);
				}
				break;

			case SDL_MOUSEBUTTONUP:
				if(ev.button.button==SDL_BUTTON_LEFT)
				{
					click=0;
					clicktwo=0;
				}
				break;

			case SDL_QUIT:
				quit=1;
				break;
			}
		}

		if(aut)
		{
			SDL_Delay(100);
			round(cells);
			drawcell(cells,screen,kep);
			SDL_Flip(screen);
		}


	}


	SDL_FreeSurface(kep);
	SDL_Quit();
	exit(0);
	return 0;
}
Beispiel #20
0
void
init_voters(ModeInfo * mi)
{
	int         size = MI_SIZE(mi);
	int         i, col, row, colrow;
	voterstruct *vp;

	if (voters == NULL) {
		if ((voters = (voterstruct *) calloc(MI_NUM_SCREENS(mi),
					      sizeof (voterstruct))) == NULL)
			return;
	}
	vp = &voters[MI_SCREEN(mi)];

	vp->generation = 0;
	if (!vp->first) {	/* Genesis of democracy */
		icon_width = donkey_width;
		icon_height = donkey_height;
		if (!init_list(vp)) {
			free_voters(vp);
			return;
		}
		for (i = 0; i < BITMAPS; i++) {
			logo[i].width = icon_width;
			logo[i].height = icon_height;
			logo[i].bytes_per_line = (icon_width + 7) / 8;
		}
	} else			/* Exterminate all free thinking individuals */
		flush_list(vp);
	if (MI_IS_FULLRANDOM(mi)) {
		vp->vertical = (Bool) (LRAND() & 1);
	} else {
		vp->vertical = vertical;
	}
	vp->width = MI_WIDTH(mi);
	vp->height = MI_HEIGHT(mi);

	for (i = 0; i < NEIGHBORKINDS; i++) {
		if (neighbors == plots[i]) {
			vp->neighbors = neighbors;
			break;
		}
		if (i == NEIGHBORKINDS - 1) {
#if 0
			vp->neighbors = plots[NRAND(NEIGHBORKINDS)];
			vp->neighbors = (LRAND() & 1) ? 4 : 8;
#else
			vp->neighbors = 8;
#endif
			break;
		}
	}

	if (vp->neighbors == 6) {
		int nccols, ncrows, sides;

		if (!vp->vertical) {
			vp->height = MI_WIDTH(mi);
			vp->width = MI_HEIGHT(mi);
		}
		if (vp->width < 8)
			vp->width = 8;
		if (vp->height < 8)
			vp->height = 8;
		if (size < -MINSIZE)
			vp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(vp->width, vp->height) /
				      MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE;
		else if (size < MINSIZE) {
			if (!size)
				vp->ys = MAX(MINSIZE, MIN(vp->width, vp->height) / MINGRIDSIZE);
			else
				vp->ys = MINSIZE;
		} else
			vp->ys = MIN(size, MAX(MINSIZE, MIN(vp->width, vp->height) /
					       MINGRIDSIZE));
		vp->xs = vp->ys;
		vp->pixelmode = True;
		nccols = MAX(vp->width / vp->xs - 2, 2);
		ncrows = MAX(vp->height / vp->ys - 1, 4);
		vp->ncols = nccols / 2;
		vp->nrows = 2 * (ncrows / 4);
		vp->xb = (vp->width - vp->xs * nccols) / 2 + vp->xs / 2;
		vp->yb = (vp->height - vp->ys * (ncrows / 2) * 2) / 2 +
			vp->ys - 2;
		for (sides = 0; sides < 6; sides++) {
			if (vp->vertical) {
				vp->shape.hexagon[sides].x =
					(vp->xs - 1) * hexagonUnit[sides].x;
				vp->shape.hexagon[sides].y =
					((vp->ys - 1) * hexagonUnit[sides].y /
					2) * 4 / 3;
			} else {
				vp->shape.hexagon[sides].y =
					(vp->xs - 1) * hexagonUnit[sides].x;
				vp->shape.hexagon[sides].x =
					((vp->ys - 1) * hexagonUnit[sides].y /
					2) * 4 / 3;
			}
		}
	} else if (vp->neighbors == 4 || vp->neighbors == 8) {
		if (vp->width < 2)
			vp->width = 2;
		if (vp->height < 2)
			vp->height = 2;
		if (size == 0 ||
		    MINGRIDSIZE * size > vp->width || MINGRIDSIZE * size > vp->height) {
			if (vp->width > MINGRIDSIZE * icon_width &&
			    vp->height > MINGRIDSIZE * icon_height) {
				vp->pixelmode = False;
				vp->xs = icon_width;
				vp->ys = icon_height;
			} else {
				vp->pixelmode = True;
				vp->xs = vp->ys = MAX(MINSIZE, MIN(vp->width, vp->height) /
						      MINGRIDSIZE);
			}
		} else {
			vp->pixelmode = True;
			if (size < -MINSIZE)
				vp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(vp->width, vp->height) /
				      MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE;
			else if (size < MINSIZE)
				vp->ys = MINSIZE;
			else
				vp->ys = MIN(size, MAX(MINSIZE, MIN(vp->width, vp->height) /
						       MINGRIDSIZE));
			vp->xs = vp->ys;
		}
		vp->ncols = MAX(vp->width / vp->xs, 2);
		vp->nrows = MAX(vp->height / vp->ys, 2);
		vp->xb = (vp->width - vp->xs * vp->ncols) / 2;
		vp->yb = (vp->height - vp->ys * vp->nrows) / 2;
	} else {		/* TRI */
		int orient, sides;

		if (!vp->vertical) {
			vp->height = MI_WIDTH(mi);
			vp->width = MI_HEIGHT(mi);
		}
		if (vp->width < 2)
			vp->width = 2;
		if (vp->height < 2)
			vp->height = 2;
		if (size < -MINSIZE)
			vp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(vp->width, vp->height) /
				      MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE;
		else if (size < MINSIZE) {
			if (!size)
				vp->ys = MAX(MINSIZE, MIN(vp->width, vp->height) / MINGRIDSIZE);
			else
				vp->ys = MINSIZE;
		} else
			vp->ys = MIN(size, MAX(MINSIZE, MIN(vp->width, vp->height) /
					       MINGRIDSIZE));
		vp->xs = (int) (1.52 * vp->ys);
		vp->pixelmode = True;
		vp->ncols = (MAX(vp->width / vp->xs - 1, 2) / 2) * 2;
		vp->nrows = (MAX(vp->height / vp->ys - 1, 2) / 2) * 2;
		vp->xb = (vp->width - vp->xs * vp->ncols) / 2 + vp->xs / 2;
		vp->yb = (vp->height - vp->ys * vp->nrows) / 2 + vp->ys / 2;
		for (orient = 0; orient < 2; orient++) {
			for (sides = 0; sides < 3; sides++) {
				if (vp->vertical) {
					vp->shape.triangle[orient][sides].x =
						(vp->xs - 2) * triangleUnit[orient][sides].x;
					vp->shape.triangle[orient][sides].y =
						(vp->ys - 2) * triangleUnit[orient][sides].y;
				} else {
					vp->shape.triangle[orient][sides].y =
						(vp->xs - 2) * triangleUnit[orient][sides].x;
					vp->shape.triangle[orient][sides].x =
						(vp->ys - 2) * triangleUnit[orient][sides].y;
				}
			}
		}
	}

	vp->npositions = vp->ncols * vp->nrows;
	if (vp->arr != NULL)
		free(vp->arr);
	if ((vp->arr = (char *) calloc(vp->npositions, sizeof (char))) == NULL) {
		free_voters(vp);
		return;
	}

	/* Play G-d with these numbers */
	vp->nparties = MI_COUNT(mi);
	if (vp->nparties < MINPARTIES || vp->nparties > BITMAPS)
		vp->nparties = NRAND(BITMAPS - MINPARTIES + 1) + MINPARTIES;
	if (vp->pixelmode)
		vp->nparties = 2;

	vp->busyLoop = 0;
	MI_CLEARWINDOW(mi);
	vp->painted = False;

	for (i = 0; i < BITMAPS; i++)
		vp->number_in_party[i] = 0;

	for (row = 0; row < vp->nrows; row++)
		for (col = 0; col < vp->ncols; col++) {
			colrow = col + row * vp->ncols;
			if (vp->nparties == 2)
				i = (NRAND(vp->nparties) + 2) % BITMAPS;
			else
				i = NRAND(vp->nparties);
			vp->arr[colrow] = (char) i;
			drawcell(mi, col, row, (unsigned long) (MI_NPIXELS(mi) * i / BITMAPS),
				 i, False);
			vp->number_in_party[i]++;
		}
}
Beispiel #21
0
void
draw_voters(ModeInfo * mi)
{
	int         i, spineless_dude, neighbor_direction;
	int         spineless_col, spineless_row;
	int         new_opinion, old_opinion;
	cellstruct  info;
	voterstruct *vp;

	if (voters == NULL)
		return;
	vp = &voters[MI_SCREEN(mi)];
	if (vp->first == NULL)
		return;

	MI_IS_DRAWN(mi) = True;
	vp->painted = True;
	if (vp->busyLoop) {
		if (vp->busyLoop >= 5000)
			vp->busyLoop = 0;
		else
			vp->busyLoop++;
		return;
	}
	for (i = 0; i < BITMAPS; i++)
		if (vp->number_in_party[i] == vp->npositions) {		/* The End of the WORLD */
			init_voters(mi);	/* Create a more interesting planet */
		}
	spineless_dude = NRAND(vp->npositions);
	neighbor_direction = NRAND(vp->neighbors) * 360 / vp->neighbors;
	spineless_col = spineless_dude % vp->ncols;
	spineless_row = spineless_dude / vp->ncols;
	old_opinion = vp->arr[spineless_dude];
	new_opinion = neighbors_opinion(vp, spineless_col, spineless_row,
					neighbor_direction);
	if (old_opinion != new_opinion) {
		vp->number_in_party[old_opinion]--;
		vp->number_in_party[new_opinion]++;
		vp->arr[spineless_dude] = new_opinion;
		info.kind = new_opinion;
		info.age = (old_opinion - new_opinion);
		if (info.age == 2)
			info.age = -1;
		if (info.age == -2)
			info.age = 1;
		info.age *= (FACTOR * MI_NPIXELS(mi)) / 3;
		info.col = spineless_col;
		info.row = spineless_row;
		if (MI_NPIXELS(mi) > 2) {
			advanceColors(mi, spineless_col, spineless_row);
			if (!addto_list(vp, info)) {
				free_voters(vp);
				return;
			}
		}
		drawcell(mi, spineless_col, spineless_row,
			 (MI_NPIXELS(mi) + info.age / FACTOR +
		  (MI_NPIXELS(mi) * new_opinion / BITMAPS)) % MI_NPIXELS(mi),
			 new_opinion, True);
	} else if (MI_NPIXELS(mi) > 2)
		advanceColors(mi, -1, -1);
	vp->generation++;
	for (i = 0; i < BITMAPS; i++)
		if (vp->number_in_party[i] == vp->npositions) {		/* The End of the WORLD */
			vp->busyLoop = 1;
			refresh_voters(mi);
		}
}
Beispiel #22
0
static int zoom1(int x, int y)
{				/* called by Input_pointer */
    int top, bottom, left, right;
    int n, row, col;
    int nrows, ncols;
    struct Cell_head cellhd;
    int mag;
    double magnification();
    double north, south, east, west;

    if (In_view(pick_view = VIEW_MAP1, x, y)) {
	main_view = VIEW_MAP1;
	zoom_view = VIEW_MAP1_ZOOM;
	target_flag = 0;
    }
    else if (In_view(pick_view = VIEW_MAP2, x, y)) {
	if (!pick_view->cell.configured)
	    return 0;		/* ignore the mouse event */
	main_view = VIEW_MAP2;
	zoom_view = VIEW_MAP2_ZOOM;
	target_flag = 1;
    }
    else if (In_view(pick_view = VIEW_MAP1_ZOOM, x, y)) {
	if (!pick_view->cell.configured)
	    return 0;		/* ignore the mouse event */
	main_view = VIEW_MAP1;
	zoom_view = VIEW_MAP1_ZOOM;
	target_flag = 0;
    }
    else if (In_view(pick_view = VIEW_MAP2_ZOOM, x, y)) {
	if (!pick_view->cell.configured)
	    return 0;		/* ignore the mouse event */
	main_view = VIEW_MAP2;
	zoom_view = VIEW_MAP2_ZOOM;
	target_flag = 1;
    }
    else
	return 0;		/* ignore the mouse event */
    if (!pick_view->cell.configured)
	return 0;		/* just to be sure */
    /*
     * make sure point is within edges of image as well
     */
    if (x <= pick_view->cell.left)
	return 0;
    if (x >= pick_view->cell.right)
	return 0;
    if (y <= pick_view->cell.top)
	return 0;
    if (y >= pick_view->cell.bottom)
	return 0;


    /*
     * ok, erase menu messages
     */
    Menu_msg("");

    /* determine magnification of zoom */
    if (zoom_view->cell.configured) {
	if (zoom_view == pick_view)
	    mag = floor(magnification(zoom_view) + 1.0) + .1;
	else
	    mag = ceil(magnification(zoom_view)) + .1;
    }
    else {
	mag = floor(magnification(main_view) + 1.0) + .1;
    }
    if (!ask_magnification(&mag))
	return 1;
    /* 
     * Determine the the zoom window (ie, cellhd)
     */

    G_copy(&cellhd, &main_view->cell.head, sizeof(cellhd));
    cellhd.ns_res = main_view->cell.ns_res / mag;
    cellhd.ew_res = main_view->cell.ew_res / mag;
    cellhd.cols = (cellhd.east - cellhd.west) / cellhd.ew_res;
    cellhd.rows = (cellhd.north - cellhd.south) / cellhd.ns_res;


    /* convert x,y to col,row */

    col = view_to_col(pick_view, x);
    east = col_to_easting(&pick_view->cell.head, col, 0.5);
    col = easting_to_col(&cellhd, east);

    row = view_to_row(pick_view, y);
    north = row_to_northing(&pick_view->cell.head, row, 0.5);
    row = northing_to_row(&cellhd, north);

    ncols = zoom_view->ncols;
    nrows = zoom_view->nrows;


    n = cellhd.cols - col;
    if (n > col)
	n = col;
    if (n + n + 1 >= ncols) {
	n = ncols / 2;
	if (n + n + 1 >= ncols)
	    n--;
    }
    left = col - n;
    right = col + n;

    n = cellhd.rows - row;
    if (n > row)
	n = row;
    if (n + n + 1 >= nrows) {
	n = nrows / 2;
	if (n + n + 1 >= nrows)
	    n--;
    }
    top = row - n;
    bottom = row + n;


    north = row_to_northing(&cellhd, top, 0.0);
    west = col_to_easting(&cellhd, left, 0.0);
    south = row_to_northing(&cellhd, bottom, 1.0);
    east = col_to_easting(&cellhd, right, 1.0);


    cellhd.north = north;
    cellhd.south = south;
    cellhd.east = east;
    cellhd.west = west;

    cellhd.rows = (cellhd.north - cellhd.south) / cellhd.ns_res;
    cellhd.cols = (cellhd.east - cellhd.west) / cellhd.ew_res;

    /*
     * Outline the zoom window on the main map
     * Turn previous one to grey.
     */
    if (zoom_view->cell.configured) {
	R_standard_color(GREY);
	Outline_cellhd(main_view, &zoom_view->cell.head);
    }
    R_standard_color(RED);
    Outline_cellhd(main_view, &cellhd);


    /*
     * zoom
     */
    if (target_flag)
	select_target_env();
    G_copy(&zoom_view->cell.head, &cellhd, sizeof(cellhd));
    Configure_view(zoom_view, pick_view->cell.name, pick_view->cell.mapset,
		   pick_view->cell.ns_res, pick_view->cell.ew_res);
    drawcell(zoom_view);
    select_current_env();
    display_points(1);

    return 1;			/* pop back */
}
Beispiel #23
0
int main(int argc, char *argv[])
{
    char mapset[GMAPSET_MAX];
    char name[GNAME_MAX];
    char *camera;

    struct GModule *module;
    struct Option *group_opt, *map_opt, *target_map_opt;
    struct Cell_head cellhd;
    int ok;
    int nfiles;

    /* must run in a term window */
    G_putenv("GRASS_UI_TERM", "1");

    G_gisinit(argv[0]);

    module = G_define_module();
    module->keywords = _("imagery, orthorectify");
    module->description = _("Creates control points on an image "
			    "to be ortho-rectified.");

    group_opt = G_define_option();
    group_opt->key = "group";
    group_opt->type = TYPE_STRING;
    group_opt->required = YES;
    group_opt->multiple = NO;
    group_opt->description = _("Name of imagery group");

    map_opt = G_define_standard_option(G_OPT_R_MAP);
    map_opt->required = NO;
    map_opt->description = _("Name of image to be rectified which will "
			     "be initially drawn on screen");

    target_map_opt = G_define_standard_option(G_OPT_R_MAP);
    target_map_opt->key = "target";
    target_map_opt->required = NO;
    target_map_opt->description = _("Name of a map from target mapset which "
				    "will be initially drawn on screen");

    if (G_parser(argc, argv))
	exit(EXIT_FAILURE);


    G_suppress_masking();	/* need to do this for target location */

    camera = (char *)G_malloc(40 * sizeof(char));
    strcpy(name, group_opt->answer);

    interrupt_char = G_intr_char();
    tempfile1 = G_tempfile();
    tempfile2 = G_tempfile();
    tempfile_dot = G_tempfile();
    tempfile_dot2 = G_tempfile();
    tempfile_win = G_tempfile();
    tempfile_win2 = G_tempfile();
    cell_list = G_tempfile();
    vect_list = G_tempfile();
    group_list = G_tempfile();
    digit_points = G_tempfile();

    if (R_open_driver() != 0)
	G_fatal_error(_("No graphics device selected"));

    /* get group ref */
    strcpy(group.name, name);
    if (!I_find_group(group.name))
	G_fatal_error(_("Group [%s] not found"), group.name);

    /* get the group ref */
    I_get_group_ref(group.name, &group.group_ref);
    nfiles = group.group_ref.nfiles;

    /* write block files to block list file */
    prepare_group_list();

    /** look for camera info  for this group**/
    G_suppress_warnings(1);
    if (!I_get_group_camera(group.name, camera))
	G_fatal_error(_("No camera reference file selected for group [%s]"),
		group.name);

    if (!I_get_cam_info(camera, &group.camera_ref))
	G_fatal_error(_("Bad format in camera file for group [%s]"),
			group.name);

    G_suppress_warnings(0);

    /* get initial camera exposure station, if any */
    if (!(ok = I_find_initial(group.name)))
	G_warning(_("No initial camera exposure station for group [%s]"),
		group.name);

    if (ok && (!I_get_init_info(group.name, &group.camera_exp)) )
	G_warning(_("Bad format in initial camera exposure station for group [%s]"),
		  group.name);

    /* get target info and environment */
    G_suppress_warnings(1);
    get_target();
    find_target_files();
    G_suppress_warnings(0);

    /* read group reference points, if any */
    G_suppress_warnings(1);
    if (!I_get_ref_points(group.name, &group.photo_points)) {
	G_suppress_warnings(0);
	if (group.photo_points.count == 0)
	    G_fatal_error(_("No photo points for group [%s]"), group.name);
	else if (group.ref_equation_stat == 0)
	    G_fatal_error(_("Poorly placed photo points for group [%s]"),
			  group.name);
    }
    G_suppress_warnings(0);

    /* determine transformation equation */
    Compute_ref_equation();

    /* read group control points, format: image x,y,cfl; target E,N,Z */
    G_suppress_warnings(1);
    if (!I_get_con_points(group.name, &group.control_points))
	group.control_points.count = 0;
    G_suppress_warnings(0);

    /* compute image coordinates of photo control points */

    /********
    I_convert_con_points (group.name, &group.control_points, 
			 &group.control_points, group.E12, group.N12);
    ********/

    /* determine transformation equation */
    G_message(_("Computing equations ..."));
    if (group.control_points.count > 0)
	Compute_ortho_equation();


    /*   signal (SIGINT, SIG_IGN); */
    /*   signal (SIGQUIT, SIG_IGN); */

    select_current_env();
    Init_graphics();
    display_title(VIEW_MAP1);
    select_target_env();
    display_title(VIEW_MAP2);
    select_current_env();

    Begin_curses();
    G_set_error_routine(error);

    /*
       #ifdef SIGTSTP
       signal (SIGTSTP, SIG_IGN);
       #endif
     */

    /* Set image to be rectified */
    if (map_opt->answer) {
	char *ms;

	ms = G_find_cell(map_opt->answer, "");
	if (ms == NULL) {
	    G_fatal_error(_("Raster map <%s> not found"), map_opt->answer);
	}
	strcpy(name, map_opt->answer);
	strcpy(mapset, ms);
	if (G_get_cellhd(name, mapset, &cellhd) < 0) {
	    G_fatal_error(_("Unable to read raster header of <%s>"), map_opt->answer);
	}
    }
    else {
	/* ask user for group file to be displayed */
	do {
	    if (!choose_groupfile(name, mapset))
		quit(EXIT_SUCCESS);
	    /* display this file in "map1" */
	} while (G_get_cellhd(name, mapset, &cellhd) < 0);
    }

    G_adjust_window_to_box(&cellhd, &VIEW_MAP1->cell.head, VIEW_MAP1->nrows,
			   VIEW_MAP1->ncols);
    Configure_view(VIEW_MAP1, name, mapset, cellhd.ns_res, cellhd.ew_res);

    drawcell(VIEW_MAP1);

    /* Set target map if specified */
    if (target_map_opt->answer) {
	char *ms;

	select_target_env();
	ms = G_find_cell(target_map_opt->answer, "");
	if (ms == NULL) {
	    G_fatal_error(_("Raster map <%s> not found"),
			  target_map_opt->answer);
	}
	strcpy(name, target_map_opt->answer);
	strcpy(mapset, ms);
	if (G_get_cellhd(name, mapset, &cellhd) < 0) {
	    G_fatal_error(_("Unable to read raster header of <%s>"),
			  target_map_opt->answer);
	}

	G_adjust_window_to_box(&cellhd, &VIEW_MAP2->cell.head,
			       VIEW_MAP2->nrows, VIEW_MAP2->ncols);
	Configure_view(VIEW_MAP2, name, mapset, cellhd.ns_res, cellhd.ew_res);

	drawcell(VIEW_MAP2);

	from_flag = 1;
	from_keyboard = 0;
	from_screen = 1;
    }

    display_conz_points(1);

    Curses_clear_window(PROMPT_WINDOW);

    /* determine initial input method. */
    setup_digitizer();
    if (use_digitizer) {
	from_digitizer = 1;
	from_keyboard = 0;
	from_flag = 1;
    }

    /* go do the work */
    driver();

    quit(EXIT_SUCCESS);
}