int equipmentUpdater::upgradeEquipment(int equipID,int isHaveRuby,int isHavaSap) { int ret = equipID; UpgradeInfo* pui = smashHeroDatabaseUtil::getInstance()->getUpgradeInfoForItemID(equipID); timeval psv; gettimeofday(&psv, NULL); unsigned long int seed = psv.tv_sec * 1000 + psv.tv_usec / 1000; srand(seed); int roll = rand()%100+1; // CCLOG(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::rolled : %i with succedrate :%i",roll,pui->succeedRate); if (roll<=(pui->succeedRate+pui->succeedRate*isHaveRuby)) { ret = upgrade(equipID); } else { //srand(unsigned(time(0))); roll = rand()%100+1; if (isHavaSap==1) { ret = equipID; } else { if (roll<pui->destoryRate) { ret = 0; } else if(roll<pui->destoryRate+pui->degradeRate) { ret = degrade(equipID); } } } delete pui; pui = NULL; return ret; }
void initColorTab(){//fonction qui initialise et rempli le tableau de dégradé couleursDegrade=malloc(100*sizeof(couleur)); //---------------------------------------- /*ici on utilise addCouleur pour chaque couleur que l'on souhaite utiliser pour définir le dégradé final*/ addCouleur(bleuFonce); addCouleur(jaune); addCouleur(rouge); //------------------------------------------ tabCouleur=malloc(((nbCouleur-1)*nbCouleurDegrade)*sizeof(couleur)); for(int i=0;i<nbCouleur-1;i++){ for(int j=0;j<nbCouleurDegrade;j++){ tabCouleur[nbCouleurDegrade*i+j]=degrade(couleursDegrade[i],couleursDegrade[i+1],(float)j/(float)127); } } free(couleursDegrade); }
int main() { int largeur = 300; int hauteur = 300; t_image img; //img.pixels = LireImagePGM("guadalest.pgm", &largeur, &hauteur); img.hauteur = hauteur; img.largeur = largeur; img.pixels = creerImage(largeur, hauteur); degrade(img); negatif(img); //miroir(img, 1); ecrireImagePGM("truc.pgm", img); afficherImage("truc.pgm"); free(img.pixels); return(0); }
void simulate(struct state *s) { int i, j; struct tile (* t) [MAX_HEIGHT] = s->grid.tiles; int enemy_pop [MAX_PLAYER]; int my_pop [MAX_PLAYER]; int need_to_reeval = 0; /* increment time */ s->time++; /* per tile events */ for(i=0; i<s->grid.width; ++i) { for(j=0; j<s->grid.height; ++j) { /* mines ownership */ if (t[i][j].cl == mine){ int k; int owner = NEUTRAL; for(k=0; k<DIRECTIONS; ++k) { int di = dirs[k].i; int dj = dirs[k].j; if( i+di >= 0 && i+di < s->grid.width && j+dj >= 0 && j+dj < s->grid.height && is_inhabitable (t[i+di][j+dj].cl) ) { int pl = t[i+di][j+dj].pl; if (owner == NEUTRAL) owner = pl; else if (owner != pl && pl != NEUTRAL) owner = -1; } } if (owner != -1) t[i][j].pl = owner; else t[i][j].pl = NEUTRAL; if (t[i][j].pl != NEUTRAL) s->country[owner].gold += 1; } /* fight */ int p; int total_pop = 0; for(p=0; p<MAX_PLAYER; ++p){ my_pop[p] = t[i][j].units[p][citizen]; total_pop += my_pop[p]; } int defender_dmg = 0; for(p=0; p<MAX_PLAYER; ++p){ enemy_pop[p] = total_pop - my_pop[p]; int dmg = rnd_round( (float)enemy_pop[p] * my_pop[p] / total_pop ); t[i][j].units[p][citizen] = MAX(my_pop[p] - dmg, 0); if (t[i][j].pl == p) defender_dmg = dmg; } /* burning cities */ if (defender_dmg > 2.0 * MAX_POP * ATTACK && is_a_city(t[i][j].cl)) { if (rand() % 1 == 0){ need_to_reeval = 1; degrade (&s->grid, i, j); } } /* determine ownership */ if (is_inhabitable(t[i][j].cl)){ t[i][j].pl = NEUTRAL; for(p=0; p<MAX_PLAYER; ++p){ if (t[i][j].units[p][citizen] > t[i][j].units[t[i][j].pl][citizen]) { t[i][j].pl = p; } } } if (is_a_city(t[i][j].cl)) { /* population growth */ int owner = t[i][j].pl; int pop = t[i][j].units[owner][citizen]; float fnpop = (float) pop * growth(t[i][j].cl); int npop = rnd_round(fnpop); npop = MIN(npop, MAX_POP); /* death */ //npop = npop - rnd_round(0.01*pow(pop,1.5)); //npop = npop - rnd_round(1.0e-20 * pow(2.0,pop)); //npop = MAX(npop, 0); t[i][j].units[owner][citizen] = npop; } } } /* migration */ int k, di, dj, p; int i_start, i_end, i_inc; int j_start, j_end, j_inc; if(rand()%2 == 0) { i_start = 0; i_end = s->grid.width; i_inc = 1; } else { i_start = s->grid.width-1; i_end = -1; i_inc = -1; } if(rand()%2 == 0) { j_start = 0; j_end = s->grid.height; j_inc = 1; } else { j_start = s->grid.height-1; j_end = -1; j_inc = -1; } for(i=i_start; i!=i_end; i+=i_inc) { for(j=j_start; j!=j_end; j+=j_inc) { for(p=0; p<MAX_PLAYER; ++p){ int initial_pop = t[i][j].units[p][citizen]; int k_shift = rand() % DIRECTIONS; for(k=0; k<DIRECTIONS; ++k) { di = dirs[(k + k_shift) % DIRECTIONS].i; dj = dirs[(k + k_shift) % DIRECTIONS].j; if( i+di >= 0 && i+di < s->grid.width && j+dj >= 0 && j+dj < s->grid.height && is_inhabitable (t[i+di][j+dj].cl) ) { int pop = t[i][j].units[p][citizen]; int dcall = MAX(0, s->fg[p].call[i+di][j+dj] - s->fg[p].call[i][j]); if (pop > 0) { int dpop = rnd_round (MOVE * initial_pop + CALL_MOVE * dcall * initial_pop); dpop = MIN(dpop, pop); dpop = MIN(dpop, MAX_POP - t[i+di][j+dj].units[p][citizen]); t[i+di][j+dj].units[p][citizen] += dpop; t[i][j].units[p][citizen] -= dpop; } } } } } } /* determine ownership again */ for(i=0; i<s->grid.width; ++i) { for(j=0; j<s->grid.height; ++j) { if (is_inhabitable(t[i][j].cl)){ t[i][j].pl = NEUTRAL; for(p=0; p<MAX_PLAYER; ++p){ if (t[i][j].units[p][citizen] > t[i][j].units[t[i][j].pl][citizen]) { t[i][j].pl = p; } } } } } /* Kings reevaluate the map */ if(need_to_reeval) { for(i=0; i<s->kings_num; ++i) { king_evaluate_map(&s->king[i], &s->grid, s->dif); } } /* give gold to AI on hard difficulties */ int add_gold = 0; switch(s->dif) { case dif_hard: add_gold = 1; break; case dif_hardest: add_gold = 2; break; default: ; } for(i=0; i<MAX_PLAYER; ++i){ if (i != NEUTRAL && i != s->controlled && s->country[i].gold>0) s->country[i].gold += add_gold; } }