Im xml reader können jetzt daten, die gamecode-related sind, abgeschaltet werden (etwas komische API, aber es geht. Das verhindert, dass der Mapper (der gamecode nicht linkt) über fehlende use-Funktionen von items jammert.

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.
This commit is contained in:
Enno Rehling 2005-01-30 23:33:28 +00:00
parent a44951cf6f
commit b7130d8ba7
8 changed files with 179 additions and 200 deletions

View File

@ -2,8 +2,11 @@
#include <kernel/eressea.h> #include <kernel/eressea.h>
#include "items.h" #include "items.h"
#include <kernel/curse.h>
#include <kernel/building.h>
#include <kernel/faction.h> #include <kernel/faction.h>
#include <kernel/item.h> #include <kernel/item.h>
#include <kernel/magic.h>
#include <kernel/message.h> #include <kernel/message.h>
#include <kernel/movement.h> #include <kernel/movement.h>
#include <kernel/order.h> #include <kernel/order.h>
@ -16,6 +19,7 @@
#include <util/attrib.h> #include <util/attrib.h>
#include <util/functions.h> #include <util/functions.h>
#include <util/rand.h>
/* BEGIN studypotion */ /* BEGIN studypotion */
#define MAXGAIN 15 #define MAXGAIN 15
@ -86,9 +90,111 @@ use_speedsail(struct unit * u, const struct item_type * itype, int amount, struc
} }
/* END speedsail */ /* 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 void
register_itemimplementations(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_studypotion, "use_studypotion");
register_function((pf_generic)use_speedsail, "use_speedsail"); 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");
} }

View File

@ -25,7 +25,6 @@
#include <kernel/message.h> #include <kernel/message.h>
#include <kernel/magic.h> #include <kernel/magic.h>
#include <kernel/ship.h> #include <kernel/ship.h>
#include <kernel/building.h>
/* util includes */ /* util includes */
#include <util/functions.h> #include <util/functions.h>
@ -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 void
register_artrewards(void) register_artrewards(void)
{ {
@ -331,12 +168,4 @@ register_artrewards(void)
register_function((pf_generic)use_hornofdancing, "usehornofdancing"); register_function((pf_generic)use_hornofdancing, "usehornofdancing");
it_register(&it_trappedairelemental); it_register(&it_trappedairelemental);
register_function((pf_generic)use_trappedairelemental, "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");
} }

View File

@ -41,6 +41,13 @@ without prior permission by the authors of Eressea.
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
static boolean gamecode_enabled = false;
void
enable_xml_gamecode(void)
{
gamecode_enabled = true;
}
static void static void
xml_readtext(xmlNodePtr node, struct locale ** lang, xmlChar **text) xml_readtext(xmlNodePtr node, struct locale ** lang, xmlChar **text)
@ -539,41 +546,42 @@ xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
} }
xmlXPathFreeObject(result); xmlXPathFreeObject(result);
/* reading item/function */ if (gamecode_enabled) {
xpath->node = node; /* reading item/function */
result = xmlXPathEvalExpression(BAD_CAST "function", xpath); xpath->node = node;
for (k=0;k!=result->nodesetval->nodeNr;++k) { result = xmlXPathEvalExpression(BAD_CAST "function", xpath);
xmlNodePtr node = result->nodesetval->nodeTab[k]; for (k=0;k!=result->nodesetval->nodeNr;++k) {
xmlChar * property; xmlNodePtr node = result->nodesetval->nodeTab[k];
pf_generic fun; xmlChar * property;
pf_generic fun;
property = xmlGetProp(node, BAD_CAST "value"); property = xmlGetProp(node, BAD_CAST "value");
assert(property!=NULL); assert(property!=NULL);
fun = get_function((const char*)property); fun = get_function((const char*)property);
if (fun==NULL) { if (fun==NULL) {
log_error(("unknown function name '%s' for item '%s'\n", log_error(("unknown function name '%s' for item '%s'\n",
(const char*)property, rtype->_name[0])); (const char*)property, rtype->_name[0]));
xmlFree(property);
continue;
}
xmlFree(property); xmlFree(property);
continue;
}
xmlFree(property);
property = xmlGetProp(node, BAD_CAST "name"); property = xmlGetProp(node, BAD_CAST "name");
assert(property!=NULL); assert(property!=NULL);
if (strcmp((const char*)property, "give")==0) { if (strcmp((const char*)property, "give")==0) {
itype->give = (boolean (*)(const struct unit*, const struct unit*, const struct item_type *, int, struct order *))fun; 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) { xmlXPathFreeObject(result);
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);
xpath->node = node;
return itype; return itype;
} }

View File

@ -17,6 +17,7 @@ extern "C" {
#endif #endif
#include <libxml/tree.h> #include <libxml/tree.h>
extern void register_xmlreader(void); extern void register_xmlreader(void);
extern void enable_xml_gamecode(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -177,6 +177,7 @@ game_init(void)
#endif #endif
register_xmlreader(); register_xmlreader();
enable_xml_gamecode();
init_spells(); init_spells();
init_data(xmlfile); init_data(xmlfile);

View File

@ -183,6 +183,7 @@ game_init(void)
#endif #endif
register_xmlreader(); register_xmlreader();
enable_xml_gamecode();
init_spells(); init_spells();
init_data(xmlfile); init_data(xmlfile);

View File

@ -32,6 +32,7 @@
<xi:include href="eressea/en/strings.xml"/> <xi:include href="eressea/en/strings.xml"/>
<xi:include href="eressea/races.xml"/> <xi:include href="eressea/races.xml"/>
<xi:include href="eressea/items.xml"/> <xi:include href="eressea/items.xml"/>
<xi:include href="eressea/artrewards.xml"/>
<xi:include href="eressea/dungeons.xml"/> <xi:include href="eressea/dungeons.xml"/>
<xi:include href="eressea/temple.xml"/> <xi:include href="eressea/temple.xml"/>
<strings> <strings>

View File

@ -0,0 +1,32 @@
<?xml version="1.0"?>
<resources>
<resource name="instantartsculpture">
<function name="change" value="changeitem"/>
<item weight="1">
<function name="use" value="use_instantartsculpture"/>
</item>
</resource>
<resource name="instantartacademy">
<function name="change" value="changeitem"/>
<item weight="1">
<function name="use" value="use_instantacademy"/>
</item>
</resource>
<resource name="aurapotion50">
<function name="change" value="changeitem"/>
<item weight="1">
<function name="use" value="use_aurapotion50"/>
</item>
</resource>
<resource name="bagpipeoffear">
<function name="change" value="changeitem"/>
<item weight="1">
<function name="use" value="use_bagpipeoffear"/>
</item>
</resource>
</resources>