From d305e983b22a35d5b5edda6b2bf8c0473f8a5445 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 31 Oct 2008 17:50:19 +0000 Subject: [PATCH] http://bugs.eressea.de/view.php?id=1499 MACHEN Adamantium - Adamantium and Laen require a mine (and this is now a xml-configuration) - everything compiles with the latest luabind/boost/lua version - fixed a broken assert --- src/common/gamecode/economy.c | 40 +++++++++++++---------------------- src/common/kernel/item.h | 2 ++ src/common/kernel/unit.c | 2 +- src/common/kernel/xmlreader.c | 19 ++++++++++++++--- src/eressea/lua/list.h | 1 + src/res/eressea/items.xml | 1 + src/res/resources.xml | 1 + 7 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index 72824efed..6d404e15e 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -1347,21 +1347,26 @@ allocate_resource(unit * u, const resource_type * rtype, int want) return; } } - - if (itype == olditemtype[I_LAEN]) { - struct building * b = inside_building(u); - const struct building_type * btype = b?b->type:NULL; - if (btype != bt_find("mine")) { - cmistake(u, u->thisorder, 104, MSG_PRODUCE); - return; - } - } - + if (besieged(u)) { cmistake(u, u->thisorder, 60, MSG_PRODUCE); return; } + if (rdata->modifiers) { + resource_mod * mod = rdata->modifiers; + for (;mod->flags!=0;++mod) { + if (mod->flags & RMF_REQUIREDBUILDING) { + struct building * b = inside_building(u); + const struct building_type * btype = b?b->type:NULL; + if (mod->btype && mod->btype!=btype) { + cmistake(u, u->thisorder, 104, MSG_PRODUCE); + return; + } + } + } + } + if (rdata->guard!=0) { unit * u2; for (u2 = r->units; u2; u2 = u2->next) { @@ -1472,21 +1477,6 @@ allocate_resource(unit * u, const resource_type * rtype, int want) } } } - } else if (itype==olditemtype[I_IRON]) { - struct building * b = inside_building(u); - const struct building_type * btype = b?b->type:NULL; - if (btype==bt_find("mine")) - al->save *= 0.5; - if (u->race == new_race[RC_DWARF]) { - al->save *= 0.75; - } - } else if (itype==olditemtype[I_STONE]) { - struct building * b = inside_building(u); - const struct building_type * btype = b?b->type:NULL; - if (btype==bt_find("quarry")) - al->save = al->save*0.5; - if (u->race == new_race[RC_TROLL]) - al->save = al->save*0.75; } } diff --git a/src/common/kernel/item.h b/src/common/kernel/item.h index 7eaa54bd7..e1fd7be9b 100644 --- a/src/common/kernel/item.h +++ b/src/common/kernel/item.h @@ -78,6 +78,8 @@ extern const resource_type * findresourcetype(const char * name, const struct lo #define RMF_SKILL 0x01 /* int, bonus on resource production skill */ #define RMF_SAVEMATERIAL 0x02 /* float, multiplier on resource usage */ #define RMF_SAVERESOURCE 0x03 /* int, bonus on resource production skill */ +#define RMF_REQUIREDBUILDING 0x04 /* building, required to build */ + typedef struct resource_mod { variant value; const struct building_type * btype; diff --git a/src/common/kernel/unit.c b/src/common/kernel/unit.c index a2dca0598..82078d61b 100644 --- a/src/common/kernel/unit.c +++ b/src/common/kernel/unit.c @@ -1053,7 +1053,7 @@ set_number(unit * u, int count) u->faction->num_people += count - u->number; } u->number = (unsigned short)count; - } else { + } else if (u->number>0) { assert(!"why doesn't this unit have a faction? this will fuck up num_people"); } } diff --git a/src/common/kernel/xmlreader.c b/src/common/kernel/xmlreader.c index 7bb529952..b22027400 100644 --- a/src/common/kernel/xmlreader.c +++ b/src/common/kernel/xmlreader.c @@ -1038,13 +1038,26 @@ parse_resources(xmlDocPtr doc) assert(propValue!=NULL); if (strcmp((const char *)propValue, "skill")==0) { rdata->modifiers[k].value.i = xml_ivalue(node, "value", 0); - rdata->modifiers[k].flags |= RMF_SKILL; + rdata->modifiers[k].flags = RMF_SKILL; } else if (strcmp((const char *)propValue, "material")==0) { rdata->modifiers[k].value.f = (float)xml_fvalue(node, "value", 0); - rdata->modifiers[k].flags |= RMF_SAVEMATERIAL; + rdata->modifiers[k].flags = RMF_SAVEMATERIAL; } else if (strcmp((const char *)propValue, "resource")==0) { rdata->modifiers[k].value.f = (float)xml_fvalue(node, "value", 0); - rdata->modifiers[k].flags |= RMF_SAVERESOURCE; + rdata->modifiers[k].flags = RMF_SAVERESOURCE; + } else if (strcmp((const char *)propValue, "require")==0) { + xmlChar * propBldg = xmlGetProp(node, BAD_CAST "building"); + if (propBldg!=NULL) { + btype = bt_find((const char*)propBldg); + if (btype==NULL) { + btype = calloc(sizeof(building_type), 1); + btype->_name = strdup((const char *)propBldg); + bt_register(btype); + } + rdata->modifiers[k].btype = btype; + rdata->modifiers[k].flags = RMF_REQUIREDBUILDING; + xmlFree(propBldg); + } } else { log_error(("unknown type '%s' for resourcelimit-modifier '%s'\n", (const char*)propValue, rtype->_name[0])); diff --git a/src/eressea/lua/list.h b/src/eressea/lua/list.h index 0cad21dd3..fe9834d76 100644 --- a/src/eressea/lua/list.h +++ b/src/eressea/lua/list.h @@ -19,6 +19,7 @@ namespace eressea { class iterator { public: iterator(const N& index) : m_index(index) {} + ~iterator() {} T operator*() { return nodetype::value(m_index); } bool operator==(const iterator& iter) { return iter.m_index==m_index; diff --git a/src/res/eressea/items.xml b/src/res/eressea/items.xml index 33b0ca2ca..a1efc9620 100644 --- a/src/res/eressea/items.xml +++ b/src/res/eressea/items.xml @@ -169,6 +169,7 @@ + diff --git a/src/res/resources.xml b/src/res/resources.xml index 55be4f60f..46089da90 100644 --- a/src/res/resources.xml +++ b/src/res/resources.xml @@ -96,6 +96,7 @@ +