- made startup regions more balanced

implementing free_gamedata():
- cleaning up some static variables
This commit is contained in:
Enno Rehling 2008-05-22 10:46:02 +00:00
parent a40e5a3711
commit 1052e46613
31 changed files with 227 additions and 180 deletions

View file

@ -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])
@ -510,7 +512,7 @@ recruit(unit * u, struct order * ord, request ** recruitorders)
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;
}
@ -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);
@ -535,13 +537,13 @@ recruit(unit * u, struct order * ord, request ** recruitorders)
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;
@ -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){

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,8 @@
#include <config.h>
#include "calendar.h"
#include <assert.h>
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 */

View file

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

View file

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

View file

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

View file

@ -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. */

View file

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

View file

@ -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 && dir<MAXDIRECTIONS);
if (r->connect[dir]) return r->connect[dir];
#endif
assert(dir<MAXDIRECTIONS);
if (r != last) {
set = 0;
last = r;
}
else
if (set & (1 << dir)) return buffer[dir];
buffer[dir] = rfindhash(r->x + delta_x[dir], r->y + delta_y[dir]);
set |= (1<<dir);
result = rfindhash(r->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);

View file

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

View file

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

View file

@ -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 (n<r->terrain->size/200) {
n = r->terrain->size/200;
rsethorses(r, n);
}
n = rtrees(r, 2);
if (n<r->terrain->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;

View file

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

View file

@ -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++) {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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[] = {

View file

@ -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), "/*");

View file

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

View file

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

View file

@ -129,9 +129,6 @@
#if defined(_MSC_VER)
# include <crtdbg.h>
#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();