BUG 2305: show the correct Parteitarnung in the CR.

We didn't have the required tests, so of course I broke it.
This commit is contained in:
Enno Rehling 2017-03-07 19:30:52 +01:00
parent ce9e2ce314
commit 29a8342b4e
2 changed files with 72 additions and 16 deletions

View File

@ -751,7 +751,7 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
const char *pzTmp;
skill *sv;
item result[MAX_INVENTORY];
const faction *fother, *fseen;
const faction *fother;
const char *prefix;
bool allied;
@ -783,24 +783,27 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
}
}
fseen = u->faction;
fother = get_otherfaction(u);
allied = u->faction == f || alliedunit(u, f, HELP_FSTEALTH);
if (fother && f != u->faction && !allied) {
/* getarnt, keine eigene, und kein HELFE fuer uns: wir sehen den fake */
fseen = fother;
if (allied) {
/* allies can tell that the unit is anonymous */
/* the true faction is visible to allies */
stream_printf(out, "%d;Partei\n", u->faction->no);
if (fother) {
stream_printf(out, "%d;Anderepartei\n", fother->no);
}
} else if (!fval(u, UFL_ANON_FACTION)) {
/* OBS: anonymity overrides everything */
/* we have no alliance, so we get duped */
stream_printf(out, "%d;Partei\n", (fother ? fother : u->faction)->no);
if (fother==f) {
/* sieht aus wie unsere, ist es aber nicht. */
stream_printf(out, "1;Verraeter\n");
}
}
stream_printf(out, "%d;Partei\n", fseen->no);
if (fother && fother!=fseen) {
stream_printf(out, "%d;Anderepartei\n", fother->no);
}
if (fseen==f && fval(u, UFL_ANON_FACTION)) {
if (fval(u, UFL_ANON_FACTION)) {
sputs("1;Parteitarnung", out);
}
if (!allied && fother == f) {
/* sieht aus wie unsere, ist es aber nicht. */
stream_printf(out, "1;Verraeter\n");
}
prefix = raceprefix(u);
if (prefix) {
prefix = mkname("prefix", prefix);

View File

@ -130,10 +130,12 @@ static void test_cr_resources(CuTest *tc) {
static int cr_get_int(stream *strm, const char *match, int def)
{
char line[1024];
size_t len = strlen(match);
strm->api->rewind(strm->handle);
while (strm->api->readln(strm->handle, line, sizeof(line))==0) {
if (strstr(line, match)) {
const char * pos = strstr(line, match);
if (pos && pos[len]=='\0') {
return atoi(line);
}
}
@ -153,30 +155,69 @@ static void test_cr_factionstealth(CuTest *tc) {
r = test_create_region(0, 0, 0);
u = test_create_unit(f1, r);
/* report to ourselves */
mstream_init(&strm);
cr_output_unit(&strm, u->region, f1, u, seen_unit);
CuAssertIntEquals(tc, f1->no, cr_get_int(&strm, ";Partei", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Anderepartei", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Verraeter", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Parteitarnung", -1));
mstream_done(&strm);
/* ... also when we are anonymous */
u->flags |= UFL_ANON_FACTION;
mstream_init(&strm);
cr_output_unit(&strm, u->region, f1, u, seen_unit);
CuAssertIntEquals(tc, f1->no, cr_get_int(&strm, ";Partei", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Anderepartei", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Verraeter", -1));
CuAssertIntEquals(tc, 1, cr_get_int(&strm, ";Parteitarnung", -1));
u->flags &= ~UFL_ANON_FACTION;
mstream_done(&strm);
/* we see that our unit is cloaked */
set_factionstealth(u, f2);
CuAssertPtrNotNull(tc, u->attribs);
mstream_init(&strm);
cr_output_unit(&strm, u->region, f1, u, seen_unit);
CuAssertIntEquals(tc, f1->no, cr_get_int(&strm, ";Partei", -1));
CuAssertIntEquals(tc, f2->no, cr_get_int(&strm, ";Anderepartei", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Verraeter", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Parteitarnung", -1));
mstream_done(&strm);
/* ... also when we are anonymous */
u->flags |= UFL_ANON_FACTION;
mstream_init(&strm);
cr_output_unit(&strm, u->region, f1, u, seen_unit);
CuAssertIntEquals(tc, f1->no, cr_get_int(&strm, ";Partei", -1));
CuAssertIntEquals(tc, f2->no, cr_get_int(&strm, ";Anderepartei", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Verraeter", -1));
CuAssertIntEquals(tc, 1, cr_get_int(&strm, ";Parteitarnung", -1));
u->flags &= ~UFL_ANON_FACTION;
mstream_done(&strm);
/* we can tell that someone is presenting as us */
mstream_init(&strm);
cr_output_unit(&strm, u->region, f2, u, seen_unit);
CuAssertIntEquals(tc, f2->no, cr_get_int(&strm, ";Partei", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Anderepartei", -1));
CuAssertIntEquals(tc, 1, cr_get_int(&strm, ";Verraeter", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Parteitarnung", -1));
mstream_done(&strm);
/* ... but not if they are anonymous */
u->flags |= UFL_ANON_FACTION;
mstream_init(&strm);
cr_output_unit(&strm, u->region, f2, u, seen_unit);
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Partei", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Anderepartei", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Verraeter", -1));
CuAssertIntEquals(tc, 1, cr_get_int(&strm, ";Parteitarnung", -1));
u->flags &= ~UFL_ANON_FACTION;
mstream_done(&strm);
/* we see the same thing as them when we are an ally */
al = ally_add(&f1->allies, f2);
al->status = HELP_FSTEALTH;
mstream_init(&strm);
@ -184,6 +225,18 @@ static void test_cr_factionstealth(CuTest *tc) {
CuAssertIntEquals(tc, f1->no, cr_get_int(&strm, ";Partei", -1));
CuAssertIntEquals(tc, f2->no, cr_get_int(&strm, ";Anderepartei", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Verraeter", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Parteitarnung", -1));
mstream_done(&strm);
/* ... also when they are anonymous */
u->flags |= UFL_ANON_FACTION;
mstream_init(&strm);
cr_output_unit(&strm, u->region, f1, u, seen_unit);
CuAssertIntEquals(tc, f1->no, cr_get_int(&strm, ";Partei", -1));
CuAssertIntEquals(tc, f2->no, cr_get_int(&strm, ";Anderepartei", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Verraeter", -1));
CuAssertIntEquals(tc, 1, cr_get_int(&strm, ";Parteitarnung", -1));
u->flags &= ~UFL_ANON_FACTION;
mstream_done(&strm);
test_cleanup();