forked from github/server
kill lua_canuse_item and itype->canuse
This commit is contained in:
parent
d9d542cfee
commit
50bdc71c1b
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<resource name="plate">
|
||||
<item weight="400" score="150">
|
||||
<function name="canuse" value="lua_canuse_item"/>
|
||||
<construction skill="armorer" minskill="4">
|
||||
<requirement type="iron" quantity="5"/>
|
||||
</construction>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<resource name="axe">
|
||||
<item weight="200">
|
||||
<function name="canuse" value="lua_canuse_item"/>
|
||||
<construction skill="weaponsmithing" minskill="3">
|
||||
<requirement type="log" quantity="1"/>
|
||||
<requirement type="iron" quantity="1"/>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<resource name="greatbow">
|
||||
<item weight="100" allow="elf">
|
||||
<function name="canuse" value="lua_canuse_item"/>
|
||||
<item weight="100">
|
||||
<construction skill="weaponsmithing" minskill="5">
|
||||
<modifier function="mod_elves_only"/>
|
||||
<requirement type="mallorn" quantity="2"/>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<resource name="greatsword">
|
||||
<item weight="200" score="30">
|
||||
<function name="canuse" value="lua_canuse_item"/>
|
||||
<construction skill="weaponsmithing" minskill="4">
|
||||
<requirement type="iron" quantity="2"/>
|
||||
</construction>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<resource name="halberd">
|
||||
<item weight="200">
|
||||
<function name="canuse" value="lua_canuse_item"/>
|
||||
<construction skill="weaponsmithing" minskill="3">
|
||||
<requirement type="log" quantity="2"/>
|
||||
<requirement type="iron" quantity="1"/>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<resource name="lance">
|
||||
<item weight="200">
|
||||
<function name="canuse" value="lua_canuse_item"/>
|
||||
<construction skill="weaponsmithing" minskill="2">
|
||||
<requirement type="log" quantity="2"/>
|
||||
</construction>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<resource name="mallornlance">
|
||||
<item weight="100">
|
||||
<function name="canuse" value="lua_canuse_item"/>
|
||||
<construction skill="weaponsmithing" minskill="5">
|
||||
<requirement type="mallorn" quantity="2"/>
|
||||
</construction>
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<resource name="rep_crossbow">
|
||||
<item weight="100" allow="dwarf halfling">
|
||||
<function name="canuse" value="lua_canuse_item"/>
|
||||
<construction skill="weaponsmithing" minskill="5">
|
||||
<modifier function="mod_dwarves_only"/>
|
||||
<requirement type="log" quantity="1"/>
|
||||
<requirement type="iron" quantity="1"/>
|
||||
</construction>
|
||||
<weapon armorpiercing="true" pierce="true" missile="true" skill="crossbow" offmod="0" defmod="0" reload="1">
|
||||
<damage type="rider" value="3d4+5"/>
|
||||
<damage type="footman" value="3d4+5"/>
|
||||
<modifier type="missile_target" value="0"/>
|
||||
</weapon>
|
||||
</item>
|
||||
</resource>
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<resource name="rustyaxe">
|
||||
<item weight="200">
|
||||
<function name="canuse" value="lua_canuse_item"/>
|
||||
<construction skill="weaponsmithing" minskill="3">
|
||||
<requirement type="log" quantity="1"/>
|
||||
<requirement type="iron" quantity="1"/>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<resource name="rustyhalberd">
|
||||
<item weight="200" score="20">
|
||||
<function name="canuse" value="lua_canuse_item"/>
|
||||
<construction skill="weaponsmithing" minskill="3">
|
||||
<requirement type="iron" quantity="1"/>
|
||||
<requirement type="log" quantity="1"/>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<resource name="plate">
|
||||
<item weight="400" score="150" deny="goblin">
|
||||
<function name="canuse" value="lua_canuse_item"/>
|
||||
<construction skill="armorer" minskill="4">
|
||||
<requirement type="iron" quantity="4"/>
|
||||
</construction>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<resource name="scale">
|
||||
<item weight="300" score="150" allow="dwarf halfling">
|
||||
<function name="canuse" value="lua_canuse_item"/>
|
||||
<construction skill="armorer" minskill="5">
|
||||
<modifier function="mod_dwarves_only"/>
|
||||
<requirement type="iron" quantity="2"/>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<resource name="towershield">
|
||||
<item weight="200" score="60" allow="dwarf">
|
||||
<function name="canuse" value="lua_canuse_item"/>
|
||||
<construction skill="armorer" minskill="4">
|
||||
<modifier function="mod_dwarves_only"/>
|
||||
<requirement type="iron" quantity="1"/>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<resource name="axe">
|
||||
<item weight="200" deny="goblin">
|
||||
<function name="canuse" value="lua_canuse_item"/>
|
||||
<construction skill="weaponsmithing" minskill="3">
|
||||
<requirement type="log" quantity="1"/>
|
||||
<requirement type="iron" quantity="1"/>
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
-->
|
||||
<resource name="greatbow">
|
||||
<item weight="100" allow="elf">
|
||||
<function name="canuse" value="lua_canuse_item"/>
|
||||
<construction skill="weaponsmithing" minskill="5">
|
||||
<modifier function="mod_elves_only"/>
|
||||
<requirement type="mallorn" quantity="2"/>
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
-->
|
||||
<resource name="halberd">
|
||||
<item weight="200" deny="goblin">
|
||||
<function name="canuse" value="lua_canuse_item"/>
|
||||
<construction skill="weaponsmithing" minskill="3">
|
||||
<requirement type="log" quantity="2"/>
|
||||
<requirement type="iron" quantity="1"/>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<resource name="lance">
|
||||
<item weight="200" deny="goblin">
|
||||
<function name="canuse" value="lua_canuse_item"/>
|
||||
<construction skill="weaponsmithing" minskill="2">
|
||||
<requirement type="log" quantity="2"/>
|
||||
</construction>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<resource name="mallornlance">
|
||||
<item weight="100" deny="goblin">
|
||||
<function name="canuse" value="lua_canuse_item"/>
|
||||
<construction skill="weaponsmithing" minskill="5">
|
||||
<requirement type="mallorn" quantity="2"/>
|
||||
</construction>
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
-->
|
||||
<resource name="rustyhalberd">
|
||||
<item weight="200" score="20" deny="goblin">
|
||||
<function name="canuse" value="lua_canuse_item"/>
|
||||
<construction skill="weaponsmithing" minskill="3">
|
||||
<requirement type="iron" quantity="1"/>
|
||||
<requirement type="log" quantity="1"/>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
12
src/battle.c
12
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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue