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.4 2005/05/22 03:37:05 y0netan1 Exp $ */
6 /* Contains code for 'd', 'D' (drop), '>', '<' (up, down) and 't' (throw) */
10 extern struct obj *splitobj(), *addinv();
11 extern boolean hmon();
12 extern boolean level_exists[];
13 extern struct monst youmonst;
14 extern char *Doname();
19 return(drop(getobj("0$#", "drop")));
23 drop(obj) struct obj *obj; {
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!");
48 setuwep((struct obj *) 0);
50 pline("You dropped %s.", doname(obj));
55 /* Called in several places - should not produce texts */
66 if(obj->otyp == CRYSKNIFE)
67 obj->otyp = WORM_TOOTH;
72 if(Invisible) newsym(u.ux,u.uy);
77 /* drop several things */
79 return(ggetobj("drop", drop, 0));
84 if(u.ux != xdnstair || u.uy != ydnstair) {
85 pline("You can't go down here.");
89 pline("You are being held, and cannot go down.");
93 pline("You're floating high above the stairs.");
97 goto_level(dlevel+1, TRUE);
103 if(u.ux != xupstair || u.uy != yupstair) {
104 pline("You can't go up here.");
108 pline("You are being held, and cannot go up.");
111 if(!Levitation && inv_weight() + 5 > 0) {
112 pline("Your load is too heavy to climb the stairs.");
116 goto_level(dlevel-1, TRUE);
120 goto_level(newlevel, at_stairs)
125 boolean up = (newlevel < dlevel);
127 if(newlevel <= 0) done("escaped"); /* in fact < 0 is impossible */
128 if(newlevel > MAXLEVEL) newlevel = MAXLEVEL; /* strange ... */
129 if(newlevel == dlevel) return; /* this can happen */
132 fd = creat(lock, FMASK);
135 * This is not quite impossible: e.g., we may have
136 * exceeded our quota. If that is the case then we
137 * cannot leave this level, and cannot save either.
138 * Another possibility is that the directory was not
141 pline("A mysterious force prevents you from going %s.",
146 if(Punished) unplacebc();
147 u.utrap = 0; /* needed in level_tele */
148 u.ustuck = 0; /* idem */
151 if(u.uswallow) /* idem */
152 u.uswldtim = u.uswallow = 0;
154 u.ux = FAR; /* hack */
155 (void) inshop(); /* probably was a trapdoor */
161 if(maxdlevel < dlevel)
165 if(!level_exists[dlevel])
170 if((fd = open(lock,0)) < 0) {
171 pline("Cannot open %s .", lock);
172 pline("Probably someone removed it.");
175 getlev(fd, hackpid, dlevel);
183 if(!u.ux) { /* entering a maze from below? */
184 u.ux = xupstair; /* this will confuse the player! */
187 if(Punished && !Levitation){
188 pline("With great effort you climb the stairs.");
194 if(inv_weight() + 5 > 0 || Punished){
195 pline("You fall down the stairs."); /* %% */
196 losehp(rnd(3), "fall");
198 if(uwep != uball && rn2(3)){
199 pline("... and are hit by the iron ball.");
200 losehp(rnd(20), "iron ball");
204 selftouch("Falling, you");
207 { struct monst *mtmp = m_at(u.ux, u.uy);
211 } else { /* trapdoor or level_tele */
215 } while(levl[u.ux][u.uy].typ != ROOM ||
218 if(uwep != uball && !up /* %% */ && rn2(5)){
219 pline("The iron ball falls on your head.");
220 losehp(rnd(25), "iron ball");
224 selftouch("Falling, you");
230 { struct monst *mtmp;
231 if(mtmp = m_at(u.ux, u.uy)) mnexto(mtmp); /* riv05!a3 */
235 seeobjs(); /* make old cadavers disappear - riv05!a3 */
238 read_engr_at(u.ux,u.uy);
242 return(1); /* Do nothing, but let other things happen */
246 nomovemsg = "You finished your prayer.";
251 struct monst *bhit(), *boomhit();
258 obj = getobj("#)", "throw"); /* it is also possible to throw food */
259 /* (or jewels, or iron balls ... ) */
260 if(!obj || !getdir(1)) /* ask "in what direction?" */
262 if(obj->owornmask & (W_ARMOR | W_RING)){
263 pline("You can't throw something you are wearing.");
271 pline("Your weapon is welded to your hand.");
275 setuwep(splitobj(obj, 1));
277 setuwep((struct obj *) 0);
279 else if(obj->quan > 1)
280 (void) splitobj(obj, 1);
288 pline("%s hits the ceiling, then falls back on top of your head.",
289 Doname(obj)); /* note: obj->quan == 1 */
290 if(obj->olet == POTION_SYM)
291 potionhit(&youmonst, obj);
293 if(uarmh) pline("Fortunately, you are wearing a helmet!");
294 losehp(uarmh ? 1 : rnd((int)(obj->owt)), "falling object");
298 pline("%s hits the floor.", Doname(obj));
299 if(obj->otyp == EXPENSIVE_CAMERA) {
300 pline("It is shattered in a thousand pieces!");
301 obfree(obj, Null(obj));
302 } else if(obj->otyp == EGG) {
303 pline("\"Splash!\"");
304 obfree(obj, Null(obj));
305 } else if(obj->olet == POTION_SYM) {
306 pline("The flask breaks, and you smell a peculiar odor ...");
308 obfree(obj, Null(obj));
314 } else if(obj->otyp == BOOMERANG) {
315 mon = boomhit(u.dx, u.dy);
316 if(mon == &youmonst) { /* the thing was caught */
321 if(obj->otyp == PICK_AXE && shkcatch(obj))
324 mon = bhit(u.dx, u.dy, (obj->otyp == ICE_BOX) ? 1 :
325 (!Punished || obj != uball) ? 8 : !u.ustuck ? 5 : 1,
327 (int (*)()) 0, (int (*)()) 0, obj);
330 /* awake monster if sleeping */
333 if(obj->olet == WEAPON_SYM) {
334 tmp = -1+u.ulevel+mon->data->ac+abon();
335 if(obj->otyp < ROCK) {
337 uwep->otyp != obj->otyp+(BOW-ARROW))
343 if(obj->otyp == BOOMERANG) tmp += 4;
345 if(u.uswallow || tmp >= rnd(20)) {
346 if(hmon(mon,obj,1) == TRUE){
347 /* mon still alive */
349 cutworm(mon,bhitpos.x,bhitpos.y,obj->otyp);
352 /* weapons thrown disappear sometimes */
353 if(obj->otyp < BOOMERANG && rn2(3)) {
354 /* check bill; free */
355 obfree(obj, (struct obj *) 0);
358 } else miss(objects[obj->otyp].oc_name, mon);
359 } else if(obj->otyp == HEAVY_IRON_BALL) {
360 tmp = -1+u.ulevel+mon->data->ac+abon();
361 if(!Punished || obj != uball) tmp += 2;
362 if(u.utrap) tmp -= 2;
363 if(u.uswallow || tmp >= rnd(20)) {
364 if(hmon(mon,obj,1) == FALSE)
365 mon = 0; /* he died */
366 } else miss("iron ball", mon);
367 } else if(obj->olet == POTION_SYM && u.ulevel > rn2(15)) {
371 if(cansee(bhitpos.x,bhitpos.y))
372 pline("You miss %s.",monnam(mon));
373 else pline("You miss it.");
374 if(obj->olet == FOOD_SYM && mon->data->mlet == 'd')
375 if(tamedog(mon,obj)) return(1);
376 if(obj->olet == GEM_SYM && mon->data->mlet == 'u' &&
378 if(obj->dknown && objects[obj->otyp].oc_name_known){
379 if(objects[obj->otyp].g_val > 0){
383 pline("%s is not interested in your junk.",
386 } else { /* value unknown to @ */
389 if(u.uluck > LUCKMAX) /* dan@ut-ngp */
391 pline("%s graciously accepts your gift.",
400 /* the code following might become part of dropy() */
401 if(obj->otyp == CRYSKNIFE)
402 obj->otyp = WORM_TOOTH;
407 /* prevent him from throwing articles to the exit and escaping */
408 /* subfrombill(obj); */
410 if(Punished && obj == uball &&
411 (bhitpos.x != u.ux || bhitpos.y != u.uy)){
415 if(u.utraptype == TT_PIT)
416 pline("The ball pulls you out of the pit!");
419 rn2(3) ? LEFT_SIDE : RIGHT_SIDE;
420 pline("The ball pulls you out of the bear trap.");
421 pline("Your %s leg is severely damaged.",
422 (side == LEFT_SIDE) ? "left" : "right");
423 set_wounded_legs(side, 500+rn2(1000));
424 losehp(2, "thrown ball");
431 u.ux = uchain->ox = bhitpos.x - u.dx;
432 u.uy = uchain->oy = bhitpos.y - u.dy;
436 if(cansee(bhitpos.x, bhitpos.y)) prl(bhitpos.x,bhitpos.y);
440 /* split obj so that it gets size num */
441 /* remainder is put in the object structure delivered by this call */
443 splitobj(obj, num) struct obj *obj; int num; {
446 *otmp = *obj; /* copies whole structure */
447 otmp->o_id = flags.ident++;
450 obj->owt = weight(obj);
452 otmp->owt = weight(otmp); /* -= obj->owt ? */
454 if(obj->unpaid) splitbill(obj,otmp);
458 more_experienced(exp,rexp)
461 extern char pl_character[];
464 u.urexp += 4*exp + rexp;
465 if(exp) flags.botl = 1;
466 if(u.urexp >= ((pl_character[0] == 'W') ? 1000 : 2000))
470 set_wounded_legs(side, timex)
474 if(!Wounded_legs || (Wounded_legs & TIMEOUT))
475 Wounded_legs |= side + timex;
477 Wounded_legs |= side;
483 if((Wounded_legs & BOTH_SIDES) == BOTH_SIDES)
484 pline("Your legs feel somewhat better.");
486 pline("Your leg feels somewhat better.");