trying to extract allocation modifiers into a separate function

This commit is contained in:
Enno Rehling 2017-02-15 09:30:36 +01:00
parent 50083fc668
commit 20ff8981df
1 changed files with 35 additions and 45 deletions

View File

@ -883,6 +883,32 @@ enum {
AFL_LOWSKILL = 1 << 1 AFL_LOWSKILL = 1 << 1
}; };
struct message * get_modifiers(unit *u, const resource_mod *mod, double *savep, int *skillp) {
struct building *b = inside_building(u);
const struct building_type *btype = building_is_active(b) ? b->type : NULL;
double save = 1.0;
int skill = 0;
for (; mod->flags != 0; ++mod) {
if (mod->btype == NULL || mod->btype == btype) {
if (mod->flags & RMF_REQUIREDBUILDING) {
return msg_error(u, u->thisorder, 104);;
}
if (mod->race == NULL || mod->race == u_race(u)) {
if (mod->flags & RMF_SAVEMATERIAL) {
save *= mod->value.f;
}
if (mod->flags & RMF_SKILL) {
skill += mod->value.i;
}
}
}
}
*skillp = skill;
*savep = save;
return NULL;
}
static void allocate_resource(unit * u, const resource_type * rtype, int want) static void allocate_resource(unit * u, const resource_type * rtype, int want)
{ {
const item_type *itype = resource2item(rtype); const item_type *itype = resource2item(rtype);
@ -893,7 +919,8 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want)
attrib *a = a_find(rtype->attribs, &at_resourcelimit); attrib *a = a_find(rtype->attribs, &at_resourcelimit);
resource_limit *rdata = (resource_limit *)a->data.v; resource_limit *rdata = (resource_limit *)a->data.v;
const resource_type *rring; const resource_type *rring;
int amount, skill; int amount, skill, skill_mod;
double save_mod;
/* momentan kann man keine ressourcen abbauen, wenn man daf<61>r /* momentan kann man keine ressourcen abbauen, wenn man daf<61>r
* Materialverbrauch hat: */ * Materialverbrauch hat: */
@ -915,18 +942,13 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want)
} }
if (rdata->modifiers) { if (rdata->modifiers) {
resource_mod *mod = rdata->modifiers; message *msg = get_modifiers(u, rdata->modifiers, &save_mod, &skill_mod);
for (; mod->flags != 0; ++mod) { if (msg) {
if (mod->flags & RMF_REQUIREDBUILDING) { ADDMSG(&u->faction->msgs, msg);
struct building *b = inside_building(u); msg_release(msg);
const struct building_type *btype = building_is_active(b) ? b->type : NULL;
if (mod->btype && mod->btype != btype) {
cmistake(u, u->thisorder, 104, MSG_PRODUCE);
return; return;
} }
} }
}
}
/* Bergw<67>chter k<>nnen Abbau von Eisen/Laen durch Bewachen verhindern. /* Bergw<67>chter k<>nnen Abbau von Eisen/Laen durch Bewachen verhindern.
* Als magische Wesen 'sehen' Bergw<EFBFBD>chter alles und werden durch * Als magische Wesen 'sehen' Bergw<EFBFBD>chter alles und werden durch
@ -962,23 +984,7 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want)
itype->rtype)); itype->rtype));
return; return;
} }
else { skill += skill_mod;
struct building *b = inside_building(u);
const struct building_type *btype = building_is_active(b) ? b->type : NULL;
if (rdata->modifiers) {
resource_mod *mod = rdata->modifiers;
for (; mod->flags != 0; ++mod) {
if (mod->flags & RMF_SKILL) {
if (mod->btype == NULL || mod->btype == btype) {
if (mod->race == NULL || mod->race == u_race(u)) {
skill += mod->value.i;
}
}
}
}
}
}
amount = skill * u->number; amount = skill * u->number;
/* nun ist amount die Gesamtproduktion der Einheit (in punkten) */ /* nun ist amount die Gesamtproduktion der Einheit (in punkten) */
@ -1013,26 +1019,10 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want)
} }
al = new_allocation(); al = new_allocation();
al->want = amount; al->want = amount;
al->save = 1.0; al->save = save_mod;
al->next = alist->data; al->next = alist->data;
al->unit = u; al->unit = u;
alist->data = al; alist->data = al;
if (rdata->modifiers) {
struct building *b = inside_building(u);
const struct building_type *btype = building_is_active(b) ? b->type : NULL;
resource_mod *mod = rdata->modifiers;
for (; mod->flags != 0; ++mod) {
if (mod->flags & RMF_SAVEMATERIAL) {
if (mod->btype == NULL || mod->btype == btype) {
if (mod->race == NULL || mod->race == u_race(u)) {
al->save *= mod->value.f;
}
}
}
}
}
} }
static int required(int want, double save) static int required(int want, double save)