fehlende updates vom samstag: main.c aufgeraeumt, argument-parsing an zerntraler stelle. init/done funktionen umgestellt

This commit is contained in:
Enno Rehling 2001-02-05 16:11:59 +00:00
parent 176ffef3cb
commit fc03d7922a
16 changed files with 265 additions and 547 deletions

View File

@ -1,6 +1,6 @@
/* vi: set ts=2: /* vi: set ts=2:
* *
* $Id: main.c,v 1.3 2001/02/03 13:45:27 enno Exp $ * $Id: main.c,v 1.4 2001/02/05 16:11:57 enno Exp $
* Eressea PB(E)M host Copyright (C) 1998-2000 * Eressea PB(E)M host Copyright (C) 1998-2000
* Christian Schlittchen (corwin@amber.kn-bremen.de) * Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de)
@ -450,10 +450,6 @@ main(int argc, char *argv[])
case 'q': case 'q':
quiet = 1; quiet = 1;
break; break;
case 'i':
inside_only = 1;
printf(" - Lade nur die innersten Regionen.\n");
break;
case 'x': case 'x':
maxregions = atoi(argv[++i]); maxregions = atoi(argv[++i]);
maxregions = (maxregions*81+80) / 81; maxregions = (maxregions*81+80) / 81;
@ -465,8 +461,9 @@ main(int argc, char *argv[])
strcat(strcpy(zText, resourcepath()), "/timestrings"); strcat(strcpy(zText, resourcepath()), "/timestrings");
read_datenames(zText); read_datenames(zText);
} }
kernel_init();
init_game(); init_game();
initgame();
readgame(false); readgame(false);
#if MALLOCDBG #if MALLOCDBG
assert(_CrtCheckMemory()); assert(_CrtCheckMemory());
@ -590,8 +587,6 @@ main(int argc, char *argv[])
case 'x': case 'x':
i++; i++;
case 'q': case 'q':
case 'i':
/* inner_world, quiet, minfaction und maxregions wird schon vorher abgefragt */
break; break;
default: default:
fprintf(stderr, "Usage: %s [options]\n" fprintf(stderr, "Usage: %s [options]\n"

View File

@ -1,6 +1,6 @@
/* vi: set ts=2: /* vi: set ts=2:
* *
* $Id: creport.c,v 1.4 2001/02/03 13:45:29 enno Exp $ * $Id: creport.c,v 1.5 2001/02/05 16:11:57 enno Exp $
* Eressea PB(E)M host Copyright (C) 1998-2000 * Eressea PB(E)M host Copyright (C) 1998-2000
* Christian Schlittchen (corwin@amber.kn-bremen.de) * Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de)
@ -21,10 +21,11 @@
#include <config.h> #include <config.h>
#include "eressea.h" #include "eressea.h"
#include "reports.h" #include "creport.h"
#include "plane.h" #include <reports.h>
#include "render.h" #include <plane.h>
#include <render.h>
#include "movement.h" #include "movement.h"
#include "item.h" #include "item.h"
#include "faction.h" #include "faction.h"

View File

@ -1,6 +1,6 @@
/* vi: set ts=2: /* vi: set ts=2:
* *
* $Id: report.c,v 1.10 2001/02/04 18:50:59 corwin Exp $ * $Id: report.c,v 1.11 2001/02/05 16:11:57 enno Exp $
* Eressea PB(E)M host Copyright (C) 1998-2000 * Eressea PB(E)M host Copyright (C) 1998-2000
* Christian Schlittchen (corwin@amber.kn-bremen.de) * Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de)
@ -91,9 +91,8 @@ int seasons;
extern int weeks_per_month; extern int weeks_per_month;
extern int months_per_year; extern int months_per_year;
void int
read_datenames(char *filename) read_datenames(const char *filename)
{ {
FILE *namesFP; FILE *namesFP;
char line[256]; char line[256];
@ -101,7 +100,7 @@ read_datenames(char *filename)
if( (namesFP=fopen(filename,"r")) == NULL) { if( (namesFP=fopen(filename,"r")) == NULL) {
fprintf(stderr, "Kann Datei '%s' nicht öffnen, Abbruch\n",filename); fprintf(stderr, "Kann Datei '%s' nicht öffnen, Abbruch\n",filename);
exit(1); return -1;
} }
fgets(line,255,namesFP); fgets(line,255,namesFP);
@ -157,6 +156,7 @@ read_datenames(char *filename)
} }
fclose(namesFP); fclose(namesFP);
return 0;
} }
char * char *
@ -1793,7 +1793,7 @@ report(FILE *F, faction * f)
centre(F, "Kämpfe", false); centre(F, "Kämpfe", false);
rnl(F); rnl(F);
for (bm=f->battles;bm;bm=bm->next) { for (bm=f->battles;bm;bm=bm->next) {
#if HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
snprintf(buf, 80, "In %s findet ein Kampf statt:", snprintf(buf, 80, "In %s findet ein Kampf statt:",
translate_regions(regionid(bm->r), f)); translate_regions(regionid(bm->r), f));
#else #else

View File

@ -1,6 +1,6 @@
/* vi: set ts=2: /* vi: set ts=2:
* *
* $Id: battle.c,v 1.5 2001/02/04 10:04:36 corwin Exp $ * $Id: battle.c,v 1.6 2001/02/05 16:11:57 enno Exp $
* Eressea PB(E)M host Copyright (C) 1998-2000 * Eressea PB(E)M host Copyright (C) 1998-2000
* Christian Schlittchen (corwin@amber.kn-bremen.de) * Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de)
@ -2901,9 +2901,8 @@ make_battle(region * r)
if (!nobattledebug) { if (!nobattledebug) {
char zText[MAX_PATH]; char zText[MAX_PATH];
sprintf(zText, "%s/battles", basepath());
if (!debug) {
char zFilename[MAX_PATH]; char zFilename[MAX_PATH];
sprintf(zText, "%s/battles", basepath());
makedir(zText, 0700); makedir(zText, 0700);
#ifdef HAVE_ZLIB #ifdef HAVE_ZLIB
sprintf(zFilename, "%s/battle-%d-%s.log.gz", zText, obs_count, simplename(r)); sprintf(zFilename, "%s/battle-%d-%s.log.gz", zText, obs_count, simplename(r));
@ -2919,7 +2918,6 @@ make_battle(region * r)
else { else {
dbgprintf((bdebug, "In %s findet ein Kampf statt:", rname(r, NULL))); dbgprintf((bdebug, "In %s findet ein Kampf statt:", rname(r, NULL)));
} }
}
obs_count++; obs_count++;
} }
nextside = 0; nextside = 0;

View File

@ -1,6 +1,6 @@
/* vi: set ts=2: /* vi: set ts=2:
* *
* $Id: eressea.c,v 1.8 2001/02/05 07:23:17 corwin Exp $ * $Id: eressea.c,v 1.9 2001/02/05 16:11:58 enno Exp $
* Eressea PB(E)M host Copyright (C) 1998-2000 * Eressea PB(E)M host Copyright (C) 1998-2000
* Christian Schlittchen (corwin@amber.kn-bremen.de) * Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de)
@ -459,8 +459,6 @@ stripunit(unit * u)
while (u->attribs) a_remove (&u->attribs, u->attribs); while (u->attribs) a_remove (&u->attribs, u->attribs);
} }
extern int inside_only;
void void
verify_data (void) verify_data (void)
{ {
@ -470,8 +468,6 @@ verify_data (void)
unit *u; unit *u;
int mage, alchemist; int mage, alchemist;
if (inside_only)
return;
puts(" - Überprüfe Daten auf Korrektheit..."); puts(" - Überprüfe Daten auf Korrektheit...");
list_foreach(faction, factions, f) { list_foreach(faction, factions, f) {
@ -1893,15 +1889,35 @@ init_tokens(void)
} }
} }
extern void attrib_init(void); extern void render_cleanup(void);
void void
initgame(void) kernel_done(void)
{
/* calling this function releases memory assigned to static variables, etc.
* calling it is optional, e.g. a release server will most likely not do it.
*/
render_cleanup();
skill_done();
gc_done();
}
extern void attrib_init(void);
extern void render_init(void);
void
kernel_init(void)
{ {
init_tokens(); init_tokens();
skill_init(); skill_init();
attrib_init(); attrib_init();
init_locales();
render_init();
if (!turn) turn = lastturn(); if (!turn) turn = lastturn();
if (turn == 0)
srand(time((time_t *) NULL));
else
srand(turn);
} }
/*********************/ /*********************/

View File

@ -1,6 +1,6 @@
/* vi: set ts=2: /* vi: set ts=2:
* *
* $Id: eressea.h,v 1.11 2001/02/05 07:23:17 corwin Exp $ * $Id: eressea.h,v 1.12 2001/02/05 16:11:58 enno Exp $
* Eressea PB(E)M host Copyright (C) 1998-2000 * Eressea PB(E)M host Copyright (C) 1998-2000
* Christian Schlittchen (corwin@amber.kn-bremen.de) * Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de)
@ -911,8 +911,6 @@ extern char buf[BUFSIZE + 1];
/* special units */ /* special units */
struct unit *make_undead_unit(struct region * r, struct faction * f, int n, race_t race); struct unit *make_undead_unit(struct region * r, struct faction * f, int n, race_t race);
extern FILE *debug; /* Hier können bei -debug Debug-Ausgaben hineingeschreiben werden. */
extern struct region *regions; extern struct region *regions;
extern struct faction *factions; extern struct faction *factions;
@ -1061,8 +1059,6 @@ boolean idle(struct faction * f);
boolean unit_has_cursed_item(struct unit *u); boolean unit_has_cursed_item(struct unit *u);
struct region * rconnect(const struct region *, direction_t dir); struct region * rconnect(const struct region *, direction_t dir);
void game_done(void);
/* simple garbage collection: */ /* simple garbage collection: */
void * gc_add(void * p); void * gc_add(void * p);
void gc_done(void); void gc_done(void);
@ -1131,6 +1127,8 @@ extern void add_income(struct unit * u, int type, int want, int qty);
extern int month(int offset); extern int month(int offset);
extern const char * basepath(void); extern const char * basepath(void);
extern const char * resourcepath(void); extern const char * resourcepath(void);
extern void kernel_init(void);
extern void kernel_done(void);
#define FIRST_TURN 184 #define FIRST_TURN 184

View File

@ -1,6 +1,6 @@
/* vi: set ts=2: /* vi: set ts=2:
* *
* $Id: plane.h,v 1.2 2001/01/26 16:19:40 enno Exp $ * $Id: plane.h,v 1.3 2001/02/05 16:11:58 enno Exp $
* Eressea PB(E)M host Copyright (C) 1998-2000 * Eressea PB(E)M host Copyright (C) 1998-2000
* Christian Schlittchen (corwin@amber.kn-bremen.de) * Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de)
@ -47,13 +47,13 @@ typedef struct plane {
attrib *attribs; attrib *attribs;
} plane; } plane;
plane *planes; struct plane *planes;
plane *getplane(const struct region *r); struct plane *getplane(const struct region *r);
plane *findplane(int x, int y); struct plane *findplane(int x, int y);
void init_planes(void); void init_planes(void);
int getplaneid(struct region *r); int getplaneid(struct region *r);
plane * getplanebyid(int id); struct plane * getplanebyid(int id);
int region_x(const struct region *r, const struct faction *f); int region_x(const struct region *r, const struct faction *f);
int region_y(const struct region *r, const struct faction *f); int region_y(const struct region *r, const struct faction *f);
int plane_center_x(plane *pl); int plane_center_x(plane *pl);

View File

@ -1,6 +1,6 @@
/* vi: set ts=2: /* vi: set ts=2:
* *
* $Id: region.c,v 1.6 2001/02/03 13:45:32 enno Exp $ * $Id: region.c,v 1.7 2001/02/05 16:11:58 enno Exp $
* Eressea PB(E)M host Copyright (C) 1998-2000 * Eressea PB(E)M host Copyright (C) 1998-2000
* Christian Schlittchen (corwin@amber.kn-bremen.de) * Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de)
@ -75,10 +75,12 @@ tregionid(const region * r, const faction * f)
} else if (pl && fval(pl, PFL_NOCOORDS)) { } else if (pl && fval(pl, PFL_NOCOORDS)) {
strncpy(buf, rname(r, f->locale), 65); strncpy(buf, rname(r, f->locale), 65);
} else { } else {
#if HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
snprintf(buf, 65, "%s (%d,%d)", rname(r, f->locale), region_x(r, f), region_y(r, f)); snprintf(buf, 65, "%s (%d,%d)", rname(r, f->locale), region_x(r, f), region_y(r, f));
#else #else
sprintf(buf, "%s (%d,%d)", rname(r, f->locale), region_x(r, f), region_y(r, f)); strncpy(buf, rname(r, f->locale), 50);
buf[50]=0;
sprintf(buf+strlen(buf), " (%d,%d)", region_x(r, f), region_y(r, f));
#endif #endif
} }
buf[64] = 0; buf[64] = 0;

View File

@ -1,6 +1,6 @@
/* vi: set ts=2: /* vi: set ts=2:
* *
* $Id: reports.h,v 1.2 2001/01/26 16:19:40 enno Exp $ * $Id: reports.h,v 1.3 2001/02/05 16:11:58 enno Exp $
* Eressea PB(E)M host Copyright (C) 1998-2000 * Eressea PB(E)M host Copyright (C) 1998-2000
* Christian Schlittchen (corwin@amber.kn-bremen.de) * Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de)
@ -35,7 +35,7 @@ extern boolean kann_finden(struct faction * f1, struct faction * f2);
extern void add_find(struct faction *, struct unit *); extern void add_find(struct faction *, struct unit *);
extern struct unit * can_find(struct faction *, struct faction *); extern struct unit * can_find(struct faction *, struct faction *);
/* funktionen zum schreiben eines reports */ /* funktionen zum schreiben eines reports */
void read_datenames(char *filename); extern int read_datenames(const char *filename);
void sparagraph(struct strlist ** SP, const char *s, int indent, char mark); void sparagraph(struct strlist ** SP, const char *s, int indent, char mark);
void lparagraph(struct strlist ** SP, char *s, int indent, char mark); void lparagraph(struct strlist ** SP, char *s, int indent, char mark);
const char *hp_status(const struct unit * u); const char *hp_status(const struct unit * u);

View File

@ -1,6 +1,6 @@
/* vi: set ts=2: /* vi: set ts=2:
* *
* $Id: save.c,v 1.10 2001/02/04 09:46:47 corwin Exp $ * $Id: save.c,v 1.11 2001/02/05 16:11:58 enno Exp $
* Eressea PB(E)M host Copyright (C) 1998-2000 * Eressea PB(E)M host Copyright (C) 1998-2000
* Christian Schlittchen (corwin@amber.kn-bremen.de) * Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de)
@ -75,7 +75,6 @@ extern void resolve2(void);
#define ESCAPE_FIX #define ESCAPE_FIX
int inside_only = 0;
int minfaction = 0; int minfaction = 0;
const char * g_datadir; const char * g_datadir;
/* imported symbols */ /* imported symbols */
@ -542,7 +541,7 @@ readorders(const char *filename)
} }
fclose(F); fclose(F);
return 1; return 0;
} }
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
@ -760,9 +759,6 @@ readgame(boolean backup)
nextborder = ri(F); nextborder = ri(F);
} }
printf(" - Version: %d.%d, Runde %d.\n",
global.data_version / 10, global.data_version % 10, turn);
/* Planes */ /* Planes */
planes = NULL; planes = NULL;
n = ri(F); n = ri(F);
@ -1195,14 +1191,7 @@ readgame(boolean backup)
init=true; init=true;
} }
#endif #endif
#ifdef AMIGA
u = &dummyu;
#else
if (inside_only && inner_world(r) < 2)
u = &dummyu;
else
u = (unit *) calloc(1, sizeof(unit)); u = (unit *) calloc(1, sizeof(unit));
#endif
#if USE_EVENTS #if USE_EVENTS
add_handler(&u->attribs, "hunger", print_hunger, 0); add_handler(&u->attribs, "hunger", print_hunger, 0);
@ -1396,14 +1385,9 @@ readgame(boolean backup)
} }
a_read(F, &u->attribs); a_read(F, &u->attribs);
if (inside_only && inner_world(r) < 2) {
destroy_unit(u);
memset(u, 0, sizeof(unit));
} else {
addlist2(up,u); addlist2(up,u);
} }
} }
}
if (global.data_version >= BORDER_VERSION) read_borders(F); if (global.data_version >= BORDER_VERSION) read_borders(F);
#if defined(OLD_TRIGGER) || defined(CONVERT_TRIGGER) #if defined(OLD_TRIGGER) || defined(CONVERT_TRIGGER)
if (global.data_version >= TIMEOUT_VERSION) load_timeouts(F); if (global.data_version >= TIMEOUT_VERSION) load_timeouts(F);
@ -2169,24 +2153,6 @@ attrib_init(void)
at_register(&at_jihad); at_register(&at_jihad);
} }
extern void skill_init(void);
extern void skill_done(void);
void game_done(void)
{
#if 0
int l, i;
for (i=0;i!=MAX_MSG;++i) {
fprintf(stderr, "%s\t\n", report_options[i]);
for (l=0;l!=ML_MAX;++l)
fprintf(stderr, "\t%.8d", cmsg[i][l]);
fprintf(stderr, report_options[i]);
fprintf(stderr, "\n");
}
#endif
skill_done();
gc_done();
}
extern void inittokens(void); extern void inittokens(void);
extern void create_teleport_plane(void); extern void create_teleport_plane(void);

View File

@ -1,6 +1,6 @@
/* vi: set ts=2: /* vi: set ts=2:
* *
* $Id: save.h,v 1.3 2001/01/30 23:16:17 enno Exp $ * $Id: save.h,v 1.4 2001/02/05 16:11:58 enno Exp $
* Eressea PB(E)M host Copyright (C) 1998-2000 * Eressea PB(E)M host Copyright (C) 1998-2000
* Christian Schlittchen (corwin@amber.kn-bremen.de) * Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de)
@ -30,12 +30,9 @@ double version(void);
/* Nach MAX_INPUT_SIZE brechen wir das Einlesen der Zeile ab und nehmen an, /* Nach MAX_INPUT_SIZE brechen wir das Einlesen der Zeile ab und nehmen an,
* dass hier ein Fehler (fehlende ") vorliegt */ * dass hier ein Fehler (fehlende ") vorliegt */
extern int inside_only;
FILE * cfopen(const char *filename, const char *mode); FILE * cfopen(const char *filename, const char *mode);
int readorders(const char *); int readorders(const char *);
int creategame(void); int creategame(void);
void initgame(void);
int readgame(boolean backup); int readgame(boolean backup);
void writegame(char *path, char quiet); void writegame(char *path, char quiet);

View File

@ -1,6 +1,6 @@
/* vi: set ts=2: /* vi: set ts=2:
* *
* $Id: config.h,v 1.4 2001/02/03 13:45:27 enno Exp $ * $Id: config.h,v 1.5 2001/02/05 16:11:57 enno Exp $
* Eressea PB(E)M host Copyright (C) 1998-2000 * Eressea PB(E)M host Copyright (C) 1998-2000
* Christian Schlittchen (corwin@amber.kn-bremen.de) * Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de)
@ -121,6 +121,7 @@ typedef int boolean;
# define HAVE_MKDIR_WITH_PERMISSION # define HAVE_MKDIR_WITH_PERMISSION
# include <string.h> # include <string.h>
# define HAVE_STRDUP # define HAVE_STRDUP
# define HAVE_SNPRINTF
#endif #endif
/* egcpp 4 dos */ /* egcpp 4 dos */
@ -139,7 +140,8 @@ typedef int boolean;
# define HAVE_STRICMP # define HAVE_STRICMP
# define HAVE_STRNICMP # define HAVE_STRNICMP
# define HAVE_STRDUP # define HAVE_STRDUP
# define HAVE__SNPRINTF # define snprintf _snprintf
# define HAVE_SNPRINTF
# undef HAVE_STRCASECMP # undef HAVE_STRCASECMP
# undef HAVE_STRNCASECMP # undef HAVE_STRNCASECMP
# define R_OK 4 # define R_OK 4
@ -150,6 +152,9 @@ typedef int boolean;
# define R_OK 4 # define R_OK 4
# define HAVE__MKDIR_WITHOUT_PERMISSION # define HAVE__MKDIR_WITHOUT_PERMISSION
# define snprintf _snprintf
# define HAVE_SNPRINTF
/* MSVC has _access */ /* MSVC has _access */
_CRTIMP int __cdecl _access(const char *, int); _CRTIMP int __cdecl _access(const char *, int);
# define access(f, m) _access(f, m) # define access(f, m) _access(f, m)

View File

@ -119,7 +119,7 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 0 # PROP Ignore_Export_Lib 0
# PROP Target_Dir "" # PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /I ".." /I "../common" /I "../common/util" /I "../common/kernel" /I "../common/gamecode" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD BASE CPP /nologo /W3 /GX /O2 /I ".." /I "../common" /I "../common/util" /I "../common/kernel" /I "../common/gamecode" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /Za /W4 /GX- /Zi /O2 /I ".." /I "../common" /I "../common/util" /I "../common/kernel" /I "../common/gamecode" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD CPP /nologo /Za /W4 /Zi /O2 /I ".." /I "../common" /I "../common/util" /I "../common/kernel" /I "../common/gamecode" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x407 /d "NDEBUG" # ADD BASE RSC /l 0x407 /d "NDEBUG"
# ADD RSC /l 0x407 /d "NDEBUG" # ADD RSC /l 0x407 /d "NDEBUG"
BSC32=bscmake.exe BSC32=bscmake.exe

View File

@ -1,6 +1,6 @@
/* vi: set ts=2: /* vi: set ts=2:
* *
* $Id: main.c,v 1.9 2001/02/03 13:45:34 enno Exp $ * $Id: main.c,v 1.10 2001/02/05 16:11:58 enno Exp $
* Eressea PB(E)M host Copyright (C) 1998-2000 * Eressea PB(E)M host Copyright (C) 1998-2000
* Christian Schlittchen (corwin@amber.kn-bremen.de) * Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de)
@ -19,13 +19,6 @@
* permission from the authors. * permission from the authors.
*/ */
#define BENCHMARK 0
#ifdef DMALLOC
# define ENNO_CLEANUP 1
#else
# define ENNO_CLEANUP 0
#endif
#define LOCALE_CHECK #define LOCALE_CHECK
#ifdef __LCC__ #ifdef __LCC__
#undef LOCALE_CHECK #undef LOCALE_CHECK
@ -59,8 +52,10 @@
#include <message.h> #include <message.h>
#include <teleport.h> #include <teleport.h>
#include <faction.h> #include <faction.h>
#include <plane.h>
#include <race.h> #include <race.h>
#include <reports.h> #include <reports.h>
#include <region.h>
#include <save.h> #include <save.h>
#include <time.h> #include <time.h>
#include <border.h> #include <border.h>
@ -78,8 +73,9 @@
#include <string.h> #include <string.h>
#include <locale.h> #include <locale.h>
int nodescriptions = 0; /**
int nowrite = 0; ** global variables we are importing from other modules
**/
extern char * g_reportdir; extern char * g_reportdir;
extern char * g_datadir; extern char * g_datadir;
extern char * g_basedir; extern char * g_basedir;
@ -92,15 +88,26 @@ extern boolean nomsg;
extern boolean nobattle; extern boolean nobattle;
extern boolean nobattledebug; extern boolean nobattledebug;
int mapdetail = 0; #ifdef FUZZY_BASE36
extern int fuzzy_hits;
#endif /* FUZZY_BASE36 */
extern void render_init(void); /**
** global variables wthat we are exporting
**/
struct settings global = {
"Eressea", /* gamename */
};
static char * orders = NULL;
static int nowrite = 0;
static void static void
init_game(void) game_init(void)
{ {
init_triggers(); init_triggers();
init_locales();
init_races(); init_races();
init_spells(); init_spells();
@ -116,53 +123,9 @@ init_game(void)
init_museum(); init_museum();
init_arena(); init_arena();
init_xmas2000(); init_xmas2000();
render_init();
} }
void static void
create_game(void)
{
assert(regions==NULL || !"game is initialized");
printf("Keine Spieldaten gefunden, erzeuge neues Spiel in %s...\n", datapath());
makedir(datapath(), 0700);
/* erste Insel generieren */
new_region(0, 0);
/* Monsterpartei anlegen */
createmonsters();
/* Teleportebene anlegen */
create_teleport_plane();
}
void
map(void)
{
FILE * f;
region * r;
sprintf(buf, "map-%d.cr", turn);
f = fopen(buf, "wt");
fputs("VERSION 42\n", f);
fputs("\"Standard\";konfiguration\n", f);
fprintf(f, "%d;runde\n", turn);
for (r=regions;r;r=r->next) {
fprintf(f, "REGION %d %d\n", r->x, r->y);
fprintf(f, "\"%s\";name\n", rname(r, NULL));
fprintf(f, "\"%s\";terrain\n", terrain[rterrain(r)].name);
if (!mapdetail) continue;
fprintf(f, "%d;silber\n", rmoney(r));
if (r->display && strlen(r->display))
fprintf(f, "\"%s\";beschr\n", r->display);
fprintf(f, "%d;bauern\n", rpeasants(r));
fprintf(f, "%d;baeume\n", rtrees(r));
fprintf(f, "%d;pferde\n", rhorses(r));
if (rterrain(r) == T_MOUNTAIN || rterrain(r) == T_GLACIER) {
fprintf(f, "%d;eisen\n", riron(r));
if (rlaen(r)>=0) fprintf(f, "%d;laen\n", rlaen(r));
}
}
fclose(f);
}
void
getgarbage(void) getgarbage(void)
{ {
faction *f; faction *f;
@ -186,9 +149,7 @@ getgarbage(void)
#endif #endif
} }
int quickleave = 0; static void
void
writepasswd(void) writepasswd(void)
{ {
FILE * F; FILE * F;
@ -207,29 +168,25 @@ writepasswd(void)
} }
} }
#ifdef FUZZY_BASE36 static int
extern int fuzzy_hits;
#endif /* FUZZY_BASE36 */
void
processturn(char *filename) processturn(char *filename)
{ {
struct summary * begin, * end; struct summary * begin, * end;
int i;
begin = make_summary(false); begin = make_summary(false);
printf(" - Korrekturen Runde %d\n", turn); printf(" - Korrekturen Runde %d\n", turn);
korrektur(); korrektur();
turn++; turn++;
if (!quickleave) {
puts(" - entferne Texte der letzten Runde"); puts(" - entferne Texte der letzten Runde");
getgarbage(); getgarbage();
puts(" - Nehme Korrekturen am Datenbestand vor"); puts(" - Nehme Korrekturen am Datenbestand vor");
if (!readorders(filename)) return; if ((i=readorders(filename))!=0) return i;
#if BENCHMARK #if BENCHMARK
exit(0); exit(0);
#endif #endif
processorders(); processorders();
score(); score();
}
#ifdef WACH_WAFF #ifdef WACH_WAFF
remove_unequipped_guarded(); remove_unequipped_guarded();
#endif #endif
@ -254,40 +211,15 @@ processturn(char *filename)
sprintf(ztext, "%s/%d", datapath(), turn); sprintf(ztext, "%s/%d", datapath(), turn);
writegame(ztext, 0); writegame(ztext, 0);
} }
return 0;
} }
void
doreports(void)
{
struct summary * begin;
begin = make_summary(true);
printf("Schreibe die Reports der %d. Runde...\n", turn);
reports();
report_summary(begin, begin, false);
free(begin);
}
void
showmap(int mode)
{
FILE * F = cfopen("karte", "w");
if (!F)
return;
puts("Schreibe Karte...");
writemap(F, mode);
fclose(F);
}
#if ENNO_CLEANUP
extern void creport_cleanup(void); extern void creport_cleanup(void);
extern void reports_cleanup(void); extern void reports_cleanup(void);
extern void render_cleanup(void); extern void freeland(land_region * lr);
void static void
cleanup(void) game_done(void)
{ {
/* Diese Routine enfernt allen allokierten Speicher wieder. Das ist nur /* Diese Routine enfernt allen allokierten Speicher wieder. Das ist nur
* zum Debugging interessant, wenn man Leak Detection hat, und nach * zum Debugging interessant, wenn man Leak Detection hat, und nach
@ -299,10 +231,6 @@ cleanup(void)
faction *f, *f2; faction *f, *f2;
ship *s, *s2; ship *s, *s2;
creport_cleanup();
reports_cleanup();
render_cleanup();
free(used_faction_ids); free(used_faction_ids);
for (r = regions; r; r = r2) { for (r = regions; r; r = r2) {
#if 0 #if 0
@ -353,8 +281,9 @@ cleanup(void)
#ifdef LEAK_DETECT #ifdef LEAK_DETECT
leak_report(stderr); leak_report(stderr);
#endif #endif
creport_cleanup();
reports_cleanup();
} }
#endif
#include "magic.h" #include "magic.h"
@ -386,7 +315,7 @@ locale_check(void)
} }
#if MALLOCDBG #if MALLOCDBG
void static void
init_malloc_debug(void) init_malloc_debug(void)
{ {
#if (defined(_MSC_VER)) #if (defined(_MSC_VER))
@ -399,89 +328,9 @@ init_malloc_debug(void)
} }
#endif #endif
int #if 0
main(int argc, char *argv[]) static void
{ write_stats(void)
int i, errorlevel = 0;
setlocale(LC_ALL, "");
#ifdef LOCALE_CHECK
if (!locale_check())
puts("ERROR: The current locale is not suitable for international Eressea.\n");
#endif
#if MALLOCDBG
init_malloc_debug();
#endif
debug = 0;
quickleave = 0;
printf(
"\n"
"%s PBEM host\n"
"Copyright (C) 1996-99 C.Schlittchen, K.Zedel, E.Rehling, H.Peters.\n\n"
"based on Atlantis v1.0\n"
"Copyright (C) 1993 by Russell Wallace.\n"
"and on German Atlantis v2.3\n"
"Copyright (C) 1996 by Alexander Schroeder.\n\n"
"Eressea is distributed in the hope that it will be useful,\n"
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"
"This program may be freely used, modified and distributed. It may\n"
"not be sold or used commercially without prior written permission\n"
"from the author.\n\n"
"Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n", global.gamename, version());
for (i = 1; i != argc; i++)
if ((argv[i][0] == '-' || argv[i][0] == '/'))
switch (argv[i][1]) {
case 'o':
g_reportdir = argv[++i];
break;
case 'd':
if (!strcmp(argv[i] + 1, "debug")) {
nodescriptions = 1;
debug = fopen("debug", "w");
break;
}
g_datadir = argv[++i];
break;
case 'r':
g_resourcedir = argv[++i];
break;
case 'b':
g_basedir = argv[++i];
break;
case 't':
turn = atoi(argv[++i]);
break;
case 'f':
firstx = atoi(argv[++i]);
firsty = atoi(argv[++i]);
break;
case 'q':
quiet = 1;
break;
case 'i':
inside_only = 1;
printf(" - Lade nur die innersten Regionen.\n");
break;
case 'x':
maxregions = atoi(argv[++i]);
maxregions = (maxregions*81+80) / 81;
break;
}
{
char zText[MAX_PATH];
strcat(strcpy(zText, resourcepath()), "/timestrings");
read_datenames(zText);
}
#ifdef WRITE_STATS
{ {
FILE * F; FILE * F;
char zText[MAX_PATH]; char zText[MAX_PATH];
@ -528,239 +377,134 @@ main(int argc, char *argv[])
} }
} }
#endif #endif
init_game();
initgame(); static int
readgame(false); usage(const char * prog, const char * arg)
#if MALLOCDBG {
assert(_CrtCheckMemory()); if (arg) {
fprintf(stderr, "unknown argument: %s\n\n", arg);
}
fprintf(stderr, "Usage: %s [options]\n"
"-x n : Lädt nur die ersten n regionen\n"
"-f x y : Lädt nur die regionen ab (x,y)\n"
"-v befehlsdatei : verarbeitet automatisch die angegebene Befehlsdatei\n"
"-d datadir : gibt das datenverzeichnis an\n"
"-b basedir : gibt das basisverzeichnis an\n"
"-r resdir : gibt das resourceverzeichnis an\n"
"-t turn : read this datafile, not the most current one\n"
"-o reportdir : gibt das reportverzeichnis an\n"
"--nomsg : keine Messages (RAM sparen)\n"
"--nobattle : keine Kämpfe\n"
"--nodebug : keine Logfiles für Kämpfe\n"
"--debug : schreibt Debug-Ausgaben in die Datei debug\n"
"--nocr : keine CRs\n"
"--nonr : keine Reports\n"
#ifdef USE_MERIAN
"--nomer : keine Meriankarten\n"
#endif #endif
/* verify_data(); */ "--help : help\n", prog);
return -1;
}
if (turn == 0) static int
srand(time((time_t *) NULL)); read_args(int argc, char **argv)
else {
srand(turn); int i;
for (i=1;i!=argc;++i) {
/* Problem: In jedem Report ist die Regionsreihenfolge eine andere. */ if (argv[i][0]!='-') {
return usage(argv[0], argv[i]);
/* { int nregions=0; region *r; for(r=regions;r;r=r->next) nregions++; } else if (argv[i][1]=='-') { /* long format */
* scramble(regions, nregions, sizeof(region *)); } */
errorlevel = -1;
for (i = 1; i != argc; i++)
if (argv[i][0] == '-' ||
argv[i][0] == '/')
switch (argv[i][1]) {
case 'c':
korrektur();
break;
case 'Q':
quickleave = 1;
break;
case 'n':
if (strcmp(argv[i]+1, "nocr")==0) nocr = true; if (strcmp(argv[i]+1, "nocr")==0) nocr = true;
else if (strcmp(argv[i]+1, "nosave")==0) nowrite = true; else if (strcmp(argv[i]+2, "nosave")==0) nowrite = true;
else if (strcmp(argv[i]+1, "nonr")==0) nonr = true; else if (strcmp(argv[i]+2, "nonr")==0) nonr = true;
else if (strcmp(argv[i]+1, "nomer")==0) nomer = true; else if (strcmp(argv[i]+2, "nomsg")==0) nomsg = true;
else if (strcmp(argv[i]+1, "nomsg")==0) nomsg = true; else if (strcmp(argv[i]+2, "nobattle")==0) nobattle = true;
else if (strcmp(argv[i]+1, "nobattle")==0) nobattle = true; else if (strcmp(argv[i]+2, "nodebug")==0) nobattledebug = true;
else if (strcmp(argv[i]+1, "nodebug")==0) nobattledebug = true; #ifdef USE_MERIAN
break; else if (strcmp(argv[i]+2, "nomer")==0) nomer = true;
case 'v':
++i;
#define TEST_BORDERS 0
#if TEST_BORDERS
{
border * b;
new_border(&bt_fogwall, findregion(5,-6), findregion(5, -5));
new_border(&bt_noway, findregion(4,-5), findregion(5, -5));
new_border(&bt_wall, findregion(5,-5), findregion(6, -5));
b = new_border(&bt_illusionwall, findregion(4,-4), findregion(5, -5));
b->data = (void*) 1; /* partei 1 hat's gezaubert */
}
#endif #endif
if (i >= argc || argv[i][0]) { else if (strcmp(argv[i]+2, "help")==0)
printf(" - verwende Befehlsdatei: %s\n", argv[i]); return usage(argv[0], NULL);
processturn(argv[i]); else
errorlevel = 0; return usage(argv[0], argv[i]);
} else { } else switch(argv[i][1]) {
puts("Fehler: keine Befehlsdatei angegeben.\n\n"); case 'o':
errorlevel = 1; g_reportdir = argv[++i];
}
break; break;
#ifdef EXTRA_CR case 'd':
case 'p' : g_datadir = argv[++i];
{
FILE * out = fopen("planes.cr", "wt");
faction * f;
region * r;
if (!out) break;
fprintf(out, "VERSION 36\n");
for (f = factions; f; f = f->next) cr_faction(out, f);
for (r = regions;r;r=r->next) if (getplane(r)) cr_region(out, r);
fclose(out);
}
break; break;
case 'w' : case 'r':
{ g_resourcedir = argv[++i];
FILE * out = fopen("world.cr", "wt");
faction * f;
region * r;
if (!out) break;
fprintf(out, "VERSION 36\n");
for (f = factions; f; f = f->next) cr_faction(out, f);
for (r = regions;r;r=r->next) cr_region(out, r);
fclose(out);
}
break; break;
#endif case 'b':
g_basedir = argv[++i];
case '#':
score();
exit(0);
break; break;
case 'm': case 't':
if (argv[i][2]=='d') mapdetail = 1; turn = atoi(argv[++i]);
map();
break; break;
case 'f': case 'f':
i++; firstx = atoi(argv[++i]);
case 'r': firsty = atoi(argv[++i]);
case 'b': break;
case 't':
case 'x':
i++;
case 'q': case 'q':
case 'i': quiet = 1;
/* inner_world, quiet, minfaction und maxregions wird schon vorher abgefragt */
break; break;
default:
fprintf(stderr, "Usage: %s [options]\n"
"-r : schreibt die Reports neu\n"
"-x n : Lädt nur die ersten n regionen\n"
"-g befehlsdatei : verarbeitet Spielleiterbefehle\n"
"-v befehlsdatei : verarbeitet automatisch die angegebene Befehlsdatei\n"
"-# : gibt Scoreliste aus\n"
"-d datadir : gibt das datenverzeichnis an\n"
"-o reportdir : gibt das reportverzeichnis an\n"
"-nomsg : keine Messages (RAM sparen)\n"
#ifdef USE_MERIAN
"-nomer : keine Meriankarten\n"
#endif
"-nocr : keine CRs\n"
"-nonr : keine Reports\n"
"-nobattle : keine Kämpfe\n"
"-debug : schreibt Debug-Ausgaben in die Datei debug\n"
"-? : help\n", argv[0]);
errorlevel = 1;
break;
}
if (errorlevel >= 0) {
#if ENNO_CLEANUP
cleanup();
#endif
game_done();
return errorlevel;
}
puts("? zeigt das Menue an.");
printf("sizeof:\n region\t%d (%d)\n unit\t%d (%d)\n", (int)sizeof(region), listlen(regions), (int)sizeof(unit), -1);
printf(" ship\t%d (%d)\n building\t%d(%d)\n", (int)sizeof(ship), -1, (int)sizeof(building), -1);
for (;;) {
if (quickleave) break;
printf("> ");
fgets(buf, 1024, stdin);
switch (buf[0]) {
case 'c':
korrektur();
break;
case 'k':
showmap(M_TERRAIN);
break;
case 'p':
showmap(M_FACTIONS);
break;
case 'u':
showmap(M_UNARMED);
break;
case 'v': case 'v':
printf("Datei mit den Befehlen? "); if (i<argc) orders = argv[++i];
fgets(buf, 1024, stdin); else return usage(argv[0], argv[i]);
if (buf[0])
processturn(buf);
break; break;
case 'x':
case 's': maxregions = atoi(argv[++i]);
{ maxregions = (maxregions*81+80) / 81;
char ztext[64];
sprintf(ztext, "data/%d", turn);
writegame(ztext, 0);
}
break; break;
case 'q':
#if ENNO_CLEANUP
cleanup();
#endif
game_done();
return 0;
case 'Q':
quickleave = 1;
break;
case 'l':
listnames();
break;
case '#':
score();
break;
#ifdef QTMAP
case '*':
qt_edit_map(argc, argv);
break;
#endif
default: default:
puts("modify:\n" usage(argv[0], argv[i]);
" v - Befehle verarbeiten.\n"
" g - Spielleiterbefehle verarbeiten.\n"
" e - Erzeuge Regionen.\n"
" t - Terraform Region.\n"
" T - Terraform Block.\n"
" m - Erschaffe Einheiten und Monster.\n"
" b - Erbaue eine Burg.\n"
" n - Neue Spieler hinzufuegen.\n"
" M - Move unit.\n"
" c - Korrekturen durchführen.\n"
"information:\n"
" a - Adressen anzeigen.\n"
" i - Info ueber eine Region.\n"
" U - Info ueber units einer Region.\n"
" k - Karte anzeigen.\n"
" p - Politische Karte anzeigen.\n"
" u - Karte unbewaffneter Regionen anzeigen.\n"
" l - Liste aller Laendernamen zeigen.\n"
#ifdef QTMAP
" * - Qt-Karte anzeigen.\n"
#endif
"save:\n"
" r - Reports schreiben.\n"
" # - Scoreliste speichern.\n"
" s - Spielstand speichern.\n"
"\n"
" q - Beenden.");
} }
} }
return 0; return 0;
} }
struct settings global = { int
"Eressea", /* gamename */ main(int argc, char *argv[])
}; {
int i;
char zText[MAX_PATH];
printf("\n%s PBEM host\n"
"Copyright (C) 1996-2001 C.Schlittchen, K.Zedel, E.Rehling, H.Peters.\n\n"
"Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n\n", global.gamename, version());
setlocale(LC_ALL, "");
#ifdef LOCALE_CHECK
if (!locale_check()) {
puts("ERROR: The current locale is not suitable for international Eressea.\n");
return -1;
}
#endif
#if MALLOCDBG
init_malloc_debug();
#endif
if ((i=read_args(argc, argv))!=0) return i;
printf(
"version %d.%d\n"
"turn %d.\n"
"orders %s.\n",
global.data_version / 10, global.data_version % 10, turn, orders);
strcat(strcpy(zText, resourcepath()), "/timestrings");
if ((i=read_datenames(zText))!=0) return i;
kernel_init();
game_init();
if ((i=readgame(false))!=0) return i;
if ((i=processturn(orders))!=0) return i;
game_done();
kernel_done();
return 0;
}

View File

@ -1,6 +1,6 @@
/* vi: set ts=2: /* vi: set ts=2:
* *
* $Id: mapper.c,v 1.5 2001/02/04 18:51:00 corwin Exp $ * $Id: mapper.c,v 1.6 2001/02/05 16:11:58 enno Exp $
* Eressea PB(E)M host Copyright (C) 1998-2000 * Eressea PB(E)M host Copyright (C) 1998-2000
* Christian Schlittchen (corwin@amber.kn-bremen.de) * Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de)
@ -1160,9 +1160,6 @@ main(int argc, char *argv[])
maxregions = atoi(argv[++i]); maxregions = atoi(argv[++i]);
maxregions = (maxregions*81+80) / 81; maxregions = (maxregions*81+80) / 81;
break; break;
case 'i':
inside_only=1;
break;
case 'q': quiet = true; break; case 'q': quiet = true; break;
case 'n': case 'n':
switch (argv[i][2]) { switch (argv[i][2]) {
@ -1194,9 +1191,9 @@ main(int argc, char *argv[])
} }
} }
initgame(); kernel_init();
init_triggers(); init_triggers();
init_locales();
init_attributes(); init_attributes();
init_resources(); init_resources();
@ -1206,7 +1203,6 @@ main(int argc, char *argv[])
init_museum(); init_museum();
init_arena(); init_arena();
init_xmas2000(); init_xmas2000();
render_init();
if(!*datafile) if(!*datafile)
sprintf(datafile, "%s/%d", datapath(), turn); sprintf(datafile, "%s/%d", datapath(), turn);

View File

@ -90,7 +90,7 @@ main(int argc, char ** argv)
if (in==NULL) return -1; if (in==NULL) return -1;
} }
initgame(); kernel_init();
readgame(false); readgame(false);
markup(in); markup(in);