Source:NetHack 3.0.0/write.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to write.c from the source code of NetHack 3.0.0. To link to a particular line, write [[NetHack 3.0.0/write.c#line123]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

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.    /*	SCCS Id: @(#)write.c	3.0	89/01/10
2.     */
3.    /* NetHack may be freely redistributed.  See license for details. */
4.    
5.    #include "hack.h"
6.    
7.    /*
8.     * returns basecost of a scroll
9.     */
10.   static int
11.   cost(scroll)
12.   register struct obj *scroll;
13.   {
14.   	switch(scroll->otyp)  {
15.   # ifdef MAIL
16.   	case SCR_MAIL:
17.   		return(2);
18.   /*		break; */
19.   # endif
20.   	case SCR_LIGHT:
21.   	case SCR_GOLD_DETECTION:
22.   	case SCR_FOOD_DETECTION:
23.   	case SCR_MAGIC_MAPPING:
24.   	case SCR_AMNESIA:
25.   	case SCR_FIRE:
26.   		return(8);
27.   /*		break; */
28.   	case SCR_DESTROY_ARMOR:
29.   	case SCR_CREATE_MONSTER:
30.   	case SCR_PUNISHMENT:
31.   		return(10);
32.   /*		break; */
33.   	case SCR_CONFUSE_MONSTER:
34.   		return(12);
35.   /*		break; */
36.   	case SCR_IDENTIFY:
37.   		return(14);
38.   /*		break; */
39.   	case SCR_ENCHANT_ARMOR:
40.   	case SCR_REMOVE_CURSE:
41.   	case SCR_ENCHANT_WEAPON:
42.   		return(16);
43.   /*		break; */
44.   	case SCR_SCARE_MONSTER:
45.   	case SCR_TAMING:
46.   	case SCR_TELEPORTATION:
47.   		return(20);
48.   /*		break; */
49.   	case SCR_GENOCIDE:
50.   		return(30);
51.   /*		break; */
52.   	case SCR_BLANK_PAPER:
53.   	default:
54.   		impossible("You can't write such a weird scroll!");
55.   	}
56.   	return(1000);
57.   }
58.   
59.   static const char write_on[] = { SCROLL_SYM, 0 };
60.   
61.   void
62.   dowrite(pen)
63.   register struct obj *pen;
64.   {
65.   	register struct obj *paper;
66.   	char namebuf[BUFSZ], scrbuf[BUFSZ];
67.   	register struct obj *newscroll;
68.   	int basecost, actualcost;
69.   	int newquan;
70.   	int curseval;
71.   	
72.   	if(!pen)
73.   		return;
74.   	if(pen->otyp != MAGIC_MARKER)  {
75.   		You("can't write with that!");
76.   		return;
77.   	}
78.   	
79.   	/* get paper to write on */
80.   	paper = getobj(write_on,"write on");
81.   	if(!paper)
82.   		return;
83.   	if(!(objects[paper->otyp].oc_name_known))  {
84.   		pline("In your haste, you rip the scroll to pieces.");
85.   		useup(paper);
86.   		return;
87.   	}
88.   	if(paper->otyp != SCR_BLANK_PAPER)  {
89.   		You("fool, that scroll's not blank!");
90.   		return;
91.   	}
92.   	
93.   	/* what to write */
94.   	pline("What type of scroll do you want to write? ");
95.   	getlin(namebuf);
96.   	if(namebuf[0] == '\033' || !namebuf[0])
97.   		return;
98.   	Strcpy(scrbuf,"scroll of ");
99.   	Strcat(scrbuf,namebuf);
100.  	newscroll = readobjnam(scrbuf);
101.  
102.  	newscroll->bknown = (paper->bknown && pen->bknown);
103.  	/* do this now, before we useup() the paper */
104.  
105.  	if(newscroll->olet != SCROLL_SYM ||
106.  	   newscroll->otyp == SCR_BLANK_PAPER)  {
107.  		You("can't write that!");
108.  		pline("It's obscene!");
109.  		return;
110.  	}
111.  	
112.  	/* see if there's enough ink */
113.  	basecost = cost(newscroll);
114.  	if(pen->spe < basecost/2)  {
115.  		Your("marker is too dry to write that!");
116.  		obfree(newscroll, (struct obj *) 0);
117.  		return;
118.  	}
119.  	
120.  	/* we're really going to write now, so calculate
121.  	 * cost and useup old scroll
122.  	 */
123.  	actualcost = rn1(basecost/2,basecost/2);
124.  	curseval = bcsign(pen) + bcsign(paper);
125.  	useup(paper);
126.  	
127.  	/* dry out marker */
128.  	if(pen->spe < actualcost)  {
129.  		Your("marker dries out!");
130.  		pline("The scroll is now useless and disappears!");
131.  		pen->spe = 0;
132.  		obfree(newscroll, (struct obj *) 0);
133.  		return;
134.  	}
135.  	pen->spe -= actualcost;
136.  	
137.  	/* can't write if we don't know it - unless we're lucky */
138.  	if(!(objects[newscroll->otyp].oc_name_known) && 
139.  	   !(objects[newscroll->otyp].oc_uname) && 
140.  	   (rnl(pl_character[0] == 'W' ? 3 : 15))) {
141.  		You("don't know how to write that!");
142.  		You("write \"%s was here!\" and the scroll disappears.",
143.  			plname);
144.  		obfree(newscroll, (struct obj *) 0);
145.  		return;
146.  	}
147.  	
148.  	/* and now you know it! */
149.  	makeknown(newscroll->otyp);
150.  	
151.  	/* success - don't forget to fool prinv() */
152.  	newscroll = addinv(newscroll);
153.  	newquan = newscroll->quan;
154.  	newscroll->quan = 1;
155.  	newscroll->blessed = (curseval > 0);
156.  	newscroll->cursed = (curseval < 0);
157.  	prinv(newscroll);
158.  	newscroll->quan = newquan;
159.  #ifdef MAIL
160.  	if (newscroll->otyp == SCR_MAIL) newscroll->spe = 1;
161.  #endif
162.  	newscroll->known = 1;
163.  }