diff --git a/res/core/de/strings.xml b/res/core/de/strings.xml index 75f57a6b0..c9a2ae616 100644 --- a/res/core/de/strings.xml +++ b/res/core/de/strings.xml @@ -7574,4 +7574,22 @@ + + Groaamm... + + + Tschrrrk... + Tshrrrk... + + + Schhhhh... + Shhhhhh... + + + Roaarrr... + + + Chrrr... + + diff --git a/res/core/messages.xml b/res/core/messages.xml index 15de4a153..99cf4d145 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -8441,4 +8441,15 @@ "$unit($unit) in $region($region): '$order($command)' - Heroes cannot recruit." + + + + + + + + "$unit($dragon): \"$localize($growl) $if($eq($number,1), "Ich rieche", "Wir riechen") etwas in $region($target)\"." + "$unit($dragon): \"$localize($growl) $if($eq($number,1), "I smell", "We smell") something in $region($target)\"." + + diff --git a/src/monsters.c b/src/monsters.c index 674ab0999..2fc2fcde3 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -547,21 +547,23 @@ static order *monster_seeks_target(region * r, unit * u) } #endif -static const char *random_growl(void) +void random_growl(const unit *u, region *target, int rand) { - switch (rng_int() % 5) { - case 0: - return "Groammm"; - case 1: - return "Roaaarrrr"; - case 2: - return "Chhhhhhhhhh"; - case 3: - return "Tschrrrkk"; - case 4: - return "Schhhh"; + const struct locale *lang = u->faction->locale; + const char *growl; + switch(rand){ + case 1: growl = "growl1"; break; + case 2: growl = "growl2"; break; + case 3: growl = "growl3"; break; + case 4: growl = "growl4"; break; + default: growl = "growl0"; + } + + + if (rname(target, lang)) { + message *msg = msg_message("dragon_growl", "dragon number target growl", u, u->number, target, growl); + ADDMSG(&u->region->msgs, msg); } - return ""; } extern struct attrib_type at_direction; @@ -707,17 +709,7 @@ static order *plan_dragon(unit * u) reduce_weight(u); } if (rng_int() % 100 < 15) { - const struct locale *lang = u->faction->locale; - /* do a growl */ - if (rname(tr, lang)) { - addlist(&u->orders, - create_order(K_MAIL, lang, "%s '%s... %s %s %s'", - LOC(lang, parameters[P_REGION]), - random_growl(), - u->number == - 1 ? "Ich rieche" : "Wir riechen", - "etwas in", rname(tr, u->faction->locale))); - } + random_growl(u, tr, rng_int() % 5); } } else { diff --git a/src/monsters.test.c b/src/monsters.test.c index 1660800fe..dd69e6bdb 100644 --- a/src/monsters.test.c +++ b/src/monsters.test.c @@ -12,10 +12,13 @@ #include "monster.h" #include "guard.h" +#include "reports.h" #include "skill.h" #include "study.h" #include +#include +#include #include #include @@ -185,11 +188,14 @@ static void test_dragon_attacks_the_rich(CuTest * tc) test_cleanup(); } +extern void random_growl(const unit *u, region *tr, int rand); + static void test_dragon_moves(CuTest * tc) { faction *f, *f2; region *r; unit *u, *m; + struct message *msg; create_monsters(&f, &f2, &u, &m); rsetmoney(findregion(1, 0), 1000); @@ -202,6 +208,18 @@ static void test_dragon_moves(CuTest * tc) plan_monsters(f2); CuAssertPtrNotNull(tc, find_order("move east", m)); + + mt_register(mt_new_va("dragon_growl", "dragon:unit", "number:int", "target:region", "growl:string", 0)); + + random_growl(m, findregion(1, 0), 3); + + msg = test_get_last_message(r->msgs); + assert_message(tc, msg, "dragon_growl", 4); + assert_pointer_parameter(tc, msg, 0, m); + assert_int_parameter(tc, msg, 1, 1); + assert_pointer_parameter(tc, msg, 2, findregion(1,0)); + assert_string_parameter(tc, msg, 3, "growl3"); + test_cleanup(); } diff --git a/src/tests.c b/src/tests.c index 4e6d98a74..fcb34040c 100644 --- a/src/tests.c +++ b/src/tests.c @@ -391,6 +391,29 @@ void test_clear_messages(faction *f) { } } +void assert_message(CuTest * tc, message *msg, char *name, int numpar) { + const message_type *mtype = msg->type; + assert(mtype); + + CuAssertStrEquals(tc, name, mtype->name); + CuAssertIntEquals(tc, numpar, mtype->nparameters); +} + +void assert_pointer_parameter(CuTest * tc, message *msg, int index, void *arg) { + const message_type *mtype = (msg)->type; + CuAssertIntEquals((tc), VAR_VOIDPTR, mtype->types[(index)]->vtype);CuAssertPtrEquals((tc), (arg), msg->parameters[(index)].v); +} + +void assert_int_parameter(CuTest * tc, message *msg, int index, int arg) { + const message_type *mtype = (msg)->type; + CuAssertIntEquals((tc), VAR_INT, mtype->types[(index)]->vtype);CuAssertIntEquals((tc), (arg), msg->parameters[(index)].i); +} + +void assert_string_parameter(CuTest * tc, message *msg, int index, const char *arg) { + const message_type *mtype = (msg)->type; + CuAssertIntEquals((tc), VAR_VOIDPTR, mtype->types[(index)]->vtype);CuAssertStrEquals((tc), (arg), msg->parameters[(index)].v); +} + void disabled_test(void *suite, void (*test)(CuTest *), const char *name) { (void)test; fprintf(stderr, "%s: SKIP\n", name); diff --git a/src/tests.h b/src/tests.h index 9836c42ab..d18ff6456 100644 --- a/src/tests.h +++ b/src/tests.h @@ -54,6 +54,11 @@ extern "C" { struct message * test_find_messagetype(struct message_list *msgs, const char *name); struct message * test_get_last_message(struct message_list *mlist); void test_clear_messages(struct faction *f); + void assert_message(struct CuTest * tc, struct message *msg, char *name, int numpar); + + void assert_pointer_parameter(struct CuTest * tc, struct message *msg, int index, void *arg); + void assert_int_parameter(struct CuTest * tc, struct message *msg, int index, int arg); + void assert_string_parameter(struct CuTest * tc, struct message *msg, int index, const char *arg); void disabled_test(void *suite, void (*)(struct CuTest *), const char *name); diff --git a/src/util/log.test.c b/src/util/log.test.c index 2750d4b1e..95cbefa96 100644 --- a/src/util/log.test.c +++ b/src/util/log.test.c @@ -23,10 +23,10 @@ static void test_logging(CuTest * tc) struct log_t * id2 = log_create(LOG_CPWARNING, str2, log_string); CuAssertTrue(tc, id1!=id2); log_warning("Hello %s", "World"); - CuAssertStrEquals(tc, str1, "World"); - CuAssertStrEquals(tc, str2, "World"); log_destroy(id1); log_destroy(id2); + CuAssertStrEquals(tc, "World", str1); + CuAssertStrEquals(tc, "World", str2); } CuSuite *get_log_suite(void)