From bfc801b6b7780e8d7abebb0a9be8b8f97cacc742 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 21 Sep 2007 23:49:39 +0000 Subject: [PATCH] http://eressea.upb.de/mantis/view.php?id=1275 "Pferde verschwinden nach GIB 0" fixed the give_horses function being used. --- src/common/gamecode/give.c | 4 +--- src/common/kernel/item.c | 21 +++++++++++++++++---- src/common/kernel/item.h | 2 +- src/common/kernel/xmlreader.c | 2 +- src/res/resources.xml | 5 ++++- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/common/gamecode/give.c b/src/common/gamecode/give.c index 64680d2a1..c2b5e395f 100644 --- a/src/common/gamecode/give.c +++ b/src/common/gamecode/give.c @@ -116,9 +116,7 @@ give_item(int want, const item_type * itype, unit * src, unit * dest, struct ord error = 36; } else if (itype->flags & ITF_CURSED) { error = 25; - } else if (itype->give && !itype->give(src, dest, itype, n, ord)) { - return -1; - } else { + } else if (itype->give==NULL || itype->give(src, dest, itype, n, ord)!=0) { int use = use_pooled(src, item2resource(itype), GET_SLACK, n); if (useregion, rhorses(s->region) + n); - return true; + return 0; + } + return -1; /* use the mechanism */ +} + +static int +give_money(unit * s, unit * d, const item_type * itype, int n, struct order * ord) +{ + if (d==NULL) { + rsetmoney(s->region, rmoney(s->region) + n); + return 0; + } + return -1; /* use the mechanism */ } #define R_MINOTHER R_SILVER @@ -901,6 +913,7 @@ init_resources(void) r_silver = new_resourcetype(&names[0], NULL, RTF_ITEM|RTF_POOLED); i_silver = new_itemtype(r_silver, ITF_NONE, 1/*weight*/, 0); r_silver->uchange = res_changeitem; + i_silver->give = give_money; r_permaura = new_resourcetype(&names[4], NULL, RTF_NONE); r_permaura->uchange = res_changepermaura; diff --git a/src/common/kernel/item.h b/src/common/kernel/item.h index 0fb580f4f..cf8e91924 100644 --- a/src/common/kernel/item.h +++ b/src/common/kernel/item.h @@ -128,7 +128,7 @@ typedef struct item_type { /* --- functions --- */ int (*use)(struct unit * user, const struct item_type * itype, int amount, struct order * ord); int (*useonother)(struct unit * user, int targetno, const struct item_type * itype, int amount, struct order * ord); - boolean (*give)(const struct unit * src, const struct unit * dest, const struct item_type * itm, int number, struct order * ord); + int (*give)(struct unit * src, struct unit * dest, const struct item_type * itm, int number, struct order * ord); #ifdef SCORE_MODULE int score; #endif diff --git a/src/common/kernel/xmlreader.c b/src/common/kernel/xmlreader.c index 6bfeeb779..64205f3f7 100644 --- a/src/common/kernel/xmlreader.c +++ b/src/common/kernel/xmlreader.c @@ -836,7 +836,7 @@ xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype) } assert(propValue!=NULL); if (strcmp((const char*)propValue, "give")==0) { - itype->give = (boolean (*)(const struct unit*, const struct unit*, const struct item_type *, int, struct order *))fun; + itype->give = (int (*)(struct unit*, struct unit*, const struct item_type *, int, struct order *))fun; } else if (strcmp((const char*)propValue, "use")==0) { itype->use = (int (*)(struct unit *, const struct item_type *, int, struct order *))fun; } else if (strcmp((const char*)propValue, "useonother")==0) { diff --git a/src/res/resources.xml b/src/res/resources.xml index da9392703..6670f4535 100644 --- a/src/res/resources.xml +++ b/src/res/resources.xml @@ -70,7 +70,9 @@ - + + + @@ -112,6 +114,7 @@ +