Example #1
0
void test_getspell_faction(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);
  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));

  f->spellbook = create_spellbook(0);
  spellbook_add(f->spellbook, sp, 1);
  CuAssertPtrEquals(tc, sp, unit_getspell(u, "Herp-a-derp", lang));
}
Example #2
0
void unit_add_spell(unit * u, sc_mage * m, struct spell * sp, int level)
{
  sc_mage *mage = m ? m : get_mage(u);

  if (!mage) {
    log_debug("adding new spell %s to a previously non-mage unit %s\n", sp->sname, unitname(u));
    mage = create_mage(u, u->faction?u->faction->magiegebiet:M_GRAY);
  }
  if (!mage->spellbook) {
    mage->spellbook = create_spellbook(0);
  }
  spellbook_add(mage->spellbook, sp, level);
}
Example #3
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);
}
Example #4
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));
}