diff --git a/res/races/dragon.xml b/res/races/dragon.xml index a1f347105..907ff90a7 100644 --- a/res/races/dragon.xml +++ b/res/races/dragon.xml @@ -1,6 +1,8 @@ - +"6" damage="2d30" unarmedattack="0" unarmeddefense="0" +attackmodifier="7" defensemodifier="7" scarepeasants="yes" fly="yes" +walk="yes" teach="no" getitem="yes" resistbash="yes" dragon="yes"> + diff --git a/res/races/wyrm.xml b/res/races/wyrm.xml index 5c63b0fb6..b5d3bd7a2 100644 --- a/res/races/wyrm.xml +++ b/res/races/wyrm.xml @@ -1,5 +1,5 @@ - + diff --git a/res/races/youngdragon.xml b/res/races/youngdragon.xml index fe29bbfde..d1b3a4752 100644 --- a/res/races/youngdragon.xml +++ b/res/races/youngdragon.xml @@ -1,5 +1,5 @@ - + diff --git a/src/attributes/attributes.c b/src/attributes/attributes.c index 770ba7524..a82e1941d 100644 --- a/src/attributes/attributes.c +++ b/src/attributes/attributes.c @@ -61,6 +61,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include +attrib_type at_scare = { // monster scares peasants + "scare", NULL, NULL, NULL, a_writeint, a_readint +}; + attrib_type at_unitdissolve = { "unitdissolve", NULL, NULL, NULL, a_writechars, a_readchars }; @@ -77,6 +81,7 @@ static int read_ext(attrib * a, void *owner, gamedata *data) void register_attributes(void) { /* Alle speicherbaren Attribute müssen hier registriert werden */ + at_register(&at_scare); at_register(&at_shiptrail); at_register(&at_familiar); at_register(&at_familiarmage); diff --git a/src/attributes/attributes.h b/src/attributes/attributes.h index b8974867e..91184ad98 100644 --- a/src/attributes/attributes.h +++ b/src/attributes/attributes.h @@ -22,6 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif + struct attrib_type; + extern struct attrib_type at_scare; extern void register_attributes(void); #ifdef __cplusplus diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index fd8596d1f..1dd822130 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -33,6 +33,7 @@ without prior permission by the authors of Eressea. #include "vortex.h" #include +#include /* util includes */ #include @@ -1605,6 +1606,14 @@ static void parse_param(struct param **params, xmlNodePtr node) static void parse_ai(race * rc, xmlNodePtr node) { + int n; + + n = xml_ivalue(node, "scare", 0); + if (n>0) { + attrib *a = a_new(&at_scare); + a->data.i = n; + a_add(&rc->attribs, a); + } rc->splitsize = xml_ivalue(node, "splitsize", 0); rc->aggression = (float)xml_fvalue(node, "aggression", 0.04); if (xml_bvalue(node, "killpeasants", false)) diff --git a/src/monster.c b/src/monster.c index 37c48f8b5..afb0674c9 100644 --- a/src/monster.c +++ b/src/monster.c @@ -28,6 +28,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* attributes includes */ #include #include +#include /* kernel includes */ #include @@ -79,22 +80,17 @@ static void eaten_by_monster(unit * u) int n = 0; int horse = -1; const resource_type *rhorse = get_resourcetype(R_HORSE); + const race *rc = u_race(u); + attrib *a; + if (multi == 0.0) { multi = RESOURCE_QUANTITY * newterrain(T_PLAIN)->size / 10000.0; } - // TODO: do not hard-code, make it a race property or callback? it's already RCF_KILLPEASANTS - switch (old_race(u_race(u))) { - case RC_FIREDRAGON: - n = rng_int() % 80 * u->number; - break; - case RC_DRAGON: - n = rng_int() % 200 * u->number; - break; - case RC_WYRM: - n = rng_int() % 500 * u->number; - break; - default: + a = a_find(rc->attribs, &at_scare); + if (a) { + n = rng_int() & a->data.i * u->number; + } else { n = rng_int() % (u->number / 20 + 1); horse = 0; } @@ -168,21 +164,26 @@ static int scareaway(region * r, int anzahl) static void scared_by_monster(unit * u) { int n; - - switch (old_race(u_race(u))) { - case RC_FIREDRAGON: - n = rng_int() % 160 * u->number; - break; - case RC_DRAGON: - n = rng_int() % 400 * u->number; - break; - case RC_WYRM: - n = rng_int() % 1000 * u->number; - break; - default: - n = rng_int() % (u->number / 4 + 1); + const race *rc = u_race(u); + attrib *a; + a = a_find(rc->attribs, &at_scare); + if (a) { + n = rng_int() & a->data.i * u->number; + } else { + switch (old_race(u_race(u))) { + case RC_FIREDRAGON: + n = rng_int() % 160 * u->number; + break; + case RC_DRAGON: + n = rng_int() % 400 * u->number; + break; + case RC_WYRM: + n = rng_int() % 1000 * u->number; + break; + default: + n = rng_int() % (u->number / 4 + 1); + } } - if (n > 0) { n = lovar(n); n = _min(rpeasants(u->region), n);