コード例 #1
0
ファイル: building.test.c プロジェクト: ennorehling/eressea
static void test_building_effsize(CuTest *tc) {
    building *b;
    building_type *btype;
    building_stage *stage;
    construction *cons;

    test_setup();
    btype = test_create_buildingtype("castle");
    stage = btype->stages;
    assert(stage && stage->construction);
    cons = stage->construction;
    cons->maxsize = 5;

    stage->next = calloc(1, sizeof(building_stage));
    stage = stage->next;
    cons = stage->construction = calloc(1, sizeof(construction));
    cons->maxsize = 5;

    stage->next = calloc(1, sizeof(building_stage));
    stage = stage->next;
    cons = stage->construction = calloc(1, sizeof(construction));
    cons->maxsize = -1;

    b = test_create_building(test_create_region(0,0,0), btype);
    b->size = 1;
    CuAssertIntEquals(tc, 0, buildingeffsize(b, false));
    b->size = 5;
    CuAssertIntEquals(tc, 1, buildingeffsize(b, false));
    b->size = 10;
    CuAssertIntEquals(tc, 2, buildingeffsize(b, false));
    b->size = 20;
    CuAssertIntEquals(tc, 2, buildingeffsize(b, false));
    test_teardown();
}
コード例 #2
0
ファイル: building.test.c プロジェクト: ennorehling/eressea
static void test_cmp_current_owner(CuTest *tc) {
    region *r;
    building *b1, *b2;
    building_type *btype;
    unit *u1, *u2;

    test_setup();
    config_set("rules.region_owners", "1");
    r = test_create_region(0, 0, NULL);
    btype = test_create_buildingtype("watch");
    btype->stages->construction->maxsize = 1;
    btype->taxes = 200;
    b1 = test_create_building(r, btype);
    btype = test_create_buildingtype("castle");
    btype->stages->construction->maxsize = 1;
    btype->taxes = 100;
    b2 = test_create_building(r, btype);
    b1->size = 1;
    CuAssertIntEquals(tc, 1, buildingeffsize(b1, false));
    b2->size = 1;
    CuAssertIntEquals(tc, 1, buildingeffsize(b2, false));
    u1 = test_create_unit(test_create_faction(NULL), r);
    u_set_building(u1, b1);
    u2 = test_create_unit(test_create_faction(NULL), r);
    u_set_building(u2, b2);
    region_set_owner(r, u1->faction, turn);
    CuAssertPtrEquals(tc, b1, largestbuilding(r, cmp_current_owner, false));
    CuAssertTrue(tc, cmp_current_owner(b2, b1) < 0);
    CuAssertTrue(tc, cmp_current_owner(b1, b2) > 0);
    CuAssertTrue(tc, cmp_current_owner(b1, b1) == 0);
    test_teardown();
}
コード例 #3
0
ファイル: morale.c プロジェクト: ennorehling/eressea
void morale_update(region *r) {
    int morale = region_get_morale(r);
    assert(r->land);

    if (r->land->ownership && r->land->ownership->owner) {
        int stability = turn - r->land->ownership->morale_turn;
        int maxmorale = MORALE_DEFAULT;
        building *b = largestbuilding(r, cmp_taxes, false);
        if (b) {
            int bsize = buildingeffsize(b, false);
            assert(b->type->taxes>0);
            maxmorale = (bsize + 1) * MORALE_TAX_FACTOR / b->type->taxes;
        }
        if (morale < maxmorale) {
            if (stability > MORALE_COOLDOWN && r->land->ownership->owner
                && morale < MORALE_MAX) {
                double ch = popularity();
                if (is_cursed(r->attribs, &ct_generous)) {
                    ch *= 1.2;            /* 20% improvement */
                }
                if (stability >= MORALE_AVERAGE * 2 || chance(ch)) {
                    region_set_morale(r, morale + 1, turn);
                }
            }
        }
        else if (morale > maxmorale) {
            region_set_morale(r, morale - 1, turn);
        }
    }
    else if (morale > MORALE_DEFAULT) {
        region_set_morale(r, morale - 1, turn);
    }
}
コード例 #4
0
static int building_protection(building * b, unit * u, building_bonus bonus)
{

    int i = 0;
    int bsize = buildingeffsize(b, false);
    const construction *cons = b->type->construction;
    if (!cons) {
        return 0;
    }

    for (i = 0; i < bsize; i++)
    {
        cons = cons->improvement;
    }

    switch (bonus)
    {
    case DEFENSE_BONUS:
        return cons->defense_bonus;
    case CLOSE_COMBAT_ATTACK_BONUS:
        return cons->close_combat_bonus;
    case RANGED_ATTACK_BONUS:
        return cons->ranged_bonus;
    default:
        return 0;
    }
}