Ejemplo n.º 1
0
static bool cohen_sutherland_clip(int* X1, int* Y1, int* X2, int* Y2)
{
    int x1 = *X1;
    int y1 = *Y1;
    int x2 = *X2;
    int y2 = *Y2;

    const int clipX1 = a__screen.clipX;
    const int clipX2 = a__screen.clipX2;
    const int clipY1 = a__screen.clipY;
    const int clipY2 = a__screen.clipY2;

    #define A__OUT_LEFT  1
    #define A__OUT_RIGHT 2
    #define A__OUT_TOP   4
    #define A__OUT_DOWN  8

    #define outcode(o, x, y)                  \
    {                                         \
        if(x < clipX1) o |= A__OUT_LEFT;         \
        else if(x >= clipX2) o |= A__OUT_RIGHT;  \
                                              \
        if(y < clipY1) o |= A__OUT_TOP;          \
        else if(y >= clipY2) o |= A__OUT_DOWN;   \
    }

    #define solvex() (x1 + (x1 - x2) * (y - y1) / (y1 - y2))
    #define solvey() (y1 + (y1 - y2) * (x - x1) / (x1 - x2))

    while(true) {
        int outcode1 = 0;
        int outcode2 = 0;

        outcode(outcode1, x1, y1);
        outcode(outcode2, x2, y2);

        if((outcode1 | outcode2) == 0) {
            *X1 = x1;
            *Y1 = y1;
            *X2 = x2;
            *Y2 = y2;

            return true;
        } else if(outcode1 & outcode2) {
            return false;
        } else {
            int x, y;
            const int outcode = outcode1 ? outcode1 : outcode2;

            if(outcode & A__OUT_LEFT) {
                x = clipX1;
                y = solvey();
            } else if(outcode & A__OUT_RIGHT) {
                x = clipX2 - 1;
                y = solvey();
            } else if(outcode & A__OUT_TOP) {
                y = clipY1;
                x = solvex();
            } else { // outcode & A__OUT_DOWN
                y = clipY2 - 1;
                x = solvex();
            }

            if(outcode == outcode1) {
                x1 = x;
                y1 = y;
            } else {
                x2 = x;
                y2 = y;
            }
        }
    }
}
Ejemplo n.º 2
0
void menu_option(unsigned char number)
{
  FILE *savefile;
  FILE *optionfile;
  char filename[12], savepos;
  char oldinv; //holds options.inverted when entering setup
  int move_count;
  struct postype pos, newpos;

  switch (number)
  {
	case 100: //avcount=avtotal/avcount;
				 if (g_path.move[0].f>0)
					showstats(nodes,g_seconds,g_depth,g_path); break;
	case 101: rival_help(70); break;
	case 119: rival_help(19); break;
	case 120: options.chessset++; if (options.chessset==3) options.chessset=0; break;
	case 109: options.whiteplayer=USER;
				 options.blackplayer=USER;
				 if (game.movenum>1)
				 {
					 game.movenum=game.movenum-1;
					 pos=game.firstpos;
					 for (move_count=1; move_count<=game.movenum; move_count++)
					 {
						  alter(&pos,game.previous_moves[move_count],&newpos);
						  pos=newpos;
					 }
					 current=newpos;
				 } else
				 {
					 game.movenum=0;
					 current=game.firstpos;
				 }
				 movepointer=game.movenum;
				 no_more_openings=FALSE;
				 break;
	case 110: if (game.lastmove==0)
				 {
					 current=game.firstpos;
				 } else
				 {
					 pos=game.firstpos;
					 for (move_count=1; move_count<=game.lastmove; move_count++)
					 {
						 alter(&pos, game.previous_moves[move_count], &newpos);
						 pos=newpos;
					 }
					 current=newpos;
				 }
				 game.movenum=game.lastmove;
				 movepointer=game.movenum;
				 break;
	case 111: current=game.firstpos; game.movenum=0;
				 movepointer=game.movenum;
				 no_more_openings=FALSE;
				 options.whiteplayer=USER;
				 options.blackplayer=USER;
				 break;
	case 112: if ((savepos=get_savepos('w'))!=0)
				 {
					 strcpy(filename,"RIVAL\0");
					 if (savepos<10)
					 {
						 filename[5]=savepos+48;
						 filename[6]='\0';
					 } else
					 {
						 filename[5]=savepos/10+48;
						 filename[6]=savepos%10+48;
						 filename[7]='\0';
					 }
					 strcat(filename,".SAV");
					 if (confirmation("SAVE GAME"))
					 {
						 savefile=fopen(filename,"w");
						 if (savefile!=NULL)
						 {
							  savefiledata(savefile);
						 } else // if savefile!=NULL
						 {
							  printf("ERROR! SAVE FAILED");
						 }
						 fclose(savefile);
					 } // if confirmation
				 }
				 break;
	case 113: if ((savepos=get_savepos('r'))!=0)
		  {
		     strcpy(filename,"RIVAL\0");
		     if (savepos<10)
		     {
			filename[5]=savepos+48;
			filename[6]='\0';
		     } else
		     {
			filename[5]=savepos/10+48;
			filename[6]=savepos%10+48;
			filename[7]='\0';
		     }
		     strcat(filename, ".SAV");
		     if (((savefile=fopen(filename,"r"))!=NULL) && (confirmation("LOAD GAME")))
		     {
			readfiledata(savefile);
			if (game.movenum==0)
			{
			   current=game.firstpos;
			   movepointer=0;
			} else
			{
			   pos=game.firstpos;
			   for (move_count=1; move_count<=game.movenum; move_count++)
			   {
			     alter(&pos, game.previous_moves[move_count], &newpos);
			     pos=newpos;
			   }
			   current=newpos;
			}
			FLAGnewstart=1;
			movepointer=game.movenum;
		     } //movepointer=game.movenum;
		     fclose(savefile);
		  }
		  break;
	case 107: variant_select(); break;
	case 106: time_select(); break;
	case 127: options.deep_thought=!options.deep_thought; break;
	case 133: break;
	case 118: options.library=!options.library; break;
	case 108: if (game.movenum<game.lastmove)
				 {
					 game.movenum=game.movenum+1;
					 pos=current;
					 alter(&pos,game.previous_moves[game.movenum],&current);
				 }
				 movepointer=game.movenum;
				 break;
	case 103: oldinv=options.inverted;
		  options.inverted=0;
		  enter_setup();
		  options.inverted=oldinv;
		  break;
	case 117: options.analysis=!options.analysis; break;
	case 102: options.inverted=!options.inverted; break;
	case 104: options.whiteplayer=!options.whiteplayer;
				 if (options.whiteplayer==PROGRAM)
					  if (current.mvr=='w')
						  FLAGnewstart=1;
				 break;
	case 105: options.blackplayer=!options.blackplayer;
				 if (options.blackplayer==PROGRAM)
					  if (current.mvr=='b')
						  FLAGnewstart=1;
				 break;
	case 114: if (confirmation("NEW GAME")) initialise(startbrd); no_more_openings=FALSE; break;
	case 115: iconmenu=1; break;
	case 116: iconmenu=0; break;
	case 129: switch (options.sensitivity)
				 {
					 case LOWSENS : options.sensitivity=MEDSENS; break;
					 case MEDSENS : options.sensitivity=HISENS; break;
					 case  HISENS : options.sensitivity=LOWSENS; break;
				 }
				 break;
	case 124: options=doptions; break;
	case 125: optionfile=fopen("options.riv","w");
				 fwrite(&options, sizeof(struct optiontype), 1, optionfile);
				 fclose(optionfile);
				 break;
	case 121: if (options.so<7) options.so+=1; else options.so=0; break;
	case 122: if (options.wo<35) options.wo+=5; else options.wo=0;
				 if (options.wo==options.bo) if (options.wo<35) options.wo+=5; else options.wo=0;
				 break;
	case 123: if (options.bo<35) options.bo+=5; else options.bo=0;
				 if (options.wo==options.bo) if (options.bo<35) options.bo+=5; else options.bo=0;
				 break;
	case 128: solvey(); break;
	case 130: break;
	case 148: options.game=0; break;
	case 126: options.pieceslide=!options.pieceslide; break;
	case 131: if (confirmation("QUIT RIVAL"))
				 {
					 SetTextMode();
					 printf("See you later!");
					 quit=1;
				 }
				 break;
	case 200: if (movepointer>0) movepointer--; break;
	case 201: if (movepointer<game.movenum) movepointer++; break;
	default: break;
  }
}