forked from github/server
stop using random numbers to scale units.
This commit is contained in:
parent
9188f6fbb6
commit
a67b2fa68d
2 changed files with 13 additions and 29 deletions
|
@ -1733,38 +1733,22 @@ int unit_max_hp(const unit * u)
|
||||||
|
|
||||||
void scale_number(unit * u, int n)
|
void scale_number(unit * u, int n)
|
||||||
{
|
{
|
||||||
const attrib *a;
|
if (n == u->number) {
|
||||||
int remain;
|
|
||||||
|
|
||||||
if (n == u->number)
|
|
||||||
return;
|
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) {
|
if (u->number > 0) {
|
||||||
for (a = a_find(u->attribs, &at_effect); a && a->type == &at_effect;
|
if (n>0) {
|
||||||
a = a->next) {
|
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;
|
effect_data *data = (effect_data *)a->data.v;
|
||||||
int snew = data->value / u->number * n;
|
data->value = (long long)data->value * n / u->number;
|
||||||
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 */
|
|
||||||
}
|
}
|
||||||
data->value = snew;
|
}
|
||||||
|
else {
|
||||||
|
u->hp = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (u->number == 0 || n == 0) {
|
if (u->number == 0 || n == 0) {
|
||||||
|
|
|
@ -112,7 +112,7 @@ extern "C" {
|
||||||
int flags;
|
int flags;
|
||||||
struct attrib *attribs;
|
struct attrib *attribs;
|
||||||
status_t status;
|
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? */
|
int wants; /* enno: attribut? */
|
||||||
} unit;
|
} unit;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue