/** * Display the winner crown */ static void display_winner(void) { char buf[1024]; ang_file *fp; int wid, hgt; int i = 2; int width = 0; path_build(buf, sizeof(buf), ANGBAND_DIR_SCREENS, "crown.txt"); fp = file_open(buf, MODE_READ, FTYPE_TEXT); Term_clear(); Term_get_size(&wid, &hgt); if (fp) { /* Get us the first line of file, which tells us how long the */ /* longest line is */ file_getl(fp, buf, sizeof(buf)); sscanf(buf, "%d", &width); if (!width) width = 25; /* Dump the file to the screen */ while (file_getl(fp, buf, sizeof(buf))) put_str(buf, i++, (wid/2) - (width/2)); file_close(fp); } put_str_centred(i, 0, wid, "All Hail the Mighty Champion!"); event_signal(EVENT_INPUT_FLUSH); pause_line(Term); }
/* * Change the player into a King! -RAK- */ void kingly(void) { int wid, hgt; int cx, cy; bool seppuku = streq(p_ptr->died_from, "Seppuku"); /* Hack -- retire in town */ dun_level = 0; /* Fake death */ if (!seppuku) (void)strcpy(p_ptr->died_from, "Ripe Old Age"); /* Restore the experience */ p_ptr->exp = p_ptr->max_exp; /* Restore the level */ p_ptr->lev = p_ptr->max_plv; Term_get_size(&wid, &hgt); cy = hgt / 2; cx = wid / 2; /* Hack -- Instant Gold */ p_ptr->au += 10000000; stats_on_gold_winnings(10000000); /* Clear screen */ Term_clear(); /* Display a crown */ put_str("#", cy - 11, cx - 1); put_str("#####", cy - 10, cx - 3); put_str("#", cy - 9, cx - 1); put_str(",,, $$$ ,,,", cy - 8, cx - 7); put_str(",,=$ \"$$$$$\" $=,,", cy - 7, cx - 11); put_str(",$$ $$$ $$,", cy - 6, cx - 13); put_str("*> <*> <*", cy - 5, cx - 13); put_str("$$ $$$ $$", cy - 4, cx - 13); put_str("\"$$ $$$ $$\"", cy - 3, cx - 13); put_str("\"$$ $$$ $$\"", cy - 2, cx - 12); put_str("*#########*#########*", cy - 1, cx - 11); put_str("*#########*#########*", cy, cx - 11); /* Display a message */ put_str("Veni, Vidi, Vici!", cy + 3, cx - 9); put_str("I came, I saw, I conquered!", cy + 4, cx - 14); put_str(format("All Hail the Mighty %s!", sex_info[p_ptr->psex].winner), cy + 5, cx - 13); /* Flush input */ flush(); /* Wait for response */ pause_line(hgt - 1); }
void angbandThread(void *arg) { bool new_game = FALSE; int show_score = 0; char player_name_aga[32]; /* Save the "program name" */ argv0 = (char*)arg; /* Use the "main-emx.c" support */ init_emx(); ANGBAND_SYS = "ibm"; /* Get the file paths */ init_stuff(); if (!emx_options((char**)&ANGBAND_DIR_USER, (char**)&ANGBAND_DIR_SAVE, (char**)&ANGBAND_DIR_INFO, &arg_force_roguelike, &arg_force_original, &arg_fiddle, &arg_wizard, player_name_aga)) quit(NULL); /* XXX XXX XXX (?) */ strcpy(player_name, player_name_aga); /* Process the player name */ process_player_name(TRUE); /* Tell "quit()" to call "Term_nuke()" */ quit_aux = quit_hook; /* If requested, display scores and quit */ if (show_score > 0) display_scores(0, show_score); /* Catch nasty signals */ signals_init(); /* Initialize */ init_angband(); /* Wait for response */ pause_line(23); /* Play the game */ play_game(new_game); /* Quit */ quit(NULL); }
/* * Hack -- Show information on the screen, one line at a time. * * Avoid the top two lines, to avoid interference with "note()". */ void note(const char *message) { static int y = 2; /* Draw the message */ prt(message, y, 0); pause_line(Term); /* Advance one line (wrap if needed) */ if (++y >= 24) y = 2; /* Flush it */ Term_fresh(); }
/* * Pass the appropriate "Initialisation screen" command to the game, * getting user input if needed. */ static errr get_init_cmd(void) { /* Wait for response */ pause_line(Term); if (new_game) cmd_insert(CMD_NEWGAME); else /* This might be modified to supply the filename in future. */ cmd_insert(CMD_LOADFILE); /* Everything's OK. */ return 0; }
/** * Change the player into a Winner */ static void kingly(void) { /* Hack -- retire in town */ p_ptr->depth = 0; /* Fake death */ strcpy(p_ptr->died_from, "Ripe Old Age"); /* Restore the experience */ p_ptr->exp = p_ptr->max_exp; /* Restore the level */ p_ptr->lev = p_ptr->max_lev; /* Hack -- Instant Gold */ p_ptr->au += 10000000L; /* Limit to avoid buffer overflow */ if (p_ptr->au > PY_MAX_GOLD) p_ptr->au = PY_MAX_GOLD; /* Clear screen */ Term_clear(); /* Display a crown */ put_str("#", 1, 34); put_str("#####", 2, 32); put_str("#", 3, 34); put_str(",,, $$$ ,,,", 4, 28); put_str(",,=$ \"$$$$$\" $=,,", 5, 24); put_str(",$$ $$$ $$,", 6, 22); put_str("*> <*> <*", 7, 22); put_str("$$ $$$ $$", 8, 22); put_str("\"$$ $$$ $$\"", 9, 22); put_str("\"$$ $$$ $$\"", 10, 23); put_str("*#########*#########*", 11, 24); put_str("*#########*#########*", 12, 24); /* Display a message */ put_str("Veni, Vidi, Vici!", 15, 26); put_str("I came, I saw, I conquered!", 16, 21); put_str(format("All Hail the Mighty %s!", sp_ptr->winner), 17, 22); /* Flush input */ flush(); /* Wait for response */ pause_line(23); }
/* * Display the winner crown */ static void display_winner(void) { char buf[1024]; ang_file *fp; int wid, hgt; int i = 2; int width = 0; path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "crown.txt"); fp = file_open(buf, MODE_READ, -1); Term_clear(); Term_get_size(&wid, &hgt); if (fp) { /* Get us the first line of file, which tells us how long the */ /* longest line is */ file_getl(fp, buf, sizeof(buf)); sscanf(buf, "%d", &width); if (!width) width = 25; /* Dump the file to the screen */ while (file_getl(fp, buf, sizeof(buf))) put_str(buf, i++, (wid/2) - (width/2)); file_close(fp); } put_str_centred(i, 0, wid, "All Hail the Mighty %s!", p_ptr->sex->winner); flush(); pause_line(Term); }
/* * Simple "main" function for multiple platforms. * * Note the special "--" option which terminates the processing of * standard options. All non-standard options (if any) are passed * directly to the "init_xxx()" function. */ int main(int argc, char *argv[]) { int i; bool done = FALSE; bool new_game = FALSE; int show_score = 0; cptr mstr = NULL; bool args = TRUE; /* Save the "program name" XXX XXX XXX */ argv0 = argv[0]; #ifdef USE_286 /* Attempt to use XMS (or EMS) memory for swap space */ if (_OvrInitExt(0L, 0L)) { _OvrInitEms(0, 0, 64); } #endif #ifdef SET_UID /* Default permissions on files */ (void)umask(022); # ifdef SECURE /* Authenticate */ Authenticate(); # endif #endif /* Get the file paths */ init_stuff(); #ifdef SET_UID /* Get the user id (?) */ player_uid = getuid(); #ifdef VMS /* Mega-Hack -- Factor group id */ player_uid += (getgid() * 1000); #endif # ifdef SAFE_SETUID # ifdef _POSIX_SAVED_IDS /* Save some info for later */ player_euid = geteuid(); player_egid = getegid(); # endif # if 0 /* XXX XXX XXX */ /* Redundant setting necessary in case root is running the game */ /* If not root or game not setuid the following two calls do nothing */ if (setgid(getegid()) != 0) { quit("setgid(): cannot set permissions correctly!"); } if (setuid(geteuid()) != 0) { quit("setuid(): cannot set permissions correctly!"); } # endif # endif #endif #ifdef SET_UID /* Initialize the "time" checker */ if (check_time_init() || check_time()) { quit("The gates to Angband are closed (bad time)."); } /* Initialize the "load" checker */ if (check_load_init() || check_load()) { quit("The gates to Angband are closed (bad load)."); } /* Acquire the "user name" as a default player name */ #ifdef ANGBAND_2_8_1 user_name(player_name, player_uid); #else /* ANGBAND_2_8_1 */ user_name(op_ptr->full_name, player_uid); #endif /* ANGBAND_2_8_1 */ #ifdef PRIVATE_USER_PATH /* Create a directory for the users files. */ create_user_dir(); #endif /* PRIVATE_USER_PATH */ #endif /* SET_UID */ /* Process the command line arguments */ for (i = 1; args && (i < argc); i++) { /* Require proper options */ if (argv[i][0] != '-') game_usage(); /* Analyze option */ switch (argv[i][1]) { case 'N': case 'n': { new_game = TRUE; break; } case 'F': case 'f': { arg_fiddle = TRUE; break; } case 'W': case 'w': { arg_wizard = TRUE; break; } case 'V': case 'v': { arg_sound = TRUE; break; } case 'G': case 'g': { /* HACK - Graphics mode switches on the original tiles */ arg_graphics = GRAPHICS_ORIGINAL; break; } case 'R': case 'r': { arg_force_roguelike = TRUE; break; } case 'O': case 'o': { arg_force_original = TRUE; break; } case 'S': case 's': { show_score = atoi(&argv[i][2]); if (show_score <= 0) show_score = 10; break; } case 'u': case 'U': { if (!argv[i][2]) game_usage(); #ifdef ANGBAND_2_8_1 strncpy(player_name, &argv[i][2], 32); player_name[31] = '\0'; #else /* ANGBAND_2_8_1 */ strncpy(op_ptr->full_name, &argv[i][2], 32); op_ptr->full_name[31] = '\0'; #endif /* ANGBAND_2_8_1 */ break; } case 'm': { if (!argv[i][2]) game_usage(); mstr = &argv[i][2]; break; } case 'M': { arg_monochrome = TRUE; break; } case 'd': case 'D': { change_path(&argv[i][2]); break; } case '-': { argv[i] = argv[0]; argc = argc - i; argv = argv + i; args = FALSE; break; } default: { /* Default usage-help */ game_usage(); } } } /* Hack -- Forget standard args */ if (args) { argc = 1; argv[1] = NULL; } /* Process the player name */ process_player_name(TRUE); /* Install "quit" hook */ quit_aux = quit_hook; /* * Drop privs (so X11 will work correctly) * unless we are running the Linux-SVGALib version. * * (In which case we initialize after safe_setuid_grab() * is called.) */ safe_setuid_drop(); #ifdef USE_XAW /* Attempt to use the "main-xaw.c" support */ if (!done && (!mstr || (streq(mstr, "xaw")))) { if (0 == init_xaw(argc, argv)) { ANGBAND_SYS = "xaw"; done = TRUE; } } #endif #ifdef USE_X11 /* Attempt to use the "main-x11.c" support */ if (!done && (!mstr || (streq(mstr, "x11")))) { if (0 == init_x11(argc, argv)) { ANGBAND_SYS = "x11"; done = TRUE; } } #endif #ifdef USE_XPJ /* Attempt to use the "main-xpj.c" support */ if (!done && (!mstr || (streq(mstr, "xpj")))) { if (0 == init_xpj(argc, argv)) { ANGBAND_SYS = "xpj"; done = TRUE; } } #endif #ifdef USE_GTK /* Attempt to use the "main-gtk.c" support */ if (!done && (!mstr || (streq(mstr, "gtk")))) { if (0 == init_gtk((unsigned char*) &new_game, argc, argv)) { done = TRUE; } } #endif #ifdef USE_GCU /* Attempt to use the "main-gcu.c" support */ if (!done && (!mstr || (streq(mstr, "gcu")))) { if (0 == init_gcu()) { ANGBAND_SYS = "gcu"; done = TRUE; } } #endif #ifdef USE_CAP /* Attempt to use the "main-cap.c" support */ if (!done && (!mstr || (streq(mstr, "cap")))) { if (0 == init_cap(argc, argv)) { ANGBAND_SYS = "cap"; done = TRUE; } } #endif #ifdef USE_DOS /* Attempt to use the "main-dos.c" support */ if (!done && (!mstr || (streq(mstr, "dos")))) { if (0 == init_dos()) { ANGBAND_SYS = "dos"; done = TRUE; } } #endif #ifdef USE_IBM /* Attempt to use the "main-ibm.c" support */ if (!done && (!mstr || (streq(mstr, "ibm")))) { if (0 == init_ibm()) { ANGBAND_SYS = "ibm"; done = TRUE; } } #endif #ifdef USE_EMX /* Attempt to use the "main-emx.c" support */ if (!done && (!mstr || (streq(mstr, "emx")))) { if (0 == init_emx()) { ANGBAND_SYS = "emx"; done = TRUE; } } #endif #ifdef USE_SLA /* Attempt to use the "main-sla.c" support */ if (!done && (!mstr || (streq(mstr, "sla")))) { if (0 == init_sla()) { ANGBAND_SYS = "sla"; done = TRUE; } } #endif #ifdef USE_AMI /* Attempt to use the "main-ami.c" support */ if (!done && (!mstr || (streq(mstr, "ami")))) { if (0 == init_ami()) { ANGBAND_SYS = "ami"; done = TRUE; } } #endif #ifdef USE_VME /* Attempt to use the "main-vme.c" support */ if (!done && (!mstr || (streq(mstr, "vme")))) { if (0 == init_vme()) { ANGBAND_SYS = "vme"; done = TRUE; } } #endif #ifdef USE_VCS /* Attempt to use the "main-vcs.c" support */ if (!done && (!mstr || (streq(mstr, "vcs")))) { if (0 == init_vcs(argc, argv)) { ANGBAND_SYS = "vcs"; done = TRUE; } } #endif /* USE_VCS */ /* Grab privs (dropped above for X11) */ safe_setuid_grab(); #ifdef USE_LSL /* Attempt to use the "main-lsl.c" support */ if (!done && (!mstr || (streq(mstr, "lsl")))) { if (0 == init_lsl()) { ANGBAND_SYS = "lsl"; done = TRUE; } } #endif /* Make sure we have a display! */ if (!done) quit("Unable to prepare any 'display module'!"); /* Hack -- If requested, display scores and quit */ if (show_score > 0) display_scores(0, show_score); /* Gtk initializes earlier */ if (!streq(ANGBAND_SYS, "gtk")) { /* Catch nasty signals */ signals_init(); /* Initialize */ init_angband(); } /* Wait for response */ pause_line(23); /* Play the game */ play_game(new_game); /* Quit */ quit(NULL); /* Exit */ return (0); }
/* * Simple "main" function for multiple platforms. * * Note the special "--" option which terminates the processing of * standard options. All non-standard options (if any) are passed * directly to the "init_xxx()" function. */ int main(int argc, char *argv[]) { int i; bool done = FALSE; bool new_game = FALSE; int show_score = 0; cptr mstr = NULL; bool args = TRUE; /* Save the "program name" XXX XXX XXX */ argv0 = argv[0]; #ifdef USE_286 /* Attempt to use XMS (or EMS) memory for swap space */ if (_OvrInitExt(0L, 0L)) { _OvrInitEms(0, 0, 64); } #endif #ifdef SET_UID /* Default permissions on files */ (void)umask(022); # ifdef SECURE /* Authenticate */ Authenticate(); # endif #endif /* Get the file paths */ init_stuff(); #ifdef SET_UID /* Get the user id (?) */ player_uid = getuid(); #ifdef VMS /* Mega-Hack -- Factor group id */ player_uid += (getgid() * 1000); #endif # ifdef SAFE_SETUID # ifdef _POSIX_SAVED_IDS /* Save some info for later */ player_euid = geteuid(); player_egid = getegid(); # endif # if 0 /* XXX XXX XXX */ /* Redundant setting necessary in case root is running the game */ /* If not root or game not setuid the following two calls do nothing */ if (setgid(getegid()) != 0) { quit("setgid(): cannot set permissions correctly!"); } if (setuid(geteuid()) != 0) { quit("setuid(): cannot set permissions correctly!"); } # endif # endif #endif /* Drop permissions */ safe_setuid_drop(); #ifdef SET_UID /* Initialize the "time" checker */ if (check_time_init() || check_time()) { quit("The gates to Angband are closed (bad time)."); } /* Initialize the "load" checker */ if (check_load_init() || check_load()) { quit("The gates to Angband are closed (bad load)."); } /* Acquire the "user name" as a default player name */ user_name(player_name, player_uid); #ifdef PRIVATE_USER_PATH /* Create a directory for the users files. */ create_user_dir(); #endif /* PRIVATE_USER_PATH */ #endif /* SET_UID */ /* Process the command line arguments */ for (i = 1; args && (i < argc); i++) { /* Require proper options */ if (argv[i][0] != '-') goto usage; /* Analyze option */ switch (argv[i][1]) { case 'N': case 'n': { new_game = TRUE; break; } case 'F': case 'f': { arg_fiddle = TRUE; break; } case 'W': case 'w': { arg_wizard = TRUE; break; } case 'V': case 'v': { arg_sound = TRUE; break; } case 'G': case 'g': { /* HACK - Graphics mode switches on the original tiles */ arg_graphics = GRAPHICS_ORIGINAL; break; } case 'R': case 'r': { arg_force_roguelike = TRUE; break; } case 'O': case 'o': { arg_force_original = TRUE; break; } case 'S': case 's': { show_score = atoi(&argv[i][2]); if (show_score <= 0) show_score = 10; break; } case 'u': case 'U': { if (!argv[i][2]) goto usage; strcpy(player_name, &argv[i][2]); break; } case 'm': { if (!argv[i][2]) goto usage; mstr = &argv[i][2]; break; } case 'M': { arg_monochrome = TRUE; break; } case 'd': case 'D': { change_path(&argv[i][2]); break; } case '-': { argv[i] = argv[0]; argc = argc - i; argv = argv + i; args = FALSE; break; } default: usage: { /* Dump usage information */ puts("Usage: angband [options] [-- subopts]"); puts(" -n Start a new character"); puts(" -f Request fiddle mode"); puts(" -w Request wizard mode"); puts(" -v Request sound mode"); puts(" -g Request graphics mode"); puts(" -o Request original keyset"); puts(" -r Request rogue-like keyset"); puts(" -M Request monochrome mode"); puts(" -s<num> Show <num> high scores"); puts(" -u<who> Use your <who> savefile"); puts(" -m<sys> Force 'main-<sys>.c' usage"); puts(" -d<def> Define a 'lib' dir sub-path"); puts(""); #ifdef USE_SDL puts(" -msdl To use SDL"); #endif /* USE_SDL */ #ifdef USE_X11 puts(" -mx11 To use X11"); puts(" -- Sub options"); puts(" -- -d Set display name"); puts(" -- -o Request old 8x8 tile graphics"); puts(" -- -a Request Adam Bolt 16x16 tile graphics"); puts(" -- -b Request Bigtile graphics mode"); puts(" -- -s Turn off smoothscaling graphics"); puts(" -- -n# Number of terms to use"); puts(""); #endif /* USE_X11 */ #ifdef USE_GCU puts(" -mgcu To use GCU (GNU Curses)"); #endif /* USE_GCU */ #ifdef USE_CAP puts(" -mcap To use CAP (\"Termcap\" calls)"); #endif /* USE_CAP */ #ifdef USE_DOS puts(" -mdos To use DOS (Graphics)"); #endif /* USE_DOS */ #ifdef USE_IBM puts(" -mibm To use IBM (BIOS text mode)"); #endif /* USE_IBM */ #ifdef USE_SLA puts(" -msla To use SLA (SLANG)"); #endif /* USE_SLA */ #ifdef USE_LSL puts(" -mlsl To use LSL (Linux-SVGALIB)"); #endif /* USE_LSL */ #ifdef USE_AMI puts(" -mami To use AMI (Amiga)"); #endif /* USE_AMI */ #ifdef USE_VME puts(" -mvme To use VME (VAX/ESA)"); #endif /* USE_VME */ /* Actually abort the process */ quit(NULL); } } } /* Hack -- Forget standard args */ if (args) { argc = 1; argv[1] = NULL; } /* Process the player name */ process_player_name(TRUE); /* Create any missing directories */ create_needed_dirs(); /* Install "quit" hook */ quit_aux = quit_hook; #ifdef USE_XAW /* Attempt to use the "main-xaw.c" support */ if (!done && (!mstr || (streq(mstr, "xaw")))) { extern errr init_xaw(int, char**); if (0 == init_xaw(argc, argv)) { ANGBAND_SYS = "xaw"; done = TRUE; } } #endif #ifdef USE_SDL /* Attempt to use the "main-sdl.c" support */ if (!done && (!mstr || (streq(mstr, "sdl")))) { extern errr init_sdl(int, char**); if (0 == init_sdl(argc, argv)) { ANGBAND_SYS = "sdl"; done = TRUE; } } #endif #ifdef USE_X11 /* Attempt to use the "main-x11.c" support */ if (!done && (!mstr || (streq(mstr, "x11")))) { extern errr init_x11(int, char**); if (0 == init_x11(argc, argv)) { ANGBAND_SYS = "x11"; done = TRUE; } } #endif #ifdef USE_GCU /* Attempt to use the "main-gcu.c" support */ if (!done && (!mstr || (streq(mstr, "gcu")))) { extern errr init_gcu(int, char**); if (0 == init_gcu(argc, argv)) { ANGBAND_SYS = "gcu"; done = TRUE; } } #endif #ifdef USE_CAP /* Attempt to use the "main-cap.c" support */ if (!done && (!mstr || (streq(mstr, "cap")))) { extern errr init_cap(int, char**); if (0 == init_cap(argc, argv)) { ANGBAND_SYS = "cap"; done = TRUE; } } #endif #ifdef USE_DOS /* Attempt to use the "main-dos.c" support */ if (!done && (!mstr || (streq(mstr, "dos")))) { extern errr init_dos(void); if (0 == init_dos()) { ANGBAND_SYS = "dos"; done = TRUE; } } #endif #ifdef USE_IBM /* Attempt to use the "main-ibm.c" support */ if (!done && (!mstr || (streq(mstr, "ibm")))) { extern errr init_ibm(void); if (0 == init_ibm()) { ANGBAND_SYS = "ibm"; done = TRUE; } } #endif #ifdef USE_EMX /* Attempt to use the "main-emx.c" support */ if (!done && (!mstr || (streq(mstr, "emx")))) { extern errr init_emx(void); if (0 == init_emx()) { ANGBAND_SYS = "emx"; done = TRUE; } } #endif #ifdef USE_SLA /* Attempt to use the "main-sla.c" support */ if (!done && (!mstr || (streq(mstr, "sla")))) { extern errr init_sla(void); if (0 == init_sla()) { ANGBAND_SYS = "sla"; done = TRUE; } } #endif #ifdef USE_LSL /* Attempt to use the "main-lsl.c" support */ if (!done && (!mstr || (streq(mstr, "lsl")))) { extern errr init_lsl(void); if (0 == init_lsl()) { ANGBAND_SYS = "lsl"; done = TRUE; } } #endif #ifdef USE_AMI /* Attempt to use the "main-ami.c" support */ if (!done && (!mstr || (streq(mstr, "ami")))) { extern errr init_ami(void); if (0 == init_ami()) { ANGBAND_SYS = "ami"; done = TRUE; } } #endif #ifdef USE_VME /* Attempt to use the "main-vme.c" support */ if (!done && (!mstr || (streq(mstr, "vme")))) { extern errr init_vme(void); if (0 == init_vme()) { ANGBAND_SYS = "vme"; done = TRUE; } } #endif /* Make sure we have a display! */ if (!done) quit("Unable to prepare any 'display module'!"); /* Hack -- If requested, display scores and quit */ if (show_score > 0) display_scores(0, show_score); /* Catch nasty signals */ signals_init(); /* Initialize */ init_angband(); /* Wait for response */ pause_line(23); /* Play the game */ play_game(new_game); /* Quit */ quit(NULL); /* Exit */ return (0); }
/** * Simple "main" function for multiple platforms. * * Note the special "--" option which terminates the processing of * standard options. All non-standard options (if any) are passed * directly to the "init_xxx()" function. */ int main(int argc, char *argv[]) { int i; bool done = FALSE; const char *mstr = NULL; const char *soundstr = NULL; bool args = TRUE; /* Save the "program name" XXX XXX XXX */ argv0 = argv[0]; #ifdef UNIX /* Default permissions on files */ (void)umask(022); /* Get the user id */ player_uid = getuid(); #endif /* UNIX */ #ifdef SETGID /* Save the effective GID for later recall */ player_egid = getegid(); #endif /* UNIX */ /* Drop permissions */ safe_setuid_drop(); /* Get the file paths * Paths may be overriden by -d options, so this has to occur *before* * processing command line args */ init_stuff(); /* Process the command line arguments */ for (i = 1; args && (i < argc); i++) { const char *arg = argv[i]; /* Require proper options */ if (*arg++ != '-') goto usage; /* Analyze option */ switch (*arg++) { case 'l': list_saves(); exit(0); case 'n': new_game = TRUE; break; case 'w': arg_wizard = TRUE; break; case 'p': arg_power = TRUE; break; case 'r': arg_rebalance = TRUE; break; case 'g': /* Default graphics tile */ /* in graphics.txt, 2 corresponds to adam bolt's tiles */ arg_graphics = 2; if (*arg) arg_graphics = atoi(arg); break; case 'u': { if (!*arg) goto usage; my_strcpy(op_ptr->full_name, arg, sizeof op_ptr->full_name); /* The difference here is because on setgid we have to be * careful to only let the player have savefiles stored in * the central save directory. Sanitising input using * player_safe_name() removes anything like that. * * But if the player is running with per-user saves, they * can do whatever the hell they want. */ #ifdef SETGID savefile_set_name(player_safe_name(player, FALSE)); #else savefile_set_name(arg); #endif /* SETGID */ continue; } case 'm': if (!*arg) goto usage; mstr = arg; continue; case 's': if (!*arg) goto usage; soundstr = arg; continue; case 'd': change_path(arg); continue; case 'x': debug_opt(arg); continue; case '-': argv[i] = argv[0]; argc = argc - i; argv = argv + i; args = FALSE; break; default: usage: puts("Usage: angband [options] [-- subopts]"); puts(" -n Start a new character (WARNING: overwrites default savefile without -u)"); puts(" -l Lists all savefiles you can play"); puts(" -w Resurrect dead character (marks savefile)"); puts(" -r Rebalance monsters"); puts(" -g Request graphics mode"); puts(" -x<opt> Debug options; see -xhelp"); puts(" -u<who> Use your <who> savefile"); puts(" -d<dir>=<path> Override a specific directory with <path>. <path> can be:"); for (i = 0; i < (int)N_ELEMENTS(change_path_values); i++) { #ifdef SETGID if (!change_path_values[i].setgid_ok) continue; #endif printf(" %s (default is %s)\n", change_path_values[i].name, *change_path_values[i].path); } puts(" Multiple -d options are allowed."); puts(" -s<mod> Use sound module <sys>:"); for (i = 0; i < (int)N_ELEMENTS(sound_modules); i++) printf(" %s %s\n", sound_modules[i].name, sound_modules[i].help); puts(" -m<sys> Use module <sys>, where <sys> can be:"); /* Print the name and help for each available module */ for (i = 0; i < (int)N_ELEMENTS(modules); i++) printf(" %s %s\n", modules[i].name, modules[i].help); /* Actually abort the process */ quit(NULL); } if (*arg) goto usage; } /* Hack -- Forget standard args */ if (args) { argc = 1; argv[1] = NULL; } /* Install "quit" hook */ quit_aux = quit_hook; /* If we were told which mode to use, then use it */ if (mstr) ANGBAND_SYS = mstr; if (setlocale(LC_CTYPE, "")) { /* Require UTF-8 */ if (strcmp(nl_langinfo(CODESET), "UTF-8") != 0) quit("Angband requires UTF-8 support"); } /* Try the modules in the order specified by modules[] */ for (i = 0; i < (int)N_ELEMENTS(modules); i++) { /* User requested a specific module? */ if (!mstr || (streq(mstr, modules[i].name))) { ANGBAND_SYS = modules[i].name; if (0 == modules[i].init(argc, argv)) { done = TRUE; break; } } } /* Make sure we have a display! */ if (!done) quit("Unable to prepare any 'display module'!"); #ifdef UNIX /* Get the "user name" as default player name, unless set with -u switch */ if (!op_ptr->full_name[0]) { user_name(op_ptr->full_name, sizeof(op_ptr->full_name), player_uid); /* Set the savefile to load */ savefile_set_name(player_safe_name(player, FALSE)); } /* Create any missing directories */ create_needed_dirs(); #endif /* UNIX */ /* Try the modules in the order specified by sound_modules[] */ for (i = 0; i < (int)N_ELEMENTS(sound_modules); i++) if (!soundstr || streq(soundstr, sound_modules[i].name)) if (0 == sound_modules[i].init(argc, argv)) break; /* Catch nasty signals */ signals_init(); /* Set up the command hook */ cmd_get_hook = textui_get_cmd; /* Set up the display handlers and things. */ init_display(); init_angband(); textui_init(); /* Wait for response */ pause_line(Term); /* Play the game */ play_game(new_game); /* Free resources */ textui_cleanup(); cleanup_angband(); /* Quit */ quit(NULL); /* Exit */ return (0); }
/* * Simple "main" function for multiple platforms. * * Note the special "--" option which terminates the processing of * standard options. All non-standard options (if any) are passed * directly to the "init_xxx()" function. */ int main(int argc, char *argv[]) { int i; bool done = FALSE; bool new_game = FALSE; int show_score = 0; const char * mstr = NULL; bool args = TRUE; /* Save the "program name" XXX XXX XXX */ argv0 = argv[0]; #ifdef SET_UID /* Default permissions on files */ (void)umask(022); #endif /* Get the file paths */ init_stuff(); #ifdef SET_UID /* Get the user id */ player_uid = getuid(); /* Save the effective GID for later recall */ player_egid = getegid(); # if 0 /* XXX XXX XXX */ /* Redundant setting necessary in case root is running the game */ /* If not root or game not setuid the following two calls do nothing */ if (setgid(getegid()) != 0) { quit("setgid(): cannot set permissions correctly!"); } if (setuid(geteuid()) != 0) { quit("setuid(): cannot set permissions correctly!"); } # endif #endif /* SET_UID */ #ifdef SET_UID #ifdef PRIVATE_USER_PATH /* Create directories for the users files */ create_user_dirs(); #endif /* PRIVATE_USER_PATH */ /* Acquire the "user name" as a default player name */ user_name(op_ptr->full_name, player_uid); #endif /* SET_UID */ /* Process the command line arguments */ for (i = 1; args && (i < argc); i++) { /* Require proper options */ if (argv[i][0] != '-') goto usage; /* Analyze option */ switch (argv[i][1]) { case 'N': case 'n': { new_game = TRUE; break; } case 'F': case 'f': { arg_fiddle = TRUE; break; } case 'W': case 'w': { arg_wizard = TRUE; break; } case 'V': case 'v': { arg_sound = TRUE; break; } case 'R': case 'r': { arg_force_roguelike = TRUE; break; } case 'O': case 'o': { arg_force_original = TRUE; break; } case 'S': case 's': { show_score = atoi(&argv[i][2]); if (show_score <= 0) show_score = 10; break; } case 'u': case 'U': { if (!argv[i][2]) goto usage; strncpy(op_ptr->base_name, &argv[i][2], 32); op_ptr->base_name[31] = '\0'; break; } case 'm': { if (!argv[i][2]) goto usage; mstr = &argv[i][2]; break; } case 'M': { arg_monochrome = TRUE; break; } case 'd': case 'D': { change_path(&argv[i][2]); break; } case '-': { argv[i] = argv[0]; argc = argc - i; argv = argv + i; args = FALSE; break; } default: usage: { /* Dump usage information */ puts("Usage: angband [options] [-- subopts]"); puts(" -n Start a new character"); puts(" -f Request fiddle mode"); puts(" -w Request wizard mode"); puts(" -v Request sound mode"); puts(" -g Request graphics mode"); puts(" -o Request original keyset"); puts(" -r Request rogue-like keyset"); puts(" -M Request monochrome mode"); puts(" -s<num> Show <num> high scores"); puts(" -u<who> Use your <who> savefile"); puts(" -d<path> Store pref files and screendumps in <path>"); #ifdef USE_X11 puts(" -mx11 To use X11"); puts(" -- Sub options"); puts(" -- -d Set display name"); puts(" -- -s Turn off smoothscaling graphics"); puts(" -- -n# Number of terms to use"); #endif /* USE_X11 */ #ifdef USE_GCU puts(" -mgcu To use GCU (GNU Curses)"); puts(" -- Sub options"); puts(" -- -x No extra sub-windows"); #endif /* USE_GCU */ #ifdef USE_SLA puts(" -msla To use SLA (SLANG)"); #endif /* USE_SLA */ /* Actually abort the process */ quit(NULL); } } } /* Process the player name (but only if one is specified) */ if (strlen(op_ptr->base_name)) process_player_name(FALSE); /* Hack -- Forget standard args */ if (args) { argc = 1; argv[1] = NULL; } /* Install "quit" hook */ quit_aux = quit_hook; /* Drop privs (so X11 will work correctly) */ safe_setuid_drop(); #ifdef USE_X11 /* Attempt to use the "main-x11.c" support */ if (!done && (!mstr || (streq(mstr, "x11")))) { extern errr init_x11(int, char**); if (0 == init_x11(argc, argv)) { ANGBAND_SYS = "x11"; done = TRUE; } } #endif #ifdef USE_GCU /* Attempt to use the "main-gcu.c" support */ if (!done && (!mstr || (streq(mstr, "gcu")))) { extern errr init_gcu(int, char**); if (0 == init_gcu(argc, argv)) { ANGBAND_SYS = "gcu"; done = TRUE; } } #endif #ifdef USE_SLA /* Attempt to use the "main-sla.c" support */ if (!done && (!mstr || (streq(mstr, "sla")))) { extern errr init_sla(void); if (0 == init_sla()) { ANGBAND_SYS = "sla"; done = TRUE; } } #endif /* Grab privs (dropped above for X11) */ safe_setuid_grab(); /* Make sure we have a display! */ if (!done) quit("Unable to prepare any 'display module'!"); /* Catch nasty signals */ signals_init(); /* Initialize */ init_angband(); /* Hack -- If requested, display scores and quit */ if (show_score > 0) { show_scores(); quit(NULL); } /* Wait for response */ pause_line(23); /* Play the game */ play_game(new_game); /* Quit */ quit(NULL); /* Exit */ return (0); }
/* * Change the player into a King! -RAK- */ void kingly(void) { int wid, hgt; int cx, cy; bool seppuku = streq(p_ptr->died_from, "Seppuku"); /* Hack -- retire in town */ dun_level = 0; /* Fake death */ if (!seppuku) #ifdef JP /* 引退したときの識別文字 */ (void)strcpy(p_ptr->died_from, "ripe"); #else (void)strcpy(p_ptr->died_from, "Ripe Old Age"); #endif /* Restore the experience */ p_ptr->exp = p_ptr->max_exp; /* Restore the level */ p_ptr->lev = p_ptr->max_plv; Term_get_size(&wid, &hgt); cy = hgt / 2; cx = wid / 2; /* Hack -- Instant Gold */ p_ptr->au += 10000000L; /* Clear screen */ Term_clear(); /* Display a crown */ put_str("#", cy - 11, cx - 1); put_str("#####", cy - 10, cx - 3); put_str("#", cy - 9, cx - 1); put_str(",,, $$$ ,,,", cy - 8, cx - 7); put_str(",,=$ \"$$$$$\" $=,,", cy - 7, cx - 11); put_str(",$$ $$$ $$,", cy - 6, cx - 13); put_str("*> <*> <*", cy - 5, cx - 13); put_str("$$ $$$ $$", cy - 4, cx - 13); put_str("\"$$ $$$ $$\"", cy - 3, cx - 13); put_str("\"$$ $$$ $$\"", cy - 2, cx - 12); put_str("*#########*#########*", cy - 1, cx - 11); put_str("*#########*#########*", cy, cx - 11); /* Display a message */ #ifdef JP put_str("Veni, Vidi, Vici!", cy + 3, cx - 9); put_str("来た、見た、勝った!", cy + 4, cx - 10); put_str(format("偉大なる%s万歳!", sp_ptr->winner), cy + 5, cx - 11); #else put_str("Veni, Vidi, Vici!", cy + 3, cx - 9); put_str("I came, I saw, I conquered!", cy + 4, cx - 14); put_str(format("All Hail the Mighty %s!", sp_ptr->winner), cy + 5, cx - 13); #endif /* If player did Seppuku, that is already written in playrecord */ if (!seppuku) { #ifdef JP do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "ダンジョンの探索から引退した。"); do_cmd_write_nikki(NIKKI_GAMESTART, 1, "-------- ゲームオーバー --------"); #else do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "retired exploring dungeons."); do_cmd_write_nikki(NIKKI_GAMESTART, 1, "-------- Game Over --------"); #endif do_cmd_write_nikki(NIKKI_BUNSHOU, 1, "\n\n\n\n"); } /* Flush input */ flush(); /* Wait for response */ pause_line(hgt - 1); }