Ejemplo n.º 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)); */
}
Ejemplo n.º 2
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));
}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
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));
}