Alucard648

stdArrays.zh

Dec 21st, 2022 (edited)
1,269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.61 KB | Gaming | 0 0
  1. //Shifts the given array rightwards with rotation.
  2. void ArrayShiftRight(int arr){
  3.     int lasti = SizeOfArray(arr)-1;
  4.     int res = arr[lasti];
  5.     for(int i = lasti; i>0; i--){
  6.         arr[i] = arr[i-1];
  7.     }
  8.     arr[0]=res;
  9. }
  10.  
  11. //Shifts the given array leftwards with rotation.
  12. void ArrayShiftLeft(int arr){
  13.     int lasti = SizeOfArray(arr)-1;
  14.     int res = arr[0];
  15.     for(int i = 0; i<lasti; i++){
  16.         arr[i] = arr[i+1];
  17.     }
  18.     arr[lasti]=res;
  19. }
  20.  
  21. //Returns index of the given element that exists in the given array or -1, if it does not exist.
  22. int ArrayMatch(int arr, int value){
  23.     for (int i=0; i<SizeOfArray(arr); i++){
  24.         if (arr[i] == value) return i;
  25.     }
  26.     return -1;
  27. }
  28.  
  29. //Returns trus, if the given element exists in the given array.
  30. bool ArrayMatch(int arr, int value){
  31.     if (ArrayMatch(arr, value)>=0)return true;
  32.     return false;
  33. }
  34.  
  35. //Swaps two elements in the given array
  36. void SwapArray(int arr, int pos1, int pos2){
  37.     int r = arr[pos1];
  38.     arr[pos1]=arr[pos2];
  39.     arr[pos2]=r;
  40. }
  41.  
  42. //Shuffles the given array like deck of playing cards
  43. void ShuffleArray(int arr){
  44.     int size = SizeOfArray(arr)-1;
  45.     for (int i=0; i<=size*size; i++){
  46.         int r1 = Rand(size);
  47.         int r2 = Rand(size);
  48.         SwapArray(arr, r1, r2);
  49.     }
  50. }
  51.  
  52. //Picks random elemnemt from given array and returns it
  53. int RandFromArray(int arr){
  54.     int size = SizeOfArray(arr);
  55.     int rnd = Rand(size-1);
  56.     return arr[rnd];
  57. }
  58.  
  59. //Fixed variant of AdjacentCombo function from std_extension.zh
  60. int AdjacentComboFix(int cmb, int dir)
  61. {
  62.     int combooffsets[13]={-0x10, 0x10, -1, 1, -0x11, -0x0F, 0x0F, 0x11};
  63.     if ( cmb % 16 == 0 ) combooffsets[9] = -1;//if it's the left edge
  64.     if ( (cmb % 16) == 15 ) combooffsets[10] = -1; //if it's the right edge
  65.     if ( cmb < 0x10 ) combooffsets[11] = -1; //if it's the top row
  66.     if ( cmb > 0x9F ) combooffsets[12] = -1; //if it's on the bottom row
  67.     if ( combooffsets[9]==-1 && ( dir == DIR_LEFT || dir == DIR_LEFTUP || dir == DIR_LEFTDOWN ) ) return -1; //if the left columb
  68.     if ( combooffsets[10]==-1 && ( dir == DIR_RIGHT || dir == DIR_RIGHTUP || dir == DIR_RIGHTDOWN ) ) return -1; //if the right column
  69.     if ( combooffsets[11]==-1 && ( dir == DIR_UP || dir == DIR_RIGHTUP || dir == DIR_LEFTUP ) ) return -1; //if the top row
  70.     if ( combooffsets[12]==-1 && ( dir == DIR_DOWN || dir == DIR_RIGHTDOWN || dir == DIR_LEFTDOWN ) ) return -1; //if the bottom row
  71.     if ( cmb >= 0 && cmb < 176 ) return cmb + combooffsets[dir];
  72.     else return -1;
  73. }
  74.  
  75. //! Returns the combo ID of a combo based on a location, in a givem direction, N combos away.
  76. int AdjacentComboFix(int cmb, int dir, int dist){
  77.     // if (dir==DIR_UP){
  78.     // }
  79.     // if (dir==DIR_DOWN){
  80.     // }
  81.     // if (dir==DIR_LEFT){
  82.     // }
  83.     // if (dir==DIR_RIGHT){
  84.     // }
  85.     int combooffsets[13]={-0x10, 0x10, -1, 1, -0x11, -0x0F, 0x0F, 0x11};
  86.     if ( cmb % 16 == 0 ) combooffsets[9] = -1;//if it's the left edge
  87.     if ( (cmb % 16) == 15 ) combooffsets[10] = -1; //if it's the right edge
  88.     if ( cmb < 0x10 ) combooffsets[11] = -1; //if it's the top row
  89.     if ( cmb > 0x9F ) combooffsets[12] = -1; //if it's on the bottom row
  90.     if ( combooffsets[9] && ( dir == DIR_LEFT || dir == DIR_LEFTUP || dir == DIR_LEFTDOWN || dir == DIR_LEFTUP ) ) return -1; //if the left columb
  91.     if ( combooffsets[10] && ( dir == DIR_RIGHT || dir == DIR_RIGHTUP || dir == DIR_RIGHTDOWN ) ) return -1; //if the right column
  92.     if ( combooffsets[11] && ( dir == DIR_UP || dir == DIR_RIGHTUP || dir == DIR_LEFTUP || dir == DIR_LEFTUP ) ) return -1; //if the top row
  93.     if ( combooffsets[12] && ( dir == DIR_DOWN || dir == DIR_RIGHTDOWN || dir == DIR_LEFTDOWN ) ) return -1; //if the bottom row
  94.     else if ( cmb >= 0 && cmb < 176 )
  95.         {
  96.         int cmbs[2];//needs a for loop to ensure that t returns the most valid combo
  97.        
  98.         for ( cmbs[1] = 0; cmbs[1] < dist; cmbs[1]++ )
  99.         {
  100.             cmbs[0] = cmb;
  101.             cmb += (combooffsets[dir]);
  102.             if ( cmb < 0 || cmb > 175 ) return -1;
  103.             if ( cmb % 16 == 0 ) combooffsets[9] = -1;//if it's the left edge
  104.             if ( (cmb % 16) == 15 ) combooffsets[10] = -1;  //if it's the right edge
  105.             if ( cmb < 0x10 ) combooffsets[11] = -1; //if it's the top row
  106.             if ( cmb > 0x9F ) combooffsets[12] = -1; //if it's on the bottom row
  107.             if ( combooffsets[9] && ( dir == DIR_LEFT || dir == DIR_LEFTUP || dir == DIR_LEFTDOWN || dir == DIR_LEFTUP ) ) return -1; //if the left columb
  108.             if ( combooffsets[10] && ( dir == DIR_RIGHT || dir == DIR_RIGHTUP || dir == DIR_RIGHTDOWN ) ) return -1; //if the right column
  109.             if ( combooffsets[11] && ( dir == DIR_UP || dir == DIR_RIGHTUP || dir == DIR_LEFTUP || dir == DIR_LEFTUP ) ) return -1; //if the top row
  110.             if ( combooffsets[12] && ( dir == DIR_DOWN || dir == DIR_RIGHTDOWN || dir == DIR_LEFTDOWN ) ) return -1; //if the bottom row
  111.            
  112.         }
  113.         return cmb;
  114.     }
  115.     else return -1;
  116. }
  117.  
  118. //Defines adjacency direction for given combos, or -1, if combos are not adjacent.
  119. int AdjacentComboDir(int cmb1, int cmb2){
  120.     for (int i=0;i<4;i++){
  121.         if (AdjacentComboFix(cmb1, i)==cmb2) return i;
  122.     }
  123.     return -1;
  124. }
  125.  
  126. //Rotated the given direction num times clockwise in 8-way rose wind
  127. //Use negative values for anti-clockwise direction.
  128. int RotDir(int dir, int num){
  129.     int dirs[8] = {DIR_UP, DIR_RIGHTUP, DIR_RIGHT, DIR_RIGHTDOWN, DIR_DOWN, DIR_LEFTDOWN, DIR_LEFT, DIR_LEFTUP};
  130.     int idx=-1;
  131.     for (int i=0; i<8; i++){
  132.         //Trace(dirs[i]);
  133.         if (dirs[i] == dir){
  134.             idx=i;
  135.             break;
  136.         }
  137.     }
  138.     if (idx<0) return -1;
  139.     idx+=num;
  140.     while (idx<0) idx+=8;
  141.     while (idx>=8) idx-=8;
  142.     return dirs[idx];
  143. }
  144.  
  145. //Prints a debug number on each combo in the screen from the given array. It must be 176 ints long.
  146. void DebugCombos(int arr){
  147.     for (int i=0; i<176; i++){
  148.         Screen->DrawInteger(2, ComboX(i), ComboY(i),0, 1,0 , -1, -1, arr[i], 0, OP_OPAQUE);
  149.     }
  150. }
Tags: zcsript
Advertisement
Add Comment
Please, Sign In to add comment