Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Shifts the given array rightwards with rotation.
- void ArrayShiftRight(int arr){
- int lasti = SizeOfArray(arr)-1;
- int res = arr[lasti];
- for(int i = lasti; i>0; i--){
- arr[i] = arr[i-1];
- }
- arr[0]=res;
- }
- //Shifts the given array leftwards with rotation.
- void ArrayShiftLeft(int arr){
- int lasti = SizeOfArray(arr)-1;
- int res = arr[0];
- for(int i = 0; i<lasti; i++){
- arr[i] = arr[i+1];
- }
- arr[lasti]=res;
- }
- //Returns index of the given element that exists in the given array or -1, if it does not exist.
- int ArrayMatch(int arr, int value){
- for (int i=0; i<SizeOfArray(arr); i++){
- if (arr[i] == value) return i;
- }
- return -1;
- }
- //Returns trus, if the given element exists in the given array.
- bool ArrayMatch(int arr, int value){
- if (ArrayMatch(arr, value)>=0)return true;
- return false;
- }
- //Swaps two elements in the given array
- void SwapArray(int arr, int pos1, int pos2){
- int r = arr[pos1];
- arr[pos1]=arr[pos2];
- arr[pos2]=r;
- }
- //Shuffles the given array like deck of playing cards
- void ShuffleArray(int arr){
- int size = SizeOfArray(arr)-1;
- for (int i=0; i<=size*size; i++){
- int r1 = Rand(size);
- int r2 = Rand(size);
- SwapArray(arr, r1, r2);
- }
- }
- //Picks random elemnemt from given array and returns it
- int RandFromArray(int arr){
- int size = SizeOfArray(arr);
- int rnd = Rand(size-1);
- return arr[rnd];
- }
- //Fixed variant of AdjacentCombo function from std_extension.zh
- int AdjacentComboFix(int cmb, int dir)
- {
- int combooffsets[13]={-0x10, 0x10, -1, 1, -0x11, -0x0F, 0x0F, 0x11};
- if ( cmb % 16 == 0 ) combooffsets[9] = -1;//if it's the left edge
- if ( (cmb % 16) == 15 ) combooffsets[10] = -1; //if it's the right edge
- if ( cmb < 0x10 ) combooffsets[11] = -1; //if it's the top row
- if ( cmb > 0x9F ) combooffsets[12] = -1; //if it's on the bottom row
- if ( combooffsets[9]==-1 && ( dir == DIR_LEFT || dir == DIR_LEFTUP || dir == DIR_LEFTDOWN ) ) return -1; //if the left columb
- if ( combooffsets[10]==-1 && ( dir == DIR_RIGHT || dir == DIR_RIGHTUP || dir == DIR_RIGHTDOWN ) ) return -1; //if the right column
- if ( combooffsets[11]==-1 && ( dir == DIR_UP || dir == DIR_RIGHTUP || dir == DIR_LEFTUP ) ) return -1; //if the top row
- if ( combooffsets[12]==-1 && ( dir == DIR_DOWN || dir == DIR_RIGHTDOWN || dir == DIR_LEFTDOWN ) ) return -1; //if the bottom row
- if ( cmb >= 0 && cmb < 176 ) return cmb + combooffsets[dir];
- else return -1;
- }
- //! Returns the combo ID of a combo based on a location, in a givem direction, N combos away.
- int AdjacentComboFix(int cmb, int dir, int dist){
- // if (dir==DIR_UP){
- // }
- // if (dir==DIR_DOWN){
- // }
- // if (dir==DIR_LEFT){
- // }
- // if (dir==DIR_RIGHT){
- // }
- int combooffsets[13]={-0x10, 0x10, -1, 1, -0x11, -0x0F, 0x0F, 0x11};
- if ( cmb % 16 == 0 ) combooffsets[9] = -1;//if it's the left edge
- if ( (cmb % 16) == 15 ) combooffsets[10] = -1; //if it's the right edge
- if ( cmb < 0x10 ) combooffsets[11] = -1; //if it's the top row
- if ( cmb > 0x9F ) combooffsets[12] = -1; //if it's on the bottom row
- if ( combooffsets[9] && ( dir == DIR_LEFT || dir == DIR_LEFTUP || dir == DIR_LEFTDOWN || dir == DIR_LEFTUP ) ) return -1; //if the left columb
- if ( combooffsets[10] && ( dir == DIR_RIGHT || dir == DIR_RIGHTUP || dir == DIR_RIGHTDOWN ) ) return -1; //if the right column
- if ( combooffsets[11] && ( dir == DIR_UP || dir == DIR_RIGHTUP || dir == DIR_LEFTUP || dir == DIR_LEFTUP ) ) return -1; //if the top row
- if ( combooffsets[12] && ( dir == DIR_DOWN || dir == DIR_RIGHTDOWN || dir == DIR_LEFTDOWN ) ) return -1; //if the bottom row
- else if ( cmb >= 0 && cmb < 176 )
- {
- int cmbs[2];//needs a for loop to ensure that t returns the most valid combo
- for ( cmbs[1] = 0; cmbs[1] < dist; cmbs[1]++ )
- {
- cmbs[0] = cmb;
- cmb += (combooffsets[dir]);
- if ( cmb < 0 || cmb > 175 ) return -1;
- if ( cmb % 16 == 0 ) combooffsets[9] = -1;//if it's the left edge
- if ( (cmb % 16) == 15 ) combooffsets[10] = -1; //if it's the right edge
- if ( cmb < 0x10 ) combooffsets[11] = -1; //if it's the top row
- if ( cmb > 0x9F ) combooffsets[12] = -1; //if it's on the bottom row
- if ( combooffsets[9] && ( dir == DIR_LEFT || dir == DIR_LEFTUP || dir == DIR_LEFTDOWN || dir == DIR_LEFTUP ) ) return -1; //if the left columb
- if ( combooffsets[10] && ( dir == DIR_RIGHT || dir == DIR_RIGHTUP || dir == DIR_RIGHTDOWN ) ) return -1; //if the right column
- if ( combooffsets[11] && ( dir == DIR_UP || dir == DIR_RIGHTUP || dir == DIR_LEFTUP || dir == DIR_LEFTUP ) ) return -1; //if the top row
- if ( combooffsets[12] && ( dir == DIR_DOWN || dir == DIR_RIGHTDOWN || dir == DIR_LEFTDOWN ) ) return -1; //if the bottom row
- }
- return cmb;
- }
- else return -1;
- }
- //Defines adjacency direction for given combos, or -1, if combos are not adjacent.
- int AdjacentComboDir(int cmb1, int cmb2){
- for (int i=0;i<4;i++){
- if (AdjacentComboFix(cmb1, i)==cmb2) return i;
- }
- return -1;
- }
- //Rotated the given direction num times clockwise in 8-way rose wind
- //Use negative values for anti-clockwise direction.
- int RotDir(int dir, int num){
- int dirs[8] = {DIR_UP, DIR_RIGHTUP, DIR_RIGHT, DIR_RIGHTDOWN, DIR_DOWN, DIR_LEFTDOWN, DIR_LEFT, DIR_LEFTUP};
- int idx=-1;
- for (int i=0; i<8; i++){
- //Trace(dirs[i]);
- if (dirs[i] == dir){
- idx=i;
- break;
- }
- }
- if (idx<0) return -1;
- idx+=num;
- while (idx<0) idx+=8;
- while (idx>=8) idx-=8;
- return dirs[idx];
- }
- //Prints a debug number on each combo in the screen from the given array. It must be 176 ints long.
- void DebugCombos(int arr){
- for (int i=0; i<176; i++){
- Screen->DrawInteger(2, ComboX(i), ComboY(i),0, 1,0 , -1, -1, arr[i], 0, OP_OPAQUE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment