Exemplo n.º 1
0
static void test_active_building(CuTest *tc) {
    building *b;
    region *r;
    unit *u;
    building_type *btype;

    test_setup();

    btype = test_create_buildingtype("castle");
    assert(btype && btype->maxsize == -1);
    b = test_create_building(r = test_create_region(0, 0, NULL), btype);
    u = test_create_unit(test_create_faction(NULL), r);
    CuAssertIntEquals(tc, false, building_is_active(b));
    CuAssertPtrEquals(tc, NULL, active_building(u, btype));

    b->flags |= BLD_MAINTAINED;
    CuAssertIntEquals(tc, true, building_is_active(b));
    CuAssertPtrEquals(tc, NULL, active_building(u, btype));
    u_set_building(u, b);
    CuAssertIntEquals(tc, true, building_is_active(b));
    CuAssertPtrNotNull(tc, active_building(u, btype) );
    btype->maxsize = 10;
    b->size = btype->maxsize;
    CuAssertIntEquals(tc, true, building_is_active(b));
    CuAssertPtrNotNull(tc, active_building(u, btype) );
    b->size = 9;
    CuAssertIntEquals(tc, false, building_is_active(b));
    CuAssertPtrEquals(tc, NULL, active_building(u, btype));
    btype->maxsize = -1;
    b->flags &= ~BLD_MAINTAINED;
    CuAssertIntEquals(tc, false, building_is_active(b));
    CuAssertPtrEquals(tc, NULL, active_building(u, btype));
    test_teardown();
}
Exemplo n.º 2
0
static unsigned int get_markets(region * r, unit ** results, size_t size)
{
    unsigned int n = 0;
    building *b;
    const building_type *btype = bt_find("market");
    if (!btype)
        return 0;
    for (b = r->buildings; n < size && b; b = b->next) {
        if (b->type == btype && building_is_active(b)) {
            unit *u = building_owner(b);
            /* I decided to omit check for inside_building(u) */
            unsigned int i;
            for (i = 0; u && i != n; ++i) {
                /* only one market per faction */
                if (results[i]->faction == u->faction)
                    u = NULL;
            }
            if (u) {
                results[n++] = u;
            }
        }
    }
    return n;
}
Exemplo n.º 3
0
building *active_building(const unit *u, const struct building_type *btype) {
    if (u->building && u->building->type == btype && building_is_active(u->building)) {
        return inside_building(u);
    }
    return 0;
}