From 1052e46613fad0f1ad56abc95b43d8179a2cbd31 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 22 May 2008 10:46:02 +0000 Subject: [PATCH] http://eressea.upb.de/mantis/view.php?id=1429 - made startup regions more balanced implementing free_gamedata(): - cleaning up some static variables --- src/common/gamecode/economy.c | 102 +++++++++++++++++-------------- src/common/gamecode/laws.c | 7 ++- src/common/gamecode/monster.c | 6 +- src/common/gamecode/report.c | 17 ++++-- src/common/iniparser/iniparser.c | 4 +- src/common/kernel/battle.c | 6 +- src/common/kernel/calendar.c | 5 +- src/common/kernel/eressea.c | 36 +++++++++-- src/common/kernel/eressea.h | 2 +- src/common/kernel/faction.c | 7 ++- src/common/kernel/move.c | 22 +++++-- src/common/kernel/pathfinder.c | 2 +- src/common/kernel/region.c | 34 +++++------ src/common/kernel/region.h | 2 +- src/common/kernel/teleport.c | 15 +++-- src/common/modules/autoseed.c | 47 +++++++++----- src/common/util/base36.c | 6 +- src/common/util/goodies.c | 2 +- src/common/util/language.c | 2 +- src/common/util/log.c | 6 +- src/common/util/parser.c | 2 +- src/common/util/rand.c | 2 +- src/common/util/resolve.c | 3 +- src/common/util/sql.c | 4 +- src/common/util/strings.c | 2 +- src/common/util/translation.c | 2 +- src/common/util/umlaut.c | 2 +- src/common/util/windir.c | 6 +- src/eressea/korrektur.c | 24 +++----- src/eressea/lua/gamecode.cpp | 1 + src/eressea/server.cpp | 29 +-------- 31 files changed, 227 insertions(+), 180 deletions(-) diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index 7d0957fcb..f27c34a8c 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -439,11 +439,11 @@ expandrecruit(region * r, request * recruitorders) static void recruit(unit * u, struct order * ord, request ** recruitorders) { - int n; + int n; region * r = u->region; - plane * pl; - request *o; - int recruitcost; + plane * pl; + request *o; + int recruitcost; const faction * f = u->faction; const struct race * rc = f->race; @@ -457,45 +457,47 @@ recruit(unit * u, struct order * ord, request ** recruitorders) if (rc==NULL) rc = f->race; } -#if GUARD_DISABLES_RECRUIT == 1 - /* this is a very special case because the recruiting unit may be empty - * at this point and we have to look at the creating unit instead. This - * is done in cansee, which is called indirectly by is_guarded(). */ - if (is_guarded(r, u, GUARD_RECRUIT)) { +#if GUARD_DISABLES_RECRUIT + /* this is a very special case because the recruiting unit may be empty + * at this point and we have to look at the creating unit instead. This + * is done in cansee, which is called indirectly by is_guarded(). */ + if (is_guarded(r, u, GUARD_RECRUIT)) { cmistake(u, ord, 70, MSG_EVENT); - return; - } + return; + } #endif - if (rc == new_race[RC_INSECT]) { - if (get_gamedate(turn, 0)->season == 0 && rterrain(r) != T_DESERT) { + if (rc == new_race[RC_INSECT]) { + gamedate date; + get_gamedate(turn, &date); + if (date.season == 0 && rterrain(r) != T_DESERT) { #ifdef INSECT_POTION - boolean usepotion = false; - unit *u2; + boolean usepotion = false; + unit *u2; - for (u2 = r->units; u2; u2 = u2->next) - if (fval(u2, UFL_WARMTH)) { - usepotion = true; - break; - } - if (!usepotion) + for (u2 = r->units; u2; u2 = u2->next) + if (fval(u2, UFL_WARMTH)) { + usepotion = true; + break; + } + if (!usepotion) #endif - { - cmistake(u, ord, 98, MSG_EVENT); - return; - } - } - /* in Gletschern, Eisbergen gar nicht rekrutieren */ - if (r_insectstalled(r)) { + { + cmistake(u, ord, 98, MSG_EVENT); + return; + } + } + /* in Gletschern, Eisbergen gar nicht rekrutieren */ + if (r_insectstalled(r)) { cmistake(u, ord, 97, MSG_EVENT); - return; - } - } - if (is_cursed(r->attribs, C_RIOT, 0)) { - /* Die Region befindet sich in Aufruhr */ + return; + } + } + if (is_cursed(r->attribs, C_RIOT, 0)) { + /* Die Region befindet sich in Aufruhr */ cmistake(u, ord, 237, MSG_EVENT); - return; - } + return; + } if (!(rc->ec_flags & ECF_REC_HORSES) && fval(r, RF_ORCIFIED)) { if (rc != new_race[RC_URUK]) @@ -504,16 +506,16 @@ recruit(unit * u, struct order * ord, request ** recruitorders) return; } } - + recruitcost = rc->recruitcost; if (recruitcost) { pl = getplane(r); if (pl && fval(pl, PFL_NORECRUITS)) { ADDMSG(&u->faction->msgs, - msg_feedback(u, ord, "error_pflnorecruit", "")); + msg_feedback(u, ord, "error_pflnorecruit", "")); return; } - + if (get_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT, recruitcost) < recruitcost) { cmistake(u, ord, 142, MSG_EVENT); return; @@ -524,7 +526,7 @@ recruit(unit * u, struct order * ord, request ** recruitorders) return; } /* snotlinge sollten hiermit bereits abgefangen werden, die - * parteirasse ist uruk oder ork*/ + * parteirasse ist uruk oder ork*/ if (u->race != rc) { if (u->number != 0) { cmistake(u, ord, 139, MSG_EVENT); @@ -532,16 +534,16 @@ recruit(unit * u, struct order * ord, request ** recruitorders) } else u->race = rc; } - + if (has_skill(u, SK_MAGIC)) { /* error158;de;{unit} in {region}: '{command}' - Magier arbeiten - * grundsätzlich nur alleine! */ + * grundsätzlich nur alleine! */ cmistake(u, ord, 158, MSG_EVENT); return; } if (has_skill(u, SK_ALCHEMY) - && count_skill(u->faction, SK_ALCHEMY) + n > - max_skill(u->faction, SK_ALCHEMY)) + && count_skill(u->faction, SK_ALCHEMY) + n > + max_skill(u->faction, SK_ALCHEMY)) { cmistake(u, ord, 156, MSG_EVENT); return; @@ -550,9 +552,9 @@ recruit(unit * u, struct order * ord, request ** recruitorders) int pooled = get_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT, recruitcost * n); n = min(n, pooled / recruitcost); } - + u->wants = n; - + if (!n) { cmistake(u, ord, 142, MSG_EVENT); return; @@ -2542,9 +2544,15 @@ breedtrees(region *r, unit *u, int raw) { int n, i, skill, planted = 0; const resource_type * rtype; - static int current_season = -1; + static int thisturn = -1; + static int current_season; - if (current_season<0) current_season = get_gamedate(turn, NULL)->season; + if (thisturn!=turn) { + gamedate date; + get_gamedate(turn, &date); + current_season = date.season; + thisturn = turn; + } /* Bäume züchten geht nur im Frühling */ if (current_season != SEASON_SPRING){ diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 08cce2e11..77349dc65 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -780,8 +780,11 @@ demographics(void) static int current_season = -1; if (current_season<0) { - current_season = get_gamedate(turn, NULL)->season; - last_weeks_season = get_gamedate(turn-1, NULL)->season; + gamedate date; + get_gamedate(turn, &date); + current_season = date.season; + get_gamedate(turn-1, &date); + last_weeks_season = date.season; } for (r = regions; r; r = r->next) { diff --git a/src/common/gamecode/monster.c b/src/common/gamecode/monster.c index cc1c5ee39..1d3fbd1f4 100644 --- a/src/common/gamecode/monster.c +++ b/src/common/gamecode/monster.c @@ -450,9 +450,9 @@ set_new_dragon_target(unit * u, region * r, int range) static order * make_movement_order(unit * u, const region * target, int moves, boolean (*allowed)(const region *, const region *)) { - region * r = u->region; - region ** plan; - int bytes, position = 0; + region * r = u->region; + region ** plan; + int bytes, position = 0; char zOrder[128], * bufp = zOrder; size_t size = sizeof(zOrder) - 1; diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 3489ecfa9..6e5db4dc3 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -1918,6 +1918,19 @@ report_plaintext(const char * filename, report_context * ctx, const char * chars int enc = xmlParseCharEncoding(charset); size_t size; + /* static variables can cope with writing for different turns */ + static int thisseason = -1; + static int nextseason = -1; + static int thisturn = -1; + if (thisturn!=turn) { + gamedate date; + get_gamedate(turn+1, &date); + thisseason = date.season; + get_gamedate(turn+2, &date); + nextseason = date.season; + thisturn = turn; + } + if (F==NULL) { perror(filename); return -1; @@ -2033,14 +2046,10 @@ report_plaintext(const char * filename, report_context * ctx, const char * chars /* Insekten-Winter-Warnung */ if (f->race == new_race[RC_INSECT]) { - static int thisseason = -1; - if (thisseason<0) thisseason = get_gamedate(turn+1, 0)->season; if (thisseason == 0) { centre(F, LOC(f->locale, "nr_insectwinter"), true); rnl(F); } else { - static int nextseason = -1; - if (nextseason<0) nextseason = get_gamedate(turn+2, 0)->season; if (nextseason == 0) { centre(F, LOC(f->locale, "nr_insectfall"), true); rnl(F); diff --git a/src/common/iniparser/iniparser.c b/src/common/iniparser/iniparser.c index 02da9f42f..775c48a38 100644 --- a/src/common/iniparser/iniparser.c +++ b/src/common/iniparser/iniparser.c @@ -57,7 +57,7 @@ extern "C" { static char * strlwc(const char * s) { - static char l[ASCIILINESZ+1]; + static char l[ASCIILINESZ+1]; /* STATIC_RETURN: used for return, not across calls */ int i ; if (s==NULL) return NULL ; @@ -109,7 +109,7 @@ static char * strskp(char * s) static char * strcrop(char * s) { - static char l[ASCIILINESZ+1]; + static char l[ASCIILINESZ+1]; /* STATIC_RETURN: used for return, not across calls */ char * last ; if (s==NULL) return NULL ; diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index 5bea1db47..74308410f 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -157,8 +157,8 @@ static char * sidename(side * s) { #define SIDENAMEBUFLEN 256 - static int bufno; - static char sidename_buf[4][SIDENAMEBUFLEN]; + static int bufno; /* STATIC_XCALL: used across calls */ + static char sidename_buf[4][SIDENAMEBUFLEN]; /* STATIC_RESULT: used for return, not across calls */ bufno = bufno % 4; if (s->stealthfaction) { @@ -174,7 +174,7 @@ sidename(side * s) static const char * sideabkz(side *s, boolean truename) { - static char sideabkz_buf[8]; + static char sideabkz_buf[8]; /* STATIC_RESULT: used for return, not across calls */ if (s->stealthfaction && truename == false) { abkz(s->stealthfaction->name, sideabkz_buf, sizeof(sideabkz_buf), 3); diff --git a/src/common/kernel/calendar.c b/src/common/kernel/calendar.c index 4255b3074..3587c3131 100644 --- a/src/common/kernel/calendar.c +++ b/src/common/kernel/calendar.c @@ -1,6 +1,8 @@ #include #include "calendar.h" +#include + int first_turn = 0; int first_month = 0; int weeks_per_month = 0; @@ -16,11 +18,10 @@ int seasons = 0; const gamedate * get_gamedate(int turn, gamedate * gd) { - static gamedate staticdate; int weeks_per_year = months_per_year * weeks_per_month; int t = turn - first_turn; - if (gd==NULL) gd = &staticdate; + assert(gd); if (t<0) t = turn; gd->week = t%weeks_per_month; /* 0 - weeks_per_month-1 */ diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index a9bfaf028..0ae4be1ac 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -2493,17 +2493,18 @@ besieged(const unit * u) int lifestyle(const unit * u) { - static plane * astralspace = NULL; int need; + static plane * astralspace; + static int thisturn = -1; + if (thisturn!=turn) { + astralspace = getplanebyname("Astralraum"); + thisturn = turn; + } if (is_monsters(u->faction)) return 0; need = maintenance_cost(u); - if (!astralspace) { - astralspace = getplanebyname("Astralraum"); - } - if(u->region->planep && fval(u->region->planep, PFL_NOFEED)) return 0; @@ -2994,3 +2995,28 @@ entertainmoney(const region *r) return n; } + +/** releases all memory associated with the game state. + * call this function before calling read_game() to load a new game + * if you have a previously loaded state in memory. + */ +void +free_gamedata(void) +{ + free_units(); + free_regions(); + + while (factions) { + faction * f = factions; + factions = f->next; + stripfaction(f); + free(f); + } + + while (planes) { + plane * pl = planes; + planes = planes->next; + free(pl->name); + free(pl); + } +} \ No newline at end of file diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index 7d1ac8fda..9059149e5 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -410,7 +410,7 @@ extern int entertainmoney(const struct region * r); extern void plagues(struct region * r, boolean ismagic); extern struct attrib_type at_guard; - +extern void free_gamedata(void); #if 1 /* disable to count all units */ # define count_unit(u) playerrace(u->race) #else diff --git a/src/common/kernel/faction.c b/src/common/kernel/faction.c index 7b1c3d212..5420b6592 100644 --- a/src/common/kernel/faction.c +++ b/src/common/kernel/faction.c @@ -50,7 +50,12 @@ faction * get_monsters(void) { - static faction * monsters = NULL; + static faction * monsters; + static int thisturn = -1; + if (thisturn!=turn) { + monsters = NULL; + thisturn = turn; + } if (!monsters) { faction * f; diff --git a/src/common/kernel/move.c b/src/common/kernel/move.c index 25051383a..414517707 100644 --- a/src/common/kernel/move.c +++ b/src/common/kernel/move.c @@ -879,7 +879,16 @@ is_guarded(region * r, unit * u, unsigned int mask) { unit *u2 = NULL; int i; - static unit * guardcache[MAXGUARDCACHE], * lastguard; + static unit * guardcache[MAXGUARDCACHE], * lastguard; /* STATIC_XCALL: used across calls */ + static int thisturn = -1; + if (thisturn!=turn) { + if (thisturn>=0) { + /* clear the previous turn's cache */ + memset(guardcache, 0, sizeof(guardcache)); + lastguard = NULL; + } + thisturn = turn; + } if (!fval(r, RF_GUARDED)) { return NULL; @@ -1638,12 +1647,15 @@ sail(unit * u, order * ord, boolean move_on_land, region_list **routep) } if (!flying_ship(sh)) { - static int stormyness = -1; int stormchance; + static int stormyness; + static int thisturn = -1; - if (stormyness == -1) { - int thismonth = get_gamedate(turn, 0)->month; - stormyness = storms[thismonth] * 5; + if (thisturn != turn) { + gamedate date; + get_gamedate(turn, &date); + stormyness = storms[date.month] * 5; + thisturn = turn; } /* storms should be the first thing we do. */ diff --git a/src/common/kernel/pathfinder.c b/src/common/kernel/pathfinder.c index bbba013ee..838a2b959 100644 --- a/src/common/kernel/pathfinder.c +++ b/src/common/kernel/pathfinder.c @@ -143,7 +143,7 @@ regions_in_range(struct region * start, int maxdist, boolean (*allowed)(const st static region ** internal_path_find(region *start, const region *target, int maxlen, boolean (*allowed)(const region*, const region*)) { - static region * path[MAXDEPTH+2]; + static region * path[MAXDEPTH+2]; /* STATIC_RETURN: used for return, not across calls */ direction_t d; node * root = new_node(start, 0, NULL); node ** end = &root->next; diff --git a/src/common/kernel/region.c b/src/common/kernel/region.c index 084094c40..16584fb54 100644 --- a/src/common/kernel/region.c +++ b/src/common/kernel/region.c @@ -388,9 +388,11 @@ attrib_type at_moveblock = { #define RMAXHASH MAXREGIONS static region * regionhash[RMAXHASH]; static int dummy_data; -static region * delmarker = (region*)&dummy_data; /* a funny hack */ +static region * dummy_ptr = (region*)&dummy_data; /* a funny hack */ static unsigned int uidhash[MAXREGIONS]; +#define DELMARKER dummy_ptr + unsigned int generate_region_id(void) { @@ -425,7 +427,7 @@ rfindhash(short x, short y) #endif if (rid>=0) { int key = HASH1(rid, RMAXHASH), gk = HASH2(rid, RMAXHASH); - while (regionhash[key]!=NULL && (regionhash[key]==delmarker || regionhash[key]->x!=x || regionhash[key]->y!=y)) { + while (regionhash[key]!=NULL && (regionhash[key]==DELMARKER || regionhash[key]->x!=x || regionhash[key]->y!=y)) { key = (key + gk) % RMAXHASH; #if HASH_STATISTICS ++hash_misses; @@ -441,7 +443,7 @@ rhash(region * r) { unsigned int rid = coor_hashkey(r->x, r->y); int key = HASH1(rid, RMAXHASH), gk = HASH2(rid, RMAXHASH); - while (regionhash[key]!=NULL && regionhash[key]!=delmarker && regionhash[key]!=r) { + while (regionhash[key]!=NULL && regionhash[key]!=DELMARKER && regionhash[key]!=r) { key = (key + gk) % RMAXHASH; } assert(regionhash[key]!=r || !"trying to add the same region twice"); @@ -469,37 +471,27 @@ runhash(region * r) key = (key + gk) % RMAXHASH; } assert(regionhash[key]==r || !"trying to remove a unit that is not hashed"); - regionhash[key] = delmarker; + regionhash[key] = DELMARKER; } region * r_connect(const region * r, direction_t dir) { - static int set = 0; - static region * buffer[MAXDIRECTIONS]; - static const region * last = NULL; - + region * result; #ifdef FAST_CONNECT region * rmodify = (region*)r; assert (dir>=0 && dirconnect[dir]) return r->connect[dir]; #endif assert(dirx + delta_x[dir], r->y + delta_y[dir]); - set |= (1<x + delta_x[dir], r->y + delta_y[dir]); #ifdef FAST_CONNECT - if (buffer[dir]) { - rmodify->connect[dir] = buffer[dir]; - buffer[dir]->connect[back[dir]] = rmodify; + if (result) { + rmodify->connect[dir] = result; + result->connect[back[dir]] = rmodify; } #endif - return buffer[dir]; + return result; } region * @@ -935,6 +927,7 @@ free_region(region * r) while (r->buildings) { building * b = r->buildings; r->buildings = b->next; + bunhash(b); free(b->name); free(b->display); free(b); @@ -943,6 +936,7 @@ free_region(region * r) while (r->ships) { ship * s = r->ships; r->ships = s->next; + sunhash(s); free(s->name); free(s->display); free(s); diff --git a/src/common/kernel/region.h b/src/common/kernel/region.h index d97740b11..9c9aad261 100644 --- a/src/common/kernel/region.h +++ b/src/common/kernel/region.h @@ -116,7 +116,7 @@ typedef struct region { struct faction * owner; #endif #ifdef FAST_CONNECT - struct region * connect[MAXDIRECTIONS]; + struct region * connect[MAXDIRECTIONS]; /* use rconnect(r, dir) to access */ #endif } region; diff --git a/src/common/kernel/teleport.c b/src/common/kernel/teleport.c index 837b6ea8f..0723496c2 100644 --- a/src/common/kernel/teleport.c +++ b/src/common/kernel/teleport.c @@ -163,16 +163,19 @@ get_normalplane(void) plane * get_astralplane(void) { - static plane * astral_plane = NULL; - if (astral_plane==NULL) { - astral_plane = getplanebyid(1); + static plane * astralspace; + static int thisturn = -1; + if (thisturn!=turn) { + astralspace = getplanebyname("Astralraum"); + thisturn = turn; } - if (astral_plane==NULL) { - astral_plane = create_new_plane(1, "Astralraum", + + if (astralspace==NULL) { + astralspace = create_new_plane(1, "Astralraum", TE_CENTER_X-500, TE_CENTER_X+500, TE_CENTER_Y-500, TE_CENTER_Y+500, 0); } - return astral_plane; + return astralspace; } void diff --git a/src/common/modules/autoseed.c b/src/common/modules/autoseed.c index c9742034a..8f921f0a6 100644 --- a/src/common/modules/autoseed.c +++ b/src/common/modules/autoseed.c @@ -414,6 +414,37 @@ frame_regions(int age, terrain_t terrain) } } } +static void +prepare_starting_region(region * r) +{ + int n, t; + double p; + + assert(r->land); + + /* population between 30% and 60% of max */ + p = rng_double(); + n = (int)(r->terrain->size * (0.3 + p*0.3)); + rsetpeasants(r, n); + + /* trees: don't squash the peasants, and at least 5% should be forrest */ + t = (rtrees(r, 2) + rtrees(r, 1)/2) * TREESIZE; + if (t < r->terrain->size/20 || t+n > r->terrain->size) { + double p2 = 0.05 + rng_double()*(1.0-p-0.05); + int maxtrees = (int)(r->terrain->size/1.25/TREESIZE); /* 1.25 = each young tree will take 1/2 the space of old trees */ + int trees = (int)(p2 * maxtrees); + + rsettrees(r, 2, trees); + rsettrees(r, 1, trees/2); + rsettrees(r, 0, trees/4); + } + + /* horses: between 1% and 2% */ + p = rng_double(); + rsethorses(r, (int)(r->terrain->size * (0.01 + p*0.01))); + + fix_demand(r); +} int autoseed(newfaction ** players, int nsize, int max_agediff) @@ -545,28 +576,14 @@ autoseed(newfaction ** players, int nsize, int max_agediff) newfaction ** nfp, * nextf = *players; faction * f; unit * u; - int n; isize += REGIONS_PER_FACTION; terraform(r, preferred_terrain(nextf->race)); - n = rhorses(r); - if (nterrain->size/200) { - n = r->terrain->size/200; - rsethorses(r, n); - } - n = rtrees(r, 2); - if (nterrain->size/100) { - n = r->terrain->size/100; - rsettrees(r, 2, n); - rsettrees(r, 2, n/4); - rsettrees(r, 2, n/2); - } - n = rhorses(r); + prepare_starting_region(r); ++tsize; assert(r->land && r->units==0); u = addplayer(r, addfaction(nextf->email, nextf->password, nextf->race, nextf->lang, nextf->subscription)); - fix_demand(r); f = u->faction; fset(f, FFL_ISNEW); f->alliance = nextf->allies; diff --git a/src/common/util/base36.c b/src/common/util/base36.c index e30f5099a..6123de48a 100644 --- a/src/common/util/base36.c +++ b/src/common/util/base36.c @@ -55,14 +55,14 @@ atoi36(const char * str) const char* itoab(int i, int base) { - static char **as = NULL; + static char **as = NULL; /* STATIC_RETURN: used for return, not across calls */ char * s, * dst; - static int index = 0; + static int index = 0; /* STATIC_XCALL: used across calls */ int neg = 0; if (!as) { int j; - char * x = (char*)calloc(sizeof(char), 8*4); + char * x = (char*)calloc(sizeof(char), 8*4); /* STATIC_LEAK: malloc in static variable */ as = (char **)calloc(sizeof(char*), 4); for (j=0;j!=4;++j) as[j] = x+j*8; } diff --git a/src/common/util/goodies.c b/src/common/util/goodies.c index fc52a0063..82308cf2f 100644 --- a/src/common/util/goodies.c +++ b/src/common/util/goodies.c @@ -80,7 +80,7 @@ spc_email_isvalid(const char *address) { int count = 0; const char *c, *domain; - static const char *rfc822_specials = "()<>@,;:\\\"[]"; + static const char *rfc822_specials = "()<>@,;:\\\"[]"; /* STATIC_CONST: contains a constant value */ /* first we validate the name portion (name@domain) */ for (c = address; *c; c++) { diff --git a/src/common/util/language.c b/src/common/util/language.c index 03f1fdb78..c60552f81 100644 --- a/src/common/util/language.c +++ b/src/common/util/language.c @@ -215,7 +215,7 @@ mkname_buf(const char * space, const char * name, char * buffer) const char * mkname(const char * space, const char * name) { - static char zBuffer[128]; + static char zBuffer[128]; /* STATIC_RESULT: used for return, not across calls */ return mkname_buf(space, name, zBuffer); } diff --git a/src/common/util/log.c b/src/common/util/log.c index beb319490..a5531ddfb 100644 --- a/src/common/util/log.c +++ b/src/common/util/log.c @@ -140,9 +140,9 @@ log_close(void) static int check_dupe(const char * format, const char * type) { - static const char * last_type; - static char last_message[32]; - static int dupes = 0; + static const char * last_type; /* STATIC_XCALL: used across calls */ + static char last_message[32]; /* STATIC_XCALL: used across calls */ + static int dupes = 0; /* STATIC_XCALL: used across calls */ if (strncmp(last_message, format, sizeof(last_message))==0) { ++dupes; return 1; diff --git a/src/common/util/parser.c b/src/common/util/parser.c index 05df8ee5b..8d2fdf87b 100644 --- a/src/common/util/parser.c +++ b/src/common/util/parser.c @@ -124,7 +124,7 @@ skip_token(void) const char * parse_token(const char ** str) { - static char lbuf[MAXTOKENSIZE]; + static char lbuf[MAXTOKENSIZE]; /* STATIC_RESULT: used for return, not across calls */ char * cursor = lbuf; char quotechar = 0; boolean escape = false; diff --git a/src/common/util/rand.c b/src/common/util/rand.c index 0399382df..b4757a55b 100644 --- a/src/common/util/rand.c +++ b/src/common/util/rand.c @@ -36,7 +36,7 @@ double normalvariate(double mu, double sigma) { - static double NV_MAGICCONST = 1.7155277699214135; + static const double NV_MAGICCONST = 1.7155277699214135; /* STATIC_CONST: a constant */ double z; for (;;) { double u1 = rng_double(); diff --git a/src/common/util/resolve.c b/src/common/util/resolve.c index f496c5b5c..8b5f19127 100644 --- a/src/common/util/resolve.c +++ b/src/common/util/resolve.c @@ -74,5 +74,6 @@ resolve(void) ur->resolve(ur->data, ur->ptrptr); ++ur; } - ur_list = ur_begin = ur_current; + free(ur_list); + ur_list = NULL; } diff --git a/src/common/util/sql.c b/src/common/util/sql.c index 45ba4ec88..8b66cb113 100644 --- a/src/common/util/sql.c +++ b/src/common/util/sql.c @@ -68,8 +68,8 @@ sqlquote(const char * str) { #define BUFFERS 4 #define BUFSIZE 1024 - static char sqlstring[BUFSIZE*BUFFERS]; - static int index = 0; + static char sqlstring[BUFSIZE*BUFFERS]; /* STATIC_RESULT: used for return, not across calls */ + static int index = 0; /* STATIC_XCALL: used across calls */ char * start = sqlstring+index*BUFSIZE; char * o = start; const char * i = str; diff --git a/src/common/util/strings.c b/src/common/util/strings.c index d01fef0a8..eb0829093 100644 --- a/src/common/util/strings.c +++ b/src/common/util/strings.c @@ -37,7 +37,7 @@ hashstring(const char* s) INLINE_FUNCTION const char * escape_string(const char * str, char * buffer, unsigned int len) { - static char s_buffer[4096]; + static char s_buffer[4096]; /* STATIC_RESULT: used for return, not across calls */ const char * p = str; char * o; if (buffer==NULL) { diff --git a/src/common/util/translation.c b/src/common/util/translation.c index 68555d055..51ca8f925 100644 --- a/src/common/util/translation.c +++ b/src/common/util/translation.c @@ -77,7 +77,7 @@ static struct { char * balloc(size_t size) { - static int init = 0; + static int init = 0; /* STATIC_XCALL: used across calls */ if (!init) { init = 1; buffer.current = buffer.begin = malloc(BUFSIZE); diff --git a/src/common/util/umlaut.c b/src/common/util/umlaut.c index cdd61290b..07a2f11f7 100644 --- a/src/common/util/umlaut.c +++ b/src/common/util/umlaut.c @@ -42,7 +42,7 @@ typedef struct tref { void addtoken(tnode * root, const char * str, variant id) { - static struct replace { + static const struct replace { /* STATIC_CONST: constant value */ ucs4_t ucs; const char str[3]; } replace[] = { diff --git a/src/common/util/windir.c b/src/common/util/windir.c index 2896225f8..bd17a7233 100644 --- a/src/common/util/windir.c +++ b/src/common/util/windir.c @@ -22,7 +22,7 @@ DIR * opendir(const char *name) { - static DIR direct; + static DIR direct; /* STATIC_RESULT: used for return, not across calls */ direct.first = 1; _searchenv(name, "ERESSEA_PATH", direct.name); @@ -34,8 +34,8 @@ opendir(const char *name) struct dirent * readdir(DIR * thedir) { - static struct _finddata_t ft; - static struct dirent de; + static struct _finddata_t ft; /* STATIC_RESULT: used for return, not across calls */ + static struct dirent de; /* STATIC_RESULT: used for return, not across calls */ char where[_MAX_PATH]; strcat(strcpy(where, thedir->name), "/*"); diff --git a/src/eressea/korrektur.c b/src/eressea/korrektur.c index 7040f004f..47d82adf9 100644 --- a/src/eressea/korrektur.c +++ b/src/eressea/korrektur.c @@ -128,17 +128,6 @@ curse_emptiness(void) return 0; } -void -french_testers(void) -{ - faction * f = factions; - const struct locale * french = find_locale("fr"); - while (f!=NULL) { - if (f->locale==french) fset(f, FFL_NOTIMEOUT); - f = f->next; - } -} - static void verify_owners(boolean bOnce) { @@ -928,18 +917,19 @@ fix_groups(void) void korrektur(void) { +#if GLOBAL_WARMING + gamedate date; + get_gamedate(turn, &date); + if (date.season == SEASON_SUMMER) { + global_warming(); + } +#endif check_dissolve(); - french_testers(); do_once("rdec", &road_decay); do_once("unfi", &fix_undead); do_once("chgt", &fix_chaosgates); do_once("atrx", &fix_attribflags); do_once("asfi", &fix_astral_firewalls); -#if GLOBAL_WARMING - if (get_gamedate(turn, NULL)->season == SEASON_SUMMER) { - global_warming(); - } -#endif fix_astralplane(); fix_firewalls(); fix_toads(); diff --git a/src/eressea/lua/gamecode.cpp b/src/eressea/lua/gamecode.cpp index f3e16eddf..71f1224ba 100644 --- a/src/eressea/lua/gamecode.cpp +++ b/src/eressea/lua/gamecode.cpp @@ -233,6 +233,7 @@ bind_gamecode(lua_State * L) module(L)[ def("read_game", &read_game), def("write_game", &write_game), + def("free_game", &free_gamedata), def("get_encoding", &get_encoding), def("set_encoding", &set_encoding), diff --git a/src/eressea/server.cpp b/src/eressea/server.cpp index d81ff9901..5e13a3ab4 100644 --- a/src/eressea/server.cpp +++ b/src/eressea/server.cpp @@ -129,9 +129,6 @@ #if defined(_MSC_VER) # include #endif -#if defined(USE_DMALLOC) -# define CLEANUP_CODE -#endif /** ** global variables we are importing from other modules @@ -322,42 +319,24 @@ lua_done(lua_State * luaState) lua_close(luaState); } -#ifndef CLEANUP_CODE -# define CLEANUP_CODE -#endif -#ifdef CLEANUP_CODE static void game_done(void) { +#ifdef CLEANUP_CODE /* Diese Routine enfernt allen allokierten Speicher wieder. Das ist nur * zum Debugging interessant, wenn man Leak Detection hat, und nach * nicht freigegebenem Speicher sucht, der nicht bis zum Ende benötigt * wird (temporäre Hilsstrukturen) */ - free_units(); - free_regions(); - - while (factions) { - faction * f = factions; - factions = f->next; - stripfaction(f); - free(f); - } - - while (planes) { - plane * pl = planes; - planes = planes->next; - free(pl->name); - free(pl); - } + free_game(); creport_cleanup(); #ifdef REPORT_FORMAT_NR report_cleanup(); #endif calendar_cleanup(); -} #endif +} #define CRTDBG #ifdef CRTDBG @@ -657,9 +636,7 @@ main(int argc, char *argv[]) #ifdef MSPACES malloc_stats(); #endif -#ifdef CLEANUP_CODE game_done(); -#endif kernel_done(); lua_done(luaState); log_close();