#include extern const char *__progname; #include "obj.h" #include "mon.h" #include "vars.h" #include "dice.h" #include "time.h" #include "fuses.h" #include "debug.h" #include "screen.h" #include "display.h" #include "signals.h" #include "mon-@-you.h" #include "digdungeon.h" #include "filldungeon.h" #include "main.h" /* * Just clean up the curses and tty-mode state and exit. */ void die(int exitcode) { cleanupscreen(); exit(exitcode); } /* * Handle -trace. */ static int arg_opt_trace(const char *arg) { trace_open(arg); return(0); } /* * Handle -seed. */ static int arg_opt_seed(const char *arg) { unsigned long long int v; v = strtoull(arg,0,0); set_dice_seed(v); return(0); } /* * Handle -replay. */ static int arg_opt_replay(const char *arg) { trace_replay(arg); return(0); } /* * Parse the command line. */ static void handleargs(int ac, char **av) { int skip; int errs; skip = 0; errs = 0; for (ac--,av++;ac;ac--,av++) { if (skip > 0) { skip --; continue; } if (**av != '-') { fprintf(stderr,"%s: extra argument `%s'\n",__progname,*av); errs = 1; continue; } if (0) { needarg:; fprintf(stderr,"%s: %s needs a following argument\n",__progname,*av); errs ++; continue; } #define WANTARG() do { if (++skip >= ac) goto needarg; } while (0) if (!strcmp(*av,"-trace")) { WANTARG(); errs |= arg_opt_trace(av[skip]); continue; } if (!strcmp(*av,"-seed")) { WANTARG(); arg_opt_seed(av[skip]); continue; } if (!strcmp(*av,"-replay")) { WANTARG(); arg_opt_replay(av[skip]); continue; } #undef WANTARG fprintf(stderr,"%s: unrecognized option `%s'\n",__progname,*av); errs = 1; } if (errs) exit(1); } /* * Entry point, of course. Just set stuff up and drop into the main * loop. Our main loop just repeatedly calls tick(), since the * absolute amount of time passing doesn't matter, only that things * happen in the correct order. (Of course, we stop and wait for * player interaction during only a few of these tick() calls.) */ int main(int, char **); int main(int ac, char **av) { handleargs(ac,av); initsignals(); initrandom(); curtime = 0; initfuses(); initscreen(); initdisplay(); digdungeon(); initobj(); cleardungeon(); filldungeon(); debugcatch(); initmonst(); setup_you(); init_track(); makemon_fuse(0,0); while (1) tick(); }