static void test_shock_low(CuTest *tc) {
    unit *u;
    trigger *tt;
    test_cleanup();

    u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
    create_mage(u, M_GRAY);
    set_level(u, SK_MAGIC, 5);
    set_spellpoints(u, 1);
    u->hp = 1;
    tt = trigger_shock(u);
    tt->type->handle(tt, u);
    CuAssertIntEquals(tc, 1, u->hp);
    CuAssertIntEquals(tc, 1, get_spellpoints(u));
    t_free(tt);
    free(tt);
    test_cleanup();
}
static void test_shock(CuTest *tc) {
    unit *u;
    trigger *tt;
    test_cleanup();

    u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
    create_mage(u, M_GRAY);
    set_level(u, SK_MAGIC, 5);
    set_spellpoints(u, 10);
    u->hp = 10;
    tt = trigger_shock(u);
    tt->type->handle(tt, u);
    CuAssertIntEquals(tc, 2, u->hp);
    CuAssertIntEquals(tc, 2, get_spellpoints(u));
    CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "shock"));
    t_free(tt);
    free(tt);
    test_cleanup();
}
Exemple #3
0
static void do_shock(unit * u, const char *reason)
{
  int i;

  if (u->number > 0) {
    /* HP - Verlust */
    u->hp = (unit_max_hp(u) * u->number) / 10;
    u->hp = _max(1, u->hp);
  }

  /* Aura - Verlust */
  if (is_mage(u)) {
    set_spellpoints(u, max_spellpoints(u->region, u) / 10);
  }

  /* Evt. Talenttageverlust */
  for (i = 0; i != u->skill_size; ++i)
    if (rng_int() % 5 == 0) {
      skill *sv = u->skills + i;
      int weeks = (sv->level * sv->level - sv->level) / 2;
      int change = (weeks + 9) / 10;
      reduce_skill(u, sv, change);
    }

  /* Dies ist ein Hack, um das skillmod und familiar-Attribut beim Mage
   * zu löschen wenn der Familiar getötet wird. Da sollten wir über eine
   * saubere Implementation nachdenken. */

  if (strcmp(reason, "trigger") == 0) {
    remove_familiar(u);
  }
  if (u->faction != NULL) {
    ADDMSG(&u->faction->msgs, msg_message("shock",
        "mage reason", u, _strdup(reason)));
  }
}