Skip to content

Instantly share code, notes, and snippets.

@fs-c

fs-c/osu_human.c

Created Jul 20, 2018
Embed
What would you like to do?
// 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
You can’t perform that action at this time.