forked from github/server
begin refactoring limited resources.
This commit is contained in:
parent
67831ad708
commit
ce2ea95880
|
@ -914,6 +914,11 @@ struct message * get_modifiers(unit *u, const resource_mod *mod, variant *savep,
|
||||||
return NULL;
|
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)
|
static void allocate_resource(unit * u, const resource_type * rtype, int want)
|
||||||
{
|
{
|
||||||
const item_type *itype = resource2item(rtype);
|
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;
|
int dm = 0;
|
||||||
allocation_list *alist;
|
allocation_list *alist;
|
||||||
allocation *al;
|
allocation *al;
|
||||||
attrib *a = a_find(rtype->attribs, &at_resourcelimit);
|
resource_limit *rdata = get_resourcelimit(rtype);
|
||||||
resource_limit *rdata = (resource_limit *)a->data.v;
|
|
||||||
const resource_type *rring;
|
const resource_type *rring;
|
||||||
int amount, skill, skill_mod = 0;
|
int amount, skill, skill_mod = 0;
|
||||||
variant save_mod;
|
variant save_mod;
|
||||||
|
@ -1119,8 +1123,7 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist)
|
||||||
{
|
{
|
||||||
allocation *al;
|
allocation *al;
|
||||||
int nreq = 0;
|
int nreq = 0;
|
||||||
attrib *a = a_find(rtype->attribs, &at_resourcelimit);
|
resource_limit *rdata = get_resourcelimit(rtype);
|
||||||
resource_limit *rdata = (resource_limit *)a->data.v;
|
|
||||||
int avail = rdata->value;
|
int avail = rdata->value;
|
||||||
|
|
||||||
for (al = alist; al; al = al->next) {
|
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)
|
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) {
|
if (rdata) {
|
||||||
resource_limit *rdata = (resource_limit *)a->data.v;
|
|
||||||
if (rdata->value > 0 || rdata->limit != NULL) {
|
if (rdata->value > 0 || rdata->limit != NULL) {
|
||||||
return attrib_allocation;
|
return attrib_allocation;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue