static void test_remove_empty_factions(CuTest *tc) { faction *f, *fm; int fno; test_cleanup(); fm = get_or_create_monsters(); assert(fm); f = test_create_faction(0); fno = f->no; remove_empty_factions(); CuAssertIntEquals(tc, false, f->_alive); CuAssertPtrEquals(tc, fm, factions); CuAssertPtrEquals(tc, NULL, fm->next); CuAssertPtrEquals(tc, 0, findfaction(fno)); CuAssertPtrEquals(tc, fm, get_monsters()); test_cleanup(); }
/** Drachen und Seeschlangen können entstehen */ void spawn_dragons(void) { region *r; faction *monsters = get_or_create_monsters(); for (r = regions; r; r = r->next) { unit *u; if (fval(r->terrain, SEA_REGION) && rng_int() % 10000 < 1) { u = create_unit(r, monsters, 1, get_race(RC_SEASERPENT), 0, NULL, NULL); fset(u, UFL_ISNEW | UFL_MOVED); equip_unit(u, get_equipment("monster_seaserpent")); } if ((r->terrain == newterrain(T_GLACIER) || r->terrain == newterrain(T_SWAMP) || r->terrain == newterrain(T_DESERT)) && rng_int() % 10000 < (5 + 100 * chaosfactor(r))) { if (chance(0.80)) { u = create_unit(r, monsters, nrand(60, 20) + 1, get_race(RC_FIREDRAGON), 0, NULL, NULL); } else { u = create_unit(r, monsters, nrand(30, 20) + 1, get_race(RC_DRAGON), 0, NULL, NULL); } fset(u, UFL_ISNEW | UFL_MOVED); equip_unit(u, get_equipment("monster_dragon")); log_debug("spawning %d %s in %s.\n", u->number, LOC(default_locale, rc_name_s(u_race(u), (u->number == 1) ? NAME_SINGULAR : NAME_PLURAL)), regionname(r, NULL)); name_unit(u); /* add message to the region */ ADDMSG(&r->msgs, msg_message("sighting", "region race number", r, u_race(u), u->number)); } } }
static void test_remove_dead_factions(CuTest *tc) { faction *f, *fm; region *r; int fno; test_cleanup(); r = test_create_region(0, 0, 0); fm = get_or_create_monsters(); f = test_create_faction(0); assert(fm && r && f); test_create_unit(f, r); test_create_unit(fm, r); remove_empty_factions(); CuAssertPtrEquals(tc, f, findfaction(f->no)); CuAssertPtrNotNull(tc, get_monsters()); fm->units = 0; f->_alive = false; fno = f->no; remove_empty_factions(); CuAssertPtrEquals(tc, 0, findfaction(fno)); CuAssertPtrEquals(tc, fm, get_monsters()); test_cleanup(); }
static void create_monsters(faction **player, faction **monsters, unit **u, unit **m) { race* rc; region *r; test_cleanup(); test_create_horse(); default_locale = test_create_locale(); *player = test_create_faction(NULL); *monsters = get_or_create_monsters(); assert(rc_find((*monsters)->race->_name)); rc = rc_get_or_create((*monsters)->race->_name); fset(rc, RCF_UNARMEDGUARD|RCF_NPC|RCF_DRAGON); fset(*monsters, FFL_NOIDLEOUT); assert(fval(*monsters, FFL_NPC) && fval((*monsters)->race, RCF_UNARMEDGUARD) && fval((*monsters)->race, RCF_NPC) && fval(*monsters, FFL_NOIDLEOUT)); test_create_region(-1, 0, test_create_terrain("ocean", SEA_REGION | SWIM_INTO | FLY_INTO)); test_create_region(1, 0, 0); r = test_create_region(0, 0, 0); *u = test_create_unit(*player, r); unit_setid(*u, 1); *m = test_create_unit(*monsters, r); }
static void create_monsters(faction **player, faction **monsters, region **r, unit **u, unit **m) { race* rc; test_cleanup(); init_language(); test_create_world(); *player = test_create_faction(NULL); *monsters = get_or_create_monsters(); assert(rc_find((*monsters)->race->_name)); rc = rc_get_or_create((*monsters)->race->_name); fset(rc, RCF_UNARMEDGUARD); fset(rc, RCF_NPC); fset(*monsters, FFL_NOIDLEOUT); assert(fval(*monsters, FFL_NPC) && fval((*monsters)->race, RCF_UNARMEDGUARD) && fval((*monsters)->race, RCF_NPC) && fval(*monsters, FFL_NOIDLEOUT)); (*monsters)->locale = default_locale; *r = findregion(0, 0); *u = test_create_unit(*player, *r); unit_setid(*u, 1); *m = test_create_unit(*monsters, *r); }
faction *get_monsters(void) { return get_or_create_monsters(); }