- Fix Resourcenabbau in Regionen ohne diese Resource. leveled_allocation()

sollte auch mit avail <= 0 klarkommen. Brachialfix, bitte prüfen!
This commit is contained in:
Christian Schlittchen 2003-06-15 08:06:22 +00:00
parent bfc096d825
commit c550e34abd
2 changed files with 55 additions and 44 deletions

View File

@ -1608,12 +1608,13 @@ allocate_resource(unit * u, const resource_type * rtype, int want)
const struct building_type * btype = b?b->type:NULL; const struct building_type * btype = b?b->type:NULL;
if (btype==bt_find("mine")) if (btype==bt_find("mine"))
al->save *= 0.5; al->save *= 0.5;
if (u->race == new_race[RC_DWARF]) if (u->race == new_race[RC_DWARF]) {
#if RACE_ADJUSTMENTS #if RACE_ADJUSTMENTS
al->save *= 0.75; al->save *= 0.75;
#else #else
al->save *= 0.5; al->save *= 0.5;
#endif #endif
}
} else if (itype==olditemtype[I_STONE]) { } else if (itype==olditemtype[I_STONE]) {
struct building * b = inside_building(u); struct building * b = inside_building(u);
const struct building_type * btype = b?b->type:NULL; const struct building_type * btype = b?b->type:NULL;
@ -1692,54 +1693,64 @@ leveled_allocation(const allocator * self, region * r, allocation * alist)
int need; int need;
boolean first = true; boolean first = true;
if (rm!=NULL) do { if (rm!=NULL) {
int avail = rm->amount; do {
int norders = 0; int avail = rm->amount;
allocation * al; int norders = 0;
allocation * al;
assert (avail>0); if(avail <= 0) {
for (al=alist;al;al=al->next) {
al->get = 0;
}
break;
}
for (al=alist;al;al=al->next) if (!fval(al, AFL_DONE)) { assert(avail>0);
int req = required(al->want-al->get, al->save);
assert(al->get<=al->want && al->get >= 0); for (al=alist;al;al=al->next) if (!fval(al, AFL_DONE)) {
if (eff_skill(al->unit, itype->construction->skill, r) >= rm->level+itype->construction->minskill-1) { int req = required(al->want-al->get, al->save);
if (req) { assert(al->get<=al->want && al->get >= 0);
norders += req; if (eff_skill(al->unit, itype->construction->skill, r)
>= rm->level+itype->construction->minskill-1) {
if (req) {
norders += req;
} else {
fset(al, AFL_DONE);
}
} else { } else {
fset(al, AFL_DONE); fset(al, AFL_DONE);
if (first) fset(al, AFL_LOWSKILL);
} }
} else {
fset(al, AFL_DONE);
if (first) fset(al, AFL_LOWSKILL);
} }
} need = norders;
need = norders;
avail = min(avail, norders); avail = min(avail, norders);
if (need>0) { if (need>0) {
int use = 0; int use = 0;
for (al=alist;al;al=al->next) if (!fval(al, AFL_DONE)) { for (al=alist;al;al=al->next) if (!fval(al, AFL_DONE)) {
if (avail > 0) { if (avail > 0) {
int want = required(al->want-al->get, al->save); int want = required(al->want-al->get, al->save);
int x = avail*want/norders; int x = avail*want/norders;
/* Wenn Rest, dann würfeln, ob ich was bekomme: */ /* Wenn Rest, dann würfeln, ob ich was bekomme: */
if (rand() % norders < (avail*want) % norders) if (rand() % norders < (avail*want) % norders)
++x; ++x;
avail -= x; avail -= x;
use += x; use += x;
norders -= want; norders -= want;
need -= x; need -= x;
al->get = min(al->want, al->get+(int)(x/al->save)); al->get = min(al->want, al->get+(int)(x/al->save));
}
} }
if (use) {
assert(use<=rm->amount);
rm->type->use(rm, r, use);
}
assert(avail==0 || norders==0);
} }
if (use) { first = false;
assert(use<=rm->amount); } while (need>0);
rm->type->use(rm, r, use); }
}
assert(avail==0 || norders==0);
}
first = false;
} while (need>0);
} }
#endif #endif

View File

@ -4,12 +4,12 @@ ifndef ERESSEA
endif endif
# Hier definieren, damit nicht '@gcc' # Hier definieren, damit nicht '@gcc'
CC = gcc-3.2 -D_GNU_SOURCE -ansi -pedantic CC = gcc-3.3 -D_GNU_SOURCE -ansi -pedantic
DEPEND = @gcc-3.2 -MM -MG -r DEPEND = @gcc-3.3 -MM -MG -r
# CC = gcc -D_GNU_SOURCE # CC = gcc -D_GNU_SOURCE
AR = ar AR = ar
CTAGS = ctags-exuberant CTAGS = ctags-exuberant
LD = gcc-3.2 LD = gcc-3.3
INSTALL = cp INSTALL = cp
CFLAGS += -march=athlon -minline-all-stringops CFLAGS += -march=athlon -minline-all-stringops