141229Sbostic /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
241229Sbostic /* hack.do.c - version 1.0.3 */
341229Sbostic
441229Sbostic /* Contains code for 'd', 'D' (drop), '>', '<' (up, down) and 't' (throw) */
541229Sbostic
641229Sbostic #include "hack.h"
741229Sbostic
841229Sbostic extern struct obj *splitobj(), *addinv();
941229Sbostic extern boolean hmon();
1041229Sbostic extern boolean level_exists[];
1141229Sbostic extern struct monst youmonst;
1241229Sbostic extern char *Doname();
1341229Sbostic extern char *nomovemsg;
1441229Sbostic
15*47700Sbostic static int drop();
16*47700Sbostic
dodrop()1741229Sbostic dodrop() {
1841229Sbostic return(drop(getobj("0$#", "drop")));
1941229Sbostic }
2041229Sbostic
21*47700Sbostic static int
drop(obj)2241229Sbostic drop(obj) register struct obj *obj; {
2341229Sbostic if(!obj) return(0);
2441229Sbostic if(obj->olet == '$') { /* pseudo object */
2541229Sbostic register long amount = OGOLD(obj);
2641229Sbostic
2741229Sbostic if(amount == 0)
2841229Sbostic pline("You didn't drop any gold pieces.");
2941229Sbostic else {
3041229Sbostic mkgold(amount, u.ux, u.uy);
3141229Sbostic pline("You dropped %ld gold piece%s.",
3241229Sbostic amount, plur(amount));
3341229Sbostic if(Invisible) newsym(u.ux, u.uy);
3441229Sbostic }
3541229Sbostic free((char *) obj);
3641229Sbostic return(1);
3741229Sbostic }
3841229Sbostic if(obj->owornmask & (W_ARMOR | W_RING)){
3941229Sbostic pline("You cannot drop something you are wearing.");
4041229Sbostic return(0);
4141229Sbostic }
4241229Sbostic if(obj == uwep) {
4341229Sbostic if(uwep->cursed) {
4441229Sbostic pline("Your weapon is welded to your hand!");
4541229Sbostic return(0);
4641229Sbostic }
4741229Sbostic setuwep((struct obj *) 0);
4841229Sbostic }
4941229Sbostic pline("You dropped %s.", doname(obj));
5041229Sbostic dropx(obj);
5141229Sbostic return(1);
5241229Sbostic }
5341229Sbostic
5441229Sbostic /* Called in several places - should not produce texts */
dropx(obj)5541229Sbostic dropx(obj)
5641229Sbostic register struct obj *obj;
5741229Sbostic {
5841229Sbostic freeinv(obj);
5941229Sbostic dropy(obj);
6041229Sbostic }
6141229Sbostic
dropy(obj)6241229Sbostic dropy(obj)
6341229Sbostic register struct obj *obj;
6441229Sbostic {
6541229Sbostic if(obj->otyp == CRYSKNIFE)
6641229Sbostic obj->otyp = WORM_TOOTH;
6741229Sbostic obj->ox = u.ux;
6841229Sbostic obj->oy = u.uy;
6941229Sbostic obj->nobj = fobj;
7041229Sbostic fobj = obj;
7141229Sbostic if(Invisible) newsym(u.ux,u.uy);
7241229Sbostic subfrombill(obj);
7341229Sbostic stackobj(obj);
7441229Sbostic }
7541229Sbostic
7641229Sbostic /* drop several things */
doddrop()7741229Sbostic doddrop() {
7841229Sbostic return(ggetobj("drop", drop, 0));
7941229Sbostic }
8041229Sbostic
dodown()8141229Sbostic dodown()
8241229Sbostic {
8341229Sbostic if(u.ux != xdnstair || u.uy != ydnstair) {
8441229Sbostic pline("You can't go down here.");
8541229Sbostic return(0);
8641229Sbostic }
8741229Sbostic if(u.ustuck) {
8841229Sbostic pline("You are being held, and cannot go down.");
8941229Sbostic return(1);
9041229Sbostic }
9141229Sbostic if(Levitation) {
9241229Sbostic pline("You're floating high above the stairs.");
9341229Sbostic return(0);
9441229Sbostic }
9541229Sbostic
9641229Sbostic goto_level(dlevel+1, TRUE);
9741229Sbostic return(1);
9841229Sbostic }
9941229Sbostic
doup()10041229Sbostic doup()
10141229Sbostic {
10241229Sbostic if(u.ux != xupstair || u.uy != yupstair) {
10341229Sbostic pline("You can't go up here.");
10441229Sbostic return(0);
10541229Sbostic }
10641229Sbostic if(u.ustuck) {
10741229Sbostic pline("You are being held, and cannot go up.");
10841229Sbostic return(1);
10941229Sbostic }
11041229Sbostic if(!Levitation && inv_weight() + 5 > 0) {
11141229Sbostic pline("Your load is too heavy to climb the stairs.");
11241229Sbostic return(1);
11341229Sbostic }
11441229Sbostic
11541229Sbostic goto_level(dlevel-1, TRUE);
11641229Sbostic return(1);
11741229Sbostic }
11841229Sbostic
goto_level(newlevel,at_stairs)11941229Sbostic goto_level(newlevel, at_stairs)
12041229Sbostic register int newlevel;
12141229Sbostic register boolean at_stairs;
12241229Sbostic {
12341229Sbostic register fd;
12441229Sbostic register boolean up = (newlevel < dlevel);
12541229Sbostic
12641229Sbostic if(newlevel <= 0) done("escaped"); /* in fact < 0 is impossible */
12741229Sbostic if(newlevel > MAXLEVEL) newlevel = MAXLEVEL; /* strange ... */
12841229Sbostic if(newlevel == dlevel) return; /* this can happen */
12941229Sbostic
13041229Sbostic glo(dlevel);
13141229Sbostic fd = creat(lock, FMASK);
13241229Sbostic if(fd < 0) {
13341229Sbostic /*
13441229Sbostic * This is not quite impossible: e.g., we may have
13541229Sbostic * exceeded our quota. If that is the case then we
13641229Sbostic * cannot leave this level, and cannot save either.
13741229Sbostic * Another possibility is that the directory was not
13841229Sbostic * writable.
13941229Sbostic */
14041229Sbostic pline("A mysterious force prevents you from going %s.",
14141229Sbostic up ? "up" : "down");
14241229Sbostic return;
14341229Sbostic }
14441229Sbostic
14541229Sbostic if(Punished) unplacebc();
14641229Sbostic u.utrap = 0; /* needed in level_tele */
14741229Sbostic u.ustuck = 0; /* idem */
14841229Sbostic keepdogs();
14941229Sbostic seeoff(1);
15041229Sbostic if(u.uswallow) /* idem */
15141229Sbostic u.uswldtim = u.uswallow = 0;
15241229Sbostic flags.nscrinh = 1;
15341229Sbostic u.ux = FAR; /* hack */
15441229Sbostic (void) inshop(); /* probably was a trapdoor */
15541229Sbostic
15641229Sbostic savelev(fd,dlevel);
15741229Sbostic (void) close(fd);
15841229Sbostic
15941229Sbostic dlevel = newlevel;
16041229Sbostic if(maxdlevel < dlevel)
16141229Sbostic maxdlevel = dlevel;
16241229Sbostic glo(dlevel);
16341229Sbostic
16441229Sbostic if(!level_exists[dlevel])
16541229Sbostic mklev();
16641229Sbostic else {
16741229Sbostic extern int hackpid;
16841229Sbostic
16941229Sbostic if((fd = open(lock,0)) < 0) {
17041229Sbostic pline("Cannot open %s .", lock);
17141229Sbostic pline("Probably someone removed it.");
17241229Sbostic done("tricked");
17341229Sbostic }
17441229Sbostic getlev(fd, hackpid, dlevel);
17541229Sbostic (void) close(fd);
17641229Sbostic }
17741229Sbostic
17841229Sbostic if(at_stairs) {
17941229Sbostic if(up) {
18041229Sbostic u.ux = xdnstair;
18141229Sbostic u.uy = ydnstair;
18241229Sbostic if(!u.ux) { /* entering a maze from below? */
18341229Sbostic u.ux = xupstair; /* this will confuse the player! */
18441229Sbostic u.uy = yupstair;
18541229Sbostic }
18641229Sbostic if(Punished && !Levitation){
18741229Sbostic pline("With great effort you climb the stairs.");
18841229Sbostic placebc(1);
18941229Sbostic }
19041229Sbostic } else {
19141229Sbostic u.ux = xupstair;
19241229Sbostic u.uy = yupstair;
19341229Sbostic if(inv_weight() + 5 > 0 || Punished){
19441229Sbostic pline("You fall down the stairs."); /* %% */
19541229Sbostic losehp(rnd(3), "fall");
19641229Sbostic if(Punished) {
19741229Sbostic if(uwep != uball && rn2(3)){
19841229Sbostic pline("... and are hit by the iron ball.");
19941229Sbostic losehp(rnd(20), "iron ball");
20041229Sbostic }
20141229Sbostic placebc(1);
20241229Sbostic }
20341229Sbostic selftouch("Falling, you");
20441229Sbostic }
20541229Sbostic }
20641229Sbostic { register struct monst *mtmp = m_at(u.ux, u.uy);
20741229Sbostic if(mtmp)
20841229Sbostic mnexto(mtmp);
20941229Sbostic }
21041229Sbostic } else { /* trapdoor or level_tele */
21141229Sbostic do {
21241229Sbostic u.ux = rnd(COLNO-1);
21341229Sbostic u.uy = rn2(ROWNO);
21441229Sbostic } while(levl[u.ux][u.uy].typ != ROOM ||
21541229Sbostic m_at(u.ux,u.uy));
21641229Sbostic if(Punished){
21741229Sbostic if(uwep != uball && !up /* %% */ && rn2(5)){
21841229Sbostic pline("The iron ball falls on your head.");
21941229Sbostic losehp(rnd(25), "iron ball");
22041229Sbostic }
22141229Sbostic placebc(1);
22241229Sbostic }
22341229Sbostic selftouch("Falling, you");
22441229Sbostic }
22541229Sbostic (void) inshop();
22641229Sbostic initrack();
22741229Sbostic
22841229Sbostic losedogs();
22941229Sbostic { register struct monst *mtmp;
23041229Sbostic if(mtmp = m_at(u.ux, u.uy)) mnexto(mtmp); /* riv05!a3 */
23141229Sbostic }
23241229Sbostic flags.nscrinh = 0;
23341229Sbostic setsee();
23441229Sbostic seeobjs(); /* make old cadavers disappear - riv05!a3 */
23541229Sbostic docrt();
23641229Sbostic pickup(1);
23741229Sbostic read_engr_at(u.ux,u.uy);
23841229Sbostic }
23941229Sbostic
donull()24041229Sbostic donull() {
24141229Sbostic return(1); /* Do nothing, but let other things happen */
24241229Sbostic }
24341229Sbostic
dopray()24441229Sbostic dopray() {
24541229Sbostic nomovemsg = "You finished your prayer.";
24641229Sbostic nomul(-3);
24741229Sbostic return(1);
24841229Sbostic }
24941229Sbostic
25041229Sbostic struct monst *bhit(), *boomhit();
dothrow()25141229Sbostic dothrow()
25241229Sbostic {
25341229Sbostic register struct obj *obj;
25441229Sbostic register struct monst *mon;
25541229Sbostic register tmp;
25641229Sbostic
25741229Sbostic obj = getobj("#)", "throw"); /* it is also possible to throw food */
25841229Sbostic /* (or jewels, or iron balls ... ) */
25941229Sbostic if(!obj || !getdir(1)) /* ask "in what direction?" */
26041229Sbostic return(0);
26141229Sbostic if(obj->owornmask & (W_ARMOR | W_RING)){
26241229Sbostic pline("You can't throw something you are wearing.");
26341229Sbostic return(0);
26441229Sbostic }
26541229Sbostic
26641229Sbostic u_wipe_engr(2);
26741229Sbostic
26841229Sbostic if(obj == uwep){
26941229Sbostic if(obj->cursed){
27041229Sbostic pline("Your weapon is welded to your hand.");
27141229Sbostic return(1);
27241229Sbostic }
27341229Sbostic if(obj->quan > 1)
27441229Sbostic setuwep(splitobj(obj, 1));
27541229Sbostic else
27641229Sbostic setuwep((struct obj *) 0);
27741229Sbostic }
27841229Sbostic else if(obj->quan > 1)
27941229Sbostic (void) splitobj(obj, 1);
28041229Sbostic freeinv(obj);
28141229Sbostic if(u.uswallow) {
28241229Sbostic mon = u.ustuck;
28341229Sbostic bhitpos.x = mon->mx;
28441229Sbostic bhitpos.y = mon->my;
28541229Sbostic } else if(u.dz) {
28641229Sbostic if(u.dz < 0) {
28741229Sbostic pline("%s hits the ceiling, then falls back on top of your head.",
28841229Sbostic Doname(obj)); /* note: obj->quan == 1 */
28941229Sbostic if(obj->olet == POTION_SYM)
29041229Sbostic potionhit(&youmonst, obj);
29141229Sbostic else {
29241229Sbostic if(uarmh) pline("Fortunately, you are wearing a helmet!");
29341229Sbostic losehp(uarmh ? 1 : rnd((int)(obj->owt)), "falling object");
29441229Sbostic dropy(obj);
29541229Sbostic }
29641229Sbostic } else {
29741229Sbostic pline("%s hits the floor.", Doname(obj));
29841229Sbostic if(obj->otyp == EXPENSIVE_CAMERA) {
29941229Sbostic pline("It is shattered in a thousand pieces!");
30041229Sbostic obfree(obj, Null(obj));
30141229Sbostic } else if(obj->otyp == EGG) {
30241229Sbostic pline("\"Splash!\"");
30341229Sbostic obfree(obj, Null(obj));
30441229Sbostic } else if(obj->olet == POTION_SYM) {
30541229Sbostic pline("The flask breaks, and you smell a peculiar odor ...");
30641229Sbostic potionbreathe(obj);
30741229Sbostic obfree(obj, Null(obj));
30841229Sbostic } else {
30941229Sbostic dropy(obj);
31041229Sbostic }
31141229Sbostic }
31241229Sbostic return(1);
31341229Sbostic } else if(obj->otyp == BOOMERANG) {
31441229Sbostic mon = boomhit(u.dx, u.dy);
31541229Sbostic if(mon == &youmonst) { /* the thing was caught */
31641229Sbostic (void) addinv(obj);
31741229Sbostic return(1);
31841229Sbostic }
31941229Sbostic } else {
32041229Sbostic if(obj->otyp == PICK_AXE && shkcatch(obj))
32141229Sbostic return(1);
32241229Sbostic
32341229Sbostic mon = bhit(u.dx, u.dy, (obj->otyp == ICE_BOX) ? 1 :
32441229Sbostic (!Punished || obj != uball) ? 8 : !u.ustuck ? 5 : 1,
32541229Sbostic obj->olet,
32641229Sbostic (int (*)()) 0, (int (*)()) 0, obj);
32741229Sbostic }
32841229Sbostic if(mon) {
32941229Sbostic /* awake monster if sleeping */
33041229Sbostic wakeup(mon);
33141229Sbostic
33241229Sbostic if(obj->olet == WEAPON_SYM) {
33341229Sbostic tmp = -1+u.ulevel+mon->data->ac+abon();
33441229Sbostic if(obj->otyp < ROCK) {
33541229Sbostic if(!uwep ||
33641229Sbostic uwep->otyp != obj->otyp+(BOW-ARROW))
33741229Sbostic tmp -= 4;
33841229Sbostic else {
33941229Sbostic tmp += uwep->spe;
34041229Sbostic }
34141229Sbostic } else
34241229Sbostic if(obj->otyp == BOOMERANG) tmp += 4;
34341229Sbostic tmp += obj->spe;
34441229Sbostic if(u.uswallow || tmp >= rnd(20)) {
34541229Sbostic if(hmon(mon,obj,1) == TRUE){
34641229Sbostic /* mon still alive */
34741229Sbostic #ifndef NOWORM
34841229Sbostic cutworm(mon,bhitpos.x,bhitpos.y,obj->otyp);
34941229Sbostic #endif NOWORM
35041229Sbostic } else mon = 0;
35141229Sbostic /* weapons thrown disappear sometimes */
35241229Sbostic if(obj->otyp < BOOMERANG && rn2(3)) {
35341229Sbostic /* check bill; free */
35441229Sbostic obfree(obj, (struct obj *) 0);
35541229Sbostic return(1);
35641229Sbostic }
35741229Sbostic } else miss(objects[obj->otyp].oc_name, mon);
35841229Sbostic } else if(obj->otyp == HEAVY_IRON_BALL) {
35941229Sbostic tmp = -1+u.ulevel+mon->data->ac+abon();
36041229Sbostic if(!Punished || obj != uball) tmp += 2;
36141229Sbostic if(u.utrap) tmp -= 2;
36241229Sbostic if(u.uswallow || tmp >= rnd(20)) {
36341229Sbostic if(hmon(mon,obj,1) == FALSE)
36441229Sbostic mon = 0; /* he died */
36541229Sbostic } else miss("iron ball", mon);
36641229Sbostic } else if(obj->olet == POTION_SYM && u.ulevel > rn2(15)) {
36741229Sbostic potionhit(mon, obj);
36841229Sbostic return(1);
36941229Sbostic } else {
37041229Sbostic if(cansee(bhitpos.x,bhitpos.y))
37141229Sbostic pline("You miss %s.",monnam(mon));
37241229Sbostic else pline("You miss it.");
37341229Sbostic if(obj->olet == FOOD_SYM && mon->data->mlet == 'd')
37441229Sbostic if(tamedog(mon,obj)) return(1);
37541229Sbostic if(obj->olet == GEM_SYM && mon->data->mlet == 'u' &&
37641229Sbostic !mon->mtame){
37741229Sbostic if(obj->dknown && objects[obj->otyp].oc_name_known){
37841229Sbostic if(objects[obj->otyp].g_val > 0){
37941229Sbostic u.uluck += 5;
38041229Sbostic goto valuable;
38141229Sbostic } else {
38241229Sbostic pline("%s is not interested in your junk.",
38341229Sbostic Monnam(mon));
38441229Sbostic }
38541229Sbostic } else { /* value unknown to @ */
38641229Sbostic u.uluck++;
38741229Sbostic valuable:
38841229Sbostic if(u.uluck > LUCKMAX) /* dan@ut-ngp */
38941229Sbostic u.uluck = LUCKMAX;
39041229Sbostic pline("%s graciously accepts your gift.",
39141229Sbostic Monnam(mon));
39241229Sbostic mpickobj(mon, obj);
39341229Sbostic rloc(mon);
39441229Sbostic return(1);
39541229Sbostic }
39641229Sbostic }
39741229Sbostic }
39841229Sbostic }
39941229Sbostic /* the code following might become part of dropy() */
40041229Sbostic if(obj->otyp == CRYSKNIFE)
40141229Sbostic obj->otyp = WORM_TOOTH;
40241229Sbostic obj->ox = bhitpos.x;
40341229Sbostic obj->oy = bhitpos.y;
40441229Sbostic obj->nobj = fobj;
40541229Sbostic fobj = obj;
40641229Sbostic /* prevent him from throwing articles to the exit and escaping */
40741229Sbostic /* subfrombill(obj); */
40841229Sbostic stackobj(obj);
40941229Sbostic if(Punished && obj == uball &&
41041229Sbostic (bhitpos.x != u.ux || bhitpos.y != u.uy)){
41141229Sbostic freeobj(uchain);
41241229Sbostic unpobj(uchain);
41341229Sbostic if(u.utrap){
41441229Sbostic if(u.utraptype == TT_PIT)
41541229Sbostic pline("The ball pulls you out of the pit!");
41641229Sbostic else {
41741229Sbostic register long side =
41841229Sbostic rn2(3) ? LEFT_SIDE : RIGHT_SIDE;
41941229Sbostic pline("The ball pulls you out of the bear trap.");
42041229Sbostic pline("Your %s leg is severely damaged.",
42141229Sbostic (side == LEFT_SIDE) ? "left" : "right");
42241229Sbostic set_wounded_legs(side, 500+rn2(1000));
42341229Sbostic losehp(2, "thrown ball");
42441229Sbostic }
42541229Sbostic u.utrap = 0;
42641229Sbostic }
42741229Sbostic unsee();
42841229Sbostic uchain->nobj = fobj;
42941229Sbostic fobj = uchain;
43041229Sbostic u.ux = uchain->ox = bhitpos.x - u.dx;
43141229Sbostic u.uy = uchain->oy = bhitpos.y - u.dy;
43241229Sbostic setsee();
43341229Sbostic (void) inshop();
43441229Sbostic }
43541229Sbostic if(cansee(bhitpos.x, bhitpos.y)) prl(bhitpos.x,bhitpos.y);
43641229Sbostic return(1);
43741229Sbostic }
43841229Sbostic
43941229Sbostic /* split obj so that it gets size num */
44041229Sbostic /* remainder is put in the object structure delivered by this call */
44141229Sbostic struct obj *
splitobj(obj,num)44241229Sbostic splitobj(obj, num) register struct obj *obj; register int num; {
44341229Sbostic register struct obj *otmp;
44441229Sbostic otmp = newobj(0);
44541229Sbostic *otmp = *obj; /* copies whole structure */
44641229Sbostic otmp->o_id = flags.ident++;
44741229Sbostic otmp->onamelth = 0;
44841229Sbostic obj->quan = num;
44941229Sbostic obj->owt = weight(obj);
45041229Sbostic otmp->quan -= num;
45141229Sbostic otmp->owt = weight(otmp); /* -= obj->owt ? */
45241229Sbostic obj->nobj = otmp;
45341229Sbostic if(obj->unpaid) splitbill(obj,otmp);
45441229Sbostic return(otmp);
45541229Sbostic }
45641229Sbostic
more_experienced(exp,rexp)45741229Sbostic more_experienced(exp,rexp)
45841229Sbostic register int exp, rexp;
45941229Sbostic {
46041229Sbostic extern char pl_character[];
46141229Sbostic
46241229Sbostic u.uexp += exp;
46341229Sbostic u.urexp += 4*exp + rexp;
46441229Sbostic if(exp) flags.botl = 1;
46541229Sbostic if(u.urexp >= ((pl_character[0] == 'W') ? 1000 : 2000))
46641229Sbostic flags.beginner = 0;
46741229Sbostic }
46841229Sbostic
set_wounded_legs(side,timex)46941229Sbostic set_wounded_legs(side, timex)
47041229Sbostic register long side;
47141229Sbostic register int timex;
47241229Sbostic {
47341229Sbostic if(!Wounded_legs || (Wounded_legs & TIMEOUT))
47441229Sbostic Wounded_legs |= side + timex;
47541229Sbostic else
47641229Sbostic Wounded_legs |= side;
47741229Sbostic }
47841229Sbostic
heal_legs()47941229Sbostic heal_legs()
48041229Sbostic {
48141229Sbostic if(Wounded_legs) {
48241229Sbostic if((Wounded_legs & BOTH_SIDES) == BOTH_SIDES)
48341229Sbostic pline("Your legs feel somewhat better.");
48441229Sbostic else
48541229Sbostic pline("Your leg feels somewhat better.");
48641229Sbostic Wounded_legs = 0;
48741229Sbostic }
48841229Sbostic }
489