forked from github/server
Merge branch '2279-alloc-save' into develop
This commit is contained in:
commit
ed94ef6d48
|
@ -883,6 +883,31 @@ enum {
|
|||
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->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;
|
||||
}
|
||||
}
|
||||
} else if (mod->flags & RMF_REQUIREDBUILDING) {
|
||||
return msg_error(u, u->thisorder, 104);
|
||||
}
|
||||
}
|
||||
*skillp = skill;
|
||||
*savep = save;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void allocate_resource(unit * u, const resource_type * rtype, int want)
|
||||
{
|
||||
const item_type *itype = resource2item(rtype);
|
||||
|
@ -893,7 +918,8 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want)
|
|||
attrib *a = a_find(rtype->attribs, &at_resourcelimit);
|
||||
resource_limit *rdata = (resource_limit *)a->data.v;
|
||||
const resource_type *rring;
|
||||
int amount, skill;
|
||||
int amount, skill, skill_mod = 0;
|
||||
double save_mod = 1.0;
|
||||
|
||||
/* momentan kann man keine ressourcen abbauen, wenn man daf<61>r
|
||||
* Materialverbrauch hat: */
|
||||
|
@ -915,18 +941,12 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want)
|
|||
}
|
||||
|
||||
if (rdata->modifiers) {
|
||||
resource_mod *mod = rdata->modifiers;
|
||||
for (; mod->flags != 0; ++mod) {
|
||||
if (mod->flags & RMF_REQUIREDBUILDING) {
|
||||
struct building *b = inside_building(u);
|
||||
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);
|
||||
message *msg = get_modifiers(u, rdata->modifiers, &save_mod, &skill_mod);
|
||||
if (msg) {
|
||||
ADDMSG(&u->faction->msgs, msg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Bergw<67>chter k<>nnen Abbau von Eisen/Laen durch Bewachen verhindern.
|
||||
* Als magische Wesen 'sehen' Bergw<EFBFBD>chter alles und werden durch
|
||||
|
@ -962,23 +982,7 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want)
|
|||
itype->rtype));
|
||||
return;
|
||||
}
|
||||
else {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
skill += skill_mod;
|
||||
amount = skill * u->number;
|
||||
/* nun ist amount die Gesamtproduktion der Einheit (in punkten) */
|
||||
|
||||
|
@ -1013,26 +1017,10 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want)
|
|||
}
|
||||
al = new_allocation();
|
||||
al->want = amount;
|
||||
al->save = 1.0;
|
||||
al->save = save_mod;
|
||||
al->next = alist->data;
|
||||
al->unit = u;
|
||||
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)
|
||||
|
|
|
@ -402,6 +402,13 @@ static void test_make_item(CuTest *tc) {
|
|||
split_allocations(u->region);
|
||||
CuAssertIntEquals(tc, 21, get_item(u, itype));
|
||||
CuAssertIntEquals(tc, 284, u->region->resources->amount); /* 60% saving = 6 stones make 10 stones */
|
||||
|
||||
rdata->modifiers[0].flags = RMF_REQUIREDBUILDING;
|
||||
rdata->modifiers[0].race = NULL;
|
||||
rdata->modifiers[0].btype = bt_get_or_create("mine");
|
||||
make_item(u, itype, 10);
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error104"));
|
||||
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
|
|
|
@ -270,8 +270,6 @@ void syntax_error(const struct unit *u, struct order *ord)
|
|||
ADDMSG(&u->faction->msgs, result);
|
||||
}
|
||||
|
||||
extern unsigned int new_hashstring(const char *s);
|
||||
|
||||
void free_messagelist(mlist *msgs)
|
||||
{
|
||||
struct mlist **mlistptr;
|
||||
|
|
Loading…
Reference in New Issue