home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / games / volume16 / nethack31 / part31 < prev    next >
Internet Message Format  |  1993-02-01  |  58KB

  1. Path: uunet!news.tek.com!master!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v16i031:  nethack31 - display oriented dungeons & dragons (Ver. 3.1), Part31/108
  5. Message-ID: <4319@master.CNA.TEK.COM>
  6. Date: 29 Jan 93 20:46:17 GMT
  7. Sender: news@master.CNA.TEK.COM
  8. Lines: 1960
  9. Approved: billr@saab.CNA.TEK.COM
  10. Xref: uunet comp.sources.games:1588
  11.  
  12. Submitted-by: izchak@linc.cis.upenn.edu (Izchak Miller)
  13. Posting-number: Volume 16, Issue 31
  14. Archive-name: nethack31/Part31
  15. Supersedes: nethack3p9: Volume 10, Issue 46-102
  16. Environment: Amiga, Atari, Mac, MS-DOS, OS2, Unix, VMS, X11
  17.  
  18.  
  19.  
  20. #! /bin/sh
  21. # This is a shell archive.  Remove anything before this line, then unpack
  22. # it by saving it into a file and typing "sh file".  To overwrite existing
  23. # files, type "sh file -c".  You can also feed this as standard input via
  24. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  25. # will see the following message at the end:
  26. #        "End of archive 31 (of 108)."
  27. # Contents:  dat/Elf.des src/makemon.c
  28. # Wrapped by billr@saab on Wed Jan 27 16:08:58 1993
  29. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  30. if test -f 'dat/Elf.des' -a "${1}" != "-c" ; then 
  31.   echo shar: Will not clobber existing file \"'dat/Elf.des'\"
  32. else
  33. echo shar: Extracting \"'dat/Elf.des'\" \(12738 characters\)
  34. sed "s/^X//" >'dat/Elf.des' <<'END_OF_FILE'
  35. X#    SCCS Id: @(#)Elf.des    3.1    91/12/24
  36. X#    Copyright (c) 1989 by Jean-Christophe Collet
  37. X#    Copyright (c) 1991 by M. Stephenson
  38. X# NetHack may be freely redistributed.  See license for details.
  39. X#
  40. X#    The "start" level for the quest.
  41. X#
  42. X#    Here you meet your (besieged) class leader, Earendil/Elwing
  43. X#    and receive your quest assignment.
  44. X#
  45. XMAZE: "E-start",' '
  46. XFLAGS: noteleport,hardfloor
  47. XGEOMETRY:center,center
  48. XMAP
  49. X.................................... . .....................................
  50. X................................... ... ....................................
  51. X.................................... . .....................................
  52. X................................... ... ....................................
  53. X.................................... . .....................................
  54. X..............................}}}}}}}.}}}}}}}...............................
  55. X............................}}}|----...----|}}}.............................
  56. X...........................}}|--...........--|}}............................
  57. X.................... . . . }|-...............-|} . . . .....................
  58. X................... . . . .}|.................|}. . . . ....................
  59. X............................................................................
  60. X................... . . . .}|.................|}. . . . ....................
  61. X.................... . . . }|-...............-|} . . . .....................
  62. X...........................}}|--...........--|}}............................
  63. X............................}}}|----...----|}}}.............................
  64. X..............................}}}}}}}.}}}}}}}...............................
  65. X.................................... . .....................................
  66. X................................... ... ....................................
  67. X.................................... . .....................................
  68. X................................... ... ....................................
  69. XENDMAP
  70. X# Random Monsters
  71. XRANDOM_MONSTERS: 'o', 'O'
  72. X# Dungeon Description
  73. XREGION:(00,00,75,19),lit,"ordinary"
  74. X# Stairs
  75. XSTAIR:(40,13),down
  76. X# Portal arrival point
  77. XBRANCH:(00,14,00,14),(0,0,0,0)
  78. X# Altar
  79. XALTAR:(37,10),chaos,altar
  80. X# Earendil/Elwing
  81. XMONSTER:'@',"Earendil",(37,10)
  82. X# The treasure of Earendil/Elwing
  83. XOBJECT:'(',"chest",(37,10)
  84. X# elf guards for the audience chamber
  85. XMONSTER:'@',"High-elf",(38,09)
  86. XMONSTER:'@',"High-elf",(38,10)
  87. XMONSTER:'@',"High-elf",(38,11)
  88. XMONSTER:'@',"High-elf",(36,09)
  89. XMONSTER:'@',"High-elf",(36,10)
  90. XMONSTER:'@',"High-elf",(36,11)
  91. XMONSTER:'@',"High-elf",(37,09)
  92. XMONSTER:'@',"High-elf",(37,11)
  93. X# Non diggable walls
  94. XNON_DIGGABLE:(00,00,75,19)
  95. X# traps
  96. X# One pit at each cardinal point.
  97. XTRAP:"pit",(37,05)
  98. XTRAP:"pit",(46,10)
  99. XTRAP:"pit",(37,15)
  100. XTRAP:"pit",(28,10)
  101. XTRAP:random,random
  102. XTRAP:random,random
  103. X# Monsters on siege duty.
  104. XMONSTER: 'o',"Uruk-hai",(35,04),hostile
  105. XMONSTER: 'o',"Uruk-hai",(36,03),hostile
  106. XMONSTER: 'o',"goblin",(37,03),hostile
  107. XMONSTER: 'o',"goblin",(38,03),hostile
  108. XMONSTER: 'o',"goblin",(39,04),hostile
  109. XMONSTER: 'o',"Uruk-hai",(48,09),hostile
  110. XMONSTER: 'o',"goblin",(48,10),hostile
  111. XMONSTER: 'o',"goblin",(48,11),hostile
  112. XMONSTER: 'o',"Uruk-hai",(35,16),hostile
  113. XMONSTER: 'o',"Uruk-hai",(36,17),hostile
  114. XMONSTER: 'o',"goblin",(37,17),hostile
  115. XMONSTER: 'o',"goblin",(38,17),hostile
  116. XMONSTER: 'o',"goblin",(39,16),hostile
  117. XMONSTER: 'o',"Uruk-hai",(26,09),hostile
  118. XMONSTER: 'o',"goblin",(26,10),hostile
  119. XMONSTER: 'o',"goblin",(26,11),hostile
  120. X#
  121. X#    The "locate" level for the quest.
  122. X#
  123. X#    Here you have to infiltrate the Goblins' Cave to go
  124. X#    further towards your assigned quest.
  125. X#
  126. X
  127. XMAZE: "E-locate",' '
  128. XFLAGS: hardfloor
  129. XGEOMETRY:center,center
  130. XMAP
  131. X                                                                            
  132. X ..       ....            ......            ...        .......         ..   
  133. X  ..     ......S...     ..........         .....       ........       ....  
  134. X   ..    .. ...   .    ......... ..          .           .....       ....   
  135. X    ..  ..        .      .....    ..         .             ..       .....   
  136. X     ....         .         ..     ..        S               ..        ..   
  137. X    ....          S        ..       ..      ....               ..      ..   
  138. X    .....        ...      ..         ..    ........              ..    ..   
  139. X   ......      ......   ...           ..  ............           ...  ...   
  140. X    ....      .. ....   ....       ........................S....S......     
  141. X       ..    ..   ..     ...     ........................         ..        
  142. X        ..  ..          ..       ........................          ..       
  143. X  ....   ....          ..         ........................         ..       
  144. X ......   ..          ..    ...    ....................           ..        
  145. X  ....   ....        ..    .....    ............                 ..         
  146. X   ..   ..  ..      ..       ...  .S    ............          ....     ...  
  147. X   .. ..     ..............    ....      ............      ....  ..   ..... 
  148. X    ...                   ..            ..     ....    .....      ..   .... 
  149. X                           ..............         ......           .....    
  150. X                                                                            
  151. XENDMAP
  152. X# Random Monsters
  153. XRANDOM_MONSTERS: 'o', 'O'
  154. X# Dungeon Description
  155. XREGION:(00,00,75,19),unlit,"ordinary"
  156. X# Doors
  157. XDOOR:closed,(15,02)
  158. XDOOR:closed,(18,06)
  159. XDOOR:closed,(35,15)
  160. XDOOR:closed,(45,05)
  161. XDOOR:closed,(59,09)
  162. XDOOR:closed,(64,09)
  163. X# Stairs
  164. XSTAIR:(01,01),up
  165. XSTAIR:(45,01),down
  166. X# Non diggable walls
  167. XNON_DIGGABLE:(00,00,75,19)
  168. X# Objects
  169. XOBJECT:random,random,random
  170. XOBJECT:random,random,random
  171. XOBJECT:random,random,random
  172. XOBJECT:random,random,random
  173. XOBJECT:random,random,random
  174. XOBJECT:random,random,random
  175. XOBJECT:random,random,random
  176. XOBJECT:random,random,random
  177. XOBJECT:random,random,random
  178. XOBJECT:random,random,random
  179. XOBJECT:random,random,random
  180. XOBJECT:random,random,random
  181. XOBJECT:random,random,random
  182. XOBJECT:random,random,random
  183. XOBJECT:random,random,random
  184. X# Random traps
  185. XTRAP:"pit",(13,10)
  186. XTRAP:"spiked pit",(45,03)
  187. XTRAP:"board",(41,16)
  188. XTRAP:"magic",(60,09)
  189. XTRAP:random,random
  190. XTRAP:random,random
  191. X# Random monsters.
  192. XMONSTER:'o',"Uruk-hai",(40,10),hostile
  193. XMONSTER:'o',"Uruk-hai",(41,10),hostile
  194. XMONSTER:'o',"Uruk-hai",(42,10),hostile
  195. XMONSTER:'o',"Uruk-hai",(43,10),hostile
  196. XMONSTER:'o',"goblin",(44,10),hostile
  197. XMONSTER:'o',"goblin",(45,10),hostile
  198. XMONSTER:'o',"goblin",(40,11),hostile
  199. XMONSTER:'o',"goblin",(41,11),hostile
  200. XMONSTER:'o',"goblin",(42,11),hostile
  201. XMONSTER:'o',"goblin",(43,11),hostile
  202. XMONSTER:'o',"goblin",(44,11),hostile
  203. XMONSTER:'o',"goblin",(45,11),hostile
  204. XMONSTER:'o',"goblin",(41,12),hostile
  205. XMONSTER:'o',"goblin",(42,12),hostile
  206. XMONSTER:'o',"goblin",(43,12),hostile
  207. XMONSTER:'o',"goblin",(44,12),hostile
  208. XMONSTER:'o',"goblin",random,hostile
  209. XMONSTER:'o',random,random,hostile
  210. XMONSTER:'O',random,random,hostile
  211. XMONSTER:'O',"ogre",(42,13),hostile
  212. XMONSTER:'O',"ogre",(43,13),hostile
  213. XMONSTER:'O',"ogre",(44,13),hostile
  214. XMONSTER:'O',"ogre",random,hostile
  215. X
  216. XWALLIFY
  217. X
  218. X#
  219. X#    The "goal" level for the quest.
  220. X#
  221. X#    Here you meet The Goblin King your nemesis monster.  You have to
  222. X#    defeat The Goblin King in combat to gain the artifact you have
  223. X#    been assigned to retrieve.
  224. X#
  225. X
  226. XMAZE: "E-goal", ' '
  227. XGEOMETRY:center,center
  228. XMAP
  229. X                                                                            
  230. X  ...                                                                  ...  
  231. X .......................................................................... 
  232. X  ...                                +                                 ...  
  233. X   .     ............     .......    .                   .......        .   
  234. X   .  .............................  .       ........   .........S..    .   
  235. X   .   ............    .  ......     .       .      .    .......   ..   .   
  236. X   .     .........     .   ....      +       . ...  .               ..  .   
  237. X   .        S          .         .........   .S.    .S...............   .   
  238. X   .  ...   .     ...  .         .........          .                   .   
  239. X   . ........    .....S.+.......+....\....+........+.                   .   
  240. X   .  ...         ...    S       .........           ..      .....      .   
  241. X   .                    ..       .........            ..      ......    .   
  242. X   .      .......     ...            +       ....    ....    .......... .   
  243. X   . ..............  ..              .      ......  ..  .............   .   
  244. X   .     .............               .     ..........          ......   .   
  245. X  ...                                +                                 ...  
  246. X .......................................................................... 
  247. X  ...                                                                  ...  
  248. X                                                                            
  249. XENDMAP
  250. X# Random Monsters
  251. XRANDOM_MONSTERS: 'o', 'O'
  252. X# Dungeon Description
  253. XREGION:(00,00,75,19),lit,"ordinary"
  254. X# Stairs
  255. XSTAIR:(19,10),up
  256. X# Non diggable walls
  257. XNON_DIGGABLE:(00,00,75,19)
  258. X# Objects
  259. XOBJECT:'(',"crystal ball",(37,10),blessed,0,"The Palantir of Westernesse"
  260. XOBJECT:'(',"chest",(37,10)
  261. XOBJECT:random,random,(36,09)
  262. XOBJECT:random,random,(36,10)
  263. XOBJECT:random,random,(36,11)
  264. XOBJECT:random,random,(37,09)
  265. XOBJECT:random,random,(37,11)
  266. XOBJECT:random,random,(38,09)
  267. XOBJECT:random,random,(38,10)
  268. XOBJECT:random,random,(38,11)
  269. XOBJECT:random,random,random
  270. XOBJECT:random,random,random
  271. XOBJECT:random,random,random
  272. XOBJECT:random,random,random
  273. XOBJECT:random,random,random
  274. X# Random traps
  275. XTRAP:random,random
  276. XTRAP:random,random
  277. XTRAP:random,random
  278. XTRAP:random,random
  279. XTRAP:random,random
  280. XTRAP:random,random
  281. X# doors
  282. XDOOR:locked,(12,08)
  283. XDOOR:closed,(22,10)
  284. XDOOR:locked,(24,10)
  285. XDOOR:closed,(25,11)
  286. XDOOR:closed,(32,10)
  287. XDOOR:closed,(37,03)
  288. XDOOR:closed,(37,07)
  289. XDOOR:closed,(37,13)
  290. XDOOR:closed,(37,16)
  291. XDOOR:closed,(42,10)
  292. XDOOR:locked,(46,08)
  293. XDOOR:closed,(51,10)
  294. XDOOR:locked,(53,08)
  295. XDOOR:closed,(65,05)
  296. X# Random monsters.
  297. XMONSTER:'o',"Goblin King",(37,10),hostile
  298. XMONSTER:'o',"Uruk-hai",(36,09),hostile
  299. XMONSTER:'o',"Uruk-hai",(36,10),hostile
  300. XMONSTER:'o',"Uruk-hai",(36,11),hostile
  301. XMONSTER:'o',"Uruk-hai",(37,09),hostile
  302. XMONSTER:'o',"Uruk-hai",(37,11),hostile
  303. XMONSTER:'o',"Uruk-hai",(38,09),hostile
  304. XMONSTER:'o',"goblin",(38,10),hostile
  305. XMONSTER:'o',"goblin",(38,11),hostile
  306. XMONSTER:'o',"goblin",(02,02),hostile
  307. XMONSTER:'o',"goblin",(71,02),hostile
  308. XMONSTER:'o',"goblin",(02,16),hostile
  309. XMONSTER:'o',"goblin",(71,16),hostile
  310. XMONSTER:'o',"Uruk-hai",random,hostile
  311. XMONSTER:'o',"Uruk-hai",random,hostile
  312. XMONSTER:'o',"goblin",random,hostile
  313. XMONSTER:'o',"goblin",random,hostile
  314. XMONSTER:'o',random,random,hostile
  315. XMONSTER:'o',random,random,hostile
  316. XMONSTER:'O',"ogre",(03,02),hostile
  317. XMONSTER:'O',"ogre",(72,02),hostile
  318. XMONSTER:'O',"ogre",(03,17),hostile
  319. XMONSTER:'O',"ogre",(72,17),hostile
  320. XMONSTER:'O',"ogre",(41,10),hostile
  321. XMONSTER:'O',"ogre",(33,09),hostile
  322. XMONSTER:'O',"ogre",random,hostile
  323. XMONSTER:'O',"ogre",random,hostile
  324. XMONSTER:'O',random,random,hostile
  325. X
  326. XWALLIFY
  327. X
  328. X#
  329. X#    The "fill" levels for the quest.
  330. X#
  331. X#    These levels are used to fill out any levels not occupied by specific
  332. X#    levels as defined above. "filla" is the upper filler, between the
  333. X#    start and locate levels, and "fillb" the lower between the locate
  334. X#    and goal levels.
  335. X#
  336. X
  337. XMAZE: "E-filla" , ' '
  338. XINIT_MAP: '.' , ' ', true, true, random, true
  339. XNOMAP
  340. X# Random Monsters
  341. XRANDOM_MONSTERS: 'o', 'O'
  342. X#
  343. XSTAIR: random, up
  344. XSTAIR: random, down
  345. X#
  346. XOBJECT: random, random, random
  347. XOBJECT: random, random, random
  348. XOBJECT: random, random, random
  349. XOBJECT: random, random, random
  350. XOBJECT: random, random, random
  351. XOBJECT: random, random, random
  352. XOBJECT: random, random, random
  353. X#
  354. XTRAP: random, random
  355. XTRAP: random, random
  356. XTRAP: random, random
  357. XTRAP: random, random
  358. X#
  359. XMONSTER: 'o', "goblin", random, hostile
  360. XMONSTER: 'o', "goblin", random, hostile
  361. XMONSTER: 'o', "goblin", random, hostile
  362. XMONSTER: 'o', "goblin", random, hostile
  363. XMONSTER: 'o', "Uruk-hai", random, hostile
  364. XMONSTER: 'o', random, random, hostile
  365. XMONSTER: 'O', "ogre", random, hostile
  366. X
  367. XMAZE: "E-fillb" , ' '
  368. XINIT_MAP: '.' , ' ', true, true, random, true
  369. XNOMAP
  370. X# Random Monsters
  371. XRANDOM_MONSTERS: 'o', 'O'
  372. X#
  373. XSTAIR: random, up
  374. XSTAIR: random, down
  375. X#
  376. XOBJECT: random, random, random
  377. XOBJECT: random, random, random
  378. XOBJECT: random, random, random
  379. XOBJECT: random, random, random
  380. XOBJECT: random, random, random
  381. XOBJECT: random, random, random
  382. XOBJECT: random, random, random
  383. XOBJECT: random, random, random
  384. XOBJECT: random, random, random
  385. XOBJECT: random, random, random
  386. XOBJECT: random, random, random
  387. X#
  388. XTRAP: random, random
  389. XTRAP: random, random
  390. XTRAP: random, random
  391. XTRAP: random, random
  392. X#
  393. XMONSTER: 'o', "goblin", random, hostile
  394. XMONSTER: 'o', "Uruk-hai", random, hostile
  395. XMONSTER: 'o', "Uruk-hai", random, hostile
  396. XMONSTER: 'o', "Uruk-hai", random, hostile
  397. XMONSTER: 'o', random, random, hostile
  398. XMONSTER: 'O', "ogre", random, hostile
  399. XMONSTER: 'O', "ogre", random, hostile
  400. END_OF_FILE
  401. if test 12738 -ne `wc -c <'dat/Elf.des'`; then
  402.     echo shar: \"'dat/Elf.des'\" unpacked with wrong size!
  403. fi
  404. # end of 'dat/Elf.des'
  405. fi
  406. if test -f 'src/makemon.c' -a "${1}" != "-c" ; then 
  407.   echo shar: Will not clobber existing file \"'src/makemon.c'\"
  408. else
  409. echo shar: Extracting \"'src/makemon.c'\" \(40817 characters\)
  410. sed "s/^X//" >'src/makemon.c' <<'END_OF_FILE'
  411. X/*    SCCS Id: @(#)makemon.c    3.1    92/11/01    */
  412. X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  413. X/* NetHack may be freely redistributed.  See license for details. */
  414. X
  415. X#include "hack.h"
  416. X#include "epri.h"
  417. X#include "emin.h"
  418. X#ifdef REINCARNATION
  419. X# include <ctype.h>
  420. X#endif
  421. X
  422. XSTATIC_VAR struct monst NEARDATA zeromonst;
  423. X
  424. X#define uncommon(ptr) \
  425. X    (((ptr)->geno & (G_GENOD | G_EXTINCT | G_NOGEN | G_UNIQ)) || \
  426. X     (!Inhell ? ((ptr)->geno & G_HELL) : ((ptr)->maligntyp > A_NEUTRAL)))
  427. X
  428. X#ifdef OVL0
  429. Xstatic boolean NDECL(cmavail);
  430. Xstatic int FDECL(align_shift, (struct permonst *));
  431. X#endif /* OVL0 */
  432. XSTATIC_DCL boolean FDECL(is_home_elemental,(struct permonst *));
  433. XSTATIC_DCL boolean FDECL(wrong_elem_type, (struct permonst *));
  434. XSTATIC_DCL void FDECL(m_initgrp,(struct monst *,int,int,int));
  435. XSTATIC_DCL void FDECL(m_initthrow,(struct monst *,int,int));
  436. XSTATIC_DCL void FDECL(m_initweap,(struct monst *));
  437. X#ifdef OVL1
  438. Xstatic void FDECL(m_initinv,(struct monst *));
  439. X#endif /* OVL1 */
  440. X
  441. Xextern int monstr[];
  442. X
  443. X#define m_initsgrp(mtmp, x, y)    m_initgrp(mtmp, x, y, 3)
  444. X#define m_initlgrp(mtmp, x, y)    m_initgrp(mtmp, x, y, 10)
  445. X#define toostrong(monindx, lev) (monstr[monindx] > lev)
  446. X#define tooweak(monindx, lev)    (monstr[monindx] < lev)
  447. X
  448. X#ifdef OVLB
  449. XSTATIC_OVL boolean
  450. Xis_home_elemental(ptr)
  451. Xregister struct permonst *ptr;
  452. X{
  453. X    if (ptr->mlet != S_ELEMENTAL) return FALSE;
  454. X    if (!In_endgame(&u.uz)) return FALSE;
  455. X    switch(monsndx(ptr)) {
  456. X        case PM_AIR_ELEMENTAL: return Is_airlevel(&u.uz);
  457. X        case PM_FIRE_ELEMENTAL: return Is_firelevel(&u.uz);
  458. X        case PM_EARTH_ELEMENTAL: return Is_earthlevel(&u.uz);
  459. X        case PM_WATER_ELEMENTAL: return Is_waterlevel(&u.uz);
  460. X    }
  461. X    return FALSE;    /* shouldn't be reached */
  462. X}
  463. X
  464. X/*
  465. X * Return true if the given monster cannot exist on this elemental level.
  466. X */
  467. XSTATIC_OVL boolean
  468. Xwrong_elem_type(ptr)
  469. X    register struct permonst *ptr;
  470. X{
  471. X    if (Is_earthlevel(&u.uz)) {
  472. X    /* no restrictions? */
  473. X    } else if (Is_waterlevel(&u.uz)) {
  474. X    /* just monsters that can swim */
  475. X    if(!is_swimmer(ptr)) return TRUE;
  476. X    } else if (Is_firelevel(&u.uz)) {
  477. X    if(!resists_fire(ptr)) return TRUE;
  478. X    } else if (Is_airlevel(&u.uz)) {
  479. X    if(!(is_flyer(ptr) && ptr->mlet != S_TRAPPER) && !is_floater(ptr)
  480. X       && !amorphous(ptr) && !noncorporeal(ptr) && !is_whirly(ptr))
  481. X        return TRUE;
  482. X    }
  483. X    return FALSE;
  484. X}
  485. X
  486. XSTATIC_OVL void
  487. Xm_initgrp(mtmp, x, y, n)    /* make a group just like mtmp */
  488. Xregister struct monst *mtmp;
  489. Xregister int x, y, n;
  490. X{
  491. X    coord mm;
  492. X    register int cnt = rnd(n);
  493. X    struct monst *mon;
  494. X
  495. X/*
  496. X *    Temporary kludge to cut down on swarming at lower character levels
  497. X *    till we can get this game a little more balanced. [mrs]
  498. X */
  499. X    cnt /= (u.ulevel < 3) ? 4 : (u.ulevel < 5) ? 2 : 1;
  500. X    if(!cnt) cnt++;
  501. X
  502. X    mm.x = x;
  503. X    mm.y = y;
  504. X    while(cnt--) {
  505. X        if (peace_minded(mtmp->data)) continue;
  506. X        /* Don't create groups of peaceful monsters since they'll get
  507. X         * in our way.  If the monster has a percentage chance so some
  508. X         * are peaceful and some are not, the result will just be a
  509. X         * smaller group.
  510. X         */
  511. X        if (enexto(&mm, mm.x, mm.y, mtmp->data)) {
  512. X            mon = makemon(mtmp->data, mm.x, mm.y);
  513. X            mon->mpeaceful = FALSE;
  514. X            set_malign(mon);
  515. X            /* Undo the second peace_minded() check in makemon(); if the
  516. X             * monster turned out to be peaceful the first time we
  517. X             * didn't create it at all; we don't want a second check.
  518. X             */
  519. X        }
  520. X    }
  521. X}
  522. X
  523. XSTATIC_OVL
  524. Xvoid
  525. Xm_initthrow(mtmp,otyp,oquan)
  526. Xstruct monst *mtmp;
  527. Xint otyp,oquan;
  528. X{
  529. X    register struct obj *otmp;
  530. X
  531. X    otmp = mksobj(otyp, TRUE, FALSE);
  532. X    otmp->quan = (long) rn1(oquan, 3);
  533. X    otmp->owt = weight(otmp);
  534. X    if (otyp == ORCISH_ARROW) otmp->opoisoned = TRUE;
  535. X    mpickobj(mtmp, otmp);
  536. X}
  537. X
  538. X#endif /* OVLB */
  539. X#ifdef OVL2
  540. X
  541. XSTATIC_OVL void
  542. Xm_initweap(mtmp)
  543. Xregister struct monst *mtmp;
  544. X{
  545. X    register struct permonst *ptr = mtmp->data;
  546. X    register int mm = monsndx(ptr);
  547. X#ifdef REINCARNATION
  548. X    if (Is_rogue_level(&u.uz)) return;
  549. X#endif
  550. X/*
  551. X *    first a few special cases:
  552. X *
  553. X *        giants get a boulder to throw sometimes.
  554. X *        ettins get clubs
  555. X *        kobolds get darts to throw
  556. X *        centaurs get some sort of bow & arrows or bolts
  557. X *        soldiers get all sorts of things.
  558. X *        kops get clubs & cream pies.
  559. X */
  560. X    switch (mtmp->data->mlet) {
  561. X        case S_GIANT:
  562. X        if (rn2(2)) (void)mongets(mtmp, (ptr != &mons[PM_ETTIN]) ?
  563. X                    BOULDER : CLUB);
  564. X        break;
  565. X        case S_HUMAN:
  566. X        if(is_mercenary(ptr)) {
  567. X            int w1 = 0, w2 = 0;
  568. X            switch (mm) {
  569. X
  570. X            case PM_WATCHMAN:
  571. X#ifdef ARMY
  572. X            case PM_SOLDIER:
  573. X#endif
  574. X              if (!rn2(3)) {
  575. X                  w1 = rn1(BEC_DE_CORBIN - PARTISAN + 1, PARTISAN);
  576. X                  w2 = rn2(2) ? DAGGER : KNIFE;
  577. X              } else w1 = rn2(2) ? SPEAR : SHORT_SWORD;
  578. X              break;
  579. X#ifdef ARMY
  580. X            case PM_SERGEANT:
  581. X              w1 = rn2(2) ? FLAIL : MACE;
  582. X              break;
  583. X            case PM_LIEUTENANT:
  584. X              w1 = rn2(2) ? BROADSWORD : LONG_SWORD;
  585. X              break;
  586. X            case PM_CAPTAIN:
  587. X#endif
  588. X            case PM_WATCH_CAPTAIN:
  589. X              w1 = rn2(2) ? LONG_SWORD : SILVER_SABER;
  590. X              break;
  591. X            default:
  592. X              if (!rn2(4)) w1 = DAGGER;
  593. X              if (!rn2(7)) w2 = SPEAR;
  594. X              break;
  595. X            }
  596. X            if (w1) (void)mongets(mtmp, w1);
  597. X            if (!w2 && w1 != DAGGER && !rn2(4)) w2 = KNIFE;
  598. X            if (w2) (void)mongets(mtmp, w2);
  599. X        } else if (is_elf(ptr)) {
  600. X            if (rn2(2))
  601. X            (void) mongets(mtmp,
  602. X                   rn2(2) ? ELVEN_MITHRIL_COAT : ELVEN_CLOAK);
  603. X            if (rn2(2)) (void)mongets(mtmp, ELVEN_LEATHER_HELM);
  604. X            else if (!rn2(4)) (void)mongets(mtmp, ELVEN_BOOTS);
  605. X            if (rn2(2)) (void)mongets(mtmp, ELVEN_DAGGER);
  606. X            switch (rn2(3)) {
  607. X            case 0:
  608. X                if (!rn2(4)) (void)mongets(mtmp, ELVEN_SHIELD);
  609. X                if (rn2(3)) (void)mongets(mtmp, ELVEN_SHORT_SWORD);
  610. X                (void)mongets(mtmp, ELVEN_BOW);
  611. X                m_initthrow(mtmp, ELVEN_ARROW, 12);
  612. X                break;
  613. X            case 1:
  614. X                (void)mongets(mtmp, ELVEN_BROADSWORD);
  615. X                if (rn2(2)) (void)mongets(mtmp, ELVEN_SHIELD);
  616. X                break;
  617. X            case 2:
  618. X                if (rn2(2)) {
  619. X                (void)mongets(mtmp, ELVEN_SPEAR);
  620. X                (void)mongets(mtmp, ELVEN_SHIELD);
  621. X                }
  622. X                break;
  623. X            }
  624. X            if(mtmp->data == &mons[PM_ELVENKING])
  625. X            (void)mongets(mtmp, PICK_AXE);
  626. X        }
  627. X        break;
  628. X
  629. X        case S_ANGEL:
  630. X        {
  631. X            int spe2;
  632. X            /* create minion stuff; can't use mongets */
  633. X            struct obj *otmp = mksobj(LONG_SWORD, FALSE, FALSE);
  634. X
  635. X            /* maybe make it special */
  636. X            if(!rn2(20) || is_lord(mtmp->data))
  637. X            otmp = oname(otmp, artiname(
  638. X                rn2(2) ? ART_DEMONBANE : ART_SUNSWORD), 0);
  639. X            bless(otmp);
  640. X            otmp->oerodeproof = TRUE;
  641. X            spe2 = rn2(4);
  642. X            otmp->spe = max(otmp->spe, spe2);
  643. X            mpickobj(mtmp, otmp);
  644. X
  645. X            otmp = mksobj(!rn2(4) || is_lord(mtmp->data) ?
  646. X                  SHIELD_OF_REFLECTION : LARGE_SHIELD,
  647. X                  FALSE, FALSE);
  648. X            otmp->cursed = FALSE;
  649. X            otmp->oerodeproof = TRUE;
  650. X            otmp->spe = 0;
  651. X            mpickobj(mtmp, otmp);
  652. X        }
  653. X        break;
  654. X
  655. X        case S_HUMANOID:
  656. X        if (mm == PM_HOBBIT) {
  657. X            switch (rn2(3)) {
  658. X            case 0:
  659. X                (void)mongets(mtmp, DAGGER);
  660. X                break;
  661. X            case 1:
  662. X                (void)mongets(mtmp, ELVEN_DAGGER);
  663. X                break;
  664. X            case 2:
  665. X                (void)mongets(mtmp, SLING);
  666. X                break;
  667. X              }
  668. X            if (!rn2(10)) (void)mongets(mtmp, ELVEN_MITHRIL_COAT);
  669. X            if (!rn2(10)) (void)mongets(mtmp, DWARVISH_CLOAK);
  670. X        } else if (is_dwarf(ptr)) {
  671. X            if (rn2(7)) (void)mongets(mtmp, DWARVISH_CLOAK);
  672. X            if (rn2(7)) (void)mongets(mtmp, IRON_SHOES);
  673. X            if (!rn2(4)) {
  674. X            (void)mongets(mtmp, DWARVISH_SHORT_SWORD);
  675. X            /* note: you can't use a mattock with a shield */
  676. X            if (rn2(2)) (void)mongets(mtmp, DWARVISH_MATTOCK);
  677. X            else {
  678. X                (void)mongets(mtmp, AXE);
  679. X                (void)mongets(mtmp, DWARVISH_ROUNDSHIELD);
  680. X            }
  681. X            (void)mongets(mtmp, DWARVISH_IRON_HELM);
  682. X            if (!rn2(3))
  683. X                (void)mongets(mtmp, DWARVISH_MITHRIL_COAT);
  684. X            } else {
  685. X            (void)mongets(mtmp, !rn2(3) ? PICK_AXE : DAGGER);
  686. X            }
  687. X        }
  688. X        break;
  689. X# ifdef KOPS
  690. X        case S_KOP:        /* create Keystone Kops with cream pies to
  691. X                 * throw. As suggested by KAA.       [MRS]
  692. X                 */
  693. X        if (!rn2(4)) m_initthrow(mtmp, CREAM_PIE, 2);
  694. X        if (!rn2(3)) (void)mongets(mtmp,(rn2(2)) ? CLUB : RUBBER_HOSE);
  695. X        break;
  696. X# endif
  697. X        case S_ORC:
  698. X        if(rn2(2)) (void)mongets(mtmp, ORCISH_HELM);
  699. X        switch (mm != PM_ORC_CAPTAIN ? mm :
  700. X            rn2(2) ? PM_MORDOR_ORC : PM_URUK_HAI) {
  701. X            case PM_MORDOR_ORC:
  702. X            if(!rn2(3)) (void)mongets(mtmp, SCIMITAR);
  703. X            if(!rn2(3)) (void)mongets(mtmp, ORCISH_SHIELD);
  704. X            if(!rn2(3)) (void)mongets(mtmp, KNIFE);
  705. X            if(!rn2(3)) (void)mongets(mtmp, ORCISH_CHAIN_MAIL);
  706. X            break;
  707. X            case PM_URUK_HAI:
  708. X            if(!rn2(3)) (void)mongets(mtmp, ORCISH_CLOAK);
  709. X            if(!rn2(3)) (void)mongets(mtmp, ORCISH_SHORT_SWORD);
  710. X            if(!rn2(3)) (void)mongets(mtmp, IRON_SHOES);
  711. X            if(!rn2(3)) {
  712. X                (void)mongets(mtmp, ORCISH_BOW);
  713. X                m_initthrow(mtmp, ORCISH_ARROW, 12);
  714. X            }
  715. X            if(!rn2(3)) (void)mongets(mtmp, URUK_HAI_SHIELD);
  716. X            break;
  717. X            default:
  718. X            if (mm != PM_ORC_SHAMAN && rn2(2))
  719. X              (void)mongets(mtmp, (mm == PM_GOBLIN || rn2(2) == 0)
  720. X                           ? ORCISH_DAGGER : SCIMITAR);
  721. X        }
  722. X        break;
  723. X        case S_OGRE:
  724. X        if (!rn2(mm == PM_OGRE_KING ? 3 : mm == PM_OGRE_LORD ? 6 : 12))
  725. X            (void) mongets(mtmp, BATTLE_AXE);
  726. X        break;
  727. X        case S_KOBOLD:
  728. X        if (!rn2(4)) m_initthrow(mtmp, DART, 12);
  729. X        break;
  730. X
  731. X        case S_CENTAUR:
  732. X        if (rn2(2)) {
  733. X            if(ptr == &mons[PM_FOREST_CENTAUR]) {
  734. X            (void)mongets(mtmp, BOW);
  735. X            m_initthrow(mtmp, ARROW, 12);
  736. X            } else {
  737. X            (void)mongets(mtmp, CROSSBOW);
  738. X            m_initthrow(mtmp, CROSSBOW_BOLT, 12);
  739. X            }
  740. X        }
  741. X        break;
  742. X        case S_WRAITH:
  743. X        (void)mongets(mtmp, KNIFE);
  744. X        (void)mongets(mtmp, LONG_SWORD);
  745. X        break;
  746. X        case S_DEMON:
  747. X        switch (mm) {
  748. X            case PM_BALROG:
  749. X            (void)mongets(mtmp, BULLWHIP);
  750. X            (void)mongets(mtmp, BROADSWORD);
  751. X            break;
  752. X            case PM_ORCUS:
  753. X            (void)mongets(mtmp, WAN_DEATH); /* the Wand of Orcus */
  754. X            break;
  755. X            case PM_HORNED_DEVIL:
  756. X            (void)mongets(mtmp, rn2(4) ? TRIDENT : BULLWHIP);
  757. X            break;
  758. X            case PM_ICE_DEVIL:
  759. X            if (!rn2(4)) (void)mongets(mtmp, SPEAR);
  760. X            break;
  761. X            case PM_ASMODEUS:
  762. X            (void)mongets(mtmp, WAN_COLD);
  763. X            break;
  764. X            case PM_DISPATER:
  765. X            (void)mongets(mtmp, WAN_STRIKING);
  766. X            break;
  767. X            case PM_YEENOGHU:
  768. X            (void)mongets(mtmp, FLAIL);
  769. X            break;
  770. X        }
  771. X        /* prevent djinnis and mail daemons from leaving objects when
  772. X         * they vanish
  773. X         */
  774. X        if (!is_demon(ptr)) break;
  775. X        /* fall thru */
  776. X/*
  777. X *    Now the general case, ~40% chance of getting some type
  778. X *    of weapon. TODO: Add more weapons types (use bigmonst());
  779. X */
  780. X        default:
  781. X        switch(rnd(12)) {
  782. X            case 1:
  783. X            m_initthrow(mtmp, DART, 12);
  784. X            break;
  785. X            case 2:
  786. X            (void) mongets(mtmp, CROSSBOW);
  787. X            m_initthrow(mtmp, CROSSBOW_BOLT, 12);
  788. X            break;
  789. X            case 3:
  790. X            (void) mongets(mtmp, BOW);
  791. X            m_initthrow(mtmp, ARROW, 12);
  792. X            break;
  793. X            case 4:
  794. X            m_initthrow(mtmp, DAGGER, 3);
  795. X            break;
  796. X            case 5:
  797. X            (void) mongets(mtmp, AKLYS);
  798. X            break;
  799. X            default:
  800. X            break;
  801. X        }
  802. X        break;
  803. X    }
  804. X#ifdef MUSE
  805. X    if ((int) mtmp->m_lev > rn2(70))
  806. X        (void) mongets(mtmp, rnd_offensive_item(mtmp));
  807. X#endif
  808. X}
  809. X
  810. X#endif /* OVL2 */
  811. X#ifdef OVL1
  812. X
  813. Xstatic void
  814. Xm_initinv(mtmp)
  815. Xregister struct    monst    *mtmp;
  816. X{
  817. X    register int cnt;
  818. X    register struct obj *otmp;
  819. X    register struct permonst *ptr = mtmp->data;
  820. X#ifdef REINCARNATION
  821. X    if (Is_rogue_level(&u.uz)) return;
  822. X#endif
  823. X/*
  824. X *    Soldiers get armour & rations - armour approximates their ac.
  825. X *    Nymphs may get mirror or potion of object detection.
  826. X */
  827. X    switch(ptr->mlet) {
  828. X
  829. X        case S_HUMAN:
  830. X        if(is_mercenary(ptr)) {
  831. X            register int mac;
  832. X#ifdef MUSE
  833. X            switch(monsndx(ptr)) {
  834. X            case PM_GUARD: mac = -1; break;
  835. X# ifdef ARMY
  836. X            case PM_SOLDIER: mac = 3; break;
  837. X            case PM_SERGEANT: mac = 0; break;
  838. X            case PM_LIEUTENANT: mac = -2; break;
  839. X            case PM_CAPTAIN: mac = -3; break;
  840. X# endif
  841. X            case PM_WATCHMAN: mac = 3; break;
  842. X            case PM_WATCH_CAPTAIN: mac = -2; break;
  843. X            default: impossible("odd mercenary %d?", monsndx(ptr));
  844. X                mac = 0;
  845. X                break;
  846. X            }
  847. X#else
  848. X            mac = ptr->ac;
  849. X#endif
  850. X
  851. X            if (mac < -1 && rn2(5))
  852. X            mac += 7 + mongets(mtmp, (rn2(5)) ?
  853. X                       PLATE_MAIL : CRYSTAL_PLATE_MAIL);
  854. X            else if (mac < 3 && rn2(5))
  855. X            mac += 6 + mongets(mtmp, (rn2(3)) ?
  856. X                       SPLINT_MAIL : BANDED_MAIL);
  857. X            else if (rn2(5))
  858. X            mac += 3 + mongets(mtmp, (rn2(3)) ?
  859. X                       RING_MAIL : STUDDED_LEATHER_ARMOR);
  860. X            else
  861. X            mac += 2 + mongets(mtmp, LEATHER_ARMOR);
  862. X
  863. X            if (mac < 10 && rn2(3))
  864. X            mac += 1 + mongets(mtmp, HELMET);
  865. X            else if (mac < 10 && rn2(2))
  866. X            mac += 1 + mongets(mtmp, DENTED_POT);
  867. X            if (mac < 10 && rn2(3))
  868. X            mac += 1 + mongets(mtmp, SMALL_SHIELD);
  869. X            else if (mac < 10 && rn2(2))
  870. X            mac += 2 + mongets(mtmp, LARGE_SHIELD);
  871. X            if (mac < 10 && rn2(3))
  872. X            mac += 1 + mongets(mtmp, LOW_BOOTS);
  873. X            else if (mac < 10 && rn2(2))
  874. X            mac += 2 + mongets(mtmp, HIGH_BOOTS);
  875. X            if (mac < 10 && rn2(3))
  876. X            mac += 1 + mongets(mtmp, LEATHER_GLOVES);
  877. X            else if (mac < 10 && rn2(2))
  878. X            mac += 1 + mongets(mtmp, ELVEN_CLOAK);
  879. X
  880. X#ifndef MUSE
  881. X            if (mac != 10 && rn2(5)) {    /* make up the difference */
  882. X            otmp = mksobj(RIN_PROTECTION, FALSE, FALSE);
  883. X            otmp->spe = (10 - mac + rn2(3) - rn2(3));
  884. X            if(otmp->spe < 0) curse(otmp);
  885. X            mpickobj(mtmp, otmp);
  886. X            }
  887. X#endif
  888. X#ifdef ARMY
  889. X            if(ptr != &mons[PM_GUARD] &&
  890. X            ptr != &mons[PM_WATCHMAN] &&
  891. X            ptr != &mons[PM_WATCH_CAPTAIN]) {
  892. X            if (!rn2(3)) (void) mongets(mtmp, K_RATION);
  893. X            if (!rn2(2)) (void) mongets(mtmp, C_RATION);
  894. X# ifdef MUSE
  895. X            if (ptr != &mons[PM_SOLDIER] && !rn2(3))
  896. X                (void) mongets(mtmp, BUGLE);
  897. X# endif
  898. X            } else
  899. X#endif
  900. X               if (ptr == &mons[PM_WATCHMAN] && rn2(3))
  901. X                (void) mongets(mtmp, TIN_WHISTLE);
  902. X        } else if (ptr == &mons[PM_SHOPKEEPER]) {
  903. X            (void) mongets(mtmp,SKELETON_KEY);
  904. X        }
  905. X        break;
  906. X
  907. X        case S_NYMPH:
  908. X        if(!rn2(2)) (void) mongets(mtmp, MIRROR);
  909. X        if(!rn2(2)) (void) mongets(mtmp, POT_OBJECT_DETECTION);
  910. X        break;
  911. X
  912. X        case S_GIANT:
  913. X        if (ptr == &mons[PM_MINOTAUR])
  914. X            (void) mongets(mtmp, WAN_DIGGING);
  915. X        else if (is_giant(ptr)) {
  916. X            for(cnt = rn2((int)(mtmp->m_lev / 2)); cnt; cnt--) {
  917. X                otmp = mksobj(rnd_class(DILITHIUM_CRYSTAL,LUCKSTONE-1),FALSE,FALSE);
  918. X                otmp->quan = (long) rn1(2, 3);
  919. X                otmp->owt = weight(otmp);
  920. X                mpickobj(mtmp, otmp);
  921. X            }
  922. X        }
  923. X        break;
  924. X        case S_WRAITH:
  925. X        if (ptr == &mons[PM_NAZGUL]) {
  926. X            otmp = mksobj(RIN_INVISIBILITY, FALSE, FALSE);
  927. X            curse(otmp);
  928. X            mpickobj(mtmp, otmp);
  929. X        }
  930. X        break;
  931. X        case S_QUANTMECH:
  932. X        if (!rn2(20)) {
  933. X            struct obj *cat;
  934. X
  935. X            otmp = mksobj(LARGE_BOX, FALSE, FALSE);
  936. X    /* actually, whether this is a corpse or a live cat shouldn't
  937. X       really be decided until the box is opened... */
  938. X            cat = mksobj(CORPSE, FALSE, FALSE);
  939. X            cat->corpsenm = PM_HOUSECAT;
  940. X            cat->owt = weight(cat);
  941. X            cat = oname(cat, "Schroedinger's Cat", FALSE);
  942. X            cat->nobj = otmp->cobj;
  943. X            otmp->cobj = cat;
  944. X            otmp->owt = weight(otmp);
  945. X            mpickobj(mtmp, otmp);
  946. X        }
  947. X        break;
  948. X        case S_LEPRECHAUN:
  949. X        mtmp->mgold = (long) d(level_difficulty(), 30);
  950. X        break;
  951. X        default:
  952. X        break;
  953. X    }
  954. X
  955. X#ifdef ARMY    /* ordinary soldiers rarely have access to magic (or gold :-) */
  956. X    if (ptr == &mons[PM_SOLDIER] && rn2(13)) return;
  957. X#endif
  958. X#ifdef MUSE
  959. X    if ((int) mtmp->m_lev > rn2(30))
  960. X        (void) mongets(mtmp, rnd_defensive_item(mtmp));
  961. X    if ((int) mtmp->m_lev > rn2(100))
  962. X        (void) mongets(mtmp, rnd_misc_item(mtmp));
  963. X#endif
  964. X    if (likes_gold(ptr) && !mtmp->mgold && !rn2(5))
  965. X        mtmp->mgold =
  966. X              (long) d(level_difficulty(), mtmp->minvent ? 5 : 10);
  967. X}
  968. X
  969. X/*
  970. X * called with [x,y] = coordinates;
  971. X *    [0,0] means anyplace
  972. X *    [u.ux,u.uy] means: near player (if !in_mklev)
  973. X *
  974. X *    In case we make a monster group, only return the one at [x,y].
  975. X */
  976. Xstruct monst *
  977. Xmakemon(ptr, x, y)
  978. Xregister struct permonst *ptr;
  979. Xregister int    x, y;
  980. X{
  981. X    register struct monst *mtmp;
  982. X    register int    ct;
  983. X    boolean anything = (!ptr);
  984. X    boolean byyou = (x == u.ux && y == u.uy);
  985. X
  986. X    /* if caller wants random location, do it here */
  987. X    if(x == 0 && y == 0) {
  988. X        int tryct = 0;    /* careful with bigrooms */
  989. X        do {
  990. X            x = rn1(COLNO-3,2);
  991. X            y = rn2(ROWNO);
  992. X        } while(!goodpos(x, y, (struct monst *)0, ptr) ||
  993. X            (!in_mklev && tryct++ < 50 && cansee(x, y)));
  994. X    } else if (byyou && !in_mklev) {
  995. X        coord bypos;
  996. X
  997. X        if(enexto(&bypos, u.ux, u.uy, ptr)) {
  998. X            x = bypos.x;
  999. X            y = bypos.y;
  1000. X        } else
  1001. X            return((struct monst *)0);
  1002. X    }
  1003. X
  1004. X    /* if a monster already exists at the position, return */
  1005. X    if(MON_AT(x, y))
  1006. X        return((struct monst *) 0);
  1007. X
  1008. X    if(ptr){
  1009. X        /* if you are to make a specific monster and it has
  1010. X           already been genocided, return */
  1011. X        if(ptr->geno & G_GENOD) return((struct monst *) 0);
  1012. X    } else {
  1013. X        /* make a random (common) monster that can survive here.
  1014. X         * (the special levels ask for random monsters at specific
  1015. X         * positions, causing mass drowning on the medusa level,
  1016. X         * for instance.)
  1017. X         */
  1018. X        int tryct = 0;    /* maybe there are no good choices */
  1019. X        do {
  1020. X            if(!(ptr = rndmonst())) {
  1021. X#ifdef DEBUG
  1022. X                pline("Warning: no monster.");
  1023. X#endif
  1024. X                return((struct monst *) 0);    /* no more monsters! */
  1025. X            }
  1026. X        } while(!goodpos(x, y, (struct monst *)0, ptr) && tryct++ < 50);
  1027. X    }
  1028. X    /* if it's unique, don't ever make it again */
  1029. X    if (ptr->geno & G_UNIQ) ptr->geno |= G_EXTINCT;
  1030. X
  1031. X    mtmp = newmonst(ptr->pxlth);
  1032. X    *mtmp = zeromonst;        /* clear all entries in structure */
  1033. X    for(ct = 0; ct < ptr->pxlth; ct++)
  1034. X        ((char *) &(mtmp->mextra[0]))[ct] = 0;
  1035. X    mtmp->nmon = fmon;
  1036. X    fmon = mtmp;
  1037. X    mtmp->m_id = flags.ident++;
  1038. X    mtmp->data = ptr;
  1039. X    mtmp->mxlth = ptr->pxlth;
  1040. X
  1041. X    mtmp->m_lev = adj_lev(ptr);
  1042. X    if (is_golem(ptr))
  1043. X        mtmp->mhpmax = mtmp->mhp = golemhp(monsndx(ptr));
  1044. X    else if (is_rider(ptr)) {
  1045. X        /* We want low HP, but a high mlevel so they can attack well */
  1046. X        mtmp->mhpmax = mtmp->mhp = d(10,8);
  1047. X    } else if(ptr->mlevel > 49) {
  1048. X        /* "special" fixed hp monster
  1049. X         * the hit points are encoded in the mlevel in a somewhat strange
  1050. X         * way to fit in the 50..127 positive range of a signed character
  1051. X         * above the 1..49 that indicate "normal" monster levels */
  1052. X        mtmp->mhpmax = mtmp->mhp = 2*(ptr->mlevel - 6);
  1053. X        mtmp->m_lev = mtmp->mhp / 4;    /* approximation */
  1054. X    } else if((ptr->mlet == S_DRAGON) && (ptr >= &mons[PM_GRAY_DRAGON]))
  1055. X        mtmp->mhpmax = mtmp->mhp = mtmp->m_lev*8;
  1056. X    else if(!mtmp->m_lev) mtmp->mhpmax = mtmp->mhp = rnd(4);
  1057. X    else if(is_home_elemental(ptr))
  1058. X        mtmp->mhpmax = mtmp->mhp = 3 * d((int)mtmp->m_lev, 8);
  1059. X    else mtmp->mhpmax = mtmp->mhp = d((int)mtmp->m_lev, 8);
  1060. X
  1061. X    if (is_female(ptr)) mtmp->female = TRUE;
  1062. X    else if (is_male(ptr)) mtmp->female = FALSE;
  1063. X    else mtmp->female = rn2(2);    /* ignored for neuters */
  1064. X
  1065. X    place_monster(mtmp, x, y);
  1066. X    mtmp->mcansee = mtmp->mcanmove = TRUE;
  1067. X    mtmp->mpeaceful = peace_minded(ptr);
  1068. X
  1069. X    switch(ptr->mlet) {
  1070. X        case S_MIMIC:
  1071. X            set_mimic_sym(mtmp);
  1072. X            break;
  1073. X        case S_SPIDER:
  1074. X        case S_SNAKE:
  1075. X            if(in_mklev)
  1076. X                if(x && y)
  1077. X                (void) mkobj_at(0, x, y, TRUE);
  1078. X            if(hides_under(ptr) && OBJ_AT(x, y))
  1079. X                mtmp->mundetected = TRUE;
  1080. X            break;
  1081. X        case S_STALKER:
  1082. X        case S_EEL:
  1083. X            mtmp->minvis = TRUE;
  1084. X            break;
  1085. X        case S_LEPRECHAUN:
  1086. X            mtmp->msleep = TRUE;
  1087. X            break;
  1088. X        case S_JABBERWOCK:
  1089. X        case S_NYMPH:
  1090. X            if(rn2(5) && !u.uhave.amulet) mtmp->msleep = TRUE;
  1091. X            break;
  1092. X        case S_ORC:
  1093. X            if(pl_character[0] == 'E') mtmp->mpeaceful = FALSE;
  1094. X            break;
  1095. X        case S_UNICORN:
  1096. X            if (sgn(u.ualign.type) == sgn(ptr->maligntyp))
  1097. X                mtmp->mpeaceful = TRUE;
  1098. X            break;
  1099. X    }
  1100. X    if (ptr == &mons[PM_CHAMELEON]) {
  1101. X        /* If you're protected with a ring, don't create
  1102. X         * any shape-changing chameleons -dgk
  1103. X         */
  1104. X        if (Protection_from_shape_changers)
  1105. X            mtmp->cham = FALSE;
  1106. X        else {
  1107. X            mtmp->cham = TRUE;
  1108. X            (void) newcham(mtmp, rndmonst());
  1109. X        }
  1110. X    } else if (ptr == &mons[PM_WIZARD_OF_YENDOR]) {
  1111. X        mtmp->iswiz = TRUE;
  1112. X        flags.no_of_wizards++;
  1113. X    } else if (ptr == &mons[PM_VLAD_THE_IMPALER])
  1114. X        (void) mongets(mtmp, CANDELABRUM_OF_INVOCATION);
  1115. X#ifdef MULDGN
  1116. X    else if (ptr->msound == MS_NEMESIS)
  1117. X        (void) mongets(mtmp, BELL_OF_OPENING);
  1118. X#else
  1119. X    else if (ptr == &mons[PM_MEDUSA])
  1120. X        (void) mongets(mtmp, BELL_OF_OPENING);
  1121. X#endif
  1122. X
  1123. X    if(in_mklev) {
  1124. X        if(((is_ndemon(ptr)) ||
  1125. X            (ptr == &mons[PM_WUMPUS]) ||
  1126. X            (ptr == &mons[PM_LONG_WORM]) ||
  1127. X            (ptr == &mons[PM_GIANT_EEL])) && !u.uhave.amulet && rn2(5))
  1128. X            mtmp->msleep = TRUE;
  1129. X    } else {
  1130. X        if(byyou) {
  1131. X            newsym(mtmp->mx,mtmp->my);
  1132. X            set_apparxy(mtmp);
  1133. X        }
  1134. X    }
  1135. X    if(is_dprince(ptr)) {
  1136. X        mtmp->mpeaceful = mtmp->minvis = TRUE;
  1137. X        if (uwep && uwep->oartifact == ART_EXCALIBUR)
  1138. X        mtmp->mpeaceful = mtmp->mtame = FALSE;
  1139. X    }
  1140. X    if ( (ptr == &mons[PM_LONG_WORM]) && (mtmp->wormno = get_wormno()) ) {
  1141. X        /* we can now create worms with tails - 11/91 */
  1142. X        initworm(mtmp, rn2(5));
  1143. X        if (count_wsegs(mtmp)) place_worm_tail_randomly(mtmp, x, y);
  1144. X    }
  1145. X    set_malign(mtmp);        /* having finished peaceful changes */
  1146. X    if(anything) {
  1147. X        if((ptr->geno & G_SGROUP) && rn2(2))
  1148. X        m_initsgrp(mtmp, mtmp->mx, mtmp->my);
  1149. X        else if(ptr->geno & G_LGROUP) {
  1150. X            if(rn2(3))  m_initlgrp(mtmp, mtmp->mx, mtmp->my);
  1151. X            else        m_initsgrp(mtmp, mtmp->mx, mtmp->my);
  1152. X        }
  1153. X    }
  1154. X
  1155. X    if(is_armed(ptr))
  1156. X        m_initweap(mtmp);    /* equip with weapons / armor */
  1157. X    m_initinv(mtmp);    /* add on a few special items incl. more armor */
  1158. X#ifdef MUSE
  1159. X    m_dowear(mtmp, TRUE);
  1160. X#endif
  1161. X
  1162. X    if (!in_mklev)
  1163. X        newsym(mtmp->mx,mtmp->my);    /* make sure the mon shows up */
  1164. X
  1165. X    return(mtmp);
  1166. X}
  1167. X
  1168. Xboolean
  1169. Xenexto(cc, xx, yy, mdat)
  1170. Xcoord *cc;
  1171. Xregister xchar xx, yy;
  1172. Xstruct permonst *mdat;
  1173. X{
  1174. X    register xchar x,y;
  1175. X    coord foo[15], *tfoo;
  1176. X    int range, i;
  1177. X    int xmin, xmax, ymin, ymax;
  1178. X
  1179. X    tfoo = foo;
  1180. X    range = 1;
  1181. X    do {    /* full kludge action. */
  1182. X        xmin = max(1, xx-range);
  1183. X        xmax = min(COLNO-1, xx+range);
  1184. X        ymin = max(0, yy-range);
  1185. X        ymax = min(ROWNO-1, yy+range);
  1186. X
  1187. X        for(x = xmin; x <= xmax; x++)
  1188. X            if(goodpos(x, ymin, (struct monst *)0, mdat)) {
  1189. X                tfoo->x = x;
  1190. X#ifdef MAC_MPW32
  1191. X                ( tfoo ) -> y = ymin ;
  1192. X                tfoo ++ ;
  1193. X#else
  1194. X                (tfoo++)->y = ymin;
  1195. X#endif
  1196. X                if(tfoo == &foo[15]) goto foofull;
  1197. X            }
  1198. X        for(x = xmin; x <= xmax; x++)
  1199. X            if(goodpos(x, ymax, (struct monst *)0, mdat)) {
  1200. X                tfoo->x = x;
  1201. X#ifdef MAC_MPW32
  1202. X                ( tfoo ) -> y = ymax ;
  1203. X                tfoo ++ ;
  1204. X#else
  1205. X                (tfoo++)->y = ymax;
  1206. X#endif
  1207. X                if(tfoo == &foo[15]) goto foofull;
  1208. X            }
  1209. X        for(y = ymin+1; y < ymax; y++)
  1210. X            if(goodpos(xmin, y, (struct monst *)0, mdat)) {
  1211. X                tfoo->x = xmin;
  1212. X#ifdef MAC_MPW32
  1213. X                ( tfoo ) -> y = y ;
  1214. X                tfoo ++ ;
  1215. X#else
  1216. X                (tfoo++)->y = y;
  1217. X#endif
  1218. X                if(tfoo == &foo[15]) goto foofull;
  1219. X            }
  1220. X        for(y = ymin+1; y < ymax; y++)
  1221. X            if(goodpos(xmax, y, (struct monst *)0, mdat)) {
  1222. X                tfoo->x = xmax;
  1223. X#ifdef MAC_MPW32
  1224. X                ( tfoo ) -> y = y ;
  1225. X                tfoo ++ ;
  1226. X#else
  1227. X                (tfoo++)->y = y;
  1228. X#endif
  1229. X                if(tfoo == &foo[15]) goto foofull;
  1230. X            }
  1231. X        range++;
  1232. X        if(range > ROWNO && range > COLNO) return FALSE;
  1233. X    } while(tfoo == foo);
  1234. Xfoofull:
  1235. X    i = rn2((int)(tfoo - foo));
  1236. X    cc->x = foo[i].x;
  1237. X    cc->y = foo[i].y;
  1238. X    return TRUE;
  1239. X}
  1240. X
  1241. Xint
  1242. Xgoodpos(x, y, mtmp, mdat)
  1243. Xint x,y;
  1244. Xstruct monst *mtmp;    /* existing monster being moved, if any */
  1245. Xstruct permonst *mdat;
  1246. X{
  1247. X    struct monst *mtmp2;
  1248. X
  1249. X    if (x < 1 || x > COLNO-2 || y < 1 || y > ROWNO-2 || MON_AT(x, y))
  1250. X        return 0;
  1251. X
  1252. X    /* in many cases, we're trying to create a new monster, which
  1253. X     * can't go on top of the player or any existing monster.
  1254. X     * however, occasionally we are relocating engravings or objects,
  1255. X     * which could be colocated and thus get restricted a bit too much.
  1256. X     * oh well.
  1257. X     */
  1258. X    if (x == u.ux && y == u.uy) return 0;
  1259. X    if ((mtmp2 = m_at(x, y)) && mtmp != mtmp2) return 0;
  1260. X
  1261. X    if (mdat) {
  1262. X        if (IS_POOL(levl[x][y].typ))
  1263. X        if (mdat == &playermon &&
  1264. X            (HLevitation || Wwalking || Magical_breathing))
  1265. X            return 1;
  1266. X        else    return (is_flyer(mdat) || is_swimmer(mdat));
  1267. X        if (levl[x][y].typ == LAVAPOOL)
  1268. X        if (mdat == &playermon && (HLevitation))
  1269. X            return 1;
  1270. X        else return
  1271. X            (is_flyer(mdat) || (mdat == &mons[PM_FIRE_ELEMENTAL]));
  1272. X        if (passes_walls(mdat)) return 1;
  1273. X    }
  1274. X    if (!ACCESSIBLE(levl[x][y].typ)) return 0;
  1275. X    if (closed_door(x, y) && (!mdat || !amorphous(mdat)))
  1276. X        return 0;
  1277. X    if (sobj_at(BOULDER, x, y) && (!mdat || !throws_rocks(mdat)))
  1278. X        return 0;
  1279. X    return 1;
  1280. X}
  1281. X
  1282. X#endif /* OVL1 */
  1283. X#ifdef OVLB
  1284. X
  1285. X/*
  1286. X * rloc_to()
  1287. X *
  1288. X * Pulls a monster from its current position and places a monster at
  1289. X * a new x and y.  If oldx is 0, then the monster was not in the levels.monsters
  1290. X * array.  However, if oldx is 0, oldy may still have a value because mtmp is a
  1291. X * migrating_mon.  Worm tails are always placed randomly around the head of
  1292. X * the worm.
  1293. X */
  1294. X
  1295. Xvoid
  1296. Xrloc_to(mtmp, x, y)
  1297. X    struct monst *mtmp;
  1298. X    register int x, y;
  1299. X{
  1300. X    register int oldx = mtmp->mx, oldy = mtmp->my;
  1301. X
  1302. X    if(x == mtmp->mx && y == mtmp->my) /* that was easy */
  1303. X        return;
  1304. X
  1305. X    if (oldx) {                /* "pick up" monster */
  1306. X        if(mtmp->wormno)
  1307. X        remove_worm(mtmp);
  1308. X        else {
  1309. X        remove_monster(oldx, oldy);
  1310. X        newsym(oldx, oldy);        /* update old location */
  1311. X        }
  1312. X    }
  1313. X
  1314. X    place_monster(mtmp, x, y);        /* put monster down */
  1315. X
  1316. X    if(mtmp->wormno)            /* now put down tail */
  1317. X        place_worm_tail_randomly(mtmp, x, y);
  1318. X
  1319. X    if(u.ustuck == mtmp){
  1320. X        if(u.uswallow) {
  1321. X            u.ux = x;
  1322. X            u.uy = y;
  1323. X            docrt();
  1324. X        } else    u.ustuck = 0;
  1325. X    }
  1326. X
  1327. X    newsym(x, y);                /* update new location */
  1328. X    set_apparxy(mtmp);            /* orient monster */
  1329. X}
  1330. X
  1331. X#endif /* OVLB */
  1332. X#ifdef OVL2
  1333. X
  1334. Xvoid
  1335. Xrloc(mtmp)
  1336. X    struct monst *mtmp;
  1337. X{
  1338. X    register int x = xupstair, y = yupstair, trycount;
  1339. X
  1340. X    /* if the wiz teleports away to heal, try the up staircase,
  1341. X       to block the player's escaping before he's healed */
  1342. X    if (!mtmp->iswiz || !goodpos(x, y, mtmp, mtmp->data)) {
  1343. X        trycount = 0;
  1344. X        do {
  1345. X        x = rn1(COLNO-3,2);
  1346. X        y = rn2(ROWNO);
  1347. X        } while(!goodpos(x,y,mtmp,mtmp->data) && ++trycount < 1000);
  1348. X        /* last ditch attempt to find a good place */
  1349. X        if (trycount >= 1000) {
  1350. X        for (x = 2; x < COLNO - 1; x++)
  1351. X            for (y = 0; y < ROWNO; y++)
  1352. X            if (goodpos(x,y,mtmp,mtmp->data))
  1353. X                goto found_atlast;
  1354. X        /* level either full of monsters or somehow faulty */
  1355. X        impossible("rloc(): couldn't relocate monster");
  1356. X        return;
  1357. X        }
  1358. X    }
  1359. Xfound_atlast:;
  1360. X    rloc_to(mtmp, x, y);
  1361. X}
  1362. X
  1363. Xvoid
  1364. Xrloc_shk(mtmp)   /* to be used when teleporting a shopkeeper */
  1365. Xstruct monst *mtmp;
  1366. X{
  1367. X    register int x, y, ox, oy, trycount;
  1368. X
  1369. X    if(!mtmp->isshk) return;
  1370. X    trycount = 0;
  1371. X    do {
  1372. X        x = rn1(COLNO-3,2);
  1373. X        y = rn2(ROWNO);
  1374. X    } while(!goodpos(x,y,mtmp,mtmp->data) && ++trycount < 1000);
  1375. X    /* last ditch attempt to find a good place */
  1376. X    if (trycount >= 1000) {
  1377. X        for (x = 2; x < COLNO - 1; x++)
  1378. X            for (y = 0; y < ROWNO; y++)
  1379. X            if (goodpos(x,y,mtmp,mtmp->data))
  1380. X                goto found_ok;
  1381. X        /* this really shouldn't happen - after all, shopkeeper's
  1382. X           original position should always be available */
  1383. X        impossible("rloc_shk(): couldn't relocate shopkeeper");
  1384. X        return;
  1385. X    }
  1386. Xfound_ok:;
  1387. X    ox = mtmp->mx;
  1388. X    oy = mtmp->my;
  1389. X    rloc_to(mtmp, x, y);
  1390. X    make_angry_shk(mtmp, ox, oy);
  1391. X}
  1392. X
  1393. X#endif /* OVL2 */
  1394. X#ifdef OVLB
  1395. X
  1396. Xvoid
  1397. Xvloc(mtmp)
  1398. Xstruct monst *mtmp;
  1399. X{
  1400. X    register struct mkroom *croom = search_special(VAULT);
  1401. X    coord c;
  1402. X
  1403. X    if(croom && somexy(croom, &c) && goodpos(c.x, c.y, mtmp, mtmp->data)) {
  1404. X        rloc_to(mtmp, c.x, c.y);
  1405. X        return;
  1406. X    }
  1407. X    rloc(mtmp);
  1408. X}
  1409. X
  1410. X#endif /* OVLB */
  1411. X#ifdef OVL0
  1412. X
  1413. Xstatic boolean
  1414. Xcmavail()    /* return TRUE if "common" monsters can be generated */
  1415. X{
  1416. X    struct permonst *ptr;
  1417. X
  1418. X    for(ptr = &mons[0]; ptr != &mons[NUMMONS]; ptr++)
  1419. X       if(!uncommon(ptr))  return TRUE;
  1420. X
  1421. X    return FALSE;
  1422. X}
  1423. X
  1424. X/*
  1425. X *    shift the probability of a monster's generation by
  1426. X *    comparing the dungeon alignment and monster alignment.
  1427. X *    return an integer in the range of 0-5.
  1428. X */
  1429. Xstatic int
  1430. Xalign_shift(ptr)
  1431. Xregister struct permonst *ptr;
  1432. X{
  1433. X    static long NEARDATA oldmoves = 0L;    /* != 1, starting value of moves */
  1434. X    static s_level NEARDATA *lev;
  1435. X    register int alshift;
  1436. X
  1437. X    if(oldmoves != moves) {
  1438. X    lev = Is_special(&u.uz);
  1439. X    oldmoves = moves;
  1440. X    }
  1441. X    switch((lev) ? lev->flags.align : dungeons[u.uz.dnum].flags.align) {
  1442. X    default:    /* just in case */
  1443. X    case AM_NONE:    alshift = 0;
  1444. X            break;
  1445. X    case AM_LAWFUL:    alshift = (ptr->maligntyp+20)/(2*ALIGNWEIGHT);
  1446. X            break;
  1447. X    case AM_NEUTRAL:    alshift = (20 - abs(ptr->maligntyp))/ALIGNWEIGHT;
  1448. X            break;
  1449. X    case AM_CHAOTIC:    alshift = (-(ptr->maligntyp-20))/(2*ALIGNWEIGHT);
  1450. X            break;
  1451. X    }
  1452. X    return alshift;
  1453. X}
  1454. X
  1455. Xstruct    permonst *
  1456. Xrndmonst()        /* select a random monster */
  1457. X{
  1458. X    register struct permonst *ptr;
  1459. X    register int i, ct;
  1460. X    register int zlevel;
  1461. X    static int NEARDATA minmlev, NEARDATA maxmlev, NEARDATA accept;
  1462. X    static long NEARDATA oldmoves = 0L;    /* != 1, starting value of moves */
  1463. X#ifdef REINCARNATION
  1464. X    static boolean NEARDATA upper;
  1465. X#endif
  1466. X    static boolean NEARDATA elemlevel;
  1467. X
  1468. X#ifdef MULDGN
  1469. X    if(u.uz.dnum == quest_dnum && (ptr = qt_montype())) return(ptr);
  1470. X#endif
  1471. X    if(oldmoves != moves) {        /* must recalculate accept */
  1472. X        oldmoves = moves;
  1473. X        zlevel = level_difficulty();
  1474. X        if(!cmavail()) {
  1475. X#ifdef DEBUG
  1476. X        pline("cmavail() fails!");
  1477. X#endif
  1478. X        return((struct permonst *) 0);
  1479. X        }
  1480. X
  1481. X        /* determine the level of the weakest monster to make. */
  1482. X        minmlev = zlevel/6;
  1483. X        /* determine the level of the strongest monster to make. */
  1484. X        maxmlev = (zlevel + u.ulevel)>>1;
  1485. X#ifdef REINCARNATION
  1486. X        upper = Is_rogue_level(&u.uz);
  1487. X#endif
  1488. X        elemlevel = In_endgame(&u.uz) && !Is_astralevel(&u.uz);
  1489. X/*
  1490. X *    Find out how many monsters exist in the range we have selected.
  1491. X */
  1492. X        accept = 0;
  1493. X        for(ct = 0, ptr = &mons[0] ; ptr != &mons[NUMMONS]; ct++, ptr++) {
  1494. X        if(tooweak(ct, minmlev) || toostrong(ct, maxmlev))
  1495. X            continue;
  1496. X#ifdef REINCARNATION
  1497. X        if(upper && !isupper(def_monsyms[ptr->mlet])) continue;
  1498. X#endif
  1499. X        if(elemlevel && wrong_elem_type(ptr)) continue;
  1500. X        if(uncommon(ptr)) continue;
  1501. X        accept += (ptr->geno & G_FREQ);
  1502. X        accept += align_shift(ptr);
  1503. X        }
  1504. X    }
  1505. X
  1506. X    if(!accept) {
  1507. X#ifdef DEBUG
  1508. X        pline("no accept!");
  1509. X#endif
  1510. X        return((struct permonst *) 0);
  1511. X    }
  1512. X/*
  1513. X *    Now, select a monster at random.
  1514. X */
  1515. X    ct = rnd(accept);
  1516. X    for(i = 0,ptr = &mons[0]; ptr != &mons[NUMMONS] && ct > 0; i++,ptr++) {
  1517. X        if(tooweak(i, minmlev) || toostrong(i, maxmlev))
  1518. X            continue;
  1519. X#ifdef REINCARNATION
  1520. X        if(upper & !isupper(def_monsyms[ptr->mlet])) continue;
  1521. X#endif
  1522. X        if(elemlevel && wrong_elem_type(ptr)) continue;
  1523. X        if(uncommon(ptr)) continue;
  1524. X        ct -= (ptr->geno & G_FREQ);
  1525. X        ct -= align_shift(ptr);
  1526. X    }
  1527. X    if(ct > 0) {
  1528. X#ifdef DEBUG
  1529. X        pline("no count!");
  1530. X#endif
  1531. X        return((struct permonst *) 0);
  1532. X    }
  1533. X    return(--ptr);    /* subtract extra increment */
  1534. X}
  1535. X
  1536. X#endif /* OVL0 */
  1537. X#ifdef OVL1
  1538. X
  1539. X/*    The routine below is used to make one of the multiple types
  1540. X *    of a given monster class.  The second parameter specifies a
  1541. X *    special casing bit mask to allow any of the normal genesis
  1542. X *    masks to be deactivated.  Returns 0 if no monsters
  1543. X *    in that class can be made.
  1544. X */
  1545. X
  1546. Xstruct permonst *
  1547. Xmkclass(class,spc)
  1548. Xchar    class;
  1549. Xint    spc;
  1550. X{
  1551. X    register int    first, last, num = 0;
  1552. X    int maxmlev, mask = (G_GENOD | G_EXTINCT | G_NOGEN | G_UNIQ) & ~spc;
  1553. X
  1554. X    maxmlev = level_difficulty() >> 1;
  1555. X    if(class < 1 || class >= MAXMCLASSES) {
  1556. X        impossible("mkclass called with bad class!");
  1557. X        return((struct permonst *) 0);
  1558. X    }
  1559. X/*    Assumption #1:    monsters of a given class are contiguous in the
  1560. X *            mons[] array.
  1561. X */
  1562. X    for(first = 0; first < NUMMONS; first++)
  1563. X        if (mons[first].mlet == class) break;
  1564. X    if (first == NUMMONS) return((struct permonst *) 0);
  1565. X
  1566. X    for(last = first; last < NUMMONS && mons[last].mlet == class; last++)
  1567. X        if(!(mons[last].geno & mask)) {
  1568. X        /* consider it */
  1569. X        if(num && toostrong(last, maxmlev) && rn2(2)) break;
  1570. X        num += mons[last].geno & G_FREQ;
  1571. X        }
  1572. X
  1573. X    if(!num) return((struct permonst *) 0);
  1574. X
  1575. X/*    Assumption #2:    monsters of a given class are presented in ascending
  1576. X *            order of strength.
  1577. X */
  1578. X    for(num = rnd(num); num > 0; first++)
  1579. X        if(!(mons[first].geno & mask)) {
  1580. X        /* skew towards lower value monsters at lower exp. levels */
  1581. X        if(adj_lev(&mons[first]) > (u.ulevel*2)) num--;
  1582. X        num -= mons[first].geno & G_FREQ;
  1583. X        }
  1584. X    first--; /* correct an off-by-one error */
  1585. X
  1586. X    return(&mons[first]);
  1587. X}
  1588. X
  1589. Xint
  1590. Xadj_lev(ptr)    /* adjust strength of monsters based on u.uz and u.ulevel */
  1591. Xregister struct permonst *ptr;
  1592. X{
  1593. X    int    tmp, tmp2;
  1594. X
  1595. X    if((tmp = ptr->mlevel) > 49) return(50); /* "special" demons/devils */
  1596. X    tmp2 = (level_difficulty() - tmp);
  1597. X    if(tmp2 < 0) tmp--;        /* if mlevel > u.uz decrement tmp */
  1598. X    else tmp += (tmp2 / 5);        /* else increment 1 per five diff */
  1599. X
  1600. X    tmp2 = (u.ulevel - ptr->mlevel);    /* adjust vs. the player */
  1601. X    if(tmp2 > 0) tmp += (tmp2 / 4);        /* level as well */
  1602. X
  1603. X    tmp2 = (3 * ((int) ptr->mlevel))/ 2;    /* crude upper limit */
  1604. X    return((tmp > tmp2) ? tmp2 : (tmp > 0 ? tmp : 0)); /* 0 lower limit */
  1605. X}
  1606. X
  1607. X#endif /* OVL1 */
  1608. X#ifdef OVLB
  1609. X
  1610. Xstruct permonst *
  1611. Xgrow_up(mtmp,victim)        /* mon mtmp "grows up" to a bigger version. */
  1612. Xregister struct monst *mtmp;
  1613. Xregister struct monst *victim;
  1614. X{
  1615. X    register int newtype;
  1616. X    register struct permonst *ptr = mtmp->data;
  1617. X
  1618. X    if (ptr->mlevel >= 50 || is_golem(ptr) || is_home_elemental(ptr)
  1619. X        || is_mplayer(ptr))
  1620. X        /* doesn't grow up, has strange hp calculation so might be
  1621. X         * weakened by tests below */
  1622. X        return ptr;
  1623. X
  1624. X    if (victim) {
  1625. X        mtmp->mhpmax = mtmp->mhpmax + (1 + rn2((int)victim->m_lev+1));
  1626. X        if (mtmp->mhpmax <= (8 * (int)mtmp->m_lev)
  1627. X            || (mtmp->m_lev == 0 && mtmp->mhpmax <= 4))
  1628. X        /* not ready to grow up */
  1629. X        return ptr;
  1630. X    }
  1631. X#ifdef MUSE
  1632. X    /* else it's a gain level potion; always go up a level */
  1633. X    else {
  1634. X        int foo=rnd(8);
  1635. X
  1636. X        mtmp->mhp += foo;
  1637. X        mtmp->mhpmax += foo;
  1638. X    }
  1639. X#endif
  1640. X
  1641. X    newtype = little_to_big(monsndx(ptr));
  1642. X    if ((int) (++mtmp->m_lev) >= mons[newtype].mlevel
  1643. X                    && newtype != monsndx(ptr)) {
  1644. X        if (mons[newtype].geno & G_GENOD) { /* allow G_EXTINCT */
  1645. X            pline("As %s grows up into %s, %s dies!",
  1646. X                mon_nam(mtmp),
  1647. X                an(mons[newtype].mname),
  1648. X                mon_nam(mtmp));
  1649. X            mondied(mtmp);
  1650. X            return (struct permonst *)0;
  1651. X        }
  1652. X        mtmp->data = &mons[newtype];
  1653. X        mtmp->m_lev = mons[newtype].mlevel;
  1654. X    }
  1655. X    if (newtype == monsndx(ptr) && victim &&
  1656. X        (int) mtmp->m_lev > (3*(int)mtmp->data->mlevel) / 2)
  1657. X        mtmp->m_lev = (3*(int)mtmp->data->mlevel) / 2;
  1658. X    if (mtmp->m_lev > 0) {
  1659. X        if (mtmp->mhp > (int) mtmp->m_lev * 8)
  1660. X        mtmp->mhp = mtmp->m_lev * 8;
  1661. X        if (mtmp->mhpmax > (int) mtmp->m_lev * 8)
  1662. X        mtmp->mhpmax = mtmp->m_lev * 8;
  1663. X    }
  1664. X    return(mtmp->data);
  1665. X}
  1666. X
  1667. X#endif /* OVLB */
  1668. X#ifdef OVL1
  1669. X
  1670. Xint
  1671. Xmongets(mtmp, otyp)
  1672. Xregister struct monst *mtmp;
  1673. Xregister int otyp;
  1674. X{
  1675. X    register struct obj *otmp;
  1676. X
  1677. X#ifdef MUSE
  1678. X    if (!otyp) return 0;
  1679. X#endif
  1680. X    if((otmp = (otyp) ? mksobj(otyp,TRUE,FALSE) : mkobj((char)otyp,FALSE))) {
  1681. X        if (mtmp->data->mlet == S_DEMON) {
  1682. X        /* demons always get cursed objects */
  1683. X        curse(otmp);
  1684. X        } else if(is_lminion(mtmp->data)) {
  1685. X        /* lawful minions don't get cursed, bad, or rusting objects */
  1686. X        otmp->cursed = FALSE;
  1687. X        if(otmp->spe < 0) otmp->spe = 0;
  1688. X        otmp->oerodeproof = TRUE;
  1689. X        } else if(is_mplayer(mtmp->data) && is_sword(otmp))
  1690. X            otmp->spe = (3 + rn2(4));
  1691. X        if(otmp->otyp == CANDELABRUM_OF_INVOCATION) {
  1692. X        otmp->spe = 0;
  1693. X        otmp->age = 0L;
  1694. X        otmp->lamplit = FALSE;
  1695. X        otmp->blessed = otmp->cursed = FALSE;
  1696. X        }
  1697. X        mpickobj(mtmp, otmp);
  1698. X        return(otmp->spe);
  1699. X    } else return(0);
  1700. X}
  1701. X
  1702. X#endif /* OVL1 */
  1703. X#ifdef OVLB
  1704. X
  1705. Xint
  1706. Xgolemhp(type)
  1707. Xint type;
  1708. X{
  1709. X    switch(type) {
  1710. X        case PM_STRAW_GOLEM: return 20;
  1711. X        case PM_ROPE_GOLEM: return 30;
  1712. X        case PM_LEATHER_GOLEM: return 40;
  1713. X        case PM_WOOD_GOLEM: return 50;
  1714. X        case PM_FLESH_GOLEM: return 40;
  1715. X        case PM_CLAY_GOLEM: return 50;
  1716. X        case PM_STONE_GOLEM: return 60;
  1717. X        case PM_IRON_GOLEM: return 80;
  1718. X        default: return 0;
  1719. X    }
  1720. X}
  1721. X
  1722. X#endif /* OVLB */
  1723. X#ifdef OVL1
  1724. X
  1725. X/*
  1726. X *    Alignment vs. yours determines monster's attitude to you.
  1727. X *    ( some "animal" types are co-aligned, but also hungry )
  1728. X */
  1729. Xboolean
  1730. Xpeace_minded(ptr)
  1731. Xregister struct permonst *ptr;
  1732. X{
  1733. X    aligntyp mal = ptr->maligntyp, ual = u.ualign.type;
  1734. X
  1735. X    if (always_peaceful(ptr)) return TRUE;
  1736. X    if (always_hostile(ptr)) return FALSE;
  1737. X#ifdef MULDGN
  1738. X    if (ptr->msound == MS_LEADER || ptr->msound == MS_GUARDIAN)
  1739. X        return TRUE;
  1740. X    if (ptr->msound == MS_NEMESIS)    return FALSE;
  1741. X#endif
  1742. X
  1743. X    /* the monster is hostile if its alignment is different from the
  1744. X     * player's */
  1745. X    if (sgn(mal) != sgn(ual)) return FALSE;
  1746. X
  1747. X    /* Negative monster hostile to player with Amulet. */
  1748. X    if (mal < A_NEUTRAL && u.uhave.amulet) return FALSE;
  1749. X
  1750. X    /* minions are hostile to players that have strayed at all */
  1751. X    if (is_minion(ptr)) return(u.ualign.record >= 0);
  1752. X
  1753. X    /* Last case:  a chance of a co-aligned monster being
  1754. X     * hostile.  This chance is greater if the player has strayed
  1755. X     * (u.ualign.record negative) or the monster is not strongly aligned.
  1756. X     */
  1757. X    return !!rn2(16 + (u.ualign.record < -15 ? -15 : u.ualign.record)) &&
  1758. X        !!rn2(2 + abs(mal));
  1759. X}
  1760. X
  1761. X/* Set malign to have the proper effect on player alignment if monster is
  1762. X * killed.  Negative numbers mean it's bad to kill this monster; positive
  1763. X * numbers mean it's good.  Since there are more hostile monsters than
  1764. X * peaceful monsters, the penalty for killing a peaceful monster should be
  1765. X * greater than the bonus for killing a hostile monster to maintain balance.
  1766. X * Rules:
  1767. X *   it's bad to kill peaceful monsters, potentially worse to kill always-
  1768. X *    peaceful monsters
  1769. X *   it's never bad to kill a hostile monster, although it may not be good
  1770. X */
  1771. Xvoid
  1772. Xset_malign(mtmp)
  1773. Xstruct monst *mtmp;
  1774. X{
  1775. X    schar mal = mtmp->data->maligntyp;
  1776. X    boolean coaligned;
  1777. X
  1778. X    if (mtmp->ispriest || mtmp->isminion) {
  1779. X        /* some monsters have individual alignments; check them */
  1780. X        if (mtmp->ispriest)
  1781. X            mal = EPRI(mtmp)->shralign;
  1782. X        else if (mtmp->isminion)
  1783. X            mal = EMIN(mtmp)->min_align;
  1784. X        /* unless alignment is none, set mal to -5,0,5 */
  1785. X        /* (see align.h for valid aligntyp values)     */
  1786. X        if(mal != A_NONE)
  1787. X            mal *= 5;
  1788. X    }
  1789. X
  1790. X    coaligned = (sgn(mal) == sgn(u.ualign.type));
  1791. X#ifdef MULDGN
  1792. X    if (mtmp->data->msound == MS_LEADER) {
  1793. X        mtmp->malign = -20;
  1794. X    } else
  1795. X#endif
  1796. X          if (mal == A_NONE) {
  1797. X        if (mtmp->mpeaceful)
  1798. X            mtmp->malign = 0;
  1799. X        else
  1800. X            mtmp->malign = 20;    /* really hostile */
  1801. X    } else if (always_peaceful(mtmp->data)) {
  1802. X        if (mtmp->mpeaceful)
  1803. X            mtmp->malign = -3*max(5,abs(mal));
  1804. X        else
  1805. X            mtmp->malign = 3*max(5,abs(mal)); /* renegade */
  1806. X    } else if (always_hostile(mtmp->data)) {
  1807. X        if (coaligned)
  1808. X            mtmp->malign = 0;
  1809. X        else
  1810. X            mtmp->malign = max(5,abs(mal));
  1811. X    } else if (coaligned) {
  1812. X        if (mtmp->mpeaceful)
  1813. X            mtmp->malign = -3*max(3,abs(mal));
  1814. X        else    /* renegade */
  1815. X            mtmp->malign = max(3,abs(mal));
  1816. X    } else    /* not coaligned and therefore hostile */
  1817. X        mtmp->malign = abs(mal);
  1818. X}
  1819. X
  1820. X#endif /* OVL1 */
  1821. X#ifdef OVLB
  1822. X
  1823. Xstatic char NEARDATA syms[] = {
  1824. X    MAXOCLASSES, MAXOCLASSES+1, RING_CLASS, WAND_CLASS, WEAPON_CLASS,
  1825. X    FOOD_CLASS, GOLD_CLASS, SCROLL_CLASS, POTION_CLASS, ARMOR_CLASS,
  1826. X    AMULET_CLASS, TOOL_CLASS, ROCK_CLASS, GEM_CLASS, SPBOOK_CLASS,
  1827. X    S_MIMIC_DEF, S_MIMIC_DEF, S_MIMIC_DEF,
  1828. X};
  1829. X
  1830. Xvoid
  1831. Xset_mimic_sym(mtmp)        /* KAA, modified by ERS */
  1832. Xregister struct monst *mtmp;
  1833. X{
  1834. X    int typ, roomno, rt;
  1835. X    unsigned appear, ap_type;
  1836. X    int s_sym;
  1837. X    struct obj *otmp;
  1838. X    int mx, my;
  1839. X
  1840. X    if (!mtmp) return;
  1841. X    mx = mtmp->mx; my = mtmp->my;
  1842. X    typ = levl[mx][my].typ;
  1843. X                    /* only valid for INSIDE of room */
  1844. X    roomno = levl[mx][my].roomno - ROOMOFFSET;
  1845. X    if (roomno >= 0)
  1846. X        rt = rooms[roomno].rtype;
  1847. X#ifdef SPECIALIZATION
  1848. X    else if (IS_ROOM(typ))
  1849. X        rt = OROOM,  roomno = 0;
  1850. X#endif
  1851. X    else    rt = 0;    /* roomno < 0 case for GCC_WARN */
  1852. X
  1853. X    if (OBJ_AT(mx, my)) {
  1854. X        ap_type = M_AP_OBJECT;
  1855. X        appear = level.objects[mx][my]->otyp;
  1856. X    } else if (IS_DOOR(typ) || IS_WALL(typ) ||
  1857. X           typ == SDOOR || typ == SCORR) {
  1858. X        ap_type = M_AP_FURNITURE;
  1859. X        /*
  1860. X         *  If there is a wall to the left that connects to this
  1861. X         *  location, then the mimic mimics a horizontal closed door.
  1862. X         *  This does not allow doors to be in corners of rooms.
  1863. X         */
  1864. X        if (mx != 0 &&
  1865. X            (levl[mx-1][my].typ == HWALL    ||
  1866. X             levl[mx-1][my].typ == TLCORNER ||
  1867. X             levl[mx-1][my].typ == TRWALL   ||
  1868. X             levl[mx-1][my].typ == BLCORNER ||
  1869. X             levl[mx-1][my].typ == TDWALL   ||
  1870. X             levl[mx-1][my].typ == CROSSWALL||
  1871. X             levl[mx-1][my].typ == TUWALL    ))
  1872. X            appear = S_hcdoor;
  1873. X        else
  1874. X            appear = S_vcdoor;
  1875. X
  1876. X        if(!mtmp->minvis || See_invisible)
  1877. X            block_point(mx,my);    /* vision */
  1878. X    } else if (level.flags.is_maze_lev && rn2(2)) {
  1879. X        ap_type = M_AP_OBJECT;
  1880. X        appear = STATUE;
  1881. X    } else if (roomno < 0) {
  1882. X        ap_type = M_AP_OBJECT;
  1883. X        appear = BOULDER;
  1884. X        if(!mtmp->minvis || See_invisible)
  1885. X            block_point(mx,my);    /* vision */
  1886. X    } else if (rt == ZOO || rt == VAULT) {
  1887. X        ap_type = M_AP_OBJECT;
  1888. X        appear = GOLD_PIECE;
  1889. X    } else if (rt == DELPHI) {
  1890. X        if (rn2(2)) {
  1891. X            ap_type = M_AP_OBJECT;
  1892. X            appear = STATUE;
  1893. X        } else {
  1894. X            ap_type = M_AP_FURNITURE;
  1895. X            appear = S_fountain;
  1896. X        }
  1897. X    } else if (rt == TEMPLE) {
  1898. X        ap_type = M_AP_FURNITURE;
  1899. X        appear = S_altar;
  1900. X    /*
  1901. X     * We won't bother with beehives, morgues, barracks, throne rooms
  1902. X     * since they shouldn't contain too many mimics anyway...
  1903. X     */
  1904. X    } else if (rt >= SHOPBASE) {
  1905. X        s_sym = get_shop_item(rt - SHOPBASE);
  1906. X        if (s_sym < 0) {
  1907. X            ap_type = M_AP_OBJECT;
  1908. X            appear = -s_sym;
  1909. X        } else {
  1910. X            if (s_sym == RANDOM_CLASS)
  1911. X                s_sym = syms[rn2((int)sizeof(syms)-2) + 2];
  1912. X            goto assign_sym;
  1913. X        }
  1914. X    } else {
  1915. X        s_sym = syms[rn2((int)sizeof(syms))];
  1916. Xassign_sym:
  1917. X        if (s_sym >= MAXOCLASSES) {
  1918. X            ap_type = M_AP_FURNITURE;
  1919. X            appear = s_sym == MAXOCLASSES ? S_upstair : S_dnstair;
  1920. X        } else if (s_sym == GOLD_CLASS) {
  1921. X            ap_type = M_AP_OBJECT;
  1922. X            appear = GOLD_PIECE;
  1923. X        } else {
  1924. X            ap_type = M_AP_OBJECT;
  1925. X            if (s_sym == S_MIMIC_DEF) {
  1926. X                appear = STRANGE_OBJECT;
  1927. X            } else {
  1928. X                otmp = mkobj( (char) s_sym, FALSE );
  1929. X                appear = otmp->otyp;
  1930. X                /* make sure container contents are free'ed */
  1931. X                obfree(otmp, (struct obj *) 0);
  1932. X            }
  1933. X        }
  1934. X    }
  1935. X    mtmp->m_ap_type = ap_type;
  1936. X    mtmp->mappearance = appear;
  1937. X}
  1938. X
  1939. X#endif /* OVLB */
  1940. X
  1941. X/*makemon.c*/
  1942. END_OF_FILE
  1943. if test 40817 -ne `wc -c <'src/makemon.c'`; then
  1944.     echo shar: \"'src/makemon.c'\" unpacked with wrong size!
  1945. fi
  1946. # end of 'src/makemon.c'
  1947. fi
  1948. echo shar: End of archive 31 \(of 108\).
  1949. cp /dev/null ark31isdone
  1950. MISSING=""
  1951. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \
  1952. 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \
  1953. 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \
  1954. 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 \
  1955. 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 \
  1956. 101 102 103 104 105 106 107 108 ; do
  1957.     if test ! -f ark${I}isdone ; then
  1958.     MISSING="${MISSING} ${I}"
  1959.     fi
  1960. done
  1961. if test "${MISSING}" = "" ; then
  1962.     echo You have unpacked all 108 archives.
  1963.     echo "Now execute 'rebuild.sh'"
  1964.     rm -f ark10[0-8]isdone ark[1-9]isdone ark[1-9][0-9]isdone
  1965. else
  1966.     echo You still need to unpack the following archives:
  1967.     echo "        " ${MISSING}
  1968. fi
  1969. ##  End of shell archive.
  1970. exit 0
  1971.