Esempio n. 1
0
static void test_piracy_cmd_land_to_land(CuTest * tc) {
    unit *u;
    region *r;
    faction *f;
    int target;
    const terrain_type *t_plain;
    const ship_type *stype;

    test_setup();
    setup_piracy();
    t_plain = get_or_create_terrain("plain");
    stype = test_create_shiptype("boat");

    /* create a target: */
    r = test_create_region(0, 0, t_plain);
    f = test_create_faction(NULL);
    u = test_create_unit(f, r);
    u->ship = test_create_ship(r, stype);
    target = f->no;

    /* create a pirate: */
    r = test_create_region(1, 0, t_plain);
    f = test_create_faction(NULL);
    u = test_create_unit(f, r);
    u->ship = test_create_ship(r, stype);
    set_level(u, SK_SAILING, u->ship->type->sumskill);
    u->thisorder = create_order(K_PIRACY, f->locale, "%s", itoa36(target));

    piracy_cmd(u);
    CuAssertPtrEquals(tc, NULL, u->thisorder);
    CuAssertPtrEquals(tc, r, u->region);

    test_teardown();
}
Esempio n. 2
0
static void test_sabotage_other_fail(CuTest *tc) {
    unit *u, *u2;
    region *r;
    order *ord;
    message *msg;

    setup_sabotage();
    r = test_create_region(0, 0, 0);
    assert(r);
    u = test_create_unit(test_create_faction(NULL), r);
    u2 = test_create_unit(test_create_faction(NULL), r);
    assert(u && u2);
    u2->ship = test_create_ship(r, test_create_shiptype("boat"));
    assert(u2->ship);
    u->ship = u2->ship;
    ship_update_owner(u->ship);
    assert(ship_owner(u->ship) == u);
    ord = create_order(K_SABOTAGE, u->faction->locale, "SCHIFF");
    assert(ord);
    CuAssertIntEquals(tc, 0, sabotage_cmd(u2, ord));
    msg = test_get_last_message(u2->faction->msgs);
    CuAssertStrEquals(tc, "destroy_ship_1", test_get_messagetype(msg));
    msg = test_get_last_message(u->faction->msgs);
    CuAssertStrEquals(tc, "destroy_ship_3", test_get_messagetype(msg));
    CuAssertPtrNotNull(tc, r->ships);
    free_order(ord);
    test_cleanup();
}
Esempio n. 3
0
static void test_ship_set_owner(CuTest * tc)
{
    struct region *r;
    struct ship *sh;
    struct unit *u1, *u2;
    struct faction *f;
    const struct ship_type *stype;
    const struct race *human;

    test_setup();
    test_create_world();

    human = rc_find("human");
    stype = st_find("boat");
    f = test_create_faction(human);
    r = findregion(0, 0);

    sh = test_create_ship(r, stype);
    u1 = test_create_unit(f, r);
    u_set_ship(u1, sh);
    CuAssertPtrEquals(tc, u1, ship_owner(sh));

    u2 = test_create_unit(f, r);
    u_set_ship(u2, sh);
    CuAssertPtrEquals(tc, u1, ship_owner(sh));
    ship_set_owner(u2);
    CuAssertPtrEquals(tc, u2, ship_owner(sh));
    test_teardown();
}
Esempio n. 4
0
static void test_piracy_cmd(CuTest * tc) {
    faction *f;
    region *r;
    unit *u, *u2;
    terrain_type *t_ocean;
    ship_type *st_boat;

    test_setup();
    setup_piracy();

    t_ocean = get_or_create_terrain("ocean");
    st_boat = st_get_or_create("boat");
    u2 = test_create_unit(test_create_faction(NULL), test_create_region(1, 0, t_ocean));
    assert(u2);
    u_set_ship(u2, test_create_ship(u2->region, st_boat));
    u = test_create_unit(f = test_create_faction(NULL), r = test_create_region(0, 0, t_ocean));
    assert(f && u);
    set_level(u, SK_SAILING, st_boat->sumskill);
    u_set_ship(u, test_create_ship(u->region, st_boat));
    f->locale = get_or_create_locale("de");
    u->thisorder = create_order(K_PIRACY, f->locale, "%s", itoa36(u2->faction->no));

    piracy_cmd(u);
    CuAssertPtrEquals(tc, NULL, u->thisorder);
    CuAssertTrue(tc, u->region != r);
    CuAssertPtrEquals(tc, u2->region, u->region);
    CuAssertPtrEquals(tc, u2->region, u->ship->region);
    CuAssertPtrNotNullMsg(tc, "successful PIRACY sets attribute", r->attribs); /* FIXME: this is testing implementation, not interface */
    CuAssertPtrNotNullMsg(tc, "successful PIRACY message", test_find_messagetype(f->msgs, "piratesawvictim"));
    CuAssertPtrNotNullMsg(tc, "successful PIRACY movement", test_find_messagetype(f->msgs, "shipsail"));

    test_teardown();
}
Esempio n. 5
0
void test_upkeep_default(CuTest * tc)
{
    region *r;
    unit *u1, *u2;
    faction *f1, *f2;
    const item_type *i_silver;

    test_cleanup();
    test_create_world();

    i_silver = it_find("money");
    assert(i_silver);
    r = findregion(0, 0);
    f1 = test_create_faction(test_create_race("human"));
    f2 = test_create_faction(test_create_race("human"));
    assert(f1 && f2);
    u1 = test_create_unit(f1, r);
    u2 = test_create_unit(f2, r);
    assert(r && u1 && u2);

    set_param(&global.parameters, "rules.food.flags", "0");
    i_change(&u1->items, i_silver, 20);
    get_food(r);
    // since u1 and u2 are not allied, u1 should not help u2 with upkeep
    CuAssertIntEquals(tc, 10, i_get(u1->items, i_silver));
    CuAssertIntEquals(tc, 0, fval(u1, UFL_HUNGER));
    CuAssertIntEquals(tc, UFL_HUNGER, fval(u2, UFL_HUNGER));

    test_cleanup();
}
Esempio n. 6
0
static void test_buildingowner_goes_to_same_faction_after_leave(CuTest * tc)
{
    struct region *r;
    struct building *bld;
    struct unit *u, *u2, *u3;
    struct faction *f1, *f2;

    test_setup();

    f1 = test_create_faction(NULL);
    f2 = test_create_faction(NULL);
    r = test_create_plain(0, 0);

    bld = test_create_building(r, NULL);
    CuAssertPtrNotNull(tc, bld);

    u2 = test_create_unit(f2, r);
    u3 = test_create_unit(f1, r);
    u = test_create_unit(f1, r);
    CuAssertPtrNotNull(tc, u);
    u_set_building(u, bld);
    u_set_building(u2, bld);
    u_set_building(u3, bld);
    CuAssertPtrEquals(tc, u, building_owner(bld));
    leave_building(u);
    CuAssertPtrEquals(tc, u3, building_owner(bld));
    leave_building(u3);
    CuAssertPtrEquals(tc, u2, building_owner(bld));
    leave_building(u2);
    CuAssertPtrEquals(tc, NULL, building_owner(bld));
    test_teardown();
}
Esempio n. 7
0
static void test_buildingowner_goes_to_other_when_empty(CuTest * tc)
{
    struct region *r;
    struct building *bld;
    struct unit *u, *u2;
    struct faction *f;

    test_setup();

    f = test_create_faction(NULL);
    r = test_create_plain(0, 0);

    bld = test_create_building(r, NULL);
    CuAssertPtrNotNull(tc, bld);

    u2 = test_create_unit(f, r);
    u = test_create_unit(f, r);
    CuAssertPtrNotNull(tc, u);
    u_set_building(u, bld);
    CuAssertPtrEquals(tc, u, building_owner(bld));
    u_set_building(u2, bld);
    CuAssertPtrEquals(tc, u, building_owner(bld));
    u->number = 0;
    CuAssertPtrEquals(tc, u2, building_owner(bld));
    test_teardown();
}
Esempio n. 8
0
static void test_shipowner_goes_to_other_when_empty(CuTest * tc)
{
    struct region *r;
    struct ship *sh;
    struct unit *u, *u2;
    struct faction *f;
    const struct ship_type *stype;
    const struct race *human;

    test_setup();
    test_create_world();

    human = rc_find("human");
    CuAssertPtrNotNull(tc, human);

    stype = st_find("boat");
    CuAssertPtrNotNull(tc, stype);

    f = test_create_faction(human);
    r = findregion(0, 0);

    sh = test_create_ship(r, stype);
    CuAssertPtrNotNull(tc, sh);

    u2 = test_create_unit(f, r);
    u = test_create_unit(f, r);
    CuAssertPtrNotNull(tc, u);
    u_set_ship(u, sh);
    u_set_ship(u2, sh);
    CuAssertPtrEquals(tc, u, ship_owner(sh));
    u->number = 0;
    CuAssertPtrEquals(tc, u2, ship_owner(sh));
    test_teardown();
}
Esempio n. 9
0
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();
}
Esempio n. 10
0
void test_upkeep_from_pool(CuTest * tc)
{
    region *r;
    unit *u1, *u2;
    const item_type *i_silver;

    test_cleanup();
    test_create_world();

    i_silver = it_find("money");
    assert(i_silver);
    r = findregion(0, 0);
    u1 = test_create_unit(test_create_faction(test_create_race("human")), r);
	assert(u1);
    u2 = test_create_unit(u1->faction, r);
    assert(r && u1 && u2);

    set_param(&global.parameters, "rules.food.flags", "0");
    i_change(&u1->items, i_silver, 30);
    get_food(r);
    CuAssertIntEquals(tc, 10, i_get(u1->items, i_silver));
    CuAssertIntEquals(tc, 0, fval(u1, UFL_HUNGER));
    CuAssertIntEquals(tc, 0, fval(u2, UFL_HUNGER));
    get_food(r);
    CuAssertIntEquals(tc, 0, i_get(u1->items, i_silver));
    CuAssertIntEquals(tc, 0, fval(u1, UFL_HUNGER));
    CuAssertIntEquals(tc, UFL_HUNGER, fval(u2, UFL_HUNGER));

    test_cleanup();
}
Esempio n. 11
0
void test_buildingowner_goes_to_empty_unit_after_leave(CuTest * tc)
{
    struct region *r;
    struct building *bld;
    struct unit *u1, *u2, *u3;
    struct faction *f1;

    test_setup();

    f1 = test_create_faction(NULL);
    r = test_create_plain(0, 0);

    bld = test_create_building(r, NULL);
    CuAssertPtrNotNull(tc, bld);

    u1 = test_create_unit(f1, r);
    u2 = test_create_unit(f1, r);
    u3 = test_create_unit(f1, r);
    u_set_building(u1, bld);
    u_set_building(u2, bld);
    u_set_building(u3, bld);

    CuAssertPtrEquals(tc, u1, building_owner(bld));
    u2->number = 0;
    leave_building(u1);
    CuAssertPtrEquals(tc, u3, building_owner(bld));
    leave_building(u3);
    CuAssertPtrEquals(tc, NULL, building_owner(bld));
    u2->number = 1;
    CuAssertPtrEquals(tc, u2, building_owner(bld));
    test_teardown();
}
Esempio n. 12
0
static void test_shipspeed_speedy(CuTest *tc) {
    ship_type *stype;
    ship *sh;
    unit *cap, *crw;
    test_setup();
    stype = test_create_shiptype("dragonship");
    stype->range = 5;
    stype->range_max = -1;
    stype->flags |= SFL_SPEEDY;
    cap = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
    crw = test_create_unit(cap->faction, cap->region);
    sh = test_create_ship(cap->region, stype);
    cap->ship = sh;
    crw->ship = sh;
    set_level(cap, SK_SAILING, stype->cptskill);
    set_level(crw, SK_SAILING, stype->sumskill - stype->cptskill);
    CuAssertPtrEquals(tc, cap, ship_owner(sh));
    CuAssertIntEquals(tc, 5, shipspeed(sh, cap));

    set_level(cap, SK_SAILING, stype->cptskill * 3 - 1);
    CuAssertIntEquals(tc, 5, shipspeed(sh, cap));
    set_level(cap, SK_SAILING, stype->cptskill * 3);
    CuAssertIntEquals(tc, 6, shipspeed(sh, cap));

    set_level(cap, SK_SAILING, stype->cptskill * 3 * 3 - 1);
    CuAssertIntEquals(tc, 6, shipspeed(sh, cap));
    set_level(cap, SK_SAILING, stype->cptskill * 3 * 3);
    CuAssertIntEquals(tc, 7, shipspeed(sh, cap));

    test_teardown();
}
Esempio n. 13
0
static void setup_crew(ship *sh, struct faction *f, unit **cap, unit **crew) {
    if (!f) f = test_create_faction(NULL);
    assert(cap);
    assert(crew);
    *cap = test_create_unit(f, sh->region);
    *crew = test_create_unit(f, sh->region);
    (*cap)->ship = sh;
    (*crew)->ship = sh;
    set_level(*cap, SK_SAILING, sh->type->cptskill);
    set_level(*crew, SK_SAILING, sh->type->sumskill - sh->type->cptskill);
}
Esempio n. 14
0
static void setup_give(struct give *env) {
    struct terrain_type *ter = test_create_terrain("plain", LAND_REGION);
    race *rc;

    assert(env->f1);
    rc = test_create_race(env->f1->race ? env->f1->race->_name : "humon");
    rc->ec_flags |= ECF_GIVEPERSON;

    env->r = test_create_region(0, 0, ter);
    env->src = test_create_unit(env->f1, env->r);
    env->itype = it_get_or_create(rt_get_or_create("money"));
    env->itype->flags |= ITF_HERB;
    if (env->f2) {
        ally_set(&env->f2->allies, env->f1, HELP_GIVE);
        env->dst = test_create_unit(env->f2, env->r);
    }
    else {
        env->dst = NULL;
    }
    if (env->lang) {
        locale_setstring(env->lang, env->itype->rtype->_name, "SILBER");
        init_locale(env->lang);
        env->f1->locale = env->lang;
    }

    config_set("rules.give.max_men", "-1");
    /* success messages: */
    mt_create_va(mt_new("receive_person", NULL), "unit:unit", "target:unit", "amount:int", MT_NEW_END);
    mt_create_va(mt_new("give_person", NULL), "unit:unit", "target:unit", "amount:int", MT_NEW_END);
    mt_create_va(mt_new("give_person_peasants", NULL), "unit:unit", "amount:int", MT_NEW_END);
    mt_create_va(mt_new("give_person_ocean", NULL), "unit:unit", "amount:int", MT_NEW_END);
    mt_create_va(mt_new("receive", NULL), "unit:unit", "target:unit", "resource:resource", "amount:int", MT_NEW_END);
    mt_create_va(mt_new("give", NULL), "unit:unit", "target:unit", "resource:resource", "amount:int", MT_NEW_END);
    mt_create_va(mt_new("give_peasants", NULL), "unit:unit", "resource:resource", "amount:int", MT_NEW_END);
    /* error messages: */
    mt_create_error(120);
    mt_create_error(128);
    mt_create_error(129);
    mt_create_error(96);
    mt_create_error(10);
    mt_create_feedback("feedback_give_forbidden");
    mt_create_feedback("peasants_give_invalid");
    mt_create_va(mt_new("too_many_units_in_faction", NULL), "unit:unit", "region:region", "command:order", "allowed:int", MT_NEW_END);
    mt_create_va(mt_new("too_many_units_in_alliance", NULL), "unit:unit", "region:region", "command:order", "allowed:int", MT_NEW_END);
    mt_create_va(mt_new("feedback_no_contact", NULL), "unit:unit", "region:region", "command:order", "target:unit", MT_NEW_END);
    mt_create_va(mt_new("giverestriction", NULL), "unit:unit", "region:region", "command:order", "turns:int", MT_NEW_END);
    mt_create_va(mt_new("error_unit_size", NULL), "unit:unit", "region:region", "command:order", "maxsize:int", MT_NEW_END);
    mt_create_va(mt_new("nogive_reserved", NULL), "unit:unit", "region:region", "command:order", "resource:resource", "reservation:int", MT_NEW_END);
    mt_create_va(mt_new("race_notake", NULL), "unit:unit", "region:region", "command:order", "race:race", MT_NEW_END);
    mt_create_va(mt_new("race_noregroup", NULL), "unit:unit", "region:region", "command:order", "race:race", MT_NEW_END);
}
Esempio n. 15
0
static void test_fishing_feeds_2_people(CuTest * tc)
{
    const resource_type *rtype;
    region *r;
    faction *f;
    unit *u;
    ship *sh;
    
    test_cleanup();
    test_create_world();
    r = findregion(-1, 0);
    CuAssertStrEquals(tc, "ocean", r->terrain->_name);    /* test_create_world needs coverage */
    f = test_create_faction(rc_find("human"));
    u = test_create_unit(f, r);
    sh = new_ship(st_find("boat"), r, 0);
    u_set_ship(u, sh);
    rtype = get_resourcetype(R_SILVER);
    i_change(&u->items, rtype->itype, 42);
    
    scale_number(u, 1);
    sh->flags |= SF_FISHING;
    get_food(r);
    CuAssertIntEquals(tc, 42, i_get(u->items, rtype->itype));

    scale_number(u, 2);
    sh->flags |= SF_FISHING;
    get_food(r);
    CuAssertIntEquals(tc, 42, i_get(u->items, rtype->itype));

    scale_number(u, 3);
    sh->flags |= SF_FISHING;
    get_food(r);
    CuAssertIntEquals(tc, 32, i_get(u->items, rtype->itype));
}
Esempio n. 16
0
void test_hasspell(CuTest * tc)
{
  spell *sp;
  struct unit * u;
  struct faction * f;
  struct region * r;

  test_cleanup();
  test_create_world();
  r = findregion(0, 0);
  f = test_create_faction(0);
  f->magiegebiet = M_TYBIED;
  u = test_create_unit(f, r);
  skill_enabled[SK_MAGIC] = 1;
  sp = create_spell("testspell", 0);
  sp->sptyp |= POSTCOMBATSPELL;

  unit_add_spell(u, 0, sp, 2);

  set_level(u, SK_MAGIC, 1);
  CuAssertTrue(tc, !u_hasspell(u, sp));

  set_level(u, SK_MAGIC, 2);
  CuAssertTrue(tc, u_hasspell(u, sp));

  set_level(u, SK_MAGIC, 1);
  CuAssertTrue(tc, !u_hasspell(u, sp));
}
Esempio n. 17
0
void test_pay_spell(CuTest * tc)
{
  spell *sp;
  unit * u;
  faction * f;
  region * r;
  int level;

  test_cleanup();
  test_create_world();
  r = findregion(0, 0);
  f = test_create_faction(0);
  u = test_create_unit(f, r);
  CuAssertPtrNotNull(tc, u);

  sp = test_magic_create_spell();
  CuAssertPtrNotNull(tc, sp);

  set_level(u, SK_MAGIC, 5);
  unit_add_spell(u, 0, sp, 1);

  change_resource(u, rt_find("money"), 1);
  change_resource(u, rt_find("aura"), 3);
  change_resource(u, rt_find("horse"), 3);

  level = eff_spelllevel(u, sp, 3, 1);
  CuAssertIntEquals(tc, 3, level);
  pay_spell(u, sp, level, 1);
  CuAssertIntEquals(tc, 0, get_resource(u, rt_find("money")));
  CuAssertIntEquals(tc, 0, get_resource(u, rt_find("aura")));
  CuAssertIntEquals(tc, 0, get_resource(u, rt_find("horse")));
}
Esempio n. 18
0
void test_getspell_school(CuTest * tc)
{
  spell *sp;
  struct unit * u;
  struct faction * f;
  struct region * r;
  struct locale * lang;
  struct spellbook * book;

  test_cleanup();
  test_create_world();
  r = findregion(0, 0);
  f = test_create_faction(0);
  f->magiegebiet = M_TYBIED;
  u = test_create_unit(f, r);
  create_mage(u, f->magiegebiet);
  skill_enabled[SK_MAGIC] = 1;
  set_level(u, SK_MAGIC, 1);

  lang = find_locale("de");
  sp = create_spell("testspell", 0);
  locale_setstring(lang, mkname("spell", sp->sname), "Herp-a-derp");

  CuAssertPtrEquals(tc, 0, unit_getspell(u, "Herp-a-derp", lang));

  book = faction_get_spellbook(f);
  CuAssertPtrNotNull(tc, book);
  spellbook_add(book, sp, 1);
  CuAssertPtrEquals(tc, sp, unit_getspell(u, "Herp-a-derp", lang));
}
Esempio n. 19
0
void test_set_post_combatspell(CuTest * tc)
{
  spell *sp;
  struct unit * u;
  struct faction * f;
  struct region * r;
  const int index = 2;

  test_cleanup();
  test_create_world();
  r = findregion(0, 0);
  f = test_create_faction(0);
  f->magiegebiet = M_TYBIED;
  u = test_create_unit(f, r);
  skill_enabled[SK_MAGIC] = 1;
  set_level(u, SK_MAGIC, 1);
  sp = create_spell("testspell", 0);
  sp->sptyp |= POSTCOMBATSPELL;

  unit_add_spell(u, 0, sp, 1);

  set_combatspell(u, sp, 0, 2);
  CuAssertPtrEquals(tc, sp, (spell *)get_combatspell(u, index));
  set_level(u, SK_MAGIC, 2);
  CuAssertIntEquals(tc, 2, get_combatspelllevel(u, index));
  set_level(u, SK_MAGIC, 1);
  CuAssertIntEquals(tc, 1, get_combatspelllevel(u, index));
  unset_combatspell(u, sp);
  CuAssertIntEquals(tc, 0, get_combatspelllevel(u, index));
  CuAssertPtrEquals(tc, 0, (spell *)get_combatspell(u, index));
}
Esempio n. 20
0
void test_getspell_unit(CuTest * tc)
{
  spell *sp;
  struct unit * u;
  struct faction * f;
  struct region * r;
  struct locale * lang;

  test_cleanup();
  test_create_world();
  r = findregion(0, 0);
  f = test_create_faction(0);
  u = test_create_unit(f, r);
  create_mage(u, M_GRAY);
  skill_enabled[SK_MAGIC] = 1;

  set_level(u, SK_MAGIC, 1);

  lang = find_locale("de");
  sp = create_spell("testspell", 0);
  locale_setstring(lang, mkname("spell", sp->sname), "Herp-a-derp");

  CuAssertPtrEquals(tc, 0, unit_getspell(u, "Herp-a-derp", lang));

  unit_add_spell(u, 0, sp, 1);
  CuAssertPtrNotNull(tc, unit_getspell(u, "Herp-a-derp", lang));
}
Esempio n. 21
0
void test_equipment(CuTest * tc)
{
  equipment * eq;
  unit * u;
  const item_type * it_horses;
  spell *sp;
  sc_mage * mage;
  
  test_cleanup();
  test_create_race("human");
  enable_skill(SK_MAGIC, true);
  it_horses = test_create_itemtype("horse");
  CuAssertPtrNotNull(tc, it_horses);
  sp = create_spell("testspell", 0);
  CuAssertPtrNotNull(tc, sp);

  CuAssertPtrEquals(tc, 0, get_equipment("herpderp"));
  eq = create_equipment("herpderp");
  CuAssertPtrEquals(tc, eq, get_equipment("herpderp"));

  equipment_setitem(eq, it_horses, "1");
  equipment_setskill(eq, SK_MAGIC, "5");
  equipment_addspell(eq, sp, 1);

  u = test_create_unit(0, 0);
  equip_unit_mask(u, eq, EQUIP_ALL);
  CuAssertIntEquals(tc, 1, i_get(u->items, it_horses));
  CuAssertIntEquals(tc, 5, get_level(u, SK_MAGIC));

  mage = get_mage(u);
  CuAssertPtrNotNull(tc, mage);
  CuAssertPtrNotNull(tc, mage->spellbook);
  CuAssertTrue(tc, u_hasspell(u, sp));
}
Esempio n. 22
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();
}
Esempio n. 23
0
void test_change_resource(CuTest * tc)
{
  struct unit * u;
  struct faction * f;
  struct region * r;
  const char * names[] = { "money", "aura", "permaura", "horse", "hp", 0 };
  int i;

  test_cleanup();
  test_create_world();
  skill_enabled[SK_MAGIC] = 1;

  r = findregion(0, 0);
  f = test_create_faction(0);
  u = test_create_unit(f, r);
  CuAssertPtrNotNull(tc, u);
  set_level(u, SK_MAGIC, 5);
  create_mage(u, M_DRAIG);

  for (i=0;names[i];++i) {
    const struct resource_type *rtype = rt_find(names[i]);
    int have = get_resource(u, rtype);
    CuAssertIntEquals(tc, have+1, change_resource(u, rtype, 1));
    CuAssertIntEquals(tc, have+1, get_resource(u, rtype));
  }
}
Esempio n. 24
0
static void test_rename_building_twice(CuTest * tc)
{
  region *r;
  building *b;
  unit *u;
  faction *f;
  building_type *btype;

  test_cleanup();
  test_create_world();

  btype = bt_get_or_create("castle");

  r = findregion(-1, 0);
  b = new_building(btype, r, default_locale);
  f = test_create_faction(rc_find("human"));
  u = test_create_unit(f, r);
  u_set_building(u, b);

  rename_building(u, NULL, b, "Villa Nagel");
  CuAssertStrEquals(tc, "Villa Nagel", b->name);

  rename_building(u, NULL, b, "Villa Kunterbunt");
  CuAssertStrEquals(tc, "Villa Kunterbunt", b->name);
}
Esempio n. 25
0
static void test_group(CuTest * tc)
{
    unit *u;
    region *r;
    faction *f;
    group *g;

    test_cleanup();
    test_create_world();
    r = findregion(0, 0);
    f = test_create_faction(0);
    assert(r && f);
    u = test_create_unit(f, r);
    assert(u);
    CuAssertTrue(tc, join_group(u, "hodor"));
    CuAssertPtrNotNull(tc, (g = get_group(u)));
    CuAssertStrEquals(tc, "hodor", g->name);
    CuAssertIntEquals(tc, 1, g->members);
    set_group(u, 0);
    CuAssertIntEquals(tc, 0, g->members);
    CuAssertPtrEquals(tc, 0, get_group(u));
    set_group(u, g);
    CuAssertIntEquals(tc, 1, g->members);
    CuAssertPtrEquals(tc, g, get_group(u));
    test_cleanup();
}
Esempio n. 26
0
void test_upkeep_hunger_damage(CuTest * tc)
{
    region *r;
    unit *u1;
    faction *f1;
    const item_type *i_silver;

    test_cleanup();
    test_create_world();

    i_silver = it_find("money");
    assert(i_silver);
    r = findregion(0, 0);
    f1 = test_create_faction(test_create_race("human"));
    u1 = test_create_unit(f1, r);
    assert(r && u1);

    set_param(&global.parameters, "rules.food.flags", "0");
    u1->hp = 100;
    get_food(r);
    // since u1 and u2 are not allied, u1 should not help u2 with upkeep
    CuAssertTrue(tc, u1->hp < 100);

    test_cleanup();
}
Esempio n. 27
0
static void test_piracy_cmd_errors(CuTest * tc) {
    race *r;
    faction *f;
    unit *u, *u2;
    ship_type *st_boat;

    test_setup();
    setup_piracy();

    st_boat = st_get_or_create("boat");
    r = test_create_race("pirates");
    u = test_create_unit(f = test_create_faction(r), test_create_region(0, 0, get_or_create_terrain("ocean")));
    f->locale = test_create_locale();
    u->thisorder = create_order(K_PIRACY, f->locale, "");
    assert(u && u->thisorder);

    piracy_cmd(u);
    CuAssertPtrNotNullMsg(tc, "must be on a ship for PIRACY", test_find_messagetype(f->msgs, "error144"));

    test_clear_messages(f);
    fset(r, RCF_SWIM);
    piracy_cmd(u);
    CuAssertPtrEquals_Msg(tc, "swimmers are pirates", 0, test_find_messagetype(f->msgs, "error144"));
    CuAssertPtrEquals_Msg(tc, "swimmers are pirates", 0, test_find_messagetype(f->msgs, "error146"));
    freset(r, RCF_SWIM);
    fset(r, RCF_FLY);
    CuAssertPtrEquals_Msg(tc, "flyers are pirates", 0, test_find_messagetype(f->msgs, "error144"));
    freset(r, RCF_FLY);
    test_clear_messages(f);

    u_set_ship(u, test_create_ship(u->region, st_boat));

    u2 = test_create_unit(u->faction, u->region);
    u2->thisorder = create_order(K_PIRACY, f->locale, "");
    u_set_ship(u2, u->ship);

    test_clear_messages(f);
    piracy_cmd(u2);
    CuAssertPtrNotNullMsg(tc, "must be owner for PIRACY", test_find_messagetype(f->msgs, "error146"));

    test_clear_messages(f);
    piracy_cmd(u);
    CuAssertPtrNotNullMsg(tc, "must specify target for PIRACY", test_find_messagetype(f->msgs, "piratenovictim"));
    CuAssertPtrNotNull(tc, u->thisorder);

    test_teardown();
}
Esempio n. 28
0
static void test_tax_cmd(CuTest *tc) {
    order *ord;
    faction *f;
    region *r;
    unit *u;
    item_type *sword, *silver;
    request *taxorders = 0;


    test_cleanup();
    config_set("taxing.perlevel", "20");
    test_create_world();
    f = test_create_faction(NULL);
    r = findregion(0, 0);
    assert(r && f);
    u = test_create_unit(f, r);

    ord = create_order(K_TAX, f->locale, "");
    assert(ord);

    tax_cmd(u, ord, &taxorders);
    CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error48"));
    test_clear_messages(u->faction);

    silver = get_resourcetype(R_SILVER)->itype;

    sword = it_get_or_create(rt_get_or_create("sword"));
    new_weapontype(sword, 0, 0.0, NULL, 0, 0, 0, SK_MELEE, 1);
    i_change(&u->items, sword, 1);
    set_level(u, SK_MELEE, 1);

    tax_cmd(u, ord, &taxorders);
    CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error_no_tax_skill"));
    test_clear_messages(u->faction);

    set_level(u, SK_TAXING, 1);
    tax_cmd(u, ord, &taxorders);
    CuAssertPtrEquals(tc, 0, test_find_messagetype(u->faction->msgs, "error_no_tax_skill"));
    CuAssertPtrNotNull(tc, taxorders);

    rsetmoney(r, 11);
    expandtax(r, taxorders);
    CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "income"));
    /* taxing is in multiples of 10 */
    CuAssertIntEquals(tc, 10, i_get(u->items, silver));
    test_clear_messages(u->faction);
    i_change(&u->items, silver, -i_get(u->items, silver));

    rsetmoney(r, 1000);
    taxorders = 0;
    tax_cmd(u, ord, &taxorders);
    expandtax(r, taxorders);
    CuAssertIntEquals(tc, 20, i_get(u->items, silver));
    test_clear_messages(u->faction);

    free_order(ord);
    test_cleanup();
}
Esempio n. 29
0
static void test_reorder_units(CuTest * tc)
{
    region *r;
    building *b;
    ship * s;
    unit *u0, *u1, *u2, *u3, *u4;
    struct faction * f;
    const building_type *btype;
    const ship_type *stype;

    test_cleanup();
    test_create_world();

    btype = bt_find("castle");
    stype = st_find("boat");

    r = findregion(-1, 0);
    b = test_create_building(r, btype);
    s = test_create_ship(r, stype);
    f = test_create_faction(0);

    u0 = test_create_unit(f, r);
    u_set_ship(u0, s);
    u1 = test_create_unit(f, r);
    u_set_ship(u1, s);
    ship_set_owner(u1);
    u2 = test_create_unit(f, r);
    u3 = test_create_unit(f, r);
    u_set_building(u3, b);
    u4 = test_create_unit(f, r);
    u_set_building(u4, b);
    building_set_owner(u4);

    reorder_units(r);

    CuAssertPtrEquals(tc, u4, r->units);
    CuAssertPtrEquals(tc, u3, u4->next);
    CuAssertPtrEquals(tc, u2, u3->next);
    CuAssertPtrEquals(tc, u1, u2->next);
    CuAssertPtrEquals(tc, u0, u1->next);
    CuAssertPtrEquals(tc, 0, u0->next);
}
Esempio n. 30
0
static void test_monsters_attack_ocean(CuTest * tc)
{
    faction *f, *f2;
    region *r;
    unit *u, *m;

    create_monsters(&f, &f2, &u, &m);
    r = findregion(-1, 0); // ocean
    u = test_create_unit(u->faction, r);
    unit_setid(u, 2);
    m = test_create_unit(m->faction, r);
    assert(!m->region->land);

    config_set("rules.monsters.attack_chance", "1");

    plan_monsters(f2);

    CuAssertPtrNotNull(tc, find_order("attack 2", m));
    test_cleanup();
}