Source:NetHack 1.4f/write.c

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

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

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