integrated Ennos suggestions for dragon growls

Dragons now growl 20% more elegantly!
This commit is contained in:
Steffen Mecke 2016-06-11 13:47:38 +02:00
parent cafa29426f
commit c5014fd766
8 changed files with 61 additions and 27 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

@ -8446,10 +8446,10 @@
<arg name="dragon" type="unit"/> <arg name="dragon" type="unit"/>
<arg name="number" type="int"/> <arg name="number" type="int"/>
<arg name="target" type="region"/> <arg name="target" type="region"/>
<arg name="choice" type="int"/> <arg name="growl" type="string"/>
</type> </type>
<text locale="de">"$unit($dragon): \"$if($eq($choice,0), "Groaaaam... ", "")$if($eq($choice,1), "Chrrrr... ", "")$if($eq($choice,2), "Roooarrr... ", "")$if($eq($choice,3), "Tschrrrk... ", "")$if($eq($choice,4), "Shhhhhh... ", "")$if($eq($number,1), "Ich rieche", "Wir riechen") etwas in $region($target)\"."</text> <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): \"$if($eq($choice,0), "Groaaaam... ", "")$if($eq($choice,1), "Chrrrr... ", "")$if($eq($choice,2), "Roooarrr... ", "")$if($eq($choice,3), "Tschrrrk... ", "")$if($eq($choice,4), "Shhhhhh... ", "")$if($eq($number,1), "I smell", "We smell") something 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> </message>
</messages> </messages>

View File

@ -194,7 +194,6 @@ message *msg_message(const char *name, const char *sig, ...)
} }
else { else {
log_error("invalid parameter %s for message type %s\n", paramname, mtype->name); log_error("invalid parameter %s for message type %s\n", paramname, mtype->name);
assert(!"invalid parameter for message type");
} }
while (*ic && !isalnum(*ic)) while (*ic && !isalnum(*ic))
ic++; ic++;
@ -202,7 +201,6 @@ message *msg_message(const char *name, const char *sig, ...)
va_end(vargs); va_end(vargs);
if (argnum != mtype->nparameters) { if (argnum != mtype->nparameters) {
log_error("not enough parameters for message type %s\n", mtype->name); log_error("not enough parameters for message type %s\n", mtype->name);
assert(!"not enough parameters for message type");
} }
return msg_create(mtype, args); return msg_create(mtype, args);

View File

@ -550,8 +550,18 @@ static order *monster_seeks_target(region * r, unit * u)
void random_growl(const unit *u, region *target, int rand) void random_growl(const unit *u, region *target, int rand)
{ {
const struct locale *lang = u->faction->locale; 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)) { if (rname(target, lang)) {
message *msg = msg_message("dragon_growl", "dragon number target choice", u, u->number, target, rand); message *msg = msg_message("dragon_growl", "dragon number target growl", u, u->number, target, growl);
ADDMSG(&u->region->msgs, msg); ADDMSG(&u->region->msgs, msg);
} }
} }

View File

@ -209,12 +209,16 @@ static void test_dragon_moves(CuTest * tc)
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", "choice:int", 0)); mt_register(mt_new_va("dragon_growl", "dragon:unit", "number:int", "target:region", "growl:string", 0));
random_growl(m, findregion(1, 0), 3); random_growl(m, findregion(1, 0), 3);
msg = test_get_last_message(r->msgs); msg = test_get_last_message(r->msgs);
assert_message(tc, msg, "dragon_growl", 4, m, 1, findregion(1,0), 3); 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

@ -390,27 +390,27 @@ void test_clear_messages(faction *f) {
} }
} }
void assert_message(CuTest * tc, message *msg, char *name, int numpar, ...) void assert_message(CuTest * tc, message *msg, char *name, int numpar) {
{
va_list vargs;
const message_type *mtype = msg->type; const message_type *mtype = msg->type;
assert(mtype); assert(mtype);
int i;
va_start(vargs, numpar);
CuAssertStrEquals(tc, name, mtype->name); CuAssertStrEquals(tc, name, mtype->name);
CuAssertIntEquals(tc, numpar, mtype->nparameters); CuAssertIntEquals(tc, numpar, mtype->nparameters);
for (i = 0; i != mtype->nparameters; ++i) { }
variant value = va_arg(vargs, variant);
if (mtype->types[i]->vtype == VAR_VOIDPTR) { void assert_pointer_parameter(CuTest * tc, message *msg, int index, void *arg) {
CuAssertPtrEquals(tc, value.v, msg->parameters[i].v); const message_type *mtype = (msg)->type;
} else if (mtype->types[i]->vtype == VAR_INT) { CuAssertIntEquals((tc), VAR_VOIDPTR, mtype->types[(index)]->vtype);CuAssertPtrEquals((tc), (arg), msg->parameters[(index)].v);
CuAssertIntEquals(tc, value.i, msg->parameters[i].i); }
} else {
assert(!"unknown variant type"); 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) {

View File

@ -54,7 +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_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)