Source:NetHack 1.3d/dog.c
Revision as of 23:44, 3 March 2008 by Kernigh bot (talk | contribs) (NetHack 1.3d/dog.c moved to Source:NetHack 1.3d/dog.c: Robot: moved page)
Below is the full text to dog.c from the source code of NetHack 1.3d. To link to a particular line, write [[NetHack 1.3d/dog.c#line123]], for example.
Warning! This is the source code from an old release. For the latest release, see Source code
Screenshots and source code from Hack are used under the CWI license.
1. /* SCCS Id: @(#)dog.c 1.3 87/07/14 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /* dog.c - version 1.0.3 */ 4. 5. #include "hack.h" 6. extern struct monst *makemon(); 7. #include "edog.h" 8. #include "mkroom.h" 9. 10. struct permonst li_dog = 11. { "little dog", 'd',2,18,6,0,1,6,sizeof(struct edog) }; 12. struct permonst dog = 13. { "dog", 'd',4,16,5,0,1,6,sizeof(struct edog) }; 14. struct permonst la_dog = 15. { "large dog", 'd',6,15,4,0,2,4,sizeof(struct edog) }; 16. 17. struct monst * 18. makedog(){ 19. register struct monst *mtmp = makemon(&li_dog,u.ux,u.uy); 20. if(!mtmp) return((struct monst *) 0); /* dogs were genocided */ 21. initedog(mtmp); 22. return(mtmp); 23. } 24. 25. initedog(mtmp) register struct monst *mtmp; { 26. mtmp->mtame = mtmp->mpeaceful = 1; 27. #ifdef WALKIES 28. mtmp->mleashed = 0; 29. #endif 30. EDOG(mtmp)->hungrytime = 1000 + moves; 31. EDOG(mtmp)->eattime = 0; 32. EDOG(mtmp)->droptime = 0; 33. EDOG(mtmp)->dropdist = 10000; 34. EDOG(mtmp)->apport = 10; 35. EDOG(mtmp)->whistletime = 0; 36. } 37. 38. /* attach the monsters that went down (or up) together with @ */ 39. struct monst *mydogs = 0; 40. struct monst *fallen_down = 0; /* monsters that fell through a trapdoor */ 41. /* they will appear on the next level @ goes to, even if he goes up! */ 42. 43. losedogs(){ 44. register struct monst *mtmp; 45. while(mtmp = mydogs){ 46. mydogs = mtmp->nmon; 47. mtmp->nmon = fmon; 48. fmon = mtmp; 49. mnexto(mtmp); 50. } 51. while(mtmp = fallen_down){ 52. fallen_down = mtmp->nmon; 53. mtmp->nmon = fmon; 54. #ifdef WALKIES 55. mtmp->mleashed = 0; 56. #endif 57. fmon = mtmp; 58. rloc(mtmp); 59. } 60. } 61. 62. keepdogs(){ 63. register struct monst *mtmp; 64. for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) 65. if(dist(mtmp->mx,mtmp->my) < 3 && follower(mtmp) 66. && !mtmp->msleep && !mtmp->mfroz) { 67. #ifdef DGKMOD 68. /* Bug "fix" for worm changing levels collapsing dungeon 69. */ 70. if (mtmp->data->mlet == 'w') { 71. if (canseemon(mtmp) || (Blind && Telepat)) 72. pline("The worm can't fit down the stairwell!"); 73. #ifdef WALKIES 74. pline("The leash slides off the slimy worm!"); 75. mtmp->mleashed = 0; 76. #endif 77. continue; 78. } 79. #endif 80. relmon(mtmp); 81. mtmp->nmon = mydogs; 82. mydogs = mtmp; 83. unpmon(mtmp); 84. keepdogs(); /* we destroyed the link, so use recursion */ 85. return; /* (admittedly somewhat primitive) */ 86. } 87. } 88. 89. fall_down(mtmp) register struct monst *mtmp; { 90. relmon(mtmp); 91. mtmp->nmon = fallen_down; 92. fallen_down = mtmp; 93. #ifdef WALKIES 94. if (mtmp->mleashed) { 95. 96. pline("The leash comes off!"); 97. mtmp->mleashed = 0; 98. } 99. #endif 100. unpmon(mtmp); 101. mtmp->mtame = 0; 102. } 103. 104. /* return quality of food; the lower the better */ 105. dogfood(obj) register struct obj *obj; { 106. switch(obj->olet) { 107. case FOOD_SYM: 108. return( 109. (obj->otyp == TRIPE_RATION) ? DOGFOOD : 110. (obj->otyp < CARROT) ? ACCFOOD : 111. (obj->otyp < CORPSE) ? MANFOOD : 112. (poisonous(obj) || obj->age + 50 <= moves || 113. obj->otyp == DEAD_COCKATRICE) 114. ? POISON : CADAVER 115. ); 116. default: 117. if(!obj->cursed) return(APPORT); 118. /* fall into next case */ 119. case BALL_SYM: 120. case CHAIN_SYM: 121. case ROCK_SYM: 122. return(UNDEF); 123. } 124. } 125. 126. /* return roomnumber or -1 */ 127. inroom(x,y) xchar x,y; { 128. #ifndef QUEST 129. register struct mkroom *croom = &rooms[0]; 130. while(croom->hx >= 0){ 131. if(croom->hx >= x-1 && croom->lx <= x+1 && 132. croom->hy >= y-1 && croom->ly <= y+1) 133. return(croom - rooms); 134. croom++; 135. } 136. #endif 137. return(-1); /* not in room or on door */ 138. } 139. 140. tamedog(mtmp, obj) 141. register struct monst *mtmp; 142. register struct obj *obj; 143. { 144. register struct monst *mtmp2; 145. 146. /* worst case, at least he'll be peaceful. */ 147. mtmp->mpeaceful = 1; 148. if(flags.moonphase == FULL_MOON && night() && rn2(6)) 149. return(0); 150. 151. /* If we cannot tame him, at least he's no longer afraid. */ 152. mtmp->mflee = 0; 153. mtmp->mfleetim = 0; 154. if(mtmp->mtame || mtmp->mfroz || 155. #ifndef NOWORM 156. mtmp->wormno || 157. #endif 158. mtmp->isshk || mtmp->isgd || index(" @12", mtmp->data->mlet)) 159. return(0); /* no tame long worms? */ 160. if(obj) { 161. if(dogfood(obj) >= MANFOOD) return(0); 162. if(cansee(mtmp->mx,mtmp->my)){ 163. pline("%s devours the %s.", Monnam(mtmp), 164. objects[obj->otyp].oc_name); 165. } 166. obfree(obj, (struct obj *) 0); 167. } 168. mtmp2 = newmonst(sizeof(struct edog) + mtmp->mnamelth); 169. *mtmp2 = *mtmp; 170. mtmp2->mxlth = sizeof(struct edog); 171. if(mtmp->mnamelth) (void) strcpy(NAME(mtmp2), NAME(mtmp)); 172. initedog(mtmp2); 173. replmon(mtmp,mtmp2); 174. return(1); 175. }