/** * Recolorizes the mesh (to be called by the GUI when softness changes; enforces serial entry) * @param soft The function to call to determine the softness of a given point */ void SurfaceMesh::recolorize( double ( *soft )( double, double, double ) ) { if ( material == DIRT ) { return; } for ( int i = 0; i < numVertices; ++i ) { softnesses[ i ] = soft( c4fn3fv3f[ i * 10 + 7 ], c4fn3fv3f[ i * 10 + 8 ], c4fn3fv3f[ i * 10 + 9 ] ); if (material == ROCK) { hueToRGB<GLfloat>( c4fn3fv3f + i * 10, ROCK_COLOR * ( 1.0 - softnesses[ i ] )); } if (material == MORE_ROCK) { hueToRGB<GLfloat>( c4fn3fv3f + i * 10, OTHER_ROCK_COLOR * ( 1.0 - softnesses[ i ] )); } // hueToRGB<GLfloat>( c4fn3fv3f + i * 10, 0.6666666666666667 * ( 1.0 - softnesses[ i ] ) ); } needUpdate = true; }
static double fmcp(double lambda, double kappa, double b, double w, double r) { if (fabs(b + r / w) > lambda / kappa) return(b + r / w); else { if (w > kappa) return(soft(lambda / w, b + r / w) / (1 - kappa / w)); else return(0); } }
void Fl_Value_Input_Spin::increment_cb() { if (!mouseobj) return; delta+=deltadir; double v; switch (drag) { case 3: v = increment(value(), deltadir*100); break; case 2: v = increment(value(), deltadir*10); break; default:v = increment(value(), deltadir); break; } v = round(v); handle_drag(soft()?softclamp(v):clamp(v)); }
void play() { char str[256],str2[256],log[81],done,doub,dh,split_card,suggestion ,*YouWereDealt="\1n\1k\0015 You \1n\1m were dealt: %s\r\n" ,*UserWasDealt="\1n\1m\1h%s\1n\1m was dealt: %s\r\n" ,*YourHand="\1n\1k\0015 You \1n\1m (%2d) %s" ,*UserHand="\1n\1m\1h%-25s \1n\1m(%2d) %s" ,*DealerHand="\1n\1hDealer \1n\1m(%2d) " ,*Bust="\1n\1r\1hBust\1n\r\n" ,*Natural="\1g\1h\1iNatural " ,*Three7s="\1r\1h\1iThree 7's " ,*Blackjack="\1n\0011\1k Blackjack! \1n\r\n" ,*TwentyOne="\1n\0012\1k Twenty-one \1n\r\n"; int h,i,j,file; uint max; long val; time_t start,now; struct tm* tm; sprintf(str,"MESSAGE.%d",node_num); /* remove message if waiting */ if(fexist(str)) remove(str); getgamedat(0); if(node[node_num-1]) { getgamedat(1); node[node_num-1]=0; putgamedat(); getgamedat(0); } if(total_players && misc&INPLAY) { bputs("\r\n\1hWaiting for end of hand (^A to abort)...\1n"); start=now=time(NULL); getgamedat(0); while(total_players && misc&INPLAY) { if((i=inkey(0))!=0) { /* if key was hit */ if(i==1) { /* if ctrl-a */ bputs("\r\n"); return; } } /* return */ mswait(100); getgamedat(0); now=time(NULL); if(now-start>300) { /* only wait up to 5 minutes */ bputs("\r\ntimeout\r\n"); return; } } bputs("\r\n"); } getgamedat(1); node[node_num-1]=user_number; putgamedat(); if(!total_players) shuffle(); else listplayers(); sprintf(str,"\1n\1m\1h%s \1n\1m%s\r\n",user_name,joined()); putallnodemsg(str); while(1) { aborted=0; #if DEBUG debugline("top of loop"); #endif if(autoplay) lncntr=0; bprintf(ShoeStatus,cur_card,total_decks*52); if(cur_card>(total_decks*52)-(total_players*10)-10 && lastplayer()) shuffle(); getgamedat(1); misc&=~INPLAY; status[node_num-1]=BET; node[node_num-1]=user_number; putgamedat(); bprintf("\r\n\1n\1cYou have \1h%s\1n\1ck credits\r\n" ,ultoac(credits/1024L,str)); if(credits<min_bet/1024) { bprintf("\1n\1cMinimum bet: \1h%uk\r\n",min_bet); bputs("\1n\1r\1hCome back when you have more credits.\r\n"); break; } if(credits/1024L>(ulong)max_bet) max=max_bet; else max=credits/1024L; sprintf(str,"\r\nBet amount (in kilobytes) or ~Quit [%u]: " ,ibet<credits/1024L ? ibet : credits/1024L); chat(); mnemonics(str); if(autoplay && keyhit()) autoplay=0; if(autoplay) i=ibet; else i=getnum(max); if(i==-1) /* if user hit ^C or 'Q' */ break; bputs("\r\n"); if(i) /* if user entered a value */ bet[0]=i; else /* if user hit enter */ bet[0]=ibet<credits/1024L ? ibet : credits/1024L; if(bet[0]<min_bet) { bprintf("\1n\1cMinimum bet: \1h%uk\r\n",min_bet); bputs("\1n\1r\1hCome back when you're ready to bet more.\r\n"); break; } ibet=bet[0]; getgamedat(0); /* to get all new arrivals */ sprintf(str,"\1m\1h%s\1n\1m bet \1n\1h%u\1n\1mk\r\n",user_name,bet[0]); putallnodemsg(str); pc[0]=2; /* init player's 1st hand to 2 cards */ for(i=1;i<MAX_HANDS;i++) /* init player's other hands to 0 cards */ pc[i]=0; hands=1; /* init total player's hands to 1 */ getgamedat(1); /* first come first serve to be the */ for(i=0;i<total_nodes;i++) /* dealer in control of sync */ if(node[i] && status[i]==SYNC_D) break; if(i==total_nodes) { #if DEBUG debugline("syncdealer"); #endif syncdealer(); } /* all players meet here */ else { /* first player is current after here */ #if DEBUG debugline("syncplayer"); #endif syncplayer(); } /* game is closed (INPLAY) at this point */ #if DEBUG debugline("waitturn 1"); #endif waitturn(); getnodemsg(); /* Initial deal card #1 */ getcarddat(); player[0][0]=card[cur_card++]; putcarddat(); sprintf(str,YouWereDealt,cardstr(card[cur_card-1])); if(!symbols) strip_symbols(str); bputs(str); sprintf(str,UserWasDealt,user_name,cardstr(card[cur_card-1])); putallnodemsg(str); if(lastplayer()) { getcarddat(); dealer[0]=card[cur_card++]; dc=1; putcarddat(); } nextplayer(); #if DEBUG debugline("waitturn 2"); #endif waitturn(); getnodemsg(); getcarddat(); /* Initial deal card #2 */ player[0][1]=card[cur_card++]; putcarddat(); sprintf(str,YouWereDealt,cardstr(card[cur_card-1])); if(!symbols) strip_symbols(str); bputs(str); sprintf(str,UserWasDealt,user_name,cardstr(card[cur_card-1])); putallnodemsg(str); if(lastplayer()) { getcarddat(); dealer[1]=card[cur_card++]; dc=2; putcarddat(); } nextplayer(); #if DEBUG debugline("waitturn 3"); #endif waitturn(); getnodemsg(); getcarddat(); for(i=0;i<hands;i++) { if(autoplay) lncntr=0; done=doub=0; while(!done && pc[i]<MAX_CARDS && cur_card<total_decks*52) { h=hand(player[i],pc[i]); str[0]=0; for(j=0;j<pc[i];j++) { strcat(str,cardstr(player[i][j])); strcat(str," "); } j=bstrlen(str); while(j++<19) strcat(str," "); if(h>21) { strcat(str,Bust); sprintf(str2,YourHand,h,str); if(!symbols) strip_symbols(str2); bputs(str2); sprintf(str2,UserHand,user_name,h,str); putallnodemsg(str2); break; } if(h==21) { if(pc[i]==2) { /* blackjack */ if(player[i][0].suit==player[i][1].suit) strcat(str,Natural); strcat(str,Blackjack); } else { if(player[i][0].value==7 && player[i][1].value==7 && player[i][2].value==7) strcat(str,Three7s); strcat(str,TwentyOne); } sprintf(str2,YourHand,h,str); if(!symbols) strip_symbols(str2); bputs(str2); sprintf(str2,UserHand,user_name,h,str); putallnodemsg(str2); // fdelay(500); break; } strcat(str,"\r\n"); sprintf(str2,YourHand,h,str); if(!symbols) strip_symbols(str2); bputs(str2); sprintf(str2,UserHand,user_name,h,str); putallnodemsg(str2); if(doub) break; sprintf(str,"\1n\1hDealer\1n\1m card up: %s\r\n" ,cardstr(dealer[1])); if(!symbols) strip_symbols(str); bputs(str); if(tutor) { if(pc[i]==2) split_card=pair(player[i],pc[i]); else split_card=0; if(split_card==A || (split_card==9 && (dealer[1].value<7 || (dealer[1].value>7 && dealer[1].value<10))) || split_card==8 || (split_card==7 && dealer[1].value<9) || (split_card==6 && dealer[1].value<7) || (split_card==4 && dealer[1].value==5) || (split_card && split_card<4 && dealer[1].value<8)) suggestion='P'; else if(soft(player[i],pc[i])) { if(h>18) suggestion='S'; else if(pc[i]==2 && ((h==18 && dealer[1].value>3 && dealer[1].value<7) || (h==17 && dealer[1].value>2 && dealer[1].value<7) || (h>13 && dealer[1].value>3 && dealer[1].value<7) || (h==12 && dealer[1].value>4 && dealer[1].value<7))) suggestion='D'; else suggestion='H'; } else { /* hard */ if(h>16 || (h>13 && dealer[1].value<7) || (h==12 && dealer[1].value>3 && dealer[1].value<7)) suggestion='S'; else if(pc[i]==2 && (h==11 || (h==10 && dealer[1].value<10) || (h==9 && dealer[1].value<7))) suggestion='D'; else suggestion='H'; } } if(tutor==1) suggest(suggestion); strcpy(str,"\r\n~Hit"); strcpy(tmp,"H\r"); if(bet[i]+ibet<=credits/1024L && pc[i]==2) { strcat(str,", ~Double"); strcat(tmp,"D"); } if(bet[i]+ibet<=credits/1024L && pc[i]==2 && hands<MAX_HANDS && player[i][0].value==player[i][1].value) { strcat(str,", ~Split"); strcat(tmp,"S"); } strcat(str,", or [Stand]: "); chat(); mnemonics(str); if(autoplay && keyhit()) autoplay=0; if(autoplay) { lncntr=0; bputs("\r\n"); strcpy(str,stand()); bputs(str); putallnodemsg(str); done=1; } else switch(getkeys(tmp,0)) { case 'H': /* hit */ if(tutor==2 && suggestion!='H') wrong(suggestion); strcpy(str,hit()); bputs(str); putallnodemsg(str); getcarddat(); player[i][pc[i]++]=card[cur_card++]; putcarddat(); break; case 'D': /* double down */ if(tutor==2 && suggestion!='D') wrong(suggestion); strcpy(str,doubit()); bputs(str); putallnodemsg(str); getcarddat(); player[i][pc[i]++]=card[cur_card++]; putcarddat(); doub=1; bet[i]+=ibet; break; case 'S': /* split */ if(tutor==2 && suggestion!='P') wrong(suggestion); strcpy(str,split()); bputs(str); putallnodemsg(str); player[hands][0]=player[i][1]; getcarddat(); player[i][1]=card[cur_card++]; player[hands][1]=card[cur_card++]; putcarddat(); pc[hands]=2; bet[hands]=ibet; hands++; break; case CR: if(tutor==2 && suggestion!='S') wrong(suggestion); strcpy(str,stand()); bputs(str); putallnodemsg(str); done=1; break; } } } if(lastplayer()) { /* last player plays the dealer's hand */ getcarddat(); while(hand(dealer,dc)<17 && dc<MAX_CARDS && cur_card<total_decks*52) dealer[dc++]=card[cur_card++]; putcarddat(); } nextplayer(); #if DEBUG debugline("waitturn 4"); #endif waitturn(); getnodemsg(); if(firstplayer()==node_num) { strcpy(str,"\1n\0014\1h Final \1n\r\n"); bputs(str); putallnodemsg(str); } getcarddat(); dh=hand(dealer,dc); /* display dealer's hand */ sprintf(str,DealerHand,dh); for(i=0;i<dc;i++) { strcat(str,cardstr(dealer[i])); strcat(str," "); } i=bstrlen(str); while(i++<50) /* was 50 */ strcat(str," "); if(dh>21) { strcat(str,Bust); if(!symbols) strip_symbols(str); bputs(str); } else if(dh==21) { if(dc==2) { /* blackjack */ if(dealer[0].suit==dealer[1].suit) strcat(str,Natural); strcat(str,Blackjack); } else { /* twenty-one */ if(dc==3 && dealer[0].value==7 && dealer[1].value==7 && dealer[2].value==7) strcat(str,Three7s); strcat(str,TwentyOne); } if(!symbols) strip_symbols(str); bputs(str); } else { if(!symbols) strip_symbols(str); bprintf("%s\r\n",str); } for(i=0;i<hands;i++) { /* display player's hand(s) */ h=hand(player[i],pc[i]); str[0]=0; for(j=0;j<pc[i];j++) { strcat(str,cardstr(player[i][j])); strcat(str," "); } j=bstrlen(str); while(j++<19) strcat(str," "); if(logit) { now=time(NULL); tm=localtime(&now); sprintf(log,"%02d%02d%02d.log" /* log winnings */ ,tm->tm_mon+1,tm->tm_mday,tm->tm_year%100); if((file=nopen(log,O_RDONLY))!=-1) { read(file,tmp,filelength(file)); tmp[filelength(file)]=0; val=atol(tmp); close(file); } else val=0L; if((file=nopen(log,O_WRONLY|O_CREAT|O_TRUNC))==-1) { bprintf("error opening %s\r\n",log); return; } } if(h<22 && (h>dh || dh>21 /* player won */ || (h==21 && pc[i]==2 && dh==21 && dh>2))) { /* blackjack */ j=bet[i]; /* and dealer got 21 */ if(h==21 && /* natural blackjack or three 7's */ ((player[i][0].value==7 && player[i][1].value==7 && player[i][2].value==7) || (pc[i]==2 && player[i][0].suit==player[i][1].suit))) j*=2; else if(h==21 && pc[i]==2) /* regular blackjack */ j*=1.5; /* blackjack pays 1 1/2 to 1 */ sprintf(tmp,"\1n\1h\1m\1iWon!\1n\1h %u\1n\1mk",j); strcat(str,tmp); credits+=j*1024L; val-=j*1024L; moduserdat(); } else if(h<22 && h==dh) strcat(str,"\1n\1hPush"); else { strcat(str,"\1nLost"); credits-=bet[i]*1024L; val+=bet[i]*1024L; moduserdat(); } if(logit) { sprintf(tmp,"%ld",val); write(file,tmp,strlen(tmp)); close(file); } /* close winning log */ strcat(str,"\1n\r\n"); sprintf(str2,YourHand,h,str); if(!symbols) strip_symbols(str2); bputs(str2); sprintf(str2,UserHand,user_name,h,str); putallnodemsg(str2); } nextplayer(); if(!lastplayer()) { #if DEBUG debugline("lastplayer waitturn"); #endif waitturn(); nextplayer(); } #if DEBUG debugline("end of loop"); #endif getnodemsg(); } getgamedat(1); node[node_num-1]=0; putgamedat(); sprintf(str,"\1n\1m\1h%s \1n\1m%s\r\n",user_name,left()); putallnodemsg(str); }
static double flasso(double lambda, double b, double w, double r) { return(soft(lambda / w, b + r / w)); }
int Fl_Value_Input_Spin::handle(int event) { double v; int olddelta; int mx = Fl::event_x(); int my = Fl::event_y(); int sxx = x(), syy = y(), sww = w(), shh = h(); sxx += sww - buttonssize(); sww = buttonssize(); if(!indrag && ( !sldrag || !((mx>=sxx && mx<=(sxx+sww)) && (my>=syy && my<=(syy+shh)))) ) { indrag=0; switch(event) { case FL_PUSH: case FL_DRAG: sldrag=1; break; case FL_FOCUS: input.take_focus(); break; case FL_UNFOCUS: redraw(); break; default: sldrag=0; } input.type(step()>=1.0 ? FL_INT_INPUT : FL_FLOAT_INPUT); return input.handle(event); } switch (event) { case FL_PUSH: // if (!step()) goto DEFAULT; iy = my; ix = mx; drag = Fl::event_button(); handle_push(); indrag=1; mouseobj=1; Fl::add_timeout(.5, repeat_callback, this); delta=0; if(Fl::event_inside(sxx,syy,sww,shh/2)) { deltadir=1; } else if (Fl::event_inside(sxx,syy+shh/2,sww,shh/2)) { deltadir=-1; } else { deltadir=0; } increment_cb(); redraw(); return 1; case FL_DRAG: if(mouseobj) { mouseobj=0; Fl::remove_timeout(repeat_callback, this); } // if (!step()) goto DEFAULT; olddelta=delta; delta = - (Fl::event_y()-iy); if ((delta>5) || (delta<-5) ) { deltadir=((olddelta-delta)>0)?-1:(((olddelta-delta)<0)?1:0); } else { deltadir=0; delta = olddelta;} switch (drag) { case 3: v = increment(value(), deltadir*100); break; case 2: v = increment(value(), deltadir*10); break; default:v = increment(value(), deltadir); break; } v = round(v); handle_drag(soft()?softclamp(v):clamp(v)); indrag=1; return 1; case FL_RELEASE: if(mouseobj) { Fl::remove_timeout(repeat_callback, this); } // if (!step()) goto DEFAULT; indrag=0; delta=0; deltadir=0; mouseobj=0; handle_release(); redraw(); return 1; case FL_FOCUS: indrag=0; return input.take_focus(); default: indrag=0; input.type(step()>=1.0 ? FL_INT_INPUT : FL_FLOAT_INPUT); return 1; } }
int Fl_Spin::handle(int event) { double v; int olddelta; int mx = Fl::event_x(); int my = Fl::event_y(); int sxx = x(), syy = y(), sww = w(), shh = h(); switch (event) { case FL_PUSH: // if (!step()) goto DEFAULT; iy = my; ix = mx; drag = Fl::event_button(); handle_push(); indrag=1; mouseobj=1; Fl::add_timeout(.5, repeat_callback, this); delta=0; if(Fl::event_inside(sxx,syy,sww,shh/2)) { deltadir=1; } else if (Fl::event_inside(sxx,syy+shh/2,sww,shh/2)) { deltadir=-1; } else { deltadir=0; } increment_cb(); redraw(); return 1; case FL_DRAG: if(mouseobj) { mouseobj=0; Fl::remove_timeout(repeat_callback, this); } // if (!step()) goto DEFAULT; olddelta=delta; delta = - (Fl::event_y()-iy); if ((delta>5) || (delta<-5) ) { deltadir=((olddelta-delta)>0)?-1:(((olddelta-delta)<0)?1:0); } else { deltadir=0; delta = olddelta;} switch (drag) { case 3: v = increment(value(), deltadir*100); break; case 2: v = increment(value(), deltadir*10); break; default:v = increment(value(), deltadir); break; } v = round(v); handle_drag(soft()?softclamp(v):clamp(v)); indrag=1; return 1; case FL_RELEASE: if(mouseobj) { Fl::remove_timeout(repeat_callback, this); } // if (!step()) goto DEFAULT; indrag=0; delta=0; deltadir=0; mouseobj=0; handle_release(); redraw(); return 1; default: indrag=0; return Fl_Valuator::handle(event); } }