begin refactoring limited resources.

This commit is contained in:
Enno Rehling 2017-02-22 20:28:34 +01:00
parent 67831ad708
commit ce2ea95880
1 changed files with 9 additions and 7 deletions

View File

@ -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;
}