Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.22 KB | None | 0 0
  1. int select_atacker( const Banda *const b ) {
  2.     int pula = 3;
  3.     for( int i=0 ; i<CNT_POSTACI ; i++ ) {
  4.         const Postac *const p = b->postaci + i;
  5.         if( p->live > 0 )
  6.             pula += p->evil * (p->spirit + p->strength);
  7.     }
  8.  
  9.     for( int i=2 ; 1 ; i++ ) {
  10.         const Postac *const p = b->postaci + i%CNT_POSTACI;
  11.         if( p->live > 0 )
  12.             if( p->evil * (p->spirit + p->strength) > my_rand()%pula )
  13.                 return i;
  14.     }
  15.  
  16. }
  17.  
  18.  
  19. int is_magick_atack( const Postac *const p ) {
  20.     return p->spirit * p->good + 1 >  my_rand() % ( p->spirit * p->good + p->strength * p->evil + 2 );
  21. }
  22.  
  23.  
  24. int strength_atack( const Postac *const p , int is_magick ) {
  25.     int atack;
  26.     if( is_magick )
  27.         atack = p->spirit * p->evil * bronie[p->id_bron].spritual_atack;
  28.     else
  29.         atack = p->strength * p->evil * bronie[p->id_bron].phisical_atack;
  30. }
  31.  
  32.  
  33. int select_victim( const Postac *const p ) {
  34.     int pula = 3;
  35.     for( int i=0 ; i<CNT_POSTACI ; i++ ) {
  36.         const Postac *const p = b->postaci + i;
  37.         if( p->live > 0 )
  38.             pula += p->good * p->deftness;
  39.     }
  40.  
  41.     for( int i=2 ; 1 ; i++ ) {
  42.         const Postac *const p = b->postaci + i%CNT_POSTACI;
  43.         if( p->live > 0 )
  44.             if( p->evil * (p->spirit + p->strength) > my_rand()%pula )
  45.                 return i;
  46.     }
  47.  
  48. }
  49.  
  50.  
  51. int result( Banda *const b1 , Banda *const b2 , int *res ) {
  52.     int res1=0;
  53.     int res2=0;
  54.     for( int i=0 ; i<CNT_POSTACI && (res1==0 || res2==0) ; i++ ) {
  55.         if( b1->postaci[i].live > 0 ) res1 ++ ;
  56.         if( b2->postaci[i].live > 0 ) res2 ++ ;
  57.     }
  58.     if( res1==0 && res2>0 ) {
  59.         *res = -1;
  60.         return 1;
  61.     }
  62.     if( res1>0 && res2==0 ) {
  63.         *res = +1;
  64.         return 1;
  65.     }
  66.     if( res1==0 && res2==0 ) {
  67.         *res = 0;
  68.         return 1;
  69.     }
  70.     return 0;
  71. }
  72.  
  73. int walka( Banda *const b1 , Banda *const b2 ) {
  74.     int cpy_live1[CNT_POSTACI],cpy_live2[CNT_POSTACI];
  75.     int res;
  76.     for( int i=0 ; i<CNT_POSTACI ; i++ ) {
  77.         cpy_live1[i] = b1->postaci[i].live;
  78.         cpy_live2[i] = b2->postaci[i].live;
  79.         b1->postaci[i].live = (b1->postaci[i].live + 1) * 30;
  80.         b2->postaci[i].live = (b2->postaci[i].live + 1) * 30;
  81.     }
  82.  
  83.     while( ! result( b1 , b2 , &res ) ) {
  84.         int at1 = select_atacker( b1 );
  85.         int at2 = select_atacker( b2 );
  86.  
  87.     }
  88.  
  89.     for( int i=0 ; i<CNT_POSTACI ; i++ ) {
  90.         b1->postaci[i].live = cpy_live1[i];
  91.         b2->postaci[i].live = cpy_live2[i];
  92.     }
  93.  
  94.     return res;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement