Skip to content

Instantly share code, notes, and snippets.

@fs-c
Created July 20, 2018 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fs-c/0d5e462b15ada52032f249c4fadd3e8c to your computer and use it in GitHub Desktop.
Save fs-c/0d5e462b15ada52032f249c4fadd3e8c to your computer and use it in GitHub Desktop.
// 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