Beispiel #1
0
static int tolua_faction_set_alliance(lua_State * L)
{
    struct faction *self = (struct faction *)tolua_tousertype(L, 1, 0);
    struct alliance *alli = (struct alliance *) tolua_tousertype(L, 2, 0);

    setalliance(self, alli);

    return 0;
}
Beispiel #2
0
faction *addfaction(const char *email, const char *password,
    const struct race * frace, const struct locale * loc)
{
    faction *f = calloc(1, sizeof(faction));
    char buf[128];

    if (!f) abort();
    if (check_email(email) == 0) {
        faction_setemail(f, email);
    } else {
        log_info("Invalid email address for faction %s: %s\n", itoa36(f->no), email?email:"");
        faction_setemail(f, NULL);
    }

    f->alliance_joindate = turn;
    f->lastorders = 0;
    f->_alive = true;
    f->password_id = 0;
    f->age = 0;
    f->race = frace;
    f->magiegebiet = 0;
    f->locale = loc;
    f->uid = 0;
    f->flags = FFL_ISNEW|FFL_PWMSG;

    if (password) {
        faction_setpassword(f, password_hash(password, PASSWORD_DEFAULT));
        ADDMSG(&f->msgs, msg_message("changepasswd", "value", password));
    }

    f->options =
        WANT_OPTION(O_REPORT) | WANT_OPTION(O_ZUGVORLAGE) |
        WANT_OPTION(O_COMPUTER) | WANT_OPTION(O_COMPRESS) |
        WANT_OPTION(O_ADRESSEN) | WANT_OPTION(O_STATISTICS);

    f->no = unused_faction_id();
    if (rule_region_owners()) {
        alliance *al = makealliance(f->no, NULL);
        setalliance(f, al);
    }
    addlist(&factions, f);
    fhash(f);

    slprintf(buf, sizeof(buf), "%s %s", LOC(loc, "factiondefault"), itoa36(f->no));
    f->name = str_strdup(buf);

    if (!f->race) {
        log_warning("creating a faction that has no race", itoa36(f->no));
    }

    return f;
}
Beispiel #3
0
static void test_remove_empty_factions_alliance(CuTest *tc) {
    faction *f;
    struct alliance *al;

    test_cleanup();
    f = test_create_faction(0);
    al = makealliance(0, "Hodor");
    setalliance(f, al);
    CuAssertPtrEquals(tc, f, alliance_get_leader(al));
    CuAssertIntEquals(tc, 1, ql_length(al->members));
    remove_empty_factions();
    CuAssertPtrEquals(tc, 0, al->_leader);
    CuAssertIntEquals(tc, 0, ql_length(al->members));
    test_cleanup();
}
Beispiel #4
0
void destroyfaction(faction ** fp)
{
    faction * f = *fp;
    unit *u = f->units;

    *fp = f->next;
    f->next = dead_factions;
    dead_factions = f;

    fset(f, FFL_QUIT);
    f->_alive = false;

    if (f->spellbook) {
        spellbook_clear(f->spellbook);
        free(f->spellbook);
        f->spellbook = 0;
    }

    if (f->seen_factions) {
        selist_free(f->seen_factions);
        f->seen_factions = 0;
    }

    while (u) {
        /* give away your stuff, to ghosts if you cannot (quest items) */
        if (u->items) {
            region *r = u->region;
            int result = gift_items(u, GIFT_FRIENDS | GIFT_PEASANTS);
            if (result != 0) {
                save_special_items(u);
            }
            if (r->land && !!playerrace(u_race(u))) {
                const race *rc = u_race(u);
                int m = rmoney(r);

                /* Personen gehen nur an die Bauern, wenn sie auch von dort
                    * stammen */
                if ((rc->ec_flags & ECF_REC_ETHEREAL) == 0) {
                    int p = rpeasants(u->region);
                    int h = rhorses(u->region);
                    item *itm;

                    p += (int)(u->number * rc->recruit_multi);
                    for (itm = u->items; itm; itm = itm->next) {
                        if (itm->type->flags & ITF_ANIMAL) {
                            h += itm->number;
                        }
                    }
                    rsetpeasants(r, p);
                    rsethorses(r, h);
                }
                m += get_money(u);
                rsetmoney(r, m);
            }
        }
        set_number(u, 0);
        u = u->nextF;
    }

    handle_event(f->attribs, "destroy", f);
    if (f->alliance) {
        setalliance(f, NULL);
    }

    funhash(f);

    /* units of other factions that were disguised as this faction
     * have their disguise replaced by ordinary faction hiding. */
    if (rule_stealth_other()) {
        region *rc;
        for (rc = regions; rc; rc = rc->next) {
            for (u = rc->units; u; u = u->next) {
                if (u->attribs && get_otherfaction(u) == f) {
                    a_removeall(&u->attribs, &at_otherfaction);
                    if (rule_stealth_anon()) {
                        fset(u, UFL_ANON_FACTION);
                    }
                }
            }
        }
    }
}