Permadeath

version 1 by Victor Gijsbers

  • Home page
  • Beginning
  • Previous
  • Next



  • Section - Saving

    [We need to set these number to something once the game is first saved. (We could also do this when play begins, but that might fill the Table of too quickly.) By the way, File of Adventurers is defined by the game itself.]

    First check saving the game (this is the set up save IDs rule):
        if Have-ID is false:
            now First ID is a random number between 1 and 20000;
            now Second ID is a random number between 1 and 20000;
            now Third ID is a random number between 1 and 20000;
            now Unique-save-ID is a random number between 1 and 20000;
            now Have-ID is true;
            if File of Adventurers exists:
                read File Of Adventurers into Table of Adventurers;
            choose a blank row in Table of Adventurers;
            now ID-1 entry is First ID;
            now ID-2 entry is Second ID;
            now ID-3 entry is Third ID;
            now Save-ID entry is Unique-save-ID;
            write File Of Adventurers from the Table of Adventurers.

    [If the file doesn't exits, something has gone wrong and we stop saving.]
            
    Check saving the game (this is the something gone wrong with saving rule):
        consider the safe saving allowed rules;
        if rule failed:
            unless File of Adventurers exists:
                say "Unfortunately, something seems to have gone wrong with the saving mechanism." instead.
            
    [Finally, we set a new unique number for Save-ID and write away the new table. On restoring, we will check whether the Save-ID from the table is equal to the Unique-Save-ID from the game's internal memory.]
            
    Last check saving the game (this is the permadeath saving rule):
        consider the safe saving allowed rules;
        if rule failed:
            now Unique-save-ID is a random number between 1 and 20000;
            read File Of Adventurers into Table of Adventurers;
            repeat through the Table of Adventurers:
                if the ID-1 entry is First ID and the ID-2 entry is Second ID and the ID-3 entry is Third ID:
                    now Saving-state entry is 1;
                    now Save-ID entry is Unique-save-ID;
                    write File Of Adventurers from the Table of Adventurers.

    [That was _before_ saving; now we handle what happens after saving. Save-failed is defined below; it is true if saving failed, so this rule will only run if saving succeeded. It will also only run if safe saving was not allowed.]


    Report saving the game (this is the permadeath report saving rule):
        if save-failed is false:
            consider the safe saving allowed rules;
            if rule failed:
                if File of Adventurers exists:
                    read File Of Adventurers into Table of Adventurers;
                    repeat through the Table of Adventurers:
                        if the ID-1 entry is First ID and the ID-2 entry is Second ID and the ID-3 entry is Third ID:
                            if the Saving-state entry is 1: [this means we are saving]
                                now the Saving-state entry is 0;
                                write File Of Adventurers from the Table of Adventurers;
                                try fast quitting; [Putting 'immediately end the game' here will stop the previous lines from being carried out.]
                            otherwise: [this means we are restoring]
                                if the Save-ID entry is 0:
                                    consider the killed-before rules;
                                otherwise if Unique-save-ID is not Save-ID entry:
                                    consider the wrong Save-ID rules;
                otherwise:
                    consider the missing-adventurer rules.
            

    [All this stuff is relegated to rules and rulebooks so you can easily customise it.]

    The killed-before rules are a rulebook.

    A killed-before rule (this is the standard killed before rule):
        end the game saying "This character is already dead.".

    The missing-adventurer rules are a rulebook.

    A missing-adventurer rule (this is the standard missing adventurer rule):
        end the game saying "A vital file appears to be missing!".

    The wrong Save-ID rules are a rulebook.

    A wrong Save-ID rule (this is the standard wrong Save-ID rule):
        end the game saying "This save game is too far in the past.";


    [Did saving fail or succeed?]

        


    Table of custom library messages (continued)
    library-action  library-message-id  library-message-text  
    saving the game action  1  "Saving failed.[save failed]"  
    saving the game action  2  "[save success message][save succeeded]"  

    Save-failed is a truth state that varies. Save-failed is false.

    To say save failed:
        now save-failed is true.

    To say save succeeded:
        now save-failed is false.

    To say save success message:
        consider the safe saving allowed rules;
        if rule failed:
            say "Saved. Thanks for playing!";
        otherwise:
            say "Saved.[run paragraph on]".