forked from github/server
remove resource_limit struct indirection.
This commit is contained in:
parent
c3b0b9e8b3
commit
d4b973fea4
|
@ -921,7 +921,6 @@ 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;
|
||||||
resource_limit *rdata = rtype->limit;
|
|
||||||
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;
|
||||||
|
@ -944,8 +943,8 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rdata && rdata->modifiers) {
|
if (rtype->modifiers) {
|
||||||
message *msg = get_modifiers(u, rdata->modifiers, &save_mod, &skill_mod);
|
message *msg = get_modifiers(u, rtype->modifiers, &save_mod, &skill_mod);
|
||||||
if (msg) {
|
if (msg) {
|
||||||
ADDMSG(&u->faction->msgs, msg);
|
ADDMSG(&u->faction->msgs, msg);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -348,7 +348,6 @@ static void test_make_item(CuTest *tc) {
|
||||||
struct item_type *itype;
|
struct item_type *itype;
|
||||||
const struct resource_type *rt_silver;
|
const struct resource_type *rt_silver;
|
||||||
resource_type *rtype;
|
resource_type *rtype;
|
||||||
resource_limit *rdata;
|
|
||||||
double d = 0.6;
|
double d = 0.6;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
|
@ -382,7 +381,6 @@ static void test_make_item(CuTest *tc) {
|
||||||
itype->construction->materials = 0;
|
itype->construction->materials = 0;
|
||||||
rtype->flags |= RTF_LIMITED;
|
rtype->flags |= RTF_LIMITED;
|
||||||
rmt_create(rtype);
|
rmt_create(rtype);
|
||||||
rdata = rtype->limit = calloc(1, sizeof(resource_limit));
|
|
||||||
add_resource(u->region, 1, 300, 150, rtype);
|
add_resource(u->region, 1, 300, 150, rtype);
|
||||||
u->region->resources->amount = 300; /* there are 300 stones at level 1 */
|
u->region->resources->amount = 300; /* there are 300 stones at level 1 */
|
||||||
set_level(u, SK_ALCHEMY, 10);
|
set_level(u, SK_ALCHEMY, 10);
|
||||||
|
@ -392,11 +390,11 @@ static void test_make_item(CuTest *tc) {
|
||||||
CuAssertIntEquals(tc, 11, get_item(u, itype));
|
CuAssertIntEquals(tc, 11, get_item(u, itype));
|
||||||
CuAssertIntEquals(tc, 290, u->region->resources->amount); /* used 10 stones to make 10 stones */
|
CuAssertIntEquals(tc, 290, u->region->resources->amount); /* used 10 stones to make 10 stones */
|
||||||
|
|
||||||
rdata->modifiers = calloc(2, sizeof(resource_mod));
|
rtype->modifiers = calloc(2, sizeof(resource_mod));
|
||||||
rdata->modifiers[0].flags = RMF_SAVEMATERIAL;
|
rtype->modifiers[0].flags = RMF_SAVEMATERIAL;
|
||||||
rdata->modifiers[0].race = u->_race;
|
rtype->modifiers[0].race = u->_race;
|
||||||
rdata->modifiers[0].value.sa[0] = (short)(0.5+100*d);
|
rtype->modifiers[0].value.sa[0] = (short)(0.5+100*d);
|
||||||
rdata->modifiers[0].value.sa[1] = 100;
|
rtype->modifiers[0].value.sa[1] = 100;
|
||||||
make_item(u, itype, 10);
|
make_item(u, itype, 10);
|
||||||
split_allocations(u->region);
|
split_allocations(u->region);
|
||||||
CuAssertIntEquals(tc, 21, get_item(u, itype));
|
CuAssertIntEquals(tc, 21, get_item(u, itype));
|
||||||
|
@ -407,9 +405,9 @@ static void test_make_item(CuTest *tc) {
|
||||||
CuAssertIntEquals(tc, 22, get_item(u, itype));
|
CuAssertIntEquals(tc, 22, get_item(u, itype));
|
||||||
CuAssertIntEquals(tc, 283, u->region->resources->amount); /* no free lunches */
|
CuAssertIntEquals(tc, 283, u->region->resources->amount); /* no free lunches */
|
||||||
|
|
||||||
rdata->modifiers[0].flags = RMF_REQUIREDBUILDING;
|
rtype->modifiers[0].flags = RMF_REQUIREDBUILDING;
|
||||||
rdata->modifiers[0].race = NULL;
|
rtype->modifiers[0].race = NULL;
|
||||||
rdata->modifiers[0].btype = bt_get_or_create("mine");
|
rtype->modifiers[0].btype = bt_get_or_create("mine");
|
||||||
make_item(u, itype, 10);
|
make_item(u, itype, 10);
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error104"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error104"));
|
||||||
|
|
||||||
|
|
|
@ -1236,15 +1236,12 @@ void free_rtype(resource_type *rtype) {
|
||||||
if (rtype->wtype) {
|
if (rtype->wtype) {
|
||||||
free_wtype(rtype->wtype);
|
free_wtype(rtype->wtype);
|
||||||
}
|
}
|
||||||
if (rtype->atype) {
|
|
||||||
free(rtype->atype);
|
|
||||||
}
|
|
||||||
if (rtype->itype) {
|
if (rtype->itype) {
|
||||||
free_itype(rtype->itype);
|
free_itype(rtype->itype);
|
||||||
}
|
}
|
||||||
if (rtype->raw) {
|
free(rtype->atype);
|
||||||
|
free(rtype->modifiers);
|
||||||
free(rtype->raw);
|
free(rtype->raw);
|
||||||
}
|
|
||||||
free(rtype->_name);
|
free(rtype->_name);
|
||||||
free(rtype);
|
free(rtype);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ extern "C" {
|
||||||
struct storage;
|
struct storage;
|
||||||
struct gamedata;
|
struct gamedata;
|
||||||
struct rawmaterial_type;
|
struct rawmaterial_type;
|
||||||
struct resource_limit;
|
struct resource_mod;
|
||||||
|
|
||||||
typedef struct item {
|
typedef struct item {
|
||||||
struct item *next;
|
struct item *next;
|
||||||
|
@ -80,7 +80,7 @@ extern "C" {
|
||||||
rtype_uget uget;
|
rtype_uget uget;
|
||||||
rtype_name name;
|
rtype_name name;
|
||||||
struct rawmaterial_type *raw;
|
struct rawmaterial_type *raw;
|
||||||
struct resource_limit *limit;
|
struct resource_mod *modifiers;
|
||||||
/* --- pointers --- */
|
/* --- pointers --- */
|
||||||
struct attrib *attribs;
|
struct attrib *attribs;
|
||||||
struct item_type *itype;
|
struct item_type *itype;
|
||||||
|
|
|
@ -50,10 +50,6 @@ extern "C" {
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
} resource_mod;
|
} resource_mod;
|
||||||
|
|
||||||
typedef struct resource_limit {
|
|
||||||
resource_mod *modifiers;
|
|
||||||
} resource_limit;
|
|
||||||
|
|
||||||
typedef struct rawmaterial_type {
|
typedef struct rawmaterial_type {
|
||||||
const struct resource_type *rtype;
|
const struct resource_type *rtype;
|
||||||
|
|
||||||
|
|
|
@ -988,7 +988,6 @@ static int parse_resources(xmlDocPtr doc)
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "resourcelimit", xpath);
|
result = xmlXPathEvalExpression(BAD_CAST "resourcelimit", xpath);
|
||||||
assert(result->nodesetval->nodeNr <= 1);
|
assert(result->nodesetval->nodeNr <= 1);
|
||||||
if (result->nodesetval->nodeNr != 0) {
|
if (result->nodesetval->nodeNr != 0) {
|
||||||
resource_limit *rdata = rtype->limit = calloc(1, sizeof(resource_limit));
|
|
||||||
xmlNodePtr limit = result->nodesetval->nodeTab[0];
|
xmlNodePtr limit = result->nodesetval->nodeTab[0];
|
||||||
|
|
||||||
xpath->node = limit;
|
xpath->node = limit;
|
||||||
|
@ -996,7 +995,7 @@ static int parse_resources(xmlDocPtr doc)
|
||||||
|
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "modifier", xpath);
|
result = xmlXPathEvalExpression(BAD_CAST "modifier", xpath);
|
||||||
if (result->nodesetval != NULL) {
|
if (result->nodesetval != NULL) {
|
||||||
rdata->modifiers =
|
rtype->modifiers =
|
||||||
calloc(result->nodesetval->nodeNr + 1, sizeof(resource_mod));
|
calloc(result->nodesetval->nodeNr + 1, sizeof(resource_mod));
|
||||||
for (k = 0; k != result->nodesetval->nodeNr; ++k) {
|
for (k = 0; k != result->nodesetval->nodeNr; ++k) {
|
||||||
xmlNodePtr node = result->nodesetval->nodeTab[k];
|
xmlNodePtr node = result->nodesetval->nodeTab[k];
|
||||||
|
@ -1010,31 +1009,31 @@ static int parse_resources(xmlDocPtr doc)
|
||||||
rc = rc_get_or_create((const char *)propValue);
|
rc = rc_get_or_create((const char *)propValue);
|
||||||
xmlFree(propValue);
|
xmlFree(propValue);
|
||||||
}
|
}
|
||||||
rdata->modifiers[k].race = rc;
|
rtype->modifiers[k].race = rc;
|
||||||
|
|
||||||
propValue = xmlGetProp(node, BAD_CAST "building");
|
propValue = xmlGetProp(node, BAD_CAST "building");
|
||||||
if (propValue != NULL) {
|
if (propValue != NULL) {
|
||||||
btype = bt_get_or_create((const char *)propValue);
|
btype = bt_get_or_create((const char *)propValue);
|
||||||
xmlFree(propValue);
|
xmlFree(propValue);
|
||||||
}
|
}
|
||||||
rdata->modifiers[k].btype = btype;
|
rtype->modifiers[k].btype = btype;
|
||||||
|
|
||||||
propValue = xmlGetProp(node, BAD_CAST "type");
|
propValue = xmlGetProp(node, BAD_CAST "type");
|
||||||
assert(propValue != NULL);
|
assert(propValue != NULL);
|
||||||
if (strcmp((const char *)propValue, "skill") == 0) {
|
if (strcmp((const char *)propValue, "skill") == 0) {
|
||||||
rdata->modifiers[k].value.i = xml_ivalue(node, "value", 0);
|
rtype->modifiers[k].value.i = xml_ivalue(node, "value", 0);
|
||||||
rdata->modifiers[k].flags = RMF_SKILL;
|
rtype->modifiers[k].flags = RMF_SKILL;
|
||||||
}
|
}
|
||||||
else if (strcmp((const char *)propValue, "material") == 0) {
|
else if (strcmp((const char *)propValue, "material") == 0) {
|
||||||
rdata->modifiers[k].value = xml_fraction(node, "value");
|
rtype->modifiers[k].value = xml_fraction(node, "value");
|
||||||
rdata->modifiers[k].flags = RMF_SAVEMATERIAL;
|
rtype->modifiers[k].flags = RMF_SAVEMATERIAL;
|
||||||
}
|
}
|
||||||
else if (strcmp((const char *)propValue, "require") == 0) {
|
else if (strcmp((const char *)propValue, "require") == 0) {
|
||||||
xmlChar *propBldg = xmlGetProp(node, BAD_CAST "building");
|
xmlChar *propBldg = xmlGetProp(node, BAD_CAST "building");
|
||||||
if (propBldg != NULL) {
|
if (propBldg != NULL) {
|
||||||
btype = bt_get_or_create((const char *)propBldg);
|
btype = bt_get_or_create((const char *)propBldg);
|
||||||
rdata->modifiers[k].btype = btype;
|
rtype->modifiers[k].btype = btype;
|
||||||
rdata->modifiers[k].flags = RMF_REQUIREDBUILDING;
|
rtype->modifiers[k].flags = RMF_REQUIREDBUILDING;
|
||||||
xmlFree(propBldg);
|
xmlFree(propBldg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue