Source:NetHack 2.2a/bones.c

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

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

1.   /*	SCCS Id: @(#)bones.c	1.4	87/08/08 2.   /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3.    /* bones.c - version 1.0.3 */ 4.    5.    #include "hack.h"  6.    extern char plname[PL_NSIZ]; 7.   extern long somegold; 8.   extern struct monst *makemon; 9.   extern struct permonst pm_ghost; 10.   11.   #ifdef DGK 12.  char bones[FILENAME]; 13.  #else 14.  char bones[] = "bones_xx"; 15.  #endif 16.   17.   /* save bones and possessions of a deceased adventurer */ 18.  savebones{ 19.  register fd; 20.  register struct obj *otmp; 21.  register struct trap *ttmp; 22.  register struct monst *mtmp; 23.  	if(dlevel <= 0 || dlevel > MAXLEVEL) return; 24.  	if(!rn2(1 + dlevel/2)	/* not so many ghosts on low levels */  25.   #ifdef WIZARD  26.   		&& !wizard  27.   #endif  28.   		) return; 29.  #ifdef DGK 30.  	name_file(bones, dlevel); 31.  #else 32.  	bones[6] = '0' + (dlevel/10); 33.  	bones[7] = '0' + (dlevel%10); 34.  #endif 35.  	if((fd = open(bones,0)) >= 0){ 36.  		(void) close(fd); 37.  #ifdef WIZARD 38.  		if(wizard) 39.  			pline("Bones file already exists."); 40.  #endif 41.  		return; 42.  	}  43.   	/* drop everything; the corpse's possessions are usually cursed */ 44.  	otmp = invent; 45.  	while(otmp){ 46.  		otmp->ox = u.ux; 47.  		otmp->oy = u.uy; 48.  		otmp->age = 0;		/* very long ago */ 49.  		otmp->owornmask = 0; 50.  		if(rn2(5)) otmp->cursed = 1; 51.  		if(!otmp->nobj){ 52.  			otmp->nobj = fobj; 53.  			fobj = invent; 54.  			invent = 0;	/* superfluous */ 55.  			break; 56.  		}  57.   		otmp = otmp->nobj; 58.  	}  59.   	/* spill any contained objects - added by GAN 03/23/87 */ 60.  	otmp = fcobj; 61.  	while(otmp)  { 62.  		register struct obj *otmp2; 63.   64.   		otmp2 = otmp->nobj; 65.  		spill_obj(otmp); 66.  		otmp = otmp2; 67.  	}  68.   	if(!(mtmp = makemon(PM_GHOST, u.ux, u.uy))) return; 69.  	mtmp->mx = u.ux; 70.  	mtmp->my = u.uy; 71.  	mtmp->msleep = 1; 72.  	(void) strcpy((char *) mtmp->mextra, plname); 73.  	mkgold(somegold + d(dlevel,30), u.ux, u.uy); 74.  	for(mtmp = fmon; mtmp; mtmp = mtmp->nmon){ 75.  		mtmp->m_id = 0; 76.  		if(mtmp->mtame) { 77.  			mtmp->mtame = 0; 78.  			mtmp->mpeaceful = 0; 79.  		}  80.   		mtmp->mlstmv = 0; 81.  		if(mtmp->mdispl) unpmon(mtmp); 82.  	}  83.   	for(ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) 84.  		ttmp->tseen = 0; 85.  	for(otmp = fobj; otmp; otmp = otmp->nobj) { 86.  		otmp->o_id = 0; 87.  	     /* otmp->o_cnt_id = 0; - superfluous */ 88.  		otmp->onamelth = 0; 89.  		otmp->known = 0; 90.  		otmp->invlet = 0; 91.  		if(otmp->olet == AMULET_SYM && !otmp->spe) { 92.  			otmp->spe = -1;      /* no longer the actual amulet */ 93.  			otmp->cursed = 1;    /* flag as gotten from a ghost */ 94.  		}  95.   	}  96.   #ifdef DGK 97.  	fd = open(bones, O_WRONLY | O_BINARY | O_CREAT, FMASK); 98.  #else 99.  	fd = creat(bones, FMASK); 100. #endif 101. 	if(fd < 0) { 102. #ifdef WIZARD 103. 		if(wizard) 104. 			pline("Cannot create bones file - creat failed"); 105. #endif 106. 		return; 107. 	}  108.  #ifdef DGK 109. 	savelev(fd,dlevel, COUNT | WRITE); 110. #else 111. 	savelev(fd,dlevel); 112. #endif 113. 	(void) close(fd); 114. }  115.   116.  /*  117.   * "spill" object out of box onto floor 118.  */  119.  spill_obj(obj) 120. struct obj *obj; 121. {  122.  	struct obj *otmp; 123.  124.  	for(otmp = fobj; otmp; otmp = otmp->nobj) 125. 		if(obj->o_cnt_id == otmp->o_id)  { 126. 			obj->ox = otmp->ox; 127. 			obj->oy = otmp->oy; 128. 			obj->age = 0; 129. 			if(rn2(5)) 130. 				obj->cursed = 1; 131. 			obj->nobj = otmp->nobj; 132. 			otmp->nobj = obj; 133. 			return; 134. 		}  135.  }  136.  		  137.  getbones{ 138. register fd,x,y,ok; 139. 	/* wizard check added by GAN 02/05/87 */ 140. 	if(rn2(3)	/* only once in three times do we find bones */  141.  #ifdef WIZARD  142.  		&& !wizard  143.  #endif  144.  		) return(0); 145. #ifdef DGK 146. 	name_file(bones, dlevel); 147. #else 148. 	bones[6] = '0' + dlevel/10; 149. 	bones[7] = '0' + dlevel%10; 150. #endif 151. 	if((fd = open(bones, 0)) < 0) return(0); 152. 	if((ok = uptodate(fd)) != 0){ 153. #ifdef WIZARD 154. 		if(wizard)  { 155. 			char buf[BUFSZ]; 156. 			pline("Get bones? "); 157. 			getlin(buf); 158. 			if(buf[0] == 'n')  { 159. 				(void) close(fd); 160. 				return(0); 161. 			}  162.  		}  163.  #endif 164. 		getlev(fd, 0, dlevel); 165. 		for(x = 0; x < COLNO; x++) for(y = 0; y < ROWNO; y++) 166. 			levl[x][y].seen = levl[x][y].new = 0; 167. 	}  168.  	(void) close(fd); 169. #ifdef WIZARD 170. 	if(wizard)  { 171. 		char buf[BUFSZ]; 172. 		pline("Unlink bones? "); 173. 		getlin(buf); 174. 		if(buf[0] == 'n') 175. 			return(ok); 176. 	}  177.  #endif 178. 	if(unlink(bones) < 0){ 179. 		pline("Cannot unlink %s .", bones); 180. 		return(0); 181. 	}  182.  	return(ok); 183. }