make item allow/deny XML easier to read, fix code

This commit is contained in:
Enno Rehling 2017-03-03 09:56:27 +01:00
parent 0a5d7bffa5
commit 6e8e163099
16 changed files with 42 additions and 22 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<resource name="greatbow"> <resource name="greatbow">
<item weight="100"> <item weight="100" allow="elf">
<function name="canuse" value="lua_canuse_item"/> <function name="canuse" value="lua_canuse_item"/>
<construction skill="weaponsmithing" minskill="5"> <construction skill="weaponsmithing" minskill="5">
<modifier function="mod_elves_only"/> <modifier function="mod_elves_only"/>

View File

@ -1,6 +1,6 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<resource name="rep_crossbow"> <resource name="rep_crossbow">
<item weight="100"> <item weight="100" allow="dwarf halfling">
<function name="canuse" value="lua_canuse_item"/> <function name="canuse" value="lua_canuse_item"/>
<construction skill="weaponsmithing" minskill="5"> <construction skill="weaponsmithing" minskill="5">
<modifier function="mod_dwarves_only"/> <modifier function="mod_dwarves_only"/>

View File

@ -1,6 +1,6 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<resource name="plate"> <resource name="plate">
<item weight="400" score="150"> <item weight="400" score="150" deny="goblin">
<function name="canuse" value="lua_canuse_item"/> <function name="canuse" value="lua_canuse_item"/>
<construction skill="armorer" minskill="4"> <construction skill="armorer" minskill="4">
<requirement type="iron" quantity="4"/> <requirement type="iron" quantity="4"/>

View File

@ -1,6 +1,6 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<resource name="scale"> <resource name="scale">
<item weight="300" score="150"> <item weight="300" score="150" allow="dwarf halfling">
<function name="canuse" value="lua_canuse_item"/> <function name="canuse" value="lua_canuse_item"/>
<construction skill="armorer" minskill="5"> <construction skill="armorer" minskill="5">
<modifier function="mod_dwarves_only"/> <modifier function="mod_dwarves_only"/>

View File

@ -1,6 +1,6 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<resource name="towershield"> <resource name="towershield">
<item weight="200" score="60" allow="1"> <item weight="200" score="60" allow="dwarf">
<function name="canuse" value="lua_canuse_item"/> <function name="canuse" value="lua_canuse_item"/>
<construction skill="armorer" minskill="4"> <construction skill="armorer" minskill="4">
<modifier function="mod_dwarves_only"/> <modifier function="mod_dwarves_only"/>

View File

@ -75,7 +75,7 @@
regaura="1.0" recruitcost="100" maintenance="10" weight="1000" regaura="1.0" recruitcost="100" maintenance="10" weight="1000"
capacity="540" speed="1.0" hp="20" damage="1d5" unarmedattack="-2" capacity="540" speed="1.0" hp="20" damage="1d5" unarmedattack="-2"
unarmeddefense="-2" playerrace="yes" walk="yes" giveperson="yes" unarmeddefense="-2" playerrace="yes" walk="yes" giveperson="yes"
giveunit="yes" getitem="yes" equipment="yes" items="8"> giveunit="yes" getitem="yes" equipment="yes">
<ai splitsize="10000" moverandom="yes" learn="yes"/> <ai splitsize="10000" moverandom="yes" learn="yes"/>
<param name="other_race" value="dwarf"/> <param name="other_race" value="dwarf"/>
<param name="luxury_trade" value="600"/> <param name="luxury_trade" value="600"/>
@ -124,7 +124,7 @@
recruitcost="200" maintenance="10" weight="1000" capacity="540" recruitcost="200" maintenance="10" weight="1000" capacity="540"
speed="1.0" hp="20" damage="1d5" unarmedattack="-2" speed="1.0" hp="20" damage="1d5" unarmedattack="-2"
unarmeddefense="-2" playerrace="yes" walk="yes" giveperson="yes" unarmeddefense="-2" playerrace="yes" walk="yes" giveperson="yes"
giveunit="yes" getitem="yes" equipment="yes" items="2"> giveunit="yes" getitem="yes" equipment="yes" >
<ai splitsize="10000" moverandom="yes" learn="yes"/> <ai splitsize="10000" moverandom="yes" learn="yes"/>
<skill name="armorer" modifier="-1"/> <skill name="armorer" modifier="-1"/>
<skill name="bow" modifier="2"/> <skill name="bow" modifier="2"/>
@ -168,7 +168,7 @@
recruitcost="240" maintenance="10" weight="1000" capacity="540" recruitcost="240" maintenance="10" weight="1000" capacity="540"
speed="1.0" hp="20" damage="1d5" unarmedattack="-2" speed="1.0" hp="20" damage="1d5" unarmedattack="-2"
unarmeddefense="-2" playerrace="yes" walk="yes" giveperson="yes" unarmeddefense="-2" playerrace="yes" walk="yes" giveperson="yes"
giveunit="yes" getitem="yes" equipment="yes" items="1"> giveunit="yes" getitem="yes" equipment="yes">
<ai splitsize="10000" moverandom="yes" learn="yes"/> <ai splitsize="10000" moverandom="yes" learn="yes"/>
<skill name="armorer" modifier="2"/> <skill name="armorer" modifier="2"/>
<skill name="bow" modifier="-1"/> <skill name="bow" modifier="-1"/>

View File

@ -1,9 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<resources xmlns:xi="http://www.w3.org/2001/XInclude"> <resources xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="config://core/weapons/axe.xml"/>
<xi:include href="config://core/weapons/bow.xml"/> <xi:include href="config://core/weapons/bow.xml"/>
<xi:include href="config://core/weapons/catapult.xml"/> <xi:include href="config://core/weapons/catapult.xml"/>
<xi:include href="config://core/weapons/lance.xml"/>
<xi:include href="config://core/weapons/mallornbow.xml"/> <xi:include href="config://core/weapons/mallornbow.xml"/>
<xi:include href="config://core/weapons/mallornspear.xml"/> <xi:include href="config://core/weapons/mallornspear.xml"/>
<xi:include href="config://core/weapons/rep_crossbow.xml"/> <xi:include href="config://core/weapons/rep_crossbow.xml"/>
@ -13,6 +11,8 @@
<xi:include href="config://core/weapons/spear.xml"/> <xi:include href="config://core/weapons/spear.xml"/>
<xi:include href="config://core/weapons/sword.xml"/> <xi:include href="config://core/weapons/sword.xml"/>
<xi:include href="config://core/weapons/firesword.xml"/> <xi:include href="config://core/weapons/firesword.xml"/>
<xi:include href="config://game/weapons/lance.xml"/>
<xi:include href="config://game/weapons/axe.xml"/>
<xi:include href="config://game/weapons/crossbow.xml"/> <xi:include href="config://game/weapons/crossbow.xml"/>
<xi:include href="config://game/weapons/greatbow.xml"/> <xi:include href="config://game/weapons/greatbow.xml"/>
<xi:include href="config://game/weapons/greatsword.xml"/> <xi:include href="config://game/weapons/greatsword.xml"/>

View File

@ -4,7 +4,7 @@
* has lower damage * has lower damage
--> -->
<resource name="greatbow"> <resource name="greatbow">
<item weight="100"> <item weight="100" allow="elf">
<function name="canuse" value="lua_canuse_item"/> <function name="canuse" value="lua_canuse_item"/>
<construction skill="weaponsmithing" minskill="5"> <construction skill="weaponsmithing" minskill="5">
<modifier function="mod_elves_only"/> <modifier function="mod_elves_only"/>

View File

@ -3,7 +3,7 @@
1. you cannt use this with cavalry 1. you cannt use this with cavalry
--> -->
<resource name="halberd"> <resource name="halberd">
<item weight="200"> <item weight="200" deny="goblin">
<function name="canuse" value="lua_canuse_item"/> <function name="canuse" value="lua_canuse_item"/>
<construction skill="weaponsmithing" minskill="3"> <construction skill="weaponsmithing" minskill="3">
<requirement type="log" quantity="2"/> <requirement type="log" quantity="2"/>

View File

@ -1,6 +1,6 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<resource name="mallornlance"> <resource name="mallornlance">
<item weight="100"> <item weight="100" deny="goblin">
<function name="canuse" value="lua_canuse_item"/> <function name="canuse" value="lua_canuse_item"/>
<construction skill="weaponsmithing" minskill="5"> <construction skill="weaponsmithing" minskill="5">
<requirement type="mallorn" quantity="2"/> <requirement type="mallorn" quantity="2"/>

View File

@ -3,7 +3,7 @@
1. you cannot use this with cavalry 1. you cannot use this with cavalry
--> -->
<resource name="rustyhalberd"> <resource name="rustyhalberd">
<item weight="200" score="20"> <item weight="200" score="20" deny="goblin">
<function name="canuse" value="lua_canuse_item"/> <function name="canuse" value="lua_canuse_item"/>
<construction skill="weaponsmithing" minskill="3"> <construction skill="weaponsmithing" minskill="3">
<requirement type="iron" quantity="1"/> <requirement type="iron" quantity="1"/>

View File

@ -3,7 +3,7 @@
recruitcost="60" maintenance="6" weight="600" capacity="440" recruitcost="60" maintenance="6" weight="600" capacity="440"
speed="1.0" hp="16" damage="1d5" unarmedattack="-2" unarmeddefense="0" speed="1.0" hp="16" damage="1d5" unarmedattack="-2" unarmeddefense="0"
playerrace="yes" walk="yes" giveperson="yes" giveunit="yes" playerrace="yes" walk="yes" giveperson="yes" giveunit="yes"
getitem="yes" equipment="yes" healing="2.0" items="4"> getitem="yes" equipment="yes" healing="2.0">
<ai splitsize="10000" moverandom="yes" learn="yes"/> <ai splitsize="10000" moverandom="yes" learn="yes"/>
<param name="hunger.damage" value="1d8+7"/> <param name="hunger.damage" value="1d8+7"/>
<param name="other_race" value="demon"/> <param name="other_race" value="demon"/>

View File

@ -22,8 +22,8 @@ function test_goblins()
local restricted = { local restricted = {
"towershield", "rep_crossbow", "plate", "lance", "towershield", "rep_crossbow", "plate", "lance",
"mllornlance", "greatbow", "greataxe", "axe", "scale", "mallornlance", "greatbow", "greataxe", "axe", "scale",
"plate", "rustyhalberd", "halberd", "greatsword" "plate", "halberd", "greatsword", "rustyhalberd"
} }
for k, v in ipairs(restricted) do for k, v in ipairs(restricted) do
ud:add_item(v, 1) ud:add_item(v, 1)

View File

@ -328,7 +328,7 @@ bool rc_changed(int *cache) {
bool rc_can_use(const struct race *rc, const struct item_type *itype) bool rc_can_use(const struct race *rc, const struct item_type *itype)
{ {
if (itype->mask_allow) { if (itype->mask_allow) {
return (rc->mask_item==0 || (itype->mask_allow & rc->mask_item) != 0); return (itype->mask_allow & rc->mask_item) != 0;
} }
if (itype->mask_deny) { if (itype->mask_deny) {
return (itype->mask_deny & rc->mask_item) == 0; return (itype->mask_deny & rc->mask_item) == 0;

View File

@ -146,7 +146,7 @@ static void test_rc_can_use(CuTest *tc) {
/* we are not special */ /* we are not special */
rc->mask_item = 0; rc->mask_item = 0;
CuAssertTrue(tc, rc_can_use(rc, itype)); CuAssertTrue(tc, ! rc_can_use(rc, itype));
test_cleanup(); test_cleanup();
} }

View File

@ -757,6 +757,27 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype)
return wtype; return wtype;
} }
static int race_mask = 1;
static void mask_races(xmlNodePtr node, const char *key, int *maskp) {
xmlChar *propValue = xmlGetProp(node, BAD_CAST key);
char *tok;
int mask = 0;
assert(maskp);
tok = strtok((char *)propValue, " ,");
while (tok) {
race * rc = rc_get_or_create(tok);
if (!rc->mask_item) {
rc->mask_item = race_mask;
race_mask = race_mask << 1;
}
mask |= rc->mask_item;
tok = strtok(NULL, " ,");
}
*maskp = mask;
xmlFree(propValue);
}
static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype) static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
{ {
xmlNodePtr node = xpath->node; xmlNodePtr node = xpath->node;
@ -782,8 +803,8 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
itype = rtype->itype ? rtype->itype : it_get_or_create(rtype); itype = rtype->itype ? rtype->itype : it_get_or_create(rtype);
itype->weight = xml_ivalue(node, "weight", 0); itype->weight = xml_ivalue(node, "weight", 0);
itype->capacity = xml_ivalue(node, "capacity", 0); itype->capacity = xml_ivalue(node, "capacity", 0);
itype->mask_allow = xml_ivalue(node, "allow", 0); mask_races(node, "allow", &itype->mask_allow);
itype->mask_deny = xml_ivalue(node, "deny", 0); mask_races(node, "deny", &itype->mask_deny);
itype->flags |= flags; itype->flags |= flags;
/* reading item/construction */ /* reading item/construction */
@ -1577,7 +1598,6 @@ static int parse_races(xmlDocPtr doc)
rc->speed = (float)xml_fvalue(node, "speed", rc->speed); rc->speed = (float)xml_fvalue(node, "speed", rc->speed);
rc->hitpoints = xml_ivalue(node, "hp", rc->hitpoints); rc->hitpoints = xml_ivalue(node, "hp", rc->hitpoints);
rc->armor = (char)xml_ivalue(node, "ac", rc->armor); rc->armor = (char)xml_ivalue(node, "ac", rc->armor);
rc->mask_item = (char)xml_ivalue(node, "items", rc->mask_item);
study_speed_base = xml_ivalue(node, "studyspeed", 0); study_speed_base = xml_ivalue(node, "studyspeed", 0);
rc->at_default = (char)xml_ivalue(node, "unarmedattack", -2); rc->at_default = (char)xml_ivalue(node, "unarmedattack", -2);