Source:NetHack 1.3d/polyself.c

From NetHackWiki
Revision as of 00:16, 4 March 2008 by Kernigh bot (talk | contribs) (NetHack 1.3d/polyself.c moved to Source:NetHack 1.3d/polyself.c: Robot: moved page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Below is the full text to polyself.c from the source code of NetHack 1.3d. To link to a particular line, write [[NetHack 1.3d/polyself.c#line123]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

Screenshots and source code from Hack are used under the CWI license.

1.    /*	SCCS Id: @(#)polyself.c	1.3	87/07/14
2.    /* Polymorph self routine.  Called in zap.c. Copyright 1987 by Ken Arromdee */
3.    
4.    #include "hack.h"
5.    
6.    #ifdef KAA
7.    
8.    extern char genocided[];
9.    extern char pl_character[PL_CSIZ];
10.   extern char plname[PL_NSIZ];
11.   
12.   extern long newuexp();
13.   
14.   polyself()
15.   {
16.        char buf[BUFSZ];
17.        int tmp, tmp2, mntmp;
18.   
19.        if (rn2(5)-3 > u.uluck) {
20.   	  pline("You shudder for a moment.");
21.   	  losehp(rn2(30),"system shock");
22.   	  return;
23.        }
24.        mntmp = rn2(CMNUM);
25.   /* We want to disallow certain monsters, but also allow humans. */
26.        if (index("w:",mons[mntmp].mlet) || !rn2(5)) {
27.   	  if (!rn2(10)) flags.female = !flags.female;
28.   	  tmp = u.uhpmax;
29.   	  tmp2 = u.ulevel;
30.   	  u.usym = '@';
31.   	  prme();
32.   	  u.mtimedone = u.mh = u.mhmax = 0;
33.   	  u.ulevel = u.ulevel-2+rn2(5);
34.   	  if (u.ulevel > 127 || u.ulevel == 0) u.ulevel = 1;
35.   	  if (u.ulevel > 14) u.ulevel = 14;
36.   	  if (u.ulevel == 1) u.uexp = rnd(10);
37.   	  else {  /* For the new experience level, random EXP. */
38.   	       u.ulevel--;     
39.   	       u.uexp = newuexp();
40.   	       u.uexp += rn2(u.uexp);
41.   	       u.ulevel++;
42.   	  }
43.   	  u.uhpmax = (u.uhpmax-10)*u.ulevel/tmp2 + 19 - rn2(19);
44.   /* If it was u.uhpmax*u.ulevel/tmp+9-rn2(19), then a 1st level character
45.      with 16 hp who polymorphed into a 3rd level one would have an average
46.      of 48 hp.  */
47.   	  u.uhp = u.uhp*u.uhpmax/tmp;
48.   	  tmp = u.ustrmax;
49.   	  u.ustrmax += (rn2(5)-2);
50.   	  if (u.ustrmax > 118) u.ustrmax = 118;
51.   	  if (u.ustrmax < 3) u.ustrmax = 3;
52.   	  u.ustr = u.ustr * u.ustrmax / tmp;
53.   	  if (u.ustr < 3) u.ustr = 3;  /* > 118 is impossible */
54.   	  u.uhunger = 500 + rn2(500);
55.   	  Sick = 0;
56.   	  Stoned = 0;
57.   	  if (u.uhp <= 0 || u.uhpmax <= 0) {
58.   	       killer="unsuccessful polymorph";
59.   	       done("died");
60.   	  }
61.   	  pline("You feel like a new %sman!", flags.female ? "wo" : "");
62.   newname:  more();
63.   	  do {
64.   	       pline("What is your new name? ");
65.   	       getlin(buf);
66.   	  } while (buf[0]=='\033' || buf[0]==0);
67.   	  if (!strcmp(plname,buf)) {
68.   	       pline("That is the same as your old name!");
69.   	       goto newname;
70.   	  }
71.   	  (void)strncpy(plname, buf, sizeof(plname)-1);
72.   	  flags.botl = 1;
73.   	  find_ac();
74.        } else {
75.   	  if (index(genocided,mons[mntmp].mlet)) {
76.   	       pline("You feel rather %sish.",mons[mntmp].mname);
77.   	       return;
78.   	  }
79.   	  u.umonnum = mntmp;
80.   	  u.usym = mons[mntmp].mlet;
81.   	  if (u.usym == 'D') u.mhmax = 80;
82.   	  else if (!(mons[mntmp].mlevel)) u.mhmax = rnd(4);
83.   	  else u.mhmax = d(mons[mntmp].mlevel,8);
84.   	  u.mh = u.mhmax;
85.   	  pline("You turn into a%s %s!", index("aeioOU",u.usym) ? "n" : "",
86.   	       mons[mntmp].mname);
87.   	  break_armor(u.usym);
88.   	  drop_weapon(u.usym);
89.   	  prme();
90.   	  u.mtimedone = 500 + rn2(500);
91.   	  flags.botl = 1;
92.   	  if (u.usym == 'D')
93.   	       pline("Use the command #breathe to breathe.");
94.   	  if (u.usym == 'N')
95.   	       pline("Use the command #remove if you have to remove an iron ball.");
96.   	  find_ac();
97.        }
98.        if (Inhell && !Fire_resistance) {
99.   	  pline("You burn to a crisp.");
100.  	  killer = "unwise polymorph";
101.  	  done("died");
102.       }
103.  }
104.  
105.  break_armor(turninto)
106.  char turninto;
107.  {
108.       struct obj *otmp;
109.       if (uarm) {
110.  	  if (index("CDMPRUXYdejlouz,'9", turninto)) {
111.  	       pline("The transformation causes you to break out of your armor!");
112.  	       if (uarm2) useup(uarm2);
113.  	       useup(uarm);
114.  	  } else if (index("abcfghikpqrstvxyABEFJQS", turninto)) {
115.  	       pline("Your armor falls around you!");
116.  	       if (otmp = uarm2) {
117.  		    setworn((struct obj *)0,otmp->owornmask & W_ARM2);
118.  		    dropx(otmp);
119.  	       }
120.  	       otmp = uarm;
121.  	       setworn((struct obj *)0, otmp->owornmask & W_ARM);
122.  	       dropx(otmp);
123.  	  }
124.       }
125.       if (!index("enozCGHIKLNOTUVWXYZ&',", turninto)) {
126.  	  if (otmp = uarmg) {
127.  	       pline("You drop your gloves!");
128.  	       setworn((struct obj *)0, otmp->owornmask & W_ARMG);
129.  	       dropx(otmp);
130.  	       drop_weapon('a'); /* the 'a' is dummy to ensure dropping */
131.  	  }
132.  	  if (otmp = uarms) {
133.  	       pline("You can no longer hold your shield!");
134.  	       setworn((struct obj *)0, otmp->owornmask & W_ARMS);
135.  	       dropx(otmp);
136.  	  }
137.  	  if (otmp = uarmh) {
138.  	       pline("Your helmet falls to the floor!");
139.  	       setworn((struct obj *)0, otmp->owornmask & W_ARMH);
140.  	       dropx(otmp);
141.  	  }
142.       }
143.  }
144.  
145.  drop_weapon(turninto) 
146.  char turninto;
147.  {
148.       struct obj *otmp;
149.       if (otmp = uwep) {
150.  	  if (cantwield(turninto)) {
151.  	       pline("You find you must drop your weapon!");
152.  	       setuwep((struct obj *)0);
153.  	       dropx(otmp);
154.  	  }
155.       }
156.  }
157.  
158.  cantwield(c)  /* creature type c cannot wield a weapon */
159.  char c;
160.  {
161.       return(!!index("abcdfgjklpqrsuvxyABEFJPRS',",c));
162.  }
163.  
164.  cantweararm(c)   /* creature type c cannot wear armor */
165.  char c;
166.  {
167.       return(!index("@nGHIKLNOTVWZ&',",c));
168.  }
169.  
170.  rehumanize()
171.  {
172.       u.mh = u.mhmax = u.mtimedone = 0;
173.       u.usym = '@';
174.       prme();
175.       pline("You return to %sn form!", (pl_character[0]=='E')?"elve":"huma");
176.       if (!Fire_resistance && Inhell) {
177.  	  pline("You burn to a crisp.");
178.  	  killer = "dissipating polymorph spell";
179.  	  done("died");
180.       }
181.       flags.botl = 1;
182.       find_ac();
183.  }
184.  
185.  dobreathe()
186.  {
187.       if (u.usym == 'D') {
188.  	  if(!getdir(1)) return(0);
189.  	  if (rn2(4))
190.  	       pline("You exhale a bit of smoke.");
191.  	  else buzz(10, u.ux, u.uy, u.dx, u.dy);
192.       /* Changes must be made in zap.c to accommodate this. */
193.       } else pline("You do not have the ability to breathe fire!");
194.       return(1);
195.  }
196.  
197.  doremove()
198.  {
199.       if (!Punished) {
200.  	  pline("You do not have a ball attached to your leg!");
201.  	  return(0);
202.       }
203.       if(u.usym != 'N')
204.  	  pline("You are not capable of removing a locked chain!");
205.       else {
206.  	  Punished = 0;
207.  	  uchain->spe = 0;
208.  	  uball->spe = 0;
209.  	  uchain->owornmask &= ~W_CHAIN;
210.  	  uball->owornmask &= ~W_BALL;
211.  	  uchain = uball = (struct obj *)0;
212.       }
213.       return(1);
214.  }
215.  #endif