diff --git a/.gitignore b/.gitignore index 24219490f..4e63f5d9c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,40 +1,41 @@ -.vscode/ -*.orig -eressea.ini -Debug -Release - -# SlickEdit -*.vtg -*.vpwhistu - -# Microsoft Visual Studio build artefacts -src/Debug/ -src/Release/ -src/*.vcproj.*.user -Debug/ -Release/ -ipch/ -*.ipch -*.ncb -*.opensdf -*.pdb -*.sdf -*.suo -*.user - -*~ -*.bak -bin/ -build*/ -*.log -*.log.* -tags -Thumbs.db -.gdb_history -*.cfg -*.cmd -tmp/ -tests/config.lua -tests/reports/ -tests/data/185.dat +tolua/ +.vscode/ +*.orig +eressea.ini +Debug +Release + +# SlickEdit +*.vtg +*.vpwhistu + +# Microsoft Visual Studio build artefacts +src/Debug/ +src/Release/ +src/*.vcproj.*.user +Debug/ +Release/ +ipch/ +*.ipch +*.ncb +*.opensdf +*.pdb +*.sdf +*.suo +*.user + +*~ +*.bak +bin/ +build*/ +*.log +*.log.* +tags +Thumbs.db +.gdb_history +*.cfg +*.cmd +tmp/ +tests/config.lua +tests/reports/ +tests/data/185.dat diff --git a/.gitmodules b/.gitmodules index 2242a8068..7dff5ab6a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,18 +4,9 @@ [submodule "cmake"] path = cmake url = https://github.com/ennorehling/cmake.git -[submodule "quicklist"] - path = quicklist - url = https://github.com/ennorehling/quicklist.git -[submodule "critbit"] - path = critbit - url = https://github.com/ennorehling/critbit.git [submodule "dlmalloc"] path = dlmalloc url = https://github.com/ennorehling/dlmalloc.git -[submodule "cutest"] - path = cutest - url = https://github.com/ennorehling/cutest.git [submodule "iniparser"] path = iniparser url = https://github.com/ennorehling/iniparser.git @@ -26,3 +17,6 @@ path = storage url = https://github.com/ennorehling/storage.git branch = master +[submodule "clibs"] + path = clibs + url = https://github.com/ennorehling/clibs diff --git a/CMakeLists.txt b/CMakeLists.txt index 15629bf4c..405b86a03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,6 @@ endif(WIN32) project (eressea-server C) - enable_testing() find_package (LibXml2) find_package (SQLite3) @@ -14,12 +13,10 @@ find_package (Curses) find_package (Lua REQUIRED) find_package (ToLua REQUIRED) -add_subdirectory (cutest) add_subdirectory (cJSON) add_subdirectory (storage) add_subdirectory (iniparser) -add_subdirectory (quicklist) -add_subdirectory (critbit) +add_subdirectory (clibs) add_subdirectory (process) add_subdirectory (src eressea) install(DIRECTORY res conf DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.xml") diff --git a/clibs b/clibs new file mode 160000 index 000000000..f91ef37f0 --- /dev/null +++ b/clibs @@ -0,0 +1 @@ +Subproject commit f91ef37f08c5244bf616f1836c0aa9caaf36805c diff --git a/critbit b/critbit deleted file mode 160000 index 971836241..000000000 --- a/critbit +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 971836241277e37274aa3110344836499816ff21 diff --git a/cutest b/cutest deleted file mode 160000 index 6e268687d..000000000 --- a/cutest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6e268687dbf6ae55afb63210c3753530d216a622 diff --git a/quicklist b/quicklist deleted file mode 160000 index f837dd31e..000000000 --- a/quicklist +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f837dd31e5fcf13c706db1ac2c86b7de3e706578 diff --git a/s/build b/s/build index b59804626..01acc1ae2 100755 --- a/s/build +++ b/s/build @@ -33,8 +33,6 @@ if [ ! -d $ROOT/$BUILD ]; then exit fi -git submodule update - echo "build eressea" cd $ROOT/$BUILD VERSION=$(git describe --match 'v*.*.*' --tags | sed 's/^v//') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 81a43e002..39d290560 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,11 +2,9 @@ cmake_minimum_required(VERSION 2.8) project (server C) include_directories (${CMAKE_CURRENT_SOURCE_DIR}) -include_directories (${CRITBIT_INCLUDE_DIR}) include_directories (${CJSON_INCLUDE_DIR}) +include_directories (${CLIBS_INCLUDE_DIR}) include_directories (${STORAGE_INCLUDE_DIR}) -include_directories (${QUICKLIST_INCLUDE_DIR}) -include_directories (${CUTEST_INCLUDE_DIR}) include_directories (${LUA_INCLUDE_DIR}) include_directories (${TOLUA_INCLUDE_DIR}) include_directories (${BSON_INCLUDE_DIR}) @@ -180,9 +178,8 @@ target_link_libraries(eressea game ${TOLUA_LIBRARIES} ${LUA_LIBRARIES} - ${QUICKLIST_LIBRARIES} ${STORAGE_LIBRARIES} - ${CRITBIT_LIBRARIES} + ${CLIBS_LIBRARIES} ${CJSON_LIBRARIES} ${INIPARSER_LIBRARIES} ) @@ -236,11 +233,10 @@ set(TESTS_SRC add_executable(test_eressea ${TESTS_SRC}) target_link_libraries(test_eressea game - ${CUTEST_LIBRARIES} + cutest ${LUA_LIBRARIES} - ${QUICKLIST_LIBRARIES} + ${CLIBS_LIBRARIES} ${STORAGE_LIBRARIES} - ${CRITBIT_LIBRARIES} ${CJSON_LIBRARIES} ${INIPARSER_LIBRARIES} ) diff --git a/src/battle.c b/src/battle.c index d802c0785..4105cf73f 100644 --- a/src/battle.c +++ b/src/battle.c @@ -64,7 +64,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include @@ -1244,7 +1244,7 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) rda = 0; else { int qi; - quicklist *ql; + selist *ql; unsigned int i = 0; if (u_race(du)->battle_flags & BF_RES_PIERCE) @@ -1258,8 +1258,8 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) rda /= 2; /* Schilde */ - for (qi = 0, ql = b->meffects; ql; ql_advance(&ql, &qi, 1)) { - meffect *me = (meffect *)ql_get(ql, qi); + for (qi = 0, ql = b->meffects; ql; selist_advance(&ql, &qi, 1)) { + meffect *me = (meffect *)selist_get(ql, qi); if (meffect_protection(b, me, ds) != 0) { assert(0 <= rda); /* rda sollte hier immer mindestens 0 sein */ /* jeder Schaden wird um effect% reduziert bis der Schild duration @@ -1591,11 +1591,11 @@ static troop select_opponent(battle * b, troop at, int mindist, int maxdist) return dt; } -quicklist *fighters(battle * b, const side * vs, int minrow, int maxrow, +selist *fighters(battle * b, const side * vs, int minrow, int maxrow, int mask) { side *s; - quicklist *fightervp = 0; + selist *fightervp = 0; assert(vs != NULL); @@ -1617,7 +1617,7 @@ quicklist *fighters(battle * b, const side * vs, int minrow, int maxrow, for (fig = s->fighters; fig; fig = fig->next) { int row = get_unitrow(fig, vs); if (row >= minrow && row <= maxrow) { - ql_push(&fightervp, fig); + selist_push(&fightervp, fig); } } } @@ -1789,7 +1789,7 @@ static void do_combatspell(troop at) unit *caster = fi->unit; battle *b = fi->side->battle; region *r = b->region; - quicklist *ql; + selist *ql; int level, qi; double power; int fumblechance = 0; @@ -1818,8 +1818,8 @@ static void do_combatspell(troop at) return; } - for (qi = 0, ql = b->meffects; ql; ql_advance(&ql, &qi, 1)) { - meffect *mblock = (meffect *)ql_get(ql, qi); + for (qi = 0, ql = b->meffects; ql; selist_advance(&ql, &qi, 1)) { + meffect *mblock = (meffect *)selist_get(ql, qi); if (mblock->typ == SHIELD_BLOCK) { if (meffect_blocked(b, mblock, fi->side) != 0) { fumblechance += mblock->duration; @@ -2306,11 +2306,11 @@ static void add_tactics(tactics * ta, fighter * fig, int value) if (value == 0 || value < ta->value) return; if (value > ta->value) { - ql_free(ta->fighters); + selist_free(ta->fighters); ta->fighters = 0; } - ql_push(&ta->fighters, fig); - ql_push(&fig->side->battle->leaders, fig); + selist_push(&ta->fighters, fig); + selist_push(&fig->side->battle->leaders, fig); ta->value = value; } @@ -3035,7 +3035,7 @@ static void print_stats(battle * b) b->max_tactics = 0; for (s = b->sides; s != b->sides + b->nsides; ++s) { - if (!ql_empty(s->leader.fighters)) { + if (!selist_empty(s->leader.fighters)) { b->max_tactics = MAX(b->max_tactics, s->leader.value); } } @@ -3043,11 +3043,11 @@ static void print_stats(battle * b) if (b->max_tactics > 0) { for (s = b->sides; s != b->sides + b->nsides; ++s) { if (s->leader.value == b->max_tactics) { - quicklist *ql; + selist *ql; int qi; - for (qi = 0, ql = s->leader.fighters; ql; ql_advance(&ql, &qi, 1)) { - fighter *tf = (fighter *)ql_get(ql, qi); + for (qi = 0, ql = s->leader.fighters; ql; selist_advance(&ql, &qi, 1)) { + fighter *tf = (fighter *)selist_get(ql, qi); unit *u = tf->unit; message *m = NULL; if (!is_attacker(tf)) { @@ -3498,7 +3498,7 @@ battle *make_battle(region * r) static void free_side(side * si) { - ql_free(si->leader.fighters); + selist_free(si->leader.fighters); } static void free_fighter(fighter * fig) @@ -3542,9 +3542,9 @@ void free_battle(battle * b) free(bf); } - ql_free(b->leaders); - ql_foreach(b->meffects, free); - ql_free(b->meffects); + selist_free(b->leaders); + selist_foreach(b->meffects, free); + selist_free(b->meffects); battle_free(b); } @@ -4108,7 +4108,7 @@ void do_battle(region * r) freset(sh, SF_DAMAGED); /* Gibt es eine Taktikrunde ? */ - if (!ql_empty(b->leaders)) { + if (!selist_empty(b->leaders)) { b->turn = 0; b->has_tactics_turn = true; } diff --git a/src/battle.h b/src/battle.h index 4d29f1a7f..1b4cf2588 100644 --- a/src/battle.h +++ b/src/battle.h @@ -26,6 +26,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif + struct message; + struct selist; + /** more defines **/ #define FS_ENEMY 1 #define FS_HELP 2 @@ -44,7 +47,6 @@ extern "C" { #define LAST_ROW FLEE_ROW #define MAXSIDES 192 /* if there are ever more than this, we're fucked. */ - struct message; typedef struct bfaction { struct bfaction *next; @@ -54,7 +56,7 @@ extern "C" { } bfaction; typedef struct tactics { - struct quicklist *fighters; + struct selist *fighters; int value; } tactics; @@ -87,7 +89,7 @@ extern "C" { } side; typedef struct battle { - struct quicklist *leaders; + struct selist *leaders; struct region *region; struct plane *plane; bfaction *factions; @@ -95,7 +97,7 @@ extern "C" { int nfighters; side sides[MAXSIDES]; int nsides; - struct quicklist *meffects; + struct selist *meffects; int max_tactics; int turn; bool has_tactics_turn; @@ -253,7 +255,7 @@ extern "C" { extern int hits(troop at, troop dt, weapon * awp); extern void damage_building(struct battle *b, struct building *bldg, int damage_abs); - struct quicklist *fighters(struct battle *b, const struct side *vs, + struct selist *fighters(struct battle *b, const struct side *vs, int minrow, int maxrow, int mask); int count_allies(const struct side *as, int minrow, int maxrow, int select, int allytype); diff --git a/src/bind_faction.c b/src/bind_faction.c index 2ace2ae52..f5c393de6 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -32,8 +32,6 @@ without prior permission by the authors of Eressea. #include #include -#include - #include #include #include diff --git a/src/bind_monsters.c b/src/bind_monsters.c index fd1130053..4ac15aa24 100644 --- a/src/bind_monsters.c +++ b/src/bind_monsters.c @@ -11,8 +11,6 @@ #include -#include - #include #include diff --git a/src/bind_unit.c b/src/bind_unit.c index 42fafae39..1983e0f62 100755 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -46,7 +46,7 @@ without prior permission by the authors of Eressea. #include #include #include -#include +#include #include @@ -753,12 +753,12 @@ static int tolua_unit_get_spells(lua_State * L) unit *self = (unit *) tolua_tousertype(L, 1, 0); sc_mage *mage = self ? get_mage(self) : 0; spellbook *sb = mage ? mage->spellbook : 0; - quicklist *slist = 0; + selist *slist = 0; if (sb) { - quicklist **slist_ptr = &sb->spells; + selist **slist_ptr = &sb->spells; slist = *slist_ptr; } - return tolua_quicklist_push(L, "spellbook", "spell_entry", slist); + return tolua_selist_push(L, "spellbook", "spell_entry", slist); } static int tolua_unit_get_orders(lua_State * L) diff --git a/src/bindings.c b/src/bindings.c index 80021f01e..7bf30202a 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -66,7 +66,7 @@ without prior permission by the authors of Eressea. #include #include #include -#include +#include #include #include #include @@ -115,16 +115,16 @@ int tolua_orderlist_next(lua_State * L) return 0; } -static int tolua_quicklist_iter(lua_State * L) +static int tolua_selist_iter(lua_State * L) { - quicklist **qlp = (quicklist **)lua_touserdata(L, lua_upvalueindex(1)); - quicklist *ql = *qlp; + selist **qlp = (selist **)lua_touserdata(L, lua_upvalueindex(1)); + selist *ql = *qlp; if (ql != NULL) { int index = (int)lua_tointeger(L, lua_upvalueindex(2)); const char *type = lua_tostring(L, lua_upvalueindex(3)); - void *data = ql_get(ql, index); + void *data = selist_get(ql, index); tolua_pushusertype(L, data, TOLUA_CAST type); - ql_advance(qlp, &index, 1); + selist_advance(qlp, &index, 1); lua_pushinteger(L, index); lua_replace(L, lua_upvalueindex(2)); return 1; @@ -132,18 +132,18 @@ static int tolua_quicklist_iter(lua_State * L) return 0; } -int tolua_quicklist_push(struct lua_State *L, const char *list_type, - const char *elem_type, struct quicklist *list) +int tolua_selist_push(struct lua_State *L, const char *list_type, + const char *elem_type, struct selist *list) { if (list) { - quicklist **qlist_ptr = - (quicklist **)lua_newuserdata(L, sizeof(quicklist *)); + selist **qlist_ptr = + (selist **)lua_newuserdata(L, sizeof(selist *)); *qlist_ptr = list; luaL_getmetatable(L, list_type); lua_setmetatable(L, -2); lua_pushinteger(L, 0); lua_pushstring(L, elem_type); - lua_pushcclosure(L, tolua_quicklist_iter, 3); /* OBS: this closure has multiple upvalues (list, index, type_name) */ + lua_pushcclosure(L, tolua_selist_iter, 3); /* OBS: this closure has multiple upvalues (list, index, type_name) */ } else { lua_pushnil(L); @@ -655,7 +655,7 @@ static int tolua_get_factions(lua_State * L) static int tolua_get_alliance_factions(lua_State * L) { alliance *self = (alliance *)tolua_tousertype(L, 1, 0); - return tolua_quicklist_push(L, "faction_list", "faction", self->members); + return tolua_selist_push(L, "faction_list", "faction", self->members); } static int tolua_get_alliance_id(lua_State * L) @@ -681,11 +681,11 @@ static int tolua_set_alliance_name(lua_State * L) static int config_get_ships(lua_State * L) { - quicklist *ql; + selist *ql; int qi, i = 0; - lua_createtable(L, ql_length(shiptypes), 0); - for (qi = 0, ql = shiptypes; ql; ql_advance(&ql, &qi, 1)) { - ship_type *stype = (ship_type *)ql_get(ql, qi); + lua_createtable(L, selist_length(shiptypes), 0); + for (qi = 0, ql = shiptypes; ql; selist_advance(&ql, &qi, 1)) { + ship_type *stype = (ship_type *)selist_get(ql, qi); tolua_pushstring(L, TOLUA_CAST stype->_name); lua_rawseti(L, -2, ++i); } @@ -694,11 +694,11 @@ static int config_get_ships(lua_State * L) static int config_get_buildings(lua_State * L) { - quicklist *ql; + selist *ql; int qi, i = 0; - lua_createtable(L, ql_length(buildingtypes), 0); - for (qi = 0, ql = buildingtypes; ql; ql_advance(&ql, &qi, 1)) { - building_type *btype = (building_type *)ql_get(ql, qi); + lua_createtable(L, selist_length(buildingtypes), 0); + for (qi = 0, ql = buildingtypes; ql; selist_advance(&ql, &qi, 1)) { + building_type *btype = (building_type *)selist_get(ql, qi); tolua_pushstring(L, TOLUA_CAST btype->_name); lua_rawseti(L, -2, ++i); } @@ -920,7 +920,7 @@ static int tolua_get_spell_entry_level(lua_State * L) static int tolua_get_spells(lua_State * L) { - return tolua_quicklist_push(L, "spell_list", "spell", spells); + return tolua_selist_push(L, "spell_list", "spell", spells); } static int init_data(const char *filename, const char *catalog) diff --git a/src/bindings.h b/src/bindings.h index 2db83248d..354bb199a 100755 --- a/src/bindings.h +++ b/src/bindings.h @@ -15,15 +15,15 @@ extern "C" { #endif struct lua_State; - struct quicklist; struct _dictionary_; + struct selist; int tolua_sqlite_open(struct lua_State *L); int tolua_bindings_open(struct lua_State *L, const struct _dictionary_ *d); int tolua_itemlist_next(struct lua_State *L); int tolua_orderlist_next(struct lua_State *L); - int tolua_quicklist_push(struct lua_State *L, const char *list_type, - const char *elem_type, struct quicklist *list); + int tolua_selist_push(struct lua_State *L, const char *list_type, + const char *elem_type, struct selist *list); int log_lua_error(struct lua_State *L); diff --git a/src/creport.c b/src/creport.c index e8e401190..106f34545 100644 --- a/src/creport.c +++ b/src/creport.c @@ -68,7 +68,7 @@ without prior permission by the authors of Eressea. #include #include #include -#include +#include #include #include @@ -712,11 +712,11 @@ static void cr_output_spells(stream *out, const unit * u, int maxlevel) if (book) { const faction * f = u->faction; - quicklist *ql; + selist *ql; int qi, header = 0; - for (ql = book->spells, qi = 0; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry * sbe = (spellbook_entry *)ql_get(ql, qi); + for (ql = book->spells, qi = 0; ql; selist_advance(&ql, &qi, 1)) { + spellbook_entry * sbe = (spellbook_entry *)selist_get(ql, qi); if (sbe->level <= maxlevel) { spell * sp = sbe->sp; const char *name = translate(mkname("spell", sp->sname), spell_name(sp, f->locale)); @@ -1027,12 +1027,12 @@ static void show_alliances_cr(FILE * F, const faction * f) /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ /* this is a copy of laws.c->find_address output changed. */ -static void cr_find_address(FILE * F, const faction * uf, quicklist * addresses) +static void cr_find_address(FILE * F, const faction * uf, selist * addresses) { int i = 0; - quicklist *flist = addresses; + selist *flist = addresses; while (flist) { - const faction *f = (const faction *)ql_get(flist, i); + const faction *f = (const faction *)selist_get(flist, i); if (uf != f) { fprintf(F, "PARTEI %d\n", f->no); fprintf(F, "\"%s\";Parteiname\n", f->name); @@ -1045,7 +1045,7 @@ static void cr_find_address(FILE * F, const faction * uf, quicklist * addresses) fprintf(F, "%d;alliance\n", f->alliance->id); } } - ql_advance(&flist, &i, 1); + selist_advance(&flist, &i, 1); } } diff --git a/src/creport.test.c b/src/creport.test.c index 72669e99f..21a6c09b7 100644 --- a/src/creport.test.c +++ b/src/creport.test.c @@ -18,7 +18,6 @@ #include #include -#include #include #include diff --git a/src/donations.c b/src/donations.c index 7d2f15816..b923df73b 100644 --- a/src/donations.c +++ b/src/donations.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include @@ -16,7 +16,7 @@ typedef struct transfer { int amount; } transfer; -static quicklist *transfers = 0; +static selist *transfers = 0; int cmp_transfer(const void *v1, const void *v2) { const transfer *t1 = (const transfer *)v1; @@ -36,46 +36,42 @@ int cmp_transfer(const void *v1, const void *v2) { void add_donation(faction * f1, faction * f2, int amount, region * r) { transfer tr, *tf; - quicklist *ql = transfers; + selist *ql = transfers; int qi = 0; tr.r = r; tr.f1 = f1; tr.f2 = f2; tr.amount = amount; - if (ql_set_find_ex(&ql, &qi, &tr, cmp_transfer)) { - tf = (transfer *)ql_get(ql, qi); + if (selist_set_find(&ql, &qi, &tr, cmp_transfer)) { + tf = (transfer *)selist_get(ql, qi); tf->amount += amount; } else { tf = malloc(sizeof(transfer)); memcpy(tf, &tr, sizeof(transfer)); } - ql_set_insert_ex(&transfers, tf, cmp_transfer); + selist_set_insert(&transfers, tf, cmp_transfer); } void free_donations(void) { - ql_foreach(transfers, free); - ql_free(transfers); + selist_foreach(transfers, free); + selist_free(transfers); transfers = 0; } -static void report_transfer(faction *f1, faction *f2, region *r, int amount) { - struct message *msg = msg_message("donation", - "from to amount", f1, f2, amount); - r_addmessage(r, f1, msg); - r_addmessage(r, f2, msg); - msg_release(msg); +static void report_transfer(void *data) { + transfer *tf = (transfer *)data; + if (tf->amount > 0) { + struct message *msg = msg_message("donation", + "from to amount", tf->f1, tf->f2, tf->amount); + r_addmessage(tf->r, tf->f1, msg); + r_addmessage(tf->r, tf->f2, msg); + msg_release(msg); + } } void report_donations(void) { - ql_iter qli = qli_init(&transfers); - - while (qli_more(qli)) { - transfer *tf = (transfer *)qli_next(&qli); - if (tf->amount > 0) { - report_transfer(tf->f1, tf->f2, tf->r, tf->amount); - } - } + selist_foreach(transfers, report_transfer); } diff --git a/src/kernel/alliance.c b/src/kernel/alliance.c index b53c46dc7..0feb8407d 100644 --- a/src/kernel/alliance.c +++ b/src/kernel/alliance.c @@ -31,10 +31,11 @@ without prior permission by the authors of Eressea. #include #include #include -#include #include #include +#include + /* libc includes */ #include #include @@ -49,7 +50,7 @@ void free_alliances(void) alliances = al->next; free(al->name); if (al->members) { - ql_free(al->members); + selist_free(al->members); } free(al); } @@ -115,7 +116,7 @@ faction *alliance_get_leader(alliance * al) { if (!al->_leader) { if (al->members) { - al->_leader = (faction *)ql_get(al->members, 0); + al->_leader = (faction *)selist_get(al->members, 0); } } return al->_leader; @@ -356,19 +357,19 @@ void setalliance(faction * f, alliance * al) return; if (f->alliance != NULL) { int qi; - quicklist **flistp = &f->alliance->members; + selist **flistp = &f->alliance->members; - for (qi = 0; *flistp; ql_advance(flistp, &qi, 1)) { - faction *data = (faction *)ql_get(*flistp, qi); + for (qi = 0; *flistp; selist_advance(flistp, &qi, 1)) { + faction *data = (faction *)selist_get(*flistp, qi); if (data == f) { - ql_delete(flistp, qi); + selist_delete(flistp, qi); break; } } if (f->alliance->_leader == f) { if (f->alliance->members) { - f->alliance->_leader = (faction *)ql_get(f->alliance->members, 0); + f->alliance->_leader = (faction *)selist_get(f->alliance->members, 0); } else { f->alliance->_leader = NULL; @@ -378,7 +379,7 @@ void setalliance(faction * f, alliance * al) f->alliance = al; f->alliance_joindate = turn; if (al != NULL) { - ql_push(&al->members, f); + selist_push(&al->members, f); if (al->_leader == NULL) { al->_leader = f; } diff --git a/src/kernel/alliance.h b/src/kernel/alliance.h index 4be05b871..8e112e8c9 100644 --- a/src/kernel/alliance.h +++ b/src/kernel/alliance.h @@ -30,6 +30,7 @@ extern "C" { struct unit; struct faction; struct region; + struct selist; enum { ALLIANCE_KICK, @@ -49,7 +50,7 @@ extern "C" { typedef struct alliance { struct alliance *next; struct faction *_leader; - struct quicklist *members; + struct selist *members; int flags; int id; char *name; diff --git a/src/kernel/alliance.test.c b/src/kernel/alliance.test.c index 72a31a42c..c0ec03fbc 100644 --- a/src/kernel/alliance.test.c +++ b/src/kernel/alliance.test.c @@ -7,7 +7,7 @@ #include "alliance.h" #include #include -#include +#include #include @@ -76,10 +76,10 @@ static void test_alliance_dead_faction(CuTest *tc) { setalliance(f, al); setalliance(f2, al); CuAssertPtrEquals(tc, f, alliance_get_leader(al)); - CuAssertIntEquals(tc, 2, ql_length(al->members)); + CuAssertIntEquals(tc, 2, selist_length(al->members)); CuAssertPtrEquals(tc, al, f->alliance); destroyfaction(&factions); - CuAssertIntEquals(tc, 1, ql_length(al->members)); + CuAssertIntEquals(tc, 1, selist_length(al->members)); CuAssertPtrEquals(tc, f2, alliance_get_leader(al)); CuAssertPtrEquals(tc, NULL, f->alliance); CuAssertTrue(tc, !f->_alive); diff --git a/src/kernel/building.c b/src/kernel/building.c index 9f6a8a421..98caad07a 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -41,7 +41,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include @@ -62,18 +62,18 @@ typedef struct building_typelist { building_type *type; } building_typelist; -quicklist *buildingtypes = NULL; +selist *buildingtypes = NULL; /* Returns a building type for the (internal) name */ static building_type *bt_find_i(const char *name) { - quicklist *ql; + selist *ql; int qi; assert(name); - for (qi = 0, ql = buildingtypes; ql; ql_advance(&ql, &qi, 1)) { - building_type *btype = (building_type *)ql_get(ql, qi); + for (qi = 0, ql = buildingtypes; ql; selist_advance(&ql, &qi, 1)) { + building_type *btype = (building_type *)selist_get(ql, qi); if (strcmp(btype->_name, name) == 0) return btype; } @@ -102,7 +102,7 @@ void bt_register(building_type * type) if (type->init) { type->init(type); } - ql_push(&buildingtypes, (void *)type); + selist_push(&buildingtypes, (void *)type); ++bt_changes; } @@ -115,8 +115,8 @@ static void free_buildingtype(void *ptr) { } void free_buildingtypes(void) { - ql_foreach(buildingtypes, free_buildingtype); - ql_free(buildingtypes); + selist_foreach(buildingtypes, free_buildingtype); + selist_free(buildingtypes); buildingtypes = 0; ++bt_changes; } @@ -314,15 +314,15 @@ const building_type *findbuildingtype(const char *name, bn = bn->next; } if (!bn) { - quicklist *ql = buildingtypes; + selist *ql = buildingtypes; int qi; bn = (local_names *)calloc(sizeof(local_names), 1); bn->next = bnames; bn->lang = lang; - for (qi = 0, ql = buildingtypes; ql; ql_advance(&ql, &qi, 1)) { - building_type *btype = (building_type *)ql_get(ql, qi); + for (qi = 0, ql = buildingtypes; ql; selist_advance(&ql, &qi, 1)) { + building_type *btype = (building_type *)selist_get(ql, qi); const char *n = LOC(lang, btype->_name); type.v = (void *)btype; diff --git a/src/kernel/building.h b/src/kernel/building.h index 673675348..8b1a5b05b 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -82,7 +82,7 @@ extern "C" { struct attrib *attribs; } building_type; - extern struct quicklist *buildingtypes; + extern struct selist *buildingtypes; extern struct attrib_type at_building_action; int cmp_castle_size(const struct building * b, const struct building * a); diff --git a/src/kernel/config.c b/src/kernel/config.c index efe66b2f1..83d0808da 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -63,7 +63,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/kernel/connection.c b/src/kernel/connection.c index 405b013ee..5b2615bcc 100644 --- a/src/kernel/connection.c +++ b/src/kernel/connection.c @@ -29,7 +29,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include @@ -345,7 +345,7 @@ attrib_type at_countdown = { void age_borders(void) { - quicklist *deleted = NULL, *ql; + selist *deleted = NULL, *ql; int i; for (i = 0; i != BORDER_MAXHASH; ++i) { @@ -355,17 +355,17 @@ void age_borders(void) for (; b; b = b->next) { if (b->type->age) { if (b->type->age(b) == AT_AGE_REMOVE) { - ql_push(&deleted, b); + selist_push(&deleted, b); } } } } } - for (ql = deleted, i = 0; ql; ql_advance(&ql, &i, 1)) { - connection *b = (connection *)ql_get(ql, i); + for (ql = deleted, i = 0; ql; selist_advance(&ql, &i, 1)) { + connection *b = (connection *)selist_get(ql, i); erase_border(b); } - ql_free(deleted); + selist_free(deleted); } /******** diff --git a/src/kernel/curse.c b/src/kernel/curse.c index 22b87e738..7df567940 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -287,10 +287,10 @@ attrib_type at_curse = { /* Spruch identifizieren */ #include -#include +#include #define MAXCTHASH 128 -static quicklist *cursetypes[MAXCTHASH]; +static selist *cursetypes[MAXCTHASH]; static int ct_changes = 1; bool ct_changed(int *cache) @@ -306,25 +306,25 @@ bool ct_changed(int *cache) void ct_register(const curse_type * ct) { unsigned int hash = tolower(ct->cname[0]) & 0xFF; - quicklist **ctlp = cursetypes + hash; + selist **ctlp = cursetypes + hash; - ql_set_insert(ctlp, (void *)ct); + selist_set_insert(ctlp, (void *)ct, NULL); ++ct_changes; } void ct_remove(const char *c) { unsigned int hash = tolower(c[0]); - quicklist *ctl = cursetypes[hash]; + selist *ctl = cursetypes[hash]; if (ctl) { int qi; - for (qi = 0; ctl; ql_advance(&ctl, &qi, 1)) { - curse_type *type = (curse_type *)ql_get(ctl, qi); + for (qi = 0; ctl; selist_advance(&ctl, &qi, 1)) { + curse_type *type = (curse_type *)selist_get(ctl, qi); if (strcmp(c, type->cname) == 0) { - ql_delete(&ctl, qi); + selist_delete(&ctl, qi); ++ct_changes; break; } @@ -335,14 +335,14 @@ void ct_remove(const char *c) const curse_type *ct_find(const char *c) { unsigned int hash = tolower(c[0]); - quicklist *ctl = cursetypes[hash]; + selist *ctl = cursetypes[hash]; if (ctl) { size_t c_len = strlen(c); int qi; - for (qi = 0; ctl; ql_advance(&ctl, &qi, 1)) { - curse_type *type = (curse_type *)ql_get(ctl, qi); + for (qi = 0; ctl; selist_advance(&ctl, &qi, 1)) { + curse_type *type = (curse_type *)selist_get(ctl, qi); if (strcmp(c, type->cname) == 0) { return type; @@ -360,12 +360,12 @@ const curse_type *ct_find(const char *c) void ct_checknames(void) { int i, qi; - quicklist *ctl; + selist *ctl; for (i = 0; i < MAXCTHASH; ++i) { ctl = cursetypes[i]; - for (qi = 0; ctl; ql_advance(&ctl, &qi, 1)) { - curse_type *type = (curse_type *)ql_get(ctl, qi); + for (qi = 0; ctl; selist_advance(&ctl, &qi, 1)) { + curse_type *type = (curse_type *)selist_get(ctl, qi); curse_name(type, default_locale); } @@ -847,7 +847,7 @@ double destr_curse(curse * c, int cast_level, double force) void curses_done(void) { int i; for (i = 0; i != MAXCTHASH; ++i) { - ql_free(cursetypes[i]); + selist_free(cursetypes[i]); cursetypes[i] = 0; } ++ct_changes; diff --git a/src/kernel/equipment.c b/src/kernel/equipment.c index 7874a2c32..00f8c2f95 100644 --- a/src/kernel/equipment.c +++ b/src/kernel/equipment.c @@ -28,7 +28,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "spell.h" /* util includes */ -#include +#include #include #include @@ -99,7 +99,7 @@ void equipment_addspell(equipment * eq, const char * name, int level) ls->sp = NULL; ls->level = level; ls->name = strdup(name); - ql_push(&eq->spells, ls); + selist_push(&eq->spells, ls); } } @@ -156,12 +156,12 @@ void equip_unit_mask(struct unit *u, const struct equipment *eq, int mask) if (mask & EQUIP_SPELLS) { if (eq->spells) { - quicklist * ql = eq->spells; + selist * ql = eq->spells; int qi; sc_mage * mage = get_mage(u); - for (qi = 0; ql; ql_advance(&ql, &qi, 1)) { - lazy_spell *sbe = (lazy_spell *)ql_get(ql, qi); + for (qi = 0; ql; selist_advance(&ql, &qi, 1)) { + lazy_spell *sbe = (lazy_spell *)selist_get(ql, qi); if (!sbe->sp) { sbe->sp = find_spell(sbe->name); free(sbe->name); @@ -250,8 +250,8 @@ void equipment_done(void) { *eqp = eq->next; free(eq->name); if (eq->spells) { - ql_foreach(eq->spells, free_ls); - ql_free(eq->spells); + selist_foreach(eq->spells, free_ls); + selist_free(eq->spells); } while (eq->items) { itemdata *next = eq->items->next; diff --git a/src/kernel/equipment.h b/src/kernel/equipment.h index 84fe55722..53475b510 100644 --- a/src/kernel/equipment.h +++ b/src/kernel/equipment.h @@ -48,7 +48,7 @@ extern "C" { char *name; struct itemdata *items; char *skills[MAXSKILLS]; - struct quicklist *spells; + struct selist *spells; struct subset *subsets; struct equipment *next; void(*callback) (const struct equipment *, struct unit *); diff --git a/src/kernel/equipment.test.c b/src/kernel/equipment.test.c index ad69bec10..afd53849e 100644 --- a/src/kernel/equipment.test.c +++ b/src/kernel/equipment.test.c @@ -7,8 +7,6 @@ #include #include -#include - #include #include diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 6b601f002..b7115c62f 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -51,7 +51,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include -#include +#include #include /* libc includes */ @@ -102,7 +102,7 @@ static void free_faction(faction * f) free(f->_password); free(f->name); if (f->seen_factions) { - ql_free(f->seen_factions); + selist_free(f->seen_factions); f->seen_factions = 0; } @@ -366,7 +366,7 @@ void destroyfaction(faction ** fp) } if (f->seen_factions) { - ql_free(f->seen_factions); + selist_free(f->seen_factions); f->seen_factions = 0; } @@ -593,11 +593,11 @@ static int allied_skillcount(const faction * f, skill_t sk) { int num = 0; alliance *a = f_get_alliance(f); - quicklist *members = a->members; + selist *members = a->members; int qi; - for (qi = 0; members; ql_advance(&members, &qi, 1)) { - faction *m = (faction *)ql_get(members, qi); + for (qi = 0; members; selist_advance(&members, &qi, 1)) { + faction *m = (faction *)selist_get(members, qi); num += count_skill(m, sk); } return num; diff --git a/src/kernel/faction.h b/src/kernel/faction.h index b4768e982..1bab9101c 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -33,6 +33,7 @@ extern "C" { struct seen_region; struct attrib_type; struct gamedata; + struct selist; extern struct attrib_type at_maxmagicians; @@ -98,7 +99,7 @@ extern "C" { struct message_list *msgs; } *battles; struct item *items; /* items this faction can claim */ - struct quicklist *seen_factions; + struct selist *seen_factions; bool _alive; /* enno: sollte ein flag werden */ } faction; diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index 441ca5038..b18121e2d 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -13,7 +13,7 @@ #include "monsters.h" #include #include -#include +#include #include #include @@ -47,10 +47,10 @@ static void test_remove_empty_factions_alliance(CuTest *tc) { al = makealliance(0, "Hodor"); setalliance(f, al); CuAssertPtrEquals(tc, f, alliance_get_leader(al)); - CuAssertIntEquals(tc, 1, ql_length(al->members)); + CuAssertIntEquals(tc, 1, selist_length(al->members)); remove_empty_factions(); CuAssertPtrEquals(tc, 0, al->_leader); - CuAssertIntEquals(tc, 0, ql_length(al->members)); + CuAssertIntEquals(tc, 0, selist_length(al->members)); test_cleanup(); } diff --git a/src/kernel/pathfinder.c b/src/kernel/pathfinder.c index 8ae9bf128..ba45f926c 100644 --- a/src/kernel/pathfinder.c +++ b/src/kernel/pathfinder.c @@ -18,7 +18,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include +#include #include "pathfinder.h" #include "region.h" @@ -102,10 +102,10 @@ static void free_nodes(node * root) } } -struct quicklist *regions_in_range(struct region *start, int maxdist, +struct selist *regions_in_range(struct region *start, int maxdist, bool(*allowed) (const struct region *, const struct region *)) { - quicklist * rlist = NULL; + selist * rlist = NULL; node *root = new_node(start, 0, NULL); node **end = &root->next; node *n = root; @@ -127,7 +127,7 @@ struct quicklist *regions_in_range(struct region *start, int maxdist, continue; /* can't go there */ /* add the region to the list of available ones. */ - ql_push(&rlist, rn); + selist_push(&rlist, rn); /* make sure we don't go here again, and put the region into the set for further BFS'ing */ diff --git a/src/kernel/pathfinder.h b/src/kernel/pathfinder.h index 81692e835..682fa4d25 100644 --- a/src/kernel/pathfinder.h +++ b/src/kernel/pathfinder.h @@ -34,7 +34,7 @@ extern "C" { const struct region *target); extern bool allowed_walk(const struct region *src, const struct region *target); - extern struct quicklist *regions_in_range(struct region *src, int maxdist, + extern struct selist *regions_in_range(struct region *src, int maxdist, bool(*allowed) (const struct region *, const struct region *)); extern void pathfinder_cleanup(void); diff --git a/src/kernel/save.c b/src/kernel/save.c index 66c680476..ac236d5bf 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -71,7 +71,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include +#include #include #include #include @@ -1265,7 +1265,7 @@ faction *read_faction(struct gamedata * data) assert(!al->members || !"non-allied dummy-alliance has more than one member"); } - ql_push(&al->members, f); + selist_push(&al->members, f); } else if (rule_region_owners()) { /* compat fix for non-allied factions */ diff --git a/src/kernel/ship.c b/src/kernel/ship.c index 817d54970..b9ac0b170 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -38,7 +38,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include @@ -51,7 +51,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -quicklist *shiptypes = NULL; +selist *shiptypes = NULL; static local_names *snames; @@ -66,15 +66,15 @@ const ship_type *findshiptype(const char *name, const struct locale *lang) sn = sn->next; } if (!sn) { - quicklist *ql; + selist *ql; int qi; sn = (local_names *)calloc(sizeof(local_names), 1); sn->next = snames; sn->lang = lang; - for (qi = 0, ql = shiptypes; ql; ql_advance(&ql, &qi, 1)) { - ship_type *stype = (ship_type *)ql_get(ql, qi); + for (qi = 0, ql = shiptypes; ql; selist_advance(&ql, &qi, 1)) { + ship_type *stype = (ship_type *)selist_get(ql, qi); variant var2; const char *n = LOC(lang, stype->_name); var2.v = (void *)stype; @@ -89,11 +89,11 @@ const ship_type *findshiptype(const char *name, const struct locale *lang) static ship_type *st_find_i(const char *name) { - quicklist *ql; + selist *ql; int qi; - for (qi = 0, ql = shiptypes; ql; ql_advance(&ql, &qi, 1)) { - ship_type *stype = (ship_type *)ql_get(ql, qi); + for (qi = 0, ql = shiptypes; ql; selist_advance(&ql, &qi, 1)) { + ship_type *stype = (ship_type *)selist_get(ql, qi); if (strcmp(stype->_name, name) == 0) { return stype; } @@ -111,7 +111,7 @@ ship_type *st_get_or_create(const char * name) { st = (ship_type *)calloc(sizeof(ship_type), 1); st->_name = strdup(name); st->storm = 1.0; - ql_push(&shiptypes, (void *)st); + selist_push(&shiptypes, (void *)st); } return st; } @@ -250,8 +250,8 @@ static void free_shiptype(void *ptr) { } void free_shiptypes(void) { - ql_foreach(shiptypes, free_shiptype); - ql_free(shiptypes); + selist_foreach(shiptypes, free_shiptype); + selist_free(shiptypes); shiptypes = 0; } diff --git a/src/kernel/ship.h b/src/kernel/ship.h index 964ee2124..285c29cc0 100644 --- a/src/kernel/ship.h +++ b/src/kernel/ship.h @@ -63,7 +63,7 @@ extern "C" { struct construction *construction; /* how to build a ship */ } ship_type; - extern struct quicklist *shiptypes; + extern struct selist *shiptypes; /* Alte Schiffstypen: */ diff --git a/src/kernel/spell.c b/src/kernel/spell.c index 3201a6677..5415c4a0e 100644 --- a/src/kernel/spell.c +++ b/src/kernel/spell.c @@ -26,7 +26,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include /* libc includes */ #include @@ -34,7 +34,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include static critbit_tree cb_spells; -quicklist * spells; +selist * spells; static void free_spell(spell *sp) { free(sp->syntax); @@ -50,14 +50,14 @@ static void free_spell_cb(void *cbdata) { void free_spells(void) { cb_clear(&cb_spells); - ql_foreach(spells, free_spell_cb); - ql_free(spells); + selist_foreach(spells, free_spell_cb); + selist_free(spells); spells = 0; } -void add_spell(struct quicklist **slistp, spell * sp) +void add_spell(struct selist **slistp, spell * sp) { - if (!ql_set_insert(slistp, sp)) { + if (!selist_set_insert(slistp, sp, NULL)) { log_error("add_spell: the list already contains the spell '%s'.\n", sp->sname); } } @@ -123,19 +123,19 @@ spell *find_spell(const char *name) spell *find_spellbyid(unsigned int id) { - quicklist *ql; + selist *ql; int qi; if (id == 0) return NULL; - for (qi = 0, ql = spells; ql; ql_advance(&ql, &qi, 1)) { - spell *sp = (spell *)ql_get(ql, qi); + for (qi = 0, ql = spells; ql; selist_advance(&ql, &qi, 1)) { + spell *sp = (spell *)selist_get(ql, qi); if (sp->id == id) { return sp; } } - for (qi = 0, ql = spells; ql; ql_advance(&ql, &qi, 1)) { - spell *sp = (spell *)ql_get(ql, qi); + for (qi = 0, ql = spells; ql; selist_advance(&ql, &qi, 1)) { + spell *sp = (spell *)selist_get(ql, qi); unsigned int hashid = hashstring(sp->sname); if (hashid == id) { return sp; diff --git a/src/kernel/spell.h b/src/kernel/spell.h index b447f51d4..f74fda6e2 100644 --- a/src/kernel/spell.h +++ b/src/kernel/spell.h @@ -27,7 +27,7 @@ extern "C" { struct region; struct spell; struct spell_component; - struct quicklist; + struct selist; struct attrib_type; typedef int(*spell_f)(struct castorder * co); @@ -50,13 +50,13 @@ extern "C" { struct spell * create_spell(const char * name, unsigned int id); struct spell * find_spell(const char *name); struct spell * find_spellbyid(unsigned int i); - void add_spell(struct quicklist **slistp, spell * sp); + void add_spell(struct selist **slistp, spell * sp); void free_spells(void); /** globals **/ extern struct attrib_type at_unitdissolve; extern struct attrib_type at_wdwpyramid; - extern struct quicklist * spells; + extern struct selist * spells; #ifdef __cplusplus } #endif diff --git a/src/kernel/spell.test.c b/src/kernel/spell.test.c index f61c0fffe..6bb2ac449 100644 --- a/src/kernel/spell.test.c +++ b/src/kernel/spell.test.c @@ -6,7 +6,6 @@ #include #include -#include #include #include diff --git a/src/kernel/spellbook.c b/src/kernel/spellbook.c index 13f8a04f7..bb060eaee 100644 --- a/src/kernel/spellbook.c +++ b/src/kernel/spellbook.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include @@ -58,12 +58,12 @@ void read_spellbook(spellbook **bookp, gamedata *data, int(*get_level)(const spe void write_spellbook(const struct spellbook *book, struct storage *store) { - quicklist *ql; + selist *ql; int qi; if (book) { - for (ql = book->spells, qi = 0; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry *sbe = (spellbook_entry *)ql_get(ql, qi); + for (ql = book->spells, qi = 0; ql; selist_advance(&ql, &qi, 1)) { + spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); WRITE_TOK(store, sbe->sp->sname); WRITE_INT(store, sbe->level); } @@ -84,30 +84,30 @@ void spellbook_add(spellbook *sb, struct spell * sp, int level) sbe = (spellbook_entry *)malloc(sizeof(spellbook_entry)); sbe->sp = sp; sbe->level = level; - ql_push(&sb->spells, sbe); + selist_push(&sb->spells, sbe); } void spellbook_clear(spellbook *sb) { - quicklist *ql; + selist *ql; int qi; assert(sb); - for (qi = 0, ql = sb->spells; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry *sbe = (spellbook_entry *)ql_get(ql, qi); + for (qi = 0, ql = sb->spells; ql; selist_advance(&ql, &qi, 1)) { + spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); free(sbe); } - ql_free(sb->spells); + selist_free(sb->spells); free(sb->name); } int spellbook_foreach(spellbook *sb, int(*callback)(spellbook_entry *, void *), void * data) { - quicklist *ql; + selist *ql; int qi; - for (qi = 0, ql = sb->spells; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry *sbe = (spellbook_entry *)ql_get(ql, qi); + for (qi = 0, ql = sb->spells; ql; selist_advance(&ql, &qi, 1)) { + spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); int result = callback(sbe, data); if (result) { return result; @@ -119,11 +119,11 @@ int spellbook_foreach(spellbook *sb, int(*callback)(spellbook_entry *, void *), spellbook_entry * spellbook_get(spellbook *sb, const struct spell * sp) { if (sb) { - quicklist *ql; + selist *ql; int qi; - for (qi = 0, ql = sb->spells; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry *sbe = (spellbook_entry *)ql_get(ql, qi); + for (qi = 0, ql = sb->spells; ql; selist_advance(&ql, &qi, 1)) { + spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); if (sp == sbe->sp) { return sbe; } diff --git a/src/kernel/spellbook.h b/src/kernel/spellbook.h index 84ec0ce5f..75a420c06 100644 --- a/src/kernel/spellbook.h +++ b/src/kernel/spellbook.h @@ -26,7 +26,7 @@ extern "C" { struct spell; struct storage; struct gamedata; - struct quicklist; + struct selist; typedef struct spellbook_entry { struct spell * sp; @@ -36,7 +36,7 @@ extern "C" { typedef struct spellbook { char * name; - struct quicklist * spells; + struct selist * spells; } spellbook; spellbook * create_spellbook(const char * name); diff --git a/src/kernel/spellbook.test.c b/src/kernel/spellbook.test.c index 2f78fd87d..8b997557b 100644 --- a/src/kernel/spellbook.test.c +++ b/src/kernel/spellbook.test.c @@ -2,7 +2,6 @@ #include #include -#include #include #include diff --git a/src/kernel/types.h b/src/kernel/types.h index 92f471688..b9faefce7 100644 --- a/src/kernel/types.h +++ b/src/kernel/types.h @@ -43,7 +43,7 @@ struct luxury_type; struct order; struct plane; struct potion_type; -struct quicklist; +struct selist; struct race; struct region; struct region_list; diff --git a/src/laws.c b/src/laws.c index b99b2d3f2..6b0bfda8d 100644 --- a/src/laws.c +++ b/src/laws.c @@ -89,7 +89,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include -#include +#include #include /* libc includes */ #include @@ -3453,10 +3453,10 @@ static void copy_spells(const spellbook * src, spellbook * dst, int maxlevel) { assert(dst); if (src && src->spells) { - quicklist *ql; + selist *ql; int qi; - for (qi = 0, ql = src->spells; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry * sbe = (spellbook_entry *)ql_get(ql, qi); + for (qi = 0, ql = src->spells; ql; selist_advance(&ql, &qi, 1)) { + spellbook_entry * sbe = (spellbook_entry *)selist_get(ql, qi); if (sbe->level <= maxlevel) { if (!spellbook_get(dst, sbe->sp)) { spellbook_add(dst, sbe->sp, sbe->level); diff --git a/src/magic.c b/src/magic.c index dc56ad5ff..f2992538c 100644 --- a/src/magic.c +++ b/src/magic.c @@ -58,7 +58,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include #include @@ -231,7 +231,7 @@ bool FactionSpells(void) return rule != 0; } -void read_spells(struct quicklist **slistp, magic_t mtype, +void read_spells(struct selist **slistp, magic_t mtype, struct storage *store) { for (;;) { @@ -305,13 +305,13 @@ static int read_mage(attrib * a, void *owner, struct gamedata *data) return AT_READ_OK; } -void write_spells(struct quicklist *slist, struct storage *store) +void write_spells(struct selist *slist, struct storage *store) { - quicklist *ql; + selist *ql; int qi; - for (ql = slist, qi = 0; ql; ql_advance(&ql, &qi, 1)) { - spell *sp = (spell *)ql_get(ql, qi); + for (ql = slist, qi = 0; ql; selist_advance(&ql, &qi, 1)) { + spell *sp = (spell *)selist_get(ql, qi); WRITE_TOK(store, sp->sname); } WRITE_TOK(store, "end"); @@ -424,11 +424,11 @@ static bool already_seen(const faction * f, const spell * sp) void show_new_spells(faction * f, int level, const spellbook *book) { if (book) { - quicklist *ql = book->spells; + selist *ql = book->spells; int qi; - for (qi = 0; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry *sbe = (spellbook_entry *)ql_get(ql, qi); + for (qi = 0; ql; selist_advance(&ql, &qi, 1)) { + spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); if (sbe->level <= level) { if (!already_seen(f, sbe->sp)) { @@ -451,14 +451,14 @@ void pick_random_spells(faction * f, int level, spellbook * book, int num_spells { spellbook_entry *commonspells[MAXSPELLS]; int qi, numspells = 0; - quicklist *ql; + selist *ql; if (level <= f->max_spelllevel) { return; } - for (qi = 0, ql = book->spells; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry * sbe = (spellbook_entry *)ql_get(ql, qi); + for (qi = 0, ql = book->spells; ql; selist_advance(&ql, &qi, 1)) { + spellbook_entry * sbe = (spellbook_entry *)selist_get(ql, qi); if (sbe->level <= level) { commonspells[numspells++] = sbe; } @@ -2956,14 +2956,14 @@ const char *curse_name(const curse_type * ctype, const struct locale *lang) } static void select_spellbook(void **tokens, spellbook *sb, const struct locale * lang) { - quicklist * ql; + selist * ql; int qi; assert(sb); assert(lang); - for (qi = 0, ql = sb->spells; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry *sbe = (spellbook_entry *)ql_get(ql, qi); + for (qi = 0, ql = sb->spells; ql; selist_advance(&ql, &qi, 1)) { + spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); spell *sp = sbe->sp; const char *n = spell_name(sp, lang); diff --git a/src/magic.h b/src/magic.h index 964783c32..f62c533bd 100644 --- a/src/magic.h +++ b/src/magic.h @@ -349,8 +349,8 @@ extern "C" { struct order *ord, const struct spllprm *spobj); bool FactionSpells(void); - void write_spells(struct quicklist *slist, struct storage *store); - void read_spells(struct quicklist **slistp, magic_t mtype, + void write_spells(struct selist *slist, struct storage *store); + void read_spells(struct selist **slistp, magic_t mtype, struct storage *store); struct spellbook * get_spellbook(const char * name); diff --git a/src/magic.test.c b/src/magic.test.c index 4ba867b96..befd1986d 100644 --- a/src/magic.test.c +++ b/src/magic.test.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include @@ -41,7 +41,7 @@ void test_updatespells(CuTest * tc) CuAssertPtrEquals(tc, 0, f->spellbook); pick_random_spells(f, 1, book, 1); CuAssertPtrNotNull(tc, f->spellbook); - CuAssertIntEquals(tc, 1, ql_length(f->spellbook->spells)); + CuAssertIntEquals(tc, 1, selist_length(f->spellbook->spells)); CuAssertPtrNotNull(tc, spellbook_get(f->spellbook, sp)); free_spellbook(book); test_cleanup(); @@ -370,10 +370,10 @@ void test_hasspell(CuTest * tc) test_cleanup(); } -static quicklist * casts; +static selist * casts; static int cast_fireball(struct castorder * co) { - ql_push(&casts, co); + selist_push(&casts, co); return 0; } @@ -401,8 +401,8 @@ void test_multi_cast(CuTest *tc) { CuAssertPtrEquals(tc, casts, 0); magic(); CuAssertPtrNotNull(tc, casts); - CuAssertIntEquals(tc, 2, ql_length(casts)); - ql_free(casts); + CuAssertIntEquals(tc, 2, selist_length(casts)); + selist_free(casts); test_cleanup(); } diff --git a/src/market.c b/src/market.c index cef84b9b2..42819325f 100644 --- a/src/market.c +++ b/src/market.c @@ -17,7 +17,7 @@ without prior permission by the authors of Eressea. #include #include -#include +#include #include #include @@ -92,7 +92,7 @@ bool markets_module(void) void do_markets(void) { - quicklist *traders = 0; + selist *traders = 0; unit *markets[MAX_MARKETS]; region *r; for (r = regions; r; r = r->next) { @@ -124,7 +124,7 @@ void do_markets(void) attrib *a = a_find(u->attribs, &at_market); if (a == NULL) { a = a_add(&u->attribs, a_new(&at_market)); - ql_push(&traders, u); + selist_push(&traders, u); } items = (item *)a->data.v; i_change(&items, lux, 1); @@ -138,7 +138,7 @@ void do_markets(void) attrib *a = a_find(u->attribs, &at_market); if (a == NULL) { a = a_add(&u->attribs, a_new(&at_market)); - ql_push(&traders, u); + selist_push(&traders, u); } items = (item *)a->data.v; i_change(&items, herb, 1); @@ -151,10 +151,10 @@ void do_markets(void) } if (traders) { - quicklist *qliter = traders; + selist *qliter = traders; int qli = 0; - for (qli = 0; qliter; ql_advance(&qliter, &qli, 1)) { - unit *u = (unit *)ql_get(qliter, qli); + for (qli = 0; qliter; selist_advance(&qliter, &qli, 1)) { + unit *u = (unit *)selist_get(qliter, qli); attrib *a = a_find(u->attribs, &at_market); item *items = (item *)a->data.v; @@ -176,6 +176,6 @@ void do_markets(void) a_remove(&u->attribs, a); } - ql_free(traders); + selist_free(traders); } } diff --git a/src/modules/autoseed.c b/src/modules/autoseed.c index 54fd7411e..1e2d2d23f 100644 --- a/src/modules/autoseed.c +++ b/src/modules/autoseed.c @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include @@ -295,17 +295,17 @@ static bool virgin_region(const region * r) return true; } -static quicklist * get_island(region * root) +static selist * get_island(region * root) { - quicklist * ql, *result = 0; + selist * ql, *result = 0; int qi = 0; fset(root, RF_MARK); - ql_push(&result, root); + selist_push(&result, root); - for (ql = result, qi = 0; ql; ql_advance(&ql, &qi, 1)) { + for (ql = result, qi = 0; ql; selist_advance(&ql, &qi, 1)) { int dir; - region *r = (region *)ql_get(ql, qi); + region *r = (region *)selist_get(ql, qi); region * next[MAXDIRECTIONS]; get_neighbours(r, next); @@ -314,13 +314,13 @@ static quicklist * get_island(region * root) region *rn = next[dir]; if (rn != NULL && rn->land && !fval(rn, RF_MARK)) { fset(rn, RF_MARK); - ql_push(&result, rn); + selist_push(&result, rn); } } } - for (ql = result, qi = 0; ql; ql_advance(&ql, &qi, 1)) { - region *r = (region *)ql_get(ql, qi); + for (ql = result, qi = 0; ql; selist_advance(&ql, &qi, 1)) { + region *r = (region *)selist_get(ql, qi); freset(r, RF_MARK); } return result; @@ -330,14 +330,14 @@ static void get_island_info(region * root, int *size_p, int *inhabited_p, int *maxage_p) { int qi, size = 0, maxage = 0, inhabited = 0; - quicklist *ql, *island = NULL; + selist *ql, *island = NULL; - ql_push(&island, root); + selist_push(&island, root); fset(root, RF_MARK); - for (ql = island, qi = 0; ql; ql_advance(&ql, &qi, 1)) { + for (ql = island, qi = 0; ql; selist_advance(&ql, &qi, 1)) { int d; - region *r = (region *)ql_get(ql, qi); + region *r = (region *)selist_get(ql, qi); if (r->units) { unit *u; for (u = r->units; u; u = u->next) { @@ -351,16 +351,16 @@ get_island_info(region * root, int *size_p, int *inhabited_p, int *maxage_p) for (d = 0; d != MAXDIRECTIONS; ++d) { region *rn = rconnect(r, d); if (rn && !fval(rn, RF_MARK) && rn->land) { - ql_push(&island, rn); + selist_push(&island, rn); fset(rn, RF_MARK); } } } - for (ql = island, qi = 0; ql; ql_advance(&ql, &qi, 1)) { - region *r = (region *)ql_get(ql, qi); + for (ql = island, qi = 0; ql; selist_advance(&ql, &qi, 1)) { + region *r = (region *)selist_get(ql, qi); freset(r, RF_MARK); } - ql_free(island); + selist_free(island); if (size_p) *size_p = size; if (inhabited_p) @@ -502,11 +502,11 @@ int autoseed(newfaction ** players, int nsize, int max_agediff) } if (rmin != NULL) { faction *f; - quicklist *ql, *rlist = get_island(rmin); + selist *ql, *rlist = get_island(rmin); int qi; - for (ql = rlist, qi = 0; ql; ql_advance(&ql, &qi, 1)) { - region *r = (region *)ql_get(ql, qi); + for (ql = rlist, qi = 0; ql; selist_advance(&ql, &qi, 1)) { + region *r = (region *)selist_get(ql, qi); unit *u; for (u = r->units; u; u = u->next) { f = u->faction; @@ -516,7 +516,7 @@ int autoseed(newfaction ** players, int nsize, int max_agediff) } } } - ql_free(rlist); + selist_free(rlist); if (psize > 0) { for (f = factions; f; f = f->next) { freset(f, FFL_MARK); diff --git a/src/monsters.c b/src/monsters.c index b613f48cc..bba1cbd50 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -65,7 +65,7 @@ #include #include -#include +#include /* libc includes */ #include @@ -451,11 +451,11 @@ static attrib *set_new_dragon_target(unit * u, region * r, int range) { int max_affinity = 0; region *max_region = NULL; - quicklist *ql, *rlist = regions_in_range(r, range, allowed_dragon); + selist *ql, *rlist = regions_in_range(r, range, allowed_dragon); int qi; - for (qi = 0, ql = rlist; ql; ql_advance(&ql, &qi, 1)) { - region *r2 = (region *)ql_get(ql, qi); + for (qi = 0, ql = rlist; ql; selist_advance(&ql, &qi, 1)) { + region *r2 = (region *)selist_get(ql, qi); int affinity = dragon_affinity_value(r2, u); if (affinity > max_affinity) { max_affinity = affinity; @@ -463,7 +463,7 @@ static attrib *set_new_dragon_target(unit * u, region * r, int range) } } - ql_free(rlist); + selist_free(rlist); if (max_region && max_region != r) { attrib *a = a_find(u->attribs, &at_targetregion); diff --git a/src/platform.h b/src/platform.h index 355b995d2..7ddb612ae 100644 --- a/src/platform.h +++ b/src/platform.h @@ -24,11 +24,12 @@ #endif #define UNUSED_ARG(a) (void)(a) -#define TOLUA_CAST (char*) #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define TOLUA_CAST (char*) + #ifdef NO_STRDUP char * strdup(const char *s); #endif diff --git a/src/report.c b/src/report.c index a37c38bf8..1282789fa 100644 --- a/src/report.c +++ b/src/report.c @@ -82,7 +82,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include #include @@ -1735,16 +1735,16 @@ static void rpline(struct stream *out) swrite(line, sizeof(line), 1, out); } -static void list_address(struct stream *out, const faction * uf, quicklist * seenfactions) +static void list_address(struct stream *out, const faction * uf, selist * seenfactions) { int qi = 0; - quicklist *flist = seenfactions; + selist *flist = seenfactions; centre(out, LOC(uf->locale, "nr_addresses"), false); newline(out); while (flist != NULL) { - const faction *f = (const faction *)ql_get(flist, qi); + const faction *f = (const faction *)selist_get(flist, qi); if (!is_monsters(f)) { char buf[8192]; char label = '-'; @@ -1759,7 +1759,7 @@ static void list_address(struct stream *out, const faction * uf, quicklist * see label = '+'; paragraph(out, buf, 4, 0, label); } - ql_advance(&flist, &qi, 1); + selist_advance(&flist, &qi, 1); } newline(out); rpline(out); diff --git a/src/report.test.c b/src/report.test.c index ab7c377ce..aa3c52695 100644 --- a/src/report.test.c +++ b/src/report.test.c @@ -18,7 +18,6 @@ #include #include -#include #include #include diff --git a/src/reports.c b/src/reports.c index c6df944a3..5a47acfed 100644 --- a/src/reports.c +++ b/src/reports.c @@ -57,7 +57,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include /* libc includes */ #include @@ -659,15 +659,15 @@ size_t size) spellbook *book = unit_get_spellbook(u); if (book) { - quicklist *ql = book->spells; + selist *ql = book->spells; int qi, header, maxlevel = effskill(u, SK_MAGIC, 0); int result = snprintf(bufp, size, ". Aura %d/%d", get_spellpoints(u), max_spellpoints(u->region, u)); if (wrptr(&bufp, &size, result) != 0) { WARN_STATIC_BUFFER(); } - for (header = 0, qi = 0; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry * sbe = (spellbook_entry *)ql_get(ql, qi); + for (header = 0, qi = 0; ql; selist_advance(&ql, &qi, 1)) { + spellbook_entry * sbe = (spellbook_entry *)selist_get(ql, qi); if (sbe->level <= maxlevel) { int result = 0; if (!header) { @@ -969,8 +969,7 @@ int stealth_modifier(seen_mode mode) } } -void transfer_seen(quicklist ** dst, quicklist ** src) -{ +static void transfer_seen(selist ** dst, selist ** src) { assert(!*dst); *dst = *src; *src = NULL; @@ -984,8 +983,8 @@ int cmp_faction(const void *lhs, const void *rhs) { return -1; } -static void add_seen_faction_i(struct quicklist **flist, faction *f) { - ql_set_insert_ex(flist, f, cmp_faction); +static void add_seen_faction_i(struct selist **flist, faction *f) { + selist_set_insert(flist, f, cmp_faction); } void add_seen_faction(faction *self, faction *seen) { @@ -994,7 +993,7 @@ void add_seen_faction(faction *self, faction *seen) { typedef struct address_data { faction *f, *lastf; - quicklist **flist; + selist **flist; int stealthmod; } address_data; @@ -1016,7 +1015,7 @@ static void cb_add_address(region *r, unit *ut, void *cbdata) { } } -static void add_travelthru_addresses(region *r, faction *f, quicklist **flist, int stealthmod) { +static void add_travelthru_addresses(region *r, faction *f, selist **flist, int stealthmod) { // for each traveling unit: add the faction of any unit is can see address_data cbdata = { 0 }; cbdata.f = f; @@ -1030,18 +1029,18 @@ static void get_addresses(report_context * ctx) /* "TODO: travelthru" */ region *r; const faction *lastf = NULL; - quicklist *flist = 0; + selist *flist = 0; transfer_seen(&flist, &ctx->f->seen_factions); ctx->f->seen_factions = NULL; /* do not delete it twice */ - ql_push(&flist, ctx->f); + selist_push(&flist, ctx->f); if (f_get_alliance(ctx->f)) { - quicklist *ql = ctx->f->alliance->members; + selist *ql = ctx->f->alliance->members; int qi; - for (qi = 0; ql; ql_advance(&ql, &qi, 1)) { - add_seen_faction_i(&flist, (faction *)ql_get(ql, qi)); + for (qi = 0; ql; selist_advance(&ql, &qi, 1)) { + add_seen_faction_i(&flist, (faction *)selist_get(ql, qi)); } } @@ -1126,31 +1125,31 @@ void reports_done(void) { } } -static quicklist *get_regions_distance(region * root, int radius) +static selist *get_regions_distance(region * root, int radius) { - quicklist *ql, *rlist = NULL; + selist *ql, *rlist = NULL; int qi = 0; - ql_push(&rlist, root); + selist_push(&rlist, root); fset(root, RF_MARK); ql = rlist; while (ql) { - region *r = (region *)ql_get(ql, qi); + region *r = (region *)selist_get(ql, qi); region * next[MAXDIRECTIONS]; int d; get_neighbours(r, next); for (d = 0; d != MAXDIRECTIONS; ++d) { if (next[d] && !fval(next[d], RF_MARK) && distance(next[d], root) <= radius) { - ql_push(&rlist, next[d]); + selist_push(&rlist, next[d]); fset(next[d], RF_MARK); } } - ql_advance(&ql, &qi, 1); + selist_advance(&ql, &qi, 1); } - for (ql = rlist, qi = 0; ql; ql_advance(&ql, &qi, 1)) { - region *r = (region *)ql_get(ql, qi); + for (ql = rlist, qi = 0; ql; selist_advance(&ql, &qi, 1)) { + region *r = (region *)selist_get(ql, qi); freset(r, RF_MARK); } return rlist; @@ -1186,16 +1185,16 @@ static void add_seen_nb(faction *f, region *r, seen_mode mode) { */ static void prepare_lighthouse(faction *f, region *r, int range) { - quicklist *ql, *rlist = get_regions_distance(r, range); + selist *ql, *rlist = get_regions_distance(r, range); int qi; - for (ql = rlist, qi = 0; ql; ql_advance(&ql, &qi, 1)) { - region *rl = (region *)ql_get(ql, qi); + for (ql = rlist, qi = 0; ql; selist_advance(&ql, &qi, 1)) { + region *rl = (region *)selist_get(ql, qi); if (!fval(rl->terrain, FORBIDDEN_REGION)) { add_seen_nb(f, rl, seen_lighthouse); } } - ql_free(rlist); + selist_free(rlist); } void reorder_units(region * r) @@ -1397,7 +1396,7 @@ void prepare_report(report_context *ctx, faction *f) void finish_reports(report_context *ctx) { region *r; - ql_free(ctx->addresses); + selist_free(ctx->addresses); for (r = ctx->first; r != ctx->last; r = r->next) { r->seen.mode = seen_none; } diff --git a/src/reports.h b/src/reports.h index cc197bed4..4fab104ef 100644 --- a/src/reports.h +++ b/src/reports.h @@ -25,12 +25,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -struct stream; -struct seen_region; #ifdef __cplusplus extern "C" { #endif + struct selist; + struct stream; + struct seen_region; + /* Alter, ab dem der Score angezeigt werden soll: */ #define DISPLAYSCORE 12 /* Breite einer Reportzeile: */ @@ -71,7 +73,7 @@ extern "C" { typedef struct report_context { struct faction *f; - struct quicklist *addresses; + struct selist *addresses; struct region *first, *last; void *userdata; time_t report_time; diff --git a/src/reports.test.c b/src/reports.test.c index 728145758..e3ca5c89b 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include @@ -108,14 +108,14 @@ static void test_seen_faction(CuTest *tc) { f1 = test_create_faction(rc); f2 = test_create_faction(rc); add_seen_faction(f1, f2); - CuAssertPtrEquals(tc, f2, ql_get(f1->seen_factions, 0)); - CuAssertIntEquals(tc, 1, ql_length(f1->seen_factions)); + CuAssertPtrEquals(tc, f2, selist_get(f1->seen_factions, 0)); + CuAssertIntEquals(tc, 1, selist_length(f1->seen_factions)); add_seen_faction(f1, f2); - CuAssertIntEquals(tc, 1, ql_length(f1->seen_factions)); + CuAssertIntEquals(tc, 1, selist_length(f1->seen_factions)); add_seen_faction(f1, f1); - CuAssertIntEquals(tc, 2, ql_length(f1->seen_factions)); - f2 = (faction *)ql_get(f1->seen_factions, 1); - f1 = (faction *)ql_get(f1->seen_factions, 0); + CuAssertIntEquals(tc, 2, selist_length(f1->seen_factions)); + f2 = (faction *)selist_get(f1->seen_factions, 1); + f1 = (faction *)selist_get(f1->seen_factions, 0); CuAssertTrue(tc, f1->no < f2->no); test_cleanup(); } diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index 227d94858..76fd605ff 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -38,7 +38,7 @@ #include #include -#include +#include /* libc includes */ #include @@ -295,15 +295,15 @@ int sp_stun(struct castorder * co) /** randomly shuffle an array * for correctness, see Donald E. Knuth, The Art of Computer Programming */ -static void scramble_fighters(quicklist * ql) +static void scramble_fighters(selist * ql) { - int qi, qlen = ql_length(ql); + int qi, qlen = selist_length(ql); for (qi = 0; qi != qlen; ++qi) { int qj = qi + (rng_int() % (qlen - qi)); - void *a = ql_get(ql, qi); - void *b = ql_replace(ql, qj, a); - ql_replace(ql, qi, b); + void *a = selist_get(ql, qi); + void *b = selist_replace(ql, qj, a); + selist_replace(ql, qi, b); } } @@ -314,7 +314,7 @@ int sp_combatrosthauch(struct castorder * co) int level = co->level; double power = co->force; battle *b = fi->side->battle; - quicklist *ql, *fgs; + selist *ql, *fgs; int force = lovar(power * 15); int qi, k = 0; @@ -329,8 +329,8 @@ int sp_combatrosthauch(struct castorder * co) fgs = fighters(b, fi->side, FIGHT_ROW, BEHIND_ROW - 1, FS_ENEMY); scramble_fighters(fgs); - for (qi = 0, ql = fgs; ql; ql_advance(&ql, &qi, 1)) { - fighter *df = (fighter *)ql_get(ql, qi); + for (qi = 0, ql = fgs; ql; selist_advance(&ql, &qi, 1)) { + fighter *df = (fighter *)selist_get(ql, qi); if (df->alive == 0) continue; @@ -378,7 +378,7 @@ int sp_combatrosthauch(struct castorder * co) } } } - ql_free(fgs); + selist_free(fgs); if (k == 0) { /* keine Waffen mehr da, die zerst�rt werden k�nnten */ @@ -720,7 +720,7 @@ int sp_immolation(struct castorder * co) troop at; int force, qi, killed = 0; const char *damage; - quicklist *fgs, *ql; + selist *fgs, *ql; message *m; /* 2d4 HP */ @@ -740,8 +740,8 @@ int sp_immolation(struct castorder * co) at.index = 0; fgs = fighters(b, fi->side, FIGHT_ROW, AVOID_ROW, FS_ENEMY); - for (qi = 0, ql = fgs; ql; ql_advance(&ql, &qi, 1)) { - fighter *df = (fighter *)ql_get(ql, qi); + for (qi = 0, ql = fgs; ql; selist_advance(&ql, &qi, 1)) { + fighter *df = (fighter *)selist_get(ql, qi); int n = df->alive - df->removed; troop dt; @@ -755,7 +755,7 @@ int sp_immolation(struct castorder * co) if (force == 0) break; } - ql_free(fgs); + selist_free(fgs); m = msg_message("battle::combatspell", "mage spell killed", fi->unit, sp, @@ -987,7 +987,7 @@ int sp_chaosrow(struct castorder * co) const spell * sp = co->sp; battle *b = fi->side->battle; unit *mage = fi->unit; - quicklist *fgs, *ql; + selist *fgs, *ql; message *m; const char *mtype; int qi, k = 0; @@ -1007,8 +1007,8 @@ int sp_chaosrow(struct castorder * co) fgs = fighters(b, fi->side, FIGHT_ROW, NUMROWS, FS_ENEMY); scramble_fighters(fgs); - for (qi = 0, ql = fgs; ql; ql_advance(&ql, &qi, 1)) { - fighter *df = (fighter *)ql_get(ql, qi); + for (qi = 0, ql = fgs; ql; selist_advance(&ql, &qi, 1)) { + fighter *df = (fighter *)selist_get(ql, qi); int n = df->unit->number; if (df->alive == 0) @@ -1052,7 +1052,7 @@ int sp_chaosrow(struct castorder * co) } power = MAX(0, power - n); } - ql_free(fgs); + selist_free(fgs); if (sp->id == SPL_CHAOSROW) { mtype = (k > 0) ? "sp_chaosrow_effect_1" : "sp_chaosrow_effect_0"; @@ -1077,7 +1077,7 @@ int sp_flee(struct castorder * co) const spell * sp = co->sp; battle *b = fi->side->battle; unit *mage = fi->unit; - quicklist *fgs, *ql; + selist *fgs, *ql; int force, n, qi; int panik = 0; message *msg; @@ -1106,8 +1106,8 @@ int sp_flee(struct castorder * co) fgs = fighters(b, fi->side, FIGHT_ROW, AVOID_ROW, FS_ENEMY); scramble_fighters(fgs); - for (qi = 0, ql = fgs; ql; ql_advance(&ql, &qi, 1)) { - fighter *df = (fighter *)ql_get(ql, qi); + for (qi = 0, ql = fgs; ql; selist_advance(&ql, &qi, 1)) { + fighter *df = (fighter *)selist_get(ql, qi); for (n = 0; n != df->alive; ++n) { if (force < 0) @@ -1128,7 +1128,7 @@ int sp_flee(struct castorder * co) } } } - ql_free(fgs); + selist_free(fgs); msg = msg_message("sp_flee_effect_1", "mage spell amount", mage, sp, panik); message_all(b, msg); @@ -1457,7 +1457,7 @@ static void do_meffect(fighter * af, int typ, int effect, int duration) { battle *b = af->side->battle; meffect *me = (meffect *)malloc(sizeof(struct meffect)); - ql_push(&b->meffects, me); + selist_push(&b->meffects, me); me->magician = af; me->typ = typ; me->effect = effect; @@ -1654,13 +1654,13 @@ int sp_keeploot(struct castorder * co) return level; } -static int heal_fighters(quicklist * fgs, int *power, bool heal_monsters) +static int heal_fighters(selist * fgs, int *power, bool heal_monsters) { int healhp = *power, healed = 0, qi; - quicklist *ql; + selist *ql; - for (qi = 0, ql = fgs; ql; ql_advance(&ql, &qi, 1)) { - fighter *df = (fighter *)ql_get(ql, qi); + for (qi = 0, ql = fgs; ql; selist_advance(&ql, &qi, 1)) { + fighter *df = (fighter *)selist_get(ql, qi); if (healhp <= 0) break; @@ -1705,7 +1705,7 @@ int sp_healing(struct castorder * co) unit *mage = fi->unit; int j = 0; int healhp = (int)power * 200; - quicklist *fgs; + selist *fgs; message *msg; bool use_item = has_ao_healing(mage); @@ -1723,7 +1723,7 @@ int sp_healing(struct castorder * co) scramble_fighters(fgs); j += heal_fighters(fgs, &healhp, false); j += heal_fighters(fgs, &healhp, true); - ql_free(fgs); + selist_free(fgs); if (j <= 0) { level = j; @@ -1750,7 +1750,7 @@ int sp_undeadhero(struct castorder * co) battle *b = fi->side->battle; unit *mage = fi->unit; region *r = b->region; - quicklist *fgs, *ql; + selist *fgs, *ql; int qi, n, undead = 0; message *msg; int force = (int)get_force(power, 0); @@ -1760,8 +1760,8 @@ int sp_undeadhero(struct castorder * co) fgs = fighters(b, fi->side, FIGHT_ROW, AVOID_ROW, FS_ENEMY | FS_HELP); scramble_fighters(fgs); - for (qi = 0, ql = fgs; ql; ql_advance(&ql, &qi, 1)) { - fighter *df = (fighter *)ql_get(ql, qi); + for (qi = 0, ql = fgs; ql; selist_advance(&ql, &qi, 1)) { + fighter *df = (fighter *)selist_get(ql, qi); unit *du = df->unit; if (force <= 0) @@ -1832,7 +1832,7 @@ int sp_undeadhero(struct castorder * co) } } } - ql_free(fgs); + selist_free(fgs); level = MIN(level, undead); if (undead == 0) { diff --git a/src/spy.c b/src/spy.c index a7d08d42e..eb58f792a 100644 --- a/src/spy.c +++ b/src/spy.c @@ -49,8 +49,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include - /* libc includes */ #include #include diff --git a/src/sqlite.c b/src/sqlite.c index aea0f5d20..edb5bfc62 100644 --- a/src/sqlite.c +++ b/src/sqlite.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include @@ -72,10 +72,10 @@ typedef struct db_faction { char *name; } db_faction; -static struct quicklist * +static struct selist * read_factions(sqlite3 * db, int game_id) { int res; - quicklist *result = 0; + selist *result = 0; const char * sql = "SELECT f.id, fd.code, fd.name, fd.email FROM faction f" " LEFT OUTER JOIN faction_data fd" @@ -97,7 +97,7 @@ read_factions(sqlite3 * db, int game_id) { if (text) dbf->name = strdup(text); text = (const char *)sqlite3_column_text(stmt, 3); if (text) dbf->email = strdup(text); - ql_push(&result, dbf); + selist_push(&result, dbf); res = sqlite3_step(stmt); } sqlite3_finalize(stmt); @@ -133,54 +133,71 @@ static void update_faction(sqlite3 *db, const faction *f) { sqlite3_finalize(stmt); } -int db_update_factions(sqlite3 * db, bool force, int game_id) { - quicklist *ql = read_factions(db, game_id); - faction *f; - sqlite3_exec(db, "BEGIN", 0, 0, 0); - for (f = factions; f; f = f->next) { - bool update = force; - db_faction *dbf = 0; - ql_iter it = qli_init(&ql); - while (qli_more(it)) { - db_faction *df = (db_faction*)qli_next(&it); - if (f->no == df->no || strcmp(f->email, df->email) == 0 || strcmp(f->name, df->name) == 0) { - dbf = df; - } - if (f->subscription == df->uid) { - dbf = df; - break; - } - } - if (dbf) { - if (dbf->uid != f->subscription) { - log_warning("faction %s(%d) not found in database, but matches %d\n", itoa36(f->no), f->subscription, dbf->uid); - f->subscription = dbf->uid; - } - update = (dbf->no != f->no) || (strcmp(f->email, dbf->email) != 0) || (strcmp(f->name, dbf->name) != 0); - } - else { - f->subscription = insert_faction(db, game_id, f); - log_warning("faction %s not found in database, created as %d\n", itoa36(f->no), f->subscription); - update = true; - } - if (update) { - update_faction(db, f); - log_debug("faction %s updated\n", itoa36(f->no)); - } +struct cb_data { + const faction *f; + sqlite3 *db; + db_faction *dbf; +}; + +static bool db_faction_cb(void *el, void *arg) { + db_faction *df = (db_faction *)el; + struct cb_data *cb = (struct cb_data *)arg; + const faction *f = cb->f; + + if (f->no == df->no || strcmp(f->email, df->email) == 0 || strcmp(f->name, df->name) == 0) { + cb->dbf = df; + } + if (f->subscription == df->uid) { + cb->dbf = df; + return false; + } + return true; +} + +int db_update_factions(sqlite3 * db, bool force, int game_id) { + selist *ql = read_factions(db, game_id); + if (ql) { + faction *f; + struct cb_data cbdata; + cbdata.db = db; + cbdata.dbf = NULL; + sqlite3_exec(db, "BEGIN", 0, 0, 0); + for (f = factions; f; f = f->next) { + bool update = force; + cbdata.f = f; + selist_foreach_ex(ql, db_faction_cb, &cbdata); + if (cbdata.dbf) { + const db_faction *dbf = cbdata.dbf; + if (dbf->uid != f->subscription) { + log_warning("faction %s(%d) not found in database, but matches %d\n", itoa36(f->no), f->subscription, dbf->uid); + f->subscription = dbf->uid; + } + update = (dbf->no != f->no) || (strcmp(f->email, dbf->email) != 0) || (strcmp(f->name, dbf->name) != 0); + } + else { + f->subscription = insert_faction(db, game_id, f); + log_warning("faction %s not found in database, created as %d\n", itoa36(f->no), f->subscription); + update = true; + } + if (update) { + update_faction(db, f); + log_debug("faction %s updated\n", itoa36(f->no)); + } + } + sqlite3_exec(db, "COMMIT", 0, 0, 0); } - sqlite3_exec(db, "COMMIT", 0, 0, 0); return SQLITE_OK; } int db_update_scores(sqlite3 * db, bool force) { /* - const char *sql_ins = + const char *sselist_ins = "INSERT OR FAIL INTO score (value,faction_id,turn) VALUES (?,?,?)"; - sqlite3_stmt *stmt_ins = stmt_cache_get(db, sql_ins); - const char *sql_upd = + sqlite3_stmt *stmt_ins = stmt_cache_get(db, sselist_ins); + const char *sselist_upd = "UPDATE score set value=? WHERE faction_id=? AND turn=?"; - sqlite3_stmt *stmt_upd = stmt_cache_get(db, sql_upd); + sqlite3_stmt *stmt_upd = stmt_cache_get(db, sselist_upd); faction *f; sqlite3_exec(db, "BEGIN", 0, 0, 0); for (f = factions; f; f = f->next) { diff --git a/src/study.c b/src/study.c index b69b4359f..fb87987fa 100644 --- a/src/study.c +++ b/src/study.c @@ -52,6 +52,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include @@ -222,7 +223,7 @@ teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk, a = a_add(&student->attribs, a_new(&at_learning)); teach = (teaching_info *)a->data.v; } - ql_push(&teach->teachers, teacher); + selist_push(&teach->teachers, teacher); teach->value += n; if (student->building && teacher->building == student->building) { @@ -531,6 +532,36 @@ static bool ExpensiveMigrants(void) return rule; } +struct teach_data { + unit *u; + skill_t sk; +}; + +static bool cb_msg_teach(void *el, void *arg) { + struct teach_data *td = (struct teach_data *)arg; + unit *ut = (unit *)el; + unit * u = td->u; + skill_t sk = td->sk; + if (ut->faction != u->faction) { + bool feedback = alliedunit(u, ut->faction, HELP_GUARD); + if (feedback) { + ADDMSG(&ut->faction->msgs, msg_message("teach_teacher", + "teacher student skill level", ut, u, sk, + effskill(u, sk, 0))); + } + ADDMSG(&u->faction->msgs, msg_message("teach_student", + "teacher student skill", ut, u, sk)); + } + return true; +} + +static void msg_teachers(struct selist *teachers, struct unit *u, skill_t sk) { + struct teach_data cbdata; + cbdata.sk = sk; + cbdata.u = u; + selist_foreach_ex(teachers, cb_msg_teach, &cbdata); +} + int study_cmd(unit * u, order * ord) { region *r = u->region; @@ -755,19 +786,8 @@ int study_cmd(unit * u, order * ord) learn_skill(u, sk, days); if (a != NULL) { - ql_iter qli = qli_init(&teach->teachers); - while (qli_more(qli)) { - unit *teacher = (unit *)qli_next(&qli); - if (teacher->faction != u->faction) { - bool feedback = alliedunit(u, teacher->faction, HELP_GUARD); - if (feedback) { - ADDMSG(&teacher->faction->msgs, msg_message("teach_teacher", - "teacher student skill level", teacher, u, sk, - effskill(u, sk, 0))); - } - ADDMSG(&u->faction->msgs, msg_message("teach_student", - "teacher student skill", teacher, u, sk)); - } + if (teach->teachers) { + msg_teachers(teach->teachers, u, sk); } a_remove(&u->attribs, a); a = NULL; diff --git a/src/study.h b/src/study.h index 8067bc9bd..0f8ae70f5 100644 --- a/src/study.h +++ b/src/study.h @@ -27,7 +27,7 @@ extern "C" { #endif struct unit; - struct quicklist; + struct selist; int teach_cmd(struct unit *u, struct order *ord); int study_cmd(struct unit *u, struct order *ord); @@ -48,7 +48,7 @@ extern "C" { #define TEACHNUMBER 10 typedef struct teaching_info { - struct quicklist *teachers; + struct selist *teachers; int value; } teaching_info; diff --git a/src/study.test.c b/src/study.test.c index 4c1e5f171..594ca600c 100644 --- a/src/study.test.c +++ b/src/study.test.c @@ -19,7 +19,7 @@ #include #include -#include +#include #include @@ -539,9 +539,9 @@ static void test_teach_message(CuTest *tc) { teach = (teaching_info *)a->data.v; CuAssertPtrNotNull(tc, teach->teachers); CuAssertIntEquals(tc, 600, teach->value); - CuAssertIntEquals(tc, 2, ql_length(teach->teachers)); - CuAssertPtrEquals(tc, u1, ql_get(teach->teachers, 0)); - CuAssertPtrEquals(tc, u2, ql_get(teach->teachers, 1)); + CuAssertIntEquals(tc, 2, selist_length(teach->teachers)); + CuAssertPtrEquals(tc, u1, selist_get(teach->teachers, 0)); + CuAssertPtrEquals(tc, u2, selist_get(teach->teachers, 1)); study_cmd(u, u->thisorder); CuAssertPtrEquals(tc, NULL, test_find_messagetype(u1->faction->msgs, "teach_teacher")); CuAssertPtrNotNull(tc, test_find_messagetype(u2->faction->msgs, "teach_teacher")); diff --git a/src/travelthru.c b/src/travelthru.c index 5e6cac41b..73aa97757 100644 --- a/src/travelthru.c +++ b/src/travelthru.c @@ -33,14 +33,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include +#include #include #include static void travel_done(attrib *a) { - quicklist *ql = (quicklist *)a->data.v; - ql_free(ql); + selist *ql = (selist *)a->data.v; + selist_free(ql); } /*********************/ @@ -67,7 +67,7 @@ void travelthru_add(region * r, unit * u) region *next[MAXDIRECTIONS]; int d; attrib *a; - quicklist *ql; + selist *ql; assert(r); assert(u); @@ -76,10 +76,10 @@ void travelthru_add(region * r, unit * u) if (!a) { a = a_add(&r->attribs, a_new(&at_travelunit)); } - ql = (quicklist *)a->data.v; + ql = (selist *)a->data.v; fset(r, RF_TRAVELUNIT); - ql_push(&ql, u); + selist_push(&ql, u); a->data.v = ql; /* the first and last region of the faction gets reset, because travelthrough @@ -99,18 +99,31 @@ bool travelthru_cansee(const struct region *r, const struct faction *f, const st return false; } -void travelthru_map(region * r, void(*cb)(region *, struct unit *, void *), void *cbdata) +struct cb_data { + void(*call)(region *, struct unit *, void *); + void *data; + struct region *r; +}; + +static bool cb_map(void *data, void *ex) { + struct cb_data *cb = (struct cb_data *)ex; + struct unit *u = (struct unit *)data; + cb->call(cb->r, u, cb->data); + return true; +} + +void travelthru_map(region * r, void(*cb)(region *, struct unit *, void *), void *data) { attrib *a; + struct cb_data cbdata; + assert(r); + cbdata.call = cb; + cbdata.data = data; + cbdata.r = r; a = a_find(r->attribs, &at_travelunit); if (a) { - quicklist *ql; - ql_iter qi; - ql = (quicklist *)a->data.v; - for (qi = qli_init(&ql); qli_more(qi);) { - unit *u = (unit *)qli_next(&qi); - cb(r, u, cbdata); - } + selist *ql = (selist *)a->data.v; + selist_foreach_ex(ql, cb_map, &cbdata); } } diff --git a/src/util/message.c b/src/util/message.c index b5a9592bd..c5285835e 100644 --- a/src/util/message.c +++ b/src/util/message.c @@ -16,7 +16,7 @@ #include "strings.h" #include "log.h" -#include "quicklist.h" +#include "selist.h" /* libc includes */ #include @@ -162,7 +162,7 @@ message *msg_create(const struct message_type *mtype, variant args[]) } #define MT_MAXHASH 1021 -static quicklist *messagetypes[MT_MAXHASH]; +static selist *messagetypes[MT_MAXHASH]; static void mt_free(void *val) { message_type *mtype = (message_type *)val; @@ -179,9 +179,9 @@ static void mt_free(void *val) { void mt_clear(void) { int i; for (i = 0; i != MT_MAXHASH; ++i) { - quicklist *ql = messagetypes[i]; - ql_foreach(ql, mt_free); - ql_free(ql); + selist *ql = messagetypes[i]; + selist_foreach(ql, mt_free); + selist_free(ql); messagetypes[i] = 0; } } @@ -189,11 +189,11 @@ void mt_clear(void) { const message_type *mt_find(const char *name) { unsigned int hash = hashstring(name) % MT_MAXHASH; - quicklist *ql = messagetypes[hash]; + selist *ql = messagetypes[hash]; int qi; - for (qi = 0; ql; ql_advance(&ql, &qi, 1)) { - message_type *data = (message_type *)ql_get(ql, qi); + for (qi = 0; ql; selist_advance(&ql, &qi, 1)) { + message_type *data = (message_type *)selist_get(ql, qi); if (strcmp(data->name, name) == 0) { return data; } @@ -215,9 +215,9 @@ static unsigned int mt_id(const message_type * mtype) const message_type *mt_register(message_type * type) { unsigned int hash = hashstring(type->name) % MT_MAXHASH; - quicklist **qlp = messagetypes + hash; + selist **qlp = messagetypes + hash; - if (ql_set_insert(qlp, type)) { + if (selist_set_insert(qlp, type, NULL)) { type->key = mt_id(type); } return type; diff --git a/src/wormhole.c b/src/wormhole.c index 46425a0c1..462f4e637 100644 --- a/src/wormhole.c +++ b/src/wormhole.c @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include @@ -155,8 +155,8 @@ make_wormhole(const building_type * bt_wormhole, region * r1, region * r2) #define WORMHOLE_CHANCE 10000 -static void select_wormhole_regions(quicklist **rlistp, int *countp) { - quicklist *rlist = 0; +static void select_wormhole_regions(selist **rlistp, int *countp) { + selist *rlist = 0; region *r = regions; int count = 0; @@ -170,7 +170,7 @@ static void select_wormhole_regions(quicklist **rlistp, int *countp) { } if (r == NULL) break; - ql_push(&rlist, r); + selist_push(&rlist, r); ++count; r = r->next; } @@ -179,12 +179,12 @@ static void select_wormhole_regions(quicklist **rlistp, int *countp) { *rlistp = rlist; } -void sort_wormhole_regions(quicklist *rlist, region **match, int count) { - quicklist *ql; +void sort_wormhole_regions(selist *rlist, region **match, int count) { + selist *ql; int qi, i = 0; - for (ql = rlist, qi = 0; i != count; ql_advance(&ql, &qi, 1)) { - match[i++] = (region *)ql_get(ql, qi); + for (ql = rlist, qi = 0; i != count; selist_advance(&ql, &qi, 1)) { + match[i++] = (region *)selist_get(ql, qi); } qsort(match, count, sizeof(region *), cmp_age); } @@ -200,7 +200,7 @@ void make_wormholes(region **match, int count, const building_type *bt_wormhole) void wormholes_update(void) { const building_type *bt_wormhole = bt_find("wormhole"); - quicklist *rlist = 0; + selist *rlist = 0; int count = 0; region **match; @@ -214,7 +214,7 @@ void wormholes_update(void) } match = (region **)malloc(sizeof(region *) * count); sort_wormhole_regions(rlist, match, count); - ql_free(rlist); + selist_free(rlist); make_wormholes(match, count, bt_wormhole); free(match); } diff --git a/src/wormhole.test.c b/src/wormhole.test.c index ec93c5b4c..4f3036200 100644 --- a/src/wormhole.test.c +++ b/src/wormhole.test.c @@ -10,11 +10,11 @@ #include -#include +#include #include -void sort_wormhole_regions(quicklist *rlist, region **match, int count); +void sort_wormhole_regions(selist *rlist, region **match, int count); void make_wormholes(region **match, int count, const building_type *bt_wormhole); static void test_make_wormholes(CuTest *tc) { @@ -42,7 +42,7 @@ static void test_make_wormholes(CuTest *tc) { static void test_sort_wormhole_regions(CuTest *tc) { region *r1, *r2, *match[2]; terrain_type *t_plain; - quicklist *rlist = 0; + selist *rlist = 0; test_setup(); t_plain = test_create_terrain("plain", LAND_REGION); @@ -50,12 +50,12 @@ static void test_sort_wormhole_regions(CuTest *tc) { r2 = test_create_region(1, 0, t_plain); r1->age = 4; r2->age = 2; - ql_push(&rlist, r1); - ql_push(&rlist, r2); + selist_push(&rlist, r1); + selist_push(&rlist, r2); sort_wormhole_regions(rlist, match, 2); CuAssertPtrEquals(tc, r2, match[0]); CuAssertPtrEquals(tc, r1, match[1]); - ql_free(rlist); + selist_free(rlist); test_cleanup(); }