forked from github/server
Merge pull request #669 from ennorehling/master
BUG 2305, 2309: Parteitarnung
This commit is contained in:
commit
fe3a94a7e9
|
@ -25,9 +25,9 @@ extern "C" {
|
|||
struct attrib;
|
||||
extern struct attrib_type at_otherfaction;
|
||||
|
||||
extern struct faction *get_otherfaction(const struct unit *u);
|
||||
extern struct attrib *make_otherfaction(struct faction *f);
|
||||
extern struct faction *visible_faction(const struct faction *f,
|
||||
struct faction *get_otherfaction(const struct unit *u);
|
||||
struct attrib *make_otherfaction(struct faction *f);
|
||||
struct faction *visible_faction(const struct faction *f,
|
||||
const struct unit *u);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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, f2, 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();
|
||||
|
|
|
@ -536,6 +536,10 @@ size_t size)
|
|||
if (wrptr(&bufp, &size, result) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
}
|
||||
else {
|
||||
bufp = STRLCPY(bufp, ", ", size);
|
||||
bufp = STRLCPY(bufp, factionname(fv), size);
|
||||
}
|
||||
}
|
||||
else {
|
||||
bufp = STRLCPY(bufp, ", ", size);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "travelthru.h"
|
||||
#include "keyword.h"
|
||||
|
||||
#include <kernel/ally.h>
|
||||
#include <kernel/config.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/faction.h>
|
||||
|
@ -20,10 +21,14 @@
|
|||
#include <kernel/spellbook.h>
|
||||
#include <kernel/terrain.h>
|
||||
|
||||
#include <util/attrib.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/message.h>
|
||||
|
||||
#include <attributes/key.h>
|
||||
#include <attributes/otherfaction.h>
|
||||
|
||||
#include <selist.h>
|
||||
#include <stream.h>
|
||||
#include <memstream.h>
|
||||
|
@ -153,14 +158,97 @@ static void test_sparagraph(CuTest *tc) {
|
|||
freestrlist(sp);
|
||||
}
|
||||
|
||||
static void test_write_unit(CuTest *tc) {
|
||||
static void test_bufunit_fstealth(CuTest *tc) {
|
||||
faction *f1, *f2;
|
||||
region *r;
|
||||
unit *u;
|
||||
ally *al;
|
||||
char buf[256];
|
||||
struct locale *lang;
|
||||
|
||||
test_setup();
|
||||
lang = get_or_create_locale("de");
|
||||
locale_setstring(lang, "status_aggressive", "aggressive");
|
||||
locale_setstring(lang, "anonymous", "anonymous");
|
||||
f1 = test_create_faction(0);
|
||||
f1->locale = lang;
|
||||
f2 = test_create_faction(0);
|
||||
f2->locale = lang;
|
||||
r = test_create_region(0, 0, 0);
|
||||
u = test_create_unit(f1, r);
|
||||
faction_setname(f1, "UFO");
|
||||
renumber_faction(f1, 1);
|
||||
faction_setname(f2, "TWW");
|
||||
renumber_faction(f2, 2);
|
||||
unit_setname(u, "Hodor");
|
||||
unit_setid(u, 1);
|
||||
key_set(&u->attribs, 42, 42);
|
||||
|
||||
/* report to ourselves */
|
||||
bufunit(f1, u, 0, seen_unit, buf, sizeof(buf));
|
||||
CuAssertStrEquals(tc, "Hodor (1), 1 human, aggressive.", buf);
|
||||
|
||||
/* ... also when we are anonymous */
|
||||
u->flags |= UFL_ANON_FACTION;
|
||||
bufunit(f1, u, 0, seen_unit, buf, sizeof(buf));
|
||||
CuAssertStrEquals(tc, "Hodor (1), anonymous, 1 human, aggressive.", buf);
|
||||
u->flags &= ~UFL_ANON_FACTION;
|
||||
|
||||
/* we see that our unit is cloaked */
|
||||
set_factionstealth(u, f2);
|
||||
CuAssertPtrNotNull(tc, u->attribs);
|
||||
bufunit(f1, u, 0, seen_unit, buf, sizeof(buf));
|
||||
CuAssertStrEquals(tc, "Hodor (1), TWW (2), 1 human, aggressive.", buf);
|
||||
|
||||
/* ... also when we are anonymous */
|
||||
u->flags |= UFL_ANON_FACTION;
|
||||
bufunit(f1, u, 0, seen_unit, buf, sizeof(buf));
|
||||
CuAssertStrEquals(tc, "Hodor (1), anonymous, 1 human, aggressive.", buf);
|
||||
u->flags &= ~UFL_ANON_FACTION;
|
||||
|
||||
/* we can see that someone is presenting as us */
|
||||
bufunit(f2, u, 0, seen_unit, buf, sizeof(buf));
|
||||
CuAssertStrEquals(tc, "Hodor (1), TWW (2), 1 human.", buf);
|
||||
|
||||
/* ... but not if they are anonymous */
|
||||
u->flags |= UFL_ANON_FACTION;
|
||||
bufunit(f2, u, 0, seen_unit, buf, sizeof(buf));
|
||||
CuAssertStrEquals(tc, "Hodor (1), anonymous, 1 human.", buf);
|
||||
u->flags &= ~UFL_ANON_FACTION;
|
||||
|
||||
/* we see the same thing as them when we are an ally */
|
||||
al = ally_add(&f1->allies, f2);
|
||||
al->status = HELP_FSTEALTH;
|
||||
bufunit(f2, u, 0, seen_unit, buf, sizeof(buf));
|
||||
CuAssertStrEquals(tc, "Hodor (1), TWW (2) (UFO (1)), 1 human.", buf);
|
||||
|
||||
/* ... also when they are anonymous */
|
||||
u->flags |= UFL_ANON_FACTION;
|
||||
bufunit(f2, u, 0, seen_unit, buf, sizeof(buf));
|
||||
CuAssertStrEquals(tc, "Hodor (1), anonymous, 1 human.", buf);
|
||||
u->flags &= ~UFL_ANON_FACTION;
|
||||
|
||||
/* fstealth has no influence when we are allies, same results again */
|
||||
set_factionstealth(u, NULL);
|
||||
bufunit(f2, u, 0, seen_unit, buf, sizeof(buf));
|
||||
CuAssertStrEquals(tc, "Hodor (1), UFO (1), 1 human.", buf);
|
||||
|
||||
u->flags |= UFL_ANON_FACTION;
|
||||
bufunit(f2, u, 0, seen_unit, buf, sizeof(buf));
|
||||
CuAssertStrEquals(tc, "Hodor (1), anonymous, 1 human.", buf);
|
||||
u->flags &= ~UFL_ANON_FACTION;
|
||||
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_bufunit(CuTest *tc) {
|
||||
unit *u;
|
||||
faction *f;
|
||||
race *rc;
|
||||
struct locale *lang;
|
||||
char buffer[1024];
|
||||
char buffer[256];
|
||||
|
||||
test_cleanup();
|
||||
test_setup();
|
||||
rc = rc_get_or_create("human");
|
||||
rc->bonus[SK_ALCHEMY] = 1;
|
||||
lang = get_or_create_locale("de");
|
||||
|
@ -191,6 +279,7 @@ static void test_write_unit(CuTest *tc) {
|
|||
f->locale = get_or_create_locale("de");
|
||||
bufunit(f, u, 0, 0, buffer, sizeof(buffer));
|
||||
CuAssertStrEquals(tc, "Hodor (1), UFO (1), 1 human.", buffer);
|
||||
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
|
@ -580,7 +669,8 @@ CuSuite *get_reports_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_seen_faction);
|
||||
SUITE_ADD_TEST(suite, test_regionid);
|
||||
SUITE_ADD_TEST(suite, test_sparagraph);
|
||||
SUITE_ADD_TEST(suite, test_write_unit);
|
||||
SUITE_ADD_TEST(suite, test_bufunit);
|
||||
SUITE_ADD_TEST(suite, test_bufunit_fstealth);
|
||||
SUITE_ADD_TEST(suite, test_arg_resources);
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ IF EXIST ..\build-vs10 SET BUILD=..\build-vs10\eressea\Debug
|
|||
IF EXIST ..\build-vs11 SET BUILD=..\build-vs11\eressea\Debug
|
||||
IF EXIST ..\build-vs12 SET BUILD=..\build-vs12\eressea\Debug
|
||||
IF EXIST ..\build-vs14 SET BUILD=..\build-vs14\eressea\Debug
|
||||
IF EXIST ..\build-vs15 SET BUILD=..\build-vs15\eressea\Debug
|
||||
SET SERVER=%BUILD%\eressea.exe
|
||||
%BUILD%\test_eressea.exe
|
||||
%SERVER% ..\scripts\run-tests.lua
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
@ECHO OFF
|
||||
SET VSVERSION=15
|
||||
SET SRCDIR=%CD%
|
||||
CD ..
|
||||
SET ERESSEA=%CD%
|
||||
|
||||
CD %SRCDIR%
|
||||
IF exist build-vs%VSVERSION% goto HAVEDIR
|
||||
mkdir build-vs%VSVERSION%
|
||||
:HAVEDIR
|
||||
cd build-vs%VSVERSION%
|
||||
"%ProgramFiles%\CMake\bin\cmake.exe" -G "Visual Studio %VSVERSION%" -DCMAKE_PREFIX_PATH="%ProgramFiles(x86)%/Lua/5.1;%ERESSEA%/dependencies-win32" -DCMAKE_MODULE_PATH="%SRCDIR%/cmake/Modules" -DCMAKE_SUPPRESS_REGENERATION=TRUE ..
|
||||
PAUSE
|
Loading…
Reference in New Issue