Source:Hack 1.0/mklv.makemaz.c
Jump to navigation
Jump to search
Below is the full text to mklv.makemaz.c from the source code of Hack 1.0. To link to a particular line, write [[Hack 1.0/mklv.makemaz.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. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */ 2. 3. #include "mklev.h" 4. extern struct monst *makemon(); 5. extern coord mazexy(); 6. 7. makemaz() 8. { 9. int x,y; 10. register zx,zy; 11. coord mm; 12. 13. for(x = 2; x < COLNO-1; x++) 14. for(y = 2; y < ROWNO-1; y++) 15. levl[x][y].typ = (x%2 && y%2) ? 0 : HWALL; 16. mm = mazexy(); 17. zx = mm.x; 18. zy = mm.y; 19. walkfrom(zx,zy); 20. mkobj_at(AMULET_SYM, zx, zy); 21. mkobj_at(ROCK_SYM, zx, zy); /* put a rock on top of the amulet */ 22. /* (probably this means that one needs a wand of digging to reach 23. the amulet - we must make sure that the player has a chance of 24. getting one; let us say when he kills the minotaur; of course 25. the minotaur itself may be blocked behind rocks, but well...) */ 26. for(x = 2; x < COLNO-1; x++) 27. for(y = 2; y < ROWNO-1; y++) { 28. switch(levl[x][y].typ) { 29. case HWALL: 30. levl[x][y].scrsym = '-'; 31. break; 32. case ROOM: 33. levl[x][y].scrsym = '.'; 34. break; 35. } 36. } 37. for(x = rn1(8,11); x; x--) { 38. mm = mazexy(); 39. mkobj_at(0, mm.x, mm.y); 40. } 41. for(x = rn1(10,2); x; x--) { 42. mm = mazexy(); 43. mkobj_at(ROCK_SYM, mm.x, mm.y); 44. } 45. mm = mazexy(); 46. (void) makemon(PM_MINOTAUR, mm.x, mm.y); 47. for(x = rn1(5,7); x; x--) { 48. mm = mazexy(); 49. (void) makemon((struct permonst *) 0, mm.x, mm.y); 50. } 51. for(x = rn1(6,7); x; x--) { 52. mm = mazexy(); 53. mkgold(0,mm.x,mm.y); 54. } 55. for(x = rn1(6,7); x; x--) 56. mktrap(0,1); 57. mm = mazexy(); 58. levl[(xupstair = mm.x)][(yupstair = mm.y)].scrsym = '<'; 59. levl[xupstair][yupstair].typ = STAIRS; 60. xdnstair = ydnstair = 0; 61. } 62. 63. walkfrom(x,y) int x,y; { 64. register int q,a,dir; 65. int dirs[4]; 66. levl[x][y].typ = ROOM; 67. while(1) { 68. q = 0; 69. for(a = 0; a < 4; a++) 70. if(okay(x,y,a)) dirs[q++]= a; 71. if(!q) return; 72. dir = dirs[rn2(q)]; 73. move(&x,&y,dir); 74. levl[x][y].typ = ROOM; 75. move(&x,&y,dir); 76. walkfrom(x,y); 77. } 78. } 79. 80. move(x,y,dir) 81. register int *x, *y; 82. register int dir; 83. { 84. switch(dir){ 85. case 0: --(*y); break; 86. case 1: (*x)++; break; 87. case 2: (*y)++; break; 88. case 3: --(*x); break; 89. } 90. } 91. 92. okay(x,y,dir) 93. int x,y; 94. register int dir; 95. { 96. move(&x,&y,dir); 97. move(&x,&y,dir); 98. if(x<3 || y<3 || x>COLNO-3 || y>ROWNO-3 || levl[x][y].typ != 0) 99. return(0); 100. else 101. return(1); 102. } 103. 104. coord 105. mazexy(){ 106. coord mm; 107. mm.x = 3 + 2*rn2(COLNO/2 - 2); 108. mm.y = 3 + 2*rn2(ROWNO/2 - 2); 109. return mm; 110. }