simplify race masking for weapon modifiers.

This commit is contained in:
Enno Rehling 2018-04-29 13:13:10 +02:00
parent 4812fa1c41
commit 3cb1d1a071
9 changed files with 22 additions and 67 deletions

View file

@ -11,9 +11,7 @@
<damage type="rider" value="2d6+4"/> <damage type="rider" value="2d6+4"/>
<damage type="footman" value="2d6+4"/> <damage type="footman" value="2d6+4"/>
<modifier type="missile_target" value="2"/> <modifier type="missile_target" value="2"/>
<modifier type="damage" value="1"> <modifier type="damage" value="1" races="elf"/>
<race name="elf"/>
</modifier>
</weapon> </weapon>
</item> </item>
</resource> </resource>

View file

@ -10,9 +10,7 @@
<damage type="rider" value="1d11+2"/> <damage type="rider" value="1d11+2"/>
<damage type="footman" value="1d11+2"/> <damage type="footman" value="1d11+2"/>
<modifier type="missile_target" value="2"/> <modifier type="missile_target" value="2"/>
<modifier type="damage" value="1"> <modifier type="damage" value="1" races="elf"/>
<race name="elf"/>
</modifier>
</weapon> </weapon>
</item> </item>
</resource> </resource>

View file

@ -8,9 +8,7 @@
<construction skill="armorer" minskill="4"> <construction skill="armorer" minskill="4">
<requirement type="iron" quantity="1"/> <requirement type="iron" quantity="1"/>
</construction> </construction>
<armor ac="0" penalty="-0.15" projectile="0.25" magres="0.0" shield="yes"> <armor ac="0" penalty="-0.15" projectile="0.25" magres="0.0" shield="yes"/>
<modifier type="canuse" function="mod_dwarves_only"/>
</armor>
</item> </item>
</resource> </resource>
<resource name="shield"> <resource name="shield">

View file

@ -136,9 +136,7 @@
<damage type="rider" value="2d4+5"/> <damage type="rider" value="2d4+5"/>
<damage type="footman" value="2d4+5"/> <damage type="footman" value="2d4+5"/>
<modifier type="missile_target" value="2"/> <modifier type="missile_target" value="2"/>
<modifier type="damage" value="1"> <modifier type="damage" value="1" races="elf"/>
<race name="elf"/>
</modifier>
</weapon> </weapon>
</item> </item>
</resource> </resource>

View file

@ -10,9 +10,7 @@
<damage type="footman" value="3d8+8"/> <damage type="footman" value="3d8+8"/>
<modifier type="missile_target" value="2"/> <modifier type="missile_target" value="2"/>
<modifier type="skill" value="-90"/> <modifier type="skill" value="-90"/>
<modifier type="skill" value="100"> <modifier type="skill" value="100" races="snowman"/>
<race name="snowman"/>
</modifier>
</weapon> </weapon>
</item> </item>
</resource> </resource>

View file

@ -723,6 +723,7 @@ bool missile)
} }
if (wtype->modifiers != NULL) { if (wtype->modifiers != NULL) {
/* Pferdebonus, Lanzenbonus, usw. */ /* Pferdebonus, Lanzenbonus, usw. */
const race *rc = u_race(tu);
int m; int m;
unsigned int flags = unsigned int flags =
WMF_SKILL | (attacking ? WMF_OFFENSIVE : WMF_DEFENSIVE); WMF_SKILL | (attacking ? WMF_OFFENSIVE : WMF_DEFENSIVE);
@ -738,17 +739,10 @@ bool missile)
for (m = 0; wtype->modifiers[m].value; ++m) { for (m = 0; wtype->modifiers[m].value; ++m) {
if ((wtype->modifiers[m].flags & flags) == flags) { if ((wtype->modifiers[m].flags & flags) == flags) {
race_list *rlist = wtype->modifiers[m].races; int mask = wtype->modifiers[m].race_mask;
if (rlist != NULL) { if ((mask == 0) || (mask & rc->mask_item)) {
while (rlist) { skill += wtype->modifiers[m].value;
if (rlist->data == u_race(tu))
break;
rlist = rlist->next;
}
if (rlist == NULL)
continue;
} }
skill += wtype->modifiers[m].value;
} }
} }
} }
@ -1029,17 +1023,10 @@ static int rc_specialdamage(const unit *au, const unit *du, const struct weapon_
for (m = 0; wtype->modifiers[m].value; ++m) { for (m = 0; wtype->modifiers[m].value; ++m) {
/* weapon damage for this weapon, possibly by race */ /* weapon damage for this weapon, possibly by race */
if (wtype->modifiers[m].flags & WMF_DAMAGE) { if (wtype->modifiers[m].flags & WMF_DAMAGE) {
race_list *rlist = wtype->modifiers[m].races; int mask = wtype->modifiers[m].race_mask;
if (rlist != NULL) { if ((mask == 0) || (mask & ar->mask_item)) {
while (rlist) { modifier += wtype->modifiers[m].value;
if (rlist->data == ar)
break;
rlist = rlist->next;
}
if (rlist == NULL)
continue;
} }
modifier += wtype->modifiers[m].value;
} }
} }
} }
@ -3272,8 +3259,9 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
adata->atype = itm->type->rtype->atype; adata->atype = itm->type->rtype->atype;
adata->count = itm->number; adata->count = itm->number;
for (aptr = &fig->armors; *aptr; aptr = &(*aptr)->next) { for (aptr = &fig->armors; *aptr; aptr = &(*aptr)->next) {
if (adata->atype->prot > (*aptr)->atype->prot) if (adata->atype->prot > (*aptr)->atype->prot) {
break; break;
}
} }
adata->next = *aptr; adata->next = *aptr;
*aptr = adata; *aptr = adata;

View file

@ -609,16 +609,6 @@ mod_elves_only(const unit * u, const region * r, skill_t sk, int value)
return -118; return -118;
} }
static int
mod_dwarves_only(const unit * u, const region * r, skill_t sk, int value)
{
UNUSED_ARG(r);
if (u_race(u) == get_race(RC_DWARF) || (u_race(u)->ec_flags & ECF_IRONGOLEM)) {
return value;
}
return -118;
}
void void
register_item_give(int(*foo) (struct unit *, struct unit *, register_item_give(int(*foo) (struct unit *, struct unit *,
const struct item_type *, int, struct order *), const char *name) const struct item_type *, int, struct order *), const char *name)
@ -973,7 +963,6 @@ void register_resources(void)
registered = true; registered = true;
register_function((pf_generic)mod_elves_only, "mod_elves_only"); register_function((pf_generic)mod_elves_only, "mod_elves_only");
register_function((pf_generic)mod_dwarves_only, "mod_dwarves_only");
register_function((pf_generic)res_changeitem, "changeitem"); register_function((pf_generic)res_changeitem, "changeitem");
register_function((pf_generic)res_changeperson, "changeperson"); register_function((pf_generic)res_changeperson, "changeperson");
register_function((pf_generic)res_changepeasants, "changepeasants"); register_function((pf_generic)res_changepeasants, "changepeasants");

View file

@ -147,8 +147,8 @@ extern "C" {
struct race_list; struct race_list;
typedef struct weapon_mod { typedef struct weapon_mod {
int value; int value;
unsigned int flags; int flags;
struct race_list *races; int race_mask;
} weapon_mod; } weapon_mod;
#define ATF_NONE 0x00 #define ATF_NONE 0x00

View file

@ -520,6 +520,8 @@ static armor_type *xml_readarmor(xmlXPathContextPtr xpath, item_type * itype)
return atype; return atype;
} }
static void mask_races(xmlNodePtr node, const char *key, int *maskp);
static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype) static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype)
{ {
xmlNodePtr node = xpath->node; xmlNodePtr node = xpath->node;
@ -591,8 +593,7 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype)
wtype->modifiers = calloc(result->nodesetval->nodeNr + 1, sizeof(weapon_mod)); wtype->modifiers = calloc(result->nodesetval->nodeNr + 1, sizeof(weapon_mod));
for (k = 0; k != result->nodesetval->nodeNr; ++k) { for (k = 0; k != result->nodesetval->nodeNr; ++k) {
xmlNodePtr node = result->nodesetval->nodeTab[k]; xmlNodePtr node = result->nodesetval->nodeTab[k];
xmlXPathObjectPtr races; int flags = 0;
int r, flags = 0;
if (xml_bvalue(node, "walking", false)) if (xml_bvalue(node, "walking", false))
flags |= WMF_WALKING; flags |= WMF_WALKING;
@ -619,21 +620,8 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype)
wtype->modifiers[k].flags = flags; wtype->modifiers[k].flags = flags;
wtype->modifiers[k].value = xml_ivalue(node, "value", 0); wtype->modifiers[k].value = xml_ivalue(node, "value", 0);
xpath->node = node; mask_races(node, "races", &wtype->modifiers[k].race_mask);
races = xmlXPathEvalExpression(BAD_CAST "race", xpath); wtype->modifiers[k].race_mask = 0;
for (r = 0; r != races->nodesetval->nodeNr; ++r) {
xmlNodePtr node = races->nodesetval->nodeTab[r];
propValue = xmlGetProp(node, BAD_CAST "name");
if (propValue != NULL) {
const race *rc = rc_find((const char *)propValue);
if (rc == NULL)
rc = rc_get_or_create((const char *)propValue);
racelist_insert(&wtype->modifiers[k].races, rc);
xmlFree(propValue);
}
}
xmlXPathFreeObject(races);
} }
xmlXPathFreeObject(result); xmlXPathFreeObject(result);
@ -1311,7 +1299,7 @@ static void parse_ai(race * rc, xmlNodePtr node)
rc->flags |= RCF_ATTACK_MOVED; rc->flags |= RCF_ATTACK_MOVED;
} }
static void set_study_speed(race *rc, skill_t sk, int modifier){ static void set_study_speed(race *rc, skill_t sk, int modifier) {
if (!rc->study_speed) if (!rc->study_speed)
rc->study_speed = calloc(1, MAXSKILLS); rc->study_speed = calloc(1, MAXSKILLS);
rc->study_speed[sk] = (char)modifier; rc->study_speed[sk] = (char)modifier;