/* make a random new object, returning pointer */ Object* create_object(int itemlevel) { Object* newObject; int r; int ok = false; while (! ok) { newObject = ((Object*) checkmalloc(sizeof(Object))); r= random_range(135); if (r < 20) make_thing(newObject,-1); else if (r < 40) make_food(newObject,-1); else if (r < 50) make_scroll(newObject,-1); else if (r < 60) make_potion(newObject,-1); else if (r < 70) make_weapon(newObject,-1); else if (r < 80) make_armor(newObject,-1); else if (r < 90) make_shield(newObject,-1); else if (r < 100) make_stick(newObject,-1); else if (r < 110) make_boots(newObject,-1); else if (r < 120) make_cloak(newObject,-1); else if (r < 130) make_ring(newObject,-1); else make_artifact(newObject,-1); /* not ok if object is too good for level, or if unique and already made */ /* 1/100 chance of finding object if too good for level */ ok = ((newObject->uniqueness < UNIQUE_MADE) && ((newObject->level < itemlevel+random_range(3)) || (random_range(100)==23))); if (!ok) { free_obj( newObject, true ); } } if (newObject->uniqueness == UNIQUE_UNMADE) Objects[newObject->id].uniqueness=UNIQUE_MADE; return(newObject); }
int main(int argc, char const *argv[]) { int data[]={1,2,3,4,5,6,7}; int size=sizeof(data)/sizeof(int); llink list=NULL; int i; for(i=0;i<size;i++) insert_list(&list,data[i]); if(if_has_ring(list)){ printf("Has ring!\n"); }else{ printf("No ring.\n"); } make_ring(list,find_item(list,1)); if(if_has_ring(list)){ printf("Has ring!\n"); }else{ printf("No ring.\n"); } return 0; }
/* gain for an item */ void acquire(int blessing) { char otype; int index,id = ABORT; pob newthing; if (blessing < 0) { index = random_item(); if (index == ABORT) mprint("You feel fortunate."); else { print1("Smoke drifts out of your pack.... "); print2("Destroyed: "); nprint2(itemid(Player.possessions[index])); morewait(); dispose_lost_objects(1,Player.possessions[index]); } } else { newthing = ((pob) checkmalloc(sizeof(objtype))); /* DAG this assignment looks unneccessary */ newthing->id = -1; if (gamestatusp(CHEATED)) print1("Acquire which kind of item: !?][}{)/=%%\\& "); else print1("Acquire which kind of item: !?][}{)/=%%\\ "); otype = mgetc(); switch (otype) { case (POTION&0xff): if (blessing > 0) id = itemlist(POTIONID,NUMPOTIONS); else id = random_range(NUMPOTIONS); if (id < 0) print2("You feel stupid."); else make_potion(newthing,id); break; case (SCROLL&0xff): if (blessing > 0) id = itemlist(SCROLLID,NUMSCROLLS); else id = random_range(NUMSCROLLS); if (id < 0) print2("You feel stupid."); else make_scroll(newthing,id); break; case (RING&0xff): if (blessing > 0) id = itemlist(RINGID,NUMRINGS); else id = random_range(NUMRINGS); if (id < 0) print2("You feel stupid."); else make_ring(newthing,id); break; case (STICK&0xff): if (blessing > 0) id = itemlist(STICKID,NUMSTICKS); else id = random_range(NUMSTICKS); if (id < 0) print2("You feel stupid."); else make_stick(newthing,id); break; case (ARMOR&0xff): if (blessing > 0) id = itemlist(ARMORID,NUMARMOR); else id = random_range(NUMARMOR); if (id < 0) print2("You feel stupid."); else make_armor(newthing,id); break; case (SHIELD&0xff): if (blessing > 0) id = itemlist(SHIELDID,NUMSHIELDS); else id = random_range(NUMSHIELDS); if (id < 0) print2("You feel stupid."); else make_shield(newthing,id); break; case (WEAPON&0xff): if (blessing > 0) id = itemlist(WEAPONID,NUMWEAPONS); else id = random_range(NUMWEAPONS); if (id < 0) print2("You feel stupid."); else make_weapon(newthing,id); break; case (BOOTS&0xff): if (blessing > 0) id = itemlist(BOOTID,NUMBOOTS); else id = random_range(NUMBOOTS); if (id < 0) print2("You feel stupid."); else make_boots(newthing,id); break; case (CLOAK&0xff): if (blessing > 0) id = itemlist(CLOAKID,NUMCLOAKS); else id = random_range(NUMCLOAKS); if (id < 0) print2("You feel stupid."); else make_cloak(newthing,id); break; case (FOOD&0xff): if (blessing > 0) id = itemlist(FOODID,NUMFOODS); else id = random_range(NUMFOODS); if (id < 0) print2("You feel stupid."); else make_food(newthing,id); break; case (THING&0xff): if (blessing > 0) id = itemlist(THINGID,NUMTHINGS); else id = random_range(NUMTHINGS); if (id < 0) print2("You feel stupid."); else make_thing(newthing,id); break; case (ARTIFACT&0xff): if (gamestatusp(CHEATED)) id = itemlist(ARTIFACTID,NUMARTIFACTS); else id = -1; if (id < 0) print2("You feel stupid."); else make_artifact(newthing,id); break; default: print2("You feel stupid."); } xredraw(); if (id != ABORT) { if (blessing > 0) { newthing->known = 2; Objects[id].known = 1; } newthing->used = FALSE; gain_item(newthing); } else { /* DAG newthing allocated but was not freed... was YA memory leak */ /* use free() rather than free_obj() since newthing not initialized */ free( (char *) newthing ); } } }
void ring_filter(const float *img, const int rows, const int cols, int * x_pos,int *y_pos,int *width, float *response) // Algorithm based on: // Robust real-time pupil tracking in highly off-axis images // Lech Świrski Andreas Bulling Neil A. Dodgson // Computer Laboratory, University of Cambridge, United Kingdom // Eye Tracking Research & Applications 2012 { point_t img_size = {rows,cols}; int min_h = 6; int max_h = 50; int h, i, j; float best_response = -10000; point_t best_pos ={0,0}; int best_h = 0; int h_step = 4; int step = 5; for (h = min_h; h < max_h; h+=h_step) { ring_t ring = make_ring(h); // printf("inner factor%f outer.factor %f center %i \n",ring.inner.f,ring.outer.f,(int)ring.w_o_half ); for (i=0; i<rows-ring.w_o; i +=step) { for (j=0; j<cols-ring.w_o; j+=step) { // printf("|%2.0f",img[i * cols + j]); point_t offset = {i,j}; float response = ring.outer.f*area(img,img_size,ring.outer.s,ring.outer.e,offset) +ring.middle.f*area(img,img_size,ring.middle.s,ring.middle.e,offset) +ring.inner.f*area(img,img_size,ring.inner.s,ring.inner.e,offset); // printf("| %5.2f ",response); if(response > best_response){ // printf("!"); best_response = response; best_pos = (point_t){i,j}; // printf("%i %i", (int)best_pos.r,(int)best_pos.c); best_h = ring.w_o; } } // printf("\n"); } } // now we refine the search at pixel resolution This hole part can be commented out if needed point_t window_lower = {MAX(0,best_pos.r-step+1),MAX(0,best_pos.c-step+1)}; point_t window_upper = {MIN(img_size.r,best_pos.r+step),MIN(img_size.c,best_pos.c+step)}; for (h = best_h-h_step+1; h < best_h+h_step; h+=1) { ring_t ring = make_ring(h); // printf("inner factor%f outer.factor %f center %i \n",ring.inner.f,ring.outer.f,(int)ring.w_o_half ); for (i=window_lower.r; i<MIN(window_upper.r,img_size.r-ring.w_o); i +=1) { for (j=window_lower.c; j<MIN(window_upper.c,img_size.c-ring.w_o); j +=1) { // printf("|%2.0f",img[i * cols + j]); point_t offset = {i,j}; float response = ring.outer.f*area(img,img_size,ring.outer.s,ring.outer.e,offset) +ring.middle.f*area(img,img_size,ring.middle.s,ring.middle.e,offset) +ring.inner.f*area(img,img_size,ring.inner.s,ring.inner.e,offset); // printf("| %5.2f ",response); // ikiuprintf("| %5.2f ",response); if(response > best_response){ // printf("!"); best_response = response; best_pos = (point_t){i,j}; // printf("%i %i", (int)best_pos.r,(int)best_pos.c); best_h = ring.w_o; } } // printf("\n"); } } // point_t start = {0,0}; // point_t end = {1,1}; // printf("FULL IMG SUM %1.0f\n",img[(img_size.r-1) * img_size.c + (img_size.c-1)] ); // printf("AREA:%f\n",area(img,img_size,start,end,(point_t){0,0})); *x_pos = (int)best_pos.r; *y_pos = (int)best_pos.c; *width = best_h; *response = best_response; }