forked from NetHack/NetHack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolyself.c
More file actions
2211 lines (2054 loc) · 79.5 KB
/
polyself.c
File metadata and controls
2211 lines (2054 loc) · 79.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* NetHack 3.7 polyself.c $NHDT-Date: 1681429658 2023/04/13 23:47:38 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.197 $ */
/* Copyright (C) 1987, 1988, 1989 by Ken Arromdee */
/* NetHack may be freely redistributed. See license for details. */
/*
* Polymorph self routine.
*
* Note: the light source handling code assumes that both gy.youmonst.m_id
* and gy.youmonst.mx will always remain 0 when it handles the case of the
* player polymorphed into a light-emitting monster.
*
* Transformation sequences:
* /-> polymon poly into monster form
* polyself =
* \-> newman -> polyman fail to poly, get human form
*
* rehumanize -> polyman return to original form
*
* polymon (called directly) usually golem petrification
*/
#include "hack.h"
static void check_strangling(boolean);
static void polyman(const char *, const char *);
static void dropp(struct obj *);
static void break_armor(void);
static void drop_weapon(int);
static int armor_to_dragon(int);
static void newman(void);
static void polysense(void);
static const char no_longer_petrify_resistant[] =
"No longer petrify-resistant, you";
/* update the gy.youmonst.data structure pointer and intrinsics */
void
set_uasmon(void)
{
struct permonst *mdat = &mons[u.umonnum];
boolean was_vampshifter = valid_vampshiftform(gy.youmonst.cham, u.umonnum);
set_mon_data(&gy.youmonst, mdat);
if (Protection_from_shape_changers)
gy.youmonst.cham = NON_PM;
else if (is_vampire(gy.youmonst.data))
gy.youmonst.cham = gy.youmonst.mnum;
/* assume hero-as-chameleon/doppelganger/sandestin doesn't change shape */
else if (!was_vampshifter)
gy.youmonst.cham = NON_PM;
u.mcham = gy.youmonst.cham; /* for save/restore since youmonst isn't */
#define PROPSET(PropIndx, ON) \
do { \
if (ON) \
u.uprops[PropIndx].intrinsic |= FROMFORM; \
else \
u.uprops[PropIndx].intrinsic &= ~FROMFORM; \
} while (0)
PROPSET(FIRE_RES, resists_fire(&gy.youmonst));
PROPSET(COLD_RES, resists_cold(&gy.youmonst));
PROPSET(SLEEP_RES, resists_sleep(&gy.youmonst));
PROPSET(DISINT_RES, resists_disint(&gy.youmonst));
PROPSET(SHOCK_RES, resists_elec(&gy.youmonst));
PROPSET(POISON_RES, resists_poison(&gy.youmonst));
PROPSET(ACID_RES, resists_acid(&gy.youmonst));
PROPSET(STONE_RES, resists_ston(&gy.youmonst));
{
/* resists_drli() takes wielded weapon into account; suppress it */
struct obj *save_uwep = uwep;
uwep = 0;
PROPSET(DRAIN_RES, resists_drli(&gy.youmonst));
uwep = save_uwep;
}
/* resists_magm() takes wielded, worn, and carried equipment into
into account; cheat and duplicate its monster-specific part */
PROPSET(ANTIMAGIC, (dmgtype(mdat, AD_MAGM)
|| mdat == &mons[PM_BABY_GRAY_DRAGON]
|| dmgtype(mdat, AD_RBRE)));
PROPSET(SICK_RES, (mdat->mlet == S_FUNGUS || mdat == &mons[PM_GHOUL]));
PROPSET(STUNNED, (mdat == &mons[PM_STALKER] || is_bat(mdat)));
PROPSET(HALLUC_RES, dmgtype(mdat, AD_HALU));
PROPSET(SEE_INVIS, perceives(mdat));
PROPSET(TELEPAT, telepathic(mdat));
/* note that Infravision uses mons[race] rather than usual mons[role] */
PROPSET(INFRAVISION, infravision(Upolyd ? mdat : &mons[gu.urace.mnum]));
PROPSET(INVIS, pm_invisible(mdat));
PROPSET(TELEPORT, can_teleport(mdat));
PROPSET(TELEPORT_CONTROL, control_teleport(mdat));
PROPSET(LEVITATION, is_floater(mdat));
/* floating eye is the only 'floater'; it is also flagged as a 'flyer';
suppress flying for it so that enlightenment doesn't confusingly
show latent flight capability always blocked by levitation */
PROPSET(FLYING, (is_flyer(mdat) && !is_floater(mdat)));
PROPSET(SWIMMING, is_swimmer(mdat));
/* [don't touch MAGICAL_BREATHING here; both Amphibious and Breathless
key off of it but include different monster forms...] */
PROPSET(PASSES_WALLS, passes_walls(mdat));
PROPSET(REGENERATION, regenerates(mdat));
PROPSET(REFLECTING, (mdat == &mons[PM_SILVER_DRAGON]));
PROPSET(BLINDED, !haseyes(mdat));
#undef PROPSET
float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */
polysense();
#ifdef STATUS_HILITES
if (VIA_WINDOWPORT())
status_initialize(REASSESS_ONLY);
#endif
}
/* Levitation overrides Flying; set or clear BFlying|I_SPECIAL */
void
float_vs_flight(void)
{
boolean stuck_in_floor = (u.utrap && u.utraptype != TT_PIT);
/* floating overrides flight; so does being trapped in the floor */
if ((HLevitation || ELevitation)
|| ((HFlying || EFlying) && stuck_in_floor))
BFlying |= I_SPECIAL;
else
BFlying &= ~I_SPECIAL;
/* being trapped on the ground (bear trap, web, molten lava survived
with fire resistance, former lava solidified via cold, tethered
to a buried iron ball) overrides floating--the floor is reachable */
if ((HLevitation || ELevitation) && stuck_in_floor)
BLevitation |= I_SPECIAL;
else
BLevitation &= ~I_SPECIAL;
gc.context.botl = TRUE;
}
/* for changing into form that's immune to strangulation */
static void
check_strangling(boolean on)
{
/* on -- maybe resume strangling */
if (on) {
boolean was_strangled = (Strangled != 0L);
/* when Strangled is already set, polymorphing from one
vulnerable form into another causes the counter to be reset */
if (uamul && uamul->otyp == AMULET_OF_STRANGULATION
&& can_be_strangled(&gy.youmonst)) {
Strangled = 6L;
gc.context.botl = TRUE;
Your("%s %s your %s!", simpleonames(uamul),
was_strangled ? "still constricts" : "begins constricting",
body_part(NECK)); /* "throat" */
makeknown(AMULET_OF_STRANGULATION);
}
/* off -- maybe block strangling */
} else {
if (Strangled && !can_be_strangled(&gy.youmonst)) {
Strangled = 0L;
gc.context.botl = TRUE;
You("are no longer being strangled.");
}
}
}
DISABLE_WARNING_FORMAT_NONLITERAL
/* make a (new) human out of the player */
static void
polyman(const char *fmt, const char *arg)
{
boolean sticking = (sticks(gy.youmonst.data) && u.ustuck && !u.uswallow),
was_mimicking = (U_AP_TYPE != M_AP_NOTHING);
boolean was_blind = !!Blind;
if (Upolyd) {
u.acurr = u.macurr; /* restore old attribs */
u.amax = u.mamax;
u.umonnum = u.umonster;
flags.female = u.mfemale;
}
set_uasmon();
u.mh = u.mhmax = 0;
u.mtimedone = 0;
skinback(FALSE);
u.uundetected = 0;
if (sticking)
uunstick();
find_ac();
if (was_mimicking) {
if (gm.multi < 0)
unmul("");
gy.youmonst.m_ap_type = M_AP_NOTHING;
gy.youmonst.mappearance = 0;
}
newsym(u.ux, u.uy);
urgent_pline(fmt, arg);
/* check whether player foolishly genocided self while poly'd */
if (ugenocided()) {
/* intervening activity might have clobbered genocide info */
struct kinfo *kptr = find_delayed_killer(POLYMORPH);
if (kptr != (struct kinfo *) 0 && kptr->name[0]) {
gk.killer.format = kptr->format;
Strcpy(gk.killer.name, kptr->name);
} else {
gk.killer.format = KILLED_BY;
Strcpy(gk.killer.name, "self-genocide");
}
dealloc_killer(kptr);
done(GENOCIDED);
}
if (u.twoweap && !could_twoweap(gy.youmonst.data))
untwoweapon();
if (u.utrap && u.utraptype == TT_PIT) {
set_utrap(rn1(6, 2), TT_PIT); /* time to escape resets */
}
if (was_blind && !Blind) { /* reverting from eyeless */
set_itimeout(&HBlinded, 1L);
make_blinded(0L, TRUE); /* remove blindness */
}
check_strangling(TRUE);
if (!Levitation && !u.ustuck && is_pool_or_lava(u.ux, u.uy))
spoteffects(TRUE);
see_monsters();
}
RESTORE_WARNING_FORMAT_NONLITERAL
void
change_sex(void)
{
/* Some monsters are always of one sex and their sex can't be changed;
* Succubi/incubi can change, but are handled below.
*
* !Upolyd check necessary because is_male() and is_female()
* may be true for certain roles
*/
if (!Upolyd
|| (!is_male(gy.youmonst.data) && !is_female(gy.youmonst.data)
&& !is_neuter(gy.youmonst.data)))
flags.female = !flags.female;
if (Upolyd) /* poly'd: also change saved sex */
u.mfemale = !u.mfemale;
max_rank_sz(); /* [this appears to be superfluous] */
if ((Upolyd ? u.mfemale : flags.female) && gu.urole.name.f)
Strcpy(gp.pl_character, gu.urole.name.f);
else
Strcpy(gp.pl_character, gu.urole.name.m);
if (!Upolyd) {
u.umonnum = u.umonster;
} else if (u.umonnum == PM_AMOROUS_DEMON) {
flags.female = !flags.female;
#if 0
/* change monster type to match new sex; disabled with
PM_AMOROUS_DEMON */
u.umonnum = (u.umonnum == PM_SUCCUBUS) ? PM_INCUBUS : PM_SUCCUBUS;
#endif
set_uasmon();
}
}
/* log a message if non-poly'd hero's gender has changed */
void
livelog_newform(boolean viapoly, int oldgend, int newgend)
{
char buf[BUFSZ];
const char *oldrole, *oldrank, *newrole, *newrank;
/*
* TODO?
* Give other logging feedback here instead of in newman().
*/
if (!Upolyd) {
if (newgend != oldgend) {
oldrole = (oldgend && gu.urole.name.f) ? gu.urole.name.f
: gu.urole.name.m;
newrole = (newgend && gu.urole.name.f) ? gu.urole.name.f
: gu.urole.name.m;
oldrank = rank_of(u.ulevel, Role_switch, oldgend);
newrank = rank_of(u.ulevel, Role_switch, newgend);
Sprintf(buf, "%.10s %.30s", genders[flags.female].adj, newrank);
livelog_printf(LL_MINORAC, "%s into %s",
viapoly ? "polymorphed" : "transformed",
an(strcmp(newrole, oldrole) ? newrole
: strcmp(newrank, oldrank) ? newrank
: buf));
}
}
}
static void
newman(void)
{
const char *newform;
int i, oldlvl, newlvl, oldgend, newgend, hpmax, enmax;
oldlvl = u.ulevel;
newlvl = oldlvl + rn1(5, -2); /* new = old + {-2,-1,0,+1,+2} */
if (newlvl > 127 || newlvl < 1) { /* level went below 0? */
goto dead; /* old level is still intact (in case of lifesaving) */
}
if (newlvl > MAXULEV)
newlvl = MAXULEV;
/* If your level goes down, your peak level goes down by
the same amount so that you can't simply use blessed
full healing to undo the decrease. But if your level
goes up, your peak level does *not* undergo the same
adjustment; you might end up losing out on the chance
to regain some levels previously lost to other causes. */
if (newlvl < oldlvl)
u.ulevelmax -= (oldlvl - newlvl);
if (u.ulevelmax < newlvl)
u.ulevelmax = newlvl;
u.ulevel = newlvl;
oldgend = poly_gender();
if (gs.sex_change_ok && !rn2(10))
change_sex();
adjabil(oldlvl, (int) u.ulevel);
/* random experience points for the new experience level */
u.uexp = rndexp(FALSE);
/* set up new attribute points (particularly Con) */
redist_attr();
/*
* New hit points:
* remove "level gain"-based HP from any extra HP accumulated
* (the "extra" might actually be negative);
* modify the extra, retaining {80%, 90%, 100%, or 110%};
* add in newly generated set of level-gain HP.
*
* (This used to calculate new HP in direct proportion to old HP,
* but that was subject to abuse: accumulate a large amount of
* extra HP, drain level down to 1, then polyself to level 2 or 3
* [lifesaving capability needed to handle level 0 and -1 cases]
* and the extra got multiplied by 2 or 3. Repeat the level
* drain and polyself steps until out of lifesaving capability.)
*/
hpmax = u.uhpmax;
for (i = 0; i < oldlvl; i++)
hpmax -= (int) u.uhpinc[i];
/* hpmax * rn1(4,8) / 10; 0.95*hpmax on average */
hpmax = rounddiv((long) hpmax * (long) rn1(4, 8), 10);
for (i = 0; (u.ulevel = i) < newlvl; i++)
hpmax += newhp();
if (hpmax < u.ulevel)
hpmax = u.ulevel; /* min of 1 HP per level */
/* retain same proportion for current HP; u.uhp * hpmax / u.uhpmax */
u.uhp = rounddiv((long) u.uhp * (long) hpmax, u.uhpmax);
u.uhpmax = hpmax;
/*
* Do the same for spell power.
*/
enmax = u.uenmax;
for (i = 0; i < oldlvl; i++)
enmax -= (int) u.ueninc[i];
enmax = rounddiv((long) enmax * (long) rn1(4, 8), 10);
for (i = 0; (u.ulevel = i) < newlvl; i++)
enmax += newpw();
if (enmax < u.ulevel)
enmax = u.ulevel;
u.uen = rounddiv((long) u.uen * (long) enmax,
((u.uenmax < 1) ? 1 : u.uenmax));
u.uenmax = enmax;
/* [should alignment record be tweaked too?] */
u.uhunger = rn1(500, 500);
if (Sick)
make_sick(0L, (char *) 0, FALSE, SICK_ALL);
if (Stoned)
make_stoned(0L, (char *) 0, 0, (char *) 0);
if (u.uhp <= 0) {
if (Polymorph_control) { /* even when Stunned || Unaware */
if (u.uhp <= 0)
u.uhp = 1;
} else {
dead: /* we come directly here if experience level went to 0 or less */
urgent_pline(
"Your new form doesn't seem healthy enough to survive.");
gk.killer.format = KILLED_BY_AN;
Strcpy(gk.killer.name, "unsuccessful polymorph");
done(DIED);
/* must have been life-saved to get here */
newuhs(FALSE);
(void) encumber_msg(); /* used to be done by redist_attr() */
return; /* lifesaved */
}
}
newuhs(FALSE);
/* use saved gender we're about to revert to, not current */
newform = ((Upolyd ? u.mfemale : flags.female) && gu.urace.individual.f)
? gu.urace.individual.f
: (gu.urace.individual.m)
? gu.urace.individual.m
: gu.urace.noun;
polyman("You feel like a new %s!", newform);
newgend = poly_gender();
/* note: newman() bypasses achievements for new ranks attained and
doesn't log "new <form>" when that isn't accompanied by level change */
if (newlvl != oldlvl)
livelog_printf(LL_MINORAC, "became experience level %d as a new %s",
newlvl, newform);
else
livelog_newform(TRUE, oldgend, newgend);
if (Slimed) {
Your("body transforms, but there is still slime on you.");
make_slimed(10L, (const char *) 0);
}
gc.context.botl = 1;
see_monsters();
(void) encumber_msg();
retouch_equipment(2);
if (!uarmg)
selftouch(no_longer_petrify_resistant);
}
void
polyself(int psflags)
{
char buf[BUFSZ];
int old_light, new_light, mntmp, class, tryct, gvariant = NEUTRAL;
boolean forcecontrol = ((psflags & POLY_CONTROLLED) != 0),
low_control = ((psflags & POLY_LOW_CTRL) != 0),
monsterpoly = ((psflags & POLY_MONSTER) != 0),
formrevert = ((psflags & POLY_REVERT) != 0),
draconian = (uarm && Is_dragon_armor(uarm)),
iswere = (u.ulycn >= LOW_PM),
isvamp = (is_vampire(gy.youmonst.data)
|| is_vampshifter(&gy.youmonst)),
controllable_poly = Polymorph_control && !(Stunned || Unaware);
if (Unchanging) {
You("fail to transform!");
return;
}
/* being Stunned|Unaware doesn't negate this aspect of Poly_control */
if (!Polymorph_control && !forcecontrol && !draconian && !iswere
&& !isvamp) {
if (rn2(20) > ACURR(A_CON)) {
You1(shudder_for_moment);
losehp(rnd(30), "system shock", KILLED_BY_AN);
exercise(A_CON, FALSE);
return;
}
}
old_light = emits_light(gy.youmonst.data);
mntmp = NON_PM;
if (formrevert) {
mntmp = gy.youmonst.cham;
monsterpoly = TRUE;
controllable_poly = FALSE;
}
if (forcecontrol && low_control
&& (draconian || monsterpoly || isvamp || iswere))
forcecontrol = FALSE;
if (monsterpoly && isvamp)
goto do_vampyr;
if (controllable_poly || forcecontrol) {
buf[0] = '\0';
tryct = 5;
do {
mntmp = NON_PM;
getlin("Become what kind of monster? [type the name]", buf);
(void) mungspaces(buf);
if (*buf == '\033') {
/* user is cancelling controlled poly */
if (forcecontrol) { /* wizard mode #polyself */
pline1(Never_mind);
return;
}
Strcpy(buf, "*"); /* resort to random */
}
if (!strcmp(buf, "*") || !strcmp(buf, "random")) {
/* explicitly requesting random result */
tryct = 0; /* will skip thats_enough_tries */
continue; /* end do-while(--tryct > 0) loop */
}
class = 0;
mntmp = name_to_mon(buf, &gvariant);
if (mntmp < LOW_PM) {
by_class:
class = name_to_monclass(buf, &mntmp);
if (class && mntmp == NON_PM)
mntmp = (draconian && class == S_DRAGON)
? armor_to_dragon(uarm->otyp)
: mkclass_poly(class);
}
if (mntmp < LOW_PM) {
if (!class)
pline("I've never heard of such monsters.");
else
You_cant("polymorph into any of those.");
} else if (wizard && Upolyd
&& (mntmp == u.umonster
/* "priest" and "priestess" match the monster
rather than the role; override that unless
the text explicitly contains "aligned" */
|| (u.umonster == PM_CLERIC
&& mntmp == PM_ALIGNED_CLERIC
&& !strstri(buf, "aligned")))) {
/* in wizard mode, picking own role while poly'd reverts to
normal without newman()'s chance of level or sex change */
rehumanize();
old_light = 0; /* rehumanize() extinguishes u-as-mon light */
goto made_change;
} else if (iswere && (were_beastie(mntmp) == u.ulycn
|| mntmp == counter_were(u.ulycn)
|| (Upolyd && mntmp == PM_HUMAN))) {
goto do_shift;
} else if (!polyok(&mons[mntmp])
/* Note: humans are illegal as monsters, but an
illegal monster forces newman(), which is what
we want if they specified a human.... (unless
they specified a unique monster) */
&& !(mntmp == PM_HUMAN
|| (your_race(&mons[mntmp])
&& (mons[mntmp].geno & G_UNIQ) == 0)
|| mntmp == gu.urole.mnum)) {
const char *pm_name;
/* mkclass_poly() can pick a !polyok()
candidate; if so, usually try again */
if (class) {
if (rn2(3) || --tryct > 0)
goto by_class;
/* no retries left; put one back on counter
so that end of loop decrement will yield
0 and trigger thats_enough_tries message */
++tryct;
}
pm_name = pmname(&mons[mntmp], flags.female ? FEMALE : MALE);
if (the_unique_pm(&mons[mntmp]))
pm_name = the(pm_name);
else if (!type_is_pname(&mons[mntmp]))
pm_name = an(pm_name);
You_cant("polymorph into %s.", pm_name);
} else
break;
} while (--tryct > 0);
if (!tryct)
pline1(thats_enough_tries);
/* allow skin merging, even when polymorph is controlled */
if (draconian && (tryct <= 0 || mntmp == armor_to_dragon(uarm->otyp)))
goto do_merge;
if (isvamp && (tryct <= 0 || mntmp == PM_WOLF || mntmp == PM_FOG_CLOUD
|| is_bat(&mons[mntmp])))
goto do_vampyr;
} else if (draconian || iswere || isvamp) {
/* special changes that don't require polyok() */
if (draconian) {
do_merge:
mntmp = armor_to_dragon(uarm->otyp);
if (!(gm.mvitals[mntmp].mvflags & G_GENOD)) {
unsigned was_lit = uarm->lamplit;
int arm_light = artifact_light(uarm) ? arti_light_radius(uarm)
: 0;
/* allow G_EXTINCT */
if (Is_dragon_scales(uarm)) {
/* dragon scales remain intact as uskin */
You("merge with your scaly armor.");
} else { /* dragon scale mail reverts to scales */
/* similar to noarmor(invent.c),
shorten to "<color> scale mail" */
Strcpy(buf, simpleonames(uarm));
strsubst(buf, " dragon ", " ");
/* tricky phrasing; dragon scale mail is singular, dragon
scales are plural (note: we don't use "set of scales",
which usually overrides the distinction, here) */
Your("%s reverts to scales as you merge with them.", buf);
/* uarm->spe enchantment remains unchanged;
re-converting scales to mail poses risk
of evaporation due to over enchanting */
uarm->otyp += GRAY_DRAGON_SCALES - GRAY_DRAGON_SCALE_MAIL;
uarm->dknown = 1;
gc.context.botl = 1; /* AC is changing */
}
uskin = uarm;
uarm = (struct obj *) 0;
/* save/restore hack */
uskin->owornmask |= I_SPECIAL;
if (was_lit)
maybe_adjust_light(uskin, arm_light);
update_inventory();
}
} else if (iswere) {
do_shift:
if (Upolyd && were_beastie(mntmp) != u.ulycn)
mntmp = PM_HUMAN; /* Illegal; force newman() */
else
mntmp = u.ulycn;
} else if (isvamp) {
do_vampyr:
if (mntmp < LOW_PM || (mons[mntmp].geno & G_UNIQ)) {
mntmp = (gy.youmonst.data == &mons[PM_VAMPIRE_LEADER]
&& !rn2(10)) ? PM_WOLF
: !rn2(4) ? PM_FOG_CLOUD
: PM_VAMPIRE_BAT;
if (gy.youmonst.cham >= LOW_PM
&& !is_vampire(gy.youmonst.data) && !rn2(2))
mntmp = gy.youmonst.cham;
}
if (controllable_poly) {
Sprintf(buf, "Become %s?",
an(pmname(&mons[mntmp], gvariant)));
if (y_n(buf) != 'y')
return;
}
}
/* if polymon fails, "you feel" message has been given
so don't follow up with another polymon or newman;
sex_change_ok left disabled here */
if (mntmp == PM_HUMAN)
newman(); /* werecritter */
else
(void) polymon(mntmp);
goto made_change; /* maybe not, but this is right anyway */
}
if (mntmp < LOW_PM) {
tryct = 200;
do {
/* randomly pick an "ordinary" monster */
mntmp = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
if (polyok(&mons[mntmp]) && !is_placeholder(&mons[mntmp]))
break;
} while (--tryct > 0);
}
/* The below polyok() fails either if everything is genocided, or if
* we deliberately chose something illegal to force newman().
*/
gs.sex_change_ok++;
if (!polyok(&mons[mntmp]) || (!forcecontrol && !rn2(5))
|| your_race(&mons[mntmp])) {
newman();
} else {
(void) polymon(mntmp);
}
gs.sex_change_ok--; /* reset */
made_change:
new_light = emits_light(gy.youmonst.data);
if (old_light != new_light) {
if (old_light)
del_light_source(LS_MONSTER, monst_to_any(&gy.youmonst));
if (new_light == 1)
++new_light; /* otherwise it's undetectable */
if (new_light)
new_light_source(u.ux, u.uy, new_light, LS_MONSTER,
monst_to_any(&gy.youmonst));
}
}
/* (try to) make a mntmp monster out of the player; return 1 if successful */
int
polymon(int mntmp)
{
char buf[BUFSZ], ustuckNam[BUFSZ];
boolean sticking = sticks(gy.youmonst.data) && u.ustuck && !u.uswallow,
was_blind = !!Blind, dochange = FALSE, was_expelled = FALSE;
int mlvl, newMaxStr;
if (gm.mvitals[mntmp].mvflags & G_GENOD) { /* allow G_EXTINCT */
You_feel("rather %s-ish.",
pmname(&mons[mntmp], flags.female ? FEMALE : MALE));
exercise(A_WIS, TRUE);
return 0;
}
/* KMH, conduct */
if (!u.uconduct.polyselfs++)
livelog_printf(LL_CONDUCT,
"changed form for the first time, becoming %s",
an(pmname(&mons[mntmp], flags.female ? FEMALE : MALE)));
/* exercise used to be at the very end but only Wis was affected
there since the polymorph was always in effect by then */
exercise(A_CON, FALSE);
exercise(A_WIS, TRUE);
if (!Upolyd) {
/* Human to monster; save human stats */
u.macurr = u.acurr;
u.mamax = u.amax;
u.mfemale = flags.female;
} else {
/* Monster to monster; restore human stats, to be
* immediately changed to provide stats for the new monster
*/
u.acurr = u.macurr;
u.amax = u.mamax;
flags.female = u.mfemale;
}
/* if stuck mimicking gold, stop immediately */
if (gm.multi < 0 && U_AP_TYPE == M_AP_OBJECT
&& gy.youmonst.data->mlet != S_MIMIC)
unmul("");
/* if becoming a non-mimic, stop mimicking anything */
if (mons[mntmp].mlet != S_MIMIC) {
/* as in polyman() */
gy.youmonst.m_ap_type = M_AP_NOTHING;
gy.youmonst.mappearance = 0;
}
if (is_male(&mons[mntmp])) {
if (flags.female)
dochange = TRUE;
} else if (is_female(&mons[mntmp])) {
if (!flags.female)
dochange = TRUE;
} else if (!is_neuter(&mons[mntmp]) && mntmp != u.ulycn) {
if (gs.sex_change_ok && !rn2(10))
dochange = TRUE;
}
Strcpy(ustuckNam, u.ustuck ? Some_Monnam(u.ustuck) : "");
Strcpy(buf, (u.umonnum != mntmp) ? "" : "new ");
if (dochange) {
flags.female = !flags.female;
Strcat(buf, (is_male(&mons[mntmp]) || is_female(&mons[mntmp]))
? "" : flags.female ? "female " : "male ");
}
Strcat(buf, pmname(&mons[mntmp], flags.female ? FEMALE : MALE));
You("%s %s!", (u.umonnum != mntmp) ? "turn into" : "feel like", an(buf));
if (Stoned && poly_when_stoned(&mons[mntmp])) {
/* poly_when_stoned already checked stone golem genocide */
mntmp = PM_STONE_GOLEM;
make_stoned(0L, "You turn to stone!", 0, (char *) 0);
}
u.mtimedone = rn1(500, 500);
u.umonnum = mntmp;
set_uasmon();
/* New stats for monster, to last only as long as polymorphed.
* Currently only strength gets changed.
*/
newMaxStr = uasmon_maxStr();
if (strongmonst(&mons[mntmp])) {
ABASE(A_STR) = AMAX(A_STR) = (schar) newMaxStr;
} else {
/* not a strongmonst(); if hero has exceptional strength, remove it
(note: removal is temporary until returning to original form);
we don't attempt to enforce lower maximum for wimpy forms;
unlike for strongmonst, current strength does not get set to max */
AMAX(A_STR) = (schar) newMaxStr;
/* make sure current is not higher than max (strip exceptional Str) */
if (ABASE(A_STR) > AMAX(A_STR))
ABASE(A_STR) = AMAX(A_STR);
}
if (Stone_resistance && Stoned) { /* parnes@eniac.seas.upenn.edu */
make_stoned(0L, "You no longer seem to be petrifying.", 0,
(char *) 0);
}
if (Sick_resistance && Sick) {
make_sick(0L, (char *) 0, FALSE, SICK_ALL);
You("no longer feel sick.");
}
if (Slimed) {
if (flaming(gy.youmonst.data)) {
make_slimed(0L, "The slime burns away!");
} else if (mntmp == PM_GREEN_SLIME) {
/* do it silently */
make_slimed(0L, (char *) 0);
}
}
check_strangling(FALSE); /* maybe stop strangling */
if (nohands(gy.youmonst.data))
make_glib(0);
/*
mlvl = adj_lev(&mons[mntmp]);
* We can't do the above, since there's no such thing as an
* "experience level of you as a monster" for a polymorphed character.
*/
mlvl = (int) mons[mntmp].mlevel;
if (gy.youmonst.data->mlet == S_DRAGON && mntmp >= PM_GRAY_DRAGON) {
u.mhmax = In_endgame(&u.uz) ? (8 * mlvl) : (4 * mlvl + d(mlvl, 4));
} else if (is_golem(gy.youmonst.data)) {
u.mhmax = golemhp(mntmp);
} else {
if (!mlvl)
u.mhmax = rnd(4);
else
u.mhmax = d(mlvl, 8);
if (is_home_elemental(&mons[mntmp]))
u.mhmax *= 3;
}
u.mh = u.mhmax;
if (u.ulevel < mlvl) {
/* Low level characters can't become high level monsters for long */
#ifdef DUMB
/* DRS/NS 2.2.6 messes up -- Peter Kendell */
int mtd = u.mtimedone, ulv = u.ulevel;
u.mtimedone = mtd * ulv / mlvl;
#else
u.mtimedone = u.mtimedone * u.ulevel / mlvl;
#endif
}
if (uskin && mntmp != armor_to_dragon(uskin->otyp))
skinback(FALSE);
break_armor();
drop_weapon(1);
find_ac(); /* (repeated below) */
(void) hideunder(&gy.youmonst);
if (u.utrap && u.utraptype == TT_PIT) {
set_utrap(rn1(6, 2), TT_PIT); /* time to escape resets */
}
if (was_blind && !Blind) { /* previous form was eyeless */
set_itimeout(&HBlinded, 1L);
make_blinded(0L, TRUE); /* remove blindness */
}
newsym(u.ux, u.uy); /* Change symbol */
/* you now know what an egg of your type looks like; [moved from
below in case expels() -> spoteffects() drops hero onto any eggs] */
if (lays_eggs(gy.youmonst.data)) {
learn_egg_type(u.umonnum);
/* make queen bees recognize killer bee eggs */
learn_egg_type(egg_type_from_parent(u.umonnum, TRUE));
}
if (u.uswallow) {
uchar usiz;
/* if new form can't be swallowed, make engulfer expel hero */
if (unsolid(gy.youmonst.data)
/* subset of engulf_target() */
|| (usiz = gy.youmonst.data->msize) >= MZ_HUGE
|| (u.ustuck->data->msize < usiz && !is_whirly(u.ustuck->data))) {
boolean expels_mesg = TRUE;
if (unsolid(gy.youmonst.data)) {
if (canspotmon(u.ustuck)) /* [see below for explanation] */
Strcpy(ustuckNam, Monnam(u.ustuck));
pline("%s can no longer contain you.", ustuckNam);
expels_mesg = FALSE;
}
expels(u.ustuck, u.ustuck->data, expels_mesg);
was_expelled = TRUE;
/* FIXME? if expels() triggered rehumanize then we should
return early */
}
/* [note: this 'sticking' handling is only sufficient for changing from
grabber to engulfer or vice versa because engulfing by poly'd hero
always ends immediately so won't be in effect during a polymorph] */
} else if (u.ustuck && !sticking /* && !u.uswallow */
/* being held; if now capable of holding, make holder
release so that hero doesn't automagically start holding
it; or, release if no longer capable of being held */
&& (sticks(gy.youmonst.data) || unsolid(gy.youmonst.data))) {
/* u.ustuck name was saved above in case we're changing from can-see
to can't-see; but might have changed from can't-see to can-see so
override here if hero knows who u.ustuck is */
if (canspotmon(u.ustuck))
Strcpy(ustuckNam, Monnam(u.ustuck));
set_ustuck((struct monst *) 0);
pline("%s loses its grip on you.", ustuckNam);
} else if (sticking && !sticks(gy.youmonst.data)) {
/* was holding onto u.ustuck but no longer capable of that */
uunstick();
}
if (u.usteed) {
if (touch_petrifies(u.usteed->data) && !Stone_resistance && rnl(3)) {
pline("%s touch %s.", no_longer_petrify_resistant,
mon_nam(u.usteed));
Sprintf(buf, "riding %s",
an(pmname(u.usteed->data, Mgender(u.usteed))));
instapetrify(buf);
}
if (!can_ride(u.usteed))
dismount_steed(DISMOUNT_POLY);
}
find_ac();
if (((!Levitation && !u.ustuck && !Flying && is_pool_or_lava(u.ux, u.uy))
|| (Underwater && !Swimming))
/* if expelled above, expels() already called spoteffects() */
&& !was_expelled) {
spoteffects(TRUE);
/* FIXME? if spoteffects() triggered rehumanize then we should
return early */
}
if (Passes_walls && u.utrap
&& (u.utraptype == TT_INFLOOR || u.utraptype == TT_BURIEDBALL)) {
if (u.utraptype == TT_INFLOOR) {
pline_The("rock seems to no longer trap you.");
} else {
pline_The("buried ball is no longer bound to you.");
buried_ball_to_freedom();
}
reset_utrap(TRUE);
} else if (likes_lava(gy.youmonst.data) && u.utrap
&& u.utraptype == TT_LAVA) {
pline_The("%s now feels soothing.", hliquid("lava"));
reset_utrap(TRUE);
}
if (amorphous(gy.youmonst.data) || is_whirly(gy.youmonst.data)
|| unsolid(gy.youmonst.data)) {
if (Punished) {
You("slip out of the iron chain.");
unpunish();
} else if (u.utrap && u.utraptype == TT_BURIEDBALL) {
You("slip free of the buried ball and chain.");
buried_ball_to_freedom();
}
}
if (u.utrap && (u.utraptype == TT_WEB || u.utraptype == TT_BEARTRAP)
&& (amorphous(gy.youmonst.data) || is_whirly(gy.youmonst.data)
|| unsolid(gy.youmonst.data)
|| (gy.youmonst.data->msize <= MZ_SMALL
&& u.utraptype == TT_BEARTRAP))) {
You("are no longer stuck in the %s.",
u.utraptype == TT_WEB ? "web" : "bear trap");
/* probably should burn webs too if PM_FIRE_ELEMENTAL */
reset_utrap(TRUE);
}
if (webmaker(gy.youmonst.data) && u.utrap && u.utraptype == TT_WEB) {
You("orient yourself on the web.");
reset_utrap(TRUE);
}
check_strangling(TRUE); /* maybe start strangling */
gc.context.botl = 1;
gv.vision_full_recalc = 1;
see_monsters();
(void) encumber_msg();
retouch_equipment(2);
/* this might trigger a recursive call to polymon() [stone golem
wielding cockatrice corpse and hit by stone-to-flesh, becomes
flesh golem above, now gets transformed back into stone golem;
fortunately neither form uses #monster] */
if (!uarmg)
selftouch(no_longer_petrify_resistant);
/* the explanation of '#monster' used to be shown sooner, but there are
possible fatalities above and it isn't useful unless hero survives */
if (Verbose(2, polymon)) {
static const char use_thec[] = "Use the command #%s to %s.";
static const char monsterc[] = "monster";
struct permonst *uptr = gy.youmonst.data;
boolean might_hide = (is_hider(uptr) || hides_under(uptr));
if (can_breathe(uptr))
pline(use_thec, monsterc, "use your breath weapon");
if (attacktype(uptr, AT_SPIT))
pline(use_thec, monsterc, "spit venom");
if (uptr->mlet == S_NYMPH)
pline(use_thec, monsterc, "remove an iron ball");
if (attacktype(uptr, AT_GAZE))
pline(use_thec, monsterc, "gaze at monsters");
if (might_hide && webmaker(uptr))
pline(use_thec, monsterc, "hide or to spin a web");
else if (might_hide)
pline(use_thec, monsterc, "hide");
else if (webmaker(uptr))
pline(use_thec, monsterc, "spin a web");
if (is_were(uptr))
pline(use_thec, monsterc, "summon help");
if (u.umonnum == PM_GREMLIN)
pline(use_thec, monsterc, "multiply in a fountain");
if (is_unicorn(uptr))
pline(use_thec, monsterc, "use your horn");
if (is_mind_flayer(uptr))
pline(use_thec, monsterc, "emit a mental blast");