diff --git a/s/build b/s/build index 1d580a349..178fa4f43 100755 --- a/s/build +++ b/s/build @@ -42,5 +42,7 @@ fi echo "build eressea" cd $ROOT/$BUILD +VERSION=$(git describe --match 'v*.*.*' --tags | sed 's/^v//') +cmake -DERESSEA_VERSION="$VERSION" .. make $MAKEOPTS && make test cd $OLDPWD diff --git a/s/release b/s/release index a5e4acf94..89b2bd9e9 100755 --- a/s/release +++ b/s/release @@ -3,19 +3,8 @@ import os import sys -template="""#define VERSION_MAJOR %s -#define VERSION_MINOR %s -#define VERSION_BUILD %s -""" - def new_version(ver): - sp = ver.split(".") - sp = (sp[0], sp[1], sp[2]) - file = open("src/buildno.h", "w") - file.write(template % sp) - file.close() - os.system("git add src/buildno.h") - os.system("git commit -m 'release version %s'" % ver) os.system("git tag -f v%s" % ver) + os.system("git push --tags") new_version(sys.argv[1]) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a0e1325b9..f1414c851 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,10 @@ include_directories (${TOLUA_INCLUDE_DIR}) include_directories (${BSON_INCLUDE_DIR}) include_directories (${INIPARSER_INCLUDE_DIR}) +IF(DEFINED ERESSEA_VERSION) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DERESSEA_VERSION=\\\"${ERESSEA_VERSION}\\\"") +ENDIF() + IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) # SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wno-sign-conversion") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wsign-compare -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long") @@ -194,6 +198,7 @@ set(TESTS_SRC volcano.test.c reports.test.c seen.test.c + summary.test.c travelthru.test.c callback.test.c direction.test.c diff --git a/src/attributes/dict.c b/src/attributes/dict.c index fa65d1f3d..cb24b148b 100644 --- a/src/attributes/dict.c +++ b/src/attributes/dict.c @@ -27,7 +27,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include /* util includes */ #include diff --git a/src/attributes/hate.c b/src/attributes/hate.c index 3d9a2fb0a..98a36a029 100644 --- a/src/attributes/hate.c +++ b/src/attributes/hate.c @@ -21,7 +21,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "hate.h" #include -#include #include #include diff --git a/src/attributes/targetregion.c b/src/attributes/targetregion.c index b293b458c..93ef08d0b 100644 --- a/src/attributes/targetregion.c +++ b/src/attributes/targetregion.c @@ -22,7 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include diff --git a/src/bind_storage.c b/src/bind_storage.c index 5dfca8c89..489255d3f 100644 --- a/src/bind_storage.c +++ b/src/bind_storage.c @@ -15,7 +15,6 @@ without prior permission by the authors of Eressea. #include "bind_storage.h" #include -#include #include #include diff --git a/src/bindings.c b/src/bindings.c index b95b1f9f0..9d74719f7 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -566,6 +566,9 @@ static int tolua_write_summary(lua_State * L) struct summary *sum_end = make_summary(); report_summary(sum_end, sum_begin, false); report_summary(sum_end, sum_begin, true); + free_summary(sum_end); + free_summary(sum_begin); + sum_begin = 0; return 0; } return 0; diff --git a/src/building_action.c b/src/building_action.c index b6ce0f72c..5c533f4d0 100644 --- a/src/building_action.c +++ b/src/building_action.c @@ -13,7 +13,6 @@ without prior permission by the authors of Eressea. #include #include #include -#include #include #include #include diff --git a/src/buildno.h b/src/buildno.h deleted file mode 100644 index 72049c497..000000000 --- a/src/buildno.h +++ /dev/null @@ -1,3 +0,0 @@ -#define VERSION_MAJOR 3 -#define VERSION_MINOR 10 -#define VERSION_BUILD 0 diff --git a/src/calendar.c b/src/calendar.c index 0f4617642..7a27328a7 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -38,22 +38,34 @@ void calendar_cleanup(void) free(agename); - for (i = 0; i != seasons; ++i) { - free(seasonnames[i]); + if (seasonnames) { + for (i = 0; i != seasons; ++i) { + free(seasonnames[i]); + } + free(seasonnames); + seasonnames = 0; } - free(seasonnames); - for (i = 0; i != months_per_year; ++i) { - free(monthnames[i]); + if (monthnames) { + for (i = 0; i != months_per_year; ++i) { + free(monthnames[i]); + } + free(storms); + storms = 0; + free(month_season); + month_season = 0; + free(monthnames); + monthnames = 0; } - free(storms); - free(month_season); - free(monthnames); for (i = 0; i != weeks_per_month; ++i) { - free(weeknames[i]); - free(weeknames2[i]); + if (weeknames) + free(weeknames[i]); + if (weeknames2) + free(weeknames2[i]); } free(weeknames); + weeknames = 0; free(weeknames2); + weeknames2 = 0; } diff --git a/src/creport.c b/src/creport.c index 39ecd9c2b..4cf778f23 100644 --- a/src/creport.c +++ b/src/creport.c @@ -9,7 +9,7 @@ without prior permission by the authors of Eressea. #include #include -#include "buildno.h" +#include #include "creport.h" #include "seen.h" #include "travelthru.h" @@ -1515,7 +1515,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset) fprintf(F, "%d;Basis\n", 36); fprintf(F, "%d;Runde\n", turn); fprintf(F, "%d;Zeitalter\n", era); - fprintf(F, "\"%d.%d.%d\";Build\n", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD); + fprintf(F, "\"%s\";Build\n", ERESSEA_VERSION); if (mailto != NULL) { fprintf(F, "\"%s\";mailto\n", mailto); fprintf(F, "\"%s\";mailcmd\n", LOC(f->locale, "mailcmd")); diff --git a/src/eressea.c b/src/eressea.c index c1ae4d73a..1fc69762b 100755 --- a/src/eressea.c +++ b/src/eressea.c @@ -26,6 +26,7 @@ #include #include +#include "calendar.h" #include "chaos.h" #include "creport.h" #include "items.h" @@ -50,8 +51,8 @@ void game_done(void) #ifdef REPORT_FORMAT_NR report_cleanup(); #endif - calendar_cleanup(); #endif + calendar_cleanup(); free_functions(); free_config(); free_locales(); diff --git a/src/gmtool.c b/src/gmtool.c index 7a87e4ae6..47b7794a2 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -44,7 +44,6 @@ #include #include #include -#include #include #include diff --git a/src/helpers.c b/src/helpers.c index 3d08f1c08..aa9bc12eb 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -31,7 +31,6 @@ without prior permission by the authors of Eressea. #include #include #include -#include #include diff --git a/src/kernel/building.c b/src/kernel/building.c index e4ae8f991..60b588912 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -30,7 +30,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "skill.h" #include "save.h" #include "lighthouse.h" -#include "version.h" /* util includes */ #include diff --git a/src/kernel/connection.c b/src/kernel/connection.c index ef86f9a3a..9bbff5778 100644 --- a/src/kernel/connection.c +++ b/src/kernel/connection.c @@ -24,7 +24,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "save.h" #include "terrain.h" #include "unit.h" -#include "version.h" #include #include diff --git a/src/kernel/curse.c b/src/kernel/curse.c index 612127182..646c99687 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -30,7 +30,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "ship.h" #include "skill.h" #include "unit.h" -#include "version.h" /* util includes */ #include diff --git a/src/kernel/curse.test.c b/src/kernel/curse.test.c index 2be81b19c..6514b2f3e 100644 --- a/src/kernel/curse.test.c +++ b/src/kernel/curse.test.c @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include diff --git a/src/kernel/faction.c b/src/kernel/faction.c index c1429f4f3..69231ff43 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -33,7 +33,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "spellbook.h" #include "terrain.h" #include "unit.h" -#include "version.h" /* util includes */ #include @@ -336,7 +335,39 @@ void write_faction_reference(const faction * f, struct storage *store) WRITE_INT(store, f ? f->no : 0); } -static faction *dead_factions; +#define DMAXHASH 7919 +typedef struct dead { + struct dead *nexthash; + faction *f; + int no; +} dead; + +static dead *deadhash[DMAXHASH]; + +void dhash(int no, faction * f) +{ + dead *hash = (dead *)calloc(1, sizeof(dead)); + dead *old = deadhash[no % DMAXHASH]; + hash->no = no; + hash->f = f; + deadhash[no % DMAXHASH] = hash; + hash->nexthash = old; +} + +faction *dfindhash(int no) +{ + dead *old; + + if (no < 0) + return 0; + + for (old = deadhash[no % DMAXHASH]; old; old = old->nexthash) { + if (old->no == no) { + return old->f; + } + } + return 0; +} void free_flist(faction **fp) { faction * flist = *fp; @@ -349,10 +380,7 @@ void free_flist(faction **fp) { *fp = 0; } -void free_factions(void) { - free_flist(&factions); - free_flist(&dead_factions); -} +static faction *dead_factions; void destroyfaction(faction ** fp) { @@ -814,40 +842,6 @@ int max_magicians(const faction * f) return m; } -#define DMAXHASH 7919 -typedef struct dead { - struct dead *nexthash; - faction *f; - int no; -} dead; - -static dead *deadhash[DMAXHASH]; - -void dhash(int no, faction * f) -{ - dead *hash = (dead *)calloc(1, sizeof(dead)); - dead *old = deadhash[no % DMAXHASH]; - hash->no = no; - hash->f = f; - deadhash[no % DMAXHASH] = hash; - hash->nexthash = old; -} - -faction *dfindhash(int no) -{ - dead *old; - - if (no < 0) - return 0; - - for (old = deadhash[no % DMAXHASH]; old; old = old->nexthash) { - if (old->no == no) { - return old->f; - } - } - return 0; -} - int writepasswd(void) { FILE *F; @@ -872,3 +866,15 @@ int writepasswd(void) return 1; } +void free_factions(void) { + int i; + for (i = 0; i != DMAXHASH; ++i) { + while (deadhash[i]) { + dead *d = deadhash[i]; + deadhash[i] = d->nexthash; + } + } + free_flist(&factions); + free_flist(&dead_factions); +} + diff --git a/src/kernel/group.c b/src/kernel/group.c index 19f816b13..054cf44dc 100755 --- a/src/kernel/group.c +++ b/src/kernel/group.c @@ -25,7 +25,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "faction.h" #include "save.h" #include "unit.h" -#include "version.h" /* attrib includes */ #include @@ -125,10 +124,14 @@ attrib_type at_group = { /* attribute for units assigned to a group */ void free_group(group * g) { - int index = g->gid % GMAXHASH; - group **g_ptr = ghash + index; - while (*g_ptr && (*g_ptr)->gid != g->gid) + int index; + group **g_ptr; + assert(g); + index = g->gid % GMAXHASH; + g_ptr = ghash + index; + while (*g_ptr && (*g_ptr)->gid != g->gid) { g_ptr = &(*g_ptr)->nexthash; + } assert(*g_ptr == g); *g_ptr = g->nexthash; diff --git a/src/kernel/group.test.c b/src/kernel/group.test.c index 7fa7fa234..22d55e36f 100644 --- a/src/kernel/group.test.c +++ b/src/kernel/group.test.c @@ -7,7 +7,6 @@ #include "unit.h" #include "region.h" #include "save.h" -#include "version.h" #include #include @@ -91,6 +90,7 @@ static void test_group_readwrite(CuTest * tc) write_groups(&store, f); WRITE_INT(&store, 47); + free_group(f->groups); free_group(g); f->groups = 0; data.strm.api->rewind(data.strm.handle); diff --git a/src/kernel/race.c b/src/kernel/race.c index b6a80e864..57f443ea5 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -34,7 +34,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "skill.h" #include "terrain.h" #include "unit.h" -#include "version.h" /* util includes */ #include diff --git a/src/kernel/region.c b/src/kernel/region.c index b04dc6709..d6aa9ef27 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -37,7 +37,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "terrain.h" #include "terrainid.h" #include "unit.h" -#include "version.h" /* util includes */ #include diff --git a/src/kernel/save.c b/src/kernel/save.c index fccd8468e..ea2208302 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -18,10 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include #include "save.h" -#include - #include "alchemy.h" #include "alliance.h" #include "ally.h" @@ -47,7 +46,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "terrainid.h" /* only for conversion code */ #include "unit.h" #include "lighthouse.h" -#include "version.h" /* attributes includes */ #include @@ -1860,6 +1858,12 @@ static void clear_npc_orders(faction *f) } } +int version_no(const char *str) { + int maj = 0, min = 0, bld = 0; + sscanf(str, "%d.%d.%d", &maj, &min, &bld); + return (maj << 16) | (min << 8) | bld; +} + int writegame(const char *filename) { int n; @@ -1890,7 +1894,7 @@ int writegame(const char *filename) fstream_init(&strm, F); binstore_init(&store, &strm); - WRITE_INT(&store, VERSION_BUILD); + WRITE_INT(&store, version_no(ERESSEA_VERSION)); n = write_game(&gdata); binstore_done(&store); fstream_done(&strm); diff --git a/src/kernel/save.h b/src/kernel/save.h index 3cd443926..27dd56661 100644 --- a/src/kernel/save.h +++ b/src/kernel/save.h @@ -79,6 +79,7 @@ extern "C" { int write_game(struct gamedata *data); int read_game(struct gamedata *data); + int version_no(const char *str); /* test-only functions that give access to internal implementation details (BAD) */ void _test_write_password(struct gamedata *data, const struct faction *f); diff --git a/src/kernel/save.test.c b/src/kernel/save.test.c index 9ab6c4d50..213543b77 100644 --- a/src/kernel/save.test.c +++ b/src/kernel/save.test.c @@ -11,7 +11,6 @@ #include "faction.h" #include "plane.h" #include "region.h" -#include "version.h" #include #include @@ -34,7 +33,7 @@ static void test_readwrite_data(CuTest * tc) { const char *filename = "test.dat"; char path[MAX_PATH]; - test_cleanup(); + test_setup(); CuAssertIntEquals(tc, 0, writegame(filename)); CuAssertIntEquals(tc, 0, readgame(filename, false)); join_path(datapath(), filename, path, sizeof(path)); @@ -51,7 +50,7 @@ static void test_readwrite_unit(CuTest * tc) struct faction *f; int fno; - test_cleanup(); + test_setup(); r = test_create_region(0, 0, 0); f = test_create_faction(0); fno = f->no; @@ -64,15 +63,17 @@ static void test_readwrite_unit(CuTest * tc) data.strm.api->rewind(data.strm.handle); free_gamedata(); f = test_create_faction(0); + r = test_create_region(0, 0, 0); renumber_faction(f, fno); gamedata_init(&data, &store, RELEASE_VERSION); u = read_unit(&data); - mstream_done(&data.strm); - gamedata_done(&data); - CuAssertPtrNotNull(tc, u); CuAssertPtrEquals(tc, f, u->faction); CuAssertPtrEquals(tc, 0, u->region); + + mstream_done(&data.strm); + gamedata_done(&data); + move_unit(u, r, NULL); // this makes sure that u doesn't leak test_cleanup(); } @@ -81,7 +82,7 @@ static void test_readwrite_attrib(CuTest *tc) { storage store; attrib *a = NULL; - test_cleanup(); + test_setup(); key_set(&a, 41); key_set(&a, 42); mstream_init(&data.strm); @@ -260,6 +261,7 @@ static void test_read_password(CuTest *tc) { storage store; faction *f; + test_setup(); f = test_create_faction(0); faction_setpassword(f, password_encode("secret", PASSWORD_DEFAULT)); mstream_init(&data.strm); @@ -270,6 +272,7 @@ static void test_read_password(CuTest *tc) { mstream_done(&data.strm); gamedata_done(&data); CuAssertTrue(tc, checkpasswd(f, "secret")); + test_cleanup(); } static void test_read_password_external(CuTest *tc) { @@ -279,6 +282,7 @@ static void test_read_password_external(CuTest *tc) { faction *f; FILE * F; + test_setup(); remove(pwfile); f = test_create_faction(0); faction_setpassword(f, password_encode("secret", PASSWORD_DEFAULT)); @@ -305,6 +309,13 @@ static void test_read_password_external(CuTest *tc) { mstream_done(&data.strm); gamedata_done(&data); CuAssertIntEquals(tc, 0, remove(pwfile)); + test_cleanup(); +} + +static void test_version_no(CuTest *tc) { + CuAssertIntEquals(tc, 0, version_no("0.0.0-devel")); + CuAssertIntEquals(tc, 0x10000, version_no("1.0.0-test")); + CuAssertIntEquals(tc, 0x10203, version_no("1.2.3-what.is.42")); } CuSuite *get_save_suite(void) @@ -319,5 +330,7 @@ CuSuite *get_save_suite(void) SUITE_ADD_TEST(suite, test_readwrite_dead_faction_group); SUITE_ADD_TEST(suite, test_read_password); SUITE_ADD_TEST(suite, test_read_password_external); + SUITE_ADD_TEST(suite, test_version_no); + return suite; } diff --git a/src/kernel/version.h b/src/kernel/version.h index 4aab16f5f..5b3bf0cf6 100644 --- a/src/kernel/version.h +++ b/src/kernel/version.h @@ -8,40 +8,9 @@ This program may not be used, modified or distributed without prior permission by the authors of Eressea. - */ -#define INTPAK_VERSION 329 /* in binary, ints can get packed. starting with E2/572 */ -#define NOZEROIDS_VERSION 330 /* 2008-05-16 zero is not a valid ID for anything (including factions) */ -#define NOBORDERATTRIBS_VERSION 331 /* 2008-05-17 connection::attribs has been moved to userdata */ -#define UIDHASH_VERSION 332 /* 2008-05-22 borders use the region.uid to store */ -#define REGIONOWNER_VERSION 333 /* 2009-05-14 regions have owners and morale */ -#define ALLIANCELEADER_VERSION 333 /* alliances have a leader */ -#define CURSEFLOAT_VERSION 334 /* all curse-effects are float */ -#define MOURNING_VERSION 335 /* mourning peasants */ -#define FOSS_VERSION 336 /* the open source release */ -#define OWNER_2_VERSION 337 /* region owners contain an alliance */ -#define FIX_WATCHERS_VERSION 338 /* fixed storage of watchers */ -#define UNIQUE_SPELLS_VERSION 339 /* turn 775, spell names are now unique globally, not just per school */ -#define SPELLBOOK_VERSION 340 /* turn 775, full spellbooks are stored for factions */ -#define NOOVERRIDE_VERSION 341 /* turn 775, full spellbooks are stored for factions */ -#define INTFLAGS_VERSION 342 /* turn 876, FFL_NPC is now bit 25, flags is an int */ -#define SAVEGAMEID_VERSION 343 /* instead of XMLNAME, save the game.id parameter from the config */ -#define BUILDNO_VERSION 344 /* storing the build number in the save */ -#define AUTO_RACENAME_VERSION 345 /* NPC units with name==NULL will automatically get their race for a name */ -#define JSON_REPORT_VERSION 346 /* bit 3 in f->options flags the json report */ -#define EXPLICIT_CURSE_ISNEW_VERSION 347 /* CURSE_ISNEW is not reset in read/write, but in age() */ -#define SPELL_LEVEL_VERSION 348 /* f->max_spelllevel gets stored, not calculated */ -#define OWNER_3_VERSION 349 /* regions store last owner, not last alliance */ -#define ATTRIBOWNER_VERSION 351 /* all attrib_type functions know who owns the attribute */ -#define BADCRYPT_VERSION 351 /* passwords are broken, 969.dat only. */ -#define NOCRYPT_VERSION 352 /* passwords are plaintext again */ -#define ATHASH_VERSION 353 /* attribute-type hash, not name */ -#define NOWATCH_VERSION 354 /* plane->watchers is gone */ -/* unfinished: */ -#define CRYPT_VERSION 400 /* passwords are encrypted */ -#define RELEASE_VERSION NOWATCH_VERSION /* current datafile */ -#define MIN_VERSION INTPAK_VERSION /* minimal datafile we support */ -#define MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */ - -#define STREAM_VERSION 2 /* internal encoding of binary files */ +#ifndef ERESSEA_VERSION +// the version number, if it was not passed to make with -D +#define ERESSEA_VERSION "3.10.0-devel" +#endif diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 19d661cc6..f3f866351 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -471,6 +471,8 @@ static int parse_calendar(xmlDocPtr doc) } xmlXPathFreeObject(xpathMonths); xmlXPathFreeObject(xpathSeasons); + xmlFree(newyear); + newyear = NULL; } xmlXPathFreeObject(xpathCalendars); xmlXPathFreeContext(xpath); diff --git a/src/magic.c b/src/magic.c index 6ff2ac8e5..1c4ca2adb 100644 --- a/src/magic.c +++ b/src/magic.c @@ -44,7 +44,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include diff --git a/src/main.c b/src/main.c index d011a473b..3748c2d49 100644 --- a/src/main.c +++ b/src/main.c @@ -20,8 +20,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include #include +#include #include #include #include "eressea.h" @@ -29,7 +29,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "gmtool.h" #endif -#include "buildno.h" #include "bindings.h" #include "races/races.h" #include "spells.h" @@ -166,8 +165,8 @@ static int parse_args(int argc, char **argv, int *exitcode) if (strcmp(argi + 2, "version") == 0) { printf("\n%s PBEM host\n" "Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n" - "Compilation: " __DATE__ " at " __TIME__ "\nVersion: %d.%d.%d\n\n", - game_name(), VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD); + "Compilation: " __DATE__ " at " __TIME__ "\nVersion: %s\n\n", + game_name(), ERESSEA_VERSION); #ifdef USE_CURSES } else if (strcmp(argi + 2, "color") == 0) { diff --git a/src/spells.c b/src/spells.c index e4bccadc8..ab4d6dd6d 100644 --- a/src/spells.c +++ b/src/spells.c @@ -53,7 +53,6 @@ #include #include #include -#include #include diff --git a/src/spells/borders.c b/src/spells/borders.c index 2c222a9dd..474d37796 100644 --- a/src/spells/borders.c +++ b/src/spells/borders.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include diff --git a/src/spells/flyingship.c b/src/spells/flyingship.c index 1b6b56d26..4a3c62e5e 100644 --- a/src/spells/flyingship.c +++ b/src/spells/flyingship.c @@ -1,6 +1,5 @@ #include #include -#include #include "flyingship.h" #include diff --git a/src/spells/shipcurse.c b/src/spells/shipcurse.c index 75e07a4ca..8da3c7c89 100644 --- a/src/spells/shipcurse.c +++ b/src/spells/shipcurse.c @@ -13,7 +13,6 @@ #include #include -#include #include "shipcurse.h" /* kernel includes */ diff --git a/src/spells/unitcurse.c b/src/spells/unitcurse.c index c29935479..944db2032 100644 --- a/src/spells/unitcurse.c +++ b/src/spells/unitcurse.c @@ -22,7 +22,6 @@ #include #include #include -#include /* util includes */ #include diff --git a/src/summary.c b/src/summary.c index 6378f3d7f..cbc998b4a 100644 --- a/src/summary.c +++ b/src/summary.c @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -78,28 +79,34 @@ int update_nmrs(void) int i, newplayers = 0; faction *f; int turn = global.data_turn; + int timeout = NMRTimeout(); - if (nmrs == NULL) - nmrs = malloc(sizeof(int) * (NMRTimeout() + 1)); - for (i = 0; i <= NMRTimeout(); ++i) { - nmrs[i] = 0; + if (timeout>0) { + if (nmrs == NULL) { + nmrs = malloc(sizeof(int) * (timeout + 1)); + } + for (i = 0; i <= timeout; ++i) { + nmrs[i] = 0; + } } - + for (f = factions; f; f = f->next) { if (fval(f, FFL_ISNEW)) { ++newplayers; } else if (!fval(f, FFL_NOIDLEOUT|FFL_CURSED)) { int nmr = turn - f->lastorders + 1; - if (nmr < 0 || nmr > NMRTimeout()) { - log_error("faction %s has %d NMR", factionid(f), nmr); - nmr = _max(0, nmr); - nmr = _min(nmr, NMRTimeout()); + if (timeout>0) { + if (nmr < 0 || nmr > timeout) { + log_error("faction %s has %d NMR", factionid(f), nmr); + nmr = _max(0, nmr); + nmr = _min(nmr, timeout); + } + if (nmr > 0) { + log_debug("faction %s has %d NMR", factionid(f), nmr); + } + ++nmrs[nmr]; } - if (nmr > 0) { - log_debug("faction %s has %d NMR", factionid(f), nmr); - } - ++nmrs[nmr]; } } return newplayers; @@ -141,11 +148,18 @@ static char *gamedate2(const struct locale *lang) { static char buf[256]; gamedate gd; + const char *week = "a_week", *month = "a_month"; get_gamedate(turn, &gd); + if (weeknames2) { + week = weeknames2[gd.week]; + } + if (monthnames) { + month = monthnames[gd.month]; + } sprintf(buf, "in %s des Monats %s im Jahre %d %s.", - LOC(lang, weeknames2[gd.week]), - LOC(lang, monthnames[gd.month]), + LOC(lang, week), + LOC(lang, month), gd.year, agename ? LOC(lang, agename) : ""); return buf; } @@ -179,6 +193,7 @@ void report_summary(summary * s, summary * o, bool full) int i, newplayers = 0; faction *f; char zText[MAX_PATH]; + int timeout = NMRTimeout(); if (full) { join_path(basepath(), "parteien.full", zText, sizeof(zText)); @@ -295,12 +310,14 @@ void report_summary(summary * s, summary * o, bool full) newplayers = update_nmrs(); - for (i = 0; i <= NMRTimeout(); ++i) { - if (i == NMRTimeout()) { - fprintf(F, "+ NMR:\t\t %d\n", nmrs[i]); - } - else { - fprintf(F, "%d NMR:\t\t %d\n", i, nmrs[i]); + if (nmrs) { + for (i = 0; i <= timeout; ++i) { + if (i == timeout) { + fprintf(F, "+ NMR:\t\t %d\n", nmrs[i]); + } + else { + fprintf(F, "%d NMR:\t\t %d\n", i, nmrs[i]); + } } } if (age) { @@ -314,18 +331,18 @@ void report_summary(summary * s, summary * o, bool full) fprintf(F, "Neue Spieler:\t %d\n", newplayers); if (full) { - if (factions) + if (factions) { fprintf(F, "\nParteien:\n\n"); - - for (f = factions; f; f = f->next) { - out_faction(F, f); + for (f = factions; f; f = f->next) { + out_faction(F, f); + } } - if (NMRTimeout() && full) { + if (timeout>0 && full) { fprintf(F, "\n\nFactions with NMRs:\n"); - for (i = NMRTimeout(); i > 0; --i) { + for (i = timeout; i > 0; --i) { for (f = factions; f; f = f->next) { - if (i == NMRTimeout()) { + if (i == timeout) { if (turn - f->lastorders >= i) { out_faction(F, f); } @@ -350,6 +367,15 @@ void report_summary(summary * s, summary * o, bool full) nmrs = NULL; } +void free_summary(summary *sum) { + while (sum->languages) { + struct language *next = sum->languages->next; + free(sum->languages); + sum->languages = next; + } + free(sum); +} + summary *make_summary(void) { faction *f; diff --git a/src/summary.h b/src/summary.h index aa1491a21..ea8daeee1 100644 --- a/src/summary.h +++ b/src/summary.h @@ -19,7 +19,7 @@ extern "C" { void report_summary(struct summary *n, struct summary *o, bool full); struct summary *make_summary(void); - + void free_summary(struct summary *sum); int update_nmrs(void); extern int* nmrs; diff --git a/src/summary.test.c b/src/summary.test.c new file mode 100644 index 000000000..33dc874b3 --- /dev/null +++ b/src/summary.test.c @@ -0,0 +1,29 @@ +#include + +#include "summary.h" +#include "calendar.h" + +#include +#include "tests.h" + +#include + +static void test_summary(CuTest * tc) +{ + struct summary *sum; + test_setup(); + test_create_faction(0); + test_create_faction(0); + sum = make_summary(); + report_summary(sum, sum, true); + CuAssertIntEquals(tc, 0, remove("parteien.full")); + free_summary(sum); + test_cleanup(); +} + +CuSuite *get_summary_suite(void) +{ + CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_summary); + return suite; +} diff --git a/src/test_eressea.c b/src/test_eressea.c index 18eafcf3a..0f6fc3522 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -112,6 +112,7 @@ int RunAllTests(int argc, char *argv[]) ADD_SUITE(messages); /* gamecode */ ADD_SUITE(prefix); + ADD_SUITE(summary); ADD_SUITE(names); ADD_SUITE(battle); ADD_SUITE(volcano); diff --git a/src/triggers/createcurse.c b/src/triggers/createcurse.c index d0d65571b..fe39e8b7f 100644 --- a/src/triggers/createcurse.c +++ b/src/triggers/createcurse.c @@ -21,7 +21,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "createcurse.h" /* kernel includes */ -#include #include #include diff --git a/src/triggers/createunit.c b/src/triggers/createunit.c index 6e98901ca..2fec00ade 100644 --- a/src/triggers/createunit.c +++ b/src/triggers/createunit.c @@ -25,7 +25,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include /* util includes */ #include diff --git a/src/triggers/gate.c b/src/triggers/gate.c index 2a9c5693d..acf2bb5d4 100644 --- a/src/triggers/gate.c +++ b/src/triggers/gate.c @@ -17,7 +17,6 @@ #include #include #include -#include /* util includes */ #include diff --git a/src/util/gamedata.h b/src/util/gamedata.h index e75f7d681..bb1632838 100644 --- a/src/util/gamedata.h +++ b/src/util/gamedata.h @@ -5,6 +5,42 @@ #include +#define INTPAK_VERSION 329 /* in binary, ints can get packed. starting with E2/572 */ +#define NOZEROIDS_VERSION 330 /* 2008-05-16 zero is not a valid ID for anything (including factions) */ +#define NOBORDERATTRIBS_VERSION 331 /* 2008-05-17 connection::attribs has been moved to userdata */ +#define UIDHASH_VERSION 332 /* 2008-05-22 borders use the region.uid to store */ +#define REGIONOWNER_VERSION 333 /* 2009-05-14 regions have owners and morale */ +#define ALLIANCELEADER_VERSION 333 /* alliances have a leader */ +#define CURSEFLOAT_VERSION 334 /* all curse-effects are float */ +#define MOURNING_VERSION 335 /* mourning peasants */ +#define FOSS_VERSION 336 /* the open source release */ +#define OWNER_2_VERSION 337 /* region owners contain an alliance */ +#define FIX_WATCHERS_VERSION 338 /* fixed storage of watchers */ +#define UNIQUE_SPELLS_VERSION 339 /* turn 775, spell names are now unique globally, not just per school */ +#define SPELLBOOK_VERSION 340 /* turn 775, full spellbooks are stored for factions */ +#define NOOVERRIDE_VERSION 341 /* turn 775, full spellbooks are stored for factions */ +#define INTFLAGS_VERSION 342 /* turn 876, FFL_NPC is now bit 25, flags is an int */ +#define SAVEGAMEID_VERSION 343 /* instead of XMLNAME, save the game.id parameter from the config */ +#define BUILDNO_VERSION 344 /* storing the build number in the save */ +#define AUTO_RACENAME_VERSION 345 /* NPC units with name==NULL will automatically get their race for a name */ +#define JSON_REPORT_VERSION 346 /* bit 3 in f->options flags the json report */ +#define EXPLICIT_CURSE_ISNEW_VERSION 347 /* CURSE_ISNEW is not reset in read/write, but in age() */ +#define SPELL_LEVEL_VERSION 348 /* f->max_spelllevel gets stored, not calculated */ +#define OWNER_3_VERSION 349 /* regions store last owner, not last alliance */ +#define ATTRIBOWNER_VERSION 351 /* all attrib_type functions know who owns the attribute */ +#define BADCRYPT_VERSION 351 /* passwords are broken, 969.dat only. */ +#define NOCRYPT_VERSION 352 /* passwords are plaintext again */ +#define ATHASH_VERSION 353 /* attribute-type hash, not name */ +#define NOWATCH_VERSION 354 /* plane->watchers is gone */ +/* unfinished: */ +#define CRYPT_VERSION 400 /* passwords are encrypted */ + +#define RELEASE_VERSION NOWATCH_VERSION /* current datafile */ +#define MIN_VERSION INTPAK_VERSION /* minimal datafile we support */ +#define MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */ + +#define STREAM_VERSION 2 /* internal encoding of binary files */ + struct storage; typedef struct gamedata { diff --git a/src/vortex.c b/src/vortex.c index 4b512476b..244c83a29 100644 --- a/src/vortex.c +++ b/src/vortex.c @@ -2,7 +2,6 @@ #include "vortex.h" #include -#include #include #include diff --git a/src/wormhole.c b/src/wormhole.c index 916c0509d..6a115a9f7 100644 --- a/src/wormhole.c +++ b/src/wormhole.c @@ -23,7 +23,6 @@ #include #include #include -#include /* util includes */ #include diff --git a/tests/test-turn.lua b/tests/test-turn.lua index 03178b74d..826ffc00f 100644 --- a/tests/test-turn.lua +++ b/tests/test-turn.lua @@ -3,3 +3,4 @@ turn = get_turn() eressea.free_game() print("trying to read data from " .. turn) eressea.read_game(turn .. ".dat") +eressea.free_game()