diff --git a/src/common/kernel/item.h b/src/common/kernel/item.h index 52b24447d..d42e7d3d6 100644 --- a/src/common/kernel/item.h +++ b/src/common/kernel/item.h @@ -127,7 +127,7 @@ typedef struct item_type { int capacity; struct construction * construction; /* --- functions --- */ - int (*canuse)(const struct unit * user, const struct item_type * itype); + boolean (*canuse)(const struct unit * user, const struct item_type * itype); 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 (*give)(struct unit * src, struct unit * dest, const struct item_type * itm, int number, struct order * ord); diff --git a/src/eressea/tolua/helpers.c b/src/eressea/tolua/helpers.c index edca1aeff..6977cadb6 100644 --- a/src/eressea/tolua/helpers.c +++ b/src/eressea/tolua/helpers.c @@ -313,34 +313,38 @@ lua_getresource(unit * u, const struct resource_type * rtype) return result; } -static int +static boolean lua_canuse_item(const unit * u, const struct item_type * itype) { - lua_State * L = (lua_State *)global.vm_state; - int result = -1; - const char * fname = "item_canuse"; + static int function_exists = 1; + boolean result = true; - lua_pushstring(L, fname); - lua_rawget(L, LUA_GLOBALSINDEX); - if (lua_isfunction(L, 1)) { - tolua_pushusertype(L, (void *)u, "unit"); - tolua_pushstring(L, itype->rtype->_name[0]); + if (function_exists) { + lua_State * L = (lua_State *)global.vm_state; + const char * fname = "item_canuse"; - if (lua_pcall(L, 2, 1, 0)!=0) { - const char* error = lua_tostring(L, -1); - log_error(("get(%s) calling '%s': %s.\n", - unitname(u), fname, error)); - lua_pop(L, 1); + lua_pushstring(L, fname); + lua_rawget(L, LUA_GLOBALSINDEX); + if (lua_isfunction(L, 1)) { + tolua_pushusertype(L, (void *)u, "unit"); + tolua_pushstring(L, itype->rtype->_name[0]); + + if (lua_pcall(L, 2, 1, 0)!=0) { + const char* error = lua_tostring(L, -1); + log_error(("get(%s) calling '%s': %s.\n", + unitname(u), fname, error)); + lua_pop(L, 1); + } else { + result = lua_toboolean(L, -1); + lua_pop(L, 1); + } } else { - result = lua_toboolean(L, -1); + function_exists = 0; + log_error(("get(%s) calling '%s': not a function.\n", + unitname(u), fname)); lua_pop(L, 1); } - } else { - log_error(("get(%s) calling '%s': not a function.\n", - unitname(u), fname)); - lua_pop(L, 1); } - return result; } diff --git a/src/res/armor/plate-2.xml b/src/res/armor/plate-2.xml deleted file mode 100644 index eb10f6359..000000000 --- a/src/res/armor/plate-2.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/src/res/armor/plate.xml b/src/res/armor/plate.xml index 96eb8ec08..eb10f6359 100644 --- a/src/res/armor/plate.xml +++ b/src/res/armor/plate.xml @@ -1,6 +1,7 @@ + diff --git a/src/res/e2k9/armor.xml b/src/res/e2k9/armor.xml index dccc74e69..c0a47db98 100644 --- a/src/res/e2k9/armor.xml +++ b/src/res/e2k9/armor.xml @@ -1,6 +1,6 @@ - + diff --git a/src/res/e2k9/races.xml b/src/res/e2k9/races.xml index 8bf803128..585f6e397 100644 --- a/src/res/e2k9/races.xml +++ b/src/res/e2k9/races.xml @@ -66,7 +66,6 @@ - @@ -141,7 +140,7 @@ - + diff --git a/src/res/weapons/axe.xml b/src/res/weapons/axe.xml index 2eed9dc37..7ee77b21e 100644 --- a/src/res/weapons/axe.xml +++ b/src/res/weapons/axe.xml @@ -1,6 +1,7 @@ + diff --git a/src/res/weapons/greatbow.xml b/src/res/weapons/greatbow.xml index 7ae522afe..542bd41a8 100644 --- a/src/res/weapons/greatbow.xml +++ b/src/res/weapons/greatbow.xml @@ -1,6 +1,7 @@ + diff --git a/src/res/weapons/greatsword.xml b/src/res/weapons/greatsword.xml index c19980526..481ff680c 100644 --- a/src/res/weapons/greatsword.xml +++ b/src/res/weapons/greatsword.xml @@ -1,6 +1,7 @@ + diff --git a/src/res/weapons/halberd-2.xml b/src/res/weapons/halberd-2.xml index 35ff1e900..edb933701 100644 --- a/src/res/weapons/halberd-2.xml +++ b/src/res/weapons/halberd-2.xml @@ -4,6 +4,7 @@ --> + diff --git a/src/res/weapons/halberd.xml b/src/res/weapons/halberd.xml index 25a45033c..bf3fb4af7 100644 --- a/src/res/weapons/halberd.xml +++ b/src/res/weapons/halberd.xml @@ -1,6 +1,7 @@ + diff --git a/src/res/weapons/lance.xml b/src/res/weapons/lance.xml index f64bd2d6d..1271c48f9 100644 --- a/src/res/weapons/lance.xml +++ b/src/res/weapons/lance.xml @@ -1,6 +1,7 @@ + diff --git a/src/res/weapons/mallornlance.xml b/src/res/weapons/mallornlance.xml index 5a109f89b..88973f3e0 100644 --- a/src/res/weapons/mallornlance.xml +++ b/src/res/weapons/mallornlance.xml @@ -1,6 +1,7 @@ + diff --git a/src/res/weapons/rustyaxe.xml b/src/res/weapons/rustyaxe.xml index ef3a142d4..5399de62d 100644 --- a/src/res/weapons/rustyaxe.xml +++ b/src/res/weapons/rustyaxe.xml @@ -1,6 +1,7 @@ + diff --git a/src/res/weapons/rustyhalberd-2.xml b/src/res/weapons/rustyhalberd-2.xml index c1fce385b..bab849b49 100644 --- a/src/res/weapons/rustyhalberd-2.xml +++ b/src/res/weapons/rustyhalberd-2.xml @@ -1,9 +1,10 @@ + diff --git a/src/res/weapons/rustyhalberd.xml b/src/res/weapons/rustyhalberd.xml index 9ba3f018f..4f237b989 100644 --- a/src/res/weapons/rustyhalberd.xml +++ b/src/res/weapons/rustyhalberd.xml @@ -1,6 +1,7 @@ + diff --git a/src/scripts/e2k9/items.lua b/src/scripts/e2k9/items.lua index 924472580..d2875735d 100644 --- a/src/scripts/e2k9/items.lua +++ b/src/scripts/e2k9/items.lua @@ -1,5 +1,11 @@ --- used internally to check greatbow and towershield +-- when appending to this, make sure the item has a canuse-function! +local goblin_denied = " plate lance mallornlance greatbow axe greatsword halberd rustyaxe rustyhalberd towershield " function item_canuse(u, iname) + if u.race=="goblin" then + if string.find(goblin_denied, " " .. iname .. " ") then + return false + end + end if iname=="towershield" then -- only dwarves allowed to use towershield return u.race=="dwarf"