コード例 #1
0
ファイル: ship.c プロジェクト: ennorehling/eressea
ship *new_ship(const ship_type * stype, region * r, const struct locale *lang)
{
    static char buffer[32];
    ship *sh = (ship *)calloc(1, sizeof(ship));
    const char *sname = 0;

    if (!sh) abort();
    assert(stype);
    sh->no = newcontainerid();
    sh->coast = NODIRECTION;
    sh->type = stype;
    sh->region = r;

    if (lang) {
        sname = LOC(lang, stype->_name);
        if (!sname) {
            sname = LOC(lang, parameters[P_SHIP]);
        }
    }
    if (!sname) {
        sname = parameters[P_SHIP];
    }
    assert(sname);
    snprintf(buffer, sizeof(buffer), "%s %s", sname, itoa36(sh->no));
    sh->name = str_strdup(buffer);
    shash(sh);
    if (r) {
        addlist(&r->ships, sh);
    }
    return sh;
}
コード例 #2
0
building *new_building(const struct building_type * btype, region * r,
    const struct locale * lang)
{
    building **bptr = &r->buildings;
    building *b = (building *)calloc(1, sizeof(building));
    static bool init_lighthouse = false;
    static const struct building_type *bt_lighthouse = 0;
    const char *bname = 0;
    char buffer[32];

    if (!init_lighthouse) {
        bt_lighthouse = bt_find("lighthouse");
        init_lighthouse = true;
    }

    b->no = newcontainerid();
    bhash(b);

    b->type = btype;
    b->region = r;
    while (*bptr)
        bptr = &(*bptr)->next;
    *bptr = b;

    if (b->type == bt_lighthouse) {
        r->flags |= RF_LIGHTHOUSE;
    }
    if (b->type->name) {
        bname = LOC(lang, buildingtype(btype, b, 0));
    }
    if (!bname) {
        bname = LOC(lang, btype->_name);
    }
    if (!bname) {
        bname = LOC(lang, parameters[P_GEBAEUDE]);
    }
    if (!bname) {
        bname = parameters[P_GEBAEUDE];
    }
    assert(bname);
    slprintf(buffer, sizeof(buffer), "%s %s", bname, buildingid(b));
    b->name = _strdup(bname);
    return b;
}