Beispiel #1
0
static void test_all_spy_message(CuTest *tc) {
    spy_fixture fix;

    setup_spy(&fix);

    enable_skill(SK_MAGIC, true);
    set_level(fix.victim, SK_MINING, 2);
    set_level(fix.victim, SK_MAGIC, 2);
    create_mage(fix.victim, M_DRAIG);
    set_factionstealth(fix.victim, fix.spy->faction);

    item_type *itype;
    itype = it_get_or_create(rt_get_or_create("sword"));
    new_weapontype(itype, 0, 0.0, NULL, 0, 0, 0, SK_MELEE, 2);
    i_change(&fix.victim->items, itype, 1);

    spy_message(99, fix.spy, fix.victim);

    CuAssertPtrNotNull(tc, test_find_messagetype(fix.spy->faction->msgs, "spyreport"));
    CuAssertPtrNotNull(tc, test_find_messagetype(fix.spy->faction->msgs, "spyreport_mage"));
    CuAssertPtrNotNull(tc, test_find_messagetype(fix.spy->faction->msgs, "spyreport_skills"));
    CuAssertPtrNotNull(tc, test_find_messagetype(fix.spy->faction->msgs, "spyreport_faction"));
    CuAssertPtrNotNull(tc, test_find_messagetype(fix.spy->faction->msgs, "spyreport_items"));

    test_cleanup();
}
Beispiel #2
0
static void test_cr_factionstealth(CuTest *tc) {
    stream strm;
    faction *f1, *f2;
    region *r;
    unit *u;

    test_setup();
    f1 = test_create_faction(NULL);
    f2 = test_create_faction(NULL);
    r = test_create_region(0, 0, NULL);
    u = test_create_unit(f1, r);

    /* report to ourselves */
    mstream_init(&strm);
    cr_output_unit(&strm, 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, 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, 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, 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, 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, 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 */
    ally_set(&f1->allies, f2, HELP_FSTEALTH);
    mstream_init(&strm);
    cr_output_unit(&strm, 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));
    mstream_done(&strm);

    /* ... also when they are anonymous */
    u->flags |= UFL_ANON_FACTION;
    mstream_init(&strm);
    cr_output_unit(&strm, 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_teardown();
}