Created
July 20, 2018 08:42
-
-
Save fs-c/0d5e462b15ada52032f249c4fadd3e8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TODO: This function is retarded, fix it and add actual humanization. | |
void humanize_hitpoints(int total, hitpoint **points, int level) | |
{ | |
if (!level) { | |
return; | |
} | |
int i, offset; | |
hitpoint *p = NULL; | |
for (i = 0; i < total; i++) { | |
p = *points + i; | |
// [0, level] | |
offset = generate_number(level, RNG_ROUNDS, RNG_BOUNDARY); | |
// [-(level / 2), (level / 2)] | |
offset -= (level / 2); | |
p->end_time += offset; | |
p->start_time += offset; | |
} | |
} | |
/** | |
* Returns a randomly generated number in the range of [0, range], while | |
* attemting to constrain it outside of a bound(ary) given in percent (]0, 1[), | |
* in a given number of rounds. | |
*/ | |
int generate_number(int range, int rounds, float bound) | |
{ | |
int rn; | |
float minr = 0.5 - (bound / 2); | |
float maxr = 0.5 + (bound / 2); | |
rn = rand() % range; | |
for (int i = 0; i < rounds; i++) { | |
bool in = rn > (range * minr) && rn < (range * maxr); | |
rn += (in ? (rand() % (int)(range * minr)) : 0) | |
* (rn < (range * 0.5) ? -1 : 1); | |
} | |
return rn; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment