MCPcopy Index your code
hub / github.com/NetHack/NetHack / dowrite

Function dowrite

src/write.c:73–385  ·  view source on GitHub ↗

write -- applying a magic marker */

Source from the content-addressed store, hash-verified

71
72/* write -- applying a magic marker */
73int
74dowrite(struct obj *pen)
75{
76 struct obj *paper;
77 char namebuf[BUFSZ] = DUMMY, *nm, *bp;
78 struct obj *new_obj;
79 int basecost, actualcost;
80 int curseval;
81 char qbuf[QBUFSZ];
82 int first, last, i, deferred, deferralchance, real;
83 boolean by_descr = FALSE;
84 const char *typeword;
85 int spell_knowledge;
86
87 if (nohands(gy.youmonst.data)) {
88 You("need hands to be able to write!");
89 return ECMD_OK;
90 } else if (Glib) {
91 pline("%s from your %s.", Tobjnam(pen, "slip"),
92 fingers_or_gloves(FALSE));
93 dropx(pen);
94 return ECMD_TIME;
95 }
96
97 /* get paper to write on */
98 paper = getobj("write on", write_ok, GETOBJ_NOFLAGS);
99 if (!paper)
100 return ECMD_CANCEL;
101 /* can't write on a novel (unless/until it's been converted into a blank
102 spellbook), but we want messages saying so to avoid "spellbook" */
103 typeword = (paper->otyp == SPE_NOVEL) ? "book"
104 : (paper->oclass == SPBOOK_CLASS) ? "spellbook"
105 : "scroll";
106 if (Blind) {
107 if (!paper->dknown) {
108 You("don't know whether that %s is blank or not.", typeword);
109 return ECMD_OK;
110 } else if (paper->oclass == SPBOOK_CLASS) {
111 /* can't write a magic book while blind */
112 pline("%s can't create braille text.",
113 upstart(ysimple_name(pen)));
114 return ECMD_OK;
115 }
116 }
117 observe_object(paper);
118 if (paper->otyp != SCR_BLANK_PAPER && paper->otyp != SPE_BLANK_PAPER) {
119 pline("That %s is not blank!", typeword);
120 exercise(A_WIS, FALSE);
121 return ECMD_TIME;
122 }
123 makeknown(SCR_BLANK_PAPER);
124
125 /* what to write */
126 Sprintf(qbuf, "What type of %s do you want to write?", typeword);
127 getlin(qbuf, namebuf);
128 (void) mungspaces(namebuf); /* remove any excess whitespace */
129 if (namebuf[0] == '\033' || !namebuf[0])
130 return ECMD_TIME;

Callers 1

doapplyFunction · 0.85

Calls 15

YouFunction · 0.85
TobjnamFunction · 0.85
fingers_or_glovesFunction · 0.85
dropxFunction · 0.85
getobjFunction · 0.85
upstartFunction · 0.85
ysimple_nameFunction · 0.85
observe_objectFunction · 0.85
exerciseFunction · 0.85
getlinFunction · 0.85
mungspacesFunction · 0.85
strstriFunction · 0.85

Tested by

no test coverage detected