Source:Hack 1.0/hack.mhitu.c

From NetHackWiki
Revision as of 20:27, 29 August 2006 by Jaytbot (talk | contribs) (Automated source code upload)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Below is the full text to hack.mhitu.c from the source code of Hack 1.0. To link to a particular line, write [[Hack 1.0/hack.mhitu.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.    #include	"hack.h"
2.    extern struct monst *makemon();
3.    
4.    /*
5.     * mhitu: monster hits you
6.     *	  returns 1 if monster dies (e.g. 'y', 'F'), 0 otherwise
7.     */
8.    mhitu(mtmp)
9.    register struct monst *mtmp;
10.   {
11.   	register struct permonst *mdat = mtmp->data;
12.   	register int tmp, ctmp;
13.   
14.   	nomul(0);
15.   	if(!index("&DuxynNF",mdat->mlet) && !u.uswallow)
16.   		tmp = hitu(mtmp,d(mdat->damn,mdat->damd));
17.   	else tmp = 0;
18.   
19.   	ctmp = tmp && !mtmp->mcan &&
20.   	  (!uarm || objects[uarm->otyp].a_can < rnd(3) || !rn2(50));
21.   	switch(mdat->mlet) {
22.   	case '&':
23.   		if(!mtmp->cham && !mtmp->mcan && !rn2(15)) {
24.   			(void) makemon(PM_DEMON,u.ux,u.uy);
25.   		} else {
26.   			(void) hitu(mtmp,d(2,6));
27.   			(void) hitu(mtmp,d(2,6));
28.   			(void) hitu(mtmp,rnd(3));
29.   			(void) hitu(mtmp,rnd(3));
30.   			(void) hitu(mtmp,rn1(4,2));
31.   		}
32.   		break;
33.   	case ',':
34.   		if(u.uswallow)
35.   			youswld(mtmp,4+u.uac,5,"The trapper");
36.   		else if(tmp) justswld(mtmp,"The trapper");
37.   		break;
38.   	case '\:
39.   		if(u.uswallow)
40.   			youswld(mtmp,rnd(6),7,"The lurker above");
41.   		else if(tmp) justswld(mtmp,"The lurker above");
42.   		break;
43.   	case 'A':
44.   		if(ctmp && rn2(2)) {
45.   			pline("You feel weaker!");
46.   			losestr(1);
47.   		}
48.   		break;
49.   	case 'C':
50.   		(void) hitu(mtmp,rnd(6));
51.   		break;
52.   	case 'c':
53.   		if(!rn2(5)) {
54.   			pline("You hear %s's hissing!", monnam(mtmp));
55.   			if(ctmp || !rn2(5)) {
56.   				pline("You get turned to stone!");
57.   				done_in_by(mtmp);
58.   			}
59.   		}
60.   		break;
61.   	case 'D':
62.   		if(rn2(6) || mtmp->mcan) {
63.   			(void) hitu(mtmp,d(3,10));
64.   			(void) hitu(mtmp,rnd(8));
65.   			(void) hitu(mtmp,rnd(8));
66.   			break;
67.   		}
68.   		kludge("%s breathes fire!","The dragon");
69.   		buzz(-1,mtmp->mx,mtmp->my,u.ux-mtmp->mx,u.uy-mtmp->my);
70.   		break;
71.   	case 'd':
72.   		(void) hitu(mtmp,d(2,4));
73.   		break;
74.   	case 'e':
75.   		(void) hitu(mtmp,d(3,6));
76.   		break;
77.   	case 'F':
78.   		if(mtmp->mcan) break;
79.   		kludge("%s explodes!","The freezing sphere");
80.   		if(Cold_resistance) pline("You don't seem affected by it.");
81.   		else {
82.   			xchar dn;
83.   			if(17-(u.ulevel/2) > rnd(20)) {
84.   				pline("You get blasted!");
85.   				dn = 6;
86.   			} else {
87.   				pline("You duck the blast...");
88.   				dn = 3;
89.   			}
90.    losehp_m(d(dn,6), mtmp);
91.   		}
92.   		mondead(mtmp);
93.   		return(1);
94.   	case 'g':
95.   		if(ctmp && multi >= 0 && !rn2(6)) {
96.   kludge("You are frozen by %ss juices","the cube'");
97.   			nomul(-rnd(10));
98.   		}
99.   		break;
100.  	case 'h':
101.  		if(ctmp && multi >= 0 && !rn2(5)) {
102.  			nomul(-rnd(10));
103.  kludge("You are put to sleep by %ss bite!","the homunculus'");
104.  		}
105.  		break;
106.  	case 'j':
107.  		tmp = hitu(mtmp,rnd(3));
108.  		tmp &= hitu(mtmp,rnd(3));
109.  		if(tmp){
110.  			(void) hitu(mtmp,rnd(4));
111.  			(void) hitu(mtmp,rnd(4));
112.  		}
113.  		break;
114.  	case 'k':
115.  		if((hitu(mtmp,rnd(4)) || !rn2(3)) && ctmp){
116.  			poisoned("bee's sting",mdat->mname);
117.  		}
118.  		break;
119.  	case 'L':
120.  		if(tmp) stealgold(mtmp);
121.  		break;
122.  	case 'N':
123.  		if(mtmp->mcan && !Blind) {
124.  	pline("%s tries to seduce you, but you seem not interested.",
125.  			Amonnam(mtmp, "plain"));
126.  			if(rn2(3)) rloc(mtmp);
127.  		} else if(steal(mtmp)) {
128.  			rloc(mtmp);
129.  			mtmp->mflee = 1;
130.  		}
131.  		break;
132.  	case 'n':
133.  		if(!uwep && !uarm && !uarmh && !uarms && !uarmg) {
134.  		    pline("%s hits! (I hope you don't mind)",
135.  			Monnam(mtmp));
136.  			u.uhp += rnd(7);
137.  			if(!rn2(7)) u.uhpmax++;
138.  			if(u.uhp > u.uhpmax) u.uhp = u.uhpmax;
139.  			flags.botl = 1;
140.  			if(!rn2(50)) rloc(mtmp);
141.  		} else {
142.  			(void) hitu(mtmp,d(2,6));
143.  			(void) hitu(mtmp,d(2,6));
144.  		}
145.  		break;
146.  	case 'o':
147.  		tmp = hitu(mtmp,rnd(6));
148.  		if(hitu(mtmp,rnd(6)) && ctmp &&
149.  		!u.ustuck && rn2(2)) {
150.  			u.ustuck = mtmp;
151.  			kludge("%s has grabbed you!","The owlbear");
152.  			u.uhp -= d(2,8);
153.  		} else if(u.ustuck == mtmp) {
154.  			u.uhp -= d(2,8);
155.  			pline("You are being crushed.");
156.  		}
157.  		break;
158.  	case 'P':
159.  		if(u.uswallow)
160.  			youswld(mtmp,d(2,4),12,"The purple worm");
161.  		else if(ctmp && !rn2(4))
162.  			justswld(mtmp,"The purple worm");
163.  		else (void) hitu(mtmp,d(2,4));
164.  		break;
165.  	case 'Q':
166.  		(void) hitu(mtmp,rnd(2));
167.  		(void) hitu(mtmp,rnd(2));
168.  		break;
169.  	case 'R':
170.  		if(tmp && uarmh && !uarmh->rustfree &&
171.  		    (int) uarmh->spe >= -1) {
172.  			pline("Your helmet rusts!");
173.  			uarmh->spe--;
174.  		} else
175.  		if(ctmp && uarm && !uarmh->rustfree &&
176.  		 uarm->otyp < STUDDED_LEATHER_ARMOR &&
177.  		 (int)uarm->spe >= -1) {
178.  			pline("Your armor rusts!");
179.  			uarm->spe--;
180.  		}
181.  		break;
182.  	case 'S':
183.  		if(ctmp && !rn2(8)) {
184.  			poisoned("snake's bite",mdat->mname);
185.  		}
186.  		break;
187.  	case 's':
188.  		if(tmp && !rn2(8)) {
189.  			poisoned("scorpion's sting",mdat->mname);
190.  		}
191.  		(void) hitu(mtmp,rnd(8));
192.  		(void) hitu(mtmp,rnd(8));
193.  		break;
194.  	case 'T':
195.  		(void) hitu(mtmp,rnd(6));
196.  		(void) hitu(mtmp,rnd(6));
197.  		break;
198.  	case 't':
199.  		if(!rn2(5)) rloc(mtmp);
200.  		break;
201.  	case 'u':
202.  		mtmp->mflee = 1;
203.  		break;
204.  	case 'U':
205.  		(void) hitu(mtmp,d(3,4));
206.  		(void) hitu(mtmp,d(3,4));
207.  		break;
208.  	case 'v':
209.  		if(ctmp && !u.ustuck) u.ustuck = mtmp;
210.  		break;
211.  	case 'V':
212.  		if(tmp) u.uhp -= 4;
213.  		if(ctmp && !rn2(3)) losexp();
214.  		break;
215.  	case 'W':
216.  		if(ctmp && !rn2(5)) losexp();
217.  		break;
218.  #ifndef NOWORM
219.  	case 'w':
220.  		if(tmp) wormhit(mtmp);
221.  #endif NOWORM
222.  		break;
223.  	case 'X':
224.  		(void) hitu(mtmp,rnd(3));
225.  		(void) hitu(mtmp,rnd(3));
226.  		(void) hitu(mtmp,rnd(3));
227.  		break;
228.  	case 'x':
229.  		{ register int side = rn2(2) ? RIGHT_SIDE : LEFT_SIDE;
230.  		  pline("%s pricks in your %s leg!",
231.  			Monnam(mtmp), (side == RIGHT_SIDE) ? "right" : "left");
232.  		  Wounded_legs |= side + rnd(5);
233.  		  losehp_m(2, mtmp);
234.  		  break;
235.  		}
236.  	case 'y':
237.  		if(mtmp->mcan) break;
238.  		mondead(mtmp);
239.  		if(!Blind) {
240.  			pline("You are blinded by a blast of light!");
241.  			Blind = d(4,12);
242.  			seeoff(0);
243.  		}
244.  		return(1);
245.  	case 'Y':
246.  		(void) hitu(mtmp,rnd(6));
247.  		break;
248.  	}
249.  	if(u.uhp < 1) done_in_by(mtmp);
250.  	return(0);
251.  }