Source:NetHack 3.6.5/src/rip.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to rip.c from the source code of NetHack 3.6.5. To link to a particular line, write [[Source:NetHack 3.6.5/src/rip.c#line12]], for example.

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

1. /* NetHack 3.6	rip.c	$NHDT-Date: 1488788514 2017/03/06 08:21:54 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.23 $ */
2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3. /*-Copyright (c) Robert Patrick Rankin, 2017. */
4. /* NetHack may be freely redistributed.  See license for details. */
5. 
6. #include "hack.h"
7. 
8. #if defined(TTY_GRAPHICS) || defined(X11_GRAPHICS) || defined(GEM_GRAPHICS) \
9.     || defined(MSWIN_GRAPHICS) || defined(DUMPLOG) || defined(CURSES_GRAPHICS)
10. #define TEXT_TOMBSTONE
11. #endif
12. #if defined(mac) || defined(__BEOS__) || defined(WIN32_GRAPHICS)
13. #ifndef TEXT_TOMBSTONE
14. #define TEXT_TOMBSTONE
15. #endif
16. #endif
17. 
18. #ifdef TEXT_TOMBSTONE
19. STATIC_DCL void FDECL(center, (int, char *));
20. 
21. #ifndef NH320_DEDICATION
22. /* A normal tombstone for end of game display. */
23. static const char *rip_txt[] = {
24.     "                       ----------",
25.     "                      /          \\",
26.     "                     /    REST    \\",
27.     "                    /      IN      \\",
28.     "                   /     PEACE      \\",
29.     "                  /                  \\",
30.     "                  |                  |", /* Name of player */
31.     "                  |                  |", /* Amount of $ */
32.     "                  |                  |", /* Type of death */
33.     "                  |                  |", /* . */
34.     "                  |                  |", /* . */
35.     "                  |                  |", /* . */
36.     "                  |       1001       |", /* Real year of death */
37.     "                 *|     *  *  *      | *",
38.     "        _________)/\\\\_//(\\/(/\\)/\\//\\/|_)_______", 0
39. };
40. #define STONE_LINE_CENT 28 /* char[] element of center of stone face */
41. #else                      /* NH320_DEDICATION */
42. /* NetHack 3.2.x displayed a dual tombstone as a tribute to Izchak. */
43. static const char *rip_txt[] = {
44.     "              ----------                      ----------",
45.     "             /          \\                    /          \\",
46.     "            /    REST    \\                  /    This    \\",
47.     "           /      IN      \\                /  release of  \\",
48.     "          /     PEACE      \\              /   NetHack is   \\",
49.     "         /                  \\            /   dedicated to   \\",
50.     "         |                  |            |  the memory of   |",
51.     "         |                  |            |                  |",
52.     "         |                  |            |  Izchak Miller   |",
53.     "         |                  |            |   1935 - 1994    |",
54.     "         |                  |            |                  |",
55.     "         |                  |            |     Ascended     |",
56.     "         |       1001       |            |                  |",
57.     "      *  |     *  *  *      | *        * |      *  *  *     | *",
58.     " _____)/\\|\\__//(\\/(/\\)/\\//\\/|_)________)/|\\\\_/_/(\\/(/\\)/\\/\\/|_)____",
59.     0
60. };
61. #define STONE_LINE_CENT 19 /* char[] element of center of stone face */
62. #endif                     /* NH320_DEDICATION */
63. #define STONE_LINE_LEN                               \
64.     16               /* # chars that fit on one line \
65.                       * (note 1 ' ' border)          \
66.                       */
67. #define NAME_LINE 6  /* *char[] line # for player name */
68. #define GOLD_LINE 7  /* *char[] line # for amount of gold */
69. #define DEATH_LINE 8 /* *char[] line # for death description */
70. #define YEAR_LINE 12 /* *char[] line # for year */
71. 
72. static char **rip;
73. 
74. STATIC_OVL void
75. center(line, text)
76. int line;
77. char *text;
78. {
79.     register char *ip, *op;
80.     ip = text;
81.     op = &rip[line][STONE_LINE_CENT - ((strlen(text) + 1) >> 1)];
82.     while (*ip)
83.         *op++ = *ip++;
84. }
85. 
86. void
87. genl_outrip(tmpwin, how, when)
88. winid tmpwin;
89. int how;
90. time_t when;
91. {
92.     register char **dp;
93.     register char *dpx;
94.     char buf[BUFSZ];
95.     long year;
96.     register int x;
97.     int line;
98. 
99.     rip = dp = (char **) alloc(sizeof(rip_txt));
100.     for (x = 0; rip_txt[x]; ++x)
101.         dp[x] = dupstr(rip_txt[x]);
102.     dp[x] = (char *) 0;
103. 
104.     /* Put name on stone */
105.     Sprintf(buf, "%s", plname);
106.     buf[STONE_LINE_LEN] = 0;
107.     center(NAME_LINE, buf);
108. 
109.     /* Put $ on stone */
110.     Sprintf(buf, "%ld Au", done_money);
111.     buf[STONE_LINE_LEN] = 0; /* It could be a *lot* of gold :-) */
112.     center(GOLD_LINE, buf);
113. 
114.     /* Put together death description */
115.     formatkiller(buf, sizeof buf, how, FALSE);
116. 
117.     /* Put death type on stone */
118.     for (line = DEATH_LINE, dpx = buf; line < YEAR_LINE; line++) {
119.         register int i, i0;
120.         char tmpchar;
121. 
122.         if ((i0 = strlen(dpx)) > STONE_LINE_LEN) {
123.             for (i = STONE_LINE_LEN; ((i0 > STONE_LINE_LEN) && i); i--)
124.                 if (dpx[i] == ' ')
125.                     i0 = i;
126.             if (!i)
127.                 i0 = STONE_LINE_LEN;
128.         }
129.         tmpchar = dpx[i0];
130.         dpx[i0] = 0;
131.         center(line, dpx);
132.         if (tmpchar != ' ') {
133.             dpx[i0] = tmpchar;
134.             dpx = &dpx[i0];
135.         } else
136.             dpx = &dpx[i0 + 1];
137.     }
138. 
139.     /* Put year on stone */
140.     year = yyyymmdd(when) / 10000L;
141.     Sprintf(buf, "%4ld", year);
142.     center(YEAR_LINE, buf);
143. 
144. #ifdef DUMPLOG
145.     if (tmpwin == 0)
146.         dump_forward_putstr(0, 0, "Game over:", TRUE);
147.     else
148. #endif
149.         putstr(tmpwin, 0, "");
150. 
151.     for (; *dp; dp++)
152.         putstr(tmpwin, 0, *dp);
153. 
154.     putstr(tmpwin, 0, "");
155. #ifdef DUMPLOG
156.     if (tmpwin != 0)
157. #endif
158.         putstr(tmpwin, 0, "");
159. 
160.     for (x = 0; rip_txt[x]; x++) {
161.         free((genericptr_t) rip[x]);
162.     }
163.     free((genericptr_t) rip);
164.     rip = 0;
165. }
166. 
167. #endif /* TEXT_TOMBSTONE */
168. 
169. /*rip.c*/