static void test_attrib_nexttype(CuTest * tc) { attrib_type at_foo = { "foo" }; attrib_type at_bar = { "bar" }; attrib *a, *alist = 0; CuAssertPtrNotNull(tc, (a = a_new(&at_foo))); CuAssertPtrEquals(tc, 0, a->nexttype); CuAssertPtrEquals(tc, a, a_add(&alist, a)); CuAssertPtrEquals(tc, 0, alist->nexttype); CuAssertPtrNotNull(tc, a_add(&alist, a_new(&at_foo))); CuAssertPtrEquals(tc, 0, alist->nexttype); CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_bar)))); CuAssertPtrEquals(tc, a, alist->nexttype); CuAssertPtrEquals(tc, 0, a->nexttype); a_remove(&alist, alist); CuAssertPtrEquals(tc, a, alist->nexttype); CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_bar)))); a_remove(&alist, alist->nexttype); CuAssertPtrEquals(tc, a, alist->nexttype); a_removeall(&alist, &at_foo); a_removeall(&alist, &at_bar); }
static void test_attrib_removeall(CuTest * tc) { const attrib_type at_foo = { "foo" }; const attrib_type at_bar = { "bar" }; attrib *alist = 0, *a; a_add(&alist, a_new(&at_foo)); a = a_add(&alist, a_new(&at_bar)); a_add(&alist, a_new(&at_foo)); a_removeall(&alist, &at_foo); CuAssertPtrEquals(tc, a, alist); CuAssertPtrEquals(tc, 0, alist->next); a_add(&alist, a_new(&at_bar)); a_add(&alist, a_new(&at_foo)); a_removeall(&alist, NULL); CuAssertPtrEquals(tc, 0, alist); }
static void test_upgrade_dict(CuTest *tc) { attrib *a; a = a_new(&at_dict); dict_set(a, "embassy_muschel", 42); CuAssertPtrNotNull(tc, a->type->upgrade); a->type->upgrade(&a, a); CuAssertIntEquals(tc, 42, key_get(a, atoi36("mupL"))); a_removeall(&a, NULL); }
static int tolua_region_set_terrainname(lua_State * L) { region *self = (region *) tolua_tousertype(L, 1, 0); const char *name = tolua_tostring(L, 2, 0); if (name == NULL) { a_removeall(&self->attribs, &at_racename); } else { set_racename(&self->attribs, name); } return 0; }
static void test_attrib_add(CuTest * tc) { attrib_type at_foo = { "foo" }; attrib_type at_bar = { "bar" }; attrib *a, *alist = 0; CuAssertPtrNotNull(tc, (a = a_new(&at_foo))); CuAssertPtrEquals(tc, a, a_add(&alist, a)); CuAssertPtrEquals(tc, a, alist); CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_foo)))); CuAssertPtrEquals_Msg(tc, "new attribute not added after existing", alist->next, a); CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_bar)))); CuAssertPtrEquals_Msg(tc, "new atribute not added at end of list", alist->next->next, a); CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_foo)))); CuAssertPtrEquals_Msg(tc, "messages not sorted by type", alist->next->next, a); a_removeall(&alist, &at_foo); a_removeall(&alist, &at_bar); }
static void test_attrib_remove_self(CuTest * tc) { attrib_type at_foo = { "foo" }; attrib *a, *alist = 0; CuAssertPtrNotNull(tc, a_add(&alist, a_new(&at_foo))); CuAssertPtrNotNull(tc, a = a_add(&alist, a_new(&at_foo))); CuAssertPtrEquals(tc, a, alist->next); CuAssertPtrEquals(tc, 0, alist->nexttype); CuAssertIntEquals(tc, 1, a_remove(&alist, alist)); CuAssertPtrEquals(tc, a, alist); a_removeall(&alist, NULL); }
static void test_get_set_keys(CuTest *tc) { attrib *a = 0; key_set(&a, 42, 1); key_set(&a, 43, 2); key_set(&a, 44, 3); CuAssertIntEquals(tc, 1, key_get(a, 42)); CuAssertIntEquals(tc, 2, key_get(a, 43)); CuAssertIntEquals(tc, 3, key_get(a, 44)); key_unset(&a, 42); CuAssertIntEquals(tc, 0, key_get(a, 42)); CuAssertIntEquals(tc, 2, key_get(a, 43)); CuAssertIntEquals(tc, 3, key_get(a, 44)); a_removeall(&a, NULL); }
static void test_get_set_keys(CuTest *tc) { attrib *a = 0; key_set(&a, 42); key_set(&a, 43); key_set(&a, 44); CuAssertTrue(tc, key_get(a, 42)); CuAssertTrue(tc, key_get(a, 43)); CuAssertTrue(tc, key_get(a, 44)); key_unset(&a, 42); CuAssertTrue(tc, !key_get(a, 42)); CuAssertTrue(tc, key_get(a, 43)); CuAssertTrue(tc, key_get(a, 44)); a_removeall(&a, NULL); }
static void test_upgrade_key(CuTest *tc) { attrib *alist = 0; key_set_orig(&alist, 40); key_set_orig(&alist, 41); key_set_orig(&alist, 43); key_set_orig(&alist, 42); key_set_orig(&alist, 44); CuAssertPtrNotNull(tc, alist->type->upgrade); alist->type->upgrade(&alist, alist); CuAssertIntEquals(tc, 1, key_get(alist, 40)); CuAssertIntEquals(tc, 1, key_get(alist, 41)); CuAssertIntEquals(tc, 1, key_get(alist, 42)); CuAssertIntEquals(tc, 1, key_get(alist, 43)); CuAssertIntEquals(tc, 1, key_get(alist, 44)); a_removeall(&alist, NULL); }
void alp_findet_opfer(unit * alp, region * r) { curse *c; attrib *a = a_find(alp->attribs, &at_alp); alp_data *ad = (alp_data *) a->data.v; unit *mage = ad->mage; unit *opfer = ad->target; float effect; message *msg; assert(opfer); assert(mage); /* Magier und Opfer Bescheid geben */ msg = msg_message("alp_success", "target", opfer); add_message(&mage->faction->msgs, msg); r_addmessage(opfer->region, opfer->faction, msg); msg_release(msg); /* Relations werden in destroy_unit(alp) automatisch gelöscht. * Die Aktionen, die beim Tod des Alps ausgelöst werden sollen, * müssen jetzt aber deaktiviert werden, sonst werden sie gleich * beim destroy_unit(alp) ausgelöst. */ a_removeall(&alp->attribs, &at_eventhandler); /* Alp umwandeln in Curse */ effect = -2; c = create_curse(mage, &opfer->attribs, ct_find("worse"), 2, 2, effect, opfer->number); /* solange es noch keine spezielle alp-Antimagie gibt, reagiert der * auch auf normale */ set_number(alp, 0); /* wenn der Magier stirbt, wird der Curse wieder vom Opfer genommen */ add_trigger(&mage->attribs, "destroy", trigger_removecurse(c, opfer)); }
void destroyfaction(faction ** fp) { faction * f = *fp; unit *u = f->units; *fp = f->next; f->next = dead_factions; dead_factions = f; fset(f, FFL_QUIT); f->_alive = false; if (f->spellbook) { spellbook_clear(f->spellbook); free(f->spellbook); f->spellbook = 0; } if (f->seen_factions) { selist_free(f->seen_factions); f->seen_factions = 0; } while (u) { /* give away your stuff, to ghosts if you cannot (quest items) */ if (u->items) { region *r = u->region; int result = gift_items(u, GIFT_FRIENDS | GIFT_PEASANTS); if (result != 0) { save_special_items(u); } if (r->land && !!playerrace(u_race(u))) { const race *rc = u_race(u); int m = rmoney(r); /* Personen gehen nur an die Bauern, wenn sie auch von dort * stammen */ if ((rc->ec_flags & ECF_REC_ETHEREAL) == 0) { int p = rpeasants(u->region); int h = rhorses(u->region); item *itm; p += (int)(u->number * rc->recruit_multi); for (itm = u->items; itm; itm = itm->next) { if (itm->type->flags & ITF_ANIMAL) { h += itm->number; } } rsetpeasants(r, p); rsethorses(r, h); } m += get_money(u); rsetmoney(r, m); } } set_number(u, 0); u = u->nextF; } handle_event(f->attribs, "destroy", f); if (f->alliance) { setalliance(f, NULL); } funhash(f); /* units of other factions that were disguised as this faction * have their disguise replaced by ordinary faction hiding. */ if (rule_stealth_other()) { region *rc; for (rc = regions; rc; rc = rc->next) { for (u = rc->units; u; u = u->next) { if (u->attribs && get_otherfaction(u) == f) { a_removeall(&u->attribs, &at_otherfaction); if (rule_stealth_anon()) { fset(u, UFL_ANON_FACTION); } } } } } }
void age_piracy(region *r) { a_removeall(&r->attribs, &at_piracy_direction); }