Source:NetHack 5.0.0/src/drawing.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to drawing.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/drawing.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	drawing.c	$NHDT-Date: 1596498163 2020/08/03 23:42:43 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.78 $ */
2. /* Copyright (c) NetHack Development Team 1992.                   */
3. /* NetHack may be freely redistributed.  See license for details. */
4. 
5. #include "config.h"
6. #include "color.h"
7. #include "rm.h"
8. #include "objclass.h"
9. #include "wintype.h"
10. #include "sym.h"
11. 
12. extern const struct symparse loadsyms[];
13. extern const struct class_sym def_oc_syms[MAXOCLASSES];
14. extern const struct class_sym def_monsyms[MAXMCLASSES];
15. extern const uchar def_r_oc_syms[MAXOCLASSES];
16. 
17. /* Relevant header information in rm.h, objclass.h, sym.h, defsym.h. */
18. 
19. /* Default object class symbols.  See objclass.h.
20.  * {symbol, name, explain}
21.  *     name:    used in object_detect().
22.  *     explain: used in do_look().
23.  */
24. const struct class_sym def_oc_syms[MAXOCLASSES] = {
25.     { '\0', "", "" }, /* placeholder for the "random class" */
26. #define OBJCLASS_DRAWING
27. #include "defsym.h"
28. #undef OBJCLASS_DRAWING
29. };
30. 
31. /* Default monster class symbols.  See sym.h and defsym.h. */
32. const struct class_sym def_monsyms[MAXMCLASSES] = {
33.     { '\0', "", "" },
34. #define MONSYMS_DRAWING
35. #include "defsym.h"
36. #undef MONSYMS_DRAWING
37. };
38. 
39. const struct symdef def_warnsyms[WARNCOUNT] = {
40.     /* white warning  */
41.     { '0', "unknown creature causing you worry",    CLR_WHITE },
42.     /* pink warning   */
43.     { '1', "unknown creature causing you concern",  CLR_RED },
44.     /* red warning    */
45.     { '2', "unknown creature causing you anxiety",  CLR_RED },
46.     /* ruby warning   */
47.     { '3', "unknown creature causing you disquiet", CLR_RED },
48.     /* purple warning */
49.     { '4', "unknown creature causing you alarm",    CLR_MAGENTA },
50.     /* black warning  */
51.     { '5', "unknown creature causing you dread",    CLR_BRIGHT_MAGENTA },
52. };
53. 
54. /*
55.  *  Default screen symbols with explanations and colors.
56.  *
57.  *  If adding to or removing from this list, please note that,
58.  *  for builds with tile support, there is an array called altlabels[] in
59.  *  win/share/tilemap.c that requires the same number of elements as
60.  *  this, in the same order. It is used for tile name matching when
61.  *  parsing other.txt because some of the useful tile names don't exist
62.  *  within NetHack itself.
63.  */
64. const struct symdef defsyms[MAXPCHARS + 1] = {
65. #define PCHAR_DRAWING
66. #include "defsym.h"
67. #undef PCHAR_DRAWING
68.     { 0, NULL, NO_COLOR }
69. };
70. 
71. /* default rogue level symbols */
72. const uchar def_r_oc_syms[MAXOCLASSES] = {
73. /* 0*/ '\0', ILLOBJ_SYM, WEAPON_SYM, ']', /* armor */
74.        RING_SYM,
75. /* 5*/ ',',                     /* amulet */
76.        TOOL_SYM, ':',           /* food */
77.        POTION_SYM, SCROLL_SYM,
78. /*10*/ SPBOOK_SYM, WAND_SYM,
79.        GEM_SYM,                /* gold -- yes it's the same as gems */
80.        GEM_SYM, ROCK_SYM,
81. /*15*/ BALL_SYM, CHAIN_SYM, VENOM_SYM
82. };
83. 
84. /*
85.  * Convert the given character to an object class.  If the character is not
86.  * recognized, then MAXOCLASSES is returned.  Used in detect.c, drawing.c,
87.  * invent.c, o_init.c, objnam.c, options.c, pickup.c, sp_lev.c, and
88.  * windows.c.
89.  */
90. int
91. def_char_to_objclass(char ch)
92. {
93.     int i;
94. 
95.     for (i = 1; i < MAXOCLASSES; i++)
96.         if (ch == def_oc_syms[i].sym)
97.             break;
98.     return i;
99. }
100. 
101. /*
102.  * Convert a character into a monster class.  This returns the _first_
103.  * match made.  If there are no matches, return MAXMCLASSES.
104.  * Used in detect.c, drawing.c, mondata.c, options.c, pickup.c,
105.  * sp_lev.c, and windows.c.
106.  */
107. int
108. def_char_to_monclass(char ch)
109. {
110.     int i;
111. 
112.     for (i = 1; i < MAXMCLASSES; i++)
113.         if (ch == def_monsyms[i].sym)
114.             break;
115.     return i;
116. }
117. 
118. /* does 'ch' represent a furniture character?  returns index into defsyms[] */
119. int
120. def_char_is_furniture(char ch)
121. {
122.     /* note: these refer to defsyms[] order which is much different from
123.        levl[][].typ order but both keep furniture in a contiguous block */
124.     static const char first_furniture[] = "stair", /* "staircase up" */
125.                       last_furniture[] = "fountain";
126.     int i;
127.     boolean furniture = FALSE;
128. 
129.     for (i = 0; i < MAXPCHARS; ++i) {
130.         if (!furniture) {
131.             if (!strncmp(defsyms[i].explanation, first_furniture, 5))
132.                 furniture = TRUE;
133.         }
134.         if (furniture) {
135.             if (defsyms[i].sym == (uchar) ch)
136.                 return i;
137.             if (!strcmp(defsyms[i].explanation, last_furniture))
138.                 break; /* reached last furniture */
139.         }
140.     }
141.     return -1;
142. }
143. 
144. /*drawing.c*/