Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 1.18 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // slot1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. int getsize(long nRandomOption){
  7. int nSize = 0;
  8. long k = 0;
  9. int l = 0;
  10. int MAX_RANDOM_OPTION = 3;
  11. k = 0x3ffff << 8;
  12. for (l = 0; l <= MAX_RANDOM_OPTION; l++){
  13.         if(nRandomOption & k){
  14.                 nSize = nSize + 1;
  15.         }
  16.         else{
  17.                 return nSize;
  18.         }
  19.         k = k << 18;
  20. }
  21. return nSize;
  22. }
  23. //iRandomOptItemId=item random option value(fromdb)
  24. //k=size of rand opt
  25. bool getrand(long iRandomOptItemId, int k, int& nDst, int& nAdj){
  26.         int MAX_RANDOM_OPTION = 3;
  27.         long iRandomOption = 0;
  28.         if (k < MAX_RANDOM_OPTION){
  29.                 iRandomOption = iRandomOptItemId >> (8 + k * 18);
  30.                 nAdj=int(iRandomOption & 0x1ff);
  31.         }
  32.         else{
  33.                 return false;
  34.         }
  35.         if (iRandomOption & 0x200){
  36.                 nAdj = -nAdj;
  37.         }
  38.         iRandomOption = iRandomOption >> 10;
  39.         nDst=iRandomOption & 0xff;
  40.         return (nDst > 0);
  41. }
  42. int _tmain(int argc, _TCHAR* argv[])
  43. {
  44.         long s;
  45.         std::cin >> s;
  46.         int z=getsize(s);
  47.         printf ("\n/sro ");
  48.         int k = 0;
  49.     int nDst = 0;
  50.     int nAdj = 0;
  51.         for (k = 0; k <= z; k++){
  52.                 if (getrand(s, k, nDst, nAdj)==true){
  53.                         std::cout << nDst << " " << nAdj << " ";
  54.                 }
  55.         }
  56.         printf("\n");
  57.         system("pause");
  58. }