forked from github/server
fix dragon growl for regions with an apostrophe
This commit is contained in:
parent
96b7c92d81
commit
ce312afc95
|
@ -8441,4 +8441,15 @@
|
|||
<text locale="en">"$unit($unit) in $region($region): '$order($command)' - Heroes cannot recruit."</text>
|
||||
</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="choice" type="int"/>
|
||||
</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="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>
|
||||
</message>
|
||||
|
||||
</messages>
|
||||
|
|
|
@ -547,21 +547,13 @@ 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;
|
||||
if (rname(target, lang)) {
|
||||
message *msg = msg_message("dragon_growl", "dragon number target choice", u, u->number, target, rand);
|
||||
ADDMSG(&u->region->msgs, msg);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
extern struct attrib_type at_direction;
|
||||
|
@ -707,17 +699,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 {
|
||||
|
|
|
@ -12,10 +12,13 @@
|
|||
|
||||
#include "monster.h"
|
||||
#include "guard.h"
|
||||
#include "reports.h"
|
||||
#include "skill.h"
|
||||
#include "study.h"
|
||||
|
||||
#include <util/language.h>
|
||||
#include <util/message.h>
|
||||
#include <util/nrmessage.h>
|
||||
|
||||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
@ -185,11 +188,83 @@ static void test_dragon_attacks_the_rich(CuTest * tc)
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
typedef struct msg_info {
|
||||
const char *name;
|
||||
int numpar;
|
||||
const char **argv;
|
||||
const char **pnames, **tnames;
|
||||
variant *values;
|
||||
} msg_info;
|
||||
|
||||
static msg_info *test_create_messagetype(const struct locale *lang, const char *name, int num_args, ...) {
|
||||
va_list vargs;
|
||||
const message_type *mtype;
|
||||
char zBuffer[128];
|
||||
int i;
|
||||
msg_info *info = malloc(sizeof(msg_info));
|
||||
info->argv = calloc(num_args + 1, sizeof(char *));
|
||||
info->pnames = calloc(num_args, sizeof(char *));
|
||||
info->tnames = calloc(num_args, sizeof(char *));
|
||||
info->values = calloc(num_args, sizeof(variant_type));
|
||||
|
||||
va_start(vargs, num_args);
|
||||
|
||||
info->numpar = num_args;
|
||||
info->name = name;
|
||||
|
||||
for(i = 0; i<num_args; ++i) {
|
||||
info->pnames[i] = va_arg(vargs, char *);
|
||||
info->tnames[i] = va_arg(vargs, char *);
|
||||
sprintf(zBuffer, "%s:%s", info->pnames[i], info->tnames[i]);
|
||||
info->argv[i] = _strdup(zBuffer);
|
||||
}
|
||||
|
||||
mtype = mt_register(mt_new(name, info->argv));
|
||||
nrt_register(mtype, lang, "mocktext", 0, "mocksection");
|
||||
|
||||
for(i = 0; i<num_args; ++i) {
|
||||
if (mtype->types[i]->vtype == VAR_VOIDPTR) {
|
||||
info->values[i].v = va_arg(vargs, char *);
|
||||
} else if (mtype->types[i]->vtype == VAR_INT) {
|
||||
info->values[i].i = va_arg(vargs, int);
|
||||
} else {
|
||||
assert(!"unknown variant type");
|
||||
}
|
||||
}
|
||||
va_end(vargs);
|
||||
return info;
|
||||
}
|
||||
|
||||
static void assert_message(CuTest * tc, message *msg, msg_info *info)
|
||||
{
|
||||
const message_type *mtype = msg->type;
|
||||
assert(mtype);
|
||||
int i;
|
||||
|
||||
CuAssertStrEquals(tc, info->name, mtype->name);
|
||||
CuAssertIntEquals(tc, info->numpar, mtype->nparameters);
|
||||
for (i = 0; i != mtype->nparameters; ++i) {
|
||||
CuAssertStrEquals(tc, info->pnames[i], mtype->pnames[i]);
|
||||
CuAssertStrEquals(tc, info->tnames[i], mtype->types[i]->name);
|
||||
if (mtype->types[i]->vtype == VAR_VOIDPTR) {
|
||||
CuAssertPtrEquals(tc, info->values[i].v, msg->parameters[i].v);
|
||||
} else if (mtype->types[i]->vtype == VAR_INT) {
|
||||
CuAssertIntEquals(tc, info->values[i].i, msg->parameters[i].i);
|
||||
} else {
|
||||
assert(!"unknown variant type");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
struct msg_info *msginfo;
|
||||
|
||||
create_monsters(&f, &f2, &u, &m);
|
||||
rsetmoney(findregion(1, 0), 1000);
|
||||
|
@ -202,6 +277,15 @@ static void test_dragon_moves(CuTest * tc)
|
|||
plan_monsters(f2);
|
||||
|
||||
CuAssertPtrNotNull(tc, find_order("move east", m));
|
||||
|
||||
register_reports();
|
||||
msginfo = test_create_messagetype(f->locale, "dragon_growl", 4, "dragon", "unit", "number", "int", "target", "region", "choice", "int", m, 1, findregion(1,0), 3);
|
||||
|
||||
random_growl(m, findregion(1, 0), 3);
|
||||
|
||||
msg = test_get_last_message(r->msgs);
|
||||
assert_message(tc, msg, msginfo);
|
||||
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue