]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.do.c
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
6 static char rcsid
[] = "$NetBSD: hack.do.c,v 1.3 1995/03/23 08:29:53 cgd Exp $";
9 /* Contains code for 'd', 'D' (drop), '>', '<' (up, down) and 't' (throw) */
13 extern struct obj
*splitobj(), *addinv();
14 extern boolean
hmon();
15 extern boolean level_exists
[];
16 extern struct monst youmonst
;
17 extern char *Doname();
18 extern char *nomovemsg
;
23 return(drop(getobj("0$#", "drop")));
27 drop(obj
) register struct obj
*obj
; {
29 if(obj
->olet
== '$') { /* pseudo object */
30 register long amount
= OGOLD(obj
);
33 pline("You didn't drop any gold pieces.");
35 mkgold(amount
, u
.ux
, u
.uy
);
36 pline("You dropped %ld gold piece%s.",
37 amount
, plur(amount
));
38 if(Invisible
) newsym(u
.ux
, u
.uy
);
43 if(obj
->owornmask
& (W_ARMOR
| W_RING
)){
44 pline("You cannot drop something you are wearing.");
49 pline("Your weapon is welded to your hand!");
52 setuwep((struct obj
*) 0);
54 pline("You dropped %s.", doname(obj
));
59 /* Called in several places - should not produce texts */
61 register struct obj
*obj
;
68 register struct obj
*obj
;
70 if(obj
->otyp
== CRYSKNIFE
)
71 obj
->otyp
= WORM_TOOTH
;
76 if(Invisible
) newsym(u
.ux
,u
.uy
);
81 /* drop several things */
83 return(ggetobj("drop", drop
, 0));
88 if(u
.ux
!= xdnstair
|| u
.uy
!= ydnstair
) {
89 pline("You can't go down here.");
93 pline("You are being held, and cannot go down.");
97 pline("You're floating high above the stairs.");
101 goto_level(dlevel
+1, TRUE
);
107 if(u
.ux
!= xupstair
|| u
.uy
!= yupstair
) {
108 pline("You can't go up here.");
112 pline("You are being held, and cannot go up.");
115 if(!Levitation
&& inv_weight() + 5 > 0) {
116 pline("Your load is too heavy to climb the stairs.");
120 goto_level(dlevel
-1, TRUE
);
124 goto_level(newlevel
, at_stairs
)
125 register int newlevel
;
126 register boolean at_stairs
;
129 register boolean up
= (newlevel
< dlevel
);
131 if(newlevel
<= 0) done("escaped"); /* in fact < 0 is impossible */
132 if(newlevel
> MAXLEVEL
) newlevel
= MAXLEVEL
; /* strange ... */
133 if(newlevel
== dlevel
) return; /* this can happen */
136 fd
= creat(lock
, FMASK
);
139 * This is not quite impossible: e.g., we may have
140 * exceeded our quota. If that is the case then we
141 * cannot leave this level, and cannot save either.
142 * Another possibility is that the directory was not
145 pline("A mysterious force prevents you from going %s.",
150 if(Punished
) unplacebc();
151 u
.utrap
= 0; /* needed in level_tele */
152 u
.ustuck
= 0; /* idem */
155 if(u
.uswallow
) /* idem */
156 u
.uswldtim
= u
.uswallow
= 0;
158 u
.ux
= FAR
; /* hack */
159 (void) inshop(); /* probably was a trapdoor */
165 if(maxdlevel
< dlevel
)
169 if(!level_exists
[dlevel
])
174 if((fd
= open(lock
,0)) < 0) {
175 pline("Cannot open %s .", lock
);
176 pline("Probably someone removed it.");
179 getlev(fd
, hackpid
, dlevel
);
187 if(!u
.ux
) { /* entering a maze from below? */
188 u
.ux
= xupstair
; /* this will confuse the player! */
191 if(Punished
&& !Levitation
){
192 pline("With great effort you climb the stairs.");
198 if(inv_weight() + 5 > 0 || Punished
){
199 pline("You fall down the stairs."); /* %% */
200 losehp(rnd(3), "fall");
202 if(uwep
!= uball
&& rn2(3)){
203 pline("... and are hit by the iron ball.");
204 losehp(rnd(20), "iron ball");
208 selftouch("Falling, you");
211 { register struct monst
*mtmp
= m_at(u
.ux
, u
.uy
);
215 } else { /* trapdoor or level_tele */
219 } while(levl
[u
.ux
][u
.uy
].typ
!= ROOM
||
222 if(uwep
!= uball
&& !up
/* %% */ && rn2(5)){
223 pline("The iron ball falls on your head.");
224 losehp(rnd(25), "iron ball");
228 selftouch("Falling, you");
234 { register struct monst
*mtmp
;
235 if(mtmp
= m_at(u
.ux
, u
.uy
)) mnexto(mtmp
); /* riv05!a3 */
239 seeobjs(); /* make old cadavers disappear - riv05!a3 */
242 read_engr_at(u
.ux
,u
.uy
);
246 return(1); /* Do nothing, but let other things happen */
250 nomovemsg
= "You finished your prayer.";
255 struct monst
*bhit(), *boomhit();
258 register struct obj
*obj
;
259 register struct monst
*mon
;
262 obj
= getobj("#)", "throw"); /* it is also possible to throw food */
263 /* (or jewels, or iron balls ... ) */
264 if(!obj
|| !getdir(1)) /* ask "in what direction?" */
266 if(obj
->owornmask
& (W_ARMOR
| W_RING
)){
267 pline("You can't throw something you are wearing.");
275 pline("Your weapon is welded to your hand.");
279 setuwep(splitobj(obj
, 1));
281 setuwep((struct obj
*) 0);
283 else if(obj
->quan
> 1)
284 (void) splitobj(obj
, 1);
292 pline("%s hits the ceiling, then falls back on top of your head.",
293 Doname(obj
)); /* note: obj->quan == 1 */
294 if(obj
->olet
== POTION_SYM
)
295 potionhit(&youmonst
, obj
);
297 if(uarmh
) pline("Fortunately, you are wearing a helmet!");
298 losehp(uarmh
? 1 : rnd((int)(obj
->owt
)), "falling object");
302 pline("%s hits the floor.", Doname(obj
));
303 if(obj
->otyp
== EXPENSIVE_CAMERA
) {
304 pline("It is shattered in a thousand pieces!");
305 obfree(obj
, Null(obj
));
306 } else if(obj
->otyp
== EGG
) {
307 pline("\"Splash!\"");
308 obfree(obj
, Null(obj
));
309 } else if(obj
->olet
== POTION_SYM
) {
310 pline("The flask breaks, and you smell a peculiar odor ...");
312 obfree(obj
, Null(obj
));
318 } else if(obj
->otyp
== BOOMERANG
) {
319 mon
= boomhit(u
.dx
, u
.dy
);
320 if(mon
== &youmonst
) { /* the thing was caught */
325 if(obj
->otyp
== PICK_AXE
&& shkcatch(obj
))
328 mon
= bhit(u
.dx
, u
.dy
, (obj
->otyp
== ICE_BOX
) ? 1 :
329 (!Punished
|| obj
!= uball
) ? 8 : !u
.ustuck
? 5 : 1,
331 (int (*)()) 0, (int (*)()) 0, obj
);
334 /* awake monster if sleeping */
337 if(obj
->olet
== WEAPON_SYM
) {
338 tmp
= -1+u
.ulevel
+mon
->data
->ac
+abon();
339 if(obj
->otyp
< ROCK
) {
341 uwep
->otyp
!= obj
->otyp
+(BOW
-ARROW
))
347 if(obj
->otyp
== BOOMERANG
) tmp
+= 4;
349 if(u
.uswallow
|| tmp
>= rnd(20)) {
350 if(hmon(mon
,obj
,1) == TRUE
){
351 /* mon still alive */
353 cutworm(mon
,bhitpos
.x
,bhitpos
.y
,obj
->otyp
);
356 /* weapons thrown disappear sometimes */
357 if(obj
->otyp
< BOOMERANG
&& rn2(3)) {
358 /* check bill; free */
359 obfree(obj
, (struct obj
*) 0);
362 } else miss(objects
[obj
->otyp
].oc_name
, mon
);
363 } else if(obj
->otyp
== HEAVY_IRON_BALL
) {
364 tmp
= -1+u
.ulevel
+mon
->data
->ac
+abon();
365 if(!Punished
|| obj
!= uball
) tmp
+= 2;
366 if(u
.utrap
) tmp
-= 2;
367 if(u
.uswallow
|| tmp
>= rnd(20)) {
368 if(hmon(mon
,obj
,1) == FALSE
)
369 mon
= 0; /* he died */
370 } else miss("iron ball", mon
);
371 } else if(obj
->olet
== POTION_SYM
&& u
.ulevel
> rn2(15)) {
375 if(cansee(bhitpos
.x
,bhitpos
.y
))
376 pline("You miss %s.",monnam(mon
));
377 else pline("You miss it.");
378 if(obj
->olet
== FOOD_SYM
&& mon
->data
->mlet
== 'd')
379 if(tamedog(mon
,obj
)) return(1);
380 if(obj
->olet
== GEM_SYM
&& mon
->data
->mlet
== 'u' &&
382 if(obj
->dknown
&& objects
[obj
->otyp
].oc_name_known
){
383 if(objects
[obj
->otyp
].g_val
> 0){
387 pline("%s is not interested in your junk.",
390 } else { /* value unknown to @ */
393 if(u
.uluck
> LUCKMAX
) /* dan@ut-ngp */
395 pline("%s graciously accepts your gift.",
404 /* the code following might become part of dropy() */
405 if(obj
->otyp
== CRYSKNIFE
)
406 obj
->otyp
= WORM_TOOTH
;
411 /* prevent him from throwing articles to the exit and escaping */
412 /* subfrombill(obj); */
414 if(Punished
&& obj
== uball
&&
415 (bhitpos
.x
!= u
.ux
|| bhitpos
.y
!= u
.uy
)){
419 if(u
.utraptype
== TT_PIT
)
420 pline("The ball pulls you out of the pit!");
423 rn2(3) ? LEFT_SIDE
: RIGHT_SIDE
;
424 pline("The ball pulls you out of the bear trap.");
425 pline("Your %s leg is severely damaged.",
426 (side
== LEFT_SIDE
) ? "left" : "right");
427 set_wounded_legs(side
, 500+rn2(1000));
428 losehp(2, "thrown ball");
435 u
.ux
= uchain
->ox
= bhitpos
.x
- u
.dx
;
436 u
.uy
= uchain
->oy
= bhitpos
.y
- u
.dy
;
440 if(cansee(bhitpos
.x
, bhitpos
.y
)) prl(bhitpos
.x
,bhitpos
.y
);
444 /* split obj so that it gets size num */
445 /* remainder is put in the object structure delivered by this call */
447 splitobj(obj
, num
) register struct obj
*obj
; register int num
; {
448 register struct obj
*otmp
;
450 *otmp
= *obj
; /* copies whole structure */
451 otmp
->o_id
= flags
.ident
++;
454 obj
->owt
= weight(obj
);
456 otmp
->owt
= weight(otmp
); /* -= obj->owt ? */
458 if(obj
->unpaid
) splitbill(obj
,otmp
);
462 more_experienced(exp
,rexp
)
463 register int exp
, rexp
;
465 extern char pl_character
[];
468 u
.urexp
+= 4*exp
+ rexp
;
469 if(exp
) flags
.botl
= 1;
470 if(u
.urexp
>= ((pl_character
[0] == 'W') ? 1000 : 2000))
474 set_wounded_legs(side
, timex
)
478 if(!Wounded_legs
|| (Wounded_legs
& TIMEOUT
))
479 Wounded_legs
|= side
+ timex
;
481 Wounded_legs
|= side
;
487 if((Wounded_legs
& BOTH_SIDES
) == BOTH_SIDES
)
488 pline("Your legs feel somewhat better.");
490 pline("Your leg feels somewhat better.");