Mercurial > hg > early-roguelike
comparison urogue/save.c @ 256:c495a4f288c6
Import UltraRogue from the Roguelike Restoration Project (r1490)
| author | John "Elwin" Edwards |
|---|---|
| date | Tue, 31 Jan 2017 19:56:04 -0500 |
| parents | |
| children | 096d3cfd9afd |
comparison
equal
deleted
inserted
replaced
| 253:d9badb9c0179 | 256:c495a4f288c6 |
|---|---|
| 1 /* | |
| 2 save.c - save and restore routines | |
| 3 | |
| 4 UltraRogue: The Ultimate Adventure in the Dungeons of Doom | |
| 5 Copyright (C) 1985, 1986, 1992, 1993, 1995 Herb Chong | |
| 6 All rights reserved. | |
| 7 | |
| 8 Based on "Advanced Rogue" | |
| 9 Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka | |
| 10 All rights reserved. | |
| 11 | |
| 12 Based on "Rogue: Exploring the Dungeons of Doom" | |
| 13 Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman | |
| 14 All rights reserved. | |
| 15 | |
| 16 See the file LICENSE.TXT for full copyright and licensing information. | |
| 17 */ | |
| 18 | |
| 19 #define _ALL_SOURCE /* need to remove need for this AIXism */ | |
| 20 | |
| 21 #include <time.h> | |
| 22 #include <stdlib.h> | |
| 23 #include <string.h> | |
| 24 #include <ctype.h> | |
| 25 #include <errno.h> | |
| 26 #include "rogue.h" | |
| 27 | |
| 28 int | |
| 29 save_game(void) | |
| 30 { | |
| 31 FILE *savefd; | |
| 32 char buf[2 * LINELEN]; | |
| 33 char oldfile[2*LINELEN]; | |
| 34 | |
| 35 /* get file name */ | |
| 36 | |
| 37 strcpy(oldfile,file_name); | |
| 38 | |
| 39 do | |
| 40 { | |
| 41 mpos = 0; | |
| 42 | |
| 43 if (oldfile[0] != '\0') | |
| 44 msg("Save file [%s]: ", file_name); | |
| 45 else | |
| 46 msg("Save file as: "); | |
| 47 | |
| 48 mpos = 0; | |
| 49 buf[0] = '\0'; | |
| 50 | |
| 51 if (get_string(buf, cw) == QUIT) | |
| 52 { | |
| 53 msg(""); | |
| 54 return(FALSE); | |
| 55 } | |
| 56 | |
| 57 if ( (buf[0] == 0) && (oldfile[0] != 0) ) | |
| 58 strcpy(file_name, oldfile); | |
| 59 else if (buf[0] != 0) | |
| 60 strcpy(file_name, buf); | |
| 61 else | |
| 62 { | |
| 63 msg(""); | |
| 64 return(FALSE); | |
| 65 } | |
| 66 | |
| 67 wclear(hw); | |
| 68 wmove(hw, LINES - 1, 0); | |
| 69 wrefresh(hw); | |
| 70 | |
| 71 if ((savefd = fopen(file_name, "w")) == NULL) | |
| 72 msg(strerror(errno)); /* fake perror() */ | |
| 73 } | |
| 74 while (savefd == NULL); | |
| 75 | |
| 76 /* write out [compressed?] file */ | |
| 77 | |
| 78 save_file(savefd); | |
| 79 return(TRUE); | |
| 80 } | |
| 81 | |
| 82 int | |
| 83 restore(char *file) | |
| 84 { | |
| 85 FILE *infd; | |
| 86 char *sp; | |
| 87 | |
| 88 if (strcmp(file, "-r") == 0) | |
| 89 file = file_name; | |
| 90 | |
| 91 if ((infd = fopen(file, "r")) == NULL) | |
| 92 { | |
| 93 perror(file); | |
| 94 return(FALSE); | |
| 95 } | |
| 96 | |
| 97 if ( restore_file(infd) == FALSE ) | |
| 98 return(FALSE); | |
| 99 | |
| 100 /* | |
| 101 * we do not close the file so that we will have a hold of the inode | |
| 102 * for as long as possible | |
| 103 */ | |
| 104 | |
| 105 if (remove(file) < 0) | |
| 106 { | |
| 107 printf("Cannot unlink file\n"); | |
| 108 return(FALSE); | |
| 109 } | |
| 110 | |
| 111 if ((sp = getenv("OPTIONS")) != NULL) | |
| 112 parse_opts(sp); | |
| 113 | |
| 114 strcpy(file_name, file); | |
| 115 | |
| 116 clearok(cw, TRUE); | |
| 117 touchwin(cw); | |
| 118 noecho(); | |
| 119 nonl(); | |
| 120 | |
| 121 while(playing) | |
| 122 { | |
| 123 do_daemons(BEFORE); | |
| 124 do_fuses(BEFORE); | |
| 125 | |
| 126 command(); /* Command execution */ | |
| 127 | |
| 128 if (after) | |
| 129 do_after_effects(); | |
| 130 } | |
| 131 | |
| 132 fatal(""); | |
| 133 | |
| 134 return(FALSE); | |
| 135 } |
