Пример #1
0
void test_spellbooks(CuTest * tc)
{
  spell *sp;
  spellbook *herp, *derp;
  spellbook_entry *entry;
  const char * sname = "herpderp";
  test_cleanup();

  herp = get_spellbook("herp");
  derp = get_spellbook("derp");
  CuAssertPtrNotNull(tc, herp);
  CuAssertPtrNotNull(tc, derp);
  CuAssertTrue(tc, derp!=herp);
  CuAssertStrEquals(tc, "herp", herp->name);
  CuAssertStrEquals(tc, "derp", derp->name);

  sp = create_spell(sname, 0);
  spellbook_add(herp, sp, 1);
  CuAssertPtrNotNull(tc, sp);
  entry = spellbook_get(herp, sp);
  CuAssertPtrNotNull(tc, entry);
  CuAssertPtrEquals(tc, sp, entry->sp);
  /* CuAssertPtrEquals(tc, 0, spellbook_get(derp, sname)); */

  test_cleanup();
  herp = get_spellbook("herp");
  CuAssertPtrNotNull(tc, herp);
  /* CuAssertPtrEquals(tc, 0, spellbook_get(herp, sname)); */
}
Пример #2
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));
}
Пример #3
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));
}
Пример #4
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));
}
Пример #5
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));
}
Пример #6
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));
}
Пример #7
0
static void json_spells(cJSON *json) {
    cJSON *child;
    if (json->type != cJSON_Object) {
        log_error("spells is not a json object: %d", json->type);
        return;
    }
    for (child = json->child; child; child = child->next) {
        if (child->type == cJSON_Object) {
            spell *sp;
            cJSON * item = cJSON_GetObjectItem(child, "index");
            sp = create_spell(child->string, item ? item->valueint : 0);
            for (item = child->child; item; item = item->next) {
                if (strcmp(item->string, "index") == 0) {
                    continue;
                }
                else if (strcmp(item->string, "cast") == 0) {
                    sp->cast = (spell_f)get_function(item->valuestring);
                }
                else if (strcmp(item->string, "fumble") == 0) {
                    sp->fumble = (fumble_f)get_function(item->valuestring);
                }
                else if (strcmp(item->string, "syntax") == 0) {
                    sp->syntax = _strdup(item->valuestring);
                }
            }
        }
    }
}
Пример #8
0
static void test_create_duplicate_spell(CuTest * tc)
{
    spell *sp;
    struct log_t *log;
    strlist *sl = 0;

    test_setup();
    test_log_stderr(0); /* suppress the "duplicate spell" error message */
    log = test_log_start(LOG_CPERROR, &sl);

    CuAssertPtrEquals(tc, NULL, find_spell("testspell"));

    sp = create_spell("testspell");
    CuAssertPtrEquals(tc, NULL, create_spell("testspell"));
    CuAssertPtrNotNull(tc, sl);
    CuAssertStrEquals(tc, "create_spell: duplicate name '%s'", sl->s);
    CuAssertPtrEquals(tc, NULL, sl->next);
    CuAssertPtrEquals(tc, sp, find_spell("testspell"));
    test_log_stop(log, sl);
    test_log_stderr(1); /* or teardown complains that stderr logging is off */
    test_teardown();
}
Пример #9
0
static void test_create_a_spell(CuTest * tc)
{
    spell * sp;

    test_setup();
    CuAssertPtrEquals(tc, NULL, spells);
    CuAssertPtrEquals(tc, NULL, find_spell("testspell"));

    sp = create_spell("testspell");
    CuAssertPtrEquals(tc, sp, find_spell("testspell"));
    CuAssertPtrNotNull(tc, spells);
    test_teardown();
}
Пример #10
0
static spell * test_magic_create_spell(void)
{
  spell *sp;
  sp = create_spell("testspell", 0);

  sp->components = (spell_component *) calloc(4, sizeof(spell_component));
  sp->components[0].amount = 1;
  sp->components[0].type = rt_find("money");
  sp->components[0].cost = SPC_FIX;
  sp->components[1].amount = 1;
  sp->components[1].type = rt_find("aura");
  sp->components[1].cost = SPC_LEVEL;
  sp->components[2].amount = 1;
  sp->components[2].type = rt_find("horse");
  sp->components[2].cost = SPC_LINEAR;
  return sp;
}
Пример #11
0
static void test_spellref(CuTest *tc)
{
    spellref *ref;
    spell *sp;
    test_setup();
    ref = spellref_create(NULL, "hodor");
    CuAssertPtrNotNull(tc, ref);
    CuAssertPtrEquals(tc, NULL, ref->sp);
    CuAssertStrEquals(tc, "hodor", ref->_name);
    CuAssertPtrEquals(tc, NULL, spellref_get(ref));
    CuAssertStrEquals(tc, "hodor", spellref_name(ref));
    sp = create_spell("hodor");
    CuAssertPtrNotNull(tc, sp);
    CuAssertPtrEquals(tc, sp, spellref_get(ref));
    spellref_free(ref);
    test_teardown();
}
Пример #12
0
void test_updatespells(CuTest * tc)
{
  faction * f;
  spell * sp;
  spellbook *book = 0;

  test_cleanup();
  
  f = test_create_faction(0);
  sp = create_spell("testspell", 0);
  CuAssertPtrNotNull(tc, sp);

  book = create_spellbook("spells");
  CuAssertPtrNotNull(tc, book);
  spellbook_add(book, sp, 1);

  CuAssertPtrEquals(tc, 0, f->spellbook);
  pick_random_spells(f, 1, book, 1);
  CuAssertPtrNotNull(tc, f->spellbook);
  CuAssertIntEquals(tc, 1, ql_length(f->spellbook->spells));
  CuAssertPtrNotNull(tc, spellbook_get(f->spellbook, sp));
}
Пример #13
0
void test_named_spellbooks(CuTest * tc)
{
    spell *sp;
    spellbook *sb;
    spellbook_entry *sbe;
    int counter = 0;

    sb = create_spellbook(0);
    CuAssertPtrNotNull(tc, sb);
    CuAssertPtrEquals(tc, NULL, sb->name);
    spellbook_clear(sb);
    free(sb);

    sb = create_spellbook("spells");
    CuAssertPtrNotNull(tc, sb);
    CuAssertStrEquals(tc, "spells", sb->name);

    sp = create_spell("testspell");
    spellbook_add(sb, sp, 1);
    CuAssertPtrNotNull(tc, sb->spells);

    sbe = spellbook_get(sb, sp);
    CuAssertPtrNotNull(tc, sbe);
    CuAssertIntEquals(tc, 1, sbe->level);
    CuAssertPtrEquals(tc, sp, spellref_get(&sbe->spref));

    spellbook_foreach(sb, count_spell_cb, &counter);
    CuAssertIntEquals(tc, 1, counter);

#ifdef TODO
    /* try adding the same spell twice. that should fail */
    spellbook_add(sb, sp, 1);
    spellbook_foreach(sb, count_spell_cb, &counter);
    CuAssertIntEquals(tc, 1, counter);
#endif
    spellbook_clear(sb);
    free(sb);
}