Advertisement
Valtsuh

Untitled

Jan 5th, 2022 (edited)
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.71 KB | None | 0 0
  1. typedef unsigned int DINT;
  2.  
  3. // the random class
  4. struct RANDOM {
  5.     RANDOM(DINT min = 0, DINT max = 1) {
  6.         time_t *t = new time_t;
  7.         srand((unsigned int)time(t));
  8.         delete t;
  9.         this->_set(min, max);
  10.     };
  11.     ~RANDOM() {};
  12.     DINT min, max, value, tries, comparer;
  13.  
  14.     DINT _set(DINT min, DINT max) {
  15.         this->tries = 0;
  16.         this->value = 0;
  17.         this->comparer = 0;
  18.         this->min = min;
  19.         this->max = max;
  20.         return this->max;
  21.     }
  22.  
  23.     DINT _generate() {
  24.         if (this->min == 0) {
  25.             this->value = rand() % this->max;
  26.         }
  27.         else {
  28.             this->value = rand() % (this->max - this->min) + this->min;
  29.         }
  30.         return this->value;
  31.     }
  32.  
  33.     DINT _roll(SINT min = -1, SINT max = -1) {
  34.         if (min > -1 && max > -1) {
  35.             this->_set(min, max);
  36.         }
  37.         if (this->min == 0) {
  38.             this->value = rand() % (this->max + 1);
  39.         }
  40.         else {
  41.             this->value = this->min + (rand() % this->max);
  42.         }
  43.         return this->value;
  44.     }
  45.  
  46.     DINT _compare(DINT comparer = 0, SINT min = -1, SINT max = -1) {
  47.         this->comparer = comparer;
  48.         if (this->comparer == this->value && this->tries < 5) {
  49.             this->_roll(min, max);
  50.             this->tries++;
  51.             this->_compare(this->value);
  52.         }
  53.         return this->value;
  54.     }
  55.  
  56. };
  57.  
  58. // the list class
  59.  
  60. template <typename ITEM>
  61. struct LIST {
  62.     LIST() {
  63.         this->length = 0;
  64.         for (DINT i = 0; i < 256; i++) {
  65.             this->item[i];
  66.         }
  67.     };
  68.     ~LIST() {};
  69.  
  70.     DINT length;
  71.     ITEM item[256]; // approx. max array length
  72.  
  73.     void _set(ITEM item) {
  74.         this->item[this->length] = item;
  75.         this->length += 1;
  76.     }
  77.  
  78.     void _remove(DINT position) {
  79.         this->item[position] = { 0 };
  80.     }
  81.  
  82.     ITEM _get(DINT position = 0) {
  83.         return this->item[position];
  84.     }
  85. };
  86.  
  87. // the _generate function
  88.  
  89.     void _generate(DUS dus, DINT w = 300, DINT h = 200) {
  90.         this->dus._set(dus);
  91.         this->dus.item[this->dus.length - 1].added = this->dus.length;
  92.        
  93.             this->temp = 0;
  94.             do {
  95.  
  96.                 if (this->dus.item[this->dus.length - 1].added != this->dus.item[this->temp].added) {
  97.                     if (this->dus.item[this->dus.length - 1].unique == this->dus.item[this->temp].unique) {
  98.                         do {
  99.                             this->dus.item[this->dus.length - 1].unique = this->dus.item[this->dus.length - 1].dice._roll(0, this->dus.length);
  100.                         } while (this->dus.item[this->dus.length - 1].unique == this->dus.item[this->temp].unique);
  101.                         this->temp = 0;
  102.                     }
  103.                 }
  104.                 this->temp++;
  105.             } while (this->temp < this->dus.length);
  106.        
  107.     }
  108.  
  109. // the function using both
  110.  
  111. if (this->dus.length < 4) {
  112.             RANDOM* dice = new RANDOM;
  113.             switch (this->dice._roll(0, ENGINE_DATABASE_DUS_APPEARANCE_CHANCE)) {
  114.             default:
  115.                 break;
  116.             case 0:
  117.                 this->_generate(ENGINE_DATABASE_DUS_SAMPLE, 300, 200);
  118.                 this->dus.item[this->dus.length - 1].dimension.x = dice->_roll(10, 20);
  119.                 this->dus.item[this->dus.length - 1].dimension.y = dice->_roll(10, 20);
  120.                 break;
  121.             case 1:
  122.                 this->_generate(ENGINE_DATABASE_DUS_NOTHING, 300, 200);
  123.                 this->dus.item[this->dus.length - 1].dimension.x = dice->_roll(21, 40);
  124.                 this->dus.item[this->dus.length - 1].dimension.y = dice->_roll(21, 40);
  125.                 break;
  126.             case 2:
  127.                 this->_generate(ENGINE_DATABASE_DUS_UNIQUE, 300, 200);
  128.                 this->dus.item[this->dus.length - 1].dimension.x = dice->_roll(41, 59);
  129.                 this->dus.item[this->dus.length - 1].dimension.y = dice->_roll(41, 59);
  130.                 break;
  131.             case 3:
  132.                 this->_generate(ENGINE_DATABASE_DUS_OFFENSE, 300, 200);
  133.                 this->dus.item[this->dus.length - 1].dimension.x = dice->_roll(60, 80);
  134.                 this->dus.item[this->dus.length - 1].dimension.y = dice->_roll(60, 80);
  135.                 break;
  136.             case 4:
  137.                 this->_generate(ENGINE_DATABASE_DUS_DEFENSE, 300, 200);
  138.                 this->dus.item[this->dus.length - 1].dimension.x = dice->_roll(81, 100);
  139.                 this->dus.item[this->dus.length - 1].dimension.y = dice->_roll(81, 100);
  140.                 break;
  141.  
  142.             }
  143.  
  144.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement