Changeset 500

Show
Ignore:
Timestamp:
08/11/07 17:33:30 (1 year ago)
Author:
takkaria
Message:

Commit the new savefile code. (#30)

Currently incorporated only on the ports using main.c, and even then only when the -L argument is used. I believe
this to be mostly OK now, but it still needs some testing and reorganisation.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/Makefile.inc

    r421 r500  
    1616 
    1717z-form.o: z-form.h z-util.h z-virt.h 
    18 z-rand.o: z-rand.h 
    1918z-term.o: z-term.h z-virt.h 
    20 z-util.o: z-util.h 
    2119z-virt.o: z-virt.h z-util.h 
    22 z-file.o: z-file.h 
     20z-smap.o: z-smap.h 
    2321 
    2422# Various files depend on various headers 
  • trunk/src/Makefile.src

    r480 r500  
    1515 
    1616ZFILES = z-file.o z-form.o z-msg.o z-quark.o z-rand.o z-term.o z-type.o \ 
    17          z-util.o z-virt.o 
     17         z-util.o z-virt.o z-blockfile.o z-smap.o  
    1818MAINFILES = main.o maid-x11.o main-crb.o main-gcu.o main-gtk.o \ 
    1919            main-ros.o main-sdl.o main-win.o main-x11.o main-xaw.o snd-sdl.o 
     
    3737        init2.o \ 
    3838        load.o \ 
     39        loadsave.o \ 
    3940        melee1.o \ 
    4041        melee2.o \ 
  • trunk/src/birth.c

    r404 r500  
    18921892 
    18931893        /* 
    1894          * If this a pre-existing savefile, offer to do a quick creation, based 
    1895          * on the previous character. 
     1894         * If the birth height value is set, we can do a quick-start character. 
    18961895         */ 
    1897         if (character_existed && p_ptr->ht_birth) 
     1896        if (p_ptr->ht_birth) 
    18981897        { 
    18991898                /* Prompt */ 
  • trunk/src/dungeon.c

    r469 r500  
    17851785 * 
    17861786 * If the savefile does not exist, cannot be loaded, or contains a dead 
    1787  * (non-wizard-mode) character, then a new game will be started. 
     1787 * character, then a new game will be started. 
    17881788 * 
    17891789 * Several platforms (Windows, Macintosh, Amiga) start brand new games 
     
    17991799void play_game(bool new_game) 
    18001800{ 
    1801         bool character_loaded; 
    1802         bool reusing_savefile; 
     1801        /*** Do horrible, hacky things, to start the game off ***/ 
    18031802 
    18041803        /* Hack -- Increase "icky" depth */ 
    18051804        character_icky++; 
    18061805 
    1807  
    18081806        /* Verify main term */ 
    18091807        if (!term_screen) 
    1810         { 
    18111808                quit("main window does not exist"); 
    1812         } 
    18131809 
    18141810        /* Make sure main term is active */ 
     
    18171813        /* Verify minimum size */ 
    18181814        if ((Term->hgt < 24) || (Term->wid < 80)) 
    1819         { 
    18201815                quit("main window is too small"); 
    1821         } 
    18221816 
    18231817        /* Hack -- Turn off the cursor */ 
    18241818        (void)Term_set_cursor(FALSE); 
    18251819 
    1826         /* Attempt to load */ 
    1827         if (!load_player(&character_loaded, &reusing_savefile)) 
    1828         { 
    1829                 /* Oops */ 
    1830                 quit("broken savefile"); 
    1831         } 
    1832  
    1833         /* Nothing loaded */ 
    1834         if (!character_loaded) 
     1820 
     1821        /*** Try to load the savefile ***/ 
     1822 
     1823        p_ptr->is_dead = TRUE; 
     1824 
     1825        if (savefile[0] && file_exists(savefile)) 
     1826        { 
     1827                bool ok = new_save ? load(savefile) : old_load(); 
     1828                if (!ok) quit("broken savefile"); 
     1829 
     1830                if (p_ptr->is_dead && arg_wizard) 
     1831                { 
     1832                        p_ptr->is_dead = FALSE; 
     1833                        p_ptr->noscore |= NOSCORE_WIZARD; 
     1834                } 
     1835        } 
     1836 
     1837        /* No living character loaded */ 
     1838        if (p_ptr->is_dead) 
    18351839        { 
    18361840                /* Make new player */ 
     
    18461850        /* Hack -- Default base_name */ 
    18471851        if (!op_ptr->base_name[0]) 
    1848         { 
    18491852                my_strcpy(op_ptr->base_name, "PLAYER", sizeof(op_ptr->base_name)); 
    1850         } 
     1853 
    18511854 
    18521855        /* Init RNG */ 
     
    18981901 
    18991902                /* Hack -- enter the world */ 
    1900                 turn = 1; 
    1901         } 
     1903                old_turn = turn = 1; 
     1904        } 
     1905 
    19021906 
    19031907        /* Normal machine (process player name) */ 
    19041908        if (savefile[0]) 
    1905         { 
    19061909                process_player_name(FALSE); 
    1907         } 
    19081910 
    19091911        /* Weird machine (process player name, pick savefile name) */ 
    19101912        else 
    1911         { 
    19121913                process_player_name(TRUE); 
    1913         } 
     1914 
    19141915         
    19151916        /* Check if we're overwriting a savefile */ 
    1916         while (!reusing_savefile && file_exists(savefile)) 
    1917         { 
    1918                 /* Ask for confirmation */ 
     1917        while (new_game && file_exists(savefile)) 
     1918        { 
    19191919                bool overwrite = get_check("Continuing will overwrite an existing savefile.  Overwrite? "); 
    19201920          
    1921                 if (overwrite) 
    1922                 { 
    1923                         break; 
    1924                 }                         
    1925                 else 
    1926                 { 
    1927                         get_name(TRUE); 
    1928                 }                         
    1929         } 
     1921                if (overwrite) break; 
     1922                get_name(TRUE); 
     1923        } 
     1924 
     1925        /* Stop the player being quite so dead */ 
     1926        p_ptr->is_dead = FALSE; 
     1927 
     1928 
    19301929 
    19311930        /* Flash a message */ 
    19321931        prt("Please wait...", 0, 0); 
     1932 
    19331933 
    19341934        /* Flush the message */ 
  • trunk/src/externs.h

    r488 r500  
    134134extern bool closing_flag; 
    135135extern char savefile[1024]; 
     136extern char panic_savefile[1024]; 
    136137extern s16b macro__num; 
    137138extern char **macro__pat; 
     
    337338 
    338339/* load.c */ 
    339 extern bool load_player(bool *character_loaded, bool *reusing_savefile); 
     340extern bool old_load(void); 
     341 
     342/* loadsave.c */ 
     343bool save(char *filename); 
     344bool load(char *filename); 
    340345 
    341346/* melee1.c */ 
     
    489494 
    490495/* save.c */ 
    491 extern bool save_player(void); 
     496extern bool old_save(void); 
    492497 
    493498/* spells1.c */ 
     
    742747bool make_fake_artifact(object_type *o_ptr, byte name1); 
    743748 
     749/* Testing Hacks XXX */ 
     750extern bool new_save; 
     751 
    744752#endif /* !INCLUDED_EXTERNS_H */ 
  • trunk/src/files.c

    r480 r500  
    25832583 
    25842584        /* Save the player */ 
    2585         if (save_player()) 
     2585        if (new_save ? save(savefile) : old_save()) 
    25862586        { 
    25872587                prt("Saving game... done.", 0, 0); 
     
    30273027 
    30283028        /* Save dead player */ 
    3029         if (!save_player()) 
     3029        if (new_save ? !save(savefile) : !old_save()) 
    30303030        { 
    30313031                msg_print("death save failed!"); 
     
    32853285 
    32863286        /* Panic save, or get worried */ 
    3287         if (!save_player()) quit("panic save failed!"); 
     3287        if (new_save ? !save(panic_savefile) : !old_save()) quit("panic save failed!"); 
     3288 
    32883289 
    32893290        /* Successful panic save */ 
  • trunk/src/load.c

    r469 r500  
    22442244 * there is no such file, so we must check for "empty" savefile names. 
    22452245 */ 
    2246 bool load_player(bool *character_loaded, bool *reusing_savefile
     2246bool old_load(void
    22472247{ 
    22482248        ang_file *fh; 
     
    22512251        errr err = 0; 
    22522252 
    2253  
    2254         /* Paranoia */ 
    2255         turn = 0; 
    2256         p_ptr->is_dead = FALSE; 
    2257          
    2258         *character_loaded = FALSE; 
    2259         *reusing_savefile = FALSE; 
    2260  
    2261         /* Allow empty savefile name */ 
    2262         if (!savefile[0]) return (TRUE); 
    2263  
    2264         /* No file */ 
    2265         if (!file_exists(savefile)) 
    2266         { 
    2267                 /* Give a message */ 
    2268                 msg_print("Savefile does not exist."); 
    2269                 message_flush(); 
    2270  
    2271                 /* Allow this */ 
    2272                 return (TRUE); 
    2273         } 
    2274  
    2275         /* Open savefile */ 
    2276         safe_setuid_grab(); 
    22772253        fh = file_open(savefile, MODE_READ, -1); 
    2278         safe_setuid_drop(); 
     2254 
    22792255 
    22802256        /* No file */ 
     
    23402316        if (!err) 
    23412317        { 
    2342                 *reusing_savefile = TRUE; 
    2343  
    2344                 /* Give a conversion warning */ 
    2345                 if ((version_major != sf_major) || 
    2346                     (version_minor != sf_minor) || 
    2347                     (version_patch != sf_patch)) 
    2348                 { 
    2349                         /* Message */ 
    2350                         msg_format("Converted a %d.%d.%d savefile.", 
    2351                                    sf_major, sf_minor, sf_patch); 
    2352                         message_flush(); 
    2353                 } 
    2354  
    2355                 /* Player is dead */ 
    2356                 if (p_ptr->is_dead) 
    2357                 { 
    2358                         /* Cheat death (unless the character retired) */ 
    2359                         if (arg_wizard) 
    2360                         { 
    2361                                 /* A character was loaded */ 
    2362                                 *character_loaded = TRUE; 
    2363  
    2364                                 /* Mark the savefile */ 
    2365                                 p_ptr->noscore |= NOSCORE_WIZARD; 
    2366  
    2367                                 /* Done */ 
    2368                                 return (TRUE); 
    2369                         } 
    2370  
    2371                         /* Forget death */ 
    2372                         p_ptr->is_dead = FALSE; 
    2373  
    2374                         /* A character existed in this savefile. */ 
    2375                         character_existed = TRUE; 
    2376  
    2377                         /* Count lives */ 
    2378                         sf_lives++; 
    2379  
    2380                         /* Forget turns */ 
    2381                         turn = old_turn = 0; 
    2382                          
    2383                         /* Done */ 
    2384                         return (TRUE); 
    2385                 } 
    2386  
    2387                 /* A character was loaded */ 
    2388                 *character_loaded = TRUE; 
    2389  
    23902318                /* Still alive */ 
    23912319                if (p_ptr->chp >= 0) 
  • trunk/src/main.c

    r467 r500  
    5454#ifdef USE_SOUND 
    5555 
     56bool new_save; 
     57 
    5658/* 
    5759 * List of sound modules in the order they should be tried. 
     
    362364                        } 
    363365 
     366                        case 'L': 
     367                        { 
     368                                new_save = TRUE; 
     369                                break; 
     370                        } 
     371 
    364372                        case 'F': 
    365373                        case 'f': 
     
    439447                                puts("Usage: angband [options] [-- subopts]"); 
    440448                                puts("  -n             Start a new character"); 
     449                                puts("  -L             Load a new-format save file"); 
    441450                                puts("  -w             Resurrect dead character (marks savefile)"); 
    442451                                puts("  -f             Request fiddle (verbose) mode"); 
  • trunk/src/save.c

    r489 r500  
    10401040 * Attempt to save the player in a savefile 
    10411041 */ 
    1042 bool save_player(void) 
     1042bool old_save(void) 
    10431043{ 
    10441044        char new_savefile[1024]; 
  • trunk/src/signals.c

    r199 r500  
    222222 
    223223        /* Attempt to save */ 
    224         if (save_player()) 
     224        if (new_save ? save(panic_savefile) : old_save()) 
    225225        { 
    226226                Term_putstr(45, 23, -1, TERM_RED, "Panic save succeeded!"); 
  • trunk/src/variable.c

    r469 r500  
    6060 
    6161bool character_generated;       /* The character exists */ 
    62 bool character_existed;         /* A character existed on the same savefile */ 
    6362bool character_dungeon;         /* The character has a dungeon */ 
    6463bool character_saved;           /* The character was just saved to a savefile */ 
     
    133132 */ 
    134133char savefile[1024]; 
     134char panic_savefile[1024]; 
    135135 
    136136 
  • trunk/src/wizard2.c

    r449 r500  
    118118        } 
    119119} 
    120  
    121120 
    122121/* 
     
    16491648                } 
    16501649 
     1650                case 'S': 
     1651                { 
     1652                        save("savefile.new"); 
     1653                        break; 
     1654                } 
     1655         
    16511656                /* Teleport */ 
    16521657                case 't':