From b7130d8ba7a1879262aafe9a4c8b3b4ec856d916 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 30 Jan 2005 23:33:28 +0000 Subject: [PATCH] =?UTF-8?q?Im=20xml=20reader=20k=C3=B6nnen=20jetzt=20daten?= =?UTF-8?q?,=20die=20gamecode-related=20sind,=20abgeschaltet=20werden=20(e?= =?UTF-8?q?twas=20komische=20API,=20aber=20es=20geht.=20Das=20verhindert,?= =?UTF-8?q?=20dass=20der=20Mapper=20(der=20gamecode=20nicht=20linkt)=20?= =?UTF-8?q?=C3=BCber=20fehlende=20use-Funktionen=20von=20items=20jammert.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mehr von den Funktionen in den gamecode geschoben. Insbesondere Artrewards. Die entsprechenden Items sind raus aus dem Code und rein in eine XML-Datei (artrewards.xml), die dann nur von Eressea geladen wird. --- src/common/gamecode/items.c | 106 ++++++++++++++++++++ src/common/items/artrewards.c | 171 --------------------------------- src/common/kernel/xmlreader.c | 66 +++++++------ src/common/kernel/xmlreader.h | 1 + src/eressea/main.c | 1 + src/eressea/server.cpp | 1 + src/res/eressea.xml | 1 + src/res/eressea/artrewards.xml | 32 ++++++ 8 files changed, 179 insertions(+), 200 deletions(-) create mode 100644 src/res/eressea/artrewards.xml diff --git a/src/common/gamecode/items.c b/src/common/gamecode/items.c index 05cc3a7a1..818ff1f8e 100644 --- a/src/common/gamecode/items.c +++ b/src/common/gamecode/items.c @@ -2,8 +2,11 @@ #include #include "items.h" +#include +#include #include #include +#include #include #include #include @@ -16,6 +19,7 @@ #include #include +#include /* BEGIN studypotion */ #define MAXGAIN 15 @@ -86,9 +90,111 @@ use_speedsail(struct unit * u, const struct item_type * itype, int amount, struc } /* END speedsail */ +static int +use_instantartsculpture(struct unit * u, const struct item_type * itype, + int amount, struct order * ord) +{ + building *b; + + if(u->region->land == NULL) { + cmistake(u, ord, 242, MSG_MAGIC); + return -1; + } + + b = new_building(bt_find("artsculpture"), u->region, u->faction->locale); + b->size = 100; + sprintf(buf, "%s", LOC(u->faction->locale, "artsculpture")); + set_string(&b->name, buf); + + ADDMSG(&u->region->msgs, msg_message("artsculpture_create", "unit region", + u, u->region)); + + itype->rtype->uchange(u, itype->rtype, -1); + + return 0; +} + +static int +use_instantartacademy(struct unit * u, const struct item_type * itype, + int amount, struct order * ord) +{ + building *b; + + if(u->region->land == NULL) { + cmistake(u, ord, 242, MSG_MAGIC); + return -1; + } + + b = new_building(bt_find("artacademy"), u->region, u->faction->locale); + b->size = 100; + sprintf(buf, "%s", LOC(u->faction->locale, "artacademy")); + set_string(&b->name, buf); + + ADDMSG(&u->region->msgs, msg_message( + "artacademy_create", "unit region", u, u->region)); + + itype->rtype->uchange(u, itype->rtype, -1); + + return 0; +} + +#define BAGPIPEFRACTION dice_rand("2d4+2") +#define BAGPIPEDURATION dice_rand("2d10+4") + +static int +use_bagpipeoffear(struct unit * u, const struct item_type * itype, + int amount, struct order * ord) +{ + int money; + + if(get_curse(u->region->attribs, ct_find("depression"))) { + cmistake(u, ord, 58, MSG_MAGIC); + return -1; + } + + money = entertainmoney(u->region)/BAGPIPEFRACTION; + change_money(u, money); + rsetmoney(u->region, rmoney(u->region) - money); + + create_curse(u, &u->region->attribs, ct_find("depression"), + 20, BAGPIPEDURATION, 0, 0); + + ADDMSG(&u->faction->msgs, msg_message("bagpipeoffear_faction", + "unit region command money", u, u->region, ord, money)); + + ADDMSG(&u->region->msgs, msg_message("bagpipeoffear_region", + "unit money", u, money)); + + return 0; +} + +static int +use_aurapotion50(struct unit * u, const struct item_type * itype, + int amount, struct order * ord) +{ + if(!is_mage(u)) { + cmistake(u, ord, 214, MSG_MAGIC); + return -1; + } + + change_spellpoints(u, 50); + + ADDMSG(&u->faction->msgs, msg_message("aurapotion50", + "unit region command", u, u->region, ord)); + + itype->rtype->uchange(u, itype->rtype, -1); + + return 0; +} + + void register_itemimplementations(void) { + register_function((pf_generic)use_instantartsculpture, "use_instantartsculpture"); register_function((pf_generic)use_studypotion, "use_studypotion"); register_function((pf_generic)use_speedsail, "use_speedsail"); + register_function((pf_generic)use_instantartacademy, "use_instantartacademy"); + register_function((pf_generic)use_bagpipeoffear, "use_bagpipeoffear"); + register_function((pf_generic)use_aurapotion50, "use_aurapotion50"); } diff --git a/src/common/items/artrewards.c b/src/common/items/artrewards.c index 61f47f042..8da51c0e2 100644 --- a/src/common/items/artrewards.c +++ b/src/common/items/artrewards.c @@ -25,7 +25,6 @@ #include #include #include -#include /* util includes */ #include @@ -161,168 +160,6 @@ item_type it_trappedairelemental = { }; -static int -use_aurapotion50(struct unit * u, const struct item_type * itype, - int amount, struct order * ord) -{ - if(!is_mage(u)) { - cmistake(u, ord, 214, MSG_MAGIC); - return -1; - } - - change_spellpoints(u, 50); - - ADDMSG(&u->faction->msgs, msg_message("aurapotion50", - "unit region command", u, u->region, ord)); - - itype->rtype->uchange(u, itype->rtype, -1); - - return 0; -} - -static resource_type rt_aurapotion50 = { - { "aurapotion50", "aurapotion50_p" }, - { "aurapotion50", "aurapotion50_p" }, - RTF_ITEM, - &res_changeitem -}; - -item_type it_aurapotion50 = { - &rt_aurapotion50, /* resourcetype */ - 0, 1, 0, /* flags, weight, capacity */ - NULL, /* construction */ - &use_aurapotion50, - NULL, - NULL -}; - -#define BAGPIPEFRACTION dice_rand("2d4+2") -#define BAGPIPEDURATION dice_rand("2d10+4") - -static int -use_bagpipeoffear(struct unit * u, const struct item_type * itype, - int amount, struct order * ord) -{ - int money; - - if(get_curse(u->region->attribs, ct_find("depression"))) { - cmistake(u, ord, 58, MSG_MAGIC); - return -1; - } - - money = entertainmoney(u->region)/BAGPIPEFRACTION; - change_money(u, money); - rsetmoney(u->region, rmoney(u->region) - money); - - create_curse(u, &u->region->attribs, ct_find("depression"), - 20, BAGPIPEDURATION, 0, 0); - - ADDMSG(&u->faction->msgs, msg_message("bagpipeoffear_faction", - "unit region command money", u, u->region, ord, money)); - - ADDMSG(&u->region->msgs, msg_message("bagpipeoffear_region", - "unit money", u, money)); - - return 0; -} - -static resource_type rt_bagpipeoffear = { - { "bagpipeoffear", "bagpipeoffear_p" }, - { "bagpipeoffear", "bagpipeoffear_p" }, - RTF_ITEM, - &res_changeitem -}; - -item_type it_bagpipeoffear = { - &rt_bagpipeoffear, /* resourcetype */ - 0, 1, 0, /* flags, weight, capacity */ - NULL, /* construction */ - &use_bagpipeoffear, - NULL, - NULL -}; - -static int -use_instantartacademy(struct unit * u, const struct item_type * itype, - int amount, struct order * ord) -{ - building *b; - - if(u->region->land == NULL) { - cmistake(u, ord, 242, MSG_MAGIC); - return -1; - } - - b = new_building(bt_find("artacademy"), u->region, u->faction->locale); - b->size = 100; - sprintf(buf, "%s", LOC(u->faction->locale, "artacademy")); - set_string(&b->name, buf); - - ADDMSG(&u->region->msgs, msg_message( - "artacademy_create", "unit region", u, u->region)); - - itype->rtype->uchange(u, itype->rtype, -1); - - return 0; -} - -static resource_type rt_instantartacademy = { - { "instantartacademy", "instantartacademy_p" }, - { "instantartacademy", "instantartacademy_p" }, - RTF_ITEM, - &res_changeitem -}; - -item_type it_instantartacademy = { - &rt_instantartacademy, /* resourcetype */ - 0, 1, 0, /* flags, weight, capacity */ - NULL, /* construction */ - &use_instantartacademy, - NULL, - NULL -}; - -static int -use_instantartsculpture(struct unit * u, const struct item_type * itype, - int amount, struct order * ord) -{ - building *b; - - if(u->region->land == NULL) { - cmistake(u, ord, 242, MSG_MAGIC); - return -1; - } - - b = new_building(bt_find("artsculpture"), u->region, u->faction->locale); - b->size = 100; - sprintf(buf, "%s", LOC(u->faction->locale, "artsculpture")); - set_string(&b->name, buf); - - ADDMSG(&u->region->msgs, msg_message("artsculpture_create", "unit region", - u, u->region)); - - itype->rtype->uchange(u, itype->rtype, -1); - - return 0; -} - -static resource_type rt_instantartsculpture = { - { "instantartsculpture", "instantartsculpture_p" }, - { "instantartsculpture", "instantartsculpture_p" }, - RTF_ITEM, - &res_changeitem -}; - -item_type it_instantartsculpture = { - &rt_instantartsculpture, /* resourcetype */ - 0, 1, 0, /* flags, weight, capacity */ - NULL, /* construction */ - &use_instantartsculpture, - NULL, - NULL -}; - - void register_artrewards(void) { @@ -331,12 +168,4 @@ register_artrewards(void) register_function((pf_generic)use_hornofdancing, "usehornofdancing"); it_register(&it_trappedairelemental); register_function((pf_generic)use_trappedairelemental, "trappedairelemental"); - it_register(&it_aurapotion50); - register_function((pf_generic)use_aurapotion50, "aurapotion50"); - it_register(&it_bagpipeoffear); - register_function((pf_generic)use_bagpipeoffear, "bagpipeoffear"); - it_register(&it_instantartacademy); - register_function((pf_generic)use_instantartacademy, "instantartacademy"); - it_register(&it_instantartsculpture); - register_function((pf_generic)use_instantartsculpture, "instantartsculpture"); } diff --git a/src/common/kernel/xmlreader.c b/src/common/kernel/xmlreader.c index e9cf3e967..ff7693d8c 100644 --- a/src/common/kernel/xmlreader.c +++ b/src/common/kernel/xmlreader.c @@ -41,6 +41,13 @@ without prior permission by the authors of Eressea. #include #include +static boolean gamecode_enabled = false; + +void +enable_xml_gamecode(void) +{ + gamecode_enabled = true; +} static void xml_readtext(xmlNodePtr node, struct locale ** lang, xmlChar **text) @@ -539,41 +546,42 @@ xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype) } xmlXPathFreeObject(result); - /* reading item/function */ - xpath->node = node; - result = xmlXPathEvalExpression(BAD_CAST "function", xpath); - for (k=0;k!=result->nodesetval->nodeNr;++k) { - xmlNodePtr node = result->nodesetval->nodeTab[k]; - xmlChar * property; - pf_generic fun; + if (gamecode_enabled) { + /* reading item/function */ + xpath->node = node; + result = xmlXPathEvalExpression(BAD_CAST "function", xpath); + for (k=0;k!=result->nodesetval->nodeNr;++k) { + xmlNodePtr node = result->nodesetval->nodeTab[k]; + xmlChar * property; + pf_generic fun; - property = xmlGetProp(node, BAD_CAST "value"); - assert(property!=NULL); - fun = get_function((const char*)property); - if (fun==NULL) { - log_error(("unknown function name '%s' for item '%s'\n", - (const char*)property, rtype->_name[0])); + property = xmlGetProp(node, BAD_CAST "value"); + assert(property!=NULL); + fun = get_function((const char*)property); + if (fun==NULL) { + log_error(("unknown function name '%s' for item '%s'\n", + (const char*)property, rtype->_name[0])); + xmlFree(property); + continue; + } xmlFree(property); - continue; - } - xmlFree(property); - property = xmlGetProp(node, BAD_CAST "name"); - assert(property!=NULL); - if (strcmp((const char*)property, "give")==0) { - itype->give = (boolean (*)(const struct unit*, const struct unit*, const struct item_type *, int, struct order *))fun; + property = xmlGetProp(node, BAD_CAST "name"); + assert(property!=NULL); + if (strcmp((const char*)property, "give")==0) { + itype->give = (boolean (*)(const struct unit*, const struct unit*, const struct item_type *, int, struct order *))fun; + } + else if (strcmp((const char*)property, "use")==0) { + itype->use = (int (*)(struct unit *, const struct item_type *, int, struct order *))fun; + } else { + log_error(("unknown function type '%s' for item '%s'\n", + (const char*)property, rtype->_name[0])); + } + xmlFree(property); } - else if (strcmp((const char*)property, "use")==0) { - itype->use = (int (*)(struct unit *, const struct item_type *, int, struct order *))fun; - } else { - log_error(("unknown function type '%s' for item '%s'\n", - (const char*)property, rtype->_name[0])); - } - xmlFree(property); + xmlXPathFreeObject(result); } - xmlXPathFreeObject(result); - xpath->node = node; return itype; } diff --git a/src/common/kernel/xmlreader.h b/src/common/kernel/xmlreader.h index 2d1dfc456..37cfe842a 100644 --- a/src/common/kernel/xmlreader.h +++ b/src/common/kernel/xmlreader.h @@ -17,6 +17,7 @@ extern "C" { #endif #include extern void register_xmlreader(void); + extern void enable_xml_gamecode(void); #ifdef __cplusplus } #endif diff --git a/src/eressea/main.c b/src/eressea/main.c index 9e48634ae..755149534 100644 --- a/src/eressea/main.c +++ b/src/eressea/main.c @@ -177,6 +177,7 @@ game_init(void) #endif register_xmlreader(); + enable_xml_gamecode(); init_spells(); init_data(xmlfile); diff --git a/src/eressea/server.cpp b/src/eressea/server.cpp index 5eecb6609..e5715c2b5 100644 --- a/src/eressea/server.cpp +++ b/src/eressea/server.cpp @@ -183,6 +183,7 @@ game_init(void) #endif register_xmlreader(); + enable_xml_gamecode(); init_spells(); init_data(xmlfile); diff --git a/src/res/eressea.xml b/src/res/eressea.xml index 46b25d73f..60d1bace5 100644 --- a/src/res/eressea.xml +++ b/src/res/eressea.xml @@ -32,6 +32,7 @@ + diff --git a/src/res/eressea/artrewards.xml b/src/res/eressea/artrewards.xml new file mode 100644 index 000000000..181f93969 --- /dev/null +++ b/src/res/eressea/artrewards.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +