Exemplo n.º 1
0
    virtual void onDraw(SkCanvas* canvas) {
        this->drawBG(canvas);
        
        canvas->translate(SIZE/2, SIZE/2);

        SkPaint pathPaint, triPaint;
        
        pathPaint.setColor(SK_ColorBLUE);
        pathPaint.setStrokeWidth(SIZE / 12);

        triPaint.setColor(SK_ColorRED);
        triPaint.setStyle(SkPaint::kStroke_Style);

        for (size_t i = 0; i < COUNT_PROCS; i++) {
            pathPaint.setStyle(SkPaint::kFill_Style);
            draw_path(canvas, pathPaint, fPaths[i], triPaint);

            canvas->save();
            canvas->translate(0, SIZE * 6 / 5);

            pathPaint.setStyle(SkPaint::kStroke_Style);
            draw_path(canvas, pathPaint, fPaths[i], triPaint);
            
            canvas->restore();
            canvas->translate(SIZE * 6 / 5, 0);
        }
    }
bool GrClipMaskManager::drawClipShape(GrGpu* gpu,
                                      GrTexture* target,
                                      const GrClip& clipIn,
                                      int index) {
    GrDrawState* drawState = gpu->drawState();
    GrAssert(NULL != drawState);

    drawState->setRenderTarget(target->asRenderTarget());

    if (kRect_ClipType == clipIn.getElementType(index)) {
        if (clipIn.getDoAA(index)) {
            // convert the rect to a path for AA
            SkPath temp;
            temp.addRect(clipIn.getRect(index));

            return draw_path(this->getContext(), gpu, temp,
                             kEvenOdd_PathFill, clipIn.getDoAA(index));
        } else {
            gpu->drawSimpleRect(clipIn.getRect(index), NULL, 0);
        }
    } else {
        return draw_path(this->getContext(), gpu,
                         clipIn.getPath(index),
                         clipIn.getPathFill(index),
                         clipIn.getDoAA(index));
    }
    return true;
}
Exemplo n.º 3
0
void draw_path( int m, int n )	{
	if( m == 0 && n == 0 )	return;

	printf( "(%d, %d)\n", n+1, m+1 );
//	printf( "(%d, %d)\n", m+1, n+1 );

	if( from[m][n] == LEFT )	{
		draw_path( m-1, n );
	}
	else	{
		draw_path( m, n-1 );
	}
}
Exemplo n.º 4
0
/**
 * @brief Renders everything; called once on startup
 * and then to animate solver moves.
 */
void MazeSolverApp::OnRender()
{
    SDL_FillRect(surf, NULL, SDL_MapRGB(surf->format, 0, 0, 0));
    draw_maze();
    draw_path();
    SDL_Flip(surf);
}
Exemplo n.º 5
0
bool GrClipMaskManager::drawClipShape(GrTexture* target,
                                      const SkClipStack::Iter::Clip* clip,
                                      const GrIRect& resultBounds) {
    GrDrawState* drawState = fGpu->drawState();
    GrAssert(NULL != drawState);

    drawState->setRenderTarget(target->asRenderTarget());

    if (NULL != clip->fRect) {
        if (clip->fDoAA) {
            getContext()->getAARectRenderer()->fillAARect(fGpu, fGpu,
                                                          *clip->fRect,
                                                          true);
        } else {
            fGpu->drawSimpleRect(*clip->fRect, NULL);
        }
    } else if (NULL != clip->fPath) {
        return draw_path(this->getContext(), fGpu,
                         *clip->fPath,
                         get_path_fill(*clip->fPath),
                         clip->fDoAA,
                         resultBounds);
    }
    return true;
}
Exemplo n.º 6
0
int main() {
	slurp();
	blow_path();
	drop_crumbs(&matrix[0][0]);
	draw_path();
	printf("Best sum = %ld\n", matrix[0][0].best_sum);
	return 0;
}
Exemplo n.º 7
0
void draw_cairo(cairo_surface_t *in)
{

	cairo_t *cr;
	int mid ;

	if(0)printf("%p\n", in);

	if(!psize ) return;
	if(!in) return;

	cr = cairo_create (in);
	draw_path(cr);
	draw_fill(cr);
	draw_text(cr);
	draw_mask(cr);
	return;

	cairo_set_source_rgb (cr, 0, 1, 0);
	cairo_rectangle (cr, 0, 0, 640,480);
	cairo_fill (cr);

	cairo_set_source_rgb (cr, 0, 0, 0.9);
	cairo_rectangle (cr, 0, 0, 64,480);
	cairo_fill (cr);

	//   cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
//	cairo_set_source_rgba (cr, 0, 0, 0, 0);
//	cairo_paint (cr);

	cairo_set_source_rgb (cr, 1, 1, 1);
	cairo_rectangle (cr, 0, 0, 100, 100);
	cairo_paint_with_alpha (cr, 0.5);

	//   /cairo_fill (cr);

	//*surface_inout = cairo_surface_reference (cairo_get_target (cr));
#define M_PI 3.1415
	cairo_arc (cr, 128.0, 128.0, 76.8, 0, 2 * M_PI);
	cairo_clip (cr);


	cairo_new_path (cr);  
	cairo_rectangle (cr, 0, 0, 256, 256);
	cairo_fill (cr);
	cairo_set_source_rgb (cr, 0, 1, 0);
	cairo_move_to (cr, 0, 0);
	cairo_line_to (cr, 256, 256);
	cairo_move_to (cr, 256, 0);
	cairo_line_to (cr, 0, 256);
	cairo_set_line_width (cr, 10.0);
	cairo_stroke (cr);

	cairo_destroy (cr);
}
Exemplo n.º 8
0
void clip_rgn_draw(drawingStates *states, FILE *out) {
    if (!(states->inPath) && states->currentDeviceContext.clipRGN != NULL) {
        states->currentDeviceContext.clipID = get_id(states);
        fprintf(out, "<%sdefs><%sclipPath id=\"clip-%d\">",
                states->nameSpaceString, states->nameSpaceString,
                states->currentDeviceContext.clipID);
        fprintf(out, "<%spath d=\"", states->nameSpaceString);
        draw_path(states->currentDeviceContext.clipRGN, out);
        fprintf(out, "Z\" />");
        fprintf(out, "</clipPath></defs>\n");
    }
}
Exemplo n.º 9
0
    void onDraw(SkCanvas* canvas) override {
        canvas->drawColor(SK_ColorWHITE);
        canvas->translate(STROKE_WIDTH*3/2, STROKE_WIDTH*3/2);

        SkPaint paint;
        paint.setStyle(SkPaint::kStroke_Style);
        paint.setStrokeWidth(STROKE_WIDTH);

        static const SkPaint::Join gJoins[] = {
            SkPaint::kMiter_Join, SkPaint::kRound_Join, SkPaint::kBevel_Join
        };

        static const SkScalar W = 80;
        static const SkScalar H = 80;
        static const SkRect gRects[] = {
            { 0, 0, W, H },
            { W, 0, 0, H },
            { 0, H, W, 0 },
            { 0, 0, STROKE_WIDTH, H },
            { 0, 0, W, STROKE_WIDTH },
            { 0, 0, STROKE_WIDTH/2, STROKE_WIDTH/2 },
            { 0, 0, W, 0 },
            { 0, 0, 0, H },
            { 0, 0, 0, 0 },
            { 0, 0, W, FLT_EPSILON },
            { 0, 0, FLT_EPSILON, H },
            { 0, 0, FLT_EPSILON, FLT_EPSILON },
        };

        for (int doFill = 0; doFill <= 1; ++doFill) {
            for (size_t i = 0; i < SK_ARRAY_COUNT(gJoins); ++i) {
                SkPaint::Join join = gJoins[i];
                paint.setStrokeJoin(join);

                SkAutoCanvasRestore acr(canvas, true);
                for (size_t j = 0; j < SK_ARRAY_COUNT(gRects); ++j) {
                    const SkRect& r = gRects[j];

                    SkPath path, fillPath;
                    path.addRect(r);
                    paint.getFillPath(path, &fillPath);
                    draw_path(canvas, fillPath, r, join, doFill);

                    canvas->translate(W + 2 * STROKE_WIDTH, 0);
                }
                acr.restore();
                canvas->translate(0, H + 2 * STROKE_WIDTH);
            }
            paint.setStyle(SkPaint::kStrokeAndFill_Style);
        }
    }
Exemplo n.º 10
0
static void draw_bitmap(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
    SkPaint paint;

    SkIRect bounds;
    r.roundOut(&bounds);

    SkBitmap bm;
    bm.allocN32Pixels(bounds.width(), bounds.height());
    bm.eraseColor(SK_ColorTRANSPARENT);
    SkCanvas c(bm);
    draw_path(&c, r, nullptr);

    paint.setImageFilter(std::move(imf));
    canvas->drawBitmap(bm, 0, 0, &paint);
}
Exemplo n.º 11
0
static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
    SkPaint paint;

    SkIRect bounds;
    r.roundOut(&bounds);

    SkBitmap bm;
    bm.allocN32Pixels(bounds.width(), bounds.height());
    bm.eraseColor(SK_ColorTRANSPARENT);
    SkCanvas c(bm);
    draw_path(&c, r, NULL);

    paint.setImageFilter(imf);
    canvas->save();
    canvas->clipRect(r);
    canvas->drawBitmap(bm, 0, 0, &paint);
    canvas->restore();
}
Exemplo n.º 12
0
    void onDraw(SkCanvas* canvas) override {
        SkPaint paint;
        SkPath path;
        paint.setStyle(SkPaint::Style::kStroke_Style);
        canvas->translate(5.0f, 5.0f);
        const SkScalar size = 60.0f;
        for (int i = 0; i < 2; i++) {
            paint.setAntiAlias(i == 1);
            for (int j = 0; j < 4; j++) {
                SkScalar scale = 4.0f - j;
                paint.setStrokeWidth(4.0f / scale);
                canvas->save();
                canvas->translate(size / 2.0f, size / 2.0f);
                canvas->scale(scale, scale);
                draw_path(size / 2.0f / scale, canvas, paint);
                canvas->restore();

                canvas->save();
                canvas->translate(size / 2.0f, 80.0f + size / 2.0f);
                canvas->scale(scale, scale);
                canvas->drawCircle(0.0f, 0.0f, size / 2.0f / scale, paint);
                canvas->restore();

                canvas->save();
                canvas->translate(0.0f, 160.0f);
                canvas->scale(scale, scale);
                canvas->drawRect(SkRect::MakeXYWH(0.0f, 0.0f, size / scale, size / scale), paint);
                canvas->restore();

                canvas->save();
                canvas->translate(0.0f, 240.0f);
                canvas->scale(scale, scale);
                canvas->drawLine(0.0f, 0.0f, size / scale, size / scale, paint);
                canvas->restore();

                canvas->translate(80.0f, 0.0f);
            }
        }

    }
Exemplo n.º 13
0
void
EditorInputCenter::draw(DrawingContext& context) {
  draw_tile_tip(context);
  draw_path(context);

  if (render_grid) {
    draw_tile_grid(context);
  }

  if (object_tip) {
    object_tip->draw(context, mouse_pos);
  }

  if (dragging && Editor::current()->tileselect.select_mode->get_mode() == 1
      && !dragging_right) {
    // Draw selection rectangle...
    Vector p0 = drag_start - Editor::current()->currentsector->camera->get_translation();
    Vector p1 = Vector(drag_start.x, sector_pos.y) - Editor::current()->currentsector->camera->get_translation();
    Vector p2 = Vector(sector_pos.x, drag_start.y) - Editor::current()->currentsector->camera->get_translation();

    context.draw_filled_rect(Rectf(p0, p1 + Vector(2, 2)),
                             Color(0.0f, 1.0f, 0.0f, 1.0f), 0.0f, LAYER_GUI-5);
    context.draw_filled_rect(Rectf(p2, mouse_pos + Vector(2, 2)),
                             Color(0.0f, 1.0f, 0.0f, 1.0f), 0.0f, LAYER_GUI-5);
    context.draw_filled_rect(Rectf(p0, p2 + Vector(2, 2)),
                             Color(0.0f, 1.0f, 0.0f, 1.0f), 0.0f, LAYER_GUI-5);
    context.draw_filled_rect(Rectf(p1, mouse_pos + Vector(2, 2)),
                             Color(0.0f, 1.0f, 0.0f, 1.0f), 0.0f, LAYER_GUI-5);

    context.draw_filled_rect(Rectf(p0, mouse_pos),
                             Color(0.0f, 1.0f, 0.0f, 0.2f), 0.0f, LAYER_GUI-5);
  }

  if (dragging && dragging_right) {
    context.draw_filled_rect(selection_draw_rect(),
                             Color(0.2f, 0.4f, 1.0f, 0.6f), 0.0f, LAYER_GUI-13);
  }
}
Exemplo n.º 14
0
/*
 * Handle "target" and "look".
 *
 * Note that this code can be called from "get_aim_dir()".
 *
 * Currently, when "flag" is true, that is, when
 * "interesting" grids are being used, and a directional key is used, we
 * only scroll by a single panel, in the direction requested, and check
 * for any interesting grids on that panel.  The "correct" solution would
 * actually involve scanning a larger set of grids, including ones in
 * panels which are adjacent to the one currently scanned, but this is
 * overkill for this function.  XXX XXX
 *
 * Hack -- targetting/observing an "outer border grid" may induce
 * problems, so this is not currently allowed.
 *
 * The player can use the direction keys to move among "interesting"
 * grids in a heuristic manner, or the "space", "+", and "-" keys to
 * move through the "interesting" grids in a sequential manner, or
 * can enter "location" mode, and use the direction keys to move one
 * grid at a time in any direction.  The "t" (set target) command will
 * only target a monster (as opposed to a location) if the monster is
 * target_able and the "interesting" mode is being used.
 *
 * The current grid is described using the "look" method above, and
 * a new command may be entered at any time, but note that if the
 * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
 * where "space" has no obvious meaning) then "space" will scan
 * through the description of the current grid until done, instead
 * of immediately jumping to the next "interesting" grid.  This
 * allows the "target" command to retain its old semantics.
 *
 * The "*", "+", and "-" keys may always be used to jump immediately
 * to the next (or previous) interesting grid, in the proper mode.
 *
 * The "return" key may always be used to scan through a complete
 * grid description (forever).
 *
 * This command will cancel any old target, even if used from
 * inside the "look" command.
 *
 * 'mode' is one of TARGET_LOOK or TARGET_KILL.
 * 'x' and 'y' are the initial position of the target to be highlighted,
 * or -1 if no location is specified.
 * Returns TRUE if a target has been successfully set, FALSE otherwise.
 */
bool target_set_interactive(int mode, int x, int y)
{
	int py = p_ptr->py;
	int px = p_ptr->px;

	int i, d, m, t, bd;
	int wid, hgt, help_prompt_loc;

	bool done = FALSE;
	bool flag = TRUE;
	bool help = FALSE;
	bool list_floor_objects = auto_display_lists;

	u16b path_n;
	u16b path_g[PATH_SIZE];
	u16b path_gx[PATH_SIZE];

	ui_event_data query;

	char info[80];

	/* These are used for displaying the path to the target */
	char path_char[MAX_RANGE];
	byte path_attr[MAX_RANGE];

	/* If we haven't been given an initial location, start on the
	   player. */
	if (x == -1 || y == -1)
	{
		x = p_ptr->px;
		y = p_ptr->py;
	}
    /* If we /have/ been given an initial location, make sure we
	   honour it by going into "free targeting" mode. */
	else
	{
		flag = FALSE;
	}


	/* Cancel target */
	target_set_monster(0);

	/* make some buttons */
	button_backup_all();
	button_kill_all();
	button_add("[ESCAPE]", ESCAPE);
	button_add("[NEXT]", '+');
	button_add("[PREV]", '-');
	button_add("[PLAYER]", 'p');
	button_add("[PATHFIND]", 'g');
	button_add("[TARGET]", 't');

	/* health_track(0); */

	  /* All grids are selectable */
	if (mode & (TARGET_GRID))
	{
		/* Disable other modes */
		mode &= ~(TARGET_LOOK | TARGET_KILL | TARGET_TRAP);

		/* Disable interesting grids */
		flag = FALSE;
	}

	/* Calculate the window location for the help prompt */
	Term_get_size(&wid, &hgt);
	help_prompt_loc = hgt - (mouse_buttons ? 2 : 1);

	/* Display the help prompt */
	prt("'?' - help", help_prompt_loc, 0);

	/* Prepare the "temp" array */
	target_set_interactive_prepare(mode);

	/* Start near the player */
	m = 0;

	/* Interact */
	while (!done)
	{
		button_kill('l');
		button_kill('?');
		if (list_floor_objects)
		{
			button_add("[HIDE_OBJLIST]", 'l');
		}
		else button_add("[SHOW_OBJLIST]", 'l');
		if (help)
		{
			button_add("[HIDE_HELP]", '?');
		}
		else button_add("[SHOW_HELP]",'?');

		/* Interesting grids */
		if (flag && temp_n)
		{
			bool path_drawn = FALSE;
			int yy, xx;

			y = temp_y[m];
			x = temp_x[m];

			button_add("[SCAN]",'o');

			/* Update help */
			if (help)
			{
				bool good_target = ((cave_m_idx[y][x] > 0) && target_able(cave_m_idx[y][x]));
				target_display_help(good_target, !(flag && temp_n));
			}

			/* Dummy pointers to send to project_path */
			yy = y;
			xx = x;

			/* Allow targets for monsters....or traps, if applicable */
			if (((cave_m_idx[y][x] > 0) && target_able(cave_m_idx[y][x])) ||
				((mode & (TARGET_TRAP)) && target_able_trap(y, x)))
			{
				strcpy(info, "q,t,r,l,p,o,+,-,<dir>");
			}

			/* Dis-allow target */
			else
			{
				strcpy(info, "q,p,l,o,+,-,<dir>");
			}

			/* Adjust panel if needed */
			if (adjust_panel(y, x))
			{
				/* Handle stuff */
				handle_stuff();
			}

			/* Find the path. */
			path_n = project_path(path_g, path_gx, MAX_RANGE, py, px, &yy, &xx, PROJECT_THRU);

			/* Draw the path in "target" mode. If there is one */
			if ((mode & (TARGET_KILL)) && (cave_info[y][x] & (CAVE_FIRE)))
			{
				path_drawn = draw_path(path_n, path_g, path_char, path_attr, py, px, y, x);
			}
			event_signal(EVENT_MOUSEBUTTONS);

			/* Describe and Prompt */
			query = target_set_interactive_aux(y, x, mode, info, list_floor_objects);

			/* Remove the path */
			if (path_drawn) load_path(path_n, path_g, path_char, path_attr);

			/* Cancel tracking */
			/* health_track(0); */

			/* Assume no "direction" */
			d = 0;

			/* Analyze */
			switch (query.key)
			{
				case ESCAPE:
				case 'q':
				{
					done = TRUE;
					break;
				}

				case ' ':
				case '*':
				case '+':
				{
					if (++m == temp_n) m = 0;
					break;
				}

				case '-':
				{
					if (m-- == 0)  m = temp_n - 1;
					break;
				}

				case 'p':
				{
					/* Recenter around player */
					verify_panel();

					/* Handle stuff */
					handle_stuff();

					y = py;
					x = px;
				}

				case 'o':
				{
					flag = FALSE;
					break;
				}

				case 'm':
				{
					break;
				}

				/* If we click, move the target location to the click and
				   switch to "free targetting" mode by unsetting 'flag'.
				   This means we get some info about wherever we've picked. */
				case DEFINED_XFF:
				{
					x = KEY_GRID_X(query);
					y = KEY_GRID_Y(query);
					flag = FALSE;
					break;
				}

				case 't':
				case '5':
				case '0':
				case '.':
				{
					int m_idx = cave_m_idx[y][x];

					if ((m_idx > 0) && target_able(m_idx))
					{
						health_track(m_idx);
						target_set_monster(m_idx);
						done = TRUE;
					}
					else if ((mode & (TARGET_TRAP)) && target_able_trap(y, x))
 					{
 						target_set_location(y, x);
 						done = TRUE;
 					}
					else if (mode & (TARGET_PROBE))
					{
					 	target_set_location(y, x);
					 	done = TRUE;
					}
					else
					{
						bell("Illegal target!");
					}
					break;
				}

				case 'g':
				{
					cmd_insert(CMD_PATHFIND, y, x);
					done = TRUE;
					break;
				}

				case 'l':
				{
					list_floor_objects = (!list_floor_objects);
				}

				case '?':
				{
					help = !help;

					/* Redraw main window */
					p_ptr->redraw |= (PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIP);
					Term_clear();
					handle_stuff();
					if (!help)
						prt("'?' - help", help_prompt_loc, 0);

					break;
				}

				default:
				{
					/* Extract direction */
					d = target_dir(query.key);

					/* Oops */
					if (!d) bell("Illegal command for target mode!");

					break;
				}
			}

			/* Hack -- move around */
			if (d)
			{
				int old_y = temp_y[m];
				int old_x = temp_x[m];

				/* Find a new monster */
				i = target_pick(old_y, old_x, ddy[d], ddx[d]);

				/* Scroll to find interesting grid */
				if (i < 0)
				{
					int old_wy = Term->offset_y;
					int old_wx = Term->offset_x;

					/* Change if legal */
					if (change_panel(d))
					{
						/* Recalculate interesting grids */
						target_set_interactive_prepare(mode);

						/* Find a new monster */
						i = target_pick(old_y, old_x, ddy[d], ddx[d]);

						/* Restore panel if needed */
						if ((i < 0) && modify_panel(Term, old_wy, old_wx))
						{
							/* Recalculate interesting grids */
							target_set_interactive_prepare(mode);
						}

						/* Handle stuff */
						handle_stuff();
					}
				}

				/* Use interesting grid if found */
				if (i >= 0) m = i;
			}
		}

		/* Arbitrary grids */
		else
		{
			bool path_drawn = FALSE;

			/* Dummy pointers to send to project_path */
			int yy = y;
			int xx = x;

			/* Don't need this button any more */
			button_kill('o');

			/* Update help */
			if (help)
			{
				bool good_target = ((cave_m_idx[y][x] > 0) && target_able(cave_m_idx[y][x]));
				target_display_help(good_target, !(flag && temp_n));
			}

			/* Default prompt */
			if (!(mode & (TARGET_GRID)))
			{
				strcpy(info, "q,t,l,p,m,+,-,<dir>");
			}

			/* Disable monster selection */
			else
			{
				strcpy(info, "q,t,l.p,+,-,<dir>");
			}

			/* Find the path. */
			path_n = project_path(path_g, path_gx, MAX_RANGE, py, px, &yy, &xx, PROJECT_THRU);

			/* Draw the path in "target" mode. If there is one */
			if ((mode & (TARGET_KILL)) && (cave_info[y][x] & (CAVE_FIRE)))
			{
				/* Save target info */
				path_drawn = draw_path(path_n, path_g, path_char, path_attr, py, px, y, x);
			}

			event_signal(EVENT_MOUSEBUTTONS);

			/* Describe and Prompt (enable "TARGET_LOOK") */
			query = target_set_interactive_aux(y, x, (mode | TARGET_LOOK), info, list_floor_objects);

			/* Remove the path */
			if (path_drawn)  load_path(path_n, path_g, path_char, path_attr);

			/* Cancel tracking */
			/* health_track(0); */

			/* Assume no direction */
			d = 0;

			/* Analyze the keypress */
			switch (query.key)
			{
				case ESCAPE:
				case 'q':
				{
					done = TRUE;
					break;
				}

				case ' ':
				case '*':
				case '+':
				case '-':
				{
					break;
				}

				case 'p':
				{
					/* Recenter around player */
					verify_panel();

					/* Handle stuff */
					handle_stuff();

					y = py;
					x = px;
				}

				case 'o':
				{
					break;
				}

				case 'm':
				{
					/* Monster selection is disabled */
					if (mode & (TARGET_GRID)) break;

					flag = TRUE;

					m = 0;
					bd = 999;

					/* Pick a nearby monster */
					for (i = 0; i < temp_n; i++)
					{
						t = distance(y, x, temp_y[i], temp_x[i]);

						/* Pick closest */
						if (t < bd)
						{
							m = i;
							bd = t;
						}
					}

					/* Nothing interesting */
					if (bd == 999) flag = FALSE;

					break;
				}

				case '\xff':
				{
					/* We only target if we click somewhere where the cursor
					   is already (i.e. a double-click without a time limit) */
					if (KEY_GRID_X(query) == x && KEY_GRID_Y(query) == y)
					{
						/* Make an attempt to target the monster on the given
						   square rather than the square itself (it seems this
						   is the more likely intention of clicking on a
						   monster). */
						int m_idx = cave_m_idx[y][x];

						if ((m_idx > 0) && target_able(m_idx))
						{
							health_track(m_idx);
							target_set_monster(m_idx);
						}
						else
						{
							/* There is no monster, or it isn't targettable,
							   so target the location instead. */
							target_set_location(y, x);
						}

						done = TRUE;
					}
					else
					{
						/* Just move the cursor for now - another click will
						   target. */
						x = KEY_GRID_X(query);
						y = KEY_GRID_Y(query);
					}
					break;
				}

				case 't':
				case '5':
				case '0':
				case '.':
				{
					target_set_location(y, x);
					done = TRUE;
					break;
				}

				case 'g':
				{
					cmd_insert(CMD_PATHFIND, y, x);
					done = TRUE;
					break;
				}

				case 'l':
				{
					list_floor_objects = (!list_floor_objects);
				}

				case '?':
				{
					help = !help;

					/* Redraw main window */
					p_ptr->redraw |= (PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIP);
					Term_clear();
					handle_stuff();
					if (!help)
						prt("'?' - help.", help_prompt_loc, 0);

					break;
				}


				default:
				{
					/* Extract a direction */
					d = target_dir(query.key);

					/* Oops */
					if (!d) bell("Illegal command for target mode!");

					break;
				}
			}

			/* Handle "direction" */
			if (d)
			{
				int dungeon_hgt = p_ptr->cur_map_hgt;
				int dungeon_wid = p_ptr->cur_map_wid;

				/* Move */
				x += ddx[d];
				y += ddy[d];

				/* Slide into legality */
				if (x >= dungeon_wid - 1) x--;
				else if (x <= 0) x++;

				/* Slide into legality */
				if (y >= dungeon_hgt - 1) y--;
				else if (y <= 0) y++;

				/* Adjust panel if needed */
				if (adjust_panel(y, x))
				{
					/* Handle stuff */
					handle_stuff();

					/* Recalculate interesting grids */
					target_set_interactive_prepare(mode);

				}
			}
		}
	}

	/* Forget */
	temp_n = 0;

	/* Redraw as necessary */
	if (help)
	{
		p_ptr->redraw |= (PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIP);
		Term_clear();
	}
	else
	{
		prt("", 0, 0);
		prt("", help_prompt_loc, 0);
		p_ptr->redraw |= (PR_DEPTH | PR_STATUS);
	}



	/* Recenter around player */
	verify_panel();

	/* Restore buttons */
	button_restore();

	/* Handle stuff */
	handle_stuff();

	/* Failure to set target */
	if (!p_ptr->target_set) return (FALSE);

	/* Success */
	return (TRUE);
}
Exemplo n.º 15
0
int context_menu_cave(int cy, int cx, int adjacent, int mx, int my)
{
	menu_type *m;
	rect_region r;
	int selected;
	char *labels;

	cave_type *c_ptr = area(cx,cy);
	pcave_type *pc_ptr = parea(cx,cy);
	feature_type *feat;
	object_type *o_ptr;

	/* paranoia */
	if (!in_boundsp(cx,cy)) return 0;

	m = menu_dynamic_new();
	if (!m) {
		return 0;
	}

	labels = (char*)string_make(lower_case);
	m->selections = labels;

	feat  = &(f_info[c_ptr->feat]);

	menu_dynamic_add_label(m, "Look At", 'l', 1, labels);
	if (c_ptr->m_idx) {
		menu_dynamic_add_label(m, "Recall Info", '/', 18, labels);
	}
	menu_dynamic_add_label(m, "Use Item On", 'u', 2, labels);
	if (player_can_cast()) {
		menu_dynamic_add_label(m, "Cast On", 'm', 3, labels);
	}
	if (adjacent) {
		if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml) {
			menu_dynamic_add_label(m, "Attack", '+', 4, labels);
		} else {
			menu_dynamic_add_label(m, "Alter", '+', 4, labels);
		}
		if (c_ptr->o_idx) {
			o_ptr = chest_check(cx,cy);
			if (o_ptr && o_ptr->pval) {
				//if (!squelch_item_ok(o_ptr)) {
					if (object_known_p(o_ptr)) {
						if (chest_traps[o_ptr->pval]) {
							menu_dynamic_add_label(m, "Disarm Chest", 'D', 5, labels);
							menu_dynamic_add_label(m, "Open Chest", 'o', 8, labels);
						} else {
							menu_dynamic_add_label(m, "Open Disarmed Chest", 'o', 8, labels);
						}
					} else {
						menu_dynamic_add_label(m, "Open Chest", 'o', 8, labels);
					}
				//}
			}
		}
		if (is_visible_trap(c_ptr)) {
			menu_dynamic_add_label(m, "Disarm", 'D', 5, labels);
			menu_dynamic_add_label(m, "Jump Onto", 'W', 6, labels);
		}
		if (pc_ptr->feat) {
			if ((feat->flags & FF_CLOSEABLE)
				|| ((feat->flags & FF_BROKEN) && (feat->flags & FF_DOOR)))
			{
				menu_dynamic_add_label(m, "Close", 'c', 7, labels);
			}
			if (feat->flags & FF_CLOSED) {
				menu_dynamic_add_label(m, "Open", 'o', 8, labels);
				menu_dynamic_add_label(m, "Bash Open", 'B', 9, labels);
				menu_dynamic_add_label(m, "Lock", 'D', 5, labels);
				menu_dynamic_add_label(m, "Jam", 'j', 10, labels);
			}
			if (feat->flags & FF_DIG) {
				menu_dynamic_add_label(m, "Tunnel", 'T', 11, labels);
			}
		}
		menu_dynamic_add_label(m, "Search", 's', 12, labels);
		menu_dynamic_add_label(m, "Walk Towards", ';', 14, labels);
	} else {
		menu_dynamic_add_label(m, "Pathfind To", ',', 13, labels);
		menu_dynamic_add_label(m, "Walk Towards", ';', 14, labels);
		menu_dynamic_add_label(m, "Run Towards", '.', 15, labels);
	}
	if (player_can_fire()) {
		menu_dynamic_add_label(m, "Fire On", 'f', 16, labels);
	}
	if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml) {
		if (is_pet(&(m_list[c_ptr->m_idx]))) {
			menu_dynamic_add_label(m, "Pet Commands", 'p', 19, labels);
		}
	}
	menu_dynamic_add_label(m, "Throw To", 'v', 17, labels);

	/* work out display region */
	r.width = menu_dynamic_longest_entry(m) + 3 + 2; /* +3 for tag, 2 for pad */
	if (mx > Term->wid - r.width - 1) {
		r.col = Term->wid - r.width - 1;
	} else {
		r.col = mx + 1;
	}
	r.page_rows = m->count;
	if (my > Term->hgt - r.page_rows - 1) {
		if (my - r.page_rows - 1 <= 0) {
			/* menu has too many items, so put in upper right corner */
			r.row = 1;
			r.col = Term->wid - r.width - 1;
		} else {
			r.row = Term->hgt - r.page_rows - 1;
		}
	} else {
		r.row = my + 1;
	}

	/* Hack -- no flush needed */
	msg_flag = FALSE;

	screen_save();
	button_backup_all(TRUE);

	/* if there is a monster, draw a target path, which will be erased by the
	 * screen load below */
	if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml) {
		sint path_n;
		coord path_g[2*MAX_RANGE+1];

		/* Find the path. */
		path_n = project_path(path_g, p_ptr->px, p_ptr->py, cx, cy, PROJECT_THRU);
		/* Draw the path. */
		draw_path(path_n, path_g, NULL, NULL, p_ptr->px, p_ptr->py);
	}

	menu_layout(m, &r);
	rect_region_erase_bordered(&r);

	/* display the prompt for the context menu */
	target_look_grid_prompt(0, 0, cx, cy,
		format("($UEnter to select command$Y\n$V, $UESC$ to cancel$Y%c$V) You see", ESCAPE));

	/* Hack - redraw stuff to show the target health bar */
	health_redraw();

	/* show the menu and pick from it */
	selected = menu_dynamic_select(m);

	menu_dynamic_free(m);
	string_free(labels);

	button_restore();
	screen_load();

	if (selected == 1) {
		/* look at the spot */
		if (target_set_interactive(TARGET_LOOK, cx, cy)) {
			msgf("Target Selected.");
		}
	} else
	if (selected == 2) {
		/* use an item on the spot */
		p_ptr->cmd.dir = 5;
		p_ptr->cmd.cmd = 'u';
		repeat_check();
		do_cmd_use();
		/*cmd_insert(CMD_USE_AIMED);
		cmd_set_arg_target(cmd_get_top(), 1, DIR_TARGET);*/
	} else
	if (selected == 3) {
		/* cast a spell on the spot */
		p_ptr->cmd.dir = 5;
		p_ptr->cmd.cmd = 'm';
		repeat_check();
		do_cmd_cast_wrapper();
		/*if (textui_obj_cast_ret() >= 0) {
			cmd_set_arg_target(cmd_get_top(), 1, DIR_TARGET);
		}*/
	} else
	if (selected == 4) {
		/* attack a spot adjacent to the player */
		p_ptr->cmd.dir = coords_to_dir(cx, cy);
		p_ptr->cmd.arg = 16;
		p_ptr->cmd.cmd = '+';
		repeat_check();
		do_cmd_alter();
		/*cmd_insert(CMD_ALTER);
		cmd_set_arg_direction(cmd_get_top(), 0, coords_to_dir(cy,cx));*/
	} else
	if (selected == 5) {
		/* disarm an adjacent trap or chest */
		p_ptr->cmd.dir = coords_to_dir(cx, cy);
		p_ptr->cmd.arg = 1;
		p_ptr->cmd.cmd = 'D';
		repeat_check();
		do_cmd_disarm();
		/*cmd_insert(CMD_DISARM);
		cmd_set_arg_direction(cmd_get_top(), 0, coords_to_dir(cy,cx));*/
	} else
	if (selected == 6) {
		/* walk onto an adjacent spot even if there is a trap there */
		bool orig_disarm = easy_disarm;
		easy_disarm = always_pickup;
		p_ptr->cmd.dir = coords_to_dir(cx, cy);
		p_ptr->cmd.arg = 1;
		p_ptr->cmd.cmd = 'W';
		repeat_check();
		do_cmd_walk(always_pickup);
		easy_disarm = orig_disarm;
		/*cmd_insert(CMD_JUMP);
		cmd_set_arg_direction(cmd_get_top(), 0, coords_to_dir(cy,cx));*/
	} else
	if (selected == 7) {
		/* close a door */
		p_ptr->cmd.dir = coords_to_dir(cx, cy);
		/*p_ptr->cmd.arg = 1;*/
		p_ptr->cmd.cmd = 'c';
		repeat_check();
		do_cmd_close();
		/*cmd_insert(CMD_CLOSE);
		cmd_set_arg_direction(cmd_get_top(), 0, coords_to_dir(cy,cx));*/
	} else
	if (selected == 8) {
		/* open a door or chest */
		p_ptr->cmd.dir = coords_to_dir(cx, cy);
		/*p_ptr->cmd.arg = 1;*/
		p_ptr->cmd.cmd = 'o';
		repeat_check();
		do_cmd_open();
		/*cmd_insert(CMD_OPEN);
		cmd_set_arg_direction(cmd_get_top(), 0, coords_to_dir(cy,cx));*/
	} else
	if (selected == 9) {
		/* bash a door */
		p_ptr->cmd.dir = coords_to_dir(cx, cy);
		/*p_ptr->cmd.arg = 1;*/
		p_ptr->cmd.cmd = 'o';
		repeat_check();
		do_cmd_open();
		/*p_ptr->cmd.cmd = 'B';
		do_cmd_bash();*/
		/*cmd_insert(CMD_BASH);
		cmd_set_arg_direction(cmd_get_top(), 0, coords_to_dir(cy,cx));*/
	} else
	if (selected == 10) {
		/* jam a door */
		p_ptr->cmd.dir = coords_to_dir(cx, cy);
		/*p_ptr->cmd.arg = 1;*/
		p_ptr->cmd.cmd = 'j';
		repeat_check();
		do_cmd_spike();
		/*cmd_insert(CMD_JAM);
		cmd_set_arg_direction(cmd_get_top(), 0, coords_to_dir(cy,cx));*/
	} else
	if (selected == 11) {
		/* Tunnel in a direction */
		p_ptr->cmd.dir = coords_to_dir(cx, cy);
		p_ptr->cmd.arg = 16;
		p_ptr->cmd.cmd = 'T';
		repeat_check();
		do_cmd_tunnel();
		/*cmd_insert(CMD_TUNNEL);
		cmd_set_arg_direction(cmd_get_top(), 0, coords_to_dir(cy,cx));*/
	} else
	if (selected == 12) {
		/* Search */
		/*p_ptr->cmd.arg = 1;*/
		p_ptr->cmd.cmd = 's';
		repeat_check();
		do_cmd_search();
		/*cmd_insert(CMD_SEARCH);*/
	} else
	if (selected == 13) {
		/* pathfind to the spot */
		/*p_ptr->cmd.arg = 16;*/
		p_ptr->cmd.cmd = ',';
		do_cmd_pathfind(cx,cy);
		/*cmd_insert(CMD_PATHFIND);
		cmd_set_arg_point(cmd_get_top(), 0, cx, cy);*/
	} else
	if (selected == 14) {
		/* walk towards the spot */
		p_ptr->cmd.dir = coords_to_dir(cx, cy);
		p_ptr->cmd.cmd = ';';
		repeat_check();
		do_cmd_walk(always_pickup);
		/*cmd_insert(CMD_WALK);
		cmd_set_arg_direction(cmd_get_top(), 0, coords_to_dir(cy,cx));*/
	} else
	if (selected == 15) {
		/* run towards the spot */
		p_ptr->cmd.dir = coords_to_dir(cx, cy);
		p_ptr->cmd.cmd = '.';
		repeat_check();
		do_cmd_run();
		/*cmd_insert(CMD_RUN);
		cmd_set_arg_direction(cmd_get_top(), 0, coords_to_dir(cy,cx));*/
	} else
	if (selected == 16) {
		/* Fire ammo towards the spot */
		p_ptr->cmd.dir = 5;
		p_ptr->cmd.cmd = 'f';
		repeat_check();
		do_cmd_fire();
		/*cmd_insert(CMD_FIRE);
		cmd_set_arg_target(cmd_get_top(), 1, DIR_TARGET);*/
	} else
	if (selected == 17) {
		/* throw an item towards the spot */
		p_ptr->cmd.dir = 5;
		p_ptr->cmd.cmd = 'v';
		repeat_check();
		do_cmd_throw();
		/*cmd_insert(CMD_THROW);
 		cmd_set_arg_target(cmd_get_top(), 1, DIR_TARGET);*/
	} else
	if (selected == 18) {
		/* recall monster Info */
		monster_type *m_ptr = &m_list[c_ptr->m_idx];
		if (m_ptr) {

			/* Save screen */
			screen_save();
			button_backup_all(TRUE);

			/* Recall on screen */
			screen_roff_mon(m_ptr->r_idx, 0);

			/* wait for a key or mouse press */
			inkey();

			/* Load screen */
			button_restore();
			screen_load();
		}
	} else
	if (selected == 19) {
		/* issue a pet command */
		p_ptr->cmd.cmd = 'p';
		repeat_check();
		do_cmd_pet();
	}

	return 1;
}
Exemplo n.º 16
0
void loop() {

    // Make sure we don't update the map tile on screen when we don't need to!
    uint8_t update_display_window = 0;

    if ( first_time ) {
        first_time = 0;
        update_display_window = 1;
        }

    // Joystick displacement.
    int16_t dx = 0;
    int16_t dy = 0;
    uint8_t select_button_event = 0;

    // If the map has been zoomed in or out we need to do a redraw,
    // and will center the display window about the cursor.
    // So a zoom in-out will re-center over a mis-positioned cursor!
    
    // if the map changed as a result of a zoom button press
    if (shared_new_map_num != current_map_num) {
        #ifdef DEBUG_SCROLLING
            Serial.print("Zoom from ");
            Serial.print(current_map_num);
            Serial.print(" x ");
            Serial.print(cursor_map_x);
            Serial.print(" y ");
            Serial.print(cursor_map_y);
        #endif

        // change the map and figure out the position of the cursor on
        // the new map.
        set_zoom();

        // center the display window around the cursor 
        move_window_to(
            cursor_map_x - display_window_width/2, 
            cursor_map_y - display_window_height/2);

        #ifdef DEBUG_SCROLLING
            Serial.print(" to ");
            Serial.print(current_map_num);
            Serial.print(" x ");
            Serial.print(cursor_map_x);
            Serial.print(" y ");
            Serial.print(cursor_map_y);
            Serial.println();
        #endif

        // Changed the zoom level, so we want to redraw the window
        update_display_window = 1;
    }


    // Now, see if the joystick has moved, in which case we want to
    // also want to move the visible cursor on the screen.

    // Process joystick input.
    select_button_event = process_joystick(&dx, &dy);

    // the joystick routine filters out small changes, so anything non-0
    // is a real movement
    if ( abs(dx) > 0 || abs(dy) > 0 ) {
        // redraw the path if the cursor moves: (brute force yay)
        // comment out if you find it runs too slowly, and live with the
        // cursor erasing the path
        if ( path_length > 0 ) {
	  draw_path(path_length, path, current_map_num);
        }
        // Is the cursor getting near the edge of the screen?  If so
        // then scroll the map over by re-centering the window.

        uint16_t new_screen_map_x = screen_map_x;
        uint16_t new_screen_map_y = screen_map_y;
        uint8_t need_to_move = 0;

        uint16_t cursor_screen_x;
        uint16_t cursor_screen_y;
        if ( get_cursor_screen_x_y(&cursor_screen_x, &cursor_screen_y) ) {
            // if the cursor is visible, then adjust the display to 
            // to scroll if near the edge.

            if ( cursor_screen_x < screen_left_margin ) {
                new_screen_map_x = screen_map_x - screen_scroll_delta;
		move_cursor_by(3, 0);
                need_to_move = 1;
                }
            else if ( cursor_screen_x > screen_right_margin ) {
                new_screen_map_x = screen_map_x + screen_scroll_delta;
		move_cursor_by(-3, 0);
                need_to_move = 1;
            }

            if ( cursor_screen_y < screen_top_margin ) {
                new_screen_map_y = screen_map_y - screen_scroll_delta;
		move_cursor_by(0, 3);
                need_to_move = 1;
                }
            else if ( cursor_screen_y > screen_bottom_margin ) {
                new_screen_map_y = screen_map_y + screen_scroll_delta;
		move_cursor_by(0, -3);
                need_to_move = 1;
            }

            if ( need_to_move ) {
                // move the display window, leaving cursor at same lat-lon
	        move_window_to(new_screen_map_x, new_screen_map_y);
		
                update_display_window = 1;
                } 
            else {
                // erase old cursor, move, and draw new one, no need to 
                // redraw the underlying map tile
                erase_cursor();
                move_cursor_by(dx, dy);
                draw_cursor();
                }
            }

    }

    // at this point the screen is updated, with a new tile window and
    // cursor position if necessary

    // will only be down once, then waits for a min time before allowing
    // pres again.
    if (select_button_event) {
        // Button was pressed, we are selecting a point!
        #ifdef DEBUG_PATH
            Serial.print("x ");
            Serial.print(cursor_map_x);
            Serial.print(" y ");
            Serial.print(cursor_map_y);
            Serial.println();
        #endif

        // which press is this, the start or the stop selection?

        // If we are making a request to find a shortest path, we will send out
        // the request on the serial port and then wait for a response from the
        // server.  While this is happening, the client user interface is
        // suspended.

        // if the stop point, then we send out the server request and wait.
        if ( request_state == 0 ) {
            // collect the start point
            start_lat = cursor_lat;
            start_lon = cursor_lon;
            request_state = 1;
            }
        else if ( request_state == 1) {
            // collect the stop point
            stop_lat = cursor_lat;
            stop_lon = cursor_lon;
            request_state = 0;

            // send out the start and stop coordinates to the server
            Serial.print(start_lat);
            Serial.print(" "); 
            Serial.print(start_lon);
            Serial.print(" "); 
            Serial.print(stop_lat);
            Serial.print(" "); 
            Serial.print(stop_lon);
            Serial.println();

            // free any existing path
            if ( path_length > 0 ) {
                free(path);
                }

            // read the path from the serial port
            status_msg("WAITING");
            if ( read_path(&path_length, &path) ) {
                #ifdef DEBUG_PATH
                    uint8_t is_visible;
                    for (uint16_t i=0; i < path_length; i++) {
                        is_visible = is_coord_visible(path[i]);
                        Serial.print(i);
                        Serial.print(": ");
                        Serial.print(path[i].lat);
                        Serial.print(",");
                        Serial.print(path[i].lon);
                        Serial.print(is_visible ? "V": "");
                        Serial.println();
                        }
                #endif
                update_display_window = 1;
                }
            else {
                // should display this error on the screen
                Serial.print("Path read error, code ");
                Serial.println(path_errno);
                if ( path_errno == 1 ) {
                    status_msg("Path too long");
                    delay(5000);
                    }
                    
                }

            }
        } // end of select_button_event processing

    // do we have to redraw the map tile?  
    if (update_display_window) {
        #ifdef DEBUG_SCROLLING
            Serial.println("Screen update");
            Serial.print(current_map_num);
            Serial.print(" ");
            Serial.print(cursor_lon);
            Serial.print(" ");
            Serial.print(cursor_lat);
            Serial.println();
        #endif

	    
        draw_map_screen();
        draw_cursor();

        // Need to redraw any other things that are on the screen
        if ( path_length > 0 ) {
	  draw_path(path_length, path, current_map_num);
            }

        // force a redisplay of status message
        clear_status_msg();
        }

    // always update the status message area if message changes
    // Indicate which point we are waiting for
    if ( request_state == 0 ) {
        status_msg("FROM?");
        }
    else {
        status_msg("TO?");
        }
    }
Exemplo n.º 17
0
bool draw_graph_path(int colour){
	if (zoom_level == ZOOM_OUT){
		if (!points_equal(prev_zoomed_out_min_corner, NULL_CORNER) && !points_equal(prev_zoomed_out_max_corner, NULL_CORNER)){
			draw_image_segment(prev_zoomed_out_min_corner,  prev_zoomed_out_max_corner);
		}
	}
	else{
		//First check to see if when subtracted from, it's less than 0...
		prev_zoomed_in_min_corner.x = (prev_zoomed_in_min_corner.x - curr_image_pos.x < 0) ? 0 : prev_zoomed_in_min_corner.x - curr_image_pos.x;
		prev_zoomed_in_min_corner.y = (prev_zoomed_in_min_corner.y - curr_image_pos.y < 0) ? 0 : prev_zoomed_in_min_corner.y - curr_image_pos.y;

		//Then check to see if it's greater than the DISPLAY WIDTH
		prev_zoomed_in_min_corner.x = (prev_zoomed_in_min_corner.x > DISPLAY_WIDTH) ? DISPLAY_WIDTH : prev_zoomed_in_min_corner.x;
		prev_zoomed_in_min_corner.y = (prev_zoomed_in_min_corner.y > DISPLAY_HEIGHT) ? DISPLAY_HEIGHT : prev_zoomed_in_min_corner.y;

		//This is all to make sure we don't die a horrible death of sadness and line apocalypse (of negative displays).
		prev_zoomed_in_max_corner.x = (prev_zoomed_in_max_corner.x - curr_image_pos.x < 0) ? 0 : prev_zoomed_in_max_corner.x - curr_image_pos.x;
		prev_zoomed_in_max_corner.y = (prev_zoomed_in_max_corner.y - curr_image_pos.y < 0) ? 0 : prev_zoomed_in_max_corner.y - curr_image_pos.y;
		prev_zoomed_in_max_corner.x = (prev_zoomed_in_max_corner.x > DISPLAY_WIDTH) ? DISPLAY_WIDTH : prev_zoomed_in_max_corner.x;
		prev_zoomed_in_max_corner.y = (prev_zoomed_in_max_corner.y > DISPLAY_HEIGHT) ? DISPLAY_HEIGHT : prev_zoomed_in_max_corner.y;
		if (!points_equal(prev_zoomed_in_min_corner, NULL_CORNER) && !points_equal(prev_zoomed_in_max_corner, NULL_CORNER)){
			draw_image_segment(prev_zoomed_in_min_corner,  prev_zoomed_in_max_corner);
		}
		printf("Corners are now: %d, %d\n%d, %d", prev_zoomed_in_min_corner.x, prev_zoomed_in_min_corner.y, prev_zoomed_in_max_corner.x, prev_zoomed_in_max_corner.y);
	}

	if (points != NULL){
		prev_zoomed_out_min_corner = points->zoomed_out_min_corner;
		prev_zoomed_out_max_corner = points->zoomed_out_max_corner;

		prev_zoomed_in_min_corner = points->zoomed_in_min_corner;
		prev_zoomed_in_max_corner = points->zoomed_in_max_corner;
		if (zoom_level == ZOOM_OUT)
			draw_path(points->zoomed_out_ordered_point_arr, points->actual_size, colour);
		else{
			Point points_arr[points->actual_size];
			for (int i = 0; i < points->actual_size; i++){

				points_arr[i] = NULL_CORNER;
				points_arr[i].x = points->zoomed_in_ordered_point_arr[i].x - curr_image_pos.x;
				points_arr[i].y = points->zoomed_in_ordered_point_arr[i].y - curr_image_pos.y;

				if (points_arr[i].x < 0 && points_arr[i].y < 0){
					printf("Originally... %d is  %d, %d\n", i, points_arr[i].x, points_arr[i].y);
					while (points_arr[i].x < 0 || points_arr[i].y < 0){
						points_arr[i].x+=3;
						points_arr[i].y+=1;
					}
					printf("Now point (%d): %d %d\n", i, points_arr[i].x, points_arr[i].y);
				}

				if (points_arr[i].x >= DISPLAY_WIDTH){
					points_arr[i].x = DISPLAY_WIDTH - 1;
				}
				if (points_arr[i].y >= DISPLAY_HEIGHT){
					points_arr[i].y = DISPLAY_HEIGHT - 1;
				}
				if (points_arr[i].x < 0){
					points_arr[i].x = 0;
				}
				if (points_arr[i].y < 0){
					points_arr[i].y = 0;
				}
			}
			draw_path(points_arr, points->actual_size, colour);
			VLine(600, 0, 480, BLACK);
		}
		//destroy_path_points(points);
		return true;
	}
	return false;
}
Exemplo n.º 18
0
point path_search(point initial)
{       draw_path();
	//locate the next BLUE coordinateto move onto by searching the all 4 neighbouring points possible in a 2d plane
	//checking left pixel
	int neighbours_color = getpixel(initial.x-1, initial.y);
	if(neighbours_color==BLUE)
	{	point got_bluepixel;
		got_bluepixel.x=initial.x-1;
		got_bluepixel.y=initial.y;
		return(got_bluepixel);
	}

	//checking upper pixel
	neighbours_color = getpixel(initial.x, initial.y-1);
	if(neighbours_color==BLUE)
	{	point got_bluepixel;
		got_bluepixel.x=initial.x;
		got_bluepixel.y=initial.y-1;
		return(got_bluepixel);
	}

	//checking right pixel
	neighbours_color = getpixel(initial.x+1, initial.y);
	if(neighbours_color==BLUE)
	{	point got_bluepixel;
		got_bluepixel.x=initial.x+1;
		got_bluepixel.y=initial.y;
		return(got_bluepixel);
	}

	//checking lower pixel
	neighbours_color = getpixel(initial.x, initial.y+1);
	if(neighbours_color==BLUE)
	{	point got_bluepixel;
		got_bluepixel.x=initial.x;
		got_bluepixel.y=initial.y+1;
		return(got_bluepixel);
	}

	//checking upper-left pixel
	neighbours_color = getpixel(initial.x-1, initial.y-1);
	if(neighbours_color==BLUE)
	{	point got_bluepixel;
		got_bluepixel.x=initial.x-1;
		got_bluepixel.y=initial.y-1;
		return(got_bluepixel);
	}

	//checking upper-right pixel
	neighbours_color = getpixel(initial.x+1, initial.y-1);
	if(neighbours_color==BLUE)
	{	point got_bluepixel;
		got_bluepixel.x=initial.x+1;
		got_bluepixel.y=initial.y-1;
		return(got_bluepixel);
	}

	//checking lower-left pixel
	neighbours_color = getpixel(initial.x-1, initial.y+1);
	if(neighbours_color==BLUE)
	{	point got_bluepixel;
		got_bluepixel.x=initial.x-1;
		got_bluepixel.y=initial.y+1;
		return(got_bluepixel);
	}

	//checking lower-right pixel
	neighbours_color = getpixel(initial.x+1, initial.y+1);
	if(neighbours_color==BLUE)
	{	point got_bluepixel;
		got_bluepixel.x=initial.x+1;
		got_bluepixel.y=initial.y+1;
		return(got_bluepixel);
	}

	//if reached here, that means no blue pixel exists in perifery
	point got_bluepixel;
	got_bluepixel.x=-1;
	got_bluepixel.y=-1;
	return(got_bluepixel);
}
Exemplo n.º 19
0
void path_stroke(Path* path, Image *image, int color, double brush_size)
{
  draw_path (path, image, color, brush_size, false);
}
Exemplo n.º 20
0
/*
 * Handle "target" and "look".
 *
 * Note that this code can be called from "get_aim_dir()".
 *
 * Currently, when "flag" is true, that is, when
 * "interesting" grids are being used, and a directional key is used, we
 * only scroll by a single panel, in the direction requested, and check
 * for any interesting grids on that panel.  The "correct" solution would
 * actually involve scanning a larger set of grids, including ones in
 * panels which are adjacent to the one currently scanned, but this is
 * overkill for this function.  XXX XXX
 *
 * Hack -- targetting/observing an "outer border grid" may induce
 * problems, so this is not currently allowed.
 *
 * The player can use the direction keys to move among "interesting"
 * grids in a heuristic manner, or the "space", "+", and "-" keys to
 * move through the "interesting" grids in a sequential manner, or
 * can enter "location" mode, and use the direction keys to move one
 * grid at a time in any direction.  The "t" (set target) command will
 * only target a monster (as opposed to a location) if the monster is
 * target_able and the "interesting" mode is being used.
 *
 * The current grid is described using the "look" method above, and
 * a new command may be entered at any time, but note that if the
 * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
 * where "space" has no obvious meaning) then "space" will scan
 * through the description of the current grid until done, instead
 * of immediately jumping to the next "interesting" grid.  This
 * allows the "target" command to retain its old semantics.
 *
 * The "*", "+", and "-" keys may always be used to jump immediately
 * to the next (or previous) interesting grid, in the proper mode.
 *
 * The "return" key may always be used to scan through a complete
 * grid description (forever).
 *
 * This command will cancel any old target, even if used from
 * inside the "look" command.
 *
 *
 * 'mode' is one of TARGET_LOOK or TARGET_KILL.
 * 'x' and 'y' are the initial position of the target to be highlighted,
 * or -1 if no location is specified.
 * Returns TRUE if a target has been successfully set, FALSE otherwise.
 */
bool target_set_interactive(int mode, int x, int y)
{
	int py = p_ptr->py;
	int px = p_ptr->px;

	int path_n;
	u16b path_g[256];

	int i, d, m, t, bd;
	int wid, hgt, help_prompt_loc;

	bool done = FALSE;
	bool flag = TRUE;
	bool help = FALSE;

	//struct keypress query;
	ui_event press;

	/* These are used for displaying the path to the target */
	wchar_t path_char[MAX_RANGE_LGE];
	int path_attr[MAX_RANGE_LGE];
	struct point_set *targets;

	/* If we haven't been given an initial location, start on the
	   player. */
	if (x == -1 || y == -1)
	{
		x = p_ptr->px;
		y = p_ptr->py;
	}
	/* If we /have/ been given an initial location, make sure we
	   honour it by going into "free targetting" mode. */
	else
	{
		flag = FALSE;
	}

	/* Cancel target */
	target_set_monster(0);

	/* Cancel tracking */
	/* health_track(NULL); */

	/* Calculate the window location for the help prompt */
	Term_get_size(&wid, &hgt);
	help_prompt_loc = hgt - 1;
	
	/* Display the help prompt */
	prt("Press '?' for help.", help_prompt_loc, 0);

	/* Prepare the target set */
	targets = target_set_interactive_prepare(mode);

	/* Start near the player */
	m = 0;

	/* Interact */
	while (!done) {
		bool path_drawn = FALSE;
		
		/* Interesting grids */
		if (flag && point_set_size(targets))
		{
			y = targets->pts[m].y;
			x = targets->pts[m].x;

			/* Adjust panel if needed */
			if (adjust_panel_help(y, x, help)) handle_stuff(p_ptr);
		
			/* Update help */
			if (help) {
				bool good_target = target_able(cave_monster_at(cave, y, x));
				target_display_help(good_target, !(flag && point_set_size(targets)));
			}

			/* Find the path. */
			path_n = project_path(path_g, MAX_RANGE, py, px, y, x, PROJECT_THRU);

			/* Draw the path in "target" mode. If there is one */
			if (mode & (TARGET_KILL))
				path_drawn = draw_path(path_n, path_g, path_char, path_attr, py, px);

			/* Describe and Prompt */
			press = target_set_interactive_aux(y, x, mode);

			/* Remove the path */
			if (path_drawn) load_path(path_n, path_g, path_char, path_attr);

			/* Cancel tracking */
			/* health_track(NULL); */

			/* Assume no "direction" */
			d = 0;


			/* Analyze */
			if (press.type == EVT_MOUSE) {
				if (press.mouse.button == 3) {
					/* give the target selection command */
					press.mouse.button = 2;
					press.mouse.mods = KC_MOD_CONTROL;
				}
				if (press.mouse.button == 2) {
					y = KEY_GRID_Y(press);//.mouse.y;
					x = KEY_GRID_X(press);//.mouse.x;
					if (press.mouse.mods & KC_MOD_CONTROL) {
						/* same as keyboard target selection command below */
						struct monster *m = cave_monster_at(cave, y, x);

						if (target_able(m)) {
							/* Set up target information */
							monster_race_track(m->race);
							health_track(p_ptr, m);
							target_set_monster(m);
							done = TRUE;
						} else {
							bell("Illegal target!");
						}
					} else
					if (press.mouse.mods & KC_MOD_ALT) {
						/* go to spot - same as 'g' command below */
						cmd_insert(CMD_PATHFIND);
						cmd_set_arg_point(cmd_get_top(), 0, y, x);
						done = TRUE;
					} else
					{
						/* cancel look mode */
						done = TRUE;
					}
				} else
				/*if (press.mouse.button == 3) {
				} else*/
				{
					y = KEY_GRID_Y(press);//.mouse.y;
					x = KEY_GRID_X(press);//.mouse.x;
					if (cave->m_idx[y][x] || cave->o_idx[y][x]){// || cave->feat[y][x]&) {
						/* reset the flag, to make sure we stay in this mode if
						 * something is actually there */
						flag = FALSE;
						/* scan the interesting list and see if there in anything here */
						for (i = 0; i < point_set_size(targets); i++) {
							if ((y == targets->pts[i].y) && (x == targets->pts[i].x)) {
								m = i;
								flag = TRUE;
								break;
							}
						}
					} else {
						flag = FALSE;
					}
				}
			} else
			switch (press.key.code)
			{
				case ESCAPE:
				case 'q':
				{
					done = TRUE;
					break;
				}

				case ' ':
				case '*':
				case '+':
				{
					if (++m == point_set_size(targets))
						m = 0;

					break;
				}

				case '-':
				{
					if (m-- == 0)
						m = point_set_size(targets) - 1;

					break;
				}

				case 'p':
				{
					/* Recenter around player */
					verify_panel();

					/* Handle stuff */
					handle_stuff(p_ptr);

					y = p_ptr->py;
					x = p_ptr->px;
				}

				case 'o':
				{
					flag = FALSE;
					break;
				}

				case 'm':
				{
					break;
				}

				case 't':
				case '5':
				case '0':
				case '.':
				{
					struct monster *m = cave_monster_at(cave, y, x);

					if (target_able(m))
					{
						health_track(p_ptr, m);
						target_set_monster(m);
						done = TRUE;
					}
					else
					{
						bell("Illegal target!");
					}
					break;
				}

				case 'g':
				{
					cmd_insert(CMD_PATHFIND);
					cmd_set_arg_point(cmd_get_top(), 0, y, x);
					done = TRUE;
					break;
				}
				
				case '?':
				{
					help = !help;
					
					/* Redraw main window */
					p_ptr->redraw |= (PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIP);
					Term_clear();
					handle_stuff(p_ptr);
					if (!help)
						prt("Press '?' for help.", help_prompt_loc, 0);
					
					break;
				}

				default:
				{
					/* Extract direction */
					d = target_dir(press.key);

					/* Oops */
					if (!d) bell("Illegal command for target mode!");

					break;
				}
			}

			/* Hack -- move around */
			if (d)
			{
				int old_y = targets->pts[m].y;
				int old_x = targets->pts[m].x;

				/* Find a new monster */
				i = target_pick(old_y, old_x, ddy[d], ddx[d], targets);

				/* Scroll to find interesting grid */
				if (i < 0)
				{
					int old_wy = Term->offset_y;
					int old_wx = Term->offset_x;

					/* Change if legal */
					if (change_panel(d))
					{
						/* Recalculate interesting grids */
						point_set_dispose(targets);
						targets = target_set_interactive_prepare(mode);

						/* Find a new monster */
						i = target_pick(old_y, old_x, ddy[d], ddx[d], targets);

						/* Restore panel if needed */
						if ((i < 0) && modify_panel(Term, old_wy, old_wx))
						{
							/* Recalculate interesting grids */
							point_set_dispose(targets);
							targets = target_set_interactive_prepare(mode);
						}

						/* Handle stuff */
						handle_stuff(p_ptr);
					}
				}

				/* Use interesting grid if found */
				if (i >= 0) m = i;
			}
		}

		/* Arbitrary grids */
		else
		{
			/* Update help */
			if (help) 
			{
				bool good_target = target_able(cave_monster_at(cave, y, x));
				target_display_help(good_target, !(flag && point_set_size(targets)));
			}

			/* Find the path. */
			path_n = project_path(path_g, MAX_RANGE, py, px, y, x, PROJECT_THRU);

			/* Draw the path in "target" mode. If there is one */
			if (mode & (TARGET_KILL))
				path_drawn = draw_path (path_n, path_g, path_char, path_attr, py, px);

			/* Describe and Prompt (enable "TARGET_LOOK") */
			press = target_set_interactive_aux(y, x, mode | TARGET_LOOK);

			/* Remove the path */
			if (path_drawn)  load_path(path_n, path_g, path_char, path_attr);

			/* Cancel tracking */
			/* health_track(0); */

			/* Assume no direction */
			d = 0;

			/* Analyze the keypress */
			if (press.type == EVT_MOUSE) {
				if (press.mouse.button == 3) {
					/* give the target selection command */
					press.mouse.button = 2;
					press.mouse.mods = KC_MOD_CONTROL;
				}
				if (press.mouse.button == 2) {
					if (mode & (TARGET_KILL)) {
						if ((y == KEY_GRID_Y(press)) 
								&& (x == KEY_GRID_X(press))) {
							d = -1;
						}
					}
					y = KEY_GRID_Y(press);//.mouse.y;
					x = KEY_GRID_X(press);//.mouse.x;
					if (press.mouse.mods & KC_MOD_CONTROL) {
						/* same as keyboard target selection command below */
						target_set_location(y, x);
						done = TRUE;
					} else
					if (press.mouse.mods & KC_MOD_ALT) {
						/* go to spot - same as 'g' command below */
						cmd_insert(CMD_PATHFIND);
						cmd_set_arg_point(cmd_get_top(), 0, y, x);
						done = TRUE;
					} else
					{
						/* cancel look mode */
						done = TRUE;
						if (d == -1) {
							target_set_location(y, x);
							d = 0;
						}
					}
				} else
				/*if (press.mouse.button == 3) {
				} else*/
				{
					int dungeon_hgt = cave->height;
					int dungeon_wid = cave->width;

					y = KEY_GRID_Y(press);//.mouse.y;
					x = KEY_GRID_X(press);//.mouse.x;
				  
					if (Term) {
						if (press.mouse.y <= 1) {
							/* move the screen north */
							y--;
						} else
						if (press.mouse.y >= (Term->hgt - 2)) {
							/* move the screen south */
							y++;
						} else
						if (press.mouse.x <= COL_MAP) {
							/* move the screen in west */
							x--;
						} else
						if (press.mouse.x >= (Term->wid - 2)) {
							/* move the screen east */
							x++;
						}
					}
          
					if (y < 0) y = 0;
					if (x < 0) x = 0;
					if (y >= dungeon_hgt-1) y = dungeon_hgt-1;
					if (x >= dungeon_wid-1) x = dungeon_wid-1;

					/* Adjust panel if needed */
					if (adjust_panel_help(y, x, help))
					{
						/* Handle stuff */
						handle_stuff(p_ptr);

						/* Recalculate interesting grids */
						point_set_dispose(targets);
						targets = target_set_interactive_prepare(mode);
					}

					if (cave->m_idx[y][x] || cave->o_idx[y][x]) {
						/* scan the interesting list and see if there in anything here */
						for (i = 0; i < point_set_size(targets); i++) {
							if ((y == targets->pts[i].y) && (x == targets->pts[i].x)) {
								m = i;
								flag = TRUE;
								break;
							}
						}
					} else {
						flag = FALSE;
					}
				}
			} else
			switch (press.key.code)
			{
				case ESCAPE:
				case 'q':
				{
					done = TRUE;
					break;
				}

				case ' ':
				case '*':
				case '+':
				case '-':
				{
					break;
				}

				case 'p':
				{
					/* Recenter around player */
					verify_panel();

					/* Handle stuff */
					handle_stuff(p_ptr);

					y = p_ptr->py;
					x = p_ptr->px;
				}

				case 'o':
				{
					break;
				}

				case 'm':
				{
					flag = TRUE;

					m = 0;
					bd = 999;

					/* Pick a nearby monster */
					for (i = 0; i < point_set_size(targets); i++)
					{
						t = distance(y, x, targets->pts[i].y, targets->pts[i].x);

						/* Pick closest */
						if (t < bd)
						{
							m = i;
							bd = t;
						}
					}

					/* Nothing interesting */
					if (bd == 999) flag = FALSE;

					break;
				}

				case 't':
				case '5':
				case '0':
				case '.':
				{
					target_set_location(y, x);
					done = TRUE;
					break;
				}

				case 'g':
				{
					cmd_insert(CMD_PATHFIND);
					cmd_set_arg_point(cmd_get_top(), 0, y, x);
					done = TRUE;
					break;
				}

				case '?':
				{
					help = !help;
					
					/* Redraw main window */
					p_ptr->redraw |= (PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIP);
					Term_clear();
					handle_stuff(p_ptr);
					if (!help)
						prt("Press '?' for help.", help_prompt_loc, 0);
					
					break;
				}

				default:
				{
					/* Extract a direction */
					d = target_dir(press.key);

					/* Oops */
					if (!d) bell("Illegal command for target mode!");

					break;
				}
			}

			/* Handle "direction" */
			if (d)
			{
				int dungeon_hgt = cave->height;
				int dungeon_wid = cave->width;

				/* Move */
				x += ddx[d];
				y += ddy[d];

				/* Slide into legality */
				if (x >= dungeon_wid - 1) x--;
				else if (x <= 0) x++;

				/* Slide into legality */
				if (y >= dungeon_hgt - 1) y--;
				else if (y <= 0) y++;

				/* Adjust panel if needed */
				if (adjust_panel_help(y, x, help))
				{
					/* Handle stuff */
					handle_stuff(p_ptr);

					/* Recalculate interesting grids */
					point_set_dispose(targets);
					targets = target_set_interactive_prepare(mode);
				}
			}
		}
	}

	/* Forget */
	point_set_dispose(targets);

	/* Redraw as necessary */
	if (help)
	{
		p_ptr->redraw |= (PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIP);
		Term_clear();
	}
	else
	{
		prt("", 0, 0);
		prt("", help_prompt_loc, 0);
		p_ptr->redraw |= (PR_DEPTH | PR_STATUS);
	}

	/* Recenter around player */
	verify_panel();

	/* Handle stuff */
	handle_stuff(p_ptr);

	/* Failure to set target */
	if (!target_set) return (FALSE);

	/* Success */
	return (TRUE);
}
Exemplo n.º 21
0
void path_fill(Path* path, Image *image, int color)
{
  draw_path (path, image, color, 0, true);
}
Exemplo n.º 22
0
/*
 * Handle "target" and "look".
 *
 * Note that this code can be called from "get_aim_dir()".
 *
 * Currently, when "flag" is true, that is, when
 * "interesting" grids are being used, and a directional key is used, we
 * only scroll by a single panel, in the direction requested, and check
 * for any interesting grids on that panel.  The "correct" solution would
 * actually involve scanning a larger set of grids, including ones in
 * panels which are adjacent to the one currently scanned, but this is
 * overkill for this function.  XXX XXX
 *
 * Hack -- targetting/observing an "outer border grid" may induce
 * problems, so this is not currently allowed.
 *
 * The player can use the direction keys to move among "interesting"
 * grids in a heuristic manner, or the "space", "+", and "-" keys to
 * move through the "interesting" grids in a sequential manner, or
 * can enter "location" mode, and use the direction keys to move one
 * grid at a time in any direction.  The "t" (set target) command will
 * only target a monster (as opposed to a location) if the monster is
 * target_able and the "interesting" mode is being used.
 *
 * The current grid is described using the "look" method above, and
 * a new command may be entered at any time, but note that if the
 * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
 * where "space" has no obvious meaning) then "space" will scan
 * through the description of the current grid until done, instead
 * of immediately jumping to the next "interesting" grid.  This
 * allows the "target" command to retain its old semantics.
 *
 * The "*", "+", and "-" keys may always be used to jump immediately
 * to the next (or previous) interesting grid, in the proper mode.
 *
 * The "return" key may always be used to scan through a complete
 * grid description (forever).
 *
 * This command will cancel any old target, even if used from
 * inside the "look" command.
 *
 *
 * 'mode' is one of TARGET_LOOK or TARGET_KILL.
 * 'x' and 'y' are the initial position of the target to be highlighted,
 * or -1 if no location is specified.
 * Returns TRUE if a target has been successfully set, FALSE otherwise.
 */
bool target_set_interactive(int mode, int x, int y)
{
	int py = p_ptr->py;
	int px = p_ptr->px;

	int path_n;
	u16b path_g[256];

	int i, d, m, t, bd;
	int wid, hgt, help_prompt_loc;

	bool done = FALSE;
	bool flag = TRUE;
	bool help = FALSE;

	struct keypress query;

	/* These are used for displaying the path to the target */
	char path_char[MAX_RANGE];
	byte path_attr[MAX_RANGE];

	/* If we haven't been given an initial location, start on the
	   player. */
	if (x == -1 || y == -1)
	{
		x = p_ptr->px;
		y = p_ptr->py;
	}
    /* If we /have/ been given an initial location, make sure we
	   honour it by going into "free targetting" mode. */
	else
	{
		flag = FALSE;
	}

	/* Cancel target */
	target_set_monster(0);

	/* Cancel tracking */
	/* health_track(0); */

	/* Calculate the window location for the help prompt */
	Term_get_size(&wid, &hgt);
	help_prompt_loc = hgt - 1;
	
	/* Display the help prompt */
	prt("Press '?' for help.", help_prompt_loc, 0);

	/* Prepare the "temp" array */
	target_set_interactive_prepare(mode);

	/* Start near the player */
	m = 0;

	/* Interact */
	while (!done) {
		bool path_drawn = FALSE;
		
		/* Interesting grids */
		if (flag && temp_n)
		{
			y = temp_y[m];
			x = temp_x[m];

			/* Adjust panel if needed */
			if (adjust_panel_help(y, x, help)) handle_stuff();
		
			/* Update help */
			if (help) {
				bool good_target = (cave->m_idx[y][x] > 0) &&
					target_able(cave->m_idx[y][x]);
				target_display_help(good_target, !(flag && temp_n));
			}

			/* Find the path. */
			path_n = project_path(path_g, MAX_RANGE, py, px, y, x, PROJECT_THRU);

			/* Draw the path in "target" mode. If there is one */
			if (mode & (TARGET_KILL))
				path_drawn = draw_path(path_n, path_g, path_char, path_attr, py, px);

			/* Describe and Prompt */
			query = target_set_interactive_aux(y, x, mode);

			/* Remove the path */
			if (path_drawn) load_path(path_n, path_g, path_char, path_attr);

			/* Cancel tracking */
			/* health_track(0); */

			/* Assume no "direction" */
			d = 0;


			/* Analyze */
			switch (query.code)
			{
				case ESCAPE:
				case 'q':
				{
					done = TRUE;
					break;
				}

				case ' ':
				case '*':
				case '+':
				{
					if (++m == temp_n)
						m = 0;

					break;
				}

				case '-':
				{
					if (m-- == 0)
						m = temp_n - 1;

					break;
				}

				case 'p':
				{
					/* Recenter around player */
					verify_panel();

					/* Handle stuff */
					handle_stuff();

					y = p_ptr->py;
					x = p_ptr->px;
				}

				case 'o':
				{
					flag = FALSE;
					break;
				}

				case 'm':
				{
					break;
				}

				case 't':
				case '5':
				case '0':
				case '.':
				{
					int m_idx = cave->m_idx[y][x];

					if ((m_idx > 0) && target_able(m_idx))
					{
						health_track(p_ptr, m_idx);
						target_set_monster(m_idx);
						done = TRUE;
					}
					else
					{
						bell("Illegal target!");
					}
					break;
				}

				case 'g':
				{
					cmd_insert(CMD_PATHFIND);
					cmd_set_arg_point(cmd_get_top(), 0, y, x);
					done = TRUE;
					break;
				}
				
				case '?':
				{
					help = !help;
					
					/* Redraw main window */
					p_ptr->redraw |= (PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIP);
					Term_clear();
					handle_stuff();
					if (!help)
						prt("Press '?' for help.", help_prompt_loc, 0);
					
					break;
				}

				default:
				{
					/* Extract direction */
					d = target_dir(query);

					/* Oops */
					if (!d) bell("Illegal command for target mode!");

					break;
				}
			}

			/* Hack -- move around */
			if (d)
			{
				int old_y = temp_y[m];
				int old_x = temp_x[m];

				/* Find a new monster */
				i = target_pick(old_y, old_x, ddy[d], ddx[d]);

				/* Scroll to find interesting grid */
				if (i < 0)
				{
					int old_wy = Term->offset_y;
					int old_wx = Term->offset_x;

					/* Change if legal */
					if (change_panel(d))
					{
						/* Recalculate interesting grids */
						target_set_interactive_prepare(mode);

						/* Find a new monster */
						i = target_pick(old_y, old_x, ddy[d], ddx[d]);

						/* Restore panel if needed */
						if ((i < 0) && modify_panel(Term, old_wy, old_wx))
						{
							/* Recalculate interesting grids */
							target_set_interactive_prepare(mode);
						}

						/* Handle stuff */
						handle_stuff();
					}
				}

				/* Use interesting grid if found */
				if (i >= 0) m = i;
			}
		}

		/* Arbitrary grids */
		else
		{
			/* Update help */
			if (help) 
			{
				bool good_target = ((cave->m_idx[y][x] > 0) && target_able(cave->m_idx[y][x]));
				target_display_help(good_target, !(flag && temp_n));
			}

			/* Find the path. */
			path_n = project_path(path_g, MAX_RANGE, py, px, y, x, PROJECT_THRU);

			/* Draw the path in "target" mode. If there is one */
			if (mode & (TARGET_KILL))
				path_drawn = draw_path (path_n, path_g, path_char, path_attr, py, px);

			/* Describe and Prompt (enable "TARGET_LOOK") */
			query = target_set_interactive_aux(y, x, mode | TARGET_LOOK);

			/* Remove the path */
			if (path_drawn)  load_path(path_n, path_g, path_char, path_attr);

			/* Cancel tracking */
			/* health_track(0); */

			/* Assume no direction */
			d = 0;

			/* Analyze the keypress */
			switch (query.code)
			{
				case ESCAPE:
				case 'q':
				{
					done = TRUE;
					break;
				}

				case ' ':
				case '*':
				case '+':
				case '-':
				{
					break;
				}

				case 'p':
				{
					/* Recenter around player */
					verify_panel();

					/* Handle stuff */
					handle_stuff();

					y = p_ptr->py;
					x = p_ptr->px;
				}

				case 'o':
				{
					break;
				}

				case 'm':
				{
					flag = TRUE;

					m = 0;
					bd = 999;

					/* Pick a nearby monster */
					for (i = 0; i < temp_n; i++)
					{
						t = distance(y, x, temp_y[i], temp_x[i]);

						/* Pick closest */
						if (t < bd)
						{
							m = i;
							bd = t;
						}
					}

					/* Nothing interesting */
					if (bd == 999) flag = FALSE;

					break;
				}

				case 't':
				case '5':
				case '0':
				case '.':
				{
					target_set_location(y, x);
					done = TRUE;
					break;
				}

				case 'g':
				{
					cmd_insert(CMD_PATHFIND);
					cmd_set_arg_point(cmd_get_top(), 0, y, x);
					done = TRUE;
					break;
				}

				case '?':
				{
					help = !help;
					
					/* Redraw main window */
					p_ptr->redraw |= (PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIP);
					Term_clear();
					handle_stuff();
					if (!help)
						prt("Press '?' for help.", help_prompt_loc, 0);
					
					break;
				}

				default:
				{
					/* Extract a direction */
					d = target_dir(query);

					/* Oops */
					if (!d) bell("Illegal command for target mode!");

					break;
				}
			}

			/* Handle "direction" */
			if (d)
			{
				int dungeon_hgt = (p_ptr->depth == 0) ? TOWN_HGT : DUNGEON_HGT;
				int dungeon_wid = (p_ptr->depth == 0) ? TOWN_WID : DUNGEON_WID;

				/* Move */
				x += ddx[d];
				y += ddy[d];

				/* Slide into legality */
				if (x >= dungeon_wid - 1) x--;
				else if (x <= 0) x++;

				/* Slide into legality */
				if (y >= dungeon_hgt - 1) y--;
				else if (y <= 0) y++;

				/* Adjust panel if needed */
				if (adjust_panel_help(y, x, help))
				{
					/* Handle stuff */
					handle_stuff();

					/* Recalculate interesting grids */
					target_set_interactive_prepare(mode);
				}
			}
		}
	}

	/* Forget */
	temp_n = 0;

	/* Redraw as necessary */
	if (help)
	{
		p_ptr->redraw |= (PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIP);
		Term_clear();
	}
	else
	{
		prt("", 0, 0);
		prt("", help_prompt_loc, 0);
		p_ptr->redraw |= (PR_DEPTH | PR_STATUS);
	}

	/* Recenter around player */
	verify_panel();

	/* Handle stuff */
	handle_stuff();

	/* Failure to set target */
	if (!target_set) return (FALSE);

	/* Success */
	return (TRUE);
}