1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.do.c - version 1.0.3 */
3 /* $FreeBSD: src/games/hack/hack.do.c,v 1.4 1999/11/16 10:26:36 marcel Exp $ */
4 /* $DragonFly: src/games/hack/hack.do.c,v 1.5 2006/08/21 19:45:32 pavalos Exp $ */
6 /* Contains code for 'd', 'D' (drop), '>', '<' (up, down) and 't' (throw) */
10 extern struct monst youmonst
;
12 static int drop(struct obj
*);
13 static void dropy(struct obj
*);
18 return(drop(getobj("0$#", "drop")));
25 if(obj
->olet
== '$') { /* pseudo object */
26 long amount
= OGOLD(obj
);
29 pline("You didn't drop any gold pieces.");
31 mkgold(amount
, u
.ux
, u
.uy
);
32 pline("You dropped %ld gold piece%s.",
33 amount
, plur(amount
));
34 if(Invisible
) newsym(u
.ux
, u
.uy
);
39 if(obj
->owornmask
& (W_ARMOR
| W_RING
)){
40 pline("You cannot drop something you are wearing.");
45 pline("Your weapon is welded to your hand!");
50 pline("You dropped %s.", doname(obj
));
55 /* Called in several places - should not produce texts */
57 dropx(struct obj
*obj
)
64 dropy(struct obj
*obj
)
66 if(obj
->otyp
== CRYSKNIFE
)
67 obj
->otyp
= WORM_TOOTH
;
72 if(Invisible
) newsym(u
.ux
,u
.uy
);
77 /* drop several things */
81 return(ggetobj("drop", drop
, 0));
87 if(u
.ux
!= xdnstair
|| u
.uy
!= ydnstair
) {
88 pline("You can't go down here.");
92 pline("You are being held, and cannot go down.");
96 pline("You're floating high above the stairs.");
100 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
);
125 goto_level(int newlevel
, boolean at_stairs
)
128 boolean up
= (newlevel
< dlevel
);
130 if(newlevel
<= 0) done("escaped"); /* in fact < 0 is impossible */
131 if(newlevel
> MAXLEVEL
) newlevel
= MAXLEVEL
; /* strange ... */
132 if(newlevel
== dlevel
) return; /* this can happen */
135 fd
= creat(lock
, FMASK
);
138 * This is not quite impossible: e.g., we may have
139 * exceeded our quota. If that is the case then we
140 * cannot leave this level, and cannot save either.
141 * Another possibility is that the directory was not
144 pline("A mysterious force prevents you from going %s.",
149 if(Punished
) unplacebc();
150 u
.utrap
= 0; /* needed in level_tele */
151 u
.ustuck
= 0; /* idem */
154 if(u
.uswallow
) /* idem */
155 u
.uswldtim
= u
.uswallow
= 0;
157 u
.ux
= FAR
; /* hack */
158 inshop(); /* probably was a trapdoor */
164 if(maxdlevel
< dlevel
)
168 if(!level_exists
[dlevel
])
171 if((fd
= open(lock
,0)) < 0) {
172 pline("Cannot open %s .", lock
);
173 pline("Probably someone removed it.");
176 getlev(fd
, hackpid
, dlevel
);
184 if(!u
.ux
) { /* entering a maze from below? */
185 u
.ux
= xupstair
; /* this will confuse the player! */
188 if(Punished
&& !Levitation
){
189 pline("With great effort you climb the stairs.");
195 if(inv_weight() + 5 > 0 || Punished
){
196 pline("You fall down the stairs."); /* %% */
197 losehp(rnd(3), "fall");
199 if(uwep
!= uball
&& rn2(3)){
200 pline("... and are hit by the iron ball.");
201 losehp(rnd(20), "iron ball");
205 selftouch("Falling, you");
208 { struct monst
*mtmp
= m_at(u
.ux
, u
.uy
);
212 } else { /* trapdoor or level_tele */
216 } while(levl
[u
.ux
][u
.uy
].typ
!= ROOM
||
219 if(uwep
!= uball
&& !up
/* %% */ && rn2(5)){
220 pline("The iron ball falls on your head.");
221 losehp(rnd(25), "iron ball");
225 selftouch("Falling, you");
231 { struct monst
*mtmp
;
232 if((mtmp
= m_at(u
.ux
, u
.uy
))) mnexto(mtmp
); /* riv05!a3 */
236 seeobjs(); /* make old cadavers disappear - riv05!a3 */
239 read_engr_at(u
.ux
,u
.uy
);
245 return(1); /* Do nothing, but let other things happen */
251 nomovemsg
= "You finished your prayer.";
263 obj
= getobj("#)", "throw"); /* it is also possible to throw food */
264 /* (or jewels, or iron balls ... ) */
265 if(!obj
|| !getdir(1)) /* ask "in what direction?" */
267 if(obj
->owornmask
& (W_ARMOR
| W_RING
)){
268 pline("You can't throw something you are wearing.");
276 pline("Your weapon is welded to your hand.");
280 setuwep(splitobj(obj
, 1));
284 else if(obj
->quan
> 1)
293 pline("%s hits the ceiling, then falls back on top of your head.",
294 Doname(obj
)); /* note: obj->quan == 1 */
295 if(obj
->olet
== POTION_SYM
)
296 potionhit(&youmonst
, obj
);
298 if(uarmh
) pline("Fortunately, you are wearing a helmet!");
299 losehp(uarmh
? 1 : rnd((int)(obj
->owt
)), "falling object");
303 pline("%s hits the floor.", Doname(obj
));
304 if(obj
->otyp
== EXPENSIVE_CAMERA
) {
305 pline("It is shattered in a thousand pieces!");
307 } else if(obj
->otyp
== EGG
) {
308 pline("\"Splash!\"");
310 } else if(obj
->olet
== POTION_SYM
) {
311 pline("The flask breaks, and you smell a peculiar odor ...");
319 } else if(obj
->otyp
== BOOMERANG
) {
320 mon
= boomhit(u
.dx
, u
.dy
);
321 if(mon
== &youmonst
) { /* the thing was caught */
326 if(obj
->otyp
== PICK_AXE
&& shkcatch(obj
))
329 mon
= bhit(u
.dx
, u
.dy
, (obj
->otyp
== ICE_BOX
) ? 1 :
330 (!Punished
|| obj
!= uball
) ? 8 : !u
.ustuck
? 5 : 1,
331 obj
->olet
, (void (*)(struct monst
*, struct obj
*)) 0,
332 (bool (*)(struct obj
*, struct obj
*)) 0, obj
);
335 /* awake monster if sleeping */
338 if(obj
->olet
== WEAPON_SYM
) {
339 tmp
= -1+u
.ulevel
+mon
->data
->ac
+abon();
340 if(obj
->otyp
< ROCK
) {
342 uwep
->otyp
!= obj
->otyp
+(BOW
-ARROW
))
348 if(obj
->otyp
== BOOMERANG
) tmp
+= 4;
350 if(u
.uswallow
|| tmp
>= rnd(20)) {
351 if(hmon(mon
,obj
,1) == TRUE
){
352 /* mon still alive */
354 cutworm(mon
,bhitpos
.x
,bhitpos
.y
,obj
->otyp
);
357 /* weapons thrown disappear sometimes */
358 if(obj
->otyp
< BOOMERANG
&& rn2(3)) {
359 /* check bill; free */
363 } else miss(objects
[obj
->otyp
].oc_name
, mon
);
364 } else if(obj
->otyp
== HEAVY_IRON_BALL
) {
365 tmp
= -1+u
.ulevel
+mon
->data
->ac
+abon();
366 if(!Punished
|| obj
!= uball
) tmp
+= 2;
367 if(u
.utrap
) tmp
-= 2;
368 if(u
.uswallow
|| tmp
>= rnd(20)) {
369 if(hmon(mon
,obj
,1) == FALSE
)
370 mon
= 0; /* he died */
371 } else miss("iron ball", mon
);
372 } else if(obj
->olet
== POTION_SYM
&& u
.ulevel
> rn2(15)) {
376 if(cansee(bhitpos
.x
,bhitpos
.y
))
377 pline("You miss %s.",monnam(mon
));
378 else pline("You miss it.");
379 if(obj
->olet
== FOOD_SYM
&& mon
->data
->mlet
== 'd')
380 if(tamedog(mon
,obj
)) return(1);
381 if(obj
->olet
== GEM_SYM
&& mon
->data
->mlet
== 'u' &&
383 if(obj
->dknown
&& objects
[obj
->otyp
].oc_name_known
){
384 if(objects
[obj
->otyp
].g_val
> 0){
388 pline("%s is not interested in your junk.",
391 } else { /* value unknown to @ */
394 if(u
.uluck
> LUCKMAX
) /* dan@ut-ngp */
396 pline("%s graciously accepts your gift.",
405 /* the code following might become part of dropy() */
406 if(obj
->otyp
== CRYSKNIFE
)
407 obj
->otyp
= WORM_TOOTH
;
412 /* prevent him from throwing articles to the exit and escaping */
413 /* subfrombill(obj); */
415 if(Punished
&& obj
== uball
&&
416 (bhitpos
.x
!= u
.ux
|| bhitpos
.y
!= u
.uy
)){
420 if(u
.utraptype
== TT_PIT
)
421 pline("The ball pulls you out of the pit!");
424 rn2(3) ? LEFT_SIDE
: RIGHT_SIDE
;
425 pline("The ball pulls you out of the bear trap.");
426 pline("Your %s leg is severely damaged.",
427 (side
== LEFT_SIDE
) ? "left" : "right");
428 set_wounded_legs(side
, 500+rn2(1000));
429 losehp(2, "thrown ball");
436 u
.ux
= uchain
->ox
= bhitpos
.x
- u
.dx
;
437 u
.uy
= uchain
->oy
= bhitpos
.y
- u
.dy
;
441 if(cansee(bhitpos
.x
, bhitpos
.y
)) prl(bhitpos
.x
,bhitpos
.y
);
445 /* split obj so that it gets size num */
446 /* remainder is put in the object structure delivered by this call */
448 splitobj(struct obj
*obj
, int num
)
452 *otmp
= *obj
; /* copies whole structure */
453 otmp
->o_id
= flags
.ident
++;
456 obj
->owt
= weight(obj
);
458 otmp
->owt
= weight(otmp
); /* -= obj->owt ? */
460 if(obj
->unpaid
) splitbill(obj
,otmp
);
465 more_experienced(int exp
, int rexp
)
468 u
.urexp
+= 4*exp
+ rexp
;
469 if(exp
) flags
.botl
= 1;
470 if(u
.urexp
>= ((pl_character
[0] == 'W') ? 1000 : 2000))
475 set_wounded_legs(long side
, int timex
)
477 if(!Wounded_legs
|| (Wounded_legs
& TIMEOUT
))
478 Wounded_legs
|= side
+ timex
;
480 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.");