stop using random numbers to scale units.

This commit is contained in:
Enno Rehling 2017-11-26 15:15:25 +01:00
parent 9188f6fbb6
commit a67b2fa68d
2 changed files with 13 additions and 29 deletions

View File

@ -1733,38 +1733,22 @@ int unit_max_hp(const unit * u)
void scale_number(unit * u, int n)
{
const attrib *a;
int remain;
if (n == u->number)
if (n == u->number) {
return;
if (n && u->number > 0) {
int full;
remain = ((u->hp % u->number) * (n % u->number)) % u->number;
full = u->hp / u->number; /* wieviel kriegt jede person mindestens */
u->hp = full * n + (u->hp - full * u->number) * n / u->number;
assert(u->hp >= 0);
if ((rng_int() % u->number) < remain)
++u->hp; /* Nachkommastellen */
}
else {
remain = 0;
u->hp = 0;
}
if (u->number > 0) {
for (a = a_find(u->attribs, &at_effect); a && a->type == &at_effect;
a = a->next) {
effect_data *data = (effect_data *)a->data.v;
int snew = data->value / u->number * n;
if (n) {
remain = data->value - snew / n * u->number;
snew += remain * n / u->number;
remain = (remain * n) % u->number;
if ((rng_int() % u->number) < remain)
++snew; /* Nachkommastellen */
if (n>0) {
const attrib *a = a_find(u->attribs, &at_effect);
u->hp = (long long)u->hp * n / u->number;
for (; a && a->type == &at_effect; a = a->next) {
effect_data *data = (effect_data *)a->data.v;
data->value = (long long)data->value * n / u->number;
}
data->value = snew;
}
else {
u->hp = 0;
}
}
if (u->number == 0 || n == 0) {

View File

@ -112,7 +112,7 @@ extern "C" {
int flags;
struct attrib *attribs;
status_t status;
int n; /* helper temporariy variable, used in econmy, enno: attribut? */
int n; /* helper temporary variable, used in economy, enno: attribut? */
int wants; /* enno: attribut? */
} unit;