1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.do.c - version 1.0.3 */
4 /* Contains code for 'd', 'D' (drop), '>', '<' (up, down) and 't' (throw) */
8 extern struct obj *splitobj(), *addinv();
10 extern boolean level_exists[];
11 extern struct monst youmonst;
12 extern char *Doname();
13 extern char *nomovemsg;
18 return(drop(getobj("0$#", "drop")));
22 drop(obj) register struct obj *obj; {
24 if(obj->olet == '$') { /* pseudo object */
25 register long amount = OGOLD(obj);
28 pline("You didn't drop any gold pieces.");
30 mkgold(amount, u.ux, u.uy);
31 pline("You dropped %ld gold piece%s.",
32 amount, plur(amount));
33 if(Invisible) newsym(u.ux, u.uy);
38 if(obj->owornmask & (W_ARMOR | W_RING)){
39 pline("You cannot drop something you are wearing.");
44 pline("Your weapon is welded to your hand!");
47 setuwep((struct obj *) 0);
49 pline("You dropped %s.", doname(obj));
54 /* Called in several places - should not produce texts */
56 register struct obj *obj;
63 register struct obj *obj;
65 if(obj->otyp == CRYSKNIFE)
66 obj->otyp = WORM_TOOTH;
71 if(Invisible) newsym(u.ux,u.uy);
76 /* drop several things */
78 return(ggetobj("drop", drop, 0));
83 if(u.ux != xdnstair || u.uy != ydnstair) {
84 pline("You can't go down here.");
88 pline("You are being held, and cannot go down.");
92 pline("You're floating high above the stairs.");
96 goto_level(dlevel+1, TRUE);
102 if(u.ux != xupstair || u.uy != yupstair) {
103 pline("You can't go up here.");
107 pline("You are being held, and cannot go up.");
110 if(!Levitation && inv_weight() + 5 > 0) {
111 pline("Your load is too heavy to climb the stairs.");
115 goto_level(dlevel-1, TRUE);
119 goto_level(newlevel, at_stairs)
120 register int newlevel;
121 register boolean at_stairs;
124 register boolean up = (newlevel < dlevel);
126 if(newlevel <= 0) done("escaped"); /* in fact < 0 is impossible */
127 if(newlevel > MAXLEVEL) newlevel = MAXLEVEL; /* strange ... */
128 if(newlevel == dlevel) return; /* this can happen */
131 fd = creat(lock, FMASK);
134 * This is not quite impossible: e.g., we may have
135 * exceeded our quota. If that is the case then we
136 * cannot leave this level, and cannot save either.
137 * Another possibility is that the directory was not
140 pline("A mysterious force prevents you from going %s.",
145 if(Punished) unplacebc();
146 u.utrap = 0; /* needed in level_tele */
147 u.ustuck = 0; /* idem */
150 if(u.uswallow) /* idem */
151 u.uswldtim = u.uswallow = 0;
153 u.ux = FAR; /* hack */
154 (void) inshop(); /* probably was a trapdoor */
160 if(maxdlevel < dlevel)
164 if(!level_exists[dlevel])
169 if((fd = open(lock,0)) < 0) {
170 pline("Cannot open %s .", lock);
171 pline("Probably someone removed it.");
174 getlev(fd, hackpid, dlevel);
182 if(!u.ux) { /* entering a maze from below? */
183 u.ux = xupstair; /* this will confuse the player! */
186 if(Punished && !Levitation){
187 pline("With great effort you climb the stairs.");
193 if(inv_weight() + 5 > 0 || Punished){
194 pline("You fall down the stairs."); /* %% */
195 losehp(rnd(3), "fall");
197 if(uwep != uball && rn2(3)){
198 pline("... and are hit by the iron ball.");
199 losehp(rnd(20), "iron ball");
203 selftouch("Falling, you");
206 { register struct monst *mtmp = m_at(u.ux, u.uy);
210 } else { /* trapdoor or level_tele */
214 } while(levl[u.ux][u.uy].typ != ROOM ||
217 if(uwep != uball && !up /* %% */ && rn2(5)){
218 pline("The iron ball falls on your head.");
219 losehp(rnd(25), "iron ball");
223 selftouch("Falling, you");
229 { register struct monst *mtmp;
230 if(mtmp = m_at(u.ux, u.uy)) mnexto(mtmp); /* riv05!a3 */
234 seeobjs(); /* make old cadavers disappear - riv05!a3 */
237 read_engr_at(u.ux,u.uy);
241 return(1); /* Do nothing, but let other things happen */
245 nomovemsg = "You finished your prayer.";
250 struct monst *bhit(), *boomhit();
253 register struct obj *obj;
254 register struct monst *mon;
257 obj = getobj("#)", "throw"); /* it is also possible to throw food */
258 /* (or jewels, or iron balls ... ) */
259 if(!obj || !getdir(1)) /* ask "in what direction?" */
261 if(obj->owornmask & (W_ARMOR | W_RING)){
262 pline("You can't throw something you are wearing.");
270 pline("Your weapon is welded to your hand.");
274 setuwep(splitobj(obj, 1));
276 setuwep((struct obj *) 0);
278 else if(obj->quan > 1)
279 (void) splitobj(obj, 1);
287 pline("%s hits the ceiling, then falls back on top of your head.",
288 Doname(obj)); /* note: obj->quan == 1 */
289 if(obj->olet == POTION_SYM)
290 potionhit(&youmonst, obj);
292 if(uarmh) pline("Fortunately, you are wearing a helmet!");
293 losehp(uarmh ? 1 : rnd((int)(obj->owt)), "falling object");
297 pline("%s hits the floor.", Doname(obj));
298 if(obj->otyp == EXPENSIVE_CAMERA) {
299 pline("It is shattered in a thousand pieces!");
300 obfree(obj, Null(obj));
301 } else if(obj->otyp == EGG) {
302 pline("\"Splash!\"");
303 obfree(obj, Null(obj));
304 } else if(obj->olet == POTION_SYM) {
305 pline("The flask breaks, and you smell a peculiar odor ...");
307 obfree(obj, Null(obj));
313 } else if(obj->otyp == BOOMERANG) {
314 mon = boomhit(u.dx, u.dy);
315 if(mon == &youmonst) { /* the thing was caught */
320 if(obj->otyp == PICK_AXE && shkcatch(obj))
323 mon = bhit(u.dx, u.dy, (obj->otyp == ICE_BOX) ? 1 :
324 (!Punished || obj != uball) ? 8 : !u.ustuck ? 5 : 1,
326 (int (*)()) 0, (int (*)()) 0, obj);
329 /* awake monster if sleeping */
332 if(obj->olet == WEAPON_SYM) {
333 tmp = -1+u.ulevel+mon->data->ac+abon();
334 if(obj->otyp < ROCK) {
336 uwep->otyp != obj->otyp+(BOW-ARROW))
342 if(obj->otyp == BOOMERANG) tmp += 4;
344 if(u.uswallow || tmp >= rnd(20)) {
345 if(hmon(mon,obj,1) == TRUE){
346 /* mon still alive */
348 cutworm(mon,bhitpos.x,bhitpos.y,obj->otyp);
351 /* weapons thrown disappear sometimes */
352 if(obj->otyp < BOOMERANG && rn2(3)) {
353 /* check bill; free */
354 obfree(obj, (struct obj *) 0);
357 } else miss(objects[obj->otyp].oc_name, mon);
358 } else if(obj->otyp == HEAVY_IRON_BALL) {
359 tmp = -1+u.ulevel+mon->data->ac+abon();
360 if(!Punished || obj != uball) tmp += 2;
361 if(u.utrap) tmp -= 2;
362 if(u.uswallow || tmp >= rnd(20)) {
363 if(hmon(mon,obj,1) == FALSE)
364 mon = 0; /* he died */
365 } else miss("iron ball", mon);
366 } else if(obj->olet == POTION_SYM && u.ulevel > rn2(15)) {
370 if(cansee(bhitpos.x,bhitpos.y))
371 pline("You miss %s.",monnam(mon));
372 else pline("You miss it.");
373 if(obj->olet == FOOD_SYM && mon->data->mlet == 'd')
374 if(tamedog(mon,obj)) return(1);
375 if(obj->olet == GEM_SYM && mon->data->mlet == 'u' &&
377 if(obj->dknown && objects[obj->otyp].oc_name_known){
378 if(objects[obj->otyp].g_val > 0){
382 pline("%s is not interested in your junk.",
385 } else { /* value unknown to @ */
388 if(u.uluck > LUCKMAX) /* dan@ut-ngp */
390 pline("%s graciously accepts your gift.",
399 /* the code following might become part of dropy() */
400 if(obj->otyp == CRYSKNIFE)
401 obj->otyp = WORM_TOOTH;
406 /* prevent him from throwing articles to the exit and escaping */
407 /* subfrombill(obj); */
409 if(Punished && obj == uball &&
410 (bhitpos.x != u.ux || bhitpos.y != u.uy)){
414 if(u.utraptype == TT_PIT)
415 pline("The ball pulls you out of the pit!");
418 rn2(3) ? LEFT_SIDE : RIGHT_SIDE;
419 pline("The ball pulls you out of the bear trap.");
420 pline("Your %s leg is severely damaged.",
421 (side == LEFT_SIDE) ? "left" : "right");
422 set_wounded_legs(side, 500+rn2(1000));
423 losehp(2, "thrown ball");
430 u.ux = uchain->ox = bhitpos.x - u.dx;
431 u.uy = uchain->oy = bhitpos.y - u.dy;
435 if(cansee(bhitpos.x, bhitpos.y)) prl(bhitpos.x,bhitpos.y);
439 /* split obj so that it gets size num */
440 /* remainder is put in the object structure delivered by this call */
442 splitobj(obj, num) register struct obj *obj; register int num; {
443 register struct obj *otmp;
445 *otmp = *obj; /* copies whole structure */
446 otmp->o_id = flags.ident++;
449 obj->owt = weight(obj);
451 otmp->owt = weight(otmp); /* -= obj->owt ? */
453 if(obj->unpaid) splitbill(obj,otmp);
457 more_experienced(exp,rexp)
458 register int exp, rexp;
460 extern char pl_character[];
463 u.urexp += 4*exp + rexp;
464 if(exp) flags.botl = 1;
465 if(u.urexp >= ((pl_character[0] == 'W') ? 1000 : 2000))
469 set_wounded_legs(side, timex)
473 if(!Wounded_legs || (Wounded_legs & TIMEOUT))
474 Wounded_legs |= side + timex;
476 Wounded_legs |= side;
482 if((Wounded_legs & BOTH_SIDES) == BOTH_SIDES)
483 pline("Your legs feel somewhat better.");
485 pline("Your leg feels somewhat better.");