/*
 * Strictly check if monster can enter the grid
 */
bool monster_can_enter(int y, int x, monster_race *r_ptr, u16b mode)
{
    cave_type *c_ptr = &cave[y][x];

    /* Player or other monster */
    if (player_bold(y, x)) return FALSE;
    if (c_ptr->m_idx) return FALSE;

    return monster_can_cross_terrain(c_ptr->feat, r_ptr, mode);
}
Esempio n. 2
0
/*
 * Places "streamers" of rock through dungeon
 *
 * Note that their are actually six different terrain features used
 * to represent streamers.  Three each of magma and quartz, one for
 * basic vein, one with hidden gold, and one with known gold.  The
 * hidden gold types are currently unused.
 */
void build_streamer(int feat, int chance)
{
    int        i, tx, ty;
    int        y, x, dir;
    int dummy = 0;

    cave_type *c_ptr;
    feature_type *f_ptr;

    feature_type *streamer_ptr = &f_info[feat];
    bool streamer_is_wall = have_flag(streamer_ptr->flags, FF_WALL) && !have_flag(streamer_ptr->flags, FF_PERMANENT);
    bool streamer_may_have_gold = have_flag(streamer_ptr->flags, FF_MAY_HAVE_GOLD);

    /* Hack -- Choose starting point */
    y = rand_spread(cur_hgt / 2, cur_hgt / 6);
    x = rand_spread(cur_wid / 2, cur_wid / 6);

    /* Choose a random compass direction */
    dir = ddd[randint0(8)];

    /* Place streamer into dungeon */
    while (dummy < SAFE_MAX_ATTEMPTS)
    {
        dummy++;

        /* One grid per density */
        for (i = 0; i < DUN_STR_DEN; i++)
        {
            int d = DUN_STR_RNG;

            /* Pick a nearby grid */
            while (1)
            {
                ty = rand_spread(y, d);
                tx = rand_spread(x, d);
                if (!in_bounds2(ty, tx)) continue;
                break;
            }

            /* Access the grid */
            c_ptr = &cave[ty][tx];
            f_ptr = &f_info[c_ptr->feat];

            if (have_flag(f_ptr->flags, FF_MOVE) && (have_flag(f_ptr->flags, FF_WATER) || have_flag(f_ptr->flags, FF_LAVA)))
                continue;

            /* Do not convert permanent features */
            if (have_flag(f_ptr->flags, FF_PERMANENT)) continue;

            /* Only convert "granite" walls */
            if (streamer_is_wall)
            {
                if (!is_extra_grid(c_ptr) && !is_inner_grid(c_ptr) && !is_outer_grid(c_ptr) && !is_solid_grid(c_ptr)) continue;
                if (is_closed_door(c_ptr->feat)) continue;
            }

            if (c_ptr->m_idx && !(have_flag(streamer_ptr->flags, FF_PLACE) && monster_can_cross_terrain(feat, &r_info[m_list[c_ptr->m_idx].r_idx], 0)))
            {
                /* Delete the monster (if any) */
                delete_monster(ty, tx);
            }

            if (c_ptr->o_idx && !have_flag(streamer_ptr->flags, FF_DROP))
            {
                s16b this_o_idx, next_o_idx = 0;

                /* Scan all objects in the grid */
                for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
                {
                    /* Acquire object */
                    object_type *o_ptr = &o_list[this_o_idx];

                    /* Acquire next object */
                    next_o_idx = o_ptr->next_o_idx;

                    /* Hack -- Preserve unknown artifacts */
                    if (object_is_fixed_artifact(o_ptr))
                    {
                        /* Mega-Hack -- Preserve the artifact */
                        a_info[o_ptr->name1].cur_num = 0;

                        if (cheat_peek)
                        {
                            char o_name[MAX_NLEN];
                            object_desc(o_name, o_ptr, (OD_NAME_ONLY | OD_STORE));
                            msg_format("Artifact (%s) was deleted by streamer.", o_name);
                        }
                    }
                    else if (o_ptr->name3)
                    {
                        /* Mega-Hack -- Preserve the artifact */
                        a_info[o_ptr->name3].cur_num = 0;

                        if (cheat_peek)
                        {
                            char o_name[MAX_NLEN];
                            object_desc(o_name, o_ptr, (OD_NAME_ONLY | OD_STORE));
                            msg_format("Artifact (%s) was deleted by streamer.", o_name);
                        }
                    }
                    else if (cheat_peek && o_ptr->art_name)
                    {
                        msg_print("One of the random artifacts was deleted by streamer.");
                    }
                }

                /* Delete objects */
                delete_object(ty, tx);
            }

            /* Clear previous contents, add proper vein type */
            c_ptr->feat = feat;

            /* Paranoia: Clear mimic field */
            c_ptr->mimic = 0;

            if (streamer_may_have_gold)
            {
                /* Hack -- Add some known treasure */
                if (one_in_(chance))
                {
                    cave_alter_feat(ty, tx, FF_MAY_HAVE_GOLD);
                }

                /* Hack -- Add some hidden treasure */
                else if (one_in_(chance / 4))
                {
                    cave_alter_feat(ty, tx, FF_MAY_HAVE_GOLD);
                    cave_alter_feat(ty, tx, FF_ENSECRET);
                }
            }
        }

        if (dummy >= SAFE_MAX_ATTEMPTS)
        {
            if (cheat_room)
            {
                msg_print("Warning! Could not place streamer!");

            }
            return;
        }


        /* Advance the streamer */
        y += ddy[dir];
        x += ddx[dir];

        /* Quit before leaving the dungeon */
        if (!in_bounds(y, x)) break;
    }
}