コード例 #1
0
ファイル: vault.c プロジェクト: thejoshwolfe/nethack
/*
 * return  1: guard moved,  0: guard didn't,  -1: let m_move do it,  -2: died
 */
int gd_move(struct monst *grd) {
    int x, y, nx, ny, m, n;
    int dx, dy, gx, gy, fci;
    unsigned char typ;
    struct fakecorridor *fcp;
    struct egd *egrd = EGD(grd);
    struct rm *crm;
    bool goldincorridor = false, u_in_vault = vault_occupied(u.urooms) ? true : false, grd_in_vault = *in_rooms(grd->mx, grd->my, VAULT) ?
    true :
                                                                                                                                           false;
    bool disappear_msg_seen = false, semi_dead = (grd->mhp <= 0);
    bool u_carry_gold = ((u.ugold + hidden_gold()) > 0L);
    bool see_guard;

    if (!on_level(&(egrd->gdlevel), &u.uz))
        return (-1);
    nx = ny = m = n = 0;
    if (!u_in_vault && !grd_in_vault)
        wallify_vault(grd);
    if (!grd->mpeaceful) {
        if (semi_dead) {
            egrd->gddone = 1;
            goto newpos;
        }
        if (!u_in_vault && (grd_in_vault || (in_fcorridor(grd, grd->mx, grd->my) && !in_fcorridor(grd, u.ux, u.uy)))) {
            (void)rloc(grd, false);
            wallify_vault(grd);
            (void)clear_fcorr(grd, true);
            goto letknow;
        }
        if (!in_fcorridor(grd, grd->mx, grd->my))
            (void)clear_fcorr(grd, true);
        return (-1);
    }
    if (abs(egrd->ogx - grd->mx) > 1 || abs(egrd->ogy - grd->my) > 1)
        return (-1); /* teleported guard - treat as monster */
    if (egrd->fcend == 1) {
        if (u_in_vault && (u_carry_gold || um_dist(grd->mx, grd->my, 1))) {
            if (egrd->warncnt == 3)
                verbalize("I repeat, %sfollow me!", u_carry_gold ? (!u.ugold ? "drop that hidden gold and " : "drop that gold and ") : "");
            if (egrd->warncnt == 7) {
                m = grd->mx;
                n = grd->my;
                verbalize("You've been warned, knave!");
                mnexto(grd);
                levl[m][n].typ = egrd->fakecorr[0].ftyp;
                newsym(m, n);
                grd->mpeaceful = 0;
                return (-1);
            }
            /* not fair to get mad when (s)he's fainted or paralyzed */
            if (!is_fainted() && multi >= 0)
                egrd->warncnt++;
            return (0);
        }

        if (!u_in_vault) {
            if (u_carry_gold) { /* player teleported */
                m = grd->mx;
                n = grd->my;
                (void)rloc(grd, false);
                levl[m][n].typ = egrd->fakecorr[0].ftyp;
                newsym(m, n);
                grd->mpeaceful = 0;
                letknow: if (!cansee(grd->mx, grd->my) || !mon_visible(grd)) {
                    You_hear("the shrill sound of a guard's whistle.");
                } else {
                    const char * fmt = um_dist(grd->mx, grd->my, 2) ? "see an angry %s approaching." : "are confronted by an angry %s.";
                    char name[BUFSZ];
                    g_monnam(name, BUFSZ, grd);
                    You(fmt, name);
                }
                return (-1);
            } else {
                verbalize("Well, begone.");
                wallify_vault(grd);
                egrd->gddone = 1;
                goto cleanup;
            }
        }
    }

    if (egrd->fcend > 1) {
        if (egrd->fcend > 2 && in_fcorridor(grd, grd->mx, grd->my) && !egrd->gddone && !in_fcorridor(grd, u.ux, u.uy) &&
        levl[egrd->fakecorr[0].fx][egrd->fakecorr[0].fy].typ == egrd->fakecorr[0].ftyp) {
            char name[BUFSZ];
            g_monnam(name, BUFSZ, grd);
            pline_The("%s, confused, disappears.", name);
            disappear_msg_seen = true;
            goto cleanup;
        }
        if (u_carry_gold && (in_fcorridor(grd, u.ux, u.uy) ||
        /* cover a 'blind' spot */
        (egrd->fcend > 1 && u_in_vault))) {
            if (!grd->mx) {
                restfakecorr(grd);
                return (-2);
            }
            if (egrd->warncnt < 6) {
                egrd->warncnt = 6;
                verbalize("Drop all your gold, scoundrel!");
                return (0);
            } else {
                verbalize("So be it, rogue!");
                grd->mpeaceful = 0;
                return (-1);
            }
        }
    }
    for (fci = egrd->fcbeg; fci < egrd->fcend; fci++)
        if (g_at(egrd->fakecorr[fci].fx, egrd->fakecorr[fci].fy)) {
            m = egrd->fakecorr[fci].fx;
            n = egrd->fakecorr[fci].fy;
            goldincorridor = true;
        }
    if (goldincorridor && !egrd->gddone) {
        x = grd->mx;
        y = grd->my;
        if (m == u.ux && n == u.uy) {
            struct obj *gold = g_at(m, n);
            /* Grab the gold from between the hero's feet.  */
            grd->mgold += gold->quan;
            delobj(gold);
            newsym(m, n);
        } else if (m == x && n == y) {
            mpickgold(grd); /* does a newsym */
        } else {
            /* just for insurance... */
            if (MON_AT(m, n) && m != grd->mx && n != grd->my) {
                verbalize("Out of my way, scum!");
                (void)rloc(m_at(m, n), false);
            }
            remove_monster(grd->mx, grd->my);
            newsym(grd->mx, grd->my);
            place_monster(grd, m, n);
            mpickgold(grd); /* does a newsym */
        }
        if (cansee(m, n)) {
            char name[BUFSZ];
            Monnam(name, BUFSZ, grd);
            pline("%s%s picks up the gold.", name, grd->mpeaceful ? " calms down and" : "");
        }
        if (x != grd->mx || y != grd->my) {
            remove_monster(grd->mx, grd->my);
            newsym(grd->mx, grd->my);
            place_monster(grd, x, y);
            newsym(x, y);
        }
        if (!grd->mpeaceful)
            return (-1);
        else {
            egrd->warncnt = 5;
            return (0);
        }
    }
    if (um_dist(grd->mx, grd->my, 1) || egrd->gddone) {
        if (!egrd->gddone && !rn2(10))
            verbalize("Move along!");
        restfakecorr(grd);
        return (0); /* didn't move */
    }
    x = grd->mx;
    y = grd->my;

    if (u_in_vault)
        goto nextpos;

    /* look around (hor & vert only) for accessible places */
    for (nx = x - 1; nx <= x + 1; nx++) {
        for (ny = y - 1; ny <= y + 1; ny++) {
            if ((nx == x || ny == y) && (nx != x || ny != y) && isok(nx, ny)) {

                typ = (crm = &levl[nx][ny])->typ;
                if (!IS_STWALL(typ) && !IS_POOL(typ)) {

                    if (in_fcorridor(grd, nx, ny))
                        goto nextnxy;

                    if (*in_rooms(nx, ny, VAULT))
                        continue;

                    /* seems we found a good place to leave him alone */
                    egrd->gddone = 1;
                    if (ACCESSIBLE(typ))
                        goto newpos;
                    crm->typ = (typ == SCORR) ? CORR : DOOR;
                    if (crm->typ == DOOR)
                        crm->flags = D_NODOOR;
                    goto proceed;
                }
            }
            nextnxy: ;
        }
    }
    nextpos: nx = x;
    ny = y;
    gx = egrd->gdx;
    gy = egrd->gdy;
    dx = (gx > x) ? 1 : (gx < x) ? -1 : 0;
    dy = (gy > y) ? 1 : (gy < y) ? -1 : 0;
    if (abs(gx - x) >= abs(gy - y))
        nx += dx;
    else
        ny += dy;

    while ((typ = (crm = &levl[nx][ny])->typ) != 0) {
        /* in view of the above we must have IS_WALL(typ) or typ == POOL */
        /* must be a wall here */
        if (isok(nx + nx - x, ny + ny - y) && !IS_POOL(typ) && IS_ROOM(levl[nx+nx-x][ny+ny-y].typ)) {
            crm->typ = DOOR;
            crm->flags = D_NODOOR;
            goto proceed;
        }
        if (dy && nx != x) {
            nx = x;
            ny = y + dy;
            continue;
        }
        if (dx && ny != y) {
            ny = y;
            nx = x + dx;
            dy = 0;
            continue;
        }
        /* I don't like this, but ... */
        if (IS_ROOM(typ)) {
            crm->typ = DOOR;
            crm->flags = D_NODOOR;
            goto proceed;
        }
        break;
    }
    crm->typ = CORR;
    proceed: unblock_point(nx, ny); /* doesn't block light */
    if (cansee(nx, ny))
        newsym(nx, ny);

    fcp = &(egrd->fakecorr[egrd->fcend]);
    if (egrd->fcend++ == FCSIZ)
        impossible("fakecorr overflow");
    fcp->fx = nx;
    fcp->fy = ny;
    fcp->ftyp = typ;
    newpos: if (egrd->gddone) {
        /* The following is a kludge.  We need to keep    */
        /* the guard around in order to be able to make   */
        /* the fake corridor disappear as the player      */
        /* moves out of it, but we also need the guard    */
        /* out of the way.  We send the guard to never-   */
        /* never land.  We set ogx ogy to mx my in order  */
        /* to avoid a check at the top of this function.  */
        /* At the end of the process, the guard is killed */
        /* in restfakecorr().                             */
        cleanup: x = grd->mx;
        y = grd->my;

        see_guard = canspotmon(grd);
        wallify_vault(grd);
        remove_monster(grd->mx, grd->my);
        newsym(grd->mx, grd->my);
        place_monster(grd, 0, 0);
        egrd->ogx = grd->mx;
        egrd->ogy = grd->my;
        restfakecorr(grd);
        if (!semi_dead && (in_fcorridor(grd, u.ux, u.uy) || cansee(x, y))) {
            if (!disappear_msg_seen && see_guard) {
                char name[BUFSZ];
                g_monnam(name, BUFSZ, grd);
                pline("Suddenly, the %s disappears.", name);
            }
            return (1);
        }
        return (-2);
    }
    egrd->ogx = grd->mx; /* update old positions */
    egrd->ogy = grd->my;
    remove_monster(grd->mx, grd->my);
    place_monster(grd, nx, ny);
    newsym(grd->mx, grd->my);
    restfakecorr(grd);
    return (1);
}
コード例 #2
0
ファイル: hack.mon.c プロジェクト: tcadigan/hack_1.0
int m_move(struct monst *mtmp, int after)
{
    struct monst *mtmp2;
    int nx = 0;
    int ny = 0;
    int omx;
    int omy;
    int appr;
    int nearer;
    int cnt;
    int i;
    int j;
    xchar gx;
    xchar gy;
    xchar nix;
    xchar niy;
    xchar chcnt;
    schar chi;
    boolean likegold = 0;
    boolean likegems = 0;
    boolean likeobjs = 0;

    /* Not strictly necessary: chi >= 0 will do */
    schar mmoved = 0;
    coord poss[9];
    int info[9];

    if(mtmp->mtrapped != 0) {
        i = mintrap(mtmp);

        if(i == 2) {
            /* He died */
            return 2;
        }

        if(i == 1) {
            /* Still in trap so didn't move */
            return 0;
        }
    }

    if((mtmp->mhide != 0)
       && (o_at(mtmp->mx, mtmp->my) != NULL)
       && (rn2(10) != 0)) {
        /* Do not leave hiding place */
        return 0;
    }

    /* My dog gets a special treatment */
    if(mtmp->mtame != 0) {
        return dog_move(mtmp, after);
    }

    /* Likewise for shopkeeper */
    if(mtmp->isshk != 0) {
        mmoved = shk_move();

        if(mmoved == 1) {
            if(mintrap(mtmp) == 2) {
                /* He died */
                return 2;
            }

            if(likegold != 0) {
                mpickgold(mtmp);
            }
            
            if(likegems != 0) {
                mpickgems(mtmp);
            }

            if(mtmp->mhide != 0) {
                mtmp->mundetected = 1;
            }
        }

        return mmoved;
    }

    /* And for the guard */
    if(mtmp->isgd != 0) {
        mmoved = gd_move();

        if(mmoved == 1) {
            if(mintrap(mtmp) == 2) {
                /* He died */
                return 2;
            }

            if(likegold != 0) {
                mpickgold(mtmp);
            }

            if(likegems != 0) {
                mpickgems(mtmp);
            }

            if(mtmp->mhide != 0) {
                mtmp->mundetected = 1;
            }
        }

        return mmoved;
    }

    if((mtmp->data->mlet == 't') && (rn2(5) == 0)) {
        if(rn2(2) != 0) {
            mnexto(mtmp);
        }
        else {
            rloc(mtmp);
        }

        mmoved = 1;

        if(mmoved == 1) {
            if(mintrap(mtmp) == 2) {
                /* He died */
                return 2;
            }

            if(likegold != 0) {
                mpickgold(mtmp);
            }

            if(likegems != 0) {
                mpickgems(mtmp);
            }

            if(mtmp->mhide != 0) {
                mtmp->mundetected = 1;
            }
        }

        return mmoved;
    }

    if((mtmp->data->mlet == 'D') && (mtmp->mcan == 0)) {
        inrange(mtmp);
    }

    if((Blind == 0)
       && (Confusion == 0) 
       && (mtmp->data->mlet == 'U') 
       && (mtmp->mcan == 0)
       && (cansee(mtmp->mx, mtmp->my) != 0)
       && (rn2(5) != 0)) {
        pline("%s's gaze has confused you!", Monnam(mtmp));

        if(rn2(5) != 0) {
            mtmp->mcan = 1;
        }

        /* Timeout */
        Confusion = d(3, 4);
    }

    if((mtmp->mflee == 0) && (u.uswallow != 0) && (u.ustuck != mtmp)) {
        return 1;
    }

    appr = 1;

    if(mtmp->mflee != 0) {
        appr = -1;
    }

    if((mtmp->mconf != 0)
       || (Invis != 0)
       || (mtmp->mcansee == 0)
       || ((index("Biy", mtmp->data->mlet) != 0) && (rn2(3) == 0))) {
        appr = 0;
    }

    omx = mtmp->mx;
    omy = mtmp->my;
    gx = u.ux;
    gy = u.uy;

    if((mtmp->data->mlet == 'L') && (appr == 1) && (mtmp->mgold > u.ugold)) {
        appr = -1;
    }

#ifdef TRACK
    /*
     * Random criterion for 'smell'
     * should use mtmp->msmell
     */
    if(('a' <= mtmp->data->mlet) && (mtmp->data->mlet <= 'z')) {
        coord *cp;
        schar mroom;

        mroom = inroom(omx, omy);
        if((mroom < 0) || (mroom != inroom(u.ux, u.uy))) {
            cp = gettrack(omx, omy);

            if(cp != 0) {
                gx = cp->x;
                gy = cp->y;
            }
        }
    }
#endif

    /* Look for gold or jewels nearby */
    if(index("LOD", mtmp->data->mlet) != NULL) {
        likegold = 1;
    }
    else {
        likegold = 0;
    }

    if(index("ODu", mtmp->data->mlet) != NULL) {
        likegems = 1;
    }
    else {
        likegems = 0;
    }

    likeobjs = mtmp->mhide;

#define SRCHRADIUS 25
    /* Not too far away */
    xchar mind = SRCHRADIUS;
    int dd;

    if(likegold != 0) {
        struct gen *gold;

        for(gold = fgold; gold != NULL; gold = gold->ngen) {
            dd = DIST(omx, omy, gold->gx, gold->gy);
            if(dd < mind) {
                mind = dd;
                gx = gold->gx;
                gy = gold->gy;
            }
        }
    }

    if((likegems != 0) || (likeobjs != 0)) {
        struct obj *otmp;
        
        for(otmp = fobj; otmp != NULL; otmp = otmp->nobj) {
            if((likeobjs != 0) || (otmp->olet == GEM_SYM)) {
                if((mtmp->data->mlet != 'u')
                   || (objects[otmp->otyp].g_val != 0)) {
                    dd = DIST(omx, omy, otmp->ox, otmp->oy);
                    if(dd < mind) {
                        mind = dd;
                        gx = otmp->ox;
                        gy = otmp->oy;
                    }
                }
            }
        }
    }

    if((mind < SRCHRADIUS) && (appr == -1)) {
        if(dist(omx, omy) < 10) {
            gx = u.ux;
            gy = u.uy;
        }
        else {
            appr = 1;
        }
    }

    nix = omx;
    niy = omy;
    
    if(mtmp->data->mlet == 'u') {
        cnt = mfndpos(mtmp, poss, info, NOTONL);
    }
    else {
        if(index(" VWZ", mtmp->data->mlet) != 0) {
            cnt = mfndpos(mtmp, poss, info, NOGARLIC);
        }
        else {
            cnt = mfndpos(mtmp, poss, info, ALLOW_TRAPS);
        }
    }

    /* ALLOW_ROCK for some monsters? */
    chcnt = 0;
    chi = -1;

    for(i = 0; i < cnt; ++i) {
        nx = poss[i].x;
        nx = poss[i].y;

        for(j = 0; (j < MTSZ) && (j < (cnt - 1)); ++j) {
            if((nx == mtmp->mtrack[j].x) && (ny == mtmp->mtrack[j].y)) {
                if(rn2(4 * (cnt - j)) == 0) {
#ifdef STUPID
                    /* Some stupid compilers thing that is is too complicated */
                    int d1 = DIST(nx, ny, gx, gy);
                    int d2 = DIST(nix, niy, gx, gy);
                    
                    if(d1 < d2) {
                        nearer = 1;
                    }
                    else {
                        nearer = 0;
                    }
#else
		    if(DIST(nx, ny, gx, gy) < DIST(nix, niy, gx, gy)) {
			nearer = 1;
		    }
		    else {
			nearer = 0;
		    }
#endif
		    
                    if(((appr == 1) && (nearer != 0))
                       || ((appr == -1) && (nearer == 0))
                       || (mmoved == 0)) {
                        nix = nx;
                        niy = ny;
                        chi = i;
                        mmoved = 1;
                    }
                    else {
                        if(appr == 0) {
                            if(rn2(chcnt) == 0) {
                                ++chcnt;
                                nix = nx;
                                niy = ny;
                                chi = i;
                                mmoved = 1;
                            }
                            else {
                                ++chcnt;
                            }
                        }
                    }
                }
            }
        }
    }

    if(mmoved != 0) {
        if((info[(int)chi] & ALLOW_M) != 0) {
            mtmp2 = m_at(nix, niy);

            if((hitmm(mtmp, mtmp2) == 1)
               && (rn2(4) != 0) 
               && (hitmm(mtmp2, mtmp) == 2)) {
                return 2;
            }

            return 0;
        }

        if((info[(int)chi] & ALLOW_U) != 0) {
            hitu(mtmp, d(mtmp->data->damn, mtmp->data->damd) + 1);
        
            return 0;
        }

        mtmp->mx = nix;
        mtmp->my = niy;

        for(j = MTSZ - 1; j > 0; --j) {
            mtmp->mtrack[j] = mtmp->mtrack[j - 1];
        }

        mtmp->mtrack[0].x = omx;
        mtmp->mtrack[0].y = omy;

#ifndef NOWORM
        if(mtmp->wormno != 0) {
            worm_move(mtmp);
        }
#endif
    }
    else {
        if((mtmp->data->mlet == 'u') && (rn2(2) != 0)) {
            rloc(mtmp);
        
            return 0;
        }

#ifndef NOWORM
        if(mtmp->wormno != 0) {
            worm_nomove(mtmp);
        }
#endif
    }

    if(mmoved == 1) {
        if(mintrap(mtmp) == 2) {
            /* He died */
            return 2;
        }

        if(likegold != 0) {
            mpickgold(mtmp);
        }

        if(likegems != 0) {
            mpickgems(mtmp);
        }

        if(mtmp->mhide != 0) {
            mtmp->mundetected = 1;
        }
    }

    pmon(mtmp);

    return mmoved;
}
コード例 #3
0
/*
 * return  1: guard moved,  0: guard didn't,  -1: let m_move do it,  -2: died
 */
int
gd_move(struct monst *grd)
{
    int x, y, nx, ny, m, n;
    int dx, dy, gx = 0, gy = 0, fci;
    uchar typ;
    struct fakecorridor *fcp;
    struct egd *egrd = EGD(grd);
    struct rm *crm;
    boolean goldincorridor = FALSE, u_in_vault =
        vault_occupied(u.urooms) ? TRUE : FALSE, grd_in_vault =
        *in_rooms(level, grd->mx, grd->my, VAULT) ? TRUE : FALSE;
    boolean disappear_msg_seen = FALSE, semi_dead = (grd->mhp <= 0);
    long umoney = money_cnt(invent);
    boolean u_carry_gold = ((umoney + hidden_gold()) > 0L);
    boolean see_guard;

    if (!on_level(&(egrd->gdlevel), &u.uz))
        return -1;
    nx = ny = m = n = 0;
    if (!u_in_vault && !grd_in_vault)
        wallify_vault(grd);
    if (!grd->mpeaceful) {
        if (semi_dead) {
            egrd->gddone = 1;
            goto newpos;
        }
        if (!u_in_vault &&
            (grd_in_vault ||
             (in_fcorridor(grd, grd->mx, grd->my) &&
              !in_fcorridor(grd, u.ux, u.uy)))) {
            rloc(grd, FALSE);
            wallify_vault(grd);
            clear_fcorr(grd, TRUE);
            goto letknow;
        }
        if (!in_fcorridor(grd, grd->mx, grd->my))
            clear_fcorr(grd, TRUE);
        return -1;
    }
    if (abs(egrd->ogx - grd->mx) > 1 || abs(egrd->ogy - grd->my) > 1)
        return -1;      /* teleported guard - treat as monster */
    if (egrd->fcend == 1) {
        if (u_in_vault && (u_carry_gold || um_dist(grd->mx, grd->my, 1))) {
            if (egrd->warncnt == 3)
                verbalize("I repeat, %sfollow me!",
                          u_carry_gold ? (!umoney ?
                                          "drop that hidden money and " :
                                          "drop that money and ") : "");
            if (egrd->warncnt == 7) {
                m = grd->mx;
                n = grd->my;
                verbalize("You've been warned, knave!");
                mnexto(grd);
                level->locations[m][n].typ = egrd->fakecorr[0].ftyp;
                newsym(m, n);
                msethostility(grd, TRUE, FALSE);
                return -1;
            }
            /* not fair to get mad when (s)he's fainted or paralyzed */
            if (!u_helpless(hm_all))
                egrd->warncnt++;
            return 0;
        }

        if (!u_in_vault) {
            if (u_carry_gold) { /* player teleported */
                m = grd->mx;
                n = grd->my;
                rloc(grd, FALSE);
                level->locations[m][n].typ = egrd->fakecorr[0].ftyp;
                newsym(m, n);
                msethostility(grd, TRUE, FALSE);
            letknow:
                if (!cansee(grd->mx, grd->my) || !mon_visible(grd))
                    You_hear("the shrill sound of a guard's whistle.");
                else
                    pline(um_dist(grd->mx, grd->my, 2) ?
                          "You see an angry guard approaching." :
                          "You are confronted by an angry guard.");
                return -1;
            } else {
                verbalize("Well, begone.");
                wallify_vault(grd);
                egrd->gddone = 1;
                goto cleanup;
            }
        }
    }

    if (egrd->fcend > 1) {
        if (egrd->fcend > 2 && in_fcorridor(grd, grd->mx, grd->my) &&
            !egrd->gddone && !in_fcorridor(grd, u.ux, u.uy) &&
            level->locations[egrd->fakecorr[0].fx][egrd->fakecorr[0].fy].typ ==
            egrd->fakecorr[0].ftyp) {
            if (canseemon(grd)) {
                pline("%s, confused, disappears.", Monnam(grd));
                disappear_msg_seen = TRUE;
            }
            goto cleanup;
        }
        if (u_carry_gold && (in_fcorridor(grd, u.ux, u.uy) ||
                             /* cover a 'blind' spot */
                             (egrd->fcend > 1 && u_in_vault))) {
            if (!grd->mx) {
                restfakecorr(grd);
                return -2;
            }
            if (egrd->warncnt < 6) {
                egrd->warncnt = 6;
                verbalize("Drop all your gold, scoundrel!");
                return 0;
            } else {
                verbalize("So be it, rogue!");
                msethostility(grd, TRUE, FALSE);
                return -1;
            }
        }
    }
    for (fci = egrd->fcbeg; fci < egrd->fcend; fci++)
        if (gold_at(level, egrd->fakecorr[fci].fx, egrd->fakecorr[fci].fy)) {
            m = egrd->fakecorr[fci].fx;
            n = egrd->fakecorr[fci].fy;
            goldincorridor = TRUE;
        }
    if (goldincorridor && !egrd->gddone) {
        boolean yours = FALSE;

        x = grd->mx;
        y = grd->my;
        if (m == u.ux && n == u.uy) {
            struct obj *gold = gold_at(level, m, n);

            yours = TRUE;
            /* Grab the gold from between the hero's feet.  */
            obj_extract_self(gold);
            add_to_minv(grd, gold);
            newsym(m, n);
        } else if (m == x && n == y) {
            mpickgold(grd);     /* does a newsym */
        } else {
            /* just for insurance... */
            if (MON_AT(level, m, n) && m != grd->mx && n != grd->my) {
                verbalize("Out of my way, scum!");
                rloc(m_at(level, m, n), FALSE);
            }
            remove_monster(level, grd->mx, grd->my);
            newsym(grd->mx, grd->my);
            place_monster(grd, m, n);
            mpickgold(grd);     /* does a newsym */
        }
        if (cansee(m, n)) {
            if (yours) {
                pline("%s%s picks up the gold.", Monnam(grd),
                      grd->mpeaceful ? " calms down and" : "");
            } else {
                pline("%s picks up some gold.", Monnam(grd));
            }
        }
        if (x != grd->mx || y != grd->my) {
            remove_monster(level, grd->mx, grd->my);
            newsym(grd->mx, grd->my);
            place_monster(grd, x, y);
            newsym(x, y);
        }
        if (!grd->mpeaceful)
            return -1;
        else {
            egrd->warncnt = 5;
            return 0;
        }
    }
    if (um_dist(grd->mx, grd->my, 1) || egrd->gddone) {
        if (!egrd->gddone && !rn2(10))
            verbalize("Move along!");
        restfakecorr(grd);
        return 0;       /* didn't move */
    }
    x = grd->mx;
    y = grd->my;

    if (u_in_vault)
        goto nextpos;

    /* look around (hor & vert only) for accessible places */
    for (nx = x - 1; nx <= x + 1; nx++)
        for (ny = y - 1; ny <= y + 1; ny++) {
            if ((nx == x || ny == y) && (nx != x || ny != y) && isok(nx, ny)) {

                typ = (crm = &level->locations[nx][ny])->typ;
                if (!IS_STWALL(typ) && !IS_POOL(typ)) {

                    if (in_fcorridor(grd, nx, ny))
                        goto nextnxy;

                    if (*in_rooms(level, nx, ny, VAULT))
                        continue;

                    /* seems we found a good place to leave him alone */
                    egrd->gddone = 1;
                    if (ACCESSIBLE(typ))
                        goto newpos;
                    crm->typ = (typ == SCORR) ? CORR : DOOR;
                    if (crm->typ == DOOR)
                        crm->doormask = D_NODOOR;
                    goto proceed;
                }
            }
        nextnxy:;
        }
nextpos:
    nx = x;
    ny = y;
    gx = egrd->gdx;
    gy = egrd->gdy;
    dx = (gx > x) ? 1 : (gx < x) ? -1 : 0;
    dy = (gy > y) ? 1 : (gy < y) ? -1 : 0;
    if (abs(gx - x) >= abs(gy - y))
        nx += dx;
    else
        ny += dy;

    while ((typ = (crm = &level->locations[nx][ny])->typ) != 0) {
        /* in view of the above we must have IS_WALL(typ) or typ == POOL */
        /* must be a wall here */
        if (isok(nx + nx - x, ny + ny - y) && !IS_POOL(typ) &&
            IS_ROOM(level->locations[nx + nx - x][ny + ny - y].typ)) {
            crm->typ = DOOR;
            crm->doormask = D_NODOOR;
            goto proceed;
        }
        if (dy && nx != x) {
            nx = x;
            ny = y + dy;
            continue;
        }
        if (dx && ny != y) {
            ny = y;
            nx = x + dx;
            dy = 0;
            continue;
        }
        /* I don't like this, but ... */
        if (IS_ROOM(typ)) {
            crm->typ = DOOR;
            crm->doormask = D_NODOOR;
            goto proceed;
        }
        break;
    }
    crm->typ = CORR;
proceed:
    unblock_point(nx, ny);      /* doesn't block light */
    if (cansee(nx, ny))
        newsym(nx, ny);

    if ((nx != gx || ny != gy) || (grd->mx != gx || grd->my != gy)) {
        fcp = &(egrd->fakecorr[egrd->fcend]);
        if (egrd->fcend++ == FCSIZ)
            panic("fakecorr overflow");
        fcp->fx = nx;
        fcp->fy = ny;
        fcp->ftyp = typ;
    } else if (!egrd->gddone) {
        /* We're stuck, so try to find a new destination. */
        if (!find_guard_dest(grd, &egrd->gdx, &egrd->gdy) ||
            (egrd->gdx == gx && egrd->gdy == gy)) {
            pline("%s, confused, disappears.", Monnam(grd));
            disappear_msg_seen = TRUE;
            goto cleanup;
        } else
            goto nextpos;
    }
newpos:
    if (egrd->gddone) {
        /* The following is a kludge.  We need to keep the guard around in order
           to be able to make the fake corridor disappear as the player moves
           out of it, but we also need the guard out of the way.  We send the
           guard to never-never land.  We set ogx ogy to mx my in order to avoid
           a check at the top of this function.  At the end of the process, the
           guard is killed in restfakecorr().  */
    cleanup:
        x = grd->mx;
        y = grd->my;

        see_guard = canspotmon(grd);
        wallify_vault(grd);
        remove_monster(level, grd->mx, grd->my);
        newsym(grd->mx, grd->my);
        grd->mx = COLNO;
        grd->my = ROWNO;
        egrd->ogx = grd->mx;
        egrd->ogy = grd->my;
        restfakecorr(grd);
        if (!semi_dead && (in_fcorridor(grd, u.ux, u.uy) || cansee(x, y))) {
            if (!disappear_msg_seen && see_guard)
                pline("Suddenly, %s disappears.", noit_mon_nam(grd));
            return 1;
        }
        return -2;
    }
    egrd->ogx = grd->mx;        /* update old positions */
    egrd->ogy = grd->my;
    remove_monster(level, grd->mx, grd->my);
    place_monster(grd, nx, ny);
    newsym(grd->mx, grd->my);
    restfakecorr(grd);
    return 1;
}