abstract
| - Below is the full text to hack.bones.c from the source code of Hack 1.0. To link to a particular line, write [[Hack 1.0/hack.bones.c#line123]], for example. Warning! This is the source code from an old release. For the latest release, see Source code 1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */ 2. 3. #include "hack.h" 4. extern char plname[PL_NSIZ]; 5. extern struct monst *makemon(); 6. 7. struct permonst pm_ghost = { "ghost", ' ', 10, 3, -5, 1, 1, sizeof(plname) }; 8. 9. 10. char bones[] = "bones_xx"; 11. 12. /* save bones and possessions of a deceased adventurer */ 13. savebones(){ 14. register fd; 15. register struct obj *otmp; 16. register struct gen *gtmp; 17. register struct monst *mtmp; 18. if(!rn2(1 + dlevel/2)) return; /* not so many ghosts on low levels */ 19. bones[6] = '0' + (dlevel/10); 20. bones[7] = '0' + (dlevel%10); 21. if((fd = open(bones,0)) >= 0){ 22. (void) close(fd); 23. return; 24. } 25. /* drop everything; the corpse's possessions are usually cursed */ 26. otmp = invent; 27. while(otmp){ 28. otmp->ox = u.ux; 29. otmp->oy = u.uy; 30. otmp->known = 0; 31. otmp->age = 0; /* very long ago */ 32. otmp->owornmask = 0; 33. if(rn2(5)) otmp->cursed = 1; 34. if(!otmp->nobj){ 35. otmp->nobj = fobj; 36. fobj = invent; 37. invent = 0; /* superfluous */ 38. break; 39. } 40. otmp = otmp->nobj; 41. } 42. if(!(mtmp = makemon(&pm_ghost, u.ux, u.uy))) return; 43. mtmp->mx = u.ux; 44. mtmp->my = u.uy; 45. mtmp->msleep = 1; 46. (void) strcpy((char *) mtmp->mextra, plname); 47. mkgold(somegold() + d(dlevel,30), u.ux, u.uy); 48. u.ux = FAR; /* avoid animals standing next to us */ 49. keepdogs(); /* all tame animals become wild again */ 50. for(mtmp = fmon; mtmp; mtmp = mtmp->nmon){ 51. mtmp->mlstmv = 0; 52. if(mtmp->mdispl) unpmon(mtmp); 53. } 54. for(gtmp = ftrap; gtmp; gtmp = gtmp->ngen) 55. gtmp->gflag &= ~SEEN; 56. for(otmp = fobj; otmp; otmp = otmp->nobj) 57. otmp->onamelth = 0; 58. if((fd = creat(bones, FMASK)) < 0) return; 59. savelev(fd); 60. (void) close(fd); 61. } 62. 63. getbones(){ 64. register fd,x,y,ok; 65. if(rn2(3)) return(0); /* only once in three times do we find bones */ 66. bones[6] = '0' + dlevel/10; 67. bones[7] = '0' + dlevel%10; 68. if((fd = open(bones, 0)) < 0) return(0); 69. if((ok = uptodate(fd)) != 0){ 70. (void) getlev(fd); 71. (void) close(fd); 72. for(x = 0; x < COLNO; x++) for(y = 0; y < ROWNO; y++) 73. levl[x][y].seen = levl[x][y].new = 0; 74. } 75. if(unlink(bones) < 0){ 76. pline("Cannot unlink %s", bones); 77. return(0); 78. } 79. return(ok); 80. }
|