Merge pull request #512 from stm2/dragon_growl

Dragon growl
This commit is contained in:
Enno Rehling 2016-06-11 23:16:23 +02:00 committed by GitHub
commit 61acd40424
7 changed files with 93 additions and 26 deletions

View File

@ -7574,4 +7574,22 @@
</string> </string>
</namespace> </namespace>
<string name="growl0">
<text locale="de">Groaamm...</text>
</string>
<string name="growl1">
<text locale="de">Tschrrrk...</text>
<text locale="en">Tshrrrk...</text>
</string>
<string name="growl2">
<text locale="de">Schhhhh...</text>
<text locale="en">Shhhhhh...</text>
</string>
<string name="growl3">
<text locale="de">Roaarrr...</text>
</string>
<string name="growl4">
<text locale="de">Chrrr...</text>
</string>
</strings> </strings>

View File

@ -8441,4 +8441,15 @@
<text locale="en">"$unit($unit) in $region($region): '$order($command)' - Heroes cannot recruit."</text> <text locale="en">"$unit($unit) in $region($region): '$order($command)' - Heroes cannot recruit."</text>
</message> </message>
<message name="dragon_growl" section="mail">
<type>
<arg name="dragon" type="unit"/>
<arg name="number" type="int"/>
<arg name="target" type="region"/>
<arg name="growl" type="string"/>
</type>
<text locale="de">"$unit($dragon): \"$localize($growl) $if($eq($number,1), "Ich rieche", "Wir riechen") etwas in $region($target)\"."</text>
<text locale="en">"$unit($dragon): \"$localize($growl) $if($eq($number,1), "I smell", "We smell") something in $region($target)\"."</text>
</message>
</messages> </messages>

View File

@ -547,21 +547,23 @@ static order *monster_seeks_target(region * r, unit * u)
} }
#endif #endif
static const char *random_growl(void) void random_growl(const unit *u, region *target, int rand)
{ {
switch (rng_int() % 5) { const struct locale *lang = u->faction->locale;
case 0: const char *growl;
return "Groammm"; switch(rand){
case 1: case 1: growl = "growl1"; break;
return "Roaaarrrr"; case 2: growl = "growl2"; break;
case 2: case 3: growl = "growl3"; break;
return "Chhhhhhhhhh"; case 4: growl = "growl4"; break;
case 3: default: growl = "growl0";
return "Tschrrrkk"; }
case 4:
return "Schhhh";
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; extern struct attrib_type at_direction;
@ -707,17 +709,7 @@ static order *plan_dragon(unit * u)
reduce_weight(u); reduce_weight(u);
} }
if (rng_int() % 100 < 15) { if (rng_int() % 100 < 15) {
const struct locale *lang = u->faction->locale; random_growl(u, tr, rng_int() % 5);
/* 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)));
}
} }
} }
else { else {

View File

@ -12,10 +12,13 @@
#include "monster.h" #include "monster.h"
#include "guard.h" #include "guard.h"
#include "reports.h"
#include "skill.h" #include "skill.h"
#include "study.h" #include "study.h"
#include <util/language.h> #include <util/language.h>
#include <util/message.h>
#include <util/nrmessage.h>
#include <CuTest.h> #include <CuTest.h>
#include <tests.h> #include <tests.h>
@ -185,11 +188,14 @@ static void test_dragon_attacks_the_rich(CuTest * tc)
test_cleanup(); test_cleanup();
} }
extern void random_growl(const unit *u, region *tr, int rand);
static void test_dragon_moves(CuTest * tc) static void test_dragon_moves(CuTest * tc)
{ {
faction *f, *f2; faction *f, *f2;
region *r; region *r;
unit *u, *m; unit *u, *m;
struct message *msg;
create_monsters(&f, &f2, &u, &m); create_monsters(&f, &f2, &u, &m);
rsetmoney(findregion(1, 0), 1000); rsetmoney(findregion(1, 0), 1000);
@ -202,6 +208,18 @@ static void test_dragon_moves(CuTest * tc)
plan_monsters(f2); plan_monsters(f2);
CuAssertPtrNotNull(tc, find_order("move east", m)); 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(); test_cleanup();
} }

View File

@ -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 disabled_test(void *suite, void (*test)(CuTest *), const char *name) {
(void)test; (void)test;
fprintf(stderr, "%s: SKIP\n", name); fprintf(stderr, "%s: SKIP\n", name);

View File

@ -54,6 +54,11 @@ extern "C" {
struct message * test_find_messagetype(struct message_list *msgs, const char *name); struct message * test_find_messagetype(struct message_list *msgs, const char *name);
struct message * test_get_last_message(struct message_list *mlist); struct message * test_get_last_message(struct message_list *mlist);
void test_clear_messages(struct faction *f); 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); void disabled_test(void *suite, void (*)(struct CuTest *), const char *name);

View File

@ -23,10 +23,10 @@ static void test_logging(CuTest * tc)
struct log_t * id2 = log_create(LOG_CPWARNING, str2, log_string); struct log_t * id2 = log_create(LOG_CPWARNING, str2, log_string);
CuAssertTrue(tc, id1!=id2); CuAssertTrue(tc, id1!=id2);
log_warning("Hello %s", "World"); log_warning("Hello %s", "World");
CuAssertStrEquals(tc, str1, "World");
CuAssertStrEquals(tc, str2, "World");
log_destroy(id1); log_destroy(id1);
log_destroy(id2); log_destroy(id2);
CuAssertStrEquals(tc, "World", str1);
CuAssertStrEquals(tc, "World", str2);
} }
CuSuite *get_log_suite(void) CuSuite *get_log_suite(void)