main() reorganization (trunk only)

Move some internals-related code out of port-specific main so that
it isn't duplicated a bunch of times.  One minor side-effect of this
change is that if you auto-pickup something at the very start of a game,
it will happen after any full moon/new moon/Friday 13th message rather
than before.  There's a second change for some:  the shared main() used
by several of the micro ports had a small difference in game play--if you
saved a game while on an engraving, it would automatically be read when
you resume--that will now occur for everybody [Elbereth weenies rejoice!].
pcmain() was also calling update_inventory() at start of play.  That's
unnecessary for new games, where inventory initialization triggers a call
to it for each item added to your pack; but I wasn't sure about restored
games, so everybody gets it there now.

     The Mac and BeOS ports evidently haven't been touched it some time;
they still referenced flags.move which got replaced by context.move quite
a while back.  The Windows GUI code has a declaration for mswin_moveloop()
which appears to be non-existant, but I left it alone.  I assume that the
Qt interface uses the existing main() routines; at least I couldn't find
any start of game code specific to it.  vmsmain's revised main() is the
only one which has been tested.
This commit is contained in:
nethack.rankin
2006-04-02 07:35:30 +00:00
parent 8ed2748d52
commit 2c0a072ef1
9 changed files with 94 additions and 108 deletions

View File

@@ -20,7 +20,7 @@ E char *FDECL(fmt_ptr, (const genericptr,char *));
/* ### allmain.c ### */ /* ### allmain.c ### */
E void NDECL(moveloop); E void FDECL(moveloop, (BOOLEAN_P));
E void NDECL(stop_occupation); E void NDECL(stop_occupation);
E void NDECL(display_gamewindows); E void NDECL(display_gamewindows);
E void NDECL(newgame); E void NDECL(newgame);

View File

@@ -1,4 +1,4 @@
/* SCCS Id: @(#)allmain.c 3.5 2003/04/02 */ /* SCCS Id: @(#)allmain.c 3.5 2006/04/01 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -15,7 +15,8 @@ STATIC_DCL void NDECL(do_positionbar);
#endif #endif
void void
moveloop() moveloop(resuming)
boolean resuming;
{ {
#if defined(MICRO) || defined(WIN32) #if defined(MICRO) || defined(WIN32)
char ch; char ch;
@@ -24,22 +25,6 @@ moveloop()
int moveamt = 0, wtcap = 0, change = 0; int moveamt = 0, wtcap = 0, change = 0;
boolean didmove = FALSE, monscanmove = FALSE; boolean didmove = FALSE, monscanmove = FALSE;
flags.moonphase = phase_of_the_moon();
if(flags.moonphase == FULL_MOON) {
You("are lucky! Full moon tonight.");
change_luck(1);
} else if(flags.moonphase == NEW_MOON) {
pline("Be careful! New moon tonight.");
}
flags.friday13 = friday_13th();
if (flags.friday13) {
pline("Watch out! Bad things can happen on Friday the 13th.");
change_luck(-1);
}
initrack();
/* Note: these initializers don't do anything except guarantee that /* Note: these initializers don't do anything except guarantee that
we're linked properly. we're linked properly.
*/ */
@@ -52,14 +37,38 @@ moveloop()
if (wizard) add_debug_extended_commands(); if (wizard) add_debug_extended_commands();
#endif #endif
/* side-effects from the real world */
flags.moonphase = phase_of_the_moon();
if(flags.moonphase == FULL_MOON) {
You("are lucky! Full moon tonight.");
change_luck(1);
} else if(flags.moonphase == NEW_MOON) {
pline("Be careful! New moon tonight.");
}
flags.friday13 = friday_13th();
if (flags.friday13) {
pline("Watch out! Bad things can happen on Friday the 13th.");
change_luck(-1);
}
if (!resuming) { /* new game */
set_wear(); /* handle side-effects of worn starting gear */
(void) pickup(1); /* autopickup at initial location */
} else {
update_inventory(); /* for perm_invent */
read_engr_at(u.ux, u.uy); /* subset of pickup() */
}
(void) encumber_msg(); /* in case they auto-picked up something */ (void) encumber_msg(); /* in case they auto-picked up something */
if (defer_see_monsters) { if (defer_see_monsters) {
defer_see_monsters = FALSE; defer_see_monsters = FALSE;
see_monsters(); see_monsters();
} }
initrack();
u.uz0.dlevel = u.uz.dlevel; u.uz0.dlevel = u.uz.dlevel;
youmonst.movement = NORMAL_SPEED; /* give the hero some movement points */ youmonst.movement = NORMAL_SPEED; /* give the hero some movement points */
context.move = 0;
for(;;) { for(;;) {
get_nh_event(); get_nh_event();

View File

@@ -1,4 +1,4 @@
/* SCCS Id: @(#)restore.c 3.5 2005/12/14 */ /* SCCS Id: @(#)restore.c 3.5 2006/04/01 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -849,6 +849,7 @@ register int fd;
/* Success! */ /* Success! */
welcome(FALSE); welcome(FALSE);
check_special_room(FALSE);
return(1); return(1);
} }

View File

@@ -1,4 +1,4 @@
/* SCCS Id: @(#)bemain.c 3.5 1998/07/15 */ /* SCCS Id: @(#)bemain.c 3.5 2006/04/01 */
/* Copyright (c) Dean Luick, 1996. */ /* Copyright (c) Dean Luick, 1996. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -23,6 +23,7 @@ int MAIN(int argc, char **argv)
{ {
int fd; int fd;
char *dir; char *dir;
boolean resuming = FALSE; /* assume new game */
dir = nh_getenv("NETHACKDIR"); dir = nh_getenv("NETHACKDIR");
if (!dir) dir = nh_getenv("HACKDIR"); if (!dir) dir = nh_getenv("HACKDIR");
@@ -93,37 +94,32 @@ int MAIN(int argc, char **argv)
#endif #endif
pline("Restoring save file..."); pline("Restoring save file...");
mark_synch(); /* flush output */ mark_synch(); /* flush output */
if(!dorecover(fd)) if (dorecover(fd)) {
goto not_recovered; resuming = TRUE; /* not starting new game */
#ifdef WIZARD #ifdef WIZARD
if(!wizard && remember_wiz_mode) wizard = TRUE; if (!wizard && remember_wiz_mode) wizard = TRUE;
#endif #endif
check_special_room(FALSE); if (discover)
if (discover)
You("are in non-scoring discovery mode."); You("are in non-scoring discovery mode.");
if (discover || wizard) { if (discover || wizard) {
if(yn("Do you want to keep the save file?") == 'n') if(yn("Do you want to keep the save file?") == 'n')
(void) delete_savefile(); (void) delete_savefile();
else { else {
nh_compress(fqname(SAVEF, SAVEPREFIX, 0)); nh_compress(fqname(SAVEF, SAVEPREFIX, 0));
} }
}
} }
}
flags.move = 0; if (!resuming) {
} else {
not_recovered:
player_selection(); player_selection();
newgame(); newgame();
if (discover) if (discover)
You("are in non-scoring discovery mode."); You("are in non-scoring discovery mode.");
flags.move = 0;
set_wear();
(void) pickup(1);
} }
moveloop(); moveloop(resuming);
return 0; return 0;
} }

View File

@@ -1,4 +1,4 @@
/* SCCS Id: @(#)macmain.c 3.5 1997/01/22 */ /* SCCS Id: @(#)macmain.c 3.5 2006/04/01 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -37,6 +37,7 @@ main (void)
{ {
register int fd = -1; register int fd = -1;
int argc = 1; int argc = 1;
boolean resuming = FALSE; /* assume new game */
windowprocs = mac_procs; windowprocs = mac_procs;
InitMac (); InitMac ();
@@ -108,11 +109,10 @@ main (void)
mark_synch(); /* flush output */ mark_synch(); /* flush output */
game_active = 1; game_active = 1;
if (dorecover(fd)) { if (dorecover(fd)) {
resuming = TRUE; /* not starting new game */
#ifdef WIZARD #ifdef WIZARD
if(!wizard && remember_wiz_mode) wizard = TRUE; if(!wizard && remember_wiz_mode) wizard = TRUE;
#endif #endif
check_special_room(FALSE);
if (discover || wizard) { if (discover || wizard) {
if(yn("Do you want to keep the save file?") == 'n') if(yn("Do you want to keep the save file?") == 'n')
(void) delete_savefile(); (void) delete_savefile();
@@ -121,25 +121,20 @@ main (void)
} }
} }
} }
else {
fd = -1; /* set bad status */
}
} }
if (fd < 0) {
if (!resuming) {
player_selection(); player_selection();
game_active = 1; /* done with selection, draw active game window */ game_active = 1; /* done with selection, draw active game window */
newgame(); newgame();
set_wear();
(void) pickup(1);
} }
if (discover) if (discover)
You("are in non-scoring discovery mode."); You("are in non-scoring discovery mode.");
flags.move = 0;
UndimMenuBar (); /* Yes, this is the place for it (!) */ UndimMenuBar (); /* Yes, this is the place for it (!) */
moveloop(); moveloop(resuming);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
/*NOTREACHED*/ /*NOTREACHED*/

View File

@@ -1,4 +1,4 @@
/* SCCS Id: @(#)pcmain.c 3.5 2002/08/22 */ /* SCCS Id: @(#)pcmain.c 3.5 2006/04/01 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -66,7 +66,7 @@ STATIC_DCL char *FDECL(exepath,(char *));
int FDECL(main, (int,char **)); int FDECL(main, (int,char **));
extern void FDECL(pcmain, (int,char **)); extern boolean FDECL(pcmain, (int,char **));
#if defined(__BORLANDC__) && !defined(_WIN32) #if defined(__BORLANDC__) && !defined(_WIN32)
@@ -84,18 +84,20 @@ main(argc,argv)
int argc; int argc;
char *argv[]; char *argv[];
{ {
pcmain(argc,argv); boolean resuming;
resuming = pcmain(argc,argv);
#ifdef LAN_FEATURES #ifdef LAN_FEATURES
init_lan_features(); init_lan_features();
#endif #endif
moveloop(); moveloop(resuming);
nethack_exit(EXIT_SUCCESS); nethack_exit(EXIT_SUCCESS);
/*NOTREACHED*/ /*NOTREACHED*/
return 0; return 0;
} }
#endif /*MSWIN_GRAPHICS*/ #endif /*MSWIN_GRAPHICS*/
void boolean
pcmain(argc,argv) pcmain(argc,argv)
int argc; int argc;
char *argv[]; char *argv[];
@@ -110,6 +112,7 @@ char *argv[];
#ifdef NOCWD_ASSUMPTIONS #ifdef NOCWD_ASSUMPTIONS
char failbuf[BUFSZ]; char failbuf[BUFSZ];
#endif #endif
boolean resuming = FALSE; /* assume new game */
#if defined(__BORLANDC__) && !defined(_WIN32) #if defined(__BORLANDC__) && !defined(_WIN32)
startup(); startup();
@@ -411,39 +414,29 @@ char *argv[];
pline("Restoring save file..."); pline("Restoring save file...");
mark_synch(); /* flush output */ mark_synch(); /* flush output */
if(!dorecover(fd)) if (dorecover(fd)) {
goto not_recovered; resuming = TRUE; /* not starting new game */
#ifdef WIZARD #ifdef WIZARD
if(!wizard && remember_wiz_mode) wizard = TRUE; if (!wizard && remember_wiz_mode) wizard = TRUE;
#endif #endif
check_special_room(FALSE); if (discover)
if (discover)
You("are in non-scoring discovery mode."); You("are in non-scoring discovery mode.");
update_inventory(); if (discover || wizard) {
if (discover || wizard) {
if(yn("Do you want to keep the save file?") == 'n') if(yn("Do you want to keep the save file?") == 'n')
(void) delete_savefile(); (void) delete_savefile();
else { else {
nh_compress(fqname(SAVEF, SAVEPREFIX, 0)); nh_compress(fqname(SAVEF, SAVEPREFIX, 0));
} }
}
} }
}
context.move = 0; if (!resuming) {
} else {
not_recovered:
player_selection(); player_selection();
newgame(); newgame();
if (discover) if (discover)
You("are in non-scoring discovery mode."); You("are in non-scoring discovery mode.");
context.move = 0;
set_wear();
(void) pickup(1);
read_engr_at(u.ux,u.uy);
update_inventory();
} }
#ifndef NO_SIGNAL #ifndef NO_SIGNAL
@@ -452,7 +445,7 @@ not_recovered:
#ifdef OS2 #ifdef OS2
gettty(); /* somehow ctrl-P gets turned back on during startup ... */ gettty(); /* somehow ctrl-P gets turned back on during startup ... */
#endif #endif
return; return resuming;
} }
STATIC_OVL void STATIC_OVL void

View File

@@ -1,4 +1,4 @@
/* SCCS Id: @(#)unixmain.c 3.5 1997/01/22 */ /* SCCS Id: @(#)unixmain.c 3.5 2006/04/01 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -54,6 +54,7 @@ char *argv[];
register char *dir; register char *dir;
#endif #endif
boolean exact_username; boolean exact_username;
boolean resuming = FALSE; /* assume new game */
#if defined(__APPLE__) #if defined(__APPLE__)
/* special hack to change working directory to a resource fork when /* special hack to change working directory to a resource fork when
@@ -274,35 +275,30 @@ char *argv[];
#endif #endif
pline("Restoring save file..."); pline("Restoring save file...");
mark_synch(); /* flush output */ mark_synch(); /* flush output */
if(!dorecover(fd)) if (dorecover(fd)) {
goto not_recovered; resuming = TRUE; /* not starting new game */
#ifdef WIZARD #ifdef WIZARD
if(!wizard && remember_wiz_mode) wizard = TRUE; if (!wizard && remember_wiz_mode) wizard = TRUE;
#endif #endif
check_special_room(FALSE); wd_message();
wd_message(); if (discover || wizard) {
if (discover || wizard) {
if(yn("Do you want to keep the save file?") == 'n') if(yn("Do you want to keep the save file?") == 'n')
(void) delete_savefile(); (void) delete_savefile();
else { else {
(void) chmod(fq_save,FCMASK); /* back to readable */ (void) chmod(fq_save,FCMASK); /* back to readable */
nh_compress(fq_save); nh_compress(fq_save);
} }
}
} }
context.move = 0; }
} else {
not_recovered: if (!resuming) {
player_selection(); player_selection();
newgame(); newgame();
wd_message(); wd_message();
context.move = 0;
set_wear();
(void) pickup(1);
} }
moveloop(); moveloop(resuming);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
/*NOTREACHED*/ /*NOTREACHED*/
return(0); return(0);

View File

@@ -1,4 +1,4 @@
/* SCCS Id: @(#)vmsmain.c 3.5 2003/10/16 */ /* SCCS Id: @(#)vmsmain.c 3.5 2006/04/01 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
/* main.c - VMS NetHack */ /* main.c - VMS NetHack */
@@ -36,6 +36,7 @@ char *argv[];
#ifdef CHDIR #ifdef CHDIR
register char *dir; register char *dir;
#endif #endif
boolean resuming = FALSE; /* assume new game */
#ifdef SECURE /* this should be the very first code executed */ #ifdef SECURE /* this should be the very first code executed */
privoff(); privoff();
@@ -195,34 +196,28 @@ char *argv[];
#endif #endif
pline("Restoring save file..."); pline("Restoring save file...");
mark_synch(); /* flush output */ mark_synch(); /* flush output */
if(!dorecover(fd)) if (dorecover(fd)) {
goto not_recovered; resuming = TRUE; /* not starting new game */
#ifdef WIZARD #ifdef WIZARD
if(!wizard && remember_wiz_mode) wizard = TRUE; if (!wizard && remember_wiz_mode) wizard = TRUE;
#endif #endif
check_special_room(FALSE); wd_message();
wd_message(); if (discover || wizard) {
if (discover || wizard) {
if (yn("Do you want to keep the save file?") == 'n') if (yn("Do you want to keep the save file?") == 'n')
(void) delete_savefile(); (void) delete_savefile();
else else
(void) chmod(fq_save,FCMASK); /* back to readable */ (void) chmod(fq_save,FCMASK); /* back to readable */
}
} }
}
context.move = 0; if (!resuming) {
} else {
not_recovered:
player_selection(); player_selection();
newgame(); newgame();
wd_message(); wd_message();
context.move = 0;
set_wear();
(void) pickup(1);
} }
moveloop(); moveloop(resuming);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
/*NOTREACHED*/ /*NOTREACHED*/
return(0); return(0);

View File

@@ -1,4 +1,4 @@
/* SCCS Id: @(#)winhack.c 3.5 2005/01/23 */ /* SCCS Id: @(#)winhack.c 3.5 2006/04/01 */
/* Copyright (C) 2001 by Alex Kompel */ /* Copyright (C) 2001 by Alex Kompel */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -62,7 +62,7 @@ NHWinApp _nethack_app;
#endif #endif
// Foward declarations of functions included in this code module: // Foward declarations of functions included in this code module:
extern void FDECL(pcmain, (int,char **)); extern boolean FDECL(pcmain, (int,char **));
static void __cdecl mswin_moveloop(void *); static void __cdecl mswin_moveloop(void *);
#define MAX_CMDLINE_PARAM 255 #define MAX_CMDLINE_PARAM 255
@@ -80,6 +80,7 @@ int APIENTRY WinMain(HINSTANCE hInstance,
TCHAR wbuf[BUFSZ]; TCHAR wbuf[BUFSZ];
char buf[BUFSZ]; char buf[BUFSZ];
DWORD major, minor; DWORD major, minor;
boolean resuming;
/* ensure that we don't access violate on a panic() */ /* ensure that we don't access violate on a panic() */
@@ -174,9 +175,9 @@ int APIENTRY WinMain(HINSTANCE hInstance,
} }
free(savefile); free(savefile);
} }
pcmain(argc,argv); resuming = pcmain(argc,argv);
moveloop(); moveloop(resuming);
return 0; return 0;
} }