Example #1
0
static void setup_piracy(void) {
    struct locale *lang;
    ship_type *st_boat;

    config_set("rules.ship.storms", "0");
    lang = get_or_create_locale("de");
    locale_setstring(lang, directions[D_EAST], "OSTEN");
    init_directions(lang);
    test_create_terrain("ocean", SEA_REGION);
    st_boat = test_create_shiptype("boat");
    st_boat->cargo = 1000;

    mt_create_error(144);
    mt_create_error(146);
    mt_create_va(mt_new("piratenovictim", NULL),
        "ship:ship", "unit:unit", "region:region", MT_NEW_END);
    mt_create_va(mt_new("piratesawvictim", NULL),
        "ship:ship", "unit:unit", "region:region", "dir:int", MT_NEW_END);
    mt_create_va(mt_new("shipsail", NULL),
        "ship:ship", "from:region", "to:region", MT_NEW_END);
    mt_create_va(mt_new("shipfly", NULL),
        "ship:ship", "from:region", "to:region", MT_NEW_END);
    mt_create_va(mt_new("shipnoshore", NULL),
        "ship:ship", "region:region", MT_NEW_END);
    mt_create_va(mt_new("travel", NULL),
        "unit:unit", "start:region", "end:region", "mode:int", "regions:regions", MT_NEW_END);
}
Example #2
0
static void test_export_ocean_region(CuTest * tc) {
    struct terrain_type *terrain;
    cJSON *json;
    test_cleanup();
    terrain = test_create_terrain("ocean", SEA_REGION);
    json = export_a_region(tc, terrain, 0);
    CuAssertPtrEquals(tc, 0, cJSON_GetObjectItem(json, "name"));
    cJSON_Delete(json);
    test_cleanup();
}
Example #3
0
static void test_give_unit_to_ocean(CuTest * tc) {
    struct give env = { 0 };
    test_setup_ex(tc);
    env.f1 = test_create_faction(NULL);
    env.f2 = 0;
    setup_give(&env);
    env.r->terrain = test_create_terrain("ocean", SEA_REGION);
    give_unit(env.src, NULL, NULL);
    CuAssertIntEquals(tc, 0, env.src->number);
    test_teardown();
}
Example #4
0
static void test_export_land_region(CuTest * tc) {
    region *r;
    struct terrain_type *terrain;
    cJSON *json, *attr;
    test_cleanup();
    terrain = test_create_terrain("plain", LAND_REGION);
    json = export_a_region(tc, terrain, &r);
    CuAssertPtrNotNull(tc, attr = cJSON_GetObjectItem(json, "name"));
    CuAssertStrEquals(tc, r->land->name, attr->valuestring);
    cJSON_Delete(json);
    test_cleanup();
}
Example #5
0
static void test_steal_okay(CuTest * tc) {
    struct steal env;
    race *rc;
    struct terrain_type *ter;

    test_cleanup();
    ter = test_create_terrain("plain", LAND_REGION);
    rc = test_create_race("human");
    rc->flags = 0;
    setup_steal(&env, ter, rc);
    CuAssertPtrEquals(tc, 0, check_steal(env.u, 0));
    test_cleanup();
}
Example #6
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);
}
Example #7
0
/** creates a small world and some stuff in it.
 * two terrains: 'plain' and 'ocean'
 * one race: 'human'
 * one ship_type: 'boat'
 * one building_type: 'castle'
 * in 0.0 and 1.0 is an island of two plains, around it is ocean.
 */
void test_create_world(void)
{
  terrain_type *t_plain, *t_ocean;
  region *island[2];
  int i;
  const char * names[] = { "horse", "horse_p", "boat", "boat_p", "iron", "iron_p", "stone", "stone_p" };

  make_locale("de");
  init_resources();
  assert(!olditemtype[I_HORSE]);

  olditemtype[I_HORSE] = test_create_itemtype(names+0);
  olditemtype[I_IRON] = test_create_itemtype(names+4);
  olditemtype[I_STONE] = test_create_itemtype(names+6);

  t_plain = test_create_terrain("plain", LAND_REGION | FOREST_REGION | WALK_INTO | CAVALRY_REGION);
  t_plain->size = 1000;
  t_ocean = test_create_terrain("ocean", SEA_REGION | SAIL_INTO | SWIM_INTO);
  t_ocean->size = 0;

  island[0] = test_create_region(0, 0, t_plain);
  island[1] = test_create_region(1, 0, t_plain);
  for (i = 0; i != 2; ++i) {
    int j;
    region *r = island[i];
    for (j = 0; j != MAXDIRECTIONS; ++j) {
      region *rn = r_connect(r, (direction_t)j);
      if (!rn) {
        rn = test_create_region(r->x + delta_x[j], r->y + delta_y[j], t_ocean);
      }
    }
  }

  test_create_race("human");

  test_create_buildingtype("castle");
  test_create_shiptype(names+2);
}
Example #8
0
static void test_steal_ocean(CuTest * tc) {
    struct steal env;
    race *rc;
    terrain_type *ter;
    message *msg;

    test_cleanup();
    ter = test_create_terrain("ocean", SEA_REGION);
    rc = test_create_race("human");
    setup_steal(&env, ter, rc);
    CuAssertPtrNotNull(tc, msg = check_steal(env.u, 0));
    msg_release(msg);
    test_cleanup();
}
Example #9
0
static ship *setup_ship(void) {
    region *r;
    ship_type *stype;

    set_param(&global.parameters, "movement.shipspeed.skillbonus", "0");
    r = test_create_region(0, 0, test_create_terrain("ocean", 0));
    stype = test_create_shiptype("longboat");
    stype->cptskill = 1;
    stype->sumskill = 10;
    stype->minskill = 1;
    stype->range = 2;
    stype->range_max = 4;
    return test_create_ship(r, stype);
}
Example #10
0
static void test_give_men_in_ocean(CuTest * tc) {
    struct give env = { 0 };
    message * msg;

    test_setup_ex(tc);
    env.f1 = test_create_faction(NULL);
    env.f2 = 0;
    setup_give(&env);
    env.r->terrain = test_create_terrain("ocean", SEA_REGION);
    msg = disband_men(1, env.src, NULL);
    CuAssertStrEquals(tc, "give_person_ocean", test_get_messagetype(msg));
    CuAssertIntEquals(tc, 0, env.src->number);
    msg_release(msg);
    test_teardown();
}
Example #11
0
static void test_steal_nosteal(CuTest * tc) {
    struct steal env;
    race *rc;
    terrain_type *ter;
    message *msg;

    test_cleanup();
    ter = test_create_terrain("plain", LAND_REGION);
    rc = test_create_race("human");
    rc->flags = RCF_NOSTEAL;
    setup_steal(&env, ter, rc);
    CuAssertPtrNotNull(tc, msg = check_steal(env.u, 0));
    msg_release(msg);
    test_cleanup();
}
Example #12
0
static void test_getunit(CuTest *tc) {
    unit *u, *u2;
    order *ord;
    attrib *a;
    struct region *r;
    struct locale *lang;
    struct terrain_type *t_plain;

    test_cleanup();
    lang = get_or_create_locale("de");
    test_translate_param(lang, P_TEMP, "TEMP");
    /* note that the english order is FIGHT, not COMBAT, so this is a poor example */
    t_plain = test_create_terrain("plain", LAND_REGION);
    u = test_create_unit(test_create_faction(0), test_create_region(0, 0, t_plain));
    a = a_add(&u->attribs, a_new(&at_alias));
    a->data.i = atoi36("42"); /* this unit is also TEMP 42 */
    r = test_create_region(1, 0, t_plain);

    ord = create_order(K_GIVE, lang, itoa36(u->no));
    init_order(ord);
    CuAssertIntEquals(tc, GET_UNIT, getunit(u->region, u->faction, &u2));
    CuAssertPtrEquals(tc, u, u2);
    init_order(ord);
    CuAssertIntEquals(tc, GET_NOTFOUND, getunit(r, u->faction, &u2));
    CuAssertPtrEquals(tc, NULL, u2);
    free_order(ord);

    ord = create_order(K_GIVE, lang, itoa36(u->no + 1));
    init_order(ord);
    CuAssertIntEquals(tc, GET_NOTFOUND, getunit(u->region, u->faction, &u2));
    CuAssertPtrEquals(tc, NULL, u2);
    free_order(ord);

    ord = create_order(K_GIVE, lang, "0");
    init_order(ord);
    CuAssertIntEquals(tc, GET_PEASANTS, getunit(u->region, u->faction, &u2));
    CuAssertPtrEquals(tc, NULL, u2);
    free_order(ord);

    ord = create_order(K_GIVE, lang, "TEMP 42");
    init_order(ord);
    CuAssertIntEquals(tc, GET_UNIT, getunit(u->region, u->faction, &u2));
    CuAssertPtrEquals(tc, u, u2);
    free_order(ord);

    test_cleanup();
}
static void test_read_unitid(CuTest *tc) {
    unit *u;
    order *ord;
    attrib *a;
    struct locale *lang;
    struct terrain_type *t_plain;

    test_cleanup();
    lang = get_or_create_locale("de");
    test_translate_param(lang, P_TEMP, "TEMP");
    /* note that the english order is FIGHT, not COMBAT, so this is a poor example */
    t_plain = test_create_terrain("plain", LAND_REGION);
    u = test_create_unit(test_create_faction(0), test_create_region(0, 0, t_plain));
    a = a_add(&u->attribs, a_new(&at_alias));
    a->data.i = atoi36("42"); /* this unit is also TEMP 42 */

    ord = create_order(K_GIVE, lang, "TEMP 42");
    init_order(ord);
    CuAssertIntEquals(tc, u->no, read_unitid(u->faction, u->region));
    free_order(ord);

    ord = create_order(K_GIVE, lang, "8");
    init_order(ord);
    CuAssertIntEquals(tc, 8, read_unitid(u->faction, u->region));
    free_order(ord);

    ord = create_order(K_GIVE, lang, "");
    init_order(ord);
    CuAssertIntEquals(tc, -1, read_unitid(u->faction, u->region));
    free_order(ord);

    ord = create_order(K_GIVE, lang, "TEMP");
    init_order(ord);
    CuAssertIntEquals(tc, -1, read_unitid(u->faction, u->region));
    free_order(ord);

    // bug https://bugs.eressea.de/view.php?id=1685
    ord = create_order(K_GIVE, lang, "##");
    init_order(ord);
    CuAssertIntEquals(tc, -1, read_unitid(u->faction, u->region));
    free_order(ord);

    test_cleanup();
}
Example #14
0
static void test_move_to_vortex(CuTest *tc) {
    region *r1, *r2, *r = 0;
    terrain_type *t_plain;
    unit *u;
    struct locale *lang;

    test_cleanup();
    lang = get_or_create_locale("en");
    locale_setstring(lang, "vortex", "wirbel");
    init_locale(lang);
    t_plain = test_create_terrain("plain", LAND_REGION | FOREST_REGION | WALK_INTO | CAVALRY_REGION);
    r1 = test_create_region(0, 0, t_plain);
    r2 = test_create_region(5, 0, t_plain);
    CuAssertPtrNotNull(tc, create_special_direction(r1, r2, 10, "", "vortex", true));
    u = test_create_unit(test_create_faction(rc_get_or_create("hodor")), r1);
    CuAssertIntEquals(tc, E_MOVE_NOREGION, movewhere(u, "barf", r1, &r));
    CuAssertIntEquals(tc, E_MOVE_OK, movewhere(u, "wirbel", r1, &r));
    CuAssertPtrEquals(tc, r2, r);
}
Example #15
0
static void test_regionid(CuTest * tc) {
    size_t len;
    const struct terrain_type * plain;
    struct region * r;
    char buffer[64];

    test_cleanup();
    plain = test_create_terrain("plain", 0);
    r = test_create_region(0, 0, plain);

    memset(buffer, 0x7d, sizeof(buffer));
    len = f_regionid(r, 0, buffer, sizeof(buffer));
    CuAssertIntEquals(tc, 11, len);
    CuAssertStrEquals(tc, "plain (0,0)", buffer);

    memset(buffer, 0x7d, sizeof(buffer));
    len = f_regionid(r, 0, buffer, 11);
    CuAssertIntEquals(tc, 10, len);
    CuAssertStrEquals(tc, "plain (0,0", buffer);
    CuAssertIntEquals(tc, 0x7d, buffer[11]);
}
Example #16
0
static void test_fix_demand(CuTest *tc) {
    region *r;
    terrain_type *tplain;
    item_type *ltype;

    test_cleanup();
    ltype = test_create_itemtype("balm");
    ltype->rtype->flags |= (RTF_ITEM | RTF_POOLED);
    new_luxurytype(ltype, 0);
    ltype = test_create_itemtype("oint");
    ltype->rtype->flags |= (RTF_ITEM | RTF_POOLED);
    new_luxurytype(ltype, 0);
    tplain = test_create_terrain("plain", LAND_REGION);
    r = new_region(0, 0, NULL, 0);
    CuAssertPtrNotNull(tc, r);
    terraform_region(r, tplain);
    CuAssertPtrNotNull(tc, r->land);
    CuAssertIntEquals(tc, 0, fix_demand(r));
    CuAssertPtrNotNull(tc, r->land->demands);
    CuAssertPtrNotNull(tc, r->land->demands->next);
    CuAssertPtrNotNull(tc, r_luxury(r));
    test_cleanup();
}
Example #17
0
static void create_monsters(faction **player, faction **monsters, unit **u, unit **m) {
    race* rc;
    region *r;

    test_cleanup();

    test_create_horse();
    default_locale = test_create_locale();
    *player = test_create_faction(NULL);
    *monsters = get_or_create_monsters();
    assert(rc_find((*monsters)->race->_name));
    rc = rc_get_or_create((*monsters)->race->_name);
    fset(rc, RCF_UNARMEDGUARD|RCF_NPC|RCF_DRAGON);
    fset(*monsters, FFL_NOIDLEOUT);
    assert(fval(*monsters, FFL_NPC) && fval((*monsters)->race, RCF_UNARMEDGUARD) && fval((*monsters)->race, RCF_NPC) && fval(*monsters, FFL_NOIDLEOUT));

    test_create_region(-1, 0, test_create_terrain("ocean", SEA_REGION | SWIM_INTO | FLY_INTO));
    test_create_region(1, 0, 0);
    r = test_create_region(0, 0, 0);

    *u = test_create_unit(*player, r);
    unit_setid(*u, 1);
    *m = test_create_unit(*monsters, r);
}
Example #18
0
static void setup_give(struct give *env) {
    terrain_type *ter = test_create_terrain("plain", LAND_REGION);
    env->r = test_create_region(0, 0, ter);
    env->src = test_create_unit(env->f1, env->r);
    env->dst = test_create_unit(env->f2, env->r);
}