Skip to content

Commit

Permalink
Apply xlog patch
Browse files Browse the repository at this point in the history
  • Loading branch information
moon-chilled committed Mar 10, 2017
1 parent 6a26a7d commit a3e2137
Show file tree
Hide file tree
Showing 26 changed files with 753 additions and 1,350 deletions.
186 changes: 186 additions & 0 deletions doc/xlog.readme
@@ -0,0 +1,186 @@
Extended logfile patch for Nethack 3.4.3
Version 3

This patch creates a new, more verbose logfile of all of the games
completed, in order to make interpreting the logfile easier, as well as
providing a simple way to add new fields to the log. A new file (named, by
default, 'xlogfile') is created, with each line representing a completed
game. The format looks something like:

version=3.4.3:points=24978:deathdnum=4:deathlev=8:maxlvl=12:hp=-4:maxhp=95:death
s=1:deathdate=20051215:birthdate=20051215:uid=1000:role=Bar:race=Hum:gender=Mal:
align=Neu:name=aardvark:death=killed by a gargoyle, while helpless:conduct=0xf80
:turns=5925:achieve=0x200:realtime=1414:starttime=1134705144:endtime=1134706562

The standard record and logfile both work the same as usual.

All of the information from the standard logfile is stored in the extended
logfile. In addition, code to record some extra game data is included.

version - the version of nethack (eg '3.4.3')
points - the final score
deathdnum - death dungeon number
deathlev - death level
maxlvl - max dungeon level
hp - final hit points
maxhp - max hit points
deaths - number of deaths
deathdate - the date that the game ended (eg '20041130' is Nov 30, 2004)
birthdate - the date that the game started
uid - the player's UID
role - the player's role (3-letter abbreviation, eg 'Sam')
race - the player's race (3-letter abbreviation, eg 'Hum')
gender - the player's gender (3-letter abbreviation, eg 'Mal')
align - the player's alignment (3-letter abbreviation, eg 'Law')
name - the player's name
death - the death string (eg 'killed by a woodchuck')

* turns - The number of turns elapsed during the game

* conduct - The conducts followed during the game
The conducts are encoded as a bitfield, with each bit representing one
conduct. If a bit is set, then the corresponding conduct was followed
during the game. (Note: this is backwards from my original conduct
patch, but it seems more natural this way.)

Bit 1 (0x0001) - Went without food
Bit 2 (0x0002) - Strict vegan diet
Bit 3 (0x0004) - Vegetarian diet
Bit 4 (0x0008) - Atheist
Bit 5 (0x0010) - Never hit with a wielded weapon
Bit 6 (0x0020) - Pacifist
Bit 7 (0x0040) - Illiterate
Bit 8 (0x0080) - Never polymorphed an object
Bit 9 (0x0100) - Never changed form
Bit 10 (0x0200) - Used no wishes
Bit 11 (0x0400) - Did not wish for any artifacts
Bit 12 (0x0800) - Never genocided any monsters

* realtime - The amount of time spent playing the game
Records the time (in seconds) actually spent playing the game. (Or, more
accurately, all of the time that nethack is loaded and running the game.)
Specifically, the timer is started right before giving the welcome
message, and stopped when you save or when the game is over.

Note that this will invalidate save files, because the current value of
the timer is recorded in the save file. Bones files should not be
invalidated.

* achieve - Whether or not the player reached certain milestones
This is another bitfield that records whether or not certain things were
achieved.

Achievement bitfield:
bit meaning
1 obtained the Bell of Opening
2 entered gehennom (by any means)
3 obtained the Candelabrum of Invocation
4 obtained the Book of the Dead
5 performed the invocation ritual
6 obtained the amulet
7 entered elemental planes
8 entered astral plane
9 ascended (not "escaped in celestial disgrace!")
10 obtained the luckstone from the Mines
11 obtained the sokoban prize
12 defeated Medusa (killed her by any means)

This will also invalidate save files, as a structure (u_achieve)
containing flags corresponding to a few of these achievements is added
to the savefile. Bones files should not be invalidated.

* starttime - The time the game was started, as obtained from time(2).
(That is, stored as a 32-bit integer number of seconds
since 00:00:00 UTC, January 1, 1970.) This is the same
time as "birthdate" above, but with greater precision.

* endtime - The time the game ended; it is the same time as "deathdate"
above.

* gender0 - The player's original gender (3 letter abbreviation, eg 'Mal')

* align0 - The player's original alignment (3 letter abbreviation, eg 'Law')

The file sys/unix/Makefile.top is modified to add xlogfile to the install
target. If you are using a different system, you may need to either initially
create xlogfile, or modify your makefiles appropriately.

Also included in this patch is an option to display the actual elapsed time
(the time that RECORD_REALTIME logs) on the status line. It is disabled
by default, so to enable it you can uncomment the definition of
REALTIME_ON_BOTL in config.h (and then set the flag showrealtime in either
nethackrc or via the options menu.)

The REALTIME_ON_BOTL option does not depend on XLOGFILE being defined; I
just added it to the same patch because they share most of the same code.
It does break savefile compatibility for the same reasons that
RECORD_REALTIME does.

Breakdown of files changed:
include/config.h
Added a definition for XLOGFILE, the extended logfile filename
Added definition of REALTIME_ON_BOTL
Added definitions for RECORD_CONDUCT, RECORD_TURNS, RECORD_ACHIEVE,
RECORD_REALTIME, RECORD_START_END_TIME, RECORD_GENDER0, RECORD_ALIGN0
in order to give fine-grained control of what should be logged.
include/decl.h
add d_mineend_level and d_sokoend_level to dungeon_topology structure
declaration of u_achieve structure and extern definition of achieve
declaration of realtime_data structure and extern definition
include/dungeon.h
add definitions of Is_mineend_level() and Is_sokoend_level()
include/extern.h
declaration of get_realtime function
include/flag.h
added showrealtime to iflags structure
include/obj.h
add definition of "record_achieve_special" as "corpsenm"
src/allmain.c
update the status line whenever the number of elapsed minutes changes
start the realtime timer and store the time that the game started
add get_realtime() function to calculate elapsed time
src/botl.c
display elapsed time
src/decl.c
declaration of globals achieve, realtime_data
src/do.c
set enter_gehennom=1 when the player enters gehennom
src/dungeon.c
add the mine end and sokoban end levels to the level_map list
src/end.c
update the realtime counter when the game ends
src/invent.c
set get_amulet=1, get_candelabrum=1, get_bell=1, and get_book=1 when the
corresponding item enters your inventory
set get_luckstone and finish_sokoban when the mines luckstone or sokoban
prize enters your inventory
src/mklev.c
set perform_invocation=1 when you successfully perform the invocation
ritual
src/mon.c
set killed_medusa=1 when Medusa is killed
src/options.c
add "showrealtime" option
src/pray.c
set ascended=1 when ascending
src/restore.c
read the stored value of the realtime timer from the savefile, and set the
restore time properly
src/save.c
write the elapsed time to the savefile
src/sp_lev.c
set otmp->record_achieve_special = 1 when generating mines luckstone and
sokoban prize
src/topten.c
add definition of deathtime
add munge_xlstring to convert any ':' in a string to '_'
add write_xlentry which writes a single xlogfile entry
add encodeconduct which converts the current player's conduct to a number
add encodeachieve which converts the game achievements to a number
store the time to deathtime when deathdate is calculated
open and write to the xlogfile just after writing to the logfile
sys/unix/Makefile.top
create and set permissions on xlogfile when doing a 'make install'
util/makedefs.c
add entries for XLOGFILE, RECORD_*, and REALTIME_ON_BOTL to
build_opts[] list
21 changes: 21 additions & 0 deletions include/config.h
Expand Up @@ -151,6 +151,7 @@
#endif

#define LOGFILE "logfile" /* larger file for debugging purposes */
#define XLOGFILE "xlogfile" /* even larger logfile */
#define NEWS "news" /* the file containing the latest hack news */
#define PANICLOG "paniclog" /* log of panic and impossible events */

Expand Down Expand Up @@ -347,6 +348,26 @@ typedef unsigned char uchar;
#endif /*STEED*/
/* #define SCORE_ON_BOTL */ /* added by Gary Erickson (erickson@ucivax) */

/* #define REALTIME_ON_BOTL */ /* Show elapsed time on bottom line. Note:
* this breaks savefile compatibility. */

/* The options in this section require the extended logfile support */
#ifdef XLOGFILE
#define RECORD_CONDUCT /* Record conducts kept in logfile */
#define RECORD_TURNS /* Record turns elapsed in logfile */
#define RECORD_ACHIEVE /* Record certain notable achievements in the
* logfile. Note: this breaks savefile compatibility
* due to the addition of the u_achieve struct. */
#define RECORD_REALTIME /* Record the amount of actual playing time (in
* seconds) in the record file. Note: this breaks
* savefile compatibility. */
#define RECORD_START_END_TIME /* Record to-the-second starting and ending
* times; stored as 32-bit values obtained
* from time(2) (seconds since the Epoch.) */
#define RECORD_GENDER0 /* Record initial gender in logfile */
#define RECORD_ALIGN0 /* Record initial alignment in logfile */
#endif

/*
* Section 5: EXPERIMENTAL STUFF
*
Expand Down
42 changes: 42 additions & 0 deletions include/decl.h
Expand Up @@ -76,6 +76,10 @@ E struct dgn_topology { /* special dungeon levels for speed */
xchar d_mines_dnum, d_quest_dnum;
d_level d_qstart_level, d_qlocate_level, d_nemesis_level;
d_level d_knox_level;
#ifdef RECORD_ACHIEVE
d_level d_mineend_level;
d_level d_sokoend_level;
#endif
} dungeon_topology;
/* macros for accesing the dungeon levels by their old names */
#define oracle_level (dungeon_topology.d_oracle_level)
Expand Down Expand Up @@ -109,6 +113,10 @@ E struct dgn_topology { /* special dungeon levels for speed */
#define qlocate_level (dungeon_topology.d_qlocate_level)
#define nemesis_level (dungeon_topology.d_nemesis_level)
#define knox_level (dungeon_topology.d_knox_level)
#ifdef RECORD_ACHIEVE
#define mineend_level (dungeon_topology.d_mineend_level)
#define sokoend_level (dungeon_topology.d_sokoend_level)
#endif

E NEARDATA stairway dnstair, upstair; /* stairs up and down */
#define xdnstair (dnstair.sx)
Expand Down Expand Up @@ -402,6 +410,40 @@ struct autopickup_exception {

E const char all_count[];

#ifdef RECORD_ACHIEVE
struct u_achieve {
Bitfield(get_bell,1); /* You have obtained the bell of
* opening */
Bitfield(get_candelabrum,1); /* You have obtained the candelabrum */
Bitfield(get_book,1); /* You have obtained the book of
* the dead */
Bitfield(enter_gehennom,1); /* Entered Gehennom (including the
* Valley) by any means */
Bitfield(perform_invocation,1); /* You have performed the invocation
* ritual */
Bitfield(get_amulet,1); /* You have obtained the amulet
* of Yendor */
Bitfield(ascended,1); /* You ascended to demigod[dess]hood.
* Not quite the same as
* u.uevent.ascended. */
Bitfield(get_luckstone,1); /* You obtained the luckstone at the
* end of the mines. */
Bitfield(finish_sokoban,1); /* You obtained the sokoban prize. */
Bitfield(killed_medusa,1); /* You defeated Medusa. */
};

E struct u_achieve achieve;
#endif

#if defined(RECORD_REALTIME) || defined(REALTIME_ON_BOTL)
E struct realtime_data {
time_t realtime; /* Amount of actual playing time up until the last time
* the game was restored. */
time_t restoretime; /* The time that the game was started or restored. */
time_t last_displayed_time; /* Last time displayed on the status line */
} realtime_data;
#endif /* RECORD_REALTIME || REALTIME_ON_BOTL */

#undef E

#endif /* DECL_H */
4 changes: 4 additions & 0 deletions include/dungeon.h
Expand Up @@ -123,6 +123,10 @@ typedef struct branch {
#define Is_qlocate(x) (on_level(x, &qlocate_level))
#define Is_nemesis(x) (on_level(x, &nemesis_level))
#define Is_knox(x) (on_level(x, &knox_level))
#ifdef RECORD_ACHIEVE
#define Is_mineend_level(x) (on_level(x, &mineend_level))
#define Is_sokoend_level(x) (on_level(x, &sokoend_level))
#endif

#define In_sokoban(x) ((x)->dnum == sokoban_dnum)
#define Inhell In_hell(&u.uz) /* now gehennom */
Expand Down
3 changes: 3 additions & 0 deletions include/extern.h
Expand Up @@ -26,6 +26,9 @@ E void NDECL(display_gamewindows);
E void NDECL(newgame);
E void FDECL(welcome, (BOOLEAN_P));
E int NDECL(speed_bonus);
#if defined(RECORD_REALTIME) || defined(REALTIME_ON_BOTL)
E time_t NDECL(get_realtime);
#endif

/* ### apply.c ### */

Expand Down
3 changes: 3 additions & 0 deletions include/flag.h
Expand Up @@ -290,6 +290,9 @@ struct instance_flags {
#define MAX_ALTKEYHANDLER 25
char altkeyhandler[MAX_ALTKEYHANDLER];
#endif
#ifdef REALTIME_ON_BOTL
boolean showrealtime; /* show actual elapsed time */
#endif
};

/*
Expand Down
5 changes: 5 additions & 0 deletions include/obj.h
Expand Up @@ -101,6 +101,11 @@ struct obj {
#define leashmon corpsenm /* gets m_id of attached pet */
#define spestudied corpsenm /* # of times a spellbook has been studied */
#define fromsink corpsenm /* a potion from a sink */

#ifdef RECORD_ACHIEVE
#define record_achieve_special corpsenm
#endif

unsigned oeaten; /* nutrition left in food, if partly eaten */
#define odamaged oeaten /* how much object's special power worn out */
long age; /* creation date */
Expand Down

0 comments on commit a3e2137

Please sign in to comment.