aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorKirill Petrashin <kirill8201@yandex.ru>2026-04-15 18:13:42 +0300
committerKirill Petrashin <kirill8201@yandex.ru>2026-04-15 18:13:42 +0300
commitc6db3a75f756d790ede966c34adc3dbc793803d1 (patch)
tree57740daaa72db5ad79fb58e51c9b83aedf9d63d3 /main.c
parent6427ca899baaf564f09b4610c433de88d3520045 (diff)
downloadastar-c6db3a75f756d790ede966c34adc3dbc793803d1.tar.xz
Try to implement costs, fail
Diffstat (limited to 'main.c')
-rw-r--r--main.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/main.c b/main.c
index f299d1f..93ce49f 100644
--- a/main.c
+++ b/main.c
@@ -15,8 +15,6 @@
#include "bmp.h"
/* So, TODO for now:
- - Allow maps to have costs
- - Maybe make map editor the main thing
- More messages
- check ppq_insert() order
- more info in anim()?
@@ -29,6 +27,8 @@
- time
- Comments */
+/* FIXME: Costs are broken */
+
void sigint_handler(int sig) {
(void)sig; /* We know it's a SIGINT */
endwin();
@@ -63,6 +63,7 @@ int main(int argc, char **argv) {
Position start_pos, end_pos;
size_t width, height;
Map map = NULL;
+ size_t **cell_costs = NULL;
size_t mwidth = 20; /* Maze width */
size_t mheight = 10; /* Maze height */
@@ -86,8 +87,6 @@ int main(int argc, char **argv) {
* -b {filename} to just generate a bitmap, no interface
* -4 for four directions
* -8 for eight directions */
- /* TODO: Argument to choose the algorithm */
- /* TODO: Argument to set seed */
int opt;
while ((opt = getopt(argc, argv, ":adm:f:b:48")) != -1) {
switch (opt) {
@@ -277,7 +276,26 @@ int main(int argc, char **argv) {
path_free(path, height);
path = path_func(dirs, map, NULL, width, height, start_pos, end_pos, visited, anim);
}
- break;
+ break;
+
+ case 'c': /* Load a cost file */
+ curs_set(2); /* Show the cursor */
+ echo(); /* Echo characters */
+
+ set_message(FILENAME_PROMPT);
+ print_message(height);
+ char cost_filename[FILENAME_BUF_SIZE] = "\0";
+ mvgetnstr(height + map_offset_y + 1, map_offset_x - 2 + sizeof(FILENAME_PROMPT), cost_filename, FILENAME_BUF_SIZE - 1);
+
+ cell_costs = file_plaintext_costs(cost_filename, width, height);
+ path_free(path, height);
+ path = path_func(dirs, map, cell_costs, width, height, start_pos, end_pos, visited, anim);
+ /* TODO: figure out how to print actual costs */
+ cost_free(cell_costs, height);
+
+ curs_set(0); /* Hide the cursor */
+ noecho(); /* Don't echo characters */
+ break;
case 'e':
is_maze = 0;