aboutsummaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
Diffstat (limited to 'map.c')
-rw-r--r--map.c54
1 files changed, 28 insertions, 26 deletions
diff --git a/map.c b/map.c
index 2abaf68..dd062ce 100644
--- a/map.c
+++ b/map.c
@@ -632,7 +632,7 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
char **visited = NULL;
Path path = NULL;
- set_message("You've entered the map editor. 'q' to quit");
+ set_message("You've entered the map editor. '%c' to quit", KEYBINDING_QUIT);
draw_map(*map, NULL, *width, *height, *start, *goal, NULL, path, visited, NULL);
MEVENT event;
@@ -646,7 +646,8 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
while (1) {
int ch = getch();
- /*
+ /* WARNING: these might change. If something doesn't work, see config.h
+ *
* Keybindings:
* [k] \
* [h] [l] } Move the view
@@ -656,9 +657,6 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
* [H] [L] } Move the view faster
* [J] /
*
- * [z] - Move the view to the top left corner
- * [x] - Move the view to the bottom right corner
- *
* [g] followed by:
* [s] - Move the view to the start
* [e] - Move the view to the end
@@ -672,6 +670,8 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
*
* [r] - Reverse path
*
+ * [t] - Show time it took to calculate last path
+ *
* [c] - Clear the map
*
* [s] - Save the map to a plaintext file
@@ -685,21 +685,19 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
* Drag with MMB to move the view (buggy)
*/
switch (ch) {
- case 'q': clear_message(); visited_free(visited, *height); path_free(path, *height); mousemask(oldmask, NULL); printf("\033[?1003l\n"); return;
+ case KEYBINDING_QUIT: clear_message(); visited_free(visited, *height); path_free(path, *height); mousemask(oldmask, NULL); printf("\033[?1003l\n"); return;
- case 'h': map_offset_x += 2; break;
- case 'l': map_offset_x -= 2; break;
- case 'j': map_offset_y -= 1; break;
- case 'k': map_offset_y += 1; break;
+ case KEYBINDING_LEFT: map_offset_x += 2; break;
+ case KEYBINDING_RIGHT: map_offset_x -= 2; break;
+ case KEYBINDING_DOWN: map_offset_y -= 1; break;
+ case KEYBINDING_UP: map_offset_y += 1; break;
- case 'H': clear(); map_offset_x += 20; break;
- case 'L': clear(); map_offset_x -= 20; break;
- case 'J': clear(); map_offset_y -= 10; break;
- case 'K': clear(); map_offset_y += 10; break;
+ case KEYBINDING_FLEFT: map_offset_x += 20; break;
+ case KEYBINDING_FRIGHT: map_offset_x -= 20; break;
+ case KEYBINDING_FDOWN: map_offset_y -= 10; break;
+ case KEYBINDING_FUP: map_offset_y += 10; break;
- case 'z': clear(); map_offset_x = 2; map_offset_y = 1; break; /* Move to top left corner */
- case 'x': clear(); map_offset_x = - *width * 2 + COLS - 2; map_offset_y = - *height + LINES - 2; break; /* Move to bottom right corner */
- case 'a':
+ case KEYBINDING_TOGGLE_PATHFINDING:
should_pathfind = !should_pathfind;
if (should_pathfind) {
set_message("Will pathfind");
@@ -713,14 +711,14 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
print_message(*height);
break;
- case 'g':
+ case KEYBINDING_GOTO:
switch (getch()) {
- case 's':
+ case KEYBINDING_GOTO_ST:
clear();
map_offset_x = -start->x * 2 + COLS/2;
map_offset_y = -start->y + LINES/2;
break;
- case 'e':
+ case KEYBINDING_GOTO_GL:
clear();
map_offset_x = -goal->x * 2 + COLS/2;
map_offset_y = -goal->y + LINES/2;
@@ -728,7 +726,7 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
}
break;
- case 'd':
+ case KEYBINDING_ALGO:
if (path_func == astar_path) { set_message("Dijkstra's"); path_func = &dijkstra_path; }
else { set_message("A*"); path_func = &astar_path; };
@@ -736,7 +734,7 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
if (should_pathfind) path = path_func(dirs, *map, NULL, *width, *height, *start, *goal, visited, 0);
break;
- case '4':
+ case KEYBINDING_DIRS:
if (dirs == 4) { set_message("8 directions"); dirs = 8; }
else { set_message("4 directions"); dirs = 4; };
@@ -744,7 +742,7 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
if (should_pathfind) path = path_func(dirs, *map, NULL, *width, *height, *start, *goal, visited, 0);
break;
- case 'f':
+ case KEYBINDING_WRAPAROUND:
wraparound_enabled = !wraparound_enabled;
if (wraparound_enabled)
set_message("Enabled wraparound, only works on Dijkstra's")
@@ -757,11 +755,11 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
}
break;
- case 'r':
+ case KEYBINDING_REVERSE_PATH:
path_reverse(&path, *width, *height, start, goal);
break;
- case 'c':
+ case KEYBINDING_CLEAR:
map_free(*map, *height);
path_free(path, *height);
*map = empty_map(*width, *height);
@@ -770,7 +768,11 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
}
break;
- case 's':
+ case KEYBINDING_PATH_TIME:
+ set_message("%f seconds", path_time); print_message(*height);
+ break;
+
+ case KEYBINDING_SAVE_MAP:
curs_set(2); /* Show the cursor */
echo(); /* Echo characters */