Merge pull request #562 from ennorehling/develop

memory leaks and new release management
This commit is contained in:
Enno Rehling 2016-09-10 20:07:21 +02:00 committed by GitHub
commit 56dc12d6fb
47 changed files with 251 additions and 176 deletions

View File

@ -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

View File

@ -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])

View File

@ -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

View File

@ -27,7 +27,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/save.h>
#include <kernel/ship.h>
#include <kernel/unit.h>
#include <kernel/version.h>
/* util includes */
#include <util/attrib.h>

View File

@ -21,7 +21,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "hate.h"
#include <kernel/unit.h>
#include <kernel/version.h>
#include <util/attrib.h>
#include <util/gamedata.h>

View File

@ -22,7 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include <kernel/region.h>
#include <kernel/save.h>
#include <kernel/version.h>
#include <util/attrib.h>
#include <util/gamedata.h>

View File

@ -15,7 +15,6 @@ without prior permission by the authors of Eressea.
#include "bind_storage.h"
#include <kernel/save.h>
#include <kernel/version.h>
#include <util/gamedata.h>
#include <util/log.h>

View File

@ -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;

View File

@ -13,7 +13,6 @@ without prior permission by the authors of Eressea.
#include <platform.h>
#include <kernel/config.h>
#include <kernel/building.h>
#include <kernel/version.h>
#include <util/attrib.h>
#include <util/gamedata.h>
#include <util/log.h>

View File

@ -1,3 +0,0 @@
#define VERSION_MAJOR 3
#define VERSION_MINOR 10
#define VERSION_BUILD 0

View File

@ -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;
}

View File

@ -9,7 +9,7 @@ without prior permission by the authors of Eressea.
#include <platform.h>
#include <kernel/config.h>
#include "buildno.h"
#include <kernel/version.h>
#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"));

View File

@ -26,6 +26,7 @@
#include <util/message.h>
#include <races/races.h>
#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();

View File

@ -44,7 +44,6 @@
#include <kernel/ship.h>
#include <kernel/terrain.h>
#include <kernel/xmlreader.h>
#include <kernel/version.h>
#include <attributes/attributes.h>
#include <triggers/triggers.h>

View File

@ -31,7 +31,6 @@ without prior permission by the authors of Eressea.
#include <kernel/building.h>
#include <kernel/item.h>
#include <kernel/region.h>
#include <kernel/version.h>
#include <storage.h>

View File

@ -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 <util/attrib.h>

View File

@ -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 <util/attrib.h>
#include <util/bsdstring.h>

View File

@ -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 <util/attrib.h>

View File

@ -4,7 +4,6 @@
#include <kernel/region.h>
#include <kernel/save.h>
#include <kernel/unit.h>
#include <kernel/version.h>
#include <util/attrib.h>
#include <util/gamedata.h>
#include <util/message.h>

View File

@ -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 <util/attrib.h>
@ -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);
}

View File

@ -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 <attributes/raceprefix.h>
@ -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;

View File

@ -7,7 +7,6 @@
#include "unit.h"
#include "region.h"
#include "save.h"
#include "version.h"
#include <util/gamedata.h>
#include <util/attrib.h>
@ -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);

View File

@ -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 <util/attrib.h>

View File

@ -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 <util/attrib.h>

View File

@ -18,10 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <platform.h>
#include <kernel/config.h>
#include <kernel/version.h>
#include "save.h"
#include <buildno.h>
#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 <attributes/key.h>
@ -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);

View File

@ -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);

View File

@ -11,7 +11,6 @@
#include "faction.h"
#include "plane.h"
#include "region.h"
#include "version.h"
#include <triggers/changefaction.h>
#include <triggers/createunit.h>
@ -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;
}

View File

@ -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

View File

@ -471,6 +471,8 @@ static int parse_calendar(xmlDocPtr doc)
}
xmlXPathFreeObject(xpathMonths);
xmlXPathFreeObject(xpathSeasons);
xmlFree(newyear);
newyear = NULL;
}
xmlXPathFreeObject(xpathCalendars);
xmlXPathFreeContext(xpath);

View File

@ -44,7 +44,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/spellbook.h>
#include <kernel/terrain.h>
#include <kernel/unit.h>
#include <kernel/version.h>
#include <triggers/timeout.h>
#include <triggers/shock.h>

View File

@ -20,8 +20,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/log.h>
#include <kernel/config.h>
#include <kernel/save.h>
#include <kernel/version.h>
#include <kernel/save.h>
#include <util/filereader.h>
#include <util/language.h>
#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) {

View File

@ -53,7 +53,6 @@
#include <kernel/terrainid.h>
#include <kernel/unit.h>
#include <kernel/xmlreader.h>
#include <kernel/version.h>
#include <races/races.h>

View File

@ -11,7 +11,6 @@
#include <kernel/save.h>
#include <kernel/terrain.h>
#include <kernel/unit.h>
#include <kernel/version.h>
#include <util/attrib.h>
#include <util/gamedata.h>

View File

@ -1,6 +1,5 @@
#include <platform.h>
#include <kernel/config.h>
#include <kernel/version.h>
#include "flyingship.h"
#include <kernel/build.h>

View File

@ -13,7 +13,6 @@
#include <platform.h>
#include <kernel/config.h>
#include <kernel/version.h>
#include "shipcurse.h"
/* kernel includes */

View File

@ -22,7 +22,6 @@
#include <kernel/unit.h>
#include <kernel/faction.h>
#include <kernel/objtypes.h>
#include <kernel/version.h>
/* util includes */
#include <util/gamedata.h>

View File

@ -32,6 +32,7 @@
#include <util/lists.h>
#include <util/log.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@ -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;

View File

@ -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;

29
src/summary.test.c Normal file
View File

@ -0,0 +1,29 @@
#include <platform.h>
#include "summary.h"
#include "calendar.h"
#include <CuTest.h>
#include "tests.h"
#include <stdio.h>
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;
}

View File

@ -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);

View File

@ -21,7 +21,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "createcurse.h"
/* kernel includes */
#include <kernel/version.h>
#include <kernel/curse.h>
#include <kernel/unit.h>

View File

@ -25,7 +25,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/unit.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/version.h>
/* util includes */
#include <util/attrib.h>

View File

@ -17,7 +17,6 @@
#include <kernel/building.h>
#include <kernel/region.h>
#include <kernel/unit.h>
#include <kernel/version.h>
/* util includes */
#include <util/attrib.h>

View File

@ -5,6 +5,42 @@
#include <stream.h>
#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 {

View File

@ -2,7 +2,6 @@
#include "vortex.h"
#include <kernel/config.h>
#include <kernel/version.h>
#include <kernel/region.h>
#include <util/attrib.h>

View File

@ -23,7 +23,6 @@
#include <kernel/plane.h>
#include <kernel/region.h>
#include <kernel/unit.h>
#include <kernel/version.h>
/* util includes */
#include <util/attrib.h>

View File

@ -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()