"Pferde verschwinden nach GIB 0"
fixed the give_horses function being used.
This commit is contained in:
Enno Rehling 2007-09-21 23:49:39 +00:00
parent e3079f88cc
commit bfc801b6b7
5 changed files with 24 additions and 10 deletions

View File

@ -116,9 +116,7 @@ give_item(int want, const item_type * itype, unit * src, unit * dest, struct ord
error = 36; error = 36;
} else if (itype->flags & ITF_CURSED) { } else if (itype->flags & ITF_CURSED) {
error = 25; error = 25;
} else if (itype->give && !itype->give(src, dest, itype, n, ord)) { } else if (itype->give==NULL || itype->give(src, dest, itype, n, ord)!=0) {
return -1;
} else {
int use = use_pooled(src, item2resource(itype), GET_SLACK, n); int use = use_pooled(src, item2resource(itype), GET_SLACK, n);
if (use<n) use += use_pooled(src, item2resource(itype), GET_RESERVE|GET_POOLED_SLACK, n-use); if (use<n) use += use_pooled(src, item2resource(itype), GET_RESERVE|GET_POOLED_SLACK, n-use);
if (dest) { if (dest) {

View File

@ -567,12 +567,24 @@ i_new(const item_type * itype, int size)
#include "region.h" #include "region.h"
static boolean static int
give_horses(const unit * s, const unit * d, const item_type * itype, int n, struct order * ord) give_horses(unit * s, unit * d, const item_type * itype, int n, struct order * ord)
{ {
if (d==NULL && itype == olditemtype[I_HORSE]) if (d==NULL) {
rsethorses(s->region, rhorses(s->region) + n); rsethorses(s->region, 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 #define R_MINOTHER R_SILVER
@ -901,6 +913,7 @@ init_resources(void)
r_silver = new_resourcetype(&names[0], NULL, RTF_ITEM|RTF_POOLED); r_silver = new_resourcetype(&names[0], NULL, RTF_ITEM|RTF_POOLED);
i_silver = new_itemtype(r_silver, ITF_NONE, 1/*weight*/, 0); i_silver = new_itemtype(r_silver, ITF_NONE, 1/*weight*/, 0);
r_silver->uchange = res_changeitem; r_silver->uchange = res_changeitem;
i_silver->give = give_money;
r_permaura = new_resourcetype(&names[4], NULL, RTF_NONE); r_permaura = new_resourcetype(&names[4], NULL, RTF_NONE);
r_permaura->uchange = res_changepermaura; r_permaura->uchange = res_changepermaura;

View File

@ -128,7 +128,7 @@ typedef struct item_type {
/* --- functions --- */ /* --- functions --- */
int (*use)(struct unit * user, const struct item_type * itype, int amount, struct order * ord); 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); 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 #ifdef SCORE_MODULE
int score; int score;
#endif #endif

View File

@ -836,7 +836,7 @@ xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
} }
assert(propValue!=NULL); assert(propValue!=NULL);
if (strcmp((const char*)propValue, "give")==0) { 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) { } else if (strcmp((const char*)propValue, "use")==0) {
itype->use = (int (*)(struct unit *, const struct item_type *, int, struct order *))fun; itype->use = (int (*)(struct unit *, const struct item_type *, int, struct order *))fun;
} else if (strcmp((const char*)propValue, "useonother")==0) { } else if (strcmp((const char*)propValue, "useonother")==0) {

View File

@ -70,7 +70,9 @@
</resource> </resource>
<resource name="elvenhorse"> <resource name="elvenhorse">
<item weight="5000" notlost="yes" big="yes" score="6000" capacity="7000" animal="yes"/> <item weight="5000" notlost="yes" big="yes" score="6000" capacity="7000" animal="yes">
<function name="give" value="givehorses"/>
</item>
</resource> </resource>
<resource name="dolphin"> <resource name="dolphin">
@ -112,6 +114,7 @@
<resource name="horse" limited="yes"> <resource name="horse" limited="yes">
<item weight="5000" score="10" capacity="7000" animal="yes"> <item weight="5000" score="10" capacity="7000" animal="yes">
<construction skill="training" minskill="1" reqsize="1"/> <construction skill="training" minskill="1" reqsize="1"/>
<function name="give" value="givehorses"/>
</item> </item>
<resourcelimit> <resourcelimit>
<function name="produce" value="lua_produceresource"/> <function name="produce" value="lua_produceresource"/>