Exemplo n.º 1
0
/**
 * Return the features around (or under) the character
 */
void get_feats(int *surroundings)
{
    int d;
    int xx, yy;
    int count;

    /* Count how many matches */
    count = 0;

    /* Check around (and under) the character */
    for (d = 0; d < 9; d++) 
    {
	/* Initialise */
	surroundings[d] = FEAT_FLOOR;

	/* Extract adjacent (legal) location */
	yy = p_ptr->py + ddy_ddd[d];
	xx = p_ptr->px + ddx_ddd[d];

	/* Paranoia */
	if (!in_bounds_fully(yy, xx))
	    continue;

	/* Must have knowledge */
	if (!cave_has(cave_info[yy][xx], CAVE_MARK))
	    continue;

	/* Record the feature */
	surroundings[d] = cave_feat[yy][xx];
    }

    /* All done */
    return;
}
Exemplo n.º 2
0
/*
 * Return a target set of target_able monsters.
 */
static struct point_set *target_set_interactive_prepare(int mode)
{
	int y, x;
	struct point_set *targets = point_set_new(TS_INITIAL_SIZE);

	/* Scan the current panel */
	for (y = Term->offset_y; y < Term->offset_y + SCREEN_HGT; y++)
	{
		for (x = Term->offset_x; x < Term->offset_x + SCREEN_WID; x++)
		{
			/* Check bounds */
			if (!in_bounds_fully(y, x)) continue;

			/* Require "interesting" contents */
			if (!target_set_interactive_accept(y, x)) continue;

			/* Special mode */
			if (mode & (TARGET_KILL))
			{
				/* Must contain a monster */
				if (!(cave->m_idx[y][x] > 0)) continue;

				/* Must be a targettable monster */
			 	if (!target_able(cave->m_idx[y][x])) continue;
			}

			/* Save the location */
			add_to_point_set(targets, y, x);
		}
	}

	sort(targets->pts, point_set_size(targets), sizeof(*(targets->pts)), cmp_distance);
	return targets;
}
Exemplo n.º 3
0
/*
 * Hack -- quick debugging hook
 */
static void do_cmd_wiz_hack_ben(void)
{
	int py = p_ptr->py;
	int px = p_ptr->px;

	int i, y, x;


	for (i = 0; i < MONSTER_FLOW_DEPTH; ++i)
	{
		/* Update map */
		for (y = Term->offset_y; y < Term->offset_y + SCREEN_HGT; y++)
		{
			for (x = Term->offset_x; x < Term->offset_x + SCREEN_WID; x++)
			{
				byte a = TERM_RED;

				if (!in_bounds_fully(y, x)) continue;

				/* Display proper cost */
				if (cave_cost[y][x] != i) continue;

				/* Reliability in yellow */
				if (cave_when[y][x] == cave_when[py][px])
				{
					a = TERM_YELLOW;
				}

				/* Display player/floors/walls */
				if ((y == py) && (x == px))
				{
					print_rel('@', a, y, x);
				}
				else if (cave_floor_bold(y, x))
				{
					print_rel('*', a, y, x);
				}
				else
				{
					print_rel('#', a, y, x);
				}
			}
		}

		/* Prompt */
		prt(format("Depth %d: ", i), 0, 0);

		/* Get key */
		if (inkey() == ESCAPE) break;

		/* Redraw map */
		prt_map();
	}

	/* Done */
	prt("", 0, 0);

	/* Redraw map */
	prt_map();
}
Exemplo n.º 4
0
/**
 * Handle a textui mouseclick.
 */
static void textui_process_click(ui_event_data e)
{
	int x, y;

	if (!OPT(mouse_movement)) return;

	y = KEY_GRID_Y(e);
	x = KEY_GRID_X(e);

	/* Check for a valid location */
	if (!in_bounds_fully(y, x)) return;

	/* XXX show context menu here */
	if ((p_ptr->py == y) && (p_ptr->px == x))
		textui_cmd_rest();

	else /* if (e.mousebutton == 1) */
	{
		if (p_ptr->timed[TMD_CONFUSED])
		{
			cmd_insert(CMD_WALK);
		}
		else
		{
			cmd_insert(CMD_PATHFIND);
			cmd_set_arg_point(cmd_get_top(), 0, y, x);
		}
	}

#if 0
	else if (e.mousebutton == 2)
Exemplo n.º 5
0
/*
 * Aux function -- see below
 */
void project_grid_mark(int y, int x, bool room)
{
    if(!in_bounds_fully(y, x)) return;

    /* Avoid infinite recursion */
    if (dungeon_info[y][x].cave_info & (CAVE_TEMP)) return;

    /* Option -- do not leave the current room */
    if ((room) && (!(dungeon_info[y][x].cave_info & (CAVE_ROOM)))) return;

    /* Mark the grid */
    dungeon_info[y][x].cave_info |= (CAVE_TEMP);

    /* Add it to the marked set */
    project_grids.append(make_coords(y, x));
}
Exemplo n.º 6
0
/* XXX: Untangle this. The whole temp_* thing is complete madness. */
static void target_set_interactive_prepare(int mode)
{
	int y, x;
	struct point *pts = mem_zalloc(sizeof(*pts) * SCREEN_HGT * SCREEN_WID);
	unsigned int n = 0;

	/* Scan the current panel */
	for (y = Term->offset_y; y < Term->offset_y + SCREEN_HGT; y++)
	{
		for (x = Term->offset_x; x < Term->offset_x + SCREEN_WID; x++)
		{
			/* Check bounds */
			if (!in_bounds_fully(y, x)) continue;

			/* Require "interesting" contents */
			if (!target_set_interactive_accept(y, x)) continue;

			/* Special mode */
			if (mode & (TARGET_KILL))
			{
				/* Must contain a monster */
				if (!(cave_m_idx[y][x] > 0)) continue;

				/* Must be a targettable monster */
			 	if (!target_able(cave_m_idx[y][x])) continue;
			}

			/* Save the location */
			pts[n].x = x;
			pts[n].y = y;
			n++;
		}
	}

	sort(pts, n, sizeof(*pts), cmp_distance);

	/* Reset "temp" array */
	temp_n = n;
	while (n--) {
		temp_x[n] = pts[n].x;
		temp_y[n] = pts[n].y;
	}
}
Exemplo n.º 7
0
/*
 * Prepare the "temp" array for "target_interactive_set"
 *
 * Return the number of target_able monsters in the set.
 */
static void target_set_interactive_prepare(int mode)
{
	int y, x;

	/* Reset "temp" array */
	temp_n = 0;

	/* Scan the current panel */
	for (y = Term->offset_y; y < Term->offset_y + SCREEN_HGT; y++)
	{
		for (x = Term->offset_x; x < Term->offset_x + SCREEN_WID; x++)
		{
			/* Check bounds */
			if (!in_bounds_fully(y, x)) continue;

			/* Require "interesting" contents */
			if (!target_set_interactive_accept(y, x)) continue;

			/* Special mode */
			if (mode & (TARGET_KILL))
			{
				/* Must contain a monster */
				if (!(cave_m_idx[y][x] > 0)) continue;

				/* Must be a targettable monster */
			 	if (!target_able(cave_m_idx[y][x])) continue;
			}

			/* Save the location */
			temp_x[temp_n] = x;
			temp_y[temp_n] = y;
			temp_n++;
		}
	}

	/* Set the sort hooks */
	ang_sort_comp = ang_sort_comp_distance;
	ang_sort_swap = ang_sort_swap_distance;

	/* Sort the positions */
	ang_sort(temp_x, temp_y, temp_n);
}
Exemplo n.º 8
0
/*
 * Set the target to a location
 */
void target_set_location(int y, int x)
{
	/* Legal target */
	if (in_bounds_fully(y, x))
	{
		/* Save target info */
		target_set = TRUE;
		target_who = 0;
		target_y = y;
		target_x = x;
	}

	/* Clear target */
	else
	{
		/* Reset target info */
		target_set = FALSE;
		target_who = 0;
		target_y = 0;
		target_x = 0;
	}
}
Exemplo n.º 9
0
/*
 * Return the number of doors/traps around (or under) the character
 */
static int count_feats(int *y, int *x, bool (*test)(int feat), bool under)
{
	int d;
	int xx, yy;
	int count;

	/* Count how many matches */
	count = 0;

	/* Check around (and under) the character */
	for (d = 0; d < 9; d++)
	{
		/* Not searching under the character */
		if ((d == 8) && !under) continue;

		/* Extract adjacent (legal) location */
		yy = p_ptr->py + ddy_ddd[d];
		xx = p_ptr->px + ddx_ddd[d];

		/* Paranoia */
		if (!in_bounds_fully(yy, xx)) continue;

		/* Must have knowledge */
		if (!(cave_info[yy][xx] & (CAVE_MARK))) continue;

		/* Not looking for this feature */
		if (!(*test)(cave_feat[yy][xx])) continue;

		/* Count it */
		++count;

		/* Remember the location of the last door found */
		*y = yy;
		*x = xx;
	}

	/* All done */
	return count;
}
Exemplo n.º 10
0
/*
 * Set the target to a location
 */
void target_set_location(int y, int x)
{
	/* Legal target */
	if (in_bounds_fully(y, x))
	{
		/* Save target info */
		p_ptr->target_set = TRUE;
		p_ptr->target_who = 0;
		p_ptr->target_row = y;
		p_ptr->target_col = x;
	}

	/* Clear target */
	else
	{
		/* Reset target info */
		p_ptr->target_set = FALSE;
		p_ptr->target_who = 0;
		p_ptr->target_row = 0;
		p_ptr->target_col = 0;
	}
}
Exemplo n.º 11
0
/*
 * Fire beams in random directions.
 */
bool beam_burst(int y, int x, int typ, int num, int dam)
{
    int i, yy, xx;

    bool notice = FALSE;

    /* Require legal centerpoint */
    if (!in_bounds_fully(y, x)) return (FALSE);

    /* Fire beams in all directions */
    for (i = 0; i < num; i++)
    {
        /* Get a totally random grid within six grids from current position */
        yy = rand_spread(y, 6);
        xx = rand_spread(x, 6);

        /* Fire a beam of (strong) light towards it */
        if (project(-1, 0, y, x, yy, xx, dam, typ,
            PROJECT_BEAM | PROJECT_KILL | PROJECT_EFCT, 0, 0)) notice = TRUE;
    }

    /* Return "anything noticed" */
    return (notice);
}
Exemplo n.º 12
0
/*
 * Query the dungeon
 */
static void do_cmd_wiz_query(void)
{
	int py = p_ptr->py;
	int px = p_ptr->px;

	int y, x;

	struct keypress cmd;

	u16b mask = 0x00;


	/* Get a "debug command" */
	if (!get_com("Debug Command Query: ", &cmd)) return;

	/* Extract a flag */
	switch (cmd.code)
	{
		case '0': mask = (1 << 0); break;
		case '1': mask = (1 << 1); break;
		case '2': mask = (1 << 2); break;
		case '3': mask = (1 << 3); break;
		case '4': mask = (1 << 4); break;
		case '5': mask = (1 << 5); break;
		case '6': mask = (1 << 6); break;
		case '7': mask = (1 << 7); break;

		case 'm': mask |= (CAVE_MARK); break;
		case 'g': mask |= (CAVE_GLOW); break;
		case 'r': mask |= (CAVE_ROOM); break;
		case 'i': mask |= (CAVE_ICKY); break;
		case 's': mask |= (CAVE_SEEN); break;
		case 'v': mask |= (CAVE_VIEW); break;
		case 't': mask |= (CAVE_TEMP); break;
		case 'w': mask |= (CAVE_WALL); break;
	}

	/* Scan map */
	for (y = Term->offset_y; y < Term->offset_y + SCREEN_HGT; y++)
	{
		for (x = Term->offset_x; x < Term->offset_x + SCREEN_WID; x++)
		{
			byte a = TERM_RED;

			if (!in_bounds_fully(y, x)) continue;

			/* Given mask, show only those grids */
			if (mask && !(cave->info[y][x] & mask)) continue;

			/* Given no mask, show unknown grids */
			if (!mask && (cave->info[y][x] & (CAVE_MARK))) continue;

			/* Color */
			if (cave_floor_bold(y, x)) a = TERM_YELLOW;

			/* Display player/floors/walls */
			if ((y == py) && (x == px))
				print_rel(L'@', a, y, x);
			else if (cave_floor_bold(y, x))
				print_rel(L'*', a, y, x);
			else
				print_rel(L'#', a, y, x);
		}
	}

	/* Get keypress */
	msg("Press any key.");
	message_flush();

	/* Redraw map */
	prt_map();
}
Exemplo n.º 13
0
/**
 * Allocates some objects (using "place" and "type")
 */
void alloc_object(int set, int typ, int num)
{
    int y, x, k;
    feature_type *f_ptr;

    /* Place some objects */
    for (k = 0; k < num; k++) {
	/* Pick a "legal" spot */
	while (TRUE) {
	    bool room;

	    /* Location */
	    y = randint0(DUNGEON_HGT);
	    x = randint0(DUNGEON_WID);
	    f_ptr = &f_info[cave_feat[y][x]];

	    /* Paranoia - keep objects out of the outer walls */
	    if (!in_bounds_fully(y, x))
		continue;

	    /* Require "naked" floor grid */
	    f_ptr = &f_info[cave_feat[y][x]];
	    if (!(cave_naked_bold(y, x) && tf_has(f_ptr->flags, TF_FLOOR)))
		continue;

	    /* Check for "room" */
	    room = cave_has(cave_info[y][x], CAVE_ROOM) ? TRUE : FALSE;

	    /* Require corridor? */
	    if ((set == ALLOC_SET_CORR) && room)
		continue;

	    /* Require room? */
	    if ((set == ALLOC_SET_ROOM) && !room)
		continue;

	    /* Accept it */
	    break;
	}

	/* Place something */
	switch (typ) {
	case ALLOC_TYP_RUBBLE:
	    {
		place_rubble(y, x);
		break;
	    }

	case ALLOC_TYP_TRAP:
	    {
		place_trap(y, x, -1, p_ptr->depth);
		break;
	    }

	case ALLOC_TYP_GOLD:
	    {
		place_gold(y, x);
		break;
	    }

	case ALLOC_TYP_OBJECT:
	    {
		place_object(y, x, FALSE, FALSE, FALSE);
		break;
	    }
	}
    }
}
Exemplo n.º 14
0
/*
 * Using the angle given, find a grid that is in that direction from the
 * origin.
 *
 * Note:  This function does not yield very good results when the
 * character is adjacent to the outer wall of the dungeon and the projection
 * heads towards it.
 */
void get_grid_using_angle(int angle, int y0, int x0, int *ty, int *tx)
{
	int y, x;
	int best_y = 0, best_x = 0;

	int diff;
	int this_angle;
	int fudge = 180;


	/* Angle must be legal */
	if ((angle < 0) || (angle >= 180)) return;

	/* Scan the table, get as good a match as possible */
	for (y = 0; y < 41; y++)
	{
		for (x = 0; x < 41; x++)
		{
			/* Corresponding grid in dungeon must be fully in bounds  XXX */
			if (!in_bounds_fully(y0 - 20 + y, x0 - 20 + x)) continue;

			/* Check this table grid */
			this_angle = get_angle_to_grid[y][x];

			/* Get inaccuracy of this angle */
			diff = ABS(angle - this_angle);

			/* Inaccuracy is lower than previous best */
			if (diff < fudge)
			{
				/* Note coordinates */
				best_y = y;
				best_x = x;

				/* Save inaccuracy as a new best */
				fudge = diff;

				/* Note perfection */
				if (fudge == 0) break;
			}
		}

		/* Note perfection */
		if (fudge == 0) break;
	}

	/* We have an unacceptably large fudge factor */
	if (fudge >= 30)
	{
		/* Set target to original grid */
		*ty = y0;
		*tx = x0;
	}

	/* Usual case */
	else
	{
		/* Set target */
		*ty = y0 - 20 + best_y;
		*tx = x0 - 20 + best_x;
	}
}
Exemplo n.º 15
0
/*
 * Prepare the "temp" array for "target_interactive_set"
 *
 * Return the number of target_able monsters in the set.
 */
static void target_set_interactive_prepare(int mode)
{
    int y, x;

    bool expand_look = (mode & (TARGET_LOOK)) ? TRUE : FALSE;

    /* Reset "temp" array */
    target_grids.clear();

    // Not needed.
    if (mode & (TARGET_GRID)) return;

    QRect vis = visible_dungeon();

    /* Scan the current panel */
    for (y = vis.y(); y <= vis.y() + vis.height(); y++)
    {
        for (x = vis.x(); x <= vis.x() + vis.width(); x++)
        {
            bool do_continue = FALSE;

            /* Check bounds */
            if (!in_bounds_fully(y, x)) continue;

            /* Require line of sight, unless "look" is "expanded" */
            if (!player_has_los_bold(y, x) && (!expand_look)) continue;

            /* Require "interesting" contents */
            if (!target_set_interactive_accept(mode, y, x)) continue;

            /* Special mode */
            if (mode & (TARGET_KILL))
            {
                /* Must contain a monster */
                if (!dungeon_info[y][x].has_monster()) do_continue = TRUE;

                /* Must be a targetable monster */
                if (!target_able(dungeon_info[y][x].monster_idx, FALSE)) do_continue = TRUE;
            }

            /* Don't continue on the trap exception, or if probing. */
            if ((mode & (TARGET_TRAP)) && target_able_trap(y, x)) do_continue = FALSE;
            else if (mode & (TARGET_PROBE)) do_continue = FALSE;

            if (do_continue) continue;

            /*
             * Hack - don't go over redundant elemental terrain \
             * (since we have large lakes and pools of the same terrain)
             */
            if ((p_ptr->target_row > 0) || (p_ptr->target_col > 0))
            {
                if (dungeon_info[p_ptr->target_row][p_ptr->target_col].feature_idx == dungeon_info[y][x].feature_idx)
                {
                    if (cave_ff3_match(y, x, TERRAIN_MASK)) continue;
                }
            }

            /* Save the location */
            target_grids.append(make_coords(y, x));
        }
    }

    // Sort by distance
    qSort(target_grids.begin(), target_grids.end(), coords_sort_distance);
}
Exemplo n.º 16
0
/*
 * Read the dungeon
 *
 * The monsters/objects must be loaded in the same order
 * that they were stored, since the actual indexes matter.
 *
 * Note that the size of the dungeon is now hard-coded to
 * DUNGEON_HGT by DUNGEON_WID, and any dungeon with another
 * size will be silently discarded by this routine.
 *
 * Note that dungeon objects, including objects held by monsters, are
 * placed directly into the dungeon, using "object_copy()", which will
 * copy "iy", "ix", and "held_m_idx", leaving "next_o_idx" blank for
 * objects held by monsters, since it is not saved in the savefile.
 *
 * After loading the monsters, the objects being held by monsters are
 * linked directly into those monsters.
 */
static errr rd_dungeon(void)
{
	int i, y, x;

	s16b depth;
	s16b py, px;

	byte count;
	byte tmp8u;
	u16b tmp16u;

	u16b limit;


	/*** Basic info ***/

	/* Header info */
	rd_s16b(&depth);
	rd_u16b(&p_ptr->dungeon_type);
	/* Get dungeon capabilities */
	set_dungeon_type(p_ptr->dungeon_type);

	rd_s16b(&py);
	rd_s16b(&px);
	rd_byte(&p_ptr->cur_map_hgt);
	rd_byte(&p_ptr->cur_map_wid);
	rd_u16b(&altered_inventory_counter);
	/* Paranoia */
	allow_altered_inventory = FALSE;

	rd_u16b(&tmp16u);


	/* Ignore illegal dungeons */
	if ((depth < 0) || (depth >= MAX_DEPTH))
	{
		note(format("Ignoring illegal dungeon depth (%d)", depth));
		return (0);
	}

	/* Ignore illegal dungeons */
	if ((p_ptr->cur_map_hgt > MAX_DUNGEON_HGT) || (p_ptr->cur_map_wid > MAX_DUNGEON_WID))
	{
		/* XXX XXX XXX */
		note(format("Ignoring illegal dungeon size (%d,%d).", p_ptr->cur_map_hgt, p_ptr->cur_map_wid));
		return (0);
	}

	/* Ignore illegal dungeons */
	if ((px < 0) || (px >= p_ptr->cur_map_wid) ||
		(py < 0) || (py >= p_ptr->cur_map_hgt))
	{
		note(format("Ignoring illegal player location (%d,%d).", py, px));
		return (1);
	}


	/*** Run length decoding ***/

	/* Load the dungeon data */
	for (x = y = 0; y < p_ptr->cur_map_hgt; )
	{
		/* Grab RLE info */
		rd_byte(&count);
		rd_byte(&tmp8u);

		/* Apply the RLE info */
		for (i = count; i > 0; i--)
		{
			/* Extract "info" */
			cave_info[y][x] = tmp8u;

			/* Advance/Wrap */
			if (++x >= p_ptr->cur_map_wid)
			{
				/* Wrap */
				x = 0;

				/* Advance/Wrap */
				if (++y >= p_ptr->cur_map_hgt) break;
			}
		}
	}


	/*** Run length decoding ***/

	/* Load the dungeon data */
	for (x = y = 0; y < p_ptr->cur_map_hgt; )
	{
		/* Grab RLE info */
		rd_byte(&count);
		rd_byte(&tmp8u);

		/* Apply the RLE info */
		for (i = count; i > 0; i--)
		{
			feature_type *f_ptr;

			/* Extract "feat" */
			cave_feat[y][x] = tmp8u;

			update_los_proj_move(y, x);

			/* Get fast access to feature */
			f_ptr = &f_info[tmp8u];

			/* Handle glowing grids */
			if (_feat_ff2_match(f_ptr, FF2_GLOW))
			{
				int d;

				/* Turn on super glow */
				cave_info[y][x] |= (CAVE_HALO);

				/* Spread super glow through adjacent grids */
				for (d = 0; d < 8; d++)
				{
					/* Get coordinates */
					int yy = y + ddy_ddd[d];
					int xx = x + ddx_ddd[d];

					/* Ignore annoying locations */
					if (!in_bounds_fully(yy, xx))
					{
						continue;
					}

					/* Turn on super glow */
					cave_info[yy][xx] |= (CAVE_HALO);
				}
			}

			/* Register dynamic features */
			if (_feat_ff3_match(f_ptr, FF3_DYNAMIC))
			{
				(void)add_dynamic_terrain(y, x);
			}

			/* Update the flags of the current level */
			if (_feat_ff3_match(f_ptr, TERRAIN_MASK))
			{
				level_flag |= get_level_flag((u16b)(f_ptr - f_info));
			}

			/* Advance/Wrap */
			if (++x >= p_ptr->cur_map_wid)
			{
				/* Wrap */
				x = 0;

				/* Advance/Wrap */
				if (++y >= p_ptr->cur_map_hgt) break;
			}
		}
	}


	/*** Player ***/

	/* Load depth */
	p_ptr->depth = depth;


	/* Place player in dungeon */
	if (!player_place(py, px))
	{
		note(format("Cannot place player (%d,%d)!", py, px));
		return (-1);
	}


	/*** Objects ***/

	/* Read the item count */
	rd_u16b(&limit);

	/* Verify maximum */
	if (limit > z_info->o_max)
	{
		note(format("Too many (%d) object entries!", limit));
		return (-1);
	}

	/* Read the dungeon items */
	for (i = 1; i < limit; i++)
	{
		object_type *i_ptr;
		object_type object_type_body;

		s16b o_idx;
		object_type *o_ptr;


		/* Get the object */
		i_ptr = &object_type_body;

		/* Wipe the object */
		object_wipe(i_ptr);

		/* Read the item */
		if (rd_item(i_ptr))
		{
			note("Error reading item");
			return (-1);
		}

		/* Make an object */
		o_idx = o_pop();

		/* Paranoia */
		if (o_idx != i)
		{
			note(format("Cannot place object %d!", i));
			return (-1);
		}

		/* Get the object */
		o_ptr = &o_list[o_idx];

		/* Structure Copy */
		object_copy(o_ptr, i_ptr);

		/* Dungeon floor */
		if (!i_ptr->held_m_idx)
		{
			int x = i_ptr->ix;
			int y = i_ptr->iy;

			/* ToDo: Verify coordinates */

			/* Link the object to the pile */
			o_ptr->next_o_idx = cave_o_idx[y][x];

			/* Link the floor to the object */
			cave_o_idx[y][x] = o_idx;

			/* Rearrange stack if needed */
			rearrange_stack(y, x);
		}
	}


	/*** Monsters ***/

	/* Read the monster count */
	rd_u16b(&limit);

	/* Hack -- verify */
	if (limit > z_info->m_max)
	{
		note(format("Too many (%d) monster entries!", limit));
		return (-1);
	}

	/* Read the monsters */
	for (i = 1; i < limit; i++)
	{
		monster_type *n_ptr;
		monster_type monster_type_body;
		monster_race *r_ptr;

		int r_idx;

		/* Get local monster */
		n_ptr = &monster_type_body;

		/* Clear the monster */
		(void)WIPE(n_ptr, monster_type);

		/* Read the monster */
		rd_monster(n_ptr);

		/* Access the "r_idx" of the chosen monster */
		r_idx = n_ptr->r_idx;

		/* Access the actual race */
		r_ptr = &r_info[r_idx];

		/* If a player ghost, some special features need to be added. */
		if (r_ptr->flags2 & (RF2_PLAYER_GHOST))
		{
			(void)prepare_ghost(n_ptr->r_idx);
		}

		/* Place monster in dungeon */
		if (monster_place(n_ptr->fy, n_ptr->fx, n_ptr) != i)
		{
			note(format("Cannot place monster %d", i));
			return (-1);
		}
	}


	/*** Holding ***/

	/* Reacquire objects */
	for (i = 1; i < o_max; ++i)
	{
		object_type *o_ptr;

		monster_type *m_ptr;

		/* Get the object */
		o_ptr = &o_list[i];

		/* Ignore dungeon objects */
		if (!o_ptr->held_m_idx) continue;

		/* Verify monster index */
		if (o_ptr->held_m_idx > z_info->m_max)
		{
			note("Invalid monster index");
			return (-1);
		}

		/* Get the monster */
		m_ptr = &mon_list[o_ptr->held_m_idx];

		/* Link the object to the pile */
		o_ptr->next_o_idx = m_ptr->hold_o_idx;

		/* Link the monster to the object */
		m_ptr->hold_o_idx = i;
	}

	/*** Effects ***/
	/* Read the effect count */
	rd_u16b(&limit);

	/* Verify maximum */
	if (limit > z_info->x_max)
	{
		note(format("Too many (%d) effect entries!", limit));
		return (-1);
	}

	/* Read the dungeon items */
	for (i = 1; i < limit; i++)
	{

		/* Read the item */
		if (rd_effect())
		{
			note("Error reading effect");
			return (-1);
		}
	}


	/*** Success ***/

	/* The dungeon is ready */
	character_dungeon = TRUE;

	/* Success */
	return (0);
}
Exemplo n.º 17
0
/*
 * Prepare the "temp" array for "target_interactive_set"
 *
 * Return the number of target_able monsters in the set.
 */
static void target_set_interactive_prepare(int mode)
{
	int y, x;

	bool expand_look = (mode & (TARGET_LOOK)) ? TRUE : FALSE;

	/* Reset "temp" array */
	clear_temp_array();

	/* Scan the current panel */
	for (y = Term->offset_y; y < Term->offset_y + SCREEN_HGT; y++)
	{
		for (x = Term->offset_x; x < Term->offset_x + SCREEN_WID; x++)
		{
			bool do_continue = FALSE;

			/* Check overflow */
			if (temp_n >= TEMP_MAX) continue;

			/* Check bounds */
			if (!in_bounds_fully(y, x)) continue;

			/* Require line of sight, unless "look" is "expanded" */
			if (!player_has_los_bold(y, x) && (!expand_look)) continue;

			/* Require "interesting" contents */
			if (!target_set_interactive_accept(y, x)) continue;

			/* Special mode */
			if (mode & (TARGET_KILL))
			{
				/* Must contain a monster */
				if (!(cave_m_idx[y][x] > 0)) do_continue = TRUE;

				/* Must be a targettable monster */
			 	if (!target_able(cave_m_idx[y][x])) do_continue = TRUE;
			}

			/* Don't continue on the trap exception, or if probing. */
			if ((mode & (TARGET_TRAP)) && target_able_trap(y, x)) do_continue = FALSE;
			else if (mode & (TARGET_PROBE)) do_continue = FALSE;

			if (do_continue) continue;

			/*
			 * Hack - don't go over redundant elemental terrain \
			 * (since we have large lakes and pools of the same terrain)
			 */
			if ((p_ptr->target_row > 0) || (p_ptr->target_col > 0))
			{
				if (cave_feat[p_ptr->target_row][p_ptr->target_col] == cave_feat[y][x])
				{
					if (cave_ff3_match(y, x, TERRAIN_MASK)) continue;
				}
			}

			/* Save the location */
			temp_x[temp_n] = x;
			temp_y[temp_n] = y;
			temp_n++;
		}
	}

	/* Set the sort hooks */
	ang_sort_comp = ang_sort_comp_distance;
	ang_sort_swap = ang_sort_swap_distance;

	/* Sort the positions */
	ang_sort(temp_x, temp_y, temp_n);
}
Exemplo n.º 18
0
/**
 * Move player in the given direction, with the given "pickup" flag.
 *
 * This routine should only be called when energy has been expended.
 *
 * Note that this routine handles monsters in the destination grid,
 * and also handles attempting to move into walls/doors/etc.
 */
void move_player(int dir, bool no_options)
{
	unsigned int py = p_ptr->py;
	unsigned int px = p_ptr->px;

	byte str_escape, dex_escape;

	/* Permit the player to move? */
	bool can_move = FALSE;

	/* Player is jumping off a cliff */
	bool falling = FALSE;

	/* Player hits a trap (always unless flying) */
	bool trapped = TRUE;
	
	/* Sliding on the ice */
	bool icy_slide = FALSE;

	int temp;
	unsigned int y, x;

	feature_type *f_ptr;

	/* Find the result of moving */
	y = py + ddy[dir];
	x = px + ddx[dir];
	f_ptr = &f_info[cave_feat[y][x]];


	/* Hack -- attack monsters */
	if (cave_m_idx[y][x] > 0) {
		/* Attack */
		if (py_attack(y, x, TRUE))
			return;
	}

	/* It takes some dexterity, or failing that strength, to get out of pits */
	if (cave_feat[py][px] == FEAT_PIT) {
		str_escape = adj_dex_dis[p_ptr->state.stat_ind[A_STR]];
		dex_escape = adj_dex_dis[p_ptr->state.stat_ind[A_DEX]];

		/* First attempt to leap out of the pit, */
		if ((dex_escape + 1) * 2 < randint1(16)) {
			/* then attempt to climb out of the pit. */
			if (str_escape + 3 < randint1(16)) {
				/* Failure costs a turn. */
				msg("You remain stuck in the pit.");
				/* Failure clears movement */
				p_ptr->previous_action[0] = ACTION_NOTHING;
				return;
			} else
				msg("You clamber out of the pit.");
		} else
			msg("You leap out of the pit.");
	}


	/* Rooted players cannot move */
	if (p_ptr->timed[TMD_ROOT])
	{
		can_move = FALSE;
		msg("You are rooted to the ground and can't move.");
		
		/* Prevent repeated attempts */
		disturb(0, 0);
		
		return;
	}
	
	/* Option to disarm a visible trap. -TNB- */
	/* Hack - Rogues can walk over their own trap - BR */
	else if (cave_visible_trap(y, x) && cave_player_trap(y, x)
			&& OPT(easy_alter)) {
		bool more = FALSE;
		/* Auto-repeat if not already repeating */
		if (cmd_get_nrepeats() == 0)
			cmd_set_repeat(99);

		more = do_cmd_disarm_aux(y, x);

		/* Cancel repeat unless we may continue */
		if (!more)
			disturb(0, 0);
		return;
	}

	/* Some terrain is impassable for the player, such as stone walls. */
	else if (!tf_has(f_ptr->flags, TF_PASSABLE)) {
		/* Disturb the player */
		disturb(0, 0);

		/* Notice unknown obstacles */
		if (!sqinfo_has(cave_info[y][x], SQUARE_MARK)) {
			/* Closed door */
			if (tf_has(f_ptr->flags, TF_DOOR_CLOSED)) {
				msgt(MSG_HITWALL, "You feel a door blocking your way.");
				sqinfo_on(cave_info[y][x], SQUARE_MARK);
				light_spot(y, x);
			}

			/* Wall (or secret door) */
			else {
				msgt(MSG_HITWALL, "You feel a wall blocking your way.");
				sqinfo_on(cave_info[y][x], SQUARE_MARK);
				light_spot(y, x);
			}
		}

		/* Mention known obstacles */
		else {
			/* Closed door */
			if (tf_has(f_ptr->flags, TF_DOOR_CLOSED)) {
				/* Option to automatically open doors. -TNB- */
				if (OPT(easy_alter)) {
					bool more = FALSE;

					/* Auto-repeat if not already repeating */
					if (cmd_get_nrepeats() == 0)
						cmd_set_repeat(99);

					/* Open the door */
					more = do_cmd_open_aux(y, x);

					/* Cancel repeat unless we may continue */
					if (!more)
						disturb(0, 0);
					/* Clear action list */
					p_ptr->previous_action[0] = ACTION_NOTHING;
                    return;
				}

				/* Otherwise, a message. */
				msgt(MSG_HITWALL, "There is a door blocking your way.");
			}

			/* Wall (or secret door) */
			else {
				msgt(MSG_HITWALL, "There is a wall blocking your way.");
			}
		}

		/* Sound */
		sound(MSG_HITWALL);
	}

	/* Normal movement */
	else {
		/* Assume terrain can be traversed normally. */
		can_move = TRUE;

		/* Terrain blocked by a friendly monster */
		if (cave_m_idx[y][x] > 0)
		{
		    monster_type *n_ptr = & m_list[cave_m_idx[y][x]];
		    
		    /* Push monster if it doesn't have a target and hasn't been pushed.
			 * This allows the player to move into a corridor with a monster in
			 * front of him, and have the monster move ahead, if it is faster. If its
			 * not faster, the player will push over it on the second move, as the push
			 * flag below will have been set. */
			 if(((n_ptr->mflag & MFLAG_PUSH) == 0) && !(n_ptr->ty) && !(n_ptr->tx) && push_aside_player(p_ptr->py, p_ptr->px, n_ptr))
			 {
			     int dy = n_ptr->fy - y;
			     int dx = n_ptr->fx - x;
			     unsigned int count = 0;
			     
			     n_ptr->ty = n_ptr->fy;
			     n_ptr->tx = n_ptr->fx;
			     
			     /* Hack -- get new target as far as the monster can move in the direction
				 * pushed. We do this with a walking stick approach to prevent us getting
				 * invalid target locations like (0,0) */
				while (in_bounds_fully(n_ptr->ty + dy, n_ptr->tx + dx)
						&& cave_exist_mon(&r_info[n_ptr->r_idx], n_ptr->ty + dy, n_ptr->tx + dx, TRUE)
						&& (count++ < (MAX_SIGHT / 2)))
				{
					n_ptr->ty = n_ptr->ty + dy;
					n_ptr->tx = n_ptr->tx + dx;
				}

				/* Clear target if none available */
				if ((n_ptr->ty == n_ptr->fy) && (n_ptr->tx == n_ptr->fx))
				{
					n_ptr->ty = 0;
					n_ptr->tx = 0;
				}
			}

			/* The other monster cannot switch places */
			else if (!cave_exist_mon(&r_info[n_ptr->r_idx], p_ptr->py, p_ptr->px, TRUE))
			{
				/* Try to push it aside. Allow aborting of move if an ally */
				if ((!push_aside_player(p_ptr->py, p_ptr->px, n_ptr)) && (get_reaction(F_PLAYER, n_ptr->faction) <= REACT_FRIEND))
				{
					/* No warning if sliding */
					if (no_options)	{}
					/* Don't provide more warning */
					else if (!get_check("Are you sure?")) 
					{
					    temp = FALSE;
					    p_ptr->running = 0;
					    can_move = FALSE;
					}
				}
			}

			/* Hack -- we clear the target if we move over a monster */
			else
			{
				n_ptr->ty = 0;
				n_ptr->tx = 0;
			}

			/* Mark monsters as pushed */
			n_ptr->mflag |= (MFLAG_PUSH);
		}
        
        /*** Handle traversable terrain.  ***/
		if (tf_has(f_ptr->flags, TF_ROCK)) {
			/* Dwarves move easily through rubble */
			if (player_has(PF_DWARVEN))
				can_move = TRUE;

			/* Bats, dragons can fly */
			else if ((p_ptr->schange == SHAPE_BAT)
					 || (p_ptr->schange == SHAPE_WYRM))
				can_move = TRUE;

			/* Require more energy */
			else {
				can_move = TRUE;
				p_ptr->energy_use += 100;
			}
		}

		if (tf_has(f_ptr->flags, TF_TREE)) {
			/* Druids, rangers, Plant Cutie Marks slip easily under
			 * trees */
			if ((player_has(PF_WOODSMAN)) || (player_has(PF_PLANT_FRIEND)))
				can_move = TRUE;

			/* Bats, dragons can fly */
			else if ((p_ptr->schange == SHAPE_BAT)
					 || (p_ptr->schange == SHAPE_WYRM))
				can_move = TRUE;

			/* Require more energy */
			else {
				can_move = TRUE;
				p_ptr->energy_use += 100;
			}
		}

		/* Water now slows rather than stopping -NRM- */
		if (tf_has(f_ptr->flags, TF_WATERY)) {
			/* Stop any run. */
			disturb(0, 0);

			can_move = TRUE;

			/* Speed will need updating */
			p_ptr->update |= PU_BONUS;
		}
		
		/* Walking on to ice can cause you to slide an additional square. */
		if (tf_has(f_ptr->flags, TF_ICY)) {
			/* Stop any run */
			disturb(0, 0);
			
			can_move = TRUE;
			
			/* Slide is less likely with Cold Resist. Never slide with Levitation */
			if (!p_ptr->state.ffall && ((!p_immune(P_RES_COLD)) && (randint1((p_resist_pos(P_RES_COLD) || p_resist_strong(P_RES_COLD)) ? 2 : 4) != 1)))
			    icy_slide = TRUE;
			
			/* Speed will need updating */
			p_ptr->update |= PU_BONUS;
		}

		if (tf_has(f_ptr->flags, TF_FIERY)) {
			/* Assume player will continue. */
			temp = TRUE;

			/* Smart enough to stop running. */
			if (p_ptr->running) {
				/* Ice keeps sliding */
				if (no_options) {}
				else if (!get_check("Lava blocks your path.  Step into it? ")) {
					temp = FALSE;
					p_ptr->running = 0;
				}
			}

			/* Smart enough to sense trouble. */
			else if ((!p_resist_pos(P_RES_FIRE))
					 || (!p_resist_strong(P_RES_FIRE)
						 && (p_ptr->chp <= 100))
					 || (!p_immune(P_RES_FIRE) && (p_ptr->chp <= 30))) {
				/* Sliding continues regardless */
				if (no_options) {}
				else if (!get_check
					("The heat of the lava scalds you! Really enter? ")) {
					temp = FALSE;
				}
			}

			/* Enter if OK or confirmed. */
			if (temp) {
				/* Can always cross. */
				can_move = TRUE;

				/* Feather fall makes one lightfooted. */
				if (p_ptr->state.ffall) {
					notice_obj(OF_FEATHER, 0);
					temp = 49 + randint1(51);
				} else
					temp = 124 + randint1(126);

				/* Will take serious fire damage. */
				fire_dam(temp, "burnt to a cinder in molten lava", SOURCE_ENVIRONMENTAL);
			}
			else
				/* Player refuse to go. */
				can_move = FALSE;
		}
		
		if (tf_has(f_ptr->flags, TF_BURNING))
		{
            /* Assume player will continue */
            temp = TRUE;
            
            /* Smart enough to stop running */
            if (p_ptr->running)
            {
            	if (no_options) {}
				else if (!get_check("Your path is block by a burning tree. Step into it? "))
            	{
            		temp = FALSE;
            		p_ptr->running = 9;
            	}
            }
            
            /* Smart enough to sense trouble */
            else if ((!p_resist_pos(P_RES_FIRE))
					 || (!p_resist_strong(P_RES_FIRE)
						 && (p_ptr->chp <= 100))
					 || (!p_immune(P_RES_FIRE) && (p_ptr->chp <= 30))) {
				if (no_options) {}
				else if (!get_check
					("The heat of the fire burns you! Really enter? ")) {
					temp = FALSE;
				}
			}

			/* Enter if OK or confirmed. */
			if (temp) {
				/* Can always cross. */
				can_move = TRUE;

				/* Take light damage from the fire */
				temp = 49 + randint1(51);

				/* Will take serious fire damage. */
				fire_dam(temp, "burnt to death in a fire.", SOURCE_ENVIRONMENTAL);
			}
			else
				/* Player refuse to go. */
				can_move = FALSE;
		}

		if (tf_has(f_ptr->flags, TF_FALL)) {
			/* Bats, dragons can fly */
			if (!(p_ptr->schange == SHAPE_BAT) &&
				!(p_ptr->schange == SHAPE_WYRM)) {
				/* Assume player will continue. */
				temp = TRUE;

				/* Smart enough to stop running. */
				if (p_ptr->running) {
					if (no_options) {}
					else if (!get_check
						("You have come to a cliff.  Step off it? ")) {
						can_move = FALSE;
						temp = FALSE;
						p_ptr->running = 0;
					}
				}

				/* Smart enough to sense trouble. */
				else if (!p_ptr->timed[TMD_BLIND]) {
					if (no_options) {}
					else if (!get_check("It's a cliff! Really step off it? ")) {
						can_move = FALSE;
						temp = FALSE;
					}
				}

				/* Step off if confirmed. */
				if (temp) {
					/* Will take serious damage. */
					falling = TRUE;
				}
			}
		}
	}

	/* If the player can move, handle various things. */
	if (can_move) {
		/* Move player */
		monster_swap(py, px, y, x);

		/* Update speed if stepping out of water */
		if (tf_has(f_info[cave_feat[py][px]].flags, TF_WATERY))
			p_ptr->update |= PU_BONUS;

		/* Update stealth for Unlight */
		if (player_has(PF_UNLIGHT))
			p_ptr->update |= PU_BONUS;

		/* Update speed for Plant cutie mark woodspersons */
		if (player_has(PF_WOODSMAN) && player_has(PF_PLANT_FRIEND))
			p_ptr->update |= PU_BONUS;

		/* New location */
		y = py = p_ptr->py;
		x = px = p_ptr->px;
		f_ptr = &f_info[cave_feat[y][x]];
		    

		/* Fall off a cliff */
		if (falling)
			fall_off_cliff();
			
		
        /* Sliding on ice prevents searching */
        if (!icy_slide)
        {
			/* Spontaneous Searching */
			if (p_ptr->state.skills[SKILL_SEARCH_FREQUENCY] > 49) {
				(void) search(FALSE);
			} else if (0 ==
					   randint0(50 -
								p_ptr->state.skills[SKILL_SEARCH_FREQUENCY])) {
				(void) search(FALSE);
			}
	
			/* Continuous Searching */
			if (p_ptr->searching) {
				(void) search(FALSE);
			}
		}

		/* Handle "store doors" */
		if (tf_has(f_ptr->flags, TF_SHOP)) {
			/* Disturb */
			disturb(0, 0);
			cmd_insert(CMD_ENTER_STORE);
		}

		/* All other grids (including traps) */
		else {
			/* Handle objects (later) */
			p_ptr->notice |= (PN_PICKUP);
		}

		/* Flying players have a chance to miss traps */
		if ((p_ptr->schange == SHAPE_BAT)
			|| (p_ptr->schange == SHAPE_WYRM)) {
			if (cave_invisible_trap(y, x) && cave_player_trap(y, x)
				&& (randint0(3) != 0))
				trapped = FALSE;
			else if (cave_visible_trap(y, x) && cave_player_trap(y, x) &&
					 (randint0(10) != 0))
				trapped = FALSE;
		}

		/* Discover invisible traps */
		if (cave_invisible_trap(y, x) && trapped) {
			/* Disturb */
			disturb(0, 0);

			/* Hit the trap. */
			hit_trap(y, x);
		}

		/* Set off a visible trap */
		else if (cave_visible_trap(y, x) && cave_player_trap(y, x) &&
				 trapped) {
			/* Disturb */
			disturb(0, 0);

			/* Hit the trap. */
			hit_trap(y, x);
		}

		/* Walk on a monster trap */
		else if (cave_monster_trap(y, x)) {
			msg("You inspect your cunning trap.");
		}
		
		/* Slide an additional square on the ice */
		if (icy_slide)
		    move_player(dir, TRUE);
	}
}