diff --git a/src/economy.c b/src/economy.c index 94a1a90fa..f98d0f8e1 100644 --- a/src/economy.c +++ b/src/economy.c @@ -914,6 +914,11 @@ struct message * get_modifiers(unit *u, const resource_mod *mod, variant *savep, return NULL; } +static resource_limit *get_resourcelimit(const resource_type *rtype) { + attrib *a = a_find(rtype->attribs, &at_resourcelimit); + return a ? (resource_limit *)a->data.v : NULL; +} + static void allocate_resource(unit * u, const resource_type * rtype, int want) { const item_type *itype = resource2item(rtype); @@ -921,8 +926,7 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) int dm = 0; allocation_list *alist; allocation *al; - attrib *a = a_find(rtype->attribs, &at_resourcelimit); - resource_limit *rdata = (resource_limit *)a->data.v; + resource_limit *rdata = get_resourcelimit(rtype); const resource_type *rring; int amount, skill, skill_mod = 0; variant save_mod; @@ -1119,8 +1123,7 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist) { allocation *al; int nreq = 0; - attrib *a = a_find(rtype->attribs, &at_resourcelimit); - resource_limit *rdata = (resource_limit *)a->data.v; + resource_limit *rdata = get_resourcelimit(rtype); int avail = rdata->value; for (al = alist; al; al = al->next) { @@ -1160,10 +1163,9 @@ typedef void(*allocate_function) (const resource_type *, struct region *, static allocate_function get_allocator(const struct resource_type *rtype) { - attrib *a = a_find(rtype->attribs, &at_resourcelimit); + resource_limit *rdata = get_resourcelimit(rtype); - if (a != NULL) { - resource_limit *rdata = (resource_limit *)a->data.v; + if (rdata) { if (rdata->value > 0 || rdata->limit != NULL) { return attrib_allocation; }