forked from github/server
hacked the item-use function,
XML needs cleaning up, funpointer needs to die
This commit is contained in:
parent
44c3838d79
commit
715c8569ba
|
@ -13,6 +13,7 @@ without prior permission by the authors of Eressea.
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "vortex.h"
|
#include "vortex.h"
|
||||||
|
#include "alchemy.h"
|
||||||
|
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
#include <util/base36.h>
|
#include <util/base36.h>
|
||||||
|
@ -491,20 +492,21 @@ static int lua_equipmentcallback(const struct equipment *eq, unit * u)
|
||||||
|
|
||||||
/** callback for an item-use function written in lua. */
|
/** callback for an item-use function written in lua. */
|
||||||
static int
|
static int
|
||||||
use_item_lua(struct unit *u, const struct item_type *itype, int amount,
|
use_item_lua(unit *u, const item_type *itype, int amount, struct order *ord)
|
||||||
struct order *ord)
|
|
||||||
{
|
{
|
||||||
lua_State *L = (lua_State *)global.vm_state;
|
lua_State *L = (lua_State *)global.vm_state;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
char fname[64];
|
char fname[64];
|
||||||
|
int (*callout)(unit *, const item_type *, int, struct order *);
|
||||||
if (itype->use) {
|
|
||||||
return itype->use(u, itype, amount, ord);
|
|
||||||
}
|
|
||||||
|
|
||||||
strlcpy(fname, "use_", sizeof(fname));
|
strlcpy(fname, "use_", sizeof(fname));
|
||||||
strlcat(fname, itype->rtype->_name, sizeof(fname));
|
strlcat(fname, itype->rtype->_name, sizeof(fname));
|
||||||
|
|
||||||
|
callout = (int(*)(unit *, const item_type *, int, struct order *))get_function(fname);
|
||||||
|
if (callout) {
|
||||||
|
return callout(u, itype, amount, ord);
|
||||||
|
}
|
||||||
|
|
||||||
lua_getglobal(L, fname);
|
lua_getglobal(L, fname);
|
||||||
if (lua_isfunction(L, -1)) {
|
if (lua_isfunction(L, -1)) {
|
||||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
||||||
|
@ -520,11 +522,18 @@ struct order *ord)
|
||||||
result = (int)lua_tonumber(L, -1);
|
result = (int)lua_tonumber(L, -1);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
else {
|
if (itype->rtype->ptype) {
|
||||||
log_error("use(%s) calling '%s': not a function.\n", unitname(u), fname);
|
return use_potion(u, itype, amount, ord);
|
||||||
lua_pop(L, 1);
|
} else {
|
||||||
|
log_error("no such callout: %s", fname);
|
||||||
}
|
}
|
||||||
|
if (itype->use) {
|
||||||
|
return itype->use(u, itype, amount, ord);
|
||||||
|
}
|
||||||
|
log_error("use(%s) calling '%s': not a function.\n", unitname(u), fname);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1292,9 +1292,9 @@ void register_resources(void)
|
||||||
register_item_use(use_tacticcrystal, "use_tacticcrystal");
|
register_item_use(use_tacticcrystal, "use_tacticcrystal");
|
||||||
register_item_use(use_birthdayamulet, "use_birthdayamulet");
|
register_item_use(use_birthdayamulet, "use_birthdayamulet");
|
||||||
register_item_use(use_warmthpotion, "usewarmthpotion");
|
register_item_use(use_warmthpotion, "usewarmthpotion");
|
||||||
register_item_use(use_bloodpotion, "usebloodpotion");
|
register_item_use(use_bloodpotion, "use_peasantblood");
|
||||||
register_item_use(use_healingpotion, "usehealingpotion");
|
register_item_use(use_healingpotion, "usehealingpotion");
|
||||||
register_item_use(use_foolpotion, "usefoolpotion");
|
register_item_use(use_foolpotion, "use_p7");
|
||||||
register_item_use(use_mistletoe, "usemistletoe");
|
register_item_use(use_mistletoe, "usemistletoe");
|
||||||
register_item_use(use_magicboost, "usemagicboost");
|
register_item_use(use_magicboost, "usemagicboost");
|
||||||
register_item_use(use_snowball, "usesnowball");
|
register_item_use(use_snowball, "usesnowball");
|
||||||
|
|
|
@ -805,6 +805,10 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "potion", xpath);
|
result = xmlXPathEvalExpression(BAD_CAST "potion", xpath);
|
||||||
assert(result->nodesetval->nodeNr <= 1);
|
assert(result->nodesetval->nodeNr <= 1);
|
||||||
if (result->nodesetval->nodeNr != 0) {
|
if (result->nodesetval->nodeNr != 0) {
|
||||||
|
if ((itype->flags & ITF_CANUSE) == 0) {
|
||||||
|
log_error("potion %s has no use attribute", rtype->_name);
|
||||||
|
itype->flags |= ITF_CANUSE;
|
||||||
|
}
|
||||||
xpath->node = result->nodesetval->nodeTab[0];
|
xpath->node = result->nodesetval->nodeTab[0];
|
||||||
rtype->ptype = xml_readpotion(xpath, itype);
|
rtype->ptype = xml_readpotion(xpath, itype);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue