Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef unsigned int DINT;
- // the random class
- struct RANDOM {
- RANDOM(DINT min = 0, DINT max = 1) {
- time_t *t = new time_t;
- srand((unsigned int)time(t));
- delete t;
- this->_set(min, max);
- };
- ~RANDOM() {};
- DINT min, max, value, tries, comparer;
- DINT _set(DINT min, DINT max) {
- this->tries = 0;
- this->value = 0;
- this->comparer = 0;
- this->min = min;
- this->max = max;
- return this->max;
- }
- DINT _generate() {
- if (this->min == 0) {
- this->value = rand() % this->max;
- }
- else {
- this->value = rand() % (this->max - this->min) + this->min;
- }
- return this->value;
- }
- DINT _roll(SINT min = -1, SINT max = -1) {
- if (min > -1 && max > -1) {
- this->_set(min, max);
- }
- if (this->min == 0) {
- this->value = rand() % (this->max + 1);
- }
- else {
- this->value = this->min + (rand() % this->max);
- }
- return this->value;
- }
- DINT _compare(DINT comparer = 0, SINT min = -1, SINT max = -1) {
- this->comparer = comparer;
- if (this->comparer == this->value && this->tries < 5) {
- this->_roll(min, max);
- this->tries++;
- this->_compare(this->value);
- }
- return this->value;
- }
- };
- // the list class
- template <typename ITEM>
- struct LIST {
- LIST() {
- this->length = 0;
- for (DINT i = 0; i < 256; i++) {
- this->item[i];
- }
- };
- ~LIST() {};
- DINT length;
- ITEM item[256]; // approx. max array length
- void _set(ITEM item) {
- this->item[this->length] = item;
- this->length += 1;
- }
- void _remove(DINT position) {
- this->item[position] = { 0 };
- }
- ITEM _get(DINT position = 0) {
- return this->item[position];
- }
- };
- // the _generate function
- void _generate(DUS dus, DINT w = 300, DINT h = 200) {
- this->dus._set(dus);
- this->dus.item[this->dus.length - 1].added = this->dus.length;
- this->temp = 0;
- do {
- if (this->dus.item[this->dus.length - 1].added != this->dus.item[this->temp].added) {
- if (this->dus.item[this->dus.length - 1].unique == this->dus.item[this->temp].unique) {
- do {
- this->dus.item[this->dus.length - 1].unique = this->dus.item[this->dus.length - 1].dice._roll(0, this->dus.length);
- } while (this->dus.item[this->dus.length - 1].unique == this->dus.item[this->temp].unique);
- this->temp = 0;
- }
- }
- this->temp++;
- } while (this->temp < this->dus.length);
- }
- // the function using both
- if (this->dus.length < 4) {
- RANDOM* dice = new RANDOM;
- switch (this->dice._roll(0, ENGINE_DATABASE_DUS_APPEARANCE_CHANCE)) {
- default:
- break;
- case 0:
- this->_generate(ENGINE_DATABASE_DUS_SAMPLE, 300, 200);
- this->dus.item[this->dus.length - 1].dimension.x = dice->_roll(10, 20);
- this->dus.item[this->dus.length - 1].dimension.y = dice->_roll(10, 20);
- break;
- case 1:
- this->_generate(ENGINE_DATABASE_DUS_NOTHING, 300, 200);
- this->dus.item[this->dus.length - 1].dimension.x = dice->_roll(21, 40);
- this->dus.item[this->dus.length - 1].dimension.y = dice->_roll(21, 40);
- break;
- case 2:
- this->_generate(ENGINE_DATABASE_DUS_UNIQUE, 300, 200);
- this->dus.item[this->dus.length - 1].dimension.x = dice->_roll(41, 59);
- this->dus.item[this->dus.length - 1].dimension.y = dice->_roll(41, 59);
- break;
- case 3:
- this->_generate(ENGINE_DATABASE_DUS_OFFENSE, 300, 200);
- this->dus.item[this->dus.length - 1].dimension.x = dice->_roll(60, 80);
- this->dus.item[this->dus.length - 1].dimension.y = dice->_roll(60, 80);
- break;
- case 4:
- this->_generate(ENGINE_DATABASE_DUS_DEFENSE, 300, 200);
- this->dus.item[this->dus.length - 1].dimension.x = dice->_roll(81, 100);
- this->dus.item[this->dus.length - 1].dimension.y = dice->_roll(81, 100);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement