xref: /csrg-svn/games/hack/hack.bones.c (revision 41227)
1*41227Sbostic /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2*41227Sbostic /* hack.bones.c - version 1.0.3 */
3*41227Sbostic 
4*41227Sbostic #include "hack.h"
5*41227Sbostic extern char plname[PL_NSIZ];
6*41227Sbostic extern long somegold();
7*41227Sbostic extern struct monst *makemon();
8*41227Sbostic extern struct permonst pm_ghost;
9*41227Sbostic 
10*41227Sbostic char bones[] = "bones_xx";
11*41227Sbostic 
12*41227Sbostic /* save bones and possessions of a deceased adventurer */
savebones()13*41227Sbostic savebones(){
14*41227Sbostic register fd;
15*41227Sbostic register struct obj *otmp;
16*41227Sbostic register struct trap *ttmp;
17*41227Sbostic register struct monst *mtmp;
18*41227Sbostic 	if(dlevel <= 0 || dlevel > MAXLEVEL) return;
19*41227Sbostic 	if(!rn2(1 + dlevel/2)) return;	/* not so many ghosts on low levels */
20*41227Sbostic 	bones[6] = '0' + (dlevel/10);
21*41227Sbostic 	bones[7] = '0' + (dlevel%10);
22*41227Sbostic 	if((fd = open(bones,0)) >= 0){
23*41227Sbostic 		(void) close(fd);
24*41227Sbostic 		return;
25*41227Sbostic 	}
26*41227Sbostic 	/* drop everything; the corpse's possessions are usually cursed */
27*41227Sbostic 	otmp = invent;
28*41227Sbostic 	while(otmp){
29*41227Sbostic 		otmp->ox = u.ux;
30*41227Sbostic 		otmp->oy = u.uy;
31*41227Sbostic 		otmp->age = 0;		/* very long ago */
32*41227Sbostic 		otmp->owornmask = 0;
33*41227Sbostic 		if(rn2(5)) otmp->cursed = 1;
34*41227Sbostic 		if(!otmp->nobj){
35*41227Sbostic 			otmp->nobj = fobj;
36*41227Sbostic 			fobj = invent;
37*41227Sbostic 			invent = 0;	/* superfluous */
38*41227Sbostic 			break;
39*41227Sbostic 		}
40*41227Sbostic 		otmp = otmp->nobj;
41*41227Sbostic 	}
42*41227Sbostic 	if(!(mtmp = makemon(PM_GHOST, u.ux, u.uy))) return;
43*41227Sbostic 	mtmp->mx = u.ux;
44*41227Sbostic 	mtmp->my = u.uy;
45*41227Sbostic 	mtmp->msleep = 1;
46*41227Sbostic 	(void) strcpy((char *) mtmp->mextra, plname);
47*41227Sbostic 	mkgold(somegold() + d(dlevel,30), u.ux, u.uy);
48*41227Sbostic 	for(mtmp = fmon; mtmp; mtmp = mtmp->nmon){
49*41227Sbostic 		mtmp->m_id = 0;
50*41227Sbostic 		if(mtmp->mtame) {
51*41227Sbostic 			mtmp->mtame = 0;
52*41227Sbostic 			mtmp->mpeaceful = 0;
53*41227Sbostic 		}
54*41227Sbostic 		mtmp->mlstmv = 0;
55*41227Sbostic 		if(mtmp->mdispl) unpmon(mtmp);
56*41227Sbostic 	}
57*41227Sbostic 	for(ttmp = ftrap; ttmp; ttmp = ttmp->ntrap)
58*41227Sbostic 		ttmp->tseen = 0;
59*41227Sbostic 	for(otmp = fobj; otmp; otmp = otmp->nobj) {
60*41227Sbostic 		otmp->o_id = 0;
61*41227Sbostic 	     /* otmp->o_cnt_id = 0; - superfluous */
62*41227Sbostic 		otmp->onamelth = 0;
63*41227Sbostic 		otmp->known = 0;
64*41227Sbostic 		otmp->invlet = 0;
65*41227Sbostic 		if(otmp->olet == AMULET_SYM && !otmp->spe) {
66*41227Sbostic 			otmp->spe = -1;      /* no longer the actual amulet */
67*41227Sbostic 			otmp->cursed = 1;    /* flag as gotten from a ghost */
68*41227Sbostic 		}
69*41227Sbostic 	}
70*41227Sbostic 	if((fd = creat(bones, FMASK)) < 0) return;
71*41227Sbostic 	savelev(fd,dlevel);
72*41227Sbostic 	(void) close(fd);
73*41227Sbostic }
74*41227Sbostic 
getbones()75*41227Sbostic getbones(){
76*41227Sbostic register fd,x,y,ok;
77*41227Sbostic 	if(rn2(3)) return(0);	/* only once in three times do we find bones */
78*41227Sbostic 	bones[6] = '0' + dlevel/10;
79*41227Sbostic 	bones[7] = '0' + dlevel%10;
80*41227Sbostic 	if((fd = open(bones, 0)) < 0) return(0);
81*41227Sbostic 	if((ok = uptodate(fd)) != 0){
82*41227Sbostic 		getlev(fd, 0, dlevel);
83*41227Sbostic 		for(x = 0; x < COLNO; x++) for(y = 0; y < ROWNO; y++)
84*41227Sbostic 			levl[x][y].seen = levl[x][y].new = 0;
85*41227Sbostic 	}
86*41227Sbostic 	(void) close(fd);
87*41227Sbostic #ifdef WIZARD
88*41227Sbostic 	if(!wizard)	/* duvel!frans: don't remove bones while debugging */
89*41227Sbostic #endif WiZARD
90*41227Sbostic 	    if(unlink(bones) < 0){
91*41227Sbostic 		pline("Cannot unlink %s .", bones);
92*41227Sbostic 		return(0);
93*41227Sbostic 	}
94*41227Sbostic 	return(ok);
95*41227Sbostic }
96