Source:NetHack 5.0.0/src/were.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to were.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/were.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	were.c	$NHDT-Date: 1766588485 2025/12/24 07:01:25 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.41 $ */
2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3. /*-Copyright (c) Robert Patrick Rankin, 2011. */
4. /* NetHack may be freely redistributed.  See license for details. */
5. 
6. #include "hack.h"
7. 
8. void
9. were_change(struct monst *mon)
10. {
11.     if (!is_were(mon->data))
12.         return;
13. 
14.     if (is_human(mon->data)) {
15.         if (!Protection_from_shape_changers
16.             && !rn2(night() ? (flags.moonphase == FULL_MOON ? 3 : 30)
17.                             : (flags.moonphase == FULL_MOON ? 10 : 50))) {
18.             new_were(mon); /* change into animal form */
19.             gw.were_changes++;
20.             if (!Deaf && !canseemon(mon)) {
21.                 const char *howler;
22. 
23.                 switch (monsndx(mon->data)) {
24.                 case PM_WEREWOLF:
25.                     howler = "wolf";
26.                     break;
27.                 case PM_WEREJACKAL:
28.                     howler = "jackal";
29.                     break;
30.                 default:
31.                     howler = (char *) 0;
32.                     break;
33.                 }
34.                 if (howler) {
35.                     Soundeffect(se_canine_howl, 50);
36.                     You_hear("a %s howling at the moon.", howler);
37.                     wake_nearto(mon->mx, mon->my, 4 * 4);
38.                 }
39.             }
40.         }
41.     } else if (!rn2(30) || Protection_from_shape_changers) {
42.         new_were(mon); /* change back into human form */
43.         gw.were_changes++;
44.     }
45. }
46. 
47. int
48. counter_were(int pm)
49. {
50.     switch (pm) {
51.     case PM_WEREWOLF:
52.         return PM_HUMAN_WEREWOLF;
53.     case PM_HUMAN_WEREWOLF:
54.         return PM_WEREWOLF;
55.     case PM_WEREJACKAL:
56.         return PM_HUMAN_WEREJACKAL;
57.     case PM_HUMAN_WEREJACKAL:
58.         return PM_WEREJACKAL;
59.     case PM_WERERAT:
60.         return PM_HUMAN_WERERAT;
61.     case PM_HUMAN_WERERAT:
62.         return PM_WERERAT;
63.     default:
64.         return NON_PM;
65.     }
66. }
67. 
68. /* convert monsters similar to werecritters into appropriate werebeast */
69. int
70. were_beastie(int pm)
71. {
72.     switch (pm) {
73.     case PM_WERERAT:
74.     case PM_SEWER_RAT:
75.     case PM_GIANT_RAT:
76.     case PM_RABID_RAT:
77.         return PM_WERERAT;
78.     case PM_WEREJACKAL:
79.     case PM_JACKAL:
80.     case PM_FOX:
81.     case PM_COYOTE:
82.         return PM_WEREJACKAL;
83.     case PM_WEREWOLF:
84.     case PM_WOLF:
85.     case PM_WARG:
86.     case PM_WINTER_WOLF:
87.     case PM_WINTER_WOLF_CUB:
88.         return PM_WEREWOLF;
89.     default:
90.         break;
91.     }
92.     return NON_PM;
93. }
94. 
95. void
96. new_were(struct monst *mon)
97. {
98.     int pm;
99. 
100.     /* neither hero nor werecreature can change from human form to
101.        critter form if hero has Protection_from_shape_changers extrinsic;
102.        if already in critter form, always change to human form for that */
103.     if (Protection_from_shape_changers && is_human(mon->data))
104.         return;
105. 
106.     pm = counter_were(monsndx(mon->data));
107.     if (pm < LOW_PM) {
108.         impossible("unknown lycanthrope %s.",
109.                     mon->data->pmnames[NEUTRAL]);
110.         return;
111.     }
112. 
113.     if (canseemon(mon) && !Hallucination)
114.         pline("%s changes into a %s.", Monnam(mon),
115.               is_human(&mons[pm]) ? "human"
116.                                   /* pmname()+4: skip past "were" prefix */
117.                                   : pmname(&mons[pm], Mgender(mon)) + 4);
118. 
119.     set_mon_data(mon, &mons[pm]);
120.     if (helpless(mon)) {
121.         /* transformation wakens and/or revitalizes */
122.         mon->msleeping = 0;
123.         mon->mfrozen = 0; /* not asleep or paralyzed */
124.         mon->mcanmove = 1;
125.     }
126.     /* regenerate by 1/4 of the lost hit points */
127.     healmon(mon, (mon->mhpmax - mon->mhp) / 4, 0);
128.     newsym(mon->mx, mon->my);
129.     mon_break_armor(mon, FALSE);
130.     possibly_unwield(mon, FALSE);
131. 
132.     /* vision capability isn't changing so we don't call set_apparxy() to
133.        update mon's idea of where hero is; peaceful check is redundant */
134.     if (svc.context.mon_moving && !mon->mpeaceful
135.         && onscary(mon->mux, mon->muy, mon)
136.         && monnear(mon, mon->mux, mon->muy))
137.         monflee(mon, rn1(9, 2), TRUE, TRUE); /* 2..10 turns */
138. }
139. 
140. /* were-creature (even you) summons a horde */
141. int
142. were_summon(
143.     struct permonst *ptr,
144.     boolean yours,
145.     int *visible, /* number of visible helpers created */
146.     char *genbuf)
147. {
148.     int i, typ, pm = monsndx(ptr);
149.     struct monst *mtmp;
150.     int total = 0;
151. 
152.     *visible = 0;
153.     if (Protection_from_shape_changers && !yours)
154.         return 0;
155.     for (i = rnd(5); i > 0; i--) {
156.         switch (pm) {
157.         case PM_WERERAT:
158.         case PM_HUMAN_WERERAT:
159.             typ = rn2(3) ? PM_SEWER_RAT
160.                          : rn2(3) ? PM_GIANT_RAT : PM_RABID_RAT;
161.             if (genbuf)
162.                 Strcpy(genbuf, "rat");
163.             break;
164.         case PM_WEREJACKAL:
165.         case PM_HUMAN_WEREJACKAL:
166.             typ = rn2(7) ? PM_JACKAL : rn2(3) ? PM_COYOTE : PM_FOX;
167.             if (genbuf)
168.                 Strcpy(genbuf, "jackal");
169.             break;
170.         case PM_WEREWOLF:
171.         case PM_HUMAN_WEREWOLF:
172.             typ = rn2(5) ? PM_WOLF : rn2(2) ? PM_WARG : PM_WINTER_WOLF;
173.             if (genbuf)
174.                 Strcpy(genbuf, "wolf");
175.             break;
176.         default:
177.             continue;
178.         }
179.         mtmp = makemon(&mons[typ], u.ux, u.uy, NO_MM_FLAGS);
180.         if (mtmp) {
181.             total++;
182.             if (canseemon(mtmp))
183.                 *visible += 1;
184.         }
185.         if (yours && mtmp)
186.             (void) tamedog(mtmp, (struct obj *) 0, FALSE);
187.     }
188.     return total;
189. }
190. 
191. void
192. you_were(void)
193. {
194.     char qbuf[QBUFSZ];
195.     boolean controllable_poly = Polymorph_control && !(Stunned || Unaware);
196. 
197.     if (Unchanging || u.umonnum == u.ulycn)
198.         return;
199.     if (controllable_poly) {
200.         /* `+4' => skip "were" prefix to get name of beast */
201.         Sprintf(qbuf, "Do you want to change into %s?",
202.                 an(mons[u.ulycn].pmnames[NEUTRAL] + 4));
203.         if (!paranoid_query(ParanoidWerechange, qbuf))
204.             return;
205.     } else if (monster_nearby()) {
206.         return;
207.     }
208.     gw.were_changes++;
209.     (void) polymon(u.ulycn);
210. }
211. 
212. void
213. you_unwere(boolean purify)
214. {
215.     boolean controllable_poly = Polymorph_control && !(Stunned || Unaware);
216. 
217.     if (purify) {
218.         You_feel("purified.");
219.         set_ulycn(NON_PM); /* cure lycanthropy */
220.     }
221.     if (!Unchanging && is_were(gy.youmonst.data)
222.         && !monster_nearby()
223.         && (!controllable_poly
224.             || !paranoid_query(ParanoidWerechange, "Remain in beast form?")))
225.         rehumanize();
226.     else if (is_were(gy.youmonst.data) && !u.mtimedone)
227.         u.mtimedone = rn1(200, 200); /* 40% of initial were change */
228. }
229. 
230. /* lycanthropy is being caught or cured, but no shape change is involved */
231. void
232. set_ulycn(int which)
233. {
234.     u.ulycn = which;
235.     /* add or remove lycanthrope's innate intrinsics (Drain_resistance) */
236.     set_uasmon();
237. }
238. 
239. /*were.c*/