Source:NetHack 5.0.0/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 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/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 5.0	rip.c	$NHDT-Date: 1597967808 2020/08/20 23:56:48 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.33 $ */
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. /* Defining TEXT_TOMBSTONE causes genl_outrip() to exist, but it doesn't
9.    necessarily have to be used by a binary with multiple window-ports */
10. 
11. #if defined(TTY_GRAPHICS) || defined(X11_GRAPHICS) || defined(GEM_GRAPHICS) \
12.     || defined(DUMPLOG) || defined(CURSES_GRAPHICS) || defined(SHIM_GRAPHICS) \
13.     || defined(AMII_GRAPHICS)
14. #define TEXT_TOMBSTONE
15. #endif
16. #if defined(mac) || defined(__BEOS__)
17. #ifndef TEXT_TOMBSTONE
18. #define TEXT_TOMBSTONE
19. #endif
20. #endif
21. 
22. #ifdef TEXT_TOMBSTONE
23. staticfn void center(int, char *);
24. 
25. #ifndef NH320_DEDICATION
26. /* A normal tombstone for end of game display. */
27. static const char *const rip_txt[] = {
28.     "                       ----------",
29.     "                      /          \\",
30.     "                     /    REST    \\",
31.     "                    /      IN      \\",
32.     "                   /     PEACE      \\",
33.     "                  /                  \\",
34.     "                  |                  |", /* Name of player */
35.     "                  |                  |", /* Amount of $ */
36.     "                  |                  |", /* Type of death */
37.     "                  |                  |", /* . */
38.     "                  |                  |", /* . */
39.     "                  |                  |", /* . */
40.     "                  |       1001       |", /* Real year of death */
41.     "                 *|     *  *  *      | *",
42.     "        _________)/\\\\_//(\\/(/\\)/\\//\\/|_)_______", 0
43. };
44. #define STONE_LINE_CENT 28 /* char[] element of center of stone face */
45. #else                      /* NH320_DEDICATION */
46. /* NetHack 3.2.x displayed a dual tombstone as a tribute to Izchak. */
47. static const char *const rip_txt[] = {
48.     "              ----------                      ----------",
49.     "             /          \\                    /          \\",
50.     "            /    REST    \\                  /    This    \\",
51.     "           /      IN      \\                /  release of  \\",
52.     "          /     PEACE      \\              /   NetHack is   \\",
53.     "         /                  \\            /   dedicated to   \\",
54.     "         |                  |            |  the memory of   |",
55.     "         |                  |            |                  |",
56.     "         |                  |            |  Izchak Miller   |",
57.     "         |                  |            |   1935 - 1994    |",
58.     "         |                  |            |                  |",
59.     "         |                  |            |     Ascended     |",
60.     "         |       1001       |            |                  |",
61.     "      *  |     *  *  *      | *        * |      *  *  *     | *",
62.     (" _____)/\\|\\__//(\\/(/\\)/\\//\\/|_)___"
63.      "_____)/|\\\\_/_/(\\/(/\\)/\\/\\/|_)____"),
64.     0
65. };
66. #define STONE_LINE_CENT 19 /* char[] element of center of stone face */
67. #endif                     /* NH320_DEDICATION */
68. #define STONE_LINE_LEN  16 /* # chars that fit on one line
69.                             * (note 1 ' ' border)           */
70. #define NAME_LINE  6 /* *char[] line # for player name */
71. #define GOLD_LINE  7 /* *char[] line # for amount of gold */
72. #define DEATH_LINE 8 /* *char[] line # for death description */
73. #define YEAR_LINE 12 /* *char[] line # for year */
74. 
75. staticfn void
76. center(int line, char *text)
77. {
78.     char *ip, *op;
79.     ip = text;
80.     op = &gr.rip[line][STONE_LINE_CENT - ((strlen(text) + 1) >> 1)];
81.     while (*ip)
82.         *op++ = *ip++;
83. }
84. 
85. void
86. genl_outrip(winid tmpwin, int how, time_t when)
87. {
88.     char **dp;
89.     char *dpx;
90.     char buf[BUFSZ];
91.     int x;
92.     int line, year;
93.     long cash;
94. 
95.     gr.rip = dp = (char **) alloc(sizeof(rip_txt));
96.     for (x = 0; rip_txt[x]; ++x)
97.         dp[x] = dupstr(rip_txt[x]);
98.     dp[x] = (char *) 0;
99. 
100.     /* Put name on stone */
101.     Sprintf(buf, "%.*s", (int) STONE_LINE_LEN, svp.plname);
102.     center(NAME_LINE, buf);
103. 
104.     /* Put $ on stone */
105.     cash = max(gd.done_money, 0L);
106.     /* arbitrary upper limit; practical upper limit is quite a bit less */
107.     if (cash > 999999999L)
108.         cash = 999999999L;
109.     Sprintf(buf, "%ld Au", cash);
110.     center(GOLD_LINE, buf);
111. 
112.     /* Put together death description */
113.     formatkiller(buf, sizeof buf, how, FALSE);
114. 
115.     /* Put death type on stone */
116.     for (line = DEATH_LINE, dpx = buf; line < YEAR_LINE; line++) {
117.         char tmpchar;
118.         int i, i0 = (int) strlen(dpx);
119. 
120.         if (i0 > STONE_LINE_LEN) {
121.             for (i = STONE_LINE_LEN; (i > 0) && (i0 > STONE_LINE_LEN); --i)
122.                 if (dpx[i] == ' ')
123.                     i0 = i;
124.             if (!i)
125.                 i0 = STONE_LINE_LEN;
126.         }
127.         tmpchar = dpx[i0];
128.         dpx[i0] = 0;
129.         center(line, dpx);
130.         if (tmpchar != ' ') {
131.             dpx[i0] = tmpchar;
132.             dpx = &dpx[i0];
133.         } else
134.             dpx = &dpx[i0 + 1];
135.     }
136. 
137.     /* Put year on stone */
138.     year = (int) ((yyyymmdd(when) / 10000L) % 10000L);
139.     Sprintf(buf, "%4d", year);
140.     center(YEAR_LINE, buf);
141. 
142. #ifdef DUMPLOG
143.     if (tmpwin == 0)
144.         dump_forward_putstr(0, 0, "Game over:", TRUE);
145.     else
146. #endif
147.         putstr(tmpwin, 0, "");
148. 
149.     for (; *dp; dp++)
150.         putstr(tmpwin, 0, *dp);
151. 
152.     putstr(tmpwin, 0, "");
153. #ifdef DUMPLOG
154.     if (tmpwin != 0)
155. #endif
156.         putstr(tmpwin, 0, "");
157. 
158.     for (x = 0; rip_txt[x]; x++) {
159.         free((genericptr_t) gr.rip[x]);
160.     }
161.     free((genericptr_t) gr.rip);
162.     gr.rip = 0;
163. }
164. 
165. #endif /* TEXT_TOMBSTONE */
166. 
167. /*rip.c*/