From abcaac8f97de26d075fdaff1777ebd017ae4fb43 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 25 Oct 2005 21:24:15 +0000 Subject: [PATCH] removing seeds and mallornseeds from the source (less warnings, too). --- src/common/gamecode/economy.c | 48 +++++++++--------- src/common/items/seed.c | 93 ++++++++++------------------------- src/common/items/seed.h | 6 +-- src/common/kernel/xmlreader.c | 1 + src/res/resources.xml | 10 ++++ src/todo.txt | 1 + 6 files changed, 62 insertions(+), 97 deletions(-) diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index 694e3a1e8..d46962fc7 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -2385,7 +2385,7 @@ static void planttrees(region *r, unit *u, int raw) { int n, i, skill, planted = 0; - const item_type * itype; + const resource_type * rtype; if (!fval(r->terrain, LAND_REGION)) { return; @@ -2393,9 +2393,9 @@ planttrees(region *r, unit *u, int raw) /* Mallornbäume kann man nur in Mallornregionen züchten */ if (fval(r, RF_MALLORN)) { - itype = &it_mallornseed; + rtype = rt_mallornseed; } else { - itype = &it_seed; + rtype = rt_seed; } /* Skill prüfen */ @@ -2403,22 +2403,21 @@ planttrees(region *r, unit *u, int raw) if (skill < 6) { add_message(&u->faction->msgs, msg_feedback(u, u->thisorder, "plant_skills", - "skill minskill product", SK_HERBALISM, 6, itype->rtype, 1)); + "skill minskill product", SK_HERBALISM, 6, rtype, 1)); return; } if (fval(r, RF_MALLORN) && skill < 7 ) { add_message(&u->faction->msgs, msg_feedback(u, u->thisorder, "plant_skills", - "skill minskill product", SK_HERBALISM, 7, itype->rtype, 1)); + "skill minskill product", SK_HERBALISM, 7, rtype, 1)); return; } - n = new_get_pooled(u, itype->rtype, GET_DEFAULT); + n = new_get_pooled(u, rtype, GET_DEFAULT); /* Samen prüfen */ if (n==0) { add_message(&u->faction->msgs, - msg_feedback(u, u->thisorder, "resource_missing", "missing", - itype->rtype)); + msg_feedback(u, u->thisorder, "resource_missing", "missing", rtype)); return; } @@ -2434,10 +2433,10 @@ planttrees(region *r, unit *u, int raw) /* Alles ok. Abziehen. */ produceexp(u, SK_HERBALISM, u->number); - new_use_pooled(u, itype->rtype, GET_DEFAULT, n); + new_use_pooled(u, rtype, GET_DEFAULT, n); ADDMSG(&u->faction->msgs, msg_message("plant", - "unit region amount herb", u, r, planted, itype->rtype)); + "unit region amount herb", u, r, planted, rtype)); } /* züchte bäume */ @@ -2445,7 +2444,7 @@ static void breedtrees(region *r, unit *u, int raw) { int n, i, skill, planted = 0; - const item_type * itype; + const resource_type * rtype; static int current_season = -1; if (current_season<0) current_season = get_gamedate(turn, NULL)->season; @@ -2462,9 +2461,9 @@ breedtrees(region *r, unit *u, int raw) /* Mallornbäume kann man nur in Mallornregionen züchten */ if (fval(r, RF_MALLORN)) { - itype = &it_mallornseed; + rtype = rt_mallornseed; } else { - itype = &it_seed; + rtype = rt_seed; } /* Skill prüfen */ @@ -2473,12 +2472,11 @@ breedtrees(region *r, unit *u, int raw) planttrees(r, u, raw); return; } - n = new_get_pooled(u, itype->rtype, GET_DEFAULT); + n = new_get_pooled(u, rtype, GET_DEFAULT); /* Samen prüfen */ if (n==0) { add_message(&u->faction->msgs, - msg_feedback(u, u->thisorder, "resource_missing", "missing", - itype->rtype)); + msg_feedback(u, u->thisorder, "resource_missing", "missing", rtype)); return; } @@ -2494,10 +2492,10 @@ breedtrees(region *r, unit *u, int raw) /* Alles ok. Abziehen. */ produceexp(u, SK_HERBALISM, u->number); - new_use_pooled(u, itype->rtype, GET_DEFAULT, n); + new_use_pooled(u, rtype, GET_DEFAULT, n); add_message(&u->faction->msgs, new_message(u->faction, - "plant%u:unit%r:region%i:amount%X:herb", u, r, planted, itype->rtype)); + "plant%u:unit%r:region%i:amount%X:herb", u, r, planted, rtype)); } static void @@ -2507,7 +2505,7 @@ plant_cmd(unit *u, struct order * ord) int m; const char *s; param_t p; - const item_type * itype = NULL; + const resource_type * rtype = NULL; if (r->land==NULL) { /* TODO: error message here */ @@ -2527,11 +2525,11 @@ plant_cmd(unit *u, struct order * ord) m = INT_MAX; } - if(!s[0]){ + if (!s[0]) { p = P_ANY; } else { p = findparam(s, u->faction->locale); - itype = finditemtype(s, u->faction->locale); + rtype = findresourcetype(s, u->faction->locale); } if (p==P_HERBS){ @@ -2542,8 +2540,8 @@ plant_cmd(unit *u, struct order * ord) breedtrees(r, u, m); return; } - else if (itype!=NULL){ - if (itype==&it_mallornseed || itype==&it_seed) { + else if (rtype!=NULL){ + if (rtype==rt_mallornseed || rtype==rt_seed) { breedtrees(r, u, m); return; } @@ -3240,6 +3238,6 @@ init_economy(void) add_allocator(make_allocator(item2resource(olditemtype[I_STONE]), leveled_allocation)); add_allocator(make_allocator(item2resource(olditemtype[I_IRON]), leveled_allocation)); add_allocator(make_allocator(item2resource(olditemtype[I_LAEN]), leveled_allocation)); - add_allocator(make_allocator(&rt_seed, attrib_allocation)); - add_allocator(make_allocator(&rt_mallornseed, attrib_allocation)); + add_allocator(make_allocator(rt_seed, attrib_allocation)); + add_allocator(make_allocator(rt_mallornseed, attrib_allocation)); } diff --git a/src/common/items/seed.c b/src/common/items/seed.c index ba2c83280..9ccd04d33 100644 --- a/src/common/items/seed.c +++ b/src/common/items/seed.c @@ -27,37 +27,20 @@ /* libc includes */ #include -resource_type rt_seed = { - { "seed", "seed_p" }, - { "seed", "seed_p" }, - RTF_ITEM|RTF_LIMITED, - &res_changeitem -}; - -static construction con_seed = { - SK_HERBALISM, 3, /* skill, minskill */ - -1, 1 /* maxsize, reqsize [,materials] */ -}; - -item_type it_seed = { - &rt_seed, /* resourcetype */ - 0, 10, 0, /* flags, weight, capacity */ - &con_seed, /* construction */ - NULL, /* use */ - NULL /* give */ -}; +resource_type * rt_seed = 0; +resource_type * rt_mallornseed = 0; static void produce_seeds(region * r, const resource_type * rtype, int norders) { - assert(rtype==&rt_seed && r->land && r->land->trees[0] >= norders); + assert(rtype==rt_seed && r->land && r->land->trees[0] >= norders); r->land->trees[0] -= norders; } static int limit_seeds(const region * r, const resource_type * rtype) { - assert(rtype==&rt_seed); + assert(rtype==rt_seed); if(fval(r, RF_MALLORN)) return 0; return r->land?r->land->trees[0]:0; } @@ -66,46 +49,24 @@ void register_seed(void) { attrib * a; + resource_limit * rdata; - it_register(&it_seed); - it_seed.rtype->flags |= RTF_LIMITED; - it_seed.rtype->itype->flags |= ITF_NOBUILDBESIEGED; - it_seed.rtype->flags |= RTF_POOLED; + rt_seed = rt_find("seed"); + assert(rt_seed!=NULL); + rt_seed->itype->flags |= ITF_NOBUILDBESIEGED; - a = a_add(&it_seed.rtype->attribs, a_new(&at_resourcelimit)); - { - resource_limit * rdata = (resource_limit*)a->data.v; - rdata->limit = limit_seeds; - rdata->use = produce_seeds; - } + a = a_add(&rt_seed->attribs, a_new(&at_resourcelimit)); + rdata = (resource_limit*)a->data.v; + rdata->limit = limit_seeds; + rdata->use = produce_seeds; } /* mallorn */ -resource_type rt_mallornseed = { - { "mallornseed", "mallornseed_p" }, - { "mallornseed", "mallornseed_p" }, - RTF_ITEM|RTF_LIMITED, - &res_changeitem -}; - -static construction con_mallornseed = { - SK_HERBALISM, 4, /* skill, minskill */ - -1, 1 /* maxsize, reqsize [,materials] */ -}; - -item_type it_mallornseed = { - &rt_mallornseed, /* resourcetype */ - 0, 10, 0, /* flags, weight, capacity */ - &con_mallornseed, /* construction */ - NULL, /* use */ - NULL /* give */ -}; - static void produce_mallornseeds(region * r, const resource_type * rtype, int norders) { - assert(rtype==&rt_mallornseed && r->land && r->land->trees[0] >= norders); + assert(rtype==rt_mallornseed && r->land && r->land->trees[0] >= norders); assert(fval(r, RF_MALLORN)); r->land->trees[0] -= norders; } @@ -113,8 +74,8 @@ produce_mallornseeds(region * r, const resource_type * rtype, int norders) static int limit_mallornseeds(const region * r, const resource_type * rtype) { - assert(rtype==&rt_mallornseed); - if(! fval(r, RF_MALLORN)) { + assert(rtype==rt_mallornseed); + if (!fval(r, RF_MALLORN)) { return 0; } return r->land?r->land->trees[0]:0; @@ -124,20 +85,16 @@ void register_mallornseed(void) { attrib * a; + resource_limit * rdata; - it_register(&it_mallornseed); - it_mallornseed.rtype->flags |= RTF_LIMITED; - it_mallornseed.rtype->itype->flags |= ITF_NOBUILDBESIEGED; - it_mallornseed.rtype->flags |= RTF_POOLED; - register_function((pf_generic)limit_seeds, "limit_seeds"); - register_function((pf_generic)produce_seeds, "produce_seeds"); - register_function((pf_generic)limit_mallornseeds, "limit_mallornseeds"); - register_function((pf_generic)produce_mallornseeds, "produce_mallornseeds"); + rt_mallornseed = rt_find("mallornseed"); + assert(rt_mallornseed!=NULL); + rt_mallornseed->flags |= RTF_LIMITED; + rt_mallornseed->itype->flags |= ITF_NOBUILDBESIEGED; + rt_mallornseed->flags |= RTF_POOLED; - a = a_add(&it_mallornseed.rtype->attribs, a_new(&at_resourcelimit)); - { - resource_limit * rdata = (resource_limit*)a->data.v; - rdata->limit = limit_mallornseeds; - rdata->use = produce_mallornseeds; - } + a = a_add(&rt_mallornseed->attribs, a_new(&at_resourcelimit)); + rdata = (resource_limit*)a->data.v; + rdata->limit = limit_mallornseeds; + rdata->use = produce_mallornseeds; } diff --git a/src/common/items/seed.h b/src/common/items/seed.h index d8105141c..27b00c112 100644 --- a/src/common/items/seed.h +++ b/src/common/items/seed.h @@ -19,12 +19,10 @@ extern "C" { #endif -extern struct item_type it_seed; -extern struct resource_type rt_seed; +extern struct resource_type * rt_seed; extern void register_seed(void); -extern struct item_type it_mallornseed; -extern struct resource_type rt_mallornseed; +extern struct resource_type * rt_mallornseed; extern void register_mallornseed(void); #ifdef __cplusplus diff --git a/src/common/kernel/xmlreader.c b/src/common/kernel/xmlreader.c index dc5f2eb19..370cc3eb1 100644 --- a/src/common/kernel/xmlreader.c +++ b/src/common/kernel/xmlreader.c @@ -821,6 +821,7 @@ parse_resources(xmlDocPtr doc) int k; if (xml_bvalue(node, "pooled", true)) flags |= RTF_POOLED; + if (xml_bvalue(node, "limited", false)) flags |= RTF_LIMITED; if (xml_bvalue(node, "sneak", true)) flags |= RTF_SNEAK; name = xmlGetProp(node, BAD_CAST "name"); diff --git a/src/res/resources.xml b/src/res/resources.xml index aa7c46468..84d526525 100644 --- a/src/res/resources.xml +++ b/src/res/resources.xml @@ -7,6 +7,16 @@ + + + + + + + + + + diff --git a/src/todo.txt b/src/todo.txt index f57177d3f..fd888ccd0 100644 --- a/src/todo.txt +++ b/src/todo.txt @@ -16,6 +16,7 @@ Code cleanup: - age branch (store birthdate instead of age) - give monsters name with lua - kick init_oldherbs out (good for terrain) +- allocators aus economy nach XML Larger Features: - eressea (b/g)zip reports?