diff options
author | Manoj Srivastava <srivasta@debian.org> | 2020-05-22 19:57:41 -0700 |
---|---|---|
committer | Manoj Srivastava <srivasta@debian.org> | 2020-05-22 20:02:19 -0700 |
commit | c3d2579ad8d7eb33059aa8fdbaf5b564411a57f2 (patch) | |
tree | 1570cda0676fdcf4171a69a7fe313c1b89a52b0c /src/notes.cc | |
parent | 986b7742bf244b4073ecca0723615f70be8a1ab6 (diff) | |
parent | 4e9b9c402ed95bf9a17fd6d795bc49bb4128a6fa (diff) |
Merge branch 'upstream' into debian-cmake-fixes
Diffstat (limited to 'src/notes.cc')
-rw-r--r-- | src/notes.cc | 189 |
1 files changed, 189 insertions, 0 deletions
diff --git a/src/notes.cc b/src/notes.cc new file mode 100644 index 00000000..17990992 --- /dev/null +++ b/src/notes.cc @@ -0,0 +1,189 @@ +/* + * Copyright (c) 1989, 1999 James E. Wilson, Robert A. Koeneke, + * Robert Ruehlmann + * + * This software may be copied and distributed for educational, research, and + * not for profit purposes provided that this copyright and statement are + * included in all such copies. + */ + +#include "notes.hpp" + +#include "files.hpp" +#include "game.hpp" +#include "player_class.hpp" +#include "player_type.hpp" +#include "util.hpp" +#include "util.h" +#include "variable.h" +#include "variable.hpp" + +/* + * Show the notes file on the screen + */ +void show_notes_file() +{ + char basename[13]; + char buf[1024]; + char caption[10 + 13]; + + /* Hack -- extract first 8 characters of name and append an extension */ + strnfmt(basename, sizeof(basename), "%.8s.nte", game->player_base.c_str()); + basename[sizeof(basename) - 1] = '\0'; + + /* Build the path */ + path_build(buf, sizeof(buf), ANGBAND_DIR_NOTE, basename); + + /* Use a caption, forcing direct access to the note file */ + sprintf(caption, "Note file %s", basename); + + /* Invoke show_file */ + show_file(buf, caption); + + /* Done */ + return; +} + +/* + * Output a string to the notes file. + * This is the only function that references that file. + */ +void output_note(const char *final_note) +{ + FILE *fff; + char basename[13]; + char buf[1024]; + + /* Hack -- extract first 8 characters of name and append an extension */ + strnfmt(basename, sizeof(basename), "%.8s.nte", game->player_base.c_str()); + basename[sizeof(basename) - 1] = '\0'; + + /* Build the path */ + path_build(buf, sizeof(buf), ANGBAND_DIR_NOTE, basename); + + /* Open notes file */ + fff = my_fopen(buf, "a"); + + /* Failure */ + if (!fff) return; + + /* Add note, and close note file */ + fprintf(fff, "%s\n", final_note); + + /* Close the handle */ + my_fclose(fff); + + /* Done */ + return; +} + + +/* + * Add note to file using a string + character symbol + * to specify its type so that the notes file can be + * searched easily by external utilities. + */ +void add_note(char *note, char code) +{ + char buf[100]; + char final_note[100]; + char turn_s[50]; + char depths[32]; + + /* Get the first 60 chars - so do not have an overflow */ + memset(buf, 0, sizeof(buf)); + strncpy(buf, note, 60); + + /* Get date and time */ + sprintf(turn_s, "Turn % 12ld", static_cast<long int>(turn)); + + /* Get depth */ + if (!dun_level) strcpy(depths, " Town"); + else sprintf(depths, "Lev%3d", dun_level); + + /* Make note */ + sprintf(final_note, "%-20s %s %c: %s", turn_s, depths, code, buf); + + /* Output to the notes file */ + output_note(final_note); +} + + +/* + * Append a note to the notes file using a "type". + */ +void add_note_type(int note_number) +{ + auto const &class_info = game->edit_data.class_info; + + char true_long_day[50]; + char buf[1024]; + time_t ct = time((time_t*)0); + + /* Get the date */ + strftime(true_long_day, 30, "%Y-%m-%d at %H:%M:%S", localtime(&ct)); + + /* Work out what to do */ + switch (note_number) + { + case NOTE_BIRTH: + { + /* Player has just been born */ + char player[100]; + + /* Build the string containing the player information */ + auto const player_race_name = get_player_race_name(p_ptr->prace, p_ptr->pracem); + sprintf(player, + "the %s %s", + player_race_name.c_str(), + class_info[p_ptr->pclass].spec[p_ptr->pspec].title); + + /* Add in "character start" information */ + sprintf(buf, + "\n" + "================================================\n" + "%s %s\n" + "Born on %s\n" + "================================================\n", + game->player_name.c_str(), player, true_long_day); + + break; + } + + case NOTE_WINNER: + { + sprintf(buf, + "%s slew Morgoth on %s\n" + "Long live %s!\n" + "================================================", + game->player_name.c_str(), true_long_day, game->player_name.c_str()); + + break; + } + + case NOTE_SAVE_GAME: + { + /* Saving the game */ + sprintf(buf, "\nSession end: %s", true_long_day); + + break; + } + + case NOTE_ENTER_DUNGEON: + { + /* Entering the game after a break. */ + sprintf(buf, + "================================================\n" + "New session start: %s\n", + true_long_day); + + break; + } + + default: + return; + } + + /* Output the notes to the file */ + output_note(buf); +} |