From 50bdc71c1b9f359dc2b8bbbfb5d0840be4e05c06 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 4 Mar 2017 17:27:13 +0100 Subject: [PATCH] kill lua_canuse_item and itype->canuse --- res/core/armor/plate.xml | 1 - res/core/weapons/axe.xml | 1 - res/core/weapons/greatbow.xml | 3 +-- res/core/weapons/greatsword.xml | 1 - res/core/weapons/halberd.xml | 1 - res/core/weapons/lance.xml | 1 - res/core/weapons/mallornlance.xml | 1 - res/core/weapons/rep_crossbow.xml | 16 ---------------- res/core/weapons/rustyaxe.xml | 1 - res/core/weapons/rustyhalberd.xml | 1 - res/e3a/armor/plate.xml | 1 - res/e3a/armor/scale.xml | 1 - res/e3a/armor/towershield.xml | 1 - res/e3a/weapons/axe.xml | 1 - res/e3a/weapons/greatbow.xml | 1 - res/e3a/weapons/halberd.xml | 1 - res/e3a/weapons/lance.xml | 1 - res/e3a/weapons/mallornlance.xml | 1 - res/e3a/weapons/rustyhalberd.xml | 1 - scripts/eressea/e3/rules.lua | 28 ---------------------------- scripts/eressea/resources.lua | 7 ------- src/battle.c | 12 +----------- src/helpers.c | 30 ------------------------------ src/kernel/item.h | 3 --- src/kernel/xmlreader.c | 8 +------- 25 files changed, 3 insertions(+), 121 deletions(-) delete mode 100644 res/core/weapons/rep_crossbow.xml diff --git a/res/core/armor/plate.xml b/res/core/armor/plate.xml index a22064e90..97d855a73 100644 --- a/res/core/armor/plate.xml +++ b/res/core/armor/plate.xml @@ -1,7 +1,6 @@ - diff --git a/res/core/weapons/axe.xml b/res/core/weapons/axe.xml index 80a872ad7..3f97a5b8a 100644 --- a/res/core/weapons/axe.xml +++ b/res/core/weapons/axe.xml @@ -1,7 +1,6 @@ - diff --git a/res/core/weapons/greatbow.xml b/res/core/weapons/greatbow.xml index 14734a129..32f07a41e 100644 --- a/res/core/weapons/greatbow.xml +++ b/res/core/weapons/greatbow.xml @@ -1,7 +1,6 @@ - - + diff --git a/res/core/weapons/greatsword.xml b/res/core/weapons/greatsword.xml index cd48b8296..56285f6af 100644 --- a/res/core/weapons/greatsword.xml +++ b/res/core/weapons/greatsword.xml @@ -1,7 +1,6 @@ - diff --git a/res/core/weapons/halberd.xml b/res/core/weapons/halberd.xml index 5025f4793..7abc86902 100644 --- a/res/core/weapons/halberd.xml +++ b/res/core/weapons/halberd.xml @@ -1,7 +1,6 @@ - diff --git a/res/core/weapons/lance.xml b/res/core/weapons/lance.xml index abbb7f31f..4a02bc06f 100644 --- a/res/core/weapons/lance.xml +++ b/res/core/weapons/lance.xml @@ -1,7 +1,6 @@ - diff --git a/res/core/weapons/mallornlance.xml b/res/core/weapons/mallornlance.xml index 0186143e4..c67390d52 100644 --- a/res/core/weapons/mallornlance.xml +++ b/res/core/weapons/mallornlance.xml @@ -1,7 +1,6 @@ - diff --git a/res/core/weapons/rep_crossbow.xml b/res/core/weapons/rep_crossbow.xml deleted file mode 100644 index d6f869046..000000000 --- a/res/core/weapons/rep_crossbow.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/res/core/weapons/rustyaxe.xml b/res/core/weapons/rustyaxe.xml index 2ff19570c..fea6b8642 100644 --- a/res/core/weapons/rustyaxe.xml +++ b/res/core/weapons/rustyaxe.xml @@ -1,7 +1,6 @@ - diff --git a/res/core/weapons/rustyhalberd.xml b/res/core/weapons/rustyhalberd.xml index c1b1f69a9..3f0bd93b7 100644 --- a/res/core/weapons/rustyhalberd.xml +++ b/res/core/weapons/rustyhalberd.xml @@ -1,7 +1,6 @@ - diff --git a/res/e3a/armor/plate.xml b/res/e3a/armor/plate.xml index 9aeafc3c1..79391fbcb 100644 --- a/res/e3a/armor/plate.xml +++ b/res/e3a/armor/plate.xml @@ -1,7 +1,6 @@ - diff --git a/res/e3a/armor/scale.xml b/res/e3a/armor/scale.xml index 691ce5ba7..1038f4d6c 100644 --- a/res/e3a/armor/scale.xml +++ b/res/e3a/armor/scale.xml @@ -1,7 +1,6 @@ - diff --git a/res/e3a/armor/towershield.xml b/res/e3a/armor/towershield.xml index 78e113e2a..38e4f0928 100644 --- a/res/e3a/armor/towershield.xml +++ b/res/e3a/armor/towershield.xml @@ -1,7 +1,6 @@ - diff --git a/res/e3a/weapons/axe.xml b/res/e3a/weapons/axe.xml index 991a2b504..6066c4cfc 100644 --- a/res/e3a/weapons/axe.xml +++ b/res/e3a/weapons/axe.xml @@ -1,7 +1,6 @@ - diff --git a/res/e3a/weapons/greatbow.xml b/res/e3a/weapons/greatbow.xml index b488a011c..745d1793d 100644 --- a/res/e3a/weapons/greatbow.xml +++ b/res/e3a/weapons/greatbow.xml @@ -5,7 +5,6 @@ --> - diff --git a/res/e3a/weapons/halberd.xml b/res/e3a/weapons/halberd.xml index c07cbfd4d..c22e020b4 100644 --- a/res/e3a/weapons/halberd.xml +++ b/res/e3a/weapons/halberd.xml @@ -4,7 +4,6 @@ --> - diff --git a/res/e3a/weapons/lance.xml b/res/e3a/weapons/lance.xml index a3f641833..285862484 100644 --- a/res/e3a/weapons/lance.xml +++ b/res/e3a/weapons/lance.xml @@ -1,7 +1,6 @@ - diff --git a/res/e3a/weapons/mallornlance.xml b/res/e3a/weapons/mallornlance.xml index d2aacaea7..8eb25ceb4 100644 --- a/res/e3a/weapons/mallornlance.xml +++ b/res/e3a/weapons/mallornlance.xml @@ -1,7 +1,6 @@ - diff --git a/res/e3a/weapons/rustyhalberd.xml b/res/e3a/weapons/rustyhalberd.xml index 32c0d4497..a53aec515 100644 --- a/res/e3a/weapons/rustyhalberd.xml +++ b/res/e3a/weapons/rustyhalberd.xml @@ -4,7 +4,6 @@ --> - diff --git a/scripts/eressea/e3/rules.lua b/scripts/eressea/e3/rules.lua index c0ac8978a..e7a54ff41 100644 --- a/scripts/eressea/e3/rules.lua +++ b/scripts/eressea/e3/rules.lua @@ -1,31 +1,3 @@ --- 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 scale " -function item_canuse(u, iname) - local race = u.race - if race=="goblin" then - if string.find(goblin_denied, " " .. iname .. " ") then - return false - end - end - if iname=="rep_crossbow" then - -- only dwarves and halflings allowed to use repeating crossbow - return race=="dwarf" or race=="halfling" - end - if iname=="scale" then - -- only dwarves and halflings can use scale - return race=="dwarf" or race=="halfling" - end - if iname=="towershield" then - -- only dwarves allowed to use towershield - return race=="dwarf" - end - if iname=="greatbow" then - -- only elves use greatbow - return race=="elf" - end - return true -end - function building_taxes(b, blevel) btype = b.type if btype=="castle" then diff --git a/scripts/eressea/resources.lua b/scripts/eressea/resources.lua index 2829d00c7..588620aa4 100644 --- a/scripts/eressea/resources.lua +++ b/scripts/eressea/resources.lua @@ -1,12 +1,5 @@ -- global functions used in items.xml -if not item_canuse then - -- define a default, everyone can use everything - function item_canuse(u, iname) - return true - end -end - function peasant_getresource(u) return u.region:get_resource("peasant") end diff --git a/src/battle.c b/src/battle.c index fa5725c50..e8eb426e3 100644 --- a/src/battle.c +++ b/src/battle.c @@ -576,17 +576,7 @@ static weapon *select_weapon(const troop t, bool attacking, static bool i_canuse(const unit * u, const item_type * itype) { - bool result = true; - if (itype->canuse) { - result = itype->canuse(u, itype); - } - if (result!=rc_can_use(u_race(u), itype)) { - log_error("conversion error: %s should be %s to use %s", - u->_race->_name, - result ? "allowed" : "forbidden", - itype->rtype->_name); - } - return result; + return rc_can_use(u_race(u), itype); } static int diff --git a/src/helpers.c b/src/helpers.c index e8e6521c4..a4746461b 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -320,34 +320,6 @@ static int lua_getresource(unit * u, const struct resource_type *rtype) return result; } -static bool lua_canuse_item(const unit * u, const struct item_type *itype) -{ - bool result = true; - lua_State *L = (lua_State *)global.vm_state; - const char *fname = "item_canuse"; - - lua_getglobal(L, fname); - if (lua_isfunction(L, -1)) { - tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); - tolua_pushstring(L, itype->rtype->_name); - - if (lua_pcall(L, 2, 1, 0) != 0) { - const char *error = lua_tostring(L, -1); - log_error("use(%s) calling '%s': %s.\n", unitname(u), fname, error); - lua_pop(L, 1); - } - else { - result = lua_toboolean(L, -1); - lua_pop(L, 1); - } - } - else { - log_error("use(%s) calling '%s': not a function.\n", unitname(u), fname); - lua_pop(L, 1); - } - return result; -} - static int lua_wage(const region * r, const faction * f, const race * rc, int in_turn) { @@ -563,8 +535,6 @@ void register_tolua_helpers(void) TOLUA_CAST "lua_initfamiliar"); register_function((pf_generic)lua_getresource, TOLUA_CAST "lua_getresource"); - register_function((pf_generic)lua_canuse_item, - TOLUA_CAST "lua_canuse_item"); register_function((pf_generic)lua_changeresource, TOLUA_CAST "lua_changeresource"); register_function((pf_generic)lua_equipmentcallback, diff --git a/src/kernel/item.h b/src/kernel/item.h index 5f8d879f9..dda0cf3e4 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -125,9 +125,6 @@ extern "C" { int mask_deny; struct construction *construction; char *_appearance[2]; /* wie es f�r andere aussieht */ - /* --- functions --- */ - bool(*canuse) (const struct unit * user, - const struct item_type * itype); int score; } item_type; diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index edbaa37f4..aabab91d6 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -873,13 +873,7 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype) continue; } assert(propValue != NULL); - if (strcmp((const char *)propValue, "canuse") == 0) { - itype->canuse = - (bool(*)(const struct unit *, const struct item_type *))fun; - } - else { - log_error("unknown function type '%s' for item '%s'\n", (const char *)propValue, rtype->_name); - } + log_error("unknown function type '%s' for item '%s'\n", (const char *)propValue, rtype->_name); xmlFree(propValue); } itype->score = xml_ivalue(node, "score", 0);