aboutsummaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
Diffstat (limited to 'map.c')
-rw-r--r--map.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/map.c b/map.c
index 22b88ec..a0d0f23 100644
--- a/map.c
+++ b/map.c
@@ -248,6 +248,35 @@ Map file_plaintext_map(char *filename, size_t *width, size_t *height, Position *
return map;
}
+size_t **file_plaintext_costs(char *filename, size_t width, size_t height) {
+ FILE *file = fopen(filename, "r");
+ if (file == NULL) {
+ error("Failed to open file %s\n", filename);
+ }
+
+ size_t fw, fh; /* file width and height */
+ if (fscanf(file, "%zux%zu\n", &fw, &fh) != 2) {
+ error("Failed reading size of cost file %s\n", filename);
+ }
+ if (fw != width || fh != height) {
+ set_message("Wrong size (%zux%zu vs %zux%zu) in cost file %s\n", fw, fh, width, height, filename);
+ print_message(height);
+ return NULL;
+ }
+
+ size_t **costs = cost_new(width, height);
+ if (costs == NULL) error("Failed to create a new costs array\n");
+
+ for (size_t row = 0; row < fh; row++) {
+ for (size_t col = 0; col < fw; col++) {
+ if (fscanf(file, "%zu", &costs[row][col]) != 1) error("Failed reading cost on x = %zu, y = %zu in cost file %s\n", col, row, filename);
+ }
+ fgetc(file); /* the newline */
+ }
+
+ return costs;
+}
+
void map_to_file_plaintext(char *filename, Map map, size_t width, size_t height, Position start, Position end) {
FILE *file = fopen(filename, "w");
if (file == NULL) {
@@ -606,6 +635,7 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
for (size_t i = map_offset_x; i < *width*2 + map_offset_x; i++) {
mvaddch(event.y, i, '=');
}
+ mvprintw(event.y, map_offset_x, "%u", event.y - map_offset_y);
};
size_t new_height = event.y - map_offset_y;
@@ -653,6 +683,7 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
mvaddch(i, new_width * 2 + map_offset_x, '|');
mvaddch(i, new_width * 2 + map_offset_x + 1, '|');
}
+ mvprintw(map_offset_y, new_width*2 + map_offset_x, "%u", (event.x - map_offset_x) / 2);
};
new_width = (event.x - map_offset_x) / 2;