Source:NetHack 5.0.0/src/mplayer.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to mplayer.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/mplayer.c#line12]], for example.

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

1. /* NetHack 5.0	mplayer.c	$NHDT-Date: 1596498188 2020/08/03 23:43:08 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.30 $ */
2. /*      Copyright (c) Izchak Miller, 1992.                        */
3. /* NetHack may be freely redistributed.  See license for details. */
4. 
5. #include "hack.h"
6. 
7. staticfn const char *dev_name(void);
8. staticfn void get_mplname(struct monst *, char *);
9. staticfn void mk_mplayer_armor(struct monst *, short);
10. 
11. /* These are the names of those who
12.  * contributed to the development of NetHack 3.2/3.3/3.4/3.6.
13.  *
14.  * Keep in alphabetical order within teams.
15.  * Same first name is entered once within each team.
16.  */
17. static const char *const developers[] = {
18.     /* devteam */
19.     "Alex",    "Dave",   "Dean",    "Derek",   "Eric",    "Izchak",
20.     "Janet",   "Jessie", "Ken",     "Kevin",   "Michael", "Mike",
21.     "Pasi",    "Pat",    "Patric",  "Paul",    "Sean",    "Steve",
22.     "Timo",    "Warwick",
23.     /* PC team */
24.     "Bill",    "Eric",   "Keizo",   "Ken",    "Kevin",    "Michael",
25.     "Mike",    "Paul",   "Stephen", "Steve",  "Timo",     "Yitzhak",
26.     /* Amiga team */
27.     "Andy",    "Gregg",  "Janne",   "Keni",   "Mike",     "Olaf",
28.     "Richard",
29.     /* Mac team */
30.     "Andy",    "Chris",  "Dean",    "Jon",    "Jonathan", "Kevin",
31.     "Wang",
32.     /* Atari team */
33.     "Eric",    "Marvin", "Warwick",
34.     /* NT team */
35.     "Alex",    "Dion",   "Michael",
36.     /* OS/2 team */
37.     "Helge",   "Ron",    "Timo",
38.     /* VMS team */
39.     "Joshua",  "Pat",    ""
40. };
41. 
42. /* return a randomly chosen developer name */
43. staticfn const char *
44. dev_name(void)
45. {
46.     int i, m = 0, n = SIZE(developers);
47.     struct monst *mtmp;
48.     boolean match;
49. 
50.     do {
51.         match = FALSE;
52.         i = rn2(n);
53.         for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
54.             if (!is_mplayer(mtmp->data))
55.                 continue;
56.             if (!strncmp(developers[i],
57.                          (has_mgivenname(mtmp)) ? MGIVENNAME(mtmp) : "",
58.                          strlen(developers[i]))) {
59.                 match = TRUE;
60.                 break;
61.             }
62.         }
63.         m++;
64.     } while (match && m < 100); /* m for insurance */
65. 
66.     if (match)
67.         return (const char *) 0;
68.     return (developers[i]);
69. }
70. 
71. staticfn void
72. get_mplname(struct monst *mtmp, char *nam)
73. {
74.     boolean fmlkind = is_female(mtmp->data);
75.     const char *devnam;
76. 
77.     devnam = dev_name();
78.     if (!devnam)
79.         Strcpy(nam, fmlkind ? "Eve" : "Adam");
80.     else if (fmlkind && !!strcmp(devnam, "Janet"))
81.         Strcpy(nam, rn2(2) ? "Maud" : "Eve");
82.     else
83.         Strcpy(nam, devnam);
84. 
85.     if (fmlkind || !strcmp(nam, "Janet"))
86.         mtmp->female = 1;
87.     else
88.         mtmp->female = 0;
89.     Strcat(nam, " the ");
90.     Strcat(nam, rank_of((int) mtmp->m_lev, monsndx(mtmp->data),
91.                         (boolean) mtmp->female));
92. }
93. 
94. staticfn void
95. mk_mplayer_armor(struct monst *mon, short typ)
96. {
97.     struct obj *obj;
98. 
99.     if (typ == STRANGE_OBJECT)
100.         return;
101.     obj = mksobj(typ, FALSE, FALSE);
102.     obj->oeroded = obj->oeroded2 = 0;
103.     if (!rn2(3))
104.         obj->oerodeproof = 1;
105.     if (!rn2(3))
106.         curse(obj);
107.     if (!rn2(3))
108.         bless(obj);
109.     /* Most players who get to the endgame who have cursed equipment
110.      * have it because the wizard or other monsters cursed it, so its
111.      * chances of having plusses is the same as usual....
112.      */
113.     obj->spe = rn2(10) ? (rn2(3) ? rn2(5) : rn1(4, 4)) : -rnd(3);
114.     (void) mpickobj(mon, obj);
115. }
116. 
117. struct monst *
118. mk_mplayer(struct permonst *ptr, coordxy x, coordxy y, boolean special)
119. {
120.     struct monst *mtmp;
121.     char nam[PL_NSIZ];
122. 
123.     if (!is_mplayer(ptr))
124.         return ((struct monst *) 0);
125. 
126.     if (MON_AT(x, y))
127.         (void) rloc(m_at(x, y), RLOC_ERR|RLOC_NOMSG); /* insurance */
128. 
129.     if (!In_endgame(&u.uz))
130.         special = FALSE;
131. 
132.     if ((mtmp = makemon(ptr, x, y, special ? MM_NOMSG : NO_MM_FLAGS)) != 0) {
133.         short weapon, armor, cloak, helm, shield;
134.         int quan;
135.         struct obj *otmp;
136. 
137.         mtmp->m_lev = (special ? rn1(16, 15) : rnd(16));
138.         mtmp->mhp = mtmp->mhpmax = d((int) mtmp->m_lev, 10)
139.                                    + (special ? (30 + rnd(30)) : 30);
140.         if (special) {
141.             get_mplname(mtmp, nam);
142.             mtmp = christen_monst(mtmp, nam);
143.             /* that's why they are "stuck" in the endgame :-) */
144.             (void) mongets(mtmp, FAKE_AMULET_OF_YENDOR);
145.         }
146.         mtmp->mpeaceful = 0;
147.         set_malign(mtmp); /* peaceful may have changed again */
148. 
149.         /* default equipment; much of it will be overridden below */
150.         weapon = !rn2(2) ? LONG_SWORD : rnd_class(SPEAR, BULLWHIP);
151.         armor  = rnd_class(GRAY_DRAGON_SCALE_MAIL, YELLOW_DRAGON_SCALE_MAIL);
152.         cloak  = !rn2(8) ? STRANGE_OBJECT
153.                          : rnd_class(OILSKIN_CLOAK, CLOAK_OF_DISPLACEMENT);
154.         helm   = !rn2(8) ? STRANGE_OBJECT
155.                          : rnd_class(ELVEN_LEATHER_HELM, HELM_OF_TELEPATHY);
156.         shield = !rn2(8) ? STRANGE_OBJECT
157.                          : rnd_class(ELVEN_SHIELD, SHIELD_OF_REFLECTION);
158. 
159.         switch (monsndx(ptr)) {
160.         case PM_ARCHEOLOGIST:
161.             if (rn2(2))
162.                 weapon = BULLWHIP;
163.             break;
164.         case PM_BARBARIAN:
165.             if (rn2(2)) {
166.                 weapon = rn2(2) ? TWO_HANDED_SWORD : BATTLE_AXE;
167.                 shield = STRANGE_OBJECT;
168.             }
169.             if (rn2(2))
170.                 armor = rnd_class(PLATE_MAIL, CHAIN_MAIL);
171.             if (helm == HELM_OF_BRILLIANCE)
172.                 helm = STRANGE_OBJECT;
173.             break;
174.         case PM_CAVE_DWELLER:
175.             if (rn2(4))
176.                 weapon = MACE;
177.             else if (rn2(2))
178.                 weapon = CLUB;
179.             if (helm == HELM_OF_BRILLIANCE)
180.                 helm = STRANGE_OBJECT;
181.             break;
182.         case PM_HEALER:
183.             if (rn2(4))
184.                 weapon = QUARTERSTAFF;
185.             else if (rn2(2))
186.                 weapon = rn2(2) ? UNICORN_HORN : SCALPEL;
187.             if (rn2(4))
188.                 helm = rn2(2) ? HELM_OF_BRILLIANCE : HELM_OF_TELEPATHY;
189.             if (rn2(2))
190.                 shield = STRANGE_OBJECT;
191.             break;
192.         case PM_KNIGHT:
193.             if (rn2(4))
194.                 weapon = LONG_SWORD;
195.             if (rn2(2))
196.                 armor = rnd_class(PLATE_MAIL, CHAIN_MAIL);
197.             break;
198.         case PM_MONK:
199.             weapon = !rn2(3) ? SHURIKEN : STRANGE_OBJECT;
200.             armor = STRANGE_OBJECT;
201.             cloak = ROBE;
202.             if (rn2(2))
203.                 shield = STRANGE_OBJECT;
204.             break;
205.         case PM_CLERIC:
206.             if (rn2(2))
207.                 weapon = MACE;
208.             if (rn2(2))
209.                 armor = rnd_class(PLATE_MAIL, CHAIN_MAIL);
210.             if (rn2(4))
211.                 cloak = ROBE;
212.             if (rn2(4))
213.                 helm = rn2(2) ? HELM_OF_BRILLIANCE : HELM_OF_TELEPATHY;
214.             if (rn2(2))
215.                 shield = STRANGE_OBJECT;
216.             break;
217.         case PM_RANGER:
218.             if (rn2(2))
219.                 weapon = ELVEN_DAGGER;
220.             break;
221.         case PM_ROGUE:
222.             if (rn2(2))
223.                 weapon = rn2(2) ? SHORT_SWORD : ORCISH_DAGGER;
224.             break;
225.         case PM_SAMURAI:
226.             if (rn2(2))
227.                 weapon = KATANA;
228.             break;
229.         case PM_TOURIST:
230.             /* Defaults are just fine */
231.             break;
232.         case PM_VALKYRIE:
233.             if (rn2(2))
234.                 weapon = WAR_HAMMER;
235.             if (rn2(2))
236.                 armor = rnd_class(PLATE_MAIL, CHAIN_MAIL);
237.             break;
238.         case PM_WIZARD:
239.             if (rn2(4))
240.                 weapon = rn2(2) ? QUARTERSTAFF : ATHAME;
241.             if (rn2(2)) {
242.                 armor = rn2(2) ? BLACK_DRAGON_SCALE_MAIL
243.                                : SILVER_DRAGON_SCALE_MAIL;
244.                 cloak = CLOAK_OF_MAGIC_RESISTANCE;
245.             }
246.             if (rn2(4))
247.                 helm = HELM_OF_BRILLIANCE;
248.             shield = STRANGE_OBJECT;
249.             break;
250.         default:
251.             impossible("bad mplayer monster");
252.             weapon = 0;
253.             break;
254.         }
255. 
256.         if (weapon != STRANGE_OBJECT) {
257.             otmp = mksobj(weapon, TRUE, FALSE);
258.             otmp->oeroded = otmp->oeroded2 = 0;
259.             otmp->spe = (special ? rn1(5, 4) : rn2(4));
260.             if (!rn2(3))
261.                 otmp->oerodeproof = 1;
262.             else if (!rn2(2))
263.                 otmp->greased = 1;
264.             /* mk_artifact() with otmp and A_NONE will never return NULL */
265.             if (special && rn2(2))
266.                 otmp = mk_artifact(otmp, A_NONE, 99, FALSE);
267.             /* usually increase stack size if stackable weapon */
268.             if (objects[otmp->otyp].oc_merge && !otmp->oartifact
269.                 && monmightthrowwep(otmp))
270.                 otmp->quan += (long) rn2(is_spear(otmp) ? 4 : 8);
271.             otmp->owt = weight(otmp);
272.             /* mplayers knew better than to overenchant Magicbane */
273.             if (is_art(otmp, ART_MAGICBANE))
274.                 otmp->spe = rnd(4);
275.             (void) mpickobj(mtmp, otmp);
276.         }
277. 
278.         if (special) {
279.             if (!rn2(10))
280.                 (void) mongets(mtmp, rn2(3) ? LUCKSTONE : LOADSTONE);
281.             mk_mplayer_armor(mtmp, armor);
282.             mk_mplayer_armor(mtmp, cloak);
283.             mk_mplayer_armor(mtmp, helm);
284.             mk_mplayer_armor(mtmp, shield);
285.             if (weapon == WAR_HAMMER) /* valkyrie: wimpy weapon or Mjollnir */
286.                 mk_mplayer_armor(mtmp, GAUNTLETS_OF_POWER);
287.             else if (rn2(8))
288.                 mk_mplayer_armor(mtmp, rnd_class(LEATHER_GLOVES,
289.                                                  GAUNTLETS_OF_DEXTERITY));
290.             if (rn2(8))
291.                 mk_mplayer_armor(mtmp, rnd_class(LOW_BOOTS,
292.                                                  LEVITATION_BOOTS));
293.             m_dowear(mtmp, TRUE);
294. 
295.             quan = rn2(3) ? rn2(3) : rn2(16);
296.             while (quan--)
297.                 (void) mongets(mtmp, rnd_class(DILITHIUM_CRYSTAL, JADE));
298.             /* To get the gold "right" would mean a player can double his
299.                gold supply by killing one mplayer.  Not good. */
300.             mkmonmoney(mtmp, rn2(1000));
301.             quan = rn2(10);
302.             while (quan--)
303.                 (void) mpickobj(mtmp, mkobj(RANDOM_CLASS, FALSE));
304.         }
305.         quan = rnd(3);
306.         while (quan--)
307.             (void) mongets(mtmp, rnd_offensive_item(mtmp));
308.         quan = rnd(3);
309.         while (quan--)
310.             (void) mongets(mtmp, rnd_defensive_item(mtmp));
311.         quan = rnd(3);
312.         while (quan--)
313.             (void) mongets(mtmp, rnd_misc_item(mtmp));
314.     }
315. 
316.     return (mtmp);
317. }
318. 
319. /* create the indicated number (num) of monster-players,
320.  * randomly chosen, and in randomly chosen (free) locations
321.  * on the level.  If "special", the size of num should not
322.  * be bigger than the number of _non-repeated_ names in the
323.  * developers array, otherwise a bunch of Adams and Eves will
324.  * fill up the overflow.
325.  */
326. void
327. create_mplayers(int num, boolean special)
328. {
329.     int pm, x, y;
330.     struct monst fakemon;
331. 
332.     fakemon = cg.zeromonst;
333.     while (num) {
334.         int tryct = 0;
335. 
336.         /* roll for character class */
337.         pm = rn1(PM_WIZARD - PM_ARCHEOLOGIST + 1, PM_ARCHEOLOGIST);
338.         set_mon_data(&fakemon, &mons[pm]);
339. 
340.         /* roll for an available location */
341.         do {
342.             x = rn1(COLNO - 4, 2);
343.             y = rnd(ROWNO - 2);
344.         } while (!goodpos(x, y, &fakemon, 0) && tryct++ <= 50);
345. 
346.         /* if pos not found in 50 tries, don't bother to continue */
347.         if (tryct > 50)
348.             return;
349. 
350.         (void) mk_mplayer(&mons[pm], (coordxy) x, (coordxy) y, special);
351.         num--;
352.     }
353. }
354. 
355. void
356. mplayer_talk(struct monst *mtmp)
357. {
358.     static const char
359.         *same_class_msg[3] = {
360.             "I can't win, and neither will you!",
361.             "You don't deserve to win!",
362.             "Mine should be the honor, not yours!",
363.         },
364.         *other_class_msg[3] = {
365.             "The low-life wants to talk, eh?",
366.             "Fight, scum!",
367.             "Here is what I have to say!",
368.         };
369. 
370.     if (mtmp->mpeaceful)
371.         return; /* will drop to humanoid talk */
372. 
373.     SetVoice(mtmp, 0, 80, 0);
374.     verbalize("Talk? -- %s", mtmp->data == &mons[gu.urole.mnum]
375.                                 ? same_class_msg[rn2(3)]
376.                                 : other_class_msg[rn2(3)]);
377. }
378. 
379. /*mplayer.c*/